diff --git a/Source/Framework/Dynamic/EventMap.cs b/Source/Framework/Dynamic/EventMap.cs index df701c7eb..be4aef2a7 100644 --- a/Source/Framework/Dynamic/EventMap.cs +++ b/Source/Framework/Dynamic/EventMap.cs @@ -183,6 +183,7 @@ namespace Framework.Dynamic uint eventId = (pair.Value & 0x0000FFFF); _lastEvent = pair.Value; // include phase/group _eventMap.Remove(pair); + ScheduleNextFromSeries(_lastEvent); return eventId; } } @@ -257,6 +258,12 @@ namespace Framework.Dynamic if (eventId == (pair.Value & 0x0000FFFF)) _eventMap.Remove(pair.Key, pair.Value); } + + foreach (var key in _timerSeries.Keys.ToList()) + { + if (eventId == (key & 0x0000FFFF)) + _timerSeries.Remove(key); + } } /// @@ -270,9 +277,15 @@ namespace Framework.Dynamic foreach (var pair in _eventMap.KeyValueList) { - if (Convert.ToBoolean(pair.Value & (uint)(1 << ((int)group + 15)))) + if ((pair.Value & (uint)(1 << ((int)group + 15))) != 0) _eventMap.Remove(pair.Key, pair.Value); } + + foreach (var key in _timerSeries.Keys.ToList()) + { + if ((key & (1 << ((int)group + 15))) != 0) + _timerSeries.Remove(key); + } } /// @@ -289,6 +302,52 @@ namespace Framework.Dynamic return TimeSpan.MaxValue; } + /// + /// Schedules specified event with next timer from series + /// + /// full event data, including group and phase + public void ScheduleNextFromSeries(uint eventData) + { + if (_timerSeries.TryGetValue(eventData, out Queue queue)) + return; + + if (queue.Count == 0) + return; + + ScheduleEvent(eventData, queue.Dequeue()); + } + + /// + /// Schedules specified event with first value of the series and then requeues with the next + /// + /// eventId of the event. + /// group of the event. + /// phase of the event. + /// timeSeries specifying the times the event should be automatically scheduled after each trigger (first value is initial schedule) + public void ScheduleEventSeries(uint eventId, byte group, byte phase, List timeSeries) + { + if (group != 0 && group <= 8) + eventId |= (1u << (group + 15)); + + if (phase != 0 && phase <= 8) + eventId |= (1u << (phase + 23)); + + foreach (var time in timeSeries) + _timerSeries[eventId].Enqueue(time); + + ScheduleNextFromSeries(eventId); + } + + /// + /// Schedules specified event with first value of the series and then requeues with the next + /// + /// eventId of the event. + /// timeSeries specifying the times the event should be automatically scheduled after each trigger (first value is initial schedule) + public void ScheduleEventSeries(uint eventId, List timeSeries) + { + ScheduleEventSeries(eventId, 0, 0, timeSeries); + } + /// /// Returns wether event map is in specified phase or not. /// @@ -332,5 +391,10 @@ namespace Framework.Dynamic /// - Pattern: 0xPPGGEEEE /// SortedMultiMap _eventMap = new(); + + /// + /// Stores information about time series which requeue itself until series is empty + /// + Dictionary> _timerSeries = new(); } }