diff options
Diffstat (limited to 'engines/sword2')
-rw-r--r-- | engines/sword2/animation.cpp | 4 | ||||
-rw-r--r-- | engines/sword2/controls.cpp | 8 | ||||
-rw-r--r-- | engines/sword2/function.cpp | 2 | ||||
-rw-r--r-- | engines/sword2/palette.cpp | 2 | ||||
-rw-r--r-- | engines/sword2/resman.cpp | 4 | ||||
-rw-r--r-- | engines/sword2/screen.cpp | 10 | ||||
-rw-r--r-- | engines/sword2/sound.h | 2 | ||||
-rw-r--r-- | engines/sword2/startup.cpp | 18 | ||||
-rw-r--r-- | engines/sword2/sword2.cpp | 91 | ||||
-rw-r--r-- | engines/sword2/sword2.h | 3 |
10 files changed, 96 insertions, 48 deletions
diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp index 48196a2f7d..76f14851e7 100644 --- a/engines/sword2/animation.cpp +++ b/engines/sword2/animation.cpp @@ -357,8 +357,8 @@ bool MoviePlayer::userInterrupt() { case Common::EVENT_SCREEN_CHANGED: handleScreenChanged(); break; + case Common::EVENT_RTL: case Common::EVENT_QUIT: - _vm->closeGame(); terminate = true; break; case Common::EVENT_KEYDOWN: @@ -379,7 +379,7 @@ void MoviePlayer::play(SequenceTextInfo *textList, uint32 numLines, int32 leadIn bool startNextText = false; // This happens if the user quits during the "eye" cutscene. - if (_vm->_quit) + if (_vm->quit()) return; _numSpeechLines = numLines; diff --git a/engines/sword2/controls.cpp b/engines/sword2/controls.cpp index 6b466d6be0..dcacbc78d4 100644 --- a/engines/sword2/controls.cpp +++ b/engines/sword2/controls.cpp @@ -396,7 +396,7 @@ int Dialog::runModal() { _vm->_system->delayMillis(20); - if (_vm->_quit) + if (_vm->quit()) setResult(0); } @@ -842,7 +842,7 @@ int StartDialog::runModal() { if (startDialog.runModal()) return 1; - if (_vm->_quit) + if (_vm->quit()) return 0; RestoreDialog restoreDialog(_vm); @@ -850,7 +850,7 @@ int StartDialog::runModal() { if (restoreDialog.runModal()) return 0; - if (_vm->_quit) + if (_vm->quit()) return 0; } @@ -882,7 +882,7 @@ int QuitDialog::runModal() { int result = MiniDialog::runModal(); if (result) - _vm->closeGame(); + _vm->quitGame(); return result; } diff --git a/engines/sword2/function.cpp b/engines/sword2/function.cpp index 84a5b5af76..31b799386f 100644 --- a/engines/sword2/function.cpp +++ b/engines/sword2/function.cpp @@ -2388,7 +2388,7 @@ int32 Logic::fnPlayCredits(int32 *params) { // params: none if (readVar(DEMO)) { - _vm->closeGame(); + _vm->quitGame(); return IR_STOP; } diff --git a/engines/sword2/palette.cpp b/engines/sword2/palette.cpp index 81f93c77ae..b66a3c9a81 100644 --- a/engines/sword2/palette.cpp +++ b/engines/sword2/palette.cpp @@ -212,7 +212,7 @@ uint8 Screen::getFadeStatus() { } void Screen::waitForFade() { - while (getFadeStatus() != RDFADE_NONE && getFadeStatus() != RDFADE_BLACK && !_vm->_quit) { + while (getFadeStatus() != RDFADE_NONE && getFadeStatus() != RDFADE_BLACK && !_vm->quit()) { updateDisplay(); _vm->_system->delayMillis(20); } diff --git a/engines/sword2/resman.cpp b/engines/sword2/resman.cpp index 8cddddff78..326f90cd82 100644 --- a/engines/sword2/resman.cpp +++ b/engines/sword2/resman.cpp @@ -113,7 +113,7 @@ bool ResourceManager::init() { // The resource.inf file is a simple text file containing the names of // all the resource files. - while (file.readLine(_resFiles[_totalClusters].fileName, sizeof(_resFiles[_totalClusters].fileName))) { + while (file.readLine_OLD(_resFiles[_totalClusters].fileName, sizeof(_resFiles[_totalClusters].fileName))) { _resFiles[_totalClusters].numEntries = -1; _resFiles[_totalClusters].entryTab = NULL; if (++_totalClusters >= MAX_res_files) { @@ -412,7 +412,7 @@ Common::File *ResourceManager::openCluFile(uint16 fileNum) { // quit while the game is asking for the user to insert a CD. // But recovering from this situation gracefully is just too // much trouble, so quit now. - if (_vm->_quit) + if (_vm->quit()) g_system->quit(); // If the file is supposed to be on hard disk, or we're diff --git a/engines/sword2/screen.cpp b/engines/sword2/screen.cpp index fdabb3ee6f..1faef01939 100644 --- a/engines/sword2/screen.cpp +++ b/engines/sword2/screen.cpp @@ -389,7 +389,7 @@ void Screen::displayMsg(byte *text, int time) { uint32 targetTime = _vm->getMillis() + (time * 1000); _vm->sleepUntil(targetTime); } else { - while (!_vm->_quit) { + while (!_vm->quit()) { MouseEvent *me = _vm->mouseEvent(); if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) break; @@ -919,7 +919,7 @@ void Screen::rollCredits() { while (1) { char buffer[80]; - char *line = f.readLine(buffer, sizeof(buffer)); + char *line = f.readLine_OLD(buffer, sizeof(buffer)); if (!line || *line == 0) { if (!hasCenterMark) { @@ -1035,7 +1035,7 @@ void Screen::rollCredits() { uint32 musicLength = MAX((int32)(1000 * (_vm->_sound->musicTimeRemaining() - 3)), 25 * (int32)scrollSteps); - while (scrollPos < scrollSteps && !_vm->_quit) { + while (scrollPos < scrollSteps && !_vm->quit()) { clearScene(); for (i = startLine; i < lineCount; i++) { @@ -1123,13 +1123,13 @@ void Screen::rollCredits() { // The music should either have stopped or be about to stop, so // wait for it to really happen. - while (_vm->_sound->musicTimeRemaining() && !_vm->_quit) { + while (_vm->_sound->musicTimeRemaining() && !_vm->quit()) { updateDisplay(false); _vm->_system->delayMillis(100); } } - if (_vm->_quit) + if (_vm->quit()) return; waitForFade(); diff --git a/engines/sword2/sound.h b/engines/sword2/sound.h index b89ef8f12b..684be3dacd 100644 --- a/engines/sword2/sound.h +++ b/engines/sword2/sound.h @@ -124,7 +124,7 @@ struct SoundFileHandle { Common::File file; uint32 *idxTab; uint32 idxLen; - uint32 fileSize; + int32 fileSize; uint32 fileType; volatile bool inUse; }; diff --git a/engines/sword2/startup.cpp b/engines/sword2/startup.cpp index 1841384897..09bf65bf75 100644 --- a/engines/sword2/startup.cpp +++ b/engines/sword2/startup.cpp @@ -64,19 +64,23 @@ bool Sword2Engine::initStartMenu() { // extract the filenames int start_ids[MAX_starts]; - char buf[10]; - int lineno = 0; - while (fp.readLine(buf, sizeof(buf))) { + while (!fp.eos() && !fp.ioFailed()) { + Common::String line = fp.readLine(); + + // Skip empty lines or, more likely, the end of the stream. + if (line.size() == 0) + continue; + char *errptr; int id; lineno++; - id = strtol(buf, &errptr, 10); + id = strtol(line.c_str(), &errptr, 10); if (*errptr) { - warning("startup.inf:%d: Invalid string '%s'", lineno, buf); + warning("startup.inf:%d: Invalid string '%s'", lineno, line.c_str()); continue; } @@ -98,6 +102,10 @@ bool Sword2Engine::initStartMenu() { } } + // An I/O error before EOS? That's bad, but this is not a vital file. + if (fp.ioFailed() && !fp.eos()) + warning("I/O error while reading startup.inf"); + fp.close(); // Using this method the Gode generated resource.inf must have #0d0a diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index 7331d1f761..dc884eaacb 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -33,6 +33,7 @@ #include "common/file.h" #include "common/fs.h" #include "common/events.h" +#include "common/savefile.h" #include "common/system.h" #include "engines/metaengine.h" @@ -79,13 +80,24 @@ public: return "Broken Sword Games (C) Revolution"; } + virtual bool hasFeature(MetaEngineFeature f) const; virtual GameList getSupportedGames() const; virtual GameDescriptor findGame(const char *gameid) const; - virtual GameList detectGames(const FSList &fslist) const; + virtual GameList detectGames(const Common::FSList &fslist) const; + virtual SaveStateList listSaves(const char *target) const; + virtual void removeSaveState(const char *target, int slot) const; virtual PluginError createInstance(OSystem *syst, Engine **engine) const; }; +bool Sword2MetaEngine::hasFeature(MetaEngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsListSaves) || + (f == kSupportsDirectLoad) || + (f == kSupportsDeleteSave); +} + GameList Sword2MetaEngine::getSupportedGames() const { const Sword2::GameSettings *g = Sword2::sword2_settings; GameList games; @@ -106,10 +118,10 @@ GameDescriptor Sword2MetaEngine::findGame(const char *gameid) const { return GameDescriptor(g->gameid, g->description); } -GameList Sword2MetaEngine::detectGames(const FSList &fslist) const { +GameList Sword2MetaEngine::detectGames(const Common::FSList &fslist) const { GameList detectedGames; const Sword2::GameSettings *g; - FSList::const_iterator file; + Common::FSList::const_iterator file; // TODO: It would be nice if we had code here which distinguishes // between the 'sword2' and 'sword2demo' targets. The current code @@ -139,8 +151,8 @@ GameList Sword2MetaEngine::detectGames(const FSList &fslist) const { const char *fileName = file->getName().c_str(); if (0 == scumm_stricmp("clusters", fileName)) { - FSList recList; - if (file->getChildren(recList, FilesystemNode::kListAll)) { + Common::FSList recList; + if (file->getChildren(recList, Common::FilesystemNode::kListAll)) { GameList recGames(detectGames(recList)); if (!recGames.empty()) { detectedGames.push_back(recGames); @@ -156,13 +168,52 @@ GameList Sword2MetaEngine::detectGames(const FSList &fslist) const { return detectedGames; } +SaveStateList Sword2MetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringList filenames; + char saveDesc[SAVE_DESCRIPTION_LEN]; + Common::String pattern = target; + pattern += ".???"; + + filenames = saveFileMan->listSavefiles(pattern.c_str()); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + SaveStateList saveList; + for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + if (slotNum >= 0 && slotNum <= 999) { + Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); + if (in) { + in->readUint32LE(); + in->read(saveDesc, SAVE_DESCRIPTION_LEN); + saveList.push_back(SaveStateDescriptor(slotNum, Common::String(saveDesc), *file)); + delete in; + } + } + } + + return saveList; +} + +void Sword2MetaEngine::removeSaveState(const char *target, int slot) const { + char extension[6]; + snprintf(extension, sizeof(extension), ".%03d", slot); + + Common::String filename = target; + filename += extension; + + g_system->getSavefileManager()->removeSavefile(filename.c_str()); +} + PluginError Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) const { assert(syst); assert(engine); - FSList fslist; - FilesystemNode dir(ConfMan.get("path")); - if (!dir.getChildren(fslist, FilesystemNode::kListAll)) { + Common::FSList fslist; + Common::FilesystemNode dir(ConfMan.get("path")); + if (!dir.getChildren(fslist, Common::FilesystemNode::kListAll)) { return kInvalidPathError; } @@ -190,12 +241,12 @@ namespace Sword2 { Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) { // Add default file directories - Common::File::addDefaultDirectory(_gameDataPath + "CLUSTERS/"); - Common::File::addDefaultDirectory(_gameDataPath + "SWORD2/"); - Common::File::addDefaultDirectory(_gameDataPath + "VIDEO/"); - Common::File::addDefaultDirectory(_gameDataPath + "clusters/"); - Common::File::addDefaultDirectory(_gameDataPath + "sword2/"); - Common::File::addDefaultDirectory(_gameDataPath + "video/"); + Common::File::addDefaultDirectory(_gameDataDir.getChild("CLUSTERS")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("SWORD2")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("VIDEO")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("clusters")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("sword2")); + Common::File::addDefaultDirectory(_gameDataDir.getChild("video")); if (0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2demo")) _features = GF_DEMO; @@ -229,7 +280,6 @@ Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) { _gameCycle = 0; _gameSpeed = 1; - _quit = false; syst->getEventManager()->registerRandomSource(_rnd, "sword2"); } @@ -371,7 +421,7 @@ int Sword2Engine::init() { // player will kill the music for us. Otherwise, the restore // will either have killed the music, or done a crossfade. - if (_quit) + if (quit()) return 0; if (result) @@ -443,7 +493,7 @@ int Sword2Engine::go() { // because we want the break to happen before updating the // screen again. - if (_quit) + if (quit()) break; // creates the debug text blocks @@ -463,10 +513,6 @@ int Sword2Engine::go() { return 0; } -void Sword2Engine::closeGame() { - _quit = true; -} - void Sword2Engine::restartGame() { ScreenInfo *screenInfo = _screen->getScreenInfo(); uint32 temp_demo_flag; @@ -610,9 +656,6 @@ void Sword2Engine::parseInputEvents() { _mouseEvent.buttons = RD_WHEELDOWN; } break; - case Common::EVENT_QUIT: - closeGame(); - break; default: break; } diff --git a/engines/sword2/sword2.h b/engines/sword2/sword2.h index 05c5d7fa47..9b589c347e 100644 --- a/engines/sword2/sword2.h +++ b/engines/sword2/sword2.h @@ -141,8 +141,6 @@ public: bool getSubtitles() { return _useSubtitles; } void setSubtitles(bool b) { _useSubtitles = b; } - bool _quit; - uint32 _features; MemoryManager *_memory; @@ -210,7 +208,6 @@ public: void startGame(); void gameCycle(); - void closeGame(); void restartGame(); void sleepUntil(uint32 time); |