From 300e00860559aecd499f5e8ee0f4d457b63ec7e9 Mon Sep 17 00:00:00 2001 From: Winfidonarleyan Date: Mon, 6 Jul 2020 01:57:33 +0700 Subject: [PATCH] feat(Core/EventMap): add support chrono literals for RepeatEvent --- src/common/Utilities/EventMap.cpp | 5 ++++ src/common/Utilities/EventMap.h | 46 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/common/Utilities/EventMap.cpp b/src/common/Utilities/EventMap.cpp index 6fe66b65a..7f8db98bf 100644 --- a/src/common/Utilities/EventMap.cpp +++ b/src/common/Utilities/EventMap.cpp @@ -71,6 +71,11 @@ void EventMap::RescheduleEvent(uint32 eventId, uint32 time, uint32 groupId /*= 0 ScheduleEvent(eventId, time, groupId, phase); } +void EventMap::RepeatEvent(uint32 minTime, uint32 maxTime) +{ + RepeatEvent(urand(minTime, maxTime)); +} + void EventMap::RepeatEvent(uint32 time) { if (Empty()) diff --git a/src/common/Utilities/EventMap.h b/src/common/Utilities/EventMap.h index 34ca05584..6e0a69028 100644 --- a/src/common/Utilities/EventMap.h +++ b/src/common/Utilities/EventMap.h @@ -24,6 +24,17 @@ class WH_COMMON_API EventMap { + /** + * Internal storage type. + * Key: Time as uint32 when the event should occur. + * Value: The event data as uint32. + * + * Structure of event data: + * - Bit 0 - 15: Event Id. + * - Bit 16 - 23: Group + * - Bit 24 - 31: Phase + * - Pattern: 0xPPGGEEEE + */ typedef std::multimap EventStore; public: @@ -54,6 +65,9 @@ class WH_COMMON_API EventMap return _time; } + /** + * @name SetTimer\ + */ void SetTimer(uint32 time) { _time = time; @@ -166,6 +180,16 @@ class WH_COMMON_API EventMap */ void RescheduleEvent(uint32 eventId, uint32 time, uint32 groupId = 0, uint32 phase = 0); + /** + * @name RepeatEvent + * @brief Repeats the mostly recently executed event. + * @param time Time until in milliseconds as std::chrono::duration the event occurs. + */ + void RepeatEvent(Milliseconds time) + { + RepeatEvent(uint32(time.count())); + } + /** * @name RepeatEvent * @brief Repeats the mostly recently executed event, Equivalent to Repeat(urand(minTime, maxTime). @@ -173,6 +197,25 @@ class WH_COMMON_API EventMap */ void RepeatEvent(uint32 time); + /** + * @name RepeatEvent + * @brief Repeats the mostly recently executed event. + * @param minTime Minimum time as std::chrono::duration until the event occurs. + * @param maxTime Maximum time as std::chrono::duration until the event occurs. + */ + void RepeatEvent(Milliseconds minTime, Milliseconds maxTime) + { + RepeatEvent(uint32(minTime.count()), uint32(maxTime.count())); + } + + /** + * @name RepeatEvent + * @brief Repeats the mostly recently executed event, Equivalent to Repeat(urand(minTime, maxTime). + * @param minTime Minimum time until the event occurs. + * @param maxTime Maximum time until the event occurs. + */ + void RepeatEvent(uint32 minTime, uint32 maxTime); + /** * @name PopEvent * @brief Remove the first event in the map. @@ -221,6 +264,9 @@ class WH_COMMON_API EventMap DelayEvents(uint32(delay.count()), group); } + /** + * @name DelayEventsToMax + */ void DelayEventsToMax(uint32 delay, uint32 group); /**