diff --git a/lib/hkStubs/CMakeLists.txt b/lib/hkStubs/CMakeLists.txt index 81d8eb8a..bb011b9f 100644 --- a/lib/hkStubs/CMakeLists.txt +++ b/lib/hkStubs/CMakeLists.txt @@ -10,6 +10,8 @@ add_library(hkStubs OBJECT Havok/Common/Base/Math/hkMath.h Havok/Common/Base/Math/Vector/hkVector4.h Havok/Common/Base/Math/Vector/hkVector4f.h + Havok/Common/Base/Math/Vector/hkVector4Comparison.h + Havok/Common/Base/Math/Vector/hkVector4fComparison.h Havok/Common/Base/Memory/Allocator/hkMemoryAllocator.h Havok/Common/Base/Memory/Allocator/Lifo/hkLifoAllocator.h @@ -27,6 +29,14 @@ add_library(hkStubs OBJECT Havok/Common/Base/Types/hkRefPtr.h Havok/Common/Base/Types/Geometry/Aabb/hkAabb.h + Havok/Geometry/Collide/Shapes/hkcdShape.h + + Havok/Physics2012/Collide/Agent/hkpCollisionInput.h + Havok/Physics2012/Collide/Agent/Collidable/hkpCdBody.h + Havok/Physics2012/Collide/Agent/Collidable/hkpCollidable.h + Havok/Physics2012/Collide/Agent/Collidable/hkpCollidableQualityType.h + Havok/Physics2012/Collide/BroadPhase/hkpBroadPhaseHandle.h + Havok/Physics2012/Collide/BroadPhase/hkpTypedBroadPhaseHandle.h Havok/Physics2012/Collide/Filter/hkpCollidableCollidableFilter.h Havok/Physics2012/Collide/Filter/hkpCollisionFilter.cpp Havok/Physics2012/Collide/Filter/hkpCollisionFilter.h @@ -35,12 +45,15 @@ add_library(hkStubs OBJECT Havok/Physics2012/Collide/Filter/hkpShapeCollectionFilter.h Havok/Physics2012/Collide/Filter/Group/hkpGroupFilter.cpp Havok/Physics2012/Collide/Filter/Group/hkpGroupFilter.h + Havok/Physics2012/Collide/Query/CastUtil/hkpWorldRayCastInput.h Havok/Physics2012/Collide/Shape/hkpShape.h Havok/Physics2012/Collide/Shape/hkpShapeBase.h + Havok/Physics2012/Collide/Shape/hkpShapeContainer.h Havok/Physics2012/Collide/Shape/Convex/hkpConvexShape.h Havok/Physics2012/Collide/Shape/Convex/Capsule/hkpCapsuleShape.h Havok/Physics2012/Collide/Shape/HeightField/hkpSphereRepShape.h Havok/Physics2012/Collide/Shape/Query/hkpRayShapeCollectionFilter.h + Havok/Physics2012/Collide/Shape/Query/hkpShapeRayCastInput.h Havok/Physics2012/Dynamics/Entity/hkpEntity.h Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4.h index 2fdfc076..a1cff43c 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4.h @@ -1,5 +1,3 @@ #pragma once #include - -using hkVector4 = hkVector4f; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4Comparison.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4Comparison.h new file mode 100644 index 00000000..30be489b --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4Comparison.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.h new file mode 100644 index 00000000..e180c961 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.h @@ -0,0 +1,9 @@ +#pragma once + +// FIXME: incomplete +class hkVector4fComparison { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkVector4fComparison) + + hkUint32 m_mask; +}; diff --git a/lib/hkStubs/Havok/Common/Base/Math/hkMath.h b/lib/hkStubs/Havok/Common/Base/Math/hkMath.h index c9a2f723..5358f5a6 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/hkMath.h +++ b/lib/hkStubs/Havok/Common/Base/Math/hkMath.h @@ -2,4 +2,15 @@ #include +class hkVector4f; +using hkVector4fParameter = const hkVector4f&; +class hkVector4fComparison; +using hkVector4fComparisonParameter = const hkVector4fComparison&; + #include +#include + +using hkVector4 = hkVector4f; +using hkVector4Parameter = const hkVector4f&; +using hkVector4Comparison = hkVector4fComparison; +using hkVector4ComparisonParameter = hkVector4fComparisonParameter; diff --git a/lib/hkStubs/Havok/Common/Base/Types/Geometry/Aabb/hkAabb.h b/lib/hkStubs/Havok/Common/Base/Types/Geometry/Aabb/hkAabb.h index 05a9960a..07084ded 100644 --- a/lib/hkStubs/Havok/Common/Base/Types/Geometry/Aabb/hkAabb.h +++ b/lib/hkStubs/Havok/Common/Base/Types/Geometry/Aabb/hkAabb.h @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include /// Axis aligned bounding box // FIXME: incomplete diff --git a/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h b/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h index 714e7014..8d20c094 100644 --- a/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h +++ b/lib/hkStubs/Havok/Common/Base/Types/hkBaseTypes.h @@ -91,6 +91,9 @@ private: char m_bool; }; +using hkBool32 = hkUint32; +using hkBoolLL = hkUint64; + /// For storing an enum with a particular storage size when specifying the underlying type of the /// enum is not an option. template @@ -176,6 +179,11 @@ inline bool operator!=(hkResultEnum e, hkResult r) { return r.m_enum != e; } -struct hkFinishLoadedObjectFlag { +class hkFinishLoadedObjectFlag { +public: int m_finishing = 0; }; + +HK_FORCE_INLINE hkLong hkGetByteOffset(const void* base, const void* pntr) { + return hkLong(pntr) - hkLong(base); +} diff --git a/lib/hkStubs/Havok/Geometry/Collide/Shapes/hkcdShape.h b/lib/hkStubs/Havok/Geometry/Collide/Shapes/hkcdShape.h new file mode 100644 index 00000000..4d07c5b8 --- /dev/null +++ b/lib/hkStubs/Havok/Geometry/Collide/Shapes/hkcdShape.h @@ -0,0 +1,100 @@ +#pragma once + +#include + +struct hkcdShapeType { + HK_DECLARE_CLASS_ALLOCATOR(hkcdShapeType) + + enum ShapeTypeEnum { + SPHERE = 0, ///< hkpSphereShape type. + CYLINDER = 1, ///< hkpCylinderShape type. + TRIANGLE = 2, ///< hkpTriangleShape type. + BOX = 3, ///< hkpBoxShape type. + CAPSULE = 4, ///< hkpCapsuleShape type. + CONVEX_VERTICES = 5, ///< hkpConvexVerticesShape type. + TRI_SAMPLED_HEIGHT_FIELD_COLLECTION = 6, ///< hkpTriSampledHeightFieldCollection type. + TRI_SAMPLED_HEIGHT_FIELD_BV_TREE = 7, ///< hkpTriSampledHeightFieldBvTreeShape type. + LIST = 8, ///< hkpListShape type. + MOPP = 9, ///< hkpMoppBvTreeShape type. + CONVEX_TRANSLATE = 10, ///< hkpConvexTranslateShape type. + CONVEX_TRANSFORM = 11, ///< hkpConvexTransformShape type. + SAMPLED_HEIGHT_FIELD = 12, ///< hkpSampledHeightFieldShape type. + EXTENDED_MESH = 13, ///< hkpExtendedMeshShape type. + TRANSFORM = 14, ///< hkpTransformShape type. + COMPRESSED_MESH = 15, ///< hkpCompressedMeshShape type. + STATIC_COMPOUND = 16, ///< hkpStaticCompoundShape type. + BV_COMPRESSED_MESH = 17, ///< hkpBvCompressedMeshShape type. + /// All shapes which inherit from hkpShapeCollection have this as an alternate type. + COLLECTION = 18, + USER0 = 19, ///< Custom user type. + USER1 = 20, ///< Custom user type. + USER2 = 21, ///< Custom user type. + /// All shapes which inherit from hkpBvTreeShape have this as an alternate type. + BV_TREE = 22, + /// All shapes which inherit from hkpConvexShape have this as an alternate type. + CONVEX = 23, + CONVEX_PIECE = 24, ///< DEPRECATED - hkpConvexPieceShape type. + MULTI_SPHERE = 25, ///< DEPRECATED - hkpMultiSphereShape type. + CONVEX_LIST = 26, ///< DEPRECATED - hkpConvexListShape. + TRIANGLE_COLLECTION = 27, ///< A shape collection which only returns triangles as child + ///< shapes, e.g., hkpMeshShape. + HEIGHT_FIELD = 28, ///< hkpHeightFieldShape type. + SPHERE_REP = 29, ///< hkpSphereRepShape type. + BV = 30, ///< hkpBvShape type. + PLANE = 31, ///< hkpPlaneShape type. + PHANTOM_CALLBACK = 32, ///< hkpPhantomCallbackShape type. + MULTI_RAY = 33, ///< hkpMultiRayShape type. + INVALID = 34, ///< Invalid shape + + FIRST_SHAPE_TYPE = SPHERE, ///< The first real shape. + MAX_SPU_SHAPE_TYPE = USER2 + 1, ///< Last SPU support shape type. + MAX_PPU_SHAPE_TYPE = INVALID + 1, ///< The end of the shape type list. + ALL_SHAPE_TYPES = -1, ///< All shapes flag, used by the hkpCollisionDispatcher. + }; +}; + +struct hkcdShapeDispatchType { + HK_DECLARE_CLASS_ALLOCATOR(hkcdShapeDispatchType) + + enum ShapeDispatchTypeEnum { + CONVEX_IMPLICIT, + CONVEX, + HEIGHT_FIELD, + COMPOSITE, + USER, + NUM_DISPATCH_TYPES, + }; +}; + +struct hkcdShapeInfoCodecType { + HK_DECLARE_CLASS_ALLOCATOR(hkcdShapeInfoCodecType) + + enum ShapeInfoCodecTypeEnum { + NULL_CODEC = 0, + UFM358 = 1, + MAX_NUM_CODECS = 16, + }; +}; + +class hkcdShape : public hkReferencedObject { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkcdShape) + + using ShapeType = hkcdShapeType::ShapeTypeEnum; + using DispatchType = hkcdShapeDispatchType::ShapeDispatchTypeEnum; + using ShapeInfoCodecType = hkcdShapeInfoCodecType::ShapeInfoCodecTypeEnum; + + HK_FORCE_INLINE explicit hkcdShape(ShapeType shapeType) + : m_type(shapeType), m_dispatchType(hkcdShapeDispatchType::USER), m_bitsPerKey(0), + m_shapeInfoCodecType(hkcdShapeInfoCodecType::NULL_CODEC) {} + + explicit hkcdShape(hkFinishLoadedObjectFlag flag); + + hkEnum m_type; + hkEnum m_dispatchType; + hkUint8 m_bitsPerKey; + hkEnum m_shapeInfoCodecType; +}; + +#define HKCD_DECLARE_SHAPE_TYPE(shapeType) enum { THIS_SHAPE_TYPE = (shapeType) }; +#define HKCD_SHAPE_TYPE_FROM_CLASS(ShapeClass) (hkcdShape::ShapeType) ShapeClass::THIS_SHAPE_TYPE diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCdBody.h b/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCdBody.h new file mode 100644 index 00000000..f3e9e260 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCdBody.h @@ -0,0 +1,127 @@ +#pragma once + +#include +#include + +class hkMotionState; +class hkTransform; +class hkpCollidable; + +class hkpCdBody { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpCdBody) + friend class hkpCollidable; + + HK_FORCE_INLINE hkpCdBody() {} + + HK_FORCE_INLINE hkpCdBody(const hkpShape* shape, const hkMotionState* motionState); + HK_FORCE_INLINE hkpCdBody(const hkpShape* shape, const hkTransform* t); + + HK_FORCE_INLINE hkpCdBody(const hkpCdBody& body) = delete; + + HK_FORCE_INLINE const hkTransform& getTransform() const; + HK_FORCE_INLINE const hkpShape* getShape() const; + HK_FORCE_INLINE const hkpCollidable* getRootCollidable() const; + HK_FORCE_INLINE hkpShapeKey getShapeKey() const; + HK_FORCE_INLINE hkpShapeKey getTopLevelShapeKey() const; + HK_FORCE_INLINE const hkpCdBody* getParent() const; + + // Internal functions, for collision agents. + explicit HK_FORCE_INLINE hkpCdBody(const hkpCdBody* parent); + HK_FORCE_INLINE hkpCdBody(const hkpCdBody* parent, const hkMotionState* ms); + HK_FORCE_INLINE hkpCdBody(const hkpCdBody* parent, const hkTransform* t); + HK_FORCE_INLINE void setShape(const hkpShape* shape, hkpShapeKey key); + HK_FORCE_INLINE const hkMotionState* getMotionState() const; + HK_FORCE_INLINE void setMotionState(const hkMotionState* state); + HK_FORCE_INLINE void setTransform(const hkTransform* t); + + const hkpShape* m_shape; + hkpShapeKey m_shapeKey; + +private: + // hkTransform or hkMotionState. + const void* m_motion; + +public: + const hkpCdBody* m_parent; +}; + +inline hkpCdBody::hkpCdBody(const hkpShape* shape, const hkMotionState* motionState) { + m_shape = shape; + setMotionState(motionState); + m_parent = nullptr; + m_shapeKey = HK_INVALID_SHAPE_KEY; +} + +inline hkpCdBody::hkpCdBody(const hkpShape* shape, const hkTransform* t) { + m_shape = shape; + setTransform(t); + m_parent = nullptr; + m_shapeKey = HK_INVALID_SHAPE_KEY; +} + +inline const hkTransform& hkpCdBody::getTransform() const { + return *static_cast(m_motion); +} + +inline const hkpShape* hkpCdBody::getShape() const { + return m_shape; +} + +inline const hkpCollidable* hkpCdBody::getRootCollidable() const { + const hkpCdBody* body = this; + while (body->m_parent) { + body = body->m_parent; + } + return reinterpret_cast(body); +} + +inline hkpShapeKey hkpCdBody::getShapeKey() const { + return m_shapeKey; +} + +inline hkpShapeKey hkpCdBody::getTopLevelShapeKey() const { + const hkpCdBody* body = this; + const hkpCdBody* top = body; + while (body->m_parent) { + top = body; + body = body->m_parent; + } + return top->m_shapeKey; +} + +inline const hkpCdBody* hkpCdBody::getParent() const { + return m_parent; +} + +inline hkpCdBody::hkpCdBody(const hkpCdBody* parent) { + m_parent = parent; + m_motion = parent->m_motion; +} + +inline hkpCdBody::hkpCdBody(const hkpCdBody* parent, const hkMotionState* ms) { + m_parent = parent; + setMotionState(ms); +} + +inline hkpCdBody::hkpCdBody(const hkpCdBody* parent, const hkTransform* t) { + m_parent = parent; + setTransform(t); +} + +inline void hkpCdBody::setShape(const hkpShape* shape, hkpShapeKey key) { + m_shape = shape; + m_shapeKey = key; +} + +inline const hkMotionState* hkpCdBody::getMotionState() const { + return static_cast(m_motion); +} + +inline void hkpCdBody::setMotionState(const hkMotionState* state) { + m_motion = state; +} + +inline void hkpCdBody::setTransform(const hkTransform* t) { + m_motion = t; +} diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCollidable.h b/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCollidable.h new file mode 100644 index 00000000..b30c4644 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCollidable.h @@ -0,0 +1,157 @@ +#pragma once + +#include +#include + +class hkAabbUint32; + +class hkpCollidable : public hkpCdBody { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpCollidable) + + struct BoundingVolumeData { + HK_DECLARE_CLASS_ALLOCATOR(hkpCollidable::BoundingVolumeData) + + BoundingVolumeData(); + explicit inline BoundingVolumeData(hkFinishLoadedObjectFlag flag); + + HK_FORCE_INLINE bool hasAllocations() const; + void deallocate(); + void allocate(int numChildShapes); + + HK_FORCE_INLINE void invalidate() { + m_min[0] = 1; + m_max[0] = 0; + } + HK_FORCE_INLINE bool isValid() const { return m_min[0] <= m_max[0]; } + + hkUint32 m_min[3]; + hkUint8 m_expansionMin[3]; + hkUint8 m_expansionShift; + hkUint32 m_max[3]; + hkUint8 m_expansionMax[3]; + hkUint8 m_padding; + hkUint16 m_numChildShapeAabbs; + hkUint16 m_capacityChildShapeAabbs; + hkAabbUint32* m_childShapeAabbs; + hkpShapeKey* m_childShapeKeys; + }; + + enum ForceCollideOntoPpuReasons { + FORCE_PPU_USER_REQUEST = 1, + FORCE_PPU_SHAPE_REQUEST = 2, + FORCE_PPU_MODIFIER_REQUEST = 4, + FORCE_PPU_SHAPE_UNCHECKED = 8, + }; + + explicit hkpCollidable(hkFinishLoadedObjectFlag flag); + inline hkpCollidable(const hkpShape* shape, const hkTransform* t, int type = 0); + inline hkpCollidable(const hkpShape* shape, const hkMotionState* ms, int type = 0); + inline ~hkpCollidable(); + + inline void setShape(const hkpShape* shape); + + inline void* getOwner() const; + inline void setOwner(void* owner); + + inline hkpCollidableQualityType getQualityType() const; + inline void setQualityType(hkpCollidableQualityType type); + + inline hkReal getAllowedPenetrationDepth() const; + inline void setAllowedPenetrationDepth(hkReal val); + + inline hkUint32 getCollisionFilterInfo() const; + inline void setCollisionFilterInfo(hkUint32 info); + + inline int getType() const; + +protected: + hkInt8 m_ownerOffset; + +public: + hkUint8 m_forceCollideOntoPpu; + hkUint16 m_shapeSizeOnSpu; + hkpTypedBroadPhaseHandle m_broadPhaseHandle; + BoundingVolumeData m_boundingVolumeData; + hkReal m_allowedPenetrationDepth; +}; + +inline hkpCollidable::hkpCollidable(hkFinishLoadedObjectFlag flag) + : m_broadPhaseHandle(flag), m_boundingVolumeData(flag) { + if (flag.m_finishing) { + m_broadPhaseHandle.setOwner(this); + } +} + +inline hkpCollidable::hkpCollidable(const hkpShape* shape, const hkTransform* t, int type) + : hkpCdBody(shape, t), m_ownerOffset(0), m_broadPhaseHandle(type), + m_allowedPenetrationDepth(hkReal(-1)) { + m_broadPhaseHandle.setOwner(this); + m_forceCollideOntoPpu = hkpCollidable::FORCE_PPU_SHAPE_UNCHECKED; + m_shapeSizeOnSpu = 0; +} + +inline hkpCollidable::hkpCollidable(const hkpShape* shape, const hkMotionState* ms, int type) + : hkpCdBody(shape, ms), m_ownerOffset(0), m_broadPhaseHandle(type), + m_allowedPenetrationDepth(hkReal(-1)) { + m_broadPhaseHandle.setOwner(this); + m_forceCollideOntoPpu = hkpCollidable::FORCE_PPU_SHAPE_UNCHECKED; + m_shapeSizeOnSpu = 0; +} + +inline hkpCollidable::~hkpCollidable() {} + +inline void hkpCollidable::setShape(const hkpShape* shape) { + m_shape = shape; +} + +inline void* hkpCollidable::getOwner() const { + return const_cast(reinterpret_cast(this) + m_ownerOffset); +} + +inline void hkpCollidable::setOwner(void* owner) { + auto ownerOffset = int(hkGetByteOffset(this, owner)); + m_ownerOffset = static_cast(ownerOffset); +} + +inline hkpCollidableQualityType hkpCollidable::getQualityType() const { + return hkpCollidableQualityType(m_broadPhaseHandle.m_objectQualityType); +} + +inline void hkpCollidable::setQualityType(hkpCollidableQualityType type) { + m_broadPhaseHandle.m_objectQualityType = type; +} + +inline hkReal hkpCollidable::getAllowedPenetrationDepth() const { + return m_allowedPenetrationDepth; +} + +inline void hkpCollidable::setAllowedPenetrationDepth(hkReal val) { + m_allowedPenetrationDepth = val; +} + +inline hkUint32 hkpCollidable::getCollisionFilterInfo() const { + return m_broadPhaseHandle.m_collisionFilterInfo; +} + +inline void hkpCollidable::setCollisionFilterInfo(hkUint32 info) { + m_broadPhaseHandle.m_collisionFilterInfo = info; +} + +inline int hkpCollidable::getType() const { + return m_broadPhaseHandle.getType(); +} + +inline hkpCollidable::BoundingVolumeData::BoundingVolumeData(hkFinishLoadedObjectFlag flag) { + if (flag.m_finishing) { + m_numChildShapeAabbs = 0; + m_capacityChildShapeAabbs = 0; + m_childShapeAabbs = nullptr; + m_childShapeKeys = nullptr; + invalidate(); + } +} + +inline bool hkpCollidable::BoundingVolumeData::hasAllocations() const { + return m_childShapeAabbs != nullptr; +} diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCollidableQualityType.h b/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCollidableQualityType.h new file mode 100644 index 00000000..c795ffa6 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Agent/Collidable/hkpCollidableQualityType.h @@ -0,0 +1,16 @@ +#pragma once + +enum hkpCollidableQualityType { + HK_COLLIDABLE_QUALITY_INVALID = -1, + HK_COLLIDABLE_QUALITY_FIXED = 0, + HK_COLLIDABLE_QUALITY_KEYFRAMED, + HK_COLLIDABLE_QUALITY_DEBRIS, + HK_COLLIDABLE_QUALITY_DEBRIS_SIMPLE_TOI, + HK_COLLIDABLE_QUALITY_MOVING, + HK_COLLIDABLE_QUALITY_CRITICAL, + HK_COLLIDABLE_QUALITY_BULLET, + HK_COLLIDABLE_QUALITY_USER, + HK_COLLIDABLE_QUALITY_CHARACTER, + HK_COLLIDABLE_QUALITY_KEYFRAMED_REPORTING, + HK_COLLIDABLE_QUALITY_MAX +}; diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Agent/hkpCollisionInput.h b/lib/hkStubs/Havok/Physics2012/Collide/Agent/hkpCollisionInput.h new file mode 100644 index 00000000..c2fd5ad4 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Agent/hkpCollisionInput.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include + +class hkpCollisionDispatcher; +class hkpCollisionFilter; +class hkpConvexListFilter; + +struct hkpCollisionInput { + HK_DECLARE_CLASS_ALLOCATOR(hkpCollisionInput) + + struct Aabb32Info { + HK_DECLARE_CLASS_ALLOCATOR(hkpCollisionInput::Aabb32Info) + + hkVector4 m_bitOffsetLow; + hkVector4 m_bitOffsetHigh; + hkVector4 m_bitScale; + }; + + hkpCollisionDispatcher* m_dispatcher; + hkBool32 m_weldClosestPoints; + hkBool32 m_forceAcceptContactPoints = false; + hkReal m_tolerance; + const hkpCollisionFilter* m_filter; + const hkpConvexListFilter* m_convexListFilter; + mutable hkBool32 m_createPredictiveAgents; + Aabb32Info m_aabb32Info; +}; diff --git a/lib/hkStubs/Havok/Physics2012/Collide/BroadPhase/hkpBroadPhaseHandle.h b/lib/hkStubs/Havok/Physics2012/Collide/BroadPhase/hkpBroadPhaseHandle.h new file mode 100644 index 00000000..413870ed --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/BroadPhase/hkpBroadPhaseHandle.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +class hkpBroadPhaseHandle { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpBroadPhaseHandle) + + hkpBroadPhaseHandle() : m_id(0) {} + explicit hkpBroadPhaseHandle(hkFinishLoadedObjectFlag flag) {} + + hkUint32 m_id; +}; diff --git a/lib/hkStubs/Havok/Physics2012/Collide/BroadPhase/hkpTypedBroadPhaseHandle.h b/lib/hkStubs/Havok/Physics2012/Collide/BroadPhase/hkpTypedBroadPhaseHandle.h new file mode 100644 index 00000000..7937bd46 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/BroadPhase/hkpTypedBroadPhaseHandle.h @@ -0,0 +1,63 @@ +#pragma once + +#include +#include + +class hkpTypedBroadPhaseHandle : public hkpBroadPhaseHandle { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpTypedBroadPhaseHandle) + + explicit hkpTypedBroadPhaseHandle(hkFinishLoadedObjectFlag flag) : hkpBroadPhaseHandle(flag) {} + + HK_FORCE_INLINE explicit hkpTypedBroadPhaseHandle(int type); + HK_FORCE_INLINE hkpTypedBroadPhaseHandle(void* owner, int type); + + /// See hkpWorldObject::BroadPhaseType. + HK_FORCE_INLINE int getType() const; + HK_FORCE_INLINE void* getOwner() const; + HK_FORCE_INLINE void setOwner(void* o); + +protected: + friend class hkpBroadPhaseBorder; + + inline void setType(int type); + + static constexpr int OFFSET_INVALID = 127; + hkInt8 m_type; + hkInt8 m_ownerOffset; + +public: + hkInt8 m_objectQualityType; + hkUint32 m_collisionFilterInfo; +}; + +inline hkpTypedBroadPhaseHandle::hkpTypedBroadPhaseHandle(int type) { + m_type = static_cast(type); + m_collisionFilterInfo = 0; + m_objectQualityType = HK_COLLIDABLE_QUALITY_INVALID; + m_ownerOffset = OFFSET_INVALID; +} + +inline hkpTypedBroadPhaseHandle::hkpTypedBroadPhaseHandle(void* owner, int type) { + m_type = static_cast(type); + m_collisionFilterInfo = 0; + m_objectQualityType = HK_COLLIDABLE_QUALITY_INVALID; + setOwner(owner); +} + +inline int hkpTypedBroadPhaseHandle::getType() const { + return m_type; +} + +inline void* hkpTypedBroadPhaseHandle::getOwner() const { + return const_cast(reinterpret_cast(this) + m_ownerOffset); +} + +inline void hkpTypedBroadPhaseHandle::setOwner(void* o) { + auto offset = int(hkGetByteOffset(this, o)); + m_ownerOffset = static_cast(offset); +} + +inline void hkpTypedBroadPhaseHandle::setType(int type) { + m_type = static_cast(type); +} diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Filter/Group/hkpGroupFilter.cpp b/lib/hkStubs/Havok/Physics2012/Collide/Filter/Group/hkpGroupFilter.cpp index 27e293c2..bf5cb097 100644 --- a/lib/hkStubs/Havok/Physics2012/Collide/Filter/Group/hkpGroupFilter.cpp +++ b/lib/hkStubs/Havok/Physics2012/Collide/Filter/Group/hkpGroupFilter.cpp @@ -1,4 +1,10 @@ +#include +#include +#include #include +#include +#include +#include hkpGroupFilter::hkpGroupFilter() { m_type = HK_FILTER_GROUP; diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Query/CastUtil/hkpWorldRayCastInput.h b/lib/hkStubs/Havok/Physics2012/Collide/Query/CastUtil/hkpWorldRayCastInput.h new file mode 100644 index 00000000..b0d01f5e --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Query/CastUtil/hkpWorldRayCastInput.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +struct hkpWorldRayCastInput { + HK_DECLARE_CLASS_ALLOCATOR(hkpWorldRayCastInput) + + hkVector4 m_from; + hkVector4 m_to; + hkBool m_enableShapeCollectionFilter = false; + hkUint32 m_filterInfo = 0; + hkUlong m_userData = 0; +}; diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Shape/Query/hkpShapeRayCastInput.h b/lib/hkStubs/Havok/Physics2012/Collide/Shape/Query/hkpShapeRayCastInput.h new file mode 100644 index 00000000..4f183a24 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Shape/Query/hkpShapeRayCastInput.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +class hkpCollidable; +class hkpRayShapeCollectionFilter; + +struct hkpShapeRayCastInput { + HK_DECLARE_CLASS_ALLOCATOR(hkpShapeRayCastInput) + + hkVector4 m_from; + hkVector4 m_to; + hkUint32 m_filterInfo = 0; + const hkpRayShapeCollectionFilter* m_rayShapeCollectionFilter = nullptr; + const hkpCollidable* m_collidable = nullptr; + hkUlong m_userData = 0; +}; diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShape.h b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShape.h index a8fc1ead..6e488417 100644 --- a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShape.h +++ b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShape.h @@ -1,9 +1,13 @@ #pragma once #include +#include -// FIXME: incomplete. Also this should be inheriting from hkpBase -class hkpShape : public hkReferencedObject { +#define HK_INVALID_SHAPE_KEY 0xffffffff +#define HK_INVALID_VERTEX_ID 0xffff + +// FIXME: incomplete. +class hkpShape : public hkpShapeBase { public: virtual ~hkpShape(); diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeBase.h b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeBase.h index 0e869cda..493d490c 100644 --- a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeBase.h +++ b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeBase.h @@ -1,8 +1,91 @@ #pragma once -#include +#include +#include using hkpVertexId = hkUint16; using hkpShapeKey = hkUint32; -// FIXME: hkpShapeBase +class hkAabb; +class hkSphere; +class hkTransform; +class hkcdVertex; +class hkpCdBody; +class hkpRayHitCollector; +class hkpShapeRayBundleCastInput; +class hkpShapeRayBundleCastOutput; +class hkpShapeRayCastInput; +class hkpShapeRayCastOutput; + +/// Base interface for all physics shapes. +class hkpShapeBase : public hkcdShape { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpShapeBase) + HKCD_DECLARE_SHAPE_TYPE(hkcdShapeType::INVALID) + + HK_FORCE_INLINE explicit hkpShapeBase(ShapeType type) : hkcdShape(type) {} + explicit hkpShapeBase(hkFinishLoadedObjectFlag flag); + + /// Returns true if the shape is a hkpConvexShape. + virtual bool isConvex() const { return false; } + + /// Returns true if the shape is a hkpBvTreeShape. + HK_FORCE_INLINE bool isBvTree() const; + + /// Returns true if the shape is a hkpShapeCollection. + HK_FORCE_INLINE bool isCollection() const; + + virtual void getAabb(const hkTransform& localToWorld, hkReal tolerance, hkAabb& aabbOut) const; + + virtual hkBool castRay(const hkpShapeRayCastInput& input, hkpShapeRayCastOutput& output) const; + + virtual void castRayWithCollector(const hkpShapeRayCastInput& input, const hkpCdBody& cdBody, + hkpRayHitCollector& collector) const; + + virtual hkVector4Comparison castRayBundle(const hkpShapeRayBundleCastInput& input, + hkpShapeRayBundleCastOutput& output, + hkVector4ComparisonParameter mask) const; + + virtual void getSupportingVertex(hkVector4Parameter direction, + hkcdVertex& supportingVertexOut) const; + + virtual void convertVertexIdsToVertices(const hkpVertexId* ids, int numIds, + hkcdVertex* vertexArrayOut) const; + + virtual void getCentre(hkVector4& centreOut) const; + + virtual int getNumCollisionSpheres() const; + + virtual const hkSphere* getCollisionSpheres(hkSphere* sphereBuffer) const; + + virtual int weldContactPoint(hkpVertexId* featurePoints, hkUint8& numFeaturePoints, + hkVector4& contactPointWs, const hkTransform* thisObjTransform, + const class hkpConvexShape* collidingConvexShape, + const hkTransform* collidingTransform, + hkVector4& separatingNormalInOut) const; +}; + +inline bool hkpShapeBase::isBvTree() const { + switch (m_type) { + case hkcdShapeType::BV_TREE: + case hkcdShapeType::MOPP: + case hkcdShapeType::STATIC_COMPOUND: + case hkcdShapeType::BV_COMPRESSED_MESH: + case hkcdShapeType::TRI_SAMPLED_HEIGHT_FIELD_BV_TREE: + return true; + default: + return false; + } +} + +inline bool hkpShapeBase::isCollection() const { + switch (m_type) { + case hkcdShapeType::COLLECTION: + case hkcdShapeType::LIST: + case hkcdShapeType::EXTENDED_MESH: + case hkcdShapeType::TRI_SAMPLED_HEIGHT_FIELD_COLLECTION: + return true; + default: + return false; + } +} diff --git a/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeContainer.h b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeContainer.h new file mode 100644 index 00000000..9ffc0b38 --- /dev/null +++ b/lib/hkStubs/Havok/Physics2012/Collide/Shape/hkpShapeContainer.h @@ -0,0 +1,58 @@ +#pragma once + +#include +#include + +class hkpShapeBuffer; + +class hkpShapeContainer { +public: + HK_DECLARE_CLASS_ALLOCATOR(hkpShapeContainer) + + enum ReferencePolicy { + REFERENCE_POLICY_IGNORE, + REFERENCE_POLICY_INCREMENT, + }; + + virtual ~hkpShapeContainer() = default; + + virtual int getNumChildShapes() const; + + virtual hkpShapeKey getFirstKey() const = 0; + virtual hkpShapeKey getNextKey(hkpShapeKey oldKey) const = 0; + virtual hkUint32 getCollisionFilterInfo(hkpShapeKey key) const; + virtual const hkpShape* getChildShape(hkpShapeKey key, hkpShapeBuffer& buffer) const = 0; + virtual bool isWeldingEnabled() const { return true; } +}; + +class hkpSingleShapeContainer : public hkpShapeContainer { +public: + explicit hkpSingleShapeContainer(const hkpShape* s, + ReferencePolicy ref = REFERENCE_POLICY_INCREMENT) + : m_childShape(s) { + if (ref == REFERENCE_POLICY_INCREMENT) { + m_childShape->addReference(); + } + } + + HK_DECLARE_CLASS_ALLOCATOR(hkpSingleShapeContainer) + + explicit hkpSingleShapeContainer(hkFinishLoadedObjectFlag) {} + + ~hkpSingleShapeContainer() override { + if (m_childShape) { + m_childShape->removeReference(); + } + } + + int getNumChildShapes() const override { return 1; } + hkpShapeKey getFirstKey() const override { return 0; } + hkpShapeKey getNextKey(hkpShapeKey oldKey) const override { return HK_INVALID_SHAPE_KEY; } + const hkpShape* getChildShape(hkpShapeKey key, hkpShapeBuffer& buffer) const override; + + const hkpShape* getChild() const { return m_childShape; } + const hkpShape* operator->() const { return m_childShape; } + +protected: + const hkpShape* m_childShape; +}; diff --git a/src/KingSystem/Physics/RigidBody/Shape/physCapsuleShape.h b/src/KingSystem/Physics/RigidBody/Shape/physCapsuleShape.h index 0f6c9462..3f62d705 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/physCapsuleShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/physCapsuleShape.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include