From edf3fe5a534ab711833f348519b9d7db1789d2b8 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 20 Jul 2005 06:12:54 +0000 Subject: [PATCH] revising task system and added VideoCore::UpdateTask --- include/Task.hpp | 36 +++++++++--------------------------- include/video/VideoCore.hpp | 24 ++++++++++++++++-------- src/AppCore.cpp | 6 +++--- src/Kernel.cpp | 4 ++-- src/Task.cpp | 6 +++--- src/video/VideoCore.cpp | 27 ++++++++++++++++++--------- 6 files changed, 51 insertions(+), 52 deletions(-) diff --git a/include/Task.hpp b/include/Task.hpp index c45c85c..94a2acf 100644 --- a/include/Task.hpp +++ b/include/Task.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // 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 #define PHOTON_TASK_HPP @@ -29,26 +29,6 @@ class Kernel; // via a pointer. typedef shared_ptr 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 // Abstract class for tasks, which are runnable classes for use with . // @@ -62,10 +42,12 @@ public: // // Parameters: // name - Name for task, must be unique! - // priority - Optional argument for desired for the Task, + // priority - Optional argument for desired priority for the Task, // controls order in which tasks are run by the . - // [default = PRI_NORMAL] - Task(const std::string& name, PriorityLevel priority=PRI_NORMAL); + // Tasks are executed starting with the lowest number for + // priority, meaning a task with priority=0 will execute first. + // Default priority is 5000. + Task(const std::string& name, uint priority=5000); // Function: ~Task // Virtual destructor, exists simply to make inheritance safe. @@ -122,8 +104,8 @@ public: // Get the priority of the task. // // Return: - // of task. - PriorityLevel getPriority() const; + // priority of task. + uint getPriority() const; // Function: isAlive // Check if task is alive or not. @@ -142,7 +124,7 @@ public: // data members private: 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 paused_; // if false task won't be executed }; diff --git a/include/video/VideoCore.hpp b/include/video/VideoCore.hpp index 4c866d8..8a899f0 100644 --- a/include/video/VideoCore.hpp +++ b/include/video/VideoCore.hpp @@ -5,13 +5,14 @@ // James Turk (jpt2433@rit.edu) // // 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 #define PHOTON_VIDEO_VIDEOCORE_HPP #include "types.hpp" #include "util/Singleton.hpp" +#include "Task.hpp" namespace photon { @@ -41,13 +42,6 @@ public: // Function: ~VideoCore // Shutdown underlying APIs. ~VideoCore(); - -// Group: Display Management -public: - - // Function: clearDisplay - // Clears the display. - void clear(); // Group: Viewport // Functions to set the working viewport and perspective. Orthographic and @@ -161,6 +155,20 @@ public: private: 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 private: uint displayWidth_; diff --git a/src/AppCore.cpp b/src/AppCore.cpp index 3321662..74a8d23 100644 --- a/src/AppCore.cpp +++ b/src/AppCore.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // 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" @@ -30,7 +30,7 @@ AppCore::AppCore() : util::VersionInfo glfwReq(2,4,2); // requires GLFW 2.4.2 util::ensureVersion("GLFW", initGLFW(), glfwReq); - Kernel::getInstance().addTask(task_); + Kernel::getInstance().addTask(task_); // add updater task } AppCore::~AppCore() @@ -288,7 +288,7 @@ util::VersionInfo AppCore::initGLFW() } AppCore::UpdateTask::UpdateTask() : - Task("AppCore::UpdateTask", PRI_CORE), + Task("AppCore::UpdateTask", 10), mouseX_(0), mouseY_(0), active_(false), timerPaused_(false), unpauseOnActive_(false), lastPause_(0), pausedTime_(0), diff --git a/src/Kernel.cpp b/src/Kernel.cpp index cbd5ced..4e8e961 100644 --- a/src/Kernel.cpp +++ b/src/Kernel.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // 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" @@ -80,7 +80,7 @@ void Kernel::addTask(TaskPtr task) task->onStart(); // called whenever a task is being started // 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; } diff --git a/src/Task.cpp b/src/Task.cpp index 9cb2d20..823a1a6 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -5,14 +5,14 @@ // James Turk (jpt2433@rit.edu) // // 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" 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) { } @@ -44,7 +44,7 @@ std::string Task::getName() const return name_; } -PriorityLevel Task::getPriority() const +uint Task::getPriority() const { return priority_; } diff --git a/src/video/VideoCore.cpp b/src/video/VideoCore.cpp index e3732d9..e8af6b3 100644 --- a/src/video/VideoCore.cpp +++ b/src/video/VideoCore.cpp @@ -5,15 +5,16 @@ // James Turk (jpt2433@rit.edu) // // 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 "Kernel.hpp" #include "exceptions.hpp" #include "GL/gl.h" #include "GL/glu.h" - +#include namespace photon { namespace video @@ -24,17 +25,14 @@ VideoCore::VideoCore() : viewportWidth_(0), viewportHeight_(0) { initOpenGL(); + + //add updater task + Kernel::getInstance().addTask(shared_ptr(new UpdateTask())); } 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, scalar orthoWidth, scalar orthoHeight) @@ -148,5 +146,16 @@ uint VideoCore::getDisplayHeight() return displayHeight_; } +VideoCore::UpdateTask::UpdateTask() : + Task("VideoCore::UpdateTask", 20) +{ +} + +void VideoCore::UpdateTask::update() +{ + // TODO: clear depth/stencil if requested + glClear(GL_COLOR_BUFFER_BIT); +} + } }