expose PyBullet.SHARED_MEMORY_SERVER

connect from 1 different PyBullet client using PyBullet.SHARED_MEMORY)
(don't use more than 1 other client to submit commands in parallel)
This commit is contained in:
Erwin Coumans
2018-05-07 15:57:36 -07:00
parent ab4b663800
commit 7383843b24
6 changed files with 120 additions and 21 deletions

View File

@@ -708,7 +708,8 @@ public:
int m_primitiveType;
int m_textureId;
int m_instanceId;
bool m_skipGraphicsUpdate;
void mainThreadRelease()
{
BT_PROFILE("mainThreadRelease");
@@ -725,7 +726,14 @@ public:
void workerThreadWait()
{
BT_PROFILE("workerThreadWait");
BT_PROFILE("workerThreadWait");
if (m_skipGraphicsUpdate)
{
getCriticalSection()->setSharedParam(1,eGUIHelperIdle);
m_cs->unlock();
return;
}
m_cs2->lock();
m_cs->unlock();
m_cs2->unlock();
@@ -740,7 +748,7 @@ public:
}
}
MultiThreadedOpenGLGuiHelper(CommonGraphicsApp* app, GUIHelperInterface* guiHelper)
MultiThreadedOpenGLGuiHelper(CommonGraphicsApp* app, GUIHelperInterface* guiHelper, int skipGraphicsUpdate)
:
//m_app(app),
m_cs(0),
@@ -750,7 +758,10 @@ public:
m_debugDraw(0),
m_uidGenerator(0),
m_texels(0),
m_textureId(-1)
m_shapeIndex(-1),
m_textureId(-1),
m_instanceId(-1),
m_skipGraphicsUpdate(skipGraphicsUpdate)
{
m_childGuiHelper = guiHelper;
@@ -971,6 +982,7 @@ public:
m_getShapeIndex_instance = instance;
m_cs->lock();
m_cs->setSharedParam(1,eGUIHelperGetShapeIndexFromInstance);
getShapeIndex_shapeIndex=-1;
workerThreadWait();
return getShapeIndex_shapeIndex;
}
@@ -1205,6 +1217,7 @@ public:
m_cs->lock();
m_cs->setSharedParam(1, eGUIUserDebugAddText);
m_resultUserDebugTextUid=-1;
workerThreadWait();
return m_resultUserDebugTextUid;
@@ -1237,6 +1250,7 @@ public:
m_cs->lock();
m_cs->setSharedParam(1, eGUIUserDebugAddParameter);
m_userDebugParamUid=-1;
workerThreadWait();
return m_userDebugParamUid;
@@ -1265,6 +1279,7 @@ public:
m_tmpLine.m_trackingVisualShapeIndex = trackingVisualShapeIndex;
m_cs->lock();
m_cs->setSharedParam(1, eGUIUserDebugAddLine);
m_resultDebugLineUid=-1;
workerThreadWait();
return m_resultDebugLineUid;
}
@@ -1729,9 +1744,6 @@ void PhysicsServerExample::initPhysics()
m_guiHelper->setUpAxis(upAxis);
m_threadSupport = createMotionThreadSupport(MAX_MOTION_NUM_THREADS);
@@ -3226,7 +3238,7 @@ extern int gSharedMemoryKey;
class CommonExampleInterface* PhysicsServerCreateFuncInternal(struct CommonExampleOptions& options)
{
MultiThreadedOpenGLGuiHelper* guiHelperWrapper = new MultiThreadedOpenGLGuiHelper(options.m_guiHelper->getAppInterface(),options.m_guiHelper);
MultiThreadedOpenGLGuiHelper* guiHelperWrapper = new MultiThreadedOpenGLGuiHelper(options.m_guiHelper->getAppInterface(),options.m_guiHelper, options.m_skipGraphicsUpdate);
PhysicsServerExample* example = new PhysicsServerExample(guiHelperWrapper,

View File

@@ -7,7 +7,7 @@
#include <stdio.h>
#include <string.h>
#include "PhysicsServerExampleBullet2.h"
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
#include "../CommonInterfaces/CommonExampleInterface.h"
#include "InProcessMemory.h"
@@ -158,15 +158,19 @@ class InProcessPhysicsClientExistingExampleBrowser : public PhysicsClientSharedM
b3Clock m_clock;
unsigned long long int m_prevTime;
public:
InProcessPhysicsClientExistingExampleBrowser (struct GUIHelperInterface* guiHelper)
InProcessPhysicsClientExistingExampleBrowser (struct GUIHelperInterface* guiHelper, bool useInProcessMemory, bool skipGraphicsUpdate)
{
m_sharedMem = new InProcessMemory;
m_sharedMem=0;
CommonExampleOptions options(guiHelper);
options.m_sharedMem = m_sharedMem;
m_physicsServerExample = PhysicsServerCreateFuncBullet2(options);
if (useInProcessMemory)
{
m_sharedMem = new InProcessMemory;
options.m_sharedMem = m_sharedMem;
}
options.m_skipGraphicsUpdate = skipGraphicsUpdate;
m_physicsServerExample = PhysicsServerCreateFuncBullet2(options);
m_physicsServerExample ->initPhysics();
m_physicsServerExample ->resetCamera();
setSharedMemoryInterface(m_sharedMem);
@@ -251,9 +255,36 @@ int b3InProcessMouseButtonCallback(b3PhysicsClientHandle clientHandle, int butto
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(void* guiHelperPtr)
{
static DummyGUIHelper noGfx;
GUIHelperInterface* guiHelper = (GUIHelperInterface*) guiHelperPtr;
InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper);
//InProcessPhysicsClientFromGuiHelper* cl = new InProcessPhysicsClientFromGuiHelper(guiHelper);
if (!guiHelper)
{
guiHelper = &noGfx;
}
bool useInprocessMemory = true;
bool skipGraphicsUpdate = false;
InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper,useInprocessMemory,skipGraphicsUpdate);
cl->connect();
return (b3PhysicsClientHandle ) cl;
}
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect2(void* guiHelperPtr)
{
static DummyGUIHelper noGfx;
GUIHelperInterface* guiHelper = (GUIHelperInterface*) guiHelperPtr;
if (!guiHelper)
{
guiHelper = &noGfx;
}
bool useInprocessMemory = false;
bool skipGraphicsUpdate = true;
InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper, useInprocessMemory, skipGraphicsUpdate);
cl->connect();
return (b3PhysicsClientHandle ) cl;
}

View File

@@ -16,7 +16,9 @@ B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectShar
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThread(int argc, char* argv[]);
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThreadSharedMemory(int argc, char* argv[]);
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(void* guiHelperPtr);
//B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(void* guiHelperPtr);
//create a shared memory physics server, with a DummyGUIHelper (no graphics)
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect2(void* guiHelperPtr);
///ignore the following APIs, they are for internal use for example browser
void b3InProcessRenderSceneInternal(b3PhysicsClientHandle clientHandle);

View File

@@ -668,6 +668,7 @@ enum eCONNECT_METHOD {
eCONNECT_EXISTING_EXAMPLE_BROWSER=6,
eCONNECT_GUI_SERVER=7,
eCONNECT_GUI_MAIN_THREAD=8,
eCONNECT_SHARED_MEMORY_SERVER=9,
};
enum eURDF_Flags