From 35a55b2056426d9990e0f9b7d5d707f37f8d1483 Mon Sep 17 00:00:00 2001 From: Tigran Gasparian Date: Wed, 25 Jul 2018 14:47:34 +0200 Subject: [PATCH] Changes tickPlugins to reportNotifications and only calls the processNotifications function on the plugins when there are actually notifications available. tickPlugins will to into a separate PR. --- .../PhysicsCommandProcessorInterface.h | 2 +- examples/SharedMemory/PhysicsDirect.cpp | 2 +- .../PhysicsServerCommandProcessor.cpp | 4 ++-- .../PhysicsServerCommandProcessor.h | 2 +- .../SharedMemory/PhysicsServerExample.cpp | 2 +- .../PhysicsServerSharedMemory.cpp | 4 ++-- .../SharedMemory/PhysicsServerSharedMemory.h | 2 +- examples/SharedMemory/b3PluginManager.cpp | 23 +++++++++++-------- examples/SharedMemory/b3PluginManager.h | 2 +- 9 files changed, 24 insertions(+), 19 deletions(-) diff --git a/examples/SharedMemory/PhysicsCommandProcessorInterface.h b/examples/SharedMemory/PhysicsCommandProcessorInterface.h index 014bbd437..4c5600581 100644 --- a/examples/SharedMemory/PhysicsCommandProcessorInterface.h +++ b/examples/SharedMemory/PhysicsCommandProcessorInterface.h @@ -44,7 +44,7 @@ public: virtual void enableRealTimeSimulation(bool enableRealTimeSim)=0; virtual bool isRealTimeSimulationEnabled() const=0; - virtual void tickPlugins() = 0; + virtual void reportNotifications() = 0; virtual void enableCommandLogging(bool enable, const char* fileName)=0; virtual void replayFromLogFile(const char* fileName)=0; diff --git a/examples/SharedMemory/PhysicsDirect.cpp b/examples/SharedMemory/PhysicsDirect.cpp index 091e160b7..9e3e01831 100644 --- a/examples/SharedMemory/PhysicsDirect.cpp +++ b/examples/SharedMemory/PhysicsDirect.cpp @@ -1218,7 +1218,7 @@ bool PhysicsDirect::submitClientCommand(const struct SharedMemoryCommand& comman if (m_data->m_ownsCommandProcessor) { CommandProcessorInterface *commandProcessor = (CommandProcessorInterface *)m_data->m_commandProcessor; - commandProcessor->tickPlugins(); + commandProcessor->reportNotifications(); } /*if (hasStatus) { diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 9ca47c130..e16a22c9e 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -1902,8 +1902,8 @@ void PhysicsServerCommandProcessor::processCollisionForces(btScalar timeStep) #endif//B3_ENABLE_TINY_AUDIO } -void PhysicsServerCommandProcessor::tickPlugins() { - m_data->m_pluginManager.tickPlugins(); +void PhysicsServerCommandProcessor::reportNotifications() { + m_data->m_pluginManager.reportNotifications(); } void PhysicsServerCommandProcessor::tickPlugins(btScalar timeStep, bool isPreTick) diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.h b/examples/SharedMemory/PhysicsServerCommandProcessor.h index 0b6d7c36e..f30716c1a 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.h +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.h @@ -155,7 +155,7 @@ public: virtual void replayLogCommand(char* bufferServerToClient, int bufferSizeInBytes ); //logging of object states (position etc) - virtual void tickPlugins(); + virtual void reportNotifications(); void tickPlugins(btScalar timeStep, bool isPreTick); void logObjectStates(btScalar timeStep); void processCollisionForces(btScalar timeStep); diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 6ac679403..b9405371f 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -472,7 +472,7 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) numCmdSinceSleep1ms++; } - args->m_physicsServerPtr->tickPlugins(); + args->m_physicsServerPtr->reportNotifications(); args->m_cs->lock(); cachedSharedParam = args->m_cs->getSharedParam(0); diff --git a/examples/SharedMemory/PhysicsServerSharedMemory.cpp b/examples/SharedMemory/PhysicsServerSharedMemory.cpp index 601583024..a351dac1e 100644 --- a/examples/SharedMemory/PhysicsServerSharedMemory.cpp +++ b/examples/SharedMemory/PhysicsServerSharedMemory.cpp @@ -242,9 +242,9 @@ bool PhysicsServerSharedMemory::isRealTimeSimulationEnabled() const return m_data->m_commandProcessor->isRealTimeSimulationEnabled(); } -void PhysicsServerSharedMemory::tickPlugins() +void PhysicsServerSharedMemory::reportNotifications() { - m_data->m_commandProcessor->tickPlugins(); + m_data->m_commandProcessor->reportNotifications(); } void PhysicsServerSharedMemory::processClientCommands() diff --git a/examples/SharedMemory/PhysicsServerSharedMemory.h b/examples/SharedMemory/PhysicsServerSharedMemory.h index 779f7d82b..14f994ce2 100644 --- a/examples/SharedMemory/PhysicsServerSharedMemory.h +++ b/examples/SharedMemory/PhysicsServerSharedMemory.h @@ -32,7 +32,7 @@ public: virtual void enableRealTimeSimulation(bool enableRealTimeSim); virtual bool isRealTimeSimulationEnabled() const; - virtual void tickPlugins(); + virtual void reportNotifications(); //bool supportsJointMotor(class btMultiBody* body, int linkIndex); diff --git a/examples/SharedMemory/b3PluginManager.cpp b/examples/SharedMemory/b3PluginManager.cpp index e3527d1f4..b4ab56487 100644 --- a/examples/SharedMemory/b3PluginManager.cpp +++ b/examples/SharedMemory/b3PluginManager.cpp @@ -38,7 +38,7 @@ struct b3Plugin PFN_TICK m_preTickFunc; PFN_TICK m_postTickFunc; - PFN_TICK m_tickPluginFunc; + PFN_TICK m_processNotificationsFunc; PFN_GET_RENDER_INTERFACE m_getRendererFunc; @@ -53,7 +53,7 @@ struct b3Plugin m_executeCommandFunc(0), m_preTickFunc(0), m_postTickFunc(0), - m_tickPluginFunc(0), + m_processNotificationsFunc(0), m_getRendererFunc(0), m_userPointer(0) { @@ -90,7 +90,7 @@ struct b3PluginManagerInternalData int m_activeRendererPluginUid; b3PluginManagerInternalData() - :m_activeRendererPluginUid(-1), m_activeNotificationsBufferIndex(0) + :m_activeNotificationsBufferIndex(0), m_activeRendererPluginUid(-1) { } }; @@ -174,15 +174,15 @@ int b3PluginManager::loadPlugin(const char* pluginPath, const char* postFixStr) std::string executePluginCommandStr = std::string("executePluginCommand") + postFix; std::string preTickPluginCallbackStr = std::string("preTickPluginCallback") + postFix; std::string postTickPluginCallback = std::string("postTickPluginCallback") + postFix; - std::string tickPluginStr = std::string("tickPlugin") + postFix; + std::string processNotificationsStr = std::string("processNotifications") + postFix; std::string getRendererStr = std::string("getRenderInterface") + postFix; - + plugin->m_initFunc = (PFN_INIT)B3_DYNLIB_IMPORT(pluginHandle, initStr.c_str()); plugin->m_exitFunc = (PFN_EXIT)B3_DYNLIB_IMPORT(pluginHandle, exitStr.c_str()); plugin->m_executeCommandFunc = (PFN_EXECUTE)B3_DYNLIB_IMPORT(pluginHandle, executePluginCommandStr.c_str()); plugin->m_preTickFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, preTickPluginCallbackStr.c_str()); plugin->m_postTickFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, postTickPluginCallback.c_str()); - plugin->m_tickPluginFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, tickPluginStr.c_str()); + plugin->m_processNotificationsFunc = (PFN_TICK)B3_DYNLIB_IMPORT(pluginHandle, processNotificationsStr.c_str()); plugin->m_getRendererFunc = (PFN_GET_RENDER_INTERFACE)B3_DYNLIB_IMPORT(pluginHandle, getRendererStr.c_str()); if (plugin->m_initFunc && plugin->m_exitFunc && plugin->m_executeCommandFunc) @@ -292,9 +292,14 @@ void b3PluginManager::tickPlugins(double timeStep, bool isPreTick) } } -void b3PluginManager::tickPlugins() +void b3PluginManager::reportNotifications() { b3AlignedObjectArray ¬ifications = m_data->m_notifications[m_data->m_activeNotificationsBufferIndex]; + if (notifications.size() == 0) + { + return; + } + // Swap notification buffers. m_data->m_activeNotificationsBufferIndex = 1 - m_data->m_activeNotificationsBufferIndex; @@ -313,13 +318,13 @@ void b3PluginManager::tickPlugins() continue; } - if (plugin->m_tickPluginFunc) { + if (plugin->m_processNotificationsFunc) { b3PluginContext context = {0}; context.m_userPointer = plugin->m_userPointer; context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect; context.m_numNotifications = notifications.size(); context.m_notifications = notifications.size() ? ¬ifications[0] : 0; - plugin->m_tickPluginFunc(&context); + plugin->m_processNotificationsFunc(&context); } } notifications.clear(); diff --git a/examples/SharedMemory/b3PluginManager.h b/examples/SharedMemory/b3PluginManager.h index 27522899f..6f2abfc3e 100644 --- a/examples/SharedMemory/b3PluginManager.h +++ b/examples/SharedMemory/b3PluginManager.h @@ -19,9 +19,9 @@ class b3PluginManager void clearEvents(); void addNotification(const struct b3Notification& notification); + void reportNotifications(); void tickPlugins(double timeStep, bool isPreTick); - void tickPlugins(); int registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT initFunc,PFN_EXIT exitFunc, PFN_EXECUTE executeCommandFunc, PFN_TICK preTickFunc, PFN_TICK postTickFunc, PFN_GET_RENDER_INTERFACE getRendererFunc);