diff options
Diffstat (limited to 'kyra/kyra.cpp')
-rw-r--r-- | kyra/kyra.cpp | 182 |
1 files changed, 81 insertions, 101 deletions
diff --git a/kyra/kyra.cpp b/kyra/kyra.cpp index 6969e3309e..9e4d91eb0d 100644 --- a/kyra/kyra.cpp +++ b/kyra/kyra.cpp @@ -15,7 +15,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $Header$ + * $URL$ + * $Id$ * */ @@ -347,7 +348,6 @@ int KyraEngine::init(GameDetector &detector) { memset(_flagsTable, 0, sizeof(_flagsTable)); - _fastMode = false; _abortWalkFlag = false; _abortWalkFlag2 = false; _talkingCharNum = -1; @@ -416,6 +416,9 @@ int KyraEngine::init(GameDetector &detector) { _lastMusicCommand = 0; + _gameSpeed = 60; + _tickLength = (uint8)(1000.0 / _gameSpeed); + return 0; } @@ -553,9 +556,6 @@ void KyraEngine::startup() { _animator->initAnimStateList(); setCharactersInDefaultScene(); - _gameSpeed = 50; - _tickLength = (uint8)(1000.0 / _gameSpeed); - if (!_scriptInterpreter->loadScript("_STARTUP.EMC", _npcScriptData, _opcodeTable, _opcodeTableSize, 0)) { error("Could not load \"_STARTUP.EMC\" script"); } @@ -576,7 +576,7 @@ void KyraEngine::startup() { snd_setSoundEffectFile(1); enterNewScene(_currentCharacter->sceneId, _currentCharacter->facing, 0, 0, 1); - if (_abortIntroFlag && _skipIntroFlag) { + if (_abortIntroFlag && _skipFlag) { _menuDirectlyToLoad = true; _screen->setMouseCursor(1, 1, _shapes[4]); buttonMenuCallback(0); @@ -585,6 +585,64 @@ void KyraEngine::startup() { saveGame(getSavegameFilename(0), "New game"); } +void KyraEngine::mainLoop() { + debug(9, "KyraEngine::mainLoop()"); + + while (!_quitFlag) { + int32 frameTime = (int32)_system->getMillis(); + _skipFlag = false; + + if (_currentCharacter->sceneId == 210) { + _animator->updateKyragemFading(); + if (seq_playEnd()) { + if (_deathHandler != 8) + break; + } + } + + if (_deathHandler != 0xFF) { + // this is only used until the original gui is implemented + GUI::MessageDialog dialog("Brandon is dead! Game over!", "Quit"); + dialog.runModal(); + break; + } + + if (_brandonStatusBit & 2) { + if (_brandonStatusBit0x02Flag) + animRefreshNPC(0); + } + if (_brandonStatusBit & 0x20) { + if (_brandonStatusBit0x20Flag) { + animRefreshNPC(0); + _brandonStatusBit0x20Flag = 0; + } + } + + _screen->showMouse(); + + processButtonList(_buttonList); + updateMousePointer(); + updateGameTimers(); + updateTextFade(); + + _handleInput = true; + delay((frameTime + _gameSpeed) - _system->getMillis(), true, true); + _handleInput = false; + } +} + +void KyraEngine::quitGame() { + res_unloadResources(RES_ALL); + + for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) { + _movieObjects[i]->close(); + delete _movieObjects[i]; + _movieObjects[i] = 0; + } + + _system->quit(); +} + void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { OSystem::Event event; char saveLoadSlot[20]; @@ -606,13 +664,17 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { saveGame(saveLoadSlot, savegameName); } } else if (event.kbd.flags == OSystem::KBD_CTRL) { - if (event.kbd.keycode == 'f') - _fastMode = !_fastMode; - else if (event.kbd.keycode == 'd') + if (event.kbd.keycode == 'd') _debugger->attach(); else if (event.kbd.keycode == 'q') _quitFlag = true; + } else if (event.kbd.keycode == '.') + _skipFlag = true; + else if (event.kbd.keycode == 13 || event.kbd.keycode == 32 || event.kbd.keycode == 27) { + _abortIntroFlag = true; + _skipFlag = true; } + break; case OSystem::EVENT_MOUSEMOVE: _mouseX = event.mouse.x; @@ -635,28 +697,29 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { _handleInput = false; processInput(_mouseX, _mouseY); _handleInput = true; - } + } else + _skipFlag = true; break; default: break; } } - if (_debugger->isAttached()) _debugger->onFrame(); - _sprites->updateSceneAnims(); if (update) + _sprites->updateSceneAnims(); _animator->updateAllObjectShapes(); - if (_currentCharacter->sceneId == 210) { + if (_currentCharacter && _currentCharacter->sceneId == 210) { _animator->updateKyragemFading(); } - if (amount > 0) { + if (amount > 0 && !_skipFlag) { _system->delayMillis((amount > 10) ? 10 : amount); } - } while (!_fastMode && _system->getMillis() < start + amount); + } while (!_skipFlag && _system->getMillis() < start + amount); + } void KyraEngine::waitForEvent() { @@ -677,6 +740,7 @@ void KyraEngine::waitForEvent() { break; case OSystem::EVENT_LBUTTONDOWN: finished = true; + _skipFlag = true; break; default: break; @@ -690,93 +754,9 @@ void KyraEngine::waitForEvent() { } } -void KyraEngine::mainLoop() { - debug(9, "KyraEngine::mainLoop()"); - - while (!_quitFlag) { - int32 frameTime = (int32)_system->getMillis(); - if (_currentCharacter->sceneId == 210) { - _animator->updateKyragemFading(); - if (seq_playEnd()) { - if (_deathHandler != 8) - break; - } - } - - if (_deathHandler != 0xFF) { - // this is only used until the original gui is implemented - GUI::MessageDialog dialog("Brandon is dead! Game over!", "Quit"); - dialog.runModal(); - break; - } - - if (_brandonStatusBit & 2) { - if (_brandonStatusBit0x02Flag) - animRefreshNPC(0); - } - if (_brandonStatusBit & 0x20) { - if (_brandonStatusBit0x20Flag) { - animRefreshNPC(0); - _brandonStatusBit0x20Flag = 0; - } - } - - _screen->showMouse(); - - processButtonList(_buttonList); - updateMousePointer(); - updateGameTimers(); - updateTextFade(); - - _handleInput = true; - delay((frameTime + _gameSpeed) - _system->getMillis(), true, true); - _handleInput = false; - } -} - -void KyraEngine::quitGame() { - res_unloadResources(RES_ALL); - - for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) { - _movieObjects[i]->close(); - delete _movieObjects[i]; - _movieObjects[i] = 0; - } - - _system->quit(); -} - -void KyraEngine::waitTicks(int ticks) { - debug(9, "KyraEngine::waitTicks(%d)", ticks); - const uint32 end = _system->getMillis() + ticks * 1000 / 60; - do { - OSystem::Event event; - while (_system->pollEvent(event)) { - switch (event.type) { - case OSystem::EVENT_QUIT: - _quitFlag = true; - quitGame(); - break; - case OSystem::EVENT_KEYDOWN: - if (event.kbd.flags == OSystem::KBD_CTRL) { - if (event.kbd.keycode == 'f') { - _fastMode = !_fastMode; - } - } else if (event.kbd.keycode == 13 || event.kbd.keycode == 32 || event.kbd.keycode == 27) { - _abortIntroFlag = true; - } - break; - default: - break; - } - } - _system->delayMillis(10); - } while (!_fastMode && _system->getMillis() < end); -} - void KyraEngine::delayWithTicks(int ticks) { uint32 nextTime = _system->getMillis() + ticks * _tickLength; - while (_system->getMillis() < nextTime) { + while (_system->getMillis() < nextTime && !_skipFlag) { _sprites->updateSceneAnims(); _animator->updateAllObjectShapes(); if (_currentCharacter->sceneId == 210) { @@ -1247,7 +1227,7 @@ int KyraEngine::handleMalcolmFlag() { while (_system->getMillis() < timer2) {} } snd_playWanderScoreViaMap(51, 1); - waitTicks(60); + delay(60*_tickLength); _malcolmFlag = 0; return 1; break; |