add a b3Clock::usleep in PhysicsClientUDP to avoid clogging all resources

report more meaningful connection status for UDP.
This commit is contained in:
erwincoumans
2017-01-28 12:42:04 -08:00
parent 5c92bee01c
commit 2b3c25d5f2
2 changed files with 20 additions and 7 deletions

View File

@@ -322,13 +322,10 @@ void UDPThreadFunc(void* userPtr, void* lsMemory)
do
{
b3Clock::usleep(0);
deltaTimeInSeconds += double(clock.getTimeMicroseconds()) / 1000000.;
if (deltaTimeInSeconds<(1. / 5000.))
{
// b3Clock::usleep(250);
}
else
{
clock.reset();
@@ -441,6 +438,10 @@ UdpNetworkedPhysicsProcessor::~UdpNetworkedPhysicsProcessor()
bool UdpNetworkedPhysicsProcessor::processCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes)
{
if(gVerboseNetworkMessagesClient)
{
printf("PhysicsClientUDP::processCommand\n");
}
// int sz = sizeof(SharedMemoryCommand);
int timeout = 1024 * 1024 * 1024;
@@ -475,6 +476,10 @@ bool UdpNetworkedPhysicsProcessor::processCommand(const struct SharedMemoryComma
bool UdpNetworkedPhysicsProcessor::receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes)
{
if (gVerboseNetworkMessagesClient)
{
printf("UdpNetworkedPhysicsProcessor::receiveStatus\n");
}
bool hasStatus = false;
if (m_data->m_hasStatus)
{

View File

@@ -10,11 +10,19 @@ b3PhysicsClientHandle b3ConnectPhysicsUDP(const char* hostName, int port)
UdpNetworkedPhysicsProcessor* udp = new UdpNetworkedPhysicsProcessor(hostName, port);
PhysicsDirect* direct = new PhysicsDirect(udp,true);
PhysicsDirect* direct = new PhysicsDirect(udp, true);
bool connected;
connected = direct->connect();
printf("direct!\n");
if (connected)
{
printf("b3ConnectPhysicsUDP connected successfully.\n");
}
else
{
printf("b3ConnectPhysicsUDP NOT connected.\n");
}
return (b3PhysicsClientHandle)direct;
}