From e6337d11aa74322dc6e362ede199a9f4c4ebc5cf Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Fri, 7 Nov 2008 15:35:18 +0000 Subject: * completed transition to Common::Archive for Nippon Safes. * removed lots of old Archive swap magic svn-id: r34931 --- engines/parallaction/callables_ns.cpp | 1 - engines/parallaction/disk.h | 43 +++------- engines/parallaction/disk_ns.cpp | 142 ++++++++++++++++++------------- engines/parallaction/gui_ns.cpp | 4 - engines/parallaction/parallaction.cpp | 2 - engines/parallaction/parallaction_ns.cpp | 11 +-- 6 files changed, 95 insertions(+), 108 deletions(-) (limited to 'engines') diff --git a/engines/parallaction/callables_ns.cpp b/engines/parallaction/callables_ns.cpp index 7915daa0b8..45dd597104 100644 --- a/engines/parallaction/callables_ns.cpp +++ b/engines/parallaction/callables_ns.cpp @@ -371,7 +371,6 @@ void Parallaction_ns::_c_testResult(void *parm) { _gfx->freeLabels(); _gfx->updateScreen(); - _disk->selectArchive("disk1"); parseLocation("common"); uint id[2]; diff --git a/engines/parallaction/disk.h b/engines/parallaction/disk.h index 20cb03f025..108c5fe886 100644 --- a/engines/parallaction/disk.h +++ b/engines/parallaction/disk.h @@ -77,48 +77,23 @@ public: virtual void loadMask(const char *name, MaskBuffer &buffer) { } }; - - - -#define MAX_ARCHIVE_ENTRIES 384 - -class NSArchive : public Common::Archive { - - Common::SeekableReadStream *_stream; - - char _archiveDir[MAX_ARCHIVE_ENTRIES][32]; - uint32 _archiveLenghts[MAX_ARCHIVE_ENTRIES]; - uint32 _archiveOffsets[MAX_ARCHIVE_ENTRIES]; - uint32 _numFiles; - - uint32 lookup(const char *name); - -public: - NSArchive(Common::SeekableReadStream *stream, Common::Platform platform, uint32 features); - ~NSArchive(); - - Common::SeekableReadStream *openFile(const Common::String &name); - bool hasFile(const Common::String &name); - int listMembers(Common::ArchiveMemberList &list); - Common::ArchiveMemberPtr getMember(const Common::String &name); -}; +class NSArchive; class Disk_ns : public Disk { protected: Parallaction *_vm; - NSArchive *_resArchive; - NSArchive *_locArchive; + Common::SearchSet _sset; Common::String _resArchiveName; Common::String _language; Common::SeekableReadStream *openFile(const char *filename); - Common::SeekableReadStream *tryOpenFile(const char *filename); - virtual Common::SeekableReadStream *tryOpenExternalFile(const char *filename); - virtual Common::SeekableReadStream *tryOpenArchivedFile(const char* name) { return 0; } + virtual Common::SeekableReadStream *tryOpenFile(const char *filename) { return 0; } void errorFileNotFound(const char *filename); + void addArchive(const Common::String& name, int priority); + public: Disk_ns(Parallaction *vm); virtual ~Disk_ns(); @@ -141,12 +116,14 @@ private: protected: Gfx *_gfx; - virtual Common::SeekableReadStream *tryOpenArchivedFile(const char* name); + virtual Common::SeekableReadStream *tryOpenFile(const char* name); public: DosDisk_ns(Parallaction *vm); virtual ~DosDisk_ns(); + void init(); + Script* loadLocation(const char *name); Script* loadScript(const char* name); GfxObj* loadTalk(const char *name); @@ -170,7 +147,7 @@ protected: void patchFrame(byte *dst, byte *dlta, uint16 bytesPerPlane, uint16 height); void unpackFrame(byte *dst, byte *src, uint16 planeSize); void unpackBitmap(byte *dst, byte *src, uint16 numFrames, uint16 bytesPerPlane, uint16 height); - Common::SeekableReadStream *tryOpenArchivedFile(const char* name); + Common::SeekableReadStream *tryOpenFile(const char* name); Font *createFont(const char *name, Common::SeekableReadStream &stream); void loadMask(BackgroundInfo& info, const char *name); void loadPath(BackgroundInfo& info, const char *name); @@ -180,6 +157,8 @@ public: AmigaDisk_ns(Parallaction *vm); virtual ~AmigaDisk_ns(); + void init(); + Script* loadLocation(const char *name); Script* loadScript(const char* name); GfxObj* loadTalk(const char *name); diff --git a/engines/parallaction/disk_ns.cpp b/engines/parallaction/disk_ns.cpp index 80e8a9da6d..bd6c151cf1 100644 --- a/engines/parallaction/disk_ns.cpp +++ b/engines/parallaction/disk_ns.cpp @@ -24,6 +24,7 @@ */ #include "graphics/iff.h" +#include "common/config-manager.h" #include "parallaction/parallaction.h" @@ -60,6 +61,30 @@ namespace Parallaction { #define NORMAL_ARCHIVE_DATA_OFS 0x4000 #define SMALL_ARCHIVE_DATA_OFS 0x1966 +#define MAX_ARCHIVE_ENTRIES 384 + +class NSArchive : public Common::Archive { + + Common::SeekableReadStream *_stream; + + char _archiveDir[MAX_ARCHIVE_ENTRIES][32]; + uint32 _archiveLenghts[MAX_ARCHIVE_ENTRIES]; + uint32 _archiveOffsets[MAX_ARCHIVE_ENTRIES]; + uint32 _numFiles; + + uint32 lookup(const char *name); + +public: + NSArchive(Common::SeekableReadStream *stream, Common::Platform platform, uint32 features); + ~NSArchive(); + + Common::SeekableReadStream *openFile(const Common::String &name); + bool hasFile(const Common::String &name); + int listMembers(Common::ArchiveMemberList &list); + Common::ArchiveMemberPtr getMember(const Common::String &name); +}; + + NSArchive::NSArchive(Common::SeekableReadStream *stream, Common::Platform platform, uint32 features) : _stream(stream) { if (!_stream) { error("NSArchive: invalid stream passed to constructor"); @@ -143,16 +168,18 @@ Common::ArchiveMemberPtr NSArchive::getMember(const Common::String &name) { } +#define HIGHEST_PRIORITY 9 +#define NORMAL_ARCHIVE_PRIORITY 5 +#define LOW_ARCHIVE_PRIORITY 2 +#define LOWEST_ARCHIVE_PRIORITY 1 - -Disk_ns::Disk_ns(Parallaction *vm) : _vm(vm), _language("ur") { - _locArchive = 0; - _resArchive = 0; +Disk_ns::Disk_ns(Parallaction *vm) : _vm(vm) { + Common::FSDirectory *baseDir = new Common::FSDirectory(ConfMan.get("path")); + _sset.add("basedir", baseDir, HIGHEST_PRIORITY); } Disk_ns::~Disk_ns() { - delete _resArchive; - delete _locArchive; + _sset.clear(); } void Disk_ns::errorFileNotFound(const char *s) { @@ -166,33 +193,31 @@ Common::SeekableReadStream *Disk_ns::openFile(const char *filename) { return stream; } -Common::SeekableReadStream *Disk_ns::tryOpenFile(const char *filename) { - Common::SeekableReadStream *stream = tryOpenExternalFile(filename); - if (stream) - return stream; - return tryOpenArchivedFile(filename); -} -Common::SeekableReadStream *Disk_ns::tryOpenExternalFile(const char *filename) { - assert(filename); - Common::File *stream = new Common::File; - if (!stream->open(filename)) { - delete stream; - stream = 0; - } - return stream; +void Disk_ns::addArchive(const Common::String& name, int priority) { + Common::SeekableReadStream *stream = _sset.openFile(name); + if (!stream) + error("Disk_ns::addArchive() couldn't find archive '%s'", name.c_str()); + + debugC(1, kDebugDisk, "Disk_ns::addArchive(name = %s, priority = %i)", name.c_str(), priority); + + NSArchive *arc = new NSArchive(stream, _vm->getPlatform(), _vm->getFeatures()); + _sset.add(name, arc, priority); } Common::String Disk_ns::selectArchive(const Common::String& name) { - if (name.compareToIgnoreCase(_resArchiveName) == 0) { - return _resArchiveName; + Common::String oldName = _resArchiveName; + + if (_sset.hasArchive(name)) { + return oldName; } - debugC(1, kDebugDisk, "Disk_ns::selectArchive(%s)", name.c_str()); + if (!_resArchiveName.empty()) { + _sset.remove(_resArchiveName); + } + _resArchiveName = name; + addArchive(name, LOW_ARCHIVE_PRIORITY); - Common::String oldName = _resArchiveName; - delete _resArchive; - _resArchive = new NSArchive(tryOpenExternalFile(name.c_str()), _vm->getPlatform(), _vm->getFeatures()); return oldName; } @@ -200,21 +225,23 @@ void Disk_ns::setLanguage(uint16 language) { debugC(1, kDebugDisk, "setLanguage(%i)", language); assert(language < 4); + if (!_language.empty()) { + _sset.remove(_language); + } + static const char *languages[] = { "it", "fr", "en", "ge" }; + _language = languages[language]; - if (_language.compareToIgnoreCase(languages[language]) == 0) { + if (_sset.hasArchive(_language)) { return; } - _language = languages[language]; - delete _locArchive; - _locArchive = new NSArchive(tryOpenExternalFile(_language.c_str()), _vm->getPlatform(), _vm->getFeatures()); + addArchive(_language, LOWEST_ARCHIVE_PRIORITY); } #pragma mark - - DosDisk_ns::DosDisk_ns(Parallaction* vm) : Disk_ns(vm) { } @@ -222,27 +249,21 @@ DosDisk_ns::DosDisk_ns(Parallaction* vm) : Disk_ns(vm) { DosDisk_ns::~DosDisk_ns() { } +void DosDisk_ns::init() { + // setup permament archives + addArchive("disk1", NORMAL_ARCHIVE_PRIORITY); +} -Common::SeekableReadStream *DosDisk_ns::tryOpenArchivedFile(const char* name) { - debugC(3, kDebugDisk, "DosDisk_ns::openArchivedFile(%s)", name); - - NSArchive *arc = 0; - - Common::String filename(name); - if (filename.hasSuffix(".loc")) { - arc = _locArchive; - } else { - arc = _resArchive; - } +Common::SeekableReadStream *DosDisk_ns::tryOpenFile(const char* name) { + debugC(3, kDebugDisk, "DosDisk_ns::tryOpenFile(%s)", name); - Common::SeekableReadStream *stream = arc->openFile(name); - if (stream) { + Common::SeekableReadStream *stream = _sset.openFile(name); + if (stream) return stream; - } char path[PATH_LEN]; sprintf(path, "%s.pp", name); - return arc->openFile(path); + return _sset.openFile(path); } @@ -685,6 +706,16 @@ AmigaDisk_ns::~AmigaDisk_ns() { } +void AmigaDisk_ns::init() { + // setup permament archives + if (_vm->getFeatures() & GF_DEMO) { + addArchive("disk0", NORMAL_ARCHIVE_PRIORITY); + } else { + addArchive("disk0", NORMAL_ARCHIVE_PRIORITY); + addArchive("disk1", NORMAL_ARCHIVE_PRIORITY); + } +} + #define NUM_PLANES 5 /* @@ -854,30 +885,21 @@ GfxObj* AmigaDisk_ns::loadStatic(const char* name) { return new GfxObj(0, makeCnv(s, true), name); } -Common::SeekableReadStream *AmigaDisk_ns::tryOpenArchivedFile(const char* name) { - debugC(3, kDebugDisk, "AmigaDisk_ns::openArchivedFile(%s)", name); - - NSArchive *arc = 0; - - Common::String filename(name); - if (filename.hasSuffix(".loc")) { - arc = _locArchive; - } else { - arc = _resArchive; - } +Common::SeekableReadStream *AmigaDisk_ns::tryOpenFile(const char* name) { + debugC(3, kDebugDisk, "AmigaDisk_ns::tryOpenFile(%s)", name); - Common::SeekableReadStream *stream = arc->openFile(name); + Common::SeekableReadStream *stream = _sset.openFile(name); if (stream) return stream; char path[PATH_LEN]; sprintf(path, "%s.pp", name); - stream = arc->openFile(path); + stream = _sset.openFile(path); if (stream) return new PowerPackerStream(*stream); sprintf(path, "%s.dd", name); - stream = arc->openFile(path); + stream = _sset.openFile(path); if (stream) return new PowerPackerStream(*stream); diff --git a/engines/parallaction/gui_ns.cpp b/engines/parallaction/gui_ns.cpp index 73cc1be12e..9ea11fa200 100644 --- a/engines/parallaction/gui_ns.cpp +++ b/engines/parallaction/gui_ns.cpp @@ -319,7 +319,6 @@ public: } virtual void enter() { - _vm->_disk->selectArchive("disk1"); _vm->setBackground("test", NULL, NULL); _vm->_input->setMouseState(MOUSE_ENABLED_HIDE); @@ -544,7 +543,6 @@ public: virtual void enter() { _vm->_soundMan->stopMusic(); - _vm->_disk->selectArchive((_vm->getFeatures() & GF_DEMO) ? "disk0" : "disk1"); _vm->showSlide("password"); _emptySlots.create(BLOCK_WIDTH * 8, BLOCK_HEIGHT, 1); @@ -798,8 +796,6 @@ const char *EndPartInputState_NS::endMsg6[] = {"DELL' AVVENTURA", "DE L'AVENTURE const char *EndPartInputState_NS::endMsg7[] = {"ED ORA IL GRAN FINALE ", "ET MAINTENANT LE GRAND FINAL", "NOW THE GREAT FINAL", "UND YETZT DER GROSSE SCHLUSS!"}; void Parallaction_ns::startGui() { - _disk->selectArchive((getFeatures() & GF_DEMO) ? "disk0" : "disk1"); - _menuHelper = new MenuInputHelper; assert(_menuHelper); diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index 5abc308bee..4810c4af67 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -66,8 +66,6 @@ Parallaction::Parallaction(OSystem *syst, const PARALLACTIONGameDescription *gam // FIXME _vm = this; - Common::File::addDefaultDirectory(_gameDataDir); - Common::addSpecialDebugLevel(kDebugDialogue, "dialogue", "Dialogues debug level"); Common::addSpecialDebugLevel(kDebugParser, "parser", "Parser debug level"); Common::addSpecialDebugLevel(kDebugDisk, "disk", "Disk debug level"); diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index efb5f94b84..90820a6f8f 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -155,9 +155,10 @@ Common::Error Parallaction_ns::init() { strcpy(_location._name, "fognedemo"); } _disk = new AmigaDisk_ns(this); - _disk->selectArchive((getFeatures() & GF_DEMO) ? "disk0" : "disk1"); } + _disk->init(); + if (getPlatform() == Common::kPlatformPC) { int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI); MidiDriver *driver = MidiDriver::createMidi(midiDriver); @@ -394,16 +395,11 @@ void Parallaction_ns::changeCharacter(const char *name) { // character for sanity before memory is freed freeCharacter(); - Common::String oldArchive = _disk->selectArchive((getFeatures() & GF_DEMO) ? "disk0" : "disk1"); _char._ani->gfxobj = _gfx->loadAnim(_char.getFullName()); _char._ani->gfxobj->setFlags(kGfxObjCharacter); _char._ani->gfxobj->clearFlags(kGfxObjNormal); if (!_char.dummy()) { - if (getPlatform() == Common::kPlatformAmiga) { - _disk->selectArchive("disk0"); - } - _char._head = _disk->loadHead(_char.getBaseName()); _char._talk = _disk->loadTalk(_char.getBaseName()); _char._objs = _disk->loadObjects(_char.getBaseName()); @@ -420,9 +416,6 @@ void Parallaction_ns::changeCharacter(const char *name) { parseLocation("common"); } - if (!oldArchive.empty()) - _disk->selectArchive(oldArchive); - strcpy(_characterName1, _char.getFullName()); debugC(3, kDebugExec, "changeCharacter: switch completed"); -- cgit v1.2.3