engine: turn Platform_Sleep into an inline function that directly calls platform-specific delay functions
This commit is contained in:
parent
de1361d99d
commit
e14cd758ad
9 changed files with 30 additions and 35 deletions
|
@ -652,10 +652,10 @@ static qboolean Host_Autosleep( double dt, double scale )
|
||||||
// if we have allocated time window, try to sleep
|
// if we have allocated time window, try to sleep
|
||||||
if( timewindow > realsleeptime )
|
if( timewindow > realsleeptime )
|
||||||
{
|
{
|
||||||
// Sys_Sleep isn't guaranteed to sleep an exact amount of milliseconds
|
// Platform_Sleep isn't guaranteed to sleep an exact amount of milliseconds
|
||||||
// so we measure the real sleep time and use it to decrease the window
|
// so we measure the real sleep time and use it to decrease the window
|
||||||
double t1 = Sys_DoubleTime(), t2;
|
double t1 = Sys_DoubleTime(), t2;
|
||||||
Sys_Sleep( sleep ); // in msec!
|
Platform_Sleep( sleep ); // in msec!
|
||||||
t2 = Sys_DoubleTime();
|
t2 = Sys_DoubleTime();
|
||||||
realsleeptime = t2 - t1;
|
realsleeptime = t2 - t1;
|
||||||
|
|
||||||
|
|
|
@ -1523,7 +1523,7 @@ static int NET_SendLong( netsrc_t sock, int net_socket, const char *buf, size_t
|
||||||
total_sent += size;
|
total_sent += size;
|
||||||
len -= size;
|
len -= size;
|
||||||
packet_number++;
|
packet_number++;
|
||||||
Sys_Sleep( 1 );
|
Platform_Sleep( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return total_sent;
|
return total_sent;
|
||||||
|
|
|
@ -117,22 +117,6 @@ char *Sys_GetClipboardData( void )
|
||||||
}
|
}
|
||||||
#endif // XASH_DEDICATED
|
#endif // XASH_DEDICATED
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
Sys_Sleep
|
|
||||||
|
|
||||||
freeze application for some time
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
void Sys_Sleep( int msec )
|
|
||||||
{
|
|
||||||
if( !msec )
|
|
||||||
return;
|
|
||||||
|
|
||||||
msec = Q_min( msec, 1000 );
|
|
||||||
Platform_Sleep( msec );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
================
|
================
|
||||||
Sys_GetCurrentUser
|
Sys_GetCurrentUser
|
||||||
|
@ -370,7 +354,7 @@ static void Sys_WaitForQuit( void )
|
||||||
TranslateMessage( &msg );
|
TranslateMessage( &msg );
|
||||||
DispatchMessage( &msg );
|
DispatchMessage( &msg );
|
||||||
}
|
}
|
||||||
else Sys_Sleep( 20 );
|
else Platform_Sleep( 20 );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -420,7 +404,7 @@ void Sys_Error( const char *error, ... )
|
||||||
return; // don't multiple executes
|
return; // don't multiple executes
|
||||||
|
|
||||||
// make sure that console received last message
|
// make sure that console received last message
|
||||||
if( host.change_game ) Sys_Sleep( 200 );
|
if( host.change_game ) Platform_Sleep( 200 );
|
||||||
|
|
||||||
error_on_exit = 1;
|
error_on_exit = 1;
|
||||||
host.status = HOST_ERR_FATAL;
|
host.status = HOST_ERR_FATAL;
|
||||||
|
|
|
@ -42,7 +42,6 @@ writes into struct by offsets not names
|
||||||
========================================================================
|
========================================================================
|
||||||
*/
|
*/
|
||||||
extern int error_on_exit;
|
extern int error_on_exit;
|
||||||
void Sys_Sleep( int msec );
|
|
||||||
double Sys_DoubleTime( void );
|
double Sys_DoubleTime( void );
|
||||||
char *Sys_GetClipboardData( void );
|
char *Sys_GetClipboardData( void );
|
||||||
const char *Sys_GetCurrentUser( void );
|
const char *Sys_GetCurrentUser( void );
|
||||||
|
|
|
@ -40,12 +40,8 @@ double Platform_DoubleTime( void )
|
||||||
{
|
{
|
||||||
return 0.005*ticks;
|
return 0.005*ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_Sleep( int msec )
|
|
||||||
{
|
|
||||||
//usleep( msec * 1000 );
|
|
||||||
}
|
|
||||||
#endif // XASH_TIMER == TIMER_DOS
|
#endif // XASH_TIMER == TIMER_DOS
|
||||||
|
|
||||||
#define PIT_FREQUENCY 0x1234DDL
|
#define PIT_FREQUENCY 0x1234DDL
|
||||||
#define frequency 140
|
#define frequency 140
|
||||||
#define counter PIT_FREQUENCY/frequency
|
#define counter PIT_FREQUENCY/frequency
|
||||||
|
|
|
@ -31,7 +31,6 @@ GNU General Public License for more details.
|
||||||
==============================================================================
|
==============================================================================
|
||||||
*/
|
*/
|
||||||
double Platform_DoubleTime( void );
|
double Platform_DoubleTime( void );
|
||||||
void Platform_Sleep( int msec );
|
|
||||||
void Platform_ShellExecute( const char *path, const char *parms );
|
void Platform_ShellExecute( const char *path, const char *parms );
|
||||||
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow );
|
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow );
|
||||||
void Platform_SetStatus( const char *status );
|
void Platform_SetStatus( const char *status );
|
||||||
|
@ -52,11 +51,13 @@ void IOS_LaunchDialog( void );
|
||||||
#if XASH_POSIX
|
#if XASH_POSIX
|
||||||
void Posix_Daemonize( void );
|
void Posix_Daemonize( void );
|
||||||
void Posix_SetupSigtermHandling( void );
|
void Posix_SetupSigtermHandling( void );
|
||||||
|
void Posix_Sleep( int msec );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if XASH_SDL
|
#if XASH_SDL
|
||||||
void SDLash_Init( void );
|
void SDLash_Init( void );
|
||||||
void SDLash_Shutdown( void );
|
void SDLash_Shutdown( void );
|
||||||
|
void SDLash_Sleep( int msec );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if XASH_ANDROID
|
#if XASH_ANDROID
|
||||||
|
@ -77,6 +78,7 @@ void Wcon_ShowConsole( qboolean show );
|
||||||
void Wcon_DisableInput( void );
|
void Wcon_DisableInput( void );
|
||||||
char *Wcon_Input( void );
|
char *Wcon_Input( void );
|
||||||
void Wcon_WinPrint( const char *pMsg );
|
void Wcon_WinPrint( const char *pMsg );
|
||||||
|
void Win32_Sleep( int msec );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if XASH_NSWITCH
|
#if XASH_NSWITCH
|
||||||
|
@ -165,6 +167,19 @@ static inline void Platform_SetupSigtermHandling( void )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void Platform_Sleep( int msec )
|
||||||
|
{
|
||||||
|
#if XASH_TIMER == TIMER_SDL
|
||||||
|
SDLash_Sleep( msec );
|
||||||
|
#elif XASH_TIMER == TIMER_POSIX
|
||||||
|
Posix_Sleep( msec );
|
||||||
|
#elif XASH_TIMER == TIMER_WIN32
|
||||||
|
Win32_Sleep( msec );
|
||||||
|
#else
|
||||||
|
// stub
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
|
|
|
@ -172,9 +172,10 @@ double Platform_DoubleTime( void )
|
||||||
#endif
|
#endif
|
||||||
return (double) ts.tv_sec + (double) ts.tv_nsec/1000000000.0;
|
return (double) ts.tv_sec + (double) ts.tv_nsec/1000000000.0;
|
||||||
}
|
}
|
||||||
|
#endif // XASH_TIMER == TIMER_POSIX
|
||||||
|
|
||||||
void Platform_Sleep( int msec )
|
void Posix_Sleep( int msec )
|
||||||
{
|
{
|
||||||
usleep( msec * 1000 );
|
usleep( msec * 1000 );
|
||||||
}
|
}
|
||||||
#endif // XASH_TIMER == TIMER_POSIX
|
|
||||||
|
|
|
@ -32,12 +32,12 @@ double Platform_DoubleTime( void )
|
||||||
CurrentTime = SDL_GetPerformanceCounter();
|
CurrentTime = SDL_GetPerformanceCounter();
|
||||||
return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency );
|
return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency );
|
||||||
}
|
}
|
||||||
|
#endif // XASH_TIMER == TIMER_SDL
|
||||||
|
|
||||||
void Platform_Sleep( int msec )
|
void SDLash_Sleep( int msec )
|
||||||
{
|
{
|
||||||
SDL_Delay( msec );
|
SDL_Delay( msec );
|
||||||
}
|
}
|
||||||
#endif // XASH_TIMER == TIMER_SDL
|
|
||||||
|
|
||||||
#if XASH_MESSAGEBOX == MSGBOX_SDL
|
#if XASH_MESSAGEBOX == MSGBOX_SDL
|
||||||
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
|
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
|
||||||
|
|
|
@ -34,12 +34,12 @@ double Platform_DoubleTime( void )
|
||||||
|
|
||||||
return (double)( CurrentTime.QuadPart - g_ClockStart.QuadPart ) / (double)( g_PerformanceFrequency.QuadPart );
|
return (double)( CurrentTime.QuadPart - g_ClockStart.QuadPart ) / (double)( g_PerformanceFrequency.QuadPart );
|
||||||
}
|
}
|
||||||
|
#endif // XASH_TIMER == TIMER_WIN32
|
||||||
|
|
||||||
void Platform_Sleep( int msec )
|
void Win32_Sleep( int msec )
|
||||||
{
|
{
|
||||||
Sleep( msec );
|
Sleep( msec );
|
||||||
}
|
}
|
||||||
#endif // XASH_TIMER == TIMER_WIN32
|
|
||||||
|
|
||||||
qboolean Platform_DebuggerPresent( void )
|
qboolean Platform_DebuggerPresent( void )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue