aboutsummaryrefslogtreecommitdiff
path: root/engines/fullpipe/utils.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2013-06-11 01:17:11 +0300
committerEugene Sandulenko2013-09-06 14:48:11 +0300
commita116677e6e26ed9d0e8fcc40eaf88c0c40b25391 (patch)
treec8d1459b797109cc3da2b235a07d88c8deca2a2c /engines/fullpipe/utils.cpp
parentf106d791983223906847343c4b1f1ec7ffcc05d5 (diff)
downloadscummvm-rg350-a116677e6e26ed9d0e8fcc40eaf88c0c40b25391.tar.gz
scummvm-rg350-a116677e6e26ed9d0e8fcc40eaf88c0c40b25391.tar.bz2
scummvm-rg350-a116677e6e26ed9d0e8fcc40eaf88c0c40b25391.zip
FULLPIPE: Finish loading fullpipe.gam
Diffstat (limited to 'engines/fullpipe/utils.cpp')
-rw-r--r--engines/fullpipe/utils.cpp92
1 files changed, 55 insertions, 37 deletions
diff --git a/engines/fullpipe/utils.cpp b/engines/fullpipe/utils.cpp
index a81665b48b..5df9a28500 100644
--- a/engines/fullpipe/utils.cpp
+++ b/engines/fullpipe/utils.cpp
@@ -41,7 +41,7 @@ char *MfcArchive::readPascalString(bool twoByte) {
tmp = (char *)calloc(len + 1, 1);
read(tmp, len);
- debug(0, "readPascalString: %d <%s>", len, tmp);
+ debug(9, "readPascalString: %d <%s>", len, tmp);
return tmp;
}
@@ -85,6 +85,26 @@ static const char *lookupObjectId(int id) {
return "";
}
+static CObject *createObject(int objectId) {
+ switch (objectId) {
+ case kNullObject:
+ return 0;
+ case kCInteraction:
+ return new CInteraction();
+ case kMessageQueue:
+ return new MessageQueue();
+ case kExCommand:
+ return new ExCommand();
+ case kCObjstateCommand:
+ return new CObjstateCommand();
+ case kCGameVar:
+ return new CGameVar();
+ default:
+ error("Unknown objectId: %d", objectId);
+ }
+
+ return 0;
+}
MfcArchive::MfcArchive() {
for (int i = 0; classMap[i].name; i++) {
@@ -93,45 +113,60 @@ MfcArchive::MfcArchive() {
_lastIndex = 1;
- _objectMap.push_back(kNullObject);
+ _objectMap.push_back(0);
+ _objectIdMap.push_back(kNullObject);
}
CObject *MfcArchive::readClass() {
- CObject *res = parseClass();
+ bool isCopyReturned;
+ CObject *res = parseClass(&isCopyReturned);
- if (res)
+ if (res && !isCopyReturned)
res->load(*this);
return res;
}
-CObject *MfcArchive::parseClass() {
+CObject *MfcArchive::parseClass(bool *isCopyReturned) {
char *name;
- int objectId;
+ int objectId = 0;
+ CObject *res = 0;
uint obTag = readUint16LE();
- debug(0, "parseClass::obTag = %d (%04x) at 0x%08x", obTag, obTag, pos() - 2);
+ debug(7, "parseClass::obTag = %d (%04x) at 0x%08x", obTag, obTag, pos() - 2);
if (obTag == 0xffff) {
int schema = readUint16LE();
- debug(0, "parseClass::schema = %d", schema);
+ debug(7, "parseClass::schema = %d", schema);
name = readPascalString(true);
- debug(0, "parseClass::class <%s>", name);
+ debug(7, "parseClass::class <%s>", name);
if (!_classMap.contains(name)) {
error("Unknown class in MfcArchive: <%s>", name);
}
objectId = _classMap[name];
- _objectMap.push_back(objectId);
- debug(0, "tag: %d 0x%x (%x)", _objectMap.size() - 1, _objectMap.size() - 1, objectId);
- objectId = _classMap[name];
+ debug(7, "tag: %d 0x%x (%x)", _objectMap.size() - 1, _objectMap.size() - 1, objectId);
+
+ res = createObject(objectId);
+ _objectMap.push_back(res);
+ _objectIdMap.push_back(objectId);
+
+ _objectMap.push_back(res); // Basically a hack, but behavior is all correct
+ _objectIdMap.push_back(objectId);
+
+ *isCopyReturned = false;
} else if ((obTag & 0x8000) == 0) {
- objectId = _objectMap[obTag];
+ if (_objectMap.size() < obTag) {
+ error("Object index too big: %d at 0x%08x", obTag, pos() - 2);
+ }
+ res = _objectMap[obTag];
+
+ *isCopyReturned = true;
} else {
obTag &= ~0x8000;
@@ -140,35 +175,18 @@ CObject *MfcArchive::parseClass() {
error("Object index too big: %d at 0x%08x", obTag, pos() - 2);
}
- debug(0, "parseClass::obTag <%s>", lookupObjectId(_objectMap[obTag]));
+ debug(7, "parseClass::obTag <%s>", lookupObjectId(_objectIdMap[obTag]));
- objectId = _objectMap[obTag];
- }
-
- if (objectId)
- _objectMap.push_back(objectId);
+ objectId = _objectIdMap[obTag];
- debug(0, "objectId: %d", objectId);
+ res = createObject(objectId);
+ _objectMap.push_back(res);
+ _objectIdMap.push_back(objectId);
- switch (objectId) {
- case kNullObject:
- warning("parseClass: NULL object at 0x%08x", pos() - 2);
- return 0;
- case kCInteraction:
- return new CInteraction();
- case kMessageQueue:
- return new MessageQueue();
- case kExCommand:
- return new ExCommand();
- case kCObjstateCommand:
- return new CObjstateCommand();
- case kCGameVar:
- return new CGameVar();
- default:
- error("Unknown objectId: %d", objectId);
+ *isCopyReturned = false;
}
- return 0;
+ return res;
}
} // End of namespace Fullpipe