Skip to content

Commit

Permalink
refacto: hide mesh_cache inside the rendering engine
Browse files Browse the repository at this point in the history
This permit cleaner access to meshCache and ensure we don't access to it from all the code
  • Loading branch information
nerzhul committed May 3, 2021
1 parent e071638 commit 74125a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/client/client.cpp
Expand Up @@ -1983,7 +1983,7 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename, bool cache)
return nullptr;
mesh->grab();
if (!cache)
m_rendering_engine->get_mesh_cache()->removeMesh(mesh);
m_rendering_engine->removeMesh(mesh);
return mesh;
}

Expand Down
25 changes: 1 addition & 24 deletions src/client/game.cpp
Expand Up @@ -652,8 +652,6 @@ class Game {

protected:

void extendedResourceCleanup();

// Basic initialisation
bool init(const std::string &map_dir, const std::string &address,
u16 port, const SubgameSpec &gamespec);
Expand Down Expand Up @@ -968,7 +966,7 @@ Game::~Game()
delete itemdef_manager;
delete draw_control;

extendedResourceCleanup();
clearTextureNameCache();

g_settings->deregisterChangedCallback("doubletap_jump",
&settingChangedCallback, this);
Expand Down Expand Up @@ -4063,27 +4061,6 @@ void Game::readSettings()
****************************************************************************/
/****************************************************************************/

void Game::extendedResourceCleanup()
{
// Extended resource accounting
infostream << "Irrlicht resources after cleanup:" << std::endl;
infostream << "\tRemaining meshes : "
<< RenderingEngine::get_mesh_cache()->getMeshCount() << std::endl;
infostream << "\tRemaining textures : "
<< driver->getTextureCount() << std::endl;

for (unsigned int i = 0; i < driver->getTextureCount(); i++) {
irr::video::ITexture *texture = driver->getTextureByIndex(i);
infostream << "\t\t" << i << ":" << texture->getName().getPath().c_str()
<< std::endl;
}

clearTextureNameCache();
infostream << "\tRemaining materials: "
<< driver-> getMaterialRendererCount()
<< " (note: irrlicht doesn't support removing renderers)" << std::endl;
}

void Game::showDeathFormspec()
{
static std::string formspec_str =
Expand Down
7 changes: 6 additions & 1 deletion src/client/renderingengine.cpp
Expand Up @@ -225,12 +225,17 @@ bool RenderingEngine::print_video_modes()
return videomode_list != NULL;
}

void RenderingEngine::removeMesh(const irr::scene::IMesh* mesh)
{
m_device->getSceneManager()->getMeshCache()->removeMesh(mesh);
}

void RenderingEngine::cleanupMeshCache()
{
auto mesh_cache = m_device->getSceneManager()->getMeshCache();
while (mesh_cache->getMeshCount() != 0) {
if (scene::IAnimatedMesh *mesh = mesh_cache->getMeshByIndex(0))
m_rendering_engine->get_mesh_cache()->removeMesh(mesh);
mesh_cache->removeMesh(mesh);
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/client/renderingengine.h
Expand Up @@ -26,6 +26,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "debug.h"

namespace irr { namespace scene {
class IMesh;
}}
class ITextureSource;
class Camera;
class Client;
Expand Down Expand Up @@ -58,6 +61,8 @@ class RenderingEngine
static bool print_video_modes();
void cleanupMeshCache();

void removeMesh(const irr::scene::IMesh* mesh);

static RenderingEngine *get_instance() { return s_singleton; }

io::IFileSystem *get_filesystem()
Expand All @@ -71,12 +76,6 @@ class RenderingEngine
return s_singleton->m_device->getVideoDriver();
}

static scene::IMeshCache *get_mesh_cache()
{
sanity_check(s_singleton && s_singleton->m_device);
return s_singleton->m_device->getSceneManager()->getMeshCache();
}

static scene::ISceneManager *get_scene_manager()
{
sanity_check(s_singleton && s_singleton->m_device);
Expand Down

0 comments on commit 74125a7

Please sign in to comment.