diff options
author | Travis Howell | 2006-04-20 00:42:54 +0000 |
---|---|---|
committer | Travis Howell | 2006-04-20 00:42:54 +0000 |
commit | 531a62939c1f03873de36bcc8485c1ce024a1376 (patch) | |
tree | e2746bdbdeb66cf82ba9d14ee19a020a9c11f511 /engines | |
parent | 1f01a524212074c07dc10cc8ebae99181f0f0733 (diff) | |
download | scummvm-rg350-531a62939c1f03873de36bcc8485c1ce024a1376.tar.gz scummvm-rg350-531a62939c1f03873de36bcc8485c1ce024a1376.tar.bz2 scummvm-rg350-531a62939c1f03873de36bcc8485c1ce024a1376.zip |
Update resource managment for FF, this method is more efficent for Simon 1/2 too
svn-id: r22043
Diffstat (limited to 'engines')
-rw-r--r-- | engines/simon/res.cpp | 93 | ||||
-rw-r--r-- | engines/simon/simon.cpp | 62 | ||||
-rw-r--r-- | engines/simon/simon.h | 5 |
3 files changed, 95 insertions, 65 deletions
diff --git a/engines/simon/res.cpp b/engines/simon/res.cpp index f99e6c1fda..e67258b464 100644 --- a/engines/simon/res.cpp +++ b/engines/simon/res.cpp @@ -557,10 +557,11 @@ static bool decrunchFile(byte *src, byte *dst, uint32 size) { #undef SD_TYPE_MATCH void SimonEngine::read_vga_from_datfile_1(uint vga_id) { + uint32 offs, size; + if (getFeatures() & GF_OLD_BUNDLE) { File in; char filename[15]; - uint32 size; if (vga_id == 23) vga_id = 112; if (vga_id == 328) @@ -578,44 +579,47 @@ void SimonEngine::read_vga_from_datfile_1(uint vga_id) { in.open(filename); if (in.isOpen() == false) error("read_vga_from_datfile_1: can't open %s", filename); - size = in.size(); + size = in.size(); if (getFeatures() & GF_CRUNCHED) { - byte *buffer = new byte[size]; - if (in.read(buffer, size) != size) + byte *srcBuffer = (byte *)malloc(size); + if (in.read(srcBuffer, size) != size) error("read_vga_from_datfile_1: read failed"); - decrunchFile(buffer, _vgaBufferPointers[11].vgaFile2, size); - delete [] buffer; + decrunchFile(srcBuffer, _vgaBufferPointers[11].vgaFile2, size); + free(srcBuffer); } else { if (in.read(_vgaBufferPointers[11].vgaFile2, size) != size) error("read_vga_from_datfile_1: read failed"); } in.close(); } else { - uint32 offs_a = _gameOffsetsPtr[vga_id]; - uint32 size = _gameOffsetsPtr[vga_id + 1] - offs_a; + offs = _gameOffsetsPtr[vga_id]; - resfile_read(_vgaBufferPointers[11].vgaFile2, offs_a, size); + size = _gameOffsetsPtr[vga_id + 1] - offs; + resfile_read(_vgaBufferPointers[11].vgaFile2, offs, size); } } -byte *SimonEngine::read_vga_from_datfile_2(uint id, uint type) { +byte *SimonEngine::loadVGAFile(uint id, uint type, uint &dstSize) { File in; char filename[15]; byte *dst = NULL; - - // !!! HACK !!! - // allocate more space for text to cope with foreign languages that use - // up more space than english. I hope 6400 bytes are enough. This number - // is base on: 2 (lines) * 320 (screen width) * 10 (textheight) -- olki - int extraBuffer = (id == 5 ? 6400 : 0); + uint32 file, offs, srcSize; + uint extraBuffer = 0; + + if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) { + // !!! HACK !!! + // Allocate more space for text to cope with foreign languages that use + // up more space than english. I hope 6400 bytes are enough. This number + // is base on: 2 (lines) * 320 (screen width) * 10 (textheight) -- olki + extraBuffer = (id == 5 ? 6400 : 0); + } if (getFeatures() & GF_ZLIBCOMP) { - uint32 file, offset, srcSize, dstSize; if (getPlatform() == Common::kPlatformAmiga) { - loadOffsets((const char*)"gfxindex.dat", id / 2 * 3 + type, file, offset, srcSize, dstSize); + loadOffsets((const char*)"gfxindex.dat", id / 2 * 3 + type, file, offs, srcSize, dstSize); } else { - loadOffsets((const char*)"graphics.vga", id / 2 * 3 + type, file, offset, srcSize, dstSize); + loadOffsets((const char*)"graphics.vga", id / 2 * 3 + type, file, offs, srcSize, dstSize); } if (getPlatform() == Common::kPlatformAmiga) @@ -623,11 +627,9 @@ byte *SimonEngine::read_vga_from_datfile_2(uint id, uint type) { else sprintf(filename, "graphics.vga"); - dst = allocBlock(dstSize); - decompressData(filename, dst, offset, srcSize, dstSize); - return dst; + dst = allocBlock(dstSize + extraBuffer); + decompressData(filename, dst, offs, srcSize, dstSize); } else if (getFeatures() & GF_OLD_BUNDLE) { - uint32 size; if (getPlatform() == Common::kPlatformAmiga) { if (getFeatures() & GF_TALKIE) sprintf(filename, "%.3d%d.out", id / 2, type); @@ -642,34 +644,41 @@ byte *SimonEngine::read_vga_from_datfile_2(uint id, uint type) { if (type == 3) return NULL; else - error("read_vga_from_datfile_2: can't open %s", filename); + error("loadVGAFile: can't open %s", filename); } - size = in.size(); + dstSize = srcSize = in.size(); if (getFeatures() & GF_CRUNCHED) { - byte *buffer = new byte[size]; - if (in.read(buffer, size) != size) - error("read_vga_from_datfile_2: read failed"); - dst = allocBlock (READ_BE_UINT32(buffer + size - 4) + extraBuffer); - decrunchFile(buffer, dst, size); - delete[] buffer; + byte *srcBuffer = (byte *)malloc(srcSize); + if (in.read(srcBuffer, srcSize) != srcSize) + error("loadVGAFile: read failed"); + + dstSize = READ_BE_UINT32(srcBuffer + srcSize - 4); + dst = allocBlock (dstSize + extraBuffer); + decrunchFile(srcBuffer, dst, srcSize); + free(srcBuffer); } else { - dst = allocBlock(size + extraBuffer); - if (in.read(dst, size) != size) - error("read_vga_from_datfile_2: read failed"); + dst = allocBlock(dstSize + extraBuffer); + if (in.read(dst, dstSize) != dstSize) + error("loadVGAFile: read failed"); } in.close(); - - return dst; } else { - uint32 offs_a = _gameOffsetsPtr[id]; - uint32 size = _gameOffsetsPtr[id + 1] - offs_a; + offs = _gameOffsetsPtr[id]; - dst = allocBlock(size + extraBuffer); - resfile_read(dst, offs_a, size); - - return dst; + dstSize = _gameOffsetsPtr[id + 1] - offs; + dst = allocBlock(dstSize + extraBuffer); + resfile_read(dst, offs, dstSize); } + + dstSize += extraBuffer; + return dst; +} + +void SimonEngine::resfile_read(void *dst, uint32 offs, uint32 size) { + _gameFile->seek(offs, SEEK_SET); + if (_gameFile->read(dst, size) != size) + error("resfile_read(%d,%d) read failed", offs, size); } void SimonEngine::loadSound(uint sound, uint pan, uint vol, uint type) { diff --git a/engines/simon/simon.cpp b/engines/simon/simon.cpp index 0e585df82f..09c46a5ff5 100644 --- a/engines/simon/simon.cpp +++ b/engines/simon/simon.cpp @@ -2152,6 +2152,7 @@ TextLocation *SimonEngine::getTextLocation(uint a) { void SimonEngine::loadZone(uint vga_res) { VgaPointersEntry *vpe; + uint32 size; CHECK_BOUNDS(vga_res, _vgaBufferPointers); @@ -2159,18 +2160,23 @@ void SimonEngine::loadZone(uint vga_res) { if (vpe->vgaFile1 != NULL) return; - vpe->vgaFile1 = read_vga_from_datfile_2(vga_res * 2, 1); - vpe->vgaFile2 = read_vga_from_datfile_2(vga_res * 2 + 1, 2); + vpe->vgaFile1 = loadVGAFile(vga_res * 2, 1, size); + vpe->vgaFile1End = vpe->vgaFile1 + size; + + vpe->vgaFile2 = loadVGAFile(vga_res * 2 + 1, 2, size); + vpe->vgaFile2End = vpe->vgaFile2 + size; vpe->sfxFile = NULL; - if (getGameType() == GType_FF && getPlatform() == Common::kPlatformWindows) - vpe->sfxFile = read_vga_from_datfile_2(vga_res * 2, 3); + if (getGameType() == GType_FF && getPlatform() == Common::kPlatformWindows) { + vpe->sfxFile = loadVGAFile(vga_res * 2, 3, size); + vpe->sfxFileEnd = vpe->sfxFile + size; + } } byte *SimonEngine::allocBlock(uint32 size) { byte *block, *blockEnd; - _rejectCount = 0; + _rejectCount = false; for (;;) { block = _vgaBufFreeStart; @@ -2217,13 +2223,20 @@ void SimonEngine::checkNoOverWrite(byte *end) { vpe = &_vgaBufferPointers[_noOverWrite]; - if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 || - _vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) { - _rejectBlock = 1; + if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1End) { + _rejectBlock = true; _rejectCount++; - _vgaBufFreeStart = vpe->vgaFile1 + 0x5000; + _vgaBufFreeStart = vpe->vgaFile1End; + } else if (_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2End) { + _rejectBlock = true; + _rejectCount++; + _vgaBufFreeStart = vpe->vgaFile2End; + } else if (_vgaBufFreeStart <= vpe->sfxFile && end >= vpe->sfxFileEnd) { + _rejectBlock = true; + _rejectCount++; + _vgaBufFreeStart = vpe->sfxFileEnd; } else { - _rejectBlock = 0; + _rejectBlock = false; } } @@ -2245,11 +2258,15 @@ void SimonEngine::checkZonePtrs(byte *end) { uint count = ARRAYSIZE(_vgaBufferPointers); VgaPointersEntry *vpe = _vgaBufferPointers; do { - if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 || - _vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) { - vpe->sfxFile = NULL; + if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1End || + _vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2End || + _vgaBufFreeStart <= vpe->sfxFile && end >= vpe->sfxFileEnd) { vpe->vgaFile1 = NULL; + vpe->vgaFile1End = NULL; vpe->vgaFile2 = NULL; + vpe->vgaFile2End = NULL; + vpe->sfxFile = NULL; + vpe->sfxFileEnd = NULL; } } while (++vpe, --count); @@ -2260,11 +2277,18 @@ void SimonEngine::checkAnims(uint a, byte *end) { vpe = &_vgaBufferPointers[a]; - if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 || - _vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) { + if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1End) { _rejectBlock = true; _rejectCount++; - _vgaBufFreeStart = vpe->vgaFile1 + 0x5000; + _vgaBufFreeStart = vpe->vgaFile1End; + } else if (_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2End) { + _rejectBlock = true; + _rejectCount++; + _vgaBufFreeStart = vpe->vgaFile2End; + } else if (_vgaBufFreeStart <= vpe->sfxFile && end >= vpe->sfxFileEnd) { + _rejectBlock = true; + _rejectCount++; + _vgaBufFreeStart = vpe->sfxFileEnd; } else { _rejectBlock = false; } @@ -3309,12 +3333,6 @@ void SimonEngine::playSpeech(uint speech_id, uint vgaSpriteId) { } } -void SimonEngine::resfile_read(void *dst, uint32 offs, uint32 size) { - _gameFile->seek(offs, SEEK_SET); - if (_gameFile->read(dst, size) != size) - error("resfile_read(%d,%d) read failed", offs, size); -} - void SimonEngine::openGameFile() { if (!(getFeatures() & GF_OLD_BUNDLE)) { _gameFile = new File(); diff --git a/engines/simon/simon.h b/engines/simon/simon.h index ad53375338..cb3cb8e796 100644 --- a/engines/simon/simon.h +++ b/engines/simon/simon.h @@ -75,8 +75,11 @@ struct HitArea { struct VgaPointersEntry { byte *vgaFile1; + byte *vgaFile1End; byte *vgaFile2; + byte *vgaFile2End; byte *sfxFile; + byte *sfxFileEnd; VgaPointersEntry() { memset(this, 0, sizeof(*this)); } }; @@ -1043,7 +1046,7 @@ protected: byte *getBackGround(); byte *getScaleBuf(); - byte *read_vga_from_datfile_2(uint id, uint type); + byte *loadVGAFile(uint id, uint type, uint &dstSize); void resfile_read(void *dst, uint32 offs, uint32 size); |