]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
sys: Simplify Sys_LoadLibrary. Implement Sys_LoadDependency and move bloat to it
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 6 Mar 2021 12:03:22 +0000 (12:03 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 6 Mar 2021 12:03:22 +0000 (12:03 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13096 d7cf8633-e32d-0410-b094-e92efae38249

15 files changed:
av_backend_libav.c
cap_ogg.c
cl_video_libavw.c
crypto.c
fs.c
ft2.c
image_png.c
jpeg.c
libcurl.c
snd_ogg.c
snd_xmp.c
sys.h
sys_shared.c
vid_shared.c
world.c

index db9f5609d1bf9bdca51f5a3d01c19da46cabb825..653c9b4217f9a3371203bf4170f5fb0dda50e462 100644 (file)
@@ -289,9 +289,9 @@ qbool LibAV_LoadLibrary(void)
                return false;
 
        // Load the DLL
-       if (Sys_LoadLibrary (dllnames_libavcodec, &libavcodec_dll, libavcodecfuncs))
+       if (Sys_LoadDependency (dllnames_libavcodec, &libavcodec_dll, libavcodecfuncs))
        {
-               if(Sys_LoadLibrary(dllnames_libavformat, &libavformat_dll, libavformatfuncs))
+               if(Sys_LoadDependency(dllnames_libavformat, &libavformat_dll, libavformatfuncs))
                        return true;
                Con_Printf(CON_ERROR "Failed to load the libavformat library. Cannot use libavcodec without it\n");
                Sys_FreeLibrary(&libavcodec_dll);
index 0a0c1634338e017384a9f46c9b2aa74995495bbf..6218e8ad5fd71d51040d5a90ace806fa4d46becc 100644 (file)
--- a/cap_ogg.c
+++ b/cap_ogg.c
@@ -565,13 +565,13 @@ static qbool SCR_CaptureVideo_Ogg_OpenLibrary(void)
        };
 
        return
-               Sys_LoadLibrary (dllnames_og, &og_dll, oggfuncs)
+               Sys_LoadDependency (dllnames_og, &og_dll, oggfuncs)
                &&
-               Sys_LoadLibrary (dllnames_th, &th_dll, theorafuncs)
+               Sys_LoadDependency (dllnames_th, &th_dll, theorafuncs)
                &&
-               Sys_LoadLibrary (dllnames_vo, &vo_dll, vorbisfuncs)
+               Sys_LoadDependency (dllnames_vo, &vo_dll, vorbisfuncs)
                &&
-               Sys_LoadLibrary (dllnames_ve, &ve_dll, vorbisencfuncs);
+               Sys_LoadDependency (dllnames_ve, &ve_dll, vorbisencfuncs);
 }
 
 void SCR_CaptureVideo_Ogg_Init(void)
index f85148a8eda53870f798f0803037a16884d9708f..83f4921c35677005afeb608254a0697add198831 100644 (file)
@@ -364,7 +364,7 @@ qbool LibAvW_OpenLibrary(void)
                return false;
 
        // load DLL's
-       Sys_LoadLibrary(dllnames_libavw, &libavw_dll, libavwfuncs);
+       Sys_LoadDependency(dllnames_libavw, &libavw_dll, libavwfuncs);
        if (!libavw_dll)
                return false;
 
index af34b385c819fa6269e9e2c157e442b612d3eb05..72fcd2d317aabe1dfe4433304226c650ccbd2e2e 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -279,7 +279,7 @@ static qbool Crypto_OpenLibrary (void)
                return true;
 
        // Load the DLL
-       return Sys_LoadLibrary (dllnames, &d0_blind_id_dll, d0_blind_id_funcs);
+       return Sys_LoadDependency (dllnames, &d0_blind_id_dll, d0_blind_id_funcs);
 }
 
 static void Crypto_CloseLibrary (void)
@@ -348,7 +348,7 @@ static qbool Crypto_Rijndael_OpenLibrary (void)
                return true;
 
        // Load the DLL
-       return Sys_LoadLibrary (dllnames, &d0_rijndael_dll, d0_rijndael_funcs);
+       return Sys_LoadDependency (dllnames, &d0_rijndael_dll, d0_rijndael_funcs);
 }
 
 static void Crypto_Rijndael_CloseLibrary (void)
diff --git a/fs.c b/fs.c
index 58e9de4ba2828ebd21d5868778db6375682e86f4..74733bfb0f55ced81ac21d06f33ea18a15c2303c 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -535,7 +535,7 @@ static qbool PK3_OpenLibrary (void)
                return true;
 
        // Load the DLL
-       return Sys_LoadLibrary (dllnames, &zlib_dll, zlibfuncs);
+       return Sys_LoadDependency (dllnames, &zlib_dll, zlibfuncs);
 #endif
 }
 
@@ -1823,7 +1823,7 @@ static int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t use
                break;
        case USERDIRMODE_MYGAMES:
                if (!shfolder_dll)
-                       Sys_LoadLibrary(shfolderdllnames, &shfolder_dll, shfolderfuncs);
+                       Sys_LoadDependency(shfolderdllnames, &shfolder_dll, shfolderfuncs);
                mydocsdir[0] = 0;
                if (qSHGetFolderPath && qSHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir) == S_OK)
                {
@@ -1849,9 +1849,9 @@ static int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t use
                return -1;
        case USERDIRMODE_SAVEDGAMES:
                if (!shell32_dll)
-                       Sys_LoadLibrary(shell32dllnames, &shell32_dll, shell32funcs);
+                       Sys_LoadDependency(shell32dllnames, &shell32_dll, shell32funcs);
                if (!ole32_dll)
-                       Sys_LoadLibrary(ole32dllnames, &ole32_dll, ole32funcs);
+                       Sys_LoadDependency(ole32dllnames, &ole32_dll, ole32funcs);
                if (qSHGetKnownFolderPath && qCoInitializeEx && qCoTaskMemFree && qCoUninitialize)
                {
                        savedgamesdir[0] = 0;
diff --git a/ft2.c b/ft2.c
index 2df99bcb3700d803ff834671eb5658a712b96ae5..b7421b218c3f79abe5ebd11039c51510ea868ade 100644 (file)
--- a/ft2.c
+++ b/ft2.c
@@ -367,7 +367,7 @@ qbool Font_OpenLibrary (void)
                return true;
 
        // Load the DLL
-       if (!Sys_LoadLibrary (dllnames, &ft2_dll, ft2funcs))
+       if (!Sys_LoadDependency (dllnames, &ft2_dll, ft2funcs))
                return false;
 #endif
        return true;
index f7db48aad8bb8db9e37214584d7c247aa1e5b421..6b226af060d7f4f1eb85276a1ca3f8b08216757c 100644 (file)
@@ -172,10 +172,10 @@ qbool PNG_OpenLibrary (void)
                return true;
 
        // Load the DLL
-       if(!Sys_LoadLibrary (dllnames, &png_dll, pngfuncs))
+       if(!Sys_LoadDependency (dllnames, &png_dll, pngfuncs))
                return false;
        if(qpng_access_version_number() / 100 >= 104)
-               if(!Sys_LoadLibrary (dllnames, &png14_dll, png14funcs))
+               if(!Sys_LoadDependency (dllnames, &png14_dll, png14funcs))
                {
                        Sys_FreeLibrary (&png_dll);
                        return false;
diff --git a/jpeg.c b/jpeg.c
index 1e247a66b7a0451f405328bc5c65691ac4144fbd..3791480718bbcc474053cb824dd5bfcdca66c2ac 100644 (file)
--- a/jpeg.c
+++ b/jpeg.c
@@ -523,7 +523,7 @@ qbool JPEG_OpenLibrary (void)
 #endif
 
        // Load the DLL
-       return Sys_LoadLibrary (dllnames, &jpeg_dll, jpegfuncs);
+       return Sys_LoadDependency (dllnames, &jpeg_dll, jpegfuncs);
 #endif
 }
 
index cd6d8279ddd7a14de3cbfc318c56ce2cf602b988..cd106e7e67ebfb60df40d0a1bb17b05d49dbf6d5 100644 (file)
--- a/libcurl.c
+++ b/libcurl.c
@@ -377,7 +377,7 @@ static qbool CURL_OpenLibrary (void)
                return true;
 
        // Load the DLL
-       return Sys_LoadLibrary (dllnames, &curl_dll, curlfuncs);
+       return Sys_LoadDependency (dllnames, &curl_dll, curlfuncs);
 }
 
 
index 39c09b5b2158ff732f4c1e2d1094a872dae417fb..09d20c8e307c0e2d9c9c93397c5cf8577957dff4 100644 (file)
--- a/snd_ogg.c
+++ b/snd_ogg.c
@@ -306,7 +306,7 @@ qbool OGG_OpenLibrary (void)
        // Load the DLLs
        // We need to load both by hand because some OSes seem to not load
        // the vorbis DLL automatically when loading the VorbisFile DLL
-       return Sys_LoadLibrary (dllnames_vo, &vo_dll, vorbisfuncs) && Sys_LoadLibrary (dllnames_vf, &vf_dll, vorbisfilefuncs);
+       return Sys_LoadDependency (dllnames_vo, &vo_dll, vorbisfuncs) && Sys_LoadDependency (dllnames_vf, &vf_dll, vorbisfilefuncs);
 }
 
 
