From cfe85b8618637e5d85dc183b142e0bfffc98434b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 10 Apr 2005 00:51:47 +0000 Subject: Don't call allocateArrays from readMAXS, rather call it explicitly after calling readMAXS; init _palManipCounter in the proper place (only needed when restarting); free palManip data on exit svn-id: r17495 --- scumm/intern.h | 1 + scumm/resource.cpp | 9 +-------- scumm/resource_v2.cpp | 30 ++++++++++++++---------------- scumm/resource_v3.cpp | 6 +----- scumm/resource_v4.cpp | 7 +------ scumm/resource_v7he.cpp | 6 ------ scumm/scumm.cpp | 5 +++++ 7 files changed, 23 insertions(+), 41 deletions(-) diff --git a/scumm/intern.h b/scumm/intern.h index 7aaf4e88ca..dd85c58c20 100644 --- a/scumm/intern.h +++ b/scumm/intern.h @@ -261,6 +261,7 @@ protected: virtual void readIndexFile(); void readClassicIndexFile(); // V1 void readEnhancedIndexFile(); // V2 + virtual void readGlobalObjects(); virtual void loadCharset(int no); diff --git a/scumm/resource.cpp b/scumm/resource.cpp index 0eacd914e8..0c3d2c7039 100644 --- a/scumm/resource.cpp +++ b/scumm/resource.cpp @@ -410,6 +410,7 @@ void ScummEngine::readIndexFile() { case MKID('MAXS'): readMAXS(itemsize); + allocateArrays(); break; case MKID('DIRN'): @@ -984,8 +985,6 @@ void ScummEngine_v5::readMAXS(int blockSize) { if (_shadowPaletteSize) _shadowPalette = (byte *)calloc(_shadowPaletteSize, 1); - - allocateArrays(); } void ScummEngine_v8::readMAXS(int blockSize) { @@ -1015,8 +1014,6 @@ void ScummEngine_v8::readMAXS(int blockSize) { _shadowPaletteSize = NUM_SHADOW_PALETTE * 256; _shadowPalette = (byte *)calloc(_shadowPaletteSize, 1); - - allocateArrays(); } void ScummEngine_v7::readMAXS(int blockSize) { @@ -1049,8 +1046,6 @@ void ScummEngine_v7::readMAXS(int blockSize) { _shadowPaletteSize = NUM_SHADOW_PALETTE * 256; _shadowPalette = (byte *)calloc(_shadowPaletteSize, 1); - - allocateArrays(); } void ScummEngine_v6::readMAXS(int blockSize) { @@ -1082,8 +1077,6 @@ void ScummEngine_v6::readMAXS(int blockSize) { _shadowPaletteSize = 256; _shadowPalette = (byte *)calloc(_shadowPaletteSize, 1); - - allocateArrays(); } void ScummEngine::readGlobalObjects() { diff --git a/scumm/resource_v2.cpp b/scumm/resource_v2.cpp index b2c512224d..38eb622a6e 100644 --- a/scumm/resource_v2.cpp +++ b/scumm/resource_v2.cpp @@ -65,11 +65,7 @@ void ScummEngine_v2::readClassicIndexFile() { _fileHandle->seek(0, SEEK_SET); readMAXS(0); - - // Jamieson630: palManipulate variable initialization - _palManipCounter = 0; - _palManipPalette = 0; // Will allocate when needed - _palManipIntermediatePal = 0; // Will allocate when needed + allocateArrays(); _fileHandle->readUint16LE(); /* version magic number */ for (i = 0; i != _numGlobalObjects; i++) { @@ -122,7 +118,7 @@ void ScummEngine_v2::readEnhancedIndexFile() { _musicEngine = new Player_V2(this, _midiDriver != MD_PCSPK); _numGlobalObjects = _fileHandle->readUint16LE(); - _fileHandle->seek(_numGlobalObjects, SEEK_CUR); // Skip object flags + _fileHandle->seek(_numGlobalObjects, SEEK_CUR); _numRooms = _fileHandle->readByte(); _fileHandle->seek(_numRooms * 3, SEEK_CUR); _numCostumes = _fileHandle->readByte(); @@ -135,24 +131,26 @@ void ScummEngine_v2::readEnhancedIndexFile() { _fileHandle->seek(0, SEEK_SET); readMAXS(0); - - // Jamieson630: palManipulate variable initialization - _palManipCounter = 0; - _palManipPalette = 0; // Will allocate when needed - _palManipIntermediatePal = 0; // Will allocate when needed + allocateArrays(); _fileHandle->readUint16LE(); /* version magic number */ + readGlobalObjects(); + readResTypeList(rtRoom, MKID('ROOM'), "room"); + readResTypeList(rtCostume, MKID('COST'), "costume"); + readResTypeList(rtScript, MKID('SCRP'), "script"); + readResTypeList(rtSound, MKID('SOUN'), "sound"); +} + +void ScummEngine_v2::readGlobalObjects() { + int i; int num = _fileHandle->readUint16LE(); assert(num == _numGlobalObjects); - for (int i = 0; i != num; i++) { + + for (i = 0; i != num; i++) { byte tmp = _fileHandle->readByte(); _objectOwnerTable[i] = tmp & OF_OWNER_MASK; _objectStateTable[i] = tmp >> OF_STATE_SHL; } - readResTypeList(rtRoom, MKID('ROOM'), "room"); - readResTypeList(rtCostume, MKID('COST'), "costume"); - readResTypeList(rtScript, MKID('SCRP'), "script"); - readResTypeList(rtSound, MKID('SOUN'), "sound"); } void ScummEngine_v2::readIndexFile() { diff --git a/scumm/resource_v3.cpp b/scumm/resource_v3.cpp index 94d2888b71..6313393329 100644 --- a/scumm/resource_v3.cpp +++ b/scumm/resource_v3.cpp @@ -81,11 +81,7 @@ void ScummEngine_v3old::readIndexFile() { _fileHandle->seek(0, SEEK_SET); readMAXS(0); - - // Jamieson630: palManipulate variable initialization - _palManipCounter = 0; - _palManipPalette = 0; // Will allocate when needed - _palManipIntermediatePal = 0; // Will allocate when needed + allocateArrays(); _fileHandle->readUint16LE(); /* version magic number */ readGlobalObjects(); diff --git a/scumm/resource_v4.cpp b/scumm/resource_v4.cpp index d73ac93acf..9efa16573b 100644 --- a/scumm/resource_v4.cpp +++ b/scumm/resource_v4.cpp @@ -71,11 +71,7 @@ void ScummEngine_v4::readIndexFile() { _fileHandle->seek(0, SEEK_SET); readMAXS(0); - - // Jamieson630: palManipulate variable initialization - _palManipCounter = 0; - _palManipPalette = 0; // Will allocate when needed - _palManipIntermediatePal = 0; // Will allocate when needed + allocateArrays(); while (1) { itemsize = _fileHandle->readUint32LE(); @@ -165,7 +161,6 @@ void ScummEngine_v4::readMAXS(int blockSize) { _shadowPaletteSize = 256; _shadowPalette = (byte *) calloc(_shadowPaletteSize, 1); // FIXME - needs to be removed later - allocateArrays(); } void ScummEngine_v4::readGlobalObjects() { diff --git a/scumm/resource_v7he.cpp b/scumm/resource_v7he.cpp index fd092ba90f..50ce21d870 100644 --- a/scumm/resource_v7he.cpp +++ b/scumm/resource_v7he.cpp @@ -1686,8 +1686,6 @@ void ScummEngine_v99he::readMAXS(int blockSize) { _objectRoomTable = (byte *)calloc(_numGlobalObjects, 1); _numGlobalScripts = 2048; - - allocateArrays(); } void ScummEngine_v90he::readMAXS(int blockSize) { @@ -1719,8 +1717,6 @@ void ScummEngine_v90he::readMAXS(int blockSize) { _numGlobalScripts = 2048; else _numGlobalScripts = 200; - - allocateArrays(); } void ScummEngine_v72he::readMAXS(int blockSize) { @@ -1746,8 +1742,6 @@ void ScummEngine_v72he::readMAXS(int blockSize) { _objectRoomTable = (byte *)calloc(_numGlobalObjects, 1); _numGlobalScripts = 200; - - allocateArrays(); } byte *ScummEngine_v72he::getStringAddress(int i) { diff --git a/scumm/scumm.cpp b/scumm/scumm.cpp index 8c675c871f..646073636e 100644 --- a/scumm/scumm.cpp +++ b/scumm/scumm.cpp @@ -1169,6 +1169,9 @@ ScummEngine::~ScummEngine() { delete _costumeRenderer; free(_shadowPalette); + + free(_palManipPalette); + free(_palManipIntermediatePal); res.freeResources(); if (_heversion >= 70) { @@ -1403,6 +1406,8 @@ void ScummEngine::scummInit() { initScreens(16, 144); } + _palManipCounter = 0; + for (i = 0; i < 256; i++) _roomPalette[i] = i; if (_version == 1) { -- cgit v1.2.3