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:
parent
b50df858eb
commit
a4f56de13a
13 changed files with 66 additions and 52 deletions
|
@ -201,6 +201,9 @@ DefaultEventManager::~DefaultEventManager() {
|
||||||
_boss->unlockMutex(_timeMutex);
|
_boss->unlockMutex(_timeMutex);
|
||||||
_boss->unlockMutex(_recorderMutex);
|
_boss->unlockMutex(_recorderMutex);
|
||||||
|
|
||||||
|
if (!artificialEventQueue.empty())
|
||||||
|
artificialEventQueue.clear();
|
||||||
|
|
||||||
if (_playbackFile != NULL) {
|
if (_playbackFile != NULL) {
|
||||||
delete _playbackFile;
|
delete _playbackFile;
|
||||||
}
|
}
|
||||||
|
@ -350,7 +353,11 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||||
uint32 time = _boss->getMillis();
|
uint32 time = _boss->getMillis();
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
result = _boss->pollEvent(event);
|
if (!artificialEventQueue.empty()) {
|
||||||
|
event.type = artificialEventQueue.pop();
|
||||||
|
result = true;
|
||||||
|
} else
|
||||||
|
result = _boss->pollEvent(event);
|
||||||
|
|
||||||
if (_recordMode != kPassthrough) {
|
if (_recordMode != kPassthrough) {
|
||||||
|
|
||||||
|
@ -387,12 +394,8 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||||
// Global Main Menu
|
// Global Main Menu
|
||||||
if (event.kbd.keycode == Common::KEYCODE_F11)
|
if (event.kbd.keycode == Common::KEYCODE_F11)
|
||||||
if (g_engine && !g_engine->isPaused())
|
if (g_engine && !g_engine->isPaused())
|
||||||
g_engine->mainMenuDialog();
|
pushEvent(Common::EVENT_MAINMENU);
|
||||||
|
break;
|
||||||
if (g_engine->_quit)
|
|
||||||
event.type = Common::EVENT_QUIT;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Common::EVENT_KEYUP:
|
case Common::EVENT_KEYUP:
|
||||||
_modifierState = event.kbd.flags;
|
_modifierState = event.kbd.flags;
|
||||||
|
@ -429,11 +432,12 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||||
case Common::EVENT_MAINMENU:
|
case Common::EVENT_MAINMENU:
|
||||||
if (g_engine && !g_engine->isPaused())
|
if (g_engine && !g_engine->isPaused())
|
||||||
g_engine->mainMenuDialog();
|
g_engine->mainMenuDialog();
|
||||||
|
break;
|
||||||
|
|
||||||
if (g_engine->_quit)
|
case Common::EVENT_RTL:
|
||||||
event.type = Common::EVENT_QUIT;
|
_shouldRTL = true;
|
||||||
else
|
_shouldQuit = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Common::EVENT_QUIT:
|
case Common::EVENT_QUIT:
|
||||||
if (ConfMan.getBool("confirm_exit")) {
|
if (ConfMan.getBool("confirm_exit")) {
|
||||||
|
@ -446,7 +450,6 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||||
} else
|
} else
|
||||||
_shouldQuit = true;
|
_shouldQuit = true;
|
||||||
|
|
||||||
g_engine->_quit = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -469,4 +472,8 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DefaultEventManager::pushEvent(Common::EventType eventType) {
|
||||||
|
artificialEventQueue.push(eventType);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||||
|
|
|
@ -108,6 +108,7 @@ public:
|
||||||
~DefaultEventManager();
|
~DefaultEventManager();
|
||||||
|
|
||||||
virtual bool pollEvent(Common::Event &event);
|
virtual bool pollEvent(Common::Event &event);
|
||||||
|
virtual void pushEvent(Common::EventType eventType);
|
||||||
virtual void registerRandomSource(Common::RandomSource &rnd, const char *name);
|
virtual void registerRandomSource(Common::RandomSource &rnd, const char *name);
|
||||||
virtual void processMillis(uint32 &millis);
|
virtual void processMillis(uint32 &millis);
|
||||||
|
|
||||||
|
@ -116,8 +117,7 @@ public:
|
||||||
virtual int getModifierState() const { return _modifierState; }
|
virtual int getModifierState() const { return _modifierState; }
|
||||||
virtual int shouldQuit() const { return _shouldQuit; }
|
virtual int shouldQuit() const { return _shouldQuit; }
|
||||||
virtual int shouldRTL() const { return _shouldRTL; }
|
virtual int shouldRTL() const { return _shouldRTL; }
|
||||||
virtual void setQuit() { _shouldQuit = true; }
|
virtual void resetQuit() { _shouldQuit = false; }
|
||||||
virtual void setRTL() { _shouldRTL = true; }
|
|
||||||
virtual void resetRTL() { _shouldRTL = false; }
|
virtual void resetRTL() { _shouldRTL = false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "base/version.h"
|
#include "base/version.h"
|
||||||
|
|
||||||
#include "common/config-manager.h"
|
#include "common/config-manager.h"
|
||||||
|
#include "common/events.h"
|
||||||
#include "common/file.h"
|
#include "common/file.h"
|
||||||
#include "common/fs.h"
|
#include "common/fs.h"
|
||||||
#include "common/system.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
|
// TODO: We should keep running if starting the selected game failed
|
||||||
// (so instead of just quitting, show a nice error dialog to the
|
// (so instead of just quitting, show a nice error dialog to the
|
||||||
// user and let him pick another game).
|
// 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)
|
if (result == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#define COMMON_EVENTS_H
|
#define COMMON_EVENTS_H
|
||||||
|
|
||||||
#include "common/keyboard.h"
|
#include "common/keyboard.h"
|
||||||
|
#include "common/queue.h"
|
||||||
#include "common/rect.h"
|
#include "common/rect.h"
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
#include "common/noncopyable.h"
|
#include "common/noncopyable.h"
|
||||||
|
@ -59,6 +60,7 @@ enum EventType {
|
||||||
EVENT_MBUTTONUP = 14,
|
EVENT_MBUTTONUP = 14,
|
||||||
|
|
||||||
EVENT_MAINMENU = 15,
|
EVENT_MAINMENU = 15,
|
||||||
|
EVENT_RTL = 16,
|
||||||
|
|
||||||
EVENT_QUIT = 10,
|
EVENT_QUIT = 10,
|
||||||
EVENT_SCREEN_CHANGED = 11,
|
EVENT_SCREEN_CHANGED = 11,
|
||||||
|
@ -144,6 +146,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool pollEvent(Common::Event &event) = 0;
|
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 **/
|
/** Register random source so it can be serialized in game test purposes **/
|
||||||
virtual void registerRandomSource(Common::RandomSource &rnd, const char *name) = 0;
|
virtual void registerRandomSource(Common::RandomSource &rnd, const char *name) = 0;
|
||||||
|
|
||||||
|
@ -174,17 +181,13 @@ public:
|
||||||
virtual int shouldRTL() const = 0;
|
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
|
* We have returned to the launcher, and the _shouldRTL should be reset to false
|
||||||
*/
|
|
||||||
virtual void setRTL() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We have returned to the launcher, and the RTL should be reset to false
|
|
||||||
*/
|
*/
|
||||||
virtual void resetRTL() = 0;
|
virtual void resetRTL() = 0;
|
||||||
|
|
||||||
|
@ -195,6 +198,9 @@ public:
|
||||||
|
|
||||||
// TODO: Consider removing OSystem::getScreenChangeID and
|
// TODO: Consider removing OSystem::getScreenChangeID and
|
||||||
// replacing it by a generic getScreenChangeID method here
|
// replacing it by a generic getScreenChangeID method here
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Common::Queue<Common::EventType> artificialEventQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
|
|
@ -947,7 +947,7 @@ void AGOSEngine::pauseEngineIntern(bool pauseIt) {
|
||||||
void AGOSEngine::pause() {
|
void AGOSEngine::pause() {
|
||||||
pauseEngine(true);
|
pauseEngine(true);
|
||||||
|
|
||||||
while (_pause && !_quit) {
|
while (_pause && !_eventMan->shouldQuit()) {
|
||||||
delay(1);
|
delay(1);
|
||||||
if (_keyPressed.keycode == Common::KEYCODE_p)
|
if (_keyPressed.keycode == Common::KEYCODE_p)
|
||||||
pauseEngine(false);
|
pauseEngine(false);
|
||||||
|
@ -984,7 +984,7 @@ int AGOSEngine::go() {
|
||||||
(getFeatures() & GF_DEMO)) {
|
(getFeatures() & GF_DEMO)) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
while (!_quit) {
|
while (!_eventMan->shouldQuit()) {
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
setWindowImage(3, 9902 + i);
|
setWindowImage(3, 9902 + i);
|
||||||
debug(0, "Displaying image %d", 9902 + i);
|
debug(0, "Displaying image %d", 9902 + i);
|
||||||
|
@ -1013,13 +1013,13 @@ int AGOSEngine::go() {
|
||||||
runSubroutine101();
|
runSubroutine101();
|
||||||
permitInput();
|
permitInput();
|
||||||
|
|
||||||
while (!_quit) {
|
while (!_eventMan->shouldQuit()) {
|
||||||
waitForInput();
|
waitForInput();
|
||||||
handleVerbClicked(_verbHitArea);
|
handleVerbClicked(_verbHitArea);
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _rtl;
|
return _eventMan->shouldRTL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -279,9 +279,6 @@ void MoviePlayer::handleNextFrame() {
|
||||||
case Common::EVENT_RBUTTONUP:
|
case Common::EVENT_RBUTTONUP:
|
||||||
_rightButtonDown = false;
|
_rightButtonDown = false;
|
||||||
break;
|
break;
|
||||||
case Common::EVENT_QUIT:
|
|
||||||
_vm->_quit = true;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ bool AGOSEngine::kickoffTimeEvents() {
|
||||||
|
|
||||||
cur_time = getTime() - _gameStoppedClock;
|
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;
|
result = true;
|
||||||
_pendingDeleteTimeEvent = te;
|
_pendingDeleteTimeEvent = te;
|
||||||
invokeTimeEvent(te);
|
invokeTimeEvent(te);
|
||||||
|
@ -521,7 +521,6 @@ void AGOSEngine::delay(uint amount) {
|
||||||
_rightButtonDown++;
|
_rightButtonDown++;
|
||||||
break;
|
break;
|
||||||
case Common::EVENT_QUIT:
|
case Common::EVENT_QUIT:
|
||||||
_quit = true;
|
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -544,7 +543,7 @@ void AGOSEngine::delay(uint amount) {
|
||||||
_system->delayMillis(this_delay);
|
_system->delayMillis(this_delay);
|
||||||
|
|
||||||
cur = _system->getMillis();
|
cur = _system->getMillis();
|
||||||
} while (cur < start + amount && !_quit);
|
} while (cur < start + amount && !_eventMan->shouldQuit());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AGOSEngine::timer_callback() {
|
void AGOSEngine::timer_callback() {
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
|
#include "common/events.h"
|
||||||
|
|
||||||
#include "graphics/surface.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)) {
|
if (getGameType() == GType_WW && (mode == 6 || mode == 8 || mode == 9)) {
|
||||||
setWindowImage(mode, vga_res);
|
setWindowImage(mode, vga_res);
|
||||||
} else {
|
} else {
|
||||||
while (_copyScnFlag && !_quit)
|
while (_copyScnFlag && !_eventMan->shouldQuit())
|
||||||
delay(1);
|
delay(1);
|
||||||
|
|
||||||
setWindowImage(mode, vga_res);
|
setWindowImage(mode, vga_res);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "common/config-manager.h"
|
#include "common/config-manager.h"
|
||||||
|
#include "common/events.h"
|
||||||
#include "common/file.h"
|
#include "common/file.h"
|
||||||
|
|
||||||
#include "agos/intern.h"
|
#include "agos/intern.h"
|
||||||
|
@ -189,12 +190,12 @@ void AGOSEngine::waitForInput() {
|
||||||
resetVerbs();
|
resetVerbs();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!_quit) {
|
while (!_eventMan->shouldQuit()) {
|
||||||
_lastHitArea = NULL;
|
_lastHitArea = NULL;
|
||||||
_lastHitArea3 = NULL;
|
_lastHitArea3 = NULL;
|
||||||
_dragAccept = 1;
|
_dragAccept = 1;
|
||||||
|
|
||||||
while (!_quit) {
|
while (!_eventMan->shouldQuit()) {
|
||||||
if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) &&
|
if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) &&
|
||||||
_keyPressed.keycode == Common::KEYCODE_F10)
|
_keyPressed.keycode == Common::KEYCODE_F10)
|
||||||
displayBoxStars();
|
displayBoxStars();
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
|
#include "common/events.h"
|
||||||
|
|
||||||
#include "agos/animation.h"
|
#include "agos/animation.h"
|
||||||
#include "agos/agos.h"
|
#include "agos/agos.h"
|
||||||
|
@ -410,7 +411,7 @@ void AGOSEngine::o_msg() {
|
||||||
|
|
||||||
void AGOSEngine::o_end() {
|
void AGOSEngine::o_end() {
|
||||||
// 68: exit interpreter
|
// 68: exit interpreter
|
||||||
_quit = true;
|
_eventMan->pushEvent(Common::EVENT_QUIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AGOSEngine::o_done() {
|
void AGOSEngine::o_done() {
|
||||||
|
@ -965,7 +966,7 @@ void AGOSEngine::writeVariable(uint16 variable, uint16 contents) {
|
||||||
int AGOSEngine::runScript() {
|
int AGOSEngine::runScript() {
|
||||||
bool flag;
|
bool flag;
|
||||||
|
|
||||||
if (_quit)
|
if (_eventMan->shouldQuit())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -1010,7 +1011,7 @@ int AGOSEngine::runScript() {
|
||||||
error("Invalid opcode '%d' encountered", _opcode);
|
error("Invalid opcode '%d' encountered", _opcode);
|
||||||
|
|
||||||
executeOpcode(_opcode);
|
executeOpcode(_opcode);
|
||||||
} while (getScriptCondition() != flag && !getScriptReturn() && !_quit);
|
} while (getScriptCondition() != flag && !getScriptReturn() && !_eventMan->shouldQuit());
|
||||||
|
|
||||||
return getScriptReturn();
|
return getScriptReturn();
|
||||||
}
|
}
|
||||||
|
@ -1066,7 +1067,7 @@ void AGOSEngine::waitForSync(uint a) {
|
||||||
_exitCutscene = false;
|
_exitCutscene = false;
|
||||||
_rightButtonDown = false;
|
_rightButtonDown = false;
|
||||||
|
|
||||||
while (_vgaWaitFor != 0 && !_quit) {
|
while (_vgaWaitFor != 0 && !_eventMan->shouldQuit()) {
|
||||||
if (_rightButtonDown) {
|
if (_rightButtonDown) {
|
||||||
if (_vgaWaitFor == 200 && (getGameType() == GType_FF || !getBitFlag(14))) {
|
if (_vgaWaitFor == 200 && (getGameType() == GType_FF || !getBitFlag(14))) {
|
||||||
skipSpeech();
|
skipSpeech();
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/events.h"
|
||||||
|
|
||||||
#include "agos/agos.h"
|
#include "agos/agos.h"
|
||||||
#include "agos/vga.h"
|
#include "agos/vga.h"
|
||||||
|
@ -565,7 +565,7 @@ void AGOSEngine_Elvira1::oe1_look() {
|
||||||
lobjFunc(l, "You can see "); /* Show objects */
|
lobjFunc(l, "You can see "); /* Show objects */
|
||||||
}
|
}
|
||||||
if (r && (r->flags & 4) && levelOf(i) < 10000) {
|
if (r && (r->flags & 4) && levelOf(i) < 10000) {
|
||||||
_quit = true;
|
_eventMan->pushEvent(Common::EVENT_QUIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,7 +944,7 @@ restart:
|
||||||
windowPutChar(window, *message2);
|
windowPutChar(window, *message2);
|
||||||
|
|
||||||
if (confirmYesOrNo(120, 62) == 0x7FFF) {
|
if (confirmYesOrNo(120, 62) == 0x7FFF) {
|
||||||
_quit = true;
|
_eventMan->pushEvent(Common::EVENT_QUIT);
|
||||||
} else {
|
} else {
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "common/events.h"
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
|
|
||||||
#include "agos/agos.h"
|
#include "agos/agos.h"
|
||||||
|
@ -345,14 +345,14 @@ void AGOSEngine_Simon1::os1_pauseGame() {
|
||||||
if (isSmartphone()) {
|
if (isSmartphone()) {
|
||||||
if (_keyPressed.keycode) {
|
if (_keyPressed.keycode) {
|
||||||
if (_keyPressed.keycode == Common::KEYCODE_RETURN)
|
if (_keyPressed.keycode == Common::KEYCODE_RETURN)
|
||||||
_quit = true;
|
_eventMan->pushEvent(Common::EVENT_QUIT);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (_keyPressed.keycode == keyYes)
|
if (_keyPressed.keycode == keyYes)
|
||||||
_quit = true;
|
_eventMan->pushEvent(Common::EVENT_QUIT);
|
||||||
else if (_keyPressed.keycode == keyNo)
|
else if (_keyPressed.keycode == keyNo)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,15 +108,11 @@ void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
|
||||||
_aboutDialog->runModal();
|
_aboutDialog->runModal();
|
||||||
break;
|
break;
|
||||||
case kRTLCmd:
|
case kRTLCmd:
|
||||||
//g_system->getEventManager()->setQuit();
|
g_system->getEventManager()->pushEvent(Common::EVENT_RTL);
|
||||||
//g_system->getEventManager()->setRTL();
|
|
||||||
_engine->_quit = true;
|
|
||||||
_engine->_rtl = true;
|
|
||||||
close();
|
close();
|
||||||
break;
|
break;
|
||||||
case kQuitCmd:
|
case kQuitCmd:
|
||||||
//g_system->getEventManager()->setQuit();
|
g_system->getEventManager()->pushEvent(Common::EVENT_QUIT);
|
||||||
_engine->_quit = true;
|
|
||||||
close();
|
close();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue