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
master
Loïc Blot 2017-07-02 20:29:58 +02:00 committed by GitHub
parent 51104d9cd4
commit 94c294bfdc
13 changed files with 37 additions and 52 deletions

View File

@ -38,16 +38,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define CAMERA_OFFSET_STEP 200 #define CAMERA_OFFSET_STEP 200
#include "nodedef.h" Camera::Camera(MapDrawControl &draw_control, Client *client):
Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
Client *client):
m_draw_control(draw_control), m_draw_control(draw_control),
m_client(client) m_client(client)
{ {
//dstream<<FUNCTION_NAME<<std::endl; scene::ISceneManager *smgr = RenderingEngine::get_scene_manager();
m_driver = smgr->getVideoDriver();
// note: making the camera node a child of the player node // note: making the camera node a child of the player node
// would lead to unexpected behaviour, so we don't do that. // would lead to unexpected behaviour, so we don't do that.
m_playernode = smgr->addEmptySceneNode(smgr->getRootSceneNode()); 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. // all other 3D scene nodes and before the GUI.
m_wieldmgr = smgr->createNewSceneManager(); m_wieldmgr = smgr->createNewSceneManager();
m_wieldmgr->addCameraSceneNode(); 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->setItem(ItemStack(), m_client);
m_wieldnode->drop(); // m_wieldmgr grabbed it m_wieldnode->drop(); // m_wieldmgr grabbed it
@ -643,7 +638,7 @@ void Camera::drawNametags()
utf8_to_wide(nametag_colorless).c_str()); utf8_to_wide(nametag_colorless).c_str());
f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f : f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f :
core::reciprocal(transformed_pos[3]); core::reciprocal(transformed_pos[3]);
v2u32 screensize = m_driver->getScreenSize(); v2u32 screensize = RenderingEngine::get_video_driver()->getScreenSize();
v2s32 screen_pos; v2s32 screen_pos;
screen_pos.X = screensize.X * screen_pos.X = screensize.X *
(0.5 * transformed_pos[0] * zDiv + 0.5) - textsize.Width / 2; (0.5 * transformed_pos[0] * zDiv + 0.5) - textsize.Width / 2;

View File

