2015-10-27 00:56:21 +00:00
|
|
|
#include "PhysicsLoopBack.h"
|
2015-11-23 04:50:32 +00:00
|
|
|
#include "PhysicsServerSharedMemory.h"
|
2015-10-27 00:56:21 +00:00
|
|
|
#include "PhysicsClientSharedMemory.h"
|
|
|
|
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
2017-05-31 02:54:55 +00:00
|
|
|
#include "PhysicsServerCommandProcessor.h"
|
|
|
|
#include "../CommonInterfaces/CommonExampleInterface.h"
|
2015-10-27 00:56:21 +00:00
|
|
|
struct PhysicsLoopBackInternalData
|
|
|
|
{
|
2017-05-31 02:54:55 +00:00
|
|
|
CommandProcessorInterface* m_commandProcessor;
|
2015-10-27 00:56:21 +00:00
|
|
|
PhysicsClientSharedMemory* m_physicsClient;
|
|
|
|
PhysicsServerSharedMemory* m_physicsServer;
|
|
|
|
DummyGUIHelper m_noGfx;
|
|
|
|
|
|
|
|
|
|
|
|
PhysicsLoopBackInternalData()
|
2017-05-31 02:54:55 +00:00
|
|
|
:m_commandProcessor(0),
|
|
|
|
m_physicsClient(0),
|
2015-10-27 00:56:21 +00:00
|
|
|
m_physicsServer(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-31 02:54:55 +00:00
|
|
|
struct Bullet2CommandProcessorCreation2 : public CommandProcessorCreationInterface
|
|
|
|
{
|
|
|
|
virtual class CommandProcessorInterface* createCommandProcessor()
|
|
|
|
{
|
|
|
|
PhysicsServerCommandProcessor* proc = new PhysicsServerCommandProcessor;
|
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void deleteCommandProcessor(CommandProcessorInterface* proc)
|
|
|
|
{
|
|
|
|
delete proc;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static Bullet2CommandProcessorCreation2 sB2Proc;
|
|
|
|
|
2015-10-27 00:56:21 +00:00
|
|
|
PhysicsLoopBack::PhysicsLoopBack()
|
|
|
|
{
|
|
|
|
m_data = new PhysicsLoopBackInternalData;
|
2017-05-31 02:54:55 +00:00
|
|
|
m_data->m_physicsServer = new PhysicsServerSharedMemory(&sB2Proc, 0,0);
|
2015-10-27 00:56:21 +00:00
|
|
|
m_data->m_physicsClient = new PhysicsClientSharedMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsLoopBack::~PhysicsLoopBack()
|
|
|
|
{
|
|
|
|
delete m_data->m_physicsClient;
|
|
|
|
delete m_data->m_physicsServer;
|
2017-05-31 02:54:55 +00:00
|
|
|
delete m_data->m_commandProcessor;
|
2015-10-27 00:56:21 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-09-27 19:13:45 +00:00
|
|
|
int PhysicsLoopBack::getNumBodies() const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getNumBodies();
|
|
|
|
}
|
|
|
|
|
|
|
|
int PhysicsLoopBack::getBodyUniqueId(int serialIndex) const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getBodyUniqueId(serialIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhysicsLoopBack::getBodyInfo(int bodyUniqueId, struct b3BodyInfo& info) const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getBodyInfo(bodyUniqueId, info);
|
|
|
|
}
|
|
|
|
|
2015-10-27 00:56:21 +00:00
|
|
|
int PhysicsLoopBack::getNumJoints(int bodyIndex) const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getNumJoints(bodyIndex);
|
|
|
|
}
|
|
|
|
|
2016-06-16 01:01:41 +00:00
|
|
|
bool PhysicsLoopBack::getJointInfo(int bodyIndex, int jointIndex, struct b3JointInfo& info) const
|
2015-10-27 00:56:21 +00:00
|
|
|
{
|
2016-06-16 01:01:41 +00:00
|
|
|
return m_data->m_physicsClient->getJointInfo(bodyIndex,jointIndex,info);
|
2015-10-27 00:56:21 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 03:08:31 +00:00
|
|
|
int PhysicsLoopBack::getNumUserConstraints() const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getNumUserConstraints();
|
|
|
|
}
|
|
|
|
int PhysicsLoopBack::getUserConstraintInfo(int constraintUniqueId, struct b3UserConstraint&info) const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getUserConstraintInfo( constraintUniqueId, info);
|
|
|
|
}
|
|
|
|
|
2017-05-04 01:25:25 +00:00
|
|
|
int PhysicsLoopBack::getUserConstraintId(int serialIndex) const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getUserConstraintId(serialIndex);
|
|
|
|
}
|
|
|
|
|
2017-01-23 03:08:31 +00:00
|
|
|
///todo: move this out of the interface
|
2015-10-27 00:56:21 +00:00
|
|
|
void PhysicsLoopBack::setSharedMemoryKey(int key)
|
|
|
|
{
|
|
|
|
m_data->m_physicsServer->setSharedMemoryKey(key);
|
|
|
|
m_data->m_physicsClient->setSharedMemoryKey(key);
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:47:04 +00:00
|
|
|
|
2015-10-27 00:56:21 +00:00
|
|
|
void PhysicsLoopBack::uploadBulletFileToSharedMemory(const char* data, int len)
|
|
|
|
{
|
|
|
|
m_data->m_physicsClient->uploadBulletFileToSharedMemory(data,len);
|
|
|
|
}
|
|
|
|
|
2018-06-16 15:14:00 +00:00
|
|
|
void PhysicsLoopBack::uploadRaysToSharedMemory(struct SharedMemoryCommand& command, const double* rayFromWorldArray, const double* rayToWorldArray, int numRays)
|
|
|
|
{
|
|
|
|
m_data->m_physicsClient->uploadRaysToSharedMemory(command, rayFromWorldArray, rayToWorldArray, numRays);
|
|
|
|
}
|
|
|
|
|
2015-10-27 00:56:21 +00:00
|
|
|
int PhysicsLoopBack::getNumDebugLines() const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getNumDebugLines();
|
|
|
|
}
|
|
|
|
|
|
|
|
const float* PhysicsLoopBack::getDebugLinesFrom() const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getDebugLinesFrom();
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
|
2015-10-27 00:56:21 +00:00
|
|
|
const float* PhysicsLoopBack::getDebugLinesTo() const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getDebugLinesTo();
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
|
2015-10-27 00:56:21 +00:00
|
|
|
const float* PhysicsLoopBack::getDebugLinesColor() const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getDebugLinesColor();
|
|
|
|
}
|
2016-05-31 17:23:04 +00:00
|
|
|
|
|
|
|
void PhysicsLoopBack::getCachedCameraImage(struct b3CameraImageData* cameraData)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedCameraImage(cameraData);
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
|
|
|
|
void PhysicsLoopBack::getCachedContactPointInformation(struct b3ContactInformation* contactPointData)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedContactPointInformation(contactPointData);
|
|
|
|
}
|
2016-10-19 05:05:28 +00:00
|
|
|
|
|
|
|
void PhysicsLoopBack::getCachedVisualShapeInformation(struct b3VisualShapeInformation* visualShapesInfo)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedVisualShapeInformation(visualShapesInfo);
|
2016-11-10 19:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:38:09 +00:00
|
|
|
void PhysicsLoopBack::getCachedCollisionShapeInformation(struct b3CollisionShapeInformation* collisionShapesInfo)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedCollisionShapeInformation(collisionShapesInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-27 03:40:09 +00:00
|
|
|
void PhysicsLoopBack::getCachedVREvents(struct b3VREventsData* vrEventsData)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedVREvents(vrEventsData);
|
|
|
|
}
|
|
|
|
|
2017-03-02 20:33:22 +00:00
|
|
|
void PhysicsLoopBack::getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedKeyboardEvents(keyboardEventsData);
|
|
|
|
}
|
|
|
|
|
2017-06-17 20:29:14 +00:00
|
|
|
void PhysicsLoopBack::getCachedMouseEvents(struct b3MouseEventsData* mouseEventsData)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedMouseEvents(mouseEventsData);
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:22:22 +00:00
|
|
|
void PhysicsLoopBack::getCachedOverlappingObjects(struct b3AABBOverlapData* overlappingObjects)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedOverlappingObjects(overlappingObjects);
|
|
|
|
}
|
|
|
|
|
2016-12-27 03:40:09 +00:00
|
|
|
void PhysicsLoopBack::getCachedRaycastHits(struct b3RaycastInformation* raycastHits)
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getCachedRaycastHits(raycastHits);
|
|
|
|
}
|
2017-02-24 23:34:11 +00:00
|
|
|
|
2017-10-05 15:23:10 +00:00
|
|
|
void PhysicsLoopBack::getCachedMassMatrix(int dofCountCheck, double* massMatrix)
|
|
|
|
{
|
|
|
|
m_data->m_physicsClient->getCachedMassMatrix(dofCountCheck,massMatrix);
|
|
|
|
}
|
|
|
|
|
2017-02-24 23:34:11 +00:00
|
|
|
void PhysicsLoopBack::setTimeOut(double timeOutInSeconds)
|
|
|
|
{
|
|
|
|
m_data->m_physicsClient->setTimeOut(timeOutInSeconds);
|
|
|
|
}
|
|
|
|
double PhysicsLoopBack::getTimeOut() const
|
|
|
|
{
|
|
|
|
return m_data->m_physicsClient->getTimeOut();
|
|
|
|
}
|
|
|
|
|
2018-07-03 15:45:19 +00:00
|
|
|
bool PhysicsLoopBack::getCachedUserData(int userDataId, struct b3UserDataValue &valueOut) const {
|
|
|
|
return m_data->m_physicsClient->getCachedUserData(userDataId, valueOut);
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 15:45:19 +00:00
|
|
|
int PhysicsLoopBack::getCachedUserDataId(int bodyUniqueId, int linkIndex, int visualShapeIndex, const char *key) const {
|
|
|
|
return m_data->m_physicsClient->getCachedUserDataId(bodyUniqueId, linkIndex, visualShapeIndex, key);
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 15:45:19 +00:00
|
|
|
int PhysicsLoopBack::getNumUserData(int bodyUniqueId) const {
|
|
|
|
return m_data->m_physicsClient->getNumUserData(bodyUniqueId);
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 15:45:19 +00:00
|
|
|
void PhysicsLoopBack::getUserDataInfo(int bodyUniqueId, int userDataIndex, const char **keyOut, int *userDataIdOut, int *linkIndexOut, int *visualShapeIndexOut) const {
|
|
|
|
m_data->m_physicsClient->getUserDataInfo(bodyUniqueId, userDataIndex, keyOut, userDataIdOut, linkIndexOut, visualShapeIndexOut);
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
|
|
|
|
2018-06-16 16:37:53 +00:00
|
|
|
void PhysicsLoopBack::pushProfileTiming(const char* timingName)
|
|
|
|
{
|
|
|
|
m_data->m_physicsClient->pushProfileTiming(timingName);
|
|
|
|
}
|
|
|
|
void PhysicsLoopBack::popProfileTiming()
|
|
|
|
{
|
|
|
|
m_data->m_physicsClient->popProfileTiming();
|
2018-07-03 15:45:19 +00:00
|
|
|
}
|