aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/startrek/events.cpp108
-rw-r--r--engines/startrek/graphics.cpp6
2 files changed, 63 insertions, 51 deletions
diff --git a/engines/startrek/events.cpp b/engines/startrek/events.cpp
index 58c2666c7b..b80659c315 100644
--- a/engines/startrek/events.cpp
+++ b/engines/startrek/events.cpp
@@ -23,67 +23,77 @@
namespace StarTrek {
+/**
+ * Doesn't return until an event occurs.
+ */
void StarTrekEngine::pollSystemEvents() {
Common::Event event;
TrekEvent trekEvent;
- while (_eventMan->pollEvent(event)) {
- trekEvent.mouse = event.mouse;
- trekEvent.kbd = event.kbd;
-
- switch (event.type) {
- case Common::EVENT_QUIT:
- _system->quit();
- break;
-
- case Common::EVENT_MOUSEMOVE:
- trekEvent.type = TREKEVENT_MOUSEMOVE;
- addEventToQueue(trekEvent);
- break;
-
- case Common::EVENT_LBUTTONDOWN:
- // TODO: what happens when mouse click is outside normal screen bounds?
- // (apparently this can happen)
- trekEvent.type = TREKEVENT_LBUTTONDOWN;
- addEventToQueue(trekEvent);
- break;
-
- case Common::EVENT_RBUTTONDOWN:
- trekEvent.type = TREKEVENT_RBUTTONDOWN;
- addEventToQueue(trekEvent);
- break;
-
- case Common::EVENT_KEYDOWN:
- trekEvent.type = TREKEVENT_KEYDOWN;
- addEventToQueue(trekEvent);
- break;
-
- default:
- break;
+ while (_eventQueue.empty()) {
+ while (_eventMan->pollEvent(event)) {
+ trekEvent.mouse = event.mouse;
+ trekEvent.kbd = event.kbd;
+
+ switch (event.type) {
+ case Common::EVENT_QUIT:
+ _system->quit();
+ break;
+
+ case Common::EVENT_MOUSEMOVE:
+ trekEvent.type = TREKEVENT_MOUSEMOVE;
+ addEventToQueue(trekEvent);
+
+ // WORKAROUND: this improves the responsiveness of the mouse.
+ _system->updateScreen();
+ break;
+
+ case Common::EVENT_LBUTTONDOWN:
+ // TODO: what happens when mouse click is outside normal screen bounds?
+ // (apparently this can happen)
+ trekEvent.type = TREKEVENT_LBUTTONDOWN;
+ addEventToQueue(trekEvent);
+ break;
+
+ case Common::EVENT_RBUTTONDOWN:
+ trekEvent.type = TREKEVENT_RBUTTONDOWN;
+ addEventToQueue(trekEvent);
+ break;
+
+ case Common::EVENT_KEYDOWN:
+ trekEvent.type = TREKEVENT_KEYDOWN;
+ addEventToQueue(trekEvent);
+ break;
+
+ default:
+ break;
+ }
}
- }
- // TODO: check for events other than "tick" more often.
- if (_eventQueue.empty()) {
- int delay = 1000/18.206 - (_system->getMillis() - _frameStartMillis);
+ // Check for tick event
+ uint nextFrame = _frameStartMillis + 1000 / 18.206;
- _clockTicks++;
- if (delay < 0)
- debug(5, "Late frame");
- while (delay < 0) { // Check if we're behind...
- delay += 1000/18.206;
+ if (_system->getMillis() >= nextFrame) {
_clockTicks++;
+
+ _frameStartMillis = _system->getMillis();
+
+ TrekEvent tickEvent;
+ tickEvent.type = TREKEVENT_TICK;
+ tickEvent.tick = _clockTicks;
+ addEventToQueue(tickEvent);
}
- _system->delayMillis(delay);
- _frameStartMillis = _system->getMillis();
+ if (!_eventQueue.empty())
+ break;
- TrekEvent tickEvent;
- tickEvent.type = TREKEVENT_TICK;
- tickEvent.tick = _clockTicks;
- addEventToQueue(tickEvent);
+ // Wait a 60th of a second before checking for events again
+ uint delay = 1000 / 60;
+ if (_system->getMillis() + delay > nextFrame)
+ delay = nextFrame - _system->getMillis();
+ if (delay > 0)
+ _system->delayMillis(delay);
}
-
}
void StarTrekEngine::initializeEventsAndMouse() {
diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp
index cf1fa7f4ed..8142c4d187 100644
--- a/engines/startrek/graphics.cpp
+++ b/engines/startrek/graphics.cpp
@@ -89,7 +89,8 @@ void Graphics::fadeinScreen() {
while (_paletteFadeLevel <= 100) {
TrekEvent event;
do {
- _vm->popNextEvent(&event);
+ if (!_vm->popNextEvent(&event))
+ continue;
}
while (event.type != TREKEVENT_TICK);
@@ -104,7 +105,8 @@ void Graphics::fadeoutScreen() {
while (_paletteFadeLevel >= 0) {
TrekEvent event;
do {
- _vm->popNextEvent(&event);
+ if (!_vm->popNextEvent(&event))
+ continue;
}
while (event.type != TREKEVENT_TICK);