From 7c5600724b41d4358cb4ebb1c49f204483ef249c Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Sun, 25 Feb 2007 20:12:23 +0000 Subject: [PATCH] got rid of ArchievedFile. Since only one single file is being read from the archives at every moment, the ArchivedFile structure used for bookkeeping is useless. svn-id: r25864 --- engines/parallaction/animation.cpp | 8 ++-- engines/parallaction/archive.cpp | 64 +++++++++++++++--------------- engines/parallaction/disk.h | 8 ++-- engines/parallaction/graphics.cpp | 60 ++++++++++++++-------------- engines/parallaction/location.cpp | 12 +++--- 5 files changed, 74 insertions(+), 78 deletions(-) diff --git a/engines/parallaction/animation.cpp b/engines/parallaction/animation.cpp index 8c629388467..59428e9026f 100644 --- a/engines/parallaction/animation.cpp +++ b/engines/parallaction/animation.cpp @@ -256,16 +256,16 @@ void Parallaction::loadProgram(Animation *a, char *filename) { sprintf(vC8, "%s.script", filename); - ArchivedFile *file = openArchivedFile(vC8); - if (!file) errorFileNotFound(vC8); + if (!openArchivedFile(vC8)) + errorFileNotFound(vC8); uint32 size = getArchivedFileLength(vC8); char* src = (char*)memAlloc(size+1); - readArchivedFile(file, src, size); + readArchivedFile(src, size); src[size] = '\0'; - closeArchivedFile(file); + closeArchivedFile(); _numLocals = 0; diff --git a/engines/parallaction/archive.cpp b/engines/parallaction/archive.cpp index e22bdeae08c..ec640068cd8 100644 --- a/engines/parallaction/archive.cpp +++ b/engines/parallaction/archive.cpp @@ -27,15 +27,11 @@ namespace Parallaction { -struct ArchivedFile { - uint16 _index; - uint32 _offset; - uint32 _cursor; - uint16 field_A; // unused - uint16 field_C; // unused - uint32 _endOffset; -}; - +static bool _file = false; +static uint16 _fileIndex = 0; +static uint32 _fileOffset = 0; +static uint32 _fileCursor = 0; +static uint32 _fileEndOffset = 0; #define MAX_ARCHIVE_ENTRIES 384 @@ -53,7 +49,6 @@ static char _archiveDir[MAX_ARCHIVE_ENTRIES][32]; static uint32 _archiveLenghts[MAX_ARCHIVE_ENTRIES]; static uint32 _archiveOffsets[MAX_ARCHIVE_ENTRIES]; -static uint32 _handle = MAX_ARCHIVE_ENTRIES; void openArchive(const char *file) { @@ -106,37 +101,36 @@ void closeArchive() { } -ArchivedFile *openArchivedFile(const char *name) { +bool openArchivedFile(const char *name) { uint16 i = 0; for ( ; i < MAX_ARCHIVE_ENTRIES; i++) { if (!scumm_stricmp(_archiveDir[i], name)) break; } - if (i == MAX_ARCHIVE_ENTRIES) return NULL; + if (i == MAX_ARCHIVE_ENTRIES) return false; debugC(1, kDebugDisk, "file '%s' found in slot %i", name, i); - ArchivedFile *file = (ArchivedFile*)memAlloc(sizeof(ArchivedFile)); + _file = true; - if (!file) - error("openArchivedFile: can't allocate buffer for '%s'", name); + _fileIndex = i; + _fileOffset = _archiveOffsets[i]; + _fileCursor = _archiveOffsets[i]; + _fileEndOffset = _archiveOffsets[i] + _archiveLenghts[i]; - file->_index = i; - file->_offset = _archiveOffsets[i]; - file->_cursor = _archiveOffsets[i]; - file->_endOffset = _archiveOffsets[i] + _archiveLenghts[i]; + _archive.seek(_fileOffset); - _handle = file->_index; - _archive.seek(file->_offset); - - return file; + return true; } -void closeArchivedFile(ArchivedFile *file) { - if (file) memFree(file); - _handle = MAX_ARCHIVE_ENTRIES; +void closeArchivedFile() { + _file = false; + _fileIndex = 0; + _fileCursor = 0; + _fileOffset = 0; + _fileEndOffset = 0; return; } @@ -156,17 +150,19 @@ uint16 getArchivedFileLength(const char *name) { -int16 readArchivedFile(ArchivedFile *file, void *buffer, uint16 size) { +int16 readArchivedFile(void *buffer, uint16 size) { // printf("readArchivedFile(%i, %i)\n", file->_cursor, file->_endOffset); + if (_file == false) + error("readArchiveFile: no archived file is currently open"); - if (file->_cursor == file->_endOffset) return -1; + if (_fileCursor == _fileEndOffset) return -1; - if (file->_endOffset - file->_cursor < size) - size = file->_endOffset - file->_cursor; + if (_fileEndOffset - _fileCursor < size) + size = _fileEndOffset - _fileCursor; - _archive.seek(file->_cursor); + _archive.seek(_fileCursor); int16 read = _archive.read(buffer, size); - file->_cursor += read; + _fileCursor += read; return read; } @@ -186,7 +182,9 @@ int16 readArchivedFile(ArchivedFile *file, void *buffer, uint16 size) { #endif -char *readArchivedFileText(char *buf, uint16 size, void*) { +char *readArchivedFileText(char *buf, uint16 size) { + if (_file == false) + error("readArchiveFileText: no archived file is currently open"); char *t = _archive.readLine(buf, size); diff --git a/engines/parallaction/disk.h b/engines/parallaction/disk.h index 894a95e3530..0ea18aeaa0c 100644 --- a/engines/parallaction/disk.h +++ b/engines/parallaction/disk.h @@ -36,13 +36,13 @@ struct ArchivedFile; void openArchive(const char *file); void closeArchive(); -ArchivedFile *openArchivedFile(const char *name); -void closeArchivedFile(ArchivedFile*); +bool openArchivedFile(const char *name); +void closeArchivedFile(); uint16 getArchivedFileLength(const char *name); -int16 readArchivedFile(ArchivedFile*, void *buffer, uint16 size); -char *readArchivedFileText(char *buf, uint16 size, void*); +int16 readArchivedFile(void *buffer, uint16 size); +char *readArchivedFileText(char *buf, uint16 size); diff --git a/engines/parallaction/graphics.cpp b/engines/parallaction/graphics.cpp index 3f8adab324b..b00a025fe5a 100644 --- a/engines/parallaction/graphics.cpp +++ b/engines/parallaction/graphics.cpp @@ -1020,20 +1020,19 @@ void Graphics::loadStaticCnv(const char *filename, StaticCnv *cnv) { char path[PATH_LEN]; strcpy(path, filename); - ArchivedFile *file = openArchivedFile(path); - if (!file) { + if (!openArchivedFile(path)) { sprintf(path, "%s.pp", filename); - file = openArchivedFile(path); - if (!file) errorFileNotFound(path); + if (!openArchivedFile(path)) + errorFileNotFound(path); } cnv->_width = cnv->_height = 0; byte unk; - readArchivedFile(file, &unk, 1); - readArchivedFile(file, &unk, 1); + readArchivedFile(&unk, 1); + readArchivedFile(&unk, 1); cnv->_width = unk; - readArchivedFile(file, &unk, 1); + readArchivedFile(&unk, 1); cnv->_height = unk; uint16 compressedsize = getArchivedFileLength(path) - 3; @@ -1042,8 +1041,8 @@ void Graphics::loadStaticCnv(const char *filename, StaticCnv *cnv) { uint16 size = cnv->_width*cnv->_height; cnv->_data0 = (byte*)memAlloc(size); - readArchivedFile(file, compressed, compressedsize); - closeArchivedFile(file); + readArchivedFile(compressed, compressedsize); + closeArchivedFile(); decompressChunk(compressed, cnv->_data0, size); memFree(compressed); @@ -1060,22 +1059,21 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) { char path[PATH_LEN]; strcpy(path, filename); - ArchivedFile *file = openArchivedFile(path); - if (!file) { + if (!openArchivedFile(path)) { sprintf(path, "%s.pp", filename); - file = openArchivedFile(path); - if (!file) errorFileNotFound(path); + if (!openArchivedFile(path)) + errorFileNotFound(path); } cnv->_count = cnv->_width = cnv->_height = 0; byte unk; - readArchivedFile(file, &unk, 1); + readArchivedFile(&unk, 1); cnv->_count = unk; - readArchivedFile(file, &unk, 1); + readArchivedFile(&unk, 1); cnv->_width = unk; - readArchivedFile(file, &unk, 1); + readArchivedFile(&unk, 1); cnv->_height = unk; uint16 framesize = cnv->_width*cnv->_height; @@ -1085,7 +1083,7 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) { uint32 size = getArchivedFileLength(path) - 3; byte *buf = (byte*)memAlloc(size); - readArchivedFile(file, buf, size); + readArchivedFile(buf, size); byte *s = buf; @@ -1098,7 +1096,7 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) { s += read; } - closeArchivedFile(file); + closeArchivedFile(); memFree(buf); @@ -1167,16 +1165,16 @@ void unpackBackgroundScanline(byte *src, byte *screen, byte *mask, byte *path) { void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) { // printf("Graphics::loadBackground(%s)\n", filename); - ArchivedFile *file = openArchivedFile(filename); - if (!file) errorFileNotFound(filename); + if (!openArchivedFile(filename)) + errorFileNotFound(filename); // byte palette[PALETTE_SIZE]; byte v150[4]; - readArchivedFile(file, _palette, PALETTE_SIZE); - readArchivedFile(file, &v150, 4); + readArchivedFile(_palette, PALETTE_SIZE); + readArchivedFile(&v150, 4); byte tempfx[sizeof(PaletteFxRange)*6]; - readArchivedFile(file, &tempfx, sizeof(PaletteFxRange)*6); + readArchivedFile(&tempfx, sizeof(PaletteFxRange)*6); // setPalette(palette); @@ -1207,7 +1205,7 @@ void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) { memset(_buffers[kMask0], 0, SCREENMASK_WIDTH*SCREEN_HEIGHT); byte *v4 = (byte*)memAlloc(SCREEN_SIZE); - readArchivedFile(file, v4, SCREEN_SIZE); + readArchivedFile(v4, SCREEN_SIZE); byte v144[SCREEN_WIDTH]; @@ -1218,7 +1216,7 @@ void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) { } memFree(v4); - closeArchivedFile(file); + closeArchivedFile(); return; } @@ -1231,17 +1229,17 @@ void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) { // void Graphics::loadMaskAndPath(const char *filename) { - ArchivedFile *file = openArchivedFile(filename); - if (!file) errorFileNotFound(filename); + if (!openArchivedFile(filename)) + errorFileNotFound(filename); byte v4[4]; - readArchivedFile(file, v4, 4); - readArchivedFile(file, _buffers[kPath0], SCREENPATH_WIDTH*SCREEN_HEIGHT); - readArchivedFile(file, _buffers[kMask0], SCREENMASK_WIDTH*SCREEN_HEIGHT); + readArchivedFile(v4, 4); + readArchivedFile(_buffers[kPath0], SCREENPATH_WIDTH*SCREEN_HEIGHT); + readArchivedFile(_buffers[kMask0], SCREENMASK_WIDTH*SCREEN_HEIGHT); for (uint16 _si = 0; _si < 4; _si++) _bgLayers[_si] = v4[_si]; - closeArchivedFile(file); + closeArchivedFile(); return; } diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp index 79bb8e5b3de..81167ef158a 100644 --- a/engines/parallaction/location.cpp +++ b/engines/parallaction/location.cpp @@ -66,11 +66,11 @@ void Parallaction::parseLocation(const char *filename) { _languageDir[2] = '\0'; openArchive(_languageDir); _languageDir[2] = '/'; - ArchivedFile *file = openArchivedFile(archivefile); - if (!file) { + + if (!openArchivedFile(archivefile)) { sprintf(archivefile, "%s%s.loc", _languageDir, filename); - file = openArchivedFile(archivefile); - if (!file) errorFileNotFound(filename); + if (!openArchivedFile(archivefile)) + errorFileNotFound(filename); } uint32 count = getArchivedFileLength(archivefile); @@ -78,8 +78,8 @@ void Parallaction::parseLocation(const char *filename) { _locationScript = new Script(location_src); - readArchivedFile(file, location_src, count); - closeArchivedFile(file); + readArchivedFile(location_src, count); + closeArchivedFile(); closeArchive(); fillBuffers(*_locationScript, true);