diff options
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/sys_loadlib.h | 11 | ||||
-rw-r--r-- | src/sys/sys_local.h | 3 | ||||
-rw-r--r-- | src/sys/sys_main.c | 59 | ||||
-rw-r--r-- | src/sys/sys_unix.c | 32 | ||||
-rw-r--r-- | src/sys/sys_win32.c | 70 |
5 files changed, 122 insertions, 53 deletions
diff --git a/src/sys/sys_loadlib.h b/src/sys/sys_loadlib.h index a0196f38..3d20b8ce 100644 --- a/src/sys/sys_loadlib.h +++ b/src/sys/sys_loadlib.h @@ -33,10 +33,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # define Sys_UnloadLibrary(h) dlclose(h) # define Sys_LoadFunction(h,fn) dlsym(h,fn) # define Sys_LibraryError() dlerror() -#endif +# endif #else -# include "SDL.h" -# include "SDL_loadso.h" +# ifdef USE_LOCAL_HEADERS +# include "SDL.h" +# include "SDL_loadso.h" +# else +# include <SDL.h> +# include <SDL_loadso.h> +# endif # define Sys_LoadLibrary(f) SDL_LoadObject(f) # define Sys_UnloadLibrary(h) SDL_UnloadObject(h) # define Sys_LoadFunction(h,fn) SDL_LoadFunction(h,fn) diff --git a/src/sys/sys_local.h b/src/sys/sys_local.h index 40336e3a..6d001046 100644 --- a/src/sys/sys_local.h +++ b/src/sys/sys_local.h @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA void IN_Init( void ); void IN_Frame( void ); void IN_Shutdown( void ); +void IN_Restart( void ); // Console void CON_Shutdown( void ); @@ -47,6 +48,8 @@ unsigned int CON_LogRead( char *out, unsigned int outSize ); char *Sys_StripAppBundle( char *pwd ); #endif +void Sys_GLimpInit( void ); +void Sys_PlatformInit( void ); void Sys_SigHandler( int signal ); void Sys_ErrorDialog( const char *error ); void Sys_AnsiColorPrint( const char *msg ); diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c index af0f66a9..0d682261 100644 --- a/src/sys/sys_main.c +++ b/src/sys/sys_main.c @@ -112,8 +112,7 @@ Restart the input subsystem */ void Sys_In_Restart_f( void ) { - IN_Shutdown(); - IN_Init(); + IN_Restart( ); } /* @@ -441,42 +440,6 @@ void *Sys_LoadDll( const char *name, char *fqpath , /* ================= -Sys_Idle -================= -*/ -static void Sys_Idle( void ) -{ -#ifndef DEDICATED - int appState = SDL_GetAppState( ); - int sleep = 0; - - // If we have no input focus at all, sleep a bit - if( !( appState & ( SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS ) ) ) - { - Cvar_SetValue( "com_unfocused", 1 ); - sleep += 16; - } - else - Cvar_SetValue( "com_unfocused", 0 ); - - // If we're minimised, sleep a bit more - if( !( appState & SDL_APPACTIVE ) ) - { - Cvar_SetValue( "com_minimized", 1 ); - sleep += 32; - } - else - Cvar_SetValue( "com_minimized", 0 ); - - if( !com_dedicated->integer && sleep ) - SDL_Delay( sleep ); -#else - // Dedicated server idles via NET_Sleep -#endif -} - -/* -================= Sys_ParseArgs ================= */ @@ -569,6 +532,8 @@ int main( int argc, char **argv ) } #endif + Sys_PlatformInit( ); + Sys_ParseArgs( argc, argv ); Sys_SetBinaryPath( Sys_Dirname( argv[ 0 ] ) ); Sys_SetDefaultInstallPath( DEFAULT_BASEDIR ); @@ -585,16 +550,6 @@ int main( int argc, char **argv ) CON_Init( ); -#ifndef _WIN32 - // Windows doesn't have these signals - // see CON_CtrlHandler() in con_win32.c - signal( SIGHUP, Sys_SigHandler ); - signal( SIGQUIT, Sys_SigHandler ); - signal( SIGTRAP, Sys_SigHandler ); - signal( SIGIOT, Sys_SigHandler ); - signal( SIGBUS, Sys_SigHandler ); -#endif - signal( SIGILL, Sys_SigHandler ); signal( SIGFPE, Sys_SigHandler ); signal( SIGSEGV, Sys_SigHandler ); @@ -602,7 +557,13 @@ int main( int argc, char **argv ) while( 1 ) { - Sys_Idle( ); +#ifndef DEDICATED + int appState = SDL_GetAppState( ); + + Cvar_SetValue( "com_unfocused", !( appState & SDL_APPINPUTFOCUS ) ); + Cvar_SetValue( "com_minimized", !( appState & SDL_APPACTIVE ) ); +#endif + IN_Frame( ); Com_Frame( ); } diff --git a/src/sys/sys_unix.c b/src/sys/sys_unix.c index 090e9e43..760b6022 100644 --- a/src/sys/sys_unix.c +++ b/src/sys/sys_unix.c @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "../qcommon/qcommon.h" #include "sys_local.h" +#include <signal.h> #include <sys/types.h> #include <sys/stat.h> #include <errno.h> @@ -463,6 +464,9 @@ void Sys_Sleep( int msec ) { fd_set fdset; + if( msec == 0 ) + return; + FD_ZERO(&fdset); FD_SET(fileno(stdin), &fdset); if( msec < 0 ) @@ -508,3 +512,31 @@ void Sys_ErrorDialog( const char *error ) FS_FCloseFile( f ); } + +/* +============== +Sys_GLimpInit + +Unix specific GL implementation initialisation +============== +*/ +void Sys_GLimpInit( void ) +{ + // NOP +} + +/* +============== +Sys_PlatformInit + +Unix specific initialisation +============== +*/ +void Sys_PlatformInit( void ) +{ + signal( SIGHUP, Sys_SigHandler ); + signal( SIGQUIT, Sys_SigHandler ); + signal( SIGTRAP, Sys_SigHandler ); + signal( SIGIOT, Sys_SigHandler ); + signal( SIGBUS, Sys_SigHandler ); +} diff --git a/src/sys/sys_win32.c b/src/sys/sys_win32.c index df8861d3..aac4384d 100644 --- a/src/sys/sys_win32.c +++ b/src/sys/sys_win32.c @@ -514,15 +514,26 @@ void Sys_FreeFileList( char **list ) ============== Sys_Sleep -Block execution for msec or until input is recieved. +Block execution for msec or until input is received. ============== */ void Sys_Sleep( int msec ) { + if( msec == 0 ) + return; + +#ifdef DEDICATED if( msec < 0 ) WaitForSingleObject( GetStdHandle( STD_INPUT_HANDLE ), INFINITE ); else WaitForSingleObject( GetStdHandle( STD_INPUT_HANDLE ), msec ); +#else + // Client Sys_Sleep doesn't support waiting on stdin + if( msec < 0 ) + return; + + Sleep( msec ); +#endif } /* @@ -565,3 +576,60 @@ void Sys_ErrorDialog( const char *error ) } } } + +#ifndef DEDICATED +static qboolean SDL_VIDEODRIVER_externallySet = qfalse; +#endif + +/* +============== +Sys_GLimpInit + +Windows specific GL implementation initialisation +============== +*/ +void Sys_GLimpInit( void ) +{ +#ifndef DEDICATED + if( !SDL_VIDEODRIVER_externallySet ) + { + // It's a little bit weird having in_mouse control the + // video driver, but from ioq3's point of view they're + // virtually the same except for the mouse input anyway + if( Cvar_VariableIntegerValue( "in_mouse" ) == -1 ) + { + // Use the windib SDL backend, which is closest to + // the behaviour of idq3 with in_mouse set to -1 + _putenv( "SDL_VIDEODRIVER=windib" ); + } + else + { + // Use the DirectX SDL backend + _putenv( "SDL_VIDEODRIVER=directx" ); + } + } +#endif +} + +/* +============== +Sys_PlatformInit + +Windows specific initialisation +============== +*/ +void Sys_PlatformInit( void ) +{ +#ifndef DEDICATED + const char *SDL_VIDEODRIVER = getenv( "SDL_VIDEODRIVER" ); + + if( SDL_VIDEODRIVER ) + { + Com_Printf( "SDL_VIDEODRIVER is externally set to \"%s\", " + "in_mouse -1 will have no effect\n", SDL_VIDEODRIVER ); + SDL_VIDEODRIVER_externallySet = qtrue; + } + else + SDL_VIDEODRIVER_externallySet = qfalse; +#endif +} |