revising task system and added VideoCore::UpdateTask
This commit is contained in:
parent
6edf689539
commit
edf3fe5a53
@ -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<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
|
||||
// Abstract class for tasks, which are runnable classes for use with <Kernel>.
|
||||
//
|
||||
@ -62,10 +42,12 @@ public:
|
||||
//
|
||||
// Parameters:
|
||||
// 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>.
|
||||
// [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:
|
||||
// <PriorityLevel> 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
|
||||
};
|
||||
|
@ -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_;
|
||||
|
@ -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),
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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_;
|
||||
}
|
||||
|
@ -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 <iostream>
|
||||
namespace photon
|
||||
{
|
||||
namespace video
|
||||
@ -24,17 +25,14 @@ VideoCore::VideoCore() :
|
||||
viewportWidth_(0), viewportHeight_(0)
|
||||
{
|
||||
initOpenGL();
|
||||
|
||||
//add updater task
|
||||
Kernel::getInstance().addTask(shared_ptr<Task>(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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user