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
This commit is contained in:
Robert Špalek 2009-11-12 00:45:28 +00:00
parent c0fc64ecbf
commit d281fe4717
5 changed files with 42 additions and 50 deletions

View file

@ -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<Text *>(_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;

View file

@ -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;

View file

@ -624,6 +624,10 @@ void Script::execLook(const Common::Array<int> &params) {
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<Text *>(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

View file

@ -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; }

View file

@ -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<Text *>(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() {