Skip to content

Commit

Permalink
feat(Core/EventMap): add support chrono literals for RepeatEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Winfidonarleyan committed Jul 5, 2020
1 parent 49afbf9 commit 300e008
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/common/Utilities/EventMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
46 changes: 46 additions & 0 deletions src/common/Utilities/EventMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32, uint32> EventStore;

public:
Expand Down Expand Up @@ -54,6 +65,9 @@ class WH_COMMON_API EventMap
return _time;
}

/**
* @name SetTimer\
*/
void SetTimer(uint32 time)
{
_time = time;
Expand Down Expand Up @@ -166,13 +180,42 @@ 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).
* @param time time until the event occurs.
*/
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.
Expand Down Expand Up @@ -221,6 +264,9 @@ class WH_COMMON_API EventMap
DelayEvents(uint32(delay.count()), group);
}

/**
* @name DelayEventsToMax
*/
void DelayEventsToMax(uint32 delay, uint32 group);

/**
Expand Down

0 comments on commit 300e008

Please sign in to comment.