diff options
author | Oussama <o.boukhelf@gmail.com> | 2019-01-03 14:26:51 +0100 |
---|---|---|
committer | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-01-07 12:30:35 +0100 |
commit | 22b7c9dfa80d0f7abca40f061865c2ab3c136a74 (patch) | |
tree | 311cd3f22b012329160f9d43810aea429994af48 /thirdparty/bullet/Bullet3Common/b3ResizablePool.h | |
parent | a6722cf36251ddcb538e6ebed9fa4950342b68ba (diff) |
Update Bullet to the latest commit 126b676
Diffstat (limited to 'thirdparty/bullet/Bullet3Common/b3ResizablePool.h')
-rw-r--r-- | thirdparty/bullet/Bullet3Common/b3ResizablePool.h | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/thirdparty/bullet/Bullet3Common/b3ResizablePool.h b/thirdparty/bullet/Bullet3Common/b3ResizablePool.h index 06ad8a778d..cafe3ff396 100644 --- a/thirdparty/bullet/Bullet3Common/b3ResizablePool.h +++ b/thirdparty/bullet/Bullet3Common/b3ResizablePool.h @@ -4,10 +4,10 @@ #include "Bullet3Common/b3AlignedObjectArray.h" -enum +enum { - B3_POOL_HANDLE_TERMINAL_FREE=-1, - B3_POOL_HANDLE_TERMINAL_USED =-2 + B3_POOL_HANDLE_TERMINAL_FREE = -1, + B3_POOL_HANDLE_TERMINAL_USED = -2 }; template <typename U> @@ -20,25 +20,23 @@ struct b3PoolBodyHandle : public U { m_nextFreeHandle = next; } - int getNextFree() const + int getNextFree() const { return m_nextFreeHandle; } }; -template <typename T> +template <typename T> class b3ResizablePool { - protected: - b3AlignedObjectArray<T> m_bodyHandles; - int m_numUsedHandles; // number of active handles - int m_firstFreeHandle; // free handles list + b3AlignedObjectArray<T> m_bodyHandles; + int m_numUsedHandles; // number of active handles + int m_firstFreeHandle; // free handles list T* getHandleInternal(int handle) { return &m_bodyHandles[handle]; - } const T* getHandleInternal(int handle) const { @@ -46,17 +44,16 @@ protected: } public: - b3ResizablePool() { initHandles(); } - + virtual ~b3ResizablePool() { exitHandles(); } -///handle management + ///handle management int getNumHandles() const { @@ -65,44 +62,40 @@ public: void getUsedHandles(b3AlignedObjectArray<int>& usedHandles) const { - - for (int i=0;i<m_bodyHandles.size();i++) + for (int i = 0; i < m_bodyHandles.size(); i++) { - if (m_bodyHandles[i].getNextFree()==B3_POOL_HANDLE_TERMINAL_USED) + if (m_bodyHandles[i].getNextFree() == B3_POOL_HANDLE_TERMINAL_USED) { usedHandles.push_back(i); } } } - - T* getHandle(int handle) { - b3Assert(handle>=0); - b3Assert(handle<m_bodyHandles.size()); - if ((handle<0) || (handle>=m_bodyHandles.size())) + b3Assert(handle >= 0); + b3Assert(handle < m_bodyHandles.size()); + if ((handle < 0) || (handle >= m_bodyHandles.size())) { return 0; } - if (m_bodyHandles[handle].getNextFree()==B3_POOL_HANDLE_TERMINAL_USED) + if (m_bodyHandles[handle].getNextFree() == B3_POOL_HANDLE_TERMINAL_USED) { return &m_bodyHandles[handle]; } return 0; - } const T* getHandle(int handle) const { - b3Assert(handle>=0); - b3Assert(handle<m_bodyHandles.size()); - if ((handle<0) || (handle>=m_bodyHandles.size())) + b3Assert(handle >= 0); + b3Assert(handle < m_bodyHandles.size()); + if ((handle < 0) || (handle >= m_bodyHandles.size())) { return 0; } - if (m_bodyHandles[handle].getNextFree()==B3_POOL_HANDLE_TERMINAL_USED) + if (m_bodyHandles[handle].getNextFree() == B3_POOL_HANDLE_TERMINAL_USED) { return &m_bodyHandles[handle]; } @@ -120,7 +113,6 @@ public: for (int i = curCapacity; i < newCapacity; i++) m_bodyHandles[i].setNextFree(i + 1); - m_bodyHandles[newCapacity - 1].setNextFree(-1); } m_firstFreeHandle = curCapacity; @@ -142,19 +134,18 @@ public: int allocHandle() { - b3Assert(m_firstFreeHandle>=0); + b3Assert(m_firstFreeHandle >= 0); int handle = m_firstFreeHandle; m_firstFreeHandle = getHandleInternal(handle)->getNextFree(); m_numUsedHandles++; - if (m_firstFreeHandle<0) + if (m_firstFreeHandle < 0) { //int curCapacity = m_bodyHandles.size(); - int additionalCapacity= m_bodyHandles.size(); + int additionalCapacity = m_bodyHandles.size(); increaseHandleCapacity(additionalCapacity); - getHandleInternal(handle)->setNextFree(m_firstFreeHandle); } getHandleInternal(handle)->setNextFree(B3_POOL_HANDLE_TERMINAL_USED); @@ -162,12 +153,11 @@ public: return handle; } - void freeHandle(int handle) { b3Assert(handle >= 0); - if (m_bodyHandles[handle].getNextFree()==B3_POOL_HANDLE_TERMINAL_USED) + if (m_bodyHandles[handle].getNextFree() == B3_POOL_HANDLE_TERMINAL_USED) { getHandleInternal(handle)->clear(); getHandleInternal(handle)->setNextFree(m_firstFreeHandle); @@ -176,7 +166,6 @@ public: } } }; - ///end handle management - - #endif //B3_RESIZABLE_POOL_H -
\ No newline at end of file +///end handle management + +#endif //B3_RESIZABLE_POOL_H |