From 2174c5d7dd9669384b2e68b8b406a3173042d7d9 Mon Sep 17 00:00:00 2001 From: treeston Date: Tue, 13 Sep 2016 20:02:09 +0200 Subject: Common/Utilities: More std::chrono overloads for EventMap. Specifying 2 std::chrono types now gives you a random (to milliseconds) time in that interval (inclusive) for (Re)ScheduleEvent. --- src/common/Utilities/EventMap.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/common/Utilities/EventMap.h') diff --git a/src/common/Utilities/EventMap.h b/src/common/Utilities/EventMap.h index 6a314a9e633..a2fe985c6f9 100644 --- a/src/common/Utilities/EventMap.h +++ b/src/common/Utilities/EventMap.h @@ -116,7 +116,7 @@ public: * @name ScheduleEvent * @brief Creates new event entry in map. * @param eventId The id of the new event. - * @param time The time in milliseconds as std::chrono::duration until the event occurs. + * @param time The time until the event occurs as std::chrono type. * @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group. * @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases. */ @@ -125,6 +125,20 @@ public: ScheduleEvent(eventId, uint32(time.count()), group, phase); } + /** + * @name ScheduleEvent + * @brief Creates new event entry in map. + * @param eventId The id of the new event. + * @param minTime The minimum time until the event occurs as std::chrono type. + * @param maxTime The maximum time until the event occurs as std::chrono type. + * @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group. + * @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases. + */ + void ScheduleEvent(uint32 eventId, Milliseconds const& minTime, Milliseconds const& maxTime, uint32 group = 0, uint32 phase = 0) + { + ScheduleEvent(eventId, urand(uint32(minTime.count()), uint32(maxTime.count())), group, phase); + } + /** * @name ScheduleEvent * @brief Creates new event entry in map. @@ -139,7 +153,7 @@ public: * @name RescheduleEvent * @brief Cancels the given event and reschedules it. * @param eventId The id of the event. - * @param time The time in milliseconds as std::chrono::duration until the event occurs. + * @param time The time until the event occurs as std::chrono type. * @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group. * @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases. */ @@ -148,6 +162,20 @@ public: RescheduleEvent(eventId, uint32(time.count()), group, phase); } + /** + * @name RescheduleEvent + * @brief Cancels the given event and reschedules it. + * @param eventId The id of the event. + * @param minTime The minimum time until the event occurs as std::chrono type. + * @param maxTime The maximum time until the event occurs as std::chrono type. + * @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group. + * @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases. + */ + void RescheduleEvent(uint32 eventId, Milliseconds const& minTime, Milliseconds const& maxTime, uint32 group = 0, uint32 phase = 0) + { + RescheduleEvent(eventId, urand(uint32(minTime.count()), uint32(maxTime.count())), group, phase); + } + /** * @name RescheduleEvent * @brief Cancels the given event and reschedules it. @@ -223,7 +251,7 @@ public: /** * @name DelayEvents - * @brief Delays all events in the map. If delay is greater than or equal internal timer, delay will be 0. + * @brief Delays all events in the map. If delay is greater than or equal internal timer, delay will be equal to internal timer. * @param delay Amount of delay. */ void DelayEvents(uint32 delay) -- cgit v1.2.3