revising task system and added VideoCore::UpdateTask

This commit is contained in:
James Turk 2005-07-20 06:12:54 +00:00
parent 6edf689539
commit edf3fe5a53
6 changed files with 51 additions and 52 deletions

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Task.hpp,v 1.2 2005/07/19 01:31:37 cozman Exp $ // $Id: Task.hpp,v 1.3 2005/07/20 06:12:54 cozman Exp $
#ifndef PHOTON_TASK_HPP #ifndef PHOTON_TASK_HPP
#define PHOTON_TASK_HPP #define PHOTON_TASK_HPP
@ -29,26 +29,6 @@ class Kernel;
// via a pointer. // via a pointer.
typedef shared_ptr<Task> TaskPtr; typedef shared_ptr<Task> TaskPtr;
// Enum: PriorityLevel
// Enumeration defining priority of a Task.
//
// Values:
// PRI_LOWEST - Lowest priority available.
// PRI_LOW - Lower-than-usual priority.
// PRI_NORMAL - Normal priority, suitable for most tasks.
// PRI_HIGH - Lower-than-usual priority.
// PRI_CORE - Priority used by the various cores, between high and highest.
// PRI_HIGHEST - Highest priority available.
enum PriorityLevel
{
PRI_LOWEST,
PRI_LOW,
PRI_NORMAL,
PRI_HIGH,
PRI_CORE,
PRI_HIGHEST
};
// Class: Task // 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 <Kernel>.
// //
@ -62,10 +42,12 @@ public:
// //
// Parameters: // Parameters:
// name - Name for task, must be unique! // name - Name for task, must be unique!
// priority - Optional argument for desired <PriorityLevel> for the Task, // 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 <Kernel>.
// [default = PRI_NORMAL] // Tasks are executed starting with the lowest number for
Task(const std::string& name, PriorityLevel priority=PRI_NORMAL); // priority, meaning a task with priority=0 will execute first.
// Default priority is 5000.
Task(const std::string& name, uint priority=5000);
// Function: ~Task // Function: ~Task
// Virtual destructor, exists simply to make inheritance safe. // Virtual destructor, exists simply to make inheritance safe.
@ -122,8 +104,8 @@ public:
// Get the priority of the task. // Get the priority of the task.
// //
// Return: // Return:
// <PriorityLevel> of task. // priority of task.
PriorityLevel getPriority() const; uint getPriority() const;
// Function: isAlive // Function: isAlive
// Check if task is alive or not. // Check if task is alive or not.
@ -142,7 +124,7 @@ public:
// data members // data members
private: private:
std::string name_; // all tasks need a unique name std::string name_; // all tasks need a unique name
PriorityLevel priority_; // priority determines ordering of tasks uint priority_; // priority determines ordering of tasks
bool alive_; // if false, task will be pruned bool alive_; // if false, task will be pruned
bool paused_; // if false task won't be executed bool paused_; // if false task won't be executed
}; };

View File