index 6be0bfe566067f16b669faa3246a8acfbc2673e1..9876803d571fbcfc8c0922ba1d513b5100d1f2d5 100644 (file)
--- a/snd_xmp.c
+++ b/snd_xmp.c
@@ -371,7 +371,7 @@ qbool XMP_OpenLibrary (void)
                return false;
 
        // Load the DLL
-       if (Sys_LoadLibrary (dllnames_xmp, &xmp_dll, xmpfuncs))
+       if (Sys_LoadDependency (dllnames_xmp, &xmp_dll, xmpfuncs))
        {
                if (*qxmp_vercode < 0x040200)
                {
diff --git a/sys.h b/sys.h
index b606315d70e241c4cb638ed9623eb4be1e5002b3..ea711f661e7f00a5687988a76f9869f175108a27 100644 (file)
--- a/sys.h
+++ b/sys.h
@@ -173,12 +173,20 @@ dllfunction_t;
 
 qbool Sys_LoadSelf(dllhandle_t *handle);
 
-/*! Loads a library. 
+/*! Loads a dependency library. 
  * \param dllnames a NULL terminated array of possible names for the DLL you want to load.
  * \param handle
  * \param fcts
  */
-qbool Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts);
+qbool Sys_LoadDependency (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts);
+
+/*! Loads a library.
+ * \param name a string of the library filename
+ * \param handle
+ * \return true if library was loaded successfully
+ */
+qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle);
+
 void Sys_FreeLibrary (dllhandle_t* handle);
 void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
 
index 985af9034138fc7f7b802c8696ad8f5352a20ea9..e849a9bcc2c3c571c550a5d741b5a08876bafd1e 100644 (file)
@@ -91,7 +91,7 @@ DLL MANAGEMENT
 ===============================================================================
 */
 
-static qbool Sys_LoadLibraryFunctions(dllhandle_t dllhandle, const dllfunction_t *fcts, qbool complain, qbool has_next)
+static qbool Sys_LoadDependencyFunctions(dllhandle_t dllhandle, const dllfunction_t *fcts, qbool complain, qbool has_next)
 {
        const dllfunction_t *func;
        if(dllhandle)
@@ -131,7 +131,7 @@ qbool Sys_LoadSelf(dllhandle_t *handle)
        return true;
 }
 
-qbool Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
+qbool Sys_LoadDependency (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
 {
 #ifdef SUPPORTDLL
        const dllfunction_t *func;
@@ -144,7 +144,7 @@ qbool Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunc
 #ifndef WIN32
 #ifdef PREFER_PRELOAD
        dllhandle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
-       if(Sys_LoadLibraryFunctions(dllhandle, fcts, false, false))
+       if(Sys_LoadDependencyFunctions(dllhandle, fcts, false, false))
        {
                Con_DPrintf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
                *handle = dllhandle;
@@ -173,15 +173,14 @@ notfound:
                SetDllDirectory("bin32");
 #  endif
 # endif
-               dllhandle = LoadLibrary (dllnames[i]);
-               // no need to unset this - we want ALL dlls to be loaded from there, anyway
-#else
-               dllhandle = dlopen (dllnames[i], RTLD_LAZY | RTLD_GLOBAL);
 #endif
-               if (Sys_LoadLibraryFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(sys.argv[0], '/'))))
-                       break;
-               else
-                       Sys_FreeLibrary (&dllhandle);
+               if(Sys_LoadLibrary(dllnames[i], &dllhandle))
+               {
+                       if (Sys_LoadDependencyFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(sys.argv[0], '/'))))
+                               break;
+                       else
+                               Sys_FreeLibrary (&dllhandle);
+               }
        }
 
        // see if the names can be loaded relative to the executable path
