]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/render/core.cpp
3c5aa8eff9edf5cfdbb561a62dd0ae88cf6d2459
[dragonfireclient.git] / src / client / render / core.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include "core.h"
22 #include "client/camera.h"
23 #include "client/client.h"
24 #include "client/clientmap.h"
25 #include "client/hud.h"
26 #include "client/minimap.h"
27 #include "gui/tracers.h"
28
29 RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud, Tracers *_tracers)
30         : device(_device), driver(device->getVideoDriver()), smgr(device->getSceneManager()),
31         guienv(device->getGUIEnvironment()), client(_client), camera(client->getCamera()),
32         mapper(client->getMinimap()), hud(_hud), tracers(_tracers)
33 {
34         screensize = driver->getScreenSize();
35         virtual_size = screensize;
36 }
37
38 RenderingCore::~RenderingCore()
39 {
40         clearTextures();
41 }
42
43 void RenderingCore::initialize()
44 {
45         // have to be called late as the VMT is not ready in the constructor:
46         initTextures();
47 }
48
49 void RenderingCore::updateScreenSize()
50 {
51         virtual_size = screensize;
52         clearTextures();
53         initTextures();
54 }
55
56 void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
57                 bool _draw_wield_tool, bool _draw_crosshair, bool _draw_tracers)
58 {
59         v2u32 ss = driver->getScreenSize();
60         if (screensize != ss) {
61                 screensize = ss;
62                 updateScreenSize();
63         }
64         skycolor = _skycolor;
65         show_hud = _show_hud;
66         show_minimap = _show_minimap;
67         draw_wield_tool = _draw_wield_tool;
68         draw_crosshair = _draw_crosshair;
69         draw_tracers = _draw_tracers;
70
71         beforeDraw();
72         drawAll();
73 }
74
75 void RenderingCore::draw3D()
76 {
77         
78         smgr->drawAll();
79         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
80         if (!show_hud)
81                 return;
82         hud->drawSelectionMesh();
83         if (draw_tracers)
84                 tracers->draw(driver, client);
85         if (draw_wield_tool)
86                 camera->drawWieldedTool();
87 }
88
89 void RenderingCore::drawHUD()
90 {
91         if (show_hud) {
92                 if (draw_crosshair)
93                         hud->drawCrosshair();
94         
95                 hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
96                 hud->drawLuaElements(camera->getOffset());
97                 camera->drawNametags();
98                 if (mapper && show_minimap)
99                         mapper->drawMinimap();
100         }
101         guienv->drawAll();
102 }
103
104 void RenderingCore::drawPostFx()
105 {
106         client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());
107 }