Port Sys_Milliseconds() to SDL

Sync with SDL and use unsigned int as return type.
Code outside of sys/ still uses signed ints to store the result.
This commit is contained in:
dhewg 2011-12-21 13:08:44 +01:00
parent 317e63887c
commit c994974ffc
8 changed files with 15 additions and 60 deletions

View file

@ -47,7 +47,7 @@ static int mwx, mwy;
static int mx = 0, my = 0;
// time mouse was last reset, we ignore the first 50ms of the mouse to allow settling of events
static int mouse_reset_time = 0;
static unsigned int mouse_reset_time = 0;
#define MOUSE_RESET_DELAY 50
// backup original values for pointer grab/ungrab

View file

@ -151,37 +151,6 @@ void Sys_Quit(void) {
Posix_Exit( EXIT_SUCCESS );
}
/*
================
Sys_Milliseconds
================
*/
/* base time in seconds, that's our origin
timeval:tv_sec is an int:
assuming this wraps every 0x7fffffff - ~68 years since the Epoch (1970) - we're safe till 2038
using unsigned long data type to work right with Sys_XTimeToSysTime */
unsigned long sys_timeBase = 0;
/* current time in ms, using sys_timeBase as origin
NOTE: sys_timeBase*1000 + curtime -> ms since the Epoch
0x7fffffff ms - ~24 days
or is it 48 days? the specs say int, but maybe it's casted from unsigned int?
*/
int Sys_Milliseconds( void ) {
int curtime;
struct timeval tp;
gettimeofday(&tp, NULL);
if (!sys_timeBase) {
sys_timeBase = tp.tv_sec;
return tp.tv_usec / 1000;
}
curtime = (tp.tv_sec - sys_timeBase) * 1000 + tp.tv_usec / 1000;
return curtime;
}
/*
================
Sys_Mkdir
@ -525,8 +494,6 @@ Posix_EarlyInit
void Posix_EarlyInit( void ) {
exit_spawn[0] = '\0';
Posix_InitSigs();
// set the base time
Sys_Milliseconds();
}
/*

View file

@ -39,9 +39,9 @@ If you have questions concerning this license or the applicable additional terms
#define MAX_OSPATH 256
static int frameNum;
static unsigned int frameNum;
int Sys_Milliseconds( void ) {
unsigned int Sys_Milliseconds( void ) {
return frameNum * 16;
}

View file

@ -149,7 +149,7 @@ void Sys_Sleep( int msec );
// Sys_Milliseconds should only be used for profiling purposes,
// any game related timing information should come from event timestamps
int Sys_Milliseconds( void );
unsigned int Sys_Milliseconds( void );
// for accurate performance testing
double Sys_GetClockTicks( void );

View file

@ -28,6 +28,7 @@ If you have questions concerning this license or the applicable additional terms
#include <SDL_mutex.h>
#include <SDL_thread.h>
#include <SDL_timer.h>
#include "sys/platform.h"
#include "framework/Common.h"
@ -51,6 +52,15 @@ void Sys_Sleep(int msec) {
SDL_Delay(msec);
}
/*
================
Sys_Milliseconds
================
*/
unsigned int Sys_Milliseconds() {
return SDL_GetTicks();
}
/*
==================
Sys_InitThreads

View file

@ -1037,9 +1037,6 @@ int main(int argc, char *argv[]) {
// no abort/retry/fail errors
SetErrorMode( SEM_FAILCRITICALERRORS );
// get the initial time base
Sys_Milliseconds();
#ifdef DEBUG
// disable the painfully slow MS heap check every 1024 allocs
_CrtSetDbgFlag( 0 );

View file

@ -841,7 +841,7 @@ typedef struct udpMsg_s {
byte data[MAX_UDP_MSG_SIZE];
netadr_t address;
int size;
int time;
unsigned int time;
struct udpMsg_s * next;
} udpMsg_t;

View file

@ -47,25 +47,6 @@ If you have questions concerning this license or the applicable additional terms
#pragma comment (lib, "wbemuuid.lib")
#endif
/*
================
Sys_Milliseconds
================
*/
int Sys_Milliseconds( void ) {
int sys_curtime;
static int sys_timeBase;
static bool initialized = false;
if ( !initialized ) {
sys_timeBase = timeGetTime();
initialized = true;
}
sys_curtime = timeGetTime() - sys_timeBase;
return sys_curtime;
}
/*
================
Sys_GetSystemRam