aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarbenium <carbenium@outlook.com>2020-07-25 17:59:34 +0200
committerShauren <shauren.trinity@gmail.com>2022-01-24 00:01:25 +0100
commita5d85deceda576bfa8231d0a703024d13df1ff88 (patch)
tree0bade2c99c732b23edafd2aec127c121ace508f0 /src
parent5512eb2f8f09efe730ab2f997af7e7130d1e90f5 (diff)
Core/EventMap: Unify semantics of DelayEvents
DelayEvents(Milliseconds delay) had different semantics than DelayEvents(Milliseconds delay, uint32 group). The first method delayed the events only in the case the internal timer already ticked at least for the amount of delay. In contrast the latter method delayed events regardless of the internal timer value. Use the latter semantics for DelayEvents(Milliseconds delay) as well which makes the outcome more predictable. Adapt tests accordingly. (cherry picked from commit 4470b9122379dc846b322a441951a03913912b71)
Diffstat (limited to 'src')
-rw-r--r--src/common/Utilities/EventMap.cpp11
-rw-r--r--src/common/Utilities/EventMap.h2
2 files changed, 11 insertions, 2 deletions
diff --git a/src/common/Utilities/EventMap.cpp b/src/common/Utilities/EventMap.cpp
index e4a1b447579..d2ff65a14c5 100644
--- a/src/common/Utilities/EventMap.cpp
+++ b/src/common/Utilities/EventMap.cpp
@@ -94,7 +94,16 @@ uint32 EventMap::ExecuteEvent()
void EventMap::DelayEvents(Milliseconds delay)
{
- _time = delay < _time - _time.min() ? _time - delay : TimePoint::min();
+ if (Empty())
+ return;
+
+ EventStore delayed = std::move(_eventMap);
+ for (EventStore::iterator itr = delayed.begin(); itr != delayed.end();)
+ {
+ EventStore::node_type node = delayed.extract(itr++);
+ node.key() = node.key() + delay;
+ _eventMap.insert(_eventMap.end(), std::move(node));
+ }
}
void EventMap::DelayEvents(Milliseconds delay, uint32 group)
diff --git a/src/common/Utilities/EventMap.h b/src/common/Utilities/EventMap.h
index 81f06b33b51..f627f1d1ab2 100644
--- a/src/common/Utilities/EventMap.h
+++ b/src/common/Utilities/EventMap.h
@@ -179,7 +179,7 @@ public:
/**
* @name DelayEvents
- * @brief Delays all events. If delay is greater than or equal internal timer, delay will be 0.
+ * @brief Delays all events.
* @param delay Amount of delay as std::chrono type.
*/
void DelayEvents(Milliseconds delay);