diff options
-rw-r--r-- | engines/fullpipe/utils.cpp | 17 | ||||
-rw-r--r-- | engines/fullpipe/utils.h | 18 |
2 files changed, 33 insertions, 2 deletions
diff --git a/engines/fullpipe/utils.cpp b/engines/fullpipe/utils.cpp index fff2dad15b..5403adec68 100644 --- a/engines/fullpipe/utils.cpp +++ b/engines/fullpipe/utils.cpp @@ -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) { diff --git a/engines/fullpipe/utils.h b/engines/fullpipe/utils.h index 5de919d383..44bda68cac 100644 --- a/engines/fullpipe/utils.h +++ b/engines/fullpipe/utils.h @@ -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; |