From 15741ce3aee3e2dabbec2740f76cb52a2b53217f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 7 Jan 2022 13:02:06 +0100 Subject: [PATCH] Havok: Add stubs for hkpRigidBody parent classes --- lib/hkStubs/CMakeLists.txt | 25 ++- .../Base/Container/Array/hkSmallArray.h | 62 ++++++ .../MultiThreadCheck/hkMultiThreadCheck.h | 59 ++++++ .../Havok/Common/Base/Math/Matrix/hkMatrix3.h | 5 + .../Common/Base/Math/Matrix/hkMatrix3f.h | 12 ++ .../Common/Base/Math/Matrix/hkRotation.h | 5 + .../Common/Base/Math/Matrix/hkRotationf.h | 5 + .../Common/Base/Math/Matrix/hkTransform.h | 5 + .../Common/Base/Math/Matrix/hkTransformf.h | 10 + .../Base/Math/Quaternion/hkQuaternion.h | 5 + .../Base/Math/Quaternion/hkQuaternionf.h | 10 + .../Math/SweptTransform/hkSweptTransform.h | 5 + .../Math/SweptTransform/hkSweptTransformf.h | 15 ++ .../Common/Base/Math/Vector/hkSimdFloat32.h | 8 + .../Common/Base/Math/Vector/hkSimdReal.h | 6 + .../Havok/Common/Base/Math/Vector/hkVector4.h | 3 + .../Base/Math/Vector/hkVector4Comparison.h | 3 + .../Common/Base/Math/Vector/hkVector4f.h | 3 + lib/hkStubs/Havok/Common/Base/Math/hkMath.h | 15 +- .../Base/Memory/Router/hkMemoryRouter.h | 12 ++ .../Base/System/StackTracer/hkStackTracer.h | 9 + .../Types/Physics/MotionState/hkMotionState.h | 52 +++++ .../Base/Types/Properties/hkSimpleProperty.h | 118 +++++++++++ .../Havok/Common/Base/Types/hkBaseTypes.h | 3 + .../Havok/Common/Base/Types/hkUFloat8.h | 69 +++++++ lib/hkStubs/Havok/Common/Base/hkBase.h | 2 + .../Collide/Agent/Collidable/hkpCdBody.h | 1 - .../Agent3/Machine/Nn/hkpLinkedCollidable.h | 52 +++++ .../Physics2012/Collide/Shape/hkpShape.h | 23 +++ .../Physics2012/Collide/Shape/hkpShapeBase.h | 1 - .../Physics2012/Dynamics/Common/hkpMaterial.h | 92 +++++++++ .../Physics2012/Dynamics/Common/hkpProperty.h | 6 + .../Physics2012/Dynamics/Entity/hkpEntity.h | 108 ++++++++-- .../Dynamics/Entity/hkpRigidBody.h | 24 ++- .../Motion/Rigid/hkpKeyframedRigidMotion.h | 59 ++++++ .../Physics2012/Dynamics/Motion/hkpMotion.h | 97 +++++++++ .../Dynamics/World/hkpPhysicsSystem.h | 1 - .../Dynamics/World/hkpWorldEntity.h | 21 -- .../Dynamics/World/hkpWorldObject.h | 188 +++++++++++++++++- .../Physics/RigidBody/physRigidBody.cpp | 10 +- 40 files changed, 1148 insertions(+), 61 deletions(-) create mode 100644 lib/hkStubs/Havok/Common/Base/Container/Array/hkSmallArray.h create mode 100644 lib/hkStubs/Havok/Common/Base/DebugUtil/MultiThreadCheck/hkMultiThreadCheck.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotation.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransform.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternion.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/SweptTransform/hkSweptTransform.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/SweptTransform/hkSweptTransformf.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h create mode 100644 lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdReal.h create mode 100644 lib/hkStubs/Havok/Common/Base/System/StackTracer/hkStackTracer.h create mode 100644 lib/hkStubs/Havok/Common/Base/Types/Physics/MotionState/hkMotionState.h create mode 100644 lib/hkStubs/Havok/Common/Base/Types/Properties/hkSimpleProperty.h create mode 100644 lib/hkStubs/Havok/Common/Base/Types/hkUFloat8.h create mode 100644 lib/hkStubs/Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpLinkedCollidable.h create mode 100644 lib/hkStubs/Havok/Physics2012/Dynamics/Common/hkpMaterial.h create mode 100644 lib/hkStubs/Havok/Physics2012/Dynamics/Common/hkpProperty.h create mode 100644 lib/hkStubs/Havok/Physics2012/Dynamics/Motion/Rigid/hkpKeyframedRigidMotion.h create mode 100644 lib/hkStubs/Havok/Physics2012/Dynamics/Motion/hkpMotion.h delete mode 100644 lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpWorldEntity.h diff --git a/lib/hkStubs/CMakeLists.txt b/lib/hkStubs/CMakeLists.txt index 4270759f..111b289a 100644 --- a/lib/hkStubs/CMakeLists.txt +++ b/lib/hkStubs/CMakeLists.txt @@ -6,9 +6,24 @@ add_library(hkStubs OBJECT Havok/Common/Base/Container/hkContainerAllocators.h Havok/Common/Base/Container/Array/hkArray.h Havok/Common/Base/Container/Array/hkArrayUtil.h + Havok/Common/Base/Container/Array/hkSmallArray.h Havok/Common/Base/Container/String/hkStringPtr.h + Havok/Common/Base/DebugUtil/MultiThreadCheck/hkMultiThreadCheck.h + Havok/Common/Base/Math/hkMath.h + Havok/Common/Base/Math/Matrix/hkMatrix3.h + Havok/Common/Base/Math/Matrix/hkMatrix3f.h + Havok/Common/Base/Math/Matrix/hkRotation.h + Havok/Common/Base/Math/Matrix/hkRotationf.h + Havok/Common/Base/Math/Matrix/hkTransform.h + Havok/Common/Base/Math/Matrix/hkTransformf.h + Havok/Common/Base/Math/Quaternion/hkQuaternion.h + Havok/Common/Base/Math/Quaternion/hkQuaternionf.h + Havok/Common/Base/Math/SweptTransform/hkSweptTransform.h + Havok/Common/Base/Math/SweptTransform/hkSweptTransformf.h + Havok/Common/Base/Math/Vector/hkSimdFloat32.h + Havok/Common/Base/Math/Vector/hkSimdReal.h Havok/Common/Base/Math/Vector/hkVector4.h Havok/Common/Base/Math/Vector/hkVector4f.h Havok/Common/Base/Math/Vector/hkVector4Comparison.h @@ -28,6 +43,8 @@ add_library(hkStubs OBJECT Havok/Common/Base/Reflection/hkClassMember.h Havok/Common/Base/Reflection/hkTypeInfo.h + Havok/Common/Base/System/StackTracer/hkStackTracer.h + Havok/Common/Base/Thread/Atomic/hkAtomicPrimitives.h Havok/Common/Base/Thread/Thread/hkThreadLocalData.h @@ -36,6 +53,8 @@ add_library(hkStubs OBJECT Havok/Common/Base/Types/hkRefPtr.h Havok/Common/Base/Types/hkRefVariant.h Havok/Common/Base/Types/Geometry/Aabb/hkAabb.h + Havok/Common/Base/Types/Physics/MotionState/hkMotionState.h + Havok/Common/Base/Types/Properties/hkSimpleProperty.h Havok/Common/Serialize/Resource/hkResource.h Havok/Common/Serialize/Util/hkNativePackfileUtils.h @@ -49,6 +68,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/hkpLinkedCollidable.h Havok/Physics2012/Collide/BroadPhase/hkpBroadPhaseHandle.h Havok/Physics2012/Collide/BroadPhase/hkpTypedBroadPhaseHandle.h Havok/Physics2012/Collide/Dispatch/hkpCollisionDispatcher.h @@ -74,14 +94,17 @@ add_library(hkStubs OBJECT Havok/Physics2012/Collide/Shape/Query/hkpShapeRayCastInput.h Havok/Physics2012/Collide/Util/Welding/hkpWeldingUtility.h + Havok/Physics2012/Dynamics/Common/hkpMaterial.h + Havok/Physics2012/Dynamics/Common/hkpProperty.h Havok/Physics2012/Dynamics/Entity/hkpEntity.h Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h + Havok/Physics2012/Dynamics/Motion/hkpMotion.h + Havok/Physics2012/Dynamics/Motion/Rigid/hkpKeyframedRigidMotion.h Havok/Physics2012/Dynamics/World/hkpPhysicsSystem.h Havok/Physics2012/Dynamics/World/hkpWorld.cpp Havok/Physics2012/Dynamics/World/hkpWorld.h Havok/Physics2012/Dynamics/World/hkpWorldCinfo.cpp Havok/Physics2012/Dynamics/World/hkpWorldCinfo.h - Havok/Physics2012/Dynamics/World/hkpWorldEntity.h Havok/Physics2012/Dynamics/World/hkpWorldObject.h Havok/Physics2012/Dynamics/World/Memory/hkpWorldMemoryAvailableWatchDog.h Havok/Physics2012/Dynamics/World/Memory/Default/hkpDefaultWorldMemoryWatchDog.h diff --git a/lib/hkStubs/Havok/Common/Base/Container/Array/hkSmallArray.h b/lib/hkStubs/Havok/Common/Base/Container/Array/hkSmallArray.h new file mode 100644 index 00000000..091c1e3e --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Container/Array/hkSmallArray.h @@ -0,0 +1,62 @@ +#pragma once + +#include +#include +#include + +template +class hkSmallArray { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkSmallArray) + + enum : int { + CAPACITY_MASK = hkUint16(0x3fff), + FLAG_MASK = hkUint16(0xC000), + DONT_DEALLOCATE_FLAG = hkUint16(0x8000), + LOCKED_FLAG = hkUint16(0x4000), + }; + + HK_FORCE_INLINE hkSmallArray(); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) + explicit hkSmallArray(hkFinishLoadedObjectFlag f) {} + + hkSmallArray(const hkSmallArray&) = delete; + auto operator=(const hkSmallArray&) = delete; + + HK_FORCE_INLINE ~hkSmallArray(); + + HK_FORCE_INLINE int getSize() const; + HK_FORCE_INLINE int getCapacity() const; + +protected: + void releaseMemory(); + + T* m_data; + hkUint16 m_size; + hkUint16 m_capacityAndFlags; +}; + +template +inline hkSmallArray::hkSmallArray() + : m_data(nullptr), m_size(0), m_capacityAndFlags(DONT_DEALLOCATE_FLAG) {} + +template +inline hkSmallArray::~hkSmallArray() { + releaseMemory(); +} + +template +inline int hkSmallArray::getSize() const { + return m_size; +} + +template +inline int hkSmallArray::getCapacity() const { + return m_capacityAndFlags & CAPACITY_MASK; +} + +template +inline void hkSmallArray::releaseMemory() { + if ((m_capacityAndFlags & DONT_DEALLOCATE_FLAG) == 0) + hkDeallocateChunk(m_data, getCapacity()); +} diff --git a/lib/hkStubs/Havok/Common/Base/DebugUtil/MultiThreadCheck/hkMultiThreadCheck.h b/lib/hkStubs/Havok/Common/Base/DebugUtil/MultiThreadCheck/hkMultiThreadCheck.h new file mode 100644 index 00000000..a591dc10 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/DebugUtil/MultiThreadCheck/hkMultiThreadCheck.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include + +class hkCriticalSection; + +class hkMultiThreadCheck { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkMultiThreadCheck) + HK_DECLARE_REFLECTION() + + enum AccessType { + HK_ACCESS_IGNORE = 0, + HK_ACCESS_RO = 1, + HK_ACCESS_RW = 2, + }; + + enum ReadMode { + THIS_OBJECT_ONLY, + RECURSIVE, + }; + + enum : hkUint32 { + MARKED_RO = 0xffffffe1, // and all children + MARKED_RO_SELF_ONLY = 0xffffffc1, + UNMARKED = 0xfffffff1 + }; + + HK_FORCE_INLINE hkMultiThreadCheck(); + + HK_FORCE_INLINE void init(); + + HK_FORCE_INLINE void markForRead(ReadMode mode = RECURSIVE) {} + HK_FORCE_INLINE void markForWrite() {} + HK_FORCE_INLINE bool isMarkedForWrite() { return true; } + HK_FORCE_INLINE bool isMarkedForReadRecursive() { return true; } + HK_FORCE_INLINE void unmarkForRead() {} + HK_FORCE_INLINE void unmarkForWrite() {} + + hkUint32 m_threadId; + static hkStackTracer s_stackTracer; + static hkStackTracer::CallTree* s_stackTree; + int m_stackTraceId; + hkUint16 m_markCount; + static hkCriticalSection* m_criticalSection; + static void globalCriticalSectionLock(); + static void globalCriticalSectionUnlock(); + +protected: + hkUint16 m_markBitStack; +}; + +inline hkMultiThreadCheck::hkMultiThreadCheck() : m_threadId(UNMARKED), m_markCount(0x8000) {} + +inline void hkMultiThreadCheck::init() { + m_threadId = UNMARKED; + m_markCount = 0x8000; +} diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3.h new file mode 100644 index 00000000..4e5b2c6a --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +using hkMatrix3 = hkMatrix3f; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.h new file mode 100644 index 00000000..3046e638 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +class hkMatrix3f { +public: + hkMatrix3f() {} // NOLINT(modernize-use-equals-default) + + hkVector4f m_col0; + hkVector4f m_col1; + hkVector4f m_col2; +}; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotation.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotation.h new file mode 100644 index 00000000..e9c20553 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotation.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +using hkRotation = hkRotationf; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h new file mode 100644 index 00000000..1a24fcc6 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +class hkRotationf : public hkMatrix3f {}; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransform.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransform.h new file mode 100644 index 00000000..c7abeb43 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransform.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +using hkTransform = hkTransformf; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h new file mode 100644 index 00000000..2cbcad81 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +class hkTransformf { +public: + hkRotationf m_rotation; + hkVector4f m_translation; +}; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternion.h b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternion.h new file mode 100644 index 00000000..b161a987 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternion.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +using hkQuaternion = hkQuaternionf; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h new file mode 100644 index 00000000..d1375727 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +class hkQuaternionf { +public: + hkQuaternionf() {} // NOLINT(modernize-use-equals-default) + + hkVector4f m_vec; +}; diff --git a/lib/hkStubs/Havok/Common/Base/Math/SweptTransform/hkSweptTransform.h b/lib/hkStubs/Havok/Common/Base/Math/SweptTransform/hkSweptTransform.h new file mode 100644 index 00000000..c2731a2e --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/SweptTransform/hkSweptTransform.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +using hkSweptTransform = hkSweptTransformf; diff --git a/lib/hkStubs/Havok/Common/Base/Math/SweptTransform/hkSweptTransformf.h b/lib/hkStubs/Havok/Common/Base/Math/SweptTransform/hkSweptTransformf.h new file mode 100644 index 00000000..b2679272 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/SweptTransform/hkSweptTransformf.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +class hkSweptTransformf { +public: + hkSweptTransformf() {} + + hkVector4f m_centerOfMass0; + hkVector4f m_centerOfMass1; + hkQuaternionf m_rotation0; + hkQuaternionf m_rotation1; + hkVector4f m_centerOfMassLocal; +}; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h new file mode 100644 index 00000000..5aa8ee5a --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +class hkSimdFloat32 { +public: + hkFloat32 m_real; +}; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdReal.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdReal.h new file mode 100644 index 00000000..dd7ec7b0 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdReal.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +using hkSimdReal = hkSimdFloat32; +using hkSimdRealParameter = const hkSimdReal&; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4.h index a1cff43c..78dd5d53 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4.h @@ -1,3 +1,6 @@ #pragma once #include + +using hkVector4 = hkVector4f; +using hkVector4Parameter = const hkVector4f&; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4Comparison.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4Comparison.h index 30be489b..6c233e4e 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4Comparison.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4Comparison.h @@ -1,3 +1,6 @@ #pragma once #include + +using hkVector4Comparison = hkVector4fComparison; +using hkVector4ComparisonParameter = const hkVector4Comparison&; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h index e8a6039b..6efb3a53 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h @@ -9,6 +9,9 @@ #define HK_VECTOR4F_AARCH64_NEON #endif +using hkVector4fParameter = const class hkVector4f&; +using hkVector4fComparisonParameter = const class hkVector4fComparison&; + class hkVector4f { public: HK_DECLARE_CLASS_ALLOCATOR(hkVector4f) diff --git a/lib/hkStubs/Havok/Common/Base/Math/hkMath.h b/lib/hkStubs/Havok/Common/Base/Math/hkMath.h index 5358f5a6..a0333434 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/hkMath.h +++ b/lib/hkStubs/Havok/Common/Base/Math/hkMath.h @@ -2,15 +2,10 @@ #include -class hkVector4f; -using hkVector4fParameter = const hkVector4f&; -class hkVector4fComparison; -using hkVector4fComparisonParameter = const hkVector4fComparison&; - +#include +#include +#include +#include +#include #include #include - -using hkVector4 = hkVector4f; -using hkVector4Parameter = const hkVector4f&; -using hkVector4Comparison = hkVector4fComparison; -using hkVector4ComparisonParameter = hkVector4fComparisonParameter; diff --git a/lib/hkStubs/Havok/Common/Base/Memory/Router/hkMemoryRouter.h b/lib/hkStubs/Havok/Common/Base/Memory/Router/hkMemoryRouter.h index aa34ac5b..17766817 100644 --- a/lib/hkStubs/Havok/Common/Base/Memory/Router/hkMemoryRouter.h +++ b/lib/hkStubs/Havok/Common/Base/Memory/Router/hkMemoryRouter.h @@ -70,6 +70,18 @@ protected: static HK_THREAD_LOCAL(hkMemoryRouter*) s_memoryRouter; }; +template +HK_FORCE_INLINE TYPE* hkAllocateChunk(int numberOfObjects) { + return static_cast(hkMemoryRouter::getInstance().heap().blockAlloc( + numberOfObjects * hkSizeOfTypeOrVoid::val)); +} + +template +HK_FORCE_INLINE void hkDeallocateChunk(TYPE* ptr, int numberOfObjects) { + hkMemoryRouter::getInstance().heap().blockFree(static_cast(ptr), + numberOfObjects * hkSizeOfTypeOrVoid::val); +} + #define HK_DECLARE_CLASS_ALLOCATOR_IMPL(CLASS_TYPE, ALLOCATOR) \ /* clang-tidy fails to understand that the operator delete matches the operator new */ \ /* NOLINTNEXTLINE(misc-new-delete-overloads) */ \ diff --git a/lib/hkStubs/Havok/Common/Base/System/StackTracer/hkStackTracer.h b/lib/hkStubs/Havok/Common/Base/System/StackTracer/hkStackTracer.h new file mode 100644 index 00000000..78822765 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/System/StackTracer/hkStackTracer.h @@ -0,0 +1,9 @@ +#pragma once + +class hkStackTracer { +public: + class CallTree; + + hkStackTracer(); + virtual ~hkStackTracer(); +}; diff --git a/lib/hkStubs/Havok/Common/Base/Types/Physics/MotionState/hkMotionState.h b/lib/hkStubs/Havok/Common/Base/Types/Physics/MotionState/hkMotionState.h new file mode 100644 index 00000000..d96834a9 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Types/Physics/MotionState/hkMotionState.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include + +class hkMotionState { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkMotionState) + HK_DECLARE_REFLECTION() + + inline hkMotionState(); + + void initMotionState(const hkVector4& position, const hkQuaternion& rotation); + + inline hkTransform& getTransform(); + inline const hkTransform& getTransform() const; + + inline hkSweptTransform& getSweptTransform(); + inline const hkSweptTransform& getSweptTransform() const; + +protected: + hkTransform m_transform; + hkSweptTransform m_sweptTransform; + +public: + hkVector4 m_deltaAngle; + hkReal m_objectRadius; + hkHalf m_linearDamping; + hkHalf m_angularDamping; + hkHalf m_timeFactor; + hkUFloat8 m_maxLinearVelocity; + hkUFloat8 m_maxAngularVelocity; + hkUint8 m_deactivationClass; +}; + +inline hkMotionState::hkMotionState() = default; + +inline hkTransform& hkMotionState::getTransform() { + return m_transform; +} + +inline const hkTransform& hkMotionState::getTransform() const { + return m_transform; +} + +inline hkSweptTransform& hkMotionState::getSweptTransform() { + return m_sweptTransform; +} + +inline const hkSweptTransform& hkMotionState::getSweptTransform() const { + return m_sweptTransform; +} diff --git a/lib/hkStubs/Havok/Common/Base/Types/Properties/hkSimpleProperty.h b/lib/hkStubs/Havok/Common/Base/Types/Properties/hkSimpleProperty.h new file mode 100644 index 00000000..e8ea291b --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Types/Properties/hkSimpleProperty.h @@ -0,0 +1,118 @@ +#pragma once + +#include + +struct hkSimplePropertyValue { + HK_DECLARE_CLASS_ALLOCATOR(hkSimplePropertyValue) + HK_DECLARE_REFLECTION() + + hkUint64 m_data; + + inline hkSimplePropertyValue() = default; + inline hkSimplePropertyValue(int i); // NOLINT(google-explicit-constructor) + inline hkSimplePropertyValue(hkUint32 i); // NOLINT(google-explicit-constructor) + inline hkSimplePropertyValue(hkUint64 i); // NOLINT(google-explicit-constructor) + inline hkSimplePropertyValue(hkReal r); // NOLINT(google-explicit-constructor) + inline hkSimplePropertyValue(void* p); // NOLINT(google-explicit-constructor) + + inline void setInt(int i); + inline void setUint64(hkUint64 i); + inline void setReal(hkReal r); + inline void setPtr(void* p); + + inline int getInt() const; + inline hkUint64 getUint64() const; + inline hkReal getReal() const; + inline void* getPtr() const; +}; + +class hkSimpleProperty { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkSimpleProperty) + HK_DECLARE_REFLECTION() + + inline hkSimpleProperty(); + inline hkSimpleProperty(hkUint32 key, hkSimplePropertyValue value); + explicit hkSimpleProperty(hkFinishLoadedObjectFlag flag) {} + + static void mapStringToKey(const char* string, hkUint32& keyOut); + + hkUint32 m_key; + hkUint32 m_alignmentPadding; + hkSimplePropertyValue m_value; +}; + +inline void hkSimplePropertyValue::setInt(const int i) { + m_data = i; +} + +inline void hkSimplePropertyValue::setUint64(hkUint64 i) { + m_data = i; +} + +inline void hkSimplePropertyValue::setReal(const hkReal r) { + union { + hkReal r; +#if defined(HK_REAL_IS_DOUBLE) + hkUint64 u; +#else + hkUint32 u; +#endif + } u; + u.r = r; + m_data = u.u; +} + +inline void hkSimplePropertyValue::setPtr(void* p) { + m_data = reinterpret_cast(p); +} + +inline hkSimplePropertyValue::hkSimplePropertyValue(const int i) { + setInt(i); +} + +inline hkSimplePropertyValue::hkSimplePropertyValue(const hkUint32 i) { + setInt(static_cast(i)); +} + +inline hkSimplePropertyValue::hkSimplePropertyValue(const hkUint64 i) { + setUint64(i); +} + +inline hkSimplePropertyValue::hkSimplePropertyValue(const hkReal r) { + setReal(r); +} + +inline hkSimplePropertyValue::hkSimplePropertyValue(void* p) { + setPtr(p); +} + +inline int hkSimplePropertyValue::getInt() const { + return static_cast(m_data); +} + +inline hkUint64 hkSimplePropertyValue::getUint64() const { + return m_data; +} + +inline hkReal hkSimplePropertyValue::getReal() const { + union { + hkReal r; +#if defined(HK_REAL_IS_DOUBLE) + hkUint64 u; +#else + hkUint32 u; +#endif + } u; + u.u = m_data; + return u.r; +} + +inline void* hkSimplePropertyValue::getPtr() const { + return reinterpret_cast(static_cast(m_data)); +} + +inline hkSimpleProperty::hkSimpleProperty() = default; + +inline hkSimpleProperty::hkSimpleProperty(hkUint32 key, hkSimplePropertyValue value) + : m_key(key), m_value(value) {} diff --git a/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h b/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h index a3e31a26..8b4ab3c6 100644 --- a/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h +++ b/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h @@ -24,6 +24,9 @@ using hk_size_t = std::size_t; using hkLong = long; using hkUlong = unsigned long; +using hkObjectIndex = hkUint16; +using hkTime = hkReal; + using m128 = __attribute((vector_size(16))) float; class hkHalf { diff --git a/lib/hkStubs/Havok/Common/Base/Types/hkUFloat8.h b/lib/hkStubs/Havok/Common/Base/Types/hkUFloat8.h new file mode 100644 index 00000000..ed4d308c --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Types/hkUFloat8.h @@ -0,0 +1,69 @@ +#pragma once + +#include +#include + +#define HK_UFLOAT8_MAX_VALUE 256 +#define hkUFloat8_eps 0.01f +#define hkUFloat8_maxValue 1000000.0f + +class hkUFloat8 { +public: + enum { + MAX_VALUE = HK_UFLOAT8_MAX_VALUE, + + // Constants used in compressing / decompressing the values table + ENCODED_EXPONENT_BITS = 5, + ENCODED_MANTISSA_BITS = (16 - ENCODED_EXPONENT_BITS), + ENCODED_EXPONENT_BIAS = 119, + ENCODED_EXPONENT_MASK = (1 << ENCODED_EXPONENT_BITS) - 1, + ENCODED_MANTISSA_MASK = (1 << ENCODED_MANTISSA_BITS) - 1, + + FLOAT_MANTISSA_BITS = 23, + FLOAT_MANTISSA_MASK = (1 << FLOAT_MANTISSA_BITS) - 1, + + ENCODE_MANTISSA_SHIFT = (FLOAT_MANTISSA_BITS - ENCODED_MANTISSA_BITS), + DECODE_EXPONENT_BIAS = + (ENCODED_EXPONENT_BIAS << (FLOAT_MANTISSA_BITS - ENCODE_MANTISSA_SHIFT)), + }; + + HK_FORCE_INLINE hkUFloat8() {} + HK_FORCE_INLINE hkUFloat8(float f) { *this = f; } // NOLINT(google-explicit-constructor) + HK_FORCE_INLINE hkUFloat8(double d) { *this = d; } // NOLINT(google-explicit-constructor) + + hkUFloat8& operator=(const double& dv); + hkUFloat8& operator=(const float& fv); + + HK_FORCE_INLINE bool isZero() const { return m_value == 0; } + HK_FORCE_INLINE void setZero() { m_value = 0; } + + HK_FORCE_INLINE bool isMax() const { return m_value == 255; } + HK_FORCE_INLINE void setMax() { m_value = 255; } + + HK_FORCE_INLINE hkBool operator==(const hkUFloat8& other) const { + return m_value == other.m_value; + } + + HK_FORCE_INLINE void setArithmeticMean(const hkUFloat8& a, const hkUFloat8& b) { + m_value = hkUint8((int(a.m_value) + int(b.m_value)) >> 1); + } + + // NOLINTNEXTLINE(google-explicit-constructor) + HK_FORCE_INLINE operator float() const { return decodeFloat(getEncodedFloat(m_value)); } + + static HK_FORCE_INLINE float decodeFloat(const hkUint16 i) { + const int intExpo = (i + hkUFloat8::DECODE_EXPONENT_BIAS) + << hkUFloat8::ENCODE_MANTISSA_SHIFT; + union { + const float* f; + const int* i; + } f2i; + f2i.i = &intExpo; + return i ? *f2i.f : 0.0f; + } + + hkUint8 m_value; + +protected: + static hkUint16 getEncodedFloat(hkUint8 index); +}; diff --git a/lib/hkStubs/Havok/Common/Base/hkBase.h b/lib/hkStubs/Havok/Common/Base/hkBase.h index 850f490a..a94eaf9b 100644 --- a/lib/hkStubs/Havok/Common/Base/hkBase.h +++ b/lib/hkStubs/Havok/Common/Base/hkBase.h @@ -6,10 +6,12 @@ #include #include #include +#include #include #include #include +#include #include diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCdBody.h b/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCdBody.h index f3e9e260..13e9a75b 100644 --- a/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCdBody.h +++ b/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCdBody.h @@ -4,7 +4,6 @@ #include class hkMotionState; -class hkTransform; class hkpCollidable; class hkpCdBody { diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpLinkedCollidable.h b/lib/hkStubs/Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpLinkedCollidable.h new file mode 100644 index 00000000..7bd0f5e3 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Agent3/Machine/Nn/hkpLinkedCollidable.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include + +struct hkpAgentNnEntry; + +class hkpLinkedCollidable : public hkpCollidable { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpLinkedCollidable) + HK_DECLARE_REFLECTION() + + struct CollisionEntry { + HK_DECLARE_CLASS_ALLOCATOR(CollisionEntry) + + hkpAgentNnEntry* m_agentEntry; + hkpLinkedCollidable* m_partner; + }; + + inline hkpLinkedCollidable(const hkpShape* shape, const hkMotionState* ms, int type = 0); + explicit hkpLinkedCollidable(hkFinishLoadedObjectFlag flag) : hkpCollidable(flag) {} + inline ~hkpLinkedCollidable(); + + void getCollisionEntriesSorted(hkArray& entries) const; + + hkArray& getCollisionEntriesDeterministicUnchecked(); + const hkArray& getCollisionEntriesDeterministicUnchecked() const; + + hkArray& getCollisionEntriesNonDeterministic(); + const hkArray& getCollisionEntriesNonDeterministic() const; + + void sortEntries(); + +protected: + hkArray m_collisionEntries; +}; + +inline hkpLinkedCollidable::hkpLinkedCollidable(const hkpShape* shape, const hkMotionState* ms, + int type) + : hkpCollidable(shape, ms, type) {} + +inline hkpLinkedCollidable::~hkpLinkedCollidable() = default; + +inline hkArray& +hkpLinkedCollidable::getCollisionEntriesNonDeterministic() { + return m_collisionEntries; +} + +inline const hkArray& +hkpLinkedCollidable::getCollisionEntriesNonDeterministic() const { + return m_collisionEntries; +} diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShape.h b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShape.h index 80fc2a51..c8d709f4 100644 --- a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShape.h +++ b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShape.h @@ -32,3 +32,26 @@ public: hkUlong m_userData; }; + +class hkpShapeKeyPair { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpShapeKeyPair) + + hkpShapeKey m_shapeKeyA; + hkpShapeKey m_shapeKeyB; + + HK_FORCE_INLINE bool operator==(const hkpShapeKeyPair& p1) const { + return m_shapeKeyB == p1.m_shapeKeyB && m_shapeKeyA == p1.m_shapeKeyA; + } + + HK_FORCE_INLINE bool operator<(const hkpShapeKeyPair& p1) const { + return (m_shapeKeyA < p1.m_shapeKeyA) || + (m_shapeKeyA == p1.m_shapeKeyA && m_shapeKeyB < p1.m_shapeKeyB); + } +}; + +class hkpShapeModifier { +public: + virtual ~hkpShapeModifier() = default; + virtual void modifyShape(hkpShape* shapeInOut) = 0; +}; diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeBase.h b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeBase.h index 09c38774..ca3be434 100644 --- a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeBase.h +++ b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeBase.h @@ -8,7 +8,6 @@ using hkpShapeKey = hkUint32; class hkAabb; class hkSphere; -class hkTransform; class hkcdVertex; class hkpCdBody; class hkpRayHitCollector; diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/Common/hkpMaterial.h b/lib/hkStubs/Havok/Physics2012/Dynamics/Common/hkpMaterial.h new file mode 100644 index 00000000..a23f6516 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Dynamics/Common/hkpMaterial.h @@ -0,0 +1,92 @@ +#pragma once + +#include +#include + +class hkpMaterial { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpMaterial) + HK_DECLARE_REFLECTION() + + enum ResponseType { + RESPONSE_INVALID, + RESPONSE_SIMPLE_CONTACT, + RESPONSE_REPORTING, + RESPONSE_NONE, + RESPONSE_MAX_ID + }; + + inline hkpMaterial(); + explicit hkpMaterial(hkFinishLoadedObjectFlag flag) {} + + inline hkReal getFriction() const; + inline void setFriction(hkReal newFriction); + static inline hkReal getCombinedFriction(hkReal frictionA, hkReal frictionB); + + inline hkReal getRestitution() const; + inline void setRestitution(hkReal newRestitution); + static inline hkReal getCombinedRestitution(hkReal restitutionA, hkReal restitutionB); + + inline hkReal getRollingFrictionMultiplier() const; + inline void setRollingFrictionMultiplier(hkReal newRollingFrictionMultiplier); + static inline hkReal getCombinedRollingFrictionMultiplier(hkReal multiplierA, + hkReal multiplierB); + + inline enum hkpMaterial::ResponseType getResponseType() const; + inline void setResponseType(enum hkpMaterial::ResponseType t); + +private: + hkEnum m_responseType; + hkHalf m_rollingFrictionMultiplier; + hkReal m_friction; + hkReal m_restitution; +}; + +inline hkpMaterial::hkpMaterial() : m_friction(0.5), m_restitution(0.4) { + m_rollingFrictionMultiplier.setZero(); +} + +inline hkReal hkpMaterial::getFriction() const { + return m_friction; +} + +inline void hkpMaterial::setFriction(hkReal newFriction) { + m_friction = newFriction; +} + +inline hkReal hkpMaterial::getCombinedFriction(hkReal frictionA, hkReal frictionB) { + return std::sqrt(frictionA * frictionB); +} + +inline hkReal hkpMaterial::getRestitution() const { + return m_restitution; +} + +inline void hkpMaterial::setRestitution(hkReal newRestitution) { + m_restitution = newRestitution; +} + +inline hkReal hkpMaterial::getCombinedRestitution(hkReal restitutionA, hkReal restitutionB) { + return std::sqrt(restitutionA * restitutionB); +} + +inline hkReal hkpMaterial::getRollingFrictionMultiplier() const { + return m_rollingFrictionMultiplier; +} + +inline void hkpMaterial::setRollingFrictionMultiplier(hkReal newRollingFrictionMultiplier) { + m_rollingFrictionMultiplier = newRollingFrictionMultiplier; +} + +inline hkReal hkpMaterial::getCombinedRollingFrictionMultiplier(hkReal multiplierA, + hkReal multiplierB) { + return std::sqrt(multiplierA * multiplierB); +} + +inline hkpMaterial::ResponseType hkpMaterial::getResponseType() const { + return m_responseType; +} + +inline void hkpMaterial::setResponseType(hkpMaterial::ResponseType t) { + m_responseType = t; +} diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/Common/hkpProperty.h b/lib/hkStubs/Havok/Physics2012/Dynamics/Common/hkpProperty.h new file mode 100644 index 00000000..2e2e06cd --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Dynamics/Common/hkpProperty.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +using hkpPropertyValue = hkSimplePropertyValue; +using hkpProperty = hkSimpleProperty; diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/Entity/hkpEntity.h b/lib/hkStubs/Havok/Physics2012/Dynamics/Entity/hkpEntity.h index 12059ceb..9afc4cdd 100644 --- a/lib/hkStubs/Havok/Physics2012/Dynamics/Entity/hkpEntity.h +++ b/lib/hkStubs/Havok/Physics2012/Dynamics/Entity/hkpEntity.h @@ -1,25 +1,95 @@ #pragma once -#include +#include +#include +#include +#include -class hkpMotion { +struct hkConstraintInternal; +class hkLocalFrame; +class hkSpuCollisionCallbackUtil; +class hkpAction; +class hkpBreakableBody; +class hkpConstraintInstance; +class hkpContactListener; +class hkpEntityActivationListener; +class hkpEntityListener; +class hkpSimulationIsland; + +class hkpEntity : public hkpWorldObject { public: - virtual ~hkpMotion(); - hkUchar _0[0xc0]; + HK_DECLARE_CLASS_ALLOCATOR(hkpEntity) + HK_DECLARE_REFLECTION() - /* 0xc8 */ hkHalf m_motionState__m_timeFactor; - /* */ hkUchar _cc[0x128 - 0xcc]; - /* 0x128 */ void* _128; -}; - -struct hkpMaxSizeMotion : hkpMotion { - hkUchar fill[0x140 - sizeof(hkpMotion)]; -}; // 0x140 - -class hkpEntity : public hkpWorldEntity { -public: - virtual ~hkpEntity(); - - /* */ hkUchar _133[0x150 - 0x133]; - /* 0x150 */ hkpMaxSizeMotion m_motion; + enum SpuCollisionCallbackEventFilter { + SPU_SEND_NONE = 0x00, + SPU_SEND_CONTACT_POINT_ADDED = 0x01, + SPU_SEND_CONTACT_POINT_PROCESS = 0x02, + SPU_SEND_CONTACT_POINT_REMOVED = 0x04, + SPU_SEND_CONTACT_POINT_ADDED_OR_PROCESS = + SPU_SEND_CONTACT_POINT_ADDED | SPU_SEND_CONTACT_POINT_PROCESS, + }; + + class SmallArraySerializeOverrideType { + public: + HK_DECLARE_CLASS_ALLOCATOR(SmallArraySerializeOverrideType) + HK_DECLARE_REFLECTION() + + void* m_data; + hkUint16 m_size; + hkUint16 m_capacityAndFlags; + }; + + struct SpuCollisionCallback { + HK_DECLARE_CLASS_ALLOCATOR(hkpEntity::SpuCollisionCallback) + HK_DECLARE_REFLECTION() + + SpuCollisionCallback() + : m_util(nullptr), m_capacity(0), + m_eventFilter(SPU_SEND_CONTACT_POINT_ADDED_OR_PROCESS), m_userFilter(0x01) {} + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) + explicit SpuCollisionCallback(hkFinishLoadedObjectFlag flag) {} + + hkSpuCollisionCallbackUtil* m_util; + hkUint16 m_capacity; + hkUint8 m_eventFilter; + hkUint8 m_userFilter; + }; + + struct ExtendedListeners { + HK_DECLARE_CLASS_ALLOCATOR(ExtendedListeners) + HK_DECLARE_REFLECTION() + + hkSmallArray m_activationListeners; + hkSmallArray m_entityListeners; + }; + + explicit hkpEntity(hkFinishLoadedObjectFlag flag); + ~hkpEntity() override; + + virtual void deallocateInternalArrays(); + hkMotionState* getMotionState() override { return nullptr; } + + hkpMaterial m_material; + void* m_limitContactImpulseUtilAndFlag; + hkReal m_damageMultiplier; + hkpBreakableBody* m_breakableBody; + hkUint32 m_solverData; + hkObjectIndex m_storageIndex; + hkUint16 m_contactPointCallbackDelay; + hkSmallArray m_constraintsMaster; + hkArray m_constraintsSlave; + hkArray m_constraintRuntime; + hkpSimulationIsland* m_simulationIsland; + hkInt8 m_autoRemoveLevel; + hkUint8 m_numShapeKeysInContactPointProperties; + hkUint8 m_responseModifierFlags; + hkUint32 m_uid; + SpuCollisionCallback m_spuCollisionCallback; + hkpMaxSizeMotion m_motion; + hkSmallArray m_contactListeners; + hkSmallArray m_actions; + hkRefPtr m_localFrame; + mutable ExtendedListeners* m_extendedListeners; + hkUint32 m_npData; }; diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h b/lib/hkStubs/Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h index 6f0679ec..48d0ad62 100644 --- a/lib/hkStubs/Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h +++ b/lib/hkStubs/Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h @@ -2,11 +2,33 @@ #include +class hkpRigidBodyCinfo; + class hkpRigidBody : public hkpEntity { public: HK_DECLARE_CLASS_ALLOCATOR(hkpRigidBody) HK_DECLARE_REFLECTION() - virtual ~hkpRigidBody(); + hkpRigidBody(const hkpRigidBodyCinfo& info); + explicit hkpRigidBody(hkFinishLoadedObjectFlag flag); + + ~hkpRigidBody() override; + + virtual hkpRigidBody* clone() const; + void enableDeactivation(bool _enableDeactivation); + +protected: + hkMotionState* getMotionState() override; }; + +inline hkpRigidBody* hkpGetRigidBody(const hkpCollidable* collidable) { + if (collidable->getType() == hkpWorldObject::BROAD_PHASE_ENTITY) { + return static_cast(hkpGetWorldObject(collidable)); + } + return nullptr; +} + +inline hkpRigidBody* hkpGetRigidBodyUnchecked(const hkpCollidable* collidable) { + return static_cast(hkpGetWorldObject(collidable)); +} diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/Motion/Rigid/hkpKeyframedRigidMotion.h b/lib/hkStubs/Havok/Physics2012/Dynamics/Motion/Rigid/hkpKeyframedRigidMotion.h new file mode 100644 index 00000000..df8e11e4 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Dynamics/Motion/Rigid/hkpKeyframedRigidMotion.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include + +class hkpKeyframedRigidMotion : public hkpMotion { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpKeyframedRigidMotion) + HK_DECLARE_REFLECTION() + + hkpKeyframedRigidMotion(const hkVector4& position, const hkQuaternion& rotation); + explicit hkpKeyframedRigidMotion(hkFinishLoadedObjectFlag flag) : hkpMotion(flag) {} + ~hkpKeyframedRigidMotion() override; + + void setMass(hkReal m) override; + void setMass(hkSimdRealParameter m) override; + + void setMassInv(hkReal mInv) override; + void setMassInv(hkSimdRealParameter mInv) override; + + void getInertiaLocal(hkMatrix3& inertia) const override; + void setInertiaLocal(const hkMatrix3& inertia) override; + void getInertiaWorld(hkMatrix3& inertiaOut) const override; + void setInertiaInvLocal(const hkMatrix3& inertiaInv) override; + void getInertiaInvLocal(hkMatrix3& inertiaInv) const override; + void getInertiaInvWorld(hkMatrix3& inertiaInvOut) const override; + + void getProjectedPointVelocity(const hkVector4& p, const hkVector4& normal, hkReal& velOut, + hkReal& invVirtMassOut) const override; + void getProjectedPointVelocitySimd(const hkVector4& p, const hkVector4& normal, + hkSimdReal& velOut, + hkSimdReal& invVirtMassOut) const override; + + void applyLinearImpulse(const hkVector4& imp) override; + void applyPointImpulse(const hkVector4& imp, const hkVector4& p) override; + void applyAngularImpulse(const hkVector4& imp) override; + + void applyForce(const hkReal deltaTime, const hkVector4& force) override; + void applyForce(const hkReal deltaTime, const hkVector4& force, const hkVector4& p) override; + void applyTorque(const hkReal deltaTime, const hkVector4& torque) override; + + virtual void setStepPosition(hkReal position, hkReal timestep); + virtual void setStoredMotion(hkpMaxSizeMotion* savedMotion); + +protected: + hkpKeyframedRigidMotion() : hkpMotion() { m_savedMotion = nullptr; } +}; + +class hkpMaxSizeMotion : public hkpKeyframedRigidMotion { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpMaxSizeMotion) + HK_DECLARE_REFLECTION() + + hkpMaxSizeMotion() : hkpKeyframedRigidMotion() {} + explicit hkpMaxSizeMotion(hkFinishLoadedObjectFlag flag) : hkpKeyframedRigidMotion(flag) {} + + hkpMaxSizeMotion(const hkpMaxSizeMotion&) = delete; + auto operator=(const hkpMaxSizeMotion&) = delete; +}; diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/Motion/hkpMotion.h b/lib/hkStubs/Havok/Physics2012/Dynamics/Motion/hkpMotion.h new file mode 100644 index 00000000..367c89cb --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Dynamics/Motion/hkpMotion.h @@ -0,0 +1,97 @@ +#pragma once + +#include +#include + +class hkpMaxSizeMotion; + +class hkpMotion : public hkReferencedObject { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpMotion) + HK_DECLARE_REFLECTION() + + enum MotionType { + MOTION_INVALID, + MOTION_DYNAMIC, + MOTION_SPHERE_INERTIA, + MOTION_BOX_INERTIA, + MOTION_KEYFRAMED, + MOTION_FIXED, + MOTION_THIN_BOX_INERTIA, + MOTION_CHARACTER, + MOTION_MAX_ID + }; + + enum { NUM_INACTIVE_FRAMES_TO_DEACTIVATE = 5 }; + + hkpMotion(); + hkpMotion(const hkVector4& position, const hkQuaternion& rotation, + bool wantDeactivation = false); + explicit hkpMotion(hkFinishLoadedObjectFlag flag) : hkReferencedObject(flag) { + if (flag.m_finishing) { + m_gravityFactor.setOne(); + } + } + + inline MotionType getType() const { return m_type; } + + virtual void setMass(hkReal m); + virtual void setMass(hkSimdRealParameter m); + + virtual void setMassInv(hkReal mInv); + virtual void setMassInv(hkSimdRealParameter mInv); + + virtual void getInertiaLocal(hkMatrix3& inertiaOut) const = 0; + virtual void getInertiaWorld(hkMatrix3& inertiaOut) const = 0; + virtual void setInertiaLocal(const hkMatrix3& inertia) = 0; + virtual void setInertiaInvLocal(const hkMatrix3& inertiaInv) = 0; + virtual void getInertiaInvLocal(hkMatrix3& inertiaInvOut) const = 0; + virtual void getInertiaInvWorld(hkMatrix3& inertiaInvOut) const = 0; + virtual void setCenterOfMassInLocal(const hkVector4& centerOfMass); + + virtual void setPosition(const hkVector4& position); + + virtual void setRotation(const hkQuaternion& rotation); + + virtual void setPositionAndRotation(const hkVector4& position, const hkQuaternion& rotation); + + virtual void setTransform(const hkTransform& transform); + + virtual void setLinearVelocity(const hkVector4& newVel); + virtual void setAngularVelocity(const hkVector4& newVel); + virtual void getProjectedPointVelocity(const hkVector4& p, const hkVector4& normal, + hkReal& velOut, hkReal& invVirtMassOut) const = 0; + virtual void getProjectedPointVelocitySimd(const hkVector4& p, const hkVector4& normal, + hkSimdReal& velOut, + hkSimdReal& invVirtMassOut) const = 0; + + virtual void applyLinearImpulse(const hkVector4& imp); + virtual void applyPointImpulse(const hkVector4& imp, const hkVector4& p) = 0; + virtual void applyAngularImpulse(const hkVector4& imp) = 0; + + virtual void applyForce(hkReal deltaTime, const hkVector4& force) = 0; + virtual void applyForce(hkReal deltaTime, const hkVector4& force, const hkVector4& p) = 0; + virtual void applyTorque(hkReal deltaTime, const hkVector4& torque) = 0; + + virtual void getMotionStateAndVelocitiesAndDeactivationType(hkpMotion* motionOut); + + hkEnum m_type; + hkUint8 m_deactivationIntegrateCounter; + hkUint16 m_deactivationNumInactiveFrames[2]; + hkMotionState m_motionState; + hkVector4 m_inertiaAndMassInv; + hkVector4 m_linearVelocity; + hkVector4 m_angularVelocity; + hkVector4 m_deactivationRefPosition[2]; + hkUint32 m_deactivationRefOrientation[2]; + hkpMaxSizeMotion* m_savedMotion; + hkUint16 m_savedQualityTypeIndex; + hkHalf m_gravityFactor; +}; + +class hkpRigidMotion : public hkpMotion { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpRigidMotion) + + explicit hkpRigidMotion(hkFinishLoadedObjectFlag flag) : hkpMotion(flag) {} +}; diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpPhysicsSystem.h b/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpPhysicsSystem.h index 51c04d31..f6da832e 100644 --- a/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpPhysicsSystem.h +++ b/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpPhysicsSystem.h @@ -2,7 +2,6 @@ #include -class hkTransform; class hkpRigidBody; class hkpConstraintInstance; class hkpAction; diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpWorldEntity.h b/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpWorldEntity.h deleted file mode 100644 index f9fe99c0..00000000 --- a/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpWorldEntity.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -class hkpWorldEntity : public hkReferencedObject { -public: - virtual ~hkpWorldEntity() {} - - void setUserData(void* data) { m_userData = data; } - - void setName(const char* name) { m_name = name; } - - /* */ hkUchar _8[0x18 - 0x8]; - /* 0x018 */ void* m_userData; - /* */ hkUchar _20[0x88 - 0x20]; - /* 0x088 */ hkReal _88; - /* */ hkUchar _8c[0xb0 - 0x8c]; - /* 0x0b0 */ hkStringPtr m_name; - /* */ hkUchar _b8[0x132 - 0xb8]; - /* 0x132 */ hkUchar _132; -}; diff --git a/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpWorldObject.h b/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpWorldObject.h index 435c0586..f0bd2943 100644 --- a/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpWorldObject.h +++ b/lib/hkStubs/Havok/Physics2012/Dynamics/World/hkpWorldObject.h @@ -1,11 +1,24 @@ #pragma once +#include #include +#include +#include + +class hkpShapeModifier; +class hkpWorld; + +namespace hkWorldOperation { +enum Result { + POSTPONED, + DONE, +}; +} // namespace hkWorldOperation -// FIXME: incomplete class hkpWorldObject : public hkReferencedObject { public: HK_DECLARE_CLASS_ALLOCATOR(hkpWorldObject) + HK_DECLARE_REFLECTION() enum BroadPhaseType { BROAD_PHASE_INVALID, @@ -17,4 +30,177 @@ public: BROAD_PHASE_BORDER, BROAD_PHASE_MAX_ID }; + + enum MtChecks { + MULTI_THREADING_CHECKS_ENABLE, + MULTI_THREADING_CHECKS_IGNORE, + }; + + explicit hkpWorldObject(hkFinishLoadedObjectFlag flag); + + void addProperty(hkUint32 key, hkpPropertyValue value); + hkpPropertyValue removeProperty(hkUint32 key); + void setProperty(hkUint32 key, hkpPropertyValue value); + void editProperty(hkUint32 key, hkpPropertyValue value, + MtChecks mtCheck = MULTI_THREADING_CHECKS_ENABLE); + inline hkpPropertyValue getProperty(hkUint32 key, + MtChecks mtCheck = MULTI_THREADING_CHECKS_ENABLE) const; + inline bool hasProperty(hkUint32 key, MtChecks mtCheck = MULTI_THREADING_CHECKS_ENABLE) const; + void lockProperty(hkUint32 key); + void unlockProperty(hkUint32 key); + inline void clearAndDeallocateProperties(); + + inline hkpCollidable* getCollidableRw(); + inline const hkpCollidable* getCollidable() const; + inline hkpLinkedCollidable* getLinkedCollidable(); + inline const hkpLinkedCollidable* getLinkedCollidable() const; + inline const hkpLinkedCollidable* getCollidableMtUnchecked() const; + + inline hkBool isAddedToWorld() const; + inline hkpWorld* getWorld() const; + + inline hkUlong getUserData() const; + inline void setUserData(hkUlong data); + + inline const char* getName() const; + inline void setName(const char* name); + + virtual hkWorldOperation::Result setShape(const hkpShape* shape); + virtual hkWorldOperation::Result updateShape(hkpShapeModifier* shapeModifier); + + inline hkMultiThreadCheck& getMultiThreadCheck(); + inline void markForRead(); + inline void markForWrite(); + void markForWriteImpl(); + inline void unmarkForRead(); + inline void unmarkForWrite(); + + void checkReadWrite(); + void checkReadOnly() const; + + inline ~hkpWorldObject() override; + + virtual class hkMotionState* getMotionState() = 0; + + inline void copyProperties(const hkpWorldObject* otherObj); + +protected: + friend class hkpWorld; + friend class hkpWorldOperationUtil; + inline void setWorld(hkpWorld* world); + + hkpWorldObject(const hkpShape* shape, BroadPhaseType type); + + hkpWorld* m_world; + hkUlong m_userData; + hkpLinkedCollidable m_collidable; + hkMultiThreadCheck m_multiThreadCheck; + hkStringPtr m_name; + +public: + hkArray m_properties; }; + +inline hkpWorldObject* hkpGetWorldObject(const hkpCollidable* collidable) { + return reinterpret_cast(const_cast(collidable->getOwner())); +} + +inline hkpPropertyValue hkpWorldObject::getProperty(hkUint32 key, hkpWorldObject::MtChecks) const { + for (int i = 0; i < m_properties.getSize(); ++i) { + if (m_properties[i].m_key == key) { + return m_properties[i].m_value; + } + } + return 0; +} + +inline bool hkpWorldObject::hasProperty(hkUint32 key, hkpWorldObject::MtChecks) const { + for (int i = 0; i < m_properties.getSize(); ++i) { + if (m_properties[i].m_key == key) { + return true; + } + } + return false; +} + +inline void hkpWorldObject::clearAndDeallocateProperties() { + m_properties.clearAndDeallocate(); +} + +inline hkpCollidable* hkpWorldObject::getCollidableRw() { + return &m_collidable; +} + +inline const hkpCollidable* hkpWorldObject::getCollidable() const { + return &m_collidable; +} + +inline hkpLinkedCollidable* hkpWorldObject::getLinkedCollidable() { + return &m_collidable; +} + +inline const hkpLinkedCollidable* hkpWorldObject::getLinkedCollidable() const { + return &m_collidable; +} + +inline const hkpLinkedCollidable* hkpWorldObject::getCollidableMtUnchecked() const { + return &m_collidable; +} + +inline hkBool hkpWorldObject::isAddedToWorld() const { + return m_world != nullptr; +} + +inline hkpWorld* hkpWorldObject::getWorld() const { + return m_world; +} + +inline hkUlong hkpWorldObject::getUserData() const { + return m_userData; +} + +inline void hkpWorldObject::setUserData(hkUlong data) { + m_userData = data; +} + +inline const char* hkpWorldObject::getName() const { + return m_name; +} + +inline void hkpWorldObject::setName(const char* name) { + m_name = name; +} + +inline hkMultiThreadCheck& hkpWorldObject::getMultiThreadCheck() { + return m_multiThreadCheck; +} + +inline void hkpWorldObject::markForRead() { + getMultiThreadCheck().markForRead(); +} + +inline void hkpWorldObject::markForWrite() { + getMultiThreadCheck().markForWrite(); +} + +inline void hkpWorldObject::unmarkForRead() { + getMultiThreadCheck().unmarkForRead(); +} + +inline void hkpWorldObject::unmarkForWrite() { + getMultiThreadCheck().unmarkForWrite(); +} + +inline hkpWorldObject::~hkpWorldObject() { + if (m_collidable.getShape()) { + m_collidable.getShape()->removeReference(); + } +} + +inline void hkpWorldObject::copyProperties(const hkpWorldObject* otherObj) { + m_properties = otherObj->m_properties; +} + +inline void hkpWorldObject::setWorld(hkpWorld* world) { + m_world = world; +} diff --git a/src/KingSystem/Physics/RigidBody/physRigidBody.cpp b/src/KingSystem/Physics/RigidBody/physRigidBody.cpp index 002c0aef..1129f972 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBody.cpp +++ b/src/KingSystem/Physics/RigidBody/physRigidBody.cpp @@ -11,13 +11,13 @@ RigidBody::RigidBody(u32 a, u32 mass_scaling, hkpRigidBody* hk_body, const sead: if (!name.isEmpty()) { hk_body->setName(name.cstr()); } - hk_body->setUserData(this); - hk_body->m_motion._128 = nullptr; - hk_body->m_motion.m_motionState__m_timeFactor.setOne(); + hk_body->setUserData(reinterpret_cast(this)); + hk_body->m_motion.m_savedMotion = nullptr; + hk_body->m_motion.m_motionState.m_timeFactor.setOne(); hk_body->enableDeactivation(true); - hk_body->_88 = 0.1f; + hk_body->getCollidableRw()->m_allowedPenetrationDepth = 0.1f; if (mFlags.isOn(Flag1::MassScaling)) { - hk_body->_132 |= 1; + hk_body->m_responseModifierFlags |= 1; } mFlags.change(Flag1::_80, _b4 == 5);