Merge pull request #4012 from RanTig/master

Adds a request body info command for the physics direct command.
This commit is contained in:
erwincoumans 2021-10-28 15:49:18 +00:00 committed by GitHub
commit ac3c283842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 16 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);