diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sword1/animation.cpp | 3 | ||||
-rw-r--r-- | engines/sword1/control.cpp | 12 | ||||
-rw-r--r-- | engines/sword1/control.h | 1 | ||||
-rw-r--r-- | engines/sword1/credits.cpp | 15 | ||||
-rw-r--r-- | engines/sword1/logic.cpp | 2 | ||||
-rw-r--r-- | engines/sword1/sword1.cpp | 177 | ||||
-rw-r--r-- | engines/sword1/sword1.h | 2 |
7 files changed, 130 insertions, 82 deletions
diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp index 2bb027ddb4..caf766ed9f 100644 --- a/engines/sword1/animation.cpp +++ b/engines/sword1/animation.cpp @@ -300,9 +300,6 @@ void MoviePlayer::play(void) { terminated = true; } break; - case Common::EVENT_QUIT: - _system->quit(); - break; default: break; } diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp index 980e0b4f9f..d0808d3ece 100644 --- a/engines/sword1/control.cpp +++ b/engines/sword1/control.cpp @@ -215,7 +215,7 @@ void Control::askForCd(void) { notAccepted = false; } } - } while (notAccepted && (!SwordEngine::_systemVars.engineQuit)); + } while (notAccepted && (!g_engine->quit())); _resMan->resClose(fontId); free(_screenBuf); @@ -317,7 +317,7 @@ uint8 Control::runPanel(void) { } delay(1000 / 12); newMode = getClicks(mode, &retVal); - } while ((newMode != BUTTON_DONE) && (retVal == 0) && (!SwordEngine::_systemVars.engineQuit)); + } while ((newMode != BUTTON_DONE) && (retVal == 0) && (!g_engine->quit())); if (SwordEngine::_systemVars.controlPanelMode == CP_NORMAL) { uint8 volL, volR; @@ -425,7 +425,7 @@ uint8 Control::handleButtonClick(uint8 id, uint8 mode, uint8 *retVal) { _buttons[5]->setSelected(SwordEngine::_systemVars.showText); } else if (id == BUTTON_QUIT) { if (getConfirm(_lStrings[STR_QUIT])) - SwordEngine::_systemVars.engineQuit = true; + g_engine->quitGame(); return mode; } break; @@ -703,7 +703,7 @@ void Control::handleSaveKey(Common::KeyState kbd) { bool Control::saveToFile(void) { if ((_selectedSavegame == 255) || !strlen((char*)_saveNames[_selectedSavegame])) return false; // no saveslot selected or no name entered - saveGameToFile(_selectedSavegame); + saveGameToFile(_numSaves); writeSavegameDescriptions(); return true; } @@ -741,6 +741,7 @@ void Control::readSavegameDescriptions(void) { curFileNum++; } while ((ch != 255) && (!inf->eos())); _saveFiles = curFileNum; + _numSaves = _saveFiles; } delete inf; } @@ -1091,9 +1092,6 @@ void Control::delay(uint32 msecs) { _mouseDown = false; _mouseState |= BS1_WHEEL_DOWN; break; - case Common::EVENT_QUIT: - SwordEngine::_systemVars.engineQuit = true; - break; default: break; } diff --git a/engines/sword1/control.h b/engines/sword1/control.h index 7d9af2f199..926db757b9 100644 --- a/engines/sword1/control.h +++ b/engines/sword1/control.h @@ -98,6 +98,7 @@ private: void deselectSaveslots(void); uint8 *_restoreBuf; uint8 _saveFiles; + uint8 _numSaves; uint8 _saveScrollPos; uint8 _selectedSavegame; uint8 _saveNames[64][32]; diff --git a/engines/sword1/credits.cpp b/engines/sword1/credits.cpp index 14dd0ecd2b..55f1f7358b 100644 --- a/engines/sword1/credits.cpp +++ b/engines/sword1/credits.cpp @@ -125,7 +125,7 @@ void CreditsPlayer::play(void) { uint16 renderY = BUFSIZE_Y / 2; uint16 clearY = 0xFFFF; bool clearLine = false; - while (((*textData != FNT_EOB) || (scrollY != renderY)) && !SwordEngine::_systemVars.engineQuit) { + while (((*textData != FNT_EOB) || (scrollY != renderY)) && !g_engine->quit()) { if ((int32)_mixer->getSoundElapsedTime(bgSound) - relDelay < (SCROLL_TIMING * 2)) { // sync to audio if (scrollY < BUFSIZE_Y - CREDITS_Y) _system->copyRectToScreen(screenBuf + scrollY * CREDITS_X, CREDITS_X, START_X, START_Y, CREDITS_X, CREDITS_Y); @@ -175,7 +175,7 @@ void CreditsPlayer::play(void) { uint8 *revoBuf = credFile.decompressFile(REVO_LOGO); uint8 *revoPal = credFile.fetchFile(REVO_PAL, &_palLen); _palLen /= 3; - while ((_mixer->getSoundElapsedTime(bgSound) < LOGO_FADEUP_TIME) && !SwordEngine::_systemVars.engineQuit) { + while ((_mixer->getSoundElapsedTime(bgSound) < LOGO_FADEUP_TIME) && !g_engine->quit()) { delay(100); } memset(_palette, 0, 256 * 4); @@ -184,13 +184,13 @@ void CreditsPlayer::play(void) { _system->updateScreen(); fadePalette(revoPal, true, _palLen); - while ((_mixer->getSoundElapsedTime(bgSound) < LOGO_FADEDOWN_TIME) && !SwordEngine::_systemVars.engineQuit) { + while ((_mixer->getSoundElapsedTime(bgSound) < LOGO_FADEDOWN_TIME) && !g_engine->quit()) { delay(100); } fadePalette(revoPal, false, _palLen); delay(3000); - if (SwordEngine::_systemVars.engineQuit) + if (g_engine->quit()) _mixer->stopAll(); free(revoBuf); } @@ -200,7 +200,7 @@ void CreditsPlayer::fadePalette(uint8 *srcPal, bool fadeup, uint16 len) { int fadeStart = fadeup ? 0 : 12; int relDelay = _system->getMillis(); - for (int fadeStep = fadeStart; (fadeStep >= 0) && (fadeStep <= 12) && !SwordEngine::_systemVars.engineQuit; fadeStep += fadeDir) { + for (int fadeStep = fadeStart; (fadeStep >= 0) && (fadeStep <= 12) && !g_engine->quit(); fadeStep += fadeDir) { for (uint16 cnt = 0; cnt < len * 3; cnt++) _palette[(cnt / 3) * 4 + (cnt % 3)] = (srcPal[cnt] * fadeStep) / 12; _system->setPalette(_palette, 0, 256); @@ -281,9 +281,6 @@ void CreditsPlayer::delay(int msecs) { Common::EventManager *eventMan = _system->getEventManager(); while (eventMan->pollEvent(event)) { switch (event.type) { - case Common::EVENT_QUIT: - SwordEngine::_systemVars.engineQuit = true; - break; default: break; } @@ -294,7 +291,7 @@ void CreditsPlayer::delay(int msecs) { if (msecs > 0) _system->delayMillis(10); - } while ((_system->getMillis() < start + msecs) && !SwordEngine::_systemVars.engineQuit); + } while ((_system->getMillis() < start + msecs) && !g_engine->quit()); } ArcFile::ArcFile(void) { diff --git a/engines/sword1/logic.cpp b/engines/sword1/logic.cpp index e7e1fb39a4..2fa108ebdd 100644 --- a/engines/sword1/logic.cpp +++ b/engines/sword1/logic.cpp @@ -1636,7 +1636,7 @@ int Logic::fnQuitGame(Object *cpt, int32 id, int32 a, int32 b, int32 c, int32 d, if (SwordEngine::_systemVars.isDemo) { GUI::MessageDialog dialog("This is the end of the Broken Sword 1 Demo", "OK", NULL); dialog.runModal(); - SwordEngine::_systemVars.engineQuit = true; + g_engine->quitGame(); } else error("fnQuitGame() called"); return fnQuit(cpt, id, 0, 0, 0, 0, 0, 0); diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp index 7372779199..e6dc385d8b 100644 --- a/engines/sword1/sword1.cpp +++ b/engines/sword1/sword1.cpp @@ -32,6 +32,7 @@ #include "common/fs.h" #include "common/timer.h" #include "common/events.h" +#include "common/savefile.h" #include "common/system.h" #include "engines/metaengine.h" @@ -94,13 +95,22 @@ 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 SaveStateList listSaves(const char *target) const; virtual PluginError createInstance(OSystem *syst, Engine **engine) const; }; +bool SwordMetaEngine::hasFeature(MetaEngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsListSaves) || + (f == kSupportsDirectLoad); +} + GameList SwordMetaEngine::getSupportedGames() const { GameList games; games.push_back(sword1FullSettings); @@ -187,6 +197,47 @@ PluginError SwordMetaEngine::createInstance(OSystem *syst, Engine **engine) cons return kNoError; } +SaveStateList SwordMetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + SaveStateList saveList; + + Common::String pattern = "SAVEGAME.???"; + Common::StringList filenames = saveFileMan->listSavefiles(pattern.c_str()); + sort(filenames.begin(), filenames.end()); + Common::StringList::const_iterator file = filenames.begin(); + + Common::InSaveFile *in = saveFileMan->openForLoading("SAVEGAME.INF"); + if (in) { + uint8 stop; + char saveDesc[32]; + do { + // Obtain the last digit of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 1); + + uint pos = 0; + do { + stop = in->readByte(); + if (pos < (sizeof(saveDesc) - 1)) { + if ((stop == 10) || (stop == 255) || (in->eos())) { + saveDesc[pos++] = '\0'; + } + else if (stop >= 32) { + saveDesc[pos++] = stop; + } + } + } while ((stop != 10) && (stop != 255) && (!in->eos())); + if (saveDesc[0] != 0) { + saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file)); + file++; + } + } while ((stop != 255) && (!in->eos())); + } + + delete in; + + return saveList; +} + #if PLUGIN_ENABLED_DYNAMIC(SWORD1) REGISTER_PLUGIN_DYNAMIC(SWORD1, PLUGIN_TYPE_ENGINE, SwordMetaEngine); #else @@ -247,8 +298,6 @@ int SwordEngine::init() { _resMan = new ResMan("swordres.rif", _systemVars.isMac); debug(5, "Starting object manager"); _objectMan = new ObjectMan(_resMan); - _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, Audio::Mixer::kMaxMixerVolume); - _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, Audio::Mixer::kMaxMixerVolume); _mouse = new Mouse(_system, _resMan, _objectMan); _screen = new Screen(_system, _resMan, _objectMan); _music = new Music(_mixer); @@ -257,60 +306,13 @@ int SwordEngine::init() { _logic = new Logic(_objectMan, _resMan, _screen, _mouse, _sound, _music, _menu, _system, _mixer); _mouse->useLogicAndMenu(_logic, _menu); - uint musicVol = ConfMan.getInt("music_volume"); - uint speechVol = ConfMan.getInt("speech_volume"); - uint sfxVol = ConfMan.getInt("sfx_volume"); - uint musicBal = 50; - if (ConfMan.hasKey("music_balance")) { - musicBal = CLIP(ConfMan.getInt("music_balance"), 0, 100); - } - uint speechBal = 50; - if (ConfMan.hasKey("speech_balance")) { - speechBal = CLIP(ConfMan.getInt("speech_balance"), 0, 100); - } - uint sfxBal = 50; - if (ConfMan.hasKey("sfx_balance")) { - sfxBal = CLIP(ConfMan.getInt("sfx_balance"), 0, 100); - } - - uint musicVolL = 2 * musicVol * musicBal / 100; - uint musicVolR = 2 * musicVol - musicVolL; - - uint speechVolL = 2 * speechVol * speechBal / 100; - uint speechVolR = 2 * speechVol - speechVolL; - - uint sfxVolL = 2 * sfxVol * sfxBal / 100; - uint sfxVolR = 2 * sfxVol - sfxVolL; - - if (musicVolR > 255) { - musicVolR = 255; - } - if (musicVolL > 255) { - musicVolL = 255; - } - if (speechVolR > 255) { - speechVolR = 255; - } - if (speechVolL > 255) { - speechVolL = 255; - } - if (sfxVolR > 255) { - sfxVolR = 255; - } - if (sfxVolL > 255) { - sfxVolL = 255; - } - - _music->setVolume(musicVolL, musicVolR); - _sound->setSpeechVol(speechVolL, speechVolR); - _sound->setSfxVol(sfxVolL, sfxVolR); + syncSoundSettings(); _systemVars.justRestoredGame = 0; _systemVars.currentCD = 0; _systemVars.controlPanelMode = CP_NEWGAME; _systemVars.forceRestart = false; _systemVars.wantFade = true; - _systemVars.engineQuit = false; switch (Common::parseLanguage(ConfMan.get("language"))) { case Common::DE_DEU: @@ -358,6 +360,62 @@ void SwordEngine::reinitialize(void) { _systemVars.wantFade = true; } +void SwordEngine::syncSoundSettings() { + uint musicVol = ConfMan.getInt("music_volume"); + uint sfxVol = ConfMan.getInt("sfx_volume"); + uint speechVol = ConfMan.getInt("speech_volume"); + + uint musicBal = 50; + if (ConfMan.hasKey("music_balance")) { + musicBal = CLIP(ConfMan.getInt("music_balance"), 0, 100); + } + + uint speechBal = 50; + if (ConfMan.hasKey("speech_balance")) { + speechBal = CLIP(ConfMan.getInt("speech_balance"), 0, 100); + } + uint sfxBal = 50; + if (ConfMan.hasKey("sfx_balance")) { + sfxBal = CLIP(ConfMan.getInt("sfx_balance"), 0, 100); + } + + uint musicVolL = 2 * musicVol * musicBal / 100; + uint musicVolR = 2 * musicVol - musicVolL; + + uint speechVolL = 2 * speechVol * speechBal / 100; + uint speechVolR = 2 * speechVol - speechVolL; + + uint sfxVolL = 2 * sfxVol * sfxBal / 100; + uint sfxVolR = 2 * sfxVol - sfxVolL; + + if (musicVolR > 255) { + musicVolR = 255; + } + if (musicVolL > 255) { + musicVolL = 255; + } + + if (speechVolR > 255) { + speechVolR = 255; + } + if (speechVolL > 255) { + speechVolL = 255; + } + if (sfxVolR > 255) { + sfxVolR = 255; + } + if (sfxVolL > 255) { + sfxVolL = 255; + } + + _music->setVolume(musicVolL, musicVolR); + _sound->setSpeechVol(speechVolL, speechVolR); + _sound->setSfxVol(sfxVolL, sfxVolR); + + _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); + _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); +} + void SwordEngine::flagsToBool(bool *dest, uint8 flags) { uint8 bitPos = 0; while (flags) { @@ -639,13 +697,13 @@ int SwordEngine::go() { int saveSlot = ConfMan.getInt("save_slot"); // Savegames are numbered starting from 1 in the dialog window, // but their filenames are numbered starting from 0. - if (saveSlot > 0 && _control->restoreGameFromFile(saveSlot - 1)) { + if (saveSlot >= 0 && _control->savegamesExist() && _control->restoreGameFromFile(saveSlot)) { _control->doRestore(); } else if (_control->savegamesExist()) { _systemVars.controlPanelMode = CP_NEWGAME; if (_control->runPanel() == CONTROL_GAME_RESTORED) _control->doRestore(); - else if (!_systemVars.engineQuit) + else if (!quit()) _logic->startPositions(0); } else { // no savegames, start new game. @@ -654,10 +712,10 @@ int SwordEngine::go() { } _systemVars.controlPanelMode = CP_NORMAL; - while (!_systemVars.engineQuit) { + while (!quit()) { uint8 action = mainLoop(); - if (!_systemVars.engineQuit) { + if (!quit()) { // the mainloop was left, we have to reinitialize. reinitialize(); if (action == CONTROL_GAME_RESTORED) @@ -669,7 +727,7 @@ int SwordEngine::go() { } } - return 0; + return _eventMan->shouldRTL(); } void SwordEngine::checkCd(void) { @@ -698,7 +756,7 @@ uint8 SwordEngine::mainLoop(void) { uint8 retCode = 0; _keyPressed.reset(); - while ((retCode == 0) && (!_systemVars.engineQuit)) { + while ((retCode == 0) && (!quit())) { // do we need the section45-hack from sword.c here? checkCd(); @@ -747,9 +805,9 @@ uint8 SwordEngine::mainLoop(void) { } _mouseState = 0; _keyPressed.reset(); - } while ((Logic::_scriptVars[SCREEN] == Logic::_scriptVars[NEW_SCREEN]) && (retCode == 0) && (!_systemVars.engineQuit)); + } while ((Logic::_scriptVars[SCREEN] == Logic::_scriptVars[NEW_SCREEN]) && (retCode == 0) && (!quit())); - if ((retCode == 0) && (Logic::_scriptVars[SCREEN] != 53) && _systemVars.wantFade && (!_systemVars.engineQuit)) { + if ((retCode == 0) && (Logic::_scriptVars[SCREEN] != 53) && _systemVars.wantFade && (!quit())) { _screen->fadeDownPalette(); int32 relDelay = (int32)_system->getMillis(); while (_screen->stillFading()) { @@ -796,9 +854,6 @@ void SwordEngine::delay(int32 amount) { //copied and mutilated from sky.cpp _mouseState |= BS1R_BUTTON_UP; _mouseCoord = event.mouse; break; - case Common::EVENT_QUIT: - _systemVars.engineQuit = true; - break; default: break; } diff --git a/engines/sword1/sword1.h b/engines/sword1/sword1.h index cfb6750a47..5bc80b4f6d 100644 --- a/engines/sword1/sword1.h +++ b/engines/sword1/sword1.h @@ -58,7 +58,6 @@ struct SystemVars { bool runningFromCd; uint32 currentCD; // starts at zero, then either 1 or 2 depending on section being played uint32 justRestoredGame; // see main() in sword.c & New_screen() in gtm_core.c - bool engineQuit; uint8 controlPanelMode; // 1 death screen version of the control panel, 2 = successful end of game, 3 = force restart bool forceRestart; @@ -78,6 +77,7 @@ public: virtual ~SwordEngine(); static SystemVars _systemVars; void reinitialize(void); + virtual void syncSoundSettings(); uint32 _features; protected: |