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.cpp File Reference
#include "vegastrike.h"
#include "in_kb.h"
#include "vs_random.h"
#include <sys/time.h>
#include <sys/types.h>

Go to the source code of this file.

Functions

double getNewTime ()
 
void inc_time_compression (const KBData &, KBSTATE a)
 
void dec_time_compression (const KBData &, KBSTATE a)
 
void reset_time_compression (const KBData &, KBSTATE a)
 
void pause_key (const KBData &s, KBSTATE a)
 
float getTimeCompression ()
 
void setTimeCompression (float tc)
 
bool toggle_pause ()
 
void micro_sleep (unsigned int n)
 
void InitTime ()
 
double GetElapsedTime ()
 
double queryTime ()
 
double realTime ()
 
void UpdateTime ()
 
void setNewTime (double newnewtime)
 

Variables

static double firsttime
 
VSRandom vsrandom (time(NULL))
 
static double newtime
 
static double lasttime
 
static double elapsedtime = .1
 
static double timecompression = 1
 
int timecount
 

Function Documentation

void dec_time_compression ( const KBData ,
KBSTATE  a 
)

Definition at line 71 of file lin_time.cpp.

References PRESS.

Referenced by initGlobalCommandMap().

72 {
73  if (a == PRESS) {
74  timecompression /= 1.5;
75  timecount--;
76  }
77 }
void inc_time_compression ( const KBData ,
KBSTATE  a 
)

Definition at line 63 of file lin_time.cpp.

References PRESS.

Referenced by initGlobalCommandMap().

64 {
65  if (a == PRESS) {
66  timecompression *= 1.5;
67  timecount++;
68  }
69 }
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 }
void pause_key ( const KBData s,
KBSTATE  a 
)

Definition at line 87 of file lin_time.cpp.

References PRESS, and reset_time_compression().

88 {
89  static bool paused = false;
90  if (a == PRESS) {
91  if (paused == false) {
92  timecompression = .0000001;
93  timecount = 0;
94  paused = true;
95  } else {
96  paused = false;
98  }
99  }
100 }
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 reset_time_compression ( const KBData ,
KBSTATE  a 
)

Definition at line 79 of file lin_time.cpp.

References PRESS.

Referenced by GameCockpit::Draw(), initGlobalCommandMap(), and pause_key().

80 {
81  if (a == PRESS) {
82  timecompression = 1;
83  timecount = 0;
84  }
85 }
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 }
bool toggle_pause ( )

Keyboard parsing Parses keyboard commands

Definition at line 113 of file lin_time.cpp.

References setTimeCompression().

Referenced by FireKeyboard::Execute().

114 {
115  static bool paused = false;
116  if (paused)
117  {
119  paused = false;
120  }
121  else
122  {
123  setTimeCompression(.0000001);
124  paused = true;
125  }
126  return paused;
127 }
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 }

Variable Documentation

double elapsedtime = .1
static

Definition at line 47 of file lin_time.cpp.

Referenced by GetElapsedTime().

double firsttime
static
double lasttime
static

Definition at line 42 of file lin_time.cpp.

Referenced by GameUnit< UnitType >::Explode(), GFXGetFramerate(), and UpdateTime().

double newtime
static
double timecompression = 1
static

Definition at line 48 of file lin_time.cpp.

Referenced by getTimeCompression(), and UpdateTime().

int timecount

Definition at line 59 of file lin_time.cpp.

Referenced by UpdateTimeCompressionSounds().