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:
parent
0c77177ef1
commit
cacff9a9f2
11 changed files with 101 additions and 115 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define PARALLACTION_DISK_H
|
||||
|
||||
#include "parallaction/defs.h"
|
||||
#include "common/file.h"
|
||||
|
||||
namespace Parallaction {
|
||||
|
||||
|
@ -31,8 +32,38 @@ namespace Parallaction {
|
|||
// ARCHIVE MANAGEMENT
|
||||
//------------------------------------------------------
|
||||
|
||||
void openArchive(const char *file);
|
||||
void closeArchive();
|
||||
|
||||
#define MAX_ARCHIVE_ENTRIES 384
|
||||
|
||||
#define DIRECTORY_OFFSET_IN_FILE 0x4000
|
||||
|
||||
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();
|
||||
|
@ -41,7 +72,7 @@ uint16 getArchivedFileLength(const char *name);
|
|||
|
||||
int16 readArchivedFile(void *buffer, uint16 size);
|
||||
char *readArchivedFileText(char *buf, uint16 size);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -134,7 +134,7 @@ void Parallaction::doLoadGame(uint16 slot) {
|
|||
refreshInventory(_vm->_characterName);
|
||||
|
||||
parseLocation("common");
|
||||
closeArchive();
|
||||
_archive.close();
|
||||
|
||||
strcat(_location, _vm->_characterName);
|
||||
_engineFlags |= kEngineChangeLocation;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue