Kernel --> TaskManager

This commit is contained in:
James Turk 2005-08-17 06:35:54 +00:00
parent d483237b66
commit e7658ccce4
17 changed files with 128 additions and 104 deletions

View File

@ -1,22 +1,31 @@
Sanity Check
Check Compilation from CVS
Ensure Tests Run from CVS
Sanity Check NaturalDocs
Bump Version Number
Process:
human: bump version numbers*
script: checkout fresh CVS
script: check building of library & tests
script: check building of docs
human: sanity check tests
human: sanity check docs
human: check building on Windows
script: tag CVS with version number
script: CVS export `cvs -z3 -d:ext:cozman@cvs.sourceforge.net:/cvsroot/photon export -r release-VERSION photon`
script: build docs with `scons docs`
script: remove non-distribution files**
script: rename directory to photon-MAJOR.MINOR
script: package source with tar cjf photon-MAJOR.MINOR.RELEASE-src.tar.bz2 photon-MAJOR.MINOR/
human: place in sourceforge File Release System
script: upload docs to sourceforge webspace
human: write release announcement
*Version Number Locations:
ndoc/Menu.txt : Title
src/Application.cpp : photonVer_
CHANGELOG.txt
photon.mm
Tag CVS with version number
Sourceforge.net
Get with `cvs -z3 -d:ext:cozman@cvs.sourceforge.net:/cvsroot/photon export -r release-VERSION photon`
rename directory to photon-MAJOR.MINOR
Build docs with `scons docs`
prune any files that shouldn't be included (.cvsignores)
package source with tar cjf photon-MAJOR.MINOR.RELEASE.tar.bz2 photon-MAJOR.MINOR/
Upload to Sourceforge and release via Sourceforge release system
Upload docs to Sourceforge webspace
Write release announcement, post on DevBlog/Mailing list
$Id: RELEASE-HOWTO.txt,v 1.3 2005/08/08 22:54:15 cozman Exp $
CVS Tag
**Non-Distribution Files:
photon/.cvsignore
photon/docs/.cvsignore
photon/ndoc/.cvsignore
$Id: RELEASE-HOWTO.txt,v 1.4 2005/08/17 06:35:54 cozman Exp $

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Application.hpp,v 1.21 2005/08/17 03:15:24 cozman Exp $
// $Id: Application.hpp,v 1.22 2005/08/17 06:35:56 cozman Exp $
#ifndef PHOTON_APPLICATION_HPP
#define PHOTON_APPLICATION_HPP
@ -20,7 +20,7 @@
#include "types.hpp"
#include "util/VersionInfo.hpp"
#include "State.hpp"
#include "Kernel.hpp"
#include "util/TaskManager.hpp"
#include "audio/AudioCore.hpp"
#include "util/Singleton.hpp"
@ -64,21 +64,21 @@ public:
// Sets Quit flag, terminating application.
void quit();
// Function: getUpdateKernel
// Access the application's update <Kernel>, <Tasks> registered with this
// kernel are executed after the current <State's> <State::update>.
// Function: getUpdateTaskManager
// Access the application's update <TaskManager>, <Tasks> registered with
// this TaskManager are executed after the current <State::update>.
//
// Returns:
// Reference to "Update Kernel"
Kernel& getUpdateKernel();
// Reference to "Update TaskManager"
util::TaskManager& getUpdateTaskManager();
// Function: getRenderKernel
// Access the application's render <Kernel>, <Tasks> registered with this
// kernel are executed after the current <State's> <State::render>.
// Function: getRenderTaskManager
// Access the application's render <TaskManager>, <Tasks> registered with
// this TaskManager are executed after the current <State::render>.
//
// Returns:
// Reference to "Render Kernel"
Kernel& getRenderKernel();
// Reference to "Render TaskManager"
util::TaskManager& getRenderTaskManager();
// Function: isActive
// Checks if application is active, which on most systems simply means it
@ -429,8 +429,8 @@ private:
// other
bool quit_;
Kernel updateKernel_;
Kernel renderKernel_;
util::TaskManager updateTaskManager_;
util::TaskManager renderTaskManager_;
// state system
static std::stack<StatePtr> stateStack_;

View File

@ -1,11 +1,9 @@
#ifndef PHOTON_HPP
#define PHOTON_HPP
#include "Kernel.hpp"
#include "types.hpp"
#include "State.hpp"
#include "Application.hpp"
#include "Task.hpp"
#include "exceptions.hpp"
#include "photon.hpp"
#include "entrypoint.hpp"
@ -22,7 +20,9 @@
#include "math/Circle.hpp"
#include "util/ConfigFile.hpp"
#include "util/VersionInfo.hpp"
#include "util/Task.hpp"
#include "util/Singleton.hpp"
#include "util/TaskManager.hpp"
#include "util/RandGen.hpp"
#include "util/Timer.hpp"
#include "util/FileBuffer.hpp"

View File

@ -5,10 +5,10 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Task.hpp,v 1.5 2005/08/16 06:32:39 cozman Exp $
// $Id: Task.hpp,v 1.1 2005/08/17 06:35:56 cozman Exp $
#ifndef PHOTON_TASK_HPP
#define PHOTON_TASK_HPP
#ifndef PHOTON_UTIL_TASK_HPP
#define PHOTON_UTIL_TASK_HPP
#include <string>
@ -16,6 +16,8 @@
namespace photon
{
namespace util
{
// Title: Task
@ -38,7 +40,8 @@ enum PriorityLevel
};
// Class: Task
// Abstract class for tasks, which are runnable classes for use with <Kernel>.
// Abstract class for tasks, which are runnable classes for use with
// <TaskManager>.
//
// When writing a task, only update() needs to be overloaded.
class Task
@ -51,7 +54,7 @@ public:
// Parameters:
// name - Name for task, must be unique!
// priority - Optional argument for desired priority for the Task,
// controls order in which tasks are run by the <Kernel>.
// controls order in which tasks are run by the <TaskManager>.
// Default Priority is PRI_NORMAL
Task(const std::string& name, PriorityLevel priority=PRI_NORMAL);
@ -97,8 +100,8 @@ public:
virtual void onUnpause();
// Function: kill
// Sets state of application to dead, dead tasks remove themselves from
// the Kernel's task pool.
// Sets state of task to dead, dead tasks remove themselves from the
// <TaskManager>'s task pool.
void kill();
// Group: Accessors
@ -144,6 +147,7 @@ private:
// via a pointer.
typedef shared_ptr<Task> TaskPtr;
}
}
#endif //PHOTON_TASK_HPP
#endif //PHOTON_UTIL_TASK_HPP

View File

@ -5,10 +5,10 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Kernel.hpp,v 1.4 2005/08/16 06:32:39 cozman Exp $
// $Id: TaskManager.hpp,v 1.1 2005/08/17 06:35:56 cozman Exp $
#ifndef PHOTON_KERNEL_HPP
#define PHOTON_KERNEL_HPP
#ifndef PHOTON_UTIL_TASKMANAGER_HPP
#define PHOTON_UTIL_TASKMANAGER_HPP
#include <list>
#include <algorithm>
@ -17,31 +17,33 @@
namespace photon
{
namespace util
{
// Class: Kernel
// Kernel class, maintains a list of <Tasks> and manages their status,
// Class: TaskManager
// TaskManager class, maintains a list of <Tasks> and manages their status,
// handles adding, deleting, pausing, and unpausing tasks.
//
// To use Kernel:
// To use TaskManager:
// - (1) Add any tasks (should be derived from <Task>)
// - (2) Call step() every frame when task should update.
class Kernel
class TaskManager
{
// Group: (Con/De)structors
public:
// Function: Kernel
// Kernel constructor, initializes kernel singleton.
Kernel();
// Function: TaskManager
// TaskManager constructor, initializes task manager
TaskManager();
// Function: ~Kernel
// Kernel destructor, destroys kernel singleton.
~Kernel();
// Function: ~TaskManager
// TaskManager destructor, destroys task manager
~TaskManager();
// Group: Running
public:
// Function: step
// Steps the kernel, calling each active task once.
// Steps the task manager, calling each active task once.
//
// 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.
@ -54,7 +56,7 @@ public:
// Group: Task Management
public:
// Function: addTask
// Add a new <Task> to the Kernel's list. All tasks MUST have unique
// Add a new <Task> to the TaskManager's list. All tasks MUST have unique
// names.
//
// Parameters:
@ -62,7 +64,7 @@ public:
void addTask(TaskPtr task);
// Function: killTask
// Kill a task in the Kernel task list.
// Kill a task in the TaskManager task list.
// Dead tasks are removed in next loop through tasks.
//
// Parameters:
@ -70,14 +72,14 @@ public:
void killTask(const std::string& taskName);
// Function: pauseTask
// Pause a task in the Kernel task list.
// Pause a task in the TaskManager task list.
//
// Parameters:
// taskName - Name of task to pause.
void pauseTask(const std::string& taskName);
// Function: unpauseTask
// Unpause a task in the Kernel task list.
// Unpause a task in the TaskManager task list.
//
// Parameters:
// taskName - Name of task to unpause.
@ -102,6 +104,7 @@ private:
};
};
}
}
#endif //PHOTON_KERNEL_HPP
#endif //PHOTON_UTIL_TASKMANAGER_HPP

