2017-09-23 02:17:57 +00:00
|
|
|
|
|
|
|
#include "b3PluginManager.h"
|
|
|
|
#include "Bullet3Common/b3HashMap.h"
|
|
|
|
#include "Bullet3Common/b3ResizablePool.h"
|
2017-09-25 06:26:06 +00:00
|
|
|
#include "PhysicsClientC_API.h"
|
2017-09-23 16:25:00 +00:00
|
|
|
#include "PhysicsDirect.h"
|
|
|
|
#include "plugins/b3PluginContext.h"
|
2017-09-23 02:17:57 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define VC_EXTRALEAN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
typedef HMODULE B3_DYNLIB_HANDLE;
|
|
|
|
|
2017-10-30 10:09:09 +00:00
|
|
|
#define B3_DYNLIB_OPEN LoadLibraryA
|
2017-09-23 02:17:57 +00:00
|
|
|
#define B3_DYNLIB_CLOSE FreeLibrary
|
|
|
|
#define B3_DYNLIB_IMPORT GetProcAddress
|
|
|
|
#else
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
typedef void* B3_DYNLIB_HANDLE;
|
|
|
|
|
2018-08-31 13:33:08 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#define B3_DYNLIB_OPEN(path) dlopen(path, RTLD_NOW | RTLD_GLOBAL)
|
2018-08-31 13:35:35 +00:00
|
|
|
#else
|
|
|
|
#define B3_DYNLIB_OPEN(path) dlmopen(LM_ID_NEWLM, path, RTLD_LAZY)
|
2018-08-31 13:33:08 +00:00
|
|
|
#endif
|
2017-09-23 02:17:57 +00:00
|
|
|
#define B3_DYNLIB_CLOSE dlclose
|
|
|
|
#define B3_DYNLIB_IMPORT dlsym
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct b3Plugin
|
|
|
|
{
|
|
|
|
B3_DYNLIB_HANDLE m_pluginHandle;
|
2017-09-24 01:05:23 +00:00
|
|
|
bool m_ownsPluginHandle;
|
2018-09-10 04:08:47 +00:00
|
|
|
bool m_isInitialized;
|
2017-09-23 02:17:57 +00:00
|
|
|
std::string m_pluginPath;
|
2017-09-24 01:05:23 +00:00
|
|
|
int m_pluginUniqueId;
|
2017-09-23 02:17:57 +00:00
|
|
|
PFN_INIT m_initFunc;
|
|
|
|
PFN_EXIT m_exitFunc;
|
|
|
|
PFN_EXECUTE m_executeCommandFunc;
|
2017-09-24 01:05:23 +00:00
|
|
|
|
|
|
|
PFN_TICK m_preTickFunc;
|
|
|
|
PFN_TICK m_postTickFunc;
|
2018-07-25 12:47:34 +00:00
|
|
|
PFN_TICK m_processNotificationsFunc;
|
2018-09-06 00:58:14 +00:00
|
|
|
PFN_TICK m_processClientCommandsFunc;
|
2017-09-24 01:05:23 +00:00
|
|
|
|
2018-01-17 20:48:48 +00:00
|
|
|
PFN_GET_RENDER_INTERFACE m_getRendererFunc;
|
|
|
|
|
2017-09-24 01:05:23 +00:00
|
|
|
void* m_userPointer;
|
2018-01-17 20:48:48 +00:00
|
|
|
|
2017-09-24 01:05:23 +00:00
|
|
|
b3Plugin()
|
|
|
|
:m_pluginHandle(0),
|
|
|
|
m_ownsPluginHandle(false),
|
2018-09-10 04:08:47 +00:00
|
|
|
m_isInitialized(false),
|
2017-09-24 01:05:23 +00:00
|
|
|
m_pluginUniqueId(-1),
|
|
|
|
m_initFunc(0),
|
|
|
|
m_exitFunc(0),
|
|
|
|
m_executeCommandFunc(0),
|
|
|
|
m_preTickFunc(0),
|
2017-09-25 05:39:20 +00:00
|
|
|
m_postTickFunc(0),
|
2018-07-25 12:47:34 +00:00
|
|
|
m_processNotificationsFunc(0),
|
2018-09-06 00:58:14 +00:00
|
|
|
m_processClientCommandsFunc(0),
|
2018-01-17 20:48:48 +00:00
|
|
|
m_getRendererFunc(0),
|
2017-09-24 01:05:23 +00:00
|
|
|
m_userPointer(0)
|
|
|
|
{
|
|
|
|
}
|
2017-09-23 02:17:57 +00:00
|
|
|
void clear()
|
|
|
|
{
|
2017-09-24 01:05:23 +00:00
|
|
|
if (m_ownsPluginHandle)
|
|
|
|
{
|
|
|
|
B3_DYNLIB_CLOSE(m_pluginHandle);
|
|
|
|
}
|
2017-09-23 02:17:57 +00:00
|
|
|
m_pluginHandle = 0;
|
|
|
|
m_initFunc = 0;
|
|
|
|
m_exitFunc = 0;
|
|
|
|
m_executeCommandFunc = 0;
|
2017-09-24 01:05:23 +00:00
|
|
|
m_preTickFunc = 0;
|
|
|
|
m_postTickFunc = 0;
|
2018-09-06 00:58:14 +00:00
|
|
|
m_processNotificationsFunc = 0;
|
|
|
|
m_processClientCommandsFunc = 0;
|
2018-01-17 20:48:48 +00:00
|
|
|
m_getRendererFunc = 0;
|
2018-09-06 00:58:14 +00:00
|
|
|
m_userPointer = 0;
|
2018-09-10 04:08:47 +00:00
|
|
|
m_isInitialized = false;
|
2017-09-23 02:17:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef b3PoolBodyHandle<b3Plugin> b3PluginHandle;
|
|
|
|
|
|
|
|
struct b3PluginManagerInternalData
|
|
|
|
{
|
|
|
|
b3ResizablePool<b3PluginHandle> m_plugins;
|
2018-02-06 16:56:24 +00:00
|
|
|
b3HashMap<b3HashString, int> m_pluginMap;
|
2017-09-23 16:25:00 +00:00
|
|
|
PhysicsDirect* m_physicsDirect;
|
2018-09-06 00:58:14 +00:00
|
|
|
PhysicsCommandProcessorInterface* m_rpcCommandProcessorInterface;
|
2017-10-03 22:00:52 +00:00
|
|
|
b3AlignedObjectArray<b3KeyboardEvent> m_keyEvents;
|
|
|
|
b3AlignedObjectArray<b3VRControllerEvent> m_vrEvents;
|
|
|
|
b3AlignedObjectArray<b3MouseEvent> m_mouseEvents;
|
2018-07-24 12:12:16 +00:00
|
|
|
b3AlignedObjectArray<b3Notification> m_notifications[2];
|
|
|
|
int m_activeNotificationsBufferIndex;
|
2018-01-17 20:48:48 +00:00
|
|
|
int m_activeRendererPluginUid;
|
2018-09-05 02:24:31 +00:00
|
|
|
int m_numNotificationPlugins;
|
2018-01-17 20:48:48 +00:00
|
|
|
|
|
|
|
b3PluginManagerInternalData()
|
2018-09-06 00:58:14 +00:00
|
|
|
:m_rpcCommandProcessorInterface(0), m_activeNotificationsBufferIndex(0), m_activeRendererPluginUid(-1),
|
2018-09-05 02:24:31 +00:00
|
|
|
m_numNotificationPlugins(0)
|
2018-01-17 20:48:48 +00:00
|
|
|
{
|
|
|
|
}
|
2017-09-23 02:17:57 +00:00
|
|
|
};
|
|
|
|
|
2017-09-23 16:25:00 +00:00
|
|
|
b3PluginManager::b3PluginManager(class PhysicsCommandProcessorInterface* physSdk)
|
2017-09-23 02:17:57 +00:00
|
|
|
{
|
|
|
|
m_data = new b3PluginManagerInternalData;
|
2018-09-06 00:58:14 +00:00
|
|
|
m_data->m_rpcCommandProcessorInterface = physSdk;
|
2017-09-23 16:25:00 +00:00
|
|
|
m_data->m_physicsDirect = new PhysicsDirect(physSdk,false);
|
|
|
|
|
2017-09-23 02:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b3PluginManager::~b3PluginManager()
|
|
|
|
{
|
2017-09-24 01:05:23 +00:00
|
|
|
while (m_data->m_pluginMap.size())
|
|
|
|
{
|
2018-02-06 16:56:24 +00:00
|
|
|
int* pluginUidPtr = m_data->m_pluginMap.getAtIndex(0);
|
|
|
|
if (pluginUidPtr)
|
|
|
|
{
|
|
|
|
int pluginUid = *pluginUidPtr;
|
|
|
|
unloadPlugin(*pluginUidPtr);
|
|
|
|
}
|
2017-09-24 01:05:23 +00:00
|
|
|
}
|
2017-09-23 16:25:00 +00:00
|
|
|
delete m_data->m_physicsDirect;
|
2017-09-23 02:17:57 +00:00
|
|
|
m_data->m_pluginMap.clear();
|
|
|
|
m_data->m_plugins.exitHandles();
|
|
|
|
delete m_data;
|
|
|
|
}
|
2017-09-24 01:05:23 +00:00
|
|
|
|
2017-10-03 22:00:52 +00:00
|
|
|
void b3PluginManager::addEvents(const struct b3VRControllerEvent* vrControllerEvents, int numVRControllerEvents, const struct b3KeyboardEvent* keyEvents, int numKeyEvents, const struct b3MouseEvent* mouseEvents, int numMouseEvents)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < numKeyEvents; i++)
|
|
|
|
{
|
|
|
|
m_data->m_keyEvents.push_back(keyEvents[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < numVRControllerEvents; i++)
|
|
|
|
{
|
|
|
|
m_data->m_vrEvents.push_back(vrControllerEvents[i]);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < numMouseEvents; i++)
|
|
|
|
{
|
|
|
|
m_data->m_mouseEvents.push_back(mouseEvents[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-09-24 01:05:23 +00:00
|
|
|
|
2017-10-03 22:00:52 +00:00
|
|
|
void b3PluginManager::clearEvents()
|
|
|
|
{
|
|
|
|
m_data->m_keyEvents.resize(0);
|
|
|
|
m_data->m_vrEvents.resize(0);
|
|
|
|
m_data->m_mouseEvents.resize(0);
|
|
|
|
}
|
|
|
|
|
2018-07-24 12:12:16 +00:00
|
|
|
void b3PluginManager::addNotification(const struct b3Notification& notification)
|
|
|
|
{
|
2018-09-05 02:24:31 +00:00
|
|
|
if (m_data->m_numNotificationPlugins>0)
|
|
|
|
{
|
|
|
|
m_data->m_notifications[m_data->m_activeNotificationsBufferIndex].push_back(notification);
|
|
|
|
}
|
2018-07-24 12:12:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 22:00:52 +00:00
|
|
|
int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
|
2017-09-23 02:17:57 +00:00
|
|
|
{
|
|
|
|
int pluginUniqueId = -1;
|
|
|
|
|
2018-02-06 16:56:24 +00:00
|
|
|
int* pluginUidPtr = m_data->m_pluginMap.find(pluginPath);
|
|
|
|
if (pluginUidPtr)
|
2017-09-23 02:17:57 +00:00
|
|
|
{
|
2018-09-10 04:08:47 +00:00
|
|
|
|
2017-09-23 02:17:57 +00:00
|
|
|
//already loaded
|
2018-02-06 16:56:24 +00:00
|
|
|
pluginUniqueId = *pluginUidPtr;
|
2018-09-10 04:08:47 +00:00
|
|
|
b3PluginHandle* plugin = m_data->m_plugins.getHandle(pluginUniqueId);
|
|
|
|
if (!plugin->m_isInitialized)
|
|
|
|
{
|
|
|
|
b3PluginContext context = {0};
|
|
|
|
context.m_userPointer = 0;
|
|
|
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
|
|
|
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
|
|
|
int result = plugin->m_initFunc(&context);
|
|
|
|
plugin->m_isInitialized = true;
|
|
|
|
plugin->m_userPointer = context.m_userPointer;
|
|
|
|
}
|
2017-09-23 02:17:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pluginUniqueId = m_data->m_plugins.allocHandle();
|
|
|
|
b3PluginHandle* plugin = m_data->m_plugins.getHandle(pluginUniqueId);
|
2017-09-24 01:05:23 +00:00
|
|
|
plugin->m_pluginUniqueId = pluginUniqueId;
|
2017-09-23 02:17:57 +00:00
|
|
|
B3_DYNLIB_HANDLE pluginHandle = B3_DYNLIB_OPEN(pluginPath);
|
|
|
|
bool ok = false;
|
|
|
|
if (pluginHandle)
|
|
|
|
{
|
2017-10-03 22:00:52 +00:00
|
|
|
std::string postFix = postFixStr;
|
|
|
|
std::string initStr = std::string("initPlugin") + postFix;
|
|
|
|
std::string exitStr = std::string("exitPlugin") + postFix;
|
|
|
|
std::string executePluginCommandStr = std::string("executePluginCommand") + postFix;
|
|
|
|
std::string preTickPluginCallbackStr = std::string("preTickPluginCallback") + postFix;
|
|
|
|
std::string postTickPluginCallback = std::string("postTickPluginCallback") + postFix;
|
2018-07-25 12:47:34 +00:00
|
|
|
std::string processNotificationsStr = std::string("processNotifications") + postFix;
|
2018-09-06 00:58:14 +00:00
|
|
|
std::string processClientCommandsStr = std::string("processClientCommands") + postFix;
|
2018-01-17 20:48:48 +00:00
|
|
|
std::string getRendererStr = std::string("getRenderInterface") + postFix;
|
2018-07-25 12:47:34 +00:00
|
|
|
|
2017-10-03 22:00:52 +00:00
|
|
|
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());
|
|
|
|
plugin->m_preTickFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, preTickPluginCallbackStr.c_str());
|
|
|
|
plugin->m_postTickFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, postTickPluginCallback.c_str());
|
2018-07-25 12:47:34 +00:00
|
|
|
plugin->m_processNotificationsFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, processNotificationsStr.c_str());
|
2018-09-06 00:58:14 +00:00
|
|
|
|
2018-09-05 02:24:31 +00:00
|
|
|
if (plugin->m_processNotificationsFunc)
|
|
|
|
{
|
|
|
|
m_data->m_numNotificationPlugins++;
|
|
|
|
}
|
2018-09-06 00:58:14 +00:00
|
|
|
plugin->m_processClientCommandsFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, processClientCommandsStr.c_str());
|
|
|
|
|
2018-01-17 20:48:48 +00:00
|
|
|
plugin->m_getRendererFunc = (PFN_GET_RENDER_INTERFACE)B3_DYNLIB_IMPORT(pluginHandle, getRendererStr.c_str());
|
2018-09-05 02:24:31 +00:00
|
|
|
|
|
|
|
|
2017-09-23 02:17:57 +00:00
|
|
|
if (plugin->m_initFunc && plugin->m_exitFunc && plugin->m_executeCommandFunc)
|
|
|
|
{
|
2018-09-10 04:08:47 +00:00
|
|
|
|
2017-09-24 01:05:23 +00:00
|
|
|
b3PluginContext context;
|
|
|
|
context.m_userPointer = plugin->m_userPointer;
|
|
|
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
2018-09-06 00:58:14 +00:00
|
|
|
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
2017-09-24 01:05:23 +00:00
|
|
|
int version = plugin->m_initFunc(&context);
|
2018-09-10 04:08:47 +00:00
|
|
|
plugin->m_isInitialized = true;
|
2017-09-24 01:05:23 +00:00
|
|
|
//keep the user pointer persistent
|
|
|
|
plugin->m_userPointer = context.m_userPointer;
|
2017-09-23 02:17:57 +00:00
|
|
|
if (version == SHARED_MEMORY_MAGIC_NUMBER)
|
|
|
|
{
|
2018-09-10 04:08:47 +00:00
|
|
|
|
2017-09-23 02:17:57 +00:00
|
|
|
ok = true;
|
2017-09-24 01:05:23 +00:00
|
|
|
plugin->m_ownsPluginHandle = true;
|
2017-09-23 02:17:57 +00:00
|
|
|
plugin->m_pluginHandle = pluginHandle;
|
|
|
|
plugin->m_pluginPath = pluginPath;
|
2018-02-06 16:56:24 +00:00
|
|
|
m_data->m_pluginMap.insert(pluginPath, pluginUniqueId);
|
2017-09-23 02:17:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int expect = SHARED_MEMORY_MAGIC_NUMBER;
|
|
|
|
b3Warning("Warning: plugin is wrong version: expected %d, got %d\n", expect, version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b3Warning("Loaded plugin but couldn't bind functions");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
B3_DYNLIB_CLOSE(pluginHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-02 17:35:55 +00:00
|
|
|
|
2017-09-23 02:17:57 +00:00
|
|
|
b3Warning("Warning: couldn't load plugin %s\n", pluginPath);
|
2018-07-02 17:35:55 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#else
|
|
|
|
b3Warning("Error: %s\n", dlerror() );
|
|
|
|
#endif
|
|
|
|
|
2017-09-23 02:17:57 +00:00
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
m_data->m_plugins.freeHandle(pluginUniqueId);
|
|
|
|
pluginUniqueId = -1;
|
|
|
|
}
|
|
|
|
}
|
2018-01-17 20:48:48 +00:00
|
|
|
|
|
|
|
//for now, automatically select the loaded plugin as active renderer. If wanted, we can add some 'select' mechanism.
|
|
|
|
if (pluginUniqueId>=0)
|
|
|
|
{
|
|
|
|
b3PluginHandle* plugin = m_data->m_plugins.getHandle(pluginUniqueId);
|
|
|
|
if (plugin && plugin->m_getRendererFunc)
|
|
|
|
{
|
|
|
|
selectPluginRenderer(pluginUniqueId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 02:17:57 +00:00
|
|
|
return pluginUniqueId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void b3PluginManager::unloadPlugin(int pluginUniqueId)
|
|
|
|
{
|
|
|
|
b3PluginHandle* plugin = m_data->m_plugins.getHandle(pluginUniqueId);
|
|
|
|
if (plugin)
|
|
|
|
{
|
2018-09-05 02:24:31 +00:00
|
|
|
if (plugin->m_processNotificationsFunc)
|
|
|
|
{
|
|
|
|
m_data->m_numNotificationPlugins--;
|
|
|
|
}
|
2018-07-24 12:12:16 +00:00
|
|
|
b3PluginContext context = {0};
|
2017-09-24 01:05:23 +00:00
|
|
|
context.m_userPointer = plugin->m_userPointer;
|
|
|
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
|
|
|
|
2018-09-10 04:08:47 +00:00
|
|
|
if (plugin->m_isInitialized)
|
|
|
|
{
|
|
|
|
plugin->m_exitFunc(&context);
|
|
|
|
plugin->m_userPointer = 0;
|
|
|
|
plugin->m_isInitialized = false;
|
|
|
|
}
|
2017-09-23 02:17:57 +00:00
|
|
|
m_data->m_pluginMap.remove(plugin->m_pluginPath.c_str());
|
|
|
|
m_data->m_plugins.freeHandle(pluginUniqueId);
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 00:58:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void b3PluginManager::tickPlugins(double timeStep, b3PluginManagerTickMode tickMode)
|
2017-09-24 01:05:23 +00:00
|
|
|
{
|
|
|
|
for (int i=0;i<m_data->m_pluginMap.size();i++)
|
|
|
|
{
|
2018-02-06 16:56:24 +00:00
|
|
|
int* pluginUidPtr = m_data->m_pluginMap.getAtIndex(i);
|
2017-10-03 22:00:52 +00:00
|
|
|
b3PluginHandle* plugin = 0;
|
2018-02-06 16:56:24 +00:00
|
|
|
|
|
|
|
if (pluginUidPtr)
|
2017-10-03 22:00:52 +00:00
|
|
|
{
|
2018-02-06 16:56:24 +00:00
|
|
|
int pluginUid = *pluginUidPtr;
|
|
|
|
plugin = m_data->m_plugins.getHandle(pluginUid);
|
2017-10-03 22:00:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2018-02-06 16:56:24 +00:00
|
|
|
|
2018-09-06 00:58:14 +00:00
|
|
|
PFN_TICK tick = 0;
|
|
|
|
switch (tickMode)
|
|
|
|
{
|
|
|
|
case B3_PRE_TICK_MODE:
|
|
|
|
{
|
|
|
|
tick = plugin->m_preTickFunc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B3_POST_TICK_MODE:
|
|
|
|
{
|
|
|
|
tick = plugin->m_postTickFunc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B3_PROCESS_CLIENT_COMMANDS_TICK:
|
|
|
|
{
|
|
|
|
tick = plugin->m_processClientCommandsFunc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 01:05:23 +00:00
|
|
|
if (tick)
|
|
|
|
{
|
2018-09-06 00:58:14 +00:00
|
|
|
b3PluginContext context = { 0 };
|
2017-09-24 01:05:23 +00:00
|
|
|
context.m_userPointer = plugin->m_userPointer;
|
2018-09-06 00:58:14 +00:00
|
|
|
context.m_physClient = (b3PhysicsClientHandle)m_data->m_physicsDirect;
|
2017-10-03 22:00:52 +00:00
|
|
|
context.m_numMouseEvents = m_data->m_mouseEvents.size();
|
|
|
|
context.m_mouseEvents = m_data->m_mouseEvents.size() ? &m_data->m_mouseEvents[0] : 0;
|
|
|
|
context.m_numKeyEvents = m_data->m_keyEvents.size();
|
|
|
|
context.m_keyEvents = m_data->m_keyEvents.size() ? &m_data->m_keyEvents[0] : 0;
|
|
|
|
context.m_numVRControllerEvents = m_data->m_vrEvents.size();
|
2018-09-06 00:58:14 +00:00
|
|
|
context.m_vrControllerEvents = m_data->m_vrEvents.size() ? &m_data->m_vrEvents[0] : 0;
|
|
|
|
if (tickMode == B3_PROCESS_CLIENT_COMMANDS_TICK)
|
|
|
|
{
|
|
|
|
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
|
|
|
}
|
2017-09-24 01:05:23 +00:00
|
|
|
int result = tick(&context);
|
|
|
|
plugin->m_userPointer = context.m_userPointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 12:47:34 +00:00
|
|
|
void b3PluginManager::reportNotifications()
|
2018-07-24 12:12:16 +00:00
|
|
|
{
|
|
|
|
b3AlignedObjectArray<b3Notification> ¬ifications = m_data->m_notifications[m_data->m_activeNotificationsBufferIndex];
|
2018-07-25 12:47:34 +00:00
|
|
|
if (notifications.size() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-24 12:12:16 +00:00
|
|
|
// Swap notification buffers.
|
|
|
|
m_data->m_activeNotificationsBufferIndex = 1 - m_data->m_activeNotificationsBufferIndex;
|
|
|
|
|
|
|
|
for (int i=0;i<m_data->m_pluginMap.size();i++)
|
|
|
|
{
|
|
|
|
int* pluginUidPtr = m_data->m_pluginMap.getAtIndex(i);
|
|
|
|
b3PluginHandle* plugin = 0;
|
|
|
|
|
|
|
|
if (pluginUidPtr)
|
|
|
|
{
|
|
|
|
int pluginUid = *pluginUidPtr;
|
|
|
|
plugin = m_data->m_plugins.getHandle(pluginUid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-25 12:47:34 +00:00
|
|
|
if (plugin->m_processNotificationsFunc) {
|
2018-07-24 12:12:16 +00:00
|
|
|
b3PluginContext context = {0};
|
|
|
|
context.m_userPointer = plugin->m_userPointer;
|
|
|
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
|
|
|
context.m_numNotifications = notifications.size();
|
|
|
|
context.m_notifications = notifications.size() ? ¬ifications[0] : 0;
|
2018-07-25 12:47:34 +00:00
|
|
|
plugin->m_processNotificationsFunc(&context);
|
2018-07-24 12:12:16 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-04 16:58:15 +00:00
|
|
|
notifications.resize(0);
|
2018-07-24 12:12:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-24 01:05:23 +00:00
|
|
|
int b3PluginManager::executePluginCommand(int pluginUniqueId, const b3PluginArguments* arguments)
|
2017-09-23 02:17:57 +00:00
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
|
|
|
|
b3PluginHandle* plugin = m_data->m_plugins.getHandle(pluginUniqueId);
|
|
|
|
if (plugin)
|
|
|
|
{
|
2018-07-24 12:12:16 +00:00
|
|
|
b3PluginContext context = {0};
|
2017-09-24 01:05:23 +00:00
|
|
|
context.m_userPointer = plugin->m_userPointer;
|
2017-09-23 16:25:00 +00:00
|
|
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
2018-09-06 00:58:14 +00:00
|
|
|
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
2017-09-24 01:05:23 +00:00
|
|
|
result = plugin->m_executeCommandFunc(&context, arguments);
|
|
|
|
plugin->m_userPointer = context.m_userPointer;
|
2017-09-23 02:17:57 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2017-09-24 01:05:23 +00:00
|
|
|
|
|
|
|
|
2018-09-10 04:08:47 +00:00
|
|
|
int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT initFunc,PFN_EXIT exitFunc, PFN_EXECUTE executeCommandFunc, PFN_TICK preTickFunc, PFN_TICK postTickFunc, PFN_GET_RENDER_INTERFACE getRendererFunc, PFN_TICK processClientCommandsFunc, bool initPlugin)
|
2017-09-24 01:05:23 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
b3Plugin orgPlugin;
|
|
|
|
|
|
|
|
int pluginUniqueId = m_data->m_plugins.allocHandle();
|
|
|
|
b3PluginHandle* pluginHandle = m_data->m_plugins.getHandle(pluginUniqueId);
|
|
|
|
pluginHandle->m_pluginHandle = 0;
|
|
|
|
pluginHandle->m_ownsPluginHandle =false;
|
|
|
|
pluginHandle->m_pluginUniqueId = pluginUniqueId;
|
|
|
|
pluginHandle->m_executeCommandFunc = executeCommandFunc;
|
|
|
|
pluginHandle->m_exitFunc = exitFunc;
|
|
|
|
pluginHandle->m_initFunc = initFunc;
|
|
|
|
pluginHandle->m_preTickFunc = preTickFunc;
|
|
|
|
pluginHandle->m_postTickFunc = postTickFunc;
|
2018-01-17 20:48:48 +00:00
|
|
|
pluginHandle->m_getRendererFunc = getRendererFunc;
|
2018-09-06 00:58:14 +00:00
|
|
|
pluginHandle->m_processClientCommandsFunc = processClientCommandsFunc;
|
2017-09-24 01:05:23 +00:00
|
|
|
pluginHandle->m_pluginHandle = 0;
|
|
|
|
pluginHandle->m_pluginPath = pluginPath;
|
|
|
|
pluginHandle->m_userPointer = 0;
|
|
|
|
|
2018-01-17 20:48:48 +00:00
|
|
|
|
2018-09-05 02:24:31 +00:00
|
|
|
if (pluginHandle->m_processNotificationsFunc)
|
|
|
|
{
|
|
|
|
m_data->m_numNotificationPlugins++;
|
|
|
|
}
|
|
|
|
|
2018-02-06 16:56:24 +00:00
|
|
|
m_data->m_pluginMap.insert(pluginPath, pluginUniqueId);
|
2017-09-24 01:05:23 +00:00
|
|
|
|
2018-09-10 04:08:47 +00:00
|
|
|
if (initPlugin)
|
2017-09-24 01:05:23 +00:00
|
|
|
{
|
2018-07-24 12:12:16 +00:00
|
|
|
b3PluginContext context = {0};
|
2017-09-24 01:05:23 +00:00
|
|
|
context.m_userPointer = 0;
|
|
|
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
2018-09-06 00:58:14 +00:00
|
|
|
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
2017-09-24 01:05:23 +00:00
|
|
|
int result = pluginHandle->m_initFunc(&context);
|
2018-09-10 04:08:47 +00:00
|
|
|
pluginHandle->m_isInitialized = true;
|
2017-09-24 01:05:23 +00:00
|
|
|
pluginHandle->m_userPointer = context.m_userPointer;
|
|
|
|
}
|
|
|
|
return pluginUniqueId;
|
|
|
|
}
|
2018-01-17 20:48:48 +00:00
|
|
|
|
|
|
|
void b3PluginManager::selectPluginRenderer(int pluginUniqueId)
|
|
|
|
{
|
|
|
|
m_data->m_activeRendererPluginUid = pluginUniqueId;
|
|
|
|
}
|
|
|
|
|
|
|
|
UrdfRenderingInterface* b3PluginManager::getRenderInterface()
|
|
|
|
{
|
|
|
|
UrdfRenderingInterface* renderer = 0;
|
|
|
|
|
|
|
|
if (m_data->m_activeRendererPluginUid>=0)
|
|
|
|
{
|
|
|
|
b3PluginHandle* plugin = m_data->m_plugins.getHandle(m_data->m_activeRendererPluginUid);
|
|
|
|
if (plugin)
|
|
|
|
{
|
2018-07-24 12:12:16 +00:00
|
|
|
b3PluginContext context = {0};
|
2018-01-17 20:48:48 +00:00
|
|
|
context.m_userPointer = plugin->m_userPointer;
|
|
|
|
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
|
|
|
|
|
|
|
renderer = plugin->m_getRendererFunc(&context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|