OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Assaf Muller's Timer Manager
View page
Source of version: 3
(current)
Timer_Manager from Assaf Muller on the 17th of June, 2007. {maketoc} This wiki page will show a Timer class & Timer Factory class duo to help you with all things timing! Notice that this manager is under no license. Use it however you wish. !!Timer Class Header {CODE(wrap="1", colors="c++")}#ifndef TIMER_H #define TIMER_H #include <string> #include "Ogre.h" using namespace std; using namespace Ogre; class TimerObject { private: Real mTime; bool mDone; public: TimerObject(); TimerObject(Real time); ~TimerObject(); Real elpased(); bool done(); void reset(); void reset(Real time); Timer mTimer; }; #endif{CODE} !!Timer Class Implementation {CODE(wrap="1", colors="c++")} #include "Timer.h" TimerObject::TimerObject() { TimerObject(0.0); } TimerObject::TimerObject (Real time = 0) : mTime(time) { mDone = false; mTimer.reset(); } TimerObject::~TimerObject() { } Real TimerObject::elpased() { return mTimer.getMilliseconds() * 0.001; } bool TimerObject::done() { if(!mDone) // If not done if(mTimer.getMilliseconds() * 0.001 > mTime) mDone = true; return mDone; } void TimerObject::reset() { mDone = false; mTimer.reset(); } void TimerObject::reset(Real time) { mTime = time; mDone = false; mTimer.reset(); } {CODE} !!Timer Factory Header {CODE(wrap="1", colors="c++")} #ifndef TIMER_FACTORY_H #define TIMER_FACTORY_H #include <OgreSingleton.h> #include "Timer.h" #include <map> using namespace std; class TimerFactory : public Ogre::Singleton<TimerFactory> { private: map<string, TimerObject> mTimers; public: void create(string name, Real time = 0); void destroy(string name); bool exists(string name); TimerObject& operator [] (string name); ~TimerFactory(); }; template <> TimerFactory* Ogre::Singleton<TimerFactory>::ms_Singleton = 0; #endif {CODE} !!Timer Factory Implementation {CODE(wrap="1", colors="c++")} #include "TimerFactory.h" void TimerFactory::create(string name, Real time) { if(mTimers.find(name) == mTimers.end()) mTimers[name] = TimerObject(time); } void TimerFactory::destroy(string name) { map<string, TimerObject>::iterator i = mTimers.find(name); if(i != mTimers.end()) mTimers.erase(i); } bool TimerFactory::exists(string name) { map<string, TimerObject>::iterator i = mTimers.find(name); if(i != mTimers.end()) return true; return false; } TimerObject& TimerFactory::operator [] (string name) { if(mTimers.find(name) != mTimers.end()) return mTimers[name]; else throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS, "Tried to access a non-existant timer!", "TimerFactory::operator []"); } TimerFactory::~TimerFactory() { map<string, TimerObject>::iterator i = mTimers.begin(); while(!mTimers.empty()) { mTimers.erase(mTimers.begin()); } } {CODE}
Search by Tags
Search Wiki by Freetags
Latest Changes
One Function Ogre
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
...more
Search
Find
Advanced
Search Help
Online Users
200 online users