mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-18 00:18:43 +01:00
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); ```
This commit is contained in:
@@ -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
|
||||
{
|
||||
@@ -110,6 +111,19 @@ public:
|
||||
_phase &= uint8(~(1 << (phase - 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
@@ -120,6 +134,19 @@ public:
|
||||
*/
|
||||
void ScheduleEvent(uint32 eventId, uint32 time, uint32 group = 0, uint8 phase = 0);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
@@ -134,6 +161,16 @@ public:
|
||||
ScheduleEvent(eventId, time, group, phase);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
@@ -144,6 +181,17 @@ public:
|
||||
_eventMap.insert(EventStore::value_type(_time + time, _lastEvent));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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).
|
||||
@@ -162,6 +210,16 @@ public:
|
||||
*/
|
||||
uint32 ExecuteEvent();
|
||||
|
||||
/**
|
||||
* @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.
|
||||
@@ -172,6 +230,17 @@ public:
|
||||
_time = delay < _time ? _time - delay : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
|
||||
Reference in New Issue
Block a user