From 960e46c564a3ff045e4c86fe5f82cb2b3c7aab4f Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 22 Oct 2018 00:27:52 +0300 Subject: [PATCH] engine: adapt engine code to new platform backends system --- engine/client/cl_mobile.c | 16 +++------------- engine/client/gl_rmain.c | 1 + engine/client/keys.c | 18 +++--------------- engine/client/vid_common.c | 25 +++++++++++++++++-------- engine/client/vid_common.h | 27 --------------------------- engine/common/host_state.c | 11 ++--------- 6 files changed, 26 insertions(+), 72 deletions(-) diff --git a/engine/client/cl_mobile.c b/engine/client/cl_mobile.c index c58598a5..d94eac2e 100644 --- a/engine/client/cl_mobile.c +++ b/engine/client/cl_mobile.c @@ -21,10 +21,7 @@ GNU General Public License for more details. #include "library.h" #include "gl_local.h" #include "input.h" - -#if defined(__ANDROID__) -#include "platform/android/android-main.h" -#endif +#include "platform/platform.h" mobile_engfuncs_t *gMobileEngfuncs; @@ -45,9 +42,7 @@ static void pfnVibrate( float life, char flags ) //MsgDev( D_NOTE, "Vibrate: %f %d\n", life, flags ); // here goes platform-specific backends -#ifdef __ANDROID__ - Android_Vibrate( life * vibration_length->value, flags ); -#endif + Platform_Vibrate( life * vibration_length->value, flags ); } static void Vibrate_f() @@ -97,13 +92,8 @@ static void *pfnGetNativeObject( const char *obj ) if( !obj ) return NULL; - // Backend should handle NULL // Backend should consider that obj is case-sensitive -#ifdef __ANDROID__ - return Android_GetNativeObject( obj ); -#else - return NULL; -#endif + return Platform_GetNativeObject( obj ); } static mobile_engfuncs_t gpMobileEngfuncs = diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index e21d591e..585f82a2 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -21,6 +21,7 @@ GNU General Public License for more details. #include "beamdef.h" #include "particledef.h" #include "entity_types.h" +#include "platform/platform.h" #define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA ) diff --git a/engine/client/keys.c b/engine/client/keys.c index 093ce4c8..ed421a4f 100644 --- a/engine/client/keys.c +++ b/engine/client/keys.c @@ -17,9 +17,7 @@ GNU General Public License for more details. #include "input.h" #include "client.h" #include "vgui_draw.h" -#ifdef XASH_SDL -#include "platform/sdl/events.h" -#endif // XASH_SDL +#include "platform/platform.h" typedef struct { @@ -702,20 +700,10 @@ Key_EnableTextInput */ void Key_EnableTextInput( qboolean enable, qboolean force ) { - void (*pfnEnableTextInput)( qboolean enable ); - -#if XASH_INPUT == INPUT_SDL - pfnEnableTextInput = SDLash_EnableTextInput; -#elif XASH_INPUT == INPUT_ANDROID - pfnEnableTextInput = Android_EnableTextInput; -#else -#error "Here must be a text input for your platform" - return; -#endif if( enable && ( !host.textmode || force ) ) - pfnEnableTextInput( true ); + Platform_EnableTextInput( true ); else if( !enable ) - pfnEnableTextInput( false ); + Platform_EnableTextInput( false ); if( !force ) host.textmode = enable; diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index 28432372..c390429d 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -19,6 +19,7 @@ GNU General Public License for more details. #include "mod_local.h" #include "input.h" #include "vid_common.h" +#include "platform/platform.h" #define WINDOW_NAME XASH_ENGINE_NAME " Window" // Half-Life @@ -256,10 +257,14 @@ VID_GetModeString */ const char *VID_GetModeString( int vid_mode ) { + vidmode_t *vidmode; if( vid_mode < 0 || vid_mode > R_MaxVideoModes() ) return NULL; - return R_GetVideoMode( vid_mode ).desc; + if( !( vidmode = R_GetVideoMode( vid_mode ) ) ) + return NULL; + + return vidmode->desc; } /* @@ -390,12 +395,17 @@ static void VID_Mode_f( void ) { case 2: { - vidmode_t vidmode; + vidmode_t *vidmode; vidmode = R_GetVideoMode( Q_atoi( Cmd_Argv( 1 )) ); + if( !vidmode ) + { + Con_Print( S_ERROR "unable to set mode, backend returned null" ); + return; + } - w = vidmode.width; - h = vidmode.height; + w = vidmode->width; + h = vidmode->height; break; } case 3: @@ -553,10 +563,10 @@ qboolean R_Init( void ) GL_SetDefaultState(); // create the window and set up the context - if( !R_Init_OpenGL( )) + if( !R_Init_Video( )) { GL_RemoveCommands(); - R_Free_OpenGL(); + R_Free_Video(); Sys_Error( "Can't initialize video subsystem\nProbably driver was not installed" ); return false; @@ -565,7 +575,6 @@ qboolean R_Init( void ) host.renderinfo_changed = false; r_temppool = Mem_AllocPool( "Render Zone" ); - GL_InitExtensions(); GL_SetDefaults(); R_InitImages(); R_SpriteInit(); @@ -607,7 +616,7 @@ void R_Shutdown( void ) Mem_FreePool( &r_temppool ); // shut down OS specific OpenGL stuff like contexts, etc. - R_Free_OpenGL(); + R_Free_Video(); } /* diff --git a/engine/client/vid_common.h b/engine/client/vid_common.h index 63b6812f..3047f584 100644 --- a/engine/client/vid_common.h +++ b/engine/client/vid_common.h @@ -12,14 +12,6 @@ typedef struct vidmode_s int height; } vidmode_t; -typedef enum -{ - rserr_ok, - rserr_invalid_fullscreen, - rserr_invalid_mode, - rserr_unknown -} rserr_t; - // minimal recommended resolution #define VID_MIN_WIDTH 640 #define VID_MIN_HEIGHT 480 @@ -43,23 +35,4 @@ void VID_StartupGamma( void ); void GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char *cvarname, int r_ext ); void GL_SetExtension( int r_ext, int enable ); -// -// platform-defined calls -// -void GL_InitExtensions( void ); -void VID_RestoreScreenResolution( void ); -qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ); -void VID_DestroyWindow( void ); -qboolean R_Init_OpenGL( void ); -void R_Free_OpenGL( void ); -void *GL_GetProcAddress( const char *name ); -qboolean GL_CreateContext( void ); -qboolean GL_UpdateContext( void ); -qboolean GL_DeleteContext( void ); -int R_MaxVideoModes(); -vidmode_t R_GetVideoMode( int num ); -rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ); -void R_ChangeDisplaySettingsFast( int width, int height ); // for fast resizing -qboolean VID_SetMode( void ); - #endif // VID_COMMON diff --git a/engine/common/host_state.c b/engine/common/host_state.c index 12a51446..3d60ea09 100644 --- a/engine/common/host_state.c +++ b/engine/common/host_state.c @@ -14,10 +14,7 @@ GNU General Public License for more details. */ #include "common.h" - -#ifdef XASH_SDL -#include "platform/sdl/events.h" -#endif +#include "platform/platform.h" void COM_InitHostState( void ) { @@ -138,11 +135,7 @@ void Host_ShutdownGame( void ) void Host_RunFrame( float time ) { -#if XASH_INPUT == INPUT_SDL - SDLash_RunEvents(); -#elif XASH_INPUT == INPUT_ANDROID - Android_RunEvents(); -#endif + Platform_RunEvents(); // engine main frame Host_Frame( time );