aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen/events.h
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.h
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.h')
-rw-r--r--engines/xeen/events.h58
1 files changed, 53 insertions, 5 deletions
diff --git a/engines/xeen/events.h b/engines/xeen/events.h
index 0ef2c3a9e7..80ce83aacb 100644
--- a/engines/xeen/events.h
+++ b/engines/xeen/events.h
@@ -32,9 +32,30 @@ namespace Xeen {
#define GAME_FRAME_RATE (1000 / 50)
#define GAME_FRAME_TIME 50
+#define MAX_PENDING_EVENTS 5
class XeenEngine;
+struct PendingEvent {
+ Common::KeyState _keyState;
+ bool _leftButton;
+ bool _rightButton;
+
+ PendingEvent() : _leftButton(false), _rightButton(false) {}
+ PendingEvent(const Common::KeyState &keyState) : _keyState(keyState), _leftButton(false), _rightButton(false) {}
+ PendingEvent(bool leftButton, bool rightButton) : _leftButton(leftButton), _rightButton(rightButton) {}
+
+ /**
+ * Returns true if a keyboard event is pending
+ */
+ bool isKeyboard() const { return _keyState.keycode != Common::KEYCODE_INVALID; }
+
+ /**
+ * Returns ture if a mouse button event is pending
+ */
+ bool isMouse() const { return _leftButton || _rightButton; }
+};
+
class EventsManager {
private:
XeenEngine *_vm;
@@ -43,19 +64,18 @@ private:
uint32 _gameCounter;
uint32 _gameCounters[6];
uint32 _playTime;
- Common::Queue<Common::KeyState> _keys;
+ Common::Queue<PendingEvent> _pendingEvents;
SpriteResource _sprites;
+ bool _mousePressed;
/**
* Handles moving to the next game frame
*/
void nextFrame();
public:
- bool _leftButton, _rightButton;
Common::Point _mousePos;
public:
EventsManager(XeenEngine *vm);
-
~EventsManager();
/*
@@ -78,17 +98,45 @@ public:
*/
bool isCursorVisible();
+ /**
+ * Polls the ScummVM backend for any pending events
+ */
void pollEvents();
+ /**
+ * Polls for events, and wait a slight delay. This ensures the game doesn't use up 100% of the CPU
+ */
void pollEventsAndWait();
+ /**
+ * Clears all pending events
+ */
void clearEvents();
+ /**
+ * Waits for a mouse press to be released
+ */
void debounceMouse();
- bool getKey(Common::KeyState &key);
+ /**
+ * Adds a keyboard event to the queue
+ */
+ void addEvent(const Common::KeyState &keyState);
+
+ /**
+ * Adds a mouse button event to the queue
+ */
+ void addEvent(bool leftButton, bool rightButton);
- bool isKeyPending() const;
+ /**
+ * Returns the next pending key/mouse press, if any
+ */
+ bool getEvent(PendingEvent &pe);
+
+ /**
+ * Returns true if a key or mouse event is pending
+ */
+ bool isEventPending() const { return !_pendingEvents.empty(); }
/**
* Returns true if a key or mouse press is pending