mirror of
https://github.com/minetest/minetest.git
synced 2024-12-28 08:57:30 +01:00
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
This commit is contained in:
parent
1bc855646e
commit
809e68fdc0
@ -352,7 +352,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
|
||||
if (!m_ao_manager.registerObject(object))
|
||||
return 0;
|
||||
|
||||
object->addToScene(m_texturesource);
|
||||
object->addToScene(m_texturesource, RenderingEngine::get_scene_manager());
|
||||
|
||||
// Update lighting immediately
|
||||
object->updateLight(getDayNightRatio());
|
||||
|
@ -33,13 +33,17 @@ class LocalPlayer;
|
||||
struct ItemStack;
|
||||
class WieldMeshSceneNode;
|
||||
|
||||
namespace irr { namespace scene {
|
||||
class ISceneManager;
|
||||
}}
|
||||
|
||||
class ClientActiveObject : public ActiveObject
|
||||
{
|
||||
public:
|
||||
ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
|
||||
virtual ~ClientActiveObject();
|
||||
|
||||
virtual void addToScene(ITextureSource *tsrc) {}
|
||||
virtual void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) = 0;
|
||||
virtual void removeFromScene(bool permanent) {}
|
||||
|
||||
virtual void updateLight(u32 day_night_ratio) {}
|
||||
|
@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include <IMeshManipulator.h>
|
||||
#include <IAnimatedMeshSceneNode.h>
|
||||
#include "client/client.h"
|
||||
#include "client/renderingengine.h"
|
||||
#include "client/sound.h"
|
||||
#include "client/tile.h"
|
||||
#include "util/basic_macros.h"
|
||||
@ -189,7 +188,7 @@ public:
|
||||
|
||||
static ClientActiveObject* create(Client *client, ClientEnvironment *env);
|
||||
|
||||
void addToScene(ITextureSource *tsrc);
|
||||
void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr);
|
||||
void removeFromScene(bool permanent);
|
||||
void updateLight(u32 day_night_ratio);
|
||||
void updateNodePos();
|
||||
@ -220,7 +219,7 @@ ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env)
|
||||
return new TestCAO(client, env);
|
||||
}
|
||||
|
||||
void TestCAO::addToScene(ITextureSource *tsrc)
|
||||
void TestCAO::addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr)
|
||||
{
|
||||
if(m_node != NULL)
|
||||
return;
|
||||
@ -249,7 +248,7 @@ void TestCAO::addToScene(ITextureSource *tsrc)
|
||||
// Add to mesh
|
||||
mesh->addMeshBuffer(buf);
|
||||
buf->drop();
|
||||
m_node = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
|
||||
m_node = smgr->addMeshSceneNode(mesh, NULL);
|
||||
mesh->drop();
|
||||
updateNodePos();
|
||||
}
|
||||
@ -591,9 +590,9 @@ void GenericCAO::removeFromScene(bool permanent)
|
||||
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) {
|
||||
return;
|
||||
@ -625,8 +624,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
|
||||
}
|
||||
|
||||
auto grabMatrixNode = [this] {
|
||||
m_matrixnode = RenderingEngine::get_scene_manager()->
|
||||
addDummyTransformationSceneNode();
|
||||
m_matrixnode = m_smgr->addDummyTransformationSceneNode();
|
||||
m_matrixnode->grab();
|
||||
};
|
||||
|
||||
@ -644,7 +642,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
|
||||
|
||||
if (m_prop.visual == "sprite") {
|
||||
grabMatrixNode();
|
||||
m_spritenode = RenderingEngine::get_scene_manager()->addBillboardSceneNode(
|
||||
m_spritenode = m_smgr->addBillboardSceneNode(
|
||||
m_matrixnode, v2f(1, 1), v3f(0,0,0), -1);
|
||||
m_spritenode->grab();
|
||||
m_spritenode->setMaterialTexture(0,
|
||||
@ -729,8 +727,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
|
||||
mesh->addMeshBuffer(buf);
|
||||
buf->drop();
|
||||
}
|
||||
m_meshnode = RenderingEngine::get_scene_manager()->
|
||||
addMeshSceneNode(mesh, m_matrixnode);
|
||||
m_meshnode = m_smgr->addMeshSceneNode(mesh, m_matrixnode);
|
||||
m_meshnode->grab();
|
||||
mesh->drop();
|
||||
// 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") {
|
||||
grabMatrixNode();
|
||||
scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS));
|
||||
m_meshnode = RenderingEngine::get_scene_manager()->
|
||||
addMeshSceneNode(mesh, m_matrixnode);
|
||||
m_meshnode = m_smgr->addMeshSceneNode(mesh, m_matrixnode);
|
||||
m_meshnode->grab();
|
||||
mesh->drop();
|
||||
|
||||
@ -753,8 +749,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
|
||||
grabMatrixNode();
|
||||
scene::IAnimatedMesh *mesh = m_client->getMesh(m_prop.mesh, true);
|
||||
if (mesh) {
|
||||
m_animated_meshnode = RenderingEngine::get_scene_manager()->
|
||||
addAnimatedMeshSceneNode(mesh, m_matrixnode);
|
||||
m_animated_meshnode = m_smgr->addAnimatedMeshSceneNode(mesh, m_matrixnode);
|
||||
m_animated_meshnode->grab();
|
||||
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;
|
||||
item.deSerialize(m_prop.wield_item, m_client->idef());
|
||||
}
|
||||
m_wield_meshnode = new WieldMeshSceneNode(
|
||||
RenderingEngine::get_scene_manager(), -1);
|
||||
m_wield_meshnode = new WieldMeshSceneNode(m_smgr, -1);
|
||||
m_wield_meshnode->setItem(item, m_client,
|
||||
(m_prop.visual == "wielditem"));
|
||||
|
||||
@ -1074,7 +1068,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
|
||||
}
|
||||
|
||||
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
|
||||
for (u16 cao_id : m_attachment_child_ids) {
|
||||
|
@ -236,7 +236,7 @@ public:
|
||||
|
||||
void removeFromScene(bool permanent);
|
||||
|
||||
void addToScene(ITextureSource *tsrc);
|
||||
void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr);
|
||||
|
||||
inline void expireVisuals()
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
TestClientActiveObject() : ClientActiveObject(0, nullptr, nullptr) {}
|
||||
~TestClientActiveObject() = default;
|
||||
ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_TEST; }
|
||||
virtual void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) {}
|
||||
};
|
||||
|
||||
class TestClientActiveObjectMgr : public TestBase
|
||||
|
Loading…
Reference in New Issue
Block a user