diff options
author | erwincoumans <erwincoumans@google.com> | 2019-08-08 09:57:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-08 09:57:59 -0700 |
commit | 2b36617a6eeca44c0805a815fd40f3eff7ce37ff (patch) | |
tree | d1d45cd811af31837349d2ebec39dd5cd57eff92 | |
parent | 666e1a8bad7dbebc2f40f15cb763dddc86154df6 (diff) | |
parent | ebe6d2df8641135248fd2762efb92ad3d6fe26bc (diff) | |
download | bullet3-2b36617a6eeca44c0805a815fd40f3eff7ce37ff.tar.gz |
Merge pull request #2361 from RanTig/sync-cache-clear
Clears body and user data caches on syncBodyInfo and syncUserData
-rw-r--r-- | examples/SharedMemory/PhysicsClientSharedMemory.cpp | 21 | ||||
-rw-r--r-- | examples/SharedMemory/PhysicsClientSharedMemory.h | 1 | ||||
-rw-r--r-- | examples/SharedMemory/PhysicsDirect.cpp | 14 | ||||
-rw-r--r-- | examples/SharedMemory/PhysicsDirect.h | 2 |
4 files changed, 28 insertions, 10 deletions
diff --git a/examples/SharedMemory/PhysicsClientSharedMemory.cpp b/examples/SharedMemory/PhysicsClientSharedMemory.cpp index daebb7afd..71e1a1985 100644 --- a/examples/SharedMemory/PhysicsClientSharedMemory.cpp +++ b/examples/SharedMemory/PhysicsClientSharedMemory.cpp @@ -282,11 +282,9 @@ void PhysicsClientSharedMemory::removeCachedBody(int bodyUniqueId) m_data->m_bodyJointMap.remove(bodyUniqueId); } } -void PhysicsClientSharedMemory::resetData() + +void PhysicsClientSharedMemory::clearCachedBodies() { - m_data->m_debugLinesFrom.clear(); - m_data->m_debugLinesTo.clear(); - m_data->m_debugLinesColor.clear(); for (int i = 0; i < m_data->m_bodyJointMap.size(); i++) { BodyJointInfoCache** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i); @@ -296,9 +294,17 @@ void PhysicsClientSharedMemory::resetData() } } m_data->m_bodyJointMap.clear(); +} + +void PhysicsClientSharedMemory::resetData() +{ + m_data->m_debugLinesFrom.clear(); + m_data->m_debugLinesTo.clear(); + m_data->m_debugLinesColor.clear(); m_data->m_userConstraintInfoMap.clear(); - m_data->m_userDataHandleLookup.clear(); m_data->m_userDataMap.clear(); + m_data->m_userDataHandleLookup.clear(); + clearCachedBodies(); } void PhysicsClientSharedMemory::setSharedMemoryKey(int key) { @@ -1270,6 +1276,7 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() case CMD_SYNC_BODY_INFO_COMPLETED: { + clearCachedBodies(); break; } case CMD_STATE_LOGGING_START_COMPLETED: @@ -1560,9 +1567,9 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() { (*bodyJointsPtr)->m_userDataIds.clear(); } - m_data->m_userDataMap.clear(); - m_data->m_userDataHandleLookup.clear(); } + m_data->m_userDataMap.clear(); + m_data->m_userDataHandleLookup.clear(); const int numIdentifiers = serverCmd.m_syncUserDataArgs.m_numUserDataIdentifiers; if (numIdentifiers > 0) { diff --git a/examples/SharedMemory/PhysicsClientSharedMemory.h b/examples/SharedMemory/PhysicsClientSharedMemory.h index bee0549f9..0ba485b61 100644 --- a/examples/SharedMemory/PhysicsClientSharedMemory.h +++ b/examples/SharedMemory/PhysicsClientSharedMemory.h @@ -15,6 +15,7 @@ protected: void processBodyJointInfo(int bodyUniqueId, const struct SharedMemoryStatus& serverCmd); void resetData(); void removeCachedBody(int bodyUniqueId); + void clearCachedBodies(); virtual void renderSceneInternal(){}; public: diff --git a/examples/SharedMemory/PhysicsDirect.cpp b/examples/SharedMemory/PhysicsDirect.cpp index d838cc7ba..ba0aa9508 100644 --- a/examples/SharedMemory/PhysicsDirect.cpp +++ b/examples/SharedMemory/PhysicsDirect.cpp @@ -142,6 +142,14 @@ void PhysicsDirect::resetData() m_data->m_debugLinesFrom.clear(); m_data->m_debugLinesTo.clear(); m_data->m_debugLinesColor.clear(); + m_data->m_userConstraintInfoMap.clear(); + m_data->m_userDataMap.clear(); + m_data->m_userDataHandleLookup.clear(); + clearCachedBodies(); +} + +void PhysicsDirect::clearCachedBodies() +{ for (int i = 0; i < m_data->m_bodyJointMap.size(); i++) { BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i); @@ -151,7 +159,6 @@ void PhysicsDirect::resetData() } } m_data->m_bodyJointMap.clear(); - m_data->m_userConstraintInfoMap.clear(); } // return true if connection succesfull, can also check 'isConnected' @@ -912,6 +919,7 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd break; } case CMD_SYNC_BODY_INFO_COMPLETED: + clearCachedBodies(); case CMD_MJCF_LOADING_COMPLETED: case CMD_SDF_LOADING_COMPLETED: { @@ -1193,6 +1201,8 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd { B3_PROFILE("CMD_SYNC_USER_DATA_COMPLETED"); // Remove all cached user data entries. + m_data->m_userDataMap.clear(); + m_data->m_userDataHandleLookup.clear(); for (int i = 0; i < m_data->m_bodyJointMap.size(); i++) { BodyJointInfoCache2** bodyJointsPtr = m_data->m_bodyJointMap.getAtIndex(i); @@ -1200,8 +1210,6 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd { (*bodyJointsPtr)->m_userDataIds.clear(); } - m_data->m_userDataMap.clear(); - m_data->m_userDataHandleLookup.clear(); } const int numIdentifiers = serverCmd.m_syncUserDataArgs.m_numUserDataIdentifiers; int* identifiers = new int[numIdentifiers]; diff --git a/examples/SharedMemory/PhysicsDirect.h b/examples/SharedMemory/PhysicsDirect.h index c5deec8ef..f0addbc11 100644 --- a/examples/SharedMemory/PhysicsDirect.h +++ b/examples/SharedMemory/PhysicsDirect.h @@ -34,6 +34,8 @@ protected: void removeCachedBody(int bodyUniqueId); + void clearCachedBodies(); + public: PhysicsDirect(class PhysicsCommandProcessorInterface* physSdk, bool passSdkOwnership); |