Skip to content

Commit

Permalink
refacto: RenderingEngine::get_scene_manager() is now not callable fro…
Browse files Browse the repository at this point in the history
…m singleton

This permits to make evidence that we have some bad object passing on various code parts. I fixed majority of them to reduce the scope of passed objects

Unfortunately, for some edge cases i should have to expose ISceneManager from client, this should be fixed in the future when our POO will be cleaner client side (we have a mix of rendering and processing in majority of the client objects, it works but it's not clean)
  • Loading branch information
nerzhul committed May 3, 2021
1 parent ccdd886 commit 5a02c37
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/client/client.cpp
Expand Up @@ -1475,6 +1475,11 @@ bool Client::updateWieldedItem()
return true;
}

irr::scene::ISceneManager* Client::getSceneManager()
{
return m_rendering_engine->get_scene_manager();
}

Inventory* Client::getInventory(const InventoryLocation &loc)
{
switch(loc.type){
Expand Down
1 change: 1 addition & 0 deletions src/client/client.h
Expand Up @@ -355,6 +355,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void setCamera(Camera* camera) { m_camera = camera; }

Camera* getCamera () { return m_camera; }
irr::scene::ISceneManager *getSceneManager();

bool shouldShowMinimap() const;

Expand Down
2 changes: 1 addition & 1 deletion src/client/clientenvironment.cpp
Expand Up @@ -352,7 +352,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
if (!m_ao_manager.registerObject(object))
return 0;

object->addToScene(m_texturesource, RenderingEngine::get_scene_manager());
object->addToScene(m_texturesource, m_client->getSceneManager());

// Update lighting immediately
object->updateLight(getDayNightRatio());
Expand Down
16 changes: 7 additions & 9 deletions src/client/content_mapblock.cpp
Expand Up @@ -60,18 +60,16 @@ static constexpr u16 quad_indices[] = {0, 1, 2, 2, 3, 0};

const std::string MapblockMeshGenerator::raillike_groupname = "connect_to_raillike";

MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output)
MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output,
irr::scene::IMeshManipulator *mm):
data(input),
collector(output),
nodedef(data->m_client->ndef()),
meshmanip(mm),
blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE)
{
data = input;
collector = output;

nodedef = data->m_client->ndef();
meshmanip = RenderingEngine::get_scene_manager()->getMeshManipulator();

enable_mesh_cache = g_settings->getBool("enable_mesh_cache") &&
!data->m_smooth_lighting; // Mesh cache is not supported with smooth lighting

blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
}

void MapblockMeshGenerator::useTile(int index, u8 set_flags, u8 reset_flags, bool special)
Expand Down
3 changes: 2 additions & 1 deletion src/client/content_mapblock.h
Expand Up @@ -172,7 +172,8 @@ class MapblockMeshGenerator
void drawNode();

public:
MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output,
irr::scene::IMeshManipulator *mm);
void generate();
void renderSingle(content_t node, u8 param2 = 0x00);
};
4 changes: 2 additions & 2 deletions src/client/mapblock_mesh.cpp
Expand Up @@ -1072,8 +1072,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
*/

{
MapblockMeshGenerator generator(data, &collector);
generator.generate();
MapblockMeshGenerator(data, &collector,
data->m_client->getSceneManager()->getMeshManipulator()).generate();
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/client/particles.cpp
Expand Up @@ -64,8 +64,8 @@ Particle::Particle(
v2f texsize,
video::SColor color
):
scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
RenderingEngine::get_scene_manager())
scene::ISceneNode(((Client *)gamedef)->getSceneManager()->getRootSceneNode(),
((Client *)gamedef)->getSceneManager())
{
// Misc
m_gamedef = gamedef;
Expand Down
5 changes: 2 additions & 3 deletions src/client/renderingengine.h
Expand Up @@ -79,10 +79,9 @@ class RenderingEngine
return s_singleton->m_device->getVideoDriver();
}

static scene::ISceneManager *get_scene_manager()
scene::ISceneManager *get_scene_manager()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device->getSceneManager();
return m_device->getSceneManager();
}

static irr::IrrlichtDevice *get_raw_device()
Expand Down
5 changes: 3 additions & 2 deletions src/client/wieldmesh.cpp
Expand Up @@ -307,7 +307,8 @@ static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n,
MeshMakeData mesh_make_data(client, false);
MeshCollector collector;
mesh_make_data.setSmoothLighting(false);
MapblockMeshGenerator gen(&mesh_make_data, &collector);
MapblockMeshGenerator gen(&mesh_make_data, &collector,
client->getSceneManager()->getMeshManipulator());

if (n.getParam2()) {
// keep it
Expand Down Expand Up @@ -538,7 +539,7 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
content_t id = ndef->getId(def.name);

FATAL_ERROR_IF(!g_extrusion_mesh_cache, "Extrusion mesh cache is not yet initialized");

scene::SMesh *mesh = nullptr;

// Shading is on by default
Expand Down
2 changes: 1 addition & 1 deletion src/gui/guiFormSpecMenu.cpp
Expand Up @@ -2794,7 +2794,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)

core::rect<s32> rect(pos, pos + geom);

GUIScene *e = new GUIScene(Environment, RenderingEngine::get_scene_manager(),
GUIScene *e = new GUIScene(Environment, m_client->getSceneManager(),
data->current_parent, rect, spec.fid);

auto meshnode = e->setMesh(mesh);
Expand Down
4 changes: 2 additions & 2 deletions src/nodedef.cpp
Expand Up @@ -1446,8 +1446,8 @@ void NodeDefManager::updateTextures(IGameDef *gamedef,
Client *client = (Client *)gamedef;
ITextureSource *tsrc = client->tsrc();
IShaderSource *shdsrc = client->getShaderSource();
scene::IMeshManipulator *meshmanip =
RenderingEngine::get_scene_manager()->getMeshManipulator();
auto smgr = client->getSceneManager();
scene::IMeshManipulator *meshmanip = smgr->getMeshManipulator();
TextureSettings tsettings;
tsettings.readSettings();

Expand Down

0 comments on commit 5a02c37

Please sign in to comment.