diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/cine/cine.cpp | 5 | ||||
-rw-r--r-- | engines/cine/part.cpp | 20 | ||||
-rw-r--r-- | engines/cine/part.h | 2 |
3 files changed, 13 insertions, 14 deletions
diff --git a/engines/cine/cine.cpp b/engines/cine/cine.cpp index 6c5069038a..fad6cf3f6a 100644 --- a/engines/cine/cine.cpp +++ b/engines/cine/cine.cpp @@ -75,7 +75,6 @@ CineEngine::~CineEngine() { Common::clearAllSpecialDebugLevels(); free(palPtr); - free(partBuffer); free(textDataPtr); } @@ -154,7 +153,9 @@ void CineEngine::initialize() { collisionPage = new byte[320 * 200]; textDataPtr = (byte *)malloc(8000); - partBuffer = (PartBuffer *)malloc(NUM_MAX_PARTDATA * sizeof(PartBuffer)); + // Clear part buffer as there's nothing loaded into it yet. + // Its size will change when loading data into it with the loadPart function. + partBuffer.clear(); if (g_cine->getGameType() == Cine::GType_OS) { readVolCnf(); diff --git a/engines/cine/part.cpp b/engines/cine/part.cpp index c1159a2012..df530b77f2 100644 --- a/engines/cine/part.cpp +++ b/engines/cine/part.cpp @@ -31,13 +31,10 @@ namespace Cine { -uint16 numElementInPart; - -PartBuffer *partBuffer; +Common::Array<PartBuffer> partBuffer; void loadPart(const char *partName) { - memset(partBuffer, 0, sizeof(PartBuffer) * NUM_MAX_PARTDATA); - numElementInPart = 0; + partBuffer.clear(); g_cine->_partFileHandle.close(); @@ -48,13 +45,14 @@ void loadPart(const char *partName) { setMouseCursor(MOUSE_CURSOR_DISK); - numElementInPart = g_cine->_partFileHandle.readUint16BE(); + uint16 numElementInPart = g_cine->_partFileHandle.readUint16BE(); + partBuffer.resize(numElementInPart); g_cine->_partFileHandle.readUint16BE(); // entry size if (currentPartName != partName) strcpy(currentPartName, partName); - for (uint16 i = 0; i < numElementInPart; i++) { + for (uint16 i = 0; i < partBuffer.size(); i++) { g_cine->_partFileHandle.read(partBuffer[i].partName, 14); partBuffer[i].offset = g_cine->_partFileHandle.readUint32BE(); partBuffer[i].packedSize = g_cine->_partFileHandle.readUint32BE(); @@ -190,7 +188,7 @@ void CineEngine::readVolCnf() { int16 findFileInBundle(const char *fileName) { if (g_cine->getGameType() == Cine::GType_OS) { // look first in currently loaded resource file - for (int i = 0; i < numElementInPart; i++) { + for (uint i = 0; i < partBuffer.size(); i++) { if (!scumm_stricmp(fileName, partBuffer[i].partName)) { return i; } @@ -204,7 +202,7 @@ int16 findFileInBundle(const char *fileName) { const char *part = (*it)._value; loadPart(part); } - for (int i = 0; i < numElementInPart; i++) { + for (uint i = 0; i < partBuffer.size(); i++) { if (!scumm_stricmp(fileName, partBuffer[i].partName)) { return i; } @@ -220,7 +218,7 @@ void readFromPart(int16 idx, byte *dataPtr, uint32 maxSize) { } byte *readBundleFile(int16 foundFileIdx) { - assert(foundFileIdx >= 0 && foundFileIdx < numElementInPart); + assert(foundFileIdx >= 0 && foundFileIdx < (int32)partBuffer.size()); bool error = false; byte *dataPtr = (byte *)calloc(partBuffer[foundFileIdx].unpackedSize, 1); readFromPart(foundFileIdx, dataPtr, partBuffer[foundFileIdx].unpackedSize); @@ -304,7 +302,7 @@ void dumpBundle(const char *fileName) { strcpy(tmpPart, currentPartName); loadPart(fileName); - for (int i = 0; i < numElementInPart; i++) { + for (uint i = 0; i < partBuffer.size(); i++) { byte *data = readBundleFile(i); debug(0, "%s", partBuffer[i].partName); diff --git a/engines/cine/part.h b/engines/cine/part.h index a654a1aebc..dc9d1db537 100644 --- a/engines/cine/part.h +++ b/engines/cine/part.h @@ -37,7 +37,7 @@ struct PartBuffer { #define NUM_MAX_PARTDATA 255 -extern PartBuffer *partBuffer; +extern Common::Array<PartBuffer> partBuffer; void loadPart(const char *partName); void closePart(void); |