TITANIC: Simplify freeing class list on exit

This commit is contained in:
Paul Gilbert 2016-11-07 07:36:52 -05:00
parent 57cd02b048
commit f6593ce9c0
3 changed files with 3 additions and 11 deletions

View File

@ -421,15 +421,14 @@ CSaveableObject *ClassDef::create() {
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
CSaveableObject::ClassListMap *CSaveableObject::_classList = nullptr; CSaveableObject::ClassListMap *CSaveableObject::_classList;
CSaveableObject::ClassDefList *CSaveableObject::_classDefs; CSaveableObject::ClassDefList *CSaveableObject::_classDefs;
CSaveableObject::VoidArray *CSaveableObject::_typesToFree;
#define DEFFN(T) CSaveableObject *Function##T() { return new T(); } \ #define DEFFN(T) CSaveableObject *Function##T() { return new T(); } \
ClassDef *T::_type ClassDef *T::_type
#define ADDFN(CHILD, PARENT) \ #define ADDFN(CHILD, PARENT) \
CHILD::_type = new TypeTemplate<CHILD>(#CHILD, PARENT::_type); \ CHILD::_type = new TypeTemplate<CHILD>(#CHILD, PARENT::_type); \
_typesToFree->push_back(CHILD::_type); \ _classDefs->push_back(CHILD::_type); \
(*_classList)[#CHILD] = Function##CHILD (*_classList)[#CHILD] = Function##CHILD
DEFFN(CArm); DEFFN(CArm);
@ -1023,7 +1022,6 @@ DEFFN(CTimeEventInfo);
void CSaveableObject::initClassList() { void CSaveableObject::initClassList() {
_classDefs = new ClassDefList(); _classDefs = new ClassDefList();
_classList = new ClassListMap(); _classList = new ClassListMap();
_typesToFree = new VoidArray();
ADDFN(CArm, CCarry); ADDFN(CArm, CCarry);
ADDFN(CAuditoryCentre, CBrain); ADDFN(CAuditoryCentre, CBrain);
ADDFN(CBowlEar, CEar); ADDFN(CBowlEar, CEar);
@ -1623,12 +1621,8 @@ void CSaveableObject::freeClassList() {
for (i = _classDefs->begin(); i != _classDefs->end(); ++i) for (i = _classDefs->begin(); i != _classDefs->end(); ++i)
delete *i; delete *i;
for (uint idx = 0; idx < _typesToFree->size(); ++idx)
delete (*_typesToFree)[idx];
delete _classDefs; delete _classDefs;
delete _classList; delete _classList;
delete _typesToFree;
} }
CSaveableObject *CSaveableObject::createInstance(const Common::String &name) { CSaveableObject *CSaveableObject::createInstance(const Common::String &name) {

View File

@ -61,10 +61,8 @@ class CSaveableObject {
private: private:
typedef Common::List<ClassDef *> ClassDefList; typedef Common::List<ClassDef *> ClassDefList;
typedef Common::HashMap<Common::String, CreateFunction> ClassListMap; typedef Common::HashMap<Common::String, CreateFunction> ClassListMap;
typedef Common::Array<void *> VoidArray;
static ClassDefList *_classDefs; static ClassDefList *_classDefs;
static ClassListMap *_classList; static ClassListMap *_classList;
static VoidArray *_typesToFree;
public: public:
/** /**
* Sets up the list of saveable object classes * Sets up the list of saveable object classes

View File

@ -340,7 +340,7 @@ uint TTnpcScript::getRangeValue(uint id) {
int index = (int)getRandomNumber(count) - 1; int index = (int)getRandomNumber(count) - 1;
if (count > 1 && range->_values[index] == range->_priorIndex) { if (count > 1 && range->_values[index] == range->_priorIndex) {
for (int retry = 0; retry < 8 && index != range->_priorIndex; ++retry) for (int retry = 0; retry < 8 && index != (int)range->_priorIndex; ++retry)
index = (int)getRandomNumber(count) - 1; index = (int)getRandomNumber(count) - 1;
} }