2015-11-23 04:50:32 +00:00
|
|
|
#include "PhysicsDirect.h"
|
|
|
|
|
|
|
|
#include "PhysicsClientSharedMemory.h"
|
|
|
|
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
|
|
|
#include "SharedMemoryCommands.h"
|
2016-11-04 20:15:10 +00:00
|
|
|
#include "PhysicsCommandProcessorInterface.h"
|
2017-02-22 17:33:30 +00:00
|
|
|
#include "../Utils/b3Clock.h"
|
2016-11-04 20:15:10 +00:00
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
#include "LinearMath/btHashMap.h"
|
|
|
|
#include "LinearMath/btAlignedObjectArray.h"
|
|
|
|
#include "../../Extras/Serialize/BulletFileLoader/btBulletFile.h"
|
|
|
|
#include "../../Extras/Serialize/BulletFileLoader/autogenerated/bullet.h"
|
|
|
|
#include "BodyJointInfoUtility.h"
|
2016-09-27 19:13:45 +00:00
|
|
|
#include <string>
|
2015-11-23 04:50:32 +00:00
|
|
|
|
2018-06-02 20:40:08 +00:00
|
|
|
#include "SharedMemoryUserData.h"
|
2018-06-16 13:19:49 +00:00
|
|
|
#include "LinearMath/btQuickprof.h"
|
2018-06-02 20:40:08 +00:00
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
struct BodyJointInfoCache2
|
|
|
|
{
|
2016-09-27 19:13:45 +00:00
|
|
|
std::string m_baseName;
|
2015-11-23 04:50:32 +00:00
|
|
|
btAlignedObjectArray<b3JointInfo> m_jointInfo;
|
2017-03-29 22:37:33 +00:00
|
|
|
std::string m_bodyName;
|
2018-07-03 15:45:19 +00:00
|
|
|
btAlignedObjectArray<int> m_userDataIds;
|
2019-03-27 01:13:04 +00:00
|
|
|
int m_numDofs;
|
2018-06-02 20:40:08 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
~BodyJointInfoCache2()
|
|
|
|
{
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
2015-11-23 04:50:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PhysicsDirectInternalData
|
|
|
|
{
|
|
|
|
DummyGUIHelper m_noGfx;
|
|
|
|
|
2016-11-05 00:06:55 +00:00
|
|
|
btAlignedObjectArray<char> m_serverDNA;
|
2015-11-23 04:50:32 +00:00
|
|
|
SharedMemoryCommand m_command;
|
|
|
|
SharedMemoryStatus m_serverStatus;
|
2017-11-22 23:30:56 +00:00
|
|
|
|
|
|
|
SharedMemoryCommand m_tmpInfoRequestCommand;
|
|
|
|
SharedMemoryStatus m_tmpInfoStatus;
|
2015-11-23 04:50:32 +00:00
|
|
|
bool m_hasStatus;
|
|
|
|
bool m_verboseOutput;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
btAlignedObjectArray<TmpFloat3> m_debugLinesFrom;
|
2018-09-23 21:17:31 +00:00
|
|
|
btAlignedObjectArray<TmpFloat3> m_debugLinesTo;
|
|
|
|
btAlignedObjectArray<TmpFloat3> m_debugLinesColor;
|
|
|
|
|
|
|
|
btHashMap<btHashInt, BodyJointInfoCache2*> m_bodyJointMap;
|
|
|
|
btHashMap<btHashInt, b3UserConstraint> m_userConstraintInfoMap;
|
2015-11-23 04:50:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btAlignedObjectArray<CProfileSample*> m_profileTimings;
|
2018-06-16 16:37:53 +00:00
|
|
|
btHashMap<btHashString, std::string*> m_profileTimingStringArray;
|
2018-06-16 13:19:49 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
char m_bulletStreamDataServerToClient[SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE];
|
2017-10-05 15:23:10 +00:00
|
|
|
btAlignedObjectArray<double> m_cachedMassMatrix;
|
2016-06-04 02:03:56 +00:00
|
|
|
int m_cachedCameraPixelsWidth;
|
|
|
|
int m_cachedCameraPixelsHeight;
|
|
|
|
btAlignedObjectArray<unsigned char> m_cachedCameraPixelsRGBA;
|
|
|
|
btAlignedObjectArray<float> m_cachedCameraDepthBuffer;
|
2016-08-11 21:55:30 +00:00
|
|
|
btAlignedObjectArray<int> m_cachedSegmentationMask;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
btAlignedObjectArray<b3ContactPointData> m_cachedContactPoints;
|
2016-11-10 19:22:22 +00:00
|
|
|
btAlignedObjectArray<b3OverlappingObject> m_cachedOverlappingObjects;
|
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
btAlignedObjectArray<b3VisualShapeData> m_cachedVisualShapes;
|
2018-01-04 03:17:28 +00:00
|
|
|
btAlignedObjectArray<b3CollisionShapeData> m_cachedCollisionShapes;
|
|
|
|
|
2019-06-18 04:43:38 +00:00
|
|
|
b3MeshData m_cachedMeshData;
|
|
|
|
btAlignedObjectArray<b3MeshVertex> m_cachedVertexPositions;
|
2019-06-18 00:32:01 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btAlignedObjectArray<b3VRControllerEvent> m_cachedVREvents;
|
2016-12-27 03:40:09 +00:00
|
|
|
|
2017-03-02 20:33:22 +00:00
|
|
|
btAlignedObjectArray<b3KeyboardEvent> m_cachedKeyboardEvents;
|
2017-06-17 20:29:14 +00:00
|
|
|
btAlignedObjectArray<b3MouseEvent> m_cachedMouseEvents;
|
2017-03-02 20:33:22 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btAlignedObjectArray<b3RayHitInfo> m_raycastHits;
|
2016-12-27 03:40:09 +00:00
|
|
|
|
2018-07-03 15:45:19 +00:00
|
|
|
btHashMap<btHashInt, SharedMemoryUserData> m_userDataMap;
|
|
|
|
btHashMap<SharedMemoryUserDataHashKey, int> m_userDataHandleLookup;
|
|
|
|
|
2020-10-07 03:19:39 +00:00
|
|
|
btAlignedObjectArray<char> m_cachedReturnData;
|
|
|
|
b3UserDataValue m_cachedReturnDataValue;
|
|
|
|
|
|
|
|
|
2016-11-04 20:15:10 +00:00
|
|
|
PhysicsCommandProcessorInterface* m_commandProcessor;
|
|
|
|
bool m_ownsCommandProcessor;
|
2017-02-24 23:34:11 +00:00
|
|
|
double m_timeOutInSeconds;
|
2015-11-23 04:50:32 +00:00
|
|
|
|
2019-03-07 07:27:59 +00:00
|
|
|
SendActualStateSharedMemoryStorage m_cachedState;
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
PhysicsDirectInternalData()
|
2018-09-23 21:17:31 +00:00
|
|
|
: m_hasStatus(false),
|
|
|
|
m_verboseOutput(false),
|
|
|
|
m_cachedCameraPixelsWidth(0),
|
|
|
|
m_cachedCameraPixelsHeight(0),
|
|
|
|
m_commandProcessor(NULL),
|
|
|
|
m_ownsCommandProcessor(false),
|
|
|
|
m_timeOutInSeconds(1e30)
|
2015-11-23 04:50:32 +00:00
|
|
|
{
|
2019-06-18 04:43:38 +00:00
|
|
|
memset(&m_cachedMeshData.m_numVertices, 0, sizeof(b3MeshData));
|
2017-06-10 04:19:02 +00:00
|
|
|
memset(&m_command, 0, sizeof(m_command));
|
|
|
|
memset(&m_serverStatus, 0, sizeof(m_serverStatus));
|
|
|
|
memset(m_bulletStreamDataServerToClient, 0, sizeof(m_bulletStreamDataServerToClient));
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-10 22:57:16 +00:00
|
|
|
PhysicsDirect::PhysicsDirect(PhysicsCommandProcessorInterface* physSdk, bool passSdkOwnership)
|
2015-11-23 04:50:32 +00:00
|
|
|
{
|
2017-11-22 23:30:56 +00:00
|
|
|
int sz = sizeof(SharedMemoryCommand);
|
|
|
|
int sz2 = sizeof(SharedMemoryStatus);
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
m_data = new PhysicsDirectInternalData;
|
2016-11-04 20:15:10 +00:00
|
|
|
m_data->m_commandProcessor = physSdk;
|
2017-01-10 22:57:16 +00:00
|
|
|
m_data->m_ownsCommandProcessor = passSdkOwnership;
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsDirect::~PhysicsDirect()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_data->m_profileTimingStringArray.size(); i++)
|
2018-06-16 13:19:49 +00:00
|
|
|
{
|
2018-06-16 16:37:53 +00:00
|
|
|
std::string** str = m_data->m_profileTimingStringArray.getAtIndex(i);
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
delete *str;
|
|
|
|
}
|
2018-06-16 13:19:49 +00:00
|
|
|
}
|
2018-06-16 16:37:53 +00:00
|
|
|
m_data->m_profileTimingStringArray.clear();
|
2018-06-16 13:19:49 +00:00
|
|
|
|
2016-11-04 20:15:10 +00:00
|
|
|
if (m_data->m_commandProcessor->isConnected())
|
|
|
|
{
|
|
|
|
m_data->m_commandProcessor->disconnect();
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2016-11-04 20:15:10 +00:00
|
|
|
if (m_data->m_ownsCommandProcessor)
|
|
|
|
{
|
|
|
|
delete m_data->m_commandProcessor;
|
|
|
|
}
|
2017-01-10 22:57:16 +00:00
|
|
|
|
|
|
|
resetData();
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
delete m_data;
|
|
|
|
}
|
|
|
|
|
2017-01-10 22:57:16 +00:00
|
|
|
void PhysicsDirect::resetData()
|
|
|
|
{
|
|
|
|
m_data->m_debugLinesFrom.clear();
|
|
|
|
m_data->m_debugLinesTo.clear();
|
|
|
|
m_data->m_debugLinesColor.clear();
|
2019-08-08 08:53:23 +00:00
|
|
|
m_data->m_userConstraintInfoMap.clear();
|
2019-08-08 11:20:44 +00:00
|
|
|
m_data->m_userDataMap.clear();
|
|
|
|
m_data->m_userDataHandleLookup.clear();
|
2019-08-08 08:53:23 +00:00
|
|
|
clearCachedBodies();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsDirect::clearCachedBodies()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_data->m_bodyJointMap.size(); i++)
|
2017-01-10 22:57:16 +00:00
|
|
|
{
|
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i);
|
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
|
|
|
delete (*bodyJointsPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_data->m_bodyJointMap.clear();
|
|
|
|
}
|
2015-11-23 04:50:32 +00:00
|
|
|
|
|
|
|
// return true if connection succesfull, can also check 'isConnected'
|
|
|
|
bool PhysicsDirect::connect()
|
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
bool connected = m_data->m_commandProcessor->connect();
|
2015-11-23 04:50:32 +00:00
|
|
|
m_data->m_commandProcessor->setGuiHelper(&m_data->m_noGfx);
|
2016-11-05 00:06:55 +00:00
|
|
|
|
2017-01-29 06:14:45 +00:00
|
|
|
if (connected)
|
2016-11-05 00:06:55 +00:00
|
|
|
//also request serialization data
|
|
|
|
{
|
|
|
|
SharedMemoryCommand command;
|
|
|
|
command.m_type = CMD_REQUEST_INTERNAL_DATA;
|
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
postProcessStatus(m_data->m_serverStatus);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-22 17:33:30 +00:00
|
|
|
b3Clock clock;
|
|
|
|
double timeSec = clock.getTimeInSeconds();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - timeSec < 10))
|
2016-11-05 00:06:55 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
const SharedMemoryStatus* stat = processServerStatus();
|
2016-11-05 00:06:55 +00:00
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
hasStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 20:15:10 +00:00
|
|
|
return connected;
|
2016-08-19 17:30:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return true if connection succesfull, can also check 'isConnected'
|
|
|
|
bool PhysicsDirect::connect(struct GUIHelperInterface* guiHelper)
|
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
bool connected = m_data->m_commandProcessor->connect();
|
|
|
|
|
2016-08-19 17:30:02 +00:00
|
|
|
m_data->m_commandProcessor->setGuiHelper(guiHelper);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-11-04 20:15:10 +00:00
|
|
|
return connected;
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
2016-08-19 17:30:02 +00:00
|
|
|
void PhysicsDirect::renderScene()
|
|
|
|
{
|
2017-05-16 19:19:03 +00:00
|
|
|
int renderFlags = 0;
|
|
|
|
m_data->m_commandProcessor->renderScene(renderFlags);
|
2016-08-19 17:30:02 +00:00
|
|
|
}
|
2016-11-04 20:15:10 +00:00
|
|
|
|
2016-08-19 17:30:02 +00:00
|
|
|
void PhysicsDirect::debugDraw(int debugDrawMode)
|
|
|
|
{
|
|
|
|
m_data->m_commandProcessor->physicsDebugDraw(debugDrawMode);
|
|
|
|
}
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
////todo: rename to 'disconnect'
|
|
|
|
void PhysicsDirect::disconnectSharedMemory()
|
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
m_data->m_commandProcessor->disconnect();
|
2015-11-23 04:50:32 +00:00
|
|
|
m_data->m_commandProcessor->setGuiHelper(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhysicsDirect::isConnected() const
|
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
return m_data->m_commandProcessor->isConnected();
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return non-null if there is a status, nullptr otherwise
|
2018-09-23 21:17:31 +00:00
|
|
|
const SharedMemoryStatus* PhysicsDirect::processServerStatus()
|
2015-11-23 04:50:32 +00:00
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
if (!m_data->m_hasStatus)
|
|
|
|
{
|
|
|
|
m_data->m_hasStatus = m_data->m_commandProcessor->receiveStatus(m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
}
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
SharedMemoryStatus* stat = 0;
|
|
|
|
if (m_data->m_hasStatus)
|
|
|
|
{
|
|
|
|
stat = &m_data->m_serverStatus;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-11-04 20:15:10 +00:00
|
|
|
postProcessStatus(m_data->m_serverStatus);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
m_data->m_hasStatus = false;
|
|
|
|
}
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedMemoryCommand* PhysicsDirect::getAvailableSharedMemoryCommand()
|
|
|
|
{
|
|
|
|
return &m_data->m_command;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhysicsDirect::canSubmitCommand() const
|
|
|
|
{
|
2017-01-29 06:14:45 +00:00
|
|
|
return m_data->m_commandProcessor->isConnected();
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PhysicsDirect::processDebugLines(const struct SharedMemoryCommand& orgCommand)
|
|
|
|
{
|
|
|
|
SharedMemoryCommand command = orgCommand;
|
|
|
|
|
|
|
|
const SharedMemoryStatus& serverCmd = m_data->m_serverStatus;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
2016-11-04 20:15:10 +00:00
|
|
|
|
2017-02-22 17:33:30 +00:00
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
2017-02-24 23:34:11 +00:00
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
2017-02-22 17:33:30 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
2016-11-04 20:15:10 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
const SharedMemoryStatus* stat = processServerStatus();
|
2016-11-04 20:15:10 +00:00
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
hasStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
m_data->m_hasStatus = hasStatus;
|
2016-11-04 20:15:10 +00:00
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
btAssert(m_data->m_serverStatus.m_type == CMD_DEBUG_LINES_COMPLETED);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
2015-11-23 04:50:32 +00:00
|
|
|
{
|
|
|
|
b3Printf("Success receiving %d debug lines",
|
2018-09-23 21:17:31 +00:00
|
|
|
serverCmd.m_sendDebugLinesArgs.m_numDebugLines);
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int numLines = serverCmd.m_sendDebugLinesArgs.m_numDebugLines;
|
|
|
|
float* linesFrom =
|
|
|
|
(float*)&m_data->m_bulletStreamDataServerToClient[0];
|
|
|
|
float* linesTo =
|
2018-09-23 21:17:31 +00:00
|
|
|
(float*)(&m_data->m_bulletStreamDataServerToClient[0] +
|
|
|
|
numLines * 3 * sizeof(float));
|
2015-11-23 04:50:32 +00:00
|
|
|
float* linesColor =
|
|
|
|
(float*)(&m_data->m_bulletStreamDataServerToClient[0] +
|
2018-09-23 21:17:31 +00:00
|
|
|
2 * numLines * 3 * sizeof(float));
|
2015-11-23 04:50:32 +00:00
|
|
|
|
|
|
|
m_data->m_debugLinesFrom.resize(serverCmd.m_sendDebugLinesArgs.m_startingLineIndex +
|
|
|
|
numLines);
|
|
|
|
m_data->m_debugLinesTo.resize(serverCmd.m_sendDebugLinesArgs.m_startingLineIndex +
|
2018-09-23 21:17:31 +00:00
|
|
|
numLines);
|
2015-11-23 04:50:32 +00:00
|
|
|
m_data->m_debugLinesColor.resize(
|
|
|
|
serverCmd.m_sendDebugLinesArgs.m_startingLineIndex + numLines);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numLines; i++)
|
2015-11-23 04:50:32 +00:00
|
|
|
{
|
|
|
|
TmpFloat3 from = CreateTmpFloat3(linesFrom[i * 3], linesFrom[i * 3 + 1],
|
2018-09-23 21:17:31 +00:00
|
|
|
linesFrom[i * 3 + 2]);
|
2015-11-23 04:50:32 +00:00
|
|
|
TmpFloat3 to =
|
|
|
|
CreateTmpFloat3(linesTo[i * 3], linesTo[i * 3 + 1], linesTo[i * 3 + 2]);
|
|
|
|
TmpFloat3 color = CreateTmpFloat3(linesColor[i * 3], linesColor[i * 3 + 1],
|
2018-09-23 21:17:31 +00:00
|
|
|
linesColor[i * 3 + 2]);
|
2015-11-23 04:50:32 +00:00
|
|
|
|
|
|
|
m_data
|
|
|
|
->m_debugLinesFrom[serverCmd.m_sendDebugLinesArgs.m_startingLineIndex + i] =
|
|
|
|
from;
|
|
|
|
m_data->m_debugLinesTo[serverCmd.m_sendDebugLinesArgs.m_startingLineIndex + i] =
|
|
|
|
to;
|
|
|
|
m_data->m_debugLinesColor[serverCmd.m_sendDebugLinesArgs.m_startingLineIndex +
|
2018-09-23 21:17:31 +00:00
|
|
|
i] = color;
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (serverCmd.m_sendDebugLinesArgs.m_numRemainingDebugLines > 0)
|
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
m_data->m_hasStatus = false;
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
command.m_type = CMD_REQUEST_DEBUG_LINES;
|
|
|
|
command.m_requestDebugLinesArguments.m_startingLineIndex =
|
|
|
|
serverCmd.m_sendDebugLinesArgs.m_numDebugLines +
|
|
|
|
serverCmd.m_sendDebugLinesArgs.m_startingLineIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (serverCmd.m_sendDebugLinesArgs.m_numRemainingDebugLines > 0);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
return m_data->m_hasStatus;
|
|
|
|
}
|
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
bool PhysicsDirect::processVisualShapeData(const struct SharedMemoryCommand& orgCommand)
|
|
|
|
{
|
|
|
|
SharedMemoryCommand command = orgCommand;
|
|
|
|
const SharedMemoryStatus& serverCmd = m_data->m_serverStatus;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
2016-11-04 20:15:10 +00:00
|
|
|
|
2017-02-22 17:33:30 +00:00
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
2017-02-24 23:34:11 +00:00
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
2017-02-22 17:33:30 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
2016-11-04 20:15:10 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
const SharedMemoryStatus* stat = processServerStatus();
|
2016-11-04 20:15:10 +00:00
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
hasStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
m_data->m_hasStatus = hasStatus;
|
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Visual Shape Information Request OK\n");
|
|
|
|
}
|
|
|
|
int startVisualShapeIndex = serverCmd.m_sendVisualShapeArgs.m_startingVisualShapeIndex;
|
|
|
|
int numVisualShapesCopied = serverCmd.m_sendVisualShapeArgs.m_numVisualShapesCopied;
|
|
|
|
m_data->m_cachedVisualShapes.resize(startVisualShapeIndex + numVisualShapesCopied);
|
|
|
|
b3VisualShapeData* shapeData = (b3VisualShapeData*)&m_data->m_bulletStreamDataServerToClient[0];
|
|
|
|
for (int i = 0; i < numVisualShapesCopied; i++)
|
|
|
|
{
|
|
|
|
m_data->m_cachedVisualShapes[startVisualShapeIndex + i] = shapeData[i];
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
if (serverCmd.m_sendVisualShapeArgs.m_numRemainingVisualShapes > 0 && serverCmd.m_sendVisualShapeArgs.m_numVisualShapesCopied)
|
2016-10-19 05:05:28 +00:00
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
m_data->m_hasStatus = false;
|
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
command.m_type = CMD_REQUEST_VISUAL_SHAPE_INFO;
|
|
|
|
command.m_requestVisualShapeDataArguments.m_startingVisualShapeIndex = serverCmd.m_sendVisualShapeArgs.m_startingVisualShapeIndex + serverCmd.m_sendVisualShapeArgs.m_numVisualShapesCopied;
|
|
|
|
command.m_requestVisualShapeDataArguments.m_bodyUniqueId = serverCmd.m_sendVisualShapeArgs.m_bodyUniqueId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (serverCmd.m_sendVisualShapeArgs.m_numRemainingVisualShapes > 0 && serverCmd.m_sendVisualShapeArgs.m_numVisualShapesCopied);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
return m_data->m_hasStatus;
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:22:22 +00:00
|
|
|
bool PhysicsDirect::processOverlappingObjects(const struct SharedMemoryCommand& orgCommand)
|
|
|
|
{
|
|
|
|
SharedMemoryCommand command = orgCommand;
|
|
|
|
|
|
|
|
const SharedMemoryStatus& serverCmd = m_data->m_serverStatus;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
|
2017-02-22 17:33:30 +00:00
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
2017-02-24 23:34:11 +00:00
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
2017-02-22 17:33:30 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
2016-11-10 19:22:22 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
const SharedMemoryStatus* stat = processServerStatus();
|
2016-11-10 19:22:22 +00:00
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
hasStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_data->m_hasStatus = hasStatus;
|
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Overlapping Objects Request OK\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int startOverlapIndex = serverCmd.m_sendOverlappingObjectsArgs.m_startingOverlappingObjectIndex;
|
|
|
|
int numOverlapCopied = serverCmd.m_sendOverlappingObjectsArgs.m_numOverlappingObjectsCopied;
|
|
|
|
m_data->m_cachedOverlappingObjects.resize(startOverlapIndex + numOverlapCopied);
|
|
|
|
b3OverlappingObject* objects = (b3OverlappingObject*)&m_data->m_bulletStreamDataServerToClient[0];
|
|
|
|
|
|
|
|
for (int i = 0; i < numOverlapCopied; i++)
|
|
|
|
{
|
|
|
|
m_data->m_cachedOverlappingObjects[startOverlapIndex + i] = objects[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serverCmd.m_sendOverlappingObjectsArgs.m_numRemainingOverlappingObjects > 0 && serverCmd.m_sendOverlappingObjectsArgs.m_numOverlappingObjectsCopied)
|
|
|
|
{
|
|
|
|
m_data->m_hasStatus = false;
|
|
|
|
command.m_type = CMD_REQUEST_AABB_OVERLAP;
|
|
|
|
command.m_requestOverlappingObjectsArgs.m_startingOverlappingObjectIndex = serverCmd.m_sendOverlappingObjectsArgs.m_startingOverlappingObjectIndex + serverCmd.m_sendOverlappingObjectsArgs.m_numOverlappingObjectsCopied;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (serverCmd.m_sendOverlappingObjectsArgs.m_numRemainingOverlappingObjects > 0 && serverCmd.m_sendOverlappingObjectsArgs.m_numOverlappingObjectsCopied);
|
|
|
|
|
|
|
|
return m_data->m_hasStatus;
|
|
|
|
}
|
|
|
|
|
2016-09-02 01:28:39 +00:00
|
|
|
bool PhysicsDirect::processContactPointData(const struct SharedMemoryCommand& orgCommand)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
SharedMemoryCommand command = orgCommand;
|
|
|
|
|
|
|
|
const SharedMemoryStatus& serverCmd = m_data->m_serverStatus;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
|
2017-02-22 17:33:30 +00:00
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
2017-02-24 23:34:11 +00:00
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
2017-02-22 17:33:30 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
2016-11-04 20:15:10 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
const SharedMemoryStatus* stat = processServerStatus();
|
2016-11-04 20:15:10 +00:00
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
hasStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_data->m_hasStatus = hasStatus;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Contact Point Information Request OK\n");
|
|
|
|
}
|
|
|
|
int startContactIndex = serverCmd.m_sendContactPointArgs.m_startingContactPointIndex;
|
|
|
|
int numContactsCopied = serverCmd.m_sendContactPointArgs.m_numContactPointsCopied;
|
|
|
|
|
|
|
|
m_data->m_cachedContactPoints.resize(startContactIndex + numContactsCopied);
|
|
|
|
|
|
|
|
b3ContactPointData* contactData = (b3ContactPointData*)&m_data->m_bulletStreamDataServerToClient[0];
|
|
|
|
|
|
|
|
for (int i = 0; i < numContactsCopied; i++)
|
|
|
|
{
|
|
|
|
m_data->m_cachedContactPoints[startContactIndex + i] = contactData[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serverCmd.m_sendContactPointArgs.m_numRemainingContactPoints > 0 && serverCmd.m_sendContactPointArgs.m_numContactPointsCopied)
|
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
m_data->m_hasStatus = false;
|
|
|
|
|
|
|
|
command.m_type = CMD_REQUEST_CONTACT_POINT_INFORMATION;
|
2018-09-23 21:17:31 +00:00
|
|
|
command.m_requestContactPointArguments.m_startingContactPointIndex = serverCmd.m_sendContactPointArgs.m_startingContactPointIndex + serverCmd.m_sendContactPointArgs.m_numContactPointsCopied;
|
|
|
|
command.m_requestContactPointArguments.m_objectAIndexFilter = -1;
|
|
|
|
command.m_requestContactPointArguments.m_objectBIndexFilter = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (serverCmd.m_sendContactPointArgs.m_numRemainingContactPoints > 0 && serverCmd.m_sendContactPointArgs.m_numContactPointsCopied);
|
2016-09-02 01:28:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_hasStatus;
|
2016-09-02 01:28:39 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 02:03:56 +00:00
|
|
|
bool PhysicsDirect::processCamera(const struct SharedMemoryCommand& orgCommand)
|
|
|
|
{
|
|
|
|
SharedMemoryCommand command = orgCommand;
|
|
|
|
|
|
|
|
const SharedMemoryStatus& serverCmd = m_data->m_serverStatus;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
2016-06-04 02:03:56 +00:00
|
|
|
|
2017-02-22 17:33:30 +00:00
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
2017-02-24 23:34:11 +00:00
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
2017-02-22 17:33:30 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
2016-11-04 20:15:10 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
const SharedMemoryStatus* stat = processServerStatus();
|
2016-11-04 20:15:10 +00:00
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
hasStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 02:03:56 +00:00
|
|
|
m_data->m_hasStatus = hasStatus;
|
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
btAssert(m_data->m_serverStatus.m_type == CMD_CAMERA_IMAGE_COMPLETED);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
2016-06-04 02:03:56 +00:00
|
|
|
{
|
|
|
|
b3Printf("Camera image OK\n");
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int numBytesPerPixel = 4; //RGBA
|
|
|
|
int numTotalPixels = serverCmd.m_sendPixelDataArguments.m_startingPixelIndex +
|
|
|
|
serverCmd.m_sendPixelDataArguments.m_numPixelsCopied +
|
|
|
|
serverCmd.m_sendPixelDataArguments.m_numRemainingPixels;
|
2016-06-04 02:03:56 +00:00
|
|
|
|
|
|
|
m_data->m_cachedCameraPixelsWidth = 0;
|
|
|
|
m_data->m_cachedCameraPixelsHeight = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int numPixels = serverCmd.m_sendPixelDataArguments.m_imageWidth * serverCmd.m_sendPixelDataArguments.m_imageHeight;
|
2016-06-04 02:03:56 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_cachedCameraPixelsRGBA.reserve(numPixels * numBytesPerPixel);
|
2016-06-04 02:03:56 +00:00
|
|
|
m_data->m_cachedCameraDepthBuffer.resize(numTotalPixels);
|
2016-08-11 21:55:30 +00:00
|
|
|
m_data->m_cachedSegmentationMask.resize(numTotalPixels);
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_cachedCameraPixelsRGBA.resize(numTotalPixels * numBytesPerPixel);
|
|
|
|
|
2016-06-04 02:03:56 +00:00
|
|
|
unsigned char* rgbaPixelsReceived =
|
2018-09-23 21:17:31 +00:00
|
|
|
(unsigned char*)&m_data->m_bulletStreamDataServerToClient[0];
|
|
|
|
|
|
|
|
float* depthBuffer = (float*)&(m_data->m_bulletStreamDataServerToClient[serverCmd.m_sendPixelDataArguments.m_numPixelsCopied * 4]);
|
|
|
|
int* segmentationMaskBuffer = (int*)&(m_data->m_bulletStreamDataServerToClient[serverCmd.m_sendPixelDataArguments.m_numPixelsCopied * 8]);
|
|
|
|
|
|
|
|
// printf("pixel = %d\n", rgbaPixelsReceived[0]);
|
|
|
|
|
|
|
|
for (int i = 0; i < serverCmd.m_sendPixelDataArguments.m_numPixelsCopied; i++)
|
2016-06-07 23:11:58 +00:00
|
|
|
{
|
|
|
|
m_data->m_cachedCameraDepthBuffer[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex] = depthBuffer[i];
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < serverCmd.m_sendPixelDataArguments.m_numPixelsCopied; i++)
|
2016-08-11 21:55:30 +00:00
|
|
|
{
|
|
|
|
m_data->m_cachedSegmentationMask[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex] = segmentationMaskBuffer[i];
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < serverCmd.m_sendPixelDataArguments.m_numPixelsCopied * numBytesPerPixel; i++)
|
2016-06-04 02:03:56 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_cachedCameraPixelsRGBA[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex * numBytesPerPixel] = rgbaPixelsReceived[i];
|
2016-06-04 02:03:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 21:23:44 +00:00
|
|
|
if (serverCmd.m_sendPixelDataArguments.m_numRemainingPixels > 0 && serverCmd.m_sendPixelDataArguments.m_numPixelsCopied)
|
2016-06-04 02:03:56 +00:00
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
m_data->m_hasStatus = false;
|
2016-06-04 02:03:56 +00:00
|
|
|
|
|
|
|
// continue requesting remaining pixels
|
|
|
|
command.m_type = CMD_REQUEST_CAMERA_IMAGE_DATA;
|
2018-09-23 21:17:31 +00:00
|
|
|
command.m_requestPixelDataArguments.m_startPixelIndex =
|
|
|
|
serverCmd.m_sendPixelDataArguments.m_startingPixelIndex +
|
2016-06-04 02:03:56 +00:00
|
|
|
serverCmd.m_sendPixelDataArguments.m_numPixelsCopied;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2016-06-04 02:03:56 +00:00
|
|
|
{
|
|
|
|
m_data->m_cachedCameraPixelsWidth = serverCmd.m_sendPixelDataArguments.m_imageWidth;
|
|
|
|
m_data->m_cachedCameraPixelsHeight = serverCmd.m_sendPixelDataArguments.m_imageHeight;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2016-06-04 02:03:56 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
} while (serverCmd.m_sendPixelDataArguments.m_numRemainingPixels > 0 && serverCmd.m_sendPixelDataArguments.m_numPixelsCopied);
|
2016-06-04 02:03:56 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_hasStatus;
|
2016-06-04 02:03:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 00:32:01 +00:00
|
|
|
bool PhysicsDirect::processMeshData(const struct SharedMemoryCommand& orgCommand)
|
|
|
|
{
|
|
|
|
SharedMemoryCommand command = orgCommand;
|
|
|
|
|
|
|
|
const SharedMemoryStatus& serverCmd = m_data->m_serverStatus;
|
2019-06-18 04:43:38 +00:00
|
|
|
do
|
2019-06-18 00:32:01 +00:00
|
|
|
{
|
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
|
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
|
|
|
|
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
|
|
|
{
|
|
|
|
const SharedMemoryStatus* stat = processServerStatus();
|
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
hasStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_data->m_hasStatus = hasStatus;
|
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
btAssert(m_data->m_serverStatus.m_type == CMD_REQUEST_MESH_DATA_COMPLETED);
|
|
|
|
|
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Mesh data OK\n");
|
|
|
|
}
|
|
|
|
|
2019-06-18 04:43:38 +00:00
|
|
|
const b3SendMeshDataArgs& args = serverCmd.m_sendMeshDataArgs;
|
|
|
|
int numTotalPixels = args.m_startingVertex +
|
|
|
|
args.m_numVerticesCopied + args.m_numVerticesRemaining;
|
2019-06-18 00:32:01 +00:00
|
|
|
|
2019-06-18 04:43:38 +00:00
|
|
|
btVector3* verticesReceived =
|
|
|
|
(btVector3*)&m_data->m_bulletStreamDataServerToClient[0];
|
2019-06-18 00:32:01 +00:00
|
|
|
|
2019-06-18 04:43:38 +00:00
|
|
|
|
|
|
|
m_data->m_cachedVertexPositions.resize(args.m_startingVertex +
|
|
|
|
args.m_numVerticesCopied);
|
2019-06-18 00:32:01 +00:00
|
|
|
|
2019-06-18 04:43:38 +00:00
|
|
|
for (int i = 0; i < args.m_numVerticesCopied; i++)
|
2019-06-18 00:32:01 +00:00
|
|
|
{
|
2019-06-18 04:43:38 +00:00
|
|
|
m_data->m_cachedVertexPositions[i + args.m_startingVertex].x = verticesReceived[i].x();
|
|
|
|
m_data->m_cachedVertexPositions[i + args.m_startingVertex].y = verticesReceived[i].y();
|
|
|
|
m_data->m_cachedVertexPositions[i + args.m_startingVertex].z = verticesReceived[i].z();
|
|
|
|
m_data->m_cachedVertexPositions[i + args.m_startingVertex].w = verticesReceived[i].w();
|
2019-06-18 00:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args.m_numVerticesRemaining > 0 && args.m_numVerticesCopied)
|
|
|
|
{
|
|
|
|
m_data->m_hasStatus = false;
|
|
|
|
|
|
|
|
// continue requesting remaining vertices
|
|
|
|
command.m_type = CMD_REQUEST_MESH_DATA;
|
|
|
|
command.m_requestMeshDataArgs.m_startingVertex =
|
2019-06-18 04:43:38 +00:00
|
|
|
args.m_startingVertex + args.m_numVerticesCopied;
|
2019-06-18 00:32:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-18 04:43:38 +00:00
|
|
|
m_data->m_cachedMeshData.m_numVertices = args.m_startingVertex +
|
|
|
|
args.m_numVerticesCopied;
|
2019-06-18 00:32:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (serverCmd.m_sendMeshDataArgs.m_numVerticesRemaining > 0 && serverCmd.m_sendMeshDataArgs.m_numVerticesCopied);
|
|
|
|
|
|
|
|
return m_data->m_hasStatus;
|
|
|
|
}
|
|
|
|
|
2016-06-15 01:41:19 +00:00
|
|
|
void PhysicsDirect::processBodyJointInfo(int bodyUniqueId, const SharedMemoryStatus& serverCmd)
|
|
|
|
{
|
2017-01-10 22:57:16 +00:00
|
|
|
BodyJointInfoCache2** cachePtr = m_data->m_bodyJointMap[bodyUniqueId];
|
|
|
|
//don't process same bodyUniqueId multiple times
|
|
|
|
if (cachePtr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bParse::btBulletFile bf(
|
|
|
|
&m_data->m_bulletStreamDataServerToClient[0],
|
|
|
|
serverCmd.m_numDataStreamBytes);
|
2016-11-05 00:06:55 +00:00
|
|
|
if (m_data->m_serverDNA.size())
|
|
|
|
{
|
|
|
|
bf.setFileDNA(false, &m_data->m_serverDNA[0], m_data->m_serverDNA.size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bf.setFileDNAisMemoryDNA();
|
|
|
|
}
|
2019-09-09 21:56:26 +00:00
|
|
|
{
|
|
|
|
BT_PROFILE("bf.parse");
|
|
|
|
bf.parse(false);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
BodyJointInfoCache2* bodyJoints = new BodyJointInfoCache2;
|
|
|
|
m_data->m_bodyJointMap.insert(bodyUniqueId, bodyJoints);
|
2017-03-29 22:37:33 +00:00
|
|
|
bodyJoints->m_bodyName = serverCmd.m_dataStreamArguments.m_bodyName;
|
2016-06-15 01:41:19 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < bf.m_multiBodies.size(); i++)
|
|
|
|
{
|
|
|
|
int flag = bf.getFlags();
|
|
|
|
if ((flag & bParse::FD_DOUBLE_PRECISION) != 0)
|
|
|
|
{
|
|
|
|
Bullet::btMultiBodyDoubleData* mb =
|
|
|
|
(Bullet::btMultiBodyDoubleData*)bf.m_multiBodies[i];
|
|
|
|
|
|
|
|
if (mb->m_baseName)
|
|
|
|
{
|
|
|
|
bodyJoints->m_baseName = mb->m_baseName;
|
|
|
|
}
|
|
|
|
addJointInfoFromMultiBodyData(mb, bodyJoints, m_data->m_verboseOutput);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Bullet::btMultiBodyFloatData* mb =
|
|
|
|
(Bullet::btMultiBodyFloatData*)bf.m_multiBodies[i];
|
|
|
|
|
|
|
|
if (mb->m_baseName)
|
|
|
|
{
|
|
|
|
bodyJoints->m_baseName = mb->m_baseName;
|
|
|
|
}
|
|
|
|
addJointInfoFromMultiBodyData(mb, bodyJoints, m_data->m_verboseOutput);
|
2019-09-09 21:56:26 +00:00
|
|
|
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
if (bf.ok())
|
2016-11-05 00:06:55 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Received robot description ok!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b3Warning("Robot description not received");
|
|
|
|
}
|
2016-06-15 01:41:19 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void PhysicsDirect::processAddUserData(const struct SharedMemoryStatus& serverCmd)
|
|
|
|
{
|
2018-07-03 15:45:19 +00:00
|
|
|
const UserDataResponseArgs response = serverCmd.m_userDataResponseArgs;
|
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[response.m_bodyUniqueId];
|
2018-09-23 21:17:31 +00:00
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
|
|
|
const char* dataStream = m_data->m_bulletStreamDataServerToClient;
|
2018-07-03 15:45:19 +00:00
|
|
|
SharedMemoryUserData* userData = m_data->m_userDataMap[response.m_userDataId];
|
2018-09-23 21:17:31 +00:00
|
|
|
if (userData)
|
|
|
|
{
|
2018-06-02 20:40:08 +00:00
|
|
|
// Only replace the value.
|
2018-07-03 15:45:19 +00:00
|
|
|
userData->replaceValue(dataStream, response.m_valueLength, response.m_valueType);
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
else
|
|
|
|
{
|
2018-06-02 20:40:08 +00:00
|
|
|
// Add a new user data entry.
|
2018-09-23 21:17:31 +00:00
|
|
|
const char* key = response.m_key;
|
2018-07-03 15:45:19 +00:00
|
|
|
m_data->m_userDataMap.insert(response.m_userDataId, SharedMemoryUserData(key, response.m_bodyUniqueId, response.m_linkIndex, response.m_visualShapeIndex));
|
|
|
|
userData = m_data->m_userDataMap[response.m_userDataId];
|
|
|
|
userData->replaceValue(dataStream, response.m_valueLength, response.m_valueType);
|
|
|
|
m_data->m_userDataHandleLookup.insert(SharedMemoryUserDataHashKey(userData), response.m_userDataId);
|
|
|
|
(*bodyJointsPtr)->m_userDataIds.push_back(response.m_userDataId);
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 20:15:10 +00:00
|
|
|
void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd)
|
|
|
|
{
|
|
|
|
switch (serverCmd.m_type)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REQUEST_RAY_CAST_INTERSECTIONS_COMPLETED:
|
2016-12-27 03:40:09 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Raycast completed");
|
|
|
|
}
|
|
|
|
m_data->m_raycastHits.clear();
|
|
|
|
b3RayHitInfo* rayHits = (b3RayHitInfo*)m_data->m_bulletStreamDataServerToClient;
|
|
|
|
for (int i = 0; i < serverCmd.m_raycastHits.m_numRaycastHits; i++)
|
|
|
|
{
|
|
|
|
m_data->m_raycastHits.push_back(rayHits[i]);
|
|
|
|
}
|
|
|
|
break;
|
2016-12-27 03:40:09 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REQUEST_VR_EVENTS_DATA_COMPLETED:
|
2016-12-27 03:40:09 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Request VR Events completed");
|
|
|
|
}
|
|
|
|
m_data->m_cachedVREvents.resize(serverCmd.m_sendVREvents.m_numVRControllerEvents);
|
|
|
|
for (int i = 0; i < serverCmd.m_sendVREvents.m_numVRControllerEvents; i++)
|
|
|
|
{
|
|
|
|
m_data->m_cachedVREvents[i] = serverCmd.m_sendVREvents.m_controllerEvents[i];
|
|
|
|
}
|
|
|
|
break;
|
2016-12-27 03:40:09 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REQUEST_KEYBOARD_EVENTS_DATA_COMPLETED:
|
2016-12-27 03:40:09 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Request keyboard events completed");
|
|
|
|
}
|
|
|
|
m_data->m_cachedKeyboardEvents.resize(serverCmd.m_sendKeyboardEvents.m_numKeyboardEvents);
|
|
|
|
for (int i = 0; i < serverCmd.m_sendKeyboardEvents.m_numKeyboardEvents; i++)
|
|
|
|
{
|
|
|
|
m_data->m_cachedKeyboardEvents[i] = serverCmd.m_sendKeyboardEvents.m_keyboardEvents[i];
|
|
|
|
}
|
|
|
|
break;
|
2016-12-27 03:40:09 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
case CMD_REQUEST_MOUSE_EVENTS_DATA_COMPLETED:
|
2016-12-27 03:40:09 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
B3_PROFILE("CMD_REQUEST_MOUSE_EVENTS_DATA_COMPLETED");
|
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Request mouse events completed");
|
|
|
|
}
|
|
|
|
m_data->m_cachedMouseEvents.resize(serverCmd.m_sendMouseEvents.m_numMouseEvents);
|
|
|
|
for (int i = 0; i < serverCmd.m_sendMouseEvents.m_numMouseEvents; i++)
|
|
|
|
{
|
|
|
|
m_data->m_cachedMouseEvents[i] = serverCmd.m_sendMouseEvents.m_mouseEvents[i];
|
|
|
|
}
|
|
|
|
break;
|
2017-03-02 20:33:22 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
case CMD_REQUEST_INTERNAL_DATA_COMPLETED:
|
2017-03-02 20:33:22 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (serverCmd.m_numDataStreamBytes)
|
|
|
|
{
|
|
|
|
int numStreamBytes = serverCmd.m_numDataStreamBytes;
|
|
|
|
m_data->m_serverDNA.resize(numStreamBytes);
|
|
|
|
for (int i = 0; i < numStreamBytes; i++)
|
|
|
|
{
|
|
|
|
m_data->m_serverDNA[i] = m_data->m_bulletStreamDataServerToClient[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-03-02 20:33:22 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_RESET_SIMULATION_COMPLETED:
|
2017-03-02 20:33:22 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
resetData();
|
|
|
|
break;
|
2016-12-27 03:40:09 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_USER_CONSTRAINT_INFO_COMPLETED:
|
|
|
|
case CMD_USER_CONSTRAINT_COMPLETED:
|
2017-06-17 20:29:14 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int cid = serverCmd.m_userConstraintResultArgs.m_userConstraintUniqueId;
|
|
|
|
m_data->m_userConstraintInfoMap.insert(cid, serverCmd.m_userConstraintResultArgs);
|
|
|
|
break;
|
2017-06-17 20:29:14 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REMOVE_USER_CONSTRAINT_COMPLETED:
|
2017-06-17 20:29:14 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int cid = serverCmd.m_userConstraintResultArgs.m_userConstraintUniqueId;
|
|
|
|
m_data->m_userConstraintInfoMap.remove(cid);
|
|
|
|
break;
|
2017-06-17 20:29:14 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REMOVE_BODY_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("Remove body failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_REMOVE_BODY_COMPLETED:
|
2016-11-05 00:06:55 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < serverCmd.m_removeObjectArgs.m_numBodies; i++)
|
2016-11-05 00:06:55 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int bodyUniqueId = serverCmd.m_removeObjectArgs.m_bodyUniqueIds[i];
|
|
|
|
removeCachedBody(bodyUniqueId);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < serverCmd.m_removeObjectArgs.m_numUserConstraints; i++)
|
|
|
|
{
|
|
|
|
int key = serverCmd.m_removeObjectArgs.m_userConstraintUniqueIds[i];
|
|
|
|
m_data->m_userConstraintInfoMap.remove(key);
|
2016-11-05 00:06:55 +00:00
|
|
|
}
|
2016-12-31 22:43:15 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
2017-05-04 04:53:29 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_CHANGE_USER_CONSTRAINT_COMPLETED:
|
2017-05-04 20:14:24 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int cid = serverCmd.m_userConstraintResultArgs.m_userConstraintUniqueId;
|
|
|
|
b3UserConstraint* userConstraintPtr = m_data->m_userConstraintInfoMap[cid];
|
|
|
|
if (userConstraintPtr)
|
2017-01-23 03:08:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
const b3UserConstraint* serverConstraint = &serverCmd.m_userConstraintResultArgs;
|
|
|
|
if (serverCmd.m_updateFlags & USER_CONSTRAINT_CHANGE_PIVOT_IN_B)
|
|
|
|
{
|
2017-01-23 03:08:31 +00:00
|
|
|
userConstraintPtr->m_childFrame[0] = serverConstraint->m_childFrame[0];
|
|
|
|
userConstraintPtr->m_childFrame[1] = serverConstraint->m_childFrame[1];
|
|
|
|
userConstraintPtr->m_childFrame[2] = serverConstraint->m_childFrame[2];
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
if (serverCmd.m_updateFlags & USER_CONSTRAINT_CHANGE_FRAME_ORN_IN_B)
|
|
|
|
{
|
|
|
|
userConstraintPtr->m_childFrame[3] = serverConstraint->m_childFrame[3];
|
|
|
|
userConstraintPtr->m_childFrame[4] = serverConstraint->m_childFrame[4];
|
|
|
|
userConstraintPtr->m_childFrame[5] = serverConstraint->m_childFrame[5];
|
|
|
|
userConstraintPtr->m_childFrame[6] = serverConstraint->m_childFrame[6];
|
|
|
|
}
|
|
|
|
if (serverCmd.m_updateFlags & USER_CONSTRAINT_CHANGE_MAX_FORCE)
|
|
|
|
{
|
|
|
|
userConstraintPtr->m_maxAppliedForce = serverConstraint->m_maxAppliedForce;
|
|
|
|
}
|
|
|
|
if (serverCmd.m_updateFlags & USER_CONSTRAINT_CHANGE_GEAR_RATIO)
|
|
|
|
{
|
|
|
|
userConstraintPtr->m_gearRatio = serverConstraint->m_gearRatio;
|
|
|
|
}
|
|
|
|
if (serverCmd.m_updateFlags & USER_CONSTRAINT_CHANGE_RELATIVE_POSITION_TARGET)
|
|
|
|
{
|
|
|
|
userConstraintPtr->m_relativePositionTarget = serverConstraint->m_relativePositionTarget;
|
|
|
|
}
|
|
|
|
if (serverCmd.m_updateFlags & USER_CONSTRAINT_CHANGE_ERP)
|
|
|
|
{
|
|
|
|
userConstraintPtr->m_erp = serverConstraint->m_erp;
|
|
|
|
}
|
|
|
|
if (serverCmd.m_updateFlags & USER_CONSTRAINT_CHANGE_GEAR_AUX_LINK)
|
|
|
|
{
|
|
|
|
userConstraintPtr->m_gearAuxLink = serverConstraint->m_gearAuxLink;
|
|
|
|
}
|
2017-01-23 03:08:31 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_USER_CONSTRAINT_REQUEST_STATE_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SYNC_BODY_INFO_COMPLETED:
|
|
|
|
case CMD_MJCF_LOADING_COMPLETED:
|
|
|
|
case CMD_SDF_LOADING_COMPLETED:
|
|
|
|
{
|
|
|
|
//we'll stream further info from the physics server
|
|
|
|
//so serverCmd will be invalid, make a copy
|
|
|
|
|
2019-09-09 21:56:26 +00:00
|
|
|
btAlignedObjectArray<int> bodyIdArray;
|
|
|
|
btAlignedObjectArray<int> constraintIdArray;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int numConstraints = serverCmd.m_sdfLoadedArgs.m_numUserConstraints;
|
2019-09-09 21:56:26 +00:00
|
|
|
int numBodies = serverCmd.m_sdfLoadedArgs.m_numBodies;
|
|
|
|
|
|
|
|
bodyIdArray.reserve(numBodies);
|
|
|
|
constraintIdArray.reserve(numConstraints);
|
|
|
|
|
|
|
|
if (serverCmd.m_type == CMD_SYNC_BODY_INFO_COMPLETED)
|
|
|
|
{
|
|
|
|
clearCachedBodies();
|
|
|
|
const int* bodyIds = (int*)m_data->m_bulletStreamDataServerToClient;
|
|
|
|
const int* constaintIds = bodyIds + numBodies;
|
|
|
|
|
|
|
|
for (int i = 0; i < numConstraints; i++)
|
|
|
|
{
|
|
|
|
int constraintUid = constaintIds[i];
|
|
|
|
constraintIdArray.push_back(constraintUid);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < numBodies; i++)
|
|
|
|
{
|
|
|
|
int bodyUid = bodyIds[i];
|
|
|
|
bodyIdArray.push_back(bodyUid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numConstraints; i++)
|
|
|
|
{
|
|
|
|
int constraintUid = serverCmd.m_sdfLoadedArgs.m_userConstraintUniqueIds[i];
|
|
|
|
constraintIdArray.push_back(constraintUid);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < numBodies; i++)
|
|
|
|
{
|
|
|
|
int bodyUid = serverCmd.m_sdfLoadedArgs.m_bodyUniqueIds[i];
|
|
|
|
bodyIdArray.push_back(bodyUid);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numConstraints; i++)
|
2017-10-22 23:07:00 +00:00
|
|
|
{
|
2019-09-09 21:56:26 +00:00
|
|
|
int constraintUid = constraintIdArray[i];
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
m_data->m_tmpInfoRequestCommand.m_type = CMD_USER_CONSTRAINT;
|
|
|
|
m_data->m_tmpInfoRequestCommand.m_updateFlags = USER_CONSTRAINT_REQUEST_INFO;
|
|
|
|
m_data->m_tmpInfoRequestCommand.m_userConstraintArguments.m_userConstraintUniqueId = constraintUid;
|
|
|
|
|
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(m_data->m_tmpInfoRequestCommand, m_data->m_tmpInfoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
|
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
|
|
|
|
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
|
|
|
{
|
|
|
|
hasStatus = m_data->m_commandProcessor->receiveStatus(m_data->m_tmpInfoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
int cid = m_data->m_tmpInfoStatus.m_userConstraintResultArgs.m_userConstraintUniqueId;
|
|
|
|
m_data->m_userConstraintInfoMap.insert(cid, m_data->m_tmpInfoStatus.m_userConstraintResultArgs);
|
|
|
|
}
|
2017-10-22 23:07:00 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2019-09-09 21:56:26 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numBodies; i++)
|
2017-10-22 23:07:00 +00:00
|
|
|
{
|
2019-09-09 21:56:26 +00:00
|
|
|
int bodyUniqueId = bodyIdArray[i];
|
2016-11-04 20:15:10 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_tmpInfoRequestCommand.m_type = CMD_REQUEST_BODY_INFO;
|
|
|
|
m_data->m_tmpInfoRequestCommand.m_sdfRequestInfoArgs.m_bodyUniqueId = bodyUniqueId;
|
2017-01-23 03:08:31 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(m_data->m_tmpInfoRequestCommand, m_data->m_tmpInfoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
2017-02-22 17:33:30 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
|
|
|
{
|
|
|
|
hasStatus = m_data->m_commandProcessor->receiveStatus(m_data->m_tmpInfoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
}
|
2017-01-23 03:08:31 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
processBodyJointInfo(bodyUniqueId, m_data->m_tmpInfoStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CREATE_MULTI_BODY_COMPLETED:
|
|
|
|
case CMD_URDF_LOADING_COMPLETED:
|
|
|
|
{
|
|
|
|
if (serverCmd.m_numDataStreamBytes > 0)
|
2017-01-23 03:08:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int bodyIndex = serverCmd.m_dataStreamArguments.m_bodyUniqueId;
|
|
|
|
processBodyJointInfo(bodyIndex, serverCmd);
|
2017-01-23 03:08:31 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
2017-01-23 03:08:31 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_BULLET_LOADING_FAILED:
|
2016-11-04 20:15:10 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Warning("Couldn't load .bullet file");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_BULLET_LOADING_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-11-04 20:15:10 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REQUEST_OPENGL_VISUALIZER_CAMERA_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-02-22 17:33:30 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REQUEST_OPENGL_VISUALIZER_CAMERA_FAILED:
|
|
|
|
{
|
2020-05-05 03:15:26 +00:00
|
|
|
//b3Warning("requestOpenGLVisualizeCamera failed");
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_REMOVE_USER_CONSTRAINT_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("removeConstraint failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CHANGE_USER_CONSTRAINT_FAILED:
|
|
|
|
{
|
|
|
|
//b3Warning("changeConstraint failed");
|
|
|
|
break;
|
|
|
|
}
|
2016-11-04 20:15:10 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_USER_CONSTRAINT_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("createConstraint failed");
|
|
|
|
break;
|
2016-11-04 20:15:10 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_CREATE_COLLISION_SHAPE_FAILED:
|
2016-11-04 20:15:10 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Warning("createCollisionShape failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CREATE_COLLISION_SHAPE_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
2016-11-04 20:15:10 +00:00
|
|
|
}
|
2017-04-10 18:03:41 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_CREATE_VISUAL_SHAPE_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("createVisualShape failed");
|
|
|
|
break;
|
|
|
|
}
|
2019-06-18 00:32:01 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_CREATE_VISUAL_SHAPE_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 03:08:31 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_CREATE_MULTI_BODY_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("createMultiBody failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_REQUEST_COLLISION_INFO_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_REQUEST_COLLISION_INFO_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("Request getCollisionInfo failed");
|
|
|
|
break;
|
|
|
|
}
|
2019-06-18 00:32:01 +00:00
|
|
|
case CMD_REQUEST_MESH_DATA_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_REQUEST_MESH_DATA_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("Request mesh data failed");
|
|
|
|
break;
|
|
|
|
}
|
2020-10-07 03:19:39 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_CUSTOM_COMMAND_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("custom plugin command failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CLIENT_COMMAND_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CALCULATED_JACOBIAN_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CALCULATED_JACOBIAN_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("jacobian calculation failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CALCULATED_MASS_MATRIX_FAILED:
|
2017-10-05 15:23:10 +00:00
|
|
|
{
|
|
|
|
b3Warning("calculate mass matrix failed");
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_CALCULATED_MASS_MATRIX_COMPLETED:
|
2017-10-05 15:23:10 +00:00
|
|
|
{
|
|
|
|
double* matrixData = (double*)&m_data->m_bulletStreamDataServerToClient[0];
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_cachedMassMatrix.resize(serverCmd.m_massMatrixResultArgs.m_dofCount * serverCmd.m_massMatrixResultArgs.m_dofCount);
|
|
|
|
for (int i = 0; i < serverCmd.m_massMatrixResultArgs.m_dofCount * serverCmd.m_massMatrixResultArgs.m_dofCount; i++)
|
2017-10-05 15:23:10 +00:00
|
|
|
{
|
|
|
|
m_data->m_cachedMassMatrix[i] = matrixData[i];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_ACTUAL_STATE_UPDATE_COMPLETED:
|
2017-09-26 17:05:17 +00:00
|
|
|
{
|
2019-03-07 07:27:59 +00:00
|
|
|
SendActualStateSharedMemoryStorage* serverState = (SendActualStateSharedMemoryStorage*)&m_data->m_bulletStreamDataServerToClient[0];
|
|
|
|
m_data->m_cachedState = *serverState;
|
|
|
|
m_data->m_serverStatus.m_sendActualStateArgs.m_stateDetails = &m_data->m_cachedState;
|
2017-09-26 17:05:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_DESIRED_STATE_RECEIVED_COMPLETED:
|
2017-09-26 17:05:17 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_STEP_FORWARD_SIMULATION_COMPLETED:
|
2017-09-26 17:05:17 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2021-03-26 17:31:13 +00:00
|
|
|
case CMD_PERFORM_COLLISION_DETECTION_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REQUEST_PHYSICS_SIMULATION_PARAMETERS_COMPLETED:
|
2017-10-05 18:43:14 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_SAVE_STATE_COMPLETED:
|
2018-01-04 03:17:28 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
2018-01-04 03:17:28 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_COLLISION_SHAPE_INFO_FAILED:
|
2018-01-04 03:17:28 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Warning("getCollisionShapeData failed");
|
|
|
|
break;
|
2018-01-04 03:17:28 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_COLLISION_SHAPE_INFO_COMPLETED:
|
2018-06-04 13:10:48 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
B3_PROFILE("CMD_COLLISION_SHAPE_INFO_COMPLETED");
|
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Collision Shape Information Request OK\n");
|
|
|
|
}
|
|
|
|
int numCollisionShapesCopied = serverCmd.m_sendCollisionShapeArgs.m_numCollisionShapes;
|
|
|
|
m_data->m_cachedCollisionShapes.resize(numCollisionShapesCopied);
|
|
|
|
b3CollisionShapeData* shapeData = (b3CollisionShapeData*)&m_data->m_bulletStreamDataServerToClient[0];
|
|
|
|
for (int i = 0; i < numCollisionShapesCopied; i++)
|
2018-06-04 13:10:48 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_cachedCollisionShapes[i] = shapeData[i];
|
2018-06-04 13:10:48 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_RESTORE_STATE_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("restoreState failed");
|
|
|
|
break;
|
2018-06-04 13:10:48 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_RESTORE_STATE_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_BULLET_SAVING_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_LOAD_SOFT_BODY_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("loadSoftBody failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_LOAD_SOFT_BODY_COMPLETED:
|
|
|
|
{
|
2019-04-25 22:18:25 +00:00
|
|
|
int bodyUniqueId = serverCmd.m_loadSoftBodyResultArguments.m_objectUniqueId;
|
|
|
|
BodyJointInfoCache2* bodyJoints = new BodyJointInfoCache2;
|
|
|
|
m_data->m_bodyJointMap.insert(bodyUniqueId, bodyJoints);
|
|
|
|
bodyJoints->m_bodyName = serverCmd.m_dataStreamArguments.m_bodyName;
|
2019-10-22 22:14:47 +00:00
|
|
|
bodyJoints->m_baseName = serverCmd.m_dataStreamArguments.m_bodyName;
|
2019-04-25 22:18:25 +00:00
|
|
|
break;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
case CMD_SYNC_USER_DATA_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("Synchronizing user data failed.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_ADD_USER_DATA_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("Adding user data failed (do the specified body and link exist?)");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_REMOVE_USER_DATA_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("Removing user data failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_ADD_USER_DATA_COMPLETED:
|
|
|
|
{
|
|
|
|
processAddUserData(serverCmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SYNC_USER_DATA_COMPLETED:
|
|
|
|
{
|
|
|
|
B3_PROFILE("CMD_SYNC_USER_DATA_COMPLETED");
|
2020-02-03 14:24:12 +00:00
|
|
|
if (serverCmd.m_syncUserDataArgs.m_clearCachedUserDataEntries) {
|
|
|
|
// Remove all cached user data entries.
|
|
|
|
m_data->m_userDataMap.clear();
|
|
|
|
m_data->m_userDataHandleLookup.clear();
|
|
|
|
for (int i = 0; i < m_data->m_bodyJointMap.size(); i++)
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
2020-02-03 14:24:12 +00:00
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i);
|
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
|
|
|
(*bodyJointsPtr)->m_userDataIds.clear();
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const int numIdentifiers = serverCmd.m_syncUserDataArgs.m_numUserDataIdentifiers;
|
|
|
|
int* identifiers = new int[numIdentifiers];
|
|
|
|
memcpy(identifiers, &m_data->m_bulletStreamDataServerToClient[0], numIdentifiers * sizeof(int));
|
2018-06-02 20:40:08 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numIdentifiers; i++)
|
|
|
|
{
|
|
|
|
m_data->m_tmpInfoRequestCommand.m_type = CMD_REQUEST_USER_DATA;
|
|
|
|
m_data->m_tmpInfoRequestCommand.m_userDataRequestArgs.m_userDataId = identifiers[i];
|
2018-06-02 20:40:08 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(m_data->m_tmpInfoRequestCommand, m_data->m_tmpInfoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
2018-06-02 20:40:08 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
2018-06-02 20:40:08 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
|
|
|
{
|
|
|
|
hasStatus = m_data->m_commandProcessor->receiveStatus(m_data->m_tmpInfoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
}
|
2018-06-02 20:40:08 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
processAddUserData(m_data->m_tmpInfoStatus);
|
|
|
|
}
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
delete[] identifiers;
|
|
|
|
break;
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REMOVE_USER_DATA_COMPLETED:
|
|
|
|
{
|
|
|
|
const int userDataId = serverCmd.m_removeUserDataResponseArgs.m_userDataId;
|
|
|
|
SharedMemoryUserData* userData = m_data->m_userDataMap[userDataId];
|
|
|
|
if (userData)
|
|
|
|
{
|
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[userData->m_bodyUniqueId];
|
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
|
|
|
(*bodyJointsPtr)->m_userDataIds.remove(userDataId);
|
|
|
|
}
|
|
|
|
m_data->m_userDataHandleLookup.remove(SharedMemoryUserDataHashKey(userData));
|
|
|
|
m_data->m_userDataMap.remove(userDataId);
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-09-03 00:27:05 +00:00
|
|
|
case CMD_RESET_MESH_DATA_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_RESET_MESH_DATA_FAILED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2019-04-04 03:06:40 +00:00
|
|
|
case CMD_REMOVE_STATE_FAILED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_REMOVE_STATE_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2020-10-07 03:19:39 +00:00
|
|
|
case CMD_CUSTOM_COMMAND_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
//b3Warning("Unknown server status type");
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
2020-10-07 03:19:39 +00:00
|
|
|
|
2016-11-04 20:15:10 +00:00
|
|
|
};
|
|
|
|
}
|
2020-10-07 17:12:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool PhysicsDirect::processCustomCommand(const struct SharedMemoryCommand& orgCommand)
|
|
|
|
{
|
|
|
|
SharedMemoryCommand command = orgCommand;
|
|
|
|
|
|
|
|
const SharedMemoryStatus& serverCmd = m_data->m_serverStatus;
|
|
|
|
|
|
|
|
int remaining = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
|
|
|
|
b3Clock clock;
|
|
|
|
double startTime = clock.getTimeInSeconds();
|
|
|
|
double timeOutInSeconds = m_data->m_timeOutInSeconds;
|
|
|
|
|
|
|
|
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
|
|
|
{
|
|
|
|
const SharedMemoryStatus* stat = processServerStatus();
|
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
hasStatus = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_data->m_hasStatus = hasStatus;
|
|
|
|
|
|
|
|
if (hasStatus)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Success receiving %d return data\n",
|
|
|
|
serverCmd.m_numDataStreamBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
btAssert(m_data->m_serverStatus.m_type == CMD_CUSTOM_COMMAND_COMPLETED);
|
|
|
|
|
|
|
|
if (m_data->m_serverStatus.m_type == CMD_CUSTOM_COMMAND_COMPLETED)
|
|
|
|
{
|
|
|
|
m_data->m_cachedReturnData.resize(serverCmd.m_customCommandResultArgs.m_returnDataSizeInBytes);
|
|
|
|
m_data->m_cachedReturnDataValue.m_length = serverCmd.m_customCommandResultArgs.m_returnDataSizeInBytes;
|
|
|
|
|
|
|
|
if (serverCmd.m_customCommandResultArgs.m_returnDataSizeInBytes)
|
|
|
|
{
|
|
|
|
m_data->m_cachedReturnDataValue.m_type = serverCmd.m_customCommandResultArgs.m_returnDataType;
|
|
|
|
m_data->m_cachedReturnDataValue.m_data1 = &m_data->m_cachedReturnData[0];
|
|
|
|
for (int i = 0; i < serverCmd.m_numDataStreamBytes; i++)
|
|
|
|
{
|
|
|
|
m_data->m_cachedReturnData[i+ serverCmd.m_customCommandResultArgs.m_returnDataStart] = m_data->m_bulletStreamDataServerToClient[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int totalReceived = serverCmd.m_numDataStreamBytes + serverCmd.m_customCommandResultArgs.m_returnDataStart;
|
|
|
|
remaining = serverCmd.m_customCommandResultArgs.m_returnDataSizeInBytes - totalReceived;
|
|
|
|
|
|
|
|
if (remaining > 0)
|
|
|
|
{
|
|
|
|
m_data->m_hasStatus = false;
|
|
|
|
command.m_type = CMD_CUSTOM_COMMAND;
|
|
|
|
command.m_customCommandArgs.m_startingReturnBytes =
|
|
|
|
totalReceived;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (remaining > 0);
|
|
|
|
|
|
|
|
return m_data->m_hasStatus;
|
|
|
|
}
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
bool PhysicsDirect::submitClientCommand(const struct SharedMemoryCommand& command)
|
|
|
|
{
|
2020-10-07 17:12:02 +00:00
|
|
|
if (command.m_type == CMD_CUSTOM_COMMAND)
|
|
|
|
{
|
|
|
|
return processCustomCommand(command);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (command.m_type == CMD_REQUEST_DEBUG_LINES)
|
|
|
|
{
|
2015-11-23 04:50:32 +00:00
|
|
|
return processDebugLines(command);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (command.m_type == CMD_REQUEST_CAMERA_IMAGE_DATA)
|
2016-06-04 02:03:56 +00:00
|
|
|
{
|
|
|
|
return processCamera(command);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (command.m_type == CMD_REQUEST_CONTACT_POINT_INFORMATION)
|
|
|
|
{
|
|
|
|
return processContactPointData(command);
|
|
|
|
}
|
2016-06-04 02:03:56 +00:00
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
if (command.m_type == CMD_REQUEST_VISUAL_SHAPE_INFO)
|
|
|
|
{
|
|
|
|
return processVisualShapeData(command);
|
|
|
|
}
|
2016-11-10 19:22:22 +00:00
|
|
|
if (command.m_type == CMD_REQUEST_AABB_OVERLAP)
|
|
|
|
{
|
|
|
|
return processOverlappingObjects(command);
|
|
|
|
}
|
2016-10-19 05:05:28 +00:00
|
|
|
|
2019-06-18 00:32:01 +00:00
|
|
|
if (command.m_type == CMD_REQUEST_MESH_DATA)
|
|
|
|
{
|
|
|
|
return processMeshData(command);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
2015-11-23 04:50:32 +00:00
|
|
|
m_data->m_hasStatus = hasStatus;
|
2018-07-24 12:12:16 +00:00
|
|
|
|
|
|
|
if (m_data->m_ownsCommandProcessor)
|
|
|
|
{
|
2018-09-04 06:13:15 +00:00
|
|
|
m_data->m_commandProcessor->reportNotifications();
|
2018-07-24 12:12:16 +00:00
|
|
|
}
|
2017-01-23 03:08:31 +00:00
|
|
|
/*if (hasStatus)
|
2015-11-23 04:50:32 +00:00
|
|
|
{
|
2016-11-04 20:15:10 +00:00
|
|
|
postProcessStatus(m_data->m_serverStatus);
|
2017-01-23 03:08:31 +00:00
|
|
|
m_data->m_hasStatus = false;
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
2017-01-23 03:08:31 +00:00
|
|
|
*/
|
2015-11-23 04:50:32 +00:00
|
|
|
return hasStatus;
|
|
|
|
}
|
|
|
|
|
2016-09-27 19:13:45 +00:00
|
|
|
int PhysicsDirect::getNumBodies() const
|
|
|
|
{
|
|
|
|
return m_data->m_bodyJointMap.size();
|
|
|
|
}
|
|
|
|
|
2017-05-04 04:53:29 +00:00
|
|
|
void PhysicsDirect::removeCachedBody(int bodyUniqueId)
|
|
|
|
{
|
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[bodyUniqueId];
|
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < (*bodyJointsPtr)->m_userDataIds.size(); i++)
|
|
|
|
{
|
2018-07-03 15:45:19 +00:00
|
|
|
const int userDataId = (*bodyJointsPtr)->m_userDataIds[i];
|
2018-09-23 21:17:31 +00:00
|
|
|
SharedMemoryUserData* userData = m_data->m_userDataMap[userDataId];
|
2018-07-03 15:45:19 +00:00
|
|
|
m_data->m_userDataHandleLookup.remove(SharedMemoryUserDataHashKey(userData));
|
|
|
|
m_data->m_userDataMap.remove(userDataId);
|
|
|
|
}
|
2017-05-04 04:53:29 +00:00
|
|
|
delete (*bodyJointsPtr);
|
|
|
|
m_data->m_bodyJointMap.remove(bodyUniqueId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 03:08:31 +00:00
|
|
|
int PhysicsDirect::getNumUserConstraints() const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return m_data->m_userConstraintInfoMap.size();
|
2017-01-23 03:08:31 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int PhysicsDirect::getUserConstraintInfo(int constraintUniqueId, struct b3UserConstraint& info) const
|
2017-01-23 03:08:31 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3UserConstraint* constraintPtr = m_data->m_userConstraintInfoMap[constraintUniqueId];
|
|
|
|
if (constraintPtr)
|
|
|
|
{
|
|
|
|
info = *constraintPtr;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2017-01-23 03:08:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 01:25:25 +00:00
|
|
|
int PhysicsDirect::getUserConstraintId(int serialIndex) const
|
|
|
|
{
|
|
|
|
if ((serialIndex >= 0) && (serialIndex < getNumUserConstraints()))
|
|
|
|
{
|
|
|
|
return m_data->m_userConstraintInfoMap.getKeyAtIndex(serialIndex).getUid1();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-27 19:13:45 +00:00
|
|
|
|
|
|
|
int PhysicsDirect::getBodyUniqueId(int serialIndex) const
|
|
|
|
{
|
|
|
|
if ((serialIndex >= 0) && (serialIndex < getNumBodies()))
|
|
|
|
{
|
|
|
|
return m_data->m_bodyJointMap.getKeyAtIndex(serialIndex).getUid1();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhysicsDirect::getBodyInfo(int bodyUniqueId, struct b3BodyInfo& info) const
|
|
|
|
{
|
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[bodyUniqueId];
|
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
|
|
|
BodyJointInfoCache2* bodyJoints = *bodyJointsPtr;
|
2018-09-23 21:17:31 +00:00
|
|
|
strcpy(info.m_baseName, bodyJoints->m_baseName.c_str());
|
|
|
|
strcpy(info.m_bodyName, bodyJoints->m_bodyName.c_str());
|
2016-09-27 19:13:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-09-27 19:13:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:07:55 +00:00
|
|
|
int PhysicsDirect::getNumJoints(int bodyUniqueId) const
|
2015-11-23 04:50:32 +00:00
|
|
|
{
|
2019-03-26 22:07:55 +00:00
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[bodyUniqueId];
|
2015-11-23 04:50:32 +00:00
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
|
|
|
BodyJointInfoCache2* bodyJoints = *bodyJointsPtr;
|
2018-09-23 21:17:31 +00:00
|
|
|
return bodyJoints->m_jointInfo.size();
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
btAssert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:07:55 +00:00
|
|
|
int PhysicsDirect::getNumDofs(int bodyUniqueId) const
|
|
|
|
{
|
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[bodyUniqueId];
|
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
|
|
|
BodyJointInfoCache2* bodyJoints = *bodyJointsPtr;
|
|
|
|
return bodyJoints->m_numDofs;
|
|
|
|
}
|
|
|
|
btAssert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-16 01:01:41 +00:00
|
|
|
bool PhysicsDirect::getJointInfo(int bodyIndex, int jointIndex, struct b3JointInfo& info) const
|
2015-11-23 04:50:32 +00:00
|
|
|
{
|
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[bodyIndex];
|
|
|
|
if (bodyJointsPtr && *bodyJointsPtr)
|
|
|
|
{
|
|
|
|
BodyJointInfoCache2* bodyJoints = *bodyJointsPtr;
|
2018-09-23 21:17:31 +00:00
|
|
|
if ((jointIndex >= 0) && (jointIndex < bodyJoints->m_jointInfo.size()))
|
|
|
|
{
|
|
|
|
info = bodyJoints->m_jointInfo[jointIndex];
|
2018-11-10 22:26:31 +00:00
|
|
|
info.m_qSize = 0;
|
|
|
|
info.m_uSize = 0;
|
|
|
|
|
|
|
|
switch (info.m_jointType)
|
|
|
|
{
|
|
|
|
case eSphericalType:
|
|
|
|
{
|
|
|
|
info.m_qSize = 4;//quaterion x,y,z,w
|
|
|
|
info.m_uSize = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ePlanarType:
|
|
|
|
{
|
|
|
|
info.m_qSize = 2;
|
|
|
|
info.m_uSize = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ePrismaticType:
|
|
|
|
case eRevoluteType:
|
|
|
|
{
|
|
|
|
info.m_qSize = 1;
|
|
|
|
info.m_uSize = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
return false;
|
2015-11-23 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsDirect::setSharedMemoryKey(int key)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsDirect::uploadBulletFileToSharedMemory(const char* data, int len)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (len > SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE)
|
2017-07-01 02:11:43 +00:00
|
|
|
{
|
|
|
|
len = SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < len; i++)
|
2017-07-01 02:11:43 +00:00
|
|
|
{
|
|
|
|
m_data->m_bulletStreamDataServerToClient[i] = data[i];
|
|
|
|
}
|
2015-11-23 04:50:32 +00:00
|
|
|
//m_data->m_physicsClient->uploadBulletFileToSharedMemory(data,len);
|
|
|
|
}
|
|
|
|
|
2018-06-16 15:14:00 +00:00
|
|
|
void PhysicsDirect::uploadRaysToSharedMemory(struct SharedMemoryCommand& command, const double* rayFromWorldArray, const double* rayToWorldArray, int numRays)
|
|
|
|
{
|
2018-06-16 19:28:21 +00:00
|
|
|
int curNumStreamingRays = command.m_requestRaycastIntersections.m_numStreamingRays;
|
|
|
|
int newNumRays = curNumStreamingRays + numRays;
|
2018-09-23 21:17:31 +00:00
|
|
|
btAssert(newNumRays < MAX_RAY_INTERSECTION_BATCH_SIZE_STREAMING);
|
2018-06-16 15:14:00 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (newNumRays < MAX_RAY_INTERSECTION_BATCH_SIZE_STREAMING)
|
2018-06-16 15:14:00 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numRays; i++)
|
|
|
|
{
|
|
|
|
b3RayData* rayDataStream = (b3RayData*)m_data->m_bulletStreamDataServerToClient;
|
|
|
|
rayDataStream[curNumStreamingRays + i].m_rayFromPosition[0] = rayFromWorldArray[i * 3 + 0];
|
|
|
|
rayDataStream[curNumStreamingRays + i].m_rayFromPosition[1] = rayFromWorldArray[i * 3 + 1];
|
|
|
|
rayDataStream[curNumStreamingRays + i].m_rayFromPosition[2] = rayFromWorldArray[i * 3 + 2];
|
|
|
|
rayDataStream[curNumStreamingRays + i].m_rayToPosition[0] = rayToWorldArray[i * 3 + 0];
|
|
|
|
rayDataStream[curNumStreamingRays + i].m_rayToPosition[1] = rayToWorldArray[i * 3 + 1];
|
|
|
|
rayDataStream[curNumStreamingRays + i].m_rayToPosition[2] = rayToWorldArray[i * 3 + 2];
|
2018-06-16 19:28:21 +00:00
|
|
|
command.m_requestRaycastIntersections.m_numStreamingRays++;
|
2018-06-16 15:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-23 04:50:32 +00:00
|
|
|
int PhysicsDirect::getNumDebugLines() const
|
|
|
|
{
|
|
|
|
return m_data->m_debugLinesFrom.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const float* PhysicsDirect::getDebugLinesFrom() const
|
|
|
|
{
|
|
|
|
if (getNumDebugLines())
|
|
|
|
{
|
|
|
|
return &m_data->m_debugLinesFrom[0].m_x;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const float* PhysicsDirect::getDebugLinesTo() const
|
|
|
|
{
|
|
|
|
if (getNumDebugLines())
|
|
|
|
{
|
|
|
|
return &m_data->m_debugLinesTo[0].m_x;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const float* PhysicsDirect::getDebugLinesColor() const
|
|
|
|
{
|
|
|
|
if (getNumDebugLines())
|
|
|
|
{
|
|
|
|
return &m_data->m_debugLinesColor[0].m_x;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-31 17:23:04 +00:00
|
|
|
|
|
|
|
void PhysicsDirect::getCachedCameraImage(b3CameraImageData* cameraData)
|
|
|
|
{
|
|
|
|
if (cameraData)
|
|
|
|
{
|
2016-06-04 02:03:56 +00:00
|
|
|
cameraData->m_pixelWidth = m_data->m_cachedCameraPixelsWidth;
|
|
|
|
cameraData->m_pixelHeight = m_data->m_cachedCameraPixelsHeight;
|
2016-08-12 20:55:37 +00:00
|
|
|
cameraData->m_depthValues = m_data->m_cachedCameraDepthBuffer.size() ? &m_data->m_cachedCameraDepthBuffer[0] : 0;
|
2016-06-04 02:03:56 +00:00
|
|
|
cameraData->m_rgbColorData = m_data->m_cachedCameraPixelsRGBA.size() ? &m_data->m_cachedCameraPixelsRGBA[0] : 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
cameraData->m_segmentationMaskValues = m_data->m_cachedSegmentationMask.size() ? &m_data->m_cachedSegmentationMask[0] : 0;
|
2016-05-31 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
|
2019-06-18 04:43:38 +00:00
|
|
|
void PhysicsDirect::getCachedMeshData(struct b3MeshData* meshData)
|
|
|
|
{
|
|
|
|
m_data->m_cachedMeshData.m_numVertices = m_data->m_cachedVertexPositions.size();
|
|
|
|
|
|
|
|
m_data->m_cachedMeshData.m_vertices = m_data->m_cachedMeshData.m_numVertices ? &m_data->m_cachedVertexPositions[0] : 0;
|
|
|
|
|
|
|
|
*meshData = m_data->m_cachedMeshData;
|
2019-06-18 00:32:01 +00:00
|
|
|
}
|
2019-06-18 04:43:38 +00:00
|
|
|
|
2016-09-01 20:30:07 +00:00
|
|
|
void PhysicsDirect::getCachedContactPointInformation(struct b3ContactInformation* contactPointData)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
contactPointData->m_numContactPoints = m_data->m_cachedContactPoints.size();
|
|
|
|
contactPointData->m_contactPointData = contactPointData->m_numContactPoints ? &m_data->m_cachedContactPoints[0] : 0;
|
2016-09-01 20:30:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 19:22:22 +00:00
|
|
|
void PhysicsDirect::getCachedOverlappingObjects(struct b3AABBOverlapData* overlappingObjects)
|
|
|
|
{
|
|
|
|
overlappingObjects->m_numOverlappingObjects = m_data->m_cachedOverlappingObjects.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
overlappingObjects->m_overlappingObjects = m_data->m_cachedOverlappingObjects.size() ? &m_data->m_cachedOverlappingObjects[0] : 0;
|
2016-11-10 19:22:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
void PhysicsDirect::getCachedVisualShapeInformation(struct b3VisualShapeInformation* visualShapesInfo)
|
|
|
|
{
|
|
|
|
visualShapesInfo->m_numVisualShapes = m_data->m_cachedVisualShapes.size();
|
|
|
|
visualShapesInfo->m_visualShapeData = visualShapesInfo->m_numVisualShapes ? &m_data->m_cachedVisualShapes[0] : 0;
|
|
|
|
}
|
2016-12-27 03:40:09 +00:00
|
|
|
|
2018-01-04 03:17:28 +00:00
|
|
|
void PhysicsDirect::getCachedCollisionShapeInformation(struct b3CollisionShapeInformation* collisionShapesInfo)
|
|
|
|
{
|
|
|
|
collisionShapesInfo->m_numCollisionShapes = m_data->m_cachedCollisionShapes.size();
|
|
|
|
collisionShapesInfo->m_collisionShapeData = collisionShapesInfo->m_numCollisionShapes ? &m_data->m_cachedCollisionShapes[0] : 0;
|
|
|
|
}
|
|
|
|
|
2016-12-27 03:40:09 +00:00
|
|
|
void PhysicsDirect::getCachedVREvents(struct b3VREventsData* vrEventsData)
|
|
|
|
{
|
|
|
|
vrEventsData->m_numControllerEvents = m_data->m_cachedVREvents.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
vrEventsData->m_controllerEvents = vrEventsData->m_numControllerEvents ? &m_data->m_cachedVREvents[0] : 0;
|
2016-12-27 03:40:09 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 20:33:22 +00:00
|
|
|
void PhysicsDirect::getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData)
|
|
|
|
{
|
|
|
|
keyboardEventsData->m_numKeyboardEvents = m_data->m_cachedKeyboardEvents.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
keyboardEventsData->m_keyboardEvents = keyboardEventsData->m_numKeyboardEvents ? &m_data->m_cachedKeyboardEvents[0] : 0;
|
2017-03-02 20:33:22 +00:00
|
|
|
}
|
|
|
|
|
2017-06-17 20:29:14 +00:00
|
|
|
void PhysicsDirect::getCachedMouseEvents(struct b3MouseEventsData* mouseEventsData)
|
|
|
|
{
|
|
|
|
mouseEventsData->m_numMouseEvents = m_data->m_cachedMouseEvents.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
mouseEventsData->m_mouseEvents = mouseEventsData->m_numMouseEvents ? &m_data->m_cachedMouseEvents[0] : 0;
|
2017-06-17 20:29:14 +00:00
|
|
|
}
|
|
|
|
|
2016-12-27 03:40:09 +00:00
|
|
|
void PhysicsDirect::getCachedRaycastHits(struct b3RaycastInformation* raycastHits)
|
|
|
|
{
|
|
|
|
raycastHits->m_numRayHits = m_data->m_raycastHits.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
raycastHits->m_rayHits = raycastHits->m_numRayHits ? &m_data->m_raycastHits[0] : 0;
|
2016-12-27 03:40:09 +00:00
|
|
|
}
|
2017-02-24 23:34:11 +00:00
|
|
|
|
2017-10-05 15:23:10 +00:00
|
|
|
void PhysicsDirect::getCachedMassMatrix(int dofCountCheck, double* massMatrix)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int sz = dofCountCheck * dofCountCheck;
|
2017-10-05 15:23:10 +00:00
|
|
|
if (sz == m_data->m_cachedMassMatrix.size())
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < sz; i++)
|
2017-10-05 15:23:10 +00:00
|
|
|
{
|
|
|
|
massMatrix[i] = m_data->m_cachedMassMatrix[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 03:19:39 +00:00
|
|
|
bool PhysicsDirect::getCachedReturnData(b3UserDataValue* returnData)
|
|
|
|
{
|
|
|
|
if (m_data->m_cachedReturnDataValue.m_length)
|
|
|
|
{
|
|
|
|
*returnData = m_data->m_cachedReturnDataValue;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-24 23:34:11 +00:00
|
|
|
void PhysicsDirect::setTimeOut(double timeOutInSeconds)
|
|
|
|
{
|
|
|
|
m_data->m_timeOutInSeconds = timeOutInSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
double PhysicsDirect::getTimeOut() const
|
|
|
|
{
|
|
|
|
return m_data->m_timeOutInSeconds;
|
2017-03-16 23:09:55 +00:00
|
|
|
}
|
2018-06-02 20:40:08 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool PhysicsDirect::getCachedUserData(int userDataId, struct b3UserDataValue& valueOut) const
|
|
|
|
{
|
|
|
|
SharedMemoryUserData* userDataPtr = m_data->m_userDataMap[userDataId];
|
|
|
|
if (!userDataPtr)
|
2018-06-02 20:40:08 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-03 15:45:19 +00:00
|
|
|
valueOut.m_type = (userDataPtr)->m_type;
|
2018-06-02 20:40:08 +00:00
|
|
|
valueOut.m_length = userDataPtr->m_bytes.size();
|
2018-09-23 21:17:31 +00:00
|
|
|
valueOut.m_data1 = userDataPtr->m_bytes.size() ? &userDataPtr->m_bytes[0] : 0;
|
2018-06-02 20:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int PhysicsDirect::getCachedUserDataId(int bodyUniqueId, int linkIndex, int visualShapeIndex, const char* key) const
|
|
|
|
{
|
2018-07-03 15:45:19 +00:00
|
|
|
int* userDataId = m_data->m_userDataHandleLookup.find(SharedMemoryUserDataHashKey(key, bodyUniqueId, linkIndex, visualShapeIndex));
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!userDataId)
|
|
|
|
{
|
2018-06-02 20:40:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return *userDataId;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int PhysicsDirect::getNumUserData(int bodyUniqueId) const
|
|
|
|
{
|
2018-06-02 20:40:08 +00:00
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[bodyUniqueId];
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!bodyJointsPtr || !(*bodyJointsPtr))
|
|
|
|
{
|
2018-06-02 20:40:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-07-03 15:45:19 +00:00
|
|
|
return (*bodyJointsPtr)->m_userDataIds.size();
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void PhysicsDirect::getUserDataInfo(int bodyUniqueId, int userDataIndex, const char** keyOut, int* userDataIdOut, int* linkIndexOut, int* visualShapeIndexOut) const
|
|
|
|
{
|
2018-06-02 20:40:08 +00:00
|
|
|
BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap[bodyUniqueId];
|
2019-05-06 14:26:46 +00:00
|
|
|
if (!bodyJointsPtr || !(*bodyJointsPtr) || userDataIndex < 0 || userDataIndex > (*bodyJointsPtr)->m_userDataIds.size())
|
2018-06-02 20:40:08 +00:00
|
|
|
{
|
|
|
|
*keyOut = 0;
|
|
|
|
*userDataIdOut = -1;
|
|
|
|
return;
|
|
|
|
}
|
2018-07-03 15:45:19 +00:00
|
|
|
int userDataId = (*bodyJointsPtr)->m_userDataIds[userDataIndex];
|
2018-09-23 21:17:31 +00:00
|
|
|
SharedMemoryUserData* userData = m_data->m_userDataMap[userDataId];
|
2018-07-03 15:45:19 +00:00
|
|
|
|
|
|
|
*userDataIdOut = userDataId;
|
|
|
|
*keyOut = userData->m_key.c_str();
|
|
|
|
*linkIndexOut = userData->m_linkIndex;
|
|
|
|
*visualShapeIndexOut = userData->m_visualShapeIndex;
|
2018-06-02 20:40:08 +00:00
|
|
|
}
|
2018-06-16 13:19:49 +00:00
|
|
|
|
|
|
|
void PhysicsDirect::pushProfileTiming(const char* timingName)
|
|
|
|
{
|
2018-06-16 16:37:53 +00:00
|
|
|
std::string** strPtr = m_data->m_profileTimingStringArray[timingName];
|
|
|
|
std::string* str = 0;
|
|
|
|
if (strPtr)
|
|
|
|
{
|
|
|
|
str = *strPtr;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2018-06-16 16:37:53 +00:00
|
|
|
{
|
|
|
|
str = new std::string(timingName);
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_profileTimingStringArray.insert(timingName, str);
|
|
|
|
}
|
2018-06-16 13:19:49 +00:00
|
|
|
m_data->m_profileTimings.push_back(new CProfileSample(str->c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsDirect::popProfileTiming()
|
|
|
|
{
|
|
|
|
if (m_data->m_profileTimings.size())
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
CProfileSample* sample = m_data->m_profileTimings[m_data->m_profileTimings.size() - 1];
|
2018-06-16 13:19:49 +00:00
|
|
|
m_data->m_profileTimings.pop_back();
|
|
|
|
delete sample;
|
|
|
|
}
|
|
|
|
}
|