DustyEngine::TaskTree Class Reference

TaskTree creates a general tree of tasks. More...

#include <dustytasktree.h>

List of all members.

Public Member Functions

 TaskTree (irr::IrrlichtDevice *device, DustyEngine::DustyDriver *driver)
 Constructor does nothing but initialize the tree and create a root task.
virtual ~TaskTree ()
 Destructor will completely clear out the tree, deleting and drop()ing all tasks.
void AddTask (DustyEngine::Task *task, DustyEngine::Task *parent=NULL, irr::u32 priority=0, bool paused=false, bool executeMultiple=false, irr::u32 lifetimeExecutions=0, irr::u32 lifetimeMS=0)
 AddTask adds a task to the tree.
void PauseTask (DustyEngine::Task *task, irr::u32 timeToStayPaused=0, irr::u32 timeToStayUnpaused=0)
void UnpauseTask (DustyEngine::Task *task, irr::u32 timeToStayUnpaused=0, irr::u32 timeToStayPaused=0)
void DestroyTask (DustyEngine::Task *task)
void PauseChildren (DustyEngine::Task *task, irr::u32 timeToStayPaused=0, irr::u32 timeToStayUnpaused=0)
void UnpauseChildren (DustyEngine::Task *task, irr::u32 timeToStayUnpaused=0, irr::u32 timeToStayPaused=0)
void DestroyChildren (DustyEngine::Task *task)
void ClearTree ()
 ClearTree() destroys all tasks in the tree.
void DoUpdates ()
 DoUpdates() updates all the tasks in the tree.
void PauseTree ()
 PauseTree() pauses the entire tree.
void UnpauseTree ()
 UnpauseTree() unpauses the entire tree.
bool IsPaused ()
bool IsRunning ()
void StopTree ()
 StopTree() will cause the tree to not update tasks when OnUpdate() is called.
void StartTree ()
 StartTree() will allow the tree to update tasks when OnUpdate() is called.
irr::u32 NumTasks ()

Protected Member Functions

void DeleteTasks ()
void UpdateChildren (DustyEngine::Task *task)
void UpdateTask (DustyEngine::Task *task)
void FlagTaskForDeletion (DustyEngine::Task *task)

Protected Attributes

DustyEngine::DummyTaskroot
irr::IrrlichtDevice * irrlichtDevice
DustyEngine::DustyDriverdustyDriver
bool isRunning
irr::u32 numTasks
irr::core::list< DustyEngine::Task * > tasksToDelete


Detailed Description

TaskTree creates a general tree of tasks.

TaskTree maintains a tree of tasks. The tasks have a parent-affects-child relationship, meaning if the parent task is paused, the children of the parent will not execute. If a parent task is dropped from the tree, the children tasks will also be dropped. This is very useful in game development where one entity (or process) depends upon another for execution. Tasks in the tree are referenced by pointers to the task, but the task tree is responsible for all executions such as Pausing/Unpausing/Executing/Deleting them. The task tree guarantees seamless pausing/unpausing of tasks, as well as preorder execution of parent/children tasks.

Definition at line 52 of file dustytasktree.h.


Constructor & Destructor Documentation

DustyEngine::TaskTree::TaskTree irr::IrrlichtDevice *  device,
DustyEngine::DustyDriver driver
 

Constructor does nothing but initialize the tree and create a root task.

virtual DustyEngine::TaskTree::~TaskTree  )  [virtual]
 

Destructor will completely clear out the tree, deleting and drop()ing all tasks.


Member Function Documentation

void DustyEngine::TaskTree::AddTask DustyEngine::Task task,
DustyEngine::Task parent = NULL,
irr::u32  priority = 0,
bool  paused = false,
bool  executeMultiple = false,
irr::u32  lifetimeExecutions = 0,
irr::u32  lifetimeMS = 0
 

AddTask adds a task to the tree.

Parameters:
task,: The task to add to the tree.
parent,: The task that is the parent of this task.
priority,: If priority is 0, then the task will be executed every time DoUpdates() is called. If not, then priority is the number of milliseconds between updates of the task.
paused,: If paused is true, then the task will be paused immediately after it is created.
executeMultiple,: If executeMultiple is true, then the task could possibly execute multiple times when OnUpdate() is called, if enough time has passed that it missed regular execution.
lifetimeExecutions,: The number of times the task should be executed by the tree. When the task has been executed that many times, it is automatically removed from the tree and task's OnLifetimeExpired() is called.
lifetimeMS,: The number of milliseconds the task should remain on the tree. When that amount of time has passed (discounting time that the task was paused) the task will be automatically removed from the tree, and OnLifetimeExpired() is called.

void DustyEngine::TaskTree::ClearTree  ) 
 

ClearTree() destroys all tasks in the tree.

void DustyEngine::TaskTree::DeleteTasks  )  [protected]
 

void DustyEngine::TaskTree::DestroyChildren DustyEngine::Task task  ) 
 

