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
This commit is contained in:
Christopher Page 2008-07-07 22:34:45 +00:00
parent b50df858eb
commit a4f56de13a
13 changed files with 66 additions and 52 deletions

View file

@ -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)

View file

@ -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; }
};

View file

@ -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;

View file

@ -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;
@ -174,17 +181,13 @@ public:
virtual int shouldRTL() const = 0;
/**
* Sets the quit variable to true
* We have returned to the launcher, and _shouldQuit should be reset to false
*/
virtual void setQuit() = 0;
virtual void resetQuit() = 0;
/**
* Set the RTL flag, we should return to the launcher
*/
virtual void setRTL() = 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

View file

@ -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();
}

View file

@ -279,9 +279,6 @@ void MoviePlayer::handleNextFrame() {
case Common::EVENT_RBUTTONUP:
_rightButtonDown = false;
break;
case Common::EVENT_QUIT:
_vm->_quit = true;
break;
default:
break;
}

View file

@ -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() {

View file

@ -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);

View file

@ -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();

View file

@ -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();

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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: