aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/Utilities/EventMap.cpp14
-rw-r--r--src/common/Utilities/EventMap.h18
2 files changed, 21 insertions, 11 deletions
diff --git a/src/common/Utilities/EventMap.cpp b/src/common/Utilities/EventMap.cpp
index 142b5b85220..1a227c8a874 100644
--- a/src/common/Utilities/EventMap.cpp
+++ b/src/common/Utilities/EventMap.cpp
@@ -21,7 +21,7 @@
void EventMap::Reset()
{
_eventMap.clear();
- _time = 0;
+ _time = TimePoint::min();
_phase = 0;
}
@@ -41,7 +41,7 @@ void EventMap::ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group /*=
if (phase && phase <= 8)
eventId |= (1 << (phase + 23));
- _eventMap.insert(EventStore::value_type(_time + time.count(), eventId));
+ _eventMap.insert(EventStore::value_type(_time + time, eventId));
}
void EventMap::ScheduleEvent(uint32 eventId, Milliseconds minTime, Milliseconds maxTime, uint32 group /*= 0*/, uint32 phase /*= 0*/)
@@ -62,7 +62,7 @@ void EventMap::RescheduleEvent(uint32 eventId, Milliseconds minTime, Millisecond
void EventMap::Repeat(Milliseconds time)
{
- _eventMap.insert(EventStore::value_type(_time + time.count(), _lastEvent));
+ _eventMap.insert(EventStore::value_type(_time + time, _lastEvent));
}
void EventMap::Repeat(Milliseconds minTime, Milliseconds maxTime)
@@ -94,7 +94,7 @@ uint32 EventMap::ExecuteEvent()
void EventMap::DelayEvents(Milliseconds delay)
{
- _time = delay.count() < _time ? _time - delay.count() : 0;
+ _time = delay < _time - _time.min() ? _time - delay : TimePoint::min();
}
void EventMap::DelayEvents(Milliseconds delay, uint32 group)
@@ -108,7 +108,7 @@ void EventMap::DelayEvents(Milliseconds delay, uint32 group)
{
if (itr->second & (1 << (group + 15)))
{
- delayed.insert(EventStore::value_type(itr->first + delay.count(), itr->second));
+ delayed.insert(EventStore::value_type(itr->first + delay, itr->second));
_eventMap.erase(itr++);
}
else
@@ -148,9 +148,9 @@ void EventMap::CancelEventGroup(uint32 group)
uint32 EventMap::GetTimeUntilEvent(uint32 eventId) const
{
- for (std::pair<uint32 const, uint32> const& itr : _eventMap)
+ for (std::pair<TimePoint const, uint32> const& itr : _eventMap)
if (eventId == (itr.second & 0x0000FFFF))
- return itr.first - _time;
+ return std::chrono::duration_cast<Milliseconds>((itr.first - _time)).count();
return std::numeric_limits<uint32>::max();
}
diff --git a/src/common/Utilities/EventMap.h b/src/common/Utilities/EventMap.h
index a9f864267f9..dbb297a1c63 100644
--- a/src/common/Utilities/EventMap.h
+++ b/src/common/Utilities/EventMap.h
@@ -26,7 +26,7 @@ class TC_COMMON_API EventMap
{
/**
* Internal storage type.
- * Key: Time as uint32 when the event should occur.
+ * Key: Time as TimePoint when the event should occur.
* Value: The event data as uint32.
*
* Structure of event data:
@@ -35,10 +35,10 @@ class TC_COMMON_API EventMap
* - Bit 24 - 31: Phase
* - Pattern: 0xPPGGEEEE
*/
- typedef std::multimap<uint32, uint32> EventStore;
+ typedef std::multimap<TimePoint, uint32> EventStore;
public:
- EventMap() : _time(0), _phase(0), _lastEvent(0) { }
+ EventMap() : _time(TimePoint::min()), _phase(0), _lastEvent(0) { }
/**
* @name Reset
@@ -53,6 +53,16 @@ public:
*/
void Update(uint32 time)
{
+ Update(Milliseconds(time));
+ }
+
+ /**
+ * @name Update
+ * @brief Updates the timer of the event map.
+ * @param time Value in ms to be added to time.
+ */
+ void Update(Milliseconds time)
+ {
_time += time;
}
@@ -226,7 +236,7 @@ private:
* has reached their time value. Its value is changed in the
* Update method.
*/
- uint32 _time;
+ TimePoint _time;
/**
* @name _phase