diff --git a/include/audio/AudioCore.hpp b/include/audio/AudioCore.hpp index fe3acd2..f7f4da2 100644 --- a/include/audio/AudioCore.hpp +++ b/include/audio/AudioCore.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: AudioCore.hpp,v 1.1 2005/02/27 05:55:18 cozman Exp $ +// $Id: AudioCore.hpp,v 1.2 2005/03/01 07:51:23 cozman Exp $ #ifndef PHOTON_AUDIO_AUDIOCORE_HPP #define PHOTON_AUDIO_AUDIOCORE_HPP @@ -21,18 +21,44 @@ namespace photon namespace audio { +// Class: AudioCore +// Photon's core for audio manipulation/control. Defines the +// interface through which all audio related functions are performed. +// +// Parent: +// class AudioCore : public util::Singleton { -public: - std::string getAudioDeviceName() const; +// Group: Accessors +public: + // Function: getAudioDeviceName + // Get name of active audio device. + // + // Returns: + // Name of audio device currently in use. + std::string getAudioDeviceName() const; + +// Group: Initialization +public: + // Function: setDesiredDevice + // Set the name of the desired audio device to use. Static function of + // AudioCore, must be called before AudioCore::initialize() or not at all. + // + // If called, the initialization of the audio library will attempt to + // use the specified audio device, otherwise the default device will be + // used. + // + // Parameters: + // name - Name of audio device to use. + static void setDesiredDevice(const std::string& name); + +// OpenAL specifics private: util::VersionInfo initOpenAL(); static std::string checkOpenALError(); -public: - static void setDesiredDevice(const std::string& name); - +// data members private: static std::string deviceName_; diff --git a/include/math/Vector2.hpp b/include/math/Vector2.hpp index 2d94ee5..827f703 100644 --- a/include/math/Vector2.hpp +++ b/include/math/Vector2.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Vector2.hpp,v 1.1 2005/02/27 09:00:13 cozman Exp $ +// $Id: Vector2.hpp,v 1.2 2005/03/01 07:51:23 cozman Exp $ #ifndef PHOTON_MATH_VECTOR2_HPP #define PHOTON_MATH_VECTOR2_HPP @@ -207,8 +207,11 @@ public: Vector2 operator*(scalar lhs, const Vector2 &rhs); +// Group: External Utilities + // Function: magnitude -// Find length of a vector. +// Find length of a vector. +// Same as a call to v.getMagnitude() but provided for convinience. // // Parameters: // v - Vector to calculate magnitude of @@ -217,6 +220,8 @@ Vector2 operator*(scalar lhs, const Vector2 &rhs); // Length of the vector. scalar magnitude(const Vector2 &v); +// Group: Aliases + // Typedef: Point2 // Alias for Vector2 type. typedef Vector2 Point2; diff --git a/include/math/math.hpp b/include/math/math.hpp index 341e8ae..ff52663 100644 --- a/include/math/math.hpp +++ b/include/math/math.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: math.hpp,v 1.1 2005/02/27 09:00:13 cozman Exp $ +// $Id: math.hpp,v 1.2 2005/03/01 07:51:23 cozman Exp $ #ifndef PHOTON_MATH_MATH_HPP #define PHOTON_MATH_MATH_HPP @@ -21,6 +21,10 @@ namespace math class Vector2; +// Title: Math Utilities + +// Group: Generic + // Function: clamp // Clamp a value between two boundaries. // @@ -57,6 +61,8 @@ bool scalarCompare(scalar val1, scalar val2, scalar epsilon=0.000001); // Scalar distance between the two points. scalar distance(Vector2 v1, Vector2 v2); +// Group: Degrees/Radians + // Function: degToRad // Convert degrees to radians. // diff --git a/include/util/Singleton.hpp b/include/util/Singleton.hpp index c03ee97..f8144cd 100644 --- a/include/util/Singleton.hpp +++ b/include/util/Singleton.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Singleton.hpp,v 1.3 2005/02/27 07:43:37 cozman Exp $ +// $Id: Singleton.hpp,v 1.4 2005/03/01 07:51:23 cozman Exp $ #ifndef PHOTON_UTIL_SINGLETON_HPP #define PHOTON_UTIL_SINGLETON_HPP @@ -18,17 +18,55 @@ namespace photon namespace util { +// Class: Singleton +// Template class for singleton pattern. Is non-copyable to enforce +// correct behavior. +// +// Defining a Singleton: +// (code) +// YourClass : public Singleton +// { +// // class specific data +// +// // Singleton-required code +// private: +// // Singleton-required code +// YourClass(); +// ~YourClass(); +// +// friend class util::Singleton; +// friend class std::auto_ptr; +// }; +// (end) +// +// Using The Singleton: +// (code) +// YourClass::initialize(); +// YourClass& yc(YourClass::getInstance()); +// +// // use yc +// +// YourClass::destroy(); //optional +// (end) template class Singleton : public boost::noncopyable { public: + + // Function: initialize + // Initialize the instance of the singleton, must be done explicitly. static void initialize(); + // Function: destroy + // Destroy the instance of the singleton, can be done explicitly if order + // of destruction matters. Will be done automatically if not done. static void destroy(); + // Function: getInstance + // Get a reference to the instance of the derived class. static T& getInstance(); -protected: +protected: virtual ~Singleton()=0; private: diff --git a/include/util/VersionInfo.hpp b/include/util/VersionInfo.hpp index 32894bf..1b32ef7 100644 --- a/include/util/VersionInfo.hpp +++ b/include/util/VersionInfo.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: VersionInfo.hpp,v 1.3 2005/02/27 05:50:39 cozman Exp $ +// $Id: VersionInfo.hpp,v 1.4 2005/03/01 07:51:24 cozman Exp $ #ifndef PHOTON_UTIL_VERSIONINFO_HPP #define PHOTON_UTIL_VERSIONINFO_HPP @@ -78,6 +78,8 @@ public: friend std::ostream& operator<<(std::ostream &o, const VersionInfo &rhs); }; +// Section: VersionInfo Utilities + // Function: ensureVersion // Checks a version of a library against the required version, throws // an APIError if the version is not met. diff --git a/src/AppCore.cpp b/src/AppCore.cpp index 2013bf4..02c4e7a 100644 --- a/src/AppCore.cpp +++ b/src/AppCore.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: AppCore.cpp,v 1.1 2005/02/27 07:43:37 cozman Exp $ +// $Id: AppCore.cpp,v 1.2 2005/03/01 07:52:20 cozman Exp $ #include "AppCore.hpp" @@ -95,7 +95,71 @@ int AppCore::getMouseWheelPos() scalar AppCore::getTime() { - return glfwGetTime(); + return glfwGetTime() - pausedTime_; +} + +void AppCore::update() +{ + scalar curTime = getTime(); + + // 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; + } +} + +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_; +} + +double AppCore::getElapsedTime() +{ + return secPerFrame_; +} + +double AppCore::getFramerate() +{ + return 1/secPerFrame_; } util::VersionInfo AppCore::initGLFW() @@ -109,7 +173,10 @@ util::VersionInfo AppCore::initGLFW() return util::VersionInfo(maj,min,patch); } -AppCore::AppCore() +AppCore::AppCore() : + quitRequested_(true), 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 diff --git a/src/Log.cpp b/src/Log.cpp index 13e6c72..ab423a8 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Log.cpp,v 1.6 2005/02/27 05:53:01 cozman Exp $ +// $Id: Log.cpp,v 1.7 2005/03/01 07:52:20 cozman Exp $ #include "Log.hpp" @@ -22,7 +22,7 @@ Log::Log() Log::~Log() { flush(); - removeSinks(); + removeSinks();; } void Log::addSink(LogSinkPtr sink)