mirror of
https://github.com/bulletphysics/bullet3.git
synced 2026-06-13 18:59:11 +00:00
improvement in b3PluginManager, hashing the postfix if available
(allows to load a plugin in the current executable instead of from disk)
This commit is contained in:
@@ -36,6 +36,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 +94,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 != nullptr && strlen(path) > 0)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
else if (postFix != nullptr && strlen(postFix) > 0)
|
||||
{
|
||||
return postFix;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
typedef b3PoolBodyHandle<b3Plugin> b3PluginHandle;
|
||||
@@ -113,7 +132,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 +199,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 +236,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 +253,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 +271,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 +357,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 +502,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 +511,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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user