Permalink
Browse files

SLUDGE: Objectify object manager

  • Loading branch information...
yinsimei committed Jul 18, 2017
1 parent 1036022 commit 53542073b9d9516396b1de1d883dc0192a66043b
@@ -992,7 +992,7 @@ builtIn(callEvent) {
return BR_ERROR;
trimStack(fun->stack);
int fNum = getCombinationFunction(obj1, obj2);
int fNum = g_sludge->_objMan->getCombinationFunction(obj1, obj2);
// Return value
if (fNum) {
@@ -1366,7 +1366,7 @@ builtIn(rename) {
if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar))
return BR_ERROR;
trimStack(fun->stack);
objectType *o = findObjectType(objT);
ObjectType *o = g_sludge->_objMan->findObjectType(objT);
o->screenName.clear();
o->screenName = newText;
return BR_CONTINUE;
@@ -2124,7 +2124,7 @@ builtIn(fetchEvent) {
return BR_ERROR;
trimStack(fun->stack);
int fNum = getCombinationFunction(obj1, obj2);
int fNum = g_sludge->_objMan->getCombinationFunction(obj1, obj2);
// Return value
if (fNum) {
@@ -2503,7 +2503,7 @@ builtIn(hasFlag) {
if (!getValueType(objNum, SVT_OBJTYPE, fun->stack->thisVar))
return BR_ERROR;
trimStack(fun->stack);
objectType *objT = findObjectType(objNum);
ObjectType *objT = g_sludge->_objMan->findObjectType(objNum);
if (!objT)
return BR_ERROR;
setVariable(fun->reg, SVT_INT, objT->flags & (1 << flagIndex));
@@ -173,7 +173,7 @@ int main_loop(const char *filename)
return fatal("Couldn't initialise people stuff");
if (!initFloor())
return fatal("Couldn't initialise floor stuff");
if (!initObjectTypes())
if (!g_sludge->_objMan->initObjectTypes())
return fatal("Couldn't initialise object type stuff");
initSpeech();
initStatusBar();
@@ -31,31 +31,37 @@
namespace Sludge {
objectType *allObjectTypes = NULL;
ObjectManager::~ObjectManager() {
ObjectTypeList::iterator it;
for (it = _allObjectTypes.begin(); it != _allObjectTypes.end(); ++it) {
delete [](*it)->allCombis;
delete (*it);
(*it) = nullptr;
}
}
bool initObjectTypes() {
bool ObjectManager::initObjectTypes() {
return true;
}
objectType *findObjectType(int i) {
objectType *huntType = allObjectTypes;
while (huntType) {
if (huntType->objectNum == i)
return huntType;
huntType = huntType->next;
ObjectType *ObjectManager::findObjectType(int i) {
ObjectTypeList::iterator it;
for (it = _allObjectTypes.begin(); it != _allObjectTypes.end(); ++it) {
if ((*it)->objectNum == i) {
return (*it);
}
}
return loadObjectType(i);
}
objectType *loadObjectType(int i) {
ObjectType *ObjectManager::loadObjectType(int i) {
int a, nameNum;
objectType *newType = new objectType;
ObjectType *newType = new ObjectType;
ResourceManager *rm = _vm->_resMan;
if (checkNew(newType)) {
if (g_sludge->_resMan->openObjectSlice(i)) {
Common::SeekableReadStream *readStream = g_sludge->_resMan->getData();
if (rm->openObjectSlice(i)) {
Common::SeekableReadStream *readStream = rm->getData();
nameNum = readStream->readUint16BE();
newType->r = (byte)readStream->readByte();
newType->g = (byte)readStream->readByte();
@@ -79,41 +85,40 @@ objectType *loadObjectType(int i) {
}
newType->numCom = readStream->readUint16BE();
newType->allCombis = (newType->numCom) ? new combination[newType->numCom] : NULL;
newType->allCombis = (newType->numCom) ? new Combination[newType->numCom] : nullptr;
for (a = 0; a < newType->numCom; a++) {
newType->allCombis[a].withObj = readStream->readUint16BE();
newType->allCombis[a].funcNum = readStream->readUint16BE();
}
g_sludge->_resMan->finishAccess();
newType->screenName = g_sludge->_resMan->getNumberedString(nameNum);
rm->finishAccess();
newType->screenName = rm->getNumberedString(nameNum);
newType->objectNum = i;
newType->next = allObjectTypes;
allObjectTypes = newType;
_allObjectTypes.push_back(newType);
return newType;
}
}
return NULL;
return nullptr;
}
objectType *loadObjectRef(Common::SeekableReadStream *stream) {
objectType *r = loadObjectType(stream->readUint16BE());
ObjectType *ObjectManager::loadObjectRef(Common::SeekableReadStream *stream) {
ObjectType *r = loadObjectType(stream->readUint16BE());
r->screenName.clear();
r->screenName = readString(stream);
return r;
}
void saveObjectRef(objectType *r, Common::WriteStream *stream) {
void ObjectManager::saveObjectRef(ObjectType *r, Common::WriteStream *stream) {
stream->writeUint16BE(r->objectNum);
writeString(r->screenName, stream);
}
int getCombinationFunction(int withThis, int thisObject) {
int ObjectManager::getCombinationFunction(int withThis, int thisObject) {
int i, num = 0;
objectType *obj = findObjectType(thisObject);
ObjectType *obj = findObjectType(thisObject);
for (i = 0; i < obj->numCom; i++) {
if (obj->allCombis[i].withObj == withThis) {
@@ -125,20 +130,11 @@ int getCombinationFunction(int withThis, int thisObject) {
return num;
}
void removeObjectType(objectType *oT) {
objectType **huntRegion = &allObjectTypes;
while (*huntRegion) {
if ((*huntRegion) == oT) {
*huntRegion = oT->next;
delete []oT->allCombis;
delete oT;
return;
} else {
huntRegion = &((*huntRegion)->next);
}
}
fatal("Can't delete object type: bad pointer");
void ObjectManager::removeObjectType(ObjectType *oT) {
_allObjectTypes.remove(oT);
delete []oT->allCombis;
delete oT;
oT = nullptr;
}
} // End of namespace Sludge
View
@@ -24,28 +24,41 @@
namespace Sludge {
struct combination {
class SludgeEngine;
struct Combination {
int withObj, funcNum;
};
struct objectType {
struct ObjectType {
Common::String screenName;
int objectNum;
objectType *next;
byte r, g, b;
int numCom;
int speechGap, walkSpeed, wrapSpeech, spinSpeed;
uint16 flags;
combination *allCombis;
Combination *allCombis;
};
bool initObjectTypes();
objectType *findObjectType(int i);
objectType *loadObjectType(int i);
int getCombinationFunction(int a, int b);
void removeObjectType(objectType *oT);
void saveObjectRef(objectType *r, Common::WriteStream *stream);
objectType *loadObjectRef(Common::SeekableReadStream *stream);
typedef Common::List<ObjectType *> ObjectTypeList;
class ObjectManager {
public:
ObjectManager(SludgeEngine *vm) : _vm(vm) {}
~ObjectManager();
bool initObjectTypes();
ObjectType *findObjectType(int i);
ObjectType *loadObjectType(int i);
int getCombinationFunction(int a, int b);
void removeObjectType(ObjectType *oT);
void saveObjectRef(ObjectType *r, Common::WriteStream *stream);
ObjectType *loadObjectRef(Common::SeekableReadStream *stream);
private:
ObjectTypeList _allObjectTypes;
SludgeEngine *_vm;
};
} // End of namespace Sludge
View
@@ -34,6 +34,7 @@
#include "sludge/loadsave.h"
#include "sludge/floor.h"
#include "sludge/zbuffer.h"
#include "sludge/sludge.h"
#include "sludge/sound.h"
#include "sludge/version.h"
@@ -811,7 +812,7 @@ bool addPerson(int x, int y, int objNum, persona *p) {
return false;
// EASY STUFF
newPerson->thisType = loadObjectType(objNum);
newPerson->thisType = g_sludge->_objMan->loadObjectType(objNum);
newPerson->scale = 1;
newPerson->extra = 0;
newPerson->continueAfterWalking = NULL;
@@ -909,7 +910,7 @@ void killAllPeople() {
allPeople->continueAfterWalking = NULL;
killPeople = allPeople;
allPeople = allPeople->next;
removeObjectType(killPeople->thisType);
g_sludge->_objMan->removeObjectType(killPeople->thisType);
delete killPeople;
}
}
@@ -931,7 +932,7 @@ void killMostPeople() {
if (killPeople->continueAfterWalking)
abortFunction(killPeople->continueAfterWalking);
killPeople->continueAfterWalking = NULL;
removeObjectType(killPeople->thisType);
g_sludge->_objMan->removeObjectType(killPeople->thisType);
delete killPeople;
}
}
@@ -955,7 +956,7 @@ void removeOneCharacter(int i) {
}
*killPeople = p->next;
removeObjectType(p->thisType);
g_sludge->_objMan->removeObjectType(p->thisType);
delete p;
}
}
@@ -1089,7 +1090,7 @@ bool savePeople(Common::WriteStream *stream) {
stream->writeByte(me->colourmix);
stream->writeByte(me->transparency);
saveObjectRef(me->thisType, stream);
g_sludge->_objMan->saveObjectRef(me->thisType, stream);
me = me->next;
}
@@ -1171,7 +1172,7 @@ bool loadPeople(Common::SeekableReadStream *stream) {
} else {
setMyDrawMode(me, stream->readUint16BE());
}
me->thisType = loadObjectRef(stream);
me->thisType = g_sludge->_objMan->loadObjectRef(stream);
// Anti-aliasing settings
if (ssgVersion >= VERSION(1, 6)) {
View
@@ -65,7 +65,7 @@ struct onScreenPerson {
int frameNum, frameTick, angle, wantAngle, angleOffset;
bool show;
int direction, directionWhenDoneWalking;
struct objectType *thisType;
struct ObjectType *thisType;
int extra, spinSpeed;
byte r, g, b, colourmix, transparency;
};
View
@@ -26,6 +26,7 @@
#include "sludge/newfatal.h"
#include "sludge/objtypes.h"
#include "sludge/region.h"
#include "sludge/sludge.h"
#include "sludge/sludger.h"
namespace Sludge {
@@ -55,7 +56,7 @@ void removeScreenRegion(int objectNum) {
if ((*huntRegion)->thisType->objectNum == objectNum) {
killMe = *huntRegion;
*huntRegion = killMe->next;
removeObjectType(killMe->thisType);
g_sludge->_objMan->removeObjectType(killMe->thisType);
if (killMe == overRegion)
overRegion = NULL;
delete killMe;
@@ -83,7 +84,7 @@ void saveRegions(Common::WriteStream *stream) {
stream->writeUint16BE(thisRegion->sX);
stream->writeUint16BE(thisRegion->sY);
stream->writeUint16BE(thisRegion->di);
saveObjectRef(thisRegion->thisType, stream);
g_sludge->_objMan->saveObjectRef(thisRegion->thisType, stream);
thisRegion = thisRegion->next;
}
@@ -107,7 +108,7 @@ void loadRegions(Common::SeekableReadStream *stream) {
newRegion->sX = stream->readUint16BE();
newRegion->sY = stream->readUint16BE();
newRegion->di = stream->readUint16BE();
newRegion->thisType = loadObjectRef(stream);
newRegion->thisType = g_sludge->_objMan->loadObjectRef(stream);
}
*pointy = NULL;
}
@@ -117,7 +118,7 @@ void killAllRegions() {
while (allScreenRegions) {
killRegion = allScreenRegions;
allScreenRegions = allScreenRegions->next;
removeObjectType(killRegion->thisType);
g_sludge->_objMan->removeObjectType(killRegion->thisType);
delete killRegion;
}
overRegion = NULL;
@@ -135,7 +136,7 @@ bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di,
newRegion->y2 = y2;
newRegion->sX = sX;
newRegion->sY = sY;
newRegion->thisType = loadObjectType(objectNum);
newRegion->thisType = g_sludge->_objMan->loadObjectType(objectNum);
newRegion->next = allScreenRegions;
allScreenRegions = newRegion;
return (bool) (newRegion->thisType != NULL);
View
@@ -26,7 +26,7 @@ namespace Sludge {
struct screenRegion {
int x1, y1, x2, y2, sX, sY, di;
objectType *thisType;
ObjectType *thisType;
screenRegion *next;
};
@@ -64,6 +64,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
// Init managers
_resMan = new ResourceManager();
_languageMan = new LanguageManager();
_objMan = new ObjectManager(this);
}
SludgeEngine::~SludgeEngine() {
@@ -86,6 +87,8 @@ SludgeEngine::~SludgeEngine() {
_pixelFormat = nullptr;
// Dispose managers
delete _objMan;
_objMan = nullptr;
delete _languageMan;
_languageMan = nullptr;
delete _resMan;
View
@@ -31,6 +31,7 @@
#include "sludge/console.h"
#include "sludge/fileset.h"
#include "sludge/language.h"
#include "sludge/objtypes.h"
#include "sludge/timing.h"
namespace Sludge {
@@ -70,6 +71,7 @@ class SludgeEngine: public Engine {
// managers
ResourceManager *_resMan;
LanguageManager *_languageMan;
ObjectManager *_objMan;
SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
virtual ~SludgeEngine();
Oops, something went wrong.

0 comments on commit 5354207

Please sign in to comment.