From d281fe4717f4dad20a0390e81ada17d10cead2bb Mon Sep 17 00:00:00 2001 From: Robert Špalek Date: Thu, 12 Nov 2009 00:45:28 +0000 Subject: Added runWrapper() calling run() and some actions around it. This simplifies a lot of code calling run(). Also, scripts called from the inventory are now called with disabled mouse and title, as desired. svn-id: r45848 --- engines/draci/game.cpp | 46 ++++++++++------------------------------------ engines/draci/game.h | 2 -- engines/draci/script.cpp | 29 +++++++++++++++++++++++++++++ engines/draci/script.h | 1 + engines/draci/walking.cpp | 14 ++------------ 5 files changed, 42 insertions(+), 50 deletions(-) (limited to 'engines') diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index 0336dd4320..7e521f56c0 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -329,7 +329,7 @@ void Game::handleInventoryLoop() { // If there is an inventory item under the cursor and we aren't // holding any item, run its look GPL program if (_itemUnderCursor && !_currentItem) { - _vm->_script->run(_itemUnderCursor->_program, _itemUnderCursor->_look); + _vm->_script->runWrapper(_itemUnderCursor->_program, _itemUnderCursor->_look, true, false); // Otherwise, if we are holding an item, try to place it inside the // inventory } else if (_currentItem) { @@ -368,7 +368,7 @@ void Game::handleInventoryLoop() { // run the use script for the item. } else { if (_vm->_script->testExpression(_itemUnderCursor->_program, _itemUnderCursor->_canUse)) { - _vm->_script->run(_itemUnderCursor->_program, _itemUnderCursor->_use); + _vm->_script->runWrapper(_itemUnderCursor->_program, _itemUnderCursor->_use, true, false); } } updateInventoryCursor(); @@ -801,7 +801,9 @@ void Game::dialogueMenu(int dialogueID) { break; } _currentBlock = _lines[hit]; - runDialogueProg(_dialogueBlocks[_lines[hit]]._program, 1); + + // Run the dialogue program + _vm->_script->runWrapper(_dialogueBlocks[_lines[hit]]._program, 1, false, true); } else { break; } @@ -931,16 +933,6 @@ void Game::dialogueDone() { _vm->_mouse->setCursorType(kNormalCursor); } -void Game::runDialogueProg(GPL2Program prog, int offset) { - // Mark last animation - int lastAnimIndex = _vm->_anims->getLastIndex(); - - // Run the dialogue program - _vm->_script->run(prog, offset); - - deleteAnimationsAfterIndex(lastAnimIndex); -} - int Game::playHeroAnimation(int anim_index) { GameObject *dragon = getObject(kDragonObject); const int current_anim_index = dragon->_playingAnim; @@ -1183,22 +1175,18 @@ bool Game::enterNewRoom() { f = _vm->_paletteArchive->getFile(_currentRoom._palette); _vm->_screen->setPalette(f->_data, 0, kNumColours); - // Clean the mouse and animation title. It gets first updated in - // loop(), hence if the hero walks during the initialization scripts, - // the old values would remain otherwise. - _vm->_mouse->setCursorType(kNormalCursor); - _titleAnim->markDirtyRect(_vm->_screen->getSurface()); - Text *title = reinterpret_cast(_titleAnim->getCurrentFrame()); - title->setText(""); - // Run the program for the gate the dragon came through - runGateProgram(_newGate); + debugC(6, kDraciLogicDebugLevel, "Running program for gate %d", _newGate); + _vm->_script->runWrapper(_currentRoom._program, _currentRoom._gates[_newGate], true, true); + + setExitLoop(false); // Set cursor state // Need to do this after we set the palette since the cursors use it if (_currentRoom._mouseOn) { debugC(6, kDraciLogicDebugLevel, "Mouse: ON"); _vm->_mouse->cursorOn(); + _vm->_mouse->setCursorType(kNormalCursor); } else { debugC(6, kDraciLogicDebugLevel, "Mouse: OFF"); _vm->_mouse->cursorOff(); @@ -1217,20 +1205,6 @@ bool Game::enterNewRoom() { return true; } -void Game::runGateProgram(int gate) { - debugC(6, kDraciLogicDebugLevel, "Running program for gate %d", gate); - - // Mark last animation - int lastAnimIndex = _vm->_anims->getLastIndex(); - - // Run gate program - _vm->_script->run(_currentRoom._program, _currentRoom._gates[gate]); - - deleteAnimationsAfterIndex(lastAnimIndex); - - setExitLoop(false); -} - void Game::positionAnimAsHero(Animation *anim) { // Calculate scaling factors const double scale = getPers0() + getPersStep() * _hero.y; diff --git a/engines/draci/game.h b/engines/draci/game.h index 6e71088ae0..a3f84cf363 100644 --- a/engines/draci/game.h +++ b/engines/draci/game.h @@ -299,7 +299,6 @@ public: int dialogueDraw(); void dialogueInit(int dialogID); void dialogueDone(); - void runDialogueProg(GPL2Program, int offset); bool isDialogueBegin() const { return _dialogueBegin; } bool shouldExitDialogue() const { return _dialogueExit; } @@ -338,7 +337,6 @@ private: bool enterNewRoom(); // Returns false if another room change has been triggered and therefore loop() shouldn't be called yet. void initWalkingOverlays(); void loadRoomObjects(); - void runGateProgram(int gate); void redrawWalkingPath(Animation *anim, byte colour, const WalkingPath &path); DraciEngine *_vm; diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index f7cf015c24..51df1fd2ef 100644 --- a/engines/draci/script.cpp +++ b/engines/draci/script.cpp @@ -624,6 +624,10 @@ void Script::execLook(const Common::Array ¶ms) { int objID = params[0] - 1; const GameObject *obj = _vm->_game->getObject(objID); + + // We don't have to use runWrapper(), because the has already been + // wrapped due to the fact that these commands are only run from a GPL2 + // program but never from the core player. run(obj->_program, obj->_look); } @@ -1193,5 +1197,30 @@ void Script::run(const GPL2Program &program, uint16 offset) { _vm->_game->setEnableSpeedText(true); } +void Script::runWrapper(const GPL2Program &program, uint16 offset, bool disableCursor, bool releaseAnims) { + if (disableCursor) { + // Fetch the dedicated objects' title animation / current frame + Animation *titleAnim = _vm->_anims->getAnimation(kTitleText); + titleAnim->markDirtyRect(_vm->_screen->getSurface()); + Text *title = reinterpret_cast(titleAnim->getCurrentFrame()); + title->setText(""); + + _vm->_mouse->cursorOff(); + } + + // Mark last animation + int lastAnimIndex = _vm->_anims->getLastIndex(); + + run(program, offset); + + if (releaseAnims) { + _vm->_game->deleteAnimationsAfterIndex(lastAnimIndex); + } + + if (disableCursor) { + _vm->_mouse->cursorOn(); + } +} + } // End of namespace Draci diff --git a/engines/draci/script.h b/engines/draci/script.h index 5fd63517c1..d9e5395267 100644 --- a/engines/draci/script.h +++ b/engines/draci/script.h @@ -98,6 +98,7 @@ public: Script(DraciEngine *vm) : _vm(vm), _jump(0), _endProgram(false) { setupCommandList(); }; void run(const GPL2Program &program, uint16 offset); + void runWrapper(const GPL2Program &program, uint16 offset, bool disableCursor, bool releaseAnims); bool testExpression(const GPL2Program &program, uint16 offset) const; void endCurrentProgram(bool value) { _endProgram = value; } bool shouldEndProgram() const { return _endProgram; } diff --git a/engines/draci/walking.cpp b/engines/draci/walking.cpp index 14e7153de2..3764b64bc8 100644 --- a/engines/draci/walking.cpp +++ b/engines/draci/walking.cpp @@ -453,19 +453,9 @@ void WalkingState::callback() { } debugC(2, kDraciWalkingDebugLevel, "Calling walking callback"); - // Fetch the dedicated objects' title animation / current frame - Animation *titleAnim = _vm->_anims->getAnimation(kTitleText); - Text *title = reinterpret_cast(titleAnim->getCurrentFrame()); - - _vm->_mouse->cursorOff(); - titleAnim->markDirtyRect(_vm->_screen->getSurface()); - title->setText(""); - - const GPL2Program *originalCallback = _callback; + const GPL2Program &originalCallback = *_callback; _callback = NULL; - _vm->_script->run(*originalCallback, _callbackOffset); - - _vm->_mouse->cursorOn(); + _vm->_script->runWrapper(originalCallback, _callbackOffset, true, false); } bool WalkingState::continueWalkingOrClearPath() { -- cgit v1.2.3