From bfc85ff1fd1181dc875d27f5de9cd2a7d5b5d062 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Wed, 27 Jun 2018 23:43:42 -0700 Subject: [PATCH] PyBullet: TCP connection, optimized getVREvents to allow faster Windows -> Linux Vive tracking state communication. --- examples/SharedMemory/PhysicsClientTCP.cpp | 13 ++++- examples/SharedMemory/tcp/main.cpp | 63 ++++++++++++++++------ 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/examples/SharedMemory/PhysicsClientTCP.cpp b/examples/SharedMemory/PhysicsClientTCP.cpp index f959325c0..8ac5b74f8 100644 --- a/examples/SharedMemory/PhysicsClientTCP.cpp +++ b/examples/SharedMemory/PhysicsClientTCP.cpp @@ -181,8 +181,17 @@ bool TcpNetworkedPhysicsProcessor::processCommand(const struct SharedMemoryComma } else { - sz = sizeof(SharedMemoryCommand); - data = (unsigned char*)&clientCmd; + + if (clientCmd.m_type == CMD_REQUEST_VR_EVENTS_DATA) + { + sz = 3 * sizeof(int) + sizeof(smUint64_t) + 16; + data = (unsigned char*)&clientCmd; + } + else + { + sz = sizeof(SharedMemoryCommand); + data = (unsigned char*)&clientCmd; + } } m_data->m_tcpSocket.Send((const uint8 *)data,sz); diff --git a/examples/SharedMemory/tcp/main.cpp b/examples/SharedMemory/tcp/main.cpp index 6c2df155d..234b2312e 100644 --- a/examples/SharedMemory/tcp/main.cpp +++ b/examples/SharedMemory/tcp/main.cpp @@ -184,11 +184,16 @@ int main(int argc, char *argv[]) cmdPtr = &cmd; cmd.m_type = *(int*)&bytesReceived[0]; } - + + if (numBytesRec == sizeof(SharedMemoryCommand)) { cmdPtr = (SharedMemoryCommand*)&bytesReceived[0]; } + else + { + cmdPtr = (SharedMemoryCommand*)&bytesReceived[0]; + } if (cmdPtr) { SharedMemoryStatus serverStatus; @@ -207,7 +212,7 @@ int main(int argc, char *argv[]) } if (gVerboseNetworkMessagesServer) { - printf("buffer.size = %d\n", buffer.size()); + //printf("buffer.size = %d\n", buffer.size()); printf("serverStatus.m_numDataStreamBytes = %d\n", serverStatus.m_numDataStreamBytes); } if (hasStatus) @@ -234,25 +239,49 @@ int main(int argc, char *argv[]) } else { - //create packetData with [int packetSizeInBytes, status, streamBytes) - packetData.resize(4 + sizeof(SharedMemoryStatus) + serverStatus.m_numDataStreamBytes); - int sz = packetData.size(); - int curPos = 0; - - MySerializeInt(sz, &packetData[curPos]); - curPos += 4; - for (int i = 0; i < sizeof(SharedMemoryStatus); i++) + if (cmdPtr->m_type == CMD_REQUEST_VR_EVENTS_DATA) { - packetData[i + curPos] = statBytes[i]; + int headerSize = 16+5 * sizeof(int) + sizeof(smUint64_t) + sizeof(char*) + sizeof(b3VRControllerEvent)*serverStatus.m_sendVREvents.m_numVRControllerEvents; + packetData.resize(4 + headerSize); + int sz = packetData.size(); + int curPos = 0; + MySerializeInt(sz, &packetData[curPos]); + curPos += 4; + for (int i = 0; i < headerSize; i++) + { + packetData[i + curPos] = statBytes[i]; + } + curPos += headerSize; + pClient->Send(&packetData[0], packetData.size()); } - curPos += sizeof(SharedMemoryStatus); - - for (int i = 0; i < serverStatus.m_numDataStreamBytes; i++) + else { - packetData[i + curPos] = buffer[i]; + //create packetData with [int packetSizeInBytes, status, streamBytes) + packetData.resize(4 + sizeof(SharedMemoryStatus) + serverStatus.m_numDataStreamBytes); + int sz = packetData.size(); + int curPos = 0; + + if (gVerboseNetworkMessagesServer) + { + //printf("buffer.size = %d\n", buffer.size()); + printf("serverStatus packed size = %d\n", sz); + } + + MySerializeInt(sz, &packetData[curPos]); + curPos += 4; + for (int i = 0; i < sizeof(SharedMemoryStatus); i++) + { + packetData[i + curPos] = statBytes[i]; + } + curPos += sizeof(SharedMemoryStatus); + + for (int i = 0; i < serverStatus.m_numDataStreamBytes; i++) + { + packetData[i + curPos] = buffer[i]; + } + + pClient->Send(&packetData[0], packetData.size()); } - - pClient->Send( &packetData[0], packetData.size() ); } }