Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

TimerAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "TimerAgent.h"
00010 
00011 #include "OptionAgent.h"
00012 
00013 //-----------------------------------------------------------------
00014     void
00015 TimerAgent::own_init()
00016 {
00017     m_timeinterval = OptionAgent::agent()->getAsInt("timeinterval", 100);
00018     m_lastTime = SDL_GetTicks();
00019     m_nextTime = m_lastTime;
00020     m_deltaTime = 1;
00021     m_count = 0;
00022 }
00023 //-----------------------------------------------------------------
00024 /**
00025  * Game is faster with pressed Shift.
00026  */
00027 int
00028 TimerAgent::getTimeInterval()
00029 {
00030     int result = m_timeinterval;
00031 
00032     if (SDL_GetModState() & KMOD_SHIFT) {
00033         result = m_timeinterval / 4;
00034     }
00035     return result;
00036 }
00037 //-----------------------------------------------------------------
00038 /**
00039  * Sleep fixed number miliseconds.
00040  */
00041     void
00042 TimerAgent::own_update()
00043 {
00044     m_count++;
00045 
00046     Uint32 now = SDL_GetTicks();
00047     if (now < m_nextTime) {
00048         SDL_Delay(m_nextTime - now);
00049     }
00050 
00051     now = SDL_GetTicks();
00052     //NOTE: every cycle have fixed time interval
00053     m_nextTime = now + getTimeInterval();
00054 
00055     m_deltaTime = now - m_lastTime;
00056     m_lastTime = now;
00057 }

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2