DestroyChildren() destroys all the children of the task, but does not destroy the task. Also destroys childrens' children, and so on.

Parameters:
task,: The task whose children should be destroyed.

void DustyEngine::TaskTree::DestroyTask DustyEngine::Task task  ) 
 

DestroyTask() will remove the task from the tree and also remove it from its parent. The Parent's OnRemoveChild() is called, and the task's OnDestruction() is called. All children of the task are also destroyed.

Parameters:
task,: The task to destroy.

void DustyEngine::TaskTree::DoUpdates  ) 
 

DoUpdates() updates all the tasks in the tree.

DoUpdates() iterates through the tree in a pre-order fashion. It checks to see if a task is ready to be updated. A task is ready to be updated when time equal to or greater than the task's priority has passed (in milliseconds) or if the task is set to update every frame. If a task is ready to update, the task's OnUpdate() function is called. Any tasks that are set to be deleted will be deleted when this function is called, and again tasks will be deleted after the updates have completed (not the same ones, of course.)

void DustyEngine::TaskTree::FlagTaskForDeletion DustyEngine::Task task  )  [protected]
 

bool DustyEngine::TaskTree::IsPaused  ) 
 

IsPaused() returns whether the tree has been paused by calling PauseTree() or not.

Returns:
Returns true if the tree is paused, false if not.

bool DustyEngine::TaskTree::IsRunning  )  [inline]
 

IsRunning() returns whether or not the tree has been stopped by StopTree() or is running.

Returns:
Returns true if the tree is running, false if not.

Definition at line 124 of file dustytasktree.h.

irr::u32 DustyEngine::TaskTree::NumTasks  )  [inline]
 

NumTasks() returns the number of tasks stored on the tree.

Returns:
Returns a count of the tasks on the tree. Note this only counts tasks added with AddTask. ALWAYS USE ADDTASK!

Definition at line 143 of file dustytasktree.h.

void DustyEngine::TaskTree::PauseChildren DustyEngine::Task task,
irr::u32  timeToStayPaused = 0,
irr::u32  timeToStayUnpaused = 0
 

PauseChildren() pauses all the children of the task, but does not pause the task. Also pauses childrens' children, and so on.

Parameters:
task,: The task whose children should be paused.

void DustyEngine::TaskTree::PauseTask DustyEngine::Task task,
irr::u32  timeToStayPaused = 0,
irr::u32  timeToStayUnpaused = 0
 

PauseTask() will pause the given task as well as all its children.

Parameters:
task,: The task to pause.

void DustyEngine::TaskTree::PauseTree  ) 
 

PauseTree() pauses the entire tree.

void DustyEngine::TaskTree::StartTree  )  [inline]
 

StartTree() will allow the tree to update tasks when OnUpdate() is called.

Definition at line 136 of file dustytasktree.h.

void DustyEngine::TaskTree::StopTree  )  [inline]
 

StopTree() will cause the tree to not update tasks when OnUpdate() is called.

Definition at line 130 of file dustytasktree.h.

void DustyEngine::TaskTree::UnpauseChildren DustyEngine::Task task,
irr::u32  timeToStayUnpaused = 0,
irr::u32  timeToStayPaused = 0
 

UnpauseChildren() unpauses all the children of the task, but does not unpause the task. Also unpauses childrens' children, and so on.

Parameters:
task,: The task whose children should be unpaused.

void DustyEngine::TaskTree::UnpauseTask DustyEngine::Task task,
irr::u32  timeToStayUnpaused = 0,
irr::u32  timeToStayPaused = 0
 

UnpauseTask() will unpause the given task as well as all its children.

Parameters:
task,: The task to unpause.

void DustyEngine::TaskTree::UnpauseTree  ) 
 

UnpauseTree() unpauses the entire tree.

void DustyEngine::TaskTree::UpdateChildren DustyEngine::Task task  )  [protected]
 

void DustyEngine::TaskTree::UpdateTask DustyEngine::Task task  )  [protected]
 


Member Data Documentation

DustyEngine::DustyDriver* DustyEngine::TaskTree::dustyDriver [protected]
 

Definition at line 157 of file dustytasktree.h.

irr::IrrlichtDevice* DustyEngine::TaskTree::irrlichtDevice [protected]
 

Definition at line 156 of file dustytasktree.h.

bool DustyEngine::TaskTree::isRunning [protected]
 

Definition at line 159 of file dustytasktree.h.

irr::u32 DustyEngine::TaskTree::numTasks [protected]
 

Definition at line 161 of file dustytasktree.h.

DustyEngine::DummyTask* DustyEngine::TaskTree::root [protected]
 

Definition at line 154 of file dustytasktree.h.

irr::core::list<DustyEngine::Task*> DustyEngine::TaskTree::tasksToDelete [protected]
 

Definition at line 163 of file dustytasktree.h.


The documentation for this class was generated from the following file:
Generated on Fri Jan 27 17:32:05 2006 for Dusty Engine by  doxygen 1.4.6-NO