Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ConditionalDelayedTask Class Reference

Encapsulates a function that can later be ran in a free thread. More...

#include <QueuedTask.h>

+ Inheritance diagram for Leviathan::ConditionalDelayedTask:

Public Member Functions

DLLEXPORT ConditionalDelayedTask (std::function< void()> functorun, std::function< bool()> canberuncheck, const MicrosecondDuration &delaytime)
 
virtual DLLEXPORT ~ConditionalDelayedTask ()
 
virtual DLLEXPORT bool CanBeRan (const QueuedTaskCheckValues *const checkvalues)
 Calls the checking function to see if the task can be ran. 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...
 
virtual DLLEXPORT bool IsRepeating ()
 Function called by ThreadingManager AFTER running the task //. More...
 

Protected Attributes

std::function< bool()> TaskCheckingFunc
 The function for checking if the task is allowed to be run. More...
 
WantedClockType::time_point CheckingTime
 The time after which this task may be checked again. More...
 
MicrosecondDuration DelayBetweenChecks
 The delay between checks. More...
 

Detailed Description

Encapsulates a function that can later be ran in a free thread.

Warning
Function passed to this class should be thread safe

Definition at line 102 of file QueuedTask.h.

Constructor & Destructor Documentation

◆ ConditionalDelayedTask()

DLLEXPORT Leviathan::ConditionalDelayedTask::ConditionalDelayedTask ( std::function< void()>  functorun,
std::function< bool()>  canberuncheck,
const MicrosecondDuration delaytime 
)

Constructs a task that can be controlled when it can be ran with an additional check to skip checking too often

Parameters
delaytimeThe time between checks; time that needs to pass before checking again
canberuncheckIs ran when CanBeRan is called, so it should be relatively cheap to call

Definition at line 68 of file QueuedTask.cpp.

70  :
71  QueuedTask(functorun), TaskCheckingFunc(canberuncheck),
73 {
74 
75 }
static DLLEXPORT WantedClockType::time_point GetThreadSafeSteadyTimePoint()
std::function< bool()> TaskCheckingFunc
The function for checking if the task is allowed to be run.
Definition: QueuedTask.h:119
DLLEXPORT QueuedTask(std::function< void()> functorun)
Takes in the function which is ran when the Task is ran.
Definition: QueuedTask.cpp:6
MicrosecondDuration DelayBetweenChecks
The delay between checks.
Definition: QueuedTask.h:125
WantedClockType::time_point CheckingTime
The time after which this task may be checked again.
Definition: QueuedTask.h:122

◆ ~ConditionalDelayedTask()

DLLEXPORT Leviathan::ConditionalDelayedTask::~ConditionalDelayedTask ( )
virtual

Definition at line 77 of file QueuedTask.cpp.

77  {
78 
79 }

Member Function Documentation

◆ CanBeRan()

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

Calls the checking function to see if the task can be ran.

Reimplemented from Leviathan::QueuedTask.

Definition at line 81 of file QueuedTask.cpp.

83 {
84  // Check is it too early //
85  if(checkvalues->CurrentTime < CheckingTime)
86  return false;
87 
88  // Adjust the next check time //
90 
91  // Run the checking function //
92  return TaskCheckingFunc();
93 }
static DLLEXPORT WantedClockType::time_point GetThreadSafeSteadyTimePoint()
std::function< bool()> TaskCheckingFunc
The function for checking if the task is allowed to be run.
Definition: QueuedTask.h:119
MicrosecondDuration DelayBetweenChecks
The delay between checks.
Definition: QueuedTask.h:125
WantedClockType::time_point CheckingTime
The time after which this task may be checked again.
Definition: QueuedTask.h:122
WantedClockType::time_point CurrentTime
Time the task set iteration started (may be slightly off, but it doesn&#39;t matter) //.
Definition: QueuedTask.h:27

Member Data Documentation

◆ CheckingTime

WantedClockType::time_point Leviathan::ConditionalDelayedTask::CheckingTime
protected

The time after which this task may be checked again.

Definition at line 122 of file QueuedTask.h.

◆ DelayBetweenChecks

MicrosecondDuration Leviathan::ConditionalDelayedTask::DelayBetweenChecks
protected

The delay between checks.

Definition at line 125 of file QueuedTask.h.

◆ TaskCheckingFunc

std::function<bool ()> Leviathan::ConditionalDelayedTask::TaskCheckingFunc
protected

The function for checking if the task is allowed to be run.

Definition at line 119 of file QueuedTask.h.


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