aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTarek Soliman2012-03-01 06:29:44 -0600
committerTarek Soliman2012-03-02 20:48:50 -0600
commitc0a215282d12872cf32fb24f9067216c0f869b96 (patch)
treef55b1c3591ebc7c094b78c32f3d714d45e942da7 /common
parentd12f21b31db2985faeb2e2a6b9b09cd210f82c34 (diff)
downloadscummvm-rg350-c0a215282d12872cf32fb24f9067216c0f869b96.tar.gz
scummvm-rg350-c0a215282d12872cf32fb24f9067216c0f869b96.tar.bz2
scummvm-rg350-c0a215282d12872cf32fb24f9067216c0f869b96.zip
KEYMAPPER: Add delays for *UP events coming from non-keys
Delayed entries are in a queue where each entry stores how many milliseconds should pass based on the last entry.
Diffstat (limited to 'common')
-rw-r--r--common/EventDispatcher.cpp6
-rw-r--r--common/EventMapper.cpp28
-rw-r--r--common/events.h15
3 files changed, 49 insertions, 0 deletions
diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp
index 4c7286bbb5..012a2dfce5 100644
--- a/common/EventDispatcher.cpp
+++ b/common/EventDispatcher.cpp
@@ -60,6 +60,12 @@ void EventDispatcher::dispatch() {
}
}
}
+
+ List<Event> delayedEvents = _mapper->getDelayedEvents();
+ for (List<Event>::iterator k = delayedEvents.begin(); k != delayedEvents.end(); ++k) {
+ const Event delayedEvent = *k;
+ dispatchEvent(delayedEvent);
+ }
}
void EventDispatcher::registerMapper(EventMapper *mapper) {
diff --git a/common/EventMapper.cpp b/common/EventMapper.cpp
index 0771ecdd89..47db61e472 100644
--- a/common/EventMapper.cpp
+++ b/common/EventMapper.cpp
@@ -21,6 +21,8 @@
*/
#include "common/events.h"
+
+#include "common/system.h"
#include "common/textconsole.h"
namespace Common {
@@ -61,4 +63,30 @@ List<Event> DefaultEventMapper::mapEvent(const Event &ev, EventSource *source) {
}
+void DefaultEventMapper::addDelayedEvent(uint32 millis, Event ev) {
+ if (_delayedEvents.empty()) {
+ _delayedEffectiveTime = g_system->getMillis() + millis;
+ millis = 0;
+ }
+ DelayedEventsEntry entry = DelayedEventsEntry(millis, ev);
+ _delayedEvents.push(entry);
+}
+
+List<Event> DefaultEventMapper::getDelayedEvents() {
+ List<Event> events;
+
+ if (_delayedEvents.empty())
+ return events;
+
+ uint32 now = g_system->getMillis();
+
+ while (!_delayedEvents.empty() && now >= _delayedEffectiveTime) {
+ DelayedEventsEntry entry = _delayedEvents.pop();
+ if (!_delayedEvents.empty())
+ _delayedEffectiveTime += _delayedEvents.front().timerOffset;
+ events.push_back(entry.event);
+ }
+ return events;
+}
+
} // namespace Common
diff --git a/common/events.h b/common/events.h
index 7e411ecce5..7366c51d36 100644
--- a/common/events.h
+++ b/common/events.h
@@ -232,12 +232,27 @@ public:
* Map an incoming event to one or more action events
*/
virtual List<Event> mapEvent(const Event &ev, EventSource *source) = 0;
+
+ virtual List<Event> getDelayedEvents() = 0;
};
class DefaultEventMapper : public EventMapper {
public:
+ DefaultEventMapper() : _delayedEvents(), _delayedEffectiveTime(0) {}
// EventMapper interface
virtual List<Event> mapEvent(const Event &ev, EventSource *source);
+ virtual List<Event> getDelayedEvents();
+protected:
+ virtual void addDelayedEvent(uint32 millis, Event ev);
+
+ struct DelayedEventsEntry {
+ const uint32 timerOffset;
+ const Event event;
+ DelayedEventsEntry(const uint32 offset, const Event ev) : timerOffset(offset), event(ev) { }
+ };
+
+ Queue<DelayedEventsEntry> _delayedEvents;
+ uint32 _delayedEffectiveTime;
};
/**