View File

@ -32,7 +32,6 @@ Group: photon:: {
File: Application (Application.hpp)
File: Basic Types (types.hpp)
File: Exception/Error Types (exceptions.hpp)
File: Kernel (Kernel.hpp)
File: Log (Log.hpp)
File: Logging Utilities (LogSink.hpp)
File: PhotonMain (entrypoint.hpp)
@ -40,6 +39,7 @@ Group: photon:: {
File: ResourceManager (ResourceManager.hpp)
File: State (State.hpp)
File: Task (Task.hpp)
File: TaskManager (Kernel.hpp)
Group: Audio:: {

View File

@ -21,7 +21,7 @@
<node ID="Freemind_Link_1902843385" TEXT="depthBuffer enable/disable">
<icon BUILTIN="button_ok"/>
</node>
<node ID="Freemind_Link_1912839994" TEXT="dual Kernels">
<node ID="Freemind_Link_1912839994" TEXT="dual Kernels (TaskManager)">
<icon BUILTIN="button_ok"/>
</node>
</node>
@ -183,12 +183,11 @@
<node ID="Freemind_Link_959094471" TEXT="Contest"/>
</node>
</node>
<node COLOR="#147f1e" ID="Freemind_Link_438641521" POSITION="left" TEXT="Version: $Id: photon.mm,v 1.27 2005/08/16 06:32:39 cozman Exp $">
<node COLOR="#147f1e" ID="Freemind_Link_438641521" POSITION="left" TEXT="Version: $Id: photon.mm,v 1.28 2005/08/17 06:35:54 cozman Exp $">
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
</node>
<node ID="Freemind_Link_853483912" POSITION="left" TEXT="Current Problems">
<font BOLD="true" NAME="SansSerif" SIZE="12"/>
<node ID="Freemind_Link_1298604697" TEXT="reintegrate FPSDisplayTask"/>
</node>
</node>
</map>

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Application.cpp,v 1.26 2005/08/17 03:15:23 cozman Exp $
// $Id: Application.cpp,v 1.27 2005/08/17 06:35:56 cozman Exp $
#include "Application.hpp"
@ -118,14 +118,14 @@ void Application::update()
while(timeAccumulator_ >= fixedTimeStep_)
{
stateStack_.top()->update(fixedTimeStep_);
updateKernel_.step(fixedTimeStep_);
updateTaskManager_.step(fixedTimeStep_);
timeAccumulator_ -= fixedTimeStep_;
}
}
else
{
stateStack_.top()->update(elapsedTime_);
updateKernel_.step(elapsedTime_);
updateTaskManager_.step(elapsedTime_);
}
}
@ -135,7 +135,7 @@ void Application::update()
// clear everything before rendering
glClear(clearFlags_);
stateStack_.top()->render();
renderKernel_.step(fixedTimeStep_);
renderTaskManager_.step(fixedTimeStep_);
glfwSwapBuffers(); // swap buffers after rendering
}
}
@ -147,14 +147,14 @@ void Application::quit()
quit_ = true;
}
Kernel& Application::getUpdateKernel()
util::TaskManager& Application::getUpdateTaskManager()
{
return updateKernel_;
return updateTaskManager_;
}
Kernel& Application::getRenderKernel()
util::TaskManager& Application::getRenderTaskManager()
{
return renderKernel_;
return renderTaskManager_;
}
bool Application::isActive()
@ -305,8 +305,6 @@ void Application::setOrthoProjection(scalar width, scalar height)
//back to modelview
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
setDepthBufferParams(true);
}
void Application::setPerspectiveProjection(scalar fovy, scalar zNear,
@ -323,6 +321,8 @@ void Application::setPerspectiveProjection(scalar fovy, scalar zNear,
//back to modelview
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
setDepthBufferParams(true);
}
void Application::setDepthBufferParams(bool enable, scalar depth)

View File

@ -5,12 +5,14 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Task.cpp,v 1.4 2005/08/07 07:12:47 cozman Exp $
// $Id: Task.cpp,v 1.1 2005/08/17 06:35:56 cozman Exp $
#include "Task.hpp"
#include "util/Task.hpp"
namespace photon
{
namespace util
{
Task::Task(const std::string& name, PriorityLevel priority) :
name_(name), priority_(priority), alive_(true), paused_(false)
@ -60,3 +62,4 @@ bool Task::isPaused() const
}
}
}

