summaryrefslogtreecommitdiff
path: root/src/client/clientlauncher.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-06-26 20:11:17 +0200
committerGitHub <noreply@github.com>2017-06-26 20:11:17 +0200
commitb3a36f7378ea0f299cfa36c81de42e00adb7292d (patch)
tree23d056b575ff0dba8cc759cc00f732099a1f3bce /src/client/clientlauncher.cpp
parenta8650e785df3f12efa5f8cd3c6a695fb9e22a598 (diff)
downloadminetest-b3a36f7378ea0f299cfa36c81de42e00adb7292d.tar.gz
minetest-b3a36f7378ea0f299cfa36c81de42e00adb7292d.tar.bz2
minetest-b3a36f7378ea0f299cfa36c81de42e00adb7292d.zip
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
Diffstat (limited to 'src/client/clientlauncher.cpp')
-rw-r--r--src/client/clientlauncher.cpp194
1 files changed, 38 insertions, 156 deletions
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<s32>(0, 0, 10000, 10000));
+ guiroot = RenderingEngine::get_gui_env()->addStaticText(L"",
+ core::rect<s32>(0, 0, 10000, 10000));
bool game_has_run = launch_game(error_message, reconnect_requested,
game_params, cmd_args);
@@ -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<irr::SJoystickInfo> infos;
@@ -326,7 +322,7 @@ void ClientLauncher::init_input()
// Make sure this is called maximum once per
// irrlicht device, otherwise it will give you
// multiple events for the same joystick.
- 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<video::E_DRIVER_TYPE> drivers
- = porting::getSupportedVideoDrivers();
- u32 i;
- for (i = 0; i != drivers.size(); i++) {
- if (!strcasecmp(driverstring.c_str(),
- porting::getVideoDriverName(drivers[i]))) {
- driverType = drivers[i];
- break;
- }
- }
- if (i == drivers.size()) {
- errorstream << "Invalid video_driver specified; "
- "defaulting to opengl" << std::endl;
- }
-
- SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
- params.DriverType = driverType;
- params.WindowSize = core::dimension2d<u32>(screen_w, screen_h);
- params.Bits = bits;
- params.AntiAlias = fsaa;
- params.Fullscreen = fullscreen;
- params.Stencilbuffer = false;
- params.Stereobuffer = stereo_buffer;
- params.Vsync = vsync;
- params.EventReceiver = receiver;
- params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
- params.ZBufferBits = 24;
-#ifdef __ANDROID__
- params.PrivateData = porting::app_global;
- params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM +
- "media" + DIR_DELIM + "Shaders" + DIR_DELIM).c_str();
-#endif
-
- device = createDeviceEx(params);
-
- if (device)
- porting::initIrrlicht(device);
-
- return device != NULL;
+ /* leave scene manager in a clean state */
+ RenderingEngine::get_scene_manager()->clear();
}
void ClientLauncher::speed_tests()
@@ -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<u32>(640, 480);
- params.Bits = 24;
- params.AntiAlias = fsaa;
- params.Fullscreen = false;
- params.Stencilbuffer = false;
- params.Vsync = vsync;
- params.EventReceiver = receiver;
- params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
-
- nulldevice = createDeviceEx(params);
-
- if (nulldevice == NULL) {
- delete receiver;
- return false;
- }
-
- std::cout << _("Available video modes (WxHxD):") << std::endl;
-
- video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
-
- if (videomode_list != NULL) {
- s32 videomode_count = videomode_list->getVideoModeCount();
- core::dimension2d<u32> videomode_res;
- s32 videomode_depth;
- for (s32 i = 0; i < videomode_count; ++i) {
- videomode_res = videomode_list->getVideoModeResolution(i);
- videomode_depth = videomode_list->getVideoModeDepth(i);
- std::cout << videomode_res.Width << "x" << videomode_res.Height
- << "x" << videomode_depth << std::endl;
- }
-
- std::cout << _("Active video mode (WxHxD):") << std::endl;
- videomode_res = videomode_list->getDesktopResolution();
- videomode_depth = videomode_list->getDesktopDepth();
- std::cout << videomode_res.Width << "x" << videomode_res.Height
- << "x" << videomode_depth << std::endl;
-
- }
-
- nulldevice->drop();
- delete receiver;
-
- return videomode_list != NULL;
-}