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
This commit is contained in:
Loïc Blot 2017-06-26 20:11:17 +02:00 committed by GitHub
parent a8650e785d
commit b3a36f7378
50 changed files with 1568 additions and 1567 deletions

@ -138,7 +138,6 @@ LOCAL_SRC_FILES := \
jni/src/database.cpp \ jni/src/database.cpp \
jni/src/debug.cpp \ jni/src/debug.cpp \
jni/src/defaultsettings.cpp \ jni/src/defaultsettings.cpp \
jni/src/drawscene.cpp \
jni/src/dungeongen.cpp \ jni/src/dungeongen.cpp \
jni/src/emerge.cpp \ jni/src/emerge.cpp \
jni/src/environment.cpp \ jni/src/environment.cpp \
@ -270,6 +269,7 @@ LOCAL_SRC_FILES := \
jni/src/wieldmesh.cpp \ jni/src/wieldmesh.cpp \
jni/src/client/clientlauncher.cpp \ jni/src/client/clientlauncher.cpp \
jni/src/client/inputhandler.cpp \ jni/src/client/inputhandler.cpp \
jni/src/client/renderingengine.cpp \
jni/src/client/tile.cpp \ jni/src/client/tile.cpp \
jni/src/client/joystick_controller.cpp \ jni/src/client/joystick_controller.cpp \
jni/src/irrlicht_changes/static_text.cpp jni/src/irrlicht_changes/static_text.cpp

@ -500,7 +500,6 @@ set(client_SRCS
content_cso.cpp content_cso.cpp
content_mapblock.cpp content_mapblock.cpp
convert_json.cpp convert_json.cpp
drawscene.cpp
filecache.cpp filecache.cpp
fontengine.cpp fontengine.cpp
game.cpp game.cpp

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientmap.h" // MapDrawControl #include "clientmap.h" // MapDrawControl
#include "player.h" #include "player.h"
#include <cmath> #include <cmath>
#include "client/renderingengine.h"
#include "settings.h" #include "settings.h"
#include "wieldmesh.h" #include "wieldmesh.h"
#include "noise.h" // easeCurve #include "noise.h" // easeCurve
@ -449,7 +450,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
fov_degrees = rangelim(fov_degrees, 7.0, 160.0); fov_degrees = rangelim(fov_degrees, 7.0, 160.0);
// FOV and aspect ratio // 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; m_fov_y = fov_degrees * M_PI / 180.0;
// Increase vertical FOV on lower aspect ratios (<16:10) // Increase vertical FOV on lower aspect ratios (<16:10)
m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect))); m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect)));

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cmath> #include <cmath>
#include <IFileSystem.h> #include <IFileSystem.h>
#include "threading/mutex_auto_lock.h" #include "threading/mutex_auto_lock.h"
#include "client/renderingengine.h"
#include "util/auth.h" #include "util/auth.h"
#include "util/directiontables.h" #include "util/directiontables.h"
#include "util/pointedthing.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 "clientmap.h"
#include "clientmedia.h" #include "clientmedia.h"
#include "version.h" #include "version.h"
#include "drawscene.h"
#include "database-sqlite3.h" #include "database-sqlite3.h"
#include "serialization.h" #include "serialization.h"
#include "guiscalingfilter.h" #include "guiscalingfilter.h"
@ -55,7 +55,6 @@ extern gui::IGUIEnvironment* guienv;
*/ */
Client::Client( Client::Client(
IrrlichtDevice *device,
const char *playername, const char *playername,
const std::string &password, const std::string &password,
const std::string &address_name, const std::string &address_name,
@ -77,16 +76,12 @@ Client::Client(
m_event(event), m_event(event),
m_mesh_update_thread(this), m_mesh_update_thread(this),
m_env( m_env(
new ClientMap(this, control, new ClientMap(this, control, 666),
device->getSceneManager()->getRootSceneNode(),
device->getSceneManager(), 666),
device->getSceneManager(),
tsrc, this tsrc, this
), ),
m_particle_manager(&m_env), m_particle_manager(&m_env),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this), m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this),
m_address_name(address_name), m_address_name(address_name),
m_device(device),
m_server_ser_ver(SER_FMT_VER_INVALID), m_server_ser_ver(SER_FMT_VER_INVALID),
m_last_chat_message_sent(time(NULL)), m_last_chat_message_sent(time(NULL)),
m_password(password), m_password(password),
@ -99,7 +94,7 @@ Client::Client(
m_env.setLocalPlayer(new LocalPlayer(this, playername)); m_env.setLocalPlayer(new LocalPlayer(this, playername));
if (g_settings->getBool("enable_minimap")) { if (g_settings->getBool("enable_minimap")) {
m_minimap = new Minimap(device, this); m_minimap = new Minimap(this);
} }
m_cache_save_interval = g_settings->getU16("server_map_save_interval"); m_cache_save_interval = g_settings->getU16("server_map_save_interval");
@ -217,12 +212,11 @@ Client::~Client()
} }
// cleanup 3d model meshes on client shutdown // cleanup 3d model meshes on client shutdown
while (m_device->getSceneManager()->getMeshCache()->getMeshCount() != 0) { while (RenderingEngine::get_mesh_cache()->getMeshCount() != 0) {
scene::IAnimatedMesh *mesh = scene::IAnimatedMesh *mesh = RenderingEngine::get_mesh_cache()->getMeshByIndex(0);
m_device->getSceneManager()->getMeshCache()->getMeshByIndex(0);
if (mesh) if (mesh)
m_device->getSceneManager()->getMeshCache()->removeMesh(mesh); RenderingEngine::get_mesh_cache()->removeMesh(mesh);
} }
delete m_minimap; delete m_minimap;
@ -614,8 +608,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
verbosestream<<"Client: Attempting to load image " verbosestream<<"Client: Attempting to load image "
<<"file \""<<filename<<"\""<<std::endl; <<"file \""<<filename<<"\""<<std::endl;
io::IFileSystem *irrfs = m_device->getFileSystem(); io::IFileSystem *irrfs = RenderingEngine::get_filesystem();
video::IVideoDriver *vdrv = m_device->getVideoDriver(); video::IVideoDriver *vdrv = RenderingEngine::get_video_driver();
// Create an irrlicht memory file // Create an irrlicht memory file
io::IReadFile *rfile = irrfs->createMemoryReadFile( io::IReadFile *rfile = irrfs->createMemoryReadFile(
@ -1628,7 +1622,6 @@ float Client::mediaReceiveProgress()
} }
typedef struct TextureUpdateArgs { typedef struct TextureUpdateArgs {
IrrlichtDevice *device;
gui::IGUIEnvironment *guienv; gui::IGUIEnvironment *guienv;
u64 last_time_ms; u64 last_time_ms;
u16 last_percent; u16 last_percent;
@ -1655,12 +1648,12 @@ void texture_update_progress(void *args, u32 progress, u32 max_progress)
targs->last_time_ms = time_ms; targs->last_time_ms = time_ms;
std::basic_stringstream<wchar_t> strm; std::basic_stringstream<wchar_t> strm;
strm << targs->text_base << " " << targs->last_percent << "%..."; strm << targs->text_base << " " << targs->last_percent << "%...";
draw_load_screen(strm.str(), targs->device, targs->guienv, targs->tsrc, 0, RenderingEngine::draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0,
72 + (u16) ((18. / 100.) * (double) targs->last_percent), true); 72 + (u16) ((18. / 100.) * (double) targs->last_percent), true);
} }
} }
void Client::afterContentReceived(IrrlichtDevice *device) void Client::afterContentReceived()
{ {
infostream<<"Client::afterContentReceived() started"<<std::endl; infostream<<"Client::afterContentReceived() started"<<std::endl;
assert(m_itemdef_received); // pre-condition assert(m_itemdef_received); // pre-condition
@ -1672,25 +1665,25 @@ void Client::afterContentReceived(IrrlichtDevice *device)
// Clear cached pre-scaled 2D GUI images, as this cache // Clear cached pre-scaled 2D GUI images, as this cache
// might have images with the same name but different // might have images with the same name but different
// content from previous sessions. // content from previous sessions.
guiScalingCacheClear(device->getVideoDriver()); guiScalingCacheClear();
// Rebuild inherited images and recreate textures // Rebuild inherited images and recreate textures
infostream<<"- Rebuilding images and textures"<<std::endl; infostream<<"- Rebuilding images and textures"<<std::endl;
draw_load_screen(text,device, guienv, m_tsrc, 0, 70); RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 70);
m_tsrc->rebuildImagesAndTextures(); m_tsrc->rebuildImagesAndTextures();
delete[] text; delete[] text;
// Rebuild shaders // Rebuild shaders
infostream<<"- Rebuilding shaders"<<std::endl; infostream<<"- Rebuilding shaders"<<std::endl;
text = wgettext("Rebuilding shaders..."); text = wgettext("Rebuilding shaders...");
draw_load_screen(text, device, guienv, m_tsrc, 0, 71); RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 71);
m_shsrc->rebuildShaders(); m_shsrc->rebuildShaders();
delete[] text; delete[] text;
// Update node aliases // Update node aliases
infostream<<"- Updating node aliases"<<std::endl; infostream<<"- Updating node aliases"<<std::endl;
text = wgettext("Initializing nodes..."); text = wgettext("Initializing nodes...");
draw_load_screen(text, device, guienv, m_tsrc, 0, 72); RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 72);
m_nodedef->updateAliases(m_itemdef); m_nodedef->updateAliases(m_itemdef);
std::string texture_path = g_settings->get("texture_path"); std::string texture_path = g_settings->get("texture_path");
if (texture_path != "" && fs::IsDir(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 // Update node textures and assign shaders to each tile
infostream<<"- Updating node textures"<<std::endl; infostream<<"- Updating node textures"<<std::endl;
TextureUpdateArgs tu_args; TextureUpdateArgs tu_args;
tu_args.device = device;
tu_args.guienv = guienv; tu_args.guienv = guienv;
tu_args.last_time_ms = porting::getTimeMs(); tu_args.last_time_ms = porting::getTimeMs();
tu_args.last_percent = 0; tu_args.last_percent = 0;
@ -1724,7 +1716,7 @@ void Client::afterContentReceived(IrrlichtDevice *device)
} }
text = wgettext("Done!"); text = wgettext("Done!");
draw_load_screen(text, device, guienv, m_tsrc, 0, 100); RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 100);
infostream<<"Client::afterContentReceived() done"<<std::endl; infostream<<"Client::afterContentReceived() done"<<std::endl;
delete[] text; delete[] text;
} }
@ -1742,7 +1734,7 @@ float Client::getCurRate()
void Client::makeScreenshot() void Client::makeScreenshot()
{ {
irr::video::IVideoDriver *driver = m_device->getVideoDriver(); irr::video::IVideoDriver *driver = RenderingEngine::get_video_driver();
irr::video::IImage* const raw_image = driver->createScreenShot(); irr::video::IImage* const raw_image = driver->createScreenShot();
if (!raw_image) if (!raw_image)
@ -1857,10 +1849,7 @@ IShaderSource* Client::getShaderSource()
{ {
return m_shsrc; return m_shsrc;
} }
scene::ISceneManager* Client::getSceneManager()
{
return m_device->getSceneManager();
}
u16 Client::allocateUnknownNodeId(const std::string &name) u16 Client::allocateUnknownNodeId(const std::string &name)
{ {
errorstream << "Client::allocateUnknownNodeId(): " errorstream << "Client::allocateUnknownNodeId(): "
@ -1892,22 +1881,20 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
return NULL; return NULL;
} }
const std::string &data = it->second; const std::string &data = it->second;
scene::ISceneManager *smgr = m_device->getSceneManager();
// Create the mesh, remove it from cache and return it // Create the mesh, remove it from cache and return it
// This allows unique vertex colors and other properties for each instance // This allows unique vertex colors and other properties for each instance
Buffer<char> data_rw(data.c_str(), data.size()); // Const-incorrect Irrlicht Buffer<char> data_rw(data.c_str(), data.size()); // Const-incorrect Irrlicht
io::IFileSystem *irrfs = m_device->getFileSystem(); io::IReadFile *rfile = RenderingEngine::get_filesystem()->createMemoryReadFile(
io::IReadFile *rfile = irrfs->createMemoryReadFile(
*data_rw, data_rw.getSize(), filename.c_str()); *data_rw, data_rw.getSize(), filename.c_str());
FATAL_ERROR_IF(!rfile, "Could not create/open RAM file"); 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(); rfile->drop();
// NOTE: By playing with Irrlicht refcounts, maybe we could cache a bunch // NOTE: By playing with Irrlicht refcounts, maybe we could cache a bunch
// of uniquely named instances and re-use them // of uniquely named instances and re-use them
mesh->grab(); mesh->grab();
smgr->getMeshCache()->removeMesh(mesh); RenderingEngine::get_mesh_cache()->removeMesh(mesh);
return mesh; return mesh;
} }

