refacto: don't use RenderingEngine singleton on CAO

* we don't need on CAO side more than SceneManager, and temporary. Pass only required SceneManager as a parameter to build CAO and add them to the current scene
* Use temporary the RenderingEngine singleton from ClientEnvironment, waitfor for better solution
* Make ClientActiveObject::addToScene virtual function mandatory to be defined by children to ensure we don't forget to properly define it
master
Loic Blot 2021-04-29 09:07:36 +02:00 committed by Loïc Blot
parent 1bc855646e
commit 809e68fdc0
5 changed files with 20 additions and 21 deletions

View File

@ -352,7 +352,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
if (!m_ao_manager.registerObject(object)) if (!m_ao_manager.registerObject(object))
return 0; return 0;
object->addToScene(m_texturesource); object->addToScene(m_texturesource, RenderingEngine::get_scene_manager());
// Update lighting immediately // Update lighting immediately
object->updateLight(getDayNightRatio()); object->updateLight(getDayNightRatio());

View File

@ -33,13 +33,17 @@ class LocalPlayer;
struct ItemStack; struct ItemStack;
class WieldMeshSceneNode; class WieldMeshSceneNode;
namespace irr { namespace scene {
class ISceneManager;
}}
class ClientActiveObject : public ActiveObject class ClientActiveObject : public ActiveObject
{ {
public: public:
ClientActiveObject(u16 id, Client *client, ClientEnvironment *env); ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
virtual ~ClientActiveObject(); virtual ~ClientActiveObject();
virtual void addToScene(ITextureSource *tsrc) {} virtual void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) = 0;
virtual void removeFromScene(bool permanent) {} virtual void removeFromScene(bool permanent) {}
virtual void updateLight(u32 day_night_ratio) {} virtual void updateLight(u32 day_night_ratio) {}

View File

@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IMeshManipulator.h> #include <IMeshManipulator.h>
#include <IAnimatedMeshSceneNode.h> #include <IAnimatedMeshSceneNode.h>
#include "client/client.h" #include "client/client.h"
#include "client/renderingengine.h"
#include "client/sound.h" #include "client/sound.h"
#include "client/tile.h" #include "client/tile.h"
#include "util/basic_macros.h" #include "util/basic_macros.h"
@ -189,7 +188,7 @@ public:
static ClientActiveObject* create(Client *client, ClientEnvironment *env); static ClientActiveObject* create(Client *client, ClientEnvironment *env);
void addToScene(ITextureSource *tsrc); void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr);
void removeFromScene(bool permanent); void removeFromScene(bool permanent);
void updateLight(u32 day_night_ratio); void updateLight(u32 day_night_ratio);
void updateNodePos(); void updateNodePos();
@ -220,7 +219,7 @@ ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env)
return new TestCAO(client, env); return new TestCAO(client, env);
} }
void TestCAO::addToScene(ITextureSource *tsrc) void TestCAO::addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -249,7 +248,7 @@ void TestCAO::addToScene(ITextureSource *tsrc)
// Add to mesh // Add to mesh
mesh->addMeshBuffer(buf); mesh->addMeshBuffer(buf);
buf->drop(); buf->drop();
m_node = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL); m_node = smgr->addMeshSceneNode(mesh, NULL);
mesh->drop(); mesh->drop();
updateNodePos(); updateNodePos();
} }
@ -591,9 +590,9 @@ void GenericCAO::removeFromScene(bool permanent)
m_client->getMinimap()->removeMarker(&m_marker); m_client->getMinimap()->removeMarker(&m_marker);
} }
void GenericCAO::addToScene(ITextureSource *tsrc) void GenericCAO::addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr)
{ {
m_smgr = RenderingEngine::get_scene_manager(); m_smgr = smgr;
if (getSceneNode() != NULL) { if (getSceneNode() != NULL) {
return; return;
@ -625,8 +624,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
} }
auto grabMatrixNode = [this] { auto grabMatrixNode = [this] {
m_matrixnode = RenderingEngine::get_scene_manager()-> m_matrixnode = m_smgr->addDummyTransformationSceneNode();
addDummyTransformationSceneNode();
m_matrixnode->grab(); m_matrixnode->grab();
}; };
@ -644,7 +642,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
if (m_prop.visual == "sprite") { if (m_prop.visual == "sprite") {
grabMatrixNode(); grabMatrixNode();
m_spritenode = RenderingEngine::get_scene_manager()->addBillboardSceneNode( m_spritenode = m_smgr->addBillboardSceneNode(
m_matrixnode, v2f(1, 1), v3f(0,0,0), -1); m_matrixnode, v2f(1, 1), v3f(0,0,0), -1);
m_spritenode->grab(); m_spritenode->grab();
m_spritenode->setMaterialTexture(0, m_spritenode->setMaterialTexture(0,
@ -729,8 +727,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
mesh->addMeshBuffer(buf); mesh->addMeshBuffer(buf);
buf->drop(); buf->drop();
} }
m_meshnode = RenderingEngine::get_scene_manager()-> m_meshnode = m_smgr->addMeshSceneNode(mesh, m_matrixnode);
addMeshSceneNode(mesh, m_matrixnode);
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.
@ -739,8 +736,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
} else if (m_prop.visual == "cube") { } else if (m_prop.visual == "cube") {
grabMatrixNode(); grabMatrixNode();
scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS)); scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS));
m_meshnode = RenderingEngine::get_scene_manager()-> m_meshnode = m_smgr->addMeshSceneNode(mesh, m_matrixnode);
addMeshSceneNode(mesh, m_matrixnode);
m_meshnode->grab(); m_meshnode->grab();
mesh->drop(); mesh->drop();
@ -753,8 +749,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
grabMatrixNode(); grabMatrixNode();
scene::IAnimatedMesh *mesh = m_client->getMesh(m_prop.mesh, true); scene::IAnimatedMesh *mesh = m_client->getMesh(m_prop.mesh, true);
if (mesh) { if (mesh) {
m_animated_meshnode = RenderingEngine::get_scene_manager()-> m_animated_meshnode = m_smgr->addAnimatedMeshSceneNode(mesh, m_matrixnode);
addAnimatedMeshSceneNode(mesh, m_matrixnode);
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
@ -795,8 +790,7 @@ void GenericCAO::addToScene(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( m_wield_meshnode = new WieldMeshSceneNode(m_smgr, -1);
RenderingEngine::get_scene_manager(), -1);
m_wield_meshnode->setItem(item, m_client, m_wield_meshnode->setItem(item, m_client,
(m_prop.visual == "wielditem")); (m_prop.visual == "wielditem"));
@ -1074,7 +1068,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
} }
removeFromScene(false); removeFromScene(false);
addToScene(m_client->tsrc()); addToScene(m_client->tsrc(), m_smgr);
// 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 (u16 cao_id : m_attachment_child_ids) { for (u16 cao_id : m_attachment_child_ids) {

View File

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

View File

@ -29,6 +29,7 @@ public:
TestClientActiveObject() : ClientActiveObject(0, nullptr, nullptr) {} TestClientActiveObject() : ClientActiveObject(0, nullptr, nullptr) {}
~TestClientActiveObject() = default; ~TestClientActiveObject() = default;
ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_TEST; } ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_TEST; }
virtual void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) {}
}; };
class TestClientActiveObjectMgr : public TestBase class TestClientActiveObjectMgr : public TestBase