View File

@ -5,27 +5,27 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Kernel.cpp,v 1.5 2005/08/16 06:32:39 cozman Exp $
// $Id: TaskManager.cpp,v 1.1 2005/08/17 06:35:56 cozman Exp $
#include "Kernel.hpp"
#include "util/TaskManager.hpp"
#include "exceptions.hpp"
#include "Log.hpp"
namespace photon
{
namespace util
{
Kernel::Kernel()
TaskManager::TaskManager()
{
}
Kernel::~Kernel()
TaskManager::~TaskManager()
{
killAllTasks();
}
void Kernel::step(scalar timeDelta)
void TaskManager::step(scalar timeDelta)
{
std::list<TaskPtr>::iterator it;
@ -59,7 +59,7 @@ void Kernel::step(scalar timeDelta)
}
}
void Kernel::addTask(TaskPtr task)
void TaskManager::addTask(TaskPtr task)
{
std::list<TaskPtr>::iterator it = tasks_.begin();
// attempt to find task
@ -84,7 +84,7 @@ void Kernel::addTask(TaskPtr task)
tasks_.insert(it, task); // insert task after iterator
}
void Kernel::killTask(const std::string& taskName)
void TaskManager::killTask(const std::string& taskName)
{
// attempt to find the task
std::list<TaskPtr>::iterator task = std::find_if(tasks_.begin(),
@ -102,7 +102,7 @@ void Kernel::killTask(const std::string& taskName)
}
}
void Kernel::pauseTask(const std::string& taskName)
void TaskManager::pauseTask(const std::string& taskName)
{
// attempt to find the task
std::list<TaskPtr>::iterator task = std::find_if(tasks_.begin(),
@ -120,7 +120,7 @@ void Kernel::pauseTask(const std::string& taskName)
}
}
void Kernel::unpauseTask(const std::string& taskName)
void TaskManager::unpauseTask(const std::string& taskName)
{
// attempt to find the task
std::list<TaskPtr>::iterator task = std::find_if(tasks_.begin(),
@ -138,7 +138,7 @@ void Kernel::unpauseTask(const std::string& taskName)
}
}
void Kernel::killAllTasks()
void TaskManager::killAllTasks()
{
// set all tasks to dead
for(std::list<TaskPtr>::iterator it = tasks_.begin();
@ -149,10 +149,11 @@ void Kernel::killAllTasks()
}
}
bool Kernel::TaskNameEq::operator()(const TaskPtr& lhs,
bool TaskManager::TaskNameEq::operator()(const TaskPtr& lhs,
const std::string& rhs) const
{
return lhs->getName() == rhs;
}
}
}

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Audio_test.cpp,v 1.15 2005/08/16 06:32:39 cozman Exp $
// $Id: Audio_test.cpp,v 1.16 2005/08/17 06:35:56 cozman Exp $
#include "photon.hpp"
using namespace photon;
@ -190,7 +190,7 @@ int PhotonMain(const StrVec& args)
app.initAudioCore(); // initialize audio core
// be sure to add FPSDisplayTask
//Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
app.getUpdateTaskManager().addTask(util::TaskPtr(new FPSDisplayTask()));
app.setState<MainState>(); // register state and make active
app.run(); // run until finished

