Merge pull request #3125 from erwincoumans/master

improvement in b3PluginManager, hashing the postfix if available
This commit is contained in:
erwincoumans 2020-11-03 12:48:48 -08:00 committed by GitHub
commit 20c6178329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@
#include "PhysicsDirect.h"
#include "plugins/b3PluginContext.h"
#include "../Utils/b3BulletDefaultFileIO.h"
#include <string.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
@ -36,6 +37,7 @@ struct b3Plugin
bool m_ownsPluginHandle;
bool m_isInitialized;
std::string m_pluginPath;
std::string m_pluginPostFix;
int m_pluginUniqueId;
PFN_INIT m_initFunc;
PFN_EXIT m_exitFunc;
@ -93,6 +95,24 @@ struct b3Plugin
m_returnData = 0;
m_isInitialized = false;
}
const char* GetMapKey() const
{
return GetMapKey(m_pluginPath.c_str(), m_pluginPostFix.c_str());
}
static const char* GetMapKey(const char* path, const char* postFix)
{
if (path != 0 && strlen(path) > 0)
{
return path;
}
else if (postFix != 0 && strlen(postFix) > 0)
{
return postFix;
}
return "";
}
};
typedef b3PoolBodyHandle<b3Plugin> b3PluginHandle;
@ -180,7 +200,7 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
{
int pluginUniqueId = -1;
int* pluginUidPtr = m_data->m_pluginMap.find(pluginPath);
int* pluginUidPtr = m_data->m_pluginMap.find(b3Plugin::GetMapKey(pluginPath, postFixStr));
if (pluginUidPtr)
{
//already loaded
@ -252,7 +272,8 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
plugin->m_ownsPluginHandle = true;
plugin->m_pluginHandle = pluginHandle;
plugin->m_pluginPath = pluginPath;
m_data->m_pluginMap.insert(pluginPath, pluginUniqueId);
plugin->m_pluginPostFix = postFixStr;
m_data->m_pluginMap.insert(plugin->GetMapKey(), pluginUniqueId);
}
else
{
@ -337,7 +358,7 @@ void b3PluginManager::unloadPlugin(int pluginUniqueId)
plugin->m_returnData = 0;
plugin->m_isInitialized = false;
}
m_data->m_pluginMap.remove(plugin->m_pluginPath.c_str());
m_data->m_pluginMap.remove(plugin->GetMapKey());
m_data->m_plugins.freeHandle(pluginUniqueId);
}
}
@ -482,6 +503,7 @@ int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, b3Plugi
pluginHandle->m_getFileIOFunc = functions.m_fileIoFunc;
pluginHandle->m_pluginHandle = 0;
pluginHandle->m_pluginPath = pluginPath;
pluginHandle->m_pluginPostFix = "";
pluginHandle->m_userPointer = 0;
pluginHandle->m_returnData = 0;
@ -490,7 +512,7 @@ int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, b3Plugi
m_data->m_numNotificationPlugins++;
}
m_data->m_pluginMap.insert(pluginPath, pluginUniqueId);
m_data->m_pluginMap.insert(pluginHandle->GetMapKey(), pluginUniqueId);
if (initPlugin)
{