add physics server loopback (both client and server in the same process, using shared memory)

add physics server direct (client and server in the same process, directly processing commands without shared memory transport mechanism)
This commit is contained in:
erwincoumans
2015-11-22 20:50:32 -08:00
parent 7d6c2b77f7
commit 03bf78ef49
23 changed files with 2914 additions and 2086 deletions

View File

@@ -10,26 +10,11 @@
#include "../../Extras/Serialize/BulletFileLoader/btBulletFile.h"
#include "../../Extras/Serialize/BulletFileLoader/autogenerated/bullet.h"
#include "SharedMemoryBlock.h"
#include "BodyJointInfoUtility.h"
// copied from btMultiBodyLink.h
enum JointType {
eRevoluteType = 0,
ePrismaticType = 1,
};
struct TmpFloat3 {
float m_x;
float m_y;
float m_z;
};
TmpFloat3 CreateTmpFloat3(float x, float y, float z) {
TmpFloat3 tmp;
tmp.m_x = x;
tmp.m_y = y;
tmp.m_z = z;
return tmp;
}
struct BodyJointInfoCache
{
@@ -72,14 +57,8 @@ struct PhysicsClientSharedMemoryInternalData {
bool canSubmitCommand() const;
};
static char* strDup(const char* const str)
{
#ifdef _WIN32
return _strdup(str);
#else
return strdup(str);
#endif
}
int PhysicsClientSharedMemory::getNumJoints(int bodyIndex) const
{
@@ -184,6 +163,7 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
EnumSharedMemoryServerStatus s = (EnumSharedMemoryServerStatus)serverCmd.m_type;
// consume the command
switch (serverCmd.m_type) {
case CMD_CLIENT_COMMAND_COMPLETED: {
if (m_data->m_verboseOutput) {
@@ -199,7 +179,7 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
if (serverCmd.m_dataStreamArguments.m_streamChunkLength > 0) {
bParse::btBulletFile bf(
this->m_data->m_testBlock1->m_bulletStreamDataServerToClient,
this->m_data->m_testBlock1->m_bulletStreamDataServerToClientRefactor,
serverCmd.m_dataStreamArguments.m_streamChunkLength);
bf.setFileDNAisMemoryDNA();
bf.parse(false);
@@ -209,98 +189,21 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
m_data->m_bodyJointMap.insert(bodyIndex,bodyJoints);
for (int i = 0; i < bf.m_multiBodies.size(); i++) {
int flag = bf.getFlags();
int qOffset = 7;
int uOffset = 6;
int flag = bf.getFlags();
if ((flag & bParse::FD_DOUBLE_PRECISION) != 0) {
Bullet::btMultiBodyDoubleData* mb =
(Bullet::btMultiBodyDoubleData*)bf.m_multiBodies[i];
if (mb->m_baseName) {
if (m_data->m_verboseOutput) {
b3Printf("mb->m_baseName = %s\n", mb->m_baseName);
}
}
for (int link = 0; link < mb->m_numLinks; link++) {
{
b3JointInfo info;
info.m_flags = 0;
info.m_jointIndex = link;
info.m_qIndex =
(0 < mb->m_links[link].m_posVarCount) ? qOffset : -1;
info.m_uIndex =
(0 < mb->m_links[link].m_dofCount) ? uOffset : -1;
if (mb->m_links[link].m_linkName) {
if (m_data->m_verboseOutput) {
b3Printf("mb->m_links[%d].m_linkName = %s\n", link,
mb->m_links[link].m_linkName);
}
info.m_linkName = strDup(mb->m_links[link].m_linkName);
}
if (mb->m_links[link].m_jointName) {
if (m_data->m_verboseOutput) {
b3Printf("mb->m_links[%d].m_jointName = %s\n", link,
mb->m_links[link].m_jointName);
}
info.m_jointName = strDup(mb->m_links[link].m_jointName);
}
info.m_jointType = mb->m_links[link].m_jointType;
if ((mb->m_links[link].m_jointType == eRevoluteType) ||
(mb->m_links[link].m_jointType == ePrismaticType)) {
info.m_flags |= JOINT_HAS_MOTORIZED_POWER;
}
bodyJoints->m_jointInfo.push_back(info);
}
qOffset += mb->m_links[link].m_posVarCount;
uOffset += mb->m_links[link].m_dofCount;
}
} else {
addJointInfoFromMultiBodyData(mb,bodyJoints, m_data->m_verboseOutput);
} else
{
Bullet::btMultiBodyFloatData* mb =
(Bullet::btMultiBodyFloatData*)bf.m_multiBodies[i];
if (mb->m_baseName) {
if (m_data->m_verboseOutput) {
b3Printf("mb->m_baseName = %s\n", mb->m_baseName);
}
}
for (int link = 0; link < mb->m_numLinks; link++) {
{
b3JointInfo info;
info.m_flags = 0;
info.m_jointIndex = link;
info.m_qIndex =
(0 < mb->m_links[link].m_posVarCount) ? qOffset : -1;
info.m_uIndex =
(0 < mb->m_links[link].m_dofCount) ? uOffset : -1;
if (mb->m_links[link].m_linkName) {
if (m_data->m_verboseOutput) {
b3Printf("mb->m_links[%d].m_linkName = %s\n", link,
mb->m_links[link].m_linkName);
}
info.m_linkName = strDup(mb->m_links[link].m_linkName);
}
if (mb->m_links[link].m_jointName) {
if (m_data->m_verboseOutput) {
b3Printf("mb->m_links[%d].m_jointName = %s\n", link,
mb->m_links[link].m_jointName);
}
info.m_jointName = strDup(mb->m_links[link].m_jointName);
}
info.m_jointType = mb->m_links[link].m_jointType;
if ((mb->m_links[link].m_jointType == eRevoluteType) ||
(mb->m_links[link].m_jointType == ePrismaticType)) {
info.m_flags |= JOINT_HAS_MOTORIZED_POWER;
}
bodyJoints->m_jointInfo.push_back(info);
}
qOffset += mb->m_links[link].m_posVarCount;
uOffset += mb->m_links[link].m_dofCount;
}
addJointInfoFromMultiBodyData(mb,bodyJoints, m_data->m_verboseOutput);
}
}
if (bf.ok()) {
@@ -406,6 +309,9 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
if (m_data->m_verboseOutput) {
b3Printf("CMD_RESET_SIMULATION_COMPLETED clean data\n");
}
m_data->m_debugLinesFrom.clear();
m_data->m_debugLinesTo.clear();
m_data->m_debugLinesColor.clear();
for (int i=0;i<m_data->m_bodyJointMap.size();i++)
{
BodyJointInfoCache** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i);
@@ -437,12 +343,12 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
int numLines = serverCmd.m_sendDebugLinesArgs.m_numDebugLines;
float* linesFrom =
(float*)&m_data->m_testBlock1->m_bulletStreamDataServerToClient[0];
(float*)&m_data->m_testBlock1->m_bulletStreamDataServerToClientRefactor[0];
float* linesTo =
(float*)(&m_data->m_testBlock1->m_bulletStreamDataServerToClient[0] +
(float*)(&m_data->m_testBlock1->m_bulletStreamDataServerToClientRefactor[0] +
numLines * 3 * sizeof(float));
float* linesColor =
(float*)(&m_data->m_testBlock1->m_bulletStreamDataServerToClient[0] +
(float*)(&m_data->m_testBlock1->m_bulletStreamDataServerToClientRefactor[0] +
2 * numLines * 3 * sizeof(float));
m_data->m_debugLinesFrom.resize(serverCmd.m_sendDebugLinesArgs.m_startingLineIndex +