View File

@ -7,7 +7,12 @@
// Used to measure FPS and display it in the title bar. Pretty good example
// of when to use a Task, logic is entirely separate from rest of application
// and should be executed regularly.
class FPSDisplayTask : public photon::Task
//
// Note: Realistically framerate should not be displayed in the title bar
// because changing the title causes a stutter, and changing the title
// bar every second makes applications with a lot of movement look
// terrible.
class FPSDisplayTask : public photon::util::Task
{
public:
FPSDisplayTask() :
@ -16,7 +21,7 @@ public:
lastUpdate(0)
{ }
void update()
void update(scalar timeDelta)
{
// update (at most) once a second
if(app.getTime() - lastUpdate > 1.0)

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Font_test.cpp,v 1.12 2005/08/16 06:32:39 cozman Exp $
// $Id: Font_test.cpp,v 1.13 2005/08/17 06:35:56 cozman Exp $
#include "photon.hpp"
using namespace photon;
@ -54,7 +54,7 @@ int PhotonMain(const StrVec& args)
app.createDisplay(800,600,32,0,0,false); // create window
// be sure to add FPSDisplayTask
//Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
//TaskManager::getInstance().addTask(util::TaskPtr(new FPSDisplayTask()));
app.setState<MainState>(); // register state and make active
app.run(); // run until finished

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Image_test.cpp,v 1.12 2005/08/16 06:32:39 cozman Exp $
// $Id: Image_test.cpp,v 1.13 2005/08/17 06:35:56 cozman Exp $
#include "photon.hpp"
using namespace photon;
@ -65,7 +65,7 @@ int PhotonMain(const StrVec& args)
app.createDisplay(800,600,32,0,0,false); // create window
// be sure to add FPSDisplayTask
//Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
app.getUpdateTaskManager().addTask(util::TaskPtr(new FPSDisplayTask()));
app.setState<MainState>(); // register state and make active
app.run(); // run until finished

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Input_test.cpp,v 1.11 2005/08/16 06:32:39 cozman Exp $
// $Id: Input_test.cpp,v 1.12 2005/08/17 06:35:56 cozman Exp $
#include "photon.hpp"
using namespace photon;
@ -124,7 +124,7 @@ int PhotonMain(const StrVec& args)
app.createDisplay(800,600,32,0,0,false); // create window
// be sure to add FPSDisplayTask
//Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
app.getUpdateTaskManager().addTask(util::TaskPtr(new FPSDisplayTask()));
app.setState<MainState>(); // register state and make active
app.run(); // run until finished

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Pen_test.cpp,v 1.9 2005/08/16 06:32:39 cozman Exp $
// $Id: Pen_test.cpp,v 1.10 2005/08/17 06:35:56 cozman Exp $
#include "photon.hpp"
using namespace photon;
@ -78,7 +78,7 @@ int PhotonMain(const StrVec& args)
app.createDisplay(800,600,32,0,0,false); // create window
// be sure to add FPSDisplayTask
//Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
app.getUpdateTaskManager().addTask(util::TaskPtr(new FPSDisplayTask()));
app.setState<MainState>(); // register state and make active
app.run(); // run until finished

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Texture_test.cpp,v 1.10 2005/08/16 06:32:39 cozman Exp $
// $Id: Texture_test.cpp,v 1.11 2005/08/17 06:35:56 cozman Exp $
#include "photon.hpp"
using namespace photon;
@ -78,7 +78,7 @@ int PhotonMain(const StrVec& args)
app.createDisplay(800,600,32,0,0,false); // create window
// be sure to add FPSDisplayTask
//Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
app.getUpdateTaskManager().addTask(util::TaskPtr(new FPSDisplayTask()));
app.setState<MainState>(); // register state and make active
app.run(); // run until finished