@ -5,13 +5,14 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: VideoCore.hpp,v 1.3 2005/07/18 07:19:48 cozman Exp $ // $Id: VideoCore.hpp,v 1.4 2005/07/20 06:12:54 cozman Exp $
#ifndef PHOTON_VIDEO_VIDEOCORE_HPP #ifndef PHOTON_VIDEO_VIDEOCORE_HPP
#define PHOTON_VIDEO_VIDEOCORE_HPP #define PHOTON_VIDEO_VIDEOCORE_HPP
#include "types.hpp" #include "types.hpp"
#include "util/Singleton.hpp" #include "util/Singleton.hpp"
#include "Task.hpp"
namespace photon namespace photon
{ {
@ -42,13 +43,6 @@ public:
// Shutdown underlying APIs. // Shutdown underlying APIs.
~VideoCore(); ~VideoCore();
// Group: Display Management
public:
// Function: clearDisplay
// Clears the display.
void clear();
// Group: Viewport // Group: Viewport
// Functions to set the working viewport and perspective. Orthographic and // Functions to set the working viewport and perspective. Orthographic and
// standard 3D perspective modes are available. // standard 3D perspective modes are available.
@ -161,6 +155,20 @@ public:
private: private:
void initOpenGL(); // set desired OpenGL options void initOpenGL(); // set desired OpenGL options
// UpdateTask, does the updating work of VideoCore, registered as a Task
// so that user need not call something akin to VideoCore::update() every
// frame
class UpdateTask : public Task
{
friend class VideoCore;
public:
UpdateTask();
void update();
};
// data members // data members
private: private:
uint displayWidth_; uint displayWidth_;

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: AppCore.cpp,v 1.12 2005/07/19 18:35:20 cozman Exp $ // $Id: AppCore.cpp,v 1.13 2005/07/20 06:12:54 cozman Exp $
#include "AppCore.hpp" #include "AppCore.hpp"
@ -30,7 +30,7 @@ AppCore::AppCore() :
util::VersionInfo glfwReq(2,4,2); // requires GLFW 2.4.2 util::VersionInfo glfwReq(2,4,2); // requires GLFW 2.4.2
util::ensureVersion("GLFW", initGLFW(), glfwReq); util::ensureVersion("GLFW", initGLFW(), glfwReq);
Kernel::getInstance().addTask(task_); Kernel::getInstance().addTask(task_); // add updater task
} }
AppCore::~AppCore() AppCore::~AppCore()
@ -288,7 +288,7 @@ util::VersionInfo AppCore::initGLFW()
} }
AppCore::UpdateTask::UpdateTask() : AppCore::UpdateTask::UpdateTask() :
Task("AppCore::UpdateTask", PRI_CORE), Task("AppCore::UpdateTask", 10),
mouseX_(0), mouseY_(0), mouseX_(0), mouseY_(0),
active_(false), timerPaused_(false), active_(false), timerPaused_(false),
unpauseOnActive_(false), lastPause_(0), pausedTime_(0), unpauseOnActive_(false), lastPause_(0), pausedTime_(0),

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Kernel.cpp,v 1.2 2005/07/19 01:31:38 cozman Exp $ // $Id: Kernel.cpp,v 1.3 2005/07/20 06:12:54 cozman Exp $
#include "Kernel.hpp" #include "Kernel.hpp"
@ -80,7 +80,7 @@ void Kernel::addTask(TaskPtr task)
task->onStart(); // called whenever a task is being started task->onStart(); // called whenever a task is being started
// find the first task in the list with a lower priority // find the first task in the list with a lower priority
while(it != tasks_.end() && task->getPriority() <= (*it)->getPriority()) while(it != tasks_.end() && (*it)->getPriority() <= task->getPriority())
{ {
++it; ++it;
} }

View File

@ -5,14 +5,14 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Task.cpp,v 1.2 2005/07/19 01:31:38 cozman Exp $ // $Id: Task.cpp,v 1.3 2005/07/20 06:12:54 cozman Exp $
#include "Task.hpp" #include "Task.hpp"
namespace photon namespace photon
{ {
Task::Task(const std::string& name, PriorityLevel priority) : Task::Task(const std::string& name, uint priority) :
name_(name), priority_(priority), alive_(true), paused_(false) name_(name), priority_(priority), alive_(true), paused_(false)
{ {
} }
@ -44,7 +44,7 @@ std::string Task::getName() const
return name_; return name_;
} }
PriorityLevel Task::getPriority() const uint Task::getPriority() const
{ {
return priority_; return priority_;
} }

View File

@ -5,15 +5,16 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: VideoCore.cpp,v 1.7 2005/07/03 05:20:49 cozman Exp $ // $Id: VideoCore.cpp,v 1.8 2005/07/20 06:12:54 cozman Exp $
#include "video/VideoCore.hpp" #include "video/VideoCore.hpp"
#include "Kernel.hpp"
#include "exceptions.hpp" #include "exceptions.hpp"
#include "GL/gl.h" #include "GL/gl.h"
#include "GL/glu.h" #include "GL/glu.h"
#include <iostream>
namespace photon namespace photon
{ {
namespace video namespace video
@ -24,17 +25,14 @@ VideoCore::VideoCore() :
viewportWidth_(0), viewportHeight_(0) viewportWidth_(0), viewportHeight_(0)
{ {
initOpenGL(); initOpenGL();
//add updater task
Kernel::getInstance().addTask(shared_ptr<Task>(new UpdateTask()));
} }
VideoCore::~VideoCore() VideoCore::~VideoCore()
{ { }
}
void VideoCore::clear()
{
// TODO: clear depth/stencil if requested
glClear(GL_COLOR_BUFFER_BIT);
}
void VideoCore::setOrthoView(int x, int y, int viewWidth, int viewHeight, void VideoCore::setOrthoView(int x, int y, int viewWidth, int viewHeight,
scalar orthoWidth, scalar orthoHeight) scalar orthoWidth, scalar orthoHeight)
@ -148,5 +146,16 @@ uint VideoCore::getDisplayHeight()
return displayHeight_; return displayHeight_;
} }
VideoCore::UpdateTask::UpdateTask() :
Task("VideoCore::UpdateTask", 20)
{
}
void VideoCore::UpdateTask::update()
{
// TODO: clear depth/stencil if requested
glClear(GL_COLOR_BUFFER_BIT);
}
} }
} }