mirror of
https://github.com/bulletphysics/bullet3.git
synced 2026-09-16 15:24:28 +00:00
Add an option for a plugin to report return data after calling executePluginCommand. Also add python binding.
Currently the return data has to fit in shared memory, 8MB (Linux, Windows) or 1MB (Apple) Preparation for streaming is added (to allow unlimited return data, see CMD_CUSTOM_COMMAND_STREAM_RETURN_DATA) New C-API: b3GetStatusPluginCommandReturnData PyBullet reports return data if available, in pybullet_executePluginCommand For the plugin developer: plugin can provide additional return data for executePluginCommand in the b3PluginContext, during executePluginCommand. Lifetime of this m_returnData pointer is minimum of next call to the next executePluginCommand or plugin termination.
This commit is contained in:
@@ -5757,6 +5757,8 @@ bool PhysicsServerCommandProcessor::processCustomCommand(const struct SharedMemo
|
||||
|
||||
SharedMemoryStatus& serverCmd = serverStatusOut;
|
||||
serverCmd.m_type = CMD_CUSTOM_COMMAND_FAILED;
|
||||
serverCmd.m_customCommandResultArgs.m_returnDataSizeInBytes = 0;
|
||||
serverCmd.m_customCommandResultArgs.m_returnDataType = -1;
|
||||
serverCmd.m_customCommandResultArgs.m_pluginUniqueId = -1;
|
||||
|
||||
if (clientCmd.m_updateFlags & CMD_CUSTOM_COMMAND_LOAD_PLUGIN)
|
||||
@@ -5772,6 +5774,7 @@ bool PhysicsServerCommandProcessor::processCustomCommand(const struct SharedMemo
|
||||
if (pluginUniqueId >= 0)
|
||||
{
|
||||
serverCmd.m_customCommandResultArgs.m_pluginUniqueId = pluginUniqueId;
|
||||
|
||||
serverCmd.m_type = CMD_CUSTOM_COMMAND_COMPLETED;
|
||||
}
|
||||
}
|
||||
@@ -5780,10 +5783,49 @@ bool PhysicsServerCommandProcessor::processCustomCommand(const struct SharedMemo
|
||||
m_data->m_pluginManager.unloadPlugin(clientCmd.m_customCommandArgs.m_pluginUniqueId);
|
||||
serverCmd.m_type = CMD_CUSTOM_COMMAND_COMPLETED;
|
||||
}
|
||||
if (clientCmd.m_updateFlags & CMD_CUSTOM_COMMAND_STREAM_RETURN_DATA)
|
||||
{
|
||||
serverCmd.m_type = CMD_CUSTOM_COMMAND_STREAM_RETURN_DATA_FAILED;
|
||||
const b3UserDataValue* returnData = m_data->m_pluginManager.getReturnData(clientCmd.m_customCommandArgs.m_pluginUniqueId);
|
||||
if (returnData)
|
||||
{
|
||||
int startBytes = clientCmd.m_customCommandArgs.m_startingReturnBytes;
|
||||
if (startBytes >= 0 && startBytes < returnData->m_length)
|
||||
{
|
||||
int totalRemain = returnData->m_length - startBytes;
|
||||
int numBytes = totalRemain <= bufferSizeInBytes ? totalRemain : bufferSizeInBytes;
|
||||
serverStatusOut.m_numDataStreamBytes = numBytes;
|
||||
for (int i = 0; i < numBytes; i++)
|
||||
{
|
||||
bufferServerToClient[i] = returnData->m_data1[i + startBytes];
|
||||
}
|
||||
serverCmd.m_customCommandResultArgs.m_returnDataSizeInBytes = returnData->m_length;
|
||||
serverCmd.m_customCommandResultArgs.m_returnDataType = returnData->m_type;
|
||||
serverCmd.m_type = CMD_CUSTOM_COMMAND_STREAM_RETURN_DATA_COMPLETED;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (clientCmd.m_updateFlags & CMD_CUSTOM_COMMAND_EXECUTE_PLUGIN_COMMAND)
|
||||
{
|
||||
int result = m_data->m_pluginManager.executePluginCommand(clientCmd.m_customCommandArgs.m_pluginUniqueId, &clientCmd.m_customCommandArgs.m_arguments);
|
||||
serverCmd.m_customCommandResultArgs.m_executeCommandResult = result;
|
||||
const b3UserDataValue* returnData = m_data->m_pluginManager.getReturnData(clientCmd.m_customCommandArgs.m_pluginUniqueId);
|
||||
if (returnData)
|
||||
{
|
||||
int numBytes = returnData->m_length <= bufferSizeInBytes ? returnData->m_length : bufferSizeInBytes;
|
||||
serverStatusOut.m_numDataStreamBytes = numBytes;
|
||||
for (int i = 0; i < numBytes; i++)
|
||||
{
|
||||
bufferServerToClient[i] = returnData->m_data1[i];
|
||||
}
|
||||
serverCmd.m_customCommandResultArgs.m_returnDataSizeInBytes = returnData->m_length;
|
||||
serverCmd.m_customCommandResultArgs.m_returnDataType = returnData->m_type;
|
||||
}
|
||||
else
|
||||
{
|
||||
serverStatusOut.m_numDataStreamBytes = 0;
|
||||
}
|
||||
|
||||
serverCmd.m_type = CMD_CUSTOM_COMMAND_COMPLETED;
|
||||
}
|
||||
return hasStatus;
|
||||
|
||||
Reference in New Issue
Block a user