mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-28 19:23:53 +00:00
Drop textures when no longer needed
Textures used to be unloaded as soon as they were unreferenced. The TextureMgr cache keeps an active reference to prevent load-unload-load cycles so it only unloads things when explicitly asked. This does require some more peak VRAM during map/tileset transitions especially, since old textures are unloaded only after the next map has been loaded, but the shortened load times should be worth it.
This commit is contained in:
parent
6dc9dc7e8f
commit
9cd9601485
3 changed files with 29 additions and 0 deletions
|
@ -3219,6 +3219,9 @@ void Game::applyState()
|
|||
// cutscenes immediately. --achurch
|
||||
dsq->subtitlePlayer.show(0.25);
|
||||
|
||||
// First cleanup -- we're now done loading everything; anything leftover from the prev. map can go
|
||||
dsq->texmgr.clearUnused();
|
||||
|
||||
if (verbose) debugLog("loading map init script");
|
||||
if (dsq->mod.isActive())
|
||||
dsq->runScript(dsq->mod.getPath() + "scripts/map_" + sceneName + ".lua", "init", true);
|
||||
|
@ -3264,6 +3267,10 @@ void Game::applyState()
|
|||
dsq->toggleCursor(true, 0.5);
|
||||
}
|
||||
|
||||
// Second cleanup -- after the short map init fadeout, some entities may have
|
||||
// decided to remove themselves, in which case their gfx are no longer needed
|
||||
dsq->texmgr.clearUnused();
|
||||
|
||||
debugLog("Game::applyState Done");
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@ public:
|
|||
if (!--_refcount)
|
||||
delete this;
|
||||
}
|
||||
inline unsigned refcount() const
|
||||
{
|
||||
return _refcount;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned _refcount;
|
||||
|
|
|
@ -166,6 +166,24 @@ Texture* TextureMgr::getOrLoad(const std::string& name)
|
|||
return load(name, KEEP);
|
||||
}
|
||||
|
||||
void TextureMgr::clearUnused()
|
||||
{
|
||||
size_t done = 0;
|
||||
for(TexCache::iterator it = cache.begin(); it != cache.end(); )
|
||||
{
|
||||
if(it->second->refcount() <= 1)
|
||||
{
|
||||
it = cache.erase(it);
|
||||
++done;
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
std::ostringstream os;
|
||||
os << "TextureMgr: Dropped " << done << " unused textures, now " << cache.size() << " left";
|
||||
debugLog(os.str());
|
||||
}
|
||||
|
||||
void TextureMgr::shutdown()
|
||||
{
|
||||
for(TexCache::iterator it = cache.begin(); it != cache.end(); ++it)
|
||||
|
|
Loading…
Reference in a new issue