diff options
| author | Naios <naios-dev@live.de> | 2015-07-22 01:48:11 +0200 | 
|---|---|---|
| committer | Naios <naios-dev@live.de> | 2015-07-22 01:56:12 +0200 | 
| commit | e4e55a3dcbd846fd583b4fc86344d88ca63588d7 (patch) | |
| tree | 01f23f319ca7ced8037f1775158e5ad1a3f552c8 /src | |
| parent | 4904318c43567277f2d32c758724e82874f29849 (diff) | |
Core/Utilities: Add std::chrono::duration overloads to EventMap.
* makes it possible to write:
```c++
events.ScheduleEvent(1, Seconds(10));
// ... or ...
events.ScheduleEvent(2, Minutes(1) + Seconds(20));
// ... or with C++14 support:
events.ScheduleEvent(2, 45s);
```
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/shared/Utilities/EventMap.h | 73 | 
1 files changed, 71 insertions, 2 deletions
diff --git a/src/server/shared/Utilities/EventMap.h b/src/server/shared/Utilities/EventMap.h index a12cfc0cb4d..790a25a0b63 100644 --- a/src/server/shared/Utilities/EventMap.h +++ b/src/server/shared/Utilities/EventMap.h @@ -19,6 +19,7 @@  #define _EVENT_MAP_H_  #include "Common.h" +#include "Duration.h"  class EventMap  { @@ -47,7 +48,7 @@ public:      /**      * @name Update      * @brief Updates the timer of the event map. -    * @param time Value to be added to time. +    * @param time Value in ms to be added to time.      */      void Update(uint32 time)      { @@ -56,7 +57,7 @@ public:      /**      * @name GetTimer -    * @return Current timer value. +    * @return Current timer in ms value.      */      uint32 GetTimer() const      { @@ -114,6 +115,19 @@ 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 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& time, uint32 group = 0, uint8 phase = 0) +    { +        ScheduleEvent(eventId, time.count(), group, phase); +    } + +    /** +    * @name ScheduleEvent +    * @brief Creates new event entry in map. +    * @param eventId The id of the new event.      * @param time The time in milliseconds until the event occurs.      * @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. @@ -124,6 +138,19 @@ 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 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& time, uint32 group = 0, uint8 phase = 0) +    { +        RescheduleEvent(eventId, time.count(), group, phase); +    } + +    /** +    * @name RescheduleEvent +    * @brief Cancels the given event and reschedules it. +    * @param eventId The id of the event.      * @param time The time in milliseconds until the event occurs.      * @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. @@ -137,6 +164,16 @@ public:      /**      * @name RepeatEvent      * @brief Repeats the mostly recently executed event. +    * @param time Time until in milliseconds as std::chrono::duration the event occurs. +    */ +    void Repeat(Milliseconds const& time) +    { +        Repeat(time.count()); +    } + +    /** +    * @name RepeatEvent +    * @brief Repeats the mostly recently executed event.      * @param time Time until the event occurs.      */      void Repeat(uint32 time) @@ -146,6 +183,17 @@ public:      /**      * @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 Repeat(Milliseconds const& minTime, Milliseconds const& maxTime) +    { +        Repeat(minTime.count(), 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. @@ -165,6 +213,16 @@ public:      /**      * @name DelayEvents      * @brief Delays all events in the map. If delay is greater than or equal internal timer, delay will be 0. +    * @param delay Amount of delay in ms as std::chrono::duration. +    */ +    void DelayEvents(Milliseconds const& delay) +    { +        DelayEvents(delay.count()); +    } + +    /** +    * @name DelayEvents +    * @brief Delays all events in the map. If delay is greater than or equal internal timer, delay will be 0.      * @param delay Amount of delay.      */      void DelayEvents(uint32 delay) @@ -175,6 +233,17 @@ public:      /**      * @name DelayEvents      * @brief Delay all events of the same group. +    * @param delay Amount of delay in ms as std::chrono::duration. +    * @param group Group of the events. +    */ +    void DelayEvents(Milliseconds const& delay, uint32 group) +    { +        DelayEvents(delay.count(), group); +    } + +    /** +    * @name DelayEvents +    * @brief Delay all events of the same group.      * @param delay Amount of delay.      * @param group Group of the events.      */  | 
