Skip to content

Commit

Permalink
engine: turn Platform_Sleep into an inline function that directly cal…
Browse files Browse the repository at this point in the history
…ls platform-specific delay functions
  • Loading branch information
a1batross committed Dec 4, 2024
1 parent de1361d commit e14cd75
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 35 deletions.
4 changes: 2 additions & 2 deletions engine/common/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@ static qboolean Host_Autosleep( double dt, double scale )
// if we have allocated time window, try to sleep
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
double t1 = Sys_DoubleTime(), t2;
Sys_Sleep( sleep ); // in msec!
Platform_Sleep( sleep ); // in msec!
t2 = Sys_DoubleTime();
realsleeptime = t2 - t1;

Expand Down
2 changes: 1 addition & 1 deletion engine/common/net_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ static int NET_SendLong( netsrc_t sock, int net_socket, const char *buf, size_t
total_sent += size;
len -= size;
packet_number++;
Sys_Sleep( 1 );
Platform_Sleep( 1 );
}

return total_sent;
Expand Down
20 changes: 2 additions & 18 deletions engine/common/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,6 @@ char *Sys_GetClipboardData( void )
}
#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
Expand Down Expand Up @@ -370,7 +354,7 @@ static void Sys_WaitForQuit( void )
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else Sys_Sleep( 20 );
else Platform_Sleep( 20 );
}
#endif
}
Expand Down Expand Up @@ -420,7 +404,7 @@ void Sys_Error( const char *error, ... )
return; // don't multiple executes

// 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;
host.status = HOST_ERR_FATAL;
Expand Down
1 change: 0 additions & 1 deletion engine/common/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ writes into struct by offsets not names
========================================================================
*/
extern int error_on_exit;
void Sys_Sleep( int msec );
double Sys_DoubleTime( void );
char *Sys_GetClipboardData( void );
const char *Sys_GetCurrentUser( void );
Expand Down
6 changes: 1 addition & 5 deletions engine/platform/dos/sys_dos.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ double Platform_DoubleTime( void )
{
return 0.005*ticks;
}

void Platform_Sleep( int msec )
{
//usleep( msec * 1000 );
}
#endif // XASH_TIMER == TIMER_DOS

#define PIT_FREQUENCY 0x1234DDL
#define frequency 140
#define counter PIT_FREQUENCY/frequency
Expand Down
17 changes: 16 additions & 1 deletion engine/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ GNU General Public License for more details.
==============================================================================
*/
double Platform_DoubleTime( void );
void Platform_Sleep( int msec );
void Platform_ShellExecute( const char *path, const char *parms );
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow );
void Platform_SetStatus( const char *status );
Expand All @@ -52,11 +51,13 @@ void IOS_LaunchDialog( void );
#if XASH_POSIX
void Posix_Daemonize( void );
void Posix_SetupSigtermHandling( void );
void Posix_Sleep( int msec );
#endif

#if XASH_SDL
void SDLash_Init( void );
void SDLash_Shutdown( void );
void SDLash_Sleep( int msec );
#endif

#if XASH_ANDROID
Expand All @@ -77,6 +78,7 @@ void Wcon_ShowConsole( qboolean show );
void Wcon_DisableInput( void );
char *Wcon_Input( void );
void Wcon_WinPrint( const char *pMsg );
void Win32_Sleep( int msec );
#endif

#if XASH_NSWITCH
Expand Down Expand Up @@ -165,6 +167,19 @@ static inline void Platform_SetupSigtermHandling( void )
#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
}

/*
==============================================================================
Expand Down
7 changes: 4 additions & 3 deletions engine/platform/posix/sys_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static void Posix_SigtermCallback( int signal )

void Posix_SetupSigtermHandling( void )
{
#if !XASH_PSVITA
#if !XASH_PSVITA
struct sigaction act = { 0 };
act.sa_handler = Posix_SigtermCallback;
act.sa_flags = 0;
Expand All @@ -172,9 +172,10 @@ double Platform_DoubleTime( void )
#endif
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 );
}
#endif // XASH_TIMER == TIMER_POSIX

4 changes: 2 additions & 2 deletions engine/platform/sdl/sys_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ double Platform_DoubleTime( void )
CurrentTime = SDL_GetPerformanceCounter();
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 );
}
#endif // XASH_TIMER == TIMER_SDL

#if XASH_MESSAGEBOX == MSGBOX_SDL
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
Expand Down
4 changes: 2 additions & 2 deletions engine/platform/win32/sys_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ double Platform_DoubleTime( void )

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 );
}
#endif // XASH_TIMER == TIMER_WIN32

qboolean Platform_DebuggerPresent( void )
{
Expand Down

0 comments on commit e14cd75

Please sign in to comment.