Skip to content

Commit

Permalink
engine, filesystem: unify GetNativeObject between all the APIs. Allow…
Browse files Browse the repository at this point in the history
… getting filesystem APIs through GetNativeObject
  • Loading branch information
a1batross committed Oct 31, 2023
1 parent 5ea074a commit 597429c
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 33 deletions.
1 change: 1 addition & 0 deletions common/xash3d_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 1 addition & 10 deletions engine/client/cl_mobile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -124,7 +115,7 @@ static mobile_engfuncs_t gpMobileEngfuncs =
Touch_ResetDefaultButtons,
pfnDrawScaledCharacter,
Sys_Warn,
pfnGetNativeObject,
Sys_GetNativeObject,
ID_SetCustomClientID,
pfnParseFileSafe
};
Expand Down
1 change: 1 addition & 0 deletions engine/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion engine/common/filesystem_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -53,7 +62,7 @@ static fs_interface_t fs_memfuncs =
_Mem_Realloc,
_Mem_Free,

Platform_GetNativeObject,
Sys_GetNativeObject,
};

static void FS_UnloadProgs( void )
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions engine/common/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions engine/common/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions engine/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
==============================================================================
Expand All @@ -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 );

/*
==============================================================================
Expand Down
2 changes: 0 additions & 2 deletions filesystem/VFileSystem009.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,4 @@ class IVFileSystem009 : public IBaseInterface
virtual void AddSearchPathNoWrite(const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20AddSearchPathNoWriteEPKcS1_ */
};

#define FILESYSTEM_INTERFACE_VERSION "VFileSystem009" // never change this!

#endif // VFILESYSTEM009_H
8 changes: 4 additions & 4 deletions filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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" );
}

Expand Down
5 changes: 3 additions & 2 deletions filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion filesystem/filesystem_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion filesystem/tests/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 597429c

Please sign in to comment.