Skip to content
Permalink
Browse files
refacto: hide mesh_cache inside the rendering engine
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 74125a74d34e9b1a003107d4ef6b95b8483d2464
Showing with 13 additions and 32 deletions.
  1. +1 −1 src/client/client.cpp
  2. +1 −24 src/client/game.cpp
  3. +6 −1 src/client/renderingengine.cpp
  4. +5 −6 src/client/renderingengine.h
@@ -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;
}

@@ -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);
@@ -968,7 +966,7 @@ Game::~Game()
delete itemdef_manager;
delete draw_control;

extendedResourceCleanup();
clearTextureNameCache();

g_settings->deregisterChangedCallback("doubletap_jump",
&settingChangedCallback, this);
@@ -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 =
@@ -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);
}
}

@@ -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;
@@ -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()
@@ -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);

0 comments on commit 74125a7

Please sign in to comment.