mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 22:28:10 +00:00
Created walking-callback infrastructure and converted the code to use it
svn-id: r45644
This commit is contained in:
parent
49a8462c5b
commit
930910fe5c
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user