diff options
author | Einar Johan Trøan Sømåen | 2012-06-25 15:13:34 +0200 |
---|---|---|
committer | Einar Johan Trøan Sømåen | 2012-06-25 15:13:34 +0200 |
commit | e68ab9b5721caaafd99d9936dd372fa266069957 (patch) | |
tree | 9f38572f20c4397d4870a44d429b6b231b1f5e64 | |
parent | d495c588977fc63e42c986e8404ac23ba40a4923 (diff) | |
download | scummvm-rg350-e68ab9b5721caaafd99d9936dd372fa266069957.tar.gz scummvm-rg350-e68ab9b5721caaafd99d9936dd372fa266069957.tar.bz2 scummvm-rg350-e68ab9b5721caaafd99d9936dd372fa266069957.zip |
WINTERMUTE: Make the ClassRegistry clean up after itself when returning to launcher
-rw-r--r-- | engines/wintermute/Sys/SysClassRegistry.cpp | 12 | ||||
-rw-r--r-- | engines/wintermute/Sys/SysClassRegistry.h | 8 | ||||
-rw-r--r-- | engines/wintermute/persistent.cpp | 4 | ||||
-rw-r--r-- | engines/wintermute/persistent.h | 2 | ||||
-rw-r--r-- | engines/wintermute/wintermute.cpp | 10 | ||||
-rw-r--r-- | engines/wintermute/wintermute.h | 4 |
6 files changed, 30 insertions, 10 deletions
diff --git a/engines/wintermute/Sys/SysClassRegistry.cpp b/engines/wintermute/Sys/SysClassRegistry.cpp index 05412ae0e9..0a41b59d35 100644 --- a/engines/wintermute/Sys/SysClassRegistry.cpp +++ b/engines/wintermute/Sys/SysClassRegistry.cpp @@ -28,6 +28,7 @@ #include "engines/wintermute/Base/BGame.h"
#include "engines/wintermute/PlatformSDL.h"
+#include "engines/wintermute/wintermute.h"
#include "SysInstance.h"
#include "SysClassRegistry.h"
#include "common/stream.h"
@@ -41,15 +42,20 @@ CSysClassRegistry::CSysClassRegistry() { //////////////////////////////////////////////////////////////////////////
CSysClassRegistry::~CSysClassRegistry() {
-
+ unregisterClasses();
}
//////////////////////////////////////////////////////////////////////////
CSysClassRegistry *CSysClassRegistry::GetInstance() {
- static CSysClassRegistry classReg;
- return &classReg;
+ return g_wintermute->getClassRegistry();
}
+void CSysClassRegistry::unregisterClasses() {
+ // CSysClass calls UnregisterClass upon destruction.
+ while (_classes.size() > 0) {
+ delete _classes.begin()->_value;
+ }
+}
//////////////////////////////////////////////////////////////////////////
bool CSysClassRegistry::RegisterClass(CSysClass *classObj) {
diff --git a/engines/wintermute/Sys/SysClassRegistry.h b/engines/wintermute/Sys/SysClassRegistry.h index 30516d4636..6bc2c11fcf 100644 --- a/engines/wintermute/Sys/SysClassRegistry.h +++ b/engines/wintermute/Sys/SysClassRegistry.h @@ -58,9 +58,14 @@ class CBPersistMgr; class CSysInstance;
class CSysClassRegistry {
+ void unregisterClasses();
public:
+ void registerClasses(); // persistent.cpp
static CSysClassRegistry *GetInstance();
+ CSysClassRegistry();
+ virtual ~CSysClassRegistry();
+
HRESULT EnumInstances(SYS_INSTANCE_CALLBACK lpCallback, const char *className, void *lpData);
HRESULT LoadTable(CBGame *Game, CBPersistMgr *PersistMgr);
HRESULT SaveTable(CBGame *Game, CBPersistMgr *PersistMgr, bool quickSave);
@@ -76,9 +81,6 @@ public: int GetNextID();
void AddInstanceToTable(CSysInstance *instance, void *pointer);
- CSysClassRegistry();
- virtual ~CSysClassRegistry();
-
bool _disabled;
int _count;
diff --git a/engines/wintermute/persistent.cpp b/engines/wintermute/persistent.cpp index 3b8f70bf0c..2e80f20049 100644 --- a/engines/wintermute/persistent.cpp +++ b/engines/wintermute/persistent.cpp @@ -88,12 +88,14 @@ #include "engines/wintermute/UI/UIWindow.h" #include "engines/wintermute/video/VidTheoraPlayer.h" +// CSysClass adds these objects to the registry, thus they aren't as leaked as they look #define REGISTER_CLASS(class_name, persistent_class)\ new WinterMute::CSysClass(class_name::_className, class_name::PersistBuild, class_name::PersistLoad, persistent_class); namespace WinterMute { -void registerClasses() { +// This is done in a separate file, to avoid including the kitchensink in CSysClassRegistry. +void CSysClassRegistry::registerClasses() { REGISTER_CLASS(CAdActor, false) REGISTER_CLASS(CAdEntity, false) REGISTER_CLASS(CAdGame, true) diff --git a/engines/wintermute/persistent.h b/engines/wintermute/persistent.h index 7184d48829..30f9cd8780 100644 --- a/engines/wintermute/persistent.h +++ b/engines/wintermute/persistent.h @@ -87,8 +87,6 @@ namespace WinterMute { #define TMEMBER(member_name) #member_name, &member_name #define TMEMBER_INT(member_name) #member_name, (int*)&member_name -void registerClasses(); - } // end of namespace WinterMute #endif // WINTERMUTE_PERSISTENT_H diff --git a/engines/wintermute/wintermute.cpp b/engines/wintermute/wintermute.cpp index 06ab932f21..f34aa0d9f6 100644 --- a/engines/wintermute/wintermute.cpp +++ b/engines/wintermute/wintermute.cpp @@ -66,6 +66,7 @@ WinterMuteEngine::WinterMuteEngine(OSystem *syst) _game = NULL; g_wintermute = this; + _classReg = NULL; } WinterMuteEngine::~WinterMuteEngine() { @@ -132,11 +133,14 @@ Common::Error WinterMuteEngine::run() { if (ret == 0) { ret = messageLoop(); } + deinit(); return Common::kNoError; } int WinterMuteEngine::init() { - registerClasses(); // Needs to be done before the first WME class is instantiated + _classReg = new CSysClassRegistry(); + _classReg->registerClasses(); + _game = new CAdGame; if (!_game) return 1; CBPlatform::Initialize(_game, 0, NULL); @@ -306,6 +310,10 @@ int WinterMuteEngine::messageLoop() { return 0; } +void WinterMuteEngine::deinit() { + delete _classReg; +} + uint32 WinterMuteEngine::randInt(int from, int to) { return _rnd->getRandomNumberRng(from, to); } diff --git a/engines/wintermute/wintermute.h b/engines/wintermute/wintermute.h index 92dbedc6b5..c3ade92fe4 100644 --- a/engines/wintermute/wintermute.h +++ b/engines/wintermute/wintermute.h @@ -31,6 +31,7 @@ namespace WinterMute { class Console; class CBGame; +class CSysClassRegistry; // our engine debug channels enum { kWinterMuteDebugExample = 1 << 0, @@ -47,12 +48,15 @@ public: virtual Common::Error run(); virtual bool hasFeature(EngineFeature f) const; Common::SaveFileManager *getSaveFileMan() { return _saveFileMan; } + CSysClassRegistry *getClassRegistry(){ return _classReg; } uint32 randInt(int from, int to); private: int init(); + void deinit(); int messageLoop(); Console *_console; CBGame *_game; + CSysClassRegistry *_classReg; // We need random numbers Common::RandomSource *_rnd; }; |