[Scummvm-cvs-logs] SF.net SVN: scummvm:[45848] scummvm/trunk/engines/draci

spalek at users.sourceforge.net spalek at users.sourceforge.net
Thu Nov 12 01:45:28 CET 2009


Revision: 45848
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45848&view=rev
Author:   spalek
Date:     2009-11-12 00:45:28 +0000 (Thu, 12 Nov 2009)

Log Message:
-----------
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.

Modified Paths:
--------------
    scummvm/trunk/engines/draci/game.cpp
    scummvm/trunk/engines/draci/game.h
    scummvm/trunk/engines/draci/script.cpp
    scummvm/trunk/engines/draci/script.h
    scummvm/trunk/engines/draci/walking.cpp

Modified: scummvm/trunk/engines/draci/game.cpp
===================================================================
--- scummvm/trunk/engines/draci/game.cpp	2009-11-11 23:05:19 UTC (rev 45847)
+++ scummvm/trunk/engines/draci/game.cpp	2009-11-12 00:45:28 UTC (rev 45848)
@@ -329,7 +329,7 @@
 		// 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 @@
 			// 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 @@
 				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 @@
 	_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 @@
 	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 @@
 	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;

Modified: scummvm/trunk/engines/draci/game.h
===================================================================
--- scummvm/trunk/engines/draci/game.h	2009-11-11 23:05:19 UTC (rev 45847)
+++ scummvm/trunk/engines/draci/game.h	2009-11-12 00:45:28 UTC (rev 45848)
@@ -299,7 +299,6 @@
 	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 @@
 	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;

Modified: scummvm/trunk/engines/draci/script.cpp
===================================================================
--- scummvm/trunk/engines/draci/script.cpp	2009-11-11 23:05:19 UTC (rev 45847)
+++ scummvm/trunk/engines/draci/script.cpp	2009-11-12 00:45:28 UTC (rev 45848)
@@ -624,6 +624,10 @@
 	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 @@
 	_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
 

Modified: scummvm/trunk/engines/draci/script.h
===================================================================
--- scummvm/trunk/engines/draci/script.h	2009-11-11 23:05:19 UTC (rev 45847)
+++ scummvm/trunk/engines/draci/script.h	2009-11-12 00:45:28 UTC (rev 45848)
@@ -98,6 +98,7 @@
 	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; }

Modified: scummvm/trunk/engines/draci/walking.cpp
===================================================================
--- scummvm/trunk/engines/draci/walking.cpp	2009-11-11 23:05:19 UTC (rev 45847)
+++ scummvm/trunk/engines/draci/walking.cpp	2009-11-12 00:45:28 UTC (rev 45848)
@@ -453,19 +453,9 @@
 	}
 	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() {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list