aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen/events.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2018-04-07 11:02:09 -0400
committerPaul Gilbert2018-04-07 11:02:09 -0400
commit6a3251649010e0488046c5c994b600b5c831a209 (patch)
tree6d26cdd40c3604d001397d952f04d88de82c594e /engines/xeen/events.cpp
parent28a3faa1785293df6aa94917c3e846e2f8e6258e (diff)
downloadscummvm-rg350-6a3251649010e0488046c5c994b600b5c831a209.tar.gz
scummvm-rg350-6a3251649010e0488046c5c994b600b5c831a209.tar.bz2
scummvm-rg350-6a3251649010e0488046c5c994b600b5c831a209.zip
XEEN: Cache mouse clicks as well as keyboard in EventsManager
This allows the well open door/gate, shoot at enemies, then close to work with the mouse as well as the keyboard. The pending event queue has also been limited to 5 pending events. Trust me, you don't want to spent time spamming Shoot at a high level monster that can't reach you, only for when it's killed to have to wait several minutes whilst your party keeps shooting.
Diffstat (limited to 'engines/xeen/events.cpp')
-rw-r--r--engines/xeen/events.cpp52
1 files changed, 29 insertions, 23 deletions
diff --git a/engines/xeen/events.cpp b/engines/xeen/events.cpp
index 6ceef4406b..7a0a5127cc 100644
--- a/engines/xeen/events.cpp
+++ b/engines/xeen/events.cpp
@@ -33,7 +33,7 @@ namespace Xeen {
EventsManager::EventsManager(XeenEngine *vm) : _vm(vm), _playTime(0),
_frameCounter(0), _priorFrameCounterTime(0), _gameCounter(0),
- _leftButton(false), _rightButton(false), _sprites("mouse.icn") {
+ _mousePressed(false), _sprites("mouse.icn") {
Common::fill(&_gameCounters[0], &_gameCounters[6], 0);
}
@@ -80,24 +80,23 @@ void EventsManager::pollEvents() {
_vm->_debugger->attach();
_vm->_debugger->onFrame();
} else {
- _keys.push(event.kbd);
+ addEvent(event.kbd);
}
break;
case Common::EVENT_MOUSEMOVE:
_mousePos = event.mouse;
break;
case Common::EVENT_LBUTTONDOWN:
- _leftButton = true;
- return;
- case Common::EVENT_LBUTTONUP:
- _leftButton = false;
+ _mousePressed = true;
+ addEvent(true, false);
return;
case Common::EVENT_RBUTTONDOWN:
- _rightButton = true;
- return;
+ _mousePressed = true;
+ addEvent(false, true);
+ case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONUP:
- _rightButton = false;
- break;
+ _mousePressed = false;
+ return;
default:
break;
}
@@ -110,31 +109,38 @@ void EventsManager::pollEventsAndWait() {
}
void EventsManager::clearEvents() {
- _keys.clear();
- _leftButton = _rightButton = false;
-
+ _pendingEvents.clear();
+ _mousePressed = false;
}
void EventsManager::debounceMouse() {
- while (_leftButton && !_vm->shouldExit()) {
+ while (_mousePressed && !_vm->shouldExit()) {
pollEventsAndWait();
}
}
-bool EventsManager::getKey(Common::KeyState &key) {
- if (_keys.empty()) {
+
+void EventsManager::addEvent(const Common::KeyState &keyState) {
+ if (_pendingEvents.size() < MAX_PENDING_EVENTS)
+ _pendingEvents.push(PendingEvent(keyState));
+}
+
+void EventsManager::addEvent(bool leftButton, bool rightButton) {
+ if (_pendingEvents.size() < MAX_PENDING_EVENTS)
+ _pendingEvents.push(PendingEvent(leftButton, rightButton));
+}
+
+
+bool EventsManager::getEvent(PendingEvent &pe) {
+ if (_pendingEvents.empty()) {
return false;
} else {
- key = _keys.pop();
+ pe = _pendingEvents.pop();
return true;
}
}
-bool EventsManager::isKeyPending() const {
- return !_keys.empty();
-}
-
bool EventsManager::isKeyMousePressed() {
- bool result = _leftButton || _rightButton || isKeyPending();
+ bool result = isEventPending();
debounceMouse();
clearEvents();
@@ -144,7 +150,7 @@ bool EventsManager::isKeyMousePressed() {
bool EventsManager::wait(uint numFrames, bool interruptable) {
while (!_vm->shouldExit() && timeElapsed() < numFrames) {
pollEventsAndWait();
- if (interruptable && (_leftButton || _rightButton || isKeyPending()))
+ if (interruptable && isEventPending())
return true;
}