From 959c46befe16ec1168d41b49cf33f74d8fa8a998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Thu, 21 Jan 2016 22:05:20 +0200 Subject: [PATCH] Refactor|Resources|libdoomsday: Clearing all resources libdoomsday's Resources has a virtual method that clears all resource allocations. --- .../apps/client/include/resource/resourcesystem.h | 2 ++ doomsday/apps/client/src/dd_main.cpp | 8 +------- .../apps/client/src/resource/resourcesystem.cpp | 13 +++++++++++++ .../include/doomsday/resource/resources.h | 5 +++++ doomsday/apps/libdoomsday/src/doomsdayapp.cpp | 3 +++ .../apps/libdoomsday/src/resource/resources.cpp | 3 +++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/doomsday/apps/client/include/resource/resourcesystem.h b/doomsday/apps/client/include/resource/resourcesystem.h index 17097a6a53..7d5feac7f5 100644 --- a/doomsday/apps/client/include/resource/resourcesystem.h +++ b/doomsday/apps/client/include/resource/resourcesystem.h @@ -128,6 +128,8 @@ class ResourceSystem : public Resources */ ResourceSystem(); + void clear() override; + void clearAllResources(); void clearAllRuntimeResources(); void clearAllSystemResources(); diff --git a/doomsday/apps/client/src/dd_main.cpp b/doomsday/apps/client/src/dd_main.cpp index 397826dba8..1eee9c28f1 100644 --- a/doomsday/apps/client/src/dd_main.cpp +++ b/doomsday/apps/client/src/dd_main.cpp @@ -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(); diff --git a/doomsday/apps/client/src/resource/resourcesystem.cpp b/doomsday/apps/client/src/resource/resourcesystem.cpp index 5efcd7c70e..b226698c6f 100644 --- a/doomsday/apps/client/src/resource/resourcesystem.cpp +++ b/doomsday/apps/client/src/resource/resourcesystem.cpp @@ -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 @@ -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(); diff --git a/doomsday/apps/libdoomsday/include/doomsday/resource/resources.h b/doomsday/apps/libdoomsday/include/doomsday/resource/resources.h index e0b88c2a1b..ab567822f7 100644 --- a/doomsday/apps/libdoomsday/include/doomsday/resource/resources.h +++ b/doomsday/apps/libdoomsday/include/doomsday/resource/resources.h @@ -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. */ diff --git a/doomsday/apps/libdoomsday/src/doomsdayapp.cpp b/doomsday/apps/libdoomsday/src/doomsdayapp.cpp index 602e5f55cb..8f6ab81c7c 100644 --- a/doomsday/apps/libdoomsday/src/doomsdayapp.cpp +++ b/doomsday/apps/libdoomsday/src/doomsdayapp.cpp @@ -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 @@ -495,6 +496,8 @@ void DoomsdayApp::reset() World::get().reset(); Z_FreeTags(PU_GAMESTATIC, PU_PURGELEVEL - 1); + + P_ShutdownMapEntityDefs(); } void DoomsdayApp::setGame(Game &game) diff --git a/doomsday/apps/libdoomsday/src/resource/resources.cpp b/doomsday/apps/libdoomsday/src/resource/resources.cpp index 26cfdde4fe..12c1b6ffcc 100644 --- a/doomsday/apps/libdoomsday/src/resource/resources.cpp +++ b/doomsday/apps/libdoomsday/src/resource/resources.cpp @@ -73,6 +73,9 @@ void Resources::timeChanged(Clock const &) // Nothing to do. } +void Resources::clear() +{} + Resources &Resources::get() { DENG2_ASSERT(theResources);