@ -256,7 +256,6 @@ public:
*/ */
Client( Client(
IrrlichtDevice *device,
const char *playername, const char *playername,
const std::string &password, const std::string &password,
const std::string &address_name, const std::string &address_name,
@ -467,7 +466,7 @@ public:
float mediaReceiveProgress(); float mediaReceiveProgress();
void afterContentReceived(IrrlichtDevice *device); void afterContentReceived();
float getRTT(); float getRTT();
float getCurRate(); float getCurRate();
@ -486,7 +485,6 @@ public:
ITextureSource* getTextureSource(); ITextureSource* getTextureSource();
virtual IShaderSource* getShaderSource(); virtual IShaderSource* getShaderSource();
IShaderSource *shsrc() { return getShaderSource(); } IShaderSource *shsrc() { return getShaderSource(); }
scene::ISceneManager* getSceneManager();
virtual u16 allocateUnknownNodeId(const std::string &name); virtual u16 allocateUnknownNodeId(const std::string &name);
virtual ISoundManager* getSoundManager(); virtual ISoundManager* getSoundManager();
virtual MtEventManager* getEventManager(); virtual MtEventManager* getEventManager();
@ -593,7 +591,6 @@ private:
ParticleManager m_particle_manager; ParticleManager m_particle_manager;
con::Connection m_con; con::Connection m_con;
std::string m_address_name; std::string m_address_name;
IrrlichtDevice *m_device;
Camera *m_camera = nullptr; Camera *m_camera = nullptr;
Minimap *m_minimap = nullptr; Minimap *m_minimap = nullptr;
bool m_minimap_disabled_by_server = false; bool m_minimap_disabled_by_server = false;

@ -1,4 +1,5 @@
set(client_SRCS set(client_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/renderingengine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp ${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp
${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp

@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/ */
#include "mainmenumanager.h" #include "mainmenumanager.h"
#include "debug.h"
#include "clouds.h" #include "clouds.h"
#include "server.h" #include "server.h"
#include "filesys.h" #include "filesys.h"
@ -27,14 +26,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "chat.h" #include "chat.h"
#include "gettext.h" #include "gettext.h"
#include "profiler.h" #include "profiler.h"
#include "log.h"
#include "serverlist.h" #include "serverlist.h"
#include "guiEngine.h" #include "guiEngine.h"
#include "player.h"
#include "fontengine.h" #include "fontengine.h"
#include "joystick_controller.h"
#include "clientlauncher.h" #include "clientlauncher.h"
#include "version.h" #include "version.h"
#include "renderingengine.h"
/* mainmenumanager.h /* mainmenumanager.h
*/ */
@ -58,9 +55,9 @@ ClientLauncher::~ClientLauncher()
delete input; delete input;
delete g_fontengine; delete g_fontengine;
delete g_gamecallback;
if (device) delete RenderingEngine::get_instance();
device->drop();
} }
@ -70,7 +67,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
// List video modes if requested // List video modes if requested
if (list_video_modes) if (list_video_modes)
return print_video_modes(); return RenderingEngine::print_video_modes();
if (!init_engine()) { if (!init_engine()) {
errorstream << "Could not initialize game engine." << std::endl; errorstream << "Could not initialize game engine." << std::endl;
@ -84,15 +81,14 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
return true; return true;
} }
video::IVideoDriver *video_driver = device->getVideoDriver(); video::IVideoDriver *video_driver = RenderingEngine::get_video_driver();
if (video_driver == NULL) { if (video_driver == NULL) {
errorstream << "Could not initialize video driver." << std::endl; errorstream << "Could not initialize video driver." << std::endl;
return false; return false;
} }
porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C); RenderingEngine::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
RenderingEngine::get_instance()->setWindowIcon();
porting::setWindowIcon(device);
/* /*
This changes the minimum allowed number of vertices in a VBO. This changes the minimum allowed number of vertices in a VBO.
@ -101,17 +97,17 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
//driver->setMinHardwareBufferVertexCount(50); //driver->setMinHardwareBufferVertexCount(50);
// Create game callback for menus // Create game callback for menus
g_gamecallback = new MainGameCallback(device); g_gamecallback = new MainGameCallback();
device->setResizable(true); RenderingEngine::get_instance()->setResizable(true);
init_input(); init_input();
smgr = device->getSceneManager(); RenderingEngine::get_scene_manager()->getParameters()->
smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
guienv = device->getGUIEnvironment(); guienv = RenderingEngine::get_gui_env();
skin = guienv->getSkin(); skin = RenderingEngine::get_gui_env()->getSkin();
skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255)); 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_LIGHT, video::SColor(0, 0, 0, 0));
skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30)); 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 // Create the menu clouds
if (!g_menucloudsmgr) if (!g_menucloudsmgr)
g_menucloudsmgr = smgr->createNewSceneManager(); g_menucloudsmgr = RenderingEngine::get_scene_manager()->createNewSceneManager();
if (!g_menuclouds) if (!g_menuclouds)
g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(), g_menuclouds = new Clouds(g_menucloudsmgr, -1, rand(), 100);
g_menucloudsmgr, -1, rand(), 100);
g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255)); g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
scene::ICameraSceneNode* camera; scene::ICameraSceneNode* camera;
camera = g_menucloudsmgr->addCameraSceneNode(0, camera = g_menucloudsmgr->addCameraSceneNode(0,
@ -159,25 +154,27 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
bool retval = true; bool retval = true;
bool *kill = porting::signal_handler_killstatus(); 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 // Set the window caption
const wchar_t *text = wgettext("Main Menu"); 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" " + utf8_to_wide(g_version_hash) +
L" [" + text + L"]").c_str()); L" [" + text + L"]").c_str());
delete[] text; delete[] text;
try { // This is used for catching disconnects 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 We need some kind of a root node to be able to add
custom gui elements directly on the screen. custom gui elements directly on the screen.
Otherwise they won't be automatically drawn. 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, bool game_has_run = launch_game(error_message, reconnect_requested,
game_params, cmd_args); game_params, cmd_args);
@ -199,7 +196,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
} }
// Break out of menu-game loop to shut down cleanly // Break out of menu-game loop to shut down cleanly
if (!device->run() || *kill) { if (!RenderingEngine::get_raw_device()->run() || *kill) {
if (g_settings_path != "") if (g_settings_path != "")
g_settings->updateConfigFile(g_settings_path.c_str()); g_settings->updateConfigFile(g_settings_path.c_str());
break; break;
@ -212,7 +209,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
continue; continue;
} }
device->getVideoDriver()->setTextureCreationFlag( RenderingEngine::get_video_driver()->setTextureCreationFlag(
video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map")); video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
@ -224,7 +221,6 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
kill, kill,
random_input, random_input,
input, input,
device,
worldspec.path, worldspec.path,
current_playername, current_playername,
current_password, current_password,
@ -236,7 +232,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
gamespec, gamespec,
simple_singleplayer_mode simple_singleplayer_mode
); );
smgr->clear(); RenderingEngine::get_scene_manager()->clear();
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
delete g_touchscreengui; delete g_touchscreengui;
@ -308,8 +304,8 @@ void ClientLauncher::init_args(GameParams &game_params, const Settings &cmd_args
bool ClientLauncher::init_engine() bool ClientLauncher::init_engine()
{ {
receiver = new MyEventReceiver(); receiver = new MyEventReceiver();
create_engine_device(); new RenderingEngine(receiver);
return device != NULL; return RenderingEngine::get_raw_device() != nullptr;
} }
void ClientLauncher::init_input() void ClientLauncher::init_input()
@ -317,7 +313,7 @@ void ClientLauncher::init_input()
if (random_input) if (random_input)
input = new RandomInputHandler(); input = new RandomInputHandler();
else else
input = new RealInputHandler(device, receiver); input = new RealInputHandler(receiver);
if (g_settings->getBool("enable_joysticks")) { if (g_settings->getBool("enable_joysticks")) {
irr::core::array<irr::SJoystickInfo> infos; irr::core::array<irr::SJoystickInfo> infos;
@ -326,7 +322,7 @@ void ClientLauncher::init_input()
// Make sure this is called maximum once per // Make sure this is called maximum once per
// irrlicht device, otherwise it will give you // irrlicht device, otherwise it will give you
// multiple events for the same joystick. // multiple events for the same joystick.
if (device->activateJoysticks(infos)) { if (RenderingEngine::get_raw_device()->activateJoysticks(infos)) {
infostream << "Joystick support enabled" << std::endl; infostream << "Joystick support enabled" << std::endl;
joystick_infos.reserve(infos.size()); joystick_infos.reserve(infos.size());
for (u32 i = 0; i < infos.size(); i++) { 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) void ClientLauncher::main_menu(MainMenuData *menudata)
{ {
bool *kill = porting::signal_handler_killstatus(); bool *kill = porting::signal_handler_killstatus();
video::IVideoDriver *driver = device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
infostream << "Waiting for other menus" << std::endl; infostream << "Waiting for other menus" << std::endl;
while (device->run() && *kill == false) { while (RenderingEngine::get_raw_device()->run() && *kill == false) {
if (!isMenuActive()) if (!isMenuActive())
break; break;
driver->beginScene(true, true, video::SColor(255, 128, 128, 128)); driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
guienv->drawAll(); RenderingEngine::get_gui_env()->drawAll();
driver->endScene(); driver->endScene();
// On some computers framerate doesn't seem to be automatically limited // On some computers framerate doesn't seem to be automatically limited
sleep_ms(25); sleep_ms(25);
@ -503,73 +499,14 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
// Cursor can be non-visible when coming from the game // Cursor can be non-visible when coming from the game
#ifndef ANDROID #ifndef ANDROID
device->getCursorControl()->setVisible(true); RenderingEngine::get_raw_device()->getCursorControl()->setVisible(true);
#endif #endif
/* show main menu */ /* show main menu */
GUIEngine mymenu(device, &input->joystick, guiroot, GUIEngine mymenu(&input->joystick, guiroot, &g_menumgr, menudata, *kill);
&g_menumgr, smgr, menudata, *kill);
smgr->clear(); /* leave scene manager in a clean state */ /* leave scene manager in a clean state */
} RenderingEngine::get_scene_manager()->clear();
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;
} }
void ClientLauncher::speed_tests() void ClientLauncher::speed_tests()
@ -584,8 +521,8 @@ void ClientLauncher::speed_tests()
tempv3f1 = v3f(); tempv3f1 = v3f();
tempv3f2 = v3f(); tempv3f2 = v3f();
tempstring = std::string(); tempstring.clear();
tempstring2 = std::string(); tempstring2.clear();
{ {
infostream << "The following test should take around 20ms." << std::endl; infostream << "The following test should take around 20ms." << std::endl;
@ -670,58 +607,3 @@ void ClientLauncher::speed_tests()
infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl; infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl;
} }
} }
bool ClientLauncher::print_video_modes()
{
IrrlichtDevice *nulldevice;
bool vsync = g_settings->getBool("vsync");
u16 fsaa = g_settings->getU16("fsaa");
MyEventReceiver* receiver = new MyEventReceiver();
SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
params.DriverType = video::EDT_NULL;
params.WindowSize = core::dimension2d<u32>(640, 480);
params.Bits = 24;
params.AntiAlias = fsaa;
params.Fullscreen = false;
params.Stencilbuffer = false;
params.Vsync = vsync;
params.EventReceiver = receiver;
params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
nulldevice = createDeviceEx(params);
if (nulldevice == NULL) {
delete receiver;
return false;
}
std::cout << _("Available video modes (WxHxD):") << std::endl;
video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
if (videomode_list != NULL) {
s32 videomode_count = videomode_list->getVideoModeCount();
core::dimension2d<u32> videomode_res;
s32 videomode_depth;
for (s32 i = 0; i < videomode_count; ++i) {
videomode_res = videomode_list->getVideoModeResolution(i);
videomode_depth = videomode_list->getVideoModeDepth(i);
std::cout << videomode_res.Width << "x" << videomode_res.Height
<< "x" << videomode_depth << std::endl;
}
std::cout << _("Active video mode (WxHxD):") << std::endl;
videomode_res = videomode_list->getDesktopResolution();
videomode_depth = videomode_list->getDesktopDepth();
std::cout << videomode_res.Width << "x" << videomode_res.Height
<< "x" << videomode_depth << std::endl;
}
nulldevice->drop();
delete receiver;
return videomode_list != NULL;
}

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/inputhandler.h" #include "client/inputhandler.h"
#include "gameparams.h" #include "gameparams.h"
class RenderingEngine;
class ClientLauncher class ClientLauncher
{ {
@ -43,10 +44,8 @@ protected:
GameParams &game_params, const Settings &cmd_args); GameParams &game_params, const Settings &cmd_args);
void main_menu(MainMenuData *menudata); void main_menu(MainMenuData *menudata);
bool create_engine_device();
void speed_tests(); void speed_tests();
bool print_video_modes();
bool list_video_modes = false; bool list_video_modes = false;
bool skip_main_menu = false; bool skip_main_menu = false;
@ -55,12 +54,10 @@ protected:
std::string address = ""; std::string address = "";
std::string playername = ""; std::string playername = "";
std::string password = ""; std::string password = "";
IrrlichtDevice *device = nullptr;
InputHandler *input = nullptr; InputHandler *input = nullptr;
MyEventReceiver *receiver = nullptr; MyEventReceiver *receiver = nullptr;
gui::IGUISkin *skin = nullptr; gui::IGUISkin *skin = nullptr;
gui::IGUIFont *font = nullptr; gui::IGUIFont *font = nullptr;
scene::ISceneManager *smgr = nullptr;
SubgameSpec gamespec; SubgameSpec gamespec;
WorldSpec worldspec; WorldSpec worldspec;
bool simple_singleplayer_mode; bool simple_singleplayer_mode;

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "joystick_controller.h" #include "joystick_controller.h"
#include <list> #include <list>
#include "keycode.h" #include "keycode.h"
#include "renderingengine.h"
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
#include "touchscreengui.h" #include "touchscreengui.h"
@ -219,8 +220,7 @@ public:
class RealInputHandler : public InputHandler class RealInputHandler : public InputHandler
{ {
public: public:
RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver) RealInputHandler(MyEventReceiver *receiver) : m_receiver(receiver)
: m_device(device), m_receiver(receiver)
{ {
m_receiver->joystick = &joystick; m_receiver->joystick = &joystick;
} }
@ -239,16 +239,20 @@ public:
virtual void dontListenForKeys() { m_receiver->dontListenForKeys(); } virtual void dontListenForKeys() { m_receiver->dontListenForKeys(); }
virtual v2s32 getMousePos() virtual v2s32 getMousePos()
{ {
if (m_device->getCursorControl()) { if (RenderingEngine::get_raw_device()->getCursorControl()) {
return m_device->getCursorControl()->getPosition(); return RenderingEngine::get_raw_device()
->getCursorControl()
->getPosition();
} else { } else {
return m_mousepos; return m_mousepos;
} }
} }
virtual void setMousePos(s32 x, s32 y) virtual void setMousePos(s32 x, s32 y)
{ {
if (m_device->getCursorControl()) { if (RenderingEngine::get_raw_device()->getCursorControl()) {
m_device->getCursorControl()->setPosition(x, y); RenderingEngine::get_raw_device()
->getCursorControl()
->setPosition(x, y);
} else { } else {
m_mousepos = v2s32(x, y); m_mousepos = v2s32(x, y);
} }
@ -276,7 +280,6 @@ public:
} }
private: private:
IrrlichtDevice *m_device = nullptr;
MyEventReceiver *m_receiver = nullptr; MyEventReceiver *m_receiver = nullptr;
v2s32 m_mousepos; v2s32 m_mousepos;
}; };

File diff suppressed because it is too large Load Diff

