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 103 of file QueuedTask.cpp.

104  :
105  DelayedTask(functorun, bothdelays),
106  TimeBetweenExecutions(bothdelays), ShouldRunAgain(true)
107 {}
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:83
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 109 of file QueuedTask.cpp.

111  :
112  DelayedTask(functorun, initialdelay),
113  TimeBetweenExecutions(followingduration), ShouldRunAgain(true)
114 {}
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:83
MicrosecondDuration TimeBetweenExecutions
Definition: QueuedTask.h:189

◆ ~RepeatingDelayedTask()

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

Definition at line 116 of file QueuedTask.cpp.

116 {}

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 128 of file QueuedTask.cpp.

129 {
130  // Set new execution point in time //
132 }
MicrosecondDuration TimeBetweenExecutions
Definition: QueuedTask.h:189
static DLLEXPORT TimePoint GetCurrentTimePoint()
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 118 of file QueuedTask.cpp.

119 {
120  return ShouldRunAgain;
121 }
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 123 of file QueuedTask.cpp.

124 {
125  ShouldRunAgain = newvalue;
126 }
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: