diff --git a/common/xash3d_types.h b/common/xash3d_types.h index 4c2c05d5..ad46778e 100644 --- a/common/xash3d_types.h +++ b/common/xash3d_types.h @@ -181,6 +181,7 @@ typedef struct dll_info_s } dll_info_t; 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 // the server to all connected clients. diff --git a/engine/client/cl_mobile.c b/engine/client/cl_mobile.c index 480f3c1c..69c61b5d 100644 --- a/engine/client/cl_mobile.c +++ b/engine/client/cl_mobile.c @@ -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 ); } -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 ) { Touch_HideButtons( name, state, true ); @@ -124,7 +115,7 @@ static mobile_engfuncs_t gpMobileEngfuncs = Touch_ResetDefaultButtons, pfnDrawScaledCharacter, Sys_Warn, - pfnGetNativeObject, + Sys_GetNativeObject, ID_SetCustomClientID, pfnParseFileSafe }; diff --git a/engine/common/common.h b/engine/common/common.h index c382fbcd..3ae43936 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -381,6 +381,7 @@ typedef void (*xcommand_t)( void ); qboolean FS_LoadProgs( void ); void FS_Init( void ); void FS_Shutdown( void ); +void *FS_GetNativeObject( const char *obj ); // // cmd.c diff --git a/engine/common/filesystem_engine.c b/engine/common/filesystem_engine.c index 19925792..2b1e341e 100644 --- a/engine/common/filesystem_engine.c +++ b/engine/common/filesystem_engine.c @@ -23,8 +23,17 @@ GNU General Public License for more details. fs_api_t g_fsapi; fs_globals_t *FI; +static pfnCreateInterface_t fs_pfnCreateInterface; 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 ) { FS_Rescan(); @@ -53,7 +62,7 @@ static fs_interface_t fs_memfuncs = _Mem_Realloc, _Mem_Free, - Platform_GetNativeObject, + Sys_GetNativeObject, }; static void FS_UnloadProgs( void ) @@ -98,6 +107,13 @@ qboolean FS_LoadProgs( void ) 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" ); return true; diff --git a/engine/common/system.c b/engine/common/system.c index 08ed09fe..717861f2 100644 --- a/engine/common/system.c +++ b/engine/common/system.c @@ -649,3 +649,31 @@ qboolean Sys_NewInstance( const char *gamedir ) 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; +} diff --git a/engine/common/system.h b/engine/common/system.h index 8260c38e..a14a1a07 100644 --- a/engine/common/system.h +++ b/engine/common/system.h @@ -70,6 +70,7 @@ void Sys_InitLog( void ); void Sys_CloseLog( void ); void Sys_Quit( void ) NORETURN; qboolean Sys_NewInstance( const char *gamedir ); +void *Sys_GetNativeObject( const char *obj ); // // sys_con.c diff --git a/engine/platform/platform.h b/engine/platform/platform.h index fefe4802..db3661e4 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -139,17 +139,6 @@ static inline void Platform_Shutdown( void ) #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_GetNativeObject( const char *name ); /* ============================================================================== diff --git a/filesystem/VFileSystem009.h b/filesystem/VFileSystem009.h index 60437154..e48f4b7a 100644 --- a/filesystem/VFileSystem009.h +++ b/filesystem/VFileSystem009.h @@ -150,6 +150,4 @@ public: virtual void AddSearchPathNoWrite(const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20AddSearchPathNoWriteEPKcS1_ */ }; -#define FILESYSTEM_INTERFACE_VERSION "VFileSystem009" // never change this! - #endif // VFILESYSTEM009_H diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index 4843927d..7b622350 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -1386,7 +1386,7 @@ static void _Sys_Error( const char *fmt, ... ) exit( 1 ); } -static void *_Platform_GetNativeObject_stub( const char *object ) +static void *Sys_GetNativeObject_stub( const char *object ) { return NULL; } @@ -2841,7 +2841,7 @@ fs_interface_t g_engfuncs = _Mem_Alloc, _Mem_Realloc, _Mem_Free, - _Platform_GetNativeObject_stub + Sys_GetNativeObject_stub }; 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" ); } - 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" ); } diff --git a/filesystem/filesystem.h b/filesystem/filesystem.h index d2316087..031a6e0f 100644 --- a/filesystem/filesystem.h +++ b/filesystem/filesystem.h @@ -32,7 +32,8 @@ extern "C" #endif // __cplusplus #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 enum @@ -210,7 +211,7 @@ typedef struct fs_interface_t void (*_Mem_Free)( void *data, const char *filename, int fileline ); // platform - void *(*_Platform_GetNativeObject)( const char *object ); + void *(*_Sys_GetNativeObject)( const char *object ); } fs_interface_t; typedef int (*FSAPI)( int version, fs_api_t *api, fs_globals_t **globals, fs_interface_t *interface ); diff --git a/filesystem/filesystem_internal.h b/filesystem/filesystem_internal.h index 29e78f2a..acaa9fa3 100644 --- a/filesystem/filesystem_internal.h +++ b/filesystem/filesystem_internal.h @@ -127,7 +127,7 @@ extern const fs_archive_t g_archives[]; #define Con_DPrintf (*g_engfuncs._Con_DPrintf) #define Con_Reportf (*g_engfuncs._Con_Reportf) #define Sys_Error (*g_engfuncs._Sys_Error) -#define Platform_GetNativeObject (*g_engfuncs._Platform_GetNativeObject) +#define Sys_GetNativeObject (*g_engfuncs._Sys_GetNativeObject) // // filesystem.c diff --git a/filesystem/tests/interface.cpp b/filesystem/tests/interface.cpp index 5bdbe001..833127e0 100644 --- a/filesystem/tests/interface.cpp +++ b/filesystem/tests/interface.cpp @@ -18,7 +18,6 @@ typedef void *HMODULE; HMODULE g_hModule; FSAPI g_pfnGetFSAPI; -typedef void *(*pfnCreateInterface_t)( const char *, int * ); pfnCreateInterface_t g_pfnCreateInterface; fs_api_t g_fs; fs_globals_t *g_nullglobals;