2005-03-15 19:21:51 +00:00
|
|
|
//This file is part of Photon (http://photon.sourceforge.net)
|
|
|
|
//Copyright (C) 2004-2005 James Turk
|
|
|
|
//
|
|
|
|
// Author:
|
|
|
|
// James Turk (jpt2433@rit.edu)
|
|
|
|
//
|
|
|
|
// Version:
|
2005-11-13 07:59:48 +00:00
|
|
|
// $Id: TaskManager.hpp,v 1.2 2005/11/13 07:59:48 cozman Exp $
|
2005-03-15 19:21:51 +00:00
|
|
|
|
2005-08-17 06:35:54 +00:00
|
|
|
#ifndef PHOTON_UTIL_TASKMANAGER_HPP
|
|
|
|
#define PHOTON_UTIL_TASKMANAGER_HPP
|
2005-03-15 19:21:51 +00:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "Task.hpp"
|
|
|
|
|
|
|
|
namespace photon
|
|
|
|
{
|
2005-08-17 06:35:54 +00:00
|
|
|
namespace util
|
|
|
|
{
|
2005-03-15 19:21:51 +00:00
|
|
|
|
2005-08-17 06:35:54 +00:00
|
|
|
// Class: TaskManager
|
|
|
|
// TaskManager class, maintains a list of <Tasks> and manages their status,
|
2005-08-02 23:07:51 +00:00
|
|
|
// handles adding, deleting, pausing, and unpausing tasks.
|
2005-03-15 19:21:51 +00:00
|
|
|
//
|
2005-08-17 06:35:54 +00:00
|
|
|
// To use TaskManager:
|
2005-11-13 07:59:48 +00:00
|
|
|
// - Add any tasks (should be derived from <Task>)
|
|
|
|
// - Call step() every frame when task should update.
|
2005-08-17 06:35:54 +00:00
|
|
|
class TaskManager
|
2005-03-15 19:21:51 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// Group: (Con/De)structors
|
|
|
|
public:
|
2005-08-17 06:35:54 +00:00
|
|
|
// Function: TaskManager
|
|
|
|
// TaskManager constructor, initializes task manager
|
|
|
|
TaskManager();
|
2005-03-15 19:21:51 +00:00
|
|
|
|
2005-08-17 06:35:54 +00:00
|
|
|
// Function: ~TaskManager
|
|
|
|
// TaskManager destructor, destroys task manager
|
|
|
|
~TaskManager();
|
2005-03-15 19:21:51 +00:00
|
|
|
|
|
|
|
// Group: Running
|
|
|
|
public:
|
2005-08-07 07:12:46 +00:00
|
|
|
// Function: step
|
2005-08-17 06:35:54 +00:00
|
|
|
// Steps the task manager, calling each active task once.
|
2005-08-07 07:12:46 +00:00
|
|
|
//
|
|
|
|
// Each 'step' all tasks are run in order of their priorities, if two
|
|
|
|
// tasks have the same priority, they are run in the order they were added.
|
2005-03-15 19:21:51 +00:00
|
|
|
//
|
2005-08-16 06:32:39 +00:00
|
|
|
// Parameters:
|
2005-11-13 07:59:48 +00:00
|
|
|
// timeDelta - The time elapsed between frames.
|
2005-08-16 06:32:39 +00:00
|
|
|
void step(scalar timeDelta);
|
2005-03-15 19:21:51 +00:00
|
|
|
|
|
|
|
// Group: Task Management
|
|
|
|
public:
|
|
|
|
// Function: addTask
|
2005-08-17 06:35:54 +00:00
|
|
|
// Add a new <Task> to the TaskManager's list. All tasks MUST have unique
|
2005-03-15 19:21:51 +00:00
|
|
|
// names.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// task - <TaskPtr> representing instance of <Task> subclass to add.
|
|
|
|
void addTask(TaskPtr task);
|
|
|
|
|
|
|
|
// Function: killTask
|
2005-08-17 06:35:54 +00:00
|
|
|
// Kill a task in the TaskManager task list.
|
2005-03-15 19:21:51 +00:00
|
|
|
// Dead tasks are removed in next loop through tasks.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// taskName - Name of task to kill.
|
|
|
|
void killTask(const std::string& taskName);
|
|
|
|
|
|
|
|
// Function: pauseTask
|
2005-08-17 06:35:54 +00:00
|
|
|
// Pause a task in the TaskManager task list.
|
2005-03-15 19:21:51 +00:00
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// taskName - Name of task to pause.
|
|
|
|
void pauseTask(const std::string& taskName);
|
|
|
|
|
|
|
|
// Function: unpauseTask
|
2005-08-17 06:35:54 +00:00
|
|
|
// Unpause a task in the TaskManager task list.
|
2005-03-15 19:21:51 +00:00
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// taskName - Name of task to unpause.
|
|
|
|
void unpauseTask(const std::string& taskName);
|
|
|
|
|
|
|
|
// Function: killAllTasks
|
|
|
|
// Kills all tasks.
|
|
|
|
// Dead tasks are removed in next loop through tasks.
|
|
|
|
void killAllTasks();
|
|
|
|
|
|
|
|
// data members
|
|
|
|
private:
|
|
|
|
|
|
|
|
//stored list of tasks (stored in order of priority highest to lowest)
|
|
|
|
std::list<TaskPtr> tasks_;
|
|
|
|
|
|
|
|
//predicate for search
|
|
|
|
class TaskNameEq : public std::binary_function<TaskPtr, std::string, bool>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator()(const TaskPtr& lhs, const std::string& rhs) const;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2005-08-17 06:35:54 +00:00
|
|
|
}
|
2005-03-15 19:21:51 +00:00
|
|
|
}
|
|
|
|
|
2005-08-17 06:35:54 +00:00
|
|
|
#endif //PHOTON_UTIL_TASKMANAGER_HPP
|