wrapped archive routines into a new class named Archive. File-level static variables have been made members of the new class.

svn-id: r25866
This commit is contained in:
Nicola Mettifogo 2007-02-25 20:35:47 +00:00
parent 0c77177ef1
commit cacff9a9f2
11 changed files with 101 additions and 115 deletions

View file

@ -256,16 +256,16 @@ void Parallaction::loadProgram(Animation *a, char *filename) {
sprintf(vC8, "%s.script", filename); sprintf(vC8, "%s.script", filename);
if (!openArchivedFile(vC8)) if (!_archive.openArchivedFile(vC8))
errorFileNotFound(vC8); errorFileNotFound(vC8);
uint32 size = getArchivedFileLength(vC8); uint32 size = _archive.getArchivedFileLength(vC8);
char* src = (char*)memAlloc(size+1); char* src = (char*)memAlloc(size+1);
readArchivedFile(src, size); _archive.readArchivedFile(src, size);
src[size] = '\0'; src[size] = '\0';
closeArchivedFile(); _archive.closeArchivedFile();
_numLocals = 0; _numLocals = 0;

View file

@ -27,41 +27,12 @@
namespace Parallaction { 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 void Archive::open(const char *file) {
#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) {
debugC(1, kDebugDisk, "open archive '%s'", file); debugC(1, kDebugDisk, "open archive '%s'", file);
#ifdef PALMOS_ARM
if (!_archiveP)
_archiveP = new Common::File();
#endif
if (_archive.isOpen()) if (_archive.isOpen())
closeArchive(); close();
uint32 offset = DIRECTORY_OFFSET_IN_FILE; uint32 offset = DIRECTORY_OFFSET_IN_FILE;
char path[PATH_LEN]; char path[PATH_LEN];
@ -91,8 +62,7 @@ void openArchive(const char *file) {
} }
void Archive::close() {
void closeArchive() {
debugC(1, kDebugDisk, "close current archive"); debugC(1, kDebugDisk, "close current archive");
if (!_archive.isOpen()) return; if (!_archive.isOpen()) return;
@ -101,7 +71,7 @@ void closeArchive() {
} }
bool openArchivedFile(const char *name) { bool Archive::openArchivedFile(const char *name) {
uint16 i = 0; uint16 i = 0;
for ( ; i < MAX_ARCHIVE_ENTRIES; i++) { for ( ; i < MAX_ARCHIVE_ENTRIES; i++) {
@ -124,8 +94,7 @@ bool openArchivedFile(const char *name) {
} }
void Archive::closeArchivedFile() {
void closeArchivedFile() {
_file = false; _file = false;
_fileIndex = 0; _fileIndex = 0;
_fileCursor = 0; _fileCursor = 0;
@ -135,9 +104,7 @@ void closeArchivedFile() {
} }
uint16 Archive::getArchivedFileLength(const char *name) {
uint16 getArchivedFileLength(const char *name) {
// printf("getArchivedFileLength(%s)\n", name); // printf("getArchivedFileLength(%s)\n", name);
for (uint16 i = 0; i < MAX_ARCHIVE_ENTRIES; i++) { for (uint16 i = 0; i < MAX_ARCHIVE_ENTRIES; i++) {
@ -149,8 +116,7 @@ uint16 getArchivedFileLength(const char *name) {
} }
int16 Archive::readArchivedFile(void *buffer, uint16 size) {
int16 readArchivedFile(void *buffer, uint16 size) {
// printf("readArchivedFile(%i, %i)\n", file->_cursor, file->_endOffset); // printf("readArchivedFile(%i, %i)\n", file->_cursor, file->_endOffset);
if (_file == false) if (_file == false)
error("readArchiveFile: no archived file is currently open"); error("readArchiveFile: no archived file is currently open");
@ -167,22 +133,8 @@ int16 readArchivedFile(void *buffer, uint16 size) {
return read; 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; char *Archive::readArchivedFileText(char *buf, uint16 size) {
_archive.seek(file->_cursor);
int16 read = _archive.read(buffer, size);
file->_cursor += read;
return read;
}
#endif
char *readArchivedFileText(char *buf, uint16 size) {
if (_file == false) if (_file == false)
error("readArchiveFileText: no archived file is currently open"); error("readArchiveFileText: no archived file is currently open");

View file

@ -355,7 +355,7 @@ void _c_ridux(void *parm) {
void _c_testResult(void *parm) { void _c_testResult(void *parm) {
_vm->_graphics->swapBuffers(); _vm->_graphics->swapBuffers();
_vm->parseLocation("common"); _vm->parseLocation("common");
closeArchive(); _vm->_archive.close();
_vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font); _vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font);
_vm->_graphics->_proportionalFont = false; _vm->_graphics->_proportionalFont = false;

View file

@ -526,9 +526,9 @@ void runDialogue(SpeakData *data) {
if (!scumm_stricmp(_location, "museum")) { if (!scumm_stricmp(_location, "museum")) {
closeArchive(); _vm->_archive.close();
strcpy(_vm->_disk, "disk1"); strcpy(_vm->_disk, "disk1");
openArchive(_vm->_disk); _vm->_archive.open(_vm->_disk);
_vm->_graphics->loadCnv("dino", &_tempFrames); _vm->_graphics->loadCnv("dino", &_tempFrames);
memcpy(&_yourself._cnv, &_tempFrames, sizeof(Cnv)); memcpy(&_yourself._cnv, &_tempFrames, sizeof(Cnv));

View file

@ -24,6 +24,7 @@
#define PARALLACTION_DISK_H #define PARALLACTION_DISK_H
#include "parallaction/defs.h" #include "parallaction/defs.h"
#include "common/file.h"
namespace Parallaction { namespace Parallaction {
@ -31,17 +32,47 @@ namespace Parallaction {
// ARCHIVE MANAGEMENT // ARCHIVE MANAGEMENT
//------------------------------------------------------ //------------------------------------------------------
void openArchive(const char *file);
void closeArchive();
bool openArchivedFile(const char *name); #define MAX_ARCHIVE_ENTRIES 384
void closeArchivedFile();
uint16 getArchivedFileLength(const char *name); #define DIRECTORY_OFFSET_IN_FILE 0x4000
int16 readArchivedFile(void *buffer, uint16 size); class Archive {
char *readArchivedFileText(char *buf, uint16 size);
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);
};

View file

@ -1020,29 +1020,29 @@ void Graphics::loadStaticCnv(const char *filename, StaticCnv *cnv) {
char path[PATH_LEN]; char path[PATH_LEN];
strcpy(path, filename); strcpy(path, filename);
if (!openArchivedFile(path)) { if (!_vm->_archive.openArchivedFile(path)) {
sprintf(path, "%s.pp", filename); sprintf(path, "%s.pp", filename);
if (!openArchivedFile(path)) if (!_vm->_archive.openArchivedFile(path))
errorFileNotFound(path); errorFileNotFound(path);
} }
cnv->_width = cnv->_height = 0; cnv->_width = cnv->_height = 0;
byte unk; byte unk;
readArchivedFile(&unk, 1); _vm->_archive.readArchivedFile(&unk, 1);
readArchivedFile(&unk, 1); _vm->_archive.readArchivedFile(&unk, 1);
cnv->_width = unk; cnv->_width = unk;
readArchivedFile(&unk, 1); _vm->_archive.readArchivedFile(&unk, 1);
cnv->_height = unk; cnv->_height = unk;
uint16 compressedsize = getArchivedFileLength(path) - 3; uint16 compressedsize = _vm->_archive.getArchivedFileLength(path) - 3;
byte *compressed = (byte*)memAlloc(compressedsize); byte *compressed = (byte*)memAlloc(compressedsize);
uint16 size = cnv->_width*cnv->_height; uint16 size = cnv->_width*cnv->_height;
cnv->_data0 = (byte*)memAlloc(size); cnv->_data0 = (byte*)memAlloc(size);
readArchivedFile(compressed, compressedsize); _vm->_archive.readArchivedFile(compressed, compressedsize);
closeArchivedFile(); _vm->_archive.closeArchivedFile();
decompressChunk(compressed, cnv->_data0, size); decompressChunk(compressed, cnv->_data0, size);
memFree(compressed); memFree(compressed);
@ -1059,9 +1059,9 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) {
char path[PATH_LEN]; char path[PATH_LEN];
strcpy(path, filename); strcpy(path, filename);
if (!openArchivedFile(path)) { if (!_vm->_archive.openArchivedFile(path)) {
sprintf(path, "%s.pp", filename); sprintf(path, "%s.pp", filename);
if (!openArchivedFile(path)) if (!_vm->_archive.openArchivedFile(path))
errorFileNotFound(path); errorFileNotFound(path);
} }
@ -1069,21 +1069,21 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) {
byte unk; byte unk;
readArchivedFile(&unk, 1); _vm->_archive.readArchivedFile(&unk, 1);
cnv->_count = unk; cnv->_count = unk;
readArchivedFile(&unk, 1); _vm->_archive.readArchivedFile(&unk, 1);
cnv->_width = unk; cnv->_width = unk;
readArchivedFile(&unk, 1); _vm->_archive.readArchivedFile(&unk, 1);
cnv->_height = unk; cnv->_height = unk;
uint16 framesize = cnv->_width*cnv->_height; uint16 framesize = cnv->_width*cnv->_height;
cnv->_array = (byte**)memAlloc(cnv->_count * sizeof(byte*)); 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); byte *buf = (byte*)memAlloc(size);
readArchivedFile(buf, size); _vm->_archive.readArchivedFile(buf, size);
byte *s = buf; byte *s = buf;
@ -1096,7 +1096,7 @@ void Graphics::loadCnv(const char *filename, Cnv *cnv) {
s += read; s += read;
} }
closeArchivedFile(); _vm->_archive.closeArchivedFile();
memFree(buf); 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) { void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) {
// printf("Graphics::loadBackground(%s)\n", filename); // printf("Graphics::loadBackground(%s)\n", filename);
if (!openArchivedFile(filename)) if (!_vm->_archive.openArchivedFile(filename))
errorFileNotFound(filename); errorFileNotFound(filename);
// byte palette[PALETTE_SIZE]; // byte palette[PALETTE_SIZE];
byte v150[4]; byte v150[4];
readArchivedFile(_palette, PALETTE_SIZE); _vm->_archive.readArchivedFile(_palette, PALETTE_SIZE);
readArchivedFile(&v150, 4); _vm->_archive.readArchivedFile(&v150, 4);
byte tempfx[sizeof(PaletteFxRange)*6]; byte tempfx[sizeof(PaletteFxRange)*6];
readArchivedFile(&tempfx, sizeof(PaletteFxRange)*6); _vm->_archive.readArchivedFile(&tempfx, sizeof(PaletteFxRange)*6);
// setPalette(palette); // setPalette(palette);
@ -1205,7 +1205,7 @@ void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) {
memset(_buffers[kMask0], 0, SCREENMASK_WIDTH*SCREEN_HEIGHT); memset(_buffers[kMask0], 0, SCREENMASK_WIDTH*SCREEN_HEIGHT);
byte *v4 = (byte*)memAlloc(SCREEN_SIZE); byte *v4 = (byte*)memAlloc(SCREEN_SIZE);
readArchivedFile(v4, SCREEN_SIZE); _vm->_archive.readArchivedFile(v4, SCREEN_SIZE);
byte v144[SCREEN_WIDTH]; byte v144[SCREEN_WIDTH];
@ -1216,7 +1216,7 @@ void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) {
} }
memFree(v4); memFree(v4);
closeArchivedFile(); _vm->_archive.closeArchivedFile();
return; return;
} }
@ -1229,17 +1229,17 @@ void Graphics::loadBackground(const char *filename, Graphics::Buffers buffer) {
// //
void Graphics::loadMaskAndPath(const char *filename) { void Graphics::loadMaskAndPath(const char *filename) {
if (!openArchivedFile(filename)) if (!_vm->_archive.openArchivedFile(filename))
errorFileNotFound(filename); errorFileNotFound(filename);
byte v4[4]; byte v4[4];
readArchivedFile(v4, 4); _vm->_archive.readArchivedFile(v4, 4);
readArchivedFile(_buffers[kPath0], SCREENPATH_WIDTH*SCREEN_HEIGHT); _vm->_archive.readArchivedFile(_buffers[kPath0], SCREENPATH_WIDTH*SCREEN_HEIGHT);
readArchivedFile(_buffers[kMask0], SCREENMASK_WIDTH*SCREEN_HEIGHT); _vm->_archive.readArchivedFile(_buffers[kMask0], SCREENMASK_WIDTH*SCREEN_HEIGHT);
for (uint16 _si = 0; _si < 4; _si++) _bgLayers[_si] = v4[_si]; for (uint16 _si = 0; _si < 4; _si++) _bgLayers[_si] = v4[_si];
closeArchivedFile(); _vm->_archive.closeArchivedFile();
return; return;
} }

View file

@ -61,26 +61,26 @@ void Parallaction::parseLocation(const char *filename) {
strcat(archivefile, filename); strcat(archivefile, filename);
strcat(archivefile, ".loc"); strcat(archivefile, ".loc");
if (strcmp(_disk, "null")) closeArchive(); if (strcmp(_disk, "null")) _archive.close();
_languageDir[2] = '\0'; _languageDir[2] = '\0';
openArchive(_languageDir); _archive.open(_languageDir);
_languageDir[2] = '/'; _languageDir[2] = '/';
if (!openArchivedFile(archivefile)) { if (!_archive.openArchivedFile(archivefile)) {
sprintf(archivefile, "%s%s.loc", _languageDir, filename); sprintf(archivefile, "%s%s.loc", _languageDir, filename);
if (!openArchivedFile(archivefile)) if (!_archive.openArchivedFile(archivefile))
errorFileNotFound(filename); errorFileNotFound(filename);
} }
uint32 count = getArchivedFileLength(archivefile); uint32 count = _archive.getArchivedFileLength(archivefile);
location_src = (char*)memAlloc(0x4000); location_src = (char*)memAlloc(0x4000);
_locationScript = new Script(location_src); _locationScript = new Script(location_src);
readArchivedFile(location_src, count); _archive.readArchivedFile(location_src, count);
closeArchivedFile(); _archive.closeArchivedFile();
closeArchive(); _archive.close();
fillBuffers(*_locationScript, true); fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDLOCATION")) { while (scumm_stricmp(_tokens[0], "ENDLOCATION")) {
@ -134,7 +134,7 @@ void Parallaction::parseLocation(const char *filename) {
if (!scumm_stricmp(_tokens[0], "DISK")) { if (!scumm_stricmp(_tokens[0], "DISK")) {
strcpy(_disk, _tokens[1]); strcpy(_disk, _tokens[1]);
strcpy(archivefile, _disk); strcpy(archivefile, _disk);
openArchive(archivefile); _archive.open(archivefile);
} }
if (!scumm_stricmp(_tokens[0], "LOCALFLAGS")) { if (!scumm_stricmp(_tokens[0], "LOCALFLAGS")) {
_si = 1; // _localFlagNames[0] = 'visited' _si = 1; // _localFlagNames[0] = 'visited'

View file

@ -101,7 +101,7 @@ Menu::~Menu() {
void Menu::start() { void Menu::start() {
openArchive("disk1"); _vm->_archive.open("disk1");
_vm->_graphics->_proportionalFont = false; _vm->_graphics->_proportionalFont = false;
_vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font); _vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font);
@ -157,7 +157,7 @@ void Menu::start() {
newGame(); newGame();
} }
closeArchive(); _vm->_archive.close();
return; return;
} }
@ -197,7 +197,7 @@ void Menu::newGame() {
return; // show intro return; // show intro
_vm->_graphics->freeCnv(&Graphics::_font); _vm->_graphics->freeCnv(&Graphics::_font);
closeArchive(); _vm->_archive.close();
selectCharacter(); selectCharacter();
@ -286,7 +286,7 @@ uint16 Menu::selectGame() {
strcpy(_engine->_characterName, "dough"); strcpy(_engine->_characterName, "dough");
_vm->loadGame(); _vm->loadGame();
closeArchive(); _vm->_archive.close();
return 1; // load game return 1; // load game
} }
@ -317,7 +317,7 @@ void Menu::selectCharacter() {
_vm->_graphics->_proportionalFont = false; _vm->_graphics->_proportionalFont = false;
_vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font); _vm->_graphics->loadExternalCnv("slidecnv", &Graphics::_font);
openArchive("disk1"); _vm->_archive.open("disk1");
_vm->_graphics->loadBackground("password.slide", Graphics::kBitBack); _vm->_graphics->loadBackground("password.slide", Graphics::kBitBack);
_vm->_graphics->copyScreen(Graphics::kBitBack, Graphics::kBit2); _vm->_graphics->copyScreen(Graphics::kBitBack, Graphics::kBit2);
@ -413,7 +413,7 @@ void Menu::selectCharacter() {
_vm->_graphics->setPalette(palette); _vm->_graphics->setPalette(palette);
_engineFlags |= kEngineChangeLocation; _engineFlags |= kEngineChangeLocation;
closeArchive(); _vm->_archive.close();
memFree(v14._data0); memFree(v14._data0);
_vm->_graphics->freeCnv(&Graphics::_font); _vm->_graphics->freeCnv(&Graphics::_font);

View file

@ -850,10 +850,10 @@ void Parallaction::changeCharacter(const char *name) {
freeCharacterFrames(); freeCharacterFrames();
} }
closeArchive(); _archive.close();
strcpy(_disk, "disk1"); strcpy(_disk, "disk1");
openArchive("disk1"); _archive.open("disk1");
char path[PATH_LEN]; char path[PATH_LEN];
strcpy(path, v32); strcpy(path, v32);

View file

@ -27,6 +27,7 @@
#include "parallaction/defs.h" #include "parallaction/defs.h"
#include "parallaction/inventory.h" #include "parallaction/inventory.h"
#include "parallaction/parser.h" #include "parallaction/parser.h"
#include "parallaction/disk.h"
#include "common/str.h" #include "common/str.h"
#include "gui/dialog.h" #include "gui/dialog.h"
#include "gui/widget.h" #include "gui/widget.h"
@ -273,6 +274,8 @@ public:
Script *_locationScript; Script *_locationScript;
Archive _archive;
protected: // data protected: // data
struct InputData { struct InputData {

View file

@ -134,7 +134,7 @@ void Parallaction::doLoadGame(uint16 slot) {
refreshInventory(_vm->_characterName); refreshInventory(_vm->_characterName);
parseLocation("common"); parseLocation("common");
closeArchive(); _archive.close();
strcat(_location, _vm->_characterName); strcat(_location, _vm->_characterName);
_engineFlags |= kEngineChangeLocation; _engineFlags |= kEngineChangeLocation;