preparation for CommandLogging for PhysicsServer.

This commit is contained in:
erwin coumans
2015-10-29 11:25:50 -07:00
parent 650189d50b
commit f7bbbd88e6
5 changed files with 81 additions and 15 deletions

View File

@@ -1041,7 +1041,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
}
static int toggle = 1;
if (1)
if (renderGrid)
{
if (!pauseSimulation)
processProfileData(s_profWindow,false);

View File

@@ -108,6 +108,24 @@ struct InternalBodyHandle : public InteralBodyData
return m_nextFreeHandle;
}
};
struct CommandLogger
{
FILE* m_file;
void logCommand(SharedMemoryBlock* testBlock1)
{
//fwrite(buf,buffSize+sizeof(int),1,m_file);
}
CommandLogger(const char* fileName)
{
m_file = fopen(fileName,"wb");
}
virtual ~CommandLogger()
{
fclose(m_file);
}
};
struct PhysicsServerInternalData
{
@@ -200,6 +218,7 @@ struct PhysicsServerInternalData
SharedMemoryInterface* m_sharedMemory;
SharedMemoryBlock* m_testBlock1;
CommandLogger* m_commandLogger;
bool m_isConnected;
btScalar m_physicsDeltaTime;
btAlignedObjectArray<btMultiBodyJointFeedback*> m_multiBodyJointFeedbacks;
@@ -240,6 +259,7 @@ struct PhysicsServerInternalData
PhysicsServerInternalData()
:m_sharedMemory(0),
m_testBlock1(0),
m_commandLogger(0),
m_isConnected(false),
m_physicsDeltaTime(1./240.),
m_dynamicsWorld(0),
@@ -332,6 +352,12 @@ PhysicsServerSharedMemory::PhysicsServerSharedMemory()
PhysicsServerSharedMemory::~PhysicsServerSharedMemory()
{
deleteDynamicsWorld();
if (m_data->m_commandLogger)
{
delete m_data->m_commandLogger;
m_data->m_commandLogger = 0;
}
delete m_data;
}
@@ -451,7 +477,7 @@ bool PhysicsServerSharedMemory::connectSharedMemory( struct GUIHelperInterface*
}
bool allowCreation = true;
bool allowConnectToExistingSharedMemory = false;
if (m_data->m_isConnected)
{
@@ -489,6 +515,7 @@ bool PhysicsServerSharedMemory::connectSharedMemory( struct GUIHelperInterface*
b3Error("Cannot connect to shared memory");
m_data->m_isConnected = false;
}
return m_data->m_isConnected;
}
@@ -723,11 +750,17 @@ void PhysicsServerSharedMemory::processClientCommands()
///we ignore overflow of integer for now
if (m_data->m_testBlock1->m_numClientCommands> m_data->m_testBlock1->m_numProcessedClientCommands)
{
//until we implement a proper ring buffer, we assume always maximum of 1 outstanding commands
btAssert(m_data->m_testBlock1->m_numClientCommands==m_data->m_testBlock1->m_numProcessedClientCommands+1);
const SharedMemoryCommand& clientCmd =m_data->m_testBlock1->m_clientCommands[0];
if (m_data->m_commandLogger)
{
m_data->m_commandLogger->logCommand(m_data->m_testBlock1);
}
m_data->m_testBlock1->m_numProcessedClientCommands++;
//no timestamp yet
@@ -1678,3 +1711,21 @@ void PhysicsServerSharedMemory::removePickingConstraint()
m_data->m_pickingMultiBodyPoint2Point = 0;
}
}
void PhysicsServerSharedMemory::enableCommandLogging(bool enable, const char* fileName)
{
if (enable)
{
if (0==m_data->m_commandLogger)
{
m_data->m_commandLogger = new CommandLogger(fileName);
}
} else
{
if (0!=m_data->m_commandLogger)
{
delete m_data->m_commandLogger;
m_data->m_commandLogger = 0;
}
}
}

View File

@@ -54,6 +54,8 @@ public:
void physicsDebugDraw(int debugDrawFlags);
void renderScene();
void enableCommandLogging(bool enable, const char* fileName);
};

View File

@@ -29,7 +29,10 @@ public:
virtual void stepSimulation(float deltaTime);
void enableCommandLogging()
{
m_physicsServer.enableCommandLogging(true,"BulletPhysicsCommandLog.bin");
}
virtual void resetCamera()
{
@@ -190,18 +193,7 @@ void PhysicsServerExample::physicsDebugDraw(int debugDrawFlags)
}
extern int gSharedMemoryKey;
class CommonExampleInterface* PhysicsServerCreateFunc(struct CommonExampleOptions& options)
{
PhysicsServerExample* example = new PhysicsServerExample(options.m_guiHelper);
if (gSharedMemoryKey>=0)
{
example->setSharedMemoryKey(gSharedMemoryKey);
}
return example;
}
btVector3 PhysicsServerExample::getRayTo(int x,int y)
{
@@ -267,3 +259,20 @@ btVector3 PhysicsServerExample::getRayTo(int x,int y)
return rayTo;
}
extern int gSharedMemoryKey;
class CommonExampleInterface* PhysicsServerCreateFunc(struct CommonExampleOptions& options)
{
PhysicsServerExample* example = new PhysicsServerExample(options.m_guiHelper);
if (gSharedMemoryKey>=0)
{
example->setSharedMemoryKey(gSharedMemoryKey);
}
if (options.m_option & PHYSICS_SERVER_ENABLE_COMMAND_LOGGING)
{
example->enableCommandLogging();
}
return example;
}

View File

@@ -1,6 +1,10 @@
#ifndef PHYSICS_SERVER_EXAMPLE_H
#define PHYSICS_SERVER_EXAMPLE_H
enum PhysicsServerOptions
{
PHYSICS_SERVER_ENABLE_COMMAND_LOGGING=1,
};
class CommonExampleInterface* PhysicsServerCreateFunc(struct CommonExampleOptions& options);