exit gracefully and call destructor of the current active example

fflush after printf
implemented stepForward and Shutdown for the SharedMemory client/server
This commit is contained in:
=
2015-05-29 15:04:05 -07:00
parent ff15d36edf
commit bc806ab68c
10 changed files with 206 additions and 50 deletions

View File

@@ -3,11 +3,14 @@
#include "../CommonInterfaces/CommonMultiBodyBase.h"
#include "PosixSharedMemory.h"
#include "SharedMemoryCommon.h"
class PhysicsClient : public CommonMultiBodyBase
class PhysicsClient : public SharedMemoryCommon
{
SharedMemoryInterface* m_sharedMemory;
SharedMemoryExampleData* m_testBlock1;
int m_counter;
bool m_wantsTermination;
public:
@@ -27,11 +30,17 @@ public:
m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]);
}
virtual bool wantsTermination()
{
return m_wantsTermination;
}
};
PhysicsClient::PhysicsClient(GUIHelperInterface* helper)
:CommonMultiBodyBase(helper),
m_testBlock1(0)
:SharedMemoryCommon(helper),
m_testBlock1(0),
m_counter(0),
m_wantsTermination(false)
{
b3Printf("Started PhysicsClient");
m_sharedMemory = new PosixSharedMemory();
@@ -55,6 +64,15 @@ void PhysicsClient::initPhysics()
b3Error("Error: please start server before client");
m_sharedMemory->releaseSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE);
m_testBlock1 = 0;
} else
{
//submit a 'load urdf' command to get things started
b3Printf("Client created CMD_LOAD_URDF");
m_testBlock1->m_clientCommands[0].m_type =CMD_LOAD_URDF;
sprintf(m_testBlock1->m_clientCommands[0].m_urdfArguments.m_urdfFileName,"r2d2.urdf");
m_testBlock1->m_numClientCommands++;
}
}
@@ -63,20 +81,60 @@ void PhysicsClient::initPhysics()
void PhysicsClient::stepSimulation(float deltaTime)
{
static int once = true;
if (m_testBlock1)
{
if (once)
{
once=false;
//check progress and submit further commands
//we ignore overflow right now
b3Printf("Client created CMD_LOAD_URDF");
m_testBlock1->m_clientCommands[0].m_type =CMD_LOAD_URDF;
sprintf(m_testBlock1->m_clientCommands[0].m_urdfArguments.m_urdfFileName,"r2d2.urdf");
m_testBlock1->m_numClientCommands++;
if (m_testBlock1->m_numServerCommands> m_testBlock1->m_numProcessedServerCommands)
{
btAssert(m_testBlock1->m_numServerCommands==m_testBlock1->m_numProcessedServerCommands+1);
const SharedMemoryCommand& serverCmd =m_testBlock1->m_serverCommands[0];
//consume the command
switch (serverCmd.m_type)
{
case CMD_STEP_FORWARD_SIMULATION_COMPLETED:
case CMD_URDF_LOADING_COMPLETED:
{
//submit a 'step simulation' request
if (m_counter<10)
{
m_testBlock1->m_clientCommands[0].m_type =CMD_STEP_FORWARD_SIMULATION;
m_testBlock1->m_clientCommands[0].m_stepSimulationArguments.m_deltaTimeInSeconds = 1./60.;
m_testBlock1->m_numClientCommands++;
m_counter++;
} else
{
m_wantsTermination = true;
m_testBlock1->m_clientCommands[0].m_type =CMD_SHUTDOWN;
m_testBlock1->m_numClientCommands++;
}
break;
}
case CMD_URDF_LOADING_FAILED:
{
b3Printf("Server failed loading the URDF...");
break;
}
default:
{
b3Error("Unknown server command");
btAssert(0);
}
};
m_testBlock1->m_numProcessedServerCommands++;
}
}
}