FULLPIPE: Properly save object backreferences

This commit is contained in:
Eugene Sandulenko 2016-09-18 00:59:17 +02:00
parent d9457c2f07
commit f0d786184b
2 changed files with 33 additions and 2 deletions

View File

@ -460,10 +460,23 @@ CObject *MfcArchive::parseClass(bool *isCopyReturned) {
}
void MfcArchive::writeObject(CObject *obj) {
if (obj == NULL)
if (obj == NULL) {
writeUint16LE(0);
else
} else if (_objectHash.contains(obj)) {
int32 idx = _objectHash[obj];
if (idx < 0x7fff) {
writeUint16LE(idx);
} else {
writeUint16LE(0x7fff);
writeUint32LE(idx);
}
} else {
writeUint16LE(0xffff); // New class
_objectHash[obj] = _lastIndex++;
obj->save(*this);
}
}
char *genFileName(int superId, int sceneId, const char *ext) {

View File

@ -32,12 +32,30 @@ namespace Fullpipe {
class CObject;
class NGIArchive;
struct Pointer_EqualTo {
bool operator()(const void *x, const void *y) const { return x == y; }
};
struct Pointer_Hash {
uint operator()(const void *x) const {
#ifdef SCUMM_64BITS
uint64 v = (uint64)x;
return (v >> 32) ^ (v & 0xffffffff);
#else
return (uint)x;
#endif
}
};
typedef Common::HashMap<void *, int, Pointer_Hash, Pointer_EqualTo> ObjHash;
typedef Common::HashMap<Common::String, int, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ClassMap;
class MfcArchive : public Common::SeekableReadStream, public Common::WriteStream {
ClassMap _classMap;
Common::Array<CObject *> _objectMap;
Common::Array<int> _objectIdMap;
ObjHash _objectHash;
int _lastIndex;
int _level;