From 4935a8c950eb063795c7cb197e5533c90b0f5453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 20 Jan 2022 11:59:12 +0100 Subject: [PATCH] Havok: Add hkpAgentNnTrack stub --- lib/hkStubs/CMakeLists.txt | 1 + .../Common/Base/Container/Array/hkArray.h | 41 ++++++++++++ .../Agent3/Machine/Nn/hkpAgentNnTrack.h | 64 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 lib/hkStubs/Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpAgentNnTrack.h diff --git a/lib/hkStubs/CMakeLists.txt b/lib/hkStubs/CMakeLists.txt index 2c3d8c4b..d60f9d99 100644 --- a/lib/hkStubs/CMakeLists.txt +++ b/lib/hkStubs/CMakeLists.txt @@ -77,6 +77,7 @@ add_library(hkStubs OBJECT Havok/Physics2012/Collide/Agent/Collidable/hkpCollidable.h Havok/Physics2012/Collide/Agent/Collidable/hkpCollidableQualityType.h Havok/Physics2012/Collide/Agent3/BvTree3/hkpBvTreeAgent3.h + Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpAgentNnTrack.h Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpLinkedCollidable.h Havok/Physics2012/Collide/BroadPhase/hkpBroadPhaseHandle.h Havok/Physics2012/Collide/BroadPhase/hkpTypedBroadPhaseHandle.h diff --git a/lib/hkStubs/Havok/Common/Base/Container/Array/hkArray.h b/lib/hkStubs/Havok/Common/Base/Container/Array/hkArray.h index 33f9f6f4..64e8e365 100644 --- a/lib/hkStubs/Havok/Common/Base/Container/Array/hkArray.h +++ b/lib/hkStubs/Havok/Common/Base/Container/Array/hkArray.h @@ -122,6 +122,27 @@ protected: HK_FORCE_INLINE hkArray(const hkArray& other); }; +template +class hkInplaceArray : public hkArray { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkInplaceArray) + + HK_FORCE_INLINE explicit hkInplaceArray(int size = 0); + HK_FORCE_INLINE hkInplaceArray(const hkInplaceArray& other); + explicit hkInplaceArray(hkFinishLoadedObjectFlag f) : hkArray(f) {} + HK_FORCE_INLINE ~hkInplaceArray() = default; + + using hkArray::operator=; + + HK_FORCE_INLINE void optimizeCapacity(int numFreeElemsLeft, hkBool32 shrinkExact = false); + + HK_FORCE_INLINE hkBool wasReallocated() const; + + HK_FORCE_INLINE int stillInplaceUsingMask() const; + + T m_storage[N]; +}; + template inline hkArrayBase::hkArrayBase() : m_data(nullptr), m_size(0), m_capacityAndFlags(DONT_DEALLOCATE_FLAG) {} @@ -358,3 +379,23 @@ template inline void hkArray::pushBack(const T& e) { this->_pushBack(AllocatorType().get(), e); } + +template +inline hkInplaceArray::hkInplaceArray(int size) + : hkArray(m_storage, size, N) {} + +template +inline hkInplaceArray::hkInplaceArray(const hkInplaceArray& other) + : hkArray(m_storage, 0, N) { + *this = other; +} + +template +inline hkBool hkInplaceArray::wasReallocated() const { + return this->m_data != m_storage; +} + +template +inline int hkInplaceArray::stillInplaceUsingMask() const { + return hkArray::m_capacityAndFlags & hkArrayBase::DONT_DEALLOCATE_FLAG; +} diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpAgentNnTrack.h b/lib/hkStubs/Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpAgentNnTrack.h new file mode 100644 index 00000000..005ced26 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpAgentNnTrack.h @@ -0,0 +1,64 @@ +#pragma once + +#include + +#define HK_AGENT3_MIDPHASE_AGENT_SIZE 80 +#define HK_AGENT3_NARROWPHASE_AGENT_SIZE 160 +#define HK_AGENT3_MAX_AGENT_SIZE 160 +#define HK_AGENT3_SECTOR_SIZE 960 + +struct hkpAgentNnEntry; + +enum hkpAgentNnTrackType { + HK_AGENT3_INVALID_TRACK = 0, + HK_AGENT3_MIDPHASE_TRACK = 1, + HK_AGENT3_NARROWPHASE_TRACK = 2, +}; + +struct hkpAgentNnSector { + HK_DECLARE_CLASS_ALLOCATOR(hkpAgentNnSector) + + hkpAgentNnEntry* getBegin() { return reinterpret_cast(m_data); } + + hkpAgentNnEntry* getEnd() { + return reinterpret_cast(m_data + HK_AGENT3_SECTOR_SIZE); + } + + hkUint8 m_data[HK_AGENT3_SECTOR_SIZE]; +}; + +struct hkpAgentNnTrack { + HK_DECLARE_CLASS_ALLOCATOR(hkpAgentNnTrack) + + explicit hkpAgentNnTrack(hkpAgentNnTrackType nnTrackType) { + m_bytesUsedInLastSector = HK_AGENT3_SECTOR_SIZE; + m_nnTrackType = nnTrackType; + } + + int getSectorSize(int sectorIndex) const; + HK_FORCE_INLINE static unsigned int getAgentSize(hkpAgentNnTrackType nnTrackType); + HK_FORCE_INLINE unsigned int getAgentSize() const; + + hkUint16 m_bytesUsedInLastSector; + + /// Does the track contain midphase or narrowphase agent entries? + hkEnum m_nnTrackType; + hkUint8 m_padding; + + hkInplaceArray m_sectors; +}; + +inline int hkpAgentNnTrack::getSectorSize(int sectorIndex) const { + if (sectorIndex + 1 == m_sectors.getSize()) { + return m_bytesUsedInLastSector; + } + return HK_AGENT3_SECTOR_SIZE; +} + +inline unsigned int hkpAgentNnTrack::getAgentSize(hkpAgentNnTrackType nnTrackType) { + return nnTrackType * HK_AGENT3_MIDPHASE_AGENT_SIZE; +} + +inline unsigned int hkpAgentNnTrack::getAgentSize() const { + return getAgentSize(m_nnTrackType); +}