]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/render/core.cpp
Revert "Make Lint Happy"
[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 <iostream>
22 #include "core.h"
23 #include "client/camera.h"
24 #include "client/client.h"
25 #include "client/clientmap.h"
26 #include "client/hud.h"
27 #include "client/minimap.h"
28 #include "client/content_cao.h"
29
30 RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud)
31         : device(_device), driver(device->getVideoDriver()), smgr(device->getSceneManager()),
32         guienv(device->getGUIEnvironment()), client(_client), camera(client->getCamera()),
33         mapper(client->getMinimap()), hud(_hud)
34 {
35         screensize = driver->getScreenSize();
36         virtual_size = screensize;
37 }
38
39 RenderingCore::~RenderingCore()
40 {
41         clearTextures();
42 }
43
44 void RenderingCore::initialize()
45 {
46         // have to be called late as the VMT is not ready in the constructor:
47         initTextures();
48 }
49
50 void RenderingCore::updateScreenSize()
51 {
52         virtual_size = screensize;
53         clearTextures();
54         initTextures();
55 }
56
57 void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
58                 bool _draw_wield_tool, bool _draw_crosshair, bool _draw_tracers, bool _draw_esp)
59 {
60         v2u32 ss = driver->getScreenSize();
61         if (screensize != ss) {
62                 screensize = ss;
63                 updateScreenSize();
64         }
65         skycolor = _skycolor;
66         show_hud = _show_hud;
67         show_minimap = _show_minimap;
68         draw_wield_tool = _draw_wield_tool;
69         draw_crosshair = _draw_crosshair;
70         draw_tracers = _draw_tracers;
71         draw_esp = _draw_esp;
72                 
73         beforeDraw();
74         drawAll();
75 }
76
77 void RenderingCore::drawTracersAndESP()
78 {
79         ClientEnvironment &env = client->getEnv();
80         Camera *camera = client->getCamera();
81         
82         v3f camera_offset = intToFloat(camera->getOffset(), BS);
83         
84         v3f eye_pos = (camera->getPosition() + camera->getDirection() - camera_offset);
85         
86         video::SMaterial material, oldmaterial;
87         oldmaterial = driver->getMaterial2D();
88         material.setFlag(video::EMF_LIGHTING, false);
89         material.setFlag(video::EMF_BILINEAR_FILTER, false);
90         material.setFlag(video::EMF_ZBUFFER, false);
91         material.setFlag(video::EMF_ZWRITE_ENABLE, false);
92         driver->setMaterial(material);
93         
94         auto allObjects = env.getAllActiveObjects();
95         for (auto &it : allObjects) {
96                 ClientActiveObject *cao = it.second;
97                 if (cao->isLocalPlayer() || cao->getParent())
98                         continue;
99                 GenericCAO *obj = dynamic_cast<GenericCAO *>(cao);
100                 if (! obj)
101                         continue;
102                 aabb3f box;
103                 if (! obj->getSelectionBox(&box))
104                         continue;
105                 v3f pos = obj->getPosition();
106                 pos -= camera_offset;
107                 box.MinEdge += pos;
108                 box.MaxEdge += pos;
109                 pos = box.getCenter();
110                 if (draw_esp)
111                         driver->draw3DBox(box, video::SColor(255, 255, 255, 255));
112                 if (draw_tracers)
113                         driver->draw3DLine(eye_pos, pos, video::SColor(255, 255, 255, 255));
114         }
115         
116         driver->setMaterial(oldmaterial);
117 }
118
119 void RenderingCore::draw3D()
120 {
121         smgr->drawAll();
122         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
123         if (!show_hud)
124                 return;
125         hud->drawSelectionMesh();
126         if (draw_tracers || draw_esp)
127                 drawTracersAndESP();
128         if (draw_wield_tool)
129                 camera->drawWieldedTool();
130 }
131
132 void RenderingCore::drawHUD()
133 {
134         if (show_hud) {
135                 if (draw_crosshair)
136                         hud->drawCrosshair();
137         
138                 hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
139                 hud->drawLuaElements(camera->getOffset());
140                 camera->drawNametags();
141                 if (mapper && show_minimap)
142                         mapper->drawMinimap();
143         }
144         guienv->drawAll();
145 }
146
147 void RenderingCore::drawPostFx()
148 {
149         client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());
150 }