use RingBuffer for gradual garbage collection

This commit is contained in:
Andrew Meadows 2019-02-09 08:23:09 -08:00
parent c9b142531b
commit 8bdac589b8
2 changed files with 43 additions and 24 deletions

View file

@ -6309,40 +6309,53 @@ void Application::update(float deltaTime) {
PROFILE_RANGE(simulation_physics, "PrePhysics"); PROFILE_RANGE(simulation_physics, "PrePhysics");
PerformanceTimer perfTimer("prePhysics)"); PerformanceTimer perfTimer("prePhysics)");
{ {
PROFILE_RANGE(simulation_physics, "RemoveEntities");
const VectorOfMotionStates& motionStates = _entitySimulation->getObjectsToRemoveFromPhysics(); const VectorOfMotionStates& motionStates = _entitySimulation->getObjectsToRemoveFromPhysics();
_physicsEngine->removeObjects(motionStates); _physicsEngine->removeObjects(motionStates);
_entitySimulation->deleteObjectsRemovedFromPhysics(); _entitySimulation->deleteObjectsRemovedFromPhysics();
} }
VectorOfMotionStates motionStates; {
getEntities()->getTree()->withReadLock([&] { PROFILE_RANGE(simulation_physics, "AddEntities");
_entitySimulation->getObjectsToAddToPhysics(motionStates); VectorOfMotionStates motionStates;
_physicsEngine->addObjects(motionStates); getEntities()->getTree()->withReadLock([&] {
_entitySimulation->getObjectsToAddToPhysics(motionStates);
}); _physicsEngine->addObjects(motionStates);
getEntities()->getTree()->withReadLock([&] { });
_entitySimulation->getObjectsToChange(motionStates); }
VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates); {
_entitySimulation->setObjectsToChange(stillNeedChange); VectorOfMotionStates motionStates;
}); PROFILE_RANGE(simulation_physics, "ChangeEntities");
getEntities()->getTree()->withReadLock([&] {
_entitySimulation->getObjectsToChange(motionStates);
VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates);
_entitySimulation->setObjectsToChange(stillNeedChange);
});
}
_entitySimulation->applyDynamicChanges(); _entitySimulation->applyDynamicChanges();
t1 = std::chrono::high_resolution_clock::now(); t1 = std::chrono::high_resolution_clock::now();
PhysicsEngine::Transaction transaction; {
avatarManager->buildPhysicsTransaction(transaction); PROFILE_RANGE(simulation_physics, "Avatars");
_physicsEngine->processTransaction(transaction); PhysicsEngine::Transaction transaction;
avatarManager->handleProcessedPhysicsTransaction(transaction); avatarManager->buildPhysicsTransaction(transaction);
myAvatar->getCharacterController()->buildPhysicsTransaction(transaction); _physicsEngine->processTransaction(transaction);
_physicsEngine->processTransaction(transaction); avatarManager->handleProcessedPhysicsTransaction(transaction);
myAvatar->getCharacterController()->handleProcessedPhysicsTransaction(transaction); myAvatar->getCharacterController()->buildPhysicsTransaction(transaction);
myAvatar->prepareForPhysicsSimulation(); _physicsEngine->processTransaction(transaction);
_physicsEngine->enableGlobalContactAddedCallback(myAvatar->isFlying()); myAvatar->getCharacterController()->handleProcessedPhysicsTransaction(transaction);
myAvatar->prepareForPhysicsSimulation();
_physicsEngine->enableGlobalContactAddedCallback(myAvatar->isFlying());
}
_physicsEngine->forEachDynamic([&](EntityDynamicPointer dynamic) { {
dynamic->prepareForPhysicsSimulation(); PROFILE_RANGE(simulation_physics, "PrepareActions");
}); _physicsEngine->forEachDynamic([&](EntityDynamicPointer dynamic) {
dynamic->prepareForPhysicsSimulation();
});
}
} }
auto t2 = std::chrono::high_resolution_clock::now(); auto t2 = std::chrono::high_resolution_clock::now();
{ {

View file

@ -12,6 +12,8 @@
#ifndef hifi_ShapeManager_h #ifndef hifi_ShapeManager_h
#define hifi_ShapeManager_h #define hifi_ShapeManager_h
#include <vector>
#include <btBulletDynamicsCommon.h> #include <btBulletDynamicsCommon.h>
#include <LinearMath/btHashMap.h> #include <LinearMath/btHashMap.h>
@ -41,6 +43,7 @@
// later. When that list grows big enough the ShapeManager will remove any matching // later. When that list grows big enough the ShapeManager will remove any matching
// entries that still have zero ref-count. // entries that still have zero ref-count.
class ShapeManager { class ShapeManager {
public: public:
@ -75,7 +78,10 @@ private:
// btHashMap is required because it supports memory alignment of the btCollisionShapes // btHashMap is required because it supports memory alignment of the btCollisionShapes
btHashMap<HashKey, ShapeReference> _shapeMap; btHashMap<HashKey, ShapeReference> _shapeMap;
btAlignedObjectArray<uint64_t> _pendingGarbage; //btAlignedObjectArray<uint64_t> _pendingGarbage;
std::vector<uint64_t> _garbageRing;
uint32_t _ringIndex { 0 };
}; };
#endif // hifi_ShapeManager_h #endif // hifi_ShapeManager_h