mirror of
https://github.com/bulletphysics/bullet3
synced 2025-01-19 05:20:06 +00:00
Merge pull request #3125 from erwincoumans/master
improvement in b3PluginManager, hashing the postfix if available
This commit is contained in:
commit
20c6178329
@ -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;
|
||||
@ -113,7 +133,7 @@ struct b3PluginManagerInternalData
|
||||
int m_numNotificationPlugins;
|
||||
int m_activeFileIOPluginUid;
|
||||
b3BulletDefaultFileIO m_defaultFileIO;
|
||||
|
||||
|
||||
b3PluginManagerInternalData()
|
||||
: m_physicsDirect(0), m_rpcCommandProcessorInterface(0), m_activeNotificationsBufferIndex(0), m_activeRendererPluginUid(-1), m_activeCollisionPluginUid(-1), m_numNotificationPlugins(0), m_activeFileIOPluginUid(-1)
|
||||
{
|
||||
@ -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
|
||||
@ -217,7 +237,7 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
|
||||
std::string getRendererStr = std::string("getRenderInterface") + postFix;
|
||||
std::string getCollisionStr = std::string("getCollisionInterface") + postFix;
|
||||
std::string getFileIOStr = std::string("getFileIOInterface") + postFix;
|
||||
|
||||
|
||||
plugin->m_initFunc = (PFN_INIT)B3_DYNLIB_IMPORT(pluginHandle, initStr.c_str());
|
||||
plugin->m_exitFunc = (PFN_EXIT)B3_DYNLIB_IMPORT(pluginHandle, exitStr.c_str());
|
||||
plugin->m_executeCommandFunc = (PFN_EXECUTE)B3_DYNLIB_IMPORT(pluginHandle, executePluginCommandStr.c_str());
|
||||
@ -234,7 +254,7 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
|
||||
plugin->m_getRendererFunc = (PFN_GET_RENDER_INTERFACE)B3_DYNLIB_IMPORT(pluginHandle, getRendererStr.c_str());
|
||||
plugin->m_getCollisionFunc = (PFN_GET_COLLISION_INTERFACE)B3_DYNLIB_IMPORT(pluginHandle, getCollisionStr.c_str());
|
||||
plugin->m_getFileIOFunc = (PFN_GET_FILEIO_INTERFACE)B3_DYNLIB_IMPORT(pluginHandle, getFileIOStr.c_str());
|
||||
|
||||
|
||||
|
||||
if (plugin->m_initFunc && plugin->m_exitFunc && plugin->m_executeCommandFunc)
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user