Create a PhysicsLoopBack that includes both PhysicsClient and PhysicsServer over shared memory.
Add a test for PhysicsLoopBack.
This commit is contained in:
@@ -398,6 +398,7 @@ b3PhysicsClientHandle b3ConnectSharedMemory(int key)
|
||||
return (b3PhysicsClientHandle ) cl;
|
||||
}
|
||||
|
||||
|
||||
void b3DisconnectSharedMemory(b3PhysicsClientHandle physClient)
|
||||
{
|
||||
PhysicsClient* cl = (PhysicsClient* ) physClient;
|
||||
@@ -452,7 +453,11 @@ int b3GetStatusBodyIndex(b3SharedMemoryStatusHandle statusHandle)
|
||||
int b3CanSubmitCommand(b3PhysicsClientHandle physClient)
|
||||
{
|
||||
PhysicsClient* cl = (PhysicsClient* ) physClient;
|
||||
return (int)cl->canSubmitCommand();
|
||||
if (cl)
|
||||
{
|
||||
return (int)cl->canSubmitCommand();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int b3SubmitClientCommand(b3PhysicsClientHandle physClient, const b3SharedMemoryCommandHandle commandHandle)
|
||||
|
||||
@@ -15,7 +15,7 @@ B3_DECLARE_HANDLE(b3SharedMemoryStatusHandle);
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
///make sure to start the server first, before connecting client to physics server
|
||||
///make sure to start the server first, before connecting client to a physics server over shared memory or UDP
|
||||
b3PhysicsClientHandle b3ConnectSharedMemory(int key);
|
||||
|
||||
void b3DisconnectSharedMemory(b3PhysicsClientHandle physClient);
|
||||
|
||||
115
examples/SharedMemory/PhysicsLoopBack.cpp
Normal file
115
examples/SharedMemory/PhysicsLoopBack.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
#include "PhysicsLoopBack.h"
|
||||
#include "PhysicsServer.h"
|
||||
#include "PhysicsClientSharedMemory.h"
|
||||
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||
|
||||
struct PhysicsLoopBackInternalData
|
||||
{
|
||||
PhysicsClientSharedMemory* m_physicsClient;
|
||||
PhysicsServerSharedMemory* m_physicsServer;
|
||||
DummyGUIHelper m_noGfx;
|
||||
|
||||
|
||||
PhysicsLoopBackInternalData()
|
||||
:m_physicsClient(0),
|
||||
m_physicsServer(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
PhysicsLoopBack::PhysicsLoopBack()
|
||||
{
|
||||
m_data = new PhysicsLoopBackInternalData;
|
||||
m_data->m_physicsServer = new PhysicsServerSharedMemory();
|
||||
m_data->m_physicsClient = new PhysicsClientSharedMemory();
|
||||
}
|
||||
|
||||
PhysicsLoopBack::~PhysicsLoopBack()
|
||||
{
|
||||
delete m_data->m_physicsClient;
|
||||
delete m_data->m_physicsServer;
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
|
||||
// return true if connection succesfull, can also check 'isConnected'
|
||||
bool PhysicsLoopBack::connect()
|
||||
{
|
||||
m_data->m_physicsServer->connectSharedMemory(&m_data->m_noGfx);
|
||||
m_data->m_physicsClient->connect();
|
||||
return m_data->m_physicsClient->isConnected();
|
||||
}
|
||||
|
||||
////todo: rename to 'disconnect'
|
||||
void PhysicsLoopBack::disconnectSharedMemory()
|
||||
{
|
||||
m_data->m_physicsClient->disconnectSharedMemory();
|
||||
m_data->m_physicsServer->disconnectSharedMemory(true);
|
||||
}
|
||||
|
||||
bool PhysicsLoopBack::isConnected() const
|
||||
{
|
||||
return m_data->m_physicsClient->isConnected();
|
||||
}
|
||||
|
||||
// return non-null if there is a status, nullptr otherwise
|
||||
const SharedMemoryStatus* PhysicsLoopBack::processServerStatus()
|
||||
{
|
||||
m_data->m_physicsServer->processClientCommands();
|
||||
return m_data->m_physicsClient->processServerStatus();
|
||||
}
|
||||
|
||||
SharedMemoryCommand* PhysicsLoopBack::getAvailableSharedMemoryCommand()
|
||||
{
|
||||
return m_data->m_physicsClient->getAvailableSharedMemoryCommand();
|
||||
}
|
||||
|
||||
bool PhysicsLoopBack::canSubmitCommand() const
|
||||
{
|
||||
return m_data->m_physicsClient->canSubmitCommand();
|
||||
}
|
||||
|
||||
bool PhysicsLoopBack::submitClientCommand(const struct SharedMemoryCommand& command)
|
||||
{
|
||||
return m_data->m_physicsClient->submitClientCommand(command);
|
||||
}
|
||||
|
||||
int PhysicsLoopBack::getNumJoints(int bodyIndex) const
|
||||
{
|
||||
return m_data->m_physicsClient->getNumJoints(bodyIndex);
|
||||
}
|
||||
|
||||
void PhysicsLoopBack::getJointInfo(int bodyIndex, int jointIndex, struct b3JointInfo& info) const
|
||||
{
|
||||
m_data->m_physicsClient->getJointInfo(bodyIndex,jointIndex,info);
|
||||
}
|
||||
|
||||
///todo: move this out of the
|
||||
void PhysicsLoopBack::setSharedMemoryKey(int key)
|
||||
{
|
||||
m_data->m_physicsServer->setSharedMemoryKey(key);
|
||||
m_data->m_physicsClient->setSharedMemoryKey(key);
|
||||
}
|
||||
|
||||
void PhysicsLoopBack::uploadBulletFileToSharedMemory(const char* data, int len)
|
||||
{
|
||||
m_data->m_physicsClient->uploadBulletFileToSharedMemory(data,len);
|
||||
}
|
||||
|
||||
int PhysicsLoopBack::getNumDebugLines() const
|
||||
{
|
||||
return m_data->m_physicsClient->getNumDebugLines();
|
||||
}
|
||||
|
||||
const float* PhysicsLoopBack::getDebugLinesFrom() const
|
||||
{
|
||||
return m_data->m_physicsClient->getDebugLinesFrom();
|
||||
}
|
||||
const float* PhysicsLoopBack::getDebugLinesTo() const
|
||||
{
|
||||
return m_data->m_physicsClient->getDebugLinesTo();
|
||||
}
|
||||
const float* PhysicsLoopBack::getDebugLinesColor() const
|
||||
{
|
||||
return m_data->m_physicsClient->getDebugLinesColor();
|
||||
}
|
||||
58
examples/SharedMemory/PhysicsLoopBack.h
Normal file
58
examples/SharedMemory/PhysicsLoopBack.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef PHYSICS_LOOP_BACK_H
|
||||
#define PHYSICS_LOOP_BACK_H
|
||||
|
||||
//#include "SharedMemoryCommands.h"
|
||||
|
||||
|
||||
#include "PhysicsClient.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
///todo: the PhysicsClient API was designed with shared memory in mind,
|
||||
///now it become more general we need to move out the shared memory specifics away
|
||||
///for example naming [disconnectSharedMemory -> disconnect] [ move setSharedMemoryKey to shared memory specific subclass ]
|
||||
|
||||
class PhysicsLoopBack : public PhysicsClient
|
||||
{
|
||||
struct PhysicsLoopBackInternalData* m_data;
|
||||
|
||||
public:
|
||||
|
||||
PhysicsLoopBack();
|
||||
|
||||
virtual ~PhysicsLoopBack();
|
||||
|
||||
// return true if connection succesfull, can also check 'isConnected'
|
||||
virtual bool connect();
|
||||
|
||||
////todo: rename to 'disconnect'
|
||||
virtual void disconnectSharedMemory();
|
||||
|
||||
virtual bool isConnected() const;
|
||||
|
||||
// return non-null if there is a status, nullptr otherwise
|
||||
virtual const SharedMemoryStatus* processServerStatus();
|
||||
|
||||
virtual SharedMemoryCommand* getAvailableSharedMemoryCommand();
|
||||
|
||||
virtual bool canSubmitCommand() const;
|
||||
|
||||
virtual bool submitClientCommand(const struct SharedMemoryCommand& command);
|
||||
|
||||
virtual int getNumJoints(int bodyIndex) const;
|
||||
|
||||
virtual void getJointInfo(int bodyIndex, int jointIndex, struct b3JointInfo& info) const;
|
||||
|
||||
///todo: move this out of the
|
||||
virtual void setSharedMemoryKey(int key);
|
||||
|
||||
void uploadBulletFileToSharedMemory(const char* data, int len);
|
||||
|
||||
virtual int getNumDebugLines() const;
|
||||
|
||||
virtual const float* getDebugLinesFrom() const;
|
||||
virtual const float* getDebugLinesTo() const;
|
||||
virtual const float* getDebugLinesColor() const;
|
||||
|
||||
};
|
||||
|
||||
#endif //PHYSICS_LOOP_BACK_H
|
||||
19
examples/SharedMemory/PhysicsLoopBackC_API.h
Normal file
19
examples/SharedMemory/PhysicsLoopBackC_API.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef PHYSICS_LOOPBACK_C_API_H
|
||||
#define PHYSICS_LOOPBACK_C_API_H
|
||||
|
||||
#include "PhysicsClientC_API.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
///think more about naming. The b3ConnectPhysicsLoopback
|
||||
b3PhysicsClientHandle b3ConnectPhysicsLoopback(int key);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //PHYSICS_LOOPBACK_C_API_H
|
||||
15
examples/SharedMemory/PhysicsLoopBackC_Api.cpp
Normal file
15
examples/SharedMemory/PhysicsLoopBackC_Api.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "PhysicsLoopBackC_API.h"
|
||||
|
||||
#include "PhysicsLoopBack.h"
|
||||
|
||||
|
||||
|
||||
//think more about naming. The b3ConnectPhysicsLoopback
|
||||
b3PhysicsClientHandle b3ConnectPhysicsLoopback(int key)
|
||||
{
|
||||
PhysicsLoopBack* loopBack = new PhysicsLoopBack();
|
||||
loopBack->setSharedMemoryKey(key);
|
||||
bool connected = loopBack->connect();
|
||||
return (b3PhysicsClientHandle )loopBack;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user