12 #ifndef hifi_ShapeManager_h
13 #define hifi_ShapeManager_h
20 #include <btBulletDynamicsCommon.h>
21 #include <LinearMath/btHashMap.h>
23 #include <ShapeInfo.h>
25 #include "ShapeFactory.h"
51 class ShapeManager :
public QObject {
59 const btCollisionShape* getShape(
const ShapeInfo& info);
60 const btCollisionShape* getShapeByKey(uint64_t key);
61 bool hasShapeWithKey(uint64_t key)
const;
64 bool releaseShape(
const btCollisionShape* shape);
67 void collectGarbage();
70 int getNumShapes()
const {
return _shapeMap.size(); }
71 int getNumReferences(
const ShapeInfo& info)
const;
72 int getNumReferences(
const btCollisionShape* shape)
const;
73 bool hasShape(
const btCollisionShape* shape)
const;
74 uint32_t getWorkRequestCount()
const {
return _workRequestCount; }
75 uint32_t getWorkDeliveryCount()
const {
return _workDeliveryCount; }
78 void acceptWork(ShapeFactory::Worker* worker);
81 void addToGarbage(uint64_t key);
82 bool releaseShapeByKey(uint64_t key);
84 class ShapeReference {
87 const btCollisionShape* shape;
89 ShapeReference() : refCount(0), shape(nullptr) {}
92 using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
95 KeyExpiry(uint64_t k, std::chrono::time_point<std::chrono::steady_clock> e) : expiry(e), key(k) {}
101 btHashMap<HashKey, ShapeReference> _shapeMap;
102 std::vector<uint64_t> _garbageRing;
103 std::vector<uint64_t> _pendingMeshShapes;
104 std::vector<KeyExpiry> _orphans;
105 ShapeFactory::Worker* _deadWorker {
nullptr };
106 TimePoint _nextOrphanExpiry;
107 uint32_t _ringIndex { 0 };
108 std::atomic_uint _workRequestCount { 0 };
109 std::atomic_uint _workDeliveryCount { 0 };