diff options
author | Max Horn | 2003-03-07 21:38:46 +0000 |
---|---|---|
committer | Max Horn | 2003-03-07 21:38:46 +0000 |
commit | 7ec34ab1a971a183ab68ff175d2b848a840b5266 (patch) | |
tree | 430f669754106e15b960ee000a9b67c6f5c9c4d8 /scumm | |
parent | bdd2c50af9fb208dcb40692f8d2d5bf67ee0ab53 (diff) | |
download | scummvm-rg350-7ec34ab1a971a183ab68ff175d2b848a840b5266.tar.gz scummvm-rg350-7ec34ab1a971a183ab68ff175d2b848a840b5266.tar.bz2 scummvm-rg350-7ec34ab1a971a183ab68ff175d2b848a840b5266.zip |
refactored some stuff (and made readMAXS virtual, with V2/V3 code having own implementations); cleaned up V6 array shuffle code; made more Scumm member vars/methods protected
svn-id: r6751
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/intern.h | 11 | ||||
-rw-r--r-- | scumm/resource_v2.cpp | 40 | ||||
-rw-r--r-- | scumm/resource_v3.cpp | 40 | ||||
-rw-r--r-- | scumm/script_v6.cpp | 55 | ||||
-rw-r--r-- | scumm/scumm.h | 21 | ||||
-rw-r--r-- | scumm/sound.cpp | 2 |
6 files changed, 95 insertions, 74 deletions
diff --git a/scumm/intern.h b/scumm/intern.h index e729293a71..8af677560c 100644 --- a/scumm/intern.h +++ b/scumm/intern.h @@ -162,7 +162,9 @@ class Scumm_v2 : public Scumm_v5 { public: Scumm_v2(GameDetector *detector, OSystem *syst) : Scumm_v5(detector, syst) {} - virtual void readIndexFile(); +protected: + void readIndexFile(); + void readMAXS(); }; // FIXME - maybe we should move the opcodes from v5 to v3, and change the inheritance @@ -172,14 +174,17 @@ class Scumm_v3 : public Scumm_v5 { public: Scumm_v3(GameDetector *detector, OSystem *syst) : Scumm_v5(detector, syst) {} +protected: void readIndexFile(); - virtual void loadCharset(int no); + void loadCharset(int no); + void readMAXS(); }; class Scumm_v4 : public Scumm_v3 { public: Scumm_v4(GameDetector *detector, OSystem *syst) : Scumm_v3(detector, syst) {} +protected: void loadCharset(int no); }; @@ -205,6 +210,8 @@ protected: virtual void setupScummVars(); int popRoomAndObj(int *room); + + void shuffleArray(int num, int minIdx, int maxIdx); virtual void decodeParseString(int a, int b); int getStackList(int *args, uint maxnum); diff --git a/scumm/resource_v2.cpp b/scumm/resource_v2.cpp index 313b88bfcb..de7cc6462d 100644 --- a/scumm/resource_v2.cpp +++ b/scumm/resource_v2.cpp @@ -49,30 +49,13 @@ void Scumm_v2::readIndexFile() { _fileHandle.clearIOFailed(); _fileHandle.seek(0, SEEK_SET); - // FIXME - I'm not sure for those values yet, they will have to be rechecked - - _numVariables = 800; /* 800 */ - _numBitVariables = 4096; /* 2048 */ - _numLocalObjects = 200; /* 200 */ - _numArray = 50; - _numVerbs = 100; - _numNewNames = 0; - _objectRoomTable = NULL; - _numCharsets = 9; /* 9 */ - _numInventory = 80; /* 80 */ - _numGlobalScripts = 200; - - _shadowPaletteSize = 256; - _shadowPalette = (byte *) calloc(_shadowPaletteSize, 1); // FIXME - needs to be removed later + readMAXS(); // Jamieson630: palManipulate variable initialization _palManipCounter = 0; _palManipPalette = 0; // Will allocate when needed _palManipIntermediatePal = 0; // Will allocate when needed - _numFlObject = 50; - allocateArrays(); - _fileHandle.readUint16LE(); /* version magic number */ _fileHandle.readUint16LE(); /* nb global objects */ _fileHandle.seek(_numGlobalObjects, SEEK_CUR); // Skip object flags @@ -83,3 +66,24 @@ void Scumm_v2::readIndexFile() { closeRoom(); } + +void Scumm_v2::readMAXS() { + // FIXME - I'm not sure for those values yet, they will have to be rechecked + + _numVariables = 800; // 800 + _numBitVariables = 4096; // 2048 + _numLocalObjects = 200; // 200 + _numArray = 50; + _numVerbs = 100; + _numNewNames = 0; + _objectRoomTable = NULL; + _numCharsets = 9; // 9 + _numInventory = 80; // 80 + _numGlobalScripts = 200; + _numFlObject = 50; + + _shadowPaletteSize = 256; + + _shadowPalette = (byte *) calloc(_shadowPaletteSize, 1); // FIXME - needs to be removed later + allocateArrays(); +} diff --git a/scumm/resource_v3.cpp b/scumm/resource_v3.cpp index d185f8f8db..28897b8759 100644 --- a/scumm/resource_v3.cpp +++ b/scumm/resource_v3.cpp @@ -69,30 +69,13 @@ void Scumm_v3::readIndexFile() { _fileHandle.clearIOFailed(); _fileHandle.seek(0, SEEK_SET); - /* I'm not sure for those values yet, they will have to be rechecked */ - - _numVariables = 800; /* 800 */ - _numBitVariables = 4096; /* 2048 */ - _numLocalObjects = 200; /* 200 */ - _numArray = 50; - _numVerbs = 100; - _numNewNames = 0; - _objectRoomTable = NULL; - _numCharsets = 9; /* 9 */ - _numInventory = 80; /* 80 */ - _numGlobalScripts = 200; - - _shadowPaletteSize = 256; - _shadowPalette = (byte *) calloc(_shadowPaletteSize, 1); // stupid for now. Need to be removed later + readMAXS(); // Jamieson630: palManipulate variable initialization _palManipCounter = 0; _palManipPalette = 0; // Will allocate when needed _palManipIntermediatePal = 0; // Will allocate when needed - _numFlObject = 50; - allocateArrays(); - while (1) { itemsize = _fileHandle.readUint32LE(); @@ -164,3 +147,24 @@ void Scumm_v3::loadCharset(int no) { _fileHandle.read(createResource(6, no, size), size); closeRoom(); } + +void Scumm_v3::readMAXS() { + // FIXME - I'm not sure for those values yet, they will have to be rechecked + + _numVariables = 800; // 800 + _numBitVariables = 4096; // 2048 + _numLocalObjects = 200; // 200 + _numArray = 50; + _numVerbs = 100; + _numNewNames = 0; + _objectRoomTable = NULL; + _numCharsets = 9; // 9 + _numInventory = 80; // 80 + _numGlobalScripts = 200; + _numFlObject = 50; + + _shadowPaletteSize = 256; + + _shadowPalette = (byte *) calloc(_shadowPaletteSize, 1); // FIXME - needs to be removed later + allocateArrays(); +} diff --git a/scumm/script_v6.cpp b/scumm/script_v6.cpp index aefc7840d6..c58caacde6 100644 --- a/scumm/script_v6.cpp +++ b/scumm/script_v6.cpp @@ -2808,36 +2808,25 @@ void Scumm_v6::o6_findAllObjects() { push(readVar(0)); } -static void sub_FEE_78D2(int num, int &arg1, int &arg2) { - byte *ptr = g_scumm->getResourceAddress(rtString, num); - if (g_scumm->_features & GF_AFTER_V7) { - arg1 = READ_LE_UINT32(ptr + 8); - arg2 = READ_LE_UINT32(ptr + 4); - } else { - arg1 = READ_LE_UINT16(ptr + 4); - arg2 = READ_LE_UINT16(ptr + 2); +void Scumm_v6::shuffleArray(int num, int minIdx, int maxIdx) { + int range = maxIdx - minIdx; + int count = range * 2; + + while (count--) { + int rand1 = _rnd.getRandomNumber(range) + minIdx; + int rand2 = _rnd.getRandomNumber(range) + minIdx; + _vars[VAR_V6_RANDOM_NR] = rand2; + + // FIXME - uhm this seems wrong. It replaces item rand1 with itself + // It would seem more logical if we first read elements rand1 and rand2, + // then swapped them. Assembler analysis, anybody? + writeArray(num, 0, rand1, readArray(num, 0, rand1)); + writeArray(num, 0, rand2, readArray(num, 0, rand2)); } } -static void sub_FEE_7822(int num, int arg1, int arg2) { - int var_C = arg2 - arg1; - int count = var_C * 2; - - if (count-- == 0) - return; - - do { - int cx = var_C + 1; - int rand1 = (rand() % cx) + arg1; - int rand2 = (rand() % cx) + arg1; - g_scumm->_vars[g_scumm->VAR_V6_RANDOM_NR] = rand2; - g_scumm->writeArray(num, 0, rand1, g_scumm->readArray(num, 0, rand1)); - g_scumm->writeArray(num, 0, rand2, g_scumm->readArray(num, 0, rand2)); - } while (--count); -} - void Scumm_v6::o6_shuffle() { - sub_FEE_7822(fetchScriptWord(), pop(), pop()); + shuffleArray(fetchScriptWord(), pop(), pop()); } void Scumm_v6::o6_pickVarRandom() { @@ -2857,18 +2846,26 @@ void Scumm_v6::o6_pickVarRandom() { } while (++counter < num); } - sub_FEE_7822(value, 1, num); + shuffleArray(value, 1, num); writeArray(value, 0, 0, 2); push(readArray(value, 0, 1)); return; } num = readArray(value, 0, 0); - sub_FEE_78D2(readVar(value), var_C, var_A); + + byte *ptr = getResourceAddress(rtString, num); + if (_features & GF_AFTER_V7) { + var_A = READ_LE_UINT32(ptr + 4); + var_C = READ_LE_UINT32(ptr + 8); + } else { + var_A = READ_LE_UINT16(ptr + 2); + var_C = READ_LE_UINT16(ptr + 4); + } if ((var_A - 1) < num) { int16 var_2 = readArray(value, 0, num - 1); - sub_FEE_7822(value, 1, var_A - 1); + shuffleArray(value, 1, var_A - 1); if (readArray(value, 0, 1) == var_2) { num = 2; } else { diff --git a/scumm/scumm.h b/scumm/scumm.h index bcd8966b6e..913f5ab0fc 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -564,41 +564,48 @@ protected: void askForDisk(const char *filename, int disknum); bool openResourceFile(const char *filename); -public: +protected: void loadPtrToResource(int type, int i, byte *ptr); void readResTypeList(int id, uint32 tag, const char *name); char *resTypeFromId(int id); void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode); byte *createResource(int type, int index, uint32 size); + int loadResource(int type, int i); void nukeResource(int type, int i); + +public: + bool isGlobInMemory(int type, int index); + bool isResourceLoaded(int type, int index); byte *getResourceAddress(int type, int i); byte *getStringAddress(int i); byte *getStringAddressVar(int i); void ensureResourceLoaded(int type, int i); - int loadResource(int type, int i); int getResourceRoomNr(int type, int index); + +protected: int readSoundResource(int type, int index); int readSoundResourceSmallHeader(int type, int index); void setResourceCounter(int type, int index, byte flag); bool validateResource(const char *str, int type, int index); void increaseResourceCounter(); bool isResourceInUse(int type, int i); - bool isResourceLoaded(int type, int index); void initRoomSubBlocks(); void clearRoomObjects(); void loadRoomObjects(); void loadRoomObjectsSmall(); void readArrayFromIndexFile(); - void readMAXS(); - bool isGlobInMemory(int type, int index); + virtual void readMAXS(); virtual void readIndexFile(); virtual void loadCharset(int i); void nukeCharset(int i); - int _lastLoadedRoom, _roomResource; + int _lastLoadedRoom; +public: + int _roomResource; // FIXME - should be protected but Sound::pauseSounds accesses it byte *findResourceData(uint32 tag, byte *ptr); int getResourceDataSize(byte *ptr); +protected: int getArrayId(); void nukeArray(int a); int defineArray(int a, int b, int c, int d); @@ -611,7 +618,7 @@ public: void destroy(); void dumpResource(char *tag, int index, byte *ptr); - +public: /* Should be in Object class */ byte OF_OWNER_ROOM; int getInventorySlot(); diff --git a/scumm/sound.cpp b/scumm/sound.cpp index d455d48b8f..7ec6524227 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -759,6 +759,8 @@ void Sound::pauseSounds(bool pause) { se->pause(pause); // Don't pause sounds if the game isn't active + // FIXME - this is quite a nasty hack, replace with something cleaner, and w/o + // having to access member vars directly! if (!_scumm->_roomResource) return; |