@@ -79,6 +79,10 @@ struct PhysicsDirectInternalData
79
79
btHashMap<btHashInt, SharedMemoryUserData> m_userDataMap;
80
80
btHashMap<SharedMemoryUserDataHashKey, int > m_userDataHandleLookup;
81
81
82
+ btAlignedObjectArray<char > m_cachedReturnData;
83
+ b3UserDataValue m_cachedReturnDataValue;
84
+
85
+
82
86
PhysicsCommandProcessorInterface* m_commandProcessor;
83
87
bool m_ownsCommandProcessor;
84
88
double m_timeOutInSeconds;
@@ -1113,10 +1117,7 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
1113
1117
b3Warning (" Request mesh data failed" );
1114
1118
break ;
1115
1119
}
1116
- case CMD_CUSTOM_COMMAND_COMPLETED:
1117
- {
1118
- break ;
1119
- }
1120
+
1120
1121
case CMD_CUSTOM_COMMAND_FAILED:
1121
1122
{
1122
1123
b3Warning (" custom plugin command failed" );
@@ -1309,14 +1310,95 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
1309
1310
{
1310
1311
break ;
1311
1312
}
1313
+ case CMD_CUSTOM_COMMAND_COMPLETED:
1314
+ {
1315
+ break ;
1316
+ }
1312
1317
default :
1313
1318
{
1314
1319
// b3Warning("Unknown server status type");
1315
1320
}
1321
+
1316
1322
};
1317
1323
}
1324
+
1325
+
1326
+ bool PhysicsDirect::processCustomCommand (const struct SharedMemoryCommand & orgCommand)
1327
+ {
1328
+ SharedMemoryCommand command = orgCommand;
1329
+
1330
+ const SharedMemoryStatus& serverCmd = m_data->m_serverStatus ;
1331
+
1332
+ int remaining = 0 ;
1333
+ do
1334
+ {
1335
+ bool hasStatus = m_data->m_commandProcessor ->processCommand (command, m_data->m_serverStatus , &m_data->m_bulletStreamDataServerToClient [0 ], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
1336
+
1337
+ b3Clock clock;
1338
+ double startTime = clock.getTimeInSeconds ();
1339
+ double timeOutInSeconds = m_data->m_timeOutInSeconds ;
1340
+
1341
+ while ((!hasStatus) && (clock.getTimeInSeconds () - startTime < timeOutInSeconds))
1342
+ {
1343
+ const SharedMemoryStatus* stat = processServerStatus ();
1344
+ if (stat)
1345
+ {
1346
+ hasStatus = true ;
1347
+ }
1348
+ }
1349
+
1350
+ m_data->m_hasStatus = hasStatus;
1351
+
1352
+ if (hasStatus)
1353
+ {
1354
+
1355
+ if (m_data->m_verboseOutput )
1356
+ {
1357
+ b3Printf (" Success receiving %d return data\n " ,
1358
+ serverCmd.m_numDataStreamBytes );
1359
+ }
1360
+
1361
+
1362
+ btAssert (m_data->m_serverStatus .m_type == CMD_CUSTOM_COMMAND_COMPLETED);
1363
+
1364
+ if (m_data->m_serverStatus .m_type == CMD_CUSTOM_COMMAND_COMPLETED)
1365
+ {
1366
+ m_data->m_cachedReturnData .resize (serverCmd.m_customCommandResultArgs .m_returnDataSizeInBytes );
1367
+ m_data->m_cachedReturnDataValue .m_length = serverCmd.m_customCommandResultArgs .m_returnDataSizeInBytes ;
1368
+
1369
+ if (serverCmd.m_customCommandResultArgs .m_returnDataSizeInBytes )
1370
+ {
1371
+ m_data->m_cachedReturnDataValue .m_type = serverCmd.m_customCommandResultArgs .m_returnDataType ;
1372
+ m_data->m_cachedReturnDataValue .m_data1 = &m_data->m_cachedReturnData [0 ];
1373
+ for (int i = 0 ; i < serverCmd.m_numDataStreamBytes ; i++)
1374
+ {
1375
+ m_data->m_cachedReturnData [i+ serverCmd.m_customCommandResultArgs .m_returnDataStart ] = m_data->m_bulletStreamDataServerToClient [i];
1376
+ }
1377
+ }
1378
+ int totalReceived = serverCmd.m_numDataStreamBytes + serverCmd.m_customCommandResultArgs .m_returnDataStart ;
1379
+ remaining = serverCmd.m_customCommandResultArgs .m_returnDataSizeInBytes - totalReceived;
1380
+
1381
+ if (remaining > 0 )
1382
+ {
1383
+ m_data->m_hasStatus = false ;
1384
+ command.m_type = CMD_CUSTOM_COMMAND;
1385
+ command.m_customCommandArgs .m_startingReturnBytes =
1386
+ totalReceived;
1387
+ }
1388
+ }
1389
+ }
1390
+
1391
+ } while (remaining > 0 );
1392
+
1393
+ return m_data->m_hasStatus ;
1394
+ }
1395
+
1318
1396
bool PhysicsDirect::submitClientCommand (const struct SharedMemoryCommand & command)
1319
1397
{
1398
+ if (command.m_type == CMD_CUSTOM_COMMAND)
1399
+ {
1400
+ return processCustomCommand (command);
1401
+ }
1320
1402
if (command.m_type == CMD_REQUEST_DEBUG_LINES)
1321
1403
{
1322
1404
return processDebugLines (command);
@@ -1651,6 +1733,16 @@ void PhysicsDirect::getCachedMassMatrix(int dofCountCheck, double* massMatrix)
1651
1733
}
1652
1734
}
1653
1735
1736
+ bool PhysicsDirect::getCachedReturnData (b3UserDataValue* returnData)
1737
+ {
1738
+ if (m_data->m_cachedReturnDataValue .m_length )
1739
+ {
1740
+ *returnData = m_data->m_cachedReturnDataValue ;
1741
+ return true ;
1742
+ }
1743
+ return false ;
1744
+ }
1745
+
1654
1746
void PhysicsDirect::setTimeOut (double timeOutInSeconds)
1655
1747
{
1656
1748
m_data->m_timeOutInSeconds = timeOutInSeconds;
0 commit comments