engine, filesystem: unify GetNativeObject between all the APIs. Allow getting filesystem APIs through GetNativeObject

This commit is contained in:
Alibek Omarov 2023-10-31 21:25:11 +03:00
parent 5ea074a1fd
commit 597429cf41
12 changed files with 57 additions and 33 deletions

View File

@ -181,6 +181,7 @@ typedef struct dll_info_s
} dll_info_t; } dll_info_t;
typedef void (*setpair_t)( const char *key, const void *value, const void *buffer, void *numpairs ); typedef void (*setpair_t)( const char *key, const void *value, const void *buffer, void *numpairs );
typedef void *(*pfnCreateInterface_t)( const char *, int * );
// config strings are a general means of communication from // config strings are a general means of communication from
// the server to all connected clients. // the server to all connected clients.

View File

@ -87,15 +87,6 @@ static int pfnDrawScaledCharacter( int x, int y, int number, int r, int g, int b
return CL_DrawCharacter( x, y, number, color, &g_scaled_font, flags ); return CL_DrawCharacter( x, y, number, color, &g_scaled_font, flags );
} }
static void *pfnGetNativeObject( const char *obj )
{
if( !obj )
return NULL;
// Backend should consider that obj is case-sensitive
return Platform_GetNativeObject( obj );
}
static void pfnTouch_HideButtons( const char *name, byte state ) static void pfnTouch_HideButtons( const char *name, byte state )
{ {
Touch_HideButtons( name, state, true ); Touch_HideButtons( name, state, true );
@ -124,7 +115,7 @@ static mobile_engfuncs_t gpMobileEngfuncs =
Touch_ResetDefaultButtons, Touch_ResetDefaultButtons,
pfnDrawScaledCharacter, pfnDrawScaledCharacter,
Sys_Warn, Sys_Warn,
pfnGetNativeObject, Sys_GetNativeObject,
ID_SetCustomClientID, ID_SetCustomClientID,
pfnParseFileSafe pfnParseFileSafe
}; };

View File

@ -381,6 +381,7 @@ typedef void (*xcommand_t)( void );
qboolean FS_LoadProgs( void ); qboolean FS_LoadProgs( void );
void FS_Init( void ); void FS_Init( void );
void FS_Shutdown( void ); void FS_Shutdown( void );
void *FS_GetNativeObject( const char *obj );
// //
// cmd.c // cmd.c

View File

@ -23,8 +23,17 @@ GNU General Public License for more details.
fs_api_t g_fsapi; fs_api_t g_fsapi;
fs_globals_t *FI; fs_globals_t *FI;
static pfnCreateInterface_t fs_pfnCreateInterface;
static HINSTANCE fs_hInstance; static HINSTANCE fs_hInstance;
void *FS_GetNativeObject( const char *obj )
{
if( fs_pfnCreateInterface )
return fs_pfnCreateInterface( obj, NULL );
return NULL;
}
static void FS_Rescan_f( void ) static void FS_Rescan_f( void )
{ {
FS_Rescan(); FS_Rescan();
@ -53,7 +62,7 @@ static fs_interface_t fs_memfuncs =
_Mem_Realloc, _Mem_Realloc,
_Mem_Free, _Mem_Free,
Platform_GetNativeObject, Sys_GetNativeObject,
}; };
static void FS_UnloadProgs( void ) static void FS_UnloadProgs( void )
@ -98,6 +107,13 @@ qboolean FS_LoadProgs( void )
return false; return false;
} }
if( !( fs_pfnCreateInterface = (pfnCreateInterface_t)COM_GetProcAddress( fs_hInstance, "CreateInterface" )))
{
FS_UnloadProgs();
Host_Error( "FS_LoadProgs: can't find CreateInterface entry point in %s\n", name );
return false;
}
Con_DPrintf( "FS_LoadProgs: filesystem_stdio successfully loaded\n" ); Con_DPrintf( "FS_LoadProgs: filesystem_stdio successfully loaded\n" );
return true; return true;

View File

@ -649,3 +649,31 @@ qboolean Sys_NewInstance( const char *gamedir )
return false; return false;
} }
/*
==================
Sys_GetNativeObject
Get platform-specific native object
==================
*/
void *Sys_GetNativeObject( const char *obj )
{
void *ptr;
if( !COM_CheckString( obj ))
return NULL;
ptr = FS_GetNativeObject( obj );
if( ptr )
return ptr;
// Backend should consider that obj is case-sensitive
#if XASH_ANDROID
ptr = Android_GetNativeObject( obj );
#endif // XASH_ANDROID
return ptr;
}

View File

@ -70,6 +70,7 @@ void Sys_InitLog( void );
void Sys_CloseLog( void ); void Sys_CloseLog( void );
void Sys_Quit( void ) NORETURN; void Sys_Quit( void ) NORETURN;
qboolean Sys_NewInstance( const char *gamedir ); qboolean Sys_NewInstance( const char *gamedir );
void *Sys_GetNativeObject( const char *obj );
// //
// sys_con.c // sys_con.c

View File