@ -0,0 +1,185 @@
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <vector>
#include <string>
#include "irrlichttypes_extrabloated.h"
#include "debug.h"
class ITextureSource;
class Camera;
class Client;
class LocalPlayer;
class Hud;
class Minimap;
class RenderingEngine
{
public:
RenderingEngine(IEventReceiver *eventReceiver);
~RenderingEngine();
v2u32 getWindowSize() const;
void setResizable(bool resize);
video::IVideoDriver *getVideoDriver();
static const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
static float getDisplayDensity();
static v2u32 getDisplaySize();
static void setXorgClassHint(const video::SExposedVideoData &video_data,
const std::string &name);
bool setWindowIcon();
bool setXorgWindowIconFromPath(const std::string &icon_file);
static bool print_video_modes();
static RenderingEngine *get_instance() { return s_singleton; }
static io::IFileSystem *get_filesystem()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device->getFileSystem();
}
static video::IVideoDriver *get_video_driver()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device->getVideoDriver();
}
static scene::IMeshCache *get_mesh_cache()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device->getSceneManager()->getMeshCache();
}
static scene::ISceneManager *get_scene_manager()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device->getSceneManager();
}
static irr::IrrlichtDevice *get_raw_device()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device;
}
static u32 get_timer_time()
{
sanity_check(s_singleton && s_singleton->m_device &&
s_singleton->m_device->getTimer());
return s_singleton->m_device->getTimer()->getTime();
}
static gui::IGUIEnvironment *get_gui_env()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device->getGUIEnvironment();
}
inline static void draw_load_screen(const std::wstring &text,
gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
float dtime = 0, int percent = 0, bool clouds = true)
{
s_singleton->_draw_load_screen(
text, guienv, tsrc, dtime, percent, clouds);
}
inline static void draw_scene(Camera *camera, Client *client, LocalPlayer *player,
Hud *hud, Minimap *mapper, gui::IGUIEnvironment *guienv,
const v2u32 &screensize, const video::SColor &skycolor,
bool show_hud, bool show_minimap)
{
s_singleton->_draw_scene(camera, client, player, hud, mapper, guienv,
screensize, skycolor, show_hud, show_minimap);
}
static bool run()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device->run();
}
static std::vector<core::vector3d<u32>> getSupportedVideoModes();
static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
private:
enum parallax_sign
{
LEFT = -1,
RIGHT = 1,
EYECOUNT = 2
};
void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv,
ITextureSource *tsrc, float dtime = 0, int percent = 0,
bool clouds = true);
void _draw_scene(Camera *camera, Client *client, LocalPlayer *player, Hud *hud,
Minimap *mapper, gui::IGUIEnvironment *guienv,
const v2u32 &screensize, const video::SColor &skycolor,
bool show_hud, bool show_minimap);
void draw_anaglyph_3d_mode(Camera *camera, bool show_hud, Hud *hud,
bool draw_wield_tool, Client *client,
gui::IGUIEnvironment *guienv);
void draw_interlaced_3d_mode(Camera *camera, bool show_hud, Hud *hud,
const v2u32 &screensize, bool draw_wield_tool, Client *client,
gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
void draw_sidebyside_3d_mode(Camera *camera, bool show_hud, Hud *hud,
const v2u32 &screensize, bool draw_wield_tool, Client *client,
gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
void draw_top_bottom_3d_mode(Camera *camera, bool show_hud, Hud *hud,
const v2u32 &screensize, bool draw_wield_tool, Client *client,
gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
void draw_pageflip_3d_mode(Camera *camera, bool show_hud, Hud *hud,
const v2u32 &screensize, bool draw_wield_tool, Client *client,
gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
void draw_plain(Camera *camera, bool show_hud, Hud *hud, const v2u32 &screensize,
bool draw_wield_tool, Client *client,
gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
void init_texture(const v2u32 &screensize, video::ITexture **texture,
const char *name);
video::ITexture *draw_image(const v2u32 &screensize, parallax_sign psign,
const irr::core::matrix4 &startMatrix,
const irr::core::vector3df &focusPoint, bool show_hud,
Camera *camera, Hud *hud, bool draw_wield_tool, Client *client,
gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
video::ITexture *draw_hud(const v2u32 &screensize, bool show_hud, Hud *hud,
Client *client, bool draw_crosshair,
const video::SColor &skycolor, gui::IGUIEnvironment *guienv,
Camera *camera);
irr::IrrlichtDevice *m_device = nullptr;
static RenderingEngine *s_singleton;
};

@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "imagefilters.h" #include "imagefilters.h"
#include "guiscalingfilter.h" #include "guiscalingfilter.h"
#include "nodedef.h" #include "nodedef.h"
#include "renderingengine.h"
#ifdef __ANDROID__ #ifdef __ANDROID__
@ -198,8 +199,7 @@ public:
} }
m_images.clear(); m_images.clear();
} }
void insert(const std::string &name, video::IImage *img, void insert(const std::string &name, video::IImage *img, bool prefer_local)
bool prefer_local, video::IVideoDriver *driver)
{ {
assert(img); // Pre-condition assert(img); // Pre-condition
// Remove old image // Remove old image
@ -217,7 +217,8 @@ public:
if (prefer_local){ if (prefer_local){
std::string path = getTexturePath(name); std::string path = getTexturePath(name);
if (path != ""){ if (path != ""){
video::IImage *img2 = driver->createImageFromFile(path.c_str()); video::IImage *img2 = RenderingEngine::get_video_driver()->
createImageFromFile(path.c_str());
if (img2){ if (img2){
toadd = img2; toadd = img2;
need_to_grab = false; need_to_grab = false;
@ -238,7 +239,7 @@ public:
return NULL; return NULL;
} }
// Primarily fetches from cache, secondarily tries to read from filesystem // Primarily fetches from cache, secondarily tries to read from filesystem
video::IImage* getOrLoad(const std::string &name, IrrlichtDevice *device) video::IImage *getOrLoad(const std::string &name)
{ {
std::map<std::string, video::IImage*>::iterator n; std::map<std::string, video::IImage*>::iterator n;
n = m_images.find(name); n = m_images.find(name);
@ -246,7 +247,7 @@ public:
n->second->grab(); // Grab for caller n->second->grab(); // Grab for caller
return n->second; return n->second;
} }
video::IVideoDriver* driver = device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
std::string path = getTexturePath(name); std::string path = getTexturePath(name);
if (path == ""){ if (path == ""){
infostream<<"SourceImageCache::getOrLoad(): No path found for \"" infostream<<"SourceImageCache::getOrLoad(): No path found for \""
@ -274,7 +275,7 @@ private:
class TextureSource : public IWritableTextureSource class TextureSource : public IWritableTextureSource
{ {
public: public:
TextureSource(IrrlichtDevice *device); TextureSource();
virtual ~TextureSource(); virtual ~TextureSource();
/* /*
@ -343,12 +344,6 @@ public:
virtual Palette* getPalette(const std::string &name); virtual Palette* getPalette(const std::string &name);
// Returns a pointer to the irrlicht device
virtual IrrlichtDevice* getDevice()
{
return m_device;
}
bool isKnownSourceImage(const std::string &name) bool isKnownSourceImage(const std::string &name)
{ {
bool is_known = false; bool is_known = false;
@ -387,8 +382,6 @@ private:
// The id of the thread that is allowed to use irrlicht directly // The id of the thread that is allowed to use irrlicht directly
std::thread::id m_main_thread; std::thread::id m_main_thread;
// The irrlicht device
IrrlichtDevice *m_device;
// Cache of source images // Cache of source images
// This should be only accessed from the main thread // This should be only accessed from the main thread
@ -435,16 +428,13 @@ private:
bool m_setting_anisotropic_filter; bool m_setting_anisotropic_filter;
}; };
IWritableTextureSource* createTextureSource(IrrlichtDevice *device) IWritableTextureSource *createTextureSource()
{ {
return new TextureSource(device); return new TextureSource();
} }
TextureSource::TextureSource(IrrlichtDevice *device): TextureSource::TextureSource()
m_device(device)
{ {
assert(m_device); // Pre-condition
m_main_thread = std::this_thread::get_id(); m_main_thread = std::this_thread::get_id();
// Add a NULL TextureInfo as the first index, named "" // Add a NULL TextureInfo as the first index, named ""
@ -461,7 +451,7 @@ TextureSource::TextureSource(IrrlichtDevice *device):
TextureSource::~TextureSource() TextureSource::~TextureSource()
{ {
video::IVideoDriver* driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
unsigned int textures_before = driver->getTextureCount(); unsigned int textures_before = driver->getTextureCount();
@ -622,7 +612,7 @@ u32 TextureSource::generateTexture(const std::string &name)
return 0; return 0;
} }
video::IVideoDriver *driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver); sanity_check(driver);
video::IImage *img = generateImage(name); video::IImage *img = generateImage(name);
@ -773,7 +763,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im
sanity_check(std::this_thread::get_id() == m_main_thread); sanity_check(std::this_thread::get_id() == m_main_thread);
m_sourcecache.insert(name, img, true, m_device->getVideoDriver()); m_sourcecache.insert(name, img, true);
m_source_image_existence.set(name, true); m_source_image_existence.set(name, true);
} }
@ -781,7 +771,7 @@ void TextureSource::rebuildImagesAndTextures()
{ {
MutexAutoLock lock(m_textureinfo_cache_mutex); MutexAutoLock lock(m_textureinfo_cache_mutex);
video::IVideoDriver* driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver); sanity_check(driver);
// Recreate textures // Recreate textures
@ -810,7 +800,7 @@ void TextureSource::rebuildImagesAndTextures()
video::ITexture* TextureSource::generateTextureFromMesh( video::ITexture* TextureSource::generateTextureFromMesh(
const TextureFromMeshParams &params) const TextureFromMeshParams &params)
{ {
video::IVideoDriver *driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver); sanity_check(driver);
#ifdef __ANDROID__ #ifdef __ANDROID__
@ -935,8 +925,7 @@ video::ITexture* TextureSource::generateTextureFromMesh(
} }
#endif #endif
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET) == false) if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) {
{
static bool warned = false; static bool warned = false;
if (!warned) if (!warned)
{ {
@ -967,7 +956,7 @@ video::ITexture* TextureSource::generateTextureFromMesh(
} }
// Get a scene manager // Get a scene manager
scene::ISceneManager *smgr_main = m_device->getSceneManager(); scene::ISceneManager *smgr_main = RenderingEngine::get_scene_manager();
assert(smgr_main); assert(smgr_main);
scene::ISceneManager *smgr = smgr_main->createNewSceneManager(); scene::ISceneManager *smgr = smgr_main->createNewSceneManager();
assert(smgr); assert(smgr);
@ -1065,10 +1054,6 @@ video::IImage* TextureSource::generateImage(const std::string &name)
baseimg = generateImage(name.substr(0, last_separator_pos)); baseimg = generateImage(name.substr(0, last_separator_pos));
} }
video::IVideoDriver* driver = m_device->getVideoDriver();
sanity_check(driver);
/* /*
Parse out the last part of the name of the image and act Parse out the last part of the name of the image and act
according to it according to it
@ -1196,13 +1181,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
video::IImage *& baseimg) video::IImage *& baseimg)
{ {
const char escape = '\\'; // same as in generateImage() const char escape = '\\'; // same as in generateImage()
video::IVideoDriver* driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver); sanity_check(driver);
// Stuff starting with [ are special commands // Stuff starting with [ are special commands
if (part_of_name.size() == 0 || part_of_name[0] != '[') 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__ #ifdef __ANDROID__
image = Align2Npot2(image, driver); image = Align2Npot2(image, driver);
#endif #endif
@ -1275,7 +1260,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
blit_with_alpha(image, baseimg, pos_from, pos_to, dim); blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
} else if (dim.Width * dim.Height < dim_dst.Width * dim_dst.Height) { } else if (dim.Width * dim.Height < dim_dst.Width * dim_dst.Height) {
// Upscale overlying image // Upscale overlying image
video::IImage* scaled_image = m_device->getVideoDriver()-> video::IImage *scaled_image = RenderingEngine::get_video_driver()->
createImage(video::ECF_A8R8G8B8, dim_dst); createImage(video::ECF_A8R8G8B8, dim_dst);
image->copyToScaling(scaled_image); image->copyToScaling(scaled_image);
@ -1283,7 +1268,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
scaled_image->drop(); scaled_image->drop();
} else { } else {
// Upscale base image // Upscale base image
video::IImage* scaled_base = m_device->getVideoDriver()-> video::IImage *scaled_base = RenderingEngine::get_video_driver()->
createImage(video::ECF_A8R8G8B8, dim); createImage(video::ECF_A8R8G8B8, dim);
baseimg->copyToScaling(scaled_base); baseimg->copyToScaling(scaled_base);
baseimg->drop(); baseimg->drop();
@ -1333,7 +1318,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
horizontally tiled. horizontally tiled.
*/ */
video::IImage *img_crack = m_sourcecache.getOrLoad( video::IImage *img_crack = m_sourcecache.getOrLoad(
"crack_anylength.png", m_device); "crack_anylength.png");
if (img_crack) { if (img_crack) {
draw_crack(img_crack, baseimg, draw_crack(img_crack, baseimg,
@ -1855,7 +1840,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
u32 height = stoi(sf.next("")); u32 height = stoi(sf.next(""));
core::dimension2d<u32> dim(width, height); core::dimension2d<u32> dim(width, height);
video::IImage* image = m_device->getVideoDriver()-> video::IImage *image = RenderingEngine::get_video_driver()->
createImage(video::ECF_A8R8G8B8, dim); createImage(video::ECF_A8R8G8B8, dim);
baseimg->copyToScaling(image); baseimg->copyToScaling(image);
baseimg->drop(); baseimg->drop();
@ -2356,7 +2341,7 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name)
video::SColor TextureSource::getTextureAverageColor(const std::string &name) video::SColor TextureSource::getTextureAverageColor(const std::string &name)
{ {
video::IVideoDriver *driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
video::SColor c(0, 0, 0, 0); video::SColor c(0, 0, 0, 0);
video::ITexture *texture = getTexture(name); video::ITexture *texture = getTexture(name);
video::IImage *image = driver->createImage(texture, video::IImage *image = driver->createImage(texture,
@ -2400,7 +2385,7 @@ video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present)
if (isKnownSourceImage(tname)) { if (isKnownSourceImage(tname)) {
return getTexture(tname); return getTexture(tname);
} else { } else {
video::IVideoDriver *driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
video::IImage *flags_image = driver->createImage( video::IImage *flags_image = driver->createImage(
video::ECF_A8R8G8B8, core::dimension2d<u32>(1, 1)); video::ECF_A8R8G8B8, core::dimension2d<u32>(1, 1));
sanity_check(flags_image != NULL); sanity_check(flags_image != NULL);

@ -114,7 +114,6 @@ public:
* Should be called from the main thread. * Should be called from the main thread.
*/ */
virtual Palette* getPalette(const std::string &name) = 0; virtual Palette* getPalette(const std::string &name) = 0;
virtual IrrlichtDevice* getDevice()=0;
virtual bool isKnownSourceImage(const std::string &name)=0; virtual bool isKnownSourceImage(const std::string &name)=0;
virtual video::ITexture* generateTextureFromMesh( virtual video::ITexture* generateTextureFromMesh(
const TextureFromMeshParams &params)=0; const TextureFromMeshParams &params)=0;
@ -133,7 +132,6 @@ public:
virtual video::ITexture* getTexture(u32 id)=0; virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture( virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr)=0; const std::string &name, u32 *id = nullptr)=0;
virtual IrrlichtDevice* getDevice()=0;
virtual bool isKnownSourceImage(const std::string &name)=0; virtual bool isKnownSourceImage(const std::string &name)=0;
virtual video::ITexture* generateTextureFromMesh( virtual video::ITexture* generateTextureFromMesh(
const TextureFromMeshParams &params)=0; const TextureFromMeshParams &params)=0;
@ -146,7 +144,7 @@ public:
virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0; virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0;
}; };
IWritableTextureSource* createTextureSource(IrrlichtDevice *device); IWritableTextureSource *createTextureSource();
#ifdef __ANDROID__ #ifdef __ANDROID__
video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver); video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver);

@ -31,16 +31,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "voxelalgorithms.h" #include "voxelalgorithms.h"
#include "settings.h" #include "settings.h"
#include <algorithm> #include <algorithm>
#include "client/renderingengine.h"
/* /*
ClientEnvironment ClientEnvironment
*/ */
ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr, ClientEnvironment::ClientEnvironment(ClientMap *map,
ITextureSource *texturesource, Client *client): ITextureSource *texturesource, Client *client):
Environment(client), Environment(client),
m_map(map), m_map(map),
m_smgr(smgr),
m_texturesource(texturesource), m_texturesource(texturesource),
m_client(client) m_client(client)
{ {
@ -456,7 +456,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
infostream<<"ClientEnvironment::addActiveObject(): " infostream<<"ClientEnvironment::addActiveObject(): "
<<"added (id="<<object->getId()<<")"<<std::endl; <<"added (id="<<object->getId()<<")"<<std::endl;
m_active_objects[object->getId()] = object; m_active_objects[object->getId()] = object;
object->addToScene(m_smgr, m_texturesource); object->addToScene(RenderingEngine::get_scene_manager(), m_texturesource);
{ // Update lighting immediately { // Update lighting immediately
u8 light = 0; u8 light = 0;
bool pos_ok; bool pos_ok;

@ -67,8 +67,7 @@ typedef std::unordered_map<u16, ClientActiveObject*> ClientActiveObjectMap;
class ClientEnvironment : public Environment class ClientEnvironment : public Environment
{ {
public: public:
ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr, ClientEnvironment(ClientMap *map, ITextureSource *texturesource, Client *client);
ITextureSource *texturesource, Client *client);
~ClientEnvironment(); ~ClientEnvironment();
Map & getMap(); Map & getMap();
@ -175,7 +174,6 @@ public:
private: private:
ClientMap *m_map; ClientMap *m_map;
LocalPlayer *m_local_player = nullptr; LocalPlayer *m_local_player = nullptr;
scene::ISceneManager *m_smgr;
ITextureSource *m_texturesource; ITextureSource *m_texturesource;
Client *m_client; Client *m_client;
ClientScripting *m_script = nullptr; ClientScripting *m_script = nullptr;

@ -31,16 +31,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "camera.h" // CameraModes #include "camera.h" // CameraModes
#include "util/basic_macros.h" #include "util/basic_macros.h"
#include <algorithm> #include <algorithm>
#include "client/renderingengine.h"
ClientMap::ClientMap( ClientMap::ClientMap(
Client *client, Client *client,
MapDrawControl &control, MapDrawControl &control,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id s32 id
): ):
Map(dout_client, client), 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_client(client),
m_control(control), m_control(control),
m_camera_position(0,0,0), m_camera_position(0,0,0),

@ -59,8 +59,6 @@ public:
ClientMap( ClientMap(
Client *client, Client *client,
MapDrawControl &control, MapDrawControl &control,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id s32 id
); );

@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "client/renderingengine.h"
#include "clouds.h" #include "clouds.h"
#include "noise.h" #include "noise.h"
#include "constants.h" #include "constants.h"
@ -36,14 +37,12 @@ static void cloud_3d_setting_changed(const std::string &settingname, void *data)
((Clouds *)data)->readSettings(); ((Clouds *)data)->readSettings();
} }
Clouds::Clouds( Clouds::Clouds(scene::ISceneManager* mgr,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id, s32 id,
u32 seed, u32 seed,
s16 cloudheight s16 cloudheight
): ):
scene::ISceneNode(parent, mgr, id), scene::ISceneNode(mgr->getRootSceneNode(), mgr, id),
m_seed(seed) m_seed(seed)
{ {
m_material.setFlag(video::EMF_LIGHTING, false); m_material.setFlag(video::EMF_LIGHTING, false);

@ -36,9 +36,7 @@ extern irr::scene::ISceneManager *g_menucloudsmgr;
class Clouds : public scene::ISceneNode class Clouds : public scene::ISceneNode
{ {
public: public:
Clouds( Clouds(scene::ISceneManager* mgr,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id, s32 id,
u32 seed, u32 seed,
s16 cloudheight=0 s16 cloudheight=0

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/tile.h" #include "client/tile.h"
#include "mesh.h" #include "mesh.h"
#include <IMeshManipulator.h> #include <IMeshManipulator.h>
#include "client/renderingengine.h"
#include "client.h" #include "client.h"
#include "log.h" #include "log.h"
#include "noise.h" #include "noise.h"
@ -64,8 +65,7 @@ MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector
collector = output; collector = output;
nodedef = data->m_client->ndef(); nodedef = data->m_client->ndef();
smgr = data->m_client->getSceneManager(); meshmanip = RenderingEngine::get_scene_manager()->getMeshManipulator();
meshmanip = smgr->getMeshManipulator();
enable_mesh_cache = g_settings->getBool("enable_mesh_cache") && enable_mesh_cache = g_settings->getBool("enable_mesh_cache") &&
!data->m_smooth_lighting; // Mesh cache is not supported with smooth lighting !data->m_smooth_lighting; // Mesh cache is not supported with smooth lighting

@ -39,7 +39,6 @@ public:
MeshCollector *collector; MeshCollector *collector;
INodeDefManager *nodedef; INodeDefManager *nodedef;
scene::ISceneManager *smgr;
scene::IMeshManipulator *meshmanip; scene::IMeshManipulator *meshmanip;
// options // options

@ -1,674 +0,0 @@
/*
Minetest
Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "drawscene.h"
#include "settings.h"
#include "clouds.h"
#include "clientmap.h"
#include "util/timetaker.h"
#include "fontengine.h"
#include "guiscalingfilter.h"
#include "filesys.h"
typedef enum {
LEFT = -1,
RIGHT = 1,
EYECOUNT = 2
} paralax_sign;
void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
video::IVideoDriver* driver, scene::ISceneManager* smgr,
bool draw_wield_tool, Client& client,
gui::IGUIEnvironment* guienv )
{
/* preserve old setup*/
irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
irr::core::matrix4 startMatrix =
camera.getCameraNode()->getAbsoluteTransformation();
irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
- camera.getCameraNode()->getAbsolutePosition()).setLength(1)
+ camera.getCameraNode()->getAbsolutePosition();
//Left eye...
irr::core::vector3df leftEye;
irr::core::matrix4 leftMove;
leftMove.setTranslation(
irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
0.0f, 0.0f));
leftEye = (startMatrix * leftMove).getTranslation();
//clear the depth buffer, and color
driver->beginScene( true, true, irr::video::SColor(0, 200, 200, 255));
driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_RED;
driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
+ irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
+ irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
camera.getCameraNode()->setPosition(leftEye);
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (show_hud) {
hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&leftMove);
}
guienv->drawAll();
//Right eye...
irr::core::vector3df rightEye;
irr::core::matrix4 rightMove;
rightMove.setTranslation(
irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
0.0f, 0.0f));
rightEye = (startMatrix * rightMove).getTranslation();
//clear the depth buffer
driver->clearZBuffer();
driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_GREEN
+ irr::video::ECP_BLUE;
driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
+ irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
+ irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
camera.getCameraNode()->setPosition(rightEye);
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (show_hud) {
hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&rightMove);
}
guienv->drawAll();
driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_ALL;
driver->getOverrideMaterial().EnableFlags = 0;
driver->getOverrideMaterial().EnablePasses = 0;
camera.getCameraNode()->setPosition(oldPosition);
camera.getCameraNode()->setTarget(oldTarget);
}
void init_texture(video::IVideoDriver* driver, const v2u32& screensize,
video::ITexture** texture, const char* name)
{
if (*texture != NULL)
{
driver->removeTexture(*texture);
}
*texture = driver->addRenderTargetTexture(
core::dimension2d<u32>(screensize.X, screensize.Y), name,
irr::video::ECF_A8R8G8B8);
}
video::ITexture* draw_image(const v2u32 &screensize,
paralax_sign psign, const irr::core::matrix4 &startMatrix,
const irr::core::vector3df &focusPoint, bool show_hud,
video::IVideoDriver *driver, Camera &camera, scene::ISceneManager *smgr,
Hud &hud, bool draw_wield_tool, Client &client,
gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
{
static video::ITexture* images[2] = { NULL, NULL };
static v2u32 last_screensize = v2u32(0, 0);
video::ITexture* image = NULL;
if (screensize != last_screensize) {
init_texture(driver, screensize, &images[1], "mt_drawimage_img1");
init_texture(driver, screensize, &images[0], "mt_drawimage_img2");
last_screensize = screensize;
}
if (psign == RIGHT)
image = images[1];
else
image = images[0];
driver->setRenderTarget(image, true, true,
irr::video::SColor(255,
skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
irr::core::vector3df eye_pos;
irr::core::matrix4 movement;
movement.setTranslation(
irr::core::vector3df((int) psign *
g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
eye_pos = (startMatrix * movement).getTranslation();
//clear the depth buffer
driver->clearZBuffer();
camera.getCameraNode()->setPosition(eye_pos);
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (show_hud) {
hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&movement);
}
guienv->drawAll();
/* switch back to real renderer */
driver->setRenderTarget(0, true, true,
irr::video::SColor(0,
skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
return image;
}
video::ITexture* draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
bool show_hud, Hud& hud, Client& client, bool draw_crosshair,
video::SColor skycolor, gui::IGUIEnvironment* guienv, Camera& camera )
{
static video::ITexture* image = NULL;
init_texture(driver, screensize, &image, "mt_drawimage_hud");
driver->setRenderTarget(image, true, true,
irr::video::SColor(255,0,0,0));
if (show_hud)
{
if (draw_crosshair)
hud.drawCrosshair();
hud.drawHotbar(client.getPlayerItem());
hud.drawLuaElements(camera.getOffset());
camera.drawNametags();
guienv->drawAll();
}
driver->setRenderTarget(0, true, true,
irr::video::SColor(0,
skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
return image;
}
void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
{
/* save current info */
irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
irr::core::matrix4 startMatrix =
camera.getCameraNode()->getAbsoluteTransformation();
irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
- camera.getCameraNode()->getAbsolutePosition()).setLength(1)
+ camera.getCameraNode()->getAbsolutePosition();
/* create left view */
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
//Right eye...
irr::core::vector3df rightEye;
irr::core::matrix4 rightMove;
rightMove.setTranslation(
irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
0.0f, 0.0f));
rightEye = (startMatrix * rightMove).getTranslation();
//clear the depth buffer
driver->clearZBuffer();
camera.getCameraNode()->setPosition(rightEye);
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (show_hud) {
hud.drawSelectionMesh();
if(draw_wield_tool)
camera.drawWieldedTool(&rightMove);
}
guienv->drawAll();
for (unsigned int i = 0; i < screensize.Y; i+=2 ) {
#if (IRRLICHT_VERSION_MAJOR >= 1) && (IRRLICHT_VERSION_MINOR >= 8)
driver->draw2DImage(left_image, irr::core::position2d<s32>(0, i),
#else
driver->draw2DImage(left_image, irr::core::position2d<s32>(0, screensize.Y-i),
#endif
irr::core::rect<s32>(0, i,screensize.X, i+1), 0,
irr::video::SColor(255, 255, 255, 255),
false);
}
/* cleanup */
camera.getCameraNode()->setPosition(oldPosition);
camera.getCameraNode()->setTarget(oldTarget);
}
void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
{
/* save current info */
irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
irr::core::matrix4 startMatrix =
camera.getCameraNode()->getAbsoluteTransformation();
irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
- camera.getCameraNode()->getAbsolutePosition()).setLength(1)
+ camera.getCameraNode()->getAbsolutePosition();
/* create left view */
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
/* create right view */
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
/* create hud overlay */
video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
false, skycolor, guienv, camera );
driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
//makeColorKeyTexture mirrors texture so we do it twice to get it right again
driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
draw2DImageFilterScaled(driver, left_image,
irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
draw2DImageFilterScaled(driver, hudtexture,
irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
draw2DImageFilterScaled(driver, right_image,
irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
draw2DImageFilterScaled(driver, hudtexture,
irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
left_image = NULL;
right_image = NULL;
/* cleanup */
camera.getCameraNode()->setPosition(oldPosition);
camera.getCameraNode()->setTarget(oldTarget);
}
void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
{
/* save current info */
irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
irr::core::matrix4 startMatrix =
camera.getCameraNode()->getAbsoluteTransformation();
irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
- camera.getCameraNode()->getAbsolutePosition()).setLength(1)
+ camera.getCameraNode()->getAbsolutePosition();
/* create left view */
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
/* create right view */
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
focusPoint, show_hud, driver, camera, smgr, hud,
draw_wield_tool, client, guienv, skycolor);
/* create hud overlay */
video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
false, skycolor, guienv, camera );
driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
//makeColorKeyTexture mirrors texture so we do it twice to get it right again
driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
draw2DImageFilterScaled(driver, left_image,
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
draw2DImageFilterScaled(driver, hudtexture,
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
draw2DImageFilterScaled(driver, right_image,
irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
draw2DImageFilterScaled(driver, hudtexture,
irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
left_image = NULL;
right_image = NULL;
/* cleanup */
camera.getCameraNode()->setPosition(oldPosition);
camera.getCameraNode()->setTarget(oldTarget);
}
void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor)
{
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
errorstream << "Pageflip 3D mode is not supported"
<< " with your Irrlicht version!" << std::endl;
#else
/* preserve old setup*/
irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
irr::core::matrix4 startMatrix =
camera.getCameraNode()->getAbsoluteTransformation();
irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
- camera.getCameraNode()->getAbsolutePosition()).setLength(1)
+ camera.getCameraNode()->getAbsolutePosition();
//Left eye...
driver->setRenderTarget(irr::video::ERT_STEREO_LEFT_BUFFER);
irr::core::vector3df leftEye;
irr::core::matrix4 leftMove;
leftMove.setTranslation(
irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
0.0f, 0.0f));
leftEye = (startMatrix * leftMove).getTranslation();
//clear the depth buffer, and color
driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
camera.getCameraNode()->setPosition(leftEye);
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (show_hud) {
hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&leftMove);
hud.drawHotbar(client.getPlayerItem());
hud.drawLuaElements(camera.getOffset());
camera.drawNametags();
}
guienv->drawAll();
//Right eye...
driver->setRenderTarget(irr::video::ERT_STEREO_RIGHT_BUFFER);
irr::core::vector3df rightEye;
irr::core::matrix4 rightMove;
rightMove.setTranslation(
irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
0.0f, 0.0f));
rightEye = (startMatrix * rightMove).getTranslation();
//clear the depth buffer, and color
driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
camera.getCameraNode()->setPosition(rightEye);
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (show_hud) {
hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&rightMove);
hud.drawHotbar(client.getPlayerItem());
hud.drawLuaElements(camera.getOffset());
camera.drawNametags();
}
guienv->drawAll();
camera.getCameraNode()->setPosition(oldPosition);
camera.getCameraNode()->setTarget(oldTarget);
#endif
}
// returns (size / coef), rounded upwards
inline int scaledown(int coef, int size)
{
return (size + coef - 1) / coef;
}
void draw_plain(Camera &camera, bool show_hud,
Hud &hud, video::IVideoDriver *driver,
scene::ISceneManager *smgr, const v2u32 &screensize,
bool draw_wield_tool, Client &client, gui::IGUIEnvironment *guienv,
video::SColor skycolor)
{
// Undersampling-specific stuff
static video::ITexture *image = NULL;
static v2u32 last_pixelated_size = v2u32(0, 0);
static thread_local int undersampling = g_settings->getU16("undersampling");
v2u32 pixelated_size;
v2u32 dest_size;
if (undersampling > 0) {
pixelated_size = v2u32(scaledown(undersampling, screensize.X),
scaledown(undersampling, screensize.Y));
dest_size = v2u32(undersampling * pixelated_size.X, undersampling * pixelated_size.Y);
if (pixelated_size != last_pixelated_size) {
init_texture(driver, pixelated_size, &image, "mt_drawimage_img1");
last_pixelated_size = pixelated_size;
}
driver->setRenderTarget(image, true, true, skycolor);
}
// Render
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (show_hud) {
hud.drawSelectionMesh();
if (draw_wield_tool) {
camera.drawWieldedTool();
}
}
// Upscale lowres render
if (undersampling > 0) {
driver->setRenderTarget(0, true, true);
driver->draw2DImage(image,
irr::core::rect<s32>(0, 0, dest_size.X, dest_size.Y),
irr::core::rect<s32>(0, 0, pixelated_size.X, pixelated_size.Y));
}
}
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
Camera &camera, Client &client, LocalPlayer *player, Hud &hud,
Minimap *mapper, gui::IGUIEnvironment *guienv,
const v2u32 &screensize, const video::SColor &skycolor,
bool show_hud, bool show_minimap)
{
TimeTaker timer("smgr");
bool draw_wield_tool = (show_hud &&
(player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
camera.getCameraMode() < CAMERA_MODE_THIRD );
bool draw_crosshair = ((player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
(camera.getCameraMode() != CAMERA_MODE_THIRD_FRONT));
#ifdef HAVE_TOUCHSCREENGUI
try {
draw_crosshair = !g_settings->getBool("touchtarget");
}
catch(SettingNotFoundException) {}
#endif
const std::string &draw_mode = g_settings->get("3d_mode");
if (draw_mode == "anaglyph")
{
draw_anaglyph_3d_mode(camera, show_hud, hud, driver,
smgr, draw_wield_tool, client, guienv);
draw_crosshair = false;
}
else if (draw_mode == "interlaced")
{
draw_interlaced_3d_mode(camera, show_hud, hud, driver,
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
draw_crosshair = false;
}
else if (draw_mode == "sidebyside")
{
draw_sidebyside_3d_mode(camera, show_hud, hud, driver,
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
show_hud = false;
}
else if (draw_mode == "topbottom")
{
draw_top_bottom_3d_mode(camera, show_hud, hud, driver,
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
show_hud = false;
}
else if (draw_mode == "pageflip")
{
draw_pageflip_3d_mode(camera, show_hud, hud, driver,
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
draw_crosshair = false;
show_hud = false;
}
else {
draw_plain(camera, show_hud, hud, driver,
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
}
/*
Post effects
*/
{
client.getEnv().getClientMap().renderPostFx(camera.getCameraMode());
}
//TODO how to make those 3d too
if (show_hud)
{
if (draw_crosshair)
hud.drawCrosshair();
hud.drawHotbar(client.getPlayerItem());
hud.drawLuaElements(camera.getOffset());
camera.drawNametags();
if (mapper && show_minimap)
mapper->drawMinimap();
}
guienv->drawAll();
timer.stop(true);
}
/*
Draws a screen with a single text on it.
Text will be removed when the screen is drawn the next time.
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
*/
void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
gui::IGUIEnvironment* guienv, ITextureSource *tsrc,
float dtime, int percent, bool clouds)
{
video::IVideoDriver* driver = device->getVideoDriver();
v2u32 screensize = porting::getWindowSize();
v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight());
v2s32 center(screensize.X / 2, screensize.Y / 2);
core::rect<s32> textrect(center - textsize / 2, center + textsize / 2);
gui::IGUIStaticText *guitext = guienv->addStaticText(
text.c_str(), textrect, false, false);
guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
if (cloud_menu_background)
{
g_menuclouds->step(dtime*3);
g_menuclouds->render();
driver->beginScene(true, true, video::SColor(255, 140, 186, 250));
g_menucloudsmgr->drawAll();
}
else
driver->beginScene(true, true, video::SColor(255, 0, 0, 0));
// draw progress bar
if ((percent >= 0) && (percent <= 100)) {
video::ITexture *progress_img = tsrc->getTexture("progress_bar.png");
video::ITexture *progress_img_bg = tsrc->getTexture("progress_bar_bg.png");
if (progress_img && progress_img_bg) {
#ifndef __ANDROID__
const core::dimension2d<u32> &img_size = progress_img_bg->getSize();
u32 imgW = rangelim(img_size.Width, 200, 600);
u32 imgH = rangelim(img_size.Height, 24, 72);
#else
const core::dimension2d<u32> img_size(256, 48);
float imgRatio = (float) img_size.Height / img_size.Width;
u32 imgW = screensize.X / 2.2f;
u32 imgH = floor(imgW * imgRatio);
#endif
v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2);
draw2DImageFilterScaled(
driver, progress_img_bg,
core::rect<s32>(img_pos.X,
img_pos.Y,
img_pos.X + imgW,
img_pos.Y + imgH),
core::rect<s32>(0, 0,
img_size.Width,
img_size.Height),
0, 0, true);
draw2DImageFilterScaled(
driver, progress_img,
core::rect<s32>(img_pos.X,
img_pos.Y,
img_pos.X + (percent * imgW) / 100,
img_pos.Y + imgH),
core::rect<s32>(0, 0,
(percent * img_size.Width) / 100,
img_size.Height),
0, 0, true);
}
}
guienv->drawAll();
driver->endScene();
guitext->remove();
//return guitext;
}

@ -1,39 +0,0 @@
/*
Minetest
Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef DRAWSCENE_H_
#define DRAWSCENE_H_
#include "camera.h"
#include "hud.h"
#include "minimap.h"
#include "irrlichttypes_extrabloated.h"
void draw_load_screen(const std::wstring &text, IrrlichtDevice *device,
gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime = 0,
int percent = 0, bool clouds = true);
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
Camera &camera, Client &client, LocalPlayer *player,
Hud &hud, Minimap *mapper, gui::IGUIEnvironment *guienv,
const v2u32 &screensize, const video::SColor &skycolor,
bool show_hud, bool show_minimap);
#endif /* DRAWSCENE_H_ */

@ -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., with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "fontengine.h" #include "fontengine.h"
#include "log.h" #include "client/renderingengine.h"
#include "config.h" #include "config.h"
#include "porting.h" #include "porting.h"
#include "constants.h"
#include "filesys.h" #include "filesys.h"
#if USE_FREETYPE #if USE_FREETYPE
@ -314,10 +314,8 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
if (! is_yes(m_settings->get("freetype"))) { if (! is_yes(m_settings->get("freetype"))) {
return; return;
} }
unsigned int size = floor( unsigned int size = floor(RenderingEngine::getDisplayDensity() *
porting::getDisplayDensity() * m_settings->getFloat("gui_scaling") * basesize);
m_settings->getFloat("gui_scaling") *
basesize);
u32 font_shadow = 0; u32 font_shadow = 0;
u32 font_shadow_alpha = 0; u32 font_shadow_alpha = 0;
@ -395,7 +393,7 @@ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
basesize = DEFAULT_FONT_SIZE; basesize = DEFAULT_FONT_SIZE;
unsigned int size = floor( unsigned int size = floor(
porting::getDisplayDensity() * RenderingEngine::getDisplayDensity() *
m_settings->getFloat("gui_scaling") * m_settings->getFloat("gui_scaling") *
basesize); basesize);

@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "game.h" #include "game.h"
#include <iomanip> #include <iomanip>
#include "client/renderingengine.h"
#include "camera.h" #include "camera.h"
#include "client.h" #include "client.h"
#include "client/inputhandler.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 "clouds.h"
#include "config.h" #include "config.h"
#include "content_cao.h" #include "content_cao.h"
#include "drawscene.h"
#include "event_manager.h" #include "event_manager.h"
#include "fontengine.h" #include "fontengine.h"
#include "itemdef.h" #include "itemdef.h"
@ -44,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiVolumeChange.h" #include "guiVolumeChange.h"
#include "mainmenumanager.h" #include "mainmenumanager.h"
#include "mapblock.h" #include "mapblock.h"
#include "minimap.h"
#include "nodedef.h" // Needed for determining pointing to nodes #include "nodedef.h" // Needed for determining pointing to nodes
#include "nodemetadata.h" #include "nodemetadata.h"
#include "particles.h" #include "particles.h"
@ -152,6 +153,9 @@ struct LocalFormspecHandler : public TextDest
if (fields.find("btn_exit_os") != fields.end()) { if (fields.find("btn_exit_os") != fields.end()) {
g_gamecallback->exitToOS(); g_gamecallback->exitToOS();
#ifndef __ANDROID__
RenderingEngine::get_raw_device()->closeDevice();
#endif
return; return;
} }
@ -726,7 +730,6 @@ public:
minimap_yaw.getAs3Values(minimap_yaw_array); minimap_yaw.getAs3Values(minimap_yaw_array);
#endif #endif
m_minimap_yaw.set(minimap_yaw_array, services); m_minimap_yaw.set(minimap_yaw_array, services);
} }
SamplerLayer_t base_tex = 0, SamplerLayer_t base_tex = 0,
@ -924,14 +927,13 @@ bool nodePlacementPrediction(Client &client, const ItemDefinition &playeritem_de
} }
static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec, static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec,
Client *client, IrrlichtDevice *device, JoystickController *joystick, Client *client, JoystickController *joystick,
IFormSource *fs_src, TextDest *txt_dest) IFormSource *fs_src, TextDest *txt_dest)
{ {
if (*cur_formspec == 0) { if (*cur_formspec == 0) {
*cur_formspec = new GUIFormSpecMenu(device, joystick, *cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
guiroot, -1, &g_menumgr, client, client->getTextureSource(), client, client->getTextureSource(), fs_src, txt_dest);
fs_src, txt_dest);
(*cur_formspec)->doPause = false; (*cur_formspec)->doPause = false;
/* /*
@ -996,9 +998,10 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
chat_y += 2 * line_height; chat_y += 2 * line_height;
// first pass to calculate height of text to be set // first pass to calculate height of text to be set
const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
s32 width = std::min(g_fontengine->getTextWidth(recent_chat.c_str()) + 10, s32 width = std::min(g_fontengine->getTextWidth(recent_chat.c_str()) + 10,
porting::getWindowSize().X - 20); window_size.X - 20);
core::rect<s32> rect(10, chat_y, width, chat_y + porting::getWindowSize().Y); core::rect<s32> rect(10, chat_y, width, chat_y + window_size.Y);
guitext_chat->setRelativePosition(rect); guitext_chat->setRelativePosition(rect);
//now use real height of text and adjust rect according to this size //now use real height of text and adjust rect according to this size
@ -1200,7 +1203,6 @@ public:
bool startup(bool *kill, bool startup(bool *kill,
bool random_input, bool random_input,
InputHandler *input, InputHandler *input,
IrrlichtDevice *device,
const std::string &map_dir, const std::string &map_dir,
const std::string &playername, const std::string &playername,
const std::string &password, const std::string &password,
@ -1584,7 +1586,6 @@ Game::~Game()
bool Game::startup(bool *kill, bool Game::startup(bool *kill,
bool random_input, bool random_input,
InputHandler *input, InputHandler *input,
IrrlichtDevice *device,
const std::string &map_dir, const std::string &map_dir,
const std::string &playername, const std::string &playername,
const std::string &password, const std::string &password,
@ -1597,7 +1598,7 @@ bool Game::startup(bool *kill,
bool simple_singleplayer_mode) bool simple_singleplayer_mode)
{ {
// "cache" // "cache"
this->device = device; this->device = RenderingEngine::get_raw_device();
this->kill = kill; this->kill = kill;
this->error_message = &error_message; this->error_message = &error_message;
this->reconnect_requested = reconnect; this->reconnect_requested = reconnect;
@ -1609,10 +1610,11 @@ bool Game::startup(bool *kill,
keycache.handler = input; keycache.handler = input;
keycache.populate(); keycache.populate();
driver = device->getVideoDriver(); driver = device->getVideoDriver();
smgr = device->getSceneManager(); 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)); memset(&runData, 0, sizeof(runData));
runData.time_from_last_punch = 10.0; runData.time_from_last_punch = 10.0;
@ -1649,7 +1651,7 @@ void Game::run()
Profiler::GraphValues dummyvalues; Profiler::GraphValues dummyvalues;
g_profiler->graphGet(dummyvalues); g_profiler->graphGet(dummyvalues);
draw_times.last_time = device->getTimer()->getTime(); draw_times.last_time = RenderingEngine::get_timer_time();
set_light_table(g_settings->getFloat("display_gamma")); set_light_table(g_settings->getFloat("display_gamma"));
@ -1661,12 +1663,12 @@ void Game::run()
irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"), irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"),
g_settings->getU16("screen_h")); g_settings->getU16("screen_h"));
while (device->run() while (RenderingEngine::run()
&& !(*kill || g_gamecallback->shutdown_requested && !(*kill || g_gamecallback->shutdown_requested
|| (server && server->getShutdownRequested()))) { || (server && server->getShutdownRequested()))) {
const irr::core::dimension2d<u32> &current_screen_size = const irr::core::dimension2d<u32> &current_screen_size =
device->getVideoDriver()->getScreenSize(); RenderingEngine::get_video_driver()->getScreenSize();
// Verify if window size has changed and save it if it's the case // Verify if window size has changed and save it if it's the case
// Ensure evaluating settings->getBool after verifying screensize // Ensure evaluating settings->getBool after verifying screensize
// First condition is cheaper // First condition is cheaper
@ -1779,11 +1781,11 @@ bool Game::init(
u16 port, u16 port,
const SubgameSpec &gamespec) const SubgameSpec &gamespec)
{ {
texture_src = createTextureSource(device); texture_src = createTextureSource();
showOverlayMessage("Loading...", 0, 0); showOverlayMessage("Loading...", 0, 0);
shader_src = createShaderSource(device); shader_src = createShaderSource();
itemdef_manager = createItemDefManager(); itemdef_manager = createItemDefManager();
nodedef_manager = createNodeDefManager(); nodedef_manager = createNodeDefManager();
@ -1908,7 +1910,7 @@ bool Game::createClient(const std::string &playername,
shader_src->addShaderConstantSetterFactory(scsf); shader_src->addShaderConstantSetterFactory(scsf);
// Update cached textures, meshes and materials // Update cached textures, meshes and materials
client->afterContentReceived(device); client->afterContentReceived();
/* Camera /* Camera
*/ */
@ -1920,7 +1922,7 @@ bool Game::createClient(const std::string &playername,
/* Clouds /* Clouds
*/ */
if (m_cache_enable_clouds) { if (m_cache_enable_clouds) {
clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, time(0)); clouds = new Clouds(smgr, -1, time(0));
if (!clouds) { if (!clouds) {
*error_message = "Memory allocation error (clouds)"; *error_message = "Memory allocation error (clouds)";
errorstream << *error_message << std::endl; errorstream << *error_message << std::endl;
@ -1930,7 +1932,7 @@ bool Game::createClient(const std::string &playername,
/* Skybox /* Skybox
*/ */
sky = new Sky(smgr->getRootSceneNode(), smgr, -1, texture_src); sky = new Sky(-1, texture_src);
scsf->setSky(sky); scsf->setSky(sky);
skybox = NULL; // This is used/set later on in the main run loop skybox = NULL; // This is used/set later on in the main run loop
@ -2091,8 +2093,7 @@ bool Game::connectToServer(const std::string &playername,
return false; return false;
} }
client = new Client(device, client = new Client(playername.c_str(), password, *address,
playername.c_str(), password, *address,
*draw_control, texture_src, shader_src, *draw_control, texture_src, shader_src,
itemdef_manager, nodedef_manager, sound, eventmgr, itemdef_manager, nodedef_manager, sound, eventmgr,
connect_address.isIPv6(), &flags); connect_address.isIPv6(), &flags);
@ -2118,11 +2119,11 @@ bool Game::connectToServer(const std::string &playername,
f32 dtime; f32 dtime;
f32 wait_time = 0; // in seconds f32 wait_time = 0; // in seconds
fps_control.last_time = device->getTimer()->getTime(); fps_control.last_time = RenderingEngine::get_timer_time();
client->initMods(); client->initMods();
while (device->run()) { while (RenderingEngine::run()) {
limitFps(&fps_control, &dtime); limitFps(&fps_control, &dtime);
@ -2199,9 +2200,9 @@ bool Game::getServerContent(bool *aborted)
FpsControl fps_control = { 0 }; FpsControl fps_control = { 0 };
f32 dtime; // in seconds f32 dtime; // in seconds
fps_control.last_time = device->getTimer()->getTime(); fps_control.last_time = RenderingEngine::get_timer_time();
while (device->run()) { while (RenderingEngine::run()) {
limitFps(&fps_control, &dtime); limitFps(&fps_control, &dtime);
@ -2239,13 +2240,13 @@ bool Game::getServerContent(bool *aborted)
if (!client->itemdefReceived()) { if (!client->itemdefReceived()) {
const wchar_t *text = wgettext("Item definitions..."); const wchar_t *text = wgettext("Item definitions...");
progress = 25; progress = 25;
draw_load_screen(text, device, guienv, texture_src, RenderingEngine::draw_load_screen(text, guienv, texture_src,
dtime, progress); dtime, progress);
delete[] text; delete[] text;
} else if (!client->nodedefReceived()) { } else if (!client->nodedefReceived()) {
const wchar_t *text = wgettext("Node definitions..."); const wchar_t *text = wgettext("Node definitions...");
progress = 30; progress = 30;
draw_load_screen(text, device, guienv, texture_src, RenderingEngine::draw_load_screen(text, guienv, texture_src,
dtime, progress); dtime, progress);
delete[] text; delete[] text;
} else { } else {
@ -2269,8 +2270,8 @@ bool Game::getServerContent(bool *aborted)
} }
progress = 30 + client->mediaReceiveProgress() * 35 + 0.5; progress = 30 + client->mediaReceiveProgress() * 35 + 0.5;
draw_load_screen(utf8_to_wide(message.str()), device, RenderingEngine::draw_load_screen(utf8_to_wide(message.str()), guienv,
guienv, texture_src, dtime, progress); texture_src, dtime, progress);
} }
} }
@ -2676,7 +2677,7 @@ void Game::openInventory()
PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(client); PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(client);
TextDest *txt_dst = new TextDestPlayerInventory(client); TextDest *txt_dst = new TextDestPlayerInventory(client);
create_formspec_menu(&current_formspec, client, device, &input->joystick, fs_src, txt_dst); create_formspec_menu(&current_formspec, client, &input->joystick, fs_src, txt_dst);
cur_formname = ""; cur_formname = "";
InventoryLocation inventoryloc; InventoryLocation inventoryloc;
@ -3178,7 +3179,7 @@ void Game::processClientEvents(CameraOrientation *cam)
TextDestPlayerInventory *txt_dst = TextDestPlayerInventory *txt_dst =
new TextDestPlayerInventory(client, *(event.show_formspec.formname)); new TextDestPlayerInventory(client, *(event.show_formspec.formname));
create_formspec_menu(&current_formspec, client, device, &input->joystick, create_formspec_menu(&current_formspec, client, &input->joystick,
fs_src, txt_dst); fs_src, txt_dst);
cur_formname = *(event.show_formspec.formname); cur_formname = *(event.show_formspec.formname);
} }
@ -3191,7 +3192,7 @@ void Game::processClientEvents(CameraOrientation *cam)
{ {
FormspecFormSource *fs_src = new FormspecFormSource(*event.show_formspec.formspec); FormspecFormSource *fs_src = new FormspecFormSource(*event.show_formspec.formspec);
LocalFormspecHandler *txt_dst = new LocalFormspecHandler(*event.show_formspec.formname, client); LocalFormspecHandler *txt_dst = new LocalFormspecHandler(*event.show_formspec.formname, client);
create_formspec_menu(&current_formspec, client, device, &input->joystick, create_formspec_menu(&current_formspec, client, &input->joystick,
fs_src, txt_dst); fs_src, txt_dst);
} }
delete event.show_formspec.formspec; delete event.show_formspec.formspec;
@ -3201,8 +3202,7 @@ void Game::processClientEvents(CameraOrientation *cam)
case CE_SPAWN_PARTICLE: case CE_SPAWN_PARTICLE:
case CE_ADD_PARTICLESPAWNER: case CE_ADD_PARTICLESPAWNER:
case CE_DELETE_PARTICLESPAWNER: case CE_DELETE_PARTICLESPAWNER:
client->getParticleManager()->handleParticleEvent(&event, client, client->getParticleManager()->handleParticleEvent(&event, client, player);
smgr, player);
break; break;
case CE_HUDADD: case CE_HUDADD:
@ -3343,7 +3343,7 @@ void Game::processClientEvents(CameraOrientation *cam)
} else if (*event.set_sky.type == "skybox" && } else if (*event.set_sky.type == "skybox" &&
event.set_sky.params->size() == 6) { event.set_sky.params->size() == 6) {
sky->setFallbackBgColor(*event.set_sky.bgcolor); 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)[0]),
texture_src->getTextureForMesh((*event.set_sky.params)[1]), texture_src->getTextureForMesh((*event.set_sky.params)[1]),
texture_src->getTextureForMesh((*event.set_sky.params)[2]), 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); TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
create_formspec_menu(&current_formspec, client, create_formspec_menu(&current_formspec, client,
device, &input->joystick, fs_src, txt_dst); &input->joystick, fs_src, txt_dst);
cur_formname = ""; cur_formname = "";
current_formspec->setFormSpec(meta->getString("formspec"), inventoryloc); 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; runData.dig_time_complete = params.time;
if (m_cache_enable_particles) { if (m_cache_enable_particles) {
const ContentFeatures &features = const ContentFeatures &features = client->getNodeDefManager()->get(n);
client->getNodeDefManager()->get(n); client->getParticleManager()->addPunchingParticles(client,
client->getParticleManager()->addPunchingParticles(client, smgr,
player, nodepos, n, features); player, nodepos, n, features);
} }
} }
@ -4019,7 +4018,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
if (m_cache_enable_particles) { if (m_cache_enable_particles) {
const ContentFeatures &features = const ContentFeatures &features =
client->getNodeDefManager()->get(wasnode); client->getNodeDefManager()->get(wasnode);
client->getParticleManager()->addDiggingParticles(client, smgr, client->getParticleManager()->addDiggingParticles(client,
player, nodepos, wasnode, features); player, nodepos, wasnode, features);
} }
@ -4227,7 +4226,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
TimeTaker tt_draw("mainloop: draw"); TimeTaker tt_draw("mainloop: draw");
driver->beginScene(true, true, skycolor); 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, guienv, screensize, skycolor, flags.show_hud,
flags.show_minimap); flags.show_minimap);
@ -4466,11 +4465,10 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
fps_timings->last_time = time; fps_timings->last_time = time;
} }
void Game::showOverlayMessage(const char *msg, float dtime, void Game::showOverlayMessage(const char *msg, float dtime, int percent, bool draw_clouds)
int percent, bool draw_clouds)
{ {
const wchar_t *wmsg = wgettext(msg); const wchar_t *wmsg = wgettext(msg);
draw_load_screen(wmsg, device, guienv, texture_src, dtime, percent, RenderingEngine::draw_load_screen(wmsg, guienv, texture_src, dtime, percent,
draw_clouds); draw_clouds);
delete[] wmsg; delete[] wmsg;
} }
@ -4519,7 +4517,7 @@ void Game::extendedResourceCleanup()
// Extended resource accounting // Extended resource accounting
infostream << "Irrlicht resources after cleanup:" << std::endl; infostream << "Irrlicht resources after cleanup:" << std::endl;
infostream << "\tRemaining meshes : " infostream << "\tRemaining meshes : "
<< device->getSceneManager()->getMeshCache()->getMeshCount() << std::endl; << RenderingEngine::get_mesh_cache()->getMeshCount() << std::endl;
infostream << "\tRemaining textures : " infostream << "\tRemaining textures : "
<< driver->getTextureCount() << std::endl; << driver->getTextureCount() << std::endl;
@ -4656,7 +4654,7 @@ void Game::showPauseMenu()
FormspecFormSource *fs_src = new FormspecFormSource(os.str()); FormspecFormSource *fs_src = new FormspecFormSource(os.str());
LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU"); LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
create_formspec_menu(&current_formspec, client, device, &input->joystick, fs_src, txt_dst); create_formspec_menu(&current_formspec, client, &input->joystick, fs_src, txt_dst);
current_formspec->setFocus("btn_continue"); current_formspec->setFocus("btn_continue");
current_formspec->doPause = true; current_formspec->doPause = true;
} }
@ -4670,8 +4668,6 @@ void Game::showPauseMenu()
void the_game(bool *kill, void the_game(bool *kill,
bool random_input, bool random_input,
InputHandler *input, InputHandler *input,
IrrlichtDevice *device,
const std::string &map_dir, const std::string &map_dir,
const std::string &playername, const std::string &playername,
const std::string &password, const std::string &password,
@ -4694,7 +4690,7 @@ void the_game(bool *kill,
try { try {
if (game.startup(kill, random_input, input, device, map_dir, if (game.startup(kill, random_input, input, map_dir,
playername, password, &server_address, port, error_message, playername, password, &server_address, port, error_message,
reconnect_requested, &chat_backend, gamespec, reconnect_requested, &chat_backend, gamespec,
simple_singleplayer_mode)) { simple_singleplayer_mode)) {

@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef GAME_HEADER #ifndef GAME_HEADER
#define GAME_HEADER #define GAME_HEADER
#include "irrlichttypes_extrabloated.h" #include "irrlichttypes.h"
#include <string> #include <string>
class InputHandler; class InputHandler;
@ -42,7 +42,6 @@ struct GameUIFlags
void the_game(bool *kill, void the_game(bool *kill,
bool random_input, bool random_input,
InputHandler *input, InputHandler *input,
IrrlichtDevice *device,
const std::string &map_dir, const std::string &map_dir,
const std::string &playername, const std::string &playername,
const std::string &password, const std::string &password,

@ -19,9 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiEngine.h" #include "guiEngine.h"
#include <fstream>
#include <IGUIStaticText.h> #include <IGUIStaticText.h>
#include <ICameraSceneNode.h> #include <ICameraSceneNode.h>
#include "client/renderingengine.h"
#include "scripting_mainmenu.h" #include "scripting_mainmenu.h"
#include "util/numeric.h" #include "util/numeric.h"
#include "config.h" #include "config.h"
@ -114,17 +114,14 @@ void MenuMusicFetcher::fetchSounds(const std::string &name,
/******************************************************************************/ /******************************************************************************/
/** GUIEngine */ /** GUIEngine */
/******************************************************************************/ /******************************************************************************/
GUIEngine::GUIEngine(irr::IrrlichtDevice *dev, GUIEngine::GUIEngine(JoystickController *joystick,
JoystickController *joystick,
gui::IGUIElement *parent, gui::IGUIElement *parent,
IMenuManager *menumgr, IMenuManager *menumgr,
scene::ISceneManager *smgr,
MainMenuData *data, MainMenuData *data,
bool &kill) : bool &kill) :
m_device(dev),
m_parent(parent), m_parent(parent),
m_menumanager(menumgr), m_menumanager(menumgr),
m_smgr(smgr), m_smgr(RenderingEngine::get_scene_manager()),
m_data(data), m_data(data),
m_kill(kill) m_kill(kill)
{ {
@ -136,7 +133,7 @@ GUIEngine::GUIEngine(irr::IrrlichtDevice *dev,
m_buttonhandler = new TextDestGuiEngine(this); m_buttonhandler = new TextDestGuiEngine(this);
//create texture source //create texture source
m_texture_source = new MenuTextureSource(m_device->getVideoDriver()); m_texture_source = new MenuTextureSource(RenderingEngine::get_video_driver());
//create soundmanager //create soundmanager
MenuMusicFetcher soundfetcher; MenuMusicFetcher soundfetcher;
@ -154,15 +151,14 @@ GUIEngine::GUIEngine(irr::IrrlichtDevice *dev,
rect += v2s32(4, 0); rect += v2s32(4, 0);
m_irr_toplefttext = m_irr_toplefttext =
addStaticText(m_device->getGUIEnvironment(), m_toplefttext, addStaticText(RenderingEngine::get_gui_env(), m_toplefttext,
rect, false, true, 0, -1); rect, false, true, 0, -1);
//create formspecsource //create formspecsource
m_formspecgui = new FormspecFormSource(""); m_formspecgui = new FormspecFormSource("");
/* Create menu */ /* Create menu */
m_menu = new GUIFormSpecMenu(m_device, m_menu = new GUIFormSpecMenu(joystick,
joystick,
m_parent, m_parent,
-1, -1,
m_menumanager, m_menumanager,
@ -229,7 +225,7 @@ void GUIEngine::run()
{ {
// Always create clouds because they may or may not be // Always create clouds because they may or may not be
// needed based on the game selected // needed based on the game selected
video::IVideoDriver* driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
cloudInit(); cloudInit();
@ -238,10 +234,10 @@ void GUIEngine::run()
irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"), irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"),
g_settings->getU16("screen_h")); g_settings->getU16("screen_h"));
while (m_device->run() && (!m_startgame) && (!m_kill)) { while (RenderingEngine::run() && (!m_startgame) && (!m_kill)) {
const irr::core::dimension2d<u32> &current_screen_size = const irr::core::dimension2d<u32> &current_screen_size =
m_device->getVideoDriver()->getScreenSize(); RenderingEngine::get_video_driver()->getScreenSize();
// Verify if window size has changed and save it if it's the case // Verify if window size has changed and save it if it's the case
// Ensure evaluating settings->getBool after verifying screensize // Ensure evaluating settings->getBool after verifying screensize
// First condition is cheaper // First condition is cheaper
@ -272,7 +268,7 @@ void GUIEngine::run()
drawHeader(driver); drawHeader(driver);
drawFooter(driver); drawFooter(driver);
m_device->getGUIEnvironment()->drawAll(); RenderingEngine::get_gui_env()->drawAll();
driver->endScene(); driver->endScene();
@ -292,10 +288,7 @@ void GUIEngine::run()
/******************************************************************************/ /******************************************************************************/
GUIEngine::~GUIEngine() GUIEngine::~GUIEngine()
{ {
video::IVideoDriver* driver = m_device->getVideoDriver(); if (m_sound_manager != &dummySoundManager){
FATAL_ERROR_IF(driver == 0, "Could not get video driver");
if(m_sound_manager != &dummySoundManager){
delete m_sound_manager; delete m_sound_manager;
m_sound_manager = NULL; m_sound_manager = NULL;
} }
@ -308,7 +301,7 @@ GUIEngine::~GUIEngine()
//clean up texture pointers //clean up texture pointers
for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) { for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
if (m_textures[i].texture) if (m_textures[i].texture)
driver->removeTexture(m_textures[i].texture); RenderingEngine::get_video_driver()->removeTexture(m_textures[i].texture);
} }
delete m_texture_source; delete m_texture_source;
@ -320,21 +313,20 @@ GUIEngine::~GUIEngine()
/******************************************************************************/ /******************************************************************************/
void GUIEngine::cloudInit() void GUIEngine::cloudInit()
{ {
m_cloud.clouds = new Clouds(m_smgr->getRootSceneNode(), m_cloud.clouds = new Clouds(m_smgr, -1, rand(), 100);
m_smgr, -1, rand(), 100);
m_cloud.clouds->update(v2f(0, 0), video::SColor(255,200,200,255)); m_cloud.clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
m_cloud.camera = m_smgr->addCameraSceneNode(0, m_cloud.camera = m_smgr->addCameraSceneNode(0,
v3f(0,0,0), v3f(0, 60, 100)); v3f(0,0,0), v3f(0, 60, 100));
m_cloud.camera->setFarValue(10000); m_cloud.camera->setFarValue(10000);
m_cloud.lasttime = m_device->getTimer()->getTime(); m_cloud.lasttime = RenderingEngine::get_timer_time();
} }
/******************************************************************************/ /******************************************************************************/
void GUIEngine::cloudPreProcess() void GUIEngine::cloudPreProcess()
{ {
u32 time = m_device->getTimer()->getTime(); u32 time = RenderingEngine::get_timer_time();
if(time > m_cloud.lasttime) if(time > m_cloud.lasttime)
m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0; m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0;
@ -356,7 +348,7 @@ void GUIEngine::cloudPostProcess()
u32 busytime_u32; u32 busytime_u32;
// not using getRealTime is necessary for wine // not using getRealTime is necessary for wine
u32 time = m_device->getTimer()->getTime(); u32 time = RenderingEngine::get_timer_time();
if(time > m_cloud.lasttime) if(time > m_cloud.lasttime)
busytime_u32 = time - m_cloud.lasttime; busytime_u32 = time - m_cloud.lasttime;
else else
@ -365,9 +357,9 @@ void GUIEngine::cloudPostProcess()
// FPS limiter // FPS limiter
u32 frametime_min = 1000./fps_max; u32 frametime_min = 1000./fps_max;
if(busytime_u32 < frametime_min) { if (busytime_u32 < frametime_min) {
u32 sleeptime = frametime_min - busytime_u32; u32 sleeptime = frametime_min - busytime_u32;
m_device->sleep(sleeptime); RenderingEngine::get_raw_device()->sleep(sleeptime);
} }
} }
@ -502,17 +494,14 @@ void GUIEngine::drawFooter(video::IVideoDriver *driver)
bool GUIEngine::setTexture(texture_layer layer, std::string texturepath, bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
bool tile_image, unsigned int minsize) bool tile_image, unsigned int minsize)
{ {
video::IVideoDriver* driver = m_device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
FATAL_ERROR_IF(driver == 0, "Could not get video driver");
if (m_textures[layer].texture != NULL) if (m_textures[layer].texture) {
{
driver->removeTexture(m_textures[layer].texture); driver->removeTexture(m_textures[layer].texture);
m_textures[layer].texture = NULL; m_textures[layer].texture = NULL;
} }
if ((texturepath == "") || !fs::PathExists(texturepath)) if ((texturepath == "") || !fs::PathExists(texturepath)) {
{
return false; return false;
} }
@ -520,8 +509,7 @@ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
m_textures[layer].tile = tile_image; m_textures[layer].tile = tile_image;
m_textures[layer].minsize = minsize; m_textures[layer].minsize = minsize;
if (m_textures[layer].texture == NULL) if (m_textures[layer].texture == NULL) {
{
return false; return false;
} }
@ -573,7 +561,7 @@ void GUIEngine::updateTopLeftTextSize()
m_irr_toplefttext->remove(); m_irr_toplefttext->remove();
m_irr_toplefttext = m_irr_toplefttext =
addStaticText(m_device->getGUIEnvironment(), m_toplefttext, addStaticText(RenderingEngine::get_gui_env(), m_toplefttext,
rect, false, true, 0, -1); rect, false, true, 0, -1);
} }

@ -150,11 +150,9 @@ public:
* @param smgr scene manager to add scene elements to * @param smgr scene manager to add scene elements to
* @param data struct to transfer data to main game handling * @param data struct to transfer data to main game handling
*/ */
GUIEngine(irr::IrrlichtDevice *dev, GUIEngine(JoystickController *joystick,
JoystickController *joystick,
gui::IGUIElement *parent, gui::IGUIElement *parent,
IMenuManager *menumgr, IMenuManager *menumgr,
scene::ISceneManager *smgr,
MainMenuData *data, MainMenuData *data,
bool &kill); bool &kill);
@ -192,8 +190,6 @@ private:
/** update size of topleftext element */ /** update size of topleftext element */
void updateTopLeftTextSize(); void updateTopLeftTextSize();
/** device to draw at */
irr::IrrlichtDevice *m_device = nullptr;
/** parent gui element */ /** parent gui element */
gui::IGUIElement *m_parent = nullptr; gui::IGUIElement *m_parent = nullptr;
/** manager to add menus to */ /** manager to add menus to */

@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IGUIFont.h> #include <IGUIFont.h>
#include <IGUITabControl.h> #include <IGUITabControl.h>
#include <IGUIComboBox.h> #include <IGUIComboBox.h>
#include "client/renderingengine.h"
#include "log.h" #include "log.h"
#include "client/tile.h" // ITextureSource #include "client/tile.h" // ITextureSource
#include "hud.h" // drawItemStack #include "hud.h" // drawItemStack
@ -78,14 +79,11 @@ static unsigned int font_line_height(gui::IGUIFont *font)
return font->getDimension(L"Ay").Height + font->getKerningHeight(); return font->getDimension(L"Ay").Height + font->getKerningHeight();
} }
GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev, GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
JoystickController *joystick, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, Client *client, ISimpleTextureSource *tsrc, IFormSource *fsrc, TextDest *tdst,
Client *client,
ISimpleTextureSource *tsrc, IFormSource* fsrc, TextDest* tdst,
bool remap_dbl_click) : bool remap_dbl_click) :
GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr), GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr),
m_device(dev),
m_invmgr(client), m_invmgr(client),
m_tsrc(tsrc), m_tsrc(tsrc),
m_client(client), m_client(client),
@ -2054,7 +2052,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
if (mydata.explicit_size) { if (mydata.explicit_size) {
// compute scaling for specified form size // compute scaling for specified form size
if (m_lock) { if (m_lock) {
v2u32 current_screensize = m_device->getVideoDriver()->getScreenSize(); v2u32 current_screensize = RenderingEngine::get_video_driver()->getScreenSize();
v2u32 delta = current_screensize - m_lockscreensize; v2u32 delta = current_screensize - m_lockscreensize;
if (current_screensize.Y > m_lockscreensize.Y) if (current_screensize.Y > m_lockscreensize.Y)
@ -2075,7 +2073,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
} }
double gui_scaling = g_settings->getFloat("gui_scaling"); double gui_scaling = g_settings->getFloat("gui_scaling");
double screen_dpi = porting::getDisplayDensity() * 96; double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
double use_imgsize; double use_imgsize;
if (m_lock) { if (m_lock) {
@ -2108,7 +2106,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
((5.0/4.0) * (0.5 + mydata.invsize.X)); ((5.0/4.0) * (0.5 + mydata.invsize.X));
double fity_imgsize = mydata.screensize.Y / double fity_imgsize = mydata.screensize.Y /
((15.0/13.0) * (0.85 * mydata.invsize.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; double min_imgsize = 0.3 * screen_dpi * gui_scaling;
use_imgsize = MYMAX(min_imgsize, MYMIN(prefer_imgsize, use_imgsize = MYMAX(min_imgsize, MYMIN(prefer_imgsize,
MYMIN(fitx_imgsize, fity_imgsize))); MYMIN(fitx_imgsize, fity_imgsize)));
@ -2579,7 +2577,7 @@ void GUIFormSpecMenu::drawMenu()
/* TODO find way to show tooltips on touchscreen */ /* TODO find way to show tooltips on touchscreen */
#ifndef HAVE_TOUCHSCREENGUI #ifndef HAVE_TOUCHSCREENGUI
m_pointer = m_device->getCursorControl()->getPosition(); m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition();
#endif #endif
/* /*

@ -287,8 +287,7 @@ class GUIFormSpecMenu : public GUIModalMenu
}; };
public: public:
GUIFormSpecMenu(irr::IrrlichtDevice* dev, GUIFormSpecMenu(JoystickController *joystick,
JoystickController *joystick,
gui::IGUIElement* parent, s32 id, gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr, IMenuManager *menumgr,
Client *client, Client *client,
@ -378,7 +377,6 @@ protected:
v2s32 pos_offset; v2s32 pos_offset;
std::stack<v2s32> container_stack; std::stack<v2s32> container_stack;
irr::IrrlichtDevice* m_device;
InventoryManager *m_invmgr; InventoryManager *m_invmgr;
ISimpleTextureSource *m_tsrc; ISimpleTextureSource *m_tsrc;
Client *m_client; Client *m_client;
@ -386,7 +384,6 @@ protected:
std::string m_formspec_string; std::string m_formspec_string;
InventoryLocation m_current_inventory_location; InventoryLocation m_current_inventory_location;
std::vector<ListDrawSpec> m_inventorylists; std::vector<ListDrawSpec> m_inventorylists;
std::vector<ListRingSpec> m_inventory_rings; std::vector<ListRingSpec> m_inventory_rings;
std::vector<ImageDrawSpec> m_backgrounds; std::vector<ImageDrawSpec> m_backgrounds;

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IGUISkin.h> #include <IGUISkin.h>
#include <IGUIFont.h> #include <IGUIFont.h>
#include <IGUIScrollBar.h> #include <IGUIScrollBar.h>
#include "client/renderingengine.h"
#include "debug.h" #include "debug.h"
#include "log.h" #include "log.h"
#include "client/tile.h" #include "client/tile.h"
@ -79,7 +80,8 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
updateAbsolutePosition(); updateAbsolutePosition();
core::rect<s32> relative_rect = m_scrollbar->getRelativePosition(); core::rect<s32> relative_rect = m_scrollbar->getRelativePosition();
s32 width = (relative_rect.getWidth()/(2.0/3.0)) * porting::getDisplayDensity() * s32 width = (relative_rect.getWidth()/(2.0/3.0)) *
RenderingEngine::getDisplayDensity() *
g_settings->getFloat("gui_scaling"); g_settings->getFloat("gui_scaling");
m_scrollbar->setRelativePosition(core::rect<s32>( m_scrollbar->setRelativePosition(core::rect<s32>(
relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y, relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y,

@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h" #include "settings.h"
#include "util/numeric.h" #include "util/numeric.h"
#include <stdio.h> #include <stdio.h>
#include "client/renderingengine.h"
/* Maintain a static cache to store the images that correspond to textures /* Maintain a static cache to store the images that correspond to textures
* in a format that's manipulable by code. Some platforms exhibit issues * in a format that's manipulable by code. Some platforms exhibit issues
@ -48,18 +49,18 @@ void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *v
} }
// Manually clear the cache, e.g. when switching to different worlds. // Manually clear the cache, e.g. when switching to different worlds.
void guiScalingCacheClear(video::IVideoDriver *driver) void guiScalingCacheClear()
{ {
for (std::map<io::path, video::IImage *>::iterator it = g_imgCache.begin(); for (std::map<io::path, video::IImage *>::iterator it = g_imgCache.begin();
it != g_imgCache.end(); ++it) { it != g_imgCache.end(); ++it) {
if (it->second != NULL) if (it->second)
it->second->drop(); it->second->drop();
} }
g_imgCache.clear(); g_imgCache.clear();
for (std::map<io::path, video::ITexture *>::iterator it = g_txrCache.begin(); for (std::map<io::path, video::ITexture *>::iterator it = g_txrCache.begin();
it != g_txrCache.end(); ++it) { it != g_txrCache.end(); ++it) {
if (it->second != NULL) if (it->second)
driver->removeTexture(it->second); RenderingEngine::get_video_driver()->removeTexture(it->second);
} }
g_txrCache.clear(); g_txrCache.clear();
} }

@ -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); void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *value);
// Manually clear the cache, e.g. when switching to different worlds. // Manually clear the cache, e.g. when switching to different worlds.
void guiScalingCacheClear(video::IVideoDriver *driver); void guiScalingCacheClear();
/* Get a cached, high-quality pre-scaled texture for display purposes. If the /* 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, * texture is not already cached, attempt to create it. Returns a pre-scaled texture,

@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mesh.h" #include "mesh.h"
#include "wieldmesh.h" #include "wieldmesh.h"
#include <IGUIStaticText.h> #include <IGUIStaticText.h>
#include "client/renderingengine.h"
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
#include "touchscreengui.h" #include "touchscreengui.h"
@ -51,7 +52,8 @@ Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
this->inventory = inventory; this->inventory = inventory;
m_hud_scaling = g_settings->getFloat("hud_scaling"); 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_hotbar_imagesize *= m_hud_scaling;
m_padding = m_hotbar_imagesize / 12; 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 // Position of upper left corner of bar
v2s32 pos = screen_offset; v2s32 pos = screen_offset;
pos.X *= m_hud_scaling * porting::getDisplayDensity(); pos.X *= m_hud_scaling * RenderingEngine::getDisplayDensity();
pos.Y *= m_hud_scaling * porting::getDisplayDensity(); pos.Y *= m_hud_scaling * RenderingEngine::getDisplayDensity();
pos += upperleftpos; pos += upperleftpos;
// Store hotbar_image in member variable, used by drawItem() // 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()) { if (size == v2s32()) {
dstd = srcd; dstd = srcd;
} else { } else {
float size_factor = m_hud_scaling * porting::getDisplayDensity(); float size_factor = m_hud_scaling * RenderingEngine::getDisplayDensity();
dstd.Height = size.Y * size_factor; dstd.Height = size.Y * size_factor;
dstd.Width = size.X * size_factor; dstd.Width = size.X * size_factor;
offset.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); s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3); 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")) { g_settings->getFloat("hud_hotbar_max_width")) {
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) { if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0); drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
@ -607,11 +610,14 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset)
} }
void Hud::resizeHotbar() { void Hud::resizeHotbar() {
if (m_screensize != porting::getWindowSize()) { const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * porting::getDisplayDensity() + 0.5);
if (m_screensize != window_size) {
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE *
RenderingEngine::getDisplayDensity() + 0.5);
m_hotbar_imagesize *= m_hud_scaling; m_hotbar_imagesize *= m_hud_scaling;
m_padding = m_hotbar_imagesize / 12; m_padding = m_hotbar_imagesize / 12;
m_screensize = porting::getWindowSize(); m_screensize = window_size;
m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2); m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2);
} }
} }

@ -124,17 +124,12 @@ extern bool isMenuActive();
class MainGameCallback : public IGameCallback class MainGameCallback : public IGameCallback
{ {
public: public:
MainGameCallback(IrrlichtDevice *a_device): MainGameCallback() {}
device(a_device) virtual ~MainGameCallback() {}
{
}
virtual void exitToOS() virtual void exitToOS()
{ {
shutdown_requested = true; shutdown_requested = true;
#ifndef __ANDROID__
device->closeDevice();
#endif
} }
virtual void disconnect() virtual void disconnect()
@ -170,8 +165,6 @@ public:
bool shutdown_requested = false; bool shutdown_requested = false;
bool keyconfig_changed = false; bool keyconfig_changed = false;
IrrlichtDevice *device;
}; };
extern MainGameCallback *g_gamecallback; extern MainGameCallback *g_gamecallback;

@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "shader.h" #include "shader.h"
#include "settings.h" #include "settings.h"
#include "util/directiontables.h" #include "util/directiontables.h"
#include <IMeshManipulator.h> #include "client/renderingengine.h"
/* /*
MeshMakeData MeshMakeData
@ -1008,15 +1008,11 @@ static void updateAllFastFaceRows(MeshMakeData *data,
MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
m_minimap_mapblock(NULL), m_minimap_mapblock(NULL),
m_client(data->m_client), m_tsrc(data->m_client->getTextureSource()),
m_driver(m_client->tsrc()->getDevice()->getVideoDriver()), m_shdrsrc(data->m_client->getShaderSource()),
m_tsrc(m_client->getTextureSource()),
m_shdrsrc(m_client->getShaderSource()),
m_animation_force_timer(0), // force initial animation m_animation_force_timer(0), // force initial animation
m_last_crack(-1), m_last_crack(-1),
m_crack_materials(), m_last_daynight_ratio((u32) -1)
m_last_daynight_ratio((u32) -1),
m_daynight_diffs()
{ {
for (int m = 0; m < MAX_TILE_LAYERS; m++) for (int m = 0; m < MAX_TILE_LAYERS; m++)
m_mesh[m] = new scene::SMesh(); m_mesh[m] = new scene::SMesh();
@ -1219,7 +1215,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
if (m_use_tangent_vertices) { if (m_use_tangent_vertices) {
scene::IMeshManipulator* meshmanip = scene::IMeshManipulator* meshmanip =
m_client->getSceneManager()->getMeshManipulator(); RenderingEngine::get_scene_manager()->getMeshManipulator();
meshmanip->recalculateTangents(m_mesh[layer], true, false, false); meshmanip->recalculateTangents(m_mesh[layer], true, false, false);
} }
@ -1254,7 +1250,7 @@ MapBlockMesh::~MapBlockMesh()
if (m_enable_vbo && m_mesh[m]) if (m_enable_vbo && m_mesh[m])
for (u32 i = 0; i < m_mesh[m]->getMeshBufferCount(); i++) { for (u32 i = 0; i < m_mesh[m]->getMeshBufferCount(); i++) {
scene::IMeshBuffer *buf = m_mesh[m]->getMeshBuffer(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]->drop();
m_mesh[m] = NULL; m_mesh[m] = NULL;

@ -42,7 +42,6 @@ struct MeshMakeData
v3s16 m_blockpos = v3s16(-1337,-1337,-1337); v3s16 m_blockpos = v3s16(-1337,-1337,-1337);
v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337); v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337);
bool m_smooth_lighting = false; bool m_smooth_lighting = false;
bool m_show_hud = false;
Client *m_client; Client *m_client;
bool m_use_shaders; bool m_use_shaders;
@ -138,8 +137,6 @@ public:
private: private:
scene::IMesh *m_mesh[MAX_TILE_LAYERS]; scene::IMesh *m_mesh[MAX_TILE_LAYERS];
MinimapMapblock *m_minimap_mapblock; MinimapMapblock *m_minimap_mapblock;
Client *m_client;
video::IVideoDriver *m_driver;
ITextureSource *m_tsrc; ITextureSource *m_tsrc;
IShaderSource *m_shdrsrc; IShaderSource *m_shdrsrc;

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/string.h" #include "util/string.h"
#include "mapblock.h" #include "mapblock.h"
#include <math.h> #include <math.h>
#include "client/renderingengine.h"
//// ////
@ -184,10 +185,10 @@ void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height)
//// Mapper //// Mapper
//// ////
Minimap::Minimap(IrrlichtDevice *device, Client *client) Minimap::Minimap(Client *client)
{ {
this->client = client; this->client = client;
this->driver = device->getVideoDriver(); this->driver = RenderingEngine::get_video_driver();
this->m_tsrc = client->getTextureSource(); this->m_tsrc = client->getTextureSource();
this->m_shdrsrc = client->getShaderSource(); this->m_shdrsrc = client->getShaderSource();
this->m_ndef = client->getNodeDefManager(); this->m_ndef = client->getNodeDefManager();
@ -478,7 +479,7 @@ void Minimap::drawMinimap()
return; return;
updateActiveMarkers(); updateActiveMarkers();
v2u32 screensize = porting::getWindowSize(); v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
const u32 size = 0.25 * screensize.Y; const u32 size = 0.25 * screensize.Y;
core::rect<s32> oldViewPort = driver->getViewPort(); core::rect<s32> oldViewPort = driver->getViewPort();

@ -116,7 +116,7 @@ private:
class Minimap { class Minimap {
public: public:
Minimap(IrrlichtDevice *device, Client *client); Minimap(Client *client);
~Minimap(); ~Minimap();
void addBlock(v3s16 pos, MinimapMapblock *data); void addBlock(v3s16 pos, MinimapMapblock *data);

@ -21,9 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "itemdef.h" #include "itemdef.h"
#ifndef SERVER #ifndef SERVER
#include "client/tile.h"
#include "mesh.h" #include "mesh.h"
#include "client.h" #include "client.h"
#include "client/renderingengine.h"
#include "client/tile.h"
#include <IMeshManipulator.h> #include <IMeshManipulator.h>
#endif #endif
#include "log.h" #include "log.h"
@ -1427,8 +1428,8 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef,
Client *client = (Client *)gamedef; Client *client = (Client *)gamedef;
ITextureSource *tsrc = client->tsrc(); ITextureSource *tsrc = client->tsrc();
IShaderSource *shdsrc = client->getShaderSource(); IShaderSource *shdsrc = client->getShaderSource();
scene::ISceneManager* smgr = client->getSceneManager(); scene::IMeshManipulator *meshmanip =
scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator(); RenderingEngine::get_scene_manager()->getMeshManipulator();
TextureSettings tsettings; TextureSettings tsettings;
tsettings.readSettings(); tsettings.readSettings();

@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client.h" #include "client.h"
#include "collision.h" #include "collision.h"
#include <stdlib.h> #include <stdlib.h>
#include "client/renderingengine.h"
#include "util/numeric.h" #include "util/numeric.h"
#include "light.h" #include "light.h"
#include "environment.h" #include "environment.h"
@ -42,7 +43,6 @@ v3f random_v3f(v3f min, v3f max)
Particle::Particle( Particle::Particle(
IGameDef *gamedef, IGameDef *gamedef,
scene::ISceneManager* smgr,
LocalPlayer *player, LocalPlayer *player,
ClientEnvironment *env, ClientEnvironment *env,
v3f pos, v3f pos,
@ -60,7 +60,8 @@ Particle::Particle(
u8 glow, u8 glow,
video::SColor color video::SColor color
): ):
scene::ISceneNode(smgr->getRootSceneNode(), smgr) scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
RenderingEngine::get_scene_manager())
{ {
// Misc // Misc
m_gamedef = gamedef; m_gamedef = gamedef;
@ -244,7 +245,7 @@ void Particle::updateVertices()
ParticleSpawner ParticleSpawner
*/ */
ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, LocalPlayer *player, ParticleSpawner::ParticleSpawner(IGameDef *gamedef, LocalPlayer *player,
u16 amount, float time, u16 amount, float time,
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
float minexptime, float maxexptime, float minsize, float maxsize, float minexptime, float maxexptime, float minsize, float maxsize,
@ -255,7 +256,6 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr,
m_particlemanager(p_manager) m_particlemanager(p_manager)
{ {
m_gamedef = gamedef; m_gamedef = gamedef;
m_smgr = smgr;
m_player = player; m_player = player;
m_amount = amount; m_amount = amount;
m_spawntime = time; m_spawntime = time;
@ -344,7 +344,6 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
Particle* toadd = new Particle( Particle* toadd = new Particle(
m_gamedef, m_gamedef,
m_smgr,
m_player, m_player,
env, env,
pos, pos,
@ -405,7 +404,6 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
Particle* toadd = new Particle( Particle* toadd = new Particle(
m_gamedef, m_gamedef,
m_smgr,
m_player, m_player,
env, env,
pos, pos,
@ -507,7 +505,7 @@ void ParticleManager::clearAll ()
} }
void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
scene::ISceneManager* smgr, LocalPlayer *player) LocalPlayer *player)
{ {
switch (event->type) { switch (event->type) {
case CE_DELETE_PARTICLESPAWNER: { case CE_DELETE_PARTICLESPAWNER: {
@ -533,7 +531,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
video::ITexture *texture = video::ITexture *texture =
client->tsrc()->getTextureForMesh(*(event->add_particlespawner.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.amount,
event->add_particlespawner.spawntime, event->add_particlespawner.spawntime,
*event->add_particlespawner.minpos, *event->add_particlespawner.minpos,
@ -578,7 +576,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
video::ITexture *texture = video::ITexture *texture =
client->tsrc()->getTextureForMesh(*(event->spawn_particle.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.pos,
*event->spawn_particle.vel, *event->spawn_particle.vel,
*event->spawn_particle.acc, *event->spawn_particle.acc,
@ -607,25 +605,22 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
} }
void ParticleManager::addDiggingParticles(IGameDef* gamedef, void ParticleManager::addDiggingParticles(IGameDef* gamedef,
scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos, LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
const MapNode &n, const ContentFeatures &f)
{ {
for (u16 j = 0; j < 32; j++) // set the amount of particles here // set the amount of particles here
{ for (u16 j = 0; j < 32; j++) {
addNodeParticle(gamedef, smgr, player, pos, n, f); addNodeParticle(gamedef, player, pos, n, f);
} }
} }
void ParticleManager::addPunchingParticles(IGameDef* gamedef, void ParticleManager::addPunchingParticles(IGameDef* gamedef,
scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos, LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
const MapNode &n, const ContentFeatures &f)
{ {
addNodeParticle(gamedef, smgr, player, pos, n, f); addNodeParticle(gamedef, player, pos, n, f);
} }
void ParticleManager::addNodeParticle(IGameDef* gamedef, void ParticleManager::addNodeParticle(IGameDef* gamedef,
scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos, LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
const MapNode &n, const ContentFeatures &f)
{ {
// Texture // Texture
u8 texid = myrand_range(0, 5); u8 texid = myrand_range(0, 5);
@ -667,7 +662,6 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef,
Particle* toadd = new Particle( Particle* toadd = new Particle(
gamedef, gamedef,
smgr,
player, player,
m_env, m_env,
particlepos, particlepos,

@ -38,7 +38,6 @@ class Particle : public scene::ISceneNode
public: public:
Particle( Particle(
IGameDef* gamedef, IGameDef* gamedef,
scene::ISceneManager* mgr,
LocalPlayer *player, LocalPlayer *player,
ClientEnvironment *env, ClientEnvironment *env,
v3f pos, v3f pos,
@ -119,7 +118,6 @@ class ParticleSpawner
{ {
public: public:
ParticleSpawner(IGameDef* gamedef, ParticleSpawner(IGameDef* gamedef,
scene::ISceneManager *smgr,
LocalPlayer *player, LocalPlayer *player,
u16 amount, u16 amount,
float time, float time,
@ -148,7 +146,6 @@ class ParticleSpawner
ParticleManager* m_particlemanager; ParticleManager* m_particlemanager;
float m_time; float m_time;
IGameDef *m_gamedef; IGameDef *m_gamedef;
scene::ISceneManager *m_smgr;
LocalPlayer *m_player; LocalPlayer *m_player;
u16 m_amount; u16 m_amount;
float m_spawntime; float m_spawntime;
@ -185,19 +182,16 @@ public:
void step (float dtime); void step (float dtime);
void handleParticleEvent(ClientEvent *event, Client *client, void handleParticleEvent(ClientEvent *event, Client *client,
scene::ISceneManager* smgr, LocalPlayer *player); LocalPlayer *player);
void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr, void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
LocalPlayer *player, v3s16 pos, const MapNode &n, const MapNode &n, const ContentFeatures &f);
const ContentFeatures &f);
void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr, void addPunchingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
LocalPlayer *player, v3s16 pos, const MapNode &n, const MapNode &n, const ContentFeatures &f);
const ContentFeatures &f);
void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr, void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
LocalPlayer *player, v3s16 pos, const MapNode &n, const MapNode &n, const ContentFeatures &f);
const ContentFeatures &f);
protected: protected:
void addParticle(Particle* toadd); void addParticle(Particle* toadd);

@ -41,14 +41,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define _PSTAT64 #define _PSTAT64
#include <sys/pstat.h> #include <sys/pstat.h>
#endif #endif
#if !defined(_WIN32) && !defined(__APPLE__) && \
!defined(__ANDROID__) && !defined(SERVER)
#define XORG_USED
#endif
#ifdef XORG_USED
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#endif
#include "config.h" #include "config.h"
#include "debug.h" #include "debug.h"
@ -592,304 +584,6 @@ void initializePaths()
#endif // USE_GETTEXT #endif // USE_GETTEXT
} }
void setXorgClassHint(const video::SExposedVideoData &video_data,
const std::string &name)
{
#ifdef XORG_USED
if (video_data.OpenGLLinux.X11Display == NULL)
return;
XClassHint *classhint = XAllocClassHint();
classhint->res_name = (char *)name.c_str();
classhint->res_class = (char *)name.c_str();
XSetClassHint((Display *)video_data.OpenGLLinux.X11Display,
video_data.OpenGLLinux.X11Window, classhint);
XFree(classhint);
#endif
}
bool setWindowIcon(IrrlichtDevice *device)
{
#if defined(XORG_USED)
# if RUN_IN_PLACE
return setXorgWindowIconFromPath(device,
path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png");
# else
// We have semi-support for reading in-place data if we are
// compiled with RUN_IN_PLACE. Don't break with this and
// also try the path_share location.
return
setXorgWindowIconFromPath(device,
ICON_DIR "/hicolor/128x128/apps/" PROJECT_NAME ".png") ||
setXorgWindowIconFromPath(device,
path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png");
# endif
#elif defined(_WIN32)
const video::SExposedVideoData exposedData = device->getVideoDriver()->getExposedVideoData();
HWND hWnd; // Window handle
switch (device->getVideoDriver()->getDriverType()) {
case video::EDT_DIRECT3D8:
hWnd = reinterpret_cast<HWND>(exposedData.D3D8.HWnd);
break;
case video::EDT_DIRECT3D9:
hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd);
break;
case video::EDT_OPENGL:
hWnd = reinterpret_cast<HWND>(exposedData.OpenGLWin32.HWnd);
break;
default:
return false;
}
// Load the ICON from resource file
const HICON hicon = LoadIcon(
GetModuleHandle(NULL),
MAKEINTRESOURCE(130) // The ID of the ICON defined in winresource.rc
);
if (hicon) {
SendMessage(hWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hicon));
SendMessage(hWnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(hicon));
return true;
}
return false;
#else
return false;
#endif
}
bool setXorgWindowIconFromPath(IrrlichtDevice *device,
const std::string &icon_file)
{
#ifdef XORG_USED
video::IVideoDriver *v_driver = device->getVideoDriver();
video::IImageLoader *image_loader = NULL;
u32 cnt = v_driver->getImageLoaderCount();
for (u32 i = 0; i < cnt; i++) {
if (v_driver->getImageLoader(i)->isALoadableFileExtension(icon_file.c_str())) {
image_loader = v_driver->getImageLoader(i);
break;
}
}
if (!image_loader) {
warningstream << "Could not find image loader for file '"
<< icon_file << "'" << std::endl;
return false;
}
io::IReadFile *icon_f = device->getFileSystem()->createAndOpenFile(icon_file.c_str());
if (!icon_f) {
warningstream << "Could not load icon file '"
<< icon_file << "'" << std::endl;
return false;
}
video::IImage *img = image_loader->loadImage(icon_f);
if (!img) {
warningstream << "Could not load icon file '"
<< icon_file << "'" << std::endl;
icon_f->drop();
return false;
}
u32 height = img->getDimension().Height;
u32 width = img->getDimension().Width;
size_t icon_buffer_len = 2 + height * width;
long *icon_buffer = new long[icon_buffer_len];
icon_buffer[0] = width;
icon_buffer[1] = height;
for (u32 x = 0; x < width; x++) {
for (u32 y = 0; y < height; y++) {
video::SColor col = img->getPixel(x, y);
long pixel_val = 0;
pixel_val |= (u8)col.getAlpha() << 24;
pixel_val |= (u8)col.getRed() << 16;
pixel_val |= (u8)col.getGreen() << 8;
pixel_val |= (u8)col.getBlue();
icon_buffer[2 + x + y * width] = pixel_val;
}
}
img->drop();
icon_f->drop();
const video::SExposedVideoData &video_data = v_driver->getExposedVideoData();
Display *x11_dpl = (Display *)video_data.OpenGLLinux.X11Display;
if (x11_dpl == NULL) {
warningstream << "Could not find x11 display for setting its icon."
<< std::endl;
delete [] icon_buffer;
return false;
}
Window x11_win = (Window)video_data.OpenGLLinux.X11Window;
Atom net_wm_icon = XInternAtom(x11_dpl, "_NET_WM_ICON", False);
Atom cardinal = XInternAtom(x11_dpl, "CARDINAL", False);
XChangeProperty(x11_dpl, x11_win,
net_wm_icon, cardinal, 32,
PropModeReplace, (const unsigned char *)icon_buffer,
icon_buffer_len);
delete [] icon_buffer;
#endif
return true;
}
////
//// Video/Display Information (Client-only)
////
#ifndef SERVER
static irr::IrrlichtDevice *device;
void initIrrlicht(irr::IrrlichtDevice *device_)
{
device = device_;
}
v2u32 getWindowSize()
{
return device->getVideoDriver()->getScreenSize();
}
std::vector<core::vector3d<u32> > getSupportedVideoModes()
{
IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
sanity_check(nulldevice != NULL);
std::vector<core::vector3d<u32> > mlist;
video::IVideoModeList *modelist = nulldevice->getVideoModeList();
u32 num_modes = modelist->getVideoModeCount();
for (u32 i = 0; i != num_modes; i++) {
core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
s32 mode_depth = modelist->getVideoModeDepth(i);
mlist.push_back(core::vector3d<u32>(mode_res.Width, mode_res.Height, mode_depth));
}
nulldevice->drop();
return mlist;
}
std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers()
{
std::vector<irr::video::E_DRIVER_TYPE> drivers;
for (int i = 0; i != irr::video::EDT_COUNT; i++) {
if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE)i))
drivers.push_back((irr::video::E_DRIVER_TYPE)i);
}
return drivers;
}
const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type)
{
static const char *driver_ids[] = {
"null",
"software",
"burningsvideo",
"direct3d8",
"direct3d9",
"opengl",
"ogles1",
"ogles2",
};
return driver_ids[type];
}
const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)
{
static const char *driver_names[] = {
"NULL Driver",
"Software Renderer",
"Burning's Video",
"Direct3D 8",
"Direct3D 9",
"OpenGL",
"OpenGL ES1",
"OpenGL ES2",
};
return driver_names[type];
}
# ifndef __ANDROID__
# ifdef XORG_USED
static float calcDisplayDensity()
{
const char *current_display = getenv("DISPLAY");
if (current_display != NULL) {
Display *x11display = XOpenDisplay(current_display);
if (x11display != NULL) {
/* try x direct */
float dpi_height = floor(DisplayHeight(x11display, 0) /
(DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
float dpi_width = floor(DisplayWidth(x11display, 0) /
(DisplayWidthMM(x11display, 0) * 0.039370) + 0.5);
XCloseDisplay(x11display);
return std::max(dpi_height,dpi_width) / 96.0;
}
}
/* return manually specified dpi */
return g_settings->getFloat("screen_dpi")/96.0;
}
float getDisplayDensity()
{
static float cached_display_density = calcDisplayDensity();
return cached_display_density;
}
# else // XORG_USED
float getDisplayDensity()
{
return g_settings->getFloat("screen_dpi")/96.0;
}
# endif // XORG_USED
v2u32 getDisplaySize()
{
IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
core::dimension2d<u32> deskres = nulldevice->getVideoModeList()->getDesktopResolution();
nulldevice -> drop();
return deskres;
}
# endif // __ANDROID__
#endif // SERVER
//// ////
//// OS-specific Secure Random //// OS-specific Secure Random
//// ////

@ -178,8 +178,6 @@ void initializePaths();
*/ */
std::string get_sysinfo(); std::string get_sysinfo();
void initIrrlicht(irr::IrrlichtDevice * );
// Monotonic counter getters. // Monotonic counter getters.
@ -281,19 +279,6 @@ inline u64 getDeltaMs(u64 old_time_ms, u64 new_time_ms)
} }
} }
#ifndef SERVER
float getDisplayDensity();
v2u32 getDisplaySize();
v2u32 getWindowSize();
std::vector<core::vector3d<u32> > getSupportedVideoModes();
std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
#endif
inline const char *getPlatformName() inline const char *getPlatformName()
{ {
return 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); 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. // This attaches to the parents process console, or creates a new one if it doesnt exist.

@ -33,10 +33,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serverlist.h" #include "serverlist.h"
#include "mapgen.h" #include "mapgen.h"
#include "settings.h" #include "settings.h"
#include "EDriverTypes.h"
#include <IFileArchive.h> #include <IFileArchive.h>
#include <IFileSystem.h> #include <IFileSystem.h>
#include "client/renderingengine.h"
/******************************************************************************/ /******************************************************************************/
@ -628,8 +628,7 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
GUIEngine* engine = getGuiEngine(L); GUIEngine* engine = getGuiEngine(L);
sanity_check(engine != NULL); sanity_check(engine != NULL);
GUIKeyChangeMenu *kmenu GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(),
= new GUIKeyChangeMenu( engine->m_device->getGUIEnvironment(),
engine->m_parent, engine->m_parent,
-1, -1,
engine->m_menumanager); engine->m_menumanager);
@ -832,9 +831,6 @@ int ModApiMainMenu::l_copy_dir(lua_State *L)
/******************************************************************************/ /******************************************************************************/
int ModApiMainMenu::l_extract_zip(lua_State *L) int ModApiMainMenu::l_extract_zip(lua_State *L)
{ {
GUIEngine* engine = getGuiEngine(L);
sanity_check(engine);
const char *zipfile = luaL_checkstring(L, 1); const char *zipfile = luaL_checkstring(L, 1);
const char *destination = luaL_checkstring(L, 2); const char *destination = luaL_checkstring(L, 2);
@ -843,7 +839,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
if (ModApiMainMenu::isMinetestPath(absolute_destination)) { if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
fs::CreateAllDirs(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)) { if (!fs->addFileArchive(zipfile,true,false,io::EFAT_ZIP)) {
lua_pushboolean(L,false); 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); bool is_file_select = lua_toboolean(L, 3);
GUIFileSelectMenu* fileOpenMenu = GUIFileSelectMenu* fileOpenMenu =
new GUIFileSelectMenu(engine->m_device->getGUIEnvironment(), new GUIFileSelectMenu(RenderingEngine::get_gui_env(),
engine->m_parent, engine->m_parent,
-1, -1,
engine->m_menumanager, engine->m_menumanager,
@ -997,13 +993,12 @@ int ModApiMainMenu::l_download_file(lua_State *L)
/******************************************************************************/ /******************************************************************************/
int ModApiMainMenu::l_get_video_drivers(lua_State *L) int ModApiMainMenu::l_get_video_drivers(lua_State *L)
{ {
std::vector<irr::video::E_DRIVER_TYPE> drivers std::vector<irr::video::E_DRIVER_TYPE> drivers = RenderingEngine::getSupportedVideoDrivers();
= porting::getSupportedVideoDrivers();
lua_newtable(L); lua_newtable(L);
for (u32 i = 0; i != drivers.size(); i++) { for (u32 i = 0; i != drivers.size(); i++) {
const char *name = porting::getVideoDriverName(drivers[i]); const char *name = RenderingEngine::getVideoDriverName(drivers[i]);
const char *fname = porting::getVideoDriverFriendlyName(drivers[i]); const char *fname = RenderingEngine::getVideoDriverFriendlyName(drivers[i]);
lua_newtable(L); lua_newtable(L);
lua_pushstring(L, name); 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) int ModApiMainMenu::l_get_video_modes(lua_State *L)
{ {
std::vector<core::vector3d<u32> > videomodes std::vector<core::vector3d<u32> > videomodes
= porting::getSupportedVideoModes(); = RenderingEngine::getSupportedVideoModes();
lua_newtable(L); lua_newtable(L);
for (u32 i = 0; i != videomodes.size(); i++) { for (u32 i = 0; i != videomodes.size(); i++) {
@ -1054,23 +1049,24 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L)
lua_newtable(L); lua_newtable(L);
int top = lua_gettop(L); int top = lua_gettop(L);
lua_pushstring(L,"density"); lua_pushstring(L,"density");
lua_pushnumber(L,porting::getDisplayDensity()); lua_pushnumber(L,RenderingEngine::getDisplayDensity());
lua_settable(L, top); lua_settable(L, top);
lua_pushstring(L,"display_width"); lua_pushstring(L,"display_width");
lua_pushnumber(L,porting::getDisplaySize().X); lua_pushnumber(L,RenderingEngine::getDisplaySize().X);
lua_settable(L, top); lua_settable(L, top);
lua_pushstring(L,"display_height"); lua_pushstring(L,"display_height");
lua_pushnumber(L,porting::getDisplaySize().Y); lua_pushnumber(L,RenderingEngine::getDisplaySize().Y);
lua_settable(L, top); lua_settable(L, top);
const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
lua_pushstring(L,"window_width"); lua_pushstring(L,"window_width");
lua_pushnumber(L,porting::getWindowSize().X); lua_pushnumber(L, window_size.X);
lua_settable(L, top); lua_settable(L, top);
lua_pushstring(L,"window_height"); lua_pushstring(L,"window_height");
lua_pushnumber(L,porting::getWindowSize().Y); lua_pushnumber(L, window_size.Y);
lua_settable(L, top); lua_settable(L, top);
return 1; return 1;
} }

@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IMaterialRenderer.h> #include <IMaterialRenderer.h>
#include <IMaterialRendererServices.h> #include <IMaterialRendererServices.h>
#include <IShaderConstantSetCallBack.h> #include <IShaderConstantSetCallBack.h>
#include "client/renderingengine.h"
#include "EShaderTypes.h" #include "EShaderTypes.h"
#include "log.h" #include "log.h"
#include "gamedef.h" #include "gamedef.h"
@ -177,7 +178,7 @@ class ShaderCallback : public video::IShaderConstantSetCallBack
std::vector<IShaderConstantSetter*> m_setters; std::vector<IShaderConstantSetter*> m_setters;
public: public:
ShaderCallback(const std::vector<IShaderConstantSetterFactory*> &factories) ShaderCallback(const std::vector<IShaderConstantSetterFactory *> &factories)
{ {
for (u32 i = 0; i < factories.size(); ++i) for (u32 i = 0; i < factories.size(); ++i)
m_setters.push_back(factories[i]->create()); m_setters.push_back(factories[i]->create());
@ -260,7 +261,7 @@ public:
class ShaderSource : public IWritableShaderSource class ShaderSource : public IWritableShaderSource
{ {
public: public:
ShaderSource(IrrlichtDevice *device); ShaderSource();
~ShaderSource(); ~ShaderSource();
/* /*
@ -309,8 +310,6 @@ private:
// The id of the thread that is allowed to use irrlicht directly // The id of the thread that is allowed to use irrlicht directly
std::thread::id m_main_thread; std::thread::id m_main_thread;
// The irrlicht device
IrrlichtDevice *m_device;
// Cache of source shaders // Cache of source shaders
// This should be only accessed from the main thread // This should be only accessed from the main thread
@ -332,18 +331,17 @@ private:
std::vector<ShaderCallback *> m_callbacks; std::vector<ShaderCallback *> m_callbacks;
}; };
IWritableShaderSource* createShaderSource(IrrlichtDevice *device) IWritableShaderSource *createShaderSource()
{ {
return new ShaderSource(device); return new ShaderSource();
} }
/* /*
Generate shader given the shader name. Generate shader given the shader name.
*/ */
ShaderInfo generate_shader(const std::string &name, ShaderInfo generate_shader(const std::string &name,
u8 material_type, u8 drawtype, u8 material_type, u8 drawtype, std::vector<ShaderCallback *> &callbacks,
IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks, const std::vector<IShaderConstantSetterFactory *> &setter_factories,
const std::vector<IShaderConstantSetterFactory*> &setter_factories,
SourceShaderCache *sourcecache); SourceShaderCache *sourcecache);
/* /*
@ -354,11 +352,8 @@ void load_shaders(std::string name, SourceShaderCache *sourcecache,
std::string &vertex_program, std::string &pixel_program, std::string &vertex_program, std::string &pixel_program,
std::string &geometry_program, bool &is_highlevel); std::string &geometry_program, bool &is_highlevel);
ShaderSource::ShaderSource(IrrlichtDevice *device): ShaderSource::ShaderSource()
m_device(device)
{ {
assert(m_device); // Pre-condition
m_main_thread = std::this_thread::get_id(); m_main_thread = std::this_thread::get_id();
// Add a dummy ShaderInfo as the first index, named "" // Add a dummy ShaderInfo as the first index, named ""
@ -453,7 +448,7 @@ u32 ShaderSource::getShaderIdDirect(const std::string &name,
} }
ShaderInfo info = generate_shader(name, material_type, drawtype, ShaderInfo info = generate_shader(name, material_type, drawtype,
m_device, m_callbacks, m_setter_factories, &m_sourcecache); m_callbacks, m_setter_factories, &m_sourcecache);
/* /*
Add shader to caches (add dummy shaders too) Add shader to caches (add dummy shaders too)
@ -518,7 +513,7 @@ void ShaderSource::rebuildShaders()
ShaderInfo *info = &m_shaderinfo_cache[i]; ShaderInfo *info = &m_shaderinfo_cache[i];
if(info->name != ""){ if(info->name != ""){
*info = generate_shader(info->name, info->material_type, *info = generate_shader(info->name, info->material_type,
info->drawtype, m_device, m_callbacks, info->drawtype, m_callbacks,
m_setter_factories, &m_sourcecache); m_setter_factories, &m_sourcecache);
} }
} }
@ -526,8 +521,8 @@ void ShaderSource::rebuildShaders()
ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype, ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype,
IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks, std::vector<ShaderCallback *> &callbacks,
const std::vector<IShaderConstantSetterFactory*> &setter_factories, const std::vector<IShaderConstantSetterFactory *> &setter_factories,
SourceShaderCache *sourcecache) SourceShaderCache *sourcecache)
{ {
ShaderInfo shaderinfo; ShaderInfo shaderinfo;
@ -535,7 +530,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
shaderinfo.material_type = material_type; shaderinfo.material_type = material_type;
shaderinfo.drawtype = drawtype; shaderinfo.drawtype = drawtype;
shaderinfo.material = video::EMT_SOLID; shaderinfo.material = video::EMT_SOLID;
switch(material_type){ switch (material_type) {
case TILE_MATERIAL_BASIC: case TILE_MATERIAL_BASIC:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break; break;
@ -553,15 +548,16 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
break; break;
case TILE_MATERIAL_WAVING_PLANTS: case TILE_MATERIAL_WAVING_PLANTS:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break; break;
default:
break;
} }
bool enable_shaders = g_settings->getBool("enable_shaders"); bool enable_shaders = g_settings->getBool("enable_shaders");
if (!enable_shaders) if (!enable_shaders)
return shaderinfo; return shaderinfo;
video::IVideoDriver* driver = device->getVideoDriver(); video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver);
video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices(); video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices();
if(!gpu){ if(!gpu){

@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define SHADER_HEADER #define SHADER_HEADER
#include <IMaterialRendererServices.h> #include <IMaterialRendererServices.h>
#include "irrlichttypes_extrabloated.h" #include "irrlichttypes_bloated.h"
#include <string> #include <string>
class IGameDef; class IGameDef;
@ -149,7 +149,7 @@ public:
virtual void addShaderConstantSetterFactory(IShaderConstantSetterFactory *setter) = 0; virtual void addShaderConstantSetterFactory(IShaderConstantSetterFactory *setter) = 0;
}; };
IWritableShaderSource* createShaderSource(IrrlichtDevice *device); IWritableShaderSource *createShaderSource();
void dumpShaderProgram(std::ostream &output_stream, void dumpShaderProgram(std::ostream &output_stream,
const std::string &program_type, const std::string &program); const std::string &program_type, const std::string &program);

@ -8,13 +8,14 @@
#include "profiler.h" #include "profiler.h"
#include "util/numeric.h" #include "util/numeric.h"
#include <cmath> #include <cmath>
#include "client/renderingengine.h"
#include "settings.h" #include "settings.h"
#include "camera.h" // CameraModes #include "camera.h" // CameraModes
Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, Sky::Sky(s32 id, ITextureSource *tsrc):
ITextureSource *tsrc): scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
scene::ISceneNode(parent, mgr, id) RenderingEngine::get_scene_manager(), id)
{ {
setAutomaticCulling(scene::EAC_OFF); setAutomaticCulling(scene::EAC_OFF);
m_box.MaxEdge.set(0, 0, 0); m_box.MaxEdge.set(0, 0, 0);

@ -34,8 +34,7 @@ class Sky : public scene::ISceneNode
{ {
public: public:
//! constructor //! constructor
Sky(scene::ISceneNode *parent, scene::ISceneManager *mgr, s32 id, Sky(s32 id, ITextureSource *tsrc);
ITextureSource *tsrc);
virtual void OnRegisterSceneNode(); virtual void OnRegisterSceneNode();

@ -57,8 +57,6 @@ src/daynightratio.h
src/debug.cpp src/debug.cpp
src/debug.h src/debug.h
src/defaultsettings.cpp src/defaultsettings.cpp
src/drawscene.cpp
src/drawscene.h
src/dungeongen.cpp src/dungeongen.cpp
src/dungeongen.h src/dungeongen.h
src/emerge.cpp src/emerge.cpp