allow pybullet to connect to GRPC server. (need to use flag --enable_grpc in premake build system)
add grpcPlugin, it can work in GUI, SHARED_MEMORY_SERVER, DIRECT and other modes.
example script to start server from pybullet:
import pybullet as p
p.connect(p.GUI)
#if statically linked plugin
id = p.loadPlugin("grpcPlugin")
#dynamics loading the plugin
#id = p.loadPlugin("E:/develop/bullet3/bin/pybullet_grpcPlugin_vs2010_x64_debug.dll", postFix="_grpcPlugin")
#start the GRPC server at hostname, port
if (id>=0):
p.executePluginCommand(id, "localhost:1234")
Only in DIRECT mode, since there is no 'ping' you need to call to handle RCPs:
numRPC = 10
while (1):
p.executePluginCommand(id, intArgs=[numRPC])
This commit is contained in:
@@ -43,6 +43,7 @@ struct b3Plugin
|
||||
PFN_TICK m_preTickFunc;
|
||||
PFN_TICK m_postTickFunc;
|
||||
PFN_TICK m_processNotificationsFunc;
|
||||
PFN_TICK m_processClientCommandsFunc;
|
||||
|
||||
PFN_GET_RENDER_INTERFACE m_getRendererFunc;
|
||||
|
||||
@@ -58,6 +59,7 @@ struct b3Plugin
|
||||
m_preTickFunc(0),
|
||||
m_postTickFunc(0),
|
||||
m_processNotificationsFunc(0),
|
||||
m_processClientCommandsFunc(0),
|
||||
m_getRendererFunc(0),
|
||||
m_userPointer(0)
|
||||
{
|
||||
@@ -74,8 +76,10 @@ struct b3Plugin
|
||||
m_executeCommandFunc = 0;
|
||||
m_preTickFunc = 0;
|
||||
m_postTickFunc = 0;
|
||||
m_userPointer = 0;
|
||||
m_processNotificationsFunc = 0;
|
||||
m_processClientCommandsFunc = 0;
|
||||
m_getRendererFunc = 0;
|
||||
m_userPointer = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -86,6 +90,7 @@ struct b3PluginManagerInternalData
|
||||
b3ResizablePool<b3PluginHandle> m_plugins;
|
||||
b3HashMap<b3HashString, int> m_pluginMap;
|
||||
PhysicsDirect* m_physicsDirect;
|
||||
PhysicsCommandProcessorInterface* m_rpcCommandProcessorInterface;
|
||||
b3AlignedObjectArray<b3KeyboardEvent> m_keyEvents;
|
||||
b3AlignedObjectArray<b3VRControllerEvent> m_vrEvents;
|
||||
b3AlignedObjectArray<b3MouseEvent> m_mouseEvents;
|
||||
@@ -95,7 +100,7 @@ struct b3PluginManagerInternalData
|
||||
int m_numNotificationPlugins;
|
||||
|
||||
b3PluginManagerInternalData()
|
||||
:m_activeNotificationsBufferIndex(0), m_activeRendererPluginUid(-1),
|
||||
:m_rpcCommandProcessorInterface(0), m_activeNotificationsBufferIndex(0), m_activeRendererPluginUid(-1),
|
||||
m_numNotificationPlugins(0)
|
||||
{
|
||||
}
|
||||
@@ -104,6 +109,7 @@ struct b3PluginManagerInternalData
|
||||
b3PluginManager::b3PluginManager(class PhysicsCommandProcessorInterface* physSdk)
|
||||
{
|
||||
m_data = new b3PluginManagerInternalData;
|
||||
m_data->m_rpcCommandProcessorInterface = physSdk;
|
||||
m_data->m_physicsDirect = new PhysicsDirect(physSdk,false);
|
||||
|
||||
}
|
||||
@@ -184,6 +190,7 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
|
||||
std::string preTickPluginCallbackStr = std::string("preTickPluginCallback") + postFix;
|
||||
std::string postTickPluginCallback = std::string("postTickPluginCallback") + postFix;
|
||||
std::string processNotificationsStr = std::string("processNotifications") + postFix;
|
||||
std::string processClientCommandsStr = std::string("processClientCommands") + postFix;
|
||||
std::string getRendererStr = std::string("getRenderInterface") + postFix;
|
||||
|
||||
plugin->m_initFunc = (PFN_INIT)B3_DYNLIB_IMPORT(pluginHandle, initStr.c_str());
|
||||
@@ -192,11 +199,13 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
|
||||
plugin->m_preTickFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, preTickPluginCallbackStr.c_str());
|
||||
plugin->m_postTickFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, postTickPluginCallback.c_str());
|
||||
plugin->m_processNotificationsFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, processNotificationsStr.c_str());
|
||||
|
||||
if (plugin->m_processNotificationsFunc)
|
||||
{
|
||||
m_data->m_numNotificationPlugins++;
|
||||
}
|
||||
|
||||
plugin->m_processClientCommandsFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, processClientCommandsStr.c_str());
|
||||
|
||||
plugin->m_getRendererFunc = (PFN_GET_RENDER_INTERFACE)B3_DYNLIB_IMPORT(pluginHandle, getRendererStr.c_str());
|
||||
|
||||
|
||||
@@ -206,6 +215,7 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr)
|
||||
b3PluginContext context;
|
||||
context.m_userPointer = plugin->m_userPointer;
|
||||
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
||||
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
||||
int version = plugin->m_initFunc(&context);
|
||||
//keep the user pointer persistent
|
||||
plugin->m_userPointer = context.m_userPointer;
|
||||
@@ -275,8 +285,10 @@ void b3PluginManager::unloadPlugin(int pluginUniqueId)
|
||||
m_data->m_plugins.freeHandle(pluginUniqueId);
|
||||
}
|
||||
}
|
||||
|
||||
void b3PluginManager::tickPlugins(double timeStep, bool isPreTick)
|
||||
|
||||
|
||||
|
||||
void b3PluginManager::tickPlugins(double timeStep, b3PluginManagerTickMode tickMode)
|
||||
{
|
||||
for (int i=0;i<m_data->m_pluginMap.size();i++)
|
||||
{
|
||||
@@ -293,18 +305,44 @@ void b3PluginManager::tickPlugins(double timeStep, bool isPreTick)
|
||||
continue;
|
||||
}
|
||||
|
||||
PFN_TICK tick = isPreTick? plugin->m_preTickFunc : plugin->m_postTickFunc;
|
||||
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:
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (tick)
|
||||
{
|
||||
b3PluginContext context = {0};
|
||||
b3PluginContext context = { 0 };
|
||||
context.m_userPointer = plugin->m_userPointer;
|
||||
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
||||
context.m_physClient = (b3PhysicsClientHandle)m_data->m_physicsDirect;
|
||||
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();
|
||||
context.m_vrControllerEvents = m_data->m_vrEvents.size()? &m_data->m_vrEvents[0]:0;
|
||||
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;
|
||||
}
|
||||
int result = tick(&context);
|
||||
plugin->m_userPointer = context.m_userPointer;
|
||||
}
|
||||
@@ -359,7 +397,7 @@ int b3PluginManager::executePluginCommand(int pluginUniqueId, const b3PluginArgu
|
||||
b3PluginContext context = {0};
|
||||
context.m_userPointer = plugin->m_userPointer;
|
||||
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
||||
|
||||
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
||||
result = plugin->m_executeCommandFunc(&context, arguments);
|
||||
plugin->m_userPointer = context.m_userPointer;
|
||||
}
|
||||
@@ -367,7 +405,7 @@ int b3PluginManager::executePluginCommand(int pluginUniqueId, const b3PluginArgu
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
|
||||
b3Plugin orgPlugin;
|
||||
@@ -383,6 +421,7 @@ int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT
|
||||
pluginHandle->m_preTickFunc = preTickFunc;
|
||||
pluginHandle->m_postTickFunc = postTickFunc;
|
||||
pluginHandle->m_getRendererFunc = getRendererFunc;
|
||||
pluginHandle->m_processClientCommandsFunc = processClientCommandsFunc;
|
||||
pluginHandle->m_pluginHandle = 0;
|
||||
pluginHandle->m_pluginPath = pluginPath;
|
||||
pluginHandle->m_userPointer = 0;
|
||||
@@ -399,7 +438,7 @@ int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT
|
||||
b3PluginContext context = {0};
|
||||
context.m_userPointer = 0;
|
||||
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
|
||||
|
||||
context.m_rpcCommandProcessorInterface = m_data->m_rpcCommandProcessorInterface;
|
||||
int result = pluginHandle->m_initFunc(&context);
|
||||
pluginHandle->m_userPointer = context.m_userPointer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user