post-Kernel
This commit is contained in:
parent
c822bbebc1
commit
0ba7535428
@ -5,7 +5,7 @@
|
||||
# James Turk (jpt2433@rit.edu)
|
||||
#
|
||||
# Version:
|
||||
# $Id: SConstruct,v 1.4 2005/03/04 13:06:49 cozman Exp $
|
||||
# $Id: SConstruct,v 1.5 2005/03/15 19:21:51 cozman Exp $
|
||||
|
||||
import os,os.path
|
||||
import glob
|
||||
@ -88,11 +88,13 @@ class Builder:
|
||||
|
||||
self.namedBuild('photon', os.path.join('lib',libName), 'Library',
|
||||
default=True,
|
||||
source = self.srcFiles, CPPPATH = self.incDirs)
|
||||
source = self.srcFiles, CPPPATH = 'include',
|
||||
CPPFLAGS = '-Wall -pedantic -pg')
|
||||
self.namedBuild('test00', 'test00', 'Program', default=False,
|
||||
source = 'test00.cpp', CPPPATH = self.incDirs,
|
||||
LIBPATH='./lib',
|
||||
LIBS=['photon','openal32','glfw','opengl32','glu32','physfs'])
|
||||
LIBS=['photon','openal32','glfw','opengl32','glu32','physfs'],
|
||||
CPPFLAGS = '-Wall -pedantic -pg', LINKFLAGS='-pg')
|
||||
self.buildSuperHeader(libName)
|
||||
ndoc = self.env.Command('docs/index.html', './include',
|
||||
"""NaturalDocs -nag -i $SOURCES -o HTML ./docs -p ./ndoc""",
|
||||
|
@ -5,15 +5,15 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: AppCore.hpp,v 1.4 2005/03/04 13:06:49 cozman Exp $
|
||||
// $Id: AppCore.hpp,v 1.5 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
#ifndef PHOTON_APPCORE_HPP
|
||||
#define PHOTON_APPCORE_HPP
|
||||
|
||||
#include "types.hpp"
|
||||
#include "glfw/types_glfw.hpp"
|
||||
#include "util/VersionInfo.hpp"
|
||||
#include "util/Singleton.hpp"
|
||||
#include "Task.hpp"
|
||||
|
||||
namespace photon
|
||||
{
|
||||
@ -30,6 +30,10 @@ namespace photon
|
||||
class AppCore : public util::Singleton<AppCore>
|
||||
{
|
||||
|
||||
public:
|
||||
AppCore();
|
||||
~AppCore();
|
||||
|
||||
// Group: Video
|
||||
public:
|
||||
|
||||
@ -46,11 +50,11 @@ public:
|
||||
// depthBits - desired bitdepth of depth buffer
|
||||
// stencilBits - desired bitdepth of stencil buffer
|
||||
// fullscreen - true: fullscreen, false: windowed
|
||||
// title - title of application
|
||||
// [title - title of application, optional]
|
||||
void createDisplay(uint width, uint height,
|
||||
uint redBits, uint greenBits, uint blueBits,
|
||||
uint alphaBits, uint depthBits, uint stencilBits,
|
||||
bool fullscreen, const std::string& title);
|
||||
bool fullscreen, const std::string& title="Photon App");
|
||||
|
||||
// Function: createDisplay
|
||||
// This function attempts to create a display with the given parameters.
|
||||
@ -62,10 +66,10 @@ public:
|
||||
// depthBits - desired bitdepth of depth buffer
|
||||
// stencilBits - desired bitdepth of stencil buffer
|
||||
// fullscreen - true: fullscreen, false: windowed
|
||||
// title - title of application
|
||||
// [title - title of application, optional]
|
||||
void createDisplay(uint width, uint height, uint bpp,
|
||||
uint depthBits, uint stencilBits, bool fullscreen,
|
||||
const std::string& title);
|
||||
const std::string& title="Photon App");
|
||||
|
||||
// Group: Input
|
||||
public:
|
||||
@ -125,9 +129,6 @@ public:
|
||||
|
||||
// Group: General
|
||||
public:
|
||||
// Function: update
|
||||
// Updates the internals of the application, including the display.
|
||||
void update();
|
||||
|
||||
// Function: setTitle
|
||||
// Sets title of application that shows up in title bar.
|
||||
@ -136,18 +137,6 @@ public:
|
||||
// title - New title of application.
|
||||
void setTitle(const std::string& title);
|
||||
|
||||
// Function: requestQuit
|
||||
// Sets the internal quit flag to true.
|
||||
void requestQuit();
|
||||
|
||||
// Function: quitRequested
|
||||
// Checks the internal quit flag, if a quit has been requested,
|
||||
// the application should comply.
|
||||
//
|
||||
// Returns:
|
||||
// State of internal quit flag, if true application should quit ASAP.
|
||||
bool quitRequested();
|
||||
|
||||
// Function: isActive
|
||||
// Checks if application is active, which on most systems simply means it
|
||||
// has focus.
|
||||
@ -187,30 +176,37 @@ public:
|
||||
// Height of display in pixels.
|
||||
uint getDisplayHeight();
|
||||
|
||||
class UpdateTask : public Task
|
||||
{
|
||||
|
||||
friend class AppCore;
|
||||
|
||||
public:
|
||||
UpdateTask();
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
uint mouseX_;
|
||||
uint mouseY_;
|
||||
bool active_;
|
||||
bool timerPaused_;
|
||||
bool unpauseOnActive_;
|
||||
scalar lastPause_;
|
||||
scalar pausedTime_;
|
||||
scalar secPerFrame_;
|
||||
scalar lastUpdate_;
|
||||
};
|
||||
|
||||
// data members
|
||||
private:
|
||||
uint dispWidth_;
|
||||
uint dispHeight_;
|
||||
bool quitRequested_;
|
||||
bool active_;
|
||||
bool timerPaused_;
|
||||
bool unpauseOnActive_;
|
||||
scalar lastPause_;
|
||||
scalar pausedTime_;
|
||||
scalar secPerFrame_;
|
||||
scalar lastUpdate_;
|
||||
shared_ptr<UpdateTask> task_;
|
||||
|
||||
// API initialization
|
||||
private:
|
||||
util::VersionInfo initGLFW();
|
||||
|
||||
// Singleton-required code
|
||||
private:
|
||||
AppCore();
|
||||
~AppCore();
|
||||
|
||||
friend class util::Singleton<AppCore>;
|
||||
friend class std::auto_ptr<AppCore>;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Application.hpp,v 1.6 2005/03/02 08:40:51 cozman Exp $
|
||||
// $Id: Application.hpp,v 1.7 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
#ifndef PHOTON_APPLICATION_HPP
|
||||
#define PHOTON_APPLICATION_HPP
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
#include "types.hpp"
|
||||
#include "util/VersionInfo.hpp"
|
||||
#include "Task.hpp"
|
||||
|
||||
namespace photon
|
||||
{
|
||||
@ -26,7 +27,7 @@ namespace photon
|
||||
// implementations of Application.
|
||||
//
|
||||
// Derived classes are made entrypoint via <ENTRYPOINT>.
|
||||
class Application : public boost::noncopyable
|
||||
class Application
|
||||
{
|
||||
|
||||
// Group: (Con/De)structors
|
||||
@ -39,6 +40,8 @@ public:
|
||||
// Default destructor, shuts down dependencies.
|
||||
virtual ~Application();
|
||||
|
||||
// Group: Main
|
||||
public:
|
||||
// Function: main
|
||||
// Pure virtual, must be defined by derived class, using some preprocessor
|
||||
// magic (<MAINCLASS>) on the derived class
|
||||
@ -52,34 +55,20 @@ public:
|
||||
//
|
||||
// See Also:
|
||||
// <ENTRYPOINT>
|
||||
virtual int main(StrVec args)=0;
|
||||
virtual int main(const StrVec& args)=0;
|
||||
|
||||
// Behind the scenes
|
||||
// behind the scenes
|
||||
public:
|
||||
// Function: setInitOptions(const char* arg0)
|
||||
// Internal use function, used to set initialization options.
|
||||
// (params not documented since function signature is subject to change and
|
||||
// should not be relied on by user-level code)
|
||||
static void setInitOptions(const char* appPath);
|
||||
static void setInitOptions(const char* arg0);
|
||||
|
||||
// Group: API Initialization
|
||||
private:
|
||||
// Function: initPhysFS
|
||||
// Initialize PhysFS for use.
|
||||
//
|
||||
// Parameters:
|
||||
// arg0 - Path to application (argv[0])
|
||||
//
|
||||
// Returns:
|
||||
// <VersionInfo> with PhysFS version.
|
||||
util::VersionInfo initPhysFS(const char* arg0);
|
||||
|
||||
// Data Members
|
||||
private:
|
||||
// version number for photon
|
||||
util::VersionInfo photonVer_;
|
||||
|
||||
// arg0 from command line
|
||||
static std::string arg0_;
|
||||
};
|
||||
|
||||
|
105
include/Kernel.hpp
Normal file
105
include/Kernel.hpp
Normal file
@ -0,0 +1,105 @@
|
||||
//This file is part of Photon (http://photon.sourceforge.net)
|
||||
//Copyright (C) 2004-2005 James Turk
|
||||
//
|
||||
// Author:
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Kernel.hpp,v 1.1 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
#ifndef PHOTON_KERNEL_HPP
|
||||
#define PHOTON_KERNEL_HPP
|
||||
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
|
||||
#include "util/Singleton.hpp"
|
||||
#include "Task.hpp"
|
||||
|
||||
namespace photon
|
||||
{
|
||||
|
||||
// Class: Kernel
|
||||
// Singleton Kernel class, maintains a list of <Tasks> and manages their
|
||||
// status, including adding, deleting, pausing, and unpausing tasks.
|
||||
//
|
||||
// To use Kernel:
|
||||
// - (1) Add any tasks (should be derived from <Task>)
|
||||
// - (2) call <Kernel::run>
|
||||
// - (3) in order to avoid running forever, all tasks should eventually die
|
||||
class Kernel : public util::Singleton<Kernel>
|
||||
{
|
||||
|
||||
// Group: (Con/De)structors
|
||||
public:
|
||||
// Function: Kernel
|
||||
// Kernel constructor, initializes kernel singleton.
|
||||
Kernel();
|
||||
|
||||
// Function: ~Kernel
|
||||
// Kernel destructor, destroys kernel singleton.
|
||||
~Kernel();
|
||||
|
||||
// Group: Running
|
||||
public:
|
||||
// Function: run
|
||||
// Runs tasks until all tasks are asleep or dead.
|
||||
//
|
||||
// Each 'frame' 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.
|
||||
void run();
|
||||
|
||||
// Group: Task Management
|
||||
public:
|
||||
// Function: addTask
|
||||
// Add a new <Task> to the Kernel's list. All tasks MUST have unique
|
||||
// names.
|
||||
//
|
||||
// Parameters:
|
||||
// task - <TaskPtr> representing instance of <Task> subclass to add.
|
||||
void addTask(TaskPtr task);
|
||||
|
||||
// Function: killTask
|
||||
// Kill a task in the Kernel task list.
|
||||
// Dead tasks are removed in next loop through tasks.
|
||||
//
|
||||
// Parameters:
|
||||
// taskName - Name of task to kill.
|
||||
void killTask(const std::string& taskName);
|
||||
|
||||
// Function: pauseTask
|
||||
// Pause a task in the Kernel 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.
|
||||
//
|
||||
// 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;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //PHOTON_KERNEL_HPP
|
152
include/Task.hpp
Normal file
152
include/Task.hpp
Normal file
@ -0,0 +1,152 @@
|
||||
//This file is part of Photon (http://photon.sourceforge.net)
|
||||
//Copyright (C) 2004-2005 James Turk
|
||||
//
|
||||
// Author:
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Task.hpp,v 1.1 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
#ifndef PHOTON_TASK_HPP
|
||||
#define PHOTON_TASK_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace photon
|
||||
{
|
||||
|
||||
// Title: Task
|
||||
|
||||
// Group: Helper Types
|
||||
|
||||
class Task;
|
||||
class Kernel;
|
||||
|
||||
// Type: TaskPtr
|
||||
// Pointer to a task, used since Task is abstract and will always be accessed
|
||||
// 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>.
|
||||
//
|
||||
// When writing a task, only update() needs to be overloaded.
|
||||
class Task
|
||||
{
|
||||
// Group: (Con/De)structors
|
||||
public:
|
||||
// Function: Task
|
||||
// Constructor, every task needs a name and priority.
|
||||
//
|
||||
// Parameters:
|
||||
// name - Name for task, must be unique!
|
||||
// priority - Optional argument for desired <PriorityLevel> 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);
|
||||
|
||||
// Function: ~Task
|
||||
// Virtual destructor, exists simply to make inheritance safe.
|
||||
virtual ~Task();
|
||||
|
||||
// Group: Control
|
||||
public:
|
||||
// Function: update
|
||||
// Pure virtual, every child task must overload it's own update(), when a
|
||||
// task is active this is called every 'frame.'
|
||||
virtual void update()=0;
|
||||
|
||||
// Function: onStart
|
||||
// Virtual function, overload to define behavior when the task is started.
|
||||
virtual void onStart();
|
||||
|
||||
// Function: onKill
|
||||
// Virtual function, overload to define behavior when the task is killed.
|
||||
virtual void onKill();
|
||||
|
||||
// Function: onPause
|
||||
// Virtual function, overload to define behavior every time that the
|
||||
// task is paused.
|
||||
//
|
||||
// Note:
|
||||
// Children of onPause should call Task::onPause to let the task know it's
|
||||
// been paused.
|
||||
virtual void onPause();
|
||||
|
||||
// Function: onUnpause
|
||||
// Virtual function, overload to define behavior every time that the
|
||||
// task is unpaused.
|
||||
//
|
||||
// Note:
|
||||
// Children of onUnpause should call Task::onUnpause to let the task know
|
||||
// it's been paused.
|
||||
virtual void onUnpause();
|
||||
|
||||
// Function: kill
|
||||
// Sets state of application to dead, dead tasks remove themselves from
|
||||
// the Kernel's task pool.
|
||||
void kill();
|
||||
|
||||
// Group: Accessors
|
||||
public:
|
||||
// Function: getName
|
||||
// Get the name of the task.
|
||||
//
|
||||
// Return:
|
||||
// Name of task.
|
||||
std::string getName() const;
|
||||
|
||||
// Function: getPriority
|
||||
// Get the priority of the task.
|
||||
//
|
||||
// Return:
|
||||
// <PriorityLevel> of task.
|
||||
PriorityLevel getPriority() const;
|
||||
|
||||
// Function: isAlive
|
||||
// Check if task is alive or not.
|
||||
//
|
||||
// Return:
|
||||
// true if task is alive, false if task has been killed
|
||||
bool isAlive() const;
|
||||
|
||||
// Function: isPaused
|
||||
// Check if task is paused or not.
|
||||
//
|
||||
// Return:
|
||||
// true iff task is paused
|
||||
bool isPaused() const;
|
||||
|
||||
// data members
|
||||
private:
|
||||
std::string name_;
|
||||
PriorityLevel priority_;
|
||||
bool alive_;
|
||||
bool paused_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //PHOTON_TASK_HPP
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: entrypoint.hpp,v 1.3 2005/03/04 13:06:49 cozman Exp $
|
||||
// $Id: entrypoint.hpp,v 1.4 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
|
||||
#ifndef PHOTON_ENTRYPOINT_HPP
|
||||
@ -22,7 +22,7 @@
|
||||
which implements main, in the file defining PongGame it is important to
|
||||
include ENTRYPOINT(PongGame) so that the entry point becomes PongGame::main.
|
||||
*/
|
||||
#define ENTRYPOINT(className) int main(int argc, char *argv[]) \
|
||||
#define ENTRYPOINT(className) int main(int argc, const char** argv) \
|
||||
{ return photon::mainclass<className>(argc,argv); }
|
||||
|
||||
namespace photon
|
||||
@ -30,25 +30,28 @@ namespace photon
|
||||
|
||||
// function which does all the work of MAINCLASS
|
||||
template<class App>
|
||||
int mainclass(int argc, char *argv[])
|
||||
int mainclass(int argc, const char** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
App app;
|
||||
StrVec args;
|
||||
for(int i=0; i < argc; ++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
App::setInitOptions(argv[0]);
|
||||
App app;
|
||||
|
||||
return app.main(args);
|
||||
}
|
||||
catch(photon::Exception &e)
|
||||
catch(Exception &e)
|
||||
{
|
||||
photon::Log::getInstance().error() << e;
|
||||
Log::getInstance().error() << e;
|
||||
return 0;
|
||||
}
|
||||
catch(photon::Error &e)
|
||||
catch(Error &e)
|
||||
{
|
||||
photon::Log::getInstance().critical() << e;
|
||||
Log::getInstance().critical() << e;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "Task.hpp"
|
||||
#include "types.hpp"
|
||||
#include "audio/AudioCore.hpp"
|
||||
#include "glfw/types_glfw.hpp"
|
||||
#include "math/Circle.hpp"
|
||||
#include "math/math.hpp"
|
||||
#include "math/Rect.hpp"
|
||||
|
131
src/AppCore.cpp
131
src/AppCore.cpp
@ -5,18 +5,35 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: AppCore.cpp,v 1.4 2005/03/04 13:06:49 cozman Exp $
|
||||
// $Id: AppCore.cpp,v 1.5 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
#include "AppCore.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "glfw.h" //This file depends on glfw
|
||||
|
||||
#include "Kernel.hpp"
|
||||
#include "exceptions.hpp"
|
||||
|
||||
namespace photon
|
||||
{
|
||||
|
||||
AppCore::AppCore() :
|
||||
dispWidth_(0), dispHeight_(0),
|
||||
task_(new UpdateTask())
|
||||
{
|
||||
util::VersionInfo glfwReq(2,4,2); // requires GLFW 2.4.2
|
||||
util::ensureVersion("GLFW", initGLFW(), glfwReq);
|
||||
|
||||
Kernel::getInstance().addTask(task_);
|
||||
}
|
||||
|
||||
AppCore::~AppCore()
|
||||
{
|
||||
glfwCloseWindow(); //close GLFW window
|
||||
glfwTerminate(); //shutdown GLFW
|
||||
}
|
||||
|
||||
void AppCore::createDisplay(uint width, uint height,
|
||||
uint redBits, uint greenBits, uint blueBits,
|
||||
uint alphaBits, uint depthBits, uint stencilBits,
|
||||
@ -35,8 +52,6 @@ void AppCore::createDisplay(uint width, uint height,
|
||||
dispHeight_ = height;
|
||||
|
||||
glfwSetWindowTitle(title.c_str()); // title is set separately
|
||||
|
||||
quitRequested_ = false; //now that a window is open, no quit requested
|
||||
}
|
||||
|
||||
void AppCore::createDisplay(uint width, uint height, uint bpp,
|
||||
@ -81,16 +96,12 @@ bool AppCore::mouseButtonPressed(MouseButton button)
|
||||
|
||||
int AppCore::getMouseX()
|
||||
{
|
||||
int x;
|
||||
glfwGetMousePos(&x,0); //only get x
|
||||
return x;
|
||||
return task_->mouseX_;
|
||||
}
|
||||
|
||||
int AppCore::getMouseY()
|
||||
{
|
||||
int y;
|
||||
glfwGetMousePos(0,&y); //only get y
|
||||
return y;
|
||||
return task_->mouseY_;
|
||||
}
|
||||
|
||||
int AppCore::getMouseWheelPos()
|
||||
@ -100,44 +111,7 @@ int AppCore::getMouseWheelPos()
|
||||
|
||||
scalar AppCore::getTime()
|
||||
{
|
||||
return glfwGetTime() - pausedTime_;
|
||||
}
|
||||
|
||||
void AppCore::update()
|
||||
{
|
||||
scalar curTime = getTime();
|
||||
|
||||
// update the display here instead of VideoCore (since it belongs to glfw)
|
||||
glfwSwapBuffers();
|
||||
|
||||
// keep track of time between frames
|
||||
secPerFrame_ = curTime-lastUpdate_;
|
||||
lastUpdate_ = curTime;
|
||||
|
||||
// quit on window closing or Alt-F4/Alt-X
|
||||
if(!glfwGetWindowParam(GLFW_OPENED) ||
|
||||
( (glfwGetKey(GLFW_KEY_LALT) || glfwGetKey(GLFW_KEY_RALT)) &&
|
||||
(glfwGetKey(GLFW_KEY_F4) || glfwGetKey('X')) ) )
|
||||
{
|
||||
quitRequested_ = true;
|
||||
}
|
||||
|
||||
// hold active-state
|
||||
active_ = (glfwGetWindowParam(GLFW_ACTIVE) == GL_TRUE);
|
||||
|
||||
// automatically pause/unpause app timer on focus
|
||||
if(!active_ && !timerPaused_)
|
||||
{
|
||||
timerPaused_ = true;
|
||||
lastPause_ = curTime;
|
||||
unpauseOnActive_ = true;
|
||||
}
|
||||
else if(active_ && unpauseOnActive_)
|
||||
{
|
||||
timerPaused_ = true;
|
||||
pausedTime_ += curTime - lastPause_;
|
||||
unpauseOnActive_ = false;
|
||||
}
|
||||
return glfwGetTime() - task_->pausedTime_;
|
||||
}
|
||||
|
||||
void AppCore::setTitle(const std::string& title)
|
||||
@ -145,29 +119,19 @@ void AppCore::setTitle(const std::string& title)
|
||||
glfwSetWindowTitle(title.c_str());
|
||||
}
|
||||
|
||||
void AppCore::requestQuit()
|
||||
{
|
||||
quitRequested_ = true;
|
||||
}
|
||||
|
||||
bool AppCore::quitRequested()
|
||||
{
|
||||
return quitRequested_;
|
||||
}
|
||||
|
||||
bool AppCore::isActive()
|
||||
{
|
||||
return active_;
|
||||
return task_->active_;
|
||||
}
|
||||
|
||||
double AppCore::getElapsedTime()
|
||||
{
|
||||
return secPerFrame_;
|
||||
return task_->secPerFrame_;
|
||||
}
|
||||
|
||||
double AppCore::getFramerate()
|
||||
{
|
||||
return 1/secPerFrame_;
|
||||
return 1/task_->secPerFrame_;
|
||||
}
|
||||
|
||||
uint AppCore::getDisplayWidth()
|
||||
@ -191,21 +155,50 @@ util::VersionInfo AppCore::initGLFW()
|
||||
return util::VersionInfo(maj,min,patch);
|
||||
}
|
||||
|
||||
AppCore::AppCore() :
|
||||
dispWidth_(0), dispHeight_(0),
|
||||
quitRequested_(true), active_(false), timerPaused_(false),
|
||||
AppCore::UpdateTask::UpdateTask() :
|
||||
Task("AppCore::UpdateTask", PRI_CORE),
|
||||
mouseX_(0), mouseY_(0),
|
||||
active_(false), timerPaused_(false),
|
||||
unpauseOnActive_(false), lastPause_(0), pausedTime_(0),
|
||||
secPerFrame_(0), lastUpdate_(0)
|
||||
{
|
||||
util::VersionInfo glfwReq(2,4,2); // requires GLFW 2.4.2
|
||||
|
||||
util::ensureVersion("GLFW", initGLFW(), glfwReq);
|
||||
}
|
||||
|
||||
AppCore::~AppCore()
|
||||
void AppCore::UpdateTask::update()
|
||||
{
|
||||
glfwCloseWindow(); //close GLFW window
|
||||
glfwTerminate(); //shutdown GLFW
|
||||
scalar curTime = glfwGetTime() - pausedTime_;
|
||||
|
||||
// update the display here instead of VideoCore (since it belongs to glfw)
|
||||
glfwSwapBuffers();
|
||||
|
||||
// keep track of time between frames
|
||||
secPerFrame_ = curTime-lastUpdate_;
|
||||
lastUpdate_ = curTime;
|
||||
|
||||
// quit on window closing or Alt-F4/Alt-X
|
||||
if(!glfwGetWindowParam(GLFW_OPENED) ||
|
||||
( (glfwGetKey(GLFW_KEY_LALT) || glfwGetKey(GLFW_KEY_RALT)) &&
|
||||
(glfwGetKey(GLFW_KEY_F4) || glfwGetKey('X')) ) )
|
||||
{
|
||||
Kernel::getInstance().killAllTasks();
|
||||
}
|
||||
|
||||
// hold active-state
|
||||
active_ = (glfwGetWindowParam(GLFW_ACTIVE) == GL_TRUE);
|
||||
|
||||
// automatically pause/unpause app timer on focus
|
||||
if(!active_ && !timerPaused_)
|
||||
{
|
||||
timerPaused_ = true;
|
||||
lastPause_ = curTime;
|
||||
unpauseOnActive_ = true;
|
||||
}
|
||||
else if(active_ && unpauseOnActive_)
|
||||
{
|
||||
timerPaused_ = true;
|
||||
pausedTime_ += curTime - lastPause_;
|
||||
unpauseOnActive_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,15 +5,20 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Application.cpp,v 1.5 2005/02/27 07:43:37 cozman Exp $
|
||||
|
||||
// $Id: Application.cpp,v 1.6 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "exceptions.hpp"
|
||||
|
||||
#include "physfs.h"
|
||||
#include "gl/gl.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "exceptions.hpp"
|
||||
#include "Log.hpp"
|
||||
#include "Kernel.hpp"
|
||||
#include "AppCore.hpp"
|
||||
#include "video/VideoCore.hpp"
|
||||
|
||||
namespace photon
|
||||
{
|
||||
@ -23,12 +28,36 @@ Application::Application() :
|
||||
{
|
||||
util::VersionInfo physfsReq(1,0,0); // requires PhysFS 1.0.0
|
||||
|
||||
// create the singletons
|
||||
new Log;
|
||||
new Kernel;
|
||||
new AppCore;
|
||||
new video::VideoCore;
|
||||
|
||||
// StrVec args;
|
||||
//
|
||||
// for(int i=0; i < argc; ++i)
|
||||
// {
|
||||
// args.push_back(argv[i]);
|
||||
// }
|
||||
|
||||
util::ensureVersion("PhysFS", initPhysFS(arg0_.c_str()), physfsReq);
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
PHYSFS_deinit(); //shutdown PhysFS
|
||||
|
||||
// destroy the singletons
|
||||
AppCore::destroy();
|
||||
video::VideoCore::destroy();
|
||||
Kernel::destroy();
|
||||
Log::destroy();
|
||||
}
|
||||
|
||||
void Application::setInitOptions(const char* arg0)
|
||||
{
|
||||
arg0_ = arg0;
|
||||
}
|
||||
|
||||
util::VersionInfo Application::initPhysFS(const char* arg0)
|
||||
@ -40,11 +69,6 @@ util::VersionInfo Application::initPhysFS(const char* arg0)
|
||||
return util::VersionInfo(ver.major, ver.minor, ver.patch);
|
||||
}
|
||||
|
||||
void Application::setInitOptions(const char* appPath)
|
||||
{
|
||||
arg0_ = appPath;
|
||||
}
|
||||
|
||||
std::string Application::arg0_; //static initializer
|
||||
std::string Application::arg0_;
|
||||
|
||||
}
|
||||
|
155
src/Kernel.cpp
Normal file
155
src/Kernel.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
//This file is part of Photon (http://photon.sourceforge.net)
|
||||
//Copyright (C) 2004-2005 James Turk
|
||||
//
|
||||
// Author:
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Kernel.cpp,v 1.1 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
#include "Kernel.hpp"
|
||||
|
||||
#include "exceptions.hpp"
|
||||
|
||||
#include "Log.hpp"
|
||||
|
||||
namespace photon
|
||||
{
|
||||
|
||||
Kernel::Kernel()
|
||||
{
|
||||
}
|
||||
|
||||
Kernel::~Kernel()
|
||||
{
|
||||
}
|
||||
|
||||
void Kernel::run()
|
||||
{
|
||||
// loop on activeTasks
|
||||
while(!tasks_.empty())
|
||||
{
|
||||
std::list<TaskPtr>::iterator it;
|
||||
|
||||
// loop through active tasks, updating each one
|
||||
for(it = tasks_.begin(); it != tasks_.end(); ++it)
|
||||
{
|
||||
TaskPtr& task(*it);
|
||||
|
||||
// only update alive, non-paused tasks
|
||||
if(task->isAlive() && !task->isPaused())
|
||||
{
|
||||
// Log::getInstance().note() << "updating task : " << task->getName();
|
||||
task->update();
|
||||
}
|
||||
}
|
||||
|
||||
// loop through tasks, removing any dead tasks
|
||||
for(it = tasks_.begin(); it != tasks_.end(); )
|
||||
{
|
||||
TaskPtr& task(*it);
|
||||
|
||||
// remove dead tasks
|
||||
if(!task->isAlive())
|
||||
{
|
||||
task->onKill();
|
||||
it = tasks_.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it; //advance iterator, if not deleting
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Kernel::addTask(TaskPtr task)
|
||||
{
|
||||
std::list<TaskPtr>::iterator it = tasks_.begin();
|
||||
std::list<TaskPtr>::iterator found = std::find_if(tasks_.begin(),
|
||||
tasks_.end(),
|
||||
std::bind2nd(TaskNameEq(), task->getName()) );
|
||||
|
||||
// if found task (meaning task w/ same name exists) throw exception
|
||||
if(found != tasks_.end())
|
||||
{
|
||||
throw PreconditionException("Attempted to add duplicate task \"" +
|
||||
task->getName() + "\".");
|
||||
}
|
||||
|
||||
task->onStart();
|
||||
|
||||
// find the first task in the list with a lower priority
|
||||
while(it != tasks_.end() && task->getPriority() <= (*it)->getPriority())
|
||||
{
|
||||
++it;
|
||||
}
|
||||
tasks_.insert(it, task); // insert task after iterator
|
||||
}
|
||||
|
||||
void Kernel::killTask(const std::string& taskName)
|
||||
{
|
||||
std::list<TaskPtr>::iterator task = std::find_if(tasks_.begin(),
|
||||
tasks_.end(),
|
||||
std::bind2nd(TaskNameEq(), taskName) );
|
||||
if(task != tasks_.end())
|
||||
{
|
||||
(*task)->kill();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw PreconditionException("Attempted to kill nonexistant task \"" +
|
||||
taskName + "\".");
|
||||
}
|
||||
}
|
||||
|
||||
void Kernel::pauseTask(const std::string& taskName)
|
||||
{
|
||||
std::list<TaskPtr>::iterator task = std::find_if(tasks_.begin(),
|
||||
tasks_.end(),
|
||||
std::bind2nd(TaskNameEq(), taskName) );
|
||||
if(task != tasks_.end())
|
||||
{
|
||||
(*task)->onPause();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw PreconditionException("Attempted to pause nonexistant task \"" +
|
||||
taskName + "\".");
|
||||
}
|
||||
}
|
||||
|
||||
void Kernel::unpauseTask(const std::string& taskName)
|
||||
{
|
||||
std::list<TaskPtr>::iterator task = std::find_if(tasks_.begin(),
|
||||
tasks_.end(),
|
||||
std::bind2nd(TaskNameEq(), taskName) );
|
||||
if(task != tasks_.end())
|
||||
{
|
||||
(*task)->onUnpause();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw PreconditionException("Attempted to unpause nonexistant task \"" +
|
||||
taskName + "\".");
|
||||
}
|
||||
}
|
||||
|
||||
void Kernel::killAllTasks()
|
||||
{
|
||||
// set all tasks to dead
|
||||
for(std::list<TaskPtr>::iterator it = tasks_.begin();
|
||||
it != tasks_.end();
|
||||
++it)
|
||||
{
|
||||
(*it)->kill();
|
||||
}
|
||||
}
|
||||
|
||||
bool Kernel::TaskNameEq::operator()(const TaskPtr& lhs,
|
||||
const std::string& rhs) const
|
||||
{
|
||||
return lhs->getName() == rhs;
|
||||
}
|
||||
|
||||
}
|
62
src/Task.cpp
Normal file
62
src/Task.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
//This file is part of Photon (http://photon.sourceforge.net)
|
||||
//Copyright (C) 2004-2005 James Turk
|
||||
//
|
||||
// Author:
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Task.cpp,v 1.1 2005/03/15 19:22:07 cozman Exp $
|
||||
|
||||
#include "Task.hpp"
|
||||
|
||||
namespace photon
|
||||
{
|
||||
|
||||
Task::Task(const std::string& name, PriorityLevel priority) :
|
||||
name_(name), priority_(priority), alive_(true), paused_(false)
|
||||
{
|
||||
}
|
||||
|
||||
// do nothing (how I wish destructors were virtual by default)
|
||||
Task::~Task() { }
|
||||
|
||||
// do nothings (non-pure since some tasks may not need special behavior)
|
||||
void Task::onStart() { }
|
||||
void Task::onKill() { }
|
||||
|
||||
void Task::onPause()
|
||||
{
|
||||
paused_ = true;
|
||||
}
|
||||
|
||||
void Task::onUnpause()
|
||||
{
|
||||
paused_ = false;
|
||||
}
|
||||
|
||||
void Task::kill()
|
||||
{
|
||||
alive_ = false;
|
||||
}
|
||||
|
||||
std::string Task::getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
PriorityLevel Task::getPriority() const
|
||||
{
|
||||
return priority_;
|
||||
}
|
||||
|
||||
bool Task::isAlive() const
|
||||
{
|
||||
return alive_;
|
||||
}
|
||||
|
||||
bool Task::isPaused() const
|
||||
{
|
||||
return paused_;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user