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

spalek at users.sourceforge.net spalek at users.sourceforge.net
Tue Nov 3 23:13:38 CET 2009


Revision: 45644
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45644&view=rev
Author:   spalek
Date:     2009-11-03 22:13:37 +0000 (Tue, 03 Nov 2009)

Log Message:
-----------
Created walking-callback infrastructure and converted the code to use it

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

Modified: scummvm/trunk/engines/draci/game.cpp
===================================================================
--- scummvm/trunk/engines/draci/game.cpp	2009-11-03 21:51:24 UTC (rev 45643)
+++ scummvm/trunk/engines/draci/game.cpp	2009-11-03 22:13:37 UTC (rev 45644)
@@ -45,7 +45,7 @@
 	kWalkingObliquePathOverlayColour = 73
 };
 
-Game::Game(DraciEngine *vm) : _vm(vm) {
+Game::Game(DraciEngine *vm) : _vm(vm), _walkingState(vm) {
 	uint i;
 
 	BArchive *initArchive = _vm->_initArchive;
@@ -235,10 +235,6 @@
 		return;
 	}
 
-	// Fetch the dedicated objects' title animation / current frame
-	Animation *titleAnim = _vm->_anims->getAnimation(kTitleText);
-	Text *title = reinterpret_cast<Text *>(titleAnim->getCurrentFrame());
-
 	if (_vm->_mouse->lButtonPressed()) {
 		_vm->_mouse->lButtonSet(false);
 
@@ -250,10 +246,7 @@
 			if (_objUnderCursor != kObjectNotFound) {
 				const GameObject *obj = &_objects[_objUnderCursor];
 
-				_vm->_mouse->cursorOff();
-				titleAnim->markDirtyRect(_vm->_screen->getSurface());
-				title->setText("");
-				_objUnderCursor = kObjectNotFound;
+				_walkingState.setCallback(&obj->_program, obj->_look);
 
 				if (!obj->_imLook) {
 					if (obj->_lookDir == kDirectionLast) {
@@ -263,8 +256,7 @@
 					}
 				}
 
-				_vm->_script->run(obj->_program, obj->_look);
-				_vm->_mouse->cursorOn();
+				_walkingState.callback();
 			} else {
 				walkHero(x, y, kDirectionLast);
 			}
@@ -278,10 +270,7 @@
 			const GameObject *obj = &_objects[_objUnderCursor];
 
 			if (_vm->_script->testExpression(obj->_program, obj->_canUse)) {
-				_vm->_mouse->cursorOff();
-				titleAnim->markDirtyRect(_vm->_screen->getSurface());
-				title->setText("");
-				_objUnderCursor = kObjectNotFound;
+				_walkingState.setCallback(&obj->_program, obj->_use);
 
 				if (!obj->_imUse) {
 					if (obj->_useDir == kDirectionLast) {
@@ -291,20 +280,14 @@
 					}
 				}
 
-				_vm->_script->run(obj->_program, obj->_use);
-				_vm->_mouse->cursorOn();
+				_walkingState.callback();
 			} else {
 				walkHero(x, y, kDirectionLast);
 			}
 		} else {
 			if (_vm->_script->testExpression(_currentRoom._program, _currentRoom._canUse)) {
-				_vm->_mouse->cursorOff();
-				titleAnim->markDirtyRect(_vm->_screen->getSurface());
-				title->setText("");
-
-
-				_vm->_script->run(_currentRoom._program, _currentRoom._use);
-				_vm->_mouse->cursorOn();
+				_walkingState.setCallback(&_currentRoom._program, _currentRoom._use);
+				_walkingState.callback();
 			} else {
 				walkHero(x, y, kDirectionLast);
 			}
@@ -850,7 +833,7 @@
 
 	if (_dialogueLinesNum > 1) {
 		// Call the game loop to enable interactivity until the user
-		// selects his choice.
+		// selects his choice.  _animUnderCursor will be set.
 		_vm->_mouse->cursorOn();
 		loop(kInnerDuringDialogue, false);
 		_vm->_mouse->cursorOff();
@@ -1004,7 +987,8 @@
 		redrawWalkingPath(kWalkingObliquePathOverlay, kWalkingObliquePathOverlayColour, obliquePath);
 	}
 
-	_walkingState.setPath(_hero, target, _walkingMap.getDelta(), obliquePath);
+	_walkingState.setPath(_hero, target, Common::Point(x, y),
+		_walkingMap.getDelta(), obliquePath);
 
 	// FIXME: Need to add proper walking (this only warps the dragon to position)
 	positionHero(target, dir);

Modified: scummvm/trunk/engines/draci/walking.cpp
===================================================================
--- scummvm/trunk/engines/draci/walking.cpp	2009-11-03 21:51:24 UTC (rev 45643)
+++ scummvm/trunk/engines/draci/walking.cpp	2009-11-03 22:13:37 UTC (rev 45644)
@@ -27,6 +27,8 @@
 
 #include "common/stream.h"
 
+#include "draci/animation.h"
+#include "draci/draci.h"
 #include "draci/walking.h"
 #include "draci/sprite.h"
 
@@ -420,8 +422,15 @@
 	return improved;
 }
 
-void WalkingState::setPath(const Common::Point &p1, const Common::Point &p2, const Common::Point &delta, const WalkingPath& path) {
+void WalkingState::clearPath() {
+	_path.clear();
+	_callback = NULL;
+}
+
+void WalkingState::setPath(const Common::Point &p1, const Common::Point &p2, const Common::Point &mouse, const Common::Point &delta, const WalkingPath& path) {
 	_path = path;
+	_mouse = mouse;
+
 	if (!_path.size()) {
 		return;
 	}
@@ -443,4 +452,26 @@
 	}
 }
 
+void WalkingState::setCallback(const GPL2Program *program, uint16 offset) {
+	_callback = program;
+	_callbackOffset = offset;
 }
+
+void WalkingState::callback() {
+	if (!_callback) {
+		return;
+	}
+
+	// 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("");
+
+	_vm->_script->run(*_callback, _callbackOffset);
+	_vm->_mouse->cursorOn();
+}
+
+}

Modified: scummvm/trunk/engines/draci/walking.h
===================================================================
--- scummvm/trunk/engines/draci/walking.h	2009-11-03 21:51:24 UTC (rev 45643)
+++ scummvm/trunk/engines/draci/walking.h	2009-11-03 22:13:37 UTC (rev 45644)
@@ -94,17 +94,29 @@
 	kSpeakRight, kSpeakLeft, kStopRight, kStopLeft
 };
 
+class DraciEngine;
+struct GPL2Program;
+
 class WalkingState {
 public:
-	WalkingState() : _path() {}
+	explicit WalkingState(DraciEngine *vm) : _vm(vm) { clearPath(); }
 	~WalkingState() {}
 
-	void clearPath() { _path.clear(); }
-	void setPath(const Common::Point &p1, const Common::Point &p2, const Common::Point &delta, const WalkingPath& path);
+	void clearPath();
+	void setPath(const Common::Point &p1, const Common::Point &p2, const Common::Point &mouse, const Common::Point &delta, const WalkingPath& path);
 	const WalkingPath& getPath() const { return _path; }
 
+	void setCallback(const GPL2Program *program, uint16 offset);
+	void callback();
+
 private:
+	DraciEngine *_vm;
+
 	WalkingPath _path;
+	Common::Point _mouse;
+
+	const GPL2Program *_callback;
+	uint16 _callbackOffset;
 };
 
 } // End of namespace Draci


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