Leviathan  0.8.0.0
Leviathan game engine
Leviathan::RepeatCountedTask Class Reference

Encapsulates a function that is ran certain amount of times. More...

#include <QueuedTask.h>

+ Inheritance diagram for Leviathan::RepeatCountedTask:

Public Member Functions

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 CanBeRan (const QueuedTaskCheckValues *const checkvalues)
 Function called by ThreadingManager before running this task. More...
 
virtual DLLEXPORT bool MustBeRanBefore (int eventtypeidentifier)
 Function called by ThreadingManager before certain events to make proper tasks finish before certain operations. More...
 

Protected Attributes

size_t MaxRepeats
 Holds the maximum run count. More...
 
size_t RepeatedCount
 

Detailed Description

Encapsulates a function that is ran certain amount of times.

Warning
Function passed to this class should be thread safe
Todo:
Merge common parts from this and RepeatCountedDelayedTask

Definition at line 199 of file QueuedTask.h.

Constructor & Destructor Documentation

◆ RepeatCountedTask()

DLLEXPORT Leviathan::RepeatCountedTask::RepeatCountedTask ( std::function< void()>  functorun,
size_t  repeatcount 
)

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

Parameters
repeatcountThe task is ran this specified times, or the task calls StopRepeating before that

Definition at line 134 of file QueuedTask.cpp.

135  :
136  QueuedTask(functorun),
137  MaxRepeats(repeatcount), RepeatedCount(0)
138 {}
DLLEXPORT QueuedTask(std::function< void()> functorun)
Takes in the function which is ran when the Task is ran.
Definition: QueuedTask.cpp:6
size_t MaxRepeats
Holds the maximum run count.
Definition: QueuedTask.h:229

◆ ~RepeatCountedTask()

DLLEXPORT Leviathan::RepeatCountedTask::~RepeatCountedTask ( )
virtual

Definition at line 140 of file QueuedTask.cpp.

140 {}

Member Function Documentation

◆ GetRepeatCount()

DLLEXPORT size_t Leviathan::RepeatCountedTask::GetRepeatCount ( ) const

Gets the number of repeats done.

Note
This will only be accurate if IsRepeating is only called once per repeat

Definition at line 154 of file QueuedTask.cpp.

155 {
156  return RepeatedCount;
157 }

◆ IsRepeating()

DLLEXPORT bool Leviathan::RepeatCountedTask::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 142 of file QueuedTask.cpp.

143 {
144  // Increment count and see if there are still repeats left //
145  return ++RepeatedCount < MaxRepeats;
146 }
size_t MaxRepeats
Holds the maximum run count.
Definition: QueuedTask.h:229

◆ IsThisLastRepeat()

DLLEXPORT bool Leviathan::RepeatCountedTask::IsThisLastRepeat ( ) const

Checks if this is the last repeat.

This is done by checking RepeatedCount+1 >= MaxRepeats

Definition at line 159 of file QueuedTask.cpp.

160 {
161  return RepeatedCount + 1 >= MaxRepeats;
162 }
size_t MaxRepeats
Holds the maximum run count.
Definition: QueuedTask.h:229

◆ StopRepeating()

DLLEXPORT void Leviathan::RepeatCountedTask::StopRepeating ( )

Stops repeating this function after this call.

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

Definition at line 148 of file QueuedTask.cpp.

149 {
150  // This should do the trick //
151  MaxRepeats = 0;
152 }
size_t MaxRepeats
Holds the maximum run count.
Definition: QueuedTask.h:229

Member Data Documentation

◆ MaxRepeats

size_t Leviathan::RepeatCountedTask::MaxRepeats
protected

Holds the maximum run count.

Definition at line 229 of file QueuedTask.h.

◆ RepeatedCount

size_t Leviathan::RepeatCountedTask::RepeatedCount
protected

Keeps track of how many times the task has been ran

See also
IsRepeating

Definition at line 233 of file QueuedTask.h.


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