aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Špalek2009-11-03 22:13:37 +0000
committerRobert Špalek2009-11-03 22:13:37 +0000
commit930910fe5c1f94093f74ca085f2fe7dd7e4f0b11 (patch)
tree7e8e10d922388c2bc746bf50519ce310d1fb090d
parent49a8462c5babed7953ccb0275658fdb8320a4172 (diff)
downloadscummvm-rg350-930910fe5c1f94093f74ca085f2fe7dd7e4f0b11.tar.gz
scummvm-rg350-930910fe5c1f94093f74ca085f2fe7dd7e4f0b11.tar.bz2
scummvm-rg350-930910fe5c1f94093f74ca085f2fe7dd7e4f0b11.zip
Created walking-callback infrastructure and converted the code to use it
svn-id: r45644
-rw-r--r--engines/draci/game.cpp36
-rw-r--r--engines/draci/walking.cpp33
-rw-r--r--engines/draci/walking.h18
3 files changed, 57 insertions, 30 deletions
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp
index 9a6ea970b2..51be193631 100644
--- a/engines/draci/game.cpp
+++ b/engines/draci/game.cpp
@@ -45,7 +45,7 @@ enum {
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 @@ void Game::handleOrdinaryLoop(int x, int y) {
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 @@ void Game::handleOrdinaryLoop(int x, int y) {
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 @@ void Game::handleOrdinaryLoop(int x, int y) {
}
}
- _vm->_script->run(obj->_program, obj->_look);
- _vm->_mouse->cursorOn();
+ _walkingState.callback();
} else {
walkHero(x, y, kDirectionLast);
}
@@ -278,10 +270,7 @@ void Game::handleOrdinaryLoop(int x, int y) {
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 @@ void Game::handleOrdinaryLoop(int x, int y) {
}
}
- _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 @@ int Game::dialogueDraw() {
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 @@ void Game::walkHero(int x, int y, SightDirection dir) {
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);
diff --git a/engines/draci/walking.cpp b/engines/draci/walking.cpp
index 87cd1b3284..f50a90732a 100644
--- a/engines/draci/walking.cpp
+++ b/engines/draci/walking.cpp
@@ -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 @@ bool WalkingMap::managedToOblique(WalkingPath *path) const {
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::setPath(const Common::Point &p1, const Common::Point &p2, con
}
}
+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();
+}
+
}
diff --git a/engines/draci/walking.h b/engines/draci/walking.h
index e294693ba3..4e368fdfe5 100644
--- a/engines/draci/walking.h
+++ b/engines/draci/walking.h
@@ -94,17 +94,29 @@ enum Movement {
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