Horizon Official Technical Documentation
|
|
#include <TaskScheduler.hpp>
Public Member Functions | |
TaskContext () | |
TaskContext (TaskScheduler::TaskContainer &&task, std::weak_ptr< TaskScheduler > &&owner) | |
TaskContext (TaskContext &&right) | |
TaskContext & | operator= (TaskContext &&right) |
bool | IsExpired () const |
Returns true if the owner was deallocated and this context has expired. More... | |
bool | IsInGroup (TaskScheduler::group_t const group) const |
Returns true if the event is in the given group. More... | |
TaskContext & | SetGroup (TaskScheduler::group_t const group) |
Sets the event in the given group. More... | |
TaskContext & | ClearGroup () |
Removes the group from the event. More... | |
TaskScheduler::repeated_t | GetRepeatCounter () const |
Returns the repeat counter which increases every time the task is repeated. More... | |
template<typename _Rep , typename _Period > | |
TaskContext & | Repeat (std::chrono::duration< _Rep, _Period > const &duration) |
Repeats the event and sets a new duration. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context! More... | |
TaskContext & | Repeat () |
Repeats the event with the same duration. This will consume the task context, its not possible to repeat the task again from the same task context! More... | |
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight > | |
TaskContext & | Repeat (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
Repeats the event and set a new duration that is randomized between min and max. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context! More... | |
TaskContext & | Async (std::function< void()> const &callable) |
Schedule a callable function that is executed at the next update tick from within the context. Its safe to modify the TaskScheduler from within the callable. More... | |
template<typename _Rep , typename _Period > | |
TaskContext & | Schedule (std::chrono::duration< _Rep, _Period > const &time, TaskScheduler::task_handler_t const &task) |
Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick. More... | |
template<typename _Rep , typename _Period > | |
TaskContext & | Schedule (std::chrono::duration< _Rep, _Period > const &time, TaskScheduler::group_t const group, TaskScheduler::task_handler_t const &task) |
Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick. More... | |
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight > | |
TaskContext & | Schedule (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max, TaskScheduler::task_handler_t const &task) |
Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick. More... | |
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight > | |
TaskContext & | Schedule (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max, TaskScheduler::group_t const group, TaskScheduler::task_handler_t const &task) |
Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick. More... | |
TaskContext & | CancelAll () |
Cancels all tasks from within the context. More... | |
TaskContext & | CancelGroup (TaskScheduler::group_t const group) |
Cancel all tasks of a single group from within the context. More... | |
TaskContext & | CancelGroupsOf (std::vector< TaskScheduler::group_t > const &groups) |
Cancels all groups in the given std::vector from within the context. Hint: Use std::initializer_list for this: "{1, 2, 3, 4}". More... | |
template<typename _Rep , typename _Period > | |
TaskContext & | DelayAll (std::chrono::duration< _Rep, _Period > const &duration) |
Delays all tasks with the given duration from within the context. More... | |
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight > | |
TaskContext & | DelayAll (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
Delays all tasks with a random duration between min and max from within the context. More... | |
template<typename _Rep , typename _Period > | |
TaskContext & | DelayGroup (TaskScheduler::group_t const group, std::chrono::duration< _Rep, _Period > const &duration) |
Delays all tasks of a group with the given duration from within the context. More... | |
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight > | |
TaskContext & | DelayGroup (TaskScheduler::group_t const group, std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
Delays all tasks of a group with a random duration between min and max from within the context. More... | |
template<typename _Rep , typename _Period > | |
TaskContext & | RescheduleAll (std::chrono::duration< _Rep, _Period > const &duration) |
Reschedule all tasks with the given duration. More... | |
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight > | |
TaskContext & | RescheduleAll (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
Reschedule all tasks with a random duration between min and max. More... | |
template<typename _Rep , typename _Period > | |
TaskContext & | RescheduleGroup (TaskScheduler::group_t const group, std::chrono::duration< _Rep, _Period > const &duration) |
Reschedule all tasks of a group with the given duration. More... | |
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight > | |
TaskContext & | RescheduleGroup (TaskScheduler::group_t const group, std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
Reschedule all tasks of a group with a random duration between min and max. More... | |
Private Member Functions | |
TaskContext & | Dispatch (std::function< TaskScheduler &(TaskScheduler &)> const &apply) |
Dispatches an action safe on the TaskScheduler. More... | |
TaskContext & | operator= (TaskContext const &right) |
TaskContext (TaskContext const &right) | |
void | ThrowOnConsumed () const |
Throws std::logic_error if the task was consumed already. More... | |
void | Invoke () |
Invokes the associated hook of the task. More... | |
Private Attributes | |
TaskScheduler::TaskContainer | _task |
Associated task. More... | |
std::weak_ptr< TaskScheduler > | _owner |
Owner. More... | |
std::shared_ptr< bool > | _consumed |
Marks the task as consumed. More... | |
Friends | |
class | TaskScheduler |
|
inlineprivate |
|
inline |
|
inlineexplicit |
|
inline |
TaskContext & TaskContext::Async | ( | std::function< void()> const & | callable | ) |
Schedule a callable function that is executed at the next update tick from within the context. Its safe to modify the TaskScheduler from within the callable.
References TaskScheduler::Async(), and TaskScheduler::Dispatch().
TaskContext & TaskContext::CancelAll | ( | ) |
Cancels all tasks from within the context.
References TaskScheduler::CancelAll(), and TaskScheduler::Dispatch().
TaskContext & TaskContext::CancelGroup | ( | TaskScheduler::group_t const | group | ) |
Cancel all tasks of a single group from within the context.
References TaskScheduler::CancelGroup(), and TaskScheduler::Dispatch().
TaskContext & TaskContext::CancelGroupsOf | ( | std::vector< TaskScheduler::group_t > const & | groups | ) |
Cancels all groups in the given std::vector from within the context. Hint: Use std::initializer_list for this: "{1, 2, 3, 4}".
References TaskScheduler::CancelGroupsOf(), and TaskScheduler::Dispatch().
TaskContext & TaskContext::ClearGroup | ( | ) |
Removes the group from the event.
|
inline |
Delays all tasks with the given duration from within the context.
References Dispatch().
Referenced by DelayAll().
|
inline |
Delays all tasks with a random duration between min and max from within the context.
References DelayAll(), and TaskScheduler::RandomDurationBetween().
|
inline |
Delays all tasks of a group with the given duration from within the context.
References Dispatch().
Referenced by DelayGroup().
|
inline |
Delays all tasks of a group with a random duration between min and max from within the context.
References DelayGroup(), and TaskScheduler::RandomDurationBetween().
|
private |
Dispatches an action safe on the TaskScheduler.
References ByteConverter::apply().
Referenced by DelayAll(), DelayGroup(), Repeat(), RescheduleAll(), RescheduleGroup(), and Schedule().
TaskScheduler::repeated_t TaskContext::GetRepeatCounter | ( | ) | const |
Returns the repeat counter which increases every time the task is repeated.
|
private |
Invokes the associated hook of the task.
Referenced by TaskScheduler::Dispatch().
bool TaskContext::IsExpired | ( | ) | const |
Returns true if the owner was deallocated and this context has expired.
bool TaskContext::IsInGroup | ( | TaskScheduler::group_t const | group | ) | const |
Returns true if the event is in the given group.
|
inline |
|
inlineprivate |
|
inline |
Repeats the event with the same duration. This will consume the task context, its not possible to repeat the task again from the same task context!
References _task, Dispatch(), TaskScheduler::InsertTask(), and ThrowOnConsumed().
Referenced by Repeat().
|
inline |
Repeats the event and sets a new duration. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context!
References _task, TaskScheduler::MakeDurationCalculator(), and Repeat().
Referenced by Horizon::Zone::Unit::attack(), BOOST_AUTO_TEST_CASE(), Horizon::Zone::Units::Monster::initialize(), Horizon::Zone::ZoneKernel::initialize(), Horizon::Auth::AuthServer::initialize(), Horizon::Char::CharServer::initialize(), Horizon::Zone::Unit::status_effect_start(), and Horizon::Zone::Unit::walk().
|
inline |
Repeats the event and set a new duration that is randomized between min and max. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context!
References _task, TaskScheduler::MakeDurationCalculator(), and Repeat().
|
inline |
Reschedule all tasks with the given duration.
References _task, Dispatch(), and TaskScheduler::RescheduleAt().
Referenced by RescheduleAll().
|
inline |
Reschedule all tasks with a random duration between min and max.
References TaskScheduler::RandomDurationBetween(), and RescheduleAll().
|
inline |
Reschedule all tasks of a group with the given duration.
References _task, Dispatch(), and TaskScheduler::RescheduleAtWithPredicate().
Referenced by RescheduleGroup().
|
inline |
Reschedule all tasks of a group with a random duration between min and max.
References TaskScheduler::RandomDurationBetween(), and RescheduleGroup().
|
inline |
Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.
References _task, Dispatch(), TaskScheduler::MakeDurationCalculator(), and TaskScheduler::ScheduleAt().
|
inline |
Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.
References _task, Dispatch(), TaskScheduler::MakeDurationCalculator(), and TaskScheduler::ScheduleAt().
|
inline |
Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.
References _task, Dispatch(), TaskScheduler::MakeDurationCalculator(), and TaskScheduler::ScheduleAt().
|
inline |
Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.
References _task, Dispatch(), TaskScheduler::MakeDurationCalculator(), and TaskScheduler::ScheduleAt().
TaskContext & TaskContext::SetGroup | ( | TaskScheduler::group_t const | group | ) |
Sets the event in the given group.
|
private |
|
friend |
|
private |
Marks the task as consumed.
Referenced by operator=().
|
private |
Owner.
Referenced by operator=().
|
private |
Associated task.
Referenced by operator=(), Repeat(), RescheduleAll(), RescheduleGroup(), and Schedule().