engine: adapt engine code to new platform backends system

This commit is contained in:
Alibek Omarov 2018-10-22 00:27:52 +03:00
parent 265f79fc72
commit 960e46c564
6 changed files with 26 additions and 72 deletions

View File

@ -21,10 +21,7 @@ GNU General Public License for more details.
#include "library.h" #include "library.h"
#include "gl_local.h" #include "gl_local.h"
#include "input.h" #include "input.h"
#include "platform/platform.h"
#if defined(__ANDROID__)
#include "platform/android/android-main.h"
#endif
mobile_engfuncs_t *gMobileEngfuncs; mobile_engfuncs_t *gMobileEngfuncs;
@ -45,9 +42,7 @@ static void pfnVibrate( float life, char flags )
//MsgDev( D_NOTE, "Vibrate: %f %d\n", life, flags ); //MsgDev( D_NOTE, "Vibrate: %f %d\n", life, flags );
// here goes platform-specific backends // here goes platform-specific backends
#ifdef __ANDROID__ Platform_Vibrate( life * vibration_length->value, flags );
Android_Vibrate( life * vibration_length->value, flags );
#endif
} }
static void Vibrate_f() static void Vibrate_f()
@ -97,13 +92,8 @@ static void *pfnGetNativeObject( const char *obj )
if( !obj ) if( !obj )
return NULL; return NULL;
// Backend should handle NULL
// Backend should consider that obj is case-sensitive // Backend should consider that obj is case-sensitive
#ifdef __ANDROID__ return Platform_GetNativeObject( obj );
return Android_GetNativeObject( obj );
#else
return NULL;
#endif
} }
static mobile_engfuncs_t gpMobileEngfuncs = static mobile_engfuncs_t gpMobileEngfuncs =

View File

@ -21,6 +21,7 @@ GNU General Public License for more details.
#include "beamdef.h" #include "beamdef.h"
#include "particledef.h" #include "particledef.h"
#include "entity_types.h" #include "entity_types.h"
#include "platform/platform.h"
#define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA ) #define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA )

View File

@ -17,9 +17,7 @@ GNU General Public License for more details.
#include "input.h" #include "input.h"
#include "client.h" #include "client.h"
#include "vgui_draw.h" #include "vgui_draw.h"
#ifdef XASH_SDL #include "platform/platform.h"
#include "platform/sdl/events.h"
#endif // XASH_SDL
typedef struct typedef struct
{ {
@ -702,20 +700,10 @@ Key_EnableTextInput
*/ */
void Key_EnableTextInput( qboolean enable, qboolean force ) 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 ) ) if( enable && ( !host.textmode || force ) )
pfnEnableTextInput( true ); Platform_EnableTextInput( true );
else if( !enable ) else if( !enable )
pfnEnableTextInput( false ); Platform_EnableTextInput( false );
if( !force ) if( !force )
host.textmode = enable; host.textmode = enable;

View File

@ -19,6 +19,7 @@ GNU General Public License for more details.
#include "mod_local.h" #include "mod_local.h"
#include "input.h" #include "input.h"
#include "vid_common.h" #include "vid_common.h"
#include "platform/platform.h"
#define WINDOW_NAME XASH_ENGINE_NAME " Window" // Half-Life #define WINDOW_NAME XASH_ENGINE_NAME " Window" // Half-Life
@ -256,10 +257,14 @@ VID_GetModeString
*/ */
const char *VID_GetModeString( int vid_mode ) const char *VID_GetModeString( int vid_mode )
{ {
vidmode_t *vidmode;
if( vid_mode < 0 || vid_mode > R_MaxVideoModes() ) if( vid_mode < 0 || vid_mode > R_MaxVideoModes() )
return NULL; 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: case 2:
{ {
vidmode_t vidmode; vidmode_t *vidmode;
vidmode = R_GetVideoMode( Q_atoi( Cmd_Argv( 1 )) ); 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; w = vidmode->width;
h = vidmode.height; h = vidmode->height;
break; break;
} }
case 3: case 3:
@ -553,10 +563,10 @@ qboolean R_Init( void )
GL_SetDefaultState(); GL_SetDefaultState();
// create the window and set up the context // create the window and set up the context
if( !R_Init_OpenGL( )) if( !R_Init_Video( ))
{ {
GL_RemoveCommands(); GL_RemoveCommands();
R_Free_OpenGL(); R_Free_Video();
Sys_Error( "Can't initialize video subsystem\nProbably driver was not installed" ); Sys_Error( "Can't initialize video subsystem\nProbably driver was not installed" );
return false; return false;
@ -565,7 +575,6 @@ qboolean R_Init( void )
host.renderinfo_changed = false; host.renderinfo_changed = false;
r_temppool = Mem_AllocPool( "Render Zone" ); r_temppool = Mem_AllocPool( "Render Zone" );
GL_InitExtensions();
GL_SetDefaults(); GL_SetDefaults();
R_InitImages(); R_InitImages();
R_SpriteInit(); R_SpriteInit();
@ -607,7 +616,7 @@ void R_Shutdown( void )
Mem_FreePool( &r_temppool ); Mem_FreePool( &r_temppool );
// shut down OS specific OpenGL stuff like contexts, etc. // shut down OS specific OpenGL stuff like contexts, etc.
R_Free_OpenGL(); R_Free_Video();
} }
/* /*

View File

@ -12,14 +12,6 @@ typedef struct vidmode_s
int height; int height;
} vidmode_t; } vidmode_t;
typedef enum
{
rserr_ok,
rserr_invalid_fullscreen,
rserr_invalid_mode,
rserr_unknown
} rserr_t;
// minimal recommended resolution // minimal recommended resolution
#define VID_MIN_WIDTH 640 #define VID_MIN_WIDTH 640
#define VID_MIN_HEIGHT 480 #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_CheckExtension( const char *name, const dllfunc_t *funcs, const char *cvarname, int r_ext );
void GL_SetExtension( int r_ext, int enable ); 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 #endif // VID_COMMON

View File

@ -14,10 +14,7 @@ GNU General Public License for more details.
*/ */
#include "common.h" #include "common.h"
#include "platform/platform.h"
#ifdef XASH_SDL
#include "platform/sdl/events.h"
#endif
void COM_InitHostState( void ) void COM_InitHostState( void )
{ {
@ -138,11 +135,7 @@ void Host_ShutdownGame( void )
void Host_RunFrame( float time ) void Host_RunFrame( float time )
{ {
#if XASH_INPUT == INPUT_SDL Platform_RunEvents();
SDLash_RunEvents();
#elif XASH_INPUT == INPUT_ANDROID
Android_RunEvents();
#endif
// engine main frame // engine main frame
Host_Frame( time ); Host_Frame( time );