mirror of
https://github.com/bulletphysics/bullet3.git
synced 2026-07-19 12:39:46 +00:00
Embed graphics server (shared memory) in PyBullet. Use pybullet.connect(pybullet.GRAPHICS_SERVER) to enable it.
TODO: enable for Mac OSX on mainloop, add tcp bridges from and to shared memory.
This commit is contained in:
@@ -96,6 +96,8 @@ B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMain
|
||||
return (b3PhysicsClientHandle)cl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class InProcessPhysicsClientSharedMemory : public PhysicsClientSharedMemory
|
||||
{
|
||||
btInProcessExampleBrowserInternalData* m_data;
|
||||
@@ -127,6 +129,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnect(int argc, char* argv[])
|
||||
{
|
||||
InProcessPhysicsClientSharedMemory* cl = new InProcessPhysicsClientSharedMemory(argc, argv, 1);
|
||||
@@ -306,4 +310,110 @@ B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingEx
|
||||
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect2(void* guiHelperPtr)
|
||||
{
|
||||
return b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect3(guiHelperPtr, SHARED_MEMORY_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "SharedMemoryCommands.h"
|
||||
#include "PhysicsClientSharedMemory.h"
|
||||
#include "GraphicsSharedMemoryBlock.h"
|
||||
#include "PosixSharedMemory.h"
|
||||
#include "Win32SharedMemory.h"
|
||||
class InProcessGraphicsServerSharedMemory : public PhysicsClientSharedMemory
|
||||
{
|
||||
btInProcessExampleBrowserInternalData* m_data2;
|
||||
char** m_newargv;
|
||||
SharedMemoryCommand m_command;
|
||||
|
||||
GraphicsSharedMemoryBlock* m_testBlock1;
|
||||
SharedMemoryInterface* m_sharedMemory;
|
||||
|
||||
public:
|
||||
InProcessGraphicsServerSharedMemory(int argc, char* argv[], bool useInProcessMemory)
|
||||
{
|
||||
int newargc = argc + 2;
|
||||
m_newargv = (char**)malloc(sizeof(void*) * newargc);
|
||||
char* t0 = (char*)"--unused";
|
||||
m_newargv[0] = t0;
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
m_newargv[i + 1] = argv[i];
|
||||
|
||||
char* t1 = (char*)"--start_demo_name=Graphics Server";
|
||||
m_newargv[argc + 1] = t1;
|
||||
m_data2 = btCreateInProcessExampleBrowser(newargc, m_newargv, useInProcessMemory);
|
||||
SharedMemoryInterface* shMem = btGetSharedMemoryInterface(m_data2);
|
||||
|
||||
setSharedMemoryInterface(shMem);
|
||||
///////////////////
|
||||
|
||||
#ifdef _WIN32
|
||||
m_sharedMemory = new Win32SharedMemoryServer();
|
||||
#else
|
||||
m_sharedMemory = new PosixSharedMemory();
|
||||
#endif
|
||||
|
||||
/// server always has to create and initialize shared memory
|
||||
bool allowCreation = false;
|
||||
m_testBlock1 = (GraphicsSharedMemoryBlock*)m_sharedMemory->allocateSharedMemory(
|
||||
GRAPHICS_SHARED_MEMORY_KEY, GRAPHICS_SHARED_MEMORY_SIZE, allowCreation);
|
||||
|
||||
}
|
||||
|
||||
virtual ~InProcessGraphicsServerSharedMemory()
|
||||
{
|
||||
m_sharedMemory->releaseSharedMemory(GRAPHICS_SHARED_MEMORY_KEY, GRAPHICS_SHARED_MEMORY_SIZE);
|
||||
delete m_sharedMemory;
|
||||
|
||||
setSharedMemoryInterface(0);
|
||||
btShutDownExampleBrowser(m_data2);
|
||||
free(m_newargv);
|
||||
}
|
||||
virtual bool canSubmitCommand() const
|
||||
{
|
||||
if (m_testBlock1)
|
||||
{
|
||||
if (m_testBlock1->m_magicId != GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual struct SharedMemoryCommand* getAvailableSharedMemoryCommand()
|
||||
{
|
||||
return &m_command;
|
||||
}
|
||||
|
||||
virtual bool submitClientCommand(const struct SharedMemoryCommand& command)
|
||||
{
|
||||
switch (command.m_type)
|
||||
{
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessGraphicsServerAndConnectSharedMemory(int argc, char* argv[])
|
||||
{
|
||||
InProcessGraphicsServerSharedMemory* cl = new InProcessGraphicsServerSharedMemory(argc, argv, 0);
|
||||
cl->setSharedMemoryKey(SHARED_MEMORY_KEY + 1);
|
||||
cl->connect();
|
||||
return (b3PhysicsClientHandle)cl;
|
||||
}
|
||||
#if 0
|
||||
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessGraphicsServerAndConnectMainThreadSharedMemory(int argc, char* argv[]);
|
||||
{
|
||||
InProcessGraphicsServerSharedMemory* cl = new InProcessGraphicsServerSharedMemory(argc, argv, 0);
|
||||
cl->setSharedMemoryKey(SHARED_MEMORY_KEY + 1);
|
||||
cl->connect();
|
||||
return (b3PhysicsClientHandle)cl;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user