K3dTimer.cpp

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #include "K3dTimer.h"
00034 
00035 K3dTimer::K3dTimer(K3dGameData *_pGameData)
00036 {       
00037         m_pGameData = _pGameData;
00038         // Set this pointer to the game data
00039         m_pGameData->SetTimer(this);
00040         m_fFps = (float)1;
00041         m_uiLastTime = 0;
00042         m_uiNumFrames = 0;
00043         m_uiWaitingTime = 0;
00044 }
00045 
00046 
00047 K3dTimer::~K3dTimer()
00048 {
00049 }
00050 
00052 void K3dTimer::CalculateFPS()
00053 {
00055         unsigned int uiMiliseconds = SDL_GetTicks() - m_uiLastTime;
00056 
00058         if(uiMiliseconds == 0)
00059         {
00060                 uiMiliseconds = 1;
00061         }
00062 
00063         m_fFps = (float) 1 / (uiMiliseconds / (float) 1000);
00064         m_uiLastTime = SDL_GetTicks();
00065         // Add number of frames from game start
00066         m_uiNumFrames++;
00067 }
00068 
00070 bool  K3dTimer::Wait(const int _iMsec)
00071 {
00072         unsigned int uiCurrTime = SDL_GetTicks();
00073         unsigned int uiDelay = uiCurrTime - m_uiWaitingTime;
00074         if ((int) uiDelay >= _iMsec)
00075         {
00076                 m_uiWaitingTime = uiCurrTime;
00077                 return true;
00078         }
00079         return false;
00080 }
00081 
00082 

Generated on Thu Aug 16 23:53:28 2007 for K3dEngine by  doxygen 1.5.0