Minetest  5.4.0
renderingengine.h
Go to the documentation of this file.
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>
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 
39 {
40 public:
41  RenderingEngine(IEventReceiver *eventReceiver);
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 
61 
62  static io::IFileSystem *get_filesystem()
63  {
65  return s_singleton->m_device->getFileSystem();
66  }
67 
68  static video::IVideoDriver *get_video_driver()
69  {
71  return s_singleton->m_device->getVideoDriver();
72  }
73 
74  static scene::IMeshCache *get_mesh_cache()
75  {
77  return s_singleton->m_device->getSceneManager()->getMeshCache();
78  }
79 
80  static scene::ISceneManager *get_scene_manager()
81  {
83  return s_singleton->m_device->getSceneManager();
84  }
85 
86  static irr::IrrlichtDevice *get_raw_device()
87  {
89  return s_singleton->m_device;
90  }
91 
92  static u32 get_timer_time()
93  {
95  s_singleton->m_device->getTimer());
96  return s_singleton->m_device->getTimer()->getTime();
97  }
98 
99  static gui::IGUIEnvironment *get_gui_env()
100  {
102  return s_singleton->m_device->getGUIEnvironment();
103  }
104 
105  inline static void draw_load_screen(const std::wstring &text,
106  gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
107  float dtime = 0, int percent = 0, bool clouds = true)
108  {
110  text, guienv, tsrc, dtime, percent, clouds);
111  }
112 
113  inline static void draw_menu_scene(
114  gui::IGUIEnvironment *guienv, float dtime, bool clouds)
115  {
116  s_singleton->_draw_menu_scene(guienv, dtime, clouds);
117  }
118 
119  inline static void draw_scene(video::SColor skycolor, bool show_hud,
120  bool show_minimap, bool draw_wield_tool, bool draw_crosshair)
121  {
122  s_singleton->_draw_scene(skycolor, show_hud, show_minimap,
123  draw_wield_tool, draw_crosshair);
124  }
125 
126  inline static void initialize(Client *client, Hud *hud)
127  {
129  }
130 
131  inline static void finalize() { s_singleton->_finalize(); }
132 
133  static bool run()
134  {
136  return s_singleton->m_device->run();
137  }
138 
139  static std::vector<core::vector3d<u32>> getSupportedVideoModes();
140  static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
141 
142 private:
143  void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv,
144  ITextureSource *tsrc, float dtime = 0, int percent = 0,
145  bool clouds = true);
146 
147  void _draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime = 0,
148  bool clouds = true);
149 
150  void _draw_scene(video::SColor skycolor, bool show_hud, bool show_minimap,
151  bool draw_wield_tool, bool draw_crosshair);
152 
153  void _initialize(Client *client, Hud *hud);
154 
155  void _finalize();
156 
157  std::unique_ptr<RenderingCore> core;
158  irr::IrrlichtDevice *m_device = nullptr;
159  irr::video::IVideoDriver *driver;
161 };
Definition: camera.h:79
Definition: client.h:109
Definition: hud.h:36
Definition: tile.h:86
Definition: localplayer.h:45
Definition: minimap.h:114
Definition: core.h:30
Definition: renderingengine.h:39
static scene::ISceneManager * get_scene_manager()
Definition: renderingengine.h:80
void _draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime=0, bool clouds=true)
Definition: renderingengine.cpp:546
static const char * getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)
Definition: renderingengine.cpp:628
void setupTopLevelXorgWindow(const std::string &name)
Definition: renderingengine.cpp:244
static std::vector< irr::video::E_DRIVER_TYPE > getSupportedVideoDrivers()
Definition: renderingengine.cpp:582
irr::IrrlichtDevice * m_device
Definition: renderingengine.h:158
video::IVideoDriver * getVideoDriver()
Definition: renderingengine.h:47
static void initialize(Client *client, Hud *hud)
Definition: renderingengine.h:126
static RenderingEngine * s_singleton
Definition: renderingengine.h:160
bool setWindowIcon()
Definition: renderingengine.cpp:345
~RenderingEngine()
Definition: renderingengine.cpp:153
static scene::IMeshCache * get_mesh_cache()
Definition: renderingengine.h:74
void _draw_scene(video::SColor skycolor, bool show_hud, bool show_minimap, bool draw_wield_tool, bool draw_crosshair)
Definition: renderingengine.cpp:606
static float getDisplayDensity()
Definition: renderingengine.cpp:674
void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime=0, int percent=0, bool clouds=true)
Definition: renderingengine.cpp:474
void _initialize(Client *client, Hud *hud)
Definition: renderingengine.cpp:594
static RenderingEngine * get_instance()
Definition: renderingengine.h:60
static void draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime=0, int percent=0, bool clouds=true)
Definition: renderingengine.h:105
RenderingEngine(IEventReceiver *eventReceiver)
Definition: renderingengine.cpp:84
irr::video::IVideoDriver * driver
Definition: renderingengine.h:159
bool setupTopLevelWindow(const std::string &name)
Definition: renderingengine.cpp:226
bool setXorgWindowIconFromPath(const std::string &icon_file)
Definition: renderingengine.cpp:383
v2u32 getWindowSize() const
Definition: renderingengine.cpp:160
std::unique_ptr< RenderingCore > core
Definition: renderingengine.h:157
static std::vector< core::vector3d< u32 > > getSupportedVideoModes()
Definition: renderingengine.cpp:563
static void draw_scene(video::SColor skycolor, bool show_hud, bool show_minimap, bool draw_wield_tool, bool draw_crosshair)
Definition: renderingengine.h:119
static u32 get_timer_time()
Definition: renderingengine.h:92
static video::IVideoDriver * get_video_driver()
Definition: renderingengine.h:68
static const char * getVideoDriverName(irr::video::E_DRIVER_TYPE type)
Definition: renderingengine.cpp:612
void setResizable(bool resize)
Definition: renderingengine.cpp:167
static io::IFileSystem * get_filesystem()
Definition: renderingengine.h:62
static v2u32 getDisplaySize()
Definition: renderingengine.cpp:717
static irr::IrrlichtDevice * get_raw_device()
Definition: renderingengine.h:86
static bool print_video_modes()
Definition: renderingengine.cpp:172
static bool run()
Definition: renderingengine.h:133
static gui::IGUIEnvironment * get_gui_env()
Definition: renderingengine.h:99
static void draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime, bool clouds)
Definition: renderingengine.h:113
void _finalize()
Definition: renderingengine.cpp:601
static void finalize()
Definition: renderingengine.h:131
gui::IGUIEnvironment * guienv
Definition: clientlauncher.cpp:47
#define sanity_check(expr)
Definition: debug.h:81
core::vector2d< u32 > v2u32
Definition: irr_v2d.h:29
Definition: activeobjectmgr.cpp:25