Browse Source

engine: adapt engine code to new platform backends system

pull/2/head
Alibek Omarov 6 years ago
parent
commit
960e46c564
  1. 16
      engine/client/cl_mobile.c
  2. 1
      engine/client/gl_rmain.c
  3. 18
      engine/client/keys.c
  4. 25
      engine/client/vid_common.c
  5. 27
      engine/client/vid_common.h
  6. 11
      engine/common/host_state.c

16
engine/client/cl_mobile.c

@ -21,10 +21,7 @@ GNU General Public License for more details. @@ -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 ) @@ -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 ) @@ -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 =

1
engine/client/gl_rmain.c

@ -21,6 +21,7 @@ GNU General Public License for more details. @@ -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 )

18
engine/client/keys.c

@ -17,9 +17,7 @@ GNU General Public License for more details. @@ -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 @@ -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;

25
engine/client/vid_common.c

@ -19,6 +19,7 @@ GNU General Public License for more details. @@ -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 @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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();
}
/*

27
engine/client/vid_common.h

@ -12,14 +12,6 @@ typedef struct vidmode_s @@ -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 ); @@ -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

11
engine/common/host_state.c

@ -14,10 +14,7 @@ GNU General Public License for more details. @@ -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 ) @@ -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 );

Loading…
Cancel
Save