Isolate irrlicht references and use a singleton (#6041)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Mon, 26 Jun 2017 18:11:17 +0000 (20:11 +0200)
committerGitHub <noreply@github.com>
Mon, 26 Jun 2017 18:11:17 +0000 (20:11 +0200)
* Add Device3D class which will contain IrrlichtDevice interface

move getSupportedVideoDrivers to Device3D

Add Device3D singleton & use it in various places

Rename Device3D to Rendering engine & add helper functions to various device pointers

More singleton work

RenderingEngine owns draw_load_screen

move draw functions to RenderingEngine

Reduce IrrlichtDevice exposure and guienvironment

RenderingEngine: Expose get_timer_time() to remove device from guiEngine

Make irrlichtdevice & scene manager less exposed

* Code style fixes

* Move porting::getVideoDriverName, getVideoDriverFriendlyName, getDisplayDensity, getDisplaySize to RenderingEngine

Fix XORG_USED macro -> RenderingEngine + create_engine_device from RenderingEngine constructor directly

* enum paralax => enum parallax

50 files changed:
build/android/jni/Android.mk
src/CMakeLists.txt
src/camera.cpp
src/client.cpp
src/client.h
src/client/CMakeLists.txt
src/client/clientlauncher.cpp
src/client/clientlauncher.h
src/client/inputhandler.h
src/client/renderingengine.cpp [new file with mode: 0644]
src/client/renderingengine.h [new file with mode: 0644]
src/client/tile.cpp
src/client/tile.h
src/clientenvironment.cpp
src/clientenvironment.h
src/clientmap.cpp
src/clientmap.h
src/clouds.cpp
src/clouds.h
src/content_mapblock.cpp
src/content_mapblock.h
src/drawscene.cpp [deleted file]
src/drawscene.h [deleted file]
src/fontengine.cpp
src/game.cpp
src/game.h
src/guiEngine.cpp
src/guiEngine.h
src/guiFormSpecMenu.cpp
src/guiFormSpecMenu.h
src/guiTable.cpp
src/guiscalingfilter.cpp
src/guiscalingfilter.h
src/hud.cpp
src/mainmenumanager.h
src/mapblock_mesh.cpp
src/mapblock_mesh.h
src/minimap.cpp
src/minimap.h
src/nodedef.cpp
src/particles.cpp
src/particles.h
src/porting.cpp
src/porting.h
src/script/lua_api/l_mainmenu.cpp
src/shader.cpp
src/shader.h
src/sky.cpp
src/sky.h
util/travis/clang-format-whitelist.txt

index 22ef20906009a380666bc04f5a791984e2c2dbe4..6155b0d9cef79b59409bcf5f1c195ab243e041cb 100644 (file)
@@ -138,7 +138,6 @@ LOCAL_SRC_FILES := \
                jni/src/database.cpp                      \
                jni/src/debug.cpp                         \
                jni/src/defaultsettings.cpp               \
                jni/src/database.cpp                      \
                jni/src/debug.cpp                         \
                jni/src/defaultsettings.cpp               \
-               jni/src/drawscene.cpp                     \
                jni/src/dungeongen.cpp                    \
                jni/src/emerge.cpp                        \
                jni/src/environment.cpp                   \
                jni/src/dungeongen.cpp                    \
                jni/src/emerge.cpp                        \
                jni/src/environment.cpp                   \
@@ -270,6 +269,7 @@ LOCAL_SRC_FILES := \
                jni/src/wieldmesh.cpp                     \
                jni/src/client/clientlauncher.cpp         \
                jni/src/client/inputhandler.cpp           \
                jni/src/wieldmesh.cpp                     \
                jni/src/client/clientlauncher.cpp         \
                jni/src/client/inputhandler.cpp           \
+               jni/src/client/renderingengine.cpp        \
                jni/src/client/tile.cpp                   \
                jni/src/client/joystick_controller.cpp    \
                jni/src/irrlicht_changes/static_text.cpp
                jni/src/client/tile.cpp                   \
                jni/src/client/joystick_controller.cpp    \
                jni/src/irrlicht_changes/static_text.cpp
index 9e53b0e2cd226e6eb51eeb0894849a9d9680aa2a..04f4635d19a272c69ac8cafef07b0e7b82878d72 100644 (file)
@@ -500,7 +500,6 @@ set(client_SRCS
        content_cso.cpp
        content_mapblock.cpp
        convert_json.cpp
        content_cso.cpp
        content_mapblock.cpp
        convert_json.cpp
-       drawscene.cpp
        filecache.cpp
        fontengine.cpp
        game.cpp
        filecache.cpp
        fontengine.cpp
        game.cpp
index dd4e3963b07c116225866025b595f615e9db6799..83239fe7cbfbf6e8cbfa9f47fc32f31f2bcc59a8 100644 (file)
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "clientmap.h"     // MapDrawControl
 #include "player.h"
 #include <cmath>
 #include "clientmap.h"     // MapDrawControl
 #include "player.h"
 #include <cmath>
+#include "client/renderingengine.h"
 #include "settings.h"
 #include "wieldmesh.h"
 #include "noise.h"         // easeCurve
 #include "settings.h"
 #include "wieldmesh.h"
 #include "noise.h"         // easeCurve
@@ -99,7 +100,7 @@ bool Camera::successfullyCreated(std::string &error_message)
        } else {
                error_message.clear();
        }
        } else {
                error_message.clear();
        }
-       
+
        if (g_settings->getBool("enable_client_modding")) {
                m_client->getScript()->on_camera_ready(this);
        }
        if (g_settings->getBool("enable_client_modding")) {
                m_client->getScript()->on_camera_ready(this);
        }
@@ -449,7 +450,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
        fov_degrees = rangelim(fov_degrees, 7.0, 160.0);
 
        // FOV and aspect ratio
        fov_degrees = rangelim(fov_degrees, 7.0, 160.0);
 
        // FOV and aspect ratio
-       m_aspect = (f32) porting::getWindowSize().X / (f32) porting::getWindowSize().Y;
+       const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
+       m_aspect = (f32) window_size.X / (f32) window_size.Y;
        m_fov_y = fov_degrees * M_PI / 180.0;
        // Increase vertical FOV on lower aspect ratios (<16:10)
        m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect)));
        m_fov_y = fov_degrees * M_PI / 180.0;
        // Increase vertical FOV on lower aspect ratios (<16:10)
        m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect)));
index ebe1d9c8ff5ce76c6db5bc11ec26699ccb56cdd9..5681c3ddbefb9c3e0156be2773fdaaef142e316e 100644 (file)
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <cmath>
 #include <IFileSystem.h>
 #include "threading/mutex_auto_lock.h"
 #include <cmath>
 #include <IFileSystem.h>
 #include "threading/mutex_auto_lock.h"
+#include "client/renderingengine.h"
 #include "util/auth.h"
 #include "util/directiontables.h"
 #include "util/pointedthing.h"
 #include "util/auth.h"
 #include "util/directiontables.h"
 #include "util/pointedthing.h"
@@ -41,7 +42,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "clientmap.h"
 #include "clientmedia.h"
 #include "version.h"
 #include "clientmap.h"
 #include "clientmedia.h"
 #include "version.h"
-#include "drawscene.h"
 #include "database-sqlite3.h"
 #include "serialization.h"
 #include "guiscalingfilter.h"
 #include "database-sqlite3.h"
 #include "serialization.h"
 #include "guiscalingfilter.h"
@@ -55,7 +55,6 @@ extern gui::IGUIEnvironment* guienv;
 */
 
 Client::Client(
 */
 
 Client::Client(
-               IrrlichtDevice *device,
                const char *playername,
                const std::string &password,
                const std::string &address_name,
                const char *playername,
                const std::string &password,
                const std::string &address_name,
@@ -77,16 +76,12 @@ Client::Client(
        m_event(event),
        m_mesh_update_thread(this),
        m_env(
        m_event(event),
        m_mesh_update_thread(this),
        m_env(
-               new ClientMap(this, control,
-                       device->getSceneManager()->getRootSceneNode(),
-                       device->getSceneManager(), 666),
-               device->getSceneManager(),
+               new ClientMap(this, control, 666),
                tsrc, this
        ),
        m_particle_manager(&m_env),
        m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this),
        m_address_name(address_name),
                tsrc, this
        ),
        m_particle_manager(&m_env),
        m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this),
        m_address_name(address_name),
-       m_device(device),
        m_server_ser_ver(SER_FMT_VER_INVALID),
        m_last_chat_message_sent(time(NULL)),
        m_password(password),
        m_server_ser_ver(SER_FMT_VER_INVALID),
        m_last_chat_message_sent(time(NULL)),
        m_password(password),
@@ -99,7 +94,7 @@ Client::Client(
        m_env.setLocalPlayer(new LocalPlayer(this, playername));
 
        if (g_settings->getBool("enable_minimap")) {
        m_env.setLocalPlayer(new LocalPlayer(this, playername));
 
        if (g_settings->getBool("enable_minimap")) {
-               m_minimap = new Minimap(device, this);
+               m_minimap = new Minimap(this);
        }
        m_cache_save_interval = g_settings->getU16("server_map_save_interval");
 
        }
        m_cache_save_interval = g_settings->getU16("server_map_save_interval");
 
@@ -217,12 +212,11 @@ Client::~Client()
        }
 
        // cleanup 3d model meshes on client shutdown
        }
 
        // cleanup 3d model meshes on client shutdown
-       while (m_device->getSceneManager()->getMeshCache()->getMeshCount() != 0) {
-               scene::IAnimatedMesh *mesh =
-                       m_device->getSceneManager()->getMeshCache()->getMeshByIndex(0);
+       while (RenderingEngine::get_mesh_cache()->getMeshCount() != 0) {
+               scene::IAnimatedMesh *mesh = RenderingEngine::get_mesh_cache()->getMeshByIndex(0);
 
                if (mesh)
 
                if (mesh)
-                       m_device->getSceneManager()->getMeshCache()->removeMesh(mesh);
+                       RenderingEngine::get_mesh_cache()->removeMesh(mesh);
        }
 
        delete m_minimap;
        }
 
        delete m_minimap;
@@ -614,8 +608,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
                verbosestream<<"Client: Attempting to load image "
                <<"file \""<<filename<<"\""<<std::endl;
 
                verbosestream<<"Client: Attempting to load image "
                <<"file \""<<filename<<"\""<<std::endl;
 
-               io::IFileSystem *irrfs = m_device->getFileSystem();
-               video::IVideoDriver *vdrv = m_device->getVideoDriver();
+               io::IFileSystem *irrfs = RenderingEngine::get_filesystem();
+               video::IVideoDriver *vdrv = RenderingEngine::get_video_driver();
 
                // Create an irrlicht memory file
                io::IReadFile *rfile = irrfs->createMemoryReadFile(
 
                // Create an irrlicht memory file
                io::IReadFile *rfile = irrfs->createMemoryReadFile(
@@ -1628,7 +1622,6 @@ float Client::mediaReceiveProgress()
 }
 
 typedef struct TextureUpdateArgs {
 }
 
 typedef struct TextureUpdateArgs {
-       IrrlichtDevice *device;
        gui::IGUIEnvironment *guienv;
        u64 last_time_ms;
        u16 last_percent;
        gui::IGUIEnvironment *guienv;
        u64 last_time_ms;
        u16 last_percent;
@@ -1655,12 +1648,12 @@ void texture_update_progress(void *args, u32 progress, u32 max_progress)
                        targs->last_time_ms = time_ms;
                        std::basic_stringstream<wchar_t> strm;
                        strm << targs->text_base << " " << targs->last_percent << "%...";
                        targs->last_time_ms = time_ms;
                        std::basic_stringstream<wchar_t> strm;
                        strm << targs->text_base << " " << targs->last_percent << "%...";
-                       draw_load_screen(strm.str(), targs->device, targs->guienv, targs->tsrc, 0,
+                       RenderingEngine::draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0,
                                72 + (u16) ((18. / 100.) * (double) targs->last_percent), true);
                }
 }
 
                                72 + (u16) ((18. / 100.) * (double) targs->last_percent), true);
                }
 }
 
-void Client::afterContentReceived(IrrlichtDevice *device)
+void Client::afterContentReceived()
 {
        infostream<<"Client::afterContentReceived() started"<<std::endl;
        assert(m_itemdef_received); // pre-condition
 {
        infostream<<"Client::afterContentReceived() started"<<std::endl;
        assert(m_itemdef_received); // pre-condition
@@ -1672,25 +1665,25 @@ void Client::afterContentReceived(IrrlichtDevice *device)
        // Clear cached pre-scaled 2D GUI images, as this cache
        // might have images with the same name but different
        // content from previous sessions.
        // Clear cached pre-scaled 2D GUI images, as this cache
        // might have images with the same name but different
        // content from previous sessions.
-       guiScalingCacheClear(device->getVideoDriver());
+       guiScalingCacheClear();
 
        // Rebuild inherited images and recreate textures
        infostream<<"- Rebuilding images and textures"<<std::endl;
 
        // Rebuild inherited images and recreate textures
        infostream<<"- Rebuilding images and textures"<<std::endl;
-       draw_load_screen(text,device, guienv, m_tsrc, 0, 70);
+       RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 70);
        m_tsrc->rebuildImagesAndTextures();
        delete[] text;
 
        // Rebuild shaders
        infostream<<"- Rebuilding shaders"<<std::endl;
        text = wgettext("Rebuilding shaders...");
        m_tsrc->rebuildImagesAndTextures();
        delete[] text;
 
        // Rebuild shaders
        infostream<<"- Rebuilding shaders"<<std::endl;
        text = wgettext("Rebuilding shaders...");
-       draw_load_screen(text, device, guienv, m_tsrc, 0, 71);
+       RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 71);
        m_shsrc->rebuildShaders();
        delete[] text;
 
        // Update node aliases
        infostream<<"- Updating node aliases"<<std::endl;
        text = wgettext("Initializing nodes...");
        m_shsrc->rebuildShaders();
        delete[] text;
 
        // Update node aliases
        infostream<<"- Updating node aliases"<<std::endl;
        text = wgettext("Initializing nodes...");
-       draw_load_screen(text, device, guienv, m_tsrc, 0, 72);
+       RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 72);
        m_nodedef->updateAliases(m_itemdef);
        std::string texture_path = g_settings->get("texture_path");
        if (texture_path != "" && fs::IsDir(texture_path))
        m_nodedef->updateAliases(m_itemdef);
        std::string texture_path = g_settings->get("texture_path");
        if (texture_path != "" && fs::IsDir(texture_path))
@@ -1702,7 +1695,6 @@ void Client::afterContentReceived(IrrlichtDevice *device)
        // Update node textures and assign shaders to each tile
        infostream<<"- Updating node textures"<<std::endl;
        TextureUpdateArgs tu_args;
        // Update node textures and assign shaders to each tile
        infostream<<"- Updating node textures"<<std::endl;
        TextureUpdateArgs tu_args;
-       tu_args.device = device;
        tu_args.guienv = guienv;
        tu_args.last_time_ms = porting::getTimeMs();
        tu_args.last_percent = 0;
        tu_args.guienv = guienv;
        tu_args.last_time_ms = porting::getTimeMs();
        tu_args.last_percent = 0;
@@ -1724,7 +1716,7 @@ void Client::afterContentReceived(IrrlichtDevice *device)
        }
 
        text = wgettext("Done!");
        }
 
        text = wgettext("Done!");
-       draw_load_screen(text, device, guienv, m_tsrc, 0, 100);
+       RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 100);
        infostream<<"Client::afterContentReceived() done"<<std::endl;
        delete[] text;
 }
        infostream<<"Client::afterContentReceived() done"<<std::endl;
        delete[] text;
 }
@@ -1742,7 +1734,7 @@ float Client::getCurRate()
 
 void Client::makeScreenshot()
 {
 
 void Client::makeScreenshot()
 {
-       irr::video::IVideoDriver *driver = m_device->getVideoDriver();
+       irr::video::IVideoDriver *driver = RenderingEngine::get_video_driver();
        irr::video::IImage* const raw_image = driver->createScreenShot();
 
        if (!raw_image)
        irr::video::IImage* const raw_image = driver->createScreenShot();
 
        if (!raw_image)
@@ -1857,10 +1849,7 @@ IShaderSource* Client::getShaderSource()
 {
        return m_shsrc;
 }
 {
        return m_shsrc;
 }
-scene::ISceneManager* Client::getSceneManager()
-{
-       return m_device->getSceneManager();
-}
+
 u16 Client::allocateUnknownNodeId(const std::string &name)
 {
        errorstream << "Client::allocateUnknownNodeId(): "
 u16 Client::allocateUnknownNodeId(const std::string &name)
 {
        errorstream << "Client::allocateUnknownNodeId(): "
@@ -1892,22 +1881,20 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
                return NULL;
        }
        const std::string &data    = it->second;
                return NULL;
        }
        const std::string &data    = it->second;
-       scene::ISceneManager *smgr = m_device->getSceneManager();
 
        // Create the mesh, remove it from cache and return it
        // This allows unique vertex colors and other properties for each instance
        Buffer<char> data_rw(data.c_str(), data.size()); // Const-incorrect Irrlicht
 
        // Create the mesh, remove it from cache and return it
        // This allows unique vertex colors and other properties for each instance
        Buffer<char> data_rw(data.c_str(), data.size()); // Const-incorrect Irrlicht
-       io::IFileSystem *irrfs = m_device->getFileSystem();
-       io::IReadFile *rfile   = irrfs->createMemoryReadFile(
+       io::IReadFile *rfile   = RenderingEngine::get_filesystem()->createMemoryReadFile(
                        *data_rw, data_rw.getSize(), filename.c_str());
        FATAL_ERROR_IF(!rfile, "Could not create/open RAM file");
 
                        *data_rw, data_rw.getSize(), filename.c_str());
        FATAL_ERROR_IF(!rfile, "Could not create/open RAM file");
 
-       scene::IAnimatedMesh *mesh = smgr->getMesh(rfile);
+       scene::IAnimatedMesh *mesh = RenderingEngine::get_scene_manager()->getMesh(rfile);
        rfile->drop();
        // NOTE: By playing with Irrlicht refcounts, maybe we could cache a bunch
        // of uniquely named instances and re-use them
        mesh->grab();
        rfile->drop();
        // NOTE: By playing with Irrlicht refcounts, maybe we could cache a bunch
        // of uniquely named instances and re-use them
        mesh->grab();
-       smgr->getMeshCache()->removeMesh(mesh);
+       RenderingEngine::get_mesh_cache()->removeMesh(mesh);
        return mesh;
 }
 
        return mesh;
 }
 
index ab47cfa44b3cf9a048f0fe051b17276485b9c6e1..ab9801d6218deb1a406537537500079cf6ed54c1 100644 (file)
@@ -256,7 +256,6 @@ public:
        */
 
        Client(
        */
 
        Client(
-                       IrrlichtDevice *device,
                        const char *playername,
                        const std::string &password,
                        const std::string &address_name,
                        const char *playername,
                        const std::string &password,
                        const std::string &address_name,
@@ -467,7 +466,7 @@ public:
 
        float mediaReceiveProgress();
 
 
        float mediaReceiveProgress();
 
-       void afterContentReceived(IrrlichtDevice *device);
+       void afterContentReceived();
 
        float getRTT();
        float getCurRate();
 
        float getRTT();
        float getCurRate();
@@ -486,7 +485,6 @@ public:
        ITextureSource* getTextureSource();
        virtual IShaderSource* getShaderSource();
        IShaderSource *shsrc() { return getShaderSource(); }
        ITextureSource* getTextureSource();
        virtual IShaderSource* getShaderSource();
        IShaderSource *shsrc() { return getShaderSource(); }
-       scene::ISceneManager* getSceneManager();
        virtual u16 allocateUnknownNodeId(const std::string &name);
        virtual ISoundManager* getSoundManager();
        virtual MtEventManager* getEventManager();
        virtual u16 allocateUnknownNodeId(const std::string &name);
        virtual ISoundManager* getSoundManager();
        virtual MtEventManager* getEventManager();
@@ -593,7 +591,6 @@ private:
        ParticleManager m_particle_manager;
        con::Connection m_con;
        std::string m_address_name;
        ParticleManager m_particle_manager;
        con::Connection m_con;
        std::string m_address_name;
-       IrrlichtDevice *m_device;
        Camera *m_camera = nullptr;
        Minimap *m_minimap = nullptr;
        bool m_minimap_disabled_by_server = false;
        Camera *m_camera = nullptr;
        Minimap *m_minimap = nullptr;
        bool m_minimap_disabled_by_server = false;
index 2d274ae681409451737b0bae8d0aceab2200eb1b..4ba8fea5bc879dfefaebb95164d943b5d5d2e7d5 100644 (file)
@@ -1,4 +1,5 @@
 set(client_SRCS
 set(client_SRCS
+       ${CMAKE_CURRENT_SOURCE_DIR}/renderingengine.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
index 9856c19207a4b172863a6c98c0dc2d930414089f..4fc8fb3ee908c51d028b1e111b6716a24ee2e972 100644 (file)
@@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "mainmenumanager.h"
 */
 
 #include "mainmenumanager.h"
-#include "debug.h"
 #include "clouds.h"
 #include "server.h"
 #include "filesys.h"
 #include "clouds.h"
 #include "server.h"
 #include "filesys.h"
@@ -27,14 +26,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "chat.h"
 #include "gettext.h"
 #include "profiler.h"
 #include "chat.h"
 #include "gettext.h"
 #include "profiler.h"
-#include "log.h"
 #include "serverlist.h"
 #include "guiEngine.h"
 #include "serverlist.h"
 #include "guiEngine.h"
-#include "player.h"
 #include "fontengine.h"
 #include "fontengine.h"
-#include "joystick_controller.h"
 #include "clientlauncher.h"
 #include "version.h"
 #include "clientlauncher.h"
 #include "version.h"
+#include "renderingengine.h"
 
 /* mainmenumanager.h
  */
 
 /* mainmenumanager.h
  */
@@ -58,9 +55,9 @@ ClientLauncher::~ClientLauncher()
        delete input;
 
        delete g_fontengine;
        delete input;
 
        delete g_fontengine;
+       delete g_gamecallback;
 
 
-       if (device)
-               device->drop();
+       delete RenderingEngine::get_instance();
 }
 
 
 }
 
 
@@ -70,7 +67,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
 
        // List video modes if requested
        if (list_video_modes)
 
        // List video modes if requested
        if (list_video_modes)
-               return print_video_modes();
+               return RenderingEngine::print_video_modes();
 
        if (!init_engine()) {
                errorstream << "Could not initialize game engine." << std::endl;
 
        if (!init_engine()) {
                errorstream << "Could not initialize game engine." << std::endl;
@@ -84,15 +81,14 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
                return true;
        }
 
                return true;
        }
 
-       video::IVideoDriver *video_driver = device->getVideoDriver();
+       video::IVideoDriver *video_driver = RenderingEngine::get_video_driver();
        if (video_driver == NULL) {
                errorstream << "Could not initialize video driver." << std::endl;
                return false;
        }
 
        if (video_driver == NULL) {
                errorstream << "Could not initialize video driver." << std::endl;
                return false;
        }
 
-       porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
-
-       porting::setWindowIcon(device);
+       RenderingEngine::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
+       RenderingEngine::get_instance()->setWindowIcon();
 
        /*
                This changes the minimum allowed number of vertices in a VBO.
 
        /*
                This changes the minimum allowed number of vertices in a VBO.
@@ -101,17 +97,17 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
        //driver->setMinHardwareBufferVertexCount(50);
 
        // Create game callback for menus
        //driver->setMinHardwareBufferVertexCount(50);
 
        // Create game callback for menus
-       g_gamecallback = new MainGameCallback(device);
+       g_gamecallback = new MainGameCallback();
 
 
-       device->setResizable(true);
+       RenderingEngine::get_instance()->setResizable(true);
 
        init_input();
 
 
        init_input();
 
-       smgr = device->getSceneManager();
-       smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
+       RenderingEngine::get_scene_manager()->getParameters()->
+               setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
 
 
-       guienv = device->getGUIEnvironment();
-       skin = guienv->getSkin();
+       guienv = RenderingEngine::get_gui_env();
+       skin = RenderingEngine::get_gui_env()->getSkin();
        skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
        skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0));
        skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30));
        skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
        skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0));
        skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30));
@@ -130,10 +126,9 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
 
        // Create the menu clouds
        if (!g_menucloudsmgr)
 
        // Create the menu clouds
        if (!g_menucloudsmgr)
-               g_menucloudsmgr = smgr->createNewSceneManager();
+               g_menucloudsmgr = RenderingEngine::get_scene_manager()->createNewSceneManager();
        if (!g_menuclouds)
        if (!g_menuclouds)
-               g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
-                               g_menucloudsmgr, -1, rand(), 100);
+               g_menuclouds = new Clouds(g_menucloudsmgr, -1, rand(), 100);
        g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
        scene::ICameraSceneNode* camera;
        camera = g_menucloudsmgr->addCameraSceneNode(0,
        g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
        scene::ICameraSceneNode* camera;
        camera = g_menucloudsmgr->addCameraSceneNode(0,
@@ -159,25 +154,27 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
        bool retval = true;
        bool *kill = porting::signal_handler_killstatus();
 
        bool retval = true;
        bool *kill = porting::signal_handler_killstatus();
 
-       while (device->run() && !*kill && !g_gamecallback->shutdown_requested)
-       {
+       while (RenderingEngine::run() && !*kill &&
+               !g_gamecallback->shutdown_requested) {
                // Set the window caption
                const wchar_t *text = wgettext("Main Menu");
                // Set the window caption
                const wchar_t *text = wgettext("Main Menu");
-               device->setWindowCaption((utf8_to_wide(PROJECT_NAME_C) +
+               RenderingEngine::get_raw_device()->
+                       setWindowCaption((utf8_to_wide(PROJECT_NAME_C) +
                        L" " + utf8_to_wide(g_version_hash) +
                        L" [" + text + L"]").c_str());
                delete[] text;
 
                try {   // This is used for catching disconnects
 
                        L" " + utf8_to_wide(g_version_hash) +
                        L" [" + text + L"]").c_str());
                delete[] text;
 
                try {   // This is used for catching disconnects
 
-                       guienv->clear();
+                       RenderingEngine::get_gui_env()->clear();
 
                        /*
                                We need some kind of a root node to be able to add
                                custom gui elements directly on the screen.
                                Otherwise they won't be automatically drawn.
                        */
 
                        /*
                                We need some kind of a root node to be able to add
                                custom gui elements directly on the screen.
                                Otherwise they won't be automatically drawn.
                        */
-                       guiroot = guienv->addStaticText(L"", core::rect<s32>(0, 0, 10000, 10000));
+                       guiroot = RenderingEngine::get_gui_env()->addStaticText(L"",
+                               core::rect<s32>(0, 0, 10000, 10000));
 
                        bool game_has_run = launch_game(error_message, reconnect_requested,
                                game_params, cmd_args);
 
                        bool game_has_run = launch_game(error_message, reconnect_requested,
                                game_params, cmd_args);
@@ -199,7 +196,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
                        }
 
                        // Break out of menu-game loop to shut down cleanly
                        }
 
                        // Break out of menu-game loop to shut down cleanly
-                       if (!device->run() || *kill) {
+                       if (!RenderingEngine::get_raw_device()->run() || *kill) {
                                if (g_settings_path != "")
                                        g_settings->updateConfigFile(g_settings_path.c_str());
                                break;
                                if (g_settings_path != "")
                                        g_settings->updateConfigFile(g_settings_path.c_str());
                                break;
@@ -212,7 +209,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
                                continue;
                        }
 
                                continue;
                        }
 
-                       device->getVideoDriver()->setTextureCreationFlag(
+                       RenderingEngine::get_video_driver()->setTextureCreationFlag(
                                        video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
 
 #ifdef HAVE_TOUCHSCREENGUI
                                        video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
 
 #ifdef HAVE_TOUCHSCREENGUI
@@ -224,7 +221,6 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
                                kill,
                                random_input,
                                input,
                                kill,
                                random_input,
                                input,
-                               device,
                                worldspec.path,
                                current_playername,
                                current_password,
                                worldspec.path,
                                current_playername,
                                current_password,
@@ -236,7 +232,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
                                gamespec,
                                simple_singleplayer_mode
                        );
                                gamespec,
                                simple_singleplayer_mode
                        );
-                       smgr->clear();
+                       RenderingEngine::get_scene_manager()->clear();
 
 #ifdef HAVE_TOUCHSCREENGUI
                        delete g_touchscreengui;
 
 #ifdef HAVE_TOUCHSCREENGUI
                        delete g_touchscreengui;
@@ -308,8 +304,8 @@ void ClientLauncher::init_args(GameParams &game_params, const Settings &cmd_args
 bool ClientLauncher::init_engine()
 {
        receiver = new MyEventReceiver();
 bool ClientLauncher::init_engine()
 {
        receiver = new MyEventReceiver();
-       create_engine_device();
-       return device != NULL;
+       new RenderingEngine(receiver);
+       return RenderingEngine::get_raw_device() != nullptr;
 }
 
 void ClientLauncher::init_input()
 }
 
 void ClientLauncher::init_input()
@@ -317,7 +313,7 @@ void ClientLauncher::init_input()
        if (random_input)
                input = new RandomInputHandler();
        else
        if (random_input)
                input = new RandomInputHandler();
        else
-               input = new RealInputHandler(device, receiver);
+               input = new RealInputHandler(receiver);
 
        if (g_settings->getBool("enable_joysticks")) {
                irr::core::array<irr::SJoystickInfo> infos;
 
        if (g_settings->getBool("enable_joysticks")) {
                irr::core::array<irr::SJoystickInfo> infos;
@@ -326,7 +322,7 @@ void ClientLauncher::init_input()
                // Make sure this is called maximum once per
                // irrlicht device, otherwise it will give you
                // multiple events for the same joystick.
                // Make sure this is called maximum once per
                // irrlicht device, otherwise it will give you
                // multiple events for the same joystick.
-               if (device->activateJoysticks(infos)) {
+               if (RenderingEngine::get_raw_device()->activateJoysticks(infos)) {
                        infostream << "Joystick support enabled" << std::endl;
                        joystick_infos.reserve(infos.size());
                        for (u32 i = 0; i < infos.size(); i++) {
                        infostream << "Joystick support enabled" << std::endl;
                        joystick_infos.reserve(infos.size());
                        for (u32 i = 0; i < infos.size(); i++) {
@@ -487,14 +483,14 @@ bool ClientLauncher::launch_game(std::string &error_message,
 void ClientLauncher::main_menu(MainMenuData *menudata)
 {
        bool *kill = porting::signal_handler_killstatus();
 void ClientLauncher::main_menu(MainMenuData *menudata)
 {
        bool *kill = porting::signal_handler_killstatus();
-       video::IVideoDriver *driver = device->getVideoDriver();
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
 
        infostream << "Waiting for other menus" << std::endl;
 
        infostream << "Waiting for other menus" << std::endl;
-       while (device->run() && *kill == false) {
+       while (RenderingEngine::get_raw_device()->run() && *kill == false) {
                if (!isMenuActive())
                        break;
                driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
                if (!isMenuActive())
                        break;
                driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
-               guienv->drawAll();
+               RenderingEngine::get_gui_env()->drawAll();
                driver->endScene();
                // On some computers framerate doesn't seem to be automatically limited
                sleep_ms(25);
                driver->endScene();
                // On some computers framerate doesn't seem to be automatically limited
                sleep_ms(25);
@@ -503,73 +499,14 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
 
        // Cursor can be non-visible when coming from the game
 #ifndef ANDROID
 
        // Cursor can be non-visible when coming from the game
 #ifndef ANDROID
-       device->getCursorControl()->setVisible(true);
+       RenderingEngine::get_raw_device()->getCursorControl()->setVisible(true);
 #endif
 
        /* show main menu */
 #endif
 
        /* show main menu */
-       GUIEngine mymenu(device, &input->joystick, guiroot,
-               &g_menumgr, smgr, menudata, *kill);
+       GUIEngine mymenu(&input->joystick, guiroot, &g_menumgr, menudata, *kill);
 
 
-       smgr->clear();  /* leave scene manager in a clean state */
-}
-
-bool ClientLauncher::create_engine_device()
-{
-       // Resolution selection
-       bool fullscreen = g_settings->getBool("fullscreen");
-       u16 screen_w = g_settings->getU16("screen_w");
-       u16 screen_h = g_settings->getU16("screen_h");
-
-       // bpp, fsaa, vsync
-       bool vsync = g_settings->getBool("vsync");
-       u16 bits = g_settings->getU16("fullscreen_bpp");
-       u16 fsaa = g_settings->getU16("fsaa");
-
-       // stereo buffer required for pageflip stereo
-       bool stereo_buffer = g_settings->get("3d_mode") == "pageflip";
-
-       // Determine driver
-       video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
-       const std::string &driverstring = g_settings->get("video_driver");
-       std::vector<video::E_DRIVER_TYPE> drivers
-               = porting::getSupportedVideoDrivers();
-       u32 i;
-       for (i = 0; i != drivers.size(); i++) {
-               if (!strcasecmp(driverstring.c_str(),
-                       porting::getVideoDriverName(drivers[i]))) {
-                       driverType = drivers[i];
-                       break;
-               }
-       }
-       if (i == drivers.size()) {
-               errorstream << "Invalid video_driver specified; "
-                       "defaulting to opengl" << std::endl;
-       }
-
-       SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
-       params.DriverType    = driverType;
-       params.WindowSize    = core::dimension2d<u32>(screen_w, screen_h);
-       params.Bits          = bits;
-       params.AntiAlias     = fsaa;
-       params.Fullscreen    = fullscreen;
-       params.Stencilbuffer = false;
-       params.Stereobuffer  = stereo_buffer;
-       params.Vsync         = vsync;
-       params.EventReceiver = receiver;
-       params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
-       params.ZBufferBits   = 24;
-#ifdef __ANDROID__
-       params.PrivateData = porting::app_global;
-       params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM +
-                       "media" + DIR_DELIM + "Shaders" + DIR_DELIM).c_str();
-#endif
-
-       device = createDeviceEx(params);
-
-       if (device)
-               porting::initIrrlicht(device);
-
-       return device != NULL;
+       /* leave scene manager in a clean state */
+       RenderingEngine::get_scene_manager()->clear();
 }
 
 void ClientLauncher::speed_tests()
 }
 
 void ClientLauncher::speed_tests()
@@ -584,8 +521,8 @@ void ClientLauncher::speed_tests()
 
        tempv3f1 = v3f();
        tempv3f2 = v3f();
 
        tempv3f1 = v3f();
        tempv3f2 = v3f();
-       tempstring = std::string();
-       tempstring2 = std::string();
+       tempstring.clear();
+       tempstring2.clear();
 
        {
                infostream << "The following test should take around 20ms." << std::endl;
 
        {
                infostream << "The following test should take around 20ms." << std::endl;
@@ -670,58 +607,3 @@ void ClientLauncher::speed_tests()
                infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl;
        }
 }
                infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl;
        }
 }
-
-bool ClientLauncher::print_video_modes()
-{
-       IrrlichtDevice *nulldevice;
-
-       bool vsync = g_settings->getBool("vsync");
-       u16 fsaa = g_settings->getU16("fsaa");
-       MyEventReceiver* receiver = new MyEventReceiver();
-
-       SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
-       params.DriverType    = video::EDT_NULL;
-       params.WindowSize    = core::dimension2d<u32>(640, 480);
-       params.Bits          = 24;
-       params.AntiAlias     = fsaa;
-       params.Fullscreen    = false;
-       params.Stencilbuffer = false;
-       params.Vsync         = vsync;
-       params.EventReceiver = receiver;
-       params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
-
-       nulldevice = createDeviceEx(params);
-
-       if (nulldevice == NULL) {
-               delete receiver;
-               return false;
-       }
-
-       std::cout << _("Available video modes (WxHxD):") << std::endl;
-
-       video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
-
-       if (videomode_list != NULL) {
-               s32 videomode_count = videomode_list->getVideoModeCount();
-               core::dimension2d<u32> videomode_res;
-               s32 videomode_depth;
-               for (s32 i = 0; i < videomode_count; ++i) {
-                       videomode_res = videomode_list->getVideoModeResolution(i);
-                       videomode_depth = videomode_list->getVideoModeDepth(i);
-                       std::cout << videomode_res.Width << "x" << videomode_res.Height
-                               << "x" << videomode_depth << std::endl;
-               }
-
-               std::cout << _("Active video mode (WxHxD):") << std::endl;
-               videomode_res = videomode_list->getDesktopResolution();
-               videomode_depth = videomode_list->getDesktopDepth();
-               std::cout << videomode_res.Width << "x" << videomode_res.Height
-                       << "x" << videomode_depth << std::endl;
-
-       }
-
-       nulldevice->drop();
-       delete receiver;
-
-       return videomode_list != NULL;
-}
index 9e0560b14590ca766d784fefc37acbdcb67e7906..8f8a01e2f554fc7a28557c34829bfcd29bd5ecc1 100644 (file)
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client/inputhandler.h"
 #include "gameparams.h"
 
 #include "client/inputhandler.h"
 #include "gameparams.h"
 
+class RenderingEngine;
 
 class ClientLauncher
 {
 
 class ClientLauncher
 {
@@ -43,10 +44,8 @@ protected:
                GameParams &game_params, const Settings &cmd_args);
 
        void main_menu(MainMenuData *menudata);
                GameParams &game_params, const Settings &cmd_args);
 
        void main_menu(MainMenuData *menudata);
-       bool create_engine_device();
 
        void speed_tests();
 
        void speed_tests();
-       bool print_video_modes();
 
        bool list_video_modes = false;
        bool skip_main_menu = false;
 
        bool list_video_modes = false;
        bool skip_main_menu = false;
@@ -55,12 +54,10 @@ protected:
        std::string address = "";
        std::string playername = "";
        std::string password = "";
        std::string address = "";
        std::string playername = "";
        std::string password = "";
-       IrrlichtDevice *device = nullptr;
        InputHandler *input = nullptr;
        MyEventReceiver *receiver = nullptr;
        gui::IGUISkin *skin = nullptr;
        gui::IGUIFont *font = nullptr;
        InputHandler *input = nullptr;
        MyEventReceiver *receiver = nullptr;
        gui::IGUISkin *skin = nullptr;
        gui::IGUIFont *font = nullptr;
-       scene::ISceneManager *smgr = nullptr;
        SubgameSpec gamespec;
        WorldSpec worldspec;
        bool simple_singleplayer_mode;
        SubgameSpec gamespec;
        WorldSpec worldspec;
        bool simple_singleplayer_mode;
index 19733e3ec28d7bb666f9a59f6ff034c58e921b69..822e2786309f00b9c7296619214eb0fb0ceaff9b 100644 (file)
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "joystick_controller.h"
 #include <list>
 #include "keycode.h"
 #include "joystick_controller.h"
 #include <list>
 #include "keycode.h"
+#include "renderingengine.h"
 
 #ifdef HAVE_TOUCHSCREENGUI
 #include "touchscreengui.h"
 
 #ifdef HAVE_TOUCHSCREENGUI
 #include "touchscreengui.h"
@@ -219,8 +220,7 @@ public:
 class RealInputHandler : public InputHandler
 {
 public:
 class RealInputHandler : public InputHandler
 {
 public:
-       RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver)
-           : m_device(device), m_receiver(receiver)
+       RealInputHandler(MyEventReceiver *receiver) : m_receiver(receiver)
        {
                m_receiver->joystick = &joystick;
        }
        {
                m_receiver->joystick = &joystick;
        }
@@ -239,16 +239,20 @@ public:
        virtual void dontListenForKeys() { m_receiver->dontListenForKeys(); }
        virtual v2s32 getMousePos()
        {
        virtual void dontListenForKeys() { m_receiver->dontListenForKeys(); }
        virtual v2s32 getMousePos()
        {
-               if (m_device->getCursorControl()) {
-                       return m_device->getCursorControl()->getPosition();
+               if (RenderingEngine::get_raw_device()->getCursorControl()) {
+                       return RenderingEngine::get_raw_device()
+                                       ->getCursorControl()
+                                       ->getPosition();
                } else {
                        return m_mousepos;
                }
        }
        virtual void setMousePos(s32 x, s32 y)
        {
                } else {
                        return m_mousepos;
                }
        }
        virtual void setMousePos(s32 x, s32 y)
        {
-               if (m_device->getCursorControl()) {
-                       m_device->getCursorControl()->setPosition(x, y);
+               if (RenderingEngine::get_raw_device()->getCursorControl()) {
+                       RenderingEngine::get_raw_device()
+                                       ->getCursorControl()
+                                       ->setPosition(x, y);
                } else {
                        m_mousepos = v2s32(x, y);
                }
                } else {
                        m_mousepos = v2s32(x, y);
                }
@@ -276,7 +280,6 @@ public:
        }
 
 private:
        }
 
 private:
-       IrrlichtDevice *m_device = nullptr;
        MyEventReceiver *m_receiver = nullptr;
        v2s32 m_mousepos;
 };
        MyEventReceiver *m_receiver = nullptr;
        v2s32 m_mousepos;
 };
diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp
new file mode 100644 (file)
index 0000000..ce8f643
--- /dev/null
@@ -0,0 +1,1072 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <IrrlichtDevice.h>
+#include <irrlicht.h>
+#include "fontengine.h"
+#include "clouds.h"
+#include "util/numeric.h"
+#include "guiscalingfilter.h"
+#include "hud.h"
+#include "camera.h"
+#include "minimap.h"
+#include "clientmap.h"
+#include "renderingengine.h"
+#include "inputhandler.h"
+#include "gettext.h"
+
+#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) && !defined(SERVER)
+#define XORG_USED
+#endif
+#ifdef XORG_USED
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#endif
+
+RenderingEngine *RenderingEngine::s_singleton = nullptr;
+
+RenderingEngine::RenderingEngine(IEventReceiver *receiver)
+{
+       sanity_check(!s_singleton);
+
+       // Resolution selection
+       bool fullscreen = g_settings->getBool("fullscreen");
+       u16 screen_w = g_settings->getU16("screen_w");
+       u16 screen_h = g_settings->getU16("screen_h");
+
+       // bpp, fsaa, vsync
+       bool vsync = g_settings->getBool("vsync");
+       u16 bits = g_settings->getU16("fullscreen_bpp");
+       u16 fsaa = g_settings->getU16("fsaa");
+
+       // stereo buffer required for pageflip stereo
+       bool stereo_buffer = g_settings->get("3d_mode") == "pageflip";
+
+       // Determine driver
+       video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
+       const std::string &driverstring = g_settings->get("video_driver");
+       std::vector<video::E_DRIVER_TYPE> drivers =
+                       RenderingEngine::getSupportedVideoDrivers();
+       u32 i;
+       for (i = 0; i != drivers.size(); i++) {
+               if (!strcasecmp(driverstring.c_str(),
+                                   RenderingEngine::getVideoDriverName(drivers[i]))) {
+                       driverType = drivers[i];
+                       break;
+               }
+       }
+       if (i == drivers.size()) {
+               errorstream << "Invalid video_driver specified; "
+                              "defaulting to opengl"
+                           << std::endl;
+       }
+
+       SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
+       params.DriverType = driverType;
+       params.WindowSize = core::dimension2d<u32>(screen_w, screen_h);
+       params.Bits = bits;
+       params.AntiAlias = fsaa;
+       params.Fullscreen = fullscreen;
+       params.Stencilbuffer = false;
+       params.Stereobuffer = stereo_buffer;
+       params.Vsync = vsync;
+       params.EventReceiver = receiver;
+       params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
+       params.ZBufferBits = 24;
+#ifdef __ANDROID__
+       params.PrivateData = porting::app_global;
+       params.OGLES2ShaderPath = std::string(
+                       porting::path_user + DIR_DELIM + "media" + DIR_DELIM + "Shaders" +
+                       DIR_DELIM).c_str();
+#endif
+
+       m_device = createDeviceEx(params);
+       s_singleton = this;
+}
+
+RenderingEngine::~RenderingEngine()
+{
+       m_device->drop();
+       s_singleton = nullptr;
+}
+
+v2u32 RenderingEngine::getWindowSize() const
+{
+       return m_device->getVideoDriver()->getScreenSize();
+}
+
+void RenderingEngine::setResizable(bool resize)
+{
+       m_device->setResizable(resize);
+}
+
+video::IVideoDriver *RenderingEngine::getVideoDriver()
+{
+       return m_device->getVideoDriver();
+}
+
+bool RenderingEngine::print_video_modes()
+{
+       IrrlichtDevice *nulldevice;
+
+       bool vsync = g_settings->getBool("vsync");
+       u16 fsaa = g_settings->getU16("fsaa");
+       MyEventReceiver *receiver = new MyEventReceiver();
+
+       SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
+       params.DriverType = video::EDT_NULL;
+       params.WindowSize = core::dimension2d<u32>(640, 480);
+       params.Bits = 24;
+       params.AntiAlias = fsaa;
+       params.Fullscreen = false;
+       params.Stencilbuffer = false;
+       params.Vsync = vsync;
+       params.EventReceiver = receiver;
+       params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
+
+       nulldevice = createDeviceEx(params);
+
+       if (!nulldevice) {
+               delete receiver;
+               return false;
+       }
+
+       std::cout << _("Available video modes (WxHxD):") << std::endl;
+
+       video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
+
+       if (videomode_list != NULL) {
+               s32 videomode_count = videomode_list->getVideoModeCount();
+               core::dimension2d<u32> videomode_res;
+               s32 videomode_depth;
+               for (s32 i = 0; i < videomode_count; ++i) {
+                       videomode_res = videomode_list->getVideoModeResolution(i);
+                       videomode_depth = videomode_list->getVideoModeDepth(i);
+                       std::cout << videomode_res.Width << "x" << videomode_res.Height
+                                 << "x" << videomode_depth << std::endl;
+               }
+
+               std::cout << _("Active video mode (WxHxD):") << std::endl;
+               videomode_res = videomode_list->getDesktopResolution();
+               videomode_depth = videomode_list->getDesktopDepth();
+               std::cout << videomode_res.Width << "x" << videomode_res.Height << "x"
+                         << videomode_depth << std::endl;
+       }
+
+       nulldevice->drop();
+       delete receiver;
+
+       return videomode_list != NULL;
+}
+
+void RenderingEngine::setXorgClassHint(
+               const video::SExposedVideoData &video_data, const std::string &name)
+{
+#ifdef XORG_USED
+       if (video_data.OpenGLLinux.X11Display == NULL)
+               return;
+
+       XClassHint *classhint = XAllocClassHint();
+       classhint->res_name = (char *)name.c_str();
+       classhint->res_class = (char *)name.c_str();
+
+       XSetClassHint((Display *)video_data.OpenGLLinux.X11Display,
+                       video_data.OpenGLLinux.X11Window, classhint);
+       XFree(classhint);
+#endif
+}
+
+bool RenderingEngine::setWindowIcon()
+{
+#if defined(XORG_USED)
+#if RUN_IN_PLACE
+       return setXorgWindowIconFromPath(
+                       porting::path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png");
+#else
+       // We have semi-support for reading in-place data if we are
+       // compiled with RUN_IN_PLACE. Don't break with this and
+       // also try the path_share location.
+       return setXorgWindowIconFromPath(
+                              ICON_DIR "/hicolor/128x128/apps/" PROJECT_NAME ".png") ||
+              setXorgWindowIconFromPath(porting::path_share + "/misc/" PROJECT_NAME
+                                                              "-xorg-icon-128.png");
+#endif
+#elif defined(_WIN32)
+       const video::SExposedVideoData exposedData =
+                       m_device->getVideoDriver()->getExposedVideoData();
+       HWND hWnd; // Window handle
+
+       switch (m_device->getVideoDriver()->getDriverType()) {
+       case video::EDT_DIRECT3D8:
+               hWnd = reinterpret_cast<HWND>(exposedData.D3D8.HWnd);
+               break;
+       case video::EDT_DIRECT3D9:
+               hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd);
+               break;
+       case video::EDT_OPENGL:
+               hWnd = reinterpret_cast<HWND>(exposedData.OpenGLWin32.HWnd);
+               break;
+       default:
+               return false;
+       }
+
+       // Load the ICON from resource file
+       const HICON hicon = LoadIcon(GetModuleHandle(NULL),
+                       MAKEINTRESOURCE(130) // The ID of the ICON defined in
+                                            // winresource.rc
+                       );
+
+       if (hicon) {
+               SendMessage(hWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hicon));
+               SendMessage(hWnd, WM_SETICON, ICON_SMALL,
+                               reinterpret_cast<LPARAM>(hicon));
+               return true;
+       }
+       return false;
+#else
+       return false;
+#endif
+}
+
+bool RenderingEngine::setXorgWindowIconFromPath(const std::string &icon_file)
+{
+#ifdef XORG_USED
+
+       video::IVideoDriver *v_driver = m_device->getVideoDriver();
+
+       video::IImageLoader *image_loader = NULL;
+       u32 cnt = v_driver->getImageLoaderCount();
+       for (u32 i = 0; i < cnt; i++) {
+               if (v_driver->getImageLoader(i)->isALoadableFileExtension(
+                                   icon_file.c_str())) {
+                       image_loader = v_driver->getImageLoader(i);
+                       break;
+               }
+       }
+
+       if (!image_loader) {
+               warningstream << "Could not find image loader for file '" << icon_file
+                             << "'" << std::endl;
+               return false;
+       }
+
+       io::IReadFile *icon_f =
+                       m_device->getFileSystem()->createAndOpenFile(icon_file.c_str());
+
+       if (!icon_f) {
+               warningstream << "Could not load icon file '" << icon_file << "'"
+                             << std::endl;
+               return false;
+       }
+
+       video::IImage *img = image_loader->loadImage(icon_f);
+
+       if (!img) {
+               warningstream << "Could not load icon file '" << icon_file << "'"
+                             << std::endl;
+               icon_f->drop();
+               return false;
+       }
+
+       u32 height = img->getDimension().Height;
+       u32 width = img->getDimension().Width;
+
+       size_t icon_buffer_len = 2 + height * width;
+       long *icon_buffer = new long[icon_buffer_len];
+
+       icon_buffer[0] = width;
+       icon_buffer[1] = height;
+
+       for (u32 x = 0; x < width; x++) {
+               for (u32 y = 0; y < height; y++) {
+                       video::SColor col = img->getPixel(x, y);
+                       long pixel_val = 0;
+                       pixel_val |= (u8)col.getAlpha() << 24;
+                       pixel_val |= (u8)col.getRed() << 16;
+                       pixel_val |= (u8)col.getGreen() << 8;
+                       pixel_val |= (u8)col.getBlue();
+                       icon_buffer[2 + x + y * width] = pixel_val;
+               }
+       }
+
+       img->drop();
+       icon_f->drop();
+
+       const video::SExposedVideoData &video_data = v_driver->getExposedVideoData();
+
+       Display *x11_dpl = (Display *)video_data.OpenGLLinux.X11Display;
+
+       if (x11_dpl == NULL) {
+               warningstream << "Could not find x11 display for setting its icon."
+                             << std::endl;
+               delete[] icon_buffer;
+               return false;
+       }
+
+       Window x11_win = (Window)video_data.OpenGLLinux.X11Window;
+
+       Atom net_wm_icon = XInternAtom(x11_dpl, "_NET_WM_ICON", False);
+       Atom cardinal = XInternAtom(x11_dpl, "CARDINAL", False);
+       XChangeProperty(x11_dpl, x11_win, net_wm_icon, cardinal, 32, PropModeReplace,
+                       (const unsigned char *)icon_buffer, icon_buffer_len);
+
+       delete[] icon_buffer;
+
+#endif
+       return true;
+}
+
+/*
+       Draws a screen with a single text on it.
+       Text will be removed when the screen is drawn the next time.
+       Additionally, a progressbar can be drawn when percent is set between 0 and 100.
+*/
+void RenderingEngine::_draw_load_screen(const std::wstring &text,
+               gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime,
+               int percent, bool clouds)
+{
+       v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
+
+       v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight());
+       v2s32 center(screensize.X / 2, screensize.Y / 2);
+       core::rect<s32> textrect(center - textsize / 2, center + textsize / 2);
+
+       gui::IGUIStaticText *guitext =
+                       guienv->addStaticText(text.c_str(), textrect, false, false);
+       guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
+
+       bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
+       if (cloud_menu_background) {
+               g_menuclouds->step(dtime * 3);
+               g_menuclouds->render();
+               get_video_driver()->beginScene(
+                               true, true, video::SColor(255, 140, 186, 250));
+               g_menucloudsmgr->drawAll();
+       } else
+               get_video_driver()->beginScene(true, true, video::SColor(255, 0, 0, 0));
+
+       // draw progress bar
+       if ((percent >= 0) && (percent <= 100)) {
+               video::ITexture *progress_img = tsrc->getTexture("progress_bar.png");
+               video::ITexture *progress_img_bg =
+                               tsrc->getTexture("progress_bar_bg.png");
+
+               if (progress_img && progress_img_bg) {
+#ifndef __ANDROID__
+                       const core::dimension2d<u32> &img_size =
+                                       progress_img_bg->getSize();
+                       u32 imgW = rangelim(img_size.Width, 200, 600);
+                       u32 imgH = rangelim(img_size.Height, 24, 72);
+#else
+                       const core::dimension2d<u32> img_size(256, 48);
+                       float imgRatio = (float)img_size.Height / img_size.Width;
+                       u32 imgW = screensize.X / 2.2f;
+                       u32 imgH = floor(imgW * imgRatio);
+#endif
+                       v2s32 img_pos((screensize.X - imgW) / 2,
+                                       (screensize.Y - imgH) / 2);
+
+                       draw2DImageFilterScaled(get_video_driver(), progress_img_bg,
+                                       core::rect<s32>(img_pos.X, img_pos.Y,
+                                                       img_pos.X + imgW,
+                                                       img_pos.Y + imgH),
+                                       core::rect<s32>(0, 0, img_size.Width,
+                                                       img_size.Height),
+                                       0, 0, true);
+
+                       draw2DImageFilterScaled(get_video_driver(), progress_img,
+                                       core::rect<s32>(img_pos.X, img_pos.Y,
+                                                       img_pos.X + (percent * imgW) / 100,
+                                                       img_pos.Y + imgH),
+                                       core::rect<s32>(0, 0,
+                                                       (percent * img_size.Width) / 100,
+                                                       img_size.Height),
+                                       0, 0, true);
+               }
+       }
+
+       guienv->drawAll();
+       get_video_driver()->endScene();
+       guitext->remove();
+}
+
+std::vector<core::vector3d<u32>> RenderingEngine::getSupportedVideoModes()
+{
+       IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
+       sanity_check(nulldevice);
+
+       std::vector<core::vector3d<u32>> mlist;
+       video::IVideoModeList *modelist = nulldevice->getVideoModeList();
+
+       s32 num_modes = modelist->getVideoModeCount();
+       for (s32 i = 0; i != num_modes; i++) {
+               core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
+               u32 mode_depth = (u32)modelist->getVideoModeDepth(i);
+               mlist.push_back(core::vector3d<u32>(
+                               mode_res.Width, mode_res.Height, mode_depth));
+       }
+
+       nulldevice->drop();
+       return mlist;
+}
+
+std::vector<irr::video::E_DRIVER_TYPE> RenderingEngine::getSupportedVideoDrivers()
+{
+       std::vector<irr::video::E_DRIVER_TYPE> drivers;
+
+       for (int i = 0; i != irr::video::EDT_COUNT; i++) {
+               if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE)i))
+                       drivers.push_back((irr::video::E_DRIVER_TYPE)i);
+       }
+
+       return drivers;
+}
+
+void RenderingEngine::_draw_scene(Camera *camera, Client *client, LocalPlayer *player,
+               Hud *hud, Minimap *mapper, gui::IGUIEnvironment *guienv,
+               const v2u32 &screensize, const video::SColor &skycolor, bool show_hud,
+               bool show_minimap)
+{
+       bool draw_wield_tool =
+                       (show_hud && (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
+                                       camera->getCameraMode() < CAMERA_MODE_THIRD);
+
+       bool draw_crosshair = ((player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
+                              (camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT));
+
+#ifdef HAVE_TOUCHSCREENGUI
+       try {
+               draw_crosshair = !g_settings->getBool("touchtarget");
+       } catch (SettingNotFoundException) {
+       }
+#endif
+
+       const std::string &draw_mode = g_settings->get("3d_mode");
+
+       if (draw_mode == "anaglyph") {
+               draw_anaglyph_3d_mode(
+                               camera, show_hud, hud, draw_wield_tool, client, guienv);
+               draw_crosshair = false;
+       } else if (draw_mode == "interlaced") {
+               draw_interlaced_3d_mode(camera, show_hud, hud, screensize,
+                               draw_wield_tool, client, guienv, skycolor);
+               draw_crosshair = false;
+       } else if (draw_mode == "sidebyside") {
+               draw_sidebyside_3d_mode(camera, show_hud, hud, screensize,
+                               draw_wield_tool, client, guienv, skycolor);
+               show_hud = false;
+       } else if (draw_mode == "topbottom") {
+               draw_top_bottom_3d_mode(camera, show_hud, hud, screensize,
+                               draw_wield_tool, client, guienv, skycolor);
+               show_hud = false;
+       } else if (draw_mode == "pageflip") {
+               draw_pageflip_3d_mode(camera, show_hud, hud, screensize, draw_wield_tool,
+                               client, guienv, skycolor);
+               draw_crosshair = false;
+               show_hud = false;
+       } else {
+               draw_plain(camera, show_hud, hud, screensize, draw_wield_tool, client,
+                               guienv, skycolor);
+       }
+
+       /*
+               Post effects
+       */
+       client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());
+
+       // TODO how to make those 3d too
+       if (show_hud) {
+               if (draw_crosshair)
+                       hud->drawCrosshair();
+
+               hud->drawHotbar(client->getPlayerItem());
+               hud->drawLuaElements(camera->getOffset());
+               camera->drawNametags();
+
+               if (mapper && show_minimap)
+                       mapper->drawMinimap();
+       }
+
+       guienv->drawAll();
+}
+
+void RenderingEngine::draw_anaglyph_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+               bool draw_wield_tool, Client *client, gui::IGUIEnvironment *guienv)
+{
+
+       /* preserve old setup*/
+       irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+       irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+
+       irr::core::matrix4 startMatrix =
+                       camera->getCameraNode()->getAbsoluteTransformation();
+       irr::core::vector3df focusPoint =
+                       (camera->getCameraNode()->getTarget() -
+                                       camera->getCameraNode()->getAbsolutePosition())
+                                       .setLength(1) +
+                       camera->getCameraNode()->getAbsolutePosition();
+
+       // Left eye...
+       irr::core::vector3df leftEye;
+       irr::core::matrix4 leftMove;
+       leftMove.setTranslation(irr::core::vector3df(
+                       -g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+       leftEye = (startMatrix * leftMove).getTranslation();
+
+       // clear the depth buffer, and color
+       getVideoDriver()->beginScene(true, true, irr::video::SColor(0, 200, 200, 255));
+       getVideoDriver()->getOverrideMaterial().Material.ColorMask = irr::video::ECP_RED;
+       getVideoDriver()->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
+       getVideoDriver()->getOverrideMaterial().EnablePasses =
+                       irr::scene::ESNRP_SKY_BOX + irr::scene::ESNRP_SOLID +
+                       irr::scene::ESNRP_TRANSPARENT +
+                       irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
+       camera->getCameraNode()->setPosition(leftEye);
+       camera->getCameraNode()->setTarget(focusPoint);
+       get_scene_manager()->drawAll();
+       getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+       if (show_hud) {
+               hud->drawSelectionMesh();
+               if (draw_wield_tool)
+                       camera->drawWieldedTool(&leftMove);
+       }
+
+       guienv->drawAll();
+
+       // Right eye...
+       irr::core::vector3df rightEye;
+       irr::core::matrix4 rightMove;
+       rightMove.setTranslation(irr::core::vector3df(
+                       g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+       rightEye = (startMatrix * rightMove).getTranslation();
+
+       // clear the depth buffer
+       getVideoDriver()->clearZBuffer();
+       getVideoDriver()->getOverrideMaterial().Material.ColorMask =
+                       irr::video::ECP_GREEN + irr::video::ECP_BLUE;
+       getVideoDriver()->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
+       getVideoDriver()->getOverrideMaterial().EnablePasses =
+                       irr::scene::ESNRP_SKY_BOX + irr::scene::ESNRP_SOLID +
+                       irr::scene::ESNRP_TRANSPARENT +
+                       irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
+       camera->getCameraNode()->setPosition(rightEye);
+       camera->getCameraNode()->setTarget(focusPoint);
+       get_scene_manager()->drawAll();
+       getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+       if (show_hud) {
+               hud->drawSelectionMesh();
+               if (draw_wield_tool)
+                       camera->drawWieldedTool(&rightMove);
+       }
+
+       guienv->drawAll();
+
+       getVideoDriver()->getOverrideMaterial().Material.ColorMask = irr::video::ECP_ALL;
+       getVideoDriver()->getOverrideMaterial().EnableFlags = 0;
+       getVideoDriver()->getOverrideMaterial().EnablePasses = 0;
+       camera->getCameraNode()->setPosition(oldPosition);
+       camera->getCameraNode()->setTarget(oldTarget);
+}
+
+void RenderingEngine::init_texture(
+               const v2u32 &screensize, video::ITexture **texture, const char *name)
+{
+       if (*texture) {
+               getVideoDriver()->removeTexture(*texture);
+       }
+       *texture = getVideoDriver()->addRenderTargetTexture(
+                       core::dimension2d<u32>(screensize.X, screensize.Y), name,
+                       irr::video::ECF_A8R8G8B8);
+}
+
+video::ITexture *RenderingEngine::draw_image(const v2u32 &screensize, parallax_sign psign,
+               const irr::core::matrix4 &startMatrix,
+               const irr::core::vector3df &focusPoint, bool show_hud, Camera *camera,
+               Hud *hud, bool draw_wield_tool, Client *client,
+               gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+       static video::ITexture *images[2] = {NULL, NULL};
+       static v2u32 last_screensize = v2u32(0, 0);
+
+       video::ITexture *image = NULL;
+
+       if (screensize != last_screensize) {
+               init_texture(screensize, &images[1], "mt_drawimage_img1");
+               init_texture(screensize, &images[0], "mt_drawimage_img2");
+               last_screensize = screensize;
+       }
+
+       if (psign == RIGHT)
+               image = images[1];
+       else
+               image = images[0];
+
+       getVideoDriver()->setRenderTarget(image, true, true,
+                       irr::video::SColor(255, skycolor.getRed(), skycolor.getGreen(),
+                                       skycolor.getBlue()));
+
+       irr::core::vector3df eye_pos;
+       irr::core::matrix4 movement;
+       movement.setTranslation(irr::core::vector3df(
+                       (int)psign * g_settings->getFloat("3d_paralax_strength"), 0.0f,
+                       0.0f));
+       eye_pos = (startMatrix * movement).getTranslation();
+
+       // clear the depth buffer
+       getVideoDriver()->clearZBuffer();
+       camera->getCameraNode()->setPosition(eye_pos);
+       camera->getCameraNode()->setTarget(focusPoint);
+       get_scene_manager()->drawAll();
+
+       getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+       if (show_hud) {
+               hud->drawSelectionMesh();
+               if (draw_wield_tool)
+                       camera->drawWieldedTool(&movement);
+       }
+
+       guienv->drawAll();
+
+       /* switch back to real renderer */
+       getVideoDriver()->setRenderTarget(0, true, true,
+                       irr::video::SColor(0, skycolor.getRed(), skycolor.getGreen(),
+                                       skycolor.getBlue()));
+
+       return image;
+}
+
+video::ITexture *RenderingEngine::draw_hud(const v2u32 &screensize, bool show_hud,
+               Hud *hud, Client *client, bool draw_crosshair,
+               const video::SColor &skycolor, gui::IGUIEnvironment *guienv,
+               Camera *camera)
+{
+       static video::ITexture *image = nullptr;
+       init_texture(screensize, &image, "mt_drawimage_hud");
+       getVideoDriver()->setRenderTarget(
+                       image, true, true, irr::video::SColor(255, 0, 0, 0));
+
+       if (show_hud) {
+               if (draw_crosshair)
+                       hud->drawCrosshair();
+               hud->drawHotbar(client->getPlayerItem());
+               hud->drawLuaElements(camera->getOffset());
+               camera->drawNametags();
+               guienv->drawAll();
+       }
+
+       getVideoDriver()->setRenderTarget(0, true, true,
+                       irr::video::SColor(0, skycolor.getRed(), skycolor.getGreen(),
+                                       skycolor.getBlue()));
+
+       return image;
+}
+
+void RenderingEngine::draw_interlaced_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+               const v2u32 &screensize, bool draw_wield_tool, Client *client,
+               gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+       /* save current info */
+       irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+       irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+       irr::core::matrix4 startMatrix =
+                       camera->getCameraNode()->getAbsoluteTransformation();
+       irr::core::vector3df focusPoint =
+                       (camera->getCameraNode()->getTarget() -
+                                       camera->getCameraNode()->getAbsolutePosition())
+                                       .setLength(1) +
+                       camera->getCameraNode()->getAbsolutePosition();
+
+       /* create left view */
+       video::ITexture *left_image = draw_image(screensize, LEFT, startMatrix,
+                       focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+                       guienv, skycolor);
+
+       // Right eye...
+       irr::core::vector3df rightEye;
+       irr::core::matrix4 rightMove;
+       rightMove.setTranslation(irr::core::vector3df(
+                       g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+       rightEye = (startMatrix * rightMove).getTranslation();
+
+       // clear the depth buffer
+       getVideoDriver()->clearZBuffer();
+       camera->getCameraNode()->setPosition(rightEye);
+       camera->getCameraNode()->setTarget(focusPoint);
+       get_scene_manager()->drawAll();
+
+       getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+       if (show_hud) {
+               hud->drawSelectionMesh();
+               if (draw_wield_tool)
+                       camera->drawWieldedTool(&rightMove);
+       }
+       guienv->drawAll();
+
+       for (unsigned int i = 0; i < screensize.Y; i += 2) {
+#if (IRRLICHT_VERSION_MAJOR >= 1) && (IRRLICHT_VERSION_MINOR >= 8)
+               getVideoDriver()->draw2DImage(left_image,
+                               irr::core::position2d<s32>(0, i),
+#else
+               getVideoDriver()->draw2DImage(left_image,
+                               irr::core::position2d<s32>(0, screensize.Y - i),
+#endif
+                               irr::core::rect<s32>(0, i, screensize.X, i + 1), 0,
+                               irr::video::SColor(255, 255, 255, 255), false);
+       }
+
+       /* cleanup */
+       camera->getCameraNode()->setPosition(oldPosition);
+       camera->getCameraNode()->setTarget(oldTarget);
+}
+
+void RenderingEngine::draw_sidebyside_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+               const v2u32 &screensize, bool draw_wield_tool, Client *client,
+               gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+       /* save current info */
+       irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+       irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+       irr::core::matrix4 startMatrix =
+                       camera->getCameraNode()->getAbsoluteTransformation();
+       irr::core::vector3df focusPoint =
+                       (camera->getCameraNode()->getTarget() -
+                                       camera->getCameraNode()->getAbsolutePosition())
+                                       .setLength(1) +
+                       camera->getCameraNode()->getAbsolutePosition();
+
+       /* create left view */
+       video::ITexture *left_image = draw_image(screensize, LEFT, startMatrix,
+                       focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+                       guienv, skycolor);
+
+       /* create right view */
+       video::ITexture *right_image = draw_image(screensize, RIGHT, startMatrix,
+                       focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+                       guienv, skycolor);
+
+       /* create hud overlay */
+       video::ITexture *hudtexture = draw_hud(screensize, show_hud, hud, client, false,
+                       skycolor, guienv, camera);
+       getVideoDriver()->makeColorKeyTexture(
+                       hudtexture, irr::video::SColor(255, 0, 0, 0));
+       // makeColorKeyTexture mirrors texture so we do it twice to get it right again
+       getVideoDriver()->makeColorKeyTexture(
+                       hudtexture, irr::video::SColor(255, 0, 0, 0));
+
+       draw2DImageFilterScaled(getVideoDriver(), left_image,
+                       irr::core::rect<s32>(0, 0, screensize.X / 2, screensize.Y),
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+                       false);
+
+       draw2DImageFilterScaled(getVideoDriver(), hudtexture,
+                       irr::core::rect<s32>(0, 0, screensize.X / 2, screensize.Y),
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+                       true);
+
+       draw2DImageFilterScaled(getVideoDriver(), right_image,
+                       irr::core::rect<s32>(
+                                       screensize.X / 2, 0, screensize.X, screensize.Y),
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+                       false);
+
+       draw2DImageFilterScaled(getVideoDriver(), hudtexture,
+                       irr::core::rect<s32>(
+                                       screensize.X / 2, 0, screensize.X, screensize.Y),
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+                       true);
+
+       left_image = nullptr;
+       right_image = nullptr;
+
+       /* cleanup */
+       camera->getCameraNode()->setPosition(oldPosition);
+       camera->getCameraNode()->setTarget(oldTarget);
+}
+
+void RenderingEngine::draw_top_bottom_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+               const v2u32 &screensize, bool draw_wield_tool, Client *client,
+               gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+       /* save current info */
+       irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+       irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+       irr::core::matrix4 startMatrix =
+                       camera->getCameraNode()->getAbsoluteTransformation();
+       irr::core::vector3df focusPoint =
+                       (camera->getCameraNode()->getTarget() -
+                                       camera->getCameraNode()->getAbsolutePosition())
+                                       .setLength(1) +
+                       camera->getCameraNode()->getAbsolutePosition();
+
+       /* create left view */
+       video::ITexture *left_image = draw_image(screensize, LEFT, startMatrix,
+                       focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+                       guienv, skycolor);
+
+       /* create right view */
+       video::ITexture *right_image = draw_image(screensize, RIGHT, startMatrix,
+                       focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+                       guienv, skycolor);
+
+       /* create hud overlay */
+       video::ITexture *hudtexture = draw_hud(screensize, show_hud, hud, client, false,
+                       skycolor, guienv, camera);
+       getVideoDriver()->makeColorKeyTexture(
+                       hudtexture, irr::video::SColor(255, 0, 0, 0));
+       // makeColorKeyTexture mirrors texture so we do it twice to get it right again
+       getVideoDriver()->makeColorKeyTexture(
+                       hudtexture, irr::video::SColor(255, 0, 0, 0));
+
+       draw2DImageFilterScaled(getVideoDriver(), left_image,
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y / 2),
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+                       false);
+
+       draw2DImageFilterScaled(getVideoDriver(), hudtexture,
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y / 2),
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+                       true);
+
+       draw2DImageFilterScaled(getVideoDriver(), right_image,
+                       irr::core::rect<s32>(
+                                       0, screensize.Y / 2, screensize.X, screensize.Y),
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+                       false);
+
+       draw2DImageFilterScaled(getVideoDriver(), hudtexture,
+                       irr::core::rect<s32>(
+                                       0, screensize.Y / 2, screensize.X, screensize.Y),
+                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+                       true);
+
+       left_image = NULL;
+       right_image = NULL;
+
+       /* cleanup */
+       camera->getCameraNode()->setPosition(oldPosition);
+       camera->getCameraNode()->setTarget(oldTarget);
+}
+
+void RenderingEngine::draw_pageflip_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+               const v2u32 &screensize, bool draw_wield_tool, Client *client,
+               gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
+       errorstream << "Pageflip 3D mode is not supported"
+                   << " with your Irrlicht version!" << std::endl;
+#else
+       /* preserve old setup*/
+       irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+       irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+
+       irr::core::matrix4 startMatrix =
+                       camera->getCameraNode()->getAbsoluteTransformation();
+       irr::core::vector3df focusPoint =
+                       (camera->getCameraNode()->getTarget() -
+                                       camera->getCameraNode()->getAbsolutePosition())
+                                       .setLength(1) +
+                       camera->getCameraNode()->getAbsolutePosition();
+
+       // Left eye...
+       getVideoDriver()->setRenderTarget(irr::video::ERT_STEREO_LEFT_BUFFER);
+
+       irr::core::vector3df leftEye;
+       irr::core::matrix4 leftMove;
+       leftMove.setTranslation(irr::core::vector3df(
+                       -g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+       leftEye = (startMatrix * leftMove).getTranslation();
+
+       // clear the depth buffer, and color
+       getVideoDriver()->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+       camera->getCameraNode()->setPosition(leftEye);
+       camera->getCameraNode()->setTarget(focusPoint);
+       get_scene_manager()->drawAll();
+       getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+       if (show_hud) {
+               hud->drawSelectionMesh();
+               if (draw_wield_tool)
+                       camera->drawWieldedTool(&leftMove);
+               hud->drawHotbar(client->getPlayerItem());
+               hud->drawLuaElements(camera->getOffset());
+               camera->drawNametags();
+       }
+
+       guienv->drawAll();
+
+       // Right eye...
+       getVideoDriver()->setRenderTarget(irr::video::ERT_STEREO_RIGHT_BUFFER);
+
+       irr::core::vector3df rightEye;
+       irr::core::matrix4 rightMove;
+       rightMove.setTranslation(irr::core::vector3df(
+                       g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+       rightEye = (startMatrix * rightMove).getTranslation();
+
+       // clear the depth buffer, and color
+       getVideoDriver()->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+       camera->getCameraNode()->setPosition(rightEye);
+       camera->getCameraNode()->setTarget(focusPoint);
+       get_scene_manager()->drawAll();
+       getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+       if (show_hud) {
+               hud->drawSelectionMesh();
+               if (draw_wield_tool)
+                       camera->drawWieldedTool(&rightMove);
+               hud->drawHotbar(client->getPlayerItem());
+               hud->drawLuaElements(camera->getOffset());
+               camera->drawNametags();
+       }
+
+       guienv->drawAll();
+
+       camera->getCameraNode()->setPosition(oldPosition);
+       camera->getCameraNode()->setTarget(oldTarget);
+#endif
+}
+
+// returns (size / coef), rounded upwards
+inline int scaledown(int coef, int size)
+{
+       return (size + coef - 1) / coef;
+}
+
+void RenderingEngine::draw_plain(Camera *camera, bool show_hud, Hud *hud,
+               const v2u32 &screensize, bool draw_wield_tool, Client *client,
+               gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+       // Undersampling-specific stuff
+       static video::ITexture *image = NULL;
+       static v2u32 last_pixelated_size = v2u32(0, 0);
+       static thread_local int undersampling = g_settings->getU16("undersampling");
+       v2u32 pixelated_size;
+       v2u32 dest_size;
+       if (undersampling > 0) {
+               pixelated_size = v2u32(scaledown(undersampling, screensize.X),
+                               scaledown(undersampling, screensize.Y));
+               dest_size = v2u32(undersampling * pixelated_size.X,
+                               undersampling * pixelated_size.Y);
+               if (pixelated_size != last_pixelated_size) {
+                       init_texture(pixelated_size, &image, "mt_drawimage_img1");
+                       last_pixelated_size = pixelated_size;
+               }
+               getVideoDriver()->setRenderTarget(image, true, true, skycolor);
+       }
+
+       // Render
+       get_scene_manager()->drawAll();
+       getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+       if (show_hud) {
+               hud->drawSelectionMesh();
+               if (draw_wield_tool) {
+                       camera->drawWieldedTool();
+               }
+       }
+
+       // Upscale lowres render
+       if (undersampling > 0) {
+               getVideoDriver()->setRenderTarget(0, true, true);
+               getVideoDriver()->draw2DImage(image,
+                               irr::core::rect<s32>(0, 0, dest_size.X, dest_size.Y),
+                               irr::core::rect<s32>(0, 0, pixelated_size.X,
+                                               pixelated_size.Y));
+       }
+}
+
+const char *RenderingEngine::getVideoDriverName(irr::video::E_DRIVER_TYPE type)
+{
+       static const char *driver_ids[] = {
+                       "null", "software", "burningsvideo", "direct3d8", "direct3d9",
+                       "opengl", "ogles1", "ogles2",
+       };
+
+       return driver_ids[type];
+}
+
+const char *RenderingEngine::getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)
+{
+       static const char *driver_names[] = {
+                       "NULL Driver", "Software Renderer", "Burning's Video",
+                       "Direct3D 8", "Direct3D 9", "OpenGL", "OpenGL ES1", "OpenGL ES2",
+       };
+
+       return driver_names[type];
+}
+
+#ifndef __ANDROID__
+#ifdef XORG_USED
+
+static float calcDisplayDensity()
+{
+       const char *current_display = getenv("DISPLAY");
+
+       if (current_display != NULL) {
+               Display *x11display = XOpenDisplay(current_display);
+
+               if (x11display != NULL) {
+                       /* try x direct */
+                       float dpi_height = floor(
+                                       DisplayHeight(x11display, 0) /
+                                                       (DisplayHeightMM(x11display, 0) *
+                                                                       0.039370) +
+                                       0.5);
+                       float dpi_width = floor(
+                                       DisplayWidth(x11display, 0) /
+                                                       (DisplayWidthMM(x11display, 0) *
+                                                                       0.039370) +
+                                       0.5);
+
+                       XCloseDisplay(x11display);
+
+                       return std::max(dpi_height, dpi_width) / 96.0;
+               }
+       }
+
+       /* return manually specified dpi */
+       return g_settings->getFloat("screen_dpi") / 96.0;
+}
+
+float RenderingEngine::getDisplayDensity()
+{
+       static float cached_display_density = calcDisplayDensity();
+       return cached_display_density;
+}
+
+#else  // XORG_USED
+float RenderingEngine::getDisplayDensity()
+{
+       return g_settings->getFloat("screen_dpi") / 96.0;
+}
+#endif // XORG_USED
+
+v2u32 RenderingEngine::getDisplaySize()
+{
+       IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
+
+       core::dimension2d<u32> deskres =
+                       nulldevice->getVideoModeList()->getDesktopResolution();
+       nulldevice->drop();
+
+       return deskres;
+}
+#endif // __ANDROID__
diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h
new file mode 100644 (file)
index 0000000..40fbaa8
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include <vector>
+#include <string>
+#include "irrlichttypes_extrabloated.h"
+#include "debug.h"
+
+class ITextureSource;
+class Camera;
+class Client;
+class LocalPlayer;
+class Hud;
+class Minimap;
+
+class RenderingEngine
+{
+public:
+       RenderingEngine(IEventReceiver *eventReceiver);
+       ~RenderingEngine();
+
+       v2u32 getWindowSize() const;
+       void setResizable(bool resize);
+
+       video::IVideoDriver *getVideoDriver();
+
+       static const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
+       static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
+       static float getDisplayDensity();
+       static v2u32 getDisplaySize();
+
+       static void setXorgClassHint(const video::SExposedVideoData &video_data,
+                       const std::string &name);
+       bool setWindowIcon();
+       bool setXorgWindowIconFromPath(const std::string &icon_file);
+       static bool print_video_modes();
+
+       static RenderingEngine *get_instance() { return s_singleton; }
+
+       static io::IFileSystem *get_filesystem()
+       {
+               sanity_check(s_singleton && s_singleton->m_device);
+               return s_singleton->m_device->getFileSystem();
+       }
+
+       static video::IVideoDriver *get_video_driver()
+       {
+               sanity_check(s_singleton && s_singleton->m_device);
+               return s_singleton->m_device->getVideoDriver();
+       }
+
+       static scene::IMeshCache *get_mesh_cache()
+       {
+               sanity_check(s_singleton && s_singleton->m_device);
+               return s_singleton->m_device->getSceneManager()->getMeshCache();
+       }
+
+       static scene::ISceneManager *get_scene_manager()
+       {
+               sanity_check(s_singleton && s_singleton->m_device);
+               return s_singleton->m_device->getSceneManager();
+       }
+
+       static irr::IrrlichtDevice *get_raw_device()
+       {
+               sanity_check(s_singleton && s_singleton->m_device);
+               return s_singleton->m_device;
+       }
+
+       static u32 get_timer_time()
+       {
+               sanity_check(s_singleton && s_singleton->m_device &&
+                               s_singleton->m_device->getTimer());
+               return s_singleton->m_device->getTimer()->getTime();
+       }
+
+       static gui::IGUIEnvironment *get_gui_env()
+       {
+               sanity_check(s_singleton && s_singleton->m_device);
+               return s_singleton->m_device->getGUIEnvironment();
+       }
+
+       inline static void draw_load_screen(const std::wstring &text,
+                       gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
+                       float dtime = 0, int percent = 0, bool clouds = true)
+       {
+               s_singleton->_draw_load_screen(
+                               text, guienv, tsrc, dtime, percent, clouds);
+       }
+
+       inline static void draw_scene(Camera *camera, Client *client, LocalPlayer *player,
+                       Hud *hud, Minimap *mapper, gui::IGUIEnvironment *guienv,
+                       const v2u32 &screensize, const video::SColor &skycolor,
+                       bool show_hud, bool show_minimap)
+       {
+               s_singleton->_draw_scene(camera, client, player, hud, mapper, guienv,
+                               screensize, skycolor, show_hud, show_minimap);
+       }
+
+       static bool run()
+       {
+               sanity_check(s_singleton && s_singleton->m_device);
+               return s_singleton->m_device->run();
+       }
+
+       static std::vector<core::vector3d<u32>> getSupportedVideoModes();
+       static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
+
+private:
+       enum parallax_sign
+       {
+               LEFT = -1,
+               RIGHT = 1,
+               EYECOUNT = 2
+       };
+
+       void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv,
+                       ITextureSource *tsrc, float dtime = 0, int percent = 0,
+                       bool clouds = true);
+
+       void _draw_scene(Camera *camera, Client *client, LocalPlayer *player, Hud *hud,
+                       Minimap *mapper, gui::IGUIEnvironment *guienv,
+                       const v2u32 &screensize, const video::SColor &skycolor,
+                       bool show_hud, bool show_minimap);
+
+       void draw_anaglyph_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+                       bool draw_wield_tool, Client *client,
+                       gui::IGUIEnvironment *guienv);
+
+       void draw_interlaced_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+                       const v2u32 &screensize, bool draw_wield_tool, Client *client,
+                       gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+       void draw_sidebyside_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+                       const v2u32 &screensize, bool draw_wield_tool, Client *client,
+                       gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+       void draw_top_bottom_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+                       const v2u32 &screensize, bool draw_wield_tool, Client *client,
+                       gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+       void draw_pageflip_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+                       const v2u32 &screensize, bool draw_wield_tool, Client *client,
+                       gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+       void draw_plain(Camera *camera, bool show_hud, Hud *hud, const v2u32 &screensize,
+                       bool draw_wield_tool, Client *client,
+                       gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+       void init_texture(const v2u32 &screensize, video::ITexture **texture,
+                       const char *name);
+
+       video::ITexture *draw_image(const v2u32 &screensize, parallax_sign psign,
+                       const irr::core::matrix4 &startMatrix,
+                       const irr::core::vector3df &focusPoint, bool show_hud,
+                       Camera *camera, Hud *hud, bool draw_wield_tool, Client *client,
+                       gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+       video::ITexture *draw_hud(const v2u32 &screensize, bool show_hud, Hud *hud,
+                       Client *client, bool draw_crosshair,
+                       const video::SColor &skycolor, gui::IGUIEnvironment *guienv,
+                       Camera *camera);
+
+       irr::IrrlichtDevice *m_device = nullptr;
+       static RenderingEngine *s_singleton;
+};
index e47a40ea138c1f0a50ef9e5836b75a052026bfcd..1bcbdc6f9ac04a1dc7ae7732a0fd4f5878e47623 100644 (file)
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "imagefilters.h"
 #include "guiscalingfilter.h"
 #include "nodedef.h"
 #include "imagefilters.h"
 #include "guiscalingfilter.h"
 #include "nodedef.h"
+#include "renderingengine.h"
 
 
 #ifdef __ANDROID__
 
 
 #ifdef __ANDROID__
@@ -198,8 +199,7 @@ public:
                }
                m_images.clear();
        }
                }
                m_images.clear();
        }
-       void insert(const std::string &name, video::IImage *img,
-                       bool prefer_local, video::IVideoDriver *driver)
+       void insert(const std::string &name, video::IImage *img, bool prefer_local)
        {
                assert(img); // Pre-condition
                // Remove old image
        {
                assert(img); // Pre-condition
                // Remove old image
@@ -217,7 +217,8 @@ public:
                if (prefer_local){
                        std::string path = getTexturePath(name);
                        if (path != ""){
                if (prefer_local){
                        std::string path = getTexturePath(name);
                        if (path != ""){
-                               video::IImage *img2 = driver->createImageFromFile(path.c_str());
+                               video::IImage *img2 = RenderingEngine::get_video_driver()->
+                                       createImageFromFile(path.c_str());
                                if (img2){
                                        toadd = img2;
                                        need_to_grab = false;
                                if (img2){
                                        toadd = img2;
                                        need_to_grab = false;
@@ -238,7 +239,7 @@ public:
                return NULL;
        }
        // Primarily fetches from cache, secondarily tries to read from filesystem
                return NULL;
        }
        // Primarily fetches from cache, secondarily tries to read from filesystem
-       video::IImage* getOrLoad(const std::string &name, IrrlichtDevice *device)
+       video::IImage *getOrLoad(const std::string &name)
        {
                std::map<std::string, video::IImage*>::iterator n;
                n = m_images.find(name);
        {
                std::map<std::string, video::IImage*>::iterator n;
                n = m_images.find(name);
@@ -246,7 +247,7 @@ public:
                        n->second->grab(); // Grab for caller
                        return n->second;
                }
                        n->second->grab(); // Grab for caller
                        return n->second;
                }
-               video::IVideoDriver* driver = device->getVideoDriver();
+               video::IVideoDriver *driver = RenderingEngine::get_video_driver();
                std::string path = getTexturePath(name);
                if (path == ""){
                        infostream<<"SourceImageCache::getOrLoad(): No path found for \""
                std::string path = getTexturePath(name);
                if (path == ""){
                        infostream<<"SourceImageCache::getOrLoad(): No path found for \""
@@ -274,7 +275,7 @@ private:
 class TextureSource : public IWritableTextureSource
 {
 public:
 class TextureSource : public IWritableTextureSource
 {
 public:
-       TextureSource(IrrlichtDevice *device);
+       TextureSource();
        virtual ~TextureSource();
 
        /*
        virtual ~TextureSource();
 
        /*
@@ -343,12 +344,6 @@ public:
 
        virtual Palette* getPalette(const std::string &name);
 
 
        virtual Palette* getPalette(const std::string &name);
 
-       // Returns a pointer to the irrlicht device
-       virtual IrrlichtDevice* getDevice()
-       {
-               return m_device;
-       }
-
        bool isKnownSourceImage(const std::string &name)
        {
                bool is_known = false;
        bool isKnownSourceImage(const std::string &name)
        {
                bool is_known = false;
@@ -387,8 +382,6 @@ private:
 
        // The id of the thread that is allowed to use irrlicht directly
        std::thread::id m_main_thread;
 
        // The id of the thread that is allowed to use irrlicht directly
        std::thread::id m_main_thread;
-       // The irrlicht device
-       IrrlichtDevice *m_device;
 
        // Cache of source images
        // This should be only accessed from the main thread
 
        // Cache of source images
        // This should be only accessed from the main thread
@@ -435,16 +428,13 @@ private:
        bool m_setting_anisotropic_filter;
 };
 
        bool m_setting_anisotropic_filter;
 };
 
-IWritableTextureSource* createTextureSource(IrrlichtDevice *device)
+IWritableTextureSource *createTextureSource()
 {
 {
-       return new TextureSource(device);
+       return new TextureSource();
 }
 
 }
 
-TextureSource::TextureSource(IrrlichtDevice *device):
-               m_device(device)
+TextureSource::TextureSource()
 {
 {
-       assert(m_device); // Pre-condition
-
        m_main_thread = std::this_thread::get_id();
 
        // Add a NULL TextureInfo as the first index, named ""
        m_main_thread = std::this_thread::get_id();
 
        // Add a NULL TextureInfo as the first index, named ""
@@ -461,7 +451,7 @@ TextureSource::TextureSource(IrrlichtDevice *device):
 
 TextureSource::~TextureSource()
 {
 
 TextureSource::~TextureSource()
 {
-       video::IVideoDriver* driver = m_device->getVideoDriver();
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
 
        unsigned int textures_before = driver->getTextureCount();
 
 
        unsigned int textures_before = driver->getTextureCount();
 
@@ -622,7 +612,7 @@ u32 TextureSource::generateTexture(const std::string &name)
                return 0;
        }
 
                return 0;
        }
 
-       video::IVideoDriver *driver = m_device->getVideoDriver();
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
        sanity_check(driver);
 
        video::IImage *img = generateImage(name);
        sanity_check(driver);
 
        video::IImage *img = generateImage(name);
@@ -773,7 +763,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im
 
        sanity_check(std::this_thread::get_id() == m_main_thread);
 
 
        sanity_check(std::this_thread::get_id() == m_main_thread);
 
-       m_sourcecache.insert(name, img, true, m_device->getVideoDriver());
+       m_sourcecache.insert(name, img, true);
        m_source_image_existence.set(name, true);
 }
 
        m_source_image_existence.set(name, true);
 }
 
@@ -781,7 +771,7 @@ void TextureSource::rebuildImagesAndTextures()
 {
        MutexAutoLock lock(m_textureinfo_cache_mutex);
 
 {
        MutexAutoLock lock(m_textureinfo_cache_mutex);
 
-       video::IVideoDriver* driver = m_device->getVideoDriver();
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
        sanity_check(driver);
 
        // Recreate textures
        sanity_check(driver);
 
        // Recreate textures
@@ -810,7 +800,7 @@ void TextureSource::rebuildImagesAndTextures()
 video::ITexture* TextureSource::generateTextureFromMesh(
                const TextureFromMeshParams &params)
 {
 video::ITexture* TextureSource::generateTextureFromMesh(
                const TextureFromMeshParams &params)
 {
-       video::IVideoDriver *driver = m_device->getVideoDriver();
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
        sanity_check(driver);
 
 #ifdef __ANDROID__
        sanity_check(driver);
 
 #ifdef __ANDROID__
@@ -935,8 +925,7 @@ video::ITexture* TextureSource::generateTextureFromMesh(
        }
 #endif
 
        }
 #endif
 
-       if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET) == false)
-       {
+       if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) {
                static bool warned = false;
                if (!warned)
                {
                static bool warned = false;
                if (!warned)
                {
@@ -967,7 +956,7 @@ video::ITexture* TextureSource::generateTextureFromMesh(
        }
 
        // Get a scene manager
        }
 
        // Get a scene manager
-       scene::ISceneManager *smgr_main = m_device->getSceneManager();
+       scene::ISceneManager *smgr_main = RenderingEngine::get_scene_manager();
        assert(smgr_main);
        scene::ISceneManager *smgr = smgr_main->createNewSceneManager();
        assert(smgr);
        assert(smgr_main);
        scene::ISceneManager *smgr = smgr_main->createNewSceneManager();
        assert(smgr);
@@ -1065,10 +1054,6 @@ video::IImage* TextureSource::generateImage(const std::string &name)
                baseimg = generateImage(name.substr(0, last_separator_pos));
        }
 
                baseimg = generateImage(name.substr(0, last_separator_pos));
        }
 
-
-       video::IVideoDriver* driver = m_device->getVideoDriver();
-       sanity_check(driver);
-
        /*
                Parse out the last part of the name of the image and act
                according to it
        /*
                Parse out the last part of the name of the image and act
                according to it
@@ -1196,13 +1181,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                video::IImage *& baseimg)
 {
        const char escape = '\\'; // same as in generateImage()
                video::IImage *& baseimg)
 {
        const char escape = '\\'; // same as in generateImage()
-       video::IVideoDriver* driver = m_device->getVideoDriver();
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
        sanity_check(driver);
 
        // Stuff starting with [ are special commands
        if (part_of_name.size() == 0 || part_of_name[0] != '[')
        {
        sanity_check(driver);
 
        // Stuff starting with [ are special commands
        if (part_of_name.size() == 0 || part_of_name[0] != '[')
        {
-               video::IImage *image = m_sourcecache.getOrLoad(part_of_name, m_device);
+               video::IImage *image = m_sourcecache.getOrLoad(part_of_name);
 #ifdef __ANDROID__
                image = Align2Npot2(image, driver);
 #endif
 #ifdef __ANDROID__
                image = Align2Npot2(image, driver);
 #endif
@@ -1275,7 +1260,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                                blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
                        } else if (dim.Width * dim.Height < dim_dst.Width * dim_dst.Height) {
                                // Upscale overlying image
                                blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
                        } else if (dim.Width * dim.Height < dim_dst.Width * dim_dst.Height) {
                                // Upscale overlying image
-                               video::IImage* scaled_image = m_device->getVideoDriver()->
+                               video::IImage *scaled_image = RenderingEngine::get_video_driver()->
                                        createImage(video::ECF_A8R8G8B8, dim_dst);
                                image->copyToScaling(scaled_image);
 
                                        createImage(video::ECF_A8R8G8B8, dim_dst);
                                image->copyToScaling(scaled_image);
 
@@ -1283,7 +1268,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                                scaled_image->drop();
                        } else {
                                // Upscale base image
                                scaled_image->drop();
                        } else {
                                // Upscale base image
-                               video::IImage* scaled_base = m_device->getVideoDriver()->
+                               video::IImage *scaled_base = RenderingEngine::get_video_driver()->
                                        createImage(video::ECF_A8R8G8B8, dim);
                                baseimg->copyToScaling(scaled_base);
                                baseimg->drop();
                                        createImage(video::ECF_A8R8G8B8, dim);
                                baseimg->copyToScaling(scaled_base);
                                baseimg->drop();
@@ -1333,7 +1318,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                                        horizontally tiled.
                                */
                                video::IImage *img_crack = m_sourcecache.getOrLoad(
                                        horizontally tiled.
                                */
                                video::IImage *img_crack = m_sourcecache.getOrLoad(
-                                       "crack_anylength.png", m_device);
+                                       "crack_anylength.png");
 
                                if (img_crack) {
                                        draw_crack(img_crack, baseimg,
 
                                if (img_crack) {
                                        draw_crack(img_crack, baseimg,
@@ -1855,7 +1840,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                        u32 height = stoi(sf.next(""));
                        core::dimension2d<u32> dim(width, height);
 
                        u32 height = stoi(sf.next(""));
                        core::dimension2d<u32> dim(width, height);
 
-                       video::IImage* image = m_device->getVideoDriver()->
+                       video::IImage *image = RenderingEngine::get_video_driver()->
                                createImage(video::ECF_A8R8G8B8, dim);
                        baseimg->copyToScaling(image);
                        baseimg->drop();
                                createImage(video::ECF_A8R8G8B8, dim);
                        baseimg->copyToScaling(image);
                        baseimg->drop();
@@ -2356,7 +2341,7 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name)
 
 video::SColor TextureSource::getTextureAverageColor(const std::string &name)
 {
 
 video::SColor TextureSource::getTextureAverageColor(const std::string &name)
 {
-       video::IVideoDriver *driver = m_device->getVideoDriver();
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
        video::SColor c(0, 0, 0, 0);
        video::ITexture *texture = getTexture(name);
        video::IImage *image = driver->createImage(texture,
        video::SColor c(0, 0, 0, 0);
        video::ITexture *texture = getTexture(name);
        video::IImage *image = driver->createImage(texture,
@@ -2400,7 +2385,7 @@ video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present)
        if (isKnownSourceImage(tname)) {
                return getTexture(tname);
        } else {
        if (isKnownSourceImage(tname)) {
                return getTexture(tname);
        } else {
-               video::IVideoDriver *driver = m_device->getVideoDriver();
+               video::IVideoDriver *driver = RenderingEngine::get_video_driver();
                video::IImage *flags_image = driver->createImage(
                        video::ECF_A8R8G8B8, core::dimension2d<u32>(1, 1));
                sanity_check(flags_image != NULL);
                video::IImage *flags_image = driver->createImage(
                        video::ECF_A8R8G8B8, core::dimension2d<u32>(1, 1));
                sanity_check(flags_image != NULL);
index a810aa8e51f4252424d4cde8bf597b2617451b79..b4d615427ad147d89a092cff3fd9f303f086281e 100644 (file)
@@ -114,7 +114,6 @@ public:
         * Should be called from the main thread.
         */
        virtual Palette* getPalette(const std::string &name) = 0;
         * Should be called from the main thread.
         */
        virtual Palette* getPalette(const std::string &name) = 0;
-       virtual IrrlichtDevice* getDevice()=0;
        virtual bool isKnownSourceImage(const std::string &name)=0;
        virtual video::ITexture* generateTextureFromMesh(
                        const TextureFromMeshParams &params)=0;
        virtual bool isKnownSourceImage(const std::string &name)=0;
        virtual video::ITexture* generateTextureFromMesh(
                        const TextureFromMeshParams &params)=0;
@@ -133,7 +132,6 @@ public:
        virtual video::ITexture* getTexture(u32 id)=0;
        virtual video::ITexture* getTexture(
                        const std::string &name, u32 *id = nullptr)=0;
        virtual video::ITexture* getTexture(u32 id)=0;
        virtual video::ITexture* getTexture(
                        const std::string &name, u32 *id = nullptr)=0;
-       virtual IrrlichtDevice* getDevice()=0;
        virtual bool isKnownSourceImage(const std::string &name)=0;
        virtual video::ITexture* generateTextureFromMesh(
                        const TextureFromMeshParams &params)=0;
        virtual bool isKnownSourceImage(const std::string &name)=0;
        virtual video::ITexture* generateTextureFromMesh(
                        const TextureFromMeshParams &params)=0;
@@ -146,7 +144,7 @@ public:
        virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0;
 };
 
        virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0;
 };
 
-IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
+IWritableTextureSource *createTextureSource();
 
 #ifdef __ANDROID__
 video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver);
 
 #ifdef __ANDROID__
 video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver);
@@ -302,7 +300,7 @@ struct TileSpec
                for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
                        layers[layer] = TileLayer();
        }
                for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
                        layers[layer] = TileLayer();
        }
-       
+
        /*!
         * Returns true if this tile can be merged with the other tile.
         */
        /*!
         * Returns true if this tile can be merged with the other tile.
         */
index e0398a06211997f40a8c64af9b7ea9fced4d18de..28b61b06e2ee5fde27a6ecc4f13f18cacdfeacc7 100644 (file)
@@ -31,16 +31,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "voxelalgorithms.h"
 #include "settings.h"
 #include <algorithm>
 #include "voxelalgorithms.h"
 #include "settings.h"
 #include <algorithm>
+#include "client/renderingengine.h"
 
 /*
        ClientEnvironment
 */
 
 
 /*
        ClientEnvironment
 */
 
-ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
+ClientEnvironment::ClientEnvironment(ClientMap *map,
        ITextureSource *texturesource, Client *client):
        Environment(client),
        m_map(map),
        ITextureSource *texturesource, Client *client):
        Environment(client),
        m_map(map),
-       m_smgr(smgr),
        m_texturesource(texturesource),
        m_client(client)
 {
        m_texturesource(texturesource),
        m_client(client)
 {
@@ -456,7 +456,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
        infostream<<"ClientEnvironment::addActiveObject(): "
                <<"added (id="<<object->getId()<<")"<<std::endl;
        m_active_objects[object->getId()] = object;
        infostream<<"ClientEnvironment::addActiveObject(): "
                <<"added (id="<<object->getId()<<")"<<std::endl;
        m_active_objects[object->getId()] = object;
-       object->addToScene(m_smgr, m_texturesource);
+       object->addToScene(RenderingEngine::get_scene_manager(), m_texturesource);
        { // Update lighting immediately
                u8 light = 0;
                bool pos_ok;
        { // Update lighting immediately
                u8 light = 0;
                bool pos_ok;
index 9d893766bed5d0eb6761987036c7a638cb4da4ed..05ec1908ff10f2f24b8b7a85d498471503b4674d 100644 (file)
@@ -67,8 +67,7 @@ typedef std::unordered_map<u16, ClientActiveObject*> ClientActiveObjectMap;
 class ClientEnvironment : public Environment
 {
 public:
 class ClientEnvironment : public Environment
 {
 public:
-       ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
-               ITextureSource *texturesource, Client *client);
+       ClientEnvironment(ClientMap *map, ITextureSource *texturesource, Client *client);
        ~ClientEnvironment();
 
        Map & getMap();
        ~ClientEnvironment();
 
        Map & getMap();
@@ -175,7 +174,6 @@ public:
 private:
        ClientMap *m_map;
        LocalPlayer *m_local_player = nullptr;
 private:
        ClientMap *m_map;
        LocalPlayer *m_local_player = nullptr;
-       scene::ISceneManager *m_smgr;
        ITextureSource *m_texturesource;
        Client *m_client;
        ClientScripting *m_script = nullptr;
        ITextureSource *m_texturesource;
        Client *m_client;
        ClientScripting *m_script = nullptr;
index 73d600a7a89973e431c38163f9c500f15bd9f7a5..7027d07e42ba0f7ed3a9a73758d3ade3de9f179e 100644 (file)
@@ -31,16 +31,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "camera.h"               // CameraModes
 #include "util/basic_macros.h"
 #include <algorithm>
 #include "camera.h"               // CameraModes
 #include "util/basic_macros.h"
 #include <algorithm>
+#include "client/renderingengine.h"
 
 ClientMap::ClientMap(
                Client *client,
                MapDrawControl &control,
 
 ClientMap::ClientMap(
                Client *client,
                MapDrawControl &control,
-               scene::ISceneNode* parent,
-               scene::ISceneManager* mgr,
                s32 id
 ):
        Map(dout_client, client),
                s32 id
 ):
        Map(dout_client, client),
-       scene::ISceneNode(parent, mgr, id),
+       scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
+               RenderingEngine::get_scene_manager(), id),
        m_client(client),
        m_control(control),
        m_camera_position(0,0,0),
        m_client(client),
        m_control(control),
        m_camera_position(0,0,0),
index 8d272077145bc6b209cee658f00393aba68ca4ab..a0f16e46ada177dab6b039f0df14e38d5daae17f 100644 (file)
@@ -59,8 +59,6 @@ public:
        ClientMap(
                        Client *client,
                        MapDrawControl &control,
        ClientMap(
                        Client *client,
                        MapDrawControl &control,
-                       scene::ISceneNode* parent,
-                       scene::ISceneManager* mgr,
                        s32 id
        );
 
                        s32 id
        );
 
index dc08d1ac0fdc26b90a87e846a84b24cb8f4b4a6f..dd6a2dcbdeeb329fd122f5c4f083a7e1ee3d2f67 100644 (file)
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include "client/renderingengine.h"
 #include "clouds.h"
 #include "noise.h"
 #include "constants.h"
 #include "clouds.h"
 #include "noise.h"
 #include "constants.h"
@@ -36,14 +37,12 @@ static void cloud_3d_setting_changed(const std::string &settingname, void *data)
        ((Clouds *)data)->readSettings();
 }
 
        ((Clouds *)data)->readSettings();
 }
 
-Clouds::Clouds(
-               scene::ISceneNode* parent,
-               scene::ISceneManager* mgr,
+Clouds::Clouds(scene::ISceneManager* mgr,
                s32 id,
                u32 seed,
                s16 cloudheight
 ):
                s32 id,
                u32 seed,
                s16 cloudheight
 ):
-       scene::ISceneNode(parent, mgr, id),
+       scene::ISceneNode(mgr->getRootSceneNode(), mgr, id),
        m_seed(seed)
 {
        m_material.setFlag(video::EMF_LIGHTING, false);
        m_seed(seed)
 {
        m_material.setFlag(video::EMF_LIGHTING, false);
@@ -101,22 +100,22 @@ void Clouds::render()
                return;
 
        ScopeProfiler sp(g_profiler, "Rendering of clouds, avg", SPT_AVG);
                return;
 
        ScopeProfiler sp(g_profiler, "Rendering of clouds, avg", SPT_AVG);
-       
+
        int num_faces_to_draw = m_enable_3d ? 6 : 1;
        int num_faces_to_draw = m_enable_3d ? 6 : 1;
-       
+
        m_material.setFlag(video::EMF_BACK_FACE_CULLING, m_enable_3d);
 
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
        driver->setMaterial(m_material);
        m_material.setFlag(video::EMF_BACK_FACE_CULLING, m_enable_3d);
 
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
        driver->setMaterial(m_material);
-       
+
        /*
                Clouds move from Z+ towards Z-
        */
 
        static const float cloud_size = BS * 64.0f;
        /*
                Clouds move from Z+ towards Z-
        */
 
        static const float cloud_size = BS * 64.0f;
-       
+
        const float cloud_full_radius = cloud_size * m_cloud_radius_i;
        const float cloud_full_radius = cloud_size * m_cloud_radius_i;
-       
+
        // Position of cloud noise origin from the camera
        v2f cloud_origin_from_camera_f = m_origin - m_camera_pos;
        // The center point of drawing in the noise
        // Position of cloud noise origin from the camera
        v2f cloud_origin_from_camera_f = m_origin - m_camera_pos;
        // The center point of drawing in the noise
@@ -164,7 +163,7 @@ void Clouds::render()
        bool fog_rangefog = false;
        driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density,
                        fog_pixelfog, fog_rangefog);
        bool fog_rangefog = false;
        driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density,
                        fog_pixelfog, fog_rangefog);
-       
+
        // Set our own fog
        driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5,
                        cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog);
        // Set our own fog
        driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5,
                        cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog);
@@ -340,7 +339,7 @@ void Clouds::render()
        }
 
        delete[] grid;
        }
 
        delete[] grid;
-       
+
        // Restore fog settings
        driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density,
                        fog_pixelfog, fog_rangefog);
        // Restore fog settings
        driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density,
                        fog_pixelfog, fog_rangefog);
index 869f7f7fc8b2980fe447b9bad99b965567d46a6c..52ea930f9f60a1a65d90dc1b609e3c2051dab650 100644 (file)
@@ -36,9 +36,7 @@ extern irr::scene::ISceneManager *g_menucloudsmgr;
 class Clouds : public scene::ISceneNode
 {
 public:
 class Clouds : public scene::ISceneNode
 {
 public:
-       Clouds(
-                       scene::ISceneNode* parent,
-                       scene::ISceneManager* mgr,
+       Clouds(scene::ISceneManager* mgr,
                        s32 id,
                        u32 seed,
                        s16 cloudheight=0
                        s32 id,
                        u32 seed,
                        s16 cloudheight=0
index d7ee8fb826242bca361a39cd2606f2813dd8980a..1077c23825ab34fa5261c21fc13532f47428a02c 100644 (file)
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client/tile.h"
 #include "mesh.h"
 #include <IMeshManipulator.h>
 #include "client/tile.h"
 #include "mesh.h"
 #include <IMeshManipulator.h>
+#include "client/renderingengine.h"
 #include "client.h"
 #include "log.h"
 #include "noise.h"
 #include "client.h"
 #include "log.h"
 #include "noise.h"
@@ -64,8 +65,7 @@ MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector
        collector = output;
 
        nodedef   = data->m_client->ndef();
        collector = output;
 
        nodedef   = data->m_client->ndef();
-       smgr      = data->m_client->getSceneManager();
-       meshmanip = smgr->getMeshManipulator();
+       meshmanip = RenderingEngine::get_scene_manager()->getMeshManipulator();
 
        enable_mesh_cache = g_settings->getBool("enable_mesh_cache") &&
                !data->m_smooth_lighting; // Mesh cache is not supported with smooth lighting
 
        enable_mesh_cache = g_settings->getBool("enable_mesh_cache") &&
                !data->m_smooth_lighting; // Mesh cache is not supported with smooth lighting
index 2c6a4969e3a2c958b4a3e6b0c44c43a44363d1a6..0a0b12a809b1a2aa11edfbd9abd901e2417c76b6 100644 (file)
@@ -39,7 +39,6 @@ public:
        MeshCollector *collector;
 
        INodeDefManager *nodedef;
        MeshCollector *collector;
 
        INodeDefManager *nodedef;
-       scene::ISceneManager *smgr;
        scene::IMeshManipulator *meshmanip;
 
 // options
        scene::IMeshManipulator *meshmanip;
 
 // options
diff --git a/src/drawscene.cpp b/src/drawscene.cpp
deleted file mode 100644 (file)
index 2cf9689..0000000
+++ /dev/null
@@ -1,674 +0,0 @@
-/*
-Minetest
-Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "drawscene.h"
-#include "settings.h"
-#include "clouds.h"
-#include "clientmap.h"
-#include "util/timetaker.h"
-#include "fontengine.h"
-#include "guiscalingfilter.h"
-#include "filesys.h"
-
-typedef enum {
-       LEFT = -1,
-       RIGHT = 1,
-       EYECOUNT = 2
-} paralax_sign;
-
-void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
-               video::IVideoDriver* driver, scene::ISceneManager* smgr,
-               bool draw_wield_tool, Client& client,
-               gui::IGUIEnvironment* guienv )
-{
-
-       /* preserve old setup*/
-       irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
-       irr::core::vector3df oldTarget   = camera.getCameraNode()->getTarget();
-
-       irr::core::matrix4 startMatrix =
-                       camera.getCameraNode()->getAbsoluteTransformation();
-       irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
-                       - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
-                       + camera.getCameraNode()->getAbsolutePosition();
-
-
-       //Left eye...
-       irr::core::vector3df leftEye;
-       irr::core::matrix4 leftMove;
-       leftMove.setTranslation(
-                       irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
-                                       0.0f, 0.0f));
-       leftEye = (startMatrix * leftMove).getTranslation();
-
-       //clear the depth buffer, and color
-       driver->beginScene( true, true, irr::video::SColor(0, 200, 200, 255));
-       driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_RED;
-       driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
-       driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
-                       + irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
-                       + irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
-       camera.getCameraNode()->setPosition(leftEye);
-       camera.getCameraNode()->setTarget(focusPoint);
-       smgr->drawAll();
-       driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-       if (show_hud) {
-               hud.drawSelectionMesh();
-               if (draw_wield_tool)
-                       camera.drawWieldedTool(&leftMove);
-       }
-
-       guienv->drawAll();
-
-       //Right eye...
-       irr::core::vector3df rightEye;
-       irr::core::matrix4 rightMove;
-       rightMove.setTranslation(
-                       irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
-                                       0.0f, 0.0f));
-       rightEye = (startMatrix * rightMove).getTranslation();
-
-       //clear the depth buffer
-       driver->clearZBuffer();
-       driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_GREEN
-                       + irr::video::ECP_BLUE;
-       driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
-       driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
-                       + irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
-                       + irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
-       camera.getCameraNode()->setPosition(rightEye);
-       camera.getCameraNode()->setTarget(focusPoint);
-       smgr->drawAll();
-       driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-       if (show_hud) {
-               hud.drawSelectionMesh();
-               if (draw_wield_tool)
-                       camera.drawWieldedTool(&rightMove);
-       }
-
-       guienv->drawAll();
-
-       driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_ALL;
-       driver->getOverrideMaterial().EnableFlags = 0;
-       driver->getOverrideMaterial().EnablePasses = 0;
-       camera.getCameraNode()->setPosition(oldPosition);
-       camera.getCameraNode()->setTarget(oldTarget);
-}
-
-void init_texture(video::IVideoDriver* driver, const v2u32& screensize,
-               video::ITexture** texture, const char* name)
-{
-       if (*texture != NULL)
-       {
-               driver->removeTexture(*texture);
-       }
-       *texture = driver->addRenderTargetTexture(
-                       core::dimension2d<u32>(screensize.X, screensize.Y), name,
-                       irr::video::ECF_A8R8G8B8);
-}
-
-video::ITexture* draw_image(const v2u32 &screensize,
-               paralax_sign psign, const irr::core::matrix4 &startMatrix,
-               const irr::core::vector3df &focusPoint, bool show_hud,
-               video::IVideoDriver *driver, Camera &camera, scene::ISceneManager *smgr,
-               Hud &hud, bool draw_wield_tool, Client &client,
-               gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
-{
-       static video::ITexture* images[2] = { NULL, NULL };
-       static v2u32 last_screensize = v2u32(0, 0);
-
-       video::ITexture* image = NULL;
-
-       if (screensize != last_screensize) {
-               init_texture(driver, screensize, &images[1], "mt_drawimage_img1");
-               init_texture(driver, screensize, &images[0], "mt_drawimage_img2");
-               last_screensize = screensize;
-       }
-
-       if (psign == RIGHT)
-               image = images[1];
-       else
-               image = images[0];
-
-       driver->setRenderTarget(image, true, true,
-                       irr::video::SColor(255,
-                                       skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
-
-       irr::core::vector3df eye_pos;
-       irr::core::matrix4 movement;
-       movement.setTranslation(
-                       irr::core::vector3df((int) psign *
-                                       g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
-       eye_pos = (startMatrix * movement).getTranslation();
-
-       //clear the depth buffer
-       driver->clearZBuffer();
-       camera.getCameraNode()->setPosition(eye_pos);
-       camera.getCameraNode()->setTarget(focusPoint);
-       smgr->drawAll();
-
-       driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-
-       if (show_hud) {
-               hud.drawSelectionMesh();
-               if (draw_wield_tool)
-                       camera.drawWieldedTool(&movement);
-       }
-
-       guienv->drawAll();
-
-       /* switch back to real renderer */
-       driver->setRenderTarget(0, true, true,
-                       irr::video::SColor(0,
-                                       skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
-
-       return image;
-}
-
-video::ITexture*  draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
-               bool show_hud, Hud& hud, Client& client, bool draw_crosshair,
-               video::SColor skycolor, gui::IGUIEnvironment* guienv, Camera& camera )
-{
-       static video::ITexture* image = NULL;
-       init_texture(driver, screensize, &image, "mt_drawimage_hud");
-       driver->setRenderTarget(image, true, true,
-                       irr::video::SColor(255,0,0,0));
-
-       if (show_hud)
-       {
-               if (draw_crosshair)
-                       hud.drawCrosshair();
-               hud.drawHotbar(client.getPlayerItem());
-               hud.drawLuaElements(camera.getOffset());
-               camera.drawNametags();
-               guienv->drawAll();
-       }
-
-       driver->setRenderTarget(0, true, true,
-                       irr::video::SColor(0,
-                                       skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
-
-       return image;
-}
-
-void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
-               Hud& hud, video::IVideoDriver* driver,
-               scene::ISceneManager* smgr, const v2u32& screensize,
-               bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
-               video::SColor skycolor )
-{
-       /* save current info */
-       irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
-       irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
-       irr::core::matrix4 startMatrix =
-                       camera.getCameraNode()->getAbsoluteTransformation();
-       irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
-                       - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
-                       + camera.getCameraNode()->getAbsolutePosition();
-
-       /* create left view */
-       video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud,
-                       draw_wield_tool, client, guienv, skycolor);
-
-       //Right eye...
-       irr::core::vector3df rightEye;
-       irr::core::matrix4 rightMove;
-       rightMove.setTranslation(
-                       irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
-                                       0.0f, 0.0f));
-       rightEye = (startMatrix * rightMove).getTranslation();
-
-       //clear the depth buffer
-       driver->clearZBuffer();
-       camera.getCameraNode()->setPosition(rightEye);
-       camera.getCameraNode()->setTarget(focusPoint);
-       smgr->drawAll();
-
-       driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-
-       if (show_hud) {
-               hud.drawSelectionMesh();
-               if(draw_wield_tool)
-                       camera.drawWieldedTool(&rightMove);
-       }
-       guienv->drawAll();
-
-       for (unsigned int i = 0; i < screensize.Y; i+=2 ) {
-#if (IRRLICHT_VERSION_MAJOR >= 1) && (IRRLICHT_VERSION_MINOR >= 8)
-               driver->draw2DImage(left_image, irr::core::position2d<s32>(0, i),
-#else
-               driver->draw2DImage(left_image, irr::core::position2d<s32>(0, screensize.Y-i),
-#endif
-                               irr::core::rect<s32>(0, i,screensize.X, i+1), 0,
-                               irr::video::SColor(255, 255, 255, 255),
-                               false);
-       }
-
-       /* cleanup */
-       camera.getCameraNode()->setPosition(oldPosition);
-       camera.getCameraNode()->setTarget(oldTarget);
-}
-
-void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
-               Hud& hud, video::IVideoDriver* driver,
-               scene::ISceneManager* smgr, const v2u32& screensize,
-               bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
-               video::SColor skycolor )
-{
-       /* save current info */
-       irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
-       irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
-       irr::core::matrix4 startMatrix =
-                       camera.getCameraNode()->getAbsoluteTransformation();
-       irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
-                       - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
-                       + camera.getCameraNode()->getAbsolutePosition();
-
-       /* create left view */
-       video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud,
-                       draw_wield_tool, client, guienv, skycolor);
-
-       /* create right view */
-       video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud,
-                       draw_wield_tool, client, guienv, skycolor);
-
-       /* create hud overlay */
-       video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
-                       false, skycolor, guienv, camera );
-       driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
-       //makeColorKeyTexture mirrors texture so we do it twice to get it right again
-       driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
-
-       draw2DImageFilterScaled(driver, left_image,
-                       irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
-
-       draw2DImageFilterScaled(driver, hudtexture,
-                       irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
-
-       draw2DImageFilterScaled(driver, right_image,
-                       irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
-
-       draw2DImageFilterScaled(driver, hudtexture,
-                       irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
-
-       left_image = NULL;
-       right_image = NULL;
-
-       /* cleanup */
-       camera.getCameraNode()->setPosition(oldPosition);
-       camera.getCameraNode()->setTarget(oldTarget);
-}
-
-void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
-               Hud& hud, video::IVideoDriver* driver,
-               scene::ISceneManager* smgr, const v2u32& screensize,
-               bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
-               video::SColor skycolor )
-{
-       /* save current info */
-       irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
-       irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
-       irr::core::matrix4 startMatrix =
-                       camera.getCameraNode()->getAbsoluteTransformation();
-       irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
-                       - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
-                       + camera.getCameraNode()->getAbsolutePosition();
-
-       /* create left view */
-       video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud,
-                       draw_wield_tool, client, guienv, skycolor);
-
-       /* create right view */
-       video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud,
-                       draw_wield_tool, client, guienv, skycolor);
-
-       /* create hud overlay */
-       video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
-                       false, skycolor, guienv, camera );
-       driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
-       //makeColorKeyTexture mirrors texture so we do it twice to get it right again
-       driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
-
-       draw2DImageFilterScaled(driver, left_image,
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
-
-       draw2DImageFilterScaled(driver, hudtexture,
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
-
-       draw2DImageFilterScaled(driver, right_image,
-                       irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
-
-       draw2DImageFilterScaled(driver, hudtexture,
-                       irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
-                       irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
-
-       left_image = NULL;
-       right_image = NULL;
-
-       /* cleanup */
-       camera.getCameraNode()->setPosition(oldPosition);
-       camera.getCameraNode()->setTarget(oldTarget);
-}
-
-void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
-               Hud& hud, video::IVideoDriver* driver,
-               scene::ISceneManager* smgr, const v2u32& screensize,
-               bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
-               video::SColor skycolor)
-{
-#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
-       errorstream << "Pageflip 3D mode is not supported"
-               << " with your Irrlicht version!" << std::endl;
-#else
-       /* preserve old setup*/
-       irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
-       irr::core::vector3df oldTarget   = camera.getCameraNode()->getTarget();
-
-       irr::core::matrix4 startMatrix =
-                       camera.getCameraNode()->getAbsoluteTransformation();
-       irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
-                       - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
-                       + camera.getCameraNode()->getAbsolutePosition();
-
-       //Left eye...
-       driver->setRenderTarget(irr::video::ERT_STEREO_LEFT_BUFFER);
-
-       irr::core::vector3df leftEye;
-       irr::core::matrix4 leftMove;
-       leftMove.setTranslation(
-                       irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
-                                       0.0f, 0.0f));
-       leftEye = (startMatrix * leftMove).getTranslation();
-
-       //clear the depth buffer, and color
-       driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
-       camera.getCameraNode()->setPosition(leftEye);
-       camera.getCameraNode()->setTarget(focusPoint);
-       smgr->drawAll();
-       driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-
-       if (show_hud) {
-               hud.drawSelectionMesh();
-               if (draw_wield_tool)
-                       camera.drawWieldedTool(&leftMove);
-               hud.drawHotbar(client.getPlayerItem());
-               hud.drawLuaElements(camera.getOffset());
-               camera.drawNametags();
-       }
-
-       guienv->drawAll();
-
-       //Right eye...
-       driver->setRenderTarget(irr::video::ERT_STEREO_RIGHT_BUFFER);
-
-       irr::core::vector3df rightEye;
-       irr::core::matrix4 rightMove;
-       rightMove.setTranslation(
-                       irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
-                                       0.0f, 0.0f));
-       rightEye = (startMatrix * rightMove).getTranslation();
-
-       //clear the depth buffer, and color
-       driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
-       camera.getCameraNode()->setPosition(rightEye);
-       camera.getCameraNode()->setTarget(focusPoint);
-       smgr->drawAll();
-       driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-
-       if (show_hud) {
-               hud.drawSelectionMesh();
-               if (draw_wield_tool)
-                       camera.drawWieldedTool(&rightMove);
-               hud.drawHotbar(client.getPlayerItem());
-               hud.drawLuaElements(camera.getOffset());
-               camera.drawNametags();
-       }
-
-       guienv->drawAll();
-
-       camera.getCameraNode()->setPosition(oldPosition);
-       camera.getCameraNode()->setTarget(oldTarget);
-#endif
-}
-
-// returns (size / coef), rounded upwards
-inline int scaledown(int coef, int size)
-{
-       return (size + coef - 1) / coef;
-}
-
-void draw_plain(Camera &camera, bool show_hud,
-               Hud &hud, video::IVideoDriver *driver,
-               scene::ISceneManager *smgr, const v2u32 &screensize,
-               bool draw_wield_tool, Client &client, gui::IGUIEnvironment *guienv,
-               video::SColor skycolor)
-{
-       // Undersampling-specific stuff
-       static video::ITexture *image = NULL;
-       static v2u32 last_pixelated_size = v2u32(0, 0);
-       static thread_local int undersampling = g_settings->getU16("undersampling");
-       v2u32 pixelated_size;
-       v2u32 dest_size;
-       if (undersampling > 0) {
-               pixelated_size = v2u32(scaledown(undersampling, screensize.X),
-                               scaledown(undersampling, screensize.Y));
-               dest_size = v2u32(undersampling * pixelated_size.X, undersampling * pixelated_size.Y);
-               if (pixelated_size != last_pixelated_size) {
-                       init_texture(driver, pixelated_size, &image, "mt_drawimage_img1");
-                       last_pixelated_size = pixelated_size;
-               }
-               driver->setRenderTarget(image, true, true, skycolor);
-       }
-
-       // Render
-       smgr->drawAll();
-       driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-       if (show_hud) {
-               hud.drawSelectionMesh();
-               if (draw_wield_tool) {
-                       camera.drawWieldedTool();
-               }
-       }
-
-       // Upscale lowres render
-       if (undersampling > 0) {
-               driver->setRenderTarget(0, true, true);
-               driver->draw2DImage(image,
-                               irr::core::rect<s32>(0, 0, dest_size.X, dest_size.Y),
-                               irr::core::rect<s32>(0, 0, pixelated_size.X, pixelated_size.Y));
-       }
-}
-
-void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
-               Camera &camera, Client &client, LocalPlayer *player, Hud &hud,
-               Minimap *mapper, gui::IGUIEnvironment *guienv,
-               const v2u32 &screensize, const video::SColor &skycolor,
-               bool show_hud, bool show_minimap)
-{
-       TimeTaker timer("smgr");
-
-       bool draw_wield_tool = (show_hud &&
-                       (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
-                       camera.getCameraMode() < CAMERA_MODE_THIRD );
-
-       bool draw_crosshair = ((player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
-                       (camera.getCameraMode() != CAMERA_MODE_THIRD_FRONT));
-
-#ifdef HAVE_TOUCHSCREENGUI
-       try {
-               draw_crosshair = !g_settings->getBool("touchtarget");
-       }
-       catch(SettingNotFoundException) {}
-#endif
-
-       const std::string &draw_mode = g_settings->get("3d_mode");
-
-       if (draw_mode == "anaglyph")
-       {
-               draw_anaglyph_3d_mode(camera, show_hud, hud, driver,
-                               smgr, draw_wield_tool, client, guienv);
-               draw_crosshair = false;
-       }
-       else if (draw_mode == "interlaced")
-       {
-               draw_interlaced_3d_mode(camera, show_hud, hud, driver,
-                               smgr, screensize, draw_wield_tool, client, guienv, skycolor);
-               draw_crosshair = false;
-       }
-       else if (draw_mode == "sidebyside")
-       {
-               draw_sidebyside_3d_mode(camera, show_hud, hud, driver,
-                               smgr, screensize, draw_wield_tool, client, guienv, skycolor);
-               show_hud = false;
-       }
-       else if (draw_mode == "topbottom")
-       {
-               draw_top_bottom_3d_mode(camera, show_hud, hud, driver,
-                               smgr, screensize, draw_wield_tool, client, guienv, skycolor);
-               show_hud = false;
-       }
-       else if (draw_mode == "pageflip")
-       {
-               draw_pageflip_3d_mode(camera, show_hud, hud, driver,
-                               smgr, screensize, draw_wield_tool, client, guienv, skycolor);
-               draw_crosshair = false;
-               show_hud = false;
-       }
-       else {
-               draw_plain(camera, show_hud, hud, driver,
-                               smgr, screensize, draw_wield_tool, client, guienv, skycolor);
-       }
-
-       /*
-               Post effects
-       */
-       {
-               client.getEnv().getClientMap().renderPostFx(camera.getCameraMode());
-       }
-
-       //TODO how to make those 3d too
-       if (show_hud)
-       {
-               if (draw_crosshair)
-                       hud.drawCrosshair();
-
-               hud.drawHotbar(client.getPlayerItem());
-               hud.drawLuaElements(camera.getOffset());
-               camera.drawNametags();
-
-               if (mapper && show_minimap)
-                       mapper->drawMinimap();
-       }
-
-       guienv->drawAll();
-
-       timer.stop(true);
-}
-
-/*
-       Draws a screen with a single text on it.
-       Text will be removed when the screen is drawn the next time.
-       Additionally, a progressbar can be drawn when percent is set between 0 and 100.
-*/
-void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
-               gui::IGUIEnvironment* guienv, ITextureSource *tsrc,
-               float dtime, int percent, bool clouds)
-{
-       video::IVideoDriver* driver    = device->getVideoDriver();
-       v2u32 screensize               = porting::getWindowSize();
-
-       v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight());
-       v2s32 center(screensize.X / 2, screensize.Y / 2);
-       core::rect<s32> textrect(center - textsize / 2, center + textsize / 2);
-
-       gui::IGUIStaticText *guitext = guienv->addStaticText(
-                       text.c_str(), textrect, false, false);
-       guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
-
-       bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
-       if (cloud_menu_background)
-       {
-               g_menuclouds->step(dtime*3);
-               g_menuclouds->render();
-               driver->beginScene(true, true, video::SColor(255, 140, 186, 250));
-               g_menucloudsmgr->drawAll();
-       }
-       else
-               driver->beginScene(true, true, video::SColor(255, 0, 0, 0));
-
-       // draw progress bar
-       if ((percent >= 0) && (percent <= 100)) {
-               video::ITexture *progress_img = tsrc->getTexture("progress_bar.png");
-               video::ITexture *progress_img_bg = tsrc->getTexture("progress_bar_bg.png");
-
-               if (progress_img && progress_img_bg) {
-#ifndef __ANDROID__
-                       const core::dimension2d<u32> &img_size = progress_img_bg->getSize();
-                       u32 imgW = rangelim(img_size.Width, 200, 600);
-                       u32 imgH = rangelim(img_size.Height, 24, 72);
-#else
-                       const core::dimension2d<u32> img_size(256, 48);
-                       float imgRatio = (float) img_size.Height / img_size.Width;
-                       u32 imgW = screensize.X / 2.2f;
-                       u32 imgH = floor(imgW * imgRatio);
-#endif
-                       v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2);
-
-                       draw2DImageFilterScaled(
-                               driver, progress_img_bg,
-                               core::rect<s32>(img_pos.X,
-                                               img_pos.Y,
-                                               img_pos.X + imgW,
-                                               img_pos.Y + imgH),
-                               core::rect<s32>(0, 0,
-                                               img_size.Width,
-                                               img_size.Height),
-                               0, 0, true);
-
-                       draw2DImageFilterScaled(
-                               driver, progress_img,
-                               core::rect<s32>(img_pos.X,
-                                               img_pos.Y,
-                                               img_pos.X + (percent * imgW) / 100,
-                                               img_pos.Y + imgH),
-                               core::rect<s32>(0, 0,
-                                               (percent * img_size.Width) / 100,
-                                               img_size.Height),
-                               0, 0, true);
-               }
-       }
-
-       guienv->drawAll();
-       driver->endScene();
-       guitext->remove();
-
-       //return guitext;
-}
diff --git a/src/drawscene.h b/src/drawscene.h
deleted file mode 100644 (file)
index 99ff1a6..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-Minetest
-Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#ifndef DRAWSCENE_H_
-#define DRAWSCENE_H_
-
-#include "camera.h"
-#include "hud.h"
-#include "minimap.h"
-#include "irrlichttypes_extrabloated.h"
-
-
-void draw_load_screen(const std::wstring &text, IrrlichtDevice *device,
-               gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime = 0,
-               int percent = 0, bool clouds = true);
-
-void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
-               Camera &camera, Client &client, LocalPlayer *player,
-               Hud &hud, Minimap *mapper, gui::IGUIEnvironment *guienv,
-               const v2u32 &screensize, const video::SColor &skycolor,
-               bool show_hud, bool show_minimap);
-
-#endif /* DRAWSCENE_H_ */
index 536828edeed4883aee5b5caa74b5446670945338..a4d96e0787388101684843a8d1554957bd8ad941 100644 (file)
@@ -16,11 +16,11 @@ You should have received a copy of the GNU Lesser General Public License along
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
+
 #include "fontengine.h"
 #include "fontengine.h"
-#include "log.h"
+#include "client/renderingengine.h"
 #include "config.h"
 #include "porting.h"
 #include "config.h"
 #include "porting.h"
-#include "constants.h"
 #include "filesys.h"
 
 #if USE_FREETYPE
 #include "filesys.h"
 
 #if USE_FREETYPE
@@ -314,10 +314,8 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
                if (! is_yes(m_settings->get("freetype"))) {
                        return;
                }
                if (! is_yes(m_settings->get("freetype"))) {
                        return;
                }
-               unsigned int size = floor(
-                               porting::getDisplayDensity() *
-                               m_settings->getFloat("gui_scaling") *
-                               basesize);
+               unsigned int size = floor(RenderingEngine::getDisplayDensity() *
+                               m_settings->getFloat("gui_scaling") * basesize);
                u32 font_shadow       = 0;
                u32 font_shadow_alpha = 0;
 
                u32 font_shadow       = 0;
                u32 font_shadow_alpha = 0;
 
@@ -395,7 +393,7 @@ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
                basesize = DEFAULT_FONT_SIZE;
 
        unsigned int size = floor(
                basesize = DEFAULT_FONT_SIZE;
 
        unsigned int size = floor(
-                       porting::getDisplayDensity() *
+                       RenderingEngine::getDisplayDensity() *
                        m_settings->getFloat("gui_scaling") *
                        basesize);
 
                        m_settings->getFloat("gui_scaling") *
                        basesize);
 
index cd4075978b8f83f84971f411b57ef775b94d0a65..4c903cc700e8ddce326a36108fa4f93c935191f0 100644 (file)
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "game.h"
 
 #include <iomanip>
 #include "game.h"
 
 #include <iomanip>
+#include "client/renderingengine.h"
 #include "camera.h"
 #include "client.h"
 #include "client/inputhandler.h"
 #include "camera.h"
 #include "client.h"
 #include "client/inputhandler.h"
@@ -30,7 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "clouds.h"
 #include "config.h"
 #include "content_cao.h"
 #include "clouds.h"
 #include "config.h"
 #include "content_cao.h"
-#include "drawscene.h"
 #include "event_manager.h"
 #include "fontengine.h"
 #include "itemdef.h"
 #include "event_manager.h"
 #include "fontengine.h"
 #include "itemdef.h"
@@ -44,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "guiVolumeChange.h"
 #include "mainmenumanager.h"
 #include "mapblock.h"
 #include "guiVolumeChange.h"
 #include "mainmenumanager.h"
 #include "mapblock.h"
+#include "minimap.h"
 #include "nodedef.h"         // Needed for determining pointing to nodes
 #include "nodemetadata.h"
 #include "particles.h"
 #include "nodedef.h"         // Needed for determining pointing to nodes
 #include "nodemetadata.h"
 #include "particles.h"
@@ -152,6 +153,9 @@ struct LocalFormspecHandler : public TextDest
 
                        if (fields.find("btn_exit_os") != fields.end()) {
                                g_gamecallback->exitToOS();
 
                        if (fields.find("btn_exit_os") != fields.end()) {
                                g_gamecallback->exitToOS();
+#ifndef __ANDROID__
+                               RenderingEngine::get_raw_device()->closeDevice();
+#endif
                                return;
                        }
 
                                return;
                        }
 
@@ -726,7 +730,6 @@ public:
                        minimap_yaw.getAs3Values(minimap_yaw_array);
 #endif
                        m_minimap_yaw.set(minimap_yaw_array, services);
                        minimap_yaw.getAs3Values(minimap_yaw_array);
 #endif
                        m_minimap_yaw.set(minimap_yaw_array, services);
-
                }
 
                SamplerLayer_t base_tex = 0,
                }
 
                SamplerLayer_t base_tex = 0,
@@ -924,14 +927,13 @@ bool nodePlacementPrediction(Client &client, const ItemDefinition &playeritem_de
 }
 
 static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec,
 }
 
 static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec,
-               Client *client, IrrlichtDevice *device, JoystickController *joystick,
+               Client *client, JoystickController *joystick,
                IFormSource *fs_src, TextDest *txt_dest)
 {
 
        if (*cur_formspec == 0) {
                IFormSource *fs_src, TextDest *txt_dest)
 {
 
        if (*cur_formspec == 0) {
-               *cur_formspec = new GUIFormSpecMenu(device, joystick,
-                       guiroot, -1, &g_menumgr, client, client->getTextureSource(),
-                       fs_src, txt_dest);
+               *cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
+                       client, client->getTextureSource(), fs_src, txt_dest);
                (*cur_formspec)->doPause = false;
 
                /*
                (*cur_formspec)->doPause = false;
 
                /*
@@ -996,9 +998,10 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
                chat_y += 2 * line_height;
 
        // first pass to calculate height of text to be set
                chat_y += 2 * line_height;
 
        // first pass to calculate height of text to be set
+       const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
        s32 width = std::min(g_fontengine->getTextWidth(recent_chat.c_str()) + 10,
        s32 width = std::min(g_fontengine->getTextWidth(recent_chat.c_str()) + 10,
-                            porting::getWindowSize().X - 20);
-       core::rect<s32> rect(10, chat_y, width, chat_y + porting::getWindowSize().Y);
+                       window_size.X - 20);
+       core::rect<s32> rect(10, chat_y, width, chat_y + window_size.Y);
        guitext_chat->setRelativePosition(rect);
 
        //now use real height of text and adjust rect according to this size
        guitext_chat->setRelativePosition(rect);
 
        //now use real height of text and adjust rect according to this size
@@ -1200,7 +1203,6 @@ public:
        bool startup(bool *kill,
                        bool random_input,
                        InputHandler *input,
        bool startup(bool *kill,
                        bool random_input,
                        InputHandler *input,
-                       IrrlichtDevice *device,
                        const std::string &map_dir,
                        const std::string &playername,
                        const std::string &password,
                        const std::string &map_dir,
                        const std::string &playername,
                        const std::string &password,
@@ -1584,7 +1586,6 @@ Game::~Game()
 bool Game::startup(bool *kill,
                bool random_input,
                InputHandler *input,
 bool Game::startup(bool *kill,
                bool random_input,
                InputHandler *input,
-               IrrlichtDevice *device,
                const std::string &map_dir,
                const std::string &playername,
                const std::string &password,
                const std::string &map_dir,
                const std::string &playername,
                const std::string &password,
@@ -1597,7 +1598,7 @@ bool Game::startup(bool *kill,
                bool simple_singleplayer_mode)
 {
        // "cache"
                bool simple_singleplayer_mode)
 {
        // "cache"
-       this->device              = device;
+       this->device              = RenderingEngine::get_raw_device();
        this->kill                = kill;
        this->error_message       = &error_message;
        this->reconnect_requested = reconnect;
        this->kill                = kill;
        this->error_message       = &error_message;
        this->reconnect_requested = reconnect;
@@ -1609,10 +1610,11 @@ bool Game::startup(bool *kill,
        keycache.handler = input;
        keycache.populate();
 
        keycache.handler = input;
        keycache.populate();
 
-       driver              = device->getVideoDriver();
-       smgr                = device->getSceneManager();
+       driver = device->getVideoDriver();
+       smgr = RenderingEngine::get_scene_manager();
 
 
-       smgr->getParameters()->setAttribute(scene::OBJ_LOADER_IGNORE_MATERIAL_FILES, true);
+       RenderingEngine::get_scene_manager()->getParameters()->
+               setAttribute(scene::OBJ_LOADER_IGNORE_MATERIAL_FILES, true);
 
        memset(&runData, 0, sizeof(runData));
        runData.time_from_last_punch = 10.0;
 
        memset(&runData, 0, sizeof(runData));
        runData.time_from_last_punch = 10.0;
@@ -1649,7 +1651,7 @@ void Game::run()
        Profiler::GraphValues dummyvalues;
        g_profiler->graphGet(dummyvalues);
 
        Profiler::GraphValues dummyvalues;
        g_profiler->graphGet(dummyvalues);
 
-       draw_times.last_time = device->getTimer()->getTime();
+       draw_times.last_time = RenderingEngine::get_timer_time();
 
        set_light_table(g_settings->getFloat("display_gamma"));
 
 
        set_light_table(g_settings->getFloat("display_gamma"));
 
@@ -1661,12 +1663,12 @@ void Game::run()
        irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"),
                g_settings->getU16("screen_h"));
 
        irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"),
                g_settings->getU16("screen_h"));
 
-       while (device->run()
+       while (RenderingEngine::run()
                        && !(*kill || g_gamecallback->shutdown_requested
                        || (server && server->getShutdownRequested()))) {
 
                const irr::core::dimension2d<u32> &current_screen_size =
                        && !(*kill || g_gamecallback->shutdown_requested
                        || (server && server->getShutdownRequested()))) {
 
                const irr::core::dimension2d<u32> &current_screen_size =
-                       device->getVideoDriver()->getScreenSize();
+                       RenderingEngine::get_video_driver()->getScreenSize();
                // Verify if window size has changed and save it if it's the case
                // Ensure evaluating settings->getBool after verifying screensize
                // First condition is cheaper
                // Verify if window size has changed and save it if it's the case
                // Ensure evaluating settings->getBool after verifying screensize
                // First condition is cheaper
@@ -1779,11 +1781,11 @@ bool Game::init(
                u16 port,
                const SubgameSpec &gamespec)
 {
                u16 port,
                const SubgameSpec &gamespec)
 {
-       texture_src = createTextureSource(device);
+       texture_src = createTextureSource();
 
        showOverlayMessage("Loading...", 0, 0);
 
 
        showOverlayMessage("Loading...", 0, 0);
 
-       shader_src = createShaderSource(device);
+       shader_src = createShaderSource();
 
        itemdef_manager = createItemDefManager();
        nodedef_manager = createNodeDefManager();
 
        itemdef_manager = createItemDefManager();
        nodedef_manager = createNodeDefManager();
@@ -1908,7 +1910,7 @@ bool Game::createClient(const std::string &playername,
        shader_src->addShaderConstantSetterFactory(scsf);
 
        // Update cached textures, meshes and materials
        shader_src->addShaderConstantSetterFactory(scsf);
 
        // Update cached textures, meshes and materials
-       client->afterContentReceived(device);
+       client->afterContentReceived();
 
        /* Camera
         */
 
        /* Camera
         */
@@ -1920,7 +1922,7 @@ bool Game::createClient(const std::string &playername,
        /* Clouds
         */
        if (m_cache_enable_clouds) {
        /* Clouds
         */
        if (m_cache_enable_clouds) {
-               clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, time(0));
+               clouds = new Clouds(smgr, -1, time(0));
                if (!clouds) {
                        *error_message = "Memory allocation error (clouds)";
                        errorstream << *error_message << std::endl;
                if (!clouds) {
                        *error_message = "Memory allocation error (clouds)";
                        errorstream << *error_message << std::endl;
@@ -1930,7 +1932,7 @@ bool Game::createClient(const std::string &playername,
 
        /* Skybox
         */
 
        /* Skybox
         */
-       sky = new Sky(smgr->getRootSceneNode(), smgr, -1, texture_src);
+       sky = new Sky(-1, texture_src);
        scsf->setSky(sky);
        skybox = NULL;  // This is used/set later on in the main run loop
 
        scsf->setSky(sky);
        skybox = NULL;  // This is used/set later on in the main run loop
 
@@ -2091,8 +2093,7 @@ bool Game::connectToServer(const std::string &playername,
                return false;
        }
 
                return false;
        }
 
-       client = new Client(device,
-                       playername.c_str(), password, *address,
+       client = new Client(playername.c_str(), password, *address,
                        *draw_control, texture_src, shader_src,
                        itemdef_manager, nodedef_manager, sound, eventmgr,
                        connect_address.isIPv6(), &flags);
                        *draw_control, texture_src, shader_src,
                        itemdef_manager, nodedef_manager, sound, eventmgr,
                        connect_address.isIPv6(), &flags);
@@ -2118,11 +2119,11 @@ bool Game::connectToServer(const std::string &playername,
                f32 dtime;
                f32 wait_time = 0; // in seconds
 
                f32 dtime;
                f32 wait_time = 0; // in seconds
 
-               fps_control.last_time = device->getTimer()->getTime();
+               fps_control.last_time = RenderingEngine::get_timer_time();
 
                client->initMods();
 
 
                client->initMods();
 
-               while (device->run()) {
+               while (RenderingEngine::run()) {
 
                        limitFps(&fps_control, &dtime);
 
 
                        limitFps(&fps_control, &dtime);
 
@@ -2199,9 +2200,9 @@ bool Game::getServerContent(bool *aborted)
        FpsControl fps_control = { 0 };
        f32 dtime; // in seconds
 
        FpsControl fps_control = { 0 };
        f32 dtime; // in seconds
 
-       fps_control.last_time = device->getTimer()->getTime();
+       fps_control.last_time = RenderingEngine::get_timer_time();
 
 
-       while (device->run()) {
+       while (RenderingEngine::run()) {
 
                limitFps(&fps_control, &dtime);
 
 
                limitFps(&fps_control, &dtime);
 
@@ -2239,13 +2240,13 @@ bool Game::getServerContent(bool *aborted)
                if (!client->itemdefReceived()) {
                        const wchar_t *text = wgettext("Item definitions...");
                        progress = 25;
                if (!client->itemdefReceived()) {
                        const wchar_t *text = wgettext("Item definitions...");
                        progress = 25;
-                       draw_load_screen(text, device, guienv, texture_src,
+                       RenderingEngine::draw_load_screen(text, guienv, texture_src,
                                dtime, progress);
                        delete[] text;
                } else if (!client->nodedefReceived()) {
                        const wchar_t *text = wgettext("Node definitions...");
                        progress = 30;
                                dtime, progress);
                        delete[] text;
                } else if (!client->nodedefReceived()) {
                        const wchar_t *text = wgettext("Node definitions...");
                        progress = 30;
-                       draw_load_screen(text, device, guienv, texture_src,
+                       RenderingEngine::draw_load_screen(text, guienv, texture_src,
                                dtime, progress);
                        delete[] text;
                } else {
                                dtime, progress);
                        delete[] text;
                } else {
@@ -2269,8 +2270,8 @@ bool Game::getServerContent(bool *aborted)
                        }
 
                        progress = 30 + client->mediaReceiveProgress() * 35 + 0.5;
                        }
 
                        progress = 30 + client->mediaReceiveProgress() * 35 + 0.5;
-                       draw_load_screen(utf8_to_wide(message.str()), device,
-                                       guienv, texture_src, dtime, progress);
+                       RenderingEngine::draw_load_screen(utf8_to_wide(message.str()), guienv,
+                               texture_src, dtime, progress);
                }
        }
 
                }
        }
 
@@ -2676,7 +2677,7 @@ void Game::openInventory()
        PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(client);
        TextDest *txt_dst = new TextDestPlayerInventory(client);
 
        PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(client);
        TextDest *txt_dst = new TextDestPlayerInventory(client);
 
-       create_formspec_menu(&current_formspec, client, device, &input->joystick, fs_src, txt_dst);
+       create_formspec_menu(&current_formspec, client, &input->joystick, fs_src, txt_dst);
        cur_formname = "";
 
        InventoryLocation inventoryloc;
        cur_formname = "";
 
        InventoryLocation inventoryloc;
@@ -3178,7 +3179,7 @@ void Game::processClientEvents(CameraOrientation *cam)
                                TextDestPlayerInventory *txt_dst =
                                        new TextDestPlayerInventory(client, *(event.show_formspec.formname));
 
                                TextDestPlayerInventory *txt_dst =
                                        new TextDestPlayerInventory(client, *(event.show_formspec.formname));
 
-                               create_formspec_menu(&current_formspec, client, device, &input->joystick,
+                               create_formspec_menu(&current_formspec, client, &input->joystick,
                                        fs_src, txt_dst);
                                cur_formname = *(event.show_formspec.formname);
                        }
                                        fs_src, txt_dst);
                                cur_formname = *(event.show_formspec.formname);
                        }
@@ -3191,7 +3192,7 @@ void Game::processClientEvents(CameraOrientation *cam)
                        {
                                FormspecFormSource *fs_src = new FormspecFormSource(*event.show_formspec.formspec);
                                LocalFormspecHandler *txt_dst = new LocalFormspecHandler(*event.show_formspec.formname, client);
                        {
                                FormspecFormSource *fs_src = new FormspecFormSource(*event.show_formspec.formspec);
                                LocalFormspecHandler *txt_dst = new LocalFormspecHandler(*event.show_formspec.formname, client);
-                               create_formspec_menu(&current_formspec, client, device, &input->joystick,
+                               create_formspec_menu(&current_formspec, client, &input->joystick,
                                        fs_src, txt_dst);
                        }
                        delete event.show_formspec.formspec;
                                        fs_src, txt_dst);
                        }
                        delete event.show_formspec.formspec;
@@ -3201,8 +3202,7 @@ void Game::processClientEvents(CameraOrientation *cam)
                case CE_SPAWN_PARTICLE:
                case CE_ADD_PARTICLESPAWNER:
                case CE_DELETE_PARTICLESPAWNER:
                case CE_SPAWN_PARTICLE:
                case CE_ADD_PARTICLESPAWNER:
                case CE_DELETE_PARTICLESPAWNER:
-                       client->getParticleManager()->handleParticleEvent(&event, client,
-                                       smgr, player);
+                       client->getParticleManager()->handleParticleEvent(&event, client, player);
                        break;
 
                case CE_HUDADD:
                        break;
 
                case CE_HUDADD:
@@ -3343,7 +3343,7 @@ void Game::processClientEvents(CameraOrientation *cam)
                        } else if (*event.set_sky.type == "skybox" &&
                                        event.set_sky.params->size() == 6) {
                                sky->setFallbackBgColor(*event.set_sky.bgcolor);
                        } else if (*event.set_sky.type == "skybox" &&
                                        event.set_sky.params->size() == 6) {
                                sky->setFallbackBgColor(*event.set_sky.bgcolor);
-                               skybox = smgr->addSkyBoxSceneNode(
+                               skybox = RenderingEngine::get_scene_manager()->addSkyBoxSceneNode(
                                                 texture_src->getTextureForMesh((*event.set_sky.params)[0]),
                                                 texture_src->getTextureForMesh((*event.set_sky.params)[1]),
                                                 texture_src->getTextureForMesh((*event.set_sky.params)[2]),
                                                 texture_src->getTextureForMesh((*event.set_sky.params)[0]),
                                                 texture_src->getTextureForMesh((*event.set_sky.params)[1]),
                                                 texture_src->getTextureForMesh((*event.set_sky.params)[2]),
@@ -3810,7 +3810,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
                        TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
 
                        create_formspec_menu(&current_formspec, client,
                        TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
 
                        create_formspec_menu(&current_formspec, client,
-                                       device, &input->joystick, fs_src, txt_dst);
+                               &input->joystick, fs_src, txt_dst);
                        cur_formname = "";
 
                        current_formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
                        cur_formname = "";
 
                        current_formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
@@ -3940,9 +3940,8 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                runData.dig_time_complete = params.time;
 
                if (m_cache_enable_particles) {
                runData.dig_time_complete = params.time;
 
                if (m_cache_enable_particles) {
-                       const ContentFeatures &features =
-                                       client->getNodeDefManager()->get(n);
-                       client->getParticleManager()->addPunchingParticles(client, smgr,
+                       const ContentFeatures &features = client->getNodeDefManager()->get(n);
+                       client->getParticleManager()->addPunchingParticles(client,
                                        player, nodepos, n, features);
                }
        }
                                        player, nodepos, n, features);
                }
        }
@@ -4019,7 +4018,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
                if (m_cache_enable_particles) {
                        const ContentFeatures &features =
                                client->getNodeDefManager()->get(wasnode);
                if (m_cache_enable_particles) {
                        const ContentFeatures &features =
                                client->getNodeDefManager()->get(wasnode);
-                       client->getParticleManager()->addDiggingParticles(client, smgr,
+                       client->getParticleManager()->addDiggingParticles(client,
                                player, nodepos, wasnode, features);
                }
 
                                player, nodepos, wasnode, features);
                }
 
@@ -4227,7 +4226,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
        TimeTaker tt_draw("mainloop: draw");
        driver->beginScene(true, true, skycolor);
 
        TimeTaker tt_draw("mainloop: draw");
        driver->beginScene(true, true, skycolor);
 
-       draw_scene(driver, smgr, *camera, *client, player, *hud, mapper,
+       RenderingEngine::draw_scene(camera, client, player, hud, mapper,
                        guienv, screensize, skycolor, flags.show_hud,
                        flags.show_minimap);
 
                        guienv, screensize, skycolor, flags.show_hud,
                        flags.show_minimap);
 
@@ -4466,11 +4465,10 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
        fps_timings->last_time = time;
 }
 
        fps_timings->last_time = time;
 }
 
-void Game::showOverlayMessage(const char *msg, float dtime,
-               int percent, bool draw_clouds)
+void Game::showOverlayMessage(const char *msg, float dtime, int percent, bool draw_clouds)
 {
        const wchar_t *wmsg = wgettext(msg);
 {
        const wchar_t *wmsg = wgettext(msg);
-       draw_load_screen(wmsg, device, guienv, texture_src, dtime, percent,
+       RenderingEngine::draw_load_screen(wmsg, guienv, texture_src, dtime, percent,
                draw_clouds);
        delete[] wmsg;
 }
                draw_clouds);
        delete[] wmsg;
 }
@@ -4519,7 +4517,7 @@ void Game::extendedResourceCleanup()
        // Extended resource accounting
        infostream << "Irrlicht resources after cleanup:" << std::endl;
        infostream << "\tRemaining meshes   : "
        // Extended resource accounting
        infostream << "Irrlicht resources after cleanup:" << std::endl;
        infostream << "\tRemaining meshes   : "
-                  << device->getSceneManager()->getMeshCache()->getMeshCount() << std::endl;
+                  << RenderingEngine::get_mesh_cache()->getMeshCount() << std::endl;
        infostream << "\tRemaining textures : "
                   << driver->getTextureCount() << std::endl;
 
        infostream << "\tRemaining textures : "
                   << driver->getTextureCount() << std::endl;
 
@@ -4656,7 +4654,7 @@ void Game::showPauseMenu()
        FormspecFormSource *fs_src = new FormspecFormSource(os.str());
        LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
 
        FormspecFormSource *fs_src = new FormspecFormSource(os.str());
        LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
 
-       create_formspec_menu(&current_formspec, client, device, &input->joystick, fs_src, txt_dst);
+       create_formspec_menu(&current_formspec, client, &input->joystick, fs_src, txt_dst);
        current_formspec->setFocus("btn_continue");
        current_formspec->doPause = true;
 }
        current_formspec->setFocus("btn_continue");
        current_formspec->doPause = true;
 }
@@ -4670,8 +4668,6 @@ void Game::showPauseMenu()
 void the_game(bool *kill,
                bool random_input,
                InputHandler *input,
 void the_game(bool *kill,
                bool random_input,
                InputHandler *input,
-               IrrlichtDevice *device,
-
                const std::string &map_dir,
                const std::string &playername,
                const std::string &password,
                const std::string &map_dir,
                const std::string &playername,
                const std::string &password,
@@ -4694,7 +4690,7 @@ void the_game(bool *kill,
 
        try {
 
 
        try {
 
-               if (game.startup(kill, random_input, input, device, map_dir,
+               if (game.startup(kill, random_input, input, map_dir,
                                playername, password, &server_address, port, error_message,
                                reconnect_requested, &chat_backend, gamespec,
                                simple_singleplayer_mode)) {
                                playername, password, &server_address, port, error_message,
                                reconnect_requested, &chat_backend, gamespec,
                                simple_singleplayer_mode)) {
index 4fb198be8a8d3bdb33b6bb44fb2b88ce4813562f..de3dd769fc03f871dca85fee2d18fec599fa79a8 100644 (file)
@@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef GAME_HEADER
 #define GAME_HEADER
 
 #ifndef GAME_HEADER
 #define GAME_HEADER
 
-#include "irrlichttypes_extrabloated.h"
+#include "irrlichttypes.h"
 #include <string>
 
 class InputHandler;
 #include <string>
 
 class InputHandler;
@@ -42,7 +42,6 @@ struct GameUIFlags
 void the_game(bool *kill,
                bool random_input,
                InputHandler *input,
 void the_game(bool *kill,
                bool random_input,
                InputHandler *input,
-               IrrlichtDevice *device,
                const std::string &map_dir,
                const std::string &playername,
                const std::string &password,
                const std::string &map_dir,
                const std::string &playername,
                const std::string &password,
index d4b98c1c970af375f9bd8501fbfef1a9f5ecbf10..5f5b4bbff419702866c579b6b823c7fd5ce297a5 100644 (file)
@@ -19,9 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "guiEngine.h"
 
 
 #include "guiEngine.h"
 
-#include <fstream>
 #include <IGUIStaticText.h>
 #include <ICameraSceneNode.h>
 #include <IGUIStaticText.h>
 #include <ICameraSceneNode.h>
+#include "client/renderingengine.h"
 #include "scripting_mainmenu.h"
 #include "util/numeric.h"
 #include "config.h"
 #include "scripting_mainmenu.h"
 #include "util/numeric.h"
 #include "config.h"
@@ -114,17 +114,14 @@ void MenuMusicFetcher::fetchSounds(const std::string &name,
 /******************************************************************************/
 /** GUIEngine                                                                 */
 /******************************************************************************/
 /******************************************************************************/
 /** GUIEngine                                                                 */
 /******************************************************************************/
-GUIEngine::GUIEngine(irr::IrrlichtDevice *dev,
-               JoystickController *joystick,
+GUIEngine::GUIEngine(JoystickController *joystick,
                gui::IGUIElement *parent,
                IMenuManager *menumgr,
                gui::IGUIElement *parent,
                IMenuManager *menumgr,
-               scene::ISceneManager *smgr,
                MainMenuData *data,
                bool &kill) :
                MainMenuData *data,
                bool &kill) :
-       m_device(dev),
        m_parent(parent),
        m_menumanager(menumgr),
        m_parent(parent),
        m_menumanager(menumgr),
-       m_smgr(smgr),
+       m_smgr(RenderingEngine::get_scene_manager()),
        m_data(data),
        m_kill(kill)
 {
        m_data(data),
        m_kill(kill)
 {
@@ -136,7 +133,7 @@ GUIEngine::GUIEngine(irr::IrrlichtDevice *dev,
        m_buttonhandler = new TextDestGuiEngine(this);
 
        //create texture source
        m_buttonhandler = new TextDestGuiEngine(this);
 
        //create texture source
-       m_texture_source = new MenuTextureSource(m_device->getVideoDriver());
+       m_texture_source = new MenuTextureSource(RenderingEngine::get_video_driver());
 
        //create soundmanager
        MenuMusicFetcher soundfetcher;
 
        //create soundmanager
        MenuMusicFetcher soundfetcher;
@@ -154,15 +151,14 @@ GUIEngine::GUIEngine(irr::IrrlichtDevice *dev,
        rect += v2s32(4, 0);
 
        m_irr_toplefttext =
        rect += v2s32(4, 0);
 
        m_irr_toplefttext =
-               addStaticText(m_device->getGUIEnvironment(), m_toplefttext,
+               addStaticText(RenderingEngine::get_gui_env(), m_toplefttext,
                        rect, false, true, 0, -1);
 
        //create formspecsource
        m_formspecgui = new FormspecFormSource("");
 
        /* Create menu */
                        rect, false, true, 0, -1);
 
        //create formspecsource
        m_formspecgui = new FormspecFormSource("");
 
        /* Create menu */
-       m_menu = new GUIFormSpecMenu(m_device,
-                       joystick,
+       m_menu = new GUIFormSpecMenu(joystick,
                        m_parent,
                        -1,
                        m_menumanager,
                        m_parent,
                        -1,
                        m_menumanager,
@@ -229,7 +225,7 @@ void GUIEngine::run()
 {
        // Always create clouds because they may or may not be
        // needed based on the game selected
 {
        // Always create clouds because they may or may not be
        // needed based on the game selected
-       video::IVideoDriver* driver = m_device->getVideoDriver();
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
 
        cloudInit();
 
 
        cloudInit();
 
@@ -238,10 +234,10 @@ void GUIEngine::run()
        irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"),
                g_settings->getU16("screen_h"));
 
        irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"),
                g_settings->getU16("screen_h"));
 
-       while (m_device->run() && (!m_startgame) && (!m_kill)) {
+       while (RenderingEngine::run() && (!m_startgame) && (!m_kill)) {
 
                const irr::core::dimension2d<u32> &current_screen_size =
 
                const irr::core::dimension2d<u32> &current_screen_size =
-                       m_device->getVideoDriver()->getScreenSize();
+                       RenderingEngine::get_video_driver()->getScreenSize();
                // Verify if window size has changed and save it if it's the case
                // Ensure evaluating settings->getBool after verifying screensize
                // First condition is cheaper
                // Verify if window size has changed and save it if it's the case
                // Ensure evaluating settings->getBool after verifying screensize
                // First condition is cheaper
@@ -272,7 +268,7 @@ void GUIEngine::run()
                drawHeader(driver);
                drawFooter(driver);
 
                drawHeader(driver);
                drawFooter(driver);
 
-               m_device->getGUIEnvironment()->drawAll();
+               RenderingEngine::get_gui_env()->drawAll();
 
                driver->endScene();
 
 
                driver->endScene();
 
@@ -292,10 +288,7 @@ void GUIEngine::run()
 /******************************************************************************/
 GUIEngine::~GUIEngine()
 {
 /******************************************************************************/
 GUIEngine::~GUIEngine()
 {
-       video::IVideoDriver* driver = m_device->getVideoDriver();
-       FATAL_ERROR_IF(driver == 0, "Could not get video driver");
-
-       if(m_sound_manager != &dummySoundManager){
+       if (m_sound_manager != &dummySoundManager){
                delete m_sound_manager;
                m_sound_manager = NULL;
        }
                delete m_sound_manager;
                m_sound_manager = NULL;
        }
@@ -308,7 +301,7 @@ GUIEngine::~GUIEngine()
        //clean up texture pointers
        for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
                if (m_textures[i].texture)
        //clean up texture pointers
        for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
                if (m_textures[i].texture)
-                       driver->removeTexture(m_textures[i].texture);
+                       RenderingEngine::get_video_driver()->removeTexture(m_textures[i].texture);
        }
 
        delete m_texture_source;
        }
 
        delete m_texture_source;
@@ -320,21 +313,20 @@ GUIEngine::~GUIEngine()
 /******************************************************************************/
 void GUIEngine::cloudInit()
 {
 /******************************************************************************/
 void GUIEngine::cloudInit()
 {
-       m_cloud.clouds = new Clouds(m_smgr->getRootSceneNode(),
-                       m_smgr, -1, rand(), 100);
+       m_cloud.clouds = new Clouds(m_smgr, -1, rand(), 100);
        m_cloud.clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
 
        m_cloud.camera = m_smgr->addCameraSceneNode(0,
                                v3f(0,0,0), v3f(0, 60, 100));
        m_cloud.camera->setFarValue(10000);
 
        m_cloud.clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
 
        m_cloud.camera = m_smgr->addCameraSceneNode(0,
                                v3f(0,0,0), v3f(0, 60, 100));
        m_cloud.camera->setFarValue(10000);
 
-       m_cloud.lasttime = m_device->getTimer()->getTime();
+       m_cloud.lasttime = RenderingEngine::get_timer_time();
 }
 
 /******************************************************************************/
 void GUIEngine::cloudPreProcess()
 {
 }
 
 /******************************************************************************/
 void GUIEngine::cloudPreProcess()
 {
-       u32 time = m_device->getTimer()->getTime();
+       u32 time = RenderingEngine::get_timer_time();
 
        if(time > m_cloud.lasttime)
                m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0;
 
        if(time > m_cloud.lasttime)
                m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0;
@@ -356,7 +348,7 @@ void GUIEngine::cloudPostProcess()
        u32 busytime_u32;
 
        // not using getRealTime is necessary for wine
        u32 busytime_u32;
 
        // not using getRealTime is necessary for wine
-       u32 time = m_device->getTimer()->getTime();
+       u32 time = RenderingEngine::get_timer_time();
        if(time > m_cloud.lasttime)
                busytime_u32 = time - m_cloud.lasttime;
        else
        if(time > m_cloud.lasttime)
                busytime_u32 = time - m_cloud.lasttime;
        else
@@ -365,9 +357,9 @@ void GUIEngine::cloudPostProcess()
        // FPS limiter
        u32 frametime_min = 1000./fps_max;
 
        // FPS limiter
        u32 frametime_min = 1000./fps_max;
 
-       if(busytime_u32 < frametime_min) {
+       if (busytime_u32 < frametime_min) {
                u32 sleeptime = frametime_min - busytime_u32;
                u32 sleeptime = frametime_min - busytime_u32;
-               m_device->sleep(sleeptime);
+               RenderingEngine::get_raw_device()->sleep(sleeptime);
        }
 }
 
        }
 }
 
@@ -502,17 +494,14 @@ void GUIEngine::drawFooter(video::IVideoDriver *driver)
 bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
                bool tile_image, unsigned int minsize)
 {
 bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
                bool tile_image, unsigned int minsize)
 {
-       video::IVideoDriver* driver = m_device->getVideoDriver();
-       FATAL_ERROR_IF(driver == 0, "Could not get video driver");
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
 
 
-       if (m_textures[layer].texture != NULL)
-       {
+       if (m_textures[layer].texture) {
                driver->removeTexture(m_textures[layer].texture);
                m_textures[layer].texture = NULL;
        }
 
                driver->removeTexture(m_textures[layer].texture);
                m_textures[layer].texture = NULL;
        }
 
-       if ((texturepath == "") || !fs::PathExists(texturepath))
-       {
+       if ((texturepath == "") || !fs::PathExists(texturepath)) {
                return false;
        }
 
                return false;
        }
 
@@ -520,8 +509,7 @@ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
        m_textures[layer].tile    = tile_image;
        m_textures[layer].minsize = minsize;
 
        m_textures[layer].tile    = tile_image;
        m_textures[layer].minsize = minsize;
 
-       if (m_textures[layer].texture == NULL)
-       {
+       if (m_textures[layer].texture == NULL) {
                return false;
        }
 
                return false;
        }
 
@@ -573,7 +561,7 @@ void GUIEngine::updateTopLeftTextSize()
 
        m_irr_toplefttext->remove();
        m_irr_toplefttext =
 
        m_irr_toplefttext->remove();
        m_irr_toplefttext =
-               addStaticText(m_device->getGUIEnvironment(), m_toplefttext,
+               addStaticText(RenderingEngine::get_gui_env(), m_toplefttext,
                        rect, false, true, 0, -1);
 }
 
                        rect, false, true, 0, -1);
 }
 
index cf2bade70143b21ecad5b442fc6c88260ef6632e..9f59051e8bc4f1cbd700ea16d58c9c52653bc6b3 100644 (file)
@@ -150,11 +150,9 @@ public:
         * @param smgr scene manager to add scene elements to
         * @param data struct to transfer data to main game handling
         */
         * @param smgr scene manager to add scene elements to
         * @param data struct to transfer data to main game handling
         */
-       GUIEngine(irr::IrrlichtDevice *dev,
-                       JoystickController *joystick,
+       GUIEngine(JoystickController *joystick,
                        gui::IGUIElement *parent,
                        IMenuManager *menumgr,
                        gui::IGUIElement *parent,
                        IMenuManager *menumgr,
-                       scene::ISceneManager *smgr,
                        MainMenuData *data,
                        bool &kill);
 
                        MainMenuData *data,
                        bool &kill);
 
@@ -192,8 +190,6 @@ private:
        /** update size of topleftext element */
        void updateTopLeftTextSize();
 
        /** update size of topleftext element */
        void updateTopLeftTextSize();
 
-       /** device to draw at */
-       irr::IrrlichtDevice     *m_device = nullptr;
        /** parent gui element */
        gui::IGUIElement        *m_parent = nullptr;
        /** manager to add menus to */
        /** parent gui element */
        gui::IGUIElement        *m_parent = nullptr;
        /** manager to add menus to */
index d721c917a8d9175eb9795a3403461dae8448b5bb..0592f4e1bfde539b416894043d046f6b293e0efc 100644 (file)
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <IGUIFont.h>
 #include <IGUITabControl.h>
 #include <IGUIComboBox.h>
 #include <IGUIFont.h>
 #include <IGUITabControl.h>
 #include <IGUIComboBox.h>
+#include "client/renderingengine.h"
 #include "log.h"
 #include "client/tile.h" // ITextureSource
 #include "hud.h" // drawItemStack
 #include "log.h"
 #include "client/tile.h" // ITextureSource
 #include "hud.h" // drawItemStack
@@ -78,14 +79,11 @@ static unsigned int font_line_height(gui::IGUIFont *font)
        return font->getDimension(L"Ay").Height + font->getKerningHeight();
 }
 
        return font->getDimension(L"Ay").Height + font->getKerningHeight();
 }
 
-GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
-               JoystickController *joystick,
-               gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
-               Client *client,
-               ISimpleTextureSource *tsrc, IFormSource* fsrc, TextDest* tdst,
+GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
+               gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
+               Client *client, ISimpleTextureSource *tsrc, IFormSource *fsrc, TextDest *tdst,
                bool remap_dbl_click) :
                bool remap_dbl_click) :
-       GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr),
-       m_device(dev),
+       GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr),
        m_invmgr(client),
        m_tsrc(tsrc),
        m_client(client),
        m_invmgr(client),
        m_tsrc(tsrc),
        m_client(client),
@@ -2054,7 +2052,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
        if (mydata.explicit_size) {
                // compute scaling for specified form size
                if (m_lock) {
        if (mydata.explicit_size) {
                // compute scaling for specified form size
                if (m_lock) {
-                       v2u32 current_screensize = m_device->getVideoDriver()->getScreenSize();
+                       v2u32 current_screensize = RenderingEngine::get_video_driver()->getScreenSize();
                        v2u32 delta = current_screensize - m_lockscreensize;
 
                        if (current_screensize.Y > m_lockscreensize.Y)
                        v2u32 delta = current_screensize - m_lockscreensize;
 
                        if (current_screensize.Y > m_lockscreensize.Y)
@@ -2075,7 +2073,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                }
 
                double gui_scaling = g_settings->getFloat("gui_scaling");
                }
 
                double gui_scaling = g_settings->getFloat("gui_scaling");
-               double screen_dpi = porting::getDisplayDensity() * 96;
+               double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
 
                double use_imgsize;
                if (m_lock) {
 
                double use_imgsize;
                if (m_lock) {
@@ -2108,7 +2106,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                                ((5.0/4.0) * (0.5 + mydata.invsize.X));
                        double fity_imgsize = mydata.screensize.Y /
                                ((15.0/13.0) * (0.85 * mydata.invsize.Y));
                                ((5.0/4.0) * (0.5 + mydata.invsize.X));
                        double fity_imgsize = mydata.screensize.Y /
                                ((15.0/13.0) * (0.85 * mydata.invsize.Y));
-                       double screen_dpi = porting::getDisplayDensity() * 96;
+                       double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
                        double min_imgsize = 0.3 * screen_dpi * gui_scaling;
                        use_imgsize = MYMAX(min_imgsize, MYMIN(prefer_imgsize,
                                MYMIN(fitx_imgsize, fity_imgsize)));
                        double min_imgsize = 0.3 * screen_dpi * gui_scaling;
                        use_imgsize = MYMAX(min_imgsize, MYMIN(prefer_imgsize,
                                MYMIN(fitx_imgsize, fity_imgsize)));
@@ -2579,7 +2577,7 @@ void GUIFormSpecMenu::drawMenu()
 
 /* TODO find way to show tooltips on touchscreen */
 #ifndef HAVE_TOUCHSCREENGUI
 
 /* TODO find way to show tooltips on touchscreen */
 #ifndef HAVE_TOUCHSCREENGUI
-       m_pointer = m_device->getCursorControl()->getPosition();
+       m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition();
 #endif
 
        /*
 #endif
 
        /*
index 66b9b019a9d234dd624a578f78bd4137100495bc..6d015e5c4530578ba846f807f502be6df709a991 100644 (file)
@@ -287,8 +287,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        };
 
 public:
        };
 
 public:
-       GUIFormSpecMenu(irr::IrrlichtDevice* dev,
-                       JoystickController *joystick,
+       GUIFormSpecMenu(JoystickController *joystick,
                        gui::IGUIElement* parent, s32 id,
                        IMenuManager *menumgr,
                        Client *client,
                        gui::IGUIElement* parent, s32 id,
                        IMenuManager *menumgr,
                        Client *client,
@@ -378,7 +377,6 @@ protected:
        v2s32 pos_offset;
        std::stack<v2s32> container_stack;
 
        v2s32 pos_offset;
        std::stack<v2s32> container_stack;
 
-       irr::IrrlichtDevice* m_device;
        InventoryManager *m_invmgr;
        ISimpleTextureSource *m_tsrc;
        Client *m_client;
        InventoryManager *m_invmgr;
        ISimpleTextureSource *m_tsrc;
        Client *m_client;
@@ -386,7 +384,6 @@ protected:
        std::string m_formspec_string;
        InventoryLocation m_current_inventory_location;
 
        std::string m_formspec_string;
        InventoryLocation m_current_inventory_location;
 
-
        std::vector<ListDrawSpec> m_inventorylists;
        std::vector<ListRingSpec> m_inventory_rings;
        std::vector<ImageDrawSpec> m_backgrounds;
        std::vector<ListDrawSpec> m_inventorylists;
        std::vector<ListRingSpec> m_inventory_rings;
        std::vector<ImageDrawSpec> m_backgrounds;
index 44da4aa7b3844d469739c89b9df1bd9cfdbf50a2..9354eef3d6e6281bd5749c151204ab207374e9f6 100644 (file)
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <IGUISkin.h>
 #include <IGUIFont.h>
 #include <IGUIScrollBar.h>
 #include <IGUISkin.h>
 #include <IGUIFont.h>
 #include <IGUIScrollBar.h>
+#include "client/renderingengine.h"
 #include "debug.h"
 #include "log.h"
 #include "client/tile.h"
 #include "debug.h"
 #include "log.h"
 #include "client/tile.h"
@@ -79,7 +80,8 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
        updateAbsolutePosition();
 
        core::rect<s32> relative_rect = m_scrollbar->getRelativePosition();
        updateAbsolutePosition();
 
        core::rect<s32> relative_rect = m_scrollbar->getRelativePosition();
-       s32 width = (relative_rect.getWidth()/(2.0/3.0)) * porting::getDisplayDensity() *
+       s32 width = (relative_rect.getWidth()/(2.0/3.0)) *
+                       RenderingEngine::getDisplayDensity() *
                        g_settings->getFloat("gui_scaling");
        m_scrollbar->setRelativePosition(core::rect<s32>(
                        relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y,
                        g_settings->getFloat("gui_scaling");
        m_scrollbar->setRelativePosition(core::rect<s32>(
                        relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y,
index 41cc7283659ce2fa74058bb6bdc8c5dc4f80b273..1b0dfac799d16ba967030af231a8e51e434effc4 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "util/numeric.h"
 #include <stdio.h>
 #include "settings.h"
 #include "util/numeric.h"
 #include <stdio.h>
+#include "client/renderingengine.h"
 
 /* Maintain a static cache to store the images that correspond to textures
  * in a format that's manipulable by code.  Some platforms exhibit issues
 
 /* Maintain a static cache to store the images that correspond to textures
  * in a format that's manipulable by code.  Some platforms exhibit issues
@@ -48,18 +49,18 @@ void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *v
 }
 
 // Manually clear the cache, e.g. when switching to different worlds.
 }
 
 // Manually clear the cache, e.g. when switching to different worlds.
-void guiScalingCacheClear(video::IVideoDriver *driver)
+void guiScalingCacheClear()
 {
        for (std::map<io::path, video::IImage *>::iterator it = g_imgCache.begin();
                        it != g_imgCache.end(); ++it) {
 {
        for (std::map<io::path, video::IImage *>::iterator it = g_imgCache.begin();
                        it != g_imgCache.end(); ++it) {
-               if (it->second != NULL)
+               if (it->second)
                        it->second->drop();
        }
        g_imgCache.clear();
        for (std::map<io::path, video::ITexture *>::iterator it = g_txrCache.begin();
                        it != g_txrCache.end(); ++it) {
                        it->second->drop();
        }
        g_imgCache.clear();
        for (std::map<io::path, video::ITexture *>::iterator it = g_txrCache.begin();
                        it != g_txrCache.end(); ++it) {
-               if (it->second != NULL)
-                       driver->removeTexture(it->second);
+               if (it->second)
+                       RenderingEngine::get_video_driver()->removeTexture(it->second);
        }
        g_txrCache.clear();
 }
        }
        g_txrCache.clear();
 }
index 768fe8d52729ae001a0338aaf5f7712aba7327c4..d956e1412ab5fbf3ec7f49675bafca749bb0b67c 100644 (file)
@@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *value);
 
 // Manually clear the cache, e.g. when switching to different worlds.
 void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *value);
 
 // Manually clear the cache, e.g. when switching to different worlds.
-void guiScalingCacheClear(video::IVideoDriver *driver);
+void guiScalingCacheClear();
 
 /* Get a cached, high-quality pre-scaled texture for display purposes.  If the
  * texture is not already cached, attempt to create it.  Returns a pre-scaled texture,
 
 /* Get a cached, high-quality pre-scaled texture for display purposes.  If the
  * texture is not already cached, attempt to create it.  Returns a pre-scaled texture,
index 1b3b2f26420d5e1afea5eb1a5ede3a8aadc43b76..2285fb71ee2b0e9575151da3b524ef7919415fde 100644 (file)
@@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mesh.h"
 #include "wieldmesh.h"
 #include <IGUIStaticText.h>
 #include "mesh.h"
 #include "wieldmesh.h"
 #include <IGUIStaticText.h>
+#include "client/renderingengine.h"
 
 #ifdef HAVE_TOUCHSCREENGUI
 #include "touchscreengui.h"
 
 #ifdef HAVE_TOUCHSCREENGUI
 #include "touchscreengui.h"
@@ -51,7 +52,8 @@ Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
        this->inventory   = inventory;
 
        m_hud_scaling      = g_settings->getFloat("hud_scaling");
        this->inventory   = inventory;
 
        m_hud_scaling      = g_settings->getFloat("hud_scaling");
-       m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
+       m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE *
+               RenderingEngine::getDisplayDensity() + 0.5f);
        m_hotbar_imagesize *= m_hud_scaling;
        m_padding = m_hotbar_imagesize / 12;
 
        m_hotbar_imagesize *= m_hud_scaling;
        m_padding = m_hotbar_imagesize / 12;
 
@@ -213,8 +215,8 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
 
        // Position of upper left corner of bar
        v2s32 pos = screen_offset;
 
        // Position of upper left corner of bar
        v2s32 pos = screen_offset;
-       pos.X *= m_hud_scaling * porting::getDisplayDensity();
-       pos.Y *= m_hud_scaling * porting::getDisplayDensity();
+       pos.X *= m_hud_scaling * RenderingEngine::getDisplayDensity();
+       pos.Y *= m_hud_scaling * RenderingEngine::getDisplayDensity();
        pos += upperleftpos;
 
        // Store hotbar_image in member variable, used by drawItem()
        pos += upperleftpos;
 
        // Store hotbar_image in member variable, used by drawItem()
@@ -384,7 +386,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
        if (size == v2s32()) {
                dstd = srcd;
        } else {
        if (size == v2s32()) {
                dstd = srcd;
        } else {
-               float size_factor = m_hud_scaling * porting::getDisplayDensity();
+               float size_factor = m_hud_scaling * RenderingEngine::getDisplayDensity();
                dstd.Height = size.Y * size_factor;
                dstd.Width  = size.X * size_factor;
                offset.X *= size_factor;
                dstd.Height = size.Y * size_factor;
                dstd.Width  = size.X * size_factor;
                offset.X *= size_factor;
@@ -449,7 +451,8 @@ void Hud::drawHotbar(u16 playeritem) {
        s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
        v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3);
 
        s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
        v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3);
 
-       if ( (float) width / (float) porting::getWindowSize().X <=
+       const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
+       if ( (float) width / (float) window_size.X <=
                        g_settings->getFloat("hud_hotbar_max_width")) {
                if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
                        drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
                        g_settings->getFloat("hud_hotbar_max_width")) {
                if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
                        drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
@@ -607,11 +610,14 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset)
 }
 
 void Hud::resizeHotbar() {
 }
 
 void Hud::resizeHotbar() {
-       if (m_screensize != porting::getWindowSize()) {
-               m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
+       const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
+
+       if (m_screensize != window_size) {
+               m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE *
+                       RenderingEngine::getDisplayDensity() + 0.5);
                m_hotbar_imagesize *= m_hud_scaling;
                m_padding = m_hotbar_imagesize / 12;
                m_hotbar_imagesize *= m_hud_scaling;
                m_padding = m_hotbar_imagesize / 12;
-               m_screensize = porting::getWindowSize();
+               m_screensize = window_size;
                m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2);
        }
 }
                m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2);
        }
 }
index b9bd3762bf37ccf6e64267ce1645730ad517a63e..adc40f4ffa3cd00120e1daeb39ec13c7f81fe504 100644 (file)
@@ -124,17 +124,12 @@ extern bool isMenuActive();
 class MainGameCallback : public IGameCallback
 {
 public:
 class MainGameCallback : public IGameCallback
 {
 public:
-       MainGameCallback(IrrlichtDevice *a_device):
-               device(a_device)
-       {
-       }
+       MainGameCallback() {}
+       virtual ~MainGameCallback() {}
 
        virtual void exitToOS()
        {
                shutdown_requested = true;
 
        virtual void exitToOS()
        {
                shutdown_requested = true;
-#ifndef __ANDROID__
-               device->closeDevice();
-#endif
        }
 
        virtual void disconnect()
        }
 
        virtual void disconnect()
@@ -170,8 +165,6 @@ public:
        bool shutdown_requested = false;
 
        bool keyconfig_changed = false;
        bool shutdown_requested = false;
 
        bool keyconfig_changed = false;
-
-       IrrlichtDevice *device;
 };
 
 extern MainGameCallback *g_gamecallback;
 };
 
 extern MainGameCallback *g_gamecallback;
index 04a22716c43dfe6603cdf574fba6e99ae76e0890..d8a7d4d7dc7322bd7dd87fdcd1e19c323d92b8a4 100644 (file)
@@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "shader.h"
 #include "settings.h"
 #include "util/directiontables.h"
 #include "shader.h"
 #include "settings.h"
 #include "util/directiontables.h"
-#include <IMeshManipulator.h>
+#include "client/renderingengine.h"
 
 /*
        MeshMakeData
 
 /*
        MeshMakeData
@@ -1008,15 +1008,11 @@ static void updateAllFastFaceRows(MeshMakeData *data,
 
 MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
        m_minimap_mapblock(NULL),
 
 MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
        m_minimap_mapblock(NULL),
-       m_client(data->m_client),
-       m_driver(m_client->tsrc()->getDevice()->getVideoDriver()),
-       m_tsrc(m_client->getTextureSource()),
-       m_shdrsrc(m_client->getShaderSource()),
+       m_tsrc(data->m_client->getTextureSource()),
+       m_shdrsrc(data->m_client->getShaderSource()),
        m_animation_force_timer(0), // force initial animation
        m_last_crack(-1),
        m_animation_force_timer(0), // force initial animation
        m_last_crack(-1),
-       m_crack_materials(),
-       m_last_daynight_ratio((u32) -1),
-       m_daynight_diffs()
+       m_last_daynight_ratio((u32) -1)
 {
        for (int m = 0; m < MAX_TILE_LAYERS; m++)
                m_mesh[m] = new scene::SMesh();
 {
        for (int m = 0; m < MAX_TILE_LAYERS; m++)
                m_mesh[m] = new scene::SMesh();
@@ -1219,7 +1215,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
 
                if (m_use_tangent_vertices) {
                        scene::IMeshManipulator* meshmanip =
 
                if (m_use_tangent_vertices) {
                        scene::IMeshManipulator* meshmanip =
-                               m_client->getSceneManager()->getMeshManipulator();
+                               RenderingEngine::get_scene_manager()->getMeshManipulator();
                        meshmanip->recalculateTangents(m_mesh[layer], true, false, false);
                }
 
                        meshmanip->recalculateTangents(m_mesh[layer], true, false, false);
                }
 
@@ -1254,7 +1250,7 @@ MapBlockMesh::~MapBlockMesh()
                if (m_enable_vbo && m_mesh[m])
                        for (u32 i = 0; i < m_mesh[m]->getMeshBufferCount(); i++) {
                                scene::IMeshBuffer *buf = m_mesh[m]->getMeshBuffer(i);
                if (m_enable_vbo && m_mesh[m])
                        for (u32 i = 0; i < m_mesh[m]->getMeshBufferCount(); i++) {
                                scene::IMeshBuffer *buf = m_mesh[m]->getMeshBuffer(i);
-                               m_driver->removeHardwareBuffer(buf);
+                               RenderingEngine::get_video_driver()->removeHardwareBuffer(buf);
                        }
                m_mesh[m]->drop();
                m_mesh[m] = NULL;
                        }
                m_mesh[m]->drop();
                m_mesh[m] = NULL;
index 8aeccff25a25e336bc880ea49e974e7c1a8aa381..e2a66fbb909a9041972c7a6293af82ae9f47719e 100644 (file)
@@ -42,7 +42,6 @@ struct MeshMakeData
        v3s16 m_blockpos = v3s16(-1337,-1337,-1337);
        v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337);
        bool m_smooth_lighting = false;
        v3s16 m_blockpos = v3s16(-1337,-1337,-1337);
        v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337);
        bool m_smooth_lighting = false;
-       bool m_show_hud = false;
 
        Client *m_client;
        bool m_use_shaders;
 
        Client *m_client;
        bool m_use_shaders;
@@ -138,8 +137,6 @@ public:
 private:
        scene::IMesh *m_mesh[MAX_TILE_LAYERS];
        MinimapMapblock *m_minimap_mapblock;
 private:
        scene::IMesh *m_mesh[MAX_TILE_LAYERS];
        MinimapMapblock *m_minimap_mapblock;
-       Client *m_client;
-       video::IVideoDriver *m_driver;
        ITextureSource *m_tsrc;
        IShaderSource *m_shdrsrc;
 
        ITextureSource *m_tsrc;
        IShaderSource *m_shdrsrc;
 
index 9b17cbc6ea8c342b60528bb7922d9f63f6b1ad86..8b240b199302e1b6d0d10b7e811ea17667696b0c 100644 (file)
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/string.h"
 #include "mapblock.h"
 #include <math.h>
 #include "util/string.h"
 #include "mapblock.h"
 #include <math.h>
+#include "client/renderingengine.h"
 
 
 ////
 
 
 ////
@@ -184,10 +185,10 @@ void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height)
 //// Mapper
 ////
 
 //// Mapper
 ////
 
-Minimap::Minimap(IrrlichtDevice *device, Client *client)
+Minimap::Minimap(Client *client)
 {
        this->client    = client;
 {
        this->client    = client;
-       this->driver    = device->getVideoDriver();
+       this->driver    = RenderingEngine::get_video_driver();
        this->m_tsrc    = client->getTextureSource();
        this->m_shdrsrc = client->getShaderSource();
        this->m_ndef    = client->getNodeDefManager();
        this->m_tsrc    = client->getTextureSource();
        this->m_shdrsrc = client->getShaderSource();
        this->m_ndef    = client->getNodeDefManager();
@@ -478,7 +479,7 @@ void Minimap::drawMinimap()
                return;
 
        updateActiveMarkers();
                return;
 
        updateActiveMarkers();
-       v2u32 screensize = porting::getWindowSize();
+       v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
        const u32 size = 0.25 * screensize.Y;
 
        core::rect<s32> oldViewPort = driver->getViewPort();
        const u32 size = 0.25 * screensize.Y;
 
        core::rect<s32> oldViewPort = driver->getViewPort();
index 04ac27a04984c838f7031f15235ec16c5b400337..c465abdc059c60eb6bfd7b9918f10a3e3a1e5cd6 100644 (file)
@@ -116,7 +116,7 @@ private:
 
 class Minimap {
 public:
 
 class Minimap {
 public:
-       Minimap(IrrlichtDevice *device, Client *client);
+       Minimap(Client *client);
        ~Minimap();
 
        void addBlock(v3s16 pos, MinimapMapblock *data);
        ~Minimap();
 
        void addBlock(v3s16 pos, MinimapMapblock *data);
index 1b6c28cf6cdcdda3443f06b1008c195b3e9164bc..110393d630a050fd190b7ac6859cddbe4308214b 100644 (file)
@@ -21,9 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "itemdef.h"
 #ifndef SERVER
 
 #include "itemdef.h"
 #ifndef SERVER
-#include "client/tile.h"
 #include "mesh.h"
 #include "client.h"
 #include "mesh.h"
 #include "client.h"
+#include "client/renderingengine.h"
+#include "client/tile.h"
 #include <IMeshManipulator.h>
 #endif
 #include "log.h"
 #include <IMeshManipulator.h>
 #endif
 #include "log.h"
@@ -1427,8 +1428,8 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef,
        Client *client = (Client *)gamedef;
        ITextureSource *tsrc = client->tsrc();
        IShaderSource *shdsrc = client->getShaderSource();
        Client *client = (Client *)gamedef;
        ITextureSource *tsrc = client->tsrc();
        IShaderSource *shdsrc = client->getShaderSource();
-       scene::ISceneManager* smgr = client->getSceneManager();
-       scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();
+       scene::IMeshManipulator *meshmanip =
+               RenderingEngine::get_scene_manager()->getMeshManipulator();
        TextureSettings tsettings;
        tsettings.readSettings();
 
        TextureSettings tsettings;
        tsettings.readSettings();
 
index a02c32f2175881861dc9596d714b25a2d8546d1d..10b9811bb4aea98ae38f0f00d913327f0dc2e7e6 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client.h"
 #include "collision.h"
 #include <stdlib.h>
 #include "client.h"
 #include "collision.h"
 #include <stdlib.h>
+#include "client/renderingengine.h"
 #include "util/numeric.h"
 #include "light.h"
 #include "environment.h"
 #include "util/numeric.h"
 #include "light.h"
 #include "environment.h"
@@ -42,7 +43,6 @@ v3f random_v3f(v3f min, v3f max)
 
 Particle::Particle(
        IGameDef *gamedef,
 
 Particle::Particle(
        IGameDef *gamedef,
-       scene::ISceneManager* smgr,
        LocalPlayer *player,
        ClientEnvironment *env,
        v3f pos,
        LocalPlayer *player,
        ClientEnvironment *env,
        v3f pos,
@@ -60,7 +60,8 @@ Particle::Particle(
        u8 glow,
        video::SColor color
 ):
        u8 glow,
        video::SColor color
 ):
-       scene::ISceneNode(smgr->getRootSceneNode(), smgr)
+       scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
+               RenderingEngine::get_scene_manager())
 {
        // Misc
        m_gamedef = gamedef;
 {
        // Misc
        m_gamedef = gamedef;
@@ -244,7 +245,7 @@ void Particle::updateVertices()
        ParticleSpawner
 */
 
        ParticleSpawner
 */
 
-ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, LocalPlayer *player,
+ParticleSpawner::ParticleSpawner(IGameDef *gamedef, LocalPlayer *player,
        u16 amount, float time,
        v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
        float minexptime, float maxexptime, float minsize, float maxsize,
        u16 amount, float time,
        v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
        float minexptime, float maxexptime, float minsize, float maxsize,
@@ -255,7 +256,6 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr,
        m_particlemanager(p_manager)
 {
        m_gamedef = gamedef;
        m_particlemanager(p_manager)
 {
        m_gamedef = gamedef;
-       m_smgr = smgr;
        m_player = player;
        m_amount = amount;
        m_spawntime = time;
        m_player = player;
        m_amount = amount;
        m_spawntime = time;
@@ -344,7 +344,6 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
 
                                                Particle* toadd = new Particle(
                                                        m_gamedef,
 
                                                Particle* toadd = new Particle(
                                                        m_gamedef,
-                                                       m_smgr,
                                                        m_player,
                                                        env,
                                                        pos,
                                                        m_player,
                                                        env,
                                                        pos,
@@ -405,7 +404,6 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
 
                                        Particle* toadd = new Particle(
                                                m_gamedef,
 
                                        Particle* toadd = new Particle(
                                                m_gamedef,
-                                               m_smgr,
                                                m_player,
                                                env,
                                                pos,
                                                m_player,
                                                env,
                                                pos,
@@ -507,7 +505,7 @@ void ParticleManager::clearAll ()
 }
 
 void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
 }
 
 void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
-               scene::ISceneManager* smgr, LocalPlayer *player)
+       LocalPlayer *player)
 {
        switch (event->type) {
                case CE_DELETE_PARTICLESPAWNER: {
 {
        switch (event->type) {
                case CE_DELETE_PARTICLESPAWNER: {
@@ -533,7 +531,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
                        video::ITexture *texture =
                                client->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture));
 
                        video::ITexture *texture =
                                client->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture));
 
-                       ParticleSpawner* toadd = new ParticleSpawner(client, smgr, player,
+                       ParticleSpawner *toadd = new ParticleSpawner(client, player,
                                        event->add_particlespawner.amount,
                                        event->add_particlespawner.spawntime,
                                        *event->add_particlespawner.minpos,
                                        event->add_particlespawner.amount,
                                        event->add_particlespawner.spawntime,
                                        *event->add_particlespawner.minpos,
@@ -578,7 +576,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
                        video::ITexture *texture =
                                client->tsrc()->getTextureForMesh(*(event->spawn_particle.texture));
 
                        video::ITexture *texture =
                                client->tsrc()->getTextureForMesh(*(event->spawn_particle.texture));
 
-                       Particle* toadd = new Particle(client, smgr, player, m_env,
+                       Particle *toadd = new Particle(client, player, m_env,
                                        *event->spawn_particle.pos,
                                        *event->spawn_particle.vel,
                                        *event->spawn_particle.acc,
                                        *event->spawn_particle.pos,
                                        *event->spawn_particle.vel,
                                        *event->spawn_particle.acc,
@@ -607,25 +605,22 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
 }
 
 void ParticleManager::addDiggingParticles(IGameDef* gamedef,
 }
 
 void ParticleManager::addDiggingParticles(IGameDef* gamedef,
-       scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
-       const MapNode &n, const ContentFeatures &f)
+       LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
 {
 {
-       for (u16 j = 0; j < 32; j++) // set the amount of particles here
-       {
-               addNodeParticle(gamedef, smgr, player, pos, n, f);
+       // set the amount of particles here
+       for (u16 j = 0; j < 32; j++) {
+               addNodeParticle(gamedef, player, pos, n, f);
        }
 }
 
 void ParticleManager::addPunchingParticles(IGameDef* gamedef,
        }
 }
 
 void ParticleManager::addPunchingParticles(IGameDef* gamedef,
-       scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
-       const MapNode &n, const ContentFeatures &f)
+       LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
 {
 {
-       addNodeParticle(gamedef, smgr, player, pos, n, f);
+       addNodeParticle(gamedef, player, pos, n, f);
 }
 
 void ParticleManager::addNodeParticle(IGameDef* gamedef,
 }
 
 void ParticleManager::addNodeParticle(IGameDef* gamedef,
-       scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
-       const MapNode &n, const ContentFeatures &f)
+       LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
 {
        // Texture
        u8 texid = myrand_range(0, 5);
 {
        // Texture
        u8 texid = myrand_range(0, 5);
@@ -667,7 +662,6 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef,
 
        Particle* toadd = new Particle(
                gamedef,
 
        Particle* toadd = new Particle(
                gamedef,
-               smgr,
                player,
                m_env,
                particlepos,
                player,
                m_env,
                particlepos,
index 9b10afe4b384a03a29abdbafde319c769e146802..13e73e861aaa94ed75dc820d47100cf72bcb57ce 100644 (file)
@@ -38,7 +38,6 @@ class Particle : public scene::ISceneNode
        public:
        Particle(
                IGameDef* gamedef,
        public:
        Particle(
                IGameDef* gamedef,
-               scene::ISceneManager* mgr,
                LocalPlayer *player,
                ClientEnvironment *env,
                v3f pos,
                LocalPlayer *player,
                ClientEnvironment *env,
                v3f pos,
@@ -119,7 +118,6 @@ class ParticleSpawner
 {
        public:
        ParticleSpawner(IGameDef* gamedef,
 {
        public:
        ParticleSpawner(IGameDef* gamedef,
-               scene::ISceneManager *smgr,
                LocalPlayer *player,
                u16 amount,
                float time,
                LocalPlayer *player,
                u16 amount,
                float time,
@@ -148,7 +146,6 @@ class ParticleSpawner
        ParticleManager* m_particlemanager;
        float m_time;
        IGameDef *m_gamedef;
        ParticleManager* m_particlemanager;
        float m_time;
        IGameDef *m_gamedef;
-       scene::ISceneManager *m_smgr;
        LocalPlayer *m_player;
        u16 m_amount;
        float m_spawntime;
        LocalPlayer *m_player;
        u16 m_amount;
        float m_spawntime;
@@ -185,19 +182,16 @@ public:
        void step (float dtime);
 
        void handleParticleEvent(ClientEvent *event, Client *client,
        void step (float dtime);
 
        void handleParticleEvent(ClientEvent *event, Client *client,
-                       scene::ISceneManager* smgr, LocalPlayer *player);
+                       LocalPlayer *player);
 
 
-       void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
-               LocalPlayer *player, v3s16 pos, const MapNode &n,
-               const ContentFeatures &f);
+       void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
+               const MapNode &n, const ContentFeatures &f);
 
 
-       void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
-               LocalPlayer *player, v3s16 pos, const MapNode &n,
-               const ContentFeatures &f);
+       void addPunchingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
+               const MapNode &n, const ContentFeatures &f);
 
 
-       void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
-               LocalPlayer *player, v3s16 pos, const MapNode &n,
-               const ContentFeatures &f);
+       void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
+               const MapNode &n, const ContentFeatures &f);
 
 protected:
        void addParticle(Particle* toadd);
 
 protected:
        void addParticle(Particle* toadd);
index 0cc323934ba18b2f56afdb8ad4e4e47a66f33c1c..51b36459be808752ad5683422b8e5780af688336 100644 (file)
@@ -41,14 +41,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        #define _PSTAT64
        #include <sys/pstat.h>
 #endif
        #define _PSTAT64
        #include <sys/pstat.h>
 #endif
-#if !defined(_WIN32) && !defined(__APPLE__) && \
-       !defined(__ANDROID__) && !defined(SERVER)
-       #define XORG_USED
-#endif
-#ifdef XORG_USED
-       #include <X11/Xlib.h>
-       #include <X11/Xutil.h>
-#endif
 
 #include "config.h"
 #include "debug.h"
 
 #include "config.h"
 #include "debug.h"
@@ -592,304 +584,6 @@ void initializePaths()
 #endif  // USE_GETTEXT
 }
 
 #endif  // USE_GETTEXT
 }
 
-
-
-void setXorgClassHint(const video::SExposedVideoData &video_data,
-       const std::string &name)
-{
-#ifdef XORG_USED
-       if (video_data.OpenGLLinux.X11Display == NULL)
-               return;
-
-       XClassHint *classhint = XAllocClassHint();
-       classhint->res_name  = (char *)name.c_str();
-       classhint->res_class = (char *)name.c_str();
-
-       XSetClassHint((Display *)video_data.OpenGLLinux.X11Display,
-               video_data.OpenGLLinux.X11Window, classhint);
-       XFree(classhint);
-#endif
-}
-
-bool setWindowIcon(IrrlichtDevice *device)
-{
-#if defined(XORG_USED)
-#      if RUN_IN_PLACE
-       return setXorgWindowIconFromPath(device,
-                       path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png");
-#      else
-       // We have semi-support for reading in-place data if we are
-       // compiled with RUN_IN_PLACE. Don't break with this and
-       // also try the path_share location.
-       return
-               setXorgWindowIconFromPath(device,
-                       ICON_DIR "/hicolor/128x128/apps/" PROJECT_NAME ".png") ||
-               setXorgWindowIconFromPath(device,
-                       path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png");
-#      endif
-#elif defined(_WIN32)
-       const video::SExposedVideoData exposedData = device->getVideoDriver()->getExposedVideoData();
-       HWND hWnd; // Window handle
-
-       switch (device->getVideoDriver()->getDriverType()) {
-       case video::EDT_DIRECT3D8:
-               hWnd = reinterpret_cast<HWND>(exposedData.D3D8.HWnd);
-               break;
-       case video::EDT_DIRECT3D9:
-               hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd);
-               break;
-       case video::EDT_OPENGL:
-               hWnd = reinterpret_cast<HWND>(exposedData.OpenGLWin32.HWnd);
-               break;
-       default:
-               return false;
-       }
-
-       // Load the ICON from resource file
-       const HICON hicon = LoadIcon(
-               GetModuleHandle(NULL),
-               MAKEINTRESOURCE(130) // The ID of the ICON defined in winresource.rc
-       );
-
-       if (hicon) {
-               SendMessage(hWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hicon));
-               SendMessage(hWnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(hicon));
-               return true;
-       }
-       return false;
-#else
-       return false;
-#endif
-}
-
-bool setXorgWindowIconFromPath(IrrlichtDevice *device,
-       const std::string &icon_file)
-{
-#ifdef XORG_USED
-
-       video::IVideoDriver *v_driver = device->getVideoDriver();
-
-       video::IImageLoader *image_loader = NULL;
-       u32 cnt = v_driver->getImageLoaderCount();
-       for (u32 i = 0; i < cnt; i++) {
-               if (v_driver->getImageLoader(i)->isALoadableFileExtension(icon_file.c_str())) {
-                       image_loader = v_driver->getImageLoader(i);
-                       break;
-               }
-       }
-
-       if (!image_loader) {
-               warningstream << "Could not find image loader for file '"
-                       << icon_file << "'" << std::endl;
-               return false;
-       }
-
-       io::IReadFile *icon_f = device->getFileSystem()->createAndOpenFile(icon_file.c_str());
-
-       if (!icon_f) {
-               warningstream << "Could not load icon file '"
-                       << icon_file << "'" << std::endl;
-               return false;
-       }
-
-       video::IImage *img = image_loader->loadImage(icon_f);
-
-       if (!img) {
-               warningstream << "Could not load icon file '"
-                       << icon_file << "'" << std::endl;
-               icon_f->drop();
-               return false;
-       }
-
-       u32 height = img->getDimension().Height;
-       u32 width = img->getDimension().Width;
-
-       size_t icon_buffer_len = 2 + height * width;
-       long *icon_buffer = new long[icon_buffer_len];
-
-       icon_buffer[0] = width;
-       icon_buffer[1] = height;
-
-       for (u32 x = 0; x < width; x++) {
-               for (u32 y = 0; y < height; y++) {
-                       video::SColor col = img->getPixel(x, y);
-                       long pixel_val = 0;
-                       pixel_val |= (u8)col.getAlpha() << 24;
-                       pixel_val |= (u8)col.getRed() << 16;
-                       pixel_val |= (u8)col.getGreen() << 8;
-                       pixel_val |= (u8)col.getBlue();
-                       icon_buffer[2 + x + y * width] = pixel_val;
-               }
-       }
-
-       img->drop();
-       icon_f->drop();
-
-       const video::SExposedVideoData &video_data = v_driver->getExposedVideoData();
-
-       Display *x11_dpl = (Display *)video_data.OpenGLLinux.X11Display;
-
-       if (x11_dpl == NULL) {
-               warningstream << "Could not find x11 display for setting its icon."
-                       << std::endl;
-               delete [] icon_buffer;
-               return false;
-       }
-
-       Window x11_win = (Window)video_data.OpenGLLinux.X11Window;
-
-       Atom net_wm_icon = XInternAtom(x11_dpl, "_NET_WM_ICON", False);
-       Atom cardinal = XInternAtom(x11_dpl, "CARDINAL", False);
-       XChangeProperty(x11_dpl, x11_win,
-               net_wm_icon, cardinal, 32,
-               PropModeReplace, (const unsigned char *)icon_buffer,
-               icon_buffer_len);
-
-       delete [] icon_buffer;
-
-#endif
-       return true;
-}
-
-////
-//// Video/Display Information (Client-only)
-////
-
-#ifndef SERVER
-
-static irr::IrrlichtDevice *device;
-
-void initIrrlicht(irr::IrrlichtDevice *device_)
-{
-       device = device_;
-}
-
-v2u32 getWindowSize()
-{
-       return device->getVideoDriver()->getScreenSize();
-}
-
-
-std::vector<core::vector3d<u32> > getSupportedVideoModes()
-{
-       IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
-       sanity_check(nulldevice != NULL);
-
-       std::vector<core::vector3d<u32> > mlist;
-       video::IVideoModeList *modelist = nulldevice->getVideoModeList();
-
-       u32 num_modes = modelist->getVideoModeCount();
-       for (u32 i = 0; i != num_modes; i++) {
-               core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
-               s32 mode_depth = modelist->getVideoModeDepth(i);
-               mlist.push_back(core::vector3d<u32>(mode_res.Width, mode_res.Height, mode_depth));
-       }
-
-       nulldevice->drop();
-
-       return mlist;
-}
-
-std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers()
-{
-       std::vector<irr::video::E_DRIVER_TYPE> drivers;
-
-       for (int i = 0; i != irr::video::EDT_COUNT; i++) {
-               if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE)i))
-                       drivers.push_back((irr::video::E_DRIVER_TYPE)i);
-       }
-
-       return drivers;
-}
-
-const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type)
-{
-       static const char *driver_ids[] = {
-               "null",
-               "software",
-               "burningsvideo",
-               "direct3d8",
-               "direct3d9",
-               "opengl",
-               "ogles1",
-               "ogles2",
-       };
-
-       return driver_ids[type];
-}
-
-
-const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)
-{
-       static const char *driver_names[] = {
-               "NULL Driver",
-               "Software Renderer",
-               "Burning's Video",
-               "Direct3D 8",
-               "Direct3D 9",
-               "OpenGL",
-               "OpenGL ES1",
-               "OpenGL ES2",
-       };
-
-       return driver_names[type];
-}
-
-#      ifndef __ANDROID__
-#              ifdef XORG_USED
-
-static float calcDisplayDensity()
-{
-       const char *current_display = getenv("DISPLAY");
-
-       if (current_display != NULL) {
-               Display *x11display = XOpenDisplay(current_display);
-
-               if (x11display != NULL) {
-                       /* try x direct */
-                       float dpi_height = floor(DisplayHeight(x11display, 0) /
-                                                       (DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
-                       float dpi_width = floor(DisplayWidth(x11display, 0) /
-                                                       (DisplayWidthMM(x11display, 0) * 0.039370) + 0.5);
-
-                       XCloseDisplay(x11display);
-
-                       return std::max(dpi_height,dpi_width) / 96.0;
-               }
-       }
-
-       /* return manually specified dpi */
-       return g_settings->getFloat("screen_dpi")/96.0;
-}
-
-
-float getDisplayDensity()
-{
-       static float cached_display_density = calcDisplayDensity();
-       return cached_display_density;
-}
-
-
-#              else // XORG_USED
-float getDisplayDensity()
-{
-       return g_settings->getFloat("screen_dpi")/96.0;
-}
-#              endif // XORG_USED
-
-v2u32 getDisplaySize()
-{
-       IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
-
-       core::dimension2d<u32> deskres = nulldevice->getVideoModeList()->getDesktopResolution();
-       nulldevice -> drop();
-
-       return deskres;
-}
-#      endif // __ANDROID__
-#endif // SERVER
-
-
 ////
 //// OS-specific Secure Random
 ////
 ////
 //// OS-specific Secure Random
 ////
index 05614543ac383866fe8fbb9515a1e513219fb938..216553141690521e36415f7fca554cfd7bd16c79 100644 (file)
@@ -61,7 +61,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
        // Use standard Posix macro for Linux
        #if (defined(linux) || defined(__linux)) && !defined(__linux__)
 
        // Use standard Posix macro for Linux
        #if (defined(linux) || defined(__linux)) && !defined(__linux__)
-               #define __linux__ 
+               #define __linux__
        #endif
        #if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE)
                #define _GNU_SOURCE
        #endif
        #if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE)
                #define _GNU_SOURCE
@@ -178,8 +178,6 @@ void initializePaths();
 */
 std::string get_sysinfo();
 
 */
 std::string get_sysinfo();
 
-void initIrrlicht(irr::IrrlichtDevice * );
-
 
 // Monotonic counter getters.
 
 
 // Monotonic counter getters.
 
@@ -281,19 +279,6 @@ inline u64 getDeltaMs(u64 old_time_ms, u64 new_time_ms)
        }
 }
 
        }
 }
 
-
-#ifndef SERVER
-float getDisplayDensity();
-
-v2u32 getDisplaySize();
-v2u32 getWindowSize();
-
-std::vector<core::vector3d<u32> > getSupportedVideoModes();
-std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
-const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
-const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
-#endif
-
 inline const char *getPlatformName()
 {
        return
 inline const char *getPlatformName()
 {
        return
@@ -338,18 +323,6 @@ inline const char *getPlatformName()
        ;
 }
 
        ;
 }
 
-void setXorgClassHint(const video::SExposedVideoData &video_data,
-       const std::string &name);
-
-bool setWindowIcon(IrrlichtDevice *device);
-
-bool setXorgWindowIconFromPath(IrrlichtDevice *device,
-       const std::string &icon_file);
-
-// This only needs to be called at the start of execution, since all future
-// threads in the process inherit this exception handler
-void setWin32ExceptionHandler();
-
 bool secure_rand_fill_buf(void *buf, size_t len);
 
 // This attaches to the parents process console, or creates a new one if it doesnt exist.
 bool secure_rand_fill_buf(void *buf, size_t len);
 
 // This attaches to the parents process console, or creates a new one if it doesnt exist.
index 3ed2ba0e0ee181b0a18790b5f19cc69924061539..7c86525f6e88288ce11b75c4f9d802d6180774dd 100644 (file)
@@ -33,10 +33,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "serverlist.h"
 #include "mapgen.h"
 #include "settings.h"
 #include "serverlist.h"
 #include "mapgen.h"
 #include "settings.h"
-#include "EDriverTypes.h"
 
 #include <IFileArchive.h>
 #include <IFileSystem.h>
 
 #include <IFileArchive.h>
 #include <IFileSystem.h>
+#include "client/renderingengine.h"
 
 
 /******************************************************************************/
 
 
 /******************************************************************************/
@@ -628,8 +628,7 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
        GUIEngine* engine = getGuiEngine(L);
        sanity_check(engine != NULL);
 
        GUIEngine* engine = getGuiEngine(L);
        sanity_check(engine != NULL);
 
-       GUIKeyChangeMenu *kmenu
-               = new GUIKeyChangeMenu( engine->m_device->getGUIEnvironment(),
+       GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(),
                                                                engine->m_parent,
                                                                -1,
                                                                engine->m_menumanager);
                                                                engine->m_parent,
                                                                -1,
                                                                engine->m_menumanager);
@@ -832,9 +831,6 @@ int ModApiMainMenu::l_copy_dir(lua_State *L)
 /******************************************************************************/
 int ModApiMainMenu::l_extract_zip(lua_State *L)
 {
 /******************************************************************************/
 int ModApiMainMenu::l_extract_zip(lua_State *L)
 {
-       GUIEngine* engine = getGuiEngine(L);
-       sanity_check(engine);
-
        const char *zipfile     = luaL_checkstring(L, 1);
        const char *destination = luaL_checkstring(L, 2);
 
        const char *zipfile     = luaL_checkstring(L, 1);
        const char *destination = luaL_checkstring(L, 2);
 
@@ -843,7 +839,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
        if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
                fs::CreateAllDirs(absolute_destination);
 
        if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
                fs::CreateAllDirs(absolute_destination);
 
-               io::IFileSystem* fs = engine->m_device->getFileSystem();
+               io::IFileSystem *fs = RenderingEngine::get_filesystem();
 
                if (!fs->addFileArchive(zipfile,true,false,io::EFAT_ZIP)) {
                        lua_pushboolean(L,false);
 
                if (!fs->addFileArchive(zipfile,true,false,io::EFAT_ZIP)) {
                        lua_pushboolean(L,false);
@@ -960,7 +956,7 @@ int ModApiMainMenu::l_show_path_select_dialog(lua_State *L)
        bool is_file_select = lua_toboolean(L, 3);
 
        GUIFileSelectMenu* fileOpenMenu =
        bool is_file_select = lua_toboolean(L, 3);
 
        GUIFileSelectMenu* fileOpenMenu =
-               new GUIFileSelectMenu(engine->m_device->getGUIEnvironment(),
+               new GUIFileSelectMenu(RenderingEngine::get_gui_env(),
                                                                engine->m_parent,
                                                                -1,
                                                                engine->m_menumanager,
                                                                engine->m_parent,
                                                                -1,
                                                                engine->m_menumanager,
@@ -997,13 +993,12 @@ int ModApiMainMenu::l_download_file(lua_State *L)
 /******************************************************************************/
 int ModApiMainMenu::l_get_video_drivers(lua_State *L)
 {
 /******************************************************************************/
 int ModApiMainMenu::l_get_video_drivers(lua_State *L)
 {
-       std::vector<irr::video::E_DRIVER_TYPE> drivers
-               = porting::getSupportedVideoDrivers();
+       std::vector<irr::video::E_DRIVER_TYPE> drivers = RenderingEngine::getSupportedVideoDrivers();
 
        lua_newtable(L);
        for (u32 i = 0; i != drivers.size(); i++) {
 
        lua_newtable(L);
        for (u32 i = 0; i != drivers.size(); i++) {
-               const char *name  = porting::getVideoDriverName(drivers[i]);
-               const char *fname = porting::getVideoDriverFriendlyName(drivers[i]);
+               const char *name  = RenderingEngine::getVideoDriverName(drivers[i]);
+               const char *fname = RenderingEngine::getVideoDriverFriendlyName(drivers[i]);
 
                lua_newtable(L);
                lua_pushstring(L, name);
 
                lua_newtable(L);
                lua_pushstring(L, name);
@@ -1021,7 +1016,7 @@ int ModApiMainMenu::l_get_video_drivers(lua_State *L)
 int ModApiMainMenu::l_get_video_modes(lua_State *L)
 {
        std::vector<core::vector3d<u32> > videomodes
 int ModApiMainMenu::l_get_video_modes(lua_State *L)
 {
        std::vector<core::vector3d<u32> > videomodes
-               = porting::getSupportedVideoModes();
+               = RenderingEngine::getSupportedVideoModes();
 
        lua_newtable(L);
        for (u32 i = 0; i != videomodes.size(); i++) {
 
        lua_newtable(L);
        for (u32 i = 0; i != videomodes.size(); i++) {
@@ -1054,23 +1049,24 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L)
        lua_newtable(L);
        int top = lua_gettop(L);
        lua_pushstring(L,"density");
        lua_newtable(L);
        int top = lua_gettop(L);
        lua_pushstring(L,"density");
-       lua_pushnumber(L,porting::getDisplayDensity());
+       lua_pushnumber(L,RenderingEngine::getDisplayDensity());
        lua_settable(L, top);
 
        lua_pushstring(L,"display_width");
        lua_settable(L, top);
 
        lua_pushstring(L,"display_width");
-       lua_pushnumber(L,porting::getDisplaySize().X);
+       lua_pushnumber(L,RenderingEngine::getDisplaySize().X);
        lua_settable(L, top);
 
        lua_pushstring(L,"display_height");
        lua_settable(L, top);
 
        lua_pushstring(L,"display_height");
-       lua_pushnumber(L,porting::getDisplaySize().Y);
+       lua_pushnumber(L,RenderingEngine::getDisplaySize().Y);
        lua_settable(L, top);
 
        lua_settable(L, top);
 
+       const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
        lua_pushstring(L,"window_width");
        lua_pushstring(L,"window_width");
-       lua_pushnumber(L,porting::getWindowSize().X);
+       lua_pushnumber(L, window_size.X);
        lua_settable(L, top);
 
        lua_pushstring(L,"window_height");
        lua_settable(L, top);
 
        lua_pushstring(L,"window_height");
-       lua_pushnumber(L,porting::getWindowSize().Y);
+       lua_pushnumber(L, window_size.Y);
        lua_settable(L, top);
        return 1;
 }
        lua_settable(L, top);
        return 1;
 }
index 5ff8c910b87bb68bc685cbd93a19cb0c3abdfe3f..6e89d75adca0d18739b4eefdbfe0909d8dc0a260 100644 (file)
@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <IMaterialRenderer.h>
 #include <IMaterialRendererServices.h>
 #include <IShaderConstantSetCallBack.h>
 #include <IMaterialRenderer.h>
 #include <IMaterialRendererServices.h>
 #include <IShaderConstantSetCallBack.h>
+#include "client/renderingengine.h"
 #include "EShaderTypes.h"
 #include "log.h"
 #include "gamedef.h"
 #include "EShaderTypes.h"
 #include "log.h"
 #include "gamedef.h"
@@ -177,7 +178,7 @@ class ShaderCallback : public video::IShaderConstantSetCallBack
        std::vector<IShaderConstantSetter*> m_setters;
 
 public:
        std::vector<IShaderConstantSetter*> m_setters;
 
 public:
-       ShaderCallback(const std::vector<IShaderConstantSetterFactory*> &factories)
+       ShaderCallback(const std::vector<IShaderConstantSetterFactory *> &factories)
        {
                for (u32 i = 0; i < factories.size(); ++i)
                        m_setters.push_back(factories[i]->create());
        {
                for (u32 i = 0; i < factories.size(); ++i)
                        m_setters.push_back(factories[i]->create());
@@ -260,7 +261,7 @@ public:
 class ShaderSource : public IWritableShaderSource
 {
 public:
 class ShaderSource : public IWritableShaderSource
 {
 public:
-       ShaderSource(IrrlichtDevice *device);
+       ShaderSource();
        ~ShaderSource();
 
        /*
        ~ShaderSource();
 
        /*
@@ -309,8 +310,6 @@ private:
 
        // The id of the thread that is allowed to use irrlicht directly
        std::thread::id m_main_thread;
 
        // The id of the thread that is allowed to use irrlicht directly
        std::thread::id m_main_thread;
-       // The irrlicht device
-       IrrlichtDevice *m_device;
 
        // Cache of source shaders
        // This should be only accessed from the main thread
 
        // Cache of source shaders
        // This should be only accessed from the main thread
@@ -332,18 +331,17 @@ private:
        std::vector<ShaderCallback *> m_callbacks;
 };
 
        std::vector<ShaderCallback *> m_callbacks;
 };
 
-IWritableShaderSource* createShaderSource(IrrlichtDevice *device)
+IWritableShaderSource *createShaderSource()
 {
 {
-       return new ShaderSource(device);
+       return new ShaderSource();
 }
 
 /*
        Generate shader given the shader name.
 */
 ShaderInfo generate_shader(const std::string &name,
 }
 
 /*
        Generate shader given the shader name.
 */
 ShaderInfo generate_shader(const std::string &name,
-               u8 material_type, u8 drawtype,
-               IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
-               const std::vector<IShaderConstantSetterFactory*> &setter_factories,
+               u8 material_type, u8 drawtype, std::vector<ShaderCallback *> &callbacks,
+               const std::vector<IShaderConstantSetterFactory *> &setter_factories,
                SourceShaderCache *sourcecache);
 
 /*
                SourceShaderCache *sourcecache);
 
 /*
@@ -354,11 +352,8 @@ void load_shaders(std::string name, SourceShaderCache *sourcecache,
                std::string &vertex_program, std::string &pixel_program,
                std::string &geometry_program, bool &is_highlevel);
 
                std::string &vertex_program, std::string &pixel_program,
                std::string &geometry_program, bool &is_highlevel);
 
-ShaderSource::ShaderSource(IrrlichtDevice *device):
-               m_device(device)
+ShaderSource::ShaderSource()
 {
 {
-       assert(m_device); // Pre-condition
-
        m_main_thread = std::this_thread::get_id();
 
        // Add a dummy ShaderInfo as the first index, named ""
        m_main_thread = std::this_thread::get_id();
 
        // Add a dummy ShaderInfo as the first index, named ""
@@ -453,7 +448,7 @@ u32 ShaderSource::getShaderIdDirect(const std::string &name,
        }
 
        ShaderInfo info = generate_shader(name, material_type, drawtype,
        }
 
        ShaderInfo info = generate_shader(name, material_type, drawtype,
-                       m_device, m_callbacks, m_setter_factories, &m_sourcecache);
+                       m_callbacks, m_setter_factories, &m_sourcecache);
 
        /*
                Add shader to caches (add dummy shaders too)
 
        /*
                Add shader to caches (add dummy shaders too)
@@ -518,7 +513,7 @@ void ShaderSource::rebuildShaders()
                ShaderInfo *info = &m_shaderinfo_cache[i];
                if(info->name != ""){
                        *info = generate_shader(info->name, info->material_type,
                ShaderInfo *info = &m_shaderinfo_cache[i];
                if(info->name != ""){
                        *info = generate_shader(info->name, info->material_type,
-                                       info->drawtype, m_device, m_callbacks,
+                                       info->drawtype, m_callbacks,
                                        m_setter_factories, &m_sourcecache);
                }
        }
                                        m_setter_factories, &m_sourcecache);
                }
        }
@@ -526,8 +521,8 @@ void ShaderSource::rebuildShaders()
 
 
 ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype,
 
 
 ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype,
-               IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
-               const std::vector<IShaderConstantSetterFactory*> &setter_factories,
+               std::vector<ShaderCallback *> &callbacks,
+               const std::vector<IShaderConstantSetterFactory *> &setter_factories,
                SourceShaderCache *sourcecache)
 {
        ShaderInfo shaderinfo;
                SourceShaderCache *sourcecache)
 {
        ShaderInfo shaderinfo;
@@ -535,7 +530,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
        shaderinfo.material_type = material_type;
        shaderinfo.drawtype = drawtype;
        shaderinfo.material = video::EMT_SOLID;
        shaderinfo.material_type = material_type;
        shaderinfo.drawtype = drawtype;
        shaderinfo.material = video::EMT_SOLID;
-       switch(material_type){
+       switch (material_type) {
                case TILE_MATERIAL_BASIC:
                        shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
                        break;
                case TILE_MATERIAL_BASIC:
                        shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
                        break;
@@ -553,15 +548,16 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
                        break;
                case TILE_MATERIAL_WAVING_PLANTS:
                        shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
                        break;
                case TILE_MATERIAL_WAVING_PLANTS:
                        shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
-               break;
+                       break;
+               default:
+                       break;
        }
 
        bool enable_shaders = g_settings->getBool("enable_shaders");
        if (!enable_shaders)
                return shaderinfo;
 
        }
 
        bool enable_shaders = g_settings->getBool("enable_shaders");
        if (!enable_shaders)
                return shaderinfo;
 
-       video::IVideoDriver* driver = device->getVideoDriver();
-       sanity_check(driver);
+       video::IVideoDriver *driver = RenderingEngine::get_video_driver();
 
        video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices();
        if(!gpu){
 
        video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices();
        if(!gpu){
index 979318c95a96990a7215722910da945e408a2813..1db4cba83ea08357933151dcff109c9495b8b70b 100644 (file)
@@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define SHADER_HEADER
 
 #include <IMaterialRendererServices.h>
 #define SHADER_HEADER
 
 #include <IMaterialRendererServices.h>
-#include "irrlichttypes_extrabloated.h"
+#include "irrlichttypes_bloated.h"
 #include <string>
 
 class IGameDef;
 #include <string>
 
 class IGameDef;
@@ -149,7 +149,7 @@ public:
        virtual void addShaderConstantSetterFactory(IShaderConstantSetterFactory *setter) = 0;
 };
 
        virtual void addShaderConstantSetterFactory(IShaderConstantSetterFactory *setter) = 0;
 };
 
-IWritableShaderSource* createShaderSource(IrrlichtDevice *device);
+IWritableShaderSource *createShaderSource();
 
 void dumpShaderProgram(std::ostream &output_stream,
        const std::string &program_type, const std::string &program);
 
 void dumpShaderProgram(std::ostream &output_stream,
        const std::string &program_type, const std::string &program);
index 3176ea936f0d0dfedcf8cd12e58bd977d65d16c9..463400194cc3ee7f60f004ab3ba03693117876a8 100644 (file)
@@ -8,13 +8,14 @@
 #include "profiler.h"
 #include "util/numeric.h"
 #include <cmath>
 #include "profiler.h"
 #include "util/numeric.h"
 #include <cmath>
+#include "client/renderingengine.h"
 #include "settings.h"
 #include "camera.h"  // CameraModes
 
 
 #include "settings.h"
 #include "camera.h"  // CameraModes
 
 
-Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
-               ITextureSource *tsrc):
-               scene::ISceneNode(parent, mgr, id)
+Sky::Sky(s32 id, ITextureSource *tsrc):
+               scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
+                       RenderingEngine::get_scene_manager(), id)
 {
        setAutomaticCulling(scene::EAC_OFF);
        m_box.MaxEdge.set(0, 0, 0);
 {
        setAutomaticCulling(scene::EAC_OFF);
        m_box.MaxEdge.set(0, 0, 0);
index 1fa25bd93d0a2761896fed47e2f00147eb501ecd..64d2877e5785bac28a714bf727491aecff29fa3e 100644 (file)
--- a/src/sky.h
+++ b/src/sky.h
@@ -34,8 +34,7 @@ class Sky : public scene::ISceneNode
 {
 public:
        //! constructor
 {
 public:
        //! constructor
-       Sky(scene::ISceneNode *parent, scene::ISceneManager *mgr, s32 id,
-                       ITextureSource *tsrc);
+       Sky(s32 id, ITextureSource *tsrc);
 
        virtual void OnRegisterSceneNode();
 
 
        virtual void OnRegisterSceneNode();
 
index f276af2828a958ff490b5ee0dfcc5d2bf8e7ef0d..23c036cb5395d37b3ae47a39ea9e59e2d8bbe55e 100644 (file)
@@ -57,8 +57,6 @@ src/daynightratio.h
 src/debug.cpp
 src/debug.h
 src/defaultsettings.cpp
 src/debug.cpp
 src/debug.h
 src/defaultsettings.cpp
-src/drawscene.cpp
-src/drawscene.h
 src/dungeongen.cpp
 src/dungeongen.h
 src/emerge.cpp
 src/dungeongen.cpp
 src/dungeongen.h
 src/emerge.cpp