Skip to content

Commit

Permalink
Refactor|Resources|libdoomsday: Clearing all resources
Browse files Browse the repository at this point in the history
libdoomsday's Resources has a virtual method that clears all
resource allocations.
  • Loading branch information
skyjake committed Jan 21, 2016
1 parent 16d3634 commit 959c46b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/resource/resourcesystem.h
Expand Up @@ -128,6 +128,8 @@ class ResourceSystem : public Resources
*/
ResourceSystem();

void clear() override;

void clearAllResources();
void clearAllRuntimeResources();
void clearAllSystemResources();
Expand Down
8 changes: 1 addition & 7 deletions doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -1298,13 +1298,7 @@ bool App_ChangeGame(Game &game, bool allowReload)
if(App_GameLoaded())
{
DoomsdayApp::app().reset();

P_ShutdownMapEntityDefs();

R_ShutdownSvgs();
App_ResourceSystem().clearAllRuntimeResources();
App_ResourceSystem().clearAllAnimGroups();
App_ResourceSystem().clearAllColorPalettes();
Resources::get().clear();

App_AudioSystem().clearLogical();

Expand Down
13 changes: 13 additions & 0 deletions doomsday/apps/client/src/resource/resourcesystem.cpp
Expand Up @@ -70,6 +70,7 @@
#ifdef __CLIENT__
# include "gl/gl_tex.h"
# include "gl/gl_texmanager.h"
# include "gl/svg.h"
# include "render/rend_model.h"
# include "render/rend_particle.h" // Rend_ParticleReleaseSystemTextures

Expand Down Expand Up @@ -2252,6 +2253,18 @@ DENG2_PIMPL(ResourceSystem)
ResourceSystem::ResourceSystem() : d(new Instance(this))
{}

void ResourceSystem::clear()
{
Resources::clear();

#ifdef __CLIENT__
R_ShutdownSvgs();
#endif
clearAllRuntimeResources();
clearAllAnimGroups();
clearAllColorPalettes();
}

void ResourceSystem::clearAllResources()
{
clearAllRuntimeResources();
Expand Down
Expand Up @@ -51,6 +51,11 @@ class LIBDOOMSDAY_PUBLIC Resources : public de::System
// Systems observe the passage of time.
void timeChanged(de::Clock const &) override;

/**
* Release all allocations, returning to the initial state.
*/
virtual void clear();

/**
* Lookup a ResourceClass by symbolic @a name.
*/
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/libdoomsday/src/doomsdayapp.cpp
Expand Up @@ -25,6 +25,7 @@
#include "doomsday/filesys/datafolder.h"
#include "doomsday/paths.h"
#include "doomsday/world/world.h"
#include "doomsday/world/entitydef.h"
#include "doomsday/SavedSession"

#include <de/App>
Expand Down Expand Up @@ -495,6 +496,8 @@ void DoomsdayApp::reset()
World::get().reset();

Z_FreeTags(PU_GAMESTATIC, PU_PURGELEVEL - 1);

P_ShutdownMapEntityDefs();
}

void DoomsdayApp::setGame(Game &game)
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/libdoomsday/src/resource/resources.cpp
Expand Up @@ -73,6 +73,9 @@ void Resources::timeChanged(Clock const &)
// Nothing to do.
}

void Resources::clear()
{}

Resources &Resources::get()
{
DENG2_ASSERT(theResources);
Expand Down

0 comments on commit 959c46b

Please sign in to comment.