Timer.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 //----------------------------------------------------------------------------------
00014 // Includes
00015 //----------------------------------------------------------------------------------
00016 #include "Timer.h"
00017 
00018 
00019 namespace nrEngine{
00020         
00021         //------------------------------------------------------------------------
00022         Timer::Timer(Clock& clock): _clock(clock){
00023                 
00024                 // unpause the timer and set default scaling
00025                 setPause(false);
00026                 setScale (1.0f);
00027                 setFixFrameRate(false);
00028                 
00029                 // set default values
00030                 _currentTime = 0;
00031                 _frameTime = 0;
00032                 
00033         }
00034                 
00035         //------------------------------------------------------------------------
00036         Timer::~Timer(){
00037         
00038         }
00039                 
00040         //------------------------------------------------------------------------
00041         void Timer::notifyTimeObserver(){
00042                 // if there is no pause, so update times
00043                 if (!_bPaused){
00044                         float32 frameInterval = _bFixFrameRate ? _fixFrameTime : _clock.getFrameInterval();
00045                         _frameTime = frameInterval * _fScale;
00046                 }else{
00047                         _frameTime = 0;
00048                 }
00049 
00050                 // calculate current time
00051                 _currentTime += _frameTime;
00052         }
00053         
00054         //------------------------------------------------------------------------
00055         void Timer::setFixFrameRate(bool setFixRate, float32 fixFrameRate){
00056                 _bFixFrameRate = setFixRate;
00057                 _fixFrameTime = 1.0f / fixFrameRate;
00058         }
00059 
00060         
00061         //------------------------------------------------------------------------
00062         float32 Timer::getRealFrameInterval() const
00063         {
00064                 return _clock.getRealFrameInterval();
00065         }
00066 
00067 }; // end namespace     
00068 

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1