Browse Source

engine: platform: refactor Platform_Init/Shutdown/GetNativeObject functions. They are now defined in the header, and call platform-specific functios that defined in platform code

pull/2/head
Alibek Omarov 1 year ago
parent
commit
c16a10e6f3
  1. 11
      engine/platform/dos/sys_dos.c
  2. 70
      engine/platform/platform.h
  3. 17
      engine/platform/posix/sys_posix.c
  4. 9
      engine/platform/sdl/events.c
  5. 28
      engine/platform/sdl/sys_sdl.c
  6. 13
      engine/platform/win32/sys_win.c

11
engine/platform/dos/sys_dos.c

@ -25,13 +25,6 @@ void Platform_SetClipboardText( const char *buffer, size_t size ) @@ -25,13 +25,6 @@ void Platform_SetClipboardText( const char *buffer, size_t size )
}
void *Platform_GetNativeObject( const char *name )
{
return NULL;
}
void Platform_Vibrate(float life, char flags)
{
@ -89,7 +82,7 @@ static void __interrupt __far timerhandler() @@ -89,7 +82,7 @@ static void __interrupt __far timerhandler()
// in_dos.c
extern void __interrupt __far keyhandler( void );
void Platform_Init( void )
void DOS_Init( void )
{
// save original vectors
orig_int_1c = _dos_getvect( 0x1c );
@ -104,7 +97,7 @@ void Platform_Init( void ) @@ -104,7 +97,7 @@ void Platform_Init( void )
}
void Platform_Shutdown( void )
void DOS_Shutdown( void )
{
// restore freq
outp( 0x43, 0x34 );

70
engine/platform/platform.h

@ -30,15 +30,21 @@ GNU General Public License for more details. @@ -30,15 +30,21 @@ GNU General Public License for more details.
==============================================================================
*/
void Platform_Init( void );
void Platform_Shutdown( void );
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 );
qboolean Sys_DebuggerPresent( void ); // optional, see Sys_DebugBreak
#if XASH_POSIX
void Posix_Daemonize( void );
#endif
#if XASH_SDL
void SDLash_Init( void );
void SDLash_Shutdown( void );
#endif
#if XASH_ANDROID
const char *Android_GetAndroidID( void );
const char *Android_LoadID( void );
@ -49,6 +55,8 @@ int Android_GetKeyboardHeight( void ); @@ -49,6 +55,8 @@ int Android_GetKeyboardHeight( void );
#endif
#if XASH_WIN32
void Wcon_CreateConsole( void );
void Wcon_DestroyConsole( void );
void Platform_UpdateStatusLine( void );
#else
static inline void Platform_UpdateStatusLine( void ) { }
@ -67,6 +75,62 @@ int PSVita_GetArgv( int in_argc, char **in_argv, char ***out_argv ); @@ -67,6 +75,62 @@ int PSVita_GetArgv( int in_argc, char **in_argv, char ***out_argv );
void PSVita_InputUpdate( void );
#endif
#if XASH_DOS
void DOS_Init( void );
void DOS_Shutdown( void );
#endif
static inline void Platform_Init( void )
{
#if XASH_POSIX
Posix_Daemonize( );
#endif
#if XASH_WIN32
Wcon_CreateConsole( );
#endif
#if XASH_SDL
SDLash_Init( );
#endif
#if XASH_ANDROID
Android_Init( );
#elif XASH_NSWITCH
NSwitch_Init( );
#elif XASH_PSVITA
PSVita_Init( );
#elif XASH_DOS
DOS_Init( );
#endif
}
static inline void Platform_Shutdown( void )
{
#if XASH_NSWITCH
NSwitch_Shutdown( );
#elif XASH_PSVITA
PSVita_Shutdown( );
#elif XASH_DOS
DOS_Shutdown( );
#endif
#if XASH_SDL
SDLash_Shutdown( );
#endif
}
static inline void *Platform_GetNativeObject( const char *name )
{
void *ptr = NULL;
#if XASH_ANDROID
ptr = Android_GetNativeObject( name );
#endif
return ptr;
}
/*
==============================================================================

17
engine/platform/posix/sys_posix.c

@ -146,23 +146,6 @@ void Posix_Daemonize( void ) @@ -146,23 +146,6 @@ void Posix_Daemonize( void )
}
#if !XASH_SDL && !XASH_ANDROID
void Platform_Init( void )
{
Posix_Daemonize();
}
void Platform_Shutdown( void )
{
}
void *Platform_GetNativeObject( const char *name )
{
return NULL;
}
#endif
#if XASH_TIMER == TIMER_POSIX
double Platform_DoubleTime( void )
{

9
engine/platform/sdl/events.c

@ -689,15 +689,6 @@ void Platform_RunEvents( void ) @@ -689,15 +689,6 @@ void Platform_RunEvents( void )
#endif
}
void* Platform_GetNativeObject( const char *name )
{
#if XASH_ANDROID
return Android_GetNativeObject( name );
#else
return NULL;
#endif
}
/*
========================
Platform_PreCreateMove

28
engine/platform/sdl/sys_sdl.c

@ -45,13 +45,12 @@ void Platform_MessageBox( const char *title, const char *message, qboolean paren @@ -45,13 +45,12 @@ void Platform_MessageBox( const char *title, const char *message, qboolean paren
SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, title, message, parentMainWindow ? host.hWnd : NULL );
}
#endif // XASH_MESSAGEBOX == MSGBOX_SDL
void Posix_Daemonize( void );
void Platform_Init( void )
void SDLash_Init( void )
{
#ifndef SDL_INIT_EVENTS
#define SDL_INIT_EVENTS 0
#endif
if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) )
{
Sys_Warn( "SDL_Init failed: %s", SDL_GetError() );
@ -63,31 +62,10 @@ void Platform_Init( void ) @@ -63,31 +62,10 @@ void Platform_Init( void )
SDL_StopTextInput();
#endif // XASH_SDL == 2
#if XASH_WIN32
Wcon_CreateConsole(); // system console used by dedicated server or show fatal errors
#elif XASH_POSIX
Posix_Daemonize();
#if XASH_PSVITA
PSVita_Init();
#elif XASH_NSWITCH
NSwitch_Init();
#elif XASH_ANDROID
Android_Init();
#endif
#endif // XASH_POSIX
SDLash_InitCursors();
}
void Platform_Shutdown( void )
void SDLash_Shutdown( void )
{
SDLash_FreeCursors();
#if XASH_NSWITCH
NSwitch_Shutdown();
#elif XASH_WIN32
Wcon_DestroyConsole();
#elif XASH_PSVITA
PSVita_Shutdown();
#endif
}

13
engine/platform/win32/sys_win.c

@ -81,16 +81,3 @@ void Platform_MessageBox( const char *title, const char *message, qboolean paren @@ -81,16 +81,3 @@ void Platform_MessageBox( const char *title, const char *message, qboolean paren
MessageBox( parentMainWindow ? host.hWnd : NULL, message, title, MB_OK|MB_SETFOREGROUND|MB_ICONSTOP );
}
#endif // XASH_MESSAGEBOX == MSGBOX_WIN32
#ifndef XASH_SDL
void Platform_Init( void )
{
Wcon_CreateConsole(); // system console used by dedicated server or show fatal errors
}
void Platform_Shutdown( void )
{
Wcon_DestroyConsole();
}
#endif

Loading…
Cancel
Save