]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/renderingengine.h
refacto: rendering engine singleton removal step 1 (filesystem)
[dragonfireclient.git] / src / client / renderingengine.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
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 #pragma once
22
23 #include <vector>
24 #include <memory>
25 #include <string>
26 #include "irrlichttypes_extrabloated.h"
27 #include "debug.h"
28
29 class ITextureSource;
30 class Camera;
31 class Client;
32 class LocalPlayer;
33 class Hud;
34 class Minimap;
35
36 class RenderingCore;
37
38 class RenderingEngine
39 {
40 public:
41         RenderingEngine(IEventReceiver *eventReceiver);
42         ~RenderingEngine();
43
44         v2u32 getWindowSize() const;
45         void setResizable(bool resize);
46
47         video::IVideoDriver *getVideoDriver() { return driver; }
48
49         static const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
50         static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
51         static float getDisplayDensity();
52         static v2u32 getDisplaySize();
53
54         bool setupTopLevelWindow(const std::string &name);
55         void setupTopLevelXorgWindow(const std::string &name);
56         bool setWindowIcon();
57         bool setXorgWindowIconFromPath(const std::string &icon_file);
58         static bool print_video_modes();
59
60         static RenderingEngine *get_instance() { return s_singleton; }
61
62         io::IFileSystem *get_filesystem()
63         {
64                 return m_device->getFileSystem();
65         }
66
67         static video::IVideoDriver *get_video_driver()
68         {
69                 sanity_check(s_singleton && s_singleton->m_device);
70                 return s_singleton->m_device->getVideoDriver();
71         }
72
73         static scene::IMeshCache *get_mesh_cache()
74         {
75                 sanity_check(s_singleton && s_singleton->m_device);
76                 return s_singleton->m_device->getSceneManager()->getMeshCache();
77         }
78
79         static scene::ISceneManager *get_scene_manager()
80         {
81                 sanity_check(s_singleton && s_singleton->m_device);
82                 return s_singleton->m_device->getSceneManager();
83         }
84
85         static irr::IrrlichtDevice *get_raw_device()
86         {
87                 sanity_check(s_singleton && s_singleton->m_device);
88                 return s_singleton->m_device;
89         }
90
91         static u32 get_timer_time()
92         {
93                 sanity_check(s_singleton && s_singleton->m_device &&
94                                 s_singleton->m_device->getTimer());
95                 return s_singleton->m_device->getTimer()->getTime();
96         }
97
98         static gui::IGUIEnvironment *get_gui_env()
99         {
100                 sanity_check(s_singleton && s_singleton->m_device);
101                 return s_singleton->m_device->getGUIEnvironment();
102         }
103
104         inline static void draw_load_screen(const std::wstring &text,
105                         gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
106                         float dtime = 0, int percent = 0, bool clouds = true)
107         {
108                 s_singleton->_draw_load_screen(
109                                 text, guienv, tsrc, dtime, percent, clouds);
110         }
111
112         inline static void draw_menu_scene(
113                         gui::IGUIEnvironment *guienv, float dtime, bool clouds)
114         {
115                 s_singleton->_draw_menu_scene(guienv, dtime, clouds);
116         }
117
118         inline static void draw_scene(video::SColor skycolor, bool show_hud,
119                         bool show_minimap, bool draw_wield_tool, bool draw_crosshair)
120         {
121                 s_singleton->_draw_scene(skycolor, show_hud, show_minimap,
122                                 draw_wield_tool, draw_crosshair);
123         }
124
125         inline static void initialize(Client *client, Hud *hud)
126         {
127                 s_singleton->_initialize(client, hud);
128         }
129
130         inline static void finalize() { s_singleton->_finalize(); }
131
132         static bool run()
133         {
134                 sanity_check(s_singleton && s_singleton->m_device);
135                 return s_singleton->m_device->run();
136         }
137
138         static std::vector<core::vector3d<u32>> getSupportedVideoModes();
139         static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
140
141 private:
142         void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv,
143                         ITextureSource *tsrc, float dtime = 0, int percent = 0,
144                         bool clouds = true);
145
146         void _draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime = 0,
147                         bool clouds = true);
148
149         void _draw_scene(video::SColor skycolor, bool show_hud, bool show_minimap,
150                         bool draw_wield_tool, bool draw_crosshair);
151
152         void _initialize(Client *client, Hud *hud);
153
154         void _finalize();
155
156         std::unique_ptr<RenderingCore> core;
157         irr::IrrlichtDevice *m_device = nullptr;
158         irr::video::IVideoDriver *driver;
159         static RenderingEngine *s_singleton;
160 };