From 89a3fd632316cf7dbcbe40a7e69e1aea446b89ae Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 1 Jul 2019 05:50:04 +0300 Subject: [PATCH] engine: make use of platform-unique library naming scheme --- engine/client/cl_gameui.c | 24 ++++++++++++++---------- engine/client/cl_main.c | 12 ++++++------ engine/client/vgui/vgui_draw.c | 2 +- engine/common/common.h | 1 - engine/common/filesystem.c | 23 ++++------------------- engine/server/sv_init.c | 15 ++++++++++++--- 6 files changed, 37 insertions(+), 40 deletions(-) diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index eca1a6a9..88fb182e 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -888,6 +888,7 @@ pfnCheckGameDll */ int pfnCheckGameDll( void ) { + string dllpath; void *hInst; #if TARGET_OS_IPHONE @@ -900,7 +901,9 @@ int pfnCheckGameDll( void ) if( svgame.hInstance ) return true; - if(( hInst = COM_LoadLibrary( SI.gamedll, true, false )) != NULL ) + COM_GetCommonLibraryName( LIBRARY_SERVER, dllpath, sizeof( dllpath )); + + if(( hInst = COM_LoadLibrary( dllpath, true, false )) != NULL ) { COM_FreeLibrary( hInst ); // don't increase linker's reference counter return true; @@ -1075,6 +1078,7 @@ qboolean UI_LoadProgs( void ) static ui_textfuncs_t gpTextfuncs; static ui_globalvars_t gpGlobals; UITEXTAPI GiveTextApi; + string dllpath; int i; if( gameui.hInstance ) UI_UnloadProgs(); @@ -1082,23 +1086,23 @@ qboolean UI_LoadProgs( void ) // setup globals gameui.globals = &gpGlobals; -#ifdef XASH_INTERNAL_GAMELIBS - if(!( gameui.hInstance = COM_LoadLibrary( "menu", false, false ))) - return false; -#else - if(!( gameui.hInstance = COM_LoadLibrary( va( "%s/" MENUDLL, GI->dll_path ), false, false ))) + COM_GetCommonLibraryName( LIBRARY_GAMEUI, dllpath, sizeof( dllpath )); + + if(!( gameui.hInstance = COM_LoadLibrary( dllpath, false, false ))) { FS_AllowDirectPaths( true ); - if(!( gameui.hInstance = COM_LoadLibrary( "../" MENUDLL, false, false )) - && !( gameui.hInstance = COM_LoadLibrary( MENUDLL, false, false ))) - + // no use to load it from engine directory, as library loader + // that implements internal gamelibs already knows how to load it +#ifndef XASH_INTERNAL_GAMELIBS + if(!( gameui.hInstance = COM_LoadLibrary( OS_LIB_PREFIX "menu." OS_LIB_EXT, false, false ))) +#endif { FS_AllowDirectPaths( false ); return false; } } -#endif + FS_AllowDirectPaths( false ); if(( GetMenuAPI = (MENUAPI)COM_GetProcAddress( gameui.hInstance, "GetMenuAPI" )) == NULL ) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 5740b799..4811a967 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -2967,6 +2967,8 @@ CL_Init */ void CL_Init( void ) { + string libpath; + if( host.type == HOST_DEDICATED ) return; // nothing running on the client @@ -2981,12 +2983,10 @@ void CL_Init( void ) // IN_TouchInit(); Con_LoadHistory(); -#ifdef XASH_INTERNAL_GAMELIBS - if( !CL_LoadProgs( "client" ) ) -#else - if( !CL_LoadProgs( va( "%s/%s", GI->dll_path, SI.clientlib))) -#endif - Host_Error( "can't initialize %s: %s\n", SI.clientlib, COM_GetLibraryError() ); + COM_GetCommonLibraryName( LIBRARY_CLIENT, libpath, sizeof( libpath )); + + if( !CL_LoadProgs( libpath ) ) + Host_Error( "can't initialize %s: %s\n", libpath, COM_GetLibraryError() ); cls.initialized = true; cl.maxclients = 1; // allow to drawing player in menu diff --git a/engine/client/vgui/vgui_draw.c b/engine/client/vgui/vgui_draw.c index 3a70a279..9617044b 100644 --- a/engine/client/vgui/vgui_draw.c +++ b/engine/client/vgui/vgui_draw.c @@ -266,7 +266,7 @@ void VGui_Startup( const char *clientlib, int width, int height ) Con_Reportf( S_WARN "VGUI preloading failed. Default library will be used! Reason: %s\n", COM_GetLibraryError()); } - if( Q_strstr( GI->client_lib, ".dll" ) ) + if( Q_strstr( clientlib, ".dll" ) ) Q_strncpy( vguiloader, "vgui_support.dll", 256 ); if( !vguiloader[0] && !Sys_GetParmFromCmdLine( "-vguiloader", vguiloader ) ) diff --git a/engine/common/common.h b/engine/common/common.h index 9a55d994..32fe18f2 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -234,7 +234,6 @@ typedef struct gameinfo_s char game_dll_linux[64]; // custom path for game.dll char game_dll_osx[64]; // custom path for game.dll - char client_lib[64]; // custom name of client library qboolean added; } gameinfo_t; diff --git a/engine/common/filesystem.c b/engine/common/filesystem.c index d64fc9b5..1a19d3e5 100644 --- a/engine/common/filesystem.c +++ b/engine/common/filesystem.c @@ -1489,7 +1489,6 @@ void FS_InitGameInfo( gameinfo_t *GameInfo, const char *gamedir ) Q_strncpy( GameInfo->game_dll, "dlls/hl.dll", sizeof( GameInfo->game_dll )); Q_strncpy( GameInfo->game_dll_linux, "dlls/hl.so", sizeof( GameInfo->game_dll_linux )); Q_strncpy( GameInfo->game_dll_osx, "dlls/hl.dylib", sizeof( GameInfo->game_dll_osx )); - Q_strncpy( GameInfo->client_lib, CLIENTDLL, sizeof( GameInfo->client_lib )); // .ico path Q_strncpy( GameInfo->iconpath, "game.ico", sizeof( GameInfo->iconpath )); @@ -1654,10 +1653,6 @@ void FS_ParseGenericGameInfo( gameinfo_t *GameInfo, const char *buf, const qbool { pfile = COM_ParseFile( pfile, GameInfo->sp_entity ); } - else if( !Q_stricmp( token, "clientlib" )) - { - pfile = COM_ParseFile( pfile, GameInfo->client_lib ); - } else if( isGameInfo && !Q_stricmp( token, "dllpath" )) { pfile = COM_ParseFile( pfile, GameInfo->dll_path ); @@ -1941,25 +1936,15 @@ void FS_LoadGameInfo( const char *rootfolder ) Sys_Error( "Couldn't find game directory '%s'\n", fs_gamedir ); SI.GameInfo = SI.games[i]; + if( !Sys_GetParmFromCmdLine( "-dll", SI.gamedll ) ) { -#ifdef XASH_INTERNAL_GAMELIBS - Q_strncpy( SI.gamedll, "server", sizeof( SI.gamedll ) ); -#elif defined(_WIN32) - Q_strncpy( SI.gamedll, GI->game_dll, sizeof( SI.gamedll ) ); -#elif defined(__APPLE__) - Q_strncpy( SI.gamedll, GI->game_dll_osx, sizeof( SI.gamedll ) ); -#else - Q_strncpy( SI.gamedll, GI->game_dll_linux, sizeof( SI.gamedll ) ); -#endif + SI.gamedll[0] = 0; } + if( !Sys_GetParmFromCmdLine( "-clientlib", SI.clientlib ) ) { -#ifdef XASH_INTERNAL_GAMELIBS - Q_strncpy( SI.clientlib, "client", sizeof( SI.clientlib ) ); -#else - Q_strncpy( SI.clientlib, GI->client_lib, sizeof( SI.clientlib ) ); -#endif + SI.clientlib[0] = 0; } FS_Rescan(); // create new filesystem diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 40a5a420..5215f9b2 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -665,14 +665,19 @@ A brand new game has been started */ qboolean SV_InitGame( void ) { + string dllpath; + if( svs.initialized ) return true; // already initialized ? // first initialize? COM_ResetLibraryError(); - if( !SV_LoadProgs( SI.gamedll )) + + COM_GetCommonLibraryName( LIBRARY_SERVER, dllpath, sizeof( dllpath )); + + if( !SV_LoadProgs( dllpath )) { - Con_Printf( S_ERROR "can't initialize %s: %s\n", SI.gamedll, COM_GetLibraryError() ); + Con_Printf( S_ERROR "can't initialize %s: %s\n", dllpath, COM_GetLibraryError() ); return false; // failed to loading server.dll } @@ -991,10 +996,14 @@ int SV_GetMaxClients( void ) void SV_InitGameProgs( void ) { + string dllpath; + if( svgame.hInstance ) return; // already loaded + COM_GetCommonLibraryName( LIBRARY_SERVER, dllpath, sizeof( dllpath )); + // just try to initialize - SV_LoadProgs( GI->game_dll ); + SV_LoadProgs( dllpath ); } void SV_FreeGameProgs( void )