@ -139,17 +139,6 @@ static inline void Platform_Shutdown( void )
#endif #endif
} }
static inline void *Platform_GetNativeObject( const char *name )
{
void *ptr = NULL;
#if XASH_ANDROID
ptr = Android_GetNativeObject( name );
#endif
return ptr;
}
/* /*
============================================================================== ==============================================================================
@ -158,7 +147,6 @@ static inline void *Platform_GetNativeObject( const char *name )
============================================================================== ==============================================================================
*/ */
void Platform_Vibrate( float life, char flags ); void Platform_Vibrate( float life, char flags );
void*Platform_GetNativeObject( const char *name );
/* /*
============================================================================== ==============================================================================

View File

@ -150,6 +150,4 @@ public:
virtual void AddSearchPathNoWrite(const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20AddSearchPathNoWriteEPKcS1_ */ virtual void AddSearchPathNoWrite(const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20AddSearchPathNoWriteEPKcS1_ */
}; };
#define FILESYSTEM_INTERFACE_VERSION "VFileSystem009" // never change this!
#endif // VFILESYSTEM009_H #endif // VFILESYSTEM009_H

View File

@ -1386,7 +1386,7 @@ static void _Sys_Error( const char *fmt, ... )
exit( 1 ); exit( 1 );
} }
static void *_Platform_GetNativeObject_stub( const char *object ) static void *Sys_GetNativeObject_stub( const char *object )
{ {
return NULL; return NULL;
} }
@ -2841,7 +2841,7 @@ fs_interface_t g_engfuncs =
_Mem_Alloc, _Mem_Alloc,
_Mem_Realloc, _Mem_Realloc,
_Mem_Free, _Mem_Free,
_Platform_GetNativeObject_stub Sys_GetNativeObject_stub
}; };
static qboolean FS_InitInterface( int version, fs_interface_t *engfuncs ) static qboolean FS_InitInterface( int version, fs_interface_t *engfuncs )
@ -2883,9 +2883,9 @@ static qboolean FS_InitInterface( int version, fs_interface_t *engfuncs )
Con_Reportf( "filesystem_stdio: custom memory allocation functions found\n" ); Con_Reportf( "filesystem_stdio: custom memory allocation functions found\n" );
} }
if( engfuncs->_Platform_GetNativeObject ) if( engfuncs->_Sys_GetNativeObject )
{ {
g_engfuncs._Platform_GetNativeObject = engfuncs->_Platform_GetNativeObject; g_engfuncs._Sys_GetNativeObject = engfuncs->_Sys_GetNativeObject;
Con_Reportf( "filesystem_stdio: custom platform-specific functions found\n" ); Con_Reportf( "filesystem_stdio: custom platform-specific functions found\n" );
} }

View File

@ -33,6 +33,7 @@ extern "C"
#define FS_API_VERSION 2 // not stable yet! #define FS_API_VERSION 2 // not stable yet!
#define FS_API_CREATEINTERFACE_TAG "XashFileSystem002" // follow FS_API_VERSION!!! #define FS_API_CREATEINTERFACE_TAG "XashFileSystem002" // follow FS_API_VERSION!!!
#define FILESYSTEM_INTERFACE_VERSION "VFileSystem009" // never change this!
// search path flags // search path flags
enum enum
@ -210,7 +211,7 @@ typedef struct fs_interface_t
void (*_Mem_Free)( void *data, const char *filename, int fileline ); void (*_Mem_Free)( void *data, const char *filename, int fileline );
// platform // platform
void *(*_Platform_GetNativeObject)( const char *object ); void *(*_Sys_GetNativeObject)( const char *object );
} fs_interface_t; } fs_interface_t;
typedef int (*FSAPI)( int version, fs_api_t *api, fs_globals_t **globals, fs_interface_t *interface ); typedef int (*FSAPI)( int version, fs_api_t *api, fs_globals_t **globals, fs_interface_t *interface );

View File

@ -127,7 +127,7 @@ extern const fs_archive_t g_archives[];
#define Con_DPrintf (*g_engfuncs._Con_DPrintf) #define Con_DPrintf (*g_engfuncs._Con_DPrintf)
#define Con_Reportf (*g_engfuncs._Con_Reportf) #define Con_Reportf (*g_engfuncs._Con_Reportf)
#define Sys_Error (*g_engfuncs._Sys_Error) #define Sys_Error (*g_engfuncs._Sys_Error)
#define Platform_GetNativeObject (*g_engfuncs._Platform_GetNativeObject) #define Sys_GetNativeObject (*g_engfuncs._Sys_GetNativeObject)
// //
// filesystem.c // filesystem.c

View File

@ -18,7 +18,6 @@ typedef void *HMODULE;
HMODULE g_hModule; HMODULE g_hModule;
FSAPI g_pfnGetFSAPI; FSAPI g_pfnGetFSAPI;
typedef void *(*pfnCreateInterface_t)( const char *, int * );
pfnCreateInterface_t g_pfnCreateInterface; pfnCreateInterface_t g_pfnCreateInterface;
fs_api_t g_fs; fs_api_t g_fs;
fs_globals_t *g_nullglobals; fs_globals_t *g_nullglobals;