]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/render/core.cpp
Unify wield item handling (#8677)
[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
28 RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud)
29         : device(_device), driver(device->getVideoDriver()), smgr(device->getSceneManager()),
30         guienv(device->getGUIEnvironment()), client(_client), camera(client->getCamera()),
31         mapper(client->getMinimap()), hud(_hud)
32 {
33         screensize = driver->getScreenSize();
34         virtual_size = screensize;
35 }
36
37 RenderingCore::~RenderingCore()
38 {
39         clearTextures();
40 }
41
42 void RenderingCore::initialize()
43 {
44         // have to be called late as the VMT is not ready in the constructor:
45         initTextures();
46 }
47
48 void RenderingCore::updateScreenSize()
49 {
50         virtual_size = screensize;
51         clearTextures();
52         initTextures();
53 }
54
55 void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
56                 bool _draw_wield_tool, bool _draw_crosshair)
57 {
58         v2u32 ss = driver->getScreenSize();
59         if (screensize != ss) {
60                 screensize = ss;
61                 updateScreenSize();
62         }
63         skycolor = _skycolor;
64         show_hud = _show_hud;
65         show_minimap = _show_minimap;
66         draw_wield_tool = _draw_wield_tool;
67         draw_crosshair = _draw_crosshair;
68
69         beforeDraw();
70         drawAll();
71 }
72
73 void RenderingCore::draw3D()
74 {
75         smgr->drawAll();
76         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
77         if (!show_hud)
78                 return;
79         hud->drawSelectionMesh();
80         if (draw_wield_tool)
81                 camera->drawWieldedTool();
82 }
83
84 void RenderingCore::drawHUD()
85 {
86         if (show_hud) {
87                 if (draw_crosshair)
88                         hud->drawCrosshair();
89                 hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
90                 hud->drawLuaElements(camera->getOffset());
91                 camera->drawNametags();
92                 if (mapper && show_minimap)
93                         mapper->drawMinimap();
94         }
95         guienv->drawAll();
96 }
97
98 void RenderingCore::drawPostFx()
99 {
100         client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());
101 }