From 5683f076331d2831eb4720b65bb53e8d01ca33ee Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Sat, 21 Jul 2012 18:19:07 +0200
Subject: WINTERMUTE: Rename CamelCased filenames to
prefixed_under_score-filenames
This is mostly a lead-up to namespacing the Ad/Base folders, and then
possibly removing the prefixes from the files, it also has the added
benefit of getting rid of the odd case-typos that makes for issues
on platforms that don't ignore case.
---
engines/wintermute/system/sys_class_registry.cpp | 315 +++++++++++++++++++++++
1 file changed, 315 insertions(+)
create mode 100644 engines/wintermute/system/sys_class_registry.cpp
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
new file mode 100644
index 0000000000..ce14b01385
--- /dev/null
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -0,0 +1,315 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#include "engines/wintermute/base/base_game.h"
+#include "engines/wintermute/platform_osystem.h"
+#include "engines/wintermute/wintermute.h"
+#include "engines/wintermute/system/sys_instance.h"
+#include "engines/wintermute/system/sys_class_registry.h"
+#include "engines/wintermute/system/sys_class.h"
+#include "common/stream.h"
+
+namespace WinterMute {
+
+//////////////////////////////////////////////////////////////////////////
+CSysClassRegistry::CSysClassRegistry() {
+ _count = 0;
+ _disabled = false;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+CSysClassRegistry::~CSysClassRegistry() {
+ unregisterClasses();
+}
+
+//////////////////////////////////////////////////////////////////////////
+CSysClassRegistry *CSysClassRegistry::getInstance() {
+ 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) {
+ classObj->setID(_count++);
+ //_classes.insert(classObj);
+ _classes[classObj] = classObj;
+
+ _nameMap[classObj->getName()] = classObj;
+ _idMap[classObj->getID()] = classObj;
+
+ return true;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::unregisterClass(CSysClass *classObj) {
+
+ Classes::iterator it = _classes.find(classObj);
+ if (it == _classes.end()) return false;
+
+ if (classObj->getNumInstances() != 0) {
+ char str[MAX_PATH_LENGTH];
+ sprintf(str, "Memory leak@class %-20s: %d instance(s) left\n", classObj->getName().c_str(), classObj->getNumInstances());
+ CBPlatform::outputDebugString(str);
+ }
+ _classes.erase(it);
+
+ NameMap::iterator mapIt = _nameMap.find(classObj->getName());
+ if (mapIt != _nameMap.end()) _nameMap.erase(mapIt);
+
+ IdMap::iterator idIt = _idMap.find(classObj->getID());
+ if (idIt != _idMap.end()) _idMap.erase(idIt);
+
+
+ return true;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::registerInstance(const char *className, void *instance) {
+ if (_disabled) return true;
+
+ NameMap::iterator mapIt = _nameMap.find(className);
+ if (mapIt == _nameMap.end()) return false;
+
+ CSysInstance *inst = (*mapIt)._value->addInstance(instance, _count++);
+ return (inst != NULL);
+}
+
+//////////////////////////////////////////////////////////////////////////
+void CSysClassRegistry::addInstanceToTable(CSysInstance *instance, void *pointer) {
+ _instanceMap[pointer] = instance;
+
+ if (instance->getSavedID() >= 0)
+ _savedInstanceMap[instance->getSavedID()] = instance;
+}
+
+//////////////////////////////////////////////////////////////////////////
+int CSysClassRegistry::getNextID() {
+ return _count++;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::unregisterInstance(const char *className, void *instance) {
+ NameMap::iterator mapIt = _nameMap.find(className);
+ if (mapIt == _nameMap.end()) return false;
+ (*mapIt)._value->removeInstance(instance);
+
+ InstanceMap::iterator instIt = _instanceMap.find(instance);
+ if (instIt != _instanceMap.end()) {
+ _instanceMap.erase(instIt);
+ return true;
+ } else return false;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::getPointerID(void *pointer, int *classID, int *instanceID) {
+ if (pointer == NULL) return true;
+
+ InstanceMap::iterator it = _instanceMap.find(pointer);
+ if (it == _instanceMap.end()) return false;
+
+
+ CSysInstance *inst = (*it)._value;
+ *instanceID = inst->getID();
+ *classID = inst->getClass()->getID();
+
+ return true;
+}
+
+//////////////////////////////////////////////////////////////////////////
+void *CSysClassRegistry::idToPointer(int classID, int instanceID) {
+ SavedInstanceMap::iterator it = _savedInstanceMap.find(instanceID);
+ if (it == _savedInstanceMap.end()) return NULL;
+ else return (*it)._value->getInstance();
+}
+
+bool checkHeader(const char *tag, CBPersistMgr *pm) {
+ char *test = pm->getString();
+ Common::String verify = test;
+ delete[] test;
+ bool retVal = (verify == tag);
+ if (!retVal) {
+ error("Expected %s in Save-file not found", tag);
+ }
+ return retVal;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::saveTable(CBGame *gameRef, CBPersistMgr *persistMgr, bool quickSave) {
+ persistMgr->putString("");
+ persistMgr->putDWORD(_classes.size());
+
+ int counter = 0;
+
+ Classes::iterator it;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ counter++;
+
+ if (!quickSave) {
+ gameRef->_indicatorProgress = (int)(50.0f / (float)((float)_classes.size() / (float)counter));
+ gameRef->displayContent(false);
+ gameRef->_renderer->flip();
+ }
+
+ (it->_value)->saveTable(gameRef, persistMgr);
+ }
+ persistMgr->putString("");
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::loadTable(CBGame *gameRef, CBPersistMgr *persistMgr) {
+ checkHeader("", persistMgr);
+
+ // reset SavedID of current instances
+ Classes::iterator it;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ (it->_value)->resetSavedIDs();
+ }
+
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ if ((it->_value)->isPersistent()) continue;
+ (it->_value)->removeAllInstances();
+ }
+
+ _instanceMap.clear();
+
+ uint32 numClasses = persistMgr->getDWORD();
+
+ for (uint32 i = 0; i < numClasses; i++) {
+ gameRef->_indicatorProgress = (int)(50.0f / (float)((float)numClasses / (float)i));
+ gameRef->displayContentSimple();
+ gameRef->_renderer->flip();
+
+ Common::String className = persistMgr->getStringObj();
+ NameMap::iterator mapIt = _nameMap.find(className);
+ if (mapIt != _nameMap.end())(*mapIt)._value->loadTable(gameRef, persistMgr);
+ }
+
+ checkHeader("", persistMgr);
+
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::saveInstances(CBGame *gameRef, CBPersistMgr *persistMgr, bool quickSave) {
+
+ Classes::iterator it;
+
+ // count total instances
+ int numInstances = 0;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ numInstances += (it->_value)->getNumInstances();
+ }
+
+ persistMgr->putDWORD(numInstances);
+
+ int counter = 0;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ counter++;
+
+ if (!quickSave) {
+ if (counter % 20 == 0) {
+ gameRef->_indicatorProgress = (int)(50.0f + 50.0f / (float)((float)_classes.size() / (float)counter));
+ gameRef->displayContent(false);
+ gameRef->_renderer->flip();
+ }
+ }
+ gameRef->miniUpdate();
+
+ (it->_value)->saveInstances(gameRef, persistMgr);
+ }
+
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::loadInstances(CBGame *gameRef, CBPersistMgr *persistMgr) {
+ // get total instances
+ int numInstances = persistMgr->getDWORD();
+
+ for (int i = 0; i < numInstances; i++) {
+ if (i % 20 == 0) {
+ gameRef->_indicatorProgress = (int)(50.0f + 50.0f / (float)((float)numInstances / (float)i));
+ gameRef->displayContentSimple();
+ gameRef->_renderer->flip();
+ }
+
+ checkHeader("", persistMgr);
+
+ int classID = persistMgr->getDWORD();
+ int instanceID = persistMgr->getDWORD();
+ void *instance = idToPointer(classID, instanceID);
+
+ checkHeader("", persistMgr);
+
+ Classes::iterator it;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ if ((it->_value)->getSavedID() == classID) {
+ (it->_value)->loadInstance(instance, persistMgr);
+ break;
+ }
+ }
+ checkHeader("", persistMgr);
+ }
+
+ _savedInstanceMap.clear();
+
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool CSysClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const char *className, void *lpData) {
+ NameMap::iterator mapIt = _nameMap.find(className);
+ if (mapIt == _nameMap.end()) return STATUS_FAILED;
+
+ (*mapIt)._value->instanceCallback(lpCallback, lpData);
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+void CSysClassRegistry::dumpClasses(Common::WriteStream *stream) {
+ Classes::iterator it;
+ for (it = _classes.begin(); it != _classes.end(); ++it)
+ (it->_value)->dump(stream);
+}
+
+} // end of namespace WinterMute
--
cgit v1.2.3
From b5a07fef8ebf29f7f44b15d9b34799c7e115fdad Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Sat, 21 Jul 2012 21:01:47 +0200
Subject: WINTERMUTE: Get rid of the C-prefix for class-definitions.
---
engines/wintermute/system/sys_class_registry.cpp | 46 ++++++++++++------------
1 file changed, 23 insertions(+), 23 deletions(-)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index ce14b01385..7f7814f75c 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -37,31 +37,31 @@
namespace WinterMute {
//////////////////////////////////////////////////////////////////////////
-CSysClassRegistry::CSysClassRegistry() {
+SystemClassRegistry::SystemClassRegistry() {
_count = 0;
_disabled = false;
}
//////////////////////////////////////////////////////////////////////////
-CSysClassRegistry::~CSysClassRegistry() {
+SystemClassRegistry::~SystemClassRegistry() {
unregisterClasses();
}
//////////////////////////////////////////////////////////////////////////
-CSysClassRegistry *CSysClassRegistry::getInstance() {
+SystemClassRegistry *SystemClassRegistry::getInstance() {
return g_wintermute->getClassRegistry();
}
-void CSysClassRegistry::unregisterClasses() {
- // CSysClass calls UnregisterClass upon destruction.
+void SystemClassRegistry::unregisterClasses() {
+ // SystemClass calls UnregisterClass upon destruction.
while (_classes.size() > 0) {
delete _classes.begin()->_value;
}
}
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::registerClass(CSysClass *classObj) {
+bool SystemClassRegistry::registerClass(SystemClass *classObj) {
classObj->setID(_count++);
//_classes.insert(classObj);
_classes[classObj] = classObj;
@@ -74,7 +74,7 @@ bool CSysClassRegistry::registerClass(CSysClass *classObj) {
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::unregisterClass(CSysClass *classObj) {
+bool SystemClassRegistry::unregisterClass(SystemClass *classObj) {
Classes::iterator it = _classes.find(classObj);
if (it == _classes.end()) return false;
@@ -82,7 +82,7 @@ bool CSysClassRegistry::unregisterClass(CSysClass *classObj) {
if (classObj->getNumInstances() != 0) {
char str[MAX_PATH_LENGTH];
sprintf(str, "Memory leak@class %-20s: %d instance(s) left\n", classObj->getName().c_str(), classObj->getNumInstances());
- CBPlatform::outputDebugString(str);
+ BasePlatform::outputDebugString(str);
}
_classes.erase(it);
@@ -98,18 +98,18 @@ bool CSysClassRegistry::unregisterClass(CSysClass *classObj) {
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::registerInstance(const char *className, void *instance) {
+bool SystemClassRegistry::registerInstance(const char *className, void *instance) {
if (_disabled) return true;
NameMap::iterator mapIt = _nameMap.find(className);
if (mapIt == _nameMap.end()) return false;
- CSysInstance *inst = (*mapIt)._value->addInstance(instance, _count++);
+ SystemInstance *inst = (*mapIt)._value->addInstance(instance, _count++);
return (inst != NULL);
}
//////////////////////////////////////////////////////////////////////////
-void CSysClassRegistry::addInstanceToTable(CSysInstance *instance, void *pointer) {
+void SystemClassRegistry::addInstanceToTable(SystemInstance *instance, void *pointer) {
_instanceMap[pointer] = instance;
if (instance->getSavedID() >= 0)
@@ -117,12 +117,12 @@ void CSysClassRegistry::addInstanceToTable(CSysInstance *instance, void *pointer
}
//////////////////////////////////////////////////////////////////////////
-int CSysClassRegistry::getNextID() {
+int SystemClassRegistry::getNextID() {
return _count++;
}
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::unregisterInstance(const char *className, void *instance) {
+bool SystemClassRegistry::unregisterInstance(const char *className, void *instance) {
NameMap::iterator mapIt = _nameMap.find(className);
if (mapIt == _nameMap.end()) return false;
(*mapIt)._value->removeInstance(instance);
@@ -136,14 +136,14 @@ bool CSysClassRegistry::unregisterInstance(const char *className, void *instance
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::getPointerID(void *pointer, int *classID, int *instanceID) {
+bool SystemClassRegistry::getPointerID(void *pointer, int *classID, int *instanceID) {
if (pointer == NULL) return true;
InstanceMap::iterator it = _instanceMap.find(pointer);
if (it == _instanceMap.end()) return false;
- CSysInstance *inst = (*it)._value;
+ SystemInstance *inst = (*it)._value;
*instanceID = inst->getID();
*classID = inst->getClass()->getID();
@@ -151,13 +151,13 @@ bool CSysClassRegistry::getPointerID(void *pointer, int *classID, int *instanceI
}
//////////////////////////////////////////////////////////////////////////
-void *CSysClassRegistry::idToPointer(int classID, int instanceID) {
+void *SystemClassRegistry::idToPointer(int classID, int instanceID) {
SavedInstanceMap::iterator it = _savedInstanceMap.find(instanceID);
if (it == _savedInstanceMap.end()) return NULL;
else return (*it)._value->getInstance();
}
-bool checkHeader(const char *tag, CBPersistMgr *pm) {
+bool checkHeader(const char *tag, BasePersistenceManager *pm) {
char *test = pm->getString();
Common::String verify = test;
delete[] test;
@@ -169,7 +169,7 @@ bool checkHeader(const char *tag, CBPersistMgr *pm) {
}
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::saveTable(CBGame *gameRef, CBPersistMgr *persistMgr, bool quickSave) {
+bool SystemClassRegistry::saveTable(BaseGame *gameRef, BasePersistenceManager *persistMgr, bool quickSave) {
persistMgr->putString("");
persistMgr->putDWORD(_classes.size());
@@ -193,7 +193,7 @@ bool CSysClassRegistry::saveTable(CBGame *gameRef, CBPersistMgr *persistMgr, boo
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::loadTable(CBGame *gameRef, CBPersistMgr *persistMgr) {
+bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *persistMgr) {
checkHeader("", persistMgr);
// reset SavedID of current instances
@@ -228,7 +228,7 @@ bool CSysClassRegistry::loadTable(CBGame *gameRef, CBPersistMgr *persistMgr) {
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::saveInstances(CBGame *gameRef, CBPersistMgr *persistMgr, bool quickSave) {
+bool SystemClassRegistry::saveInstances(BaseGame *gameRef, BasePersistenceManager *persistMgr, bool quickSave) {
Classes::iterator it;
@@ -260,7 +260,7 @@ bool CSysClassRegistry::saveInstances(CBGame *gameRef, CBPersistMgr *persistMgr,
}
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::loadInstances(CBGame *gameRef, CBPersistMgr *persistMgr) {
+bool SystemClassRegistry::loadInstances(BaseGame *gameRef, BasePersistenceManager *persistMgr) {
// get total instances
int numInstances = persistMgr->getDWORD();
@@ -296,7 +296,7 @@ bool CSysClassRegistry::loadInstances(CBGame *gameRef, CBPersistMgr *persistMgr)
//////////////////////////////////////////////////////////////////////////
-bool CSysClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const char *className, void *lpData) {
+bool SystemClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const char *className, void *lpData) {
NameMap::iterator mapIt = _nameMap.find(className);
if (mapIt == _nameMap.end()) return STATUS_FAILED;
@@ -306,7 +306,7 @@ bool CSysClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const ch
//////////////////////////////////////////////////////////////////////////
-void CSysClassRegistry::dumpClasses(Common::WriteStream *stream) {
+void SystemClassRegistry::dumpClasses(Common::WriteStream *stream) {
Classes::iterator it;
for (it = _classes.begin(); it != _classes.end(); ++it)
(it->_value)->dump(stream);
--
cgit v1.2.3
From ef11f9d0c53cbdd9d88a99143de6f43f34d7e24d Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Thu, 26 Jul 2012 15:59:26 +0200
Subject: WINTERMUTE: Run Astyle with add-braces to break one-line statements
into easier-to-read-code.
---
engines/wintermute/system/sys_class_registry.cpp | 61 +++++++++++++++++-------
1 file changed, 45 insertions(+), 16 deletions(-)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index 7f7814f75c..47910af4e8 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -77,7 +77,9 @@ bool SystemClassRegistry::registerClass(SystemClass *classObj) {
bool SystemClassRegistry::unregisterClass(SystemClass *classObj) {
Classes::iterator it = _classes.find(classObj);
- if (it == _classes.end()) return false;
+ if (it == _classes.end()) {
+ return false;
+ }
if (classObj->getNumInstances() != 0) {
char str[MAX_PATH_LENGTH];
@@ -87,10 +89,14 @@ bool SystemClassRegistry::unregisterClass(SystemClass *classObj) {
_classes.erase(it);
NameMap::iterator mapIt = _nameMap.find(classObj->getName());
- if (mapIt != _nameMap.end()) _nameMap.erase(mapIt);
+ if (mapIt != _nameMap.end()) {
+ _nameMap.erase(mapIt);
+ }
IdMap::iterator idIt = _idMap.find(classObj->getID());
- if (idIt != _idMap.end()) _idMap.erase(idIt);
+ if (idIt != _idMap.end()) {
+ _idMap.erase(idIt);
+ }
return true;
@@ -99,10 +105,14 @@ bool SystemClassRegistry::unregisterClass(SystemClass *classObj) {
//////////////////////////////////////////////////////////////////////////
bool SystemClassRegistry::registerInstance(const char *className, void *instance) {
- if (_disabled) return true;
+ if (_disabled) {
+ return true;
+ }
NameMap::iterator mapIt = _nameMap.find(className);
- if (mapIt == _nameMap.end()) return false;
+ if (mapIt == _nameMap.end()) {
+ return false;
+ }
SystemInstance *inst = (*mapIt)._value->addInstance(instance, _count++);
return (inst != NULL);
@@ -112,8 +122,9 @@ bool SystemClassRegistry::registerInstance(const char *className, void *instance
void SystemClassRegistry::addInstanceToTable(SystemInstance *instance, void *pointer) {
_instanceMap[pointer] = instance;
- if (instance->getSavedID() >= 0)
+ if (instance->getSavedID() >= 0) {
_savedInstanceMap[instance->getSavedID()] = instance;
+ }
}
//////////////////////////////////////////////////////////////////////////
@@ -124,23 +135,31 @@ int SystemClassRegistry::getNextID() {
//////////////////////////////////////////////////////////////////////////
bool SystemClassRegistry::unregisterInstance(const char *className, void *instance) {
NameMap::iterator mapIt = _nameMap.find(className);
- if (mapIt == _nameMap.end()) return false;
+ if (mapIt == _nameMap.end()) {
+ return false;
+ }
(*mapIt)._value->removeInstance(instance);
InstanceMap::iterator instIt = _instanceMap.find(instance);
if (instIt != _instanceMap.end()) {
_instanceMap.erase(instIt);
return true;
- } else return false;
+ } else {
+ return false;
+ }
}
//////////////////////////////////////////////////////////////////////////
bool SystemClassRegistry::getPointerID(void *pointer, int *classID, int *instanceID) {
- if (pointer == NULL) return true;
+ if (pointer == NULL) {
+ return true;
+ }
InstanceMap::iterator it = _instanceMap.find(pointer);
- if (it == _instanceMap.end()) return false;
+ if (it == _instanceMap.end()) {
+ return false;
+ }
SystemInstance *inst = (*it)._value;
@@ -153,8 +172,11 @@ bool SystemClassRegistry::getPointerID(void *pointer, int *classID, int *instanc
//////////////////////////////////////////////////////////////////////////
void *SystemClassRegistry::idToPointer(int classID, int instanceID) {
SavedInstanceMap::iterator it = _savedInstanceMap.find(instanceID);
- if (it == _savedInstanceMap.end()) return NULL;
- else return (*it)._value->getInstance();
+ if (it == _savedInstanceMap.end()) {
+ return NULL;
+ } else {
+ return (*it)._value->getInstance();
+ }
}
bool checkHeader(const char *tag, BasePersistenceManager *pm) {
@@ -203,7 +225,9 @@ bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *p
}
for (it = _classes.begin(); it != _classes.end(); ++it) {
- if ((it->_value)->isPersistent()) continue;
+ if ((it->_value)->isPersistent()) {
+ continue;
+ }
(it->_value)->removeAllInstances();
}
@@ -218,7 +242,9 @@ bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *p
Common::String className = persistMgr->getStringObj();
NameMap::iterator mapIt = _nameMap.find(className);
- if (mapIt != _nameMap.end())(*mapIt)._value->loadTable(gameRef, persistMgr);
+ if (mapIt != _nameMap.end()) {
+ (*mapIt)._value->loadTable(gameRef, persistMgr);
+ }
}
checkHeader("", persistMgr);
@@ -298,7 +324,9 @@ bool SystemClassRegistry::loadInstances(BaseGame *gameRef, BasePersistenceManage
//////////////////////////////////////////////////////////////////////////
bool SystemClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const char *className, void *lpData) {
NameMap::iterator mapIt = _nameMap.find(className);
- if (mapIt == _nameMap.end()) return STATUS_FAILED;
+ if (mapIt == _nameMap.end()) {
+ return STATUS_FAILED;
+ }
(*mapIt)._value->instanceCallback(lpCallback, lpData);
return STATUS_OK;
@@ -308,8 +336,9 @@ bool SystemClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const
//////////////////////////////////////////////////////////////////////////
void SystemClassRegistry::dumpClasses(Common::WriteStream *stream) {
Classes::iterator it;
- for (it = _classes.begin(); it != _classes.end(); ++it)
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
(it->_value)->dump(stream);
+ }
}
} // end of namespace WinterMute
--
cgit v1.2.3
From c7fa8e7d1024e4447a7396b5099870d01b775746 Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Fri, 27 Jul 2012 19:35:20 +0200
Subject: WINTERMUTE: Move settings-files to save-dir (gzipped xml now)
---
engines/wintermute/system/sys_class_registry.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index 47910af4e8..09e43529e3 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -82,9 +82,7 @@ bool SystemClassRegistry::unregisterClass(SystemClass *classObj) {
}
if (classObj->getNumInstances() != 0) {
- char str[MAX_PATH_LENGTH];
- sprintf(str, "Memory leak@class %-20s: %d instance(s) left\n", classObj->getName().c_str(), classObj->getNumInstances());
- BasePlatform::outputDebugString(str);
+ debugC(WinterMute::kWinterMuteDebugSaveGame, "Memory leak@class %-20s: %d instance(s) left\n", classObj->getName().c_str(), classObj->getNumInstances());
}
_classes.erase(it);
--
cgit v1.2.3
From 85ce9340bcb425a6c5e8dbcacff5a7fa2fb4c817 Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Sun, 29 Jul 2012 21:35:11 +0200
Subject: WINTERMUTE: Separate out SaveGame-code from BaseGame
---
engines/wintermute/system/sys_class_registry.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index 09e43529e3..e991fb3f07 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -200,7 +200,7 @@ bool SystemClassRegistry::saveTable(BaseGame *gameRef, BasePersistenceManager *p
counter++;
if (!quickSave) {
- gameRef->_indicatorProgress = (int)(50.0f / (float)((float)_classes.size() / (float)counter));
+ gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)_classes.size() / (float)counter)));
gameRef->displayContent(false);
gameRef->_renderer->flip();
}
@@ -234,7 +234,7 @@ bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *p
uint32 numClasses = persistMgr->getDWORD();
for (uint32 i = 0; i < numClasses; i++) {
- gameRef->_indicatorProgress = (int)(50.0f / (float)((float)numClasses / (float)i));
+ gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)numClasses / (float)i)));
gameRef->displayContentSimple();
gameRef->_renderer->flip();
@@ -270,7 +270,7 @@ bool SystemClassRegistry::saveInstances(BaseGame *gameRef, BasePersistenceManage
if (!quickSave) {
if (counter % 20 == 0) {
- gameRef->_indicatorProgress = (int)(50.0f + 50.0f / (float)((float)_classes.size() / (float)counter));
+ gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)_classes.size() / (float)counter)));
gameRef->displayContent(false);
gameRef->_renderer->flip();
}
@@ -290,7 +290,7 @@ bool SystemClassRegistry::loadInstances(BaseGame *gameRef, BasePersistenceManage
for (int i = 0; i < numInstances; i++) {
if (i % 20 == 0) {
- gameRef->_indicatorProgress = (int)(50.0f + 50.0f / (float)((float)numInstances / (float)i));
+ gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)numInstances / (float)i)));
gameRef->displayContentSimple();
gameRef->_renderer->flip();
}
--
cgit v1.2.3
From 43611724441e880b7283ae195d40f5e63aa6affd Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Mon, 30 Jul 2012 19:41:44 +0200
Subject: WINTERMUTE: Redraw ONLY the indicator when saving/loading.
---
engines/wintermute/system/sys_class_registry.cpp | 8 --------
1 file changed, 8 deletions(-)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index e991fb3f07..d9303ea729 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -201,8 +201,6 @@ bool SystemClassRegistry::saveTable(BaseGame *gameRef, BasePersistenceManager *p
if (!quickSave) {
gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)_classes.size() / (float)counter)));
- gameRef->displayContent(false);
- gameRef->_renderer->flip();
}
(it->_value)->saveTable(gameRef, persistMgr);
@@ -235,8 +233,6 @@ bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *p
for (uint32 i = 0; i < numClasses; i++) {
gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)numClasses / (float)i)));
- gameRef->displayContentSimple();
- gameRef->_renderer->flip();
Common::String className = persistMgr->getStringObj();
NameMap::iterator mapIt = _nameMap.find(className);
@@ -271,8 +267,6 @@ bool SystemClassRegistry::saveInstances(BaseGame *gameRef, BasePersistenceManage
if (!quickSave) {
if (counter % 20 == 0) {
gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)_classes.size() / (float)counter)));
- gameRef->displayContent(false);
- gameRef->_renderer->flip();
}
}
gameRef->miniUpdate();
@@ -291,8 +285,6 @@ bool SystemClassRegistry::loadInstances(BaseGame *gameRef, BasePersistenceManage
for (int i = 0; i < numInstances; i++) {
if (i % 20 == 0) {
gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)numInstances / (float)i)));
- gameRef->displayContentSimple();
- gameRef->_renderer->flip();
}
checkHeader("", persistMgr);
--
cgit v1.2.3
From 6b159d71ab212feb4e93bae412a7352ead59241b Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Tue, 7 Aug 2012 13:51:22 +0200
Subject: WINTERMUTE: Remove g_wintermute.
---
engines/wintermute/system/sys_class_registry.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index d9303ea729..b9e9bc8878 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -28,10 +28,11 @@
#include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/platform_osystem.h"
-#include "engines/wintermute/wintermute.h"
+#include "engines/wintermute/base/base_engine.h"
#include "engines/wintermute/system/sys_instance.h"
#include "engines/wintermute/system/sys_class_registry.h"
#include "engines/wintermute/system/sys_class.h"
+#include "engines/wintermute/wintermute.h"
#include "common/stream.h"
namespace WinterMute {
@@ -50,7 +51,7 @@ SystemClassRegistry::~SystemClassRegistry() {
//////////////////////////////////////////////////////////////////////////
SystemClassRegistry *SystemClassRegistry::getInstance() {
- return g_wintermute->getClassRegistry();
+ return BaseEngine::instance().getClassRegistry();
}
void SystemClassRegistry::unregisterClasses() {
--
cgit v1.2.3
From fed19cb66ae5b56dd7dc81b90edd5a0d15986678 Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Mon, 13 Aug 2012 03:42:30 +0200
Subject: WINTERMUTE: WinterMute -> Wintermute
---
engines/wintermute/system/sys_class_registry.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index b9e9bc8878..d836b32635 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -35,7 +35,7 @@
#include "engines/wintermute/wintermute.h"
#include "common/stream.h"
-namespace WinterMute {
+namespace Wintermute {
//////////////////////////////////////////////////////////////////////////
SystemClassRegistry::SystemClassRegistry() {
@@ -83,7 +83,7 @@ bool SystemClassRegistry::unregisterClass(SystemClass *classObj) {
}
if (classObj->getNumInstances() != 0) {
- debugC(WinterMute::kWinterMuteDebugSaveGame, "Memory leak@class %-20s: %d instance(s) left\n", classObj->getName().c_str(), classObj->getNumInstances());
+ debugC(Wintermute::kWintermuteDebugSaveGame, "Memory leak@class %-20s: %d instance(s) left\n", classObj->getName().c_str(), classObj->getNumInstances());
}
_classes.erase(it);
@@ -332,4 +332,4 @@ void SystemClassRegistry::dumpClasses(Common::WriteStream *stream) {
}
}
-} // end of namespace WinterMute
+} // end of namespace Wintermute
--
cgit v1.2.3
From b4090ead4d4334e08725323ff72fd355c93b63d5 Mon Sep 17 00:00:00 2001
From: Willem Jan Palenstijn
Date: Tue, 4 Sep 2012 22:17:23 +0200
Subject: WINTERMUTE: Convert CRLF to LF
---
engines/wintermute/system/sys_class_registry.cpp | 670 +++++++++++------------
1 file changed, 335 insertions(+), 335 deletions(-)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index d836b32635..5e3b968c5c 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -1,335 +1,335 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-/*
- * This file is based on WME Lite.
- * http://dead-code.org/redir.php?target=wmelite
- * Copyright (c) 2011 Jan Nedoma
- */
-
-#include "engines/wintermute/base/base_game.h"
-#include "engines/wintermute/platform_osystem.h"
-#include "engines/wintermute/base/base_engine.h"
-#include "engines/wintermute/system/sys_instance.h"
-#include "engines/wintermute/system/sys_class_registry.h"
-#include "engines/wintermute/system/sys_class.h"
-#include "engines/wintermute/wintermute.h"
-#include "common/stream.h"
-
-namespace Wintermute {
-
-//////////////////////////////////////////////////////////////////////////
-SystemClassRegistry::SystemClassRegistry() {
- _count = 0;
- _disabled = false;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-SystemClassRegistry::~SystemClassRegistry() {
- unregisterClasses();
-}
-
-//////////////////////////////////////////////////////////////////////////
-SystemClassRegistry *SystemClassRegistry::getInstance() {
- return BaseEngine::instance().getClassRegistry();
-}
-
-void SystemClassRegistry::unregisterClasses() {
- // SystemClass calls UnregisterClass upon destruction.
- while (_classes.size() > 0) {
- delete _classes.begin()->_value;
- }
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::registerClass(SystemClass *classObj) {
- classObj->setID(_count++);
- //_classes.insert(classObj);
- _classes[classObj] = classObj;
-
- _nameMap[classObj->getName()] = classObj;
- _idMap[classObj->getID()] = classObj;
-
- return true;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::unregisterClass(SystemClass *classObj) {
-
- Classes::iterator it = _classes.find(classObj);
- if (it == _classes.end()) {
- return false;
- }
-
- if (classObj->getNumInstances() != 0) {
- debugC(Wintermute::kWintermuteDebugSaveGame, "Memory leak@class %-20s: %d instance(s) left\n", classObj->getName().c_str(), classObj->getNumInstances());
- }
- _classes.erase(it);
-
- NameMap::iterator mapIt = _nameMap.find(classObj->getName());
- if (mapIt != _nameMap.end()) {
- _nameMap.erase(mapIt);
- }
-
- IdMap::iterator idIt = _idMap.find(classObj->getID());
- if (idIt != _idMap.end()) {
- _idMap.erase(idIt);
- }
-
-
- return true;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::registerInstance(const char *className, void *instance) {
- if (_disabled) {
- return true;
- }
-
- NameMap::iterator mapIt = _nameMap.find(className);
- if (mapIt == _nameMap.end()) {
- return false;
- }
-
- SystemInstance *inst = (*mapIt)._value->addInstance(instance, _count++);
- return (inst != NULL);
-}
-
-//////////////////////////////////////////////////////////////////////////
-void SystemClassRegistry::addInstanceToTable(SystemInstance *instance, void *pointer) {
- _instanceMap[pointer] = instance;
-
- if (instance->getSavedID() >= 0) {
- _savedInstanceMap[instance->getSavedID()] = instance;
- }
-}
-
-//////////////////////////////////////////////////////////////////////////
-int SystemClassRegistry::getNextID() {
- return _count++;
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::unregisterInstance(const char *className, void *instance) {
- NameMap::iterator mapIt = _nameMap.find(className);
- if (mapIt == _nameMap.end()) {
- return false;
- }
- (*mapIt)._value->removeInstance(instance);
-
- InstanceMap::iterator instIt = _instanceMap.find(instance);
- if (instIt != _instanceMap.end()) {
- _instanceMap.erase(instIt);
- return true;
- } else {
- return false;
- }
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::getPointerID(void *pointer, int *classID, int *instanceID) {
- if (pointer == NULL) {
- return true;
- }
-
- InstanceMap::iterator it = _instanceMap.find(pointer);
- if (it == _instanceMap.end()) {
- return false;
- }
-
-
- SystemInstance *inst = (*it)._value;
- *instanceID = inst->getID();
- *classID = inst->getClass()->getID();
-
- return true;
-}
-
-//////////////////////////////////////////////////////////////////////////
-void *SystemClassRegistry::idToPointer(int classID, int instanceID) {
- SavedInstanceMap::iterator it = _savedInstanceMap.find(instanceID);
- if (it == _savedInstanceMap.end()) {
- return NULL;
- } else {
- return (*it)._value->getInstance();
- }
-}
-
-bool checkHeader(const char *tag, BasePersistenceManager *pm) {
- char *test = pm->getString();
- Common::String verify = test;
- delete[] test;
- bool retVal = (verify == tag);
- if (!retVal) {
- error("Expected %s in Save-file not found", tag);
- }
- return retVal;
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::saveTable(BaseGame *gameRef, BasePersistenceManager *persistMgr, bool quickSave) {
- persistMgr->putString("");
- persistMgr->putDWORD(_classes.size());
-
- int counter = 0;
-
- Classes::iterator it;
- for (it = _classes.begin(); it != _classes.end(); ++it) {
- counter++;
-
- if (!quickSave) {
- gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)_classes.size() / (float)counter)));
- }
-
- (it->_value)->saveTable(gameRef, persistMgr);
- }
- persistMgr->putString("");
- return STATUS_OK;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *persistMgr) {
- checkHeader("", persistMgr);
-
- // reset SavedID of current instances
- Classes::iterator it;
- for (it = _classes.begin(); it != _classes.end(); ++it) {
- (it->_value)->resetSavedIDs();
- }
-
- for (it = _classes.begin(); it != _classes.end(); ++it) {
- if ((it->_value)->isPersistent()) {
- continue;
- }
- (it->_value)->removeAllInstances();
- }
-
- _instanceMap.clear();
-
- uint32 numClasses = persistMgr->getDWORD();
-
- for (uint32 i = 0; i < numClasses; i++) {
- gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)numClasses / (float)i)));
-
- Common::String className = persistMgr->getStringObj();
- NameMap::iterator mapIt = _nameMap.find(className);
- if (mapIt != _nameMap.end()) {
- (*mapIt)._value->loadTable(gameRef, persistMgr);
- }
- }
-
- checkHeader("", persistMgr);
-
- return STATUS_OK;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::saveInstances(BaseGame *gameRef, BasePersistenceManager *persistMgr, bool quickSave) {
-
- Classes::iterator it;
-
- // count total instances
- int numInstances = 0;
- for (it = _classes.begin(); it != _classes.end(); ++it) {
- numInstances += (it->_value)->getNumInstances();
- }
-
- persistMgr->putDWORD(numInstances);
-
- int counter = 0;
- for (it = _classes.begin(); it != _classes.end(); ++it) {
- counter++;
-
- if (!quickSave) {
- if (counter % 20 == 0) {
- gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)_classes.size() / (float)counter)));
- }
- }
- gameRef->miniUpdate();
-
- (it->_value)->saveInstances(gameRef, persistMgr);
- }
-
- return STATUS_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::loadInstances(BaseGame *gameRef, BasePersistenceManager *persistMgr) {
- // get total instances
- int numInstances = persistMgr->getDWORD();
-
- for (int i = 0; i < numInstances; i++) {
- if (i % 20 == 0) {
- gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)numInstances / (float)i)));
- }
-
- checkHeader("", persistMgr);
-
- int classID = persistMgr->getDWORD();
- int instanceID = persistMgr->getDWORD();
- void *instance = idToPointer(classID, instanceID);
-
- checkHeader("", persistMgr);
-
- Classes::iterator it;
- for (it = _classes.begin(); it != _classes.end(); ++it) {
- if ((it->_value)->getSavedID() == classID) {
- (it->_value)->loadInstance(instance, persistMgr);
- break;
- }
- }
- checkHeader("", persistMgr);
- }
-
- _savedInstanceMap.clear();
-
- return STATUS_OK;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool SystemClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const char *className, void *lpData) {
- NameMap::iterator mapIt = _nameMap.find(className);
- if (mapIt == _nameMap.end()) {
- return STATUS_FAILED;
- }
-
- (*mapIt)._value->instanceCallback(lpCallback, lpData);
- return STATUS_OK;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-void SystemClassRegistry::dumpClasses(Common::WriteStream *stream) {
- Classes::iterator it;
- for (it = _classes.begin(); it != _classes.end(); ++it) {
- (it->_value)->dump(stream);
- }
-}
-
-} // end of namespace Wintermute
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#include "engines/wintermute/base/base_game.h"
+#include "engines/wintermute/platform_osystem.h"
+#include "engines/wintermute/base/base_engine.h"
+#include "engines/wintermute/system/sys_instance.h"
+#include "engines/wintermute/system/sys_class_registry.h"
+#include "engines/wintermute/system/sys_class.h"
+#include "engines/wintermute/wintermute.h"
+#include "common/stream.h"
+
+namespace Wintermute {
+
+//////////////////////////////////////////////////////////////////////////
+SystemClassRegistry::SystemClassRegistry() {
+ _count = 0;
+ _disabled = false;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+SystemClassRegistry::~SystemClassRegistry() {
+ unregisterClasses();
+}
+
+//////////////////////////////////////////////////////////////////////////
+SystemClassRegistry *SystemClassRegistry::getInstance() {
+ return BaseEngine::instance().getClassRegistry();
+}
+
+void SystemClassRegistry::unregisterClasses() {
+ // SystemClass calls UnregisterClass upon destruction.
+ while (_classes.size() > 0) {
+ delete _classes.begin()->_value;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::registerClass(SystemClass *classObj) {
+ classObj->setID(_count++);
+ //_classes.insert(classObj);
+ _classes[classObj] = classObj;
+
+ _nameMap[classObj->getName()] = classObj;
+ _idMap[classObj->getID()] = classObj;
+
+ return true;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::unregisterClass(SystemClass *classObj) {
+
+ Classes::iterator it = _classes.find(classObj);
+ if (it == _classes.end()) {
+ return false;
+ }
+
+ if (classObj->getNumInstances() != 0) {
+ debugC(Wintermute::kWintermuteDebugSaveGame, "Memory leak@class %-20s: %d instance(s) left\n", classObj->getName().c_str(), classObj->getNumInstances());
+ }
+ _classes.erase(it);
+
+ NameMap::iterator mapIt = _nameMap.find(classObj->getName());
+ if (mapIt != _nameMap.end()) {
+ _nameMap.erase(mapIt);
+ }
+
+ IdMap::iterator idIt = _idMap.find(classObj->getID());
+ if (idIt != _idMap.end()) {
+ _idMap.erase(idIt);
+ }
+
+
+ return true;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::registerInstance(const char *className, void *instance) {
+ if (_disabled) {
+ return true;
+ }
+
+ NameMap::iterator mapIt = _nameMap.find(className);
+ if (mapIt == _nameMap.end()) {
+ return false;
+ }
+
+ SystemInstance *inst = (*mapIt)._value->addInstance(instance, _count++);
+ return (inst != NULL);
+}
+
+//////////////////////////////////////////////////////////////////////////
+void SystemClassRegistry::addInstanceToTable(SystemInstance *instance, void *pointer) {
+ _instanceMap[pointer] = instance;
+
+ if (instance->getSavedID() >= 0) {
+ _savedInstanceMap[instance->getSavedID()] = instance;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+int SystemClassRegistry::getNextID() {
+ return _count++;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::unregisterInstance(const char *className, void *instance) {
+ NameMap::iterator mapIt = _nameMap.find(className);
+ if (mapIt == _nameMap.end()) {
+ return false;
+ }
+ (*mapIt)._value->removeInstance(instance);
+
+ InstanceMap::iterator instIt = _instanceMap.find(instance);
+ if (instIt != _instanceMap.end()) {
+ _instanceMap.erase(instIt);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::getPointerID(void *pointer, int *classID, int *instanceID) {
+ if (pointer == NULL) {
+ return true;
+ }
+
+ InstanceMap::iterator it = _instanceMap.find(pointer);
+ if (it == _instanceMap.end()) {
+ return false;
+ }
+
+
+ SystemInstance *inst = (*it)._value;
+ *instanceID = inst->getID();
+ *classID = inst->getClass()->getID();
+
+ return true;
+}
+
+//////////////////////////////////////////////////////////////////////////
+void *SystemClassRegistry::idToPointer(int classID, int instanceID) {
+ SavedInstanceMap::iterator it = _savedInstanceMap.find(instanceID);
+ if (it == _savedInstanceMap.end()) {
+ return NULL;
+ } else {
+ return (*it)._value->getInstance();
+ }
+}
+
+bool checkHeader(const char *tag, BasePersistenceManager *pm) {
+ char *test = pm->getString();
+ Common::String verify = test;
+ delete[] test;
+ bool retVal = (verify == tag);
+ if (!retVal) {
+ error("Expected %s in Save-file not found", tag);
+ }
+ return retVal;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::saveTable(BaseGame *gameRef, BasePersistenceManager *persistMgr, bool quickSave) {
+ persistMgr->putString("");
+ persistMgr->putDWORD(_classes.size());
+
+ int counter = 0;
+
+ Classes::iterator it;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ counter++;
+
+ if (!quickSave) {
+ gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)_classes.size() / (float)counter)));
+ }
+
+ (it->_value)->saveTable(gameRef, persistMgr);
+ }
+ persistMgr->putString("");
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *persistMgr) {
+ checkHeader("", persistMgr);
+
+ // reset SavedID of current instances
+ Classes::iterator it;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ (it->_value)->resetSavedIDs();
+ }
+
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ if ((it->_value)->isPersistent()) {
+ continue;
+ }
+ (it->_value)->removeAllInstances();
+ }
+
+ _instanceMap.clear();
+
+ uint32 numClasses = persistMgr->getDWORD();
+
+ for (uint32 i = 0; i < numClasses; i++) {
+ gameRef->_renderer->setIndicatorVal((int)(50.0f / (float)((float)numClasses / (float)i)));
+
+ Common::String className = persistMgr->getStringObj();
+ NameMap::iterator mapIt = _nameMap.find(className);
+ if (mapIt != _nameMap.end()) {
+ (*mapIt)._value->loadTable(gameRef, persistMgr);
+ }
+ }
+
+ checkHeader("", persistMgr);
+
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::saveInstances(BaseGame *gameRef, BasePersistenceManager *persistMgr, bool quickSave) {
+
+ Classes::iterator it;
+
+ // count total instances
+ int numInstances = 0;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ numInstances += (it->_value)->getNumInstances();
+ }
+
+ persistMgr->putDWORD(numInstances);
+
+ int counter = 0;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ counter++;
+
+ if (!quickSave) {
+ if (counter % 20 == 0) {
+ gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)_classes.size() / (float)counter)));
+ }
+ }
+ gameRef->miniUpdate();
+
+ (it->_value)->saveInstances(gameRef, persistMgr);
+ }
+
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::loadInstances(BaseGame *gameRef, BasePersistenceManager *persistMgr) {
+ // get total instances
+ int numInstances = persistMgr->getDWORD();
+
+ for (int i = 0; i < numInstances; i++) {
+ if (i % 20 == 0) {
+ gameRef->_renderer->setIndicatorVal((int)(50.0f + 50.0f / (float)((float)numInstances / (float)i)));
+ }
+
+ checkHeader("", persistMgr);
+
+ int classID = persistMgr->getDWORD();
+ int instanceID = persistMgr->getDWORD();
+ void *instance = idToPointer(classID, instanceID);
+
+ checkHeader("", persistMgr);
+
+ Classes::iterator it;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ if ((it->_value)->getSavedID() == classID) {
+ (it->_value)->loadInstance(instance, persistMgr);
+ break;
+ }
+ }
+ checkHeader("", persistMgr);
+ }
+
+ _savedInstanceMap.clear();
+
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+bool SystemClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const char *className, void *lpData) {
+ NameMap::iterator mapIt = _nameMap.find(className);
+ if (mapIt == _nameMap.end()) {
+ return STATUS_FAILED;
+ }
+
+ (*mapIt)._value->instanceCallback(lpCallback, lpData);
+ return STATUS_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+void SystemClassRegistry::dumpClasses(Common::WriteStream *stream) {
+ Classes::iterator it;
+ for (it = _classes.begin(); it != _classes.end(); ++it) {
+ (it->_value)->dump(stream);
+ }
+}
+
+} // end of namespace Wintermute
--
cgit v1.2.3
From 2a6e55169530b46985d6d6af6ebcbb12e7c5a603 Mon Sep 17 00:00:00 2001
From: Einar Johan Trøan Sømåen
Date: Tue, 11 Sep 2012 02:51:33 +0200
Subject: WINTERMUTE: Only include base_renderer.h where needed
---
engines/wintermute/system/sys_class_registry.cpp | 1 +
1 file changed, 1 insertion(+)
(limited to 'engines/wintermute/system/sys_class_registry.cpp')
diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp
index 5e3b968c5c..7c1911c2bf 100644
--- a/engines/wintermute/system/sys_class_registry.cpp
+++ b/engines/wintermute/system/sys_class_registry.cpp
@@ -29,6 +29,7 @@
#include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/platform_osystem.h"
#include "engines/wintermute/base/base_engine.h"
+#include "engines/wintermute/base/gfx/base_renderer.h"
#include "engines/wintermute/system/sys_instance.h"
#include "engines/wintermute/system/sys_class_registry.h"
#include "engines/wintermute/system/sys_class.h"
--
cgit v1.2.3