aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Mettifogo2007-02-25 20:35:47 +0000
committerNicola Mettifogo2007-02-25 20:35:47 +0000
commitcacff9a9f26eff5111b1f5eef3491ac406f1245d (patch)
tree389ab1f28c51810e5634b98239319fa097d09a47
parent0c77177ef1d8ffc27710c5b2562069a4e3f6ed02 (diff)
downloadscummvm-rg350-cacff9a9f26eff5111b1f5eef3491ac406f1245d.tar.gz
scummvm-rg350-cacff9a9f26eff5111b1f5eef3491ac406f1245d.tar.bz2
scummvm-rg350-cacff9a9f26eff5111b1f5eef3491ac406f1245d.zip
wrapped archive routines into a new class named Archive. File-level static variables have been made members of the new class.
svn-id: r25866
-rw-r--r--engines/parallaction/animation.cpp8
-rw-r--r--engines/parallaction/archive.cpp64
-rw-r--r--engines/parallaction/callables.cpp2
-rw-r--r--engines/parallaction/dialogue.cpp4
-rw-r--r--engines/parallaction/disk.h45
-rw-r--r--engines/parallaction/graphics.cpp54
-rw-r--r--engines/parallaction/location.cpp18
-rw-r--r--engines/parallaction/menu.cpp12
-rw-r--r--engines/parallaction/parallaction.cpp4
-rw-r--r--engines/parallaction/parallaction.h3
-rw-r--r--engines/parallaction/saveload.cpp2
11 files changed, 101 insertions, 115 deletions
diff --git a/engines/parallaction/animation.cpp b/engines/parallaction/animation.cpp
index 59428e9026..2bfbba16e2 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);
- if (!openArchivedFile(vC8))
+ if (!_archive.openArchivedFile(vC8))
errorFileNotFound(vC8);
- uint32 size = getArchivedFileLength(vC8);
+ uint32 size = _archive.getArchivedFileLength(vC8);
char* src = (char*)memAlloc(size+1);
- readArchivedFile(src, size);
+ _archive.readArchivedFile(src, size);
src[size] = '\0';
- closeArchivedFile();
+ _archive.closeArchivedFile();
_numLocals = 0;
diff --git a/engines/parallaction/archive.cpp b/engines/parallaction/archive.cpp
index ec640068cd..5fb69cb852 100644
--- a/engines/parallaction/archive.cpp
+++ b/engines/parallaction/archive.cpp
@@ -27,41 +27,12 @@
namespace Parallaction {
-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
-
-#define DIRECTORY_OFFSET_IN_FILE 0x4000
-
-#ifdef PALMOS_ARM
- static Common::File *_archiveP = NULL;
- #define _archive (*_archiveP)
-#else
- static Common::File _archive;
-#endif
-
-
-static char _archiveDir[MAX_ARCHIVE_ENTRIES][32];
-static uint32 _archiveLenghts[MAX_ARCHIVE_ENTRIES];
-static uint32 _archiveOffsets[MAX_ARCHIVE_ENTRIES];
-
-
-
-void openArchive(const char *file) {
+void Archive::open(const char *file) {
debugC(1, kDebugDisk, "open archive '%s'", file);
-#ifdef PALMOS_ARM
- if (!_archiveP)
- _archiveP = new Common::File();
-#endif
-
if (_archive.isOpen())
- closeArchive();
-
+ close();
uint32 offset = DIRECTORY_OFFSET_IN_FILE;
char path[PATH_LEN];
@@ -91,8 +62,7 @@ void openArchive(const char *file) {
}
-
-void closeArchive() {
+void Archive::close() {
debugC(1, kDebugDisk, "close current archive");
if (!_archive.isOpen()) return;
@@ -101,7 +71,7 @@ void closeArchive() {
}
-bool openArchivedFile(const char *name) {
+bool Archive::openArchivedFile(const char *name) {
uint16 i = 0;
for ( ; i < MAX_ARCHIVE_ENTRIES; i++) {
@@ -124,8 +94,7 @@ bool openArchivedFile(const char *name) {
}
-
-void closeArchivedFile() {
+void Archive::closeArchivedFile() {
_file = false;
_fileIndex = 0;
_fileCursor = 0;
@@ -135,9 +104,7 @@ void closeArchivedFile() {
}
-
-
-uint16 getArchivedFileLength(const char *name) {
+uint16 Archive::getArchivedFileLength(const char *name) {
// printf("getArchivedFileLength(%s)\n", name);
for (uint16 i = 0; i < MAX_ARCHIVE_ENTRIES; i++) {
@@ -149,8 +116,7 @@ uint16 getArchivedFileLength(const char *name) {
}
-
-int16 readArchivedFile(void *buffer, uint16 size) {
+int16 Archive::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");
@@ -167,22 +133,8 @@ int16 readArchivedFile(void *buffer, uint16 size) {
return read;
}
-#if 0
-int16 readArchivedFile(ArchivedFile *file, void *buffer, uint16 size) {
- printf("readArchivedFile(%i, %i)\n", file->_cursor, file->_endOffset);
-
- if (file->_cursor == file->_endOffset) return -1;
-
- _archive.seek(file->_cursor);
- int16 read = _archive.read(buffer, size);
- file->_cursor += read;
-
- return read;
-}
-#endif
-
-char *readArchivedFileText(char *buf, uint16 size) {
+char *Archive::readArchivedFileText(char *buf, uint16 size) {
if (_file == false)
error("readArchiveFileText: no archived file is currently open");
diff --git a/engines/parallaction/callables.cpp b/engines/parallaction/callables.cpp
index e6e10a02f2..52cdccaec6 100644
--- a/engines/parallaction/callables.cpp
+++ b/engines/parallaction/callables.cpp
@@ -355,7 +355,7 @@ void _c_ridux(void *parm) {
void _c_testResult(void *parm) {
_vm->_graphics->swapBuffers();
_vm->parseLocation("common");
- closeArchive();
+ _vm->_archive.close();
_vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font);
_vm->_graphics->_proportionalFont = false;
diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp
index c6e4608d31..7fc936fa7a 100644
--- a/engines/parallaction/dialogue.cpp
+++ b/engines/parallaction/dialogue.cpp
@@ -526,9 +526,9 @@ void runDialogue(SpeakData *data) {
if (!scumm_stricmp(_location, "museum")) {
- closeArchive();
+ _vm->_archive.close();
strcpy(_vm->_disk, "disk1");
- openArchive(_vm->_disk);
+ _vm->_archive.open(_vm->_disk);
_vm->_graphics->loadCnv("dino", &_tempFrames);
memcpy(&_yourself._cnv, &_tempFrames, sizeof(Cnv));
diff --git a/engines/parallaction/disk.h b/engines/parallaction/disk.h
index 3b61cd31d1..45663198a1 100644
--- a/engines/parallaction/disk.h
+++ b/engines/parallaction/disk.h
@@ -24,6 +24,7 @@
#define PARALLACTION_DISK_H
#include "parallaction/defs.h"
+#include "common/file.h"
namespace Parallaction {
@@ -31,17 +32,47 @@ namespace Parallaction {
// ARCHIVE MANAGEMENT
//------------------------------------------------------
-void openArchive(const char *file);
-void closeArchive();
-bool openArchivedFile(const char *name);
-void closeArchivedFile();
+#define MAX_ARCHIVE_ENTRIES 384
-uint16 getArchivedFileLength(const char *name);
+#define DIRECTORY_OFFSET_IN_FILE 0x4000
-int16 readArchivedFile(void *buffer, uint16 size);
-char *readArchivedFileText(char *buf, uint16 size);
+class Archive {
+protected:
+
+ bool _file;
+ uint16 _fileIndex;
+ uint32 _fileOffset;
+ uint32 _fileCursor;
+ uint32 _fileEndOffset;
+
+ char _archiveDir[MAX_ARCHIVE_ENTRIES][32];
+ uint32 _archiveLenghts[MAX_ARCHIVE_ENTRIES];
+ uint32 _archiveOffsets[MAX_ARCHIVE_ENTRIES];
+
+ Common::File _archive;
+
+public:
+ Archive() {
+ _file = false;
+ _fileIndex = 0;
+ _fileOffset = 0;
+ _fileCursor = 0;
+ _fileEndOffset = 0;
+ }
+
+ void open(const char *file);
+ void close();
+
+ bool openArchivedFile(const char *name);
+ void closeArchivedFile();
+
+ uint16 getArchivedFileLength(const char *name);
+
+ 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 b00a025fe5..4404ee1896 100644
--- a/engines/parallaction/graphics.cpp
+++ b/engines/parallaction/graphics.cpp
@@ -1020,29 +1020,29 @@ void Graphics::loadStaticCnv(const char *filename, StaticCnv *cnv) {
char path[PATH_LEN];
strcpy(path, filename);
- if (!openArchivedFile(path)) {
+ if (!_vm->_archive.openArchivedFile(path)) {
sprintf(path, "%s.pp", filename);
- if (!openArchivedFile(path))
+ if (!_vm->_archive.openArchivedFile(path))
errorFileNotFound(path);
}
cnv->_width = cnv->_height = 0;
byte unk;
- readArchivedFile(&unk, 1);
- readArchivedFile(&unk, 1);
+ _vm->_archive.readArchivedFile(&unk, 1);
+ _vm->_archive.readArchivedFile(&unk, 1);
cnv->_width = unk;
- readArchivedFile(&unk, 1);
+ _vm->_archive.readArchivedFile(&unk, 1);
cnv->_height = unk;
- uint16 compressedsize = getArchivedFileLength(path) - 3;
+ uint16 compressedsize = _vm->_archive.getArchivedFileLength(path) - 3;
byte *compressed = (byte*)memAlloc(compressedsize);
uint16 size = cnv->_width*cnv->_height;
cnv->_data0 = (byte*)memAlloc(size);
- readArchivedFile(compressed, compressedsize);
- closeArchivedFile();
+ _vm->_archive.readArchivedFile(compressed, compressedsize);
+ _vm->_archive.closeArchivedFile();
decompressChunk(compressed, cnv->_data0, size);
memFree(compressed);
@@ -1059,9 +1059,9 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) {
char path[PATH_LEN];
strcpy(path, filename);
- if (!openArchivedFile(path)) {
+ if (!_vm->_archive.openArchivedFile(path)) {
sprintf(path, "%s.pp", filename);
- if (!openArchivedFile(path))
+ if (!_vm->_archive.openArchivedFile(path))
errorFileNotFound(path);
}
@@ -1069,21 +1069,21 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) {
byte unk;
- readArchivedFile(&unk, 1);
+ _vm->_archive.readArchivedFile(&unk, 1);
cnv->_count = unk;
- readArchivedFile(&unk, 1);
+ _vm->_archive.readArchivedFile(&unk, 1);
cnv->_width = unk;
- readArchivedFile(&unk, 1);
+ _vm->_archive.readArchivedFile(&unk, 1);
cnv->_height = unk;
uint16 framesize = cnv->_width*cnv->_height;
cnv->_array = (byte**)memAlloc(cnv->_count * sizeof(byte*));
- uint32 size = getArchivedFileLength(path) - 3;
+ uint32 size = _vm->_archive.getArchivedFileLength(path) - 3;
byte *buf = (byte*)memAlloc(size);
- readArchivedFile(buf, size);
+ _vm->_archive.readArchivedFile(buf, size);
byte *s = buf;
@@ -1096,7 +1096,7 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) {
s += read;
}
- closeArchivedFile();
+ _vm->_archive.closeArchivedFile();
memFree(buf);
@@ -1165,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);
- if (!openArchivedFile(filename))
+ if (!_vm->_archive.openArchivedFile(filename))
errorFileNotFound(filename);
// byte palette[PALETTE_SIZE];
byte v150[4];
- readArchivedFile(_palette, PALETTE_SIZE);
- readArchivedFile(&v150, 4);
+ _vm->_archive.readArchivedFile(_palette, PALETTE_SIZE);
+ _vm->_archive.readArchivedFile(&v150, 4);
byte tempfx[sizeof(PaletteFxRange)*6];
- readArchivedFile(&tempfx, sizeof(PaletteFxRange)*6);
+ _vm->_archive.readArchivedFile(&tempfx, sizeof(PaletteFxRange)*6);
// setPalette(palette);
@@ -1205,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(v4, SCREEN_SIZE);
+ _vm->_archive.readArchivedFile(v4, SCREEN_SIZE);
byte v144[SCREEN_WIDTH];
@@ -1216,7 +1216,7 @@ void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) {
}
memFree(v4);
- closeArchivedFile();
+ _vm->_archive.closeArchivedFile();
return;
}
@@ -1229,17 +1229,17 @@ void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) {
//
void Graphics::loadMaskAndPath(const char *filename) {
- if (!openArchivedFile(filename))
+ if (!_vm->_archive.openArchivedFile(filename))
errorFileNotFound(filename);
byte v4[4];
- readArchivedFile(v4, 4);
- readArchivedFile(_buffers[kPath0], SCREENPATH_WIDTH*SCREEN_HEIGHT);
- readArchivedFile(_buffers[kMask0], SCREENMASK_WIDTH*SCREEN_HEIGHT);
+ _vm->_archive.readArchivedFile(v4, 4);
+ _vm->_archive.readArchivedFile(_buffers[kPath0], SCREENPATH_WIDTH*SCREEN_HEIGHT);
+ _vm->_archive.readArchivedFile(_buffers[kMask0], SCREENMASK_WIDTH*SCREEN_HEIGHT);
for (uint16 _si = 0; _si < 4; _si++) _bgLayers[_si] = v4[_si];
- closeArchivedFile();
+ _vm->_archive.closeArchivedFile();
return;
}
diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp
index 81167ef158..f767b49fe6 100644
--- a/engines/parallaction/location.cpp
+++ b/engines/parallaction/location.cpp
@@ -61,26 +61,26 @@ void Parallaction::parseLocation(const char *filename) {
strcat(archivefile, filename);
strcat(archivefile, ".loc");
- if (strcmp(_disk, "null")) closeArchive();
+ if (strcmp(_disk, "null")) _archive.close();
_languageDir[2] = '\0';
- openArchive(_languageDir);
+ _archive.open(_languageDir);
_languageDir[2] = '/';
- if (!openArchivedFile(archivefile)) {
+ if (!_archive.openArchivedFile(archivefile)) {
sprintf(archivefile, "%s%s.loc", _languageDir, filename);
- if (!openArchivedFile(archivefile))
+ if (!_archive.openArchivedFile(archivefile))
errorFileNotFound(filename);
}
- uint32 count = getArchivedFileLength(archivefile);
+ uint32 count = _archive.getArchivedFileLength(archivefile);
location_src = (char*)memAlloc(0x4000);
_locationScript = new Script(location_src);
- readArchivedFile(location_src, count);
- closeArchivedFile();
- closeArchive();
+ _archive.readArchivedFile(location_src, count);
+ _archive.closeArchivedFile();
+ _archive.close();
fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDLOCATION")) {
@@ -134,7 +134,7 @@ void Parallaction::parseLocation(const char *filename) {
if (!scumm_stricmp(_tokens[0], "DISK")) {
strcpy(_disk, _tokens[1]);
strcpy(archivefile, _disk);
- openArchive(archivefile);
+ _archive.open(archivefile);
}
if (!scumm_stricmp(_tokens[0], "LOCALFLAGS")) {
_si = 1; // _localFlagNames[0] = 'visited'
diff --git a/engines/parallaction/menu.cpp b/engines/parallaction/menu.cpp
index 9fd6db583a..37024392bd 100644
--- a/engines/parallaction/menu.cpp
+++ b/engines/parallaction/menu.cpp
@@ -101,7 +101,7 @@ Menu::~Menu() {
void Menu::start() {
- openArchive("disk1");
+ _vm->_archive.open("disk1");
_vm->_graphics->_proportionalFont = false;
_vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font);
@@ -157,7 +157,7 @@ void Menu::start() {
newGame();
}
- closeArchive();
+ _vm->_archive.close();
return;
}
@@ -197,7 +197,7 @@ void Menu::newGame() {
return; // show intro
_vm->_graphics->freeCnv(&Graphics::_font);
- closeArchive();
+ _vm->_archive.close();
selectCharacter();
@@ -286,7 +286,7 @@ uint16 Menu::selectGame() {
strcpy(_engine->_characterName, "dough");
_vm->loadGame();
- closeArchive();
+ _vm->_archive.close();
return 1; // load game
}
@@ -317,7 +317,7 @@ void Menu::selectCharacter() {
_vm->_graphics->_proportionalFont = false;
_vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font);
- openArchive("disk1");
+ _vm->_archive.open("disk1");
_vm->_graphics->loadBackground("password.slide", Graphics::kBitBack);
_vm->_graphics->copyScreen(Graphics::kBitBack, Graphics::kBit2);
@@ -413,7 +413,7 @@ void Menu::selectCharacter() {
_vm->_graphics->setPalette(palette);
_engineFlags |= kEngineChangeLocation;
- closeArchive();
+ _vm->_archive.close();
memFree(v14._data0);
_vm->_graphics->freeCnv(&Graphics::_font);
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp
index 2f60f604c9..af37c4915d 100644
--- a/engines/parallaction/parallaction.cpp
+++ b/engines/parallaction/parallaction.cpp
@@ -850,10 +850,10 @@ void Parallaction::changeCharacter(const char *name) {
freeCharacterFrames();
}
- closeArchive();
+ _archive.close();
strcpy(_disk, "disk1");
- openArchive("disk1");
+ _archive.open("disk1");
char path[PATH_LEN];
strcpy(path, v32);
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 6ea8c56955..840a252053 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -27,6 +27,7 @@
#include "parallaction/defs.h"
#include "parallaction/inventory.h"
#include "parallaction/parser.h"
+#include "parallaction/disk.h"
#include "common/str.h"
#include "gui/dialog.h"
#include "gui/widget.h"
@@ -273,6 +274,8 @@ public:
Script *_locationScript;
+ Archive _archive;
+
protected: // data
struct InputData {
diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp
index 36b49e9580..66694723f0 100644
--- a/engines/parallaction/saveload.cpp
+++ b/engines/parallaction/saveload.cpp
@@ -134,7 +134,7 @@ void Parallaction::doLoadGame(uint16 slot) {
refreshInventory(_vm->_characterName);
parseLocation("common");
- closeArchive();
+ _archive.close();
strcat(_location, _vm->_characterName);
_engineFlags |= kEngineChangeLocation;