aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Page2008-07-07 22:34:45 +0000
committerChristopher Page2008-07-07 22:34:45 +0000
commita4f56de13ac2a7daaf5654c75f07ad6331f375e6 (patch)
tree8a000a805fef0d628eaeb9d662daf0649a785ffe
parentb50df858eb52520b529597d98fcd0d9b29619930 (diff)
downloadscummvm-rg350-a4f56de13ac2a7daaf5654c75f07ad6331f375e6.tar.gz
scummvm-rg350-a4f56de13ac2a7daaf5654c75f07ad6331f375e6.tar.bz2
scummvm-rg350-a4f56de13ac2a7daaf5654c75f07ad6331f375e6.zip
Implemented Common::EventManager::pushEvent() to insert fake events into the event queue. Quit and RTL events have been added, and are now tracked by the DefaultEventManager using shouldQuit() and shouldRTL(). AGOS is working with this new implementation, other engines to follow.
svn-id: r32952
-rw-r--r--backends/events/default/default-events.cpp31
-rw-r--r--backends/events/default/default-events.h4
-rw-r--r--base/main.cpp6
-rw-r--r--common/events.h22
-rw-r--r--engines/agos/agos.cpp8
-rw-r--r--engines/agos/animation.cpp3
-rw-r--r--engines/agos/event.cpp5
-rw-r--r--engines/agos/gfx.cpp3
-rw-r--r--engines/agos/input.cpp5
-rw-r--r--engines/agos/script.cpp9
-rw-r--r--engines/agos/script_e1.cpp6
-rw-r--r--engines/agos/script_s1.cpp6
-rw-r--r--engines/dialogs.cpp8
13 files changed, 65 insertions, 51 deletions
diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp
index 7e9157edd9..71e19329bf 100644
--- a/backends/events/default/default-events.cpp
+++ b/backends/events/default/default-events.cpp
@@ -201,6 +201,9 @@ DefaultEventManager::~DefaultEventManager() {
_boss->unlockMutex(_timeMutex);
_boss->unlockMutex(_recorderMutex);
+ if (!artificialEventQueue.empty())
+ artificialEventQueue.clear();
+
if (_playbackFile != NULL) {
delete _playbackFile;
}
@@ -350,7 +353,11 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
uint32 time = _boss->getMillis();
bool result;
- result = _boss->pollEvent(event);
+ if (!artificialEventQueue.empty()) {
+ event.type = artificialEventQueue.pop();
+ result = true;
+ } else
+ result = _boss->pollEvent(event);
if (_recordMode != kPassthrough) {
@@ -387,12 +394,8 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
// Global Main Menu
if (event.kbd.keycode == Common::KEYCODE_F11)
if (g_engine && !g_engine->isPaused())
- g_engine->mainMenuDialog();
-
- if (g_engine->_quit)
- event.type = Common::EVENT_QUIT;
- else
- break;
+ pushEvent(Common::EVENT_MAINMENU);
+ break;
case Common::EVENT_KEYUP:
_modifierState = event.kbd.flags;
@@ -429,11 +432,12 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
case Common::EVENT_MAINMENU:
if (g_engine && !g_engine->isPaused())
g_engine->mainMenuDialog();
+ break;
- if (g_engine->_quit)
- event.type = Common::EVENT_QUIT;
- else
- break;
+ case Common::EVENT_RTL:
+ _shouldRTL = true;
+ _shouldQuit = true;
+ break;
case Common::EVENT_QUIT:
if (ConfMan.getBool("confirm_exit")) {
@@ -446,7 +450,6 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
} else
_shouldQuit = true;
- g_engine->_quit = true;
break;
default:
@@ -469,4 +472,8 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
return result;
}
+void DefaultEventManager::pushEvent(Common::EventType eventType) {
+ artificialEventQueue.push(eventType);
+}
+
#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
diff --git a/backends/events/default/default-events.h b/backends/events/default/default-events.h
index d22658b672..88e3fd6afe 100644
--- a/backends/events/default/default-events.h
+++ b/backends/events/default/default-events.h
@@ -108,6 +108,7 @@ public:
~DefaultEventManager();
virtual bool pollEvent(Common::Event &event);
+ virtual void pushEvent(Common::EventType eventType);
virtual void registerRandomSource(Common::RandomSource &rnd, const char *name);
virtual void processMillis(uint32 &millis);
@@ -116,8 +117,7 @@ public:
virtual int getModifierState() const { return _modifierState; }
virtual int shouldQuit() const { return _shouldQuit; }
virtual int shouldRTL() const { return _shouldRTL; }
- virtual void setQuit() { _shouldQuit = true; }
- virtual void setRTL() { _shouldRTL = true; }
+ virtual void resetQuit() { _shouldQuit = false; }
virtual void resetRTL() { _shouldRTL = false; }
};
diff --git a/base/main.cpp b/base/main.cpp
index b4b075a415..b836b423a4 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -38,6 +38,7 @@
#include "base/version.h"
#include "common/config-manager.h"
+#include "common/events.h"
#include "common/file.h"
#include "common/fs.h"
#include "common/system.h"
@@ -315,6 +316,11 @@ extern "C" int scummvm_main(int argc, char *argv[]) {
// TODO: We should keep running if starting the selected game failed
// (so instead of just quitting, show a nice error dialog to the
// user and let him pick another game).
+
+ // Reset RTL and Quit flags in case we want to load another engine
+ g_system->getEventManager()->resetRTL();
+ g_system->getEventManager()->resetQuit();
+
if (result == 0)
break;
diff --git a/common/events.h b/common/events.h
index bfda389bbe..10ddb7cc62 100644
--- a/common/events.h
+++ b/common/events.h
@@ -27,6 +27,7 @@
#define COMMON_EVENTS_H
#include "common/keyboard.h"
+#include "common/queue.h"
#include "common/rect.h"
#include "common/system.h"
#include "common/noncopyable.h"
@@ -59,6 +60,7 @@ enum EventType {
EVENT_MBUTTONUP = 14,
EVENT_MAINMENU = 15,
+ EVENT_RTL = 16,
EVENT_QUIT = 10,
EVENT_SCREEN_CHANGED = 11,
@@ -144,6 +146,11 @@ public:
*/
virtual bool pollEvent(Common::Event &event) = 0;
+ /**
+ * Pushes a "fake" event of the specified type into the event queue
+ */
+ virtual void pushEvent(Common::EventType eventType) = 0;
+
/** Register random source so it can be serialized in game test purposes **/
virtual void registerRandomSource(Common::RandomSource &rnd, const char *name) = 0;
@@ -173,18 +180,14 @@ public:
*/
virtual int shouldRTL() const = 0;
- /**
- * Sets the quit variable to true
- */
- virtual void setQuit() = 0;
-
/**
- * Set the RTL flag, we should return to the launcher
+ * We have returned to the launcher, and _shouldQuit should be reset to false
*/
- virtual void setRTL() = 0;
+
+ virtual void resetQuit() = 0;
/**
- * We have returned to the launcher, and the RTL should be reset to false
+ * We have returned to the launcher, and the _shouldRTL should be reset to false
*/
virtual void resetRTL() = 0;
@@ -195,6 +198,9 @@ public:
// TODO: Consider removing OSystem::getScreenChangeID and
// replacing it by a generic getScreenChangeID method here
+protected:
+
+ Common::Queue<Common::EventType> artificialEventQueue;
};
} // End of namespace Common
diff --git a/engines/agos/agos.cpp b/engines/agos/agos.cpp
index f888931ad0..86121f89a6 100644
--- a/engines/agos/agos.cpp
+++ b/engines/agos/agos.cpp
@@ -947,7 +947,7 @@ void AGOSEngine::pauseEngineIntern(bool pauseIt) {
void AGOSEngine::pause() {
pauseEngine(true);
- while (_pause && !_quit) {
+ while (_pause && !_eventMan->shouldQuit()) {
delay(1);
if (_keyPressed.keycode == Common::KEYCODE_p)
pauseEngine(false);
@@ -984,7 +984,7 @@ int AGOSEngine::go() {
(getFeatures() & GF_DEMO)) {
int i;
- while (!_quit) {
+ while (!_eventMan->shouldQuit()) {
for (i = 0; i < 4; i++) {
setWindowImage(3, 9902 + i);
debug(0, "Displaying image %d", 9902 + i);
@@ -1013,13 +1013,13 @@ int AGOSEngine::go() {
runSubroutine101();
permitInput();
- while (!_quit) {
+ while (!_eventMan->shouldQuit()) {
waitForInput();
handleVerbClicked(_verbHitArea);
delay(100);
}
- return _rtl;
+ return _eventMan->shouldRTL();
}
diff --git a/engines/agos/animation.cpp b/engines/agos/animation.cpp
index c92f834a3b..770f48b62e 100644
--- a/engines/agos/animation.cpp
+++ b/engines/agos/animation.cpp
@@ -279,9 +279,6 @@ void MoviePlayer::handleNextFrame() {
case Common::EVENT_RBUTTONUP:
_rightButtonDown = false;
break;
- case Common::EVENT_QUIT:
- _vm->_quit = true;
- break;
default:
break;
}
diff --git a/engines/agos/event.cpp b/engines/agos/event.cpp
index 010b331cf8..4a362d420a 100644
--- a/engines/agos/event.cpp
+++ b/engines/agos/event.cpp
@@ -142,7 +142,7 @@ bool AGOSEngine::kickoffTimeEvents() {
cur_time = getTime() - _gameStoppedClock;
- while ((te = _firstTimeStruct) != NULL && te->time <= cur_time && !_quit) {
+ while ((te = _firstTimeStruct) != NULL && te->time <= cur_time && !_eventMan->shouldQuit()) {
result = true;
_pendingDeleteTimeEvent = te;
invokeTimeEvent(te);
@@ -521,7 +521,6 @@ void AGOSEngine::delay(uint amount) {
_rightButtonDown++;
break;
case Common::EVENT_QUIT:
- _quit = true;
return;
default:
break;
@@ -544,7 +543,7 @@ void AGOSEngine::delay(uint amount) {
_system->delayMillis(this_delay);
cur = _system->getMillis();
- } while (cur < start + amount && !_quit);
+ } while (cur < start + amount && !_eventMan->shouldQuit());
}
void AGOSEngine::timer_callback() {
diff --git a/engines/agos/gfx.cpp b/engines/agos/gfx.cpp
index c014413bdc..e39b7c9ea4 100644
--- a/engines/agos/gfx.cpp
+++ b/engines/agos/gfx.cpp
@@ -26,6 +26,7 @@
#include "common/system.h"
+#include "common/events.h"
#include "graphics/surface.h"
@@ -1263,7 +1264,7 @@ void AGOSEngine::setWindowImageEx(uint16 mode, uint16 vga_res) {
if (getGameType() == GType_WW && (mode == 6 || mode == 8 || mode == 9)) {
setWindowImage(mode, vga_res);
} else {
- while (_copyScnFlag && !_quit)
+ while (_copyScnFlag && !_eventMan->shouldQuit())
delay(1);
setWindowImage(mode, vga_res);
diff --git a/engines/agos/input.cpp b/engines/agos/input.cpp
index d36549f187..b3acfe188b 100644
--- a/engines/agos/input.cpp
+++ b/engines/agos/input.cpp
@@ -26,6 +26,7 @@
#include "common/config-manager.h"
+#include "common/events.h"
#include "common/file.h"
#include "agos/intern.h"
@@ -189,12 +190,12 @@ void AGOSEngine::waitForInput() {
resetVerbs();
}
- while (!_quit) {
+ while (!_eventMan->shouldQuit()) {
_lastHitArea = NULL;
_lastHitArea3 = NULL;
_dragAccept = 1;
- while (!_quit) {
+ while (!_eventMan->shouldQuit()) {
if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) &&
_keyPressed.keycode == Common::KEYCODE_F10)
displayBoxStars();
diff --git a/engines/agos/script.cpp b/engines/agos/script.cpp
index 6758aec511..da47d61891 100644
--- a/engines/agos/script.cpp
+++ b/engines/agos/script.cpp
@@ -28,6 +28,7 @@
#include "common/system.h"
+#include "common/events.h"
#include "agos/animation.h"
#include "agos/agos.h"
@@ -410,7 +411,7 @@ void AGOSEngine::o_msg() {
void AGOSEngine::o_end() {
// 68: exit interpreter
- _quit = true;
+ _eventMan->pushEvent(Common::EVENT_QUIT);
}
void AGOSEngine::o_done() {
@@ -965,7 +966,7 @@ void AGOSEngine::writeVariable(uint16 variable, uint16 contents) {
int AGOSEngine::runScript() {
bool flag;
- if (_quit)
+ if (_eventMan->shouldQuit())
return 1;
do {
@@ -1010,7 +1011,7 @@ int AGOSEngine::runScript() {
error("Invalid opcode '%d' encountered", _opcode);
executeOpcode(_opcode);
- } while (getScriptCondition() != flag && !getScriptReturn() && !_quit);
+ } while (getScriptCondition() != flag && !getScriptReturn() && !_eventMan->shouldQuit());
return getScriptReturn();
}
@@ -1066,7 +1067,7 @@ void AGOSEngine::waitForSync(uint a) {
_exitCutscene = false;
_rightButtonDown = false;
- while (_vgaWaitFor != 0 && !_quit) {
+ while (_vgaWaitFor != 0 && !_eventMan->shouldQuit()) {
if (_rightButtonDown) {
if (_vgaWaitFor == 200 && (getGameType() == GType_FF || !getBitFlag(14))) {
skipSpeech();
diff --git a/engines/agos/script_e1.cpp b/engines/agos/script_e1.cpp
index c7e1d6736e..e394779ab8 100644
--- a/engines/agos/script_e1.cpp
+++ b/engines/agos/script_e1.cpp
@@ -23,7 +23,7 @@
*
*/
-
+#include "common/events.h"
#include "agos/agos.h"
#include "agos/vga.h"
@@ -565,7 +565,7 @@ void AGOSEngine_Elvira1::oe1_look() {
lobjFunc(l, "You can see "); /* Show objects */
}
if (r && (r->flags & 4) && levelOf(i) < 10000) {
- _quit = true;
+ _eventMan->pushEvent(Common::EVENT_QUIT);
}
}
@@ -944,7 +944,7 @@ restart:
windowPutChar(window, *message2);
if (confirmYesOrNo(120, 62) == 0x7FFF) {
- _quit = true;
+ _eventMan->pushEvent(Common::EVENT_QUIT);
} else {
goto restart;
}
diff --git a/engines/agos/script_s1.cpp b/engines/agos/script_s1.cpp
index 51918b9515..e8577d21bc 100644
--- a/engines/agos/script_s1.cpp
+++ b/engines/agos/script_s1.cpp
@@ -24,7 +24,7 @@
*/
-
+#include "common/events.h"
#include "common/system.h"
#include "agos/agos.h"
@@ -345,14 +345,14 @@ void AGOSEngine_Simon1::os1_pauseGame() {
if (isSmartphone()) {
if (_keyPressed.keycode) {
if (_keyPressed.keycode == Common::KEYCODE_RETURN)
- _quit = true;
+ _eventMan->pushEvent(Common::EVENT_QUIT);
else
break;
}
}
#endif
if (_keyPressed.keycode == keyYes)
- _quit = true;
+ _eventMan->pushEvent(Common::EVENT_QUIT);
else if (_keyPressed.keycode == keyNo)
break;
}
diff --git a/engines/dialogs.cpp b/engines/dialogs.cpp
index 6d29135aca..a1af87c5b8 100644
--- a/engines/dialogs.cpp
+++ b/engines/dialogs.cpp
@@ -108,15 +108,11 @@ void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
_aboutDialog->runModal();
break;
case kRTLCmd:
- //g_system->getEventManager()->setQuit();
- //g_system->getEventManager()->setRTL();
- _engine->_quit = true;
- _engine->_rtl = true;
+ g_system->getEventManager()->pushEvent(Common::EVENT_RTL);
close();
break;
case kQuitCmd:
- //g_system->getEventManager()->setQuit();
- _engine->_quit = true;
+ g_system->getEventManager()->pushEvent(Common::EVENT_QUIT);
close();
break;
default: