Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lin_time.h File Reference
#include "vegastrike.h"

Go to the source code of this file.

Macros

#define VEGA_EPOCH   1136073600.
 

Functions

void InitTime ()
 
double GetElapsedTime ()
 
void UpdateTime ()
 
void micro_sleep (unsigned int n)
 
double getNewTime ()
 
void setNewTime (double newnewtime)
 
double queryTime ()
 
double realTime ()
 
float getTimeCompression ()
 
void setTimeCompression (float tc)
 

Macro Definition Documentation

#define VEGA_EPOCH   1136073600.

Definition at line 26 of file lin_time.h.

Referenced by main().

Function Documentation

float getTimeCompression ( )

Definition at line 102 of file lin_time.cpp.

103 {
104  return timecompression;
105 }
void InitTime ( )

Definition at line 165 of file lin_time.cpp.

Referenced by bootstrap_main_loop(), main(), AccountServer::start(), and NetServer::start().

166 {
167 #ifdef WIN32
168  QueryPerformanceFrequency( (LARGE_INTEGER*) &freq );
169  QueryPerformanceCounter( (LARGE_INTEGER*) &ttime );
170 
171 #elif defined (HAVE_GETTIMEOFDAY)
172  struct timeval tv;
173  (void) gettimeofday( &tv, NULL );
174 
175  newtime = (double) tv.tv_sec+(double) tv.tv_usec*1.e-6;
176  lasttime = newtime-.001;
177 
178 #elif defined (HAVE_SDL)
179  newtime = SDL_GetTicks()*1.e-3;
180  lasttime = newtime-.001;
181 
182 #else
183 # error "We have no way to determine the time on this system."
184 #endif
185  elapsedtime = .001;
186 }
void micro_sleep ( unsigned int  n)

Definition at line 153 of file lin_time.cpp.

154 {
155  struct timeval tv = {
156  0, 0
157  };
158 
159  tv.tv_usec = n%1000000;
160  tv.tv_sec = n/1000000;
161  select( 0, NULL, NULL, NULL, &tv );
162 }
double queryTime ( )

Definition at line 193 of file lin_time.cpp.

References firsttime.

Referenced by Orders::FireAt::ChooseTargets(), GameStarSystem::Draw(), GameCockpit::Draw(), Orders::AggressiveAI::Execute(), GFXGetFramerate(), NetClient::loginAcctLoop(), VsnetHTTPSocket::need_test_writable(), VsnetHTTPSocket::reopenConnection(), VsnetHTTPSocket::resendData(), setNewTime(), NetClient::synchronizeTime(), StarSystem::Update(), GameUnit< UnitType >::UpdatePhysics2(), and StarSystem::UpdateUnitPhysics().

194 {
195 #ifdef WIN32
196  LONGLONG tmpnewtime;
197  QueryPerformanceCounter( (LARGE_INTEGER*) &tmpnewtime );
198  return ( (double) tmpnewtime )/(double) freq-firsttime;
199 #elif defined (HAVE_GETTIMEOFDAY)
200  struct timeval tv;
201  (void) gettimeofday( &tv, NULL );
202  double tmpnewtime = (double) tv.tv_sec+(double) tv.tv_usec*1.e-6;
203  return tmpnewtime-firsttime;
204 #elif defined (HAVE_SDL)
205  double tmpnewtime = SDL_GetTicks()*1.e-3;
206  return tmpnewtime-firsttime;
207 #else
208 # error "We have no way to determine the time on this system."
209  return 0.;
210 #endif
211 }
double realTime ( )

Definition at line 213 of file lin_time.cpp.

Referenced by Audio::SceneManager::commit(), BaseInterface::Room::BaseVSMovie::Draw(), Audio::getRealTime(), Mount::PhysicsAlignedFire(), BaseInterface::Room::BaseVSMovie::SetHidePointer(), Audio::Test::testMultiStreaming(), Audio::Test::testMultiStreaming2(), Audio::Test::testStreaming(), and AnimatedTexture::UpdateAllFrame().

214 {
215 #ifdef WIN32
216  LONGLONG tmpnewtime;
217  QueryPerformanceCounter( (LARGE_INTEGER*) &tmpnewtime );
218  return ( (double) tmpnewtime )/(double) freq;
219 #elif defined (HAVE_GETTIMEOFDAY)
220  struct timeval tv;
221  (void) gettimeofday( &tv, NULL );
222  double tmpnewtime = (double) tv.tv_sec+(double) tv.tv_usec*1.e-6;
223 #elif defined (HAVE_SDL)
224  double tmpnewtime = SDL_GetTicks()*1.e-3;
225 #else
226 # error "We have no way to determine the time on this system."
227  double tmpnewtime = 0.;
228 #endif
229 
230  static double reallyfirsttime = tmpnewtime;
231  return tmpnewtime - reallyfirsttime;
232 }
void setNewTime ( double  newnewtime)

Definition at line 268 of file lin_time.cpp.

References firsttime, queryTime(), and UpdateTime().

Referenced by bootstrap_main_loop(), main(), and NetClient::synchronizeTime().

269 {
270  firsttime -= newnewtime-queryTime();
271  UpdateTime();
272 }
void setTimeCompression ( float  tc)

Definition at line 107 of file lin_time.cpp.

Referenced by UniverseUtil::SetTimeCompression(), and toggle_pause().

108 {
109  timecompression = tc;
110  timecount = 0; //to avoid any problems with time compression sounds... use getTimeCompression() instead
111 }
void UpdateTime ( )

Definition at line 234 of file lin_time.cpp.

References first(), firsttime, lasttime, newtime, and timecompression.

Referenced by AccountServer::AccountServer(), base_main_loop(), bootstrap_draw(), bootstrap_main_loop(), createObjects(), gamemenu_draw(), GameStarSystem::GameStarSystem(), main(), NetServer::NetServer(), setNewTime(), AccountServer::start(), NetServer::start(), and GameUniverse::StartDraw().

235 {
236  static bool first=true;
237 #ifdef WIN32
238  QueryPerformanceCounter( (LARGE_INTEGER*) &newtime );
239  elapsedtime = ( (double) (newtime-ttime) )/freq;
240  ttime = newtime;
241  if (freq == 0)
242  dblnewtime = 0.;
243  else
244  dblnewtime = ( (double) newtime )/( (double) freq );
245  if (first)
246  firsttime = dblnewtime;
247 #elif defined (HAVE_GETTIMEOFDAY)
248  struct timeval tv;
249  (void) gettimeofday( &tv, NULL );
250  lasttime = newtime;
251  newtime = (double) tv.tv_sec+(double) tv.tv_usec*1.e-6;
253  if (first)
254  firsttime = newtime;
255 #elif defined (HAVE_SDL)
256  lasttime = newtime;
257  newtime = SDL_GetTicks()*1.e-3;
259  if (first)
260  firsttime = newtime;
261 #else
262 # error "We have no way to determine the time on this system."
263 #endif
265  first=false;
266 }