summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerwincoumans <erwincoumans@google.com>2021-10-28 15:49:18 +0000
committerGitHub <noreply@github.com>2021-10-28 15:49:18 +0000
commitac3c283842fe5ceddc55fcdef5489fdf4458f6f6 (patch)
tree2cd446d4c47e2c7f66f8fb06fc82a6c520a16b67
parente4a450a53dc6eded9d16a0d1dde07fc8a25760d0 (diff)
parent740d2b978352b16943b24594572586d95d476466 (diff)
downloadbullet3-ac3c283842fe5ceddc55fcdef5489fdf4458f6f6.tar.gz
Merge pull request #4012 from RanTig/master
Adds a request body info command for the physics direct command.
-rw-r--r--examples/SharedMemory/PhysicsClientC_API.cpp13
-rw-r--r--examples/SharedMemory/PhysicsClientC_API.h3
-rw-r--r--examples/SharedMemory/PhysicsDirect.cpp38
-rw-r--r--examples/SharedMemory/PhysicsDirect.h2
4 files changed, 40 insertions, 16 deletions
diff --git a/examples/SharedMemory/PhysicsClientC_API.cpp b/examples/SharedMemory/PhysicsClientC_API.cpp
index 5b070713a..75f48e39d 100644
--- a/examples/SharedMemory/PhysicsClientC_API.cpp
+++ b/examples/SharedMemory/PhysicsClientC_API.cpp
@@ -3997,6 +3997,19 @@ B3_SHARED_API b3SharedMemoryCommandHandle b3InitSyncBodyInfoCommand(b3PhysicsCli
return (b3SharedMemoryCommandHandle)command;
}
+B3_SHARED_API b3SharedMemoryCommandHandle b3InitRequestBodyInfoCommand(b3PhysicsClientHandle physClient, int bodyUniqueId)
+{
+ PhysicsClient* cl = (PhysicsClient*)physClient;
+ b3Assert(cl);
+ b3Assert(cl->canSubmitCommand());
+ struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand();
+ b3Assert(command);
+
+ command->m_type = CMD_REQUEST_BODY_INFO;
+ command->m_sdfRequestInfoArgs.m_bodyUniqueId = bodyUniqueId;
+ return (b3SharedMemoryCommandHandle)command;
+}
+
B3_SHARED_API b3SharedMemoryCommandHandle b3InitSyncUserDataCommand(b3PhysicsClientHandle physClient)
{
PhysicsClient* cl = (PhysicsClient*)physClient;
diff --git a/examples/SharedMemory/PhysicsClientC_API.h b/examples/SharedMemory/PhysicsClientC_API.h
index b6ec6d63b..c14feb82f 100644
--- a/examples/SharedMemory/PhysicsClientC_API.h
+++ b/examples/SharedMemory/PhysicsClientC_API.h
@@ -106,6 +106,9 @@ extern "C"
///If you re-connected to an existing server, or server changed otherwise, sync the body info and user constraints etc.
B3_SHARED_API b3SharedMemoryCommandHandle b3InitSyncBodyInfoCommand(b3PhysicsClientHandle physClient);
+ // Sync the body info of a single body. Useful when a new body has been added by a different client (e,g, when detecting through a body added notification).
+ B3_SHARED_API b3SharedMemoryCommandHandle b3InitRequestBodyInfoCommand(b3PhysicsClientHandle physClient, int bodyUniqueId);
+
B3_SHARED_API b3SharedMemoryCommandHandle b3InitRemoveBodyCommand(b3PhysicsClientHandle physClient, int bodyUniqueId);
///return the total number of bodies in the simulation
diff --git a/examples/SharedMemory/PhysicsDirect.cpp b/examples/SharedMemory/PhysicsDirect.cpp
index ef72e7e19..a8aa72a60 100644
--- a/examples/SharedMemory/PhysicsDirect.cpp
+++ b/examples/SharedMemory/PhysicsDirect.cpp
@@ -1008,21 +1008,7 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
m_data->m_tmpInfoRequestCommand.m_type = CMD_REQUEST_BODY_INFO;
m_data->m_tmpInfoRequestCommand.m_sdfRequestInfoArgs.m_bodyUniqueId = bodyUniqueId;
-
- 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)
- {
- processBodyJointInfo(bodyUniqueId, m_data->m_tmpInfoStatus);
- }
+ processRequestBodyInfo(m_data->m_tmpInfoRequestCommand, m_data->m_tmpInfoStatus);
}
break;
}
@@ -1405,6 +1391,22 @@ bool PhysicsDirect::processCustomCommand(const struct SharedMemoryCommand& orgCo
return m_data->m_hasStatus;
}
+bool PhysicsDirect::processRequestBodyInfo(const struct SharedMemoryCommand& command, SharedMemoryStatus& status) {
+ bool hasStatus = m_data->m_commandProcessor->processCommand(command, status, &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(status, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
+ }
+ if (hasStatus) {
+ processBodyJointInfo(command.m_sdfRequestInfoArgs.m_bodyUniqueId, status);
+ }
+ m_data->m_hasStatus = hasStatus;
+ return m_data->m_hasStatus;
+}
+
bool PhysicsDirect::submitClientCommand(const struct SharedMemoryCommand& command)
{
if (command.m_type == CMD_CUSTOM_COMMAND)
@@ -1434,10 +1436,14 @@ bool PhysicsDirect::submitClientCommand(const struct SharedMemoryCommand& comman
return processOverlappingObjects(command);
}
- if (command.m_type == CMD_REQUEST_MESH_DATA)
+ if (command.m_type == CMD_REQUEST_MESH_DATA)
{
return processMeshData(command);
}
+ if (command.m_type == CMD_REQUEST_BODY_INFO)
+ {
+ return processRequestBodyInfo(command, m_data->m_serverStatus);
+ }
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
m_data->m_hasStatus = hasStatus;
diff --git a/examples/SharedMemory/PhysicsDirect.h b/examples/SharedMemory/PhysicsDirect.h
index 2e09a95d2..0d33f8119 100644
--- a/examples/SharedMemory/PhysicsDirect.h
+++ b/examples/SharedMemory/PhysicsDirect.h
@@ -28,6 +28,8 @@ protected:
void processAddUserData(const struct SharedMemoryStatus& serverCmd);
+ bool processRequestBodyInfo(const struct SharedMemoryCommand& command, SharedMemoryStatus& status);
+
bool processCustomCommand(const struct SharedMemoryCommand& orgCommand);
void postProcessStatus(const struct SharedMemoryStatus& serverCmd);