aboutsummaryrefslogtreecommitdiff
path: root/engines/draci/game.cpp
diff options
context:
space:
mode:
authorDenis Kasak2009-07-29 01:11:53 +0000
committerDenis Kasak2009-07-29 01:11:53 +0000
commite9669b8e2bcc4a65d5cc1225e9328d9171726690 (patch)
tree87361ed3d977fdfa684d5963e7621a145a8102aa /engines/draci/game.cpp
parentdd9303d27e5b55175781b55c9da63468ce287a2a (diff)
downloadscummvm-rg350-e9669b8e2bcc4a65d5cc1225e9328d9171726690.tar.gz
scummvm-rg350-e9669b8e2bcc4a65d5cc1225e9328d9171726690.tar.bz2
scummvm-rg350-e9669b8e2bcc4a65d5cc1225e9328d9171726690.zip
* Moved event handling to DraciEngine::handleEvents()
* Added Game::start() method which is called from DraciEngine::go() * Made Game::loop() suitable for calling from other places (like GPL scripts) by handling events, redrawing the screen, etc from inside. This way it doesn't freeze the game if it doesn't return immediately. * Added Game::shouldQuit() and Game::setQuit() which can be used to signal the engine to quit. * Fixed race condition related to mouse buttons not getting released. * Instead of deleting frames for the title animation and adding a new one, reset the text for its frame. svn-id: r42875
Diffstat (limited to 'engines/draci/game.cpp')
-rw-r--r--engines/draci/game.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp
index 620a8ca9e7..094364be6c 100644
--- a/engines/draci/game.cpp
+++ b/engines/draci/game.cpp
@@ -151,11 +151,21 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
assert(numIcons == _info._numIcons);
}
+void Game::start() {
+ while (!shouldQuit()) {
+ Game::loop();
+ }
+}
+
void Game::init() {
+ _shouldQuit = false;
_loopStatus = kStatusOrdinary;
_objUnderCursor = kOverlayImage;
- _vm->_anims->addText(kTitleText, true);
+ // Initialize animation for object / room titles
+ Animation *titleAnim = _vm->_anims->addText(kTitleText, true);
+ Text *title = new Text ("", _vm->_bigFont, kFontColour3, 0, 0);
+ titleAnim->addFrame(title);
loadObject(kDragonObject);
@@ -169,6 +179,11 @@ void Game::init() {
void Game::loop() {
+ _vm->handleEvents();
+
+ if (shouldQuit())
+ return;
+
if (_currentRoom._mouseOn) {
int x = _vm->_mouse->getPosX();
int y = _vm->_mouse->getPosY();
@@ -178,36 +193,40 @@ void Game::loop() {
}
int animUnderCursor = _vm->_anims->getTopAnimationID(x, y);
- Animation *anim = _vm->_anims->getAnimation(animUnderCursor);
+ //Animation *anim = _vm->_anims->getAnimation(animUnderCursor);
int curObject = getObjectWithAnimation(animUnderCursor);
GameObject *obj = &_objects[curObject];
- Animation *atitle = _vm->_anims->getAnimation(kTitleText);
+ Animation *titleAnim = _vm->_anims->getAnimation(kTitleText);
// TODO: Handle displaying title in the proper location
- atitle->deleteFrames();
if (curObject != kNotFound) {
- Text *title = new Text (obj->_title, _vm->_bigFont, kFontColour1, 0, 0);
- atitle->addFrame(title);
+ titleAnim->markDirtyRect(_vm->_screen->getSurface());
+ reinterpret_cast<Text *>(titleAnim->getFrame())->setText(obj->_title);
// HACK: Test running look and use scripts
if (_vm->_mouse->lButtonPressed()) {
- _vm->_script->run(obj->_program, obj->_look);
_vm->_mouse->lButtonSet(false);
+ _vm->_script->run(obj->_program, obj->_look);
}
if (_vm->_mouse->rButtonPressed()) {
+ _vm->_mouse->rButtonSet(false);
_vm->_script->run(obj->_program, obj->_use);
- _vm->_mouse->rButtonSet(false);
}
+ } else {
+ titleAnim->markDirtyRect(_vm->_screen->getSurface());
+ reinterpret_cast<Text *>(titleAnim->getFrame())->setText("");
}
debugC(2, kDraciAnimationDebugLevel, "Anim under cursor: %d", animUnderCursor);
-
-
}
+
+ _vm->_anims->drawScene(_vm->_screen->getSurface());
+ _vm->_screen->copyToScreen();
+ _vm->_system->delayMillis(20);
}
int Game::getObjectWithAnimation(int animID) {
@@ -626,6 +645,7 @@ Game::~Game() {
delete[] _objects;
}
+
bool WalkingMap::isWalkable(int x, int y) {
// Convert to map pixels