@@ -197,15 +196,14 @@ notfound:
                        strlcpy(temp, path, sizeof(temp));
                        strlcat(temp, dllnames[i], sizeof(temp));
                        Con_DPrintf (" \"%s\"", temp);
-#ifdef WIN32
-                       dllhandle = LoadLibrary (temp);
-#else
-                       dllhandle = dlopen (temp, RTLD_LAZY | RTLD_GLOBAL);
-#endif
-                       if (Sys_LoadLibraryFunctions(dllhandle, fcts, true, dllnames[i+1] != NULL))
-                               break;
-                       else
-                               Sys_FreeLibrary (&dllhandle);
+
+                       if(Sys_LoadLibrary(temp, &dllhandle))
+                       {
+                               if (Sys_LoadDependencyFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(sys.argv[0], '/'))))
+                                       break;
+                               else
+                                       Sys_FreeLibrary (&dllhandle);
+                       }
                }
        }
 
@@ -226,6 +224,27 @@ notfound:
 #endif
 }
 
+qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle)
+{
+       dllhandle_t dllhandle = 0;
+
+       if(handle == NULL)
+               return false;
+
+#ifdef SUPPORTDLL
+# ifdef WIN32
+       dllhandle = LoadLibrary (name);
+# else
+       dllhandle = dlopen (name, RTLD_LAZY | RTLD_GLOBAL);
+# endif
+#endif
+       if(!dllhandle)
+               return false;
+
+       *handle = dllhandle;
+       return true;
+}
+
 void Sys_FreeLibrary (dllhandle_t* handle)
 {
 #ifdef SUPPORTDLL
@@ -282,8 +301,9 @@ void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
 # define HAVE_USLEEP 1
 #endif
 
-// this one is referenced elsewhere
+// these are referenced elsewhere
 cvar_t sys_usenoclockbutbenchmark = {CF_CLIENT | CF_SERVER | CF_ARCHIVE, "sys_usenoclockbutbenchmark", "0", "don't use ANY real timing, and simulate a clock (for benchmarking); the game then runs as fast as possible. Run a QC mod with bots that does some stuff, then does a quit at the end, to benchmark a server. NEVER do this on a public server."};
+cvar_t sys_libdir = {CF_READONLY | CF_CLIENT | CF_SERVER, "sys_libdir", "", "Default engine library directory"};
 
 // these are not
 static cvar_t sys_debugsleep = {CF_CLIENT | CF_SERVER, "sys_debugsleep", "0", "write requested and attained sleep times to standard output, to be used with gnuplot"};
@@ -325,6 +345,7 @@ void Sys_Init_Commands (void)
 {
        Cvar_RegisterVariable(&sys_debugsleep);
        Cvar_RegisterVariable(&sys_usenoclockbutbenchmark);
+       Cvar_RegisterVariable(&sys_libdir);
 #if HAVE_TIMEGETTIME || HAVE_QUERYPERFORMANCECOUNTER || HAVE_CLOCKGETTIME || HAVE_GETTIMEOFDAY
        if(sys_supportsdlgetticks)
        {
index df8662d5afdcbd969fe9d806d9b604c30e62108e..bc4c98552e0918f82454f61ddd25d1bf6dae3d36 100644 (file)
@@ -1360,7 +1360,7 @@ void VID_Shared_Init(void)
        //Cvar_RegisterVariable(&joy_x360_sensitivityroll);
 
 #ifdef WIN32
-       Sys_LoadLibrary(xinputdllnames, &xinputdll_dll, xinputdllfuncs);
+       Sys_LoadDependency(xinputdllnames, &xinputdll_dll, xinputdllfuncs);
 #endif
 
        Cmd_AddCommand(CF_CLIENT, "force_centerview", Force_CenterView_f, "recenters view (stops looking up/down)");
diff --git a/world.c b/world.c
index 76ef3a7a2770f22988a23cfc1f0e061d36247cc1..6c833975188f1ef470f8e8d587a1de79cb62f9fb 100644 (file)
--- a/world.c
+++ b/world.c
@@ -1522,7 +1522,7 @@ static void World_Physics_Init(void)
 
 #ifndef LINK_TO_LIBODE
        // Load the DLL
-       if (Sys_LoadLibrary (dllnames, &ode_dll, odefuncs))
+       if (Sys_LoadDependency (dllnames, &ode_dll, odefuncs))
 #endif
        {
                dInitODE();