From 94c294bfdcfb7caa84c88649f3630605ed90e884 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sun, 2 Jul 2017 20:29:58 +0200 Subject: Irrlicht cleanup: cleanup various object to use RenderingEngine (#6088) * Irrlicht cleanup: cleanup various object to use RenderingEngine * CAO doesn't need scenemanager in addToScene * Camera doesn't need VideoDriver pointer or SceneManager in constructor * Hud doesn't need driver & scene manager in constructor * Hud doesn't need scenemanager pointer * Tile.h doesn't need IrrlichtDevice header (just SMaterial) * WieldMeshSceneNode: only take scene, we always use scene root node as parent --- src/camera.cpp | 13 ++++--------- src/camera.h | 4 +--- src/client/tile.h | 2 +- src/clientenvironment.cpp | 2 +- src/clientobject.h | 3 +-- src/content_cao.cpp | 34 +++++++++++++++++----------------- src/content_cao.h | 2 +- src/game.cpp | 4 ++-- src/hud.cpp | 9 ++++----- src/hud.h | 3 +-- src/nodedef.h | 1 + src/wieldmesh.cpp | 9 ++------- src/wieldmesh.h | 3 +-- 13 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index 40fd62767..ae6907da7 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -38,16 +38,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #define CAMERA_OFFSET_STEP 200 -#include "nodedef.h" - -Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, - Client *client): +Camera::Camera(MapDrawControl &draw_control, Client *client): m_draw_control(draw_control), m_client(client) { - //dstream<getVideoDriver(); + scene::ISceneManager *smgr = RenderingEngine::get_scene_manager(); // note: making the camera node a child of the player node // would lead to unexpected behaviour, so we don't do that. m_playernode = smgr->addEmptySceneNode(smgr->getRootSceneNode()); @@ -59,7 +54,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, // all other 3D scene nodes and before the GUI. m_wieldmgr = smgr->createNewSceneManager(); m_wieldmgr->addCameraSceneNode(); - m_wieldnode = new WieldMeshSceneNode(m_wieldmgr->getRootSceneNode(), m_wieldmgr, -1, false); + m_wieldnode = new WieldMeshSceneNode(m_wieldmgr, -1, false); m_wieldnode->setItem(ItemStack(), m_client); m_wieldnode->drop(); // m_wieldmgr grabbed it @@ -643,7 +638,7 @@ void Camera::drawNametags() utf8_to_wide(nametag_colorless).c_str()); f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f : core::reciprocal(transformed_pos[3]); - v2u32 screensize = m_driver->getScreenSize(); + v2u32 screensize = RenderingEngine::get_video_driver()->getScreenSize(); v2s32 screen_pos; screen_pos.X = screensize.X * (0.5 * transformed_pos[0] * zDiv + 0.5) - textsize.Width / 2; diff --git a/src/camera.h b/src/camera.h index f88f1cc94..51918be79 100644 --- a/src/camera.h +++ b/src/camera.h @@ -60,8 +60,7 @@ enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT}; class Camera { public: - Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, - Client *client); + Camera(MapDrawControl &draw_control, Client *client); ~Camera(); // Get camera scene node. @@ -181,7 +180,6 @@ private: MapDrawControl& m_draw_control; Client *m_client; - video::IVideoDriver *m_driver; // Absolute camera position v3f m_camera_position; diff --git a/src/client/tile.h b/src/client/tile.h index fb1c87371..aadc3e156 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -23,9 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes.h" #include "irr_v3d.h" #include -#include #include #include +#include #include "util/numeric.h" class IGameDef; diff --git a/src/clientenvironment.cpp b/src/clientenvironment.cpp index 28b61b06e..791b61531 100644 --- a/src/clientenvironment.cpp +++ b/src/clientenvironment.cpp @@ -456,7 +456,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) infostream<<"ClientEnvironment::addActiveObject(): " <<"added (id="<getId()<<")"<getId()] = object; - object->addToScene(RenderingEngine::get_scene_manager(), m_texturesource); + object->addToScene(m_texturesource); { // Update lighting immediately u8 light = 0; bool pos_ok; diff --git a/src/clientobject.h b/src/clientobject.h index d81e8e7e6..f8075d65a 100644 --- a/src/clientobject.h +++ b/src/clientobject.h @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_extrabloated.h" #include "activeobject.h" -#include #include class ClientEnvironment; @@ -39,7 +38,7 @@ public: ClientActiveObject(u16 id, Client *client, ClientEnvironment *env); virtual ~ClientActiveObject(); - virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) {}; + virtual void addToScene(ITextureSource *tsrc) {}; virtual void removeFromScene(bool permanent) {} // 0 <= light_at_pos <= LIGHT_SUN virtual void updateLight(u8 light_at_pos){} diff --git a/src/content_cao.cpp b/src/content_cao.cpp index e0ebc5fad..aff143bf2 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include #include "content_cao.h" #include "util/numeric.h" // For IntervalLimiter #include "util/serialize.h" @@ -43,8 +42,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map.h" #include "camera.h" // CameraModes #include "wieldmesh.h" -#include "log.h" #include +#include "client/renderingengine.h" class Settings; struct ToolCapabilities; @@ -128,7 +127,7 @@ public: static ClientActiveObject* create(Client *client, ClientEnvironment *env); - void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc); + void addToScene(ITextureSource *tsrc); void removeFromScene(bool permanent); void updateLight(u8 light_at_pos); v3s16 getLightPosition(); @@ -164,7 +163,7 @@ ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env) return new TestCAO(client, env); } -void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) +void TestCAO::addToScene(ITextureSource *tsrc) { if(m_node != NULL) return; @@ -193,7 +192,7 @@ void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) // Add to mesh mesh->addMeshBuffer(buf); buf->drop(); - m_node = smgr->addMeshSceneNode(mesh, NULL); + m_node = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL); mesh->drop(); updateNodePos(); } @@ -270,7 +269,7 @@ public: static ClientActiveObject* create(Client *client, ClientEnvironment *env); - void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc); + void addToScene(ITextureSource *tsrc); void removeFromScene(bool permanent); void updateLight(u8 light_at_pos); v3s16 getLightPosition(); @@ -326,7 +325,7 @@ ClientActiveObject* ItemCAO::create(Client *client, ClientEnvironment *env) return new ItemCAO(client, env); } -void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) +void ItemCAO::addToScene(ITextureSource *tsrc) { if(m_node != NULL) return; @@ -360,7 +359,7 @@ void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) // Add to mesh mesh->addMeshBuffer(buf); buf->drop(); - m_node = smgr->addMeshSceneNode(mesh, NULL); + m_node = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL); mesh->drop(); updateNodePos(); @@ -717,9 +716,9 @@ void GenericCAO::removeFromScene(bool permanent) } } -void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) +void GenericCAO::addToScene(ITextureSource *tsrc) { - m_smgr = smgr; + m_smgr = RenderingEngine::get_scene_manager(); if (getSceneNode() != NULL) { return; @@ -733,7 +732,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) if (m_prop.visual == "sprite") { infostream<<"GenericCAO::addToScene(): single_sprite"<addBillboardSceneNode( + m_spritenode = RenderingEngine::get_scene_manager()->addBillboardSceneNode( NULL, v2f(1, 1), v3f(0,0,0), -1); m_spritenode->grab(); m_spritenode->setMaterialTexture(0, @@ -796,7 +795,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) mesh->addMeshBuffer(buf); buf->drop(); } - m_meshnode = smgr->addMeshSceneNode(mesh, NULL); + m_meshnode = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL); m_meshnode->grab(); mesh->drop(); // Set it to use the materials of the meshbuffers directly. @@ -806,7 +805,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) else if(m_prop.visual == "cube") { infostream<<"GenericCAO::addToScene(): cube"<addMeshSceneNode(mesh, NULL); + m_meshnode = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL); m_meshnode->grab(); mesh->drop(); @@ -826,7 +825,8 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) scene::IAnimatedMesh *mesh = m_client->getMesh(m_prop.mesh); if(mesh) { - m_animated_meshnode = smgr->addAnimatedMeshSceneNode(mesh, NULL); + m_animated_meshnode = RenderingEngine::get_scene_manager()-> + addAnimatedMeshSceneNode(mesh, NULL); m_animated_meshnode->grab(); mesh->drop(); // The scene node took hold of it m_animated_meshnode->animateJoints(); // Needed for some animations @@ -865,8 +865,8 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) infostream << "serialized form: " << m_prop.wield_item << std::endl; item.deSerialize(m_prop.wield_item, m_client->idef()); } - m_wield_meshnode = new WieldMeshSceneNode(smgr->getRootSceneNode(), - smgr, -1); + m_wield_meshnode = new WieldMeshSceneNode( + RenderingEngine::get_scene_manager(), -1); m_wield_meshnode->setItem(item, m_client); m_wield_meshnode->setScale( @@ -1050,7 +1050,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) } removeFromScene(false); - addToScene(m_smgr, m_client->tsrc()); + addToScene(m_client->tsrc()); // Attachments, part 2: Now that the parent has been refreshed, put its attachments back for (std::vector::size_type i = 0; i < m_children.size(); i++) { diff --git a/src/content_cao.h b/src/content_cao.h index 66d5ca3f9..526f10ea3 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -168,7 +168,7 @@ public: void removeFromScene(bool permanent); - void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc); + void addToScene(ITextureSource *tsrc); inline void expireVisuals() { diff --git a/src/game.cpp b/src/game.cpp index 841b2d7ee..827512fbc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1914,7 +1914,7 @@ bool Game::createClient(const std::string &playername, /* Camera */ - camera = new Camera(smgr, *draw_control, client); + camera = new Camera(*draw_control, client); if (!camera || !camera->successfullyCreated(*error_message)) return false; client->setCamera(camera); @@ -1971,7 +1971,7 @@ bool Game::createClient(const std::string &playername, player->hurt_tilt_timer = 0; player->hurt_tilt_strength = 0; - hud = new Hud(driver, smgr, guienv, client, player, local_inventory); + hud = new Hud(guienv, client, player, local_inventory); if (!hud) { *error_message = "Memory error: could not create HUD"; diff --git a/src/hud.cpp b/src/hud.cpp index 2285fb71e..70903ce15 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -40,12 +40,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "touchscreengui.h" #endif -Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr, - gui::IGUIEnvironment* guienv, Client *client, LocalPlayer *player, +Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, Inventory *inventory) { - this->driver = driver; - this->smgr = smgr; + driver = RenderingEngine::get_video_driver(); this->guienv = guienv; this->client = client; this->player = player; @@ -339,7 +337,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) v3f p_pos = player->getPosition() / BS; v3f w_pos = e->world_pos * BS; float distance = floor(10 * p_pos.getDistanceFrom(e->world_pos)) / 10; - scene::ICameraSceneNode* camera = smgr->getActiveCamera(); + scene::ICameraSceneNode* camera = + RenderingEngine::get_scene_manager()->getActiveCamera(); w_pos -= intToFloat(camera_offset, BS); core::matrix4 trans = camera->getProjectionMatrix(); trans *= camera->getViewMatrix(); diff --git a/src/hud.h b/src/hud.h index dcbedf642..7b208a26e 100644 --- a/src/hud.h +++ b/src/hud.h @@ -120,8 +120,7 @@ public: std::string hotbar_selected_image = ""; bool use_hotbar_selected_image = false; - Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr, - gui::IGUIEnvironment* guienv, Client *client, LocalPlayer *player, + Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, Inventory *inventory); ~Hud(); diff --git a/src/nodedef.h b/src/nodedef.h index 97697e746..a0b5fc69e 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef SERVER #include "client/tile.h" #include "shader.h" +#include class Client; #endif #include "itemgroup.h" diff --git a/src/wieldmesh.cpp b/src/wieldmesh.cpp index 7da030df4..aa5f04b8d 100644 --- a/src/wieldmesh.cpp +++ b/src/wieldmesh.cpp @@ -192,13 +192,8 @@ private: ExtrusionMeshCache *g_extrusion_mesh_cache = NULL; -WieldMeshSceneNode::WieldMeshSceneNode( - scene::ISceneNode *parent, - scene::ISceneManager *mgr, - s32 id, - bool lighting -): - scene::ISceneNode(parent, mgr, id), +WieldMeshSceneNode::WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id, bool lighting): + scene::ISceneNode(mgr->getRootSceneNode(), mgr, id), m_material_type(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF), m_lighting(lighting) { diff --git a/src/wieldmesh.h b/src/wieldmesh.h index 8ef155dfd..44bca8e9f 100644 --- a/src/wieldmesh.h +++ b/src/wieldmesh.h @@ -74,8 +74,7 @@ struct ItemMesh class WieldMeshSceneNode : public scene::ISceneNode { public: - WieldMeshSceneNode(scene::ISceneNode *parent, scene::ISceneManager *mgr, - s32 id = -1, bool lighting = false); + WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id = -1, bool lighting = false); virtual ~WieldMeshSceneNode(); void setCube(const ContentFeatures &f, v3f wield_scale); -- cgit v1.2.3