Browse Source

Implement Mobility API support. Add missing IN_TouchShutdown and Joy_Shutdown calls. Don't save video and opengl configs if engine crashed.

pull/2/head
Alibek Omarov 7 years ago
parent
commit
32aa9a9f54
  1. 2
      engine/client/cl_game.c
  2. 8
      engine/client/cl_main.c
  3. 149
      engine/client/cl_mobile.c
  4. 6
      engine/client/client.h

2
engine/client/cl_game.c

@ -4215,6 +4215,8 @@ qboolean CL_LoadProgs( const char *name )
if( !R_InitRenderAPI()) // Xash3D extension if( !R_InitRenderAPI()) // Xash3D extension
Con_Reportf( S_WARN "CL_LoadProgs: couldn't get render API\n" ); Con_Reportf( S_WARN "CL_LoadProgs: couldn't get render API\n" );
if( !Mobile_Init() ) // Xash3D FWGS extension: mobile interface
Con_Reportf( S_WARN "CL_LoadProgs: couldn't get mobility API\n" );
CL_InitEdicts (); // initailize local player and world CL_InitEdicts (); // initailize local player and world
CL_InitClientMove(); // initialize pm_shared CL_InitClientMove(); // initialize pm_shared

8
engine/client/cl_main.c

@ -2802,11 +2802,17 @@ void CL_Shutdown( void )
Con_Printf( "CL_Shutdown()\n" ); Con_Printf( "CL_Shutdown()\n" );
if( !host.crashed )
{
Host_WriteOpenGLConfig (); Host_WriteOpenGLConfig ();
Host_WriteVideoConfig (); Host_WriteVideoConfig ();
}
CL_CloseDemoHeader(); IN_TouchShutdown ();
Joy_Shutdown ();
CL_CloseDemoHeader ();
IN_Shutdown (); IN_Shutdown ();
Mobile_Shutdown ();
SCR_Shutdown (); SCR_Shutdown ();
CL_UnloadProgs (); CL_UnloadProgs ();

149
engine/client/cl_mobile.c

@ -0,0 +1,149 @@
/*
cl_mobile.c - common mobile interface
Copyright (C) 2015 a1batross
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef XASH_DEDICATED
#include "common.h"
#include "client.h"
#include "mobility_int.h"
#include "library.h"
#include "gl_local.h"
#include "input.h"
#if defined(__ANDROID__)
#include "platform/android/android-main.h"
#endif
mobile_engfuncs_t *gMobileEngfuncs;
convar_t *vibration_length;
convar_t *vibration_enable;
static void pfnVibrate( float life, char flags )
{
if( !vibration_enable->value )
return;
if( life < 0.0f )
{
MsgDev( D_WARN, "Negative vibrate time: %f\n", life );
return;
}
//MsgDev( D_NOTE, "Vibrate: %f %d\n", life, flags );
// here goes platform-specific backends
#ifdef __ANDROID__
Android_Vibrate( life * vibration_length->value, flags );
#endif
}
static void Vibrate_f()
{
if( Cmd_Argc() != 2 )
{
Msg( "Usage: vibrate <time>\n" );
return;
}
pfnVibrate( Q_atof( Cmd_Argv(1) ), VIBRATE_NORMAL );
}
static void pfnEnableTextInput( int enable )
{
Key_EnableTextInput( enable, false );
}
static int pfnDrawScaledCharacter( int x, int y, int number, int r, int g, int b, float scale )
{
int width = clgame.scrInfo.charWidths[number] * scale * hud_scale->value;
int height = clgame.scrInfo.iCharHeight * scale * hud_scale->value;
if( !cls.creditsFont.valid )
return 0;
x *= hud_scale->value;
y *= hud_scale->value;
number &= 255;
number = Con_UtfProcessChar( number );
if( number < 32 )
return 0;
if( y < -height )
return 0;
pfnPIC_Set( cls.creditsFont.hFontTexture, r, g, b, 255 );
pfnPIC_DrawAdditive( x, y, width, height, &cls.creditsFont.fontRc[number] );
return width;
}
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
}
static mobile_engfuncs_t gpMobileEngfuncs =
{
MOBILITY_API_VERSION,
pfnVibrate,
pfnEnableTextInput,
IN_TouchAddClientButton,
IN_TouchAddDefaultButton,
(void*)IN_TouchHideButtons,
IN_TouchRemoveButton,
(void*)IN_TouchSetClientOnly,
IN_TouchResetDefaultButtons,
pfnDrawScaledCharacter,
Sys_Warn,
pfnGetNativeObject,
ID_SetCustomClientID
};
qboolean Mobile_Init( void )
{
qboolean success = false;
pfnMobilityInterface ExportToClient;
// find a mobility interface
ExportToClient = COM_GetProcAddress( clgame.hInstance, MOBILITY_CLIENT_EXPORT );
gMobileEngfuncs = &gpMobileEngfuncs;
if( ExportToClient && !ExportToClient( gMobileEngfuncs ) )
success = true;
Cmd_AddCommand( "vibrate", (xcommand_t)Vibrate_f, "Vibrate for specified time");
vibration_length = Cvar_Get( "vibration_length", "1.0", FCVAR_ARCHIVE, "Vibration length");
vibration_enable = Cvar_Get( "vibration_enable", "1", FCVAR_ARCHIVE, "Enable vibration");
return success;
}
void Mobile_Shutdown( void )
{
Cmd_RemoveCommand( "vibrate" );
}
#endif // XASH_DEDICATED

6
engine/client/client.h

@ -1063,6 +1063,12 @@ void pfnPIC_DrawTrans( int x, int y, int width, int height, const wrect_t *prc )
void pfnPIC_DrawHoles( int x, int y, int width, int height, const wrect_t *prc ); void pfnPIC_DrawHoles( int x, int y, int width, int height, const wrect_t *prc );
void pfnPIC_DrawAdditive( int x, int y, int width, int height, const wrect_t *prc ); void pfnPIC_DrawAdditive( int x, int y, int width, int height, const wrect_t *prc );
//
// cl_mobile.c
//
qboolean Mobile_Init( void );
void Mobile_Shutdown( void );
// //
// cl_video.c // cl_video.c
// //

Loading…
Cancel
Save