Leviathan  0.8.0.0
Leviathan game engine
Leviathan::RepeatCountedDelayedTask Class Reference

Encapsulates a function that is ran after a time period and repeated certain amount. More...

#include <QueuedTask.h>

+ Inheritance diagram for Leviathan::RepeatCountedDelayedTask:

Public Member Functions

DLLEXPORT RepeatCountedDelayedTask (std::function< void()> functorun, const MicrosecondDuration &bothdelays, int repeatcount)
 
DLLEXPORT RepeatCountedDelayedTask (std::function< void()> functorun, const MicrosecondDuration &initialdelay, const MicrosecondDuration &followingduration, int repeatcount)
 
virtual DLLEXPORT ~RepeatCountedDelayedTask ()
 
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::RepeatCountedTask
DLLEXPORT RepeatCountedTask (std::function< void()> functorun, size_t repeatcount)
 
virtual DLLEXPORT ~RepeatCountedTask ()
 
virtual DLLEXPORT bool IsRepeating ()
 Called by ThreadingManager to see if this task still wants to repeat. More...
 
DLLEXPORT void StopRepeating ()
 Stops repeating this function after this call. More...
 
DLLEXPORT size_t GetRepeatCount () const
 Gets the number of repeats done. More...
 
DLLEXPORT bool IsThisLastRepeat () const
 Checks if this is the last repeat. 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
 Time between executions. More...
 
WantedClockType::time_point ExecutionTime
 The timepoint after which this function can be ran. More...
 
- Protected Attributes inherited from Leviathan::RepeatCountedTask
size_t MaxRepeats
 Holds the maximum run count. More...
 
size_t RepeatedCount
 

Detailed Description

Encapsulates a function that is ran after a time period and repeated certain amount.

Warning
Function passed to this class should be thread safe

Definition at line 238 of file QueuedTask.h.

Constructor & Destructor Documentation

◆ RepeatCountedDelayedTask() [1/2]

DLLEXPORT Leviathan::RepeatCountedDelayedTask::RepeatCountedDelayedTask ( std::function< void()>  functorun,
const MicrosecondDuration bothdelays,
int  repeatcount 
)

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
repeatcountThe task is ran this specified times, or the task calls StopRepeating before that
See also
DelayedTask

Definition at line 164 of file QueuedTask.cpp.

165  :
166  RepeatCountedTask(functorun, repeatcount),
168 {}
MicrosecondDuration TimeBetweenExecutions
Time between executions.
Definition: QueuedTask.h:269
WantedClockType::time_point ExecutionTime
The timepoint after which this function can be ran.
Definition: QueuedTask.h:272
DLLEXPORT RepeatCountedTask(std::function< void()> functorun, size_t repeatcount)
Definition: QueuedTask.cpp:134
static DLLEXPORT TimePoint GetCurrentTimePoint()

◆ RepeatCountedDelayedTask() [2/2]

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

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
repeatcountThe task is ran this specified times, or the task calls StopRepeating before that
See also
DelayedTask

Definition at line 170 of file QueuedTask.cpp.

172  :
173  RepeatCountedTask(functorun, repeatcount),
174  TimeBetweenExecutions(followingduration),
175  ExecutionTime(Time::GetCurrentTimePoint() + initialdelay)
176 {}
MicrosecondDuration TimeBetweenExecutions
Time between executions.
Definition: QueuedTask.h:269
WantedClockType::time_point ExecutionTime
The timepoint after which this function can be ran.
Definition: QueuedTask.h:272
DLLEXPORT RepeatCountedTask(std::function< void()> functorun, size_t repeatcount)
Definition: QueuedTask.cpp:134
static DLLEXPORT TimePoint GetCurrentTimePoint()

◆ ~RepeatCountedDelayedTask()

DLLEXPORT Leviathan::RepeatCountedDelayedTask::~RepeatCountedDelayedTask ( )
virtual

Definition at line 178 of file QueuedTask.cpp.

178 {}

Member Function Documentation

◆ _PostFunctionRun()

void Leviathan::RepeatCountedDelayedTask::_PostFunctionRun ( )
protectedvirtual

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

Reimplemented from Leviathan::QueuedTask.

Definition at line 187 of file QueuedTask.cpp.

188 {
189  // Set new execution point in time //
191 }
MicrosecondDuration TimeBetweenExecutions
Time between executions.
Definition: QueuedTask.h:269
WantedClockType::time_point ExecutionTime
The timepoint after which this function can be ran.
Definition: QueuedTask.h:272
static DLLEXPORT TimePoint GetCurrentTimePoint()

◆ CanBeRan()

DLLEXPORT bool Leviathan::RepeatCountedDelayedTask::CanBeRan ( const QueuedTaskCheckValues *const  checkvalues)
virtual

Checks if the current time is past the time stamp.

Controlled by the value of ExecutionTime

Reimplemented from Leviathan::QueuedTask.

Definition at line 180 of file QueuedTask.cpp.

182 {
183  // Check is the current time past our timestamp //
184  return checkvalues->CurrentTime >= ExecutionTime;
185 }
WantedClockType::time_point ExecutionTime
The timepoint after which this function can be ran.
Definition: QueuedTask.h:272
WantedClockType::time_point CurrentTime
Time the task set iteration started (may be slightly off, but it doesn't matter) //.
Definition: QueuedTask.h:27

Member Data Documentation

◆ ExecutionTime

WantedClockType::time_point Leviathan::RepeatCountedDelayedTask::ExecutionTime
protected

The timepoint after which this function can be ran.

Definition at line 272 of file QueuedTask.h.

◆ TimeBetweenExecutions

MicrosecondDuration Leviathan::RepeatCountedDelayedTask::TimeBetweenExecutions
protected

Time between executions.

Definition at line 269 of file QueuedTask.h.


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