From b3a36f7378ea0f299cfa36c81de42e00adb7292d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Mon, 26 Jun 2017 20:11:17 +0200 Subject: [PATCH] Isolate irrlicht references and use a singleton (#6041) * 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 --- build/android/jni/Android.mk | 2 +- src/CMakeLists.txt | 1 - src/camera.cpp | 6 +- src/client.cpp | 53 +- src/client.h | 5 +- src/client/CMakeLists.txt | 1 + src/client/clientlauncher.cpp | 194 +---- src/client/clientlauncher.h | 5 +- src/client/inputhandler.h | 17 +- src/client/renderingengine.cpp | 1072 ++++++++++++++++++++++++ src/client/renderingengine.h | 185 ++++ src/client/tile.cpp | 65 +- src/client/tile.h | 6 +- src/clientenvironment.cpp | 6 +- src/clientenvironment.h | 4 +- src/clientmap.cpp | 6 +- src/clientmap.h | 2 - src/clouds.cpp | 21 +- src/clouds.h | 4 +- src/content_mapblock.cpp | 4 +- src/content_mapblock.h | 1 - src/drawscene.cpp | 674 --------------- src/drawscene.h | 39 - src/fontengine.cpp | 12 +- src/game.cpp | 100 ++- src/game.h | 3 +- src/guiEngine.cpp | 58 +- src/guiEngine.h | 6 +- src/guiFormSpecMenu.cpp | 20 +- src/guiFormSpecMenu.h | 5 +- src/guiTable.cpp | 4 +- src/guiscalingfilter.cpp | 9 +- src/guiscalingfilter.h | 2 +- src/hud.cpp | 22 +- src/mainmenumanager.h | 11 +- src/mapblock_mesh.cpp | 16 +- src/mapblock_mesh.h | 3 - src/minimap.cpp | 7 +- src/minimap.h | 2 +- src/nodedef.cpp | 7 +- src/particles.cpp | 34 +- src/particles.h | 20 +- src/porting.cpp | 306 ------- src/porting.h | 29 +- src/script/lua_api/l_mainmenu.cpp | 32 +- src/shader.cpp | 38 +- src/shader.h | 4 +- src/sky.cpp | 7 +- src/sky.h | 3 +- util/travis/clang-format-whitelist.txt | 2 - 50 files changed, 1568 insertions(+), 1567 deletions(-) create mode 100644 src/client/renderingengine.cpp create mode 100644 src/client/renderingengine.h delete mode 100644 src/drawscene.cpp delete mode 100644 src/drawscene.h diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk index 22ef20906..6155b0d9c 100644 --- a/build/android/jni/Android.mk +++ b/build/android/jni/Android.mk @@ -138,7 +138,6 @@ LOCAL_SRC_FILES := \ 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 \ @@ -270,6 +269,7 @@ LOCAL_SRC_FILES := \ 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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e53b0e2c..04f4635d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -500,7 +500,6 @@ set(client_SRCS content_cso.cpp content_mapblock.cpp convert_json.cpp - drawscene.cpp filecache.cpp fontengine.cpp game.cpp diff --git a/src/camera.cpp b/src/camera.cpp index dd4e3963b..83239fe7c 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "clientmap.h" // MapDrawControl #include "player.h" #include +#include "client/renderingengine.h" #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(); } - + 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 - 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))); diff --git a/src/client.cpp b/src/client.cpp index ebe1d9c8f..5681c3ddb 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "threading/mutex_auto_lock.h" +#include "client/renderingengine.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 "drawscene.h" #include "database-sqlite3.h" #include "serialization.h" #include "guiscalingfilter.h" @@ -55,7 +55,6 @@ extern gui::IGUIEnvironment* guienv; */ Client::Client( - IrrlichtDevice *device, 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( - 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), - m_device(device), 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_minimap = new Minimap(device, this); + m_minimap = new Minimap(this); } m_cache_save_interval = g_settings->getU16("server_map_save_interval"); @@ -217,12 +212,11 @@ Client::~Client() } // 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) - m_device->getSceneManager()->getMeshCache()->removeMesh(mesh); + RenderingEngine::get_mesh_cache()->removeMesh(mesh); } 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 \""<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( @@ -1628,7 +1622,6 @@ float Client::mediaReceiveProgress() } typedef struct TextureUpdateArgs { - IrrlichtDevice *device; 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 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); } } -void Client::afterContentReceived(IrrlichtDevice *device) +void Client::afterContentReceived() { infostream<<"Client::afterContentReceived() started"<getVideoDriver()); + guiScalingCacheClear(); // Rebuild inherited images and recreate textures infostream<<"- Rebuilding images and textures"<rebuildImagesAndTextures(); delete[] text; // Rebuild shaders infostream<<"- Rebuilding shaders"<rebuildShaders(); delete[] text; // Update node aliases infostream<<"- Updating node aliases"<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"<getVideoDriver(); + irr::video::IVideoDriver *driver = RenderingEngine::get_video_driver(); irr::video::IImage* const raw_image = driver->createScreenShot(); if (!raw_image) @@ -1857,10 +1849,7 @@ IShaderSource* Client::getShaderSource() { return m_shsrc; } -scene::ISceneManager* Client::getSceneManager() -{ - return m_device->getSceneManager(); -} + 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; - 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 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"); - 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(); - smgr->getMeshCache()->removeMesh(mesh); + RenderingEngine::get_mesh_cache()->removeMesh(mesh); return mesh; } diff --git a/src/client.h b/src/client.h index ab47cfa44..ab9801d62 100644 --- a/src/client.h +++ b/src/client.h @@ -256,7 +256,6 @@ public: */ Client( - IrrlichtDevice *device, const char *playername, const std::string &password, const std::string &address_name, @@ -467,7 +466,7 @@ public: float mediaReceiveProgress(); - void afterContentReceived(IrrlichtDevice *device); + void afterContentReceived(); float getRTT(); float getCurRate(); @@ -486,7 +485,6 @@ public: 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(); @@ -593,7 +591,6 @@ private: 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; diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 2d274ae68..4ba8fea5b 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -1,4 +1,5 @@ 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 diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 9856c1920..4fc8fb3ee 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "mainmenumanager.h" -#include "debug.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 "log.h" #include "serverlist.h" #include "guiEngine.h" -#include "player.h" #include "fontengine.h" -#include "joystick_controller.h" #include "clientlauncher.h" #include "version.h" +#include "renderingengine.h" /* mainmenumanager.h */ @@ -58,9 +55,9 @@ ClientLauncher::~ClientLauncher() 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) - return print_video_modes(); + return RenderingEngine::print_video_modes(); 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; } - 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; } - 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. @@ -101,17 +97,17 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) //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(); - 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)); @@ -130,10 +126,9 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) // Create the menu clouds if (!g_menucloudsmgr) - g_menucloudsmgr = smgr->createNewSceneManager(); + g_menucloudsmgr = RenderingEngine::get_scene_manager()->createNewSceneManager(); 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, @@ -159,25 +154,27 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) 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"); - 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 - 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. */ - guiroot = guienv->addStaticText(L"", core::rect(0, 0, 10000, 10000)); + guiroot = RenderingEngine::get_gui_env()->addStaticText(L"", + core::rect(0, 0, 10000, 10000)); 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 - if (!device->run() || *kill) { + if (!RenderingEngine::get_raw_device()->run() || *kill) { 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; } - device->getVideoDriver()->setTextureCreationFlag( + RenderingEngine::get_video_driver()->setTextureCreationFlag( 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, - device, worldspec.path, current_playername, current_password, @@ -236,7 +232,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) gamespec, simple_singleplayer_mode ); - smgr->clear(); + RenderingEngine::get_scene_manager()->clear(); #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(); - create_engine_device(); - return device != NULL; + new RenderingEngine(receiver); + return RenderingEngine::get_raw_device() != nullptr; } void ClientLauncher::init_input() @@ -317,7 +313,7 @@ void ClientLauncher::init_input() 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 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. - 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++) { @@ -487,14 +483,14 @@ bool ClientLauncher::launch_game(std::string &error_message, 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; - 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)); - guienv->drawAll(); + RenderingEngine::get_gui_env()->drawAll(); 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 - device->getCursorControl()->setVisible(true); + RenderingEngine::get_raw_device()->getCursorControl()->setVisible(true); #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 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(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() @@ -584,8 +521,8 @@ void ClientLauncher::speed_tests() tempv3f1 = v3f(); tempv3f2 = v3f(); - tempstring = std::string(); - tempstring2 = std::string(); + tempstring.clear(); + tempstring2.clear(); { 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; } } - -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(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 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; -} diff --git a/src/client/clientlauncher.h b/src/client/clientlauncher.h index 9e0560b14..8f8a01e2f 100644 --- a/src/client/clientlauncher.h +++ b/src/client/clientlauncher.h @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/inputhandler.h" #include "gameparams.h" +class RenderingEngine; class ClientLauncher { @@ -43,10 +44,8 @@ protected: GameParams &game_params, const Settings &cmd_args); void main_menu(MainMenuData *menudata); - bool create_engine_device(); void speed_tests(); - bool print_video_modes(); bool list_video_modes = false; bool skip_main_menu = false; @@ -55,12 +54,10 @@ protected: 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; - scene::ISceneManager *smgr = nullptr; SubgameSpec gamespec; WorldSpec worldspec; bool simple_singleplayer_mode; diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h index 19733e3ec..822e27863 100644 --- a/src/client/inputhandler.h +++ b/src/client/inputhandler.h @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "joystick_controller.h" #include #include "keycode.h" +#include "renderingengine.h" #ifdef HAVE_TOUCHSCREENGUI #include "touchscreengui.h" @@ -219,8 +220,7 @@ 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; } @@ -239,16 +239,20 @@ public: 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) { - 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); } @@ -276,7 +280,6 @@ public: } private: - IrrlichtDevice *m_device = nullptr; MyEventReceiver *m_receiver = nullptr; v2s32 m_mousepos; }; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp new file mode 100644 index 000000000..ce8f643b9 --- /dev/null +++ b/src/client/renderingengine.cpp @@ -0,0 +1,1072 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola +Copyright (C) 2017 nerzhul, Loic Blot + +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 +#include +#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 +#include +#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 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(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(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 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(exposedData.D3D8.HWnd); + break; + case video::EDT_DIRECT3D9: + hWnd = reinterpret_cast(exposedData.D3D9.HWnd); + break; + case video::EDT_OPENGL: + hWnd = reinterpret_cast(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(hicon)); + SendMessage(hWnd, WM_SETICON, ICON_SMALL, + reinterpret_cast(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 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 &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 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(img_pos.X, img_pos.Y, + img_pos.X + imgW, + img_pos.Y + imgH), + core::rect(0, 0, img_size.Width, + img_size.Height), + 0, 0, true); + + draw2DImageFilterScaled(get_video_driver(), progress_img, + core::rect(img_pos.X, img_pos.Y, + img_pos.X + (percent * imgW) / 100, + img_pos.Y + imgH), + core::rect(0, 0, + (percent * img_size.Width) / 100, + img_size.Height), + 0, 0, true); + } + } + + guienv->drawAll(); + get_video_driver()->endScene(); + guitext->remove(); +} + +std::vector> RenderingEngine::getSupportedVideoModes() +{ + IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL); + sanity_check(nulldevice); + + std::vector> mlist; + video::IVideoModeList *modelist = nulldevice->getVideoModeList(); + + s32 num_modes = modelist->getVideoModeCount(); + for (s32 i = 0; i != num_modes; i++) { + core::dimension2d mode_res = modelist->getVideoModeResolution(i); + u32 mode_depth = (u32)modelist->getVideoModeDepth(i); + mlist.push_back(core::vector3d( + mode_res.Width, mode_res.Height, mode_depth)); + } + + nulldevice->drop(); + return mlist; +} + +std::vector RenderingEngine::getSupportedVideoDrivers() +{ + std::vector 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(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(0, i), +#else + getVideoDriver()->draw2DImage(left_image, + irr::core::position2d(0, screensize.Y - i), +#endif + irr::core::rect(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(0, 0, screensize.X / 2, screensize.Y), + irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, + false); + + draw2DImageFilterScaled(getVideoDriver(), hudtexture, + irr::core::rect(0, 0, screensize.X / 2, screensize.Y), + irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, + true); + + draw2DImageFilterScaled(getVideoDriver(), right_image, + irr::core::rect( + screensize.X / 2, 0, screensize.X, screensize.Y), + irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, + false); + + draw2DImageFilterScaled(getVideoDriver(), hudtexture, + irr::core::rect( + screensize.X / 2, 0, screensize.X, screensize.Y), + irr::core::rect(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(0, 0, screensize.X, screensize.Y / 2), + irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, + false); + + draw2DImageFilterScaled(getVideoDriver(), hudtexture, + irr::core::rect(0, 0, screensize.X, screensize.Y / 2), + irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, + true); + + draw2DImageFilterScaled(getVideoDriver(), right_image, + irr::core::rect( + 0, screensize.Y / 2, screensize.X, screensize.Y), + irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, + false); + + draw2DImageFilterScaled(getVideoDriver(), hudtexture, + irr::core::rect( + 0, screensize.Y / 2, screensize.X, screensize.Y), + irr::core::rect(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(0, 0, dest_size.X, dest_size.Y), + irr::core::rect(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 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 index 000000000..40fbaa87d --- /dev/null +++ b/src/client/renderingengine.h @@ -0,0 +1,185 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola +Copyright (C) 2017 nerzhul, Loic Blot + +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 +#include +#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> getSupportedVideoModes(); + static std::vector 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; +}; diff --git a/src/client/tile.cpp b/src/client/tile.cpp index e47a40ea1..1bcbdc6f9 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -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 "renderingengine.h" #ifdef __ANDROID__ @@ -198,8 +199,7 @@ public: } 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 @@ -217,7 +217,8 @@ public: 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; @@ -238,7 +239,7 @@ public: 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::iterator n; n = m_images.find(name); @@ -246,7 +247,7 @@ public: 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 \"" @@ -274,7 +275,7 @@ private: class TextureSource : public IWritableTextureSource { public: - TextureSource(IrrlichtDevice *device); + TextureSource(); virtual ~TextureSource(); /* @@ -343,12 +344,6 @@ public: 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; @@ -387,8 +382,6 @@ private: // 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 @@ -435,16 +428,13 @@ private: 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 "" @@ -461,7 +451,7 @@ TextureSource::TextureSource(IrrlichtDevice *device): TextureSource::~TextureSource() { - video::IVideoDriver* driver = m_device->getVideoDriver(); + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); unsigned int textures_before = driver->getTextureCount(); @@ -622,7 +612,7 @@ u32 TextureSource::generateTexture(const std::string &name) return 0; } - video::IVideoDriver *driver = m_device->getVideoDriver(); + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); 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); - m_sourcecache.insert(name, img, true, m_device->getVideoDriver()); + m_sourcecache.insert(name, img, true); m_source_image_existence.set(name, true); } @@ -781,7 +771,7 @@ void TextureSource::rebuildImagesAndTextures() { MutexAutoLock lock(m_textureinfo_cache_mutex); - video::IVideoDriver* driver = m_device->getVideoDriver(); + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); sanity_check(driver); // Recreate textures @@ -810,7 +800,7 @@ void TextureSource::rebuildImagesAndTextures() video::ITexture* TextureSource::generateTextureFromMesh( const TextureFromMeshParams ¶ms) { - video::IVideoDriver *driver = m_device->getVideoDriver(); + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); sanity_check(driver); #ifdef __ANDROID__ @@ -935,8 +925,7 @@ video::ITexture* TextureSource::generateTextureFromMesh( } #endif - if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET) == false) - { + if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) { static bool warned = false; if (!warned) { @@ -967,7 +956,7 @@ video::ITexture* TextureSource::generateTextureFromMesh( } // 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); @@ -1065,10 +1054,6 @@ video::IImage* TextureSource::generateImage(const std::string &name) 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 @@ -1196,13 +1181,13 @@ bool TextureSource::generateImagePart(std::string part_of_name, 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] != '[') { - 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 @@ -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 - 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); @@ -1283,7 +1268,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, 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(); @@ -1333,7 +1318,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, 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, @@ -1855,7 +1840,7 @@ bool TextureSource::generateImagePart(std::string part_of_name, u32 height = stoi(sf.next("")); core::dimension2d 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(); @@ -2356,7 +2341,7 @@ video::ITexture* TextureSource::getNormalTexture(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, @@ -2400,7 +2385,7 @@ video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present) 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(1, 1)); sanity_check(flags_image != NULL); diff --git a/src/client/tile.h b/src/client/tile.h index a810aa8e5..b4d615427 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -114,7 +114,6 @@ public: * 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 ¶ms)=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 IrrlichtDevice* getDevice()=0; virtual bool isKnownSourceImage(const std::string &name)=0; virtual video::ITexture* generateTextureFromMesh( const TextureFromMeshParams ¶ms)=0; @@ -146,7 +144,7 @@ public: 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); @@ -302,7 +300,7 @@ struct TileSpec for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) layers[layer] = TileLayer(); } - + /*! * Returns true if this tile can be merged with the other tile. */ diff --git a/src/clientenvironment.cpp b/src/clientenvironment.cpp index e0398a062..28b61b06e 100644 --- a/src/clientenvironment.cpp +++ b/src/clientenvironment.cpp @@ -31,16 +31,16 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "voxelalgorithms.h" #include "settings.h" #include +#include "client/renderingengine.h" /* ClientEnvironment */ -ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr, +ClientEnvironment::ClientEnvironment(ClientMap *map, ITextureSource *texturesource, Client *client): Environment(client), m_map(map), - m_smgr(smgr), m_texturesource(texturesource), m_client(client) { @@ -456,7 +456,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) infostream<<"ClientEnvironment::addActiveObject(): " <<"added (id="<getId()<<")"<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; diff --git a/src/clientenvironment.h b/src/clientenvironment.h index 9d893766b..05ec1908f 100644 --- a/src/clientenvironment.h +++ b/src/clientenvironment.h @@ -67,8 +67,7 @@ typedef std::unordered_map ClientActiveObjectMap; 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(); @@ -175,7 +174,6 @@ public: private: ClientMap *m_map; LocalPlayer *m_local_player = nullptr; - scene::ISceneManager *m_smgr; ITextureSource *m_texturesource; Client *m_client; ClientScripting *m_script = nullptr; diff --git a/src/clientmap.cpp b/src/clientmap.cpp index 73d600a7a..7027d07e4 100644 --- a/src/clientmap.cpp +++ b/src/clientmap.cpp @@ -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 +#include "client/renderingengine.h" ClientMap::ClientMap( Client *client, MapDrawControl &control, - scene::ISceneNode* parent, - scene::ISceneManager* mgr, 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), diff --git a/src/clientmap.h b/src/clientmap.h index 8d2720771..a0f16e46a 100644 --- a/src/clientmap.h +++ b/src/clientmap.h @@ -59,8 +59,6 @@ public: ClientMap( Client *client, MapDrawControl &control, - scene::ISceneNode* parent, - scene::ISceneManager* mgr, s32 id ); diff --git a/src/clouds.cpp b/src/clouds.cpp index dc08d1ac0..dd6a2dcbd 100644 --- a/src/clouds.cpp +++ b/src/clouds.cpp @@ -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. */ +#include "client/renderingengine.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::Clouds( - scene::ISceneNode* parent, - scene::ISceneManager* mgr, +Clouds::Clouds(scene::ISceneManager* mgr, 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); @@ -101,22 +100,22 @@ void Clouds::render() return; ScopeProfiler sp(g_profiler, "Rendering of clouds, avg", SPT_AVG); - + 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); - + /* 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; - + // 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); - + // 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; - + // Restore fog settings driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density, fog_pixelfog, fog_rangefog); diff --git a/src/clouds.h b/src/clouds.h index 869f7f7fc..52ea930f9 100644 --- a/src/clouds.h +++ b/src/clouds.h @@ -36,9 +36,7 @@ extern irr::scene::ISceneManager *g_menucloudsmgr; class Clouds : public scene::ISceneNode { public: - Clouds( - scene::ISceneNode* parent, - scene::ISceneManager* mgr, + Clouds(scene::ISceneManager* mgr, s32 id, u32 seed, s16 cloudheight=0 diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index d7ee8fb82..1077c2382 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/tile.h" #include "mesh.h" #include +#include "client/renderingengine.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(); - 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 diff --git a/src/content_mapblock.h b/src/content_mapblock.h index 2c6a4969e..0a0b12a80 100644 --- a/src/content_mapblock.h +++ b/src/content_mapblock.h @@ -39,7 +39,6 @@ public: MeshCollector *collector; INodeDefManager *nodedef; - scene::ISceneManager *smgr; scene::IMeshManipulator *meshmanip; // options diff --git a/src/drawscene.cpp b/src/drawscene.cpp deleted file mode 100644 index 2cf9689a8..000000000 --- a/src/drawscene.cpp +++ /dev/null @@ -1,674 +0,0 @@ -/* -Minetest -Copyright (C) 2010-2014 celeron55, Perttu Ahola - -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(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(0, i), -#else - driver->draw2DImage(left_image, irr::core::position2d(0, screensize.Y-i), -#endif - irr::core::rect(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(0, 0, screensize.X/2, screensize.Y), - irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, false); - - draw2DImageFilterScaled(driver, hudtexture, - irr::core::rect(0, 0, screensize.X/2, screensize.Y), - irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, true); - - draw2DImageFilterScaled(driver, right_image, - irr::core::rect(screensize.X/2, 0, screensize.X, screensize.Y), - irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, false); - - draw2DImageFilterScaled(driver, hudtexture, - irr::core::rect(screensize.X/2, 0, screensize.X, screensize.Y), - irr::core::rect(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(0, 0, screensize.X, screensize.Y/2), - irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, false); - - draw2DImageFilterScaled(driver, hudtexture, - irr::core::rect(0, 0, screensize.X, screensize.Y/2), - irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, true); - - draw2DImageFilterScaled(driver, right_image, - irr::core::rect(0, screensize.Y/2, screensize.X, screensize.Y), - irr::core::rect(0, 0, screensize.X, screensize.Y), 0, 0, false); - - draw2DImageFilterScaled(driver, hudtexture, - irr::core::rect(0, screensize.Y/2, screensize.X, screensize.Y), - irr::core::rect(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(0, 0, dest_size.X, dest_size.Y), - irr::core::rect(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 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 &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 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(img_pos.X, - img_pos.Y, - img_pos.X + imgW, - img_pos.Y + imgH), - core::rect(0, 0, - img_size.Width, - img_size.Height), - 0, 0, true); - - draw2DImageFilterScaled( - driver, progress_img, - core::rect(img_pos.X, - img_pos.Y, - img_pos.X + (percent * imgW) / 100, - img_pos.Y + imgH), - core::rect(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 index 99ff1a6bc..000000000 --- a/src/drawscene.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -Minetest -Copyright (C) 2010-2014 celeron55, Perttu Ahola - -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_ */ diff --git a/src/fontengine.cpp b/src/fontengine.cpp index 536828ede..a4d96e078 100644 --- a/src/fontengine.cpp +++ b/src/fontengine.cpp @@ -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. */ + #include "fontengine.h" -#include "log.h" +#include "client/renderingengine.h" #include "config.h" #include "porting.h" -#include "constants.h" #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; } - 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; @@ -395,7 +393,7 @@ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode) basesize = DEFAULT_FONT_SIZE; unsigned int size = floor( - porting::getDisplayDensity() * + RenderingEngine::getDisplayDensity() * m_settings->getFloat("gui_scaling") * basesize); diff --git a/src/game.cpp b/src/game.cpp index cd4075978..4c903cc70 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "game.h" #include +#include "client/renderingengine.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 "drawscene.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 "minimap.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(); +#ifndef __ANDROID__ + RenderingEngine::get_raw_device()->closeDevice(); +#endif return; } @@ -726,7 +730,6 @@ public: minimap_yaw.getAs3Values(minimap_yaw_array); #endif m_minimap_yaw.set(minimap_yaw_array, services); - } 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, - Client *client, IrrlichtDevice *device, JoystickController *joystick, + Client *client, JoystickController *joystick, 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; /* @@ -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 + const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); s32 width = std::min(g_fontengine->getTextWidth(recent_chat.c_str()) + 10, - porting::getWindowSize().X - 20); - core::rect rect(10, chat_y, width, chat_y + porting::getWindowSize().Y); + window_size.X - 20); + core::rect 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 @@ -1200,7 +1203,6 @@ public: bool startup(bool *kill, bool random_input, InputHandler *input, - IrrlichtDevice *device, 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, - IrrlichtDevice *device, 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" - this->device = device; + this->device = RenderingEngine::get_raw_device(); 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(); - 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; @@ -1649,7 +1651,7 @@ void Game::run() 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")); @@ -1661,12 +1663,12 @@ void Game::run() irr::core::dimension2d 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 ¤t_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 @@ -1779,11 +1781,11 @@ bool Game::init( u16 port, const SubgameSpec &gamespec) { - texture_src = createTextureSource(device); + texture_src = createTextureSource(); showOverlayMessage("Loading...", 0, 0); - shader_src = createShaderSource(device); + shader_src = createShaderSource(); 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 - client->afterContentReceived(device); + client->afterContentReceived(); /* Camera */ @@ -1920,7 +1922,7 @@ bool Game::createClient(const std::string &playername, /* 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; @@ -1930,7 +1932,7 @@ bool Game::createClient(const std::string &playername, /* 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 @@ -2091,8 +2093,7 @@ bool Game::connectToServer(const std::string &playername, 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); @@ -2118,11 +2119,11 @@ bool Game::connectToServer(const std::string &playername, 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(); - while (device->run()) { + while (RenderingEngine::run()) { limitFps(&fps_control, &dtime); @@ -2199,9 +2200,9 @@ bool Game::getServerContent(bool *aborted) 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); @@ -2239,13 +2240,13 @@ bool Game::getServerContent(bool *aborted) 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; - draw_load_screen(text, device, guienv, texture_src, + RenderingEngine::draw_load_screen(text, guienv, texture_src, dtime, progress); delete[] text; } else { @@ -2269,8 +2270,8 @@ bool Game::getServerContent(bool *aborted) } 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); - create_formspec_menu(¤t_formspec, client, device, &input->joystick, fs_src, txt_dst); + create_formspec_menu(¤t_formspec, client, &input->joystick, fs_src, txt_dst); cur_formname = ""; InventoryLocation inventoryloc; @@ -3178,7 +3179,7 @@ void Game::processClientEvents(CameraOrientation *cam) TextDestPlayerInventory *txt_dst = new TextDestPlayerInventory(client, *(event.show_formspec.formname)); - create_formspec_menu(¤t_formspec, client, device, &input->joystick, + create_formspec_menu(¤t_formspec, client, &input->joystick, 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); - create_formspec_menu(¤t_formspec, client, device, &input->joystick, + create_formspec_menu(¤t_formspec, client, &input->joystick, 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: - client->getParticleManager()->handleParticleEvent(&event, client, - smgr, player); + client->getParticleManager()->handleParticleEvent(&event, client, player); 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); - 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]), @@ -3810,7 +3810,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed, TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client); create_formspec_menu(¤t_formspec, client, - device, &input->joystick, fs_src, txt_dst); + &input->joystick, fs_src, txt_dst); 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) { - 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); } } @@ -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); - client->getParticleManager()->addDiggingParticles(client, smgr, + client->getParticleManager()->addDiggingParticles(client, 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); - 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); @@ -4466,11 +4465,10 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime) 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); - draw_load_screen(wmsg, device, guienv, texture_src, dtime, percent, + RenderingEngine::draw_load_screen(wmsg, guienv, texture_src, dtime, percent, draw_clouds); delete[] wmsg; } @@ -4519,7 +4517,7 @@ void Game::extendedResourceCleanup() // 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; @@ -4656,7 +4654,7 @@ void Game::showPauseMenu() FormspecFormSource *fs_src = new FormspecFormSource(os.str()); LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU"); - create_formspec_menu(¤t_formspec, client, device, &input->joystick, fs_src, txt_dst); + create_formspec_menu(¤t_formspec, client, &input->joystick, fs_src, txt_dst); 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, - IrrlichtDevice *device, - const std::string &map_dir, const std::string &playername, const std::string &password, @@ -4694,7 +4690,7 @@ void the_game(bool *kill, 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)) { diff --git a/src/game.h b/src/game.h index 4fb198be8..de3dd769f 100644 --- a/src/game.h +++ b/src/game.h @@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef GAME_HEADER #define GAME_HEADER -#include "irrlichttypes_extrabloated.h" +#include "irrlichttypes.h" #include class InputHandler; @@ -42,7 +42,6 @@ struct GameUIFlags 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, diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index d4b98c1c9..5f5b4bbff 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -19,9 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiEngine.h" -#include #include #include +#include "client/renderingengine.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(irr::IrrlichtDevice *dev, - JoystickController *joystick, +GUIEngine::GUIEngine(JoystickController *joystick, gui::IGUIElement *parent, IMenuManager *menumgr, - scene::ISceneManager *smgr, MainMenuData *data, bool &kill) : - m_device(dev), m_parent(parent), m_menumanager(menumgr), - m_smgr(smgr), + m_smgr(RenderingEngine::get_scene_manager()), m_data(data), m_kill(kill) { @@ -136,7 +133,7 @@ GUIEngine::GUIEngine(irr::IrrlichtDevice *dev, 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; @@ -154,15 +151,14 @@ GUIEngine::GUIEngine(irr::IrrlichtDevice *dev, 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 */ - m_menu = new GUIFormSpecMenu(m_device, - joystick, + m_menu = new GUIFormSpecMenu(joystick, 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 - video::IVideoDriver* driver = m_device->getVideoDriver(); + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); cloudInit(); @@ -238,10 +234,10 @@ void GUIEngine::run() irr::core::dimension2d 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 ¤t_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 @@ -272,7 +268,7 @@ void GUIEngine::run() drawHeader(driver); drawFooter(driver); - m_device->getGUIEnvironment()->drawAll(); + RenderingEngine::get_gui_env()->drawAll(); driver->endScene(); @@ -292,10 +288,7 @@ void GUIEngine::run() /******************************************************************************/ 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; } @@ -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) - driver->removeTexture(m_textures[i].texture); + RenderingEngine::get_video_driver()->removeTexture(m_textures[i].texture); } delete m_texture_source; @@ -320,21 +313,20 @@ GUIEngine::~GUIEngine() /******************************************************************************/ 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.lasttime = m_device->getTimer()->getTime(); + m_cloud.lasttime = RenderingEngine::get_timer_time(); } /******************************************************************************/ 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; @@ -356,7 +348,7 @@ void GUIEngine::cloudPostProcess() 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 @@ -365,9 +357,9 @@ void GUIEngine::cloudPostProcess() // FPS limiter u32 frametime_min = 1000./fps_max; - if(busytime_u32 < frametime_min) { + if (busytime_u32 < frametime_min) { 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) { - 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; } - if ((texturepath == "") || !fs::PathExists(texturepath)) - { + if ((texturepath == "") || !fs::PathExists(texturepath)) { 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; - if (m_textures[layer].texture == NULL) - { + if (m_textures[layer].texture == NULL) { return false; } @@ -573,7 +561,7 @@ void GUIEngine::updateTopLeftTextSize() 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); } diff --git a/src/guiEngine.h b/src/guiEngine.h index cf2bade70..9f59051e8 100644 --- a/src/guiEngine.h +++ b/src/guiEngine.h @@ -150,11 +150,9 @@ public: * @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, - scene::ISceneManager *smgr, MainMenuData *data, bool &kill); @@ -192,8 +190,6 @@ private: /** 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 */ diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index d721c917a..0592f4e1b 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "client/renderingengine.h" #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(); } -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) : - 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), @@ -2054,7 +2052,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) 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) @@ -2075,7 +2073,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) } 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) { @@ -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)); - 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))); @@ -2579,7 +2577,7 @@ void GUIFormSpecMenu::drawMenu() /* 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 /* diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h index 66b9b019a..6d015e5c4 100644 --- a/src/guiFormSpecMenu.h +++ b/src/guiFormSpecMenu.h @@ -287,8 +287,7 @@ class GUIFormSpecMenu : public GUIModalMenu }; public: - GUIFormSpecMenu(irr::IrrlichtDevice* dev, - JoystickController *joystick, + GUIFormSpecMenu(JoystickController *joystick, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, Client *client, @@ -378,7 +377,6 @@ protected: v2s32 pos_offset; std::stack container_stack; - irr::IrrlichtDevice* m_device; 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::vector m_inventorylists; std::vector m_inventory_rings; std::vector m_backgrounds; diff --git a/src/guiTable.cpp b/src/guiTable.cpp index 44da4aa7b..9354eef3d 100644 --- a/src/guiTable.cpp +++ b/src/guiTable.cpp @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "client/renderingengine.h" #include "debug.h" #include "log.h" #include "client/tile.h" @@ -79,7 +80,8 @@ GUITable::GUITable(gui::IGUIEnvironment *env, updateAbsolutePosition(); core::rect 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( relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y, diff --git a/src/guiscalingfilter.cpp b/src/guiscalingfilter.cpp index 41cc72836..1b0dfac79 100644 --- a/src/guiscalingfilter.cpp +++ b/src/guiscalingfilter.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include "util/numeric.h" #include +#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 @@ -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. -void guiScalingCacheClear(video::IVideoDriver *driver) +void guiScalingCacheClear() { for (std::map::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::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(); } diff --git a/src/guiscalingfilter.h b/src/guiscalingfilter.h index 768fe8d52..d956e1412 100644 --- a/src/guiscalingfilter.h +++ b/src/guiscalingfilter.h @@ -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 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, diff --git a/src/hud.cpp b/src/hud.cpp index 1b3b2f264..2285fb71e 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mesh.h" #include "wieldmesh.h" #include +#include "client/renderingengine.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"); - 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; @@ -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; - 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() @@ -384,7 +386,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, 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; @@ -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); - 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); @@ -607,11 +610,14 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset) } 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_screensize = porting::getWindowSize(); + m_screensize = window_size; m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2); } } diff --git a/src/mainmenumanager.h b/src/mainmenumanager.h index b9bd3762b..adc40f4ff 100644 --- a/src/mainmenumanager.h +++ b/src/mainmenumanager.h @@ -124,17 +124,12 @@ extern bool isMenuActive(); class MainGameCallback : public IGameCallback { public: - MainGameCallback(IrrlichtDevice *a_device): - device(a_device) - { - } + MainGameCallback() {} + virtual ~MainGameCallback() {} virtual void exitToOS() { shutdown_requested = true; -#ifndef __ANDROID__ - device->closeDevice(); -#endif } virtual void disconnect() @@ -170,8 +165,6 @@ public: bool shutdown_requested = false; bool keyconfig_changed = false; - - IrrlichtDevice *device; }; extern MainGameCallback *g_gamecallback; diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index 04a22716c..d8a7d4d7d 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -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 +#include "client/renderingengine.h" /* MeshMakeData @@ -1008,15 +1008,11 @@ static void updateAllFastFaceRows(MeshMakeData *data, 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_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(); @@ -1219,7 +1215,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): 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); } @@ -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); - m_driver->removeHardwareBuffer(buf); + RenderingEngine::get_video_driver()->removeHardwareBuffer(buf); } m_mesh[m]->drop(); m_mesh[m] = NULL; diff --git a/src/mapblock_mesh.h b/src/mapblock_mesh.h index 8aeccff25..e2a66fbb9 100644 --- a/src/mapblock_mesh.h +++ b/src/mapblock_mesh.h @@ -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; - bool m_show_hud = false; Client *m_client; bool m_use_shaders; @@ -138,8 +137,6 @@ public: 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; diff --git a/src/minimap.cpp b/src/minimap.cpp index 9b17cbc6e..8b240b199 100644 --- a/src/minimap.cpp +++ b/src/minimap.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "mapblock.h" #include +#include "client/renderingengine.h" //// @@ -184,10 +185,10 @@ void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height) //// Mapper //// -Minimap::Minimap(IrrlichtDevice *device, Client *client) +Minimap::Minimap(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(); @@ -478,7 +479,7 @@ void Minimap::drawMinimap() return; updateActiveMarkers(); - v2u32 screensize = porting::getWindowSize(); + v2u32 screensize = RenderingEngine::get_instance()->getWindowSize(); const u32 size = 0.25 * screensize.Y; core::rect oldViewPort = driver->getViewPort(); diff --git a/src/minimap.h b/src/minimap.h index 04ac27a04..c465abdc0 100644 --- a/src/minimap.h +++ b/src/minimap.h @@ -116,7 +116,7 @@ private: class Minimap { public: - Minimap(IrrlichtDevice *device, Client *client); + Minimap(Client *client); ~Minimap(); void addBlock(v3s16 pos, MinimapMapblock *data); diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 1b6c28cf6..110393d63 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -21,9 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "itemdef.h" #ifndef SERVER -#include "client/tile.h" #include "mesh.h" #include "client.h" +#include "client/renderingengine.h" +#include "client/tile.h" #include #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(); - scene::ISceneManager* smgr = client->getSceneManager(); - scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator(); + scene::IMeshManipulator *meshmanip = + RenderingEngine::get_scene_manager()->getMeshManipulator(); TextureSettings tsettings; tsettings.readSettings(); diff --git a/src/particles.cpp b/src/particles.cpp index a02c32f21..10b9811bb 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client.h" #include "collision.h" #include +#include "client/renderingengine.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, - scene::ISceneManager* smgr, LocalPlayer *player, ClientEnvironment *env, v3f pos, @@ -60,7 +60,8 @@ Particle::Particle( 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; @@ -244,7 +245,7 @@ void Particle::updateVertices() 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, @@ -255,7 +256,6 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, m_particlemanager(p_manager) { m_gamedef = gamedef; - m_smgr = smgr; 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, - m_smgr, m_player, env, pos, @@ -405,7 +404,6 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) Particle* toadd = new Particle( m_gamedef, - m_smgr, m_player, env, pos, @@ -507,7 +505,7 @@ void ParticleManager::clearAll () } void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, - scene::ISceneManager* smgr, LocalPlayer *player) + LocalPlayer *player) { 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)); - 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, @@ -578,7 +576,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, 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, @@ -607,25 +605,22 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, } 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, - 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, - 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); @@ -667,7 +662,6 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef, Particle* toadd = new Particle( gamedef, - smgr, player, m_env, particlepos, diff --git a/src/particles.h b/src/particles.h index 9b10afe4b..13e73e861 100644 --- a/src/particles.h +++ b/src/particles.h @@ -38,7 +38,6 @@ class Particle : public scene::ISceneNode public: Particle( IGameDef* gamedef, - scene::ISceneManager* mgr, LocalPlayer *player, ClientEnvironment *env, v3f pos, @@ -119,7 +118,6 @@ class ParticleSpawner { public: ParticleSpawner(IGameDef* gamedef, - scene::ISceneManager *smgr, LocalPlayer *player, u16 amount, float time, @@ -148,7 +146,6 @@ class ParticleSpawner ParticleManager* m_particlemanager; float m_time; IGameDef *m_gamedef; - scene::ISceneManager *m_smgr; LocalPlayer *m_player; u16 m_amount; float m_spawntime; @@ -185,19 +182,16 @@ public: 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); diff --git a/src/porting.cpp b/src/porting.cpp index 0cc323934..51b36459b 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -41,14 +41,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #define _PSTAT64 #include #endif -#if !defined(_WIN32) && !defined(__APPLE__) && \ - !defined(__ANDROID__) && !defined(SERVER) - #define XORG_USED -#endif -#ifdef XORG_USED - #include - #include -#endif #include "config.h" #include "debug.h" @@ -592,304 +584,6 @@ void initializePaths() #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(exposedData.D3D8.HWnd); - break; - case video::EDT_DIRECT3D9: - hWnd = reinterpret_cast(exposedData.D3D9.HWnd); - break; - case video::EDT_OPENGL: - hWnd = reinterpret_cast(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(hicon)); - SendMessage(hWnd, WM_SETICON, ICON_SMALL, reinterpret_cast(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 > getSupportedVideoModes() -{ - IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL); - sanity_check(nulldevice != NULL); - - std::vector > mlist; - video::IVideoModeList *modelist = nulldevice->getVideoModeList(); - - u32 num_modes = modelist->getVideoModeCount(); - for (u32 i = 0; i != num_modes; i++) { - core::dimension2d mode_res = modelist->getVideoModeResolution(i); - s32 mode_depth = modelist->getVideoModeDepth(i); - mlist.push_back(core::vector3d(mode_res.Width, mode_res.Height, mode_depth)); - } - - nulldevice->drop(); - - return mlist; -} - -std::vector getSupportedVideoDrivers() -{ - std::vector 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 deskres = nulldevice->getVideoModeList()->getDesktopResolution(); - nulldevice -> drop(); - - return deskres; -} -# endif // __ANDROID__ -#endif // SERVER - - //// //// OS-specific Secure Random //// diff --git a/src/porting.h b/src/porting.h index 05614543a..216553141 100644 --- a/src/porting.h +++ b/src/porting.h @@ -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__) - #define __linux__ + #define __linux__ #endif #if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE) #define _GNU_SOURCE @@ -178,8 +178,6 @@ void initializePaths(); */ std::string get_sysinfo(); -void initIrrlicht(irr::IrrlichtDevice * ); - // 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 > getSupportedVideoModes(); -std::vector 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 @@ -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. diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 3ed2ba0e0..7c86525f6 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -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 "EDriverTypes.h" #include #include +#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); - GUIKeyChangeMenu *kmenu - = new GUIKeyChangeMenu( engine->m_device->getGUIEnvironment(), + GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(), 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) { - GUIEngine* engine = getGuiEngine(L); - sanity_check(engine); - 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); - 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); @@ -960,7 +956,7 @@ int ModApiMainMenu::l_show_path_select_dialog(lua_State *L) 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, @@ -997,13 +993,12 @@ int ModApiMainMenu::l_download_file(lua_State *L) /******************************************************************************/ int ModApiMainMenu::l_get_video_drivers(lua_State *L) { - std::vector drivers - = porting::getSupportedVideoDrivers(); + std::vector drivers = RenderingEngine::getSupportedVideoDrivers(); 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); @@ -1021,7 +1016,7 @@ int ModApiMainMenu::l_get_video_drivers(lua_State *L) int ModApiMainMenu::l_get_video_modes(lua_State *L) { std::vector > videomodes - = porting::getSupportedVideoModes(); + = RenderingEngine::getSupportedVideoModes(); 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_pushnumber(L,porting::getDisplayDensity()); + lua_pushnumber(L,RenderingEngine::getDisplayDensity()); 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_pushnumber(L,porting::getDisplaySize().Y); + lua_pushnumber(L,RenderingEngine::getDisplaySize().Y); lua_settable(L, top); + const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); 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_pushnumber(L,porting::getWindowSize().Y); + lua_pushnumber(L, window_size.Y); lua_settable(L, top); return 1; } diff --git a/src/shader.cpp b/src/shader.cpp index 5ff8c910b..6e89d75ad 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "client/renderingengine.h" #include "EShaderTypes.h" #include "log.h" #include "gamedef.h" @@ -177,7 +178,7 @@ class ShaderCallback : public video::IShaderConstantSetCallBack std::vector m_setters; public: - ShaderCallback(const std::vector &factories) + ShaderCallback(const std::vector &factories) { 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: - ShaderSource(IrrlichtDevice *device); + 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 irrlicht device - IrrlichtDevice *m_device; // Cache of source shaders // This should be only accessed from the main thread @@ -332,18 +331,17 @@ private: std::vector 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, - u8 material_type, u8 drawtype, - IrrlichtDevice *device, std::vector &callbacks, - const std::vector &setter_factories, + u8 material_type, u8 drawtype, std::vector &callbacks, + const std::vector &setter_factories, 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); -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 "" @@ -453,7 +448,7 @@ u32 ShaderSource::getShaderIdDirect(const std::string &name, } 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) @@ -518,7 +513,7 @@ void ShaderSource::rebuildShaders() 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); } } @@ -526,8 +521,8 @@ void ShaderSource::rebuildShaders() ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype, - IrrlichtDevice *device, std::vector &callbacks, - const std::vector &setter_factories, + std::vector &callbacks, + const std::vector &setter_factories, 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; - switch(material_type){ + switch (material_type) { 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; + break; + default: + break; } 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){ diff --git a/src/shader.h b/src/shader.h index 979318c95..1db4cba83 100644 --- a/src/shader.h +++ b/src/shader.h @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define SHADER_HEADER #include -#include "irrlichttypes_extrabloated.h" +#include "irrlichttypes_bloated.h" #include class IGameDef; @@ -149,7 +149,7 @@ public: 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); diff --git a/src/sky.cpp b/src/sky.cpp index 3176ea936..463400194 100644 --- a/src/sky.cpp +++ b/src/sky.cpp @@ -8,13 +8,14 @@ #include "profiler.h" #include "util/numeric.h" #include +#include "client/renderingengine.h" #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); diff --git a/src/sky.h b/src/sky.h index 1fa25bd93..64d2877e5 100644 --- a/src/sky.h +++ b/src/sky.h @@ -34,8 +34,7 @@ class Sky : public scene::ISceneNode { public: //! constructor - Sky(scene::ISceneNode *parent, scene::ISceneManager *mgr, s32 id, - ITextureSource *tsrc); + Sky(s32 id, ITextureSource *tsrc); virtual void OnRegisterSceneNode(); diff --git a/util/travis/clang-format-whitelist.txt b/util/travis/clang-format-whitelist.txt index f276af282..23c036cb5 100644 --- a/util/travis/clang-format-whitelist.txt +++ b/util/travis/clang-format-whitelist.txt @@ -57,8 +57,6 @@ src/daynightratio.h src/debug.cpp src/debug.h src/defaultsettings.cpp -src/drawscene.cpp -src/drawscene.h src/dungeongen.cpp src/dungeongen.h src/emerge.cpp