diff options
author | ModoX <moardox@gmail.com> | 2023-11-10 20:15:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 20:15:37 +0100 |
commit | c5735edcc882e0a52a26a8cea5031e4de9a6b328 (patch) | |
tree | 0b687a2e3492208ce328ce21b165a0c38b8134bc /src | |
parent | 42c44bd787458a8a0c7a12bbab874388537d61ed (diff) |
Core/Utilities: Added timer series queuing to EventMap (#29420)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Utilities/EventMap.cpp | 54 | ||||
-rw-r--r-- | src/common/Utilities/EventMap.h | 33 |
2 files changed, 87 insertions, 0 deletions
diff --git a/src/common/Utilities/EventMap.cpp b/src/common/Utilities/EventMap.cpp index d2ff65a14c5..dcfe4686f6b 100644 --- a/src/common/Utilities/EventMap.cpp +++ b/src/common/Utilities/EventMap.cpp @@ -85,6 +85,7 @@ uint32 EventMap::ExecuteEvent() uint32 eventId = (itr->second & 0x0000FFFF); _lastEvent = itr->second; // include phase/group _eventMap.erase(itr); + ScheduleNextFromSeries(_lastEvent); return eventId; } } @@ -139,6 +140,14 @@ void EventMap::CancelEvent(uint32 eventId) else ++itr; } + + for (EventSeriesStore::iterator itr = _timerSeries.begin(); itr != _timerSeries.end();) + { + if (eventId == (itr->first & 0x0000FFFF)) + _timerSeries.erase(itr++); + else + ++itr; + } } void EventMap::CancelEventGroup(uint32 group) @@ -153,6 +162,14 @@ void EventMap::CancelEventGroup(uint32 group) else ++itr; } + + for (EventSeriesStore::iterator itr = _timerSeries.begin(); itr != _timerSeries.end();) + { + if (itr->first & (1 << (group + 15))) + _timerSeries.erase(itr++); + else + ++itr; + } } Milliseconds EventMap::GetTimeUntilEvent(uint32 eventId) const @@ -163,3 +180,40 @@ Milliseconds EventMap::GetTimeUntilEvent(uint32 eventId) const return Milliseconds::max(); } + +void EventMap::ScheduleNextFromSeries(uint32 eventData) +{ + EventSeriesStore::iterator itr = _timerSeries.find(eventData); + if (itr == _timerSeries.end()) + return; + + if (itr->first != eventData) + return; + + if (itr->second.size() == 0) + return; + + Milliseconds time = itr->second.front(); + itr->second.pop(); + + ScheduleEvent(eventData, time); +} + +void EventMap::ScheduleEventSeries(uint32 eventId, uint8 group, uint8 phase, std::initializer_list<Milliseconds> const& timeSeries) +{ + if (group && group <= 8) + eventId |= (1 << (group + 15)); + + if (phase && phase <= 8) + eventId |= (1 << (phase + 23)); + + for (Milliseconds const& time : timeSeries) + _timerSeries[eventId].push(time); + + ScheduleNextFromSeries(eventId); +} + +void EventMap::ScheduleEventSeries(uint32 eventId, std::initializer_list<Milliseconds> const& timeSeries) +{ + ScheduleEventSeries(eventId, 0, 0, timeSeries); +} diff --git a/src/common/Utilities/EventMap.h b/src/common/Utilities/EventMap.h index 7bea23bf7e4..82c466408cd 100644 --- a/src/common/Utilities/EventMap.h +++ b/src/common/Utilities/EventMap.h @@ -21,6 +21,7 @@ #include "Define.h" #include "Duration.h" #include <map> +#include <queue> class TC_COMMON_API EventMap { @@ -36,6 +37,7 @@ class TC_COMMON_API EventMap * - Pattern: 0xPPGGEEEE */ typedef std::multimap<TimePoint, uint32> EventStore; + typedef std::map<uint32 /*event data*/, std::queue<Milliseconds>> EventSeriesStore; public: EventMap() : _time(TimePoint::min()), _phase(0), _lastEvent(0) { } @@ -225,6 +227,31 @@ public: */ Milliseconds GetTimeUntilEvent(uint32 eventId) const; + /** + * @name ScheduleNextFromSeries + * @brief Schedules specified event with next timer from series + * @param full event data, including group and phase + */ + void ScheduleNextFromSeries(uint32 eventData); + + /** + * @name ScheduleEventSeries + * @brief Schedules specified event with first value of the series and then requeues with the next + * @param eventId of the event. + * @param group of the event. + * @param phase of the event. + * @param timeSeries specifying the times the event should be automatically scheduled after each trigger (first value is initial schedule) + */ + void ScheduleEventSeries(uint32 eventId, uint8 group, uint8 phase, std::initializer_list<Milliseconds> const& timeSeries); + + /** + * @name ScheduleEventSeries + * @brief Schedules specified event with first value of the series and then requeues with the next + * @param eventId of the event. + * @param timeSeries specifying the times the event should be automatically scheduled after each trigger (first value is initial schedule) + */ + void ScheduleEventSeries(uint32 eventId, std::initializer_list<Milliseconds> const& series); + private: /** * @name _time @@ -262,6 +289,12 @@ private: * @brief Stores information on the most recently executed event */ uint32 _lastEvent; + + /** + * @name _timerSeries + * @brief Stores information about time series which requeue itself until series is empty + */ + EventSeriesStore _timerSeries; }; #endif // _EVENT_MAP_H_ |