@ -60,8 +60,7 @@ enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT};
class Camera class Camera
{ {
public: public:
Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, Camera(MapDrawControl &draw_control, Client *client);
Client *client);
~Camera(); ~Camera();
// Get camera scene node. // Get camera scene node.
@ -181,7 +180,6 @@ private:
MapDrawControl& m_draw_control; MapDrawControl& m_draw_control;
Client *m_client; Client *m_client;
video::IVideoDriver *m_driver;
// Absolute camera position // Absolute camera position
v3f m_camera_position; v3f m_camera_position;

View File

@ -23,9 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes.h" #include "irrlichttypes.h"
#include "irr_v3d.h" #include "irr_v3d.h"
#include <ITexture.h> #include <ITexture.h>
#include <IrrlichtDevice.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <SMaterial.h>
#include "util/numeric.h" #include "util/numeric.h"
class IGameDef; class IGameDef;

View File

@ -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(RenderingEngine::get_scene_manager(), m_texturesource); object->addToScene(m_texturesource);
{ // Update lighting immediately { // Update lighting immediately
u8 light = 0; u8 light = 0;
bool pos_ok; bool pos_ok;

View File

@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h" #include "irrlichttypes_extrabloated.h"
#include "activeobject.h" #include "activeobject.h"
#include <map>
#include <unordered_map> #include <unordered_map>
class ClientEnvironment; class ClientEnvironment;
@ -39,7 +38,7 @@ public:
ClientActiveObject(u16 id, Client *client, ClientEnvironment *env); ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
virtual ~ClientActiveObject(); virtual ~ClientActiveObject();
virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) {}; virtual void addToScene(ITextureSource *tsrc) {};
virtual void removeFromScene(bool permanent) {} virtual void removeFromScene(bool permanent) {}
// 0 <= light_at_pos <= LIGHT_SUN // 0 <= light_at_pos <= LIGHT_SUN
virtual void updateLight(u8 light_at_pos){} virtual void updateLight(u8 light_at_pos){}

View File

@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IBillboardSceneNode.h> #include <IBillboardSceneNode.h>
#include <IMeshManipulator.h> #include <IMeshManipulator.h>
#include <IAnimatedMeshSceneNode.h> #include <IAnimatedMeshSceneNode.h>
#include <IBoneSceneNode.h>
#include "content_cao.h" #include "content_cao.h"
#include "util/numeric.h" // For IntervalLimiter #include "util/numeric.h" // For IntervalLimiter
#include "util/serialize.h" #include "util/serialize.h"
@ -43,8 +42,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h" #include "map.h"
#include "camera.h" // CameraModes #include "camera.h" // CameraModes
#include "wieldmesh.h" #include "wieldmesh.h"
#include "log.h"
#include <algorithm> #include <algorithm>
#include "client/renderingengine.h"
class Settings; class Settings;
struct ToolCapabilities; struct ToolCapabilities;
@ -128,7 +127,7 @@ public:
static ClientActiveObject* create(Client *client, ClientEnvironment *env); static ClientActiveObject* create(Client *client, ClientEnvironment *env);
void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc); void addToScene(ITextureSource *tsrc);
void removeFromScene(bool permanent); void removeFromScene(bool permanent);
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();
@ -164,7 +163,7 @@ ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env)
return new TestCAO(client, env); return new TestCAO(client, env);
} }
void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) void TestCAO::addToScene(ITextureSource *tsrc)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -193,7 +192,7 @@ void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
// Add to mesh // Add to mesh
mesh->addMeshBuffer(buf); mesh->addMeshBuffer(buf);
buf->drop(); buf->drop();
m_node = smgr->addMeshSceneNode(mesh, NULL); m_node = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
mesh->drop(); mesh->drop();
updateNodePos(); updateNodePos();
} }
@ -270,7 +269,7 @@ public:
static ClientActiveObject* create(Client *client, ClientEnvironment *env); static ClientActiveObject* create(Client *client, ClientEnvironment *env);
void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc); void addToScene(ITextureSource *tsrc);
void removeFromScene(bool permanent); void removeFromScene(bool permanent);
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();
@ -326,7 +325,7 @@ ClientActiveObject* ItemCAO::create(Client *client, ClientEnvironment *env)
return new ItemCAO(client, env); return new ItemCAO(client, env);
} }
void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc) void ItemCAO::addToScene(ITextureSource *tsrc)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -360,7 +359,7 @@ void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
// Add to mesh // Add to mesh
mesh->addMeshBuffer(buf); mesh->addMeshBuffer(buf);
buf->drop(); buf->drop();
m_node = smgr->addMeshSceneNode(mesh, NULL); m_node = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
mesh->drop(); mesh->drop();
updateNodePos(); 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) { if (getSceneNode() != NULL) {
return; return;
@ -733,7 +732,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
if (m_prop.visual == "sprite") { if (m_prop.visual == "sprite") {
infostream<<"GenericCAO::addToScene(): single_sprite"<<std::endl; infostream<<"GenericCAO::addToScene(): single_sprite"<<std::endl;
m_spritenode = smgr->addBillboardSceneNode( m_spritenode = RenderingEngine::get_scene_manager()->addBillboardSceneNode(
NULL, v2f(1, 1), v3f(0,0,0), -1); NULL, v2f(1, 1), v3f(0,0,0), -1);
m_spritenode->grab(); m_spritenode->grab();
m_spritenode->setMaterialTexture(0, m_spritenode->setMaterialTexture(0,
@ -796,7 +795,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
mesh->addMeshBuffer(buf); mesh->addMeshBuffer(buf);
buf->drop(); buf->drop();
} }
m_meshnode = smgr->addMeshSceneNode(mesh, NULL); m_meshnode = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
m_meshnode->grab(); m_meshnode->grab();
mesh->drop(); mesh->drop();
// Set it to use the materials of the meshbuffers directly. // 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") { else if(m_prop.visual == "cube") {
infostream<<"GenericCAO::addToScene(): cube"<<std::endl; infostream<<"GenericCAO::addToScene(): cube"<<std::endl;
scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS)); scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS));
m_meshnode = smgr->addMeshSceneNode(mesh, NULL); m_meshnode = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
m_meshnode->grab(); m_meshnode->grab();
mesh->drop(); mesh->drop();
@ -826,7 +825,8 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
scene::IAnimatedMesh *mesh = m_client->getMesh(m_prop.mesh); scene::IAnimatedMesh *mesh = m_client->getMesh(m_prop.mesh);
if(mesh) if(mesh)
{ {
m_animated_meshnode = smgr->addAnimatedMeshSceneNode(mesh, NULL); m_animated_meshnode = RenderingEngine::get_scene_manager()->
addAnimatedMeshSceneNode(mesh, NULL);
m_animated_meshnode->grab(); m_animated_meshnode->grab();
mesh->drop(); // The scene node took hold of it mesh->drop(); // The scene node took hold of it
m_animated_meshnode->animateJoints(); // Needed for some animations 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; infostream << "serialized form: " << m_prop.wield_item << std::endl;
item.deSerialize(m_prop.wield_item, m_client->idef()); item.deSerialize(m_prop.wield_item, m_client->idef());
} }
m_wield_meshnode = new WieldMeshSceneNode(smgr->getRootSceneNode(), m_wield_meshnode = new WieldMeshSceneNode(
smgr, -1); RenderingEngine::get_scene_manager(), -1);
m_wield_meshnode->setItem(item, m_client); m_wield_meshnode->setItem(item, m_client);
m_wield_meshnode->setScale( m_wield_meshnode->setScale(
@ -1050,7 +1050,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
} }
removeFromScene(false); 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 // Attachments, part 2: Now that the parent has been refreshed, put its attachments back
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) { for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {

View File

@ -168,7 +168,7 @@ public:
void removeFromScene(bool permanent); void removeFromScene(bool permanent);
void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc); void addToScene(ITextureSource *tsrc);
inline void expireVisuals() inline void expireVisuals()
{ {

View File

@ -1914,7 +1914,7 @@ bool Game::createClient(const std::string &playername,
/* Camera /* Camera
*/ */
camera = new Camera(smgr, *draw_control, client); camera = new Camera(*draw_control, client);
if (!camera || !camera->successfullyCreated(*error_message)) if (!camera || !camera->successfullyCreated(*error_message))
return false; return false;
client->setCamera(camera); client->setCamera(camera);
@ -1971,7 +1971,7 @@ bool Game::createClient(const std::string &playername,
player->hurt_tilt_timer = 0; player->hurt_tilt_timer = 0;
player->hurt_tilt_strength = 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) { if (!hud) {
*error_message = "Memory error: could not create HUD"; *error_message = "Memory error: could not create HUD";

View File

@ -40,12 +40,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "touchscreengui.h" #include "touchscreengui.h"
#endif #endif
Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr, Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
gui::IGUIEnvironment* guienv, Client *client, LocalPlayer *player,
Inventory *inventory) Inventory *inventory)
{ {
this->driver = driver; driver = RenderingEngine::get_video_driver();
this->smgr = smgr;
this->guienv = guienv; this->guienv = guienv;
this->client = client; this->client = client;
this->player = player; this->player = player;
@ -339,7 +337,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
v3f p_pos = player->getPosition() / BS; v3f p_pos = player->getPosition() / BS;
v3f w_pos = e->world_pos * BS; v3f w_pos = e->world_pos * BS;
float distance = floor(10 * p_pos.getDistanceFrom(e->world_pos)) / 10; 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); w_pos -= intToFloat(camera_offset, BS);
core::matrix4 trans = camera->getProjectionMatrix(); core::matrix4 trans = camera->getProjectionMatrix();
trans *= camera->getViewMatrix(); trans *= camera->getViewMatrix();

View File

@ -120,8 +120,7 @@ public:
std::string hotbar_selected_image = ""; std::string hotbar_selected_image = "";
bool use_hotbar_selected_image = false; bool use_hotbar_selected_image = false;
Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr, Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
gui::IGUIEnvironment* guienv, Client *client, LocalPlayer *player,
Inventory *inventory); Inventory *inventory);
~Hud(); ~Hud();

View File

@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef SERVER #ifndef SERVER
#include "client/tile.h" #include "client/tile.h"
#include "shader.h" #include "shader.h"
#include <IMeshManipulator.h>
class Client; class Client;
#endif #endif
#include "itemgroup.h" #include "itemgroup.h"

View File

@ -192,13 +192,8 @@ private:
ExtrusionMeshCache *g_extrusion_mesh_cache = NULL; ExtrusionMeshCache *g_extrusion_mesh_cache = NULL;
WieldMeshSceneNode::WieldMeshSceneNode( WieldMeshSceneNode::WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id, bool lighting):
scene::ISceneNode *parent, scene::ISceneNode(mgr->getRootSceneNode(), mgr, id),
scene::ISceneManager *mgr,
s32 id,
bool lighting
):
scene::ISceneNode(parent, mgr, id),
m_material_type(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF), m_material_type(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF),
m_lighting(lighting) m_lighting(lighting)
{ {

View File

@ -74,8 +74,7 @@ struct ItemMesh
class WieldMeshSceneNode : public scene::ISceneNode class WieldMeshSceneNode : public scene::ISceneNode
{ {
public: public:
WieldMeshSceneNode(scene::ISceneNode *parent, scene::ISceneManager *mgr, WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id = -1, bool lighting = false);
s32 id = -1, bool lighting = false);
virtual ~WieldMeshSceneNode(); virtual ~WieldMeshSceneNode();
void setCube(const ContentFeatures &f, v3f wield_scale); void setCube(const ContentFeatures &f, v3f wield_scale);