Leviathan  0.8.0.0
Leviathan game engine
Leviathan::RepeatingDelayedTask Class Reference

Encapsulates a function that is ran after a time period. More...

#include <QueuedTask.h>

+ Inheritance diagram for Leviathan::RepeatingDelayedTask:

Public Member Functions

DLLEXPORT RepeatingDelayedTask (std::function< void()> functorun, const MicrosecondDuration &bothdelays)
 
DLLEXPORT RepeatingDelayedTask (std::function< void()> functorun, const MicrosecondDuration &initialdelay, const MicrosecondDuration &followingduration)
 
virtual DLLEXPORT ~RepeatingDelayedTask ()
 
virtual DLLEXPORT bool IsRepeating ()
 Called by ThreadingManager to see if this task still wants to repeat. More...
 
DLLEXPORT void SetRepeatStatus (bool newvalue)
 Sets the variable ShouldRunAgain to newvalue. More...
 
- Public Member Functions inherited from Leviathan::DelayedTask
DLLEXPORT DelayedTask (std::function< void()> functorun, const MicrosecondDuration &delaytime)
 
DLLEXPORT DelayedTask (std::function< void()> functorun, const WantedClockType::time_point &executetime)
 
virtual DLLEXPORT ~DelayedTask ()
 
virtual DLLEXPORT bool CanBeRan (const QueuedTaskCheckValues *const checkvalues)
 Checks if the current time is past the time stamp. More...
 
- Public Member Functions inherited from Leviathan::QueuedTask
DLLEXPORT QueuedTask (std::function< void()> functorun)
 Takes in the function which is ran when the Task is ran. More...
 
virtual DLLEXPORT ~QueuedTask ()
 
virtual DLLEXPORT void RunTask ()
 Runs the stored function. More...
 
virtual DLLEXPORT bool MustBeRanBefore (int eventtypeidentifier)
 Function called by ThreadingManager before certain events to make proper tasks finish before certain operations. More...
 

Protected Member Functions

virtual void _PostFunctionRun ()
 Used to update the time when to run the task again. More...
 

Protected Attributes

MicrosecondDuration TimeBetweenExecutions
 
bool ShouldRunAgain
 Controls if the task should still run again. More...
 
- Protected Attributes inherited from Leviathan::DelayedTask
WantedClockType::time_point ExecutionTime
 The time after which this task may be ran. More...
 

Detailed Description

Encapsulates a function that is ran after a time period.

Warning
Function passed to this class should be thread safe
The passed task will be repeatedly ran until SetRepeatStatus is called with false (or ShouldRunAgain some other way set to false)
See also
SetRepeatStatus

Definition at line 160 of file QueuedTask.h.

Constructor & Destructor Documentation

◆ RepeatingDelayedTask() [1/2]

DLLEXPORT Leviathan::RepeatingDelayedTask::RepeatingDelayedTask ( std::function< void()>  functorun,
const MicrosecondDuration bothdelays 
)

Constructs a task that can be controlled when it can be ran and how many times it is ran

Parameters
bothdelaysIs the time before first execution AND the time between following executions
See also
DelayedTask

Definition at line 120 of file QueuedTask.cpp.

121  :
122  DelayedTask(functorun, bothdelays), TimeBetweenExecutions(bothdelays), ShouldRunAgain(true)
123 {
124 
125 }
bool ShouldRunAgain
Controls if the task should still run again.
Definition: QueuedTask.h:192
DLLEXPORT DelayedTask(std::function< void()> functorun, const MicrosecondDuration &delaytime)
Definition: QueuedTask.cpp:95
MicrosecondDuration TimeBetweenExecutions
Definition: QueuedTask.h:189

◆ RepeatingDelayedTask() [2/2]

DLLEXPORT Leviathan::RepeatingDelayedTask::RepeatingDelayedTask ( std::function< void()>  functorun,
const MicrosecondDuration initialdelay,
const MicrosecondDuration followingduration 
)

Constructs a task that can be controlled when it can be ran and how many times it is ran

Parameters
initialdelayIs the time before first execution
followingdurationIs the time between following executions
See also
DelayedTask

Definition at line 127 of file QueuedTask.cpp.

129  :
130  DelayedTask(functorun, initialdelay), TimeBetweenExecutions(followingduration),
131  ShouldRunAgain(true)
132 {
133 
134 }
bool ShouldRunAgain
Controls if the task should still run again.
Definition: QueuedTask.h:192
DLLEXPORT DelayedTask(std::function< void()> functorun, const MicrosecondDuration &delaytime)
Definition: QueuedTask.cpp:95
MicrosecondDuration TimeBetweenExecutions
Definition: QueuedTask.h:189

◆ ~RepeatingDelayedTask()

DLLEXPORT Leviathan::RepeatingDelayedTask::~RepeatingDelayedTask ( )
virtual

Definition at line 136 of file QueuedTask.cpp.

136  {
137 
138 }

Member Function Documentation

◆ _PostFunctionRun()

void Leviathan::RepeatingDelayedTask::_PostFunctionRun ( )
protectedvirtual

Used to update the time when to run the task again.

Reimplemented from Leviathan::QueuedTask.

Definition at line 148 of file QueuedTask.cpp.

148  {
149  // Set new execution point in time //
151 }
static DLLEXPORT WantedClockType::time_point GetThreadSafeSteadyTimePoint()
MicrosecondDuration TimeBetweenExecutions
Definition: QueuedTask.h:189
WantedClockType::time_point ExecutionTime
The time after which this task may be ran.
Definition: QueuedTask.h:151

◆ IsRepeating()

DLLEXPORT bool Leviathan::RepeatingDelayedTask::IsRepeating ( )
virtual

Called by ThreadingManager to see if this task still wants to repeat.

See also
SetRepeatStatus ShouldRunAgain

Reimplemented from Leviathan::QueuedTask.

Definition at line 140 of file QueuedTask.cpp.

140  {
141  return ShouldRunAgain;
142 }
bool ShouldRunAgain
Controls if the task should still run again.
Definition: QueuedTask.h:192

◆ SetRepeatStatus()

DLLEXPORT void Leviathan::RepeatingDelayedTask::SetRepeatStatus ( bool  newvalue)

Sets the variable ShouldRunAgain to newvalue.

Note
To call this from the task function use TaskThread::GetThreadSpecificThreadObject
See also
ThreadSpecificData ThreadSpecificData::QuickTaskAccess

Definition at line 144 of file QueuedTask.cpp.

144  {
145  ShouldRunAgain = newvalue;
146 }
bool ShouldRunAgain
Controls if the task should still run again.
Definition: QueuedTask.h:192

Member Data Documentation

◆ ShouldRunAgain

bool Leviathan::RepeatingDelayedTask::ShouldRunAgain
protected

Controls if the task should still run again.

Definition at line 192 of file QueuedTask.h.

◆ TimeBetweenExecutions

MicrosecondDuration Leviathan::RepeatingDelayedTask::TimeBetweenExecutions
protected

Definition at line 189 of file QueuedTask.h.


The documentation for this class was generated from the following files: