Add more Havok prereqs for ContactListener

This commit is contained in:
Léo Lam 2022-03-03 14:35:48 +01:00
parent a222e40180
commit 9b35b62368
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
15 changed files with 394 additions and 5 deletions

View File

@ -99,6 +99,7 @@ add_library(hkStubs OBJECT
Havok/Physics2012/Collide/BroadPhase/hkpBroadPhaseHandle.h
Havok/Physics2012/Collide/BroadPhase/hkpTypedBroadPhaseHandle.h
Havok/Physics2012/Collide/Dispatch/hkpCollisionDispatcher.h
Havok/Physics2012/Collide/Dispatch/ContactMgr/hkpContactMgrFactory.h
Havok/Physics2012/Collide/Filter/hkpCollidableCollidableFilter.h
Havok/Physics2012/Collide/Filter/hkpCollisionFilter.cpp
Havok/Physics2012/Collide/Filter/hkpCollisionFilter.h
@ -136,6 +137,7 @@ add_library(hkStubs OBJECT
Havok/Physics2012/Dynamics/Action/hkpAction.h
Havok/Physics2012/Dynamics/Collide/hkpDynamicsContactMgr.h
Havok/Physics2012/Dynamics/Collide/hkpResponseModifier.h
Havok/Physics2012/Dynamics/Collide/hkpSimpleConstraintContactMgr.h
Havok/Physics2012/Dynamics/Collide/ContactListener/hkpCollisionEvent.h
Havok/Physics2012/Dynamics/Collide/ContactListener/hkpContactListener.h
Havok/Physics2012/Dynamics/Collide/ContactListener/hkpContactPointEvent.h
@ -143,7 +145,12 @@ add_library(hkStubs OBJECT
Havok/Physics2012/Dynamics/Common/hkpProperty.h
Havok/Physics2012/Dynamics/Constraint/hkpConstraintInstance.h
Havok/Physics2012/Dynamics/Constraint/hkpConstraintOwner.h
Havok/Physics2012/Dynamics/Constraint/Atom/hkpModifierConstraintAtom.h
Havok/Physics2012/Dynamics/Constraint/Atom/hkpSimpleContactConstraintAtom.h
Havok/Physics2012/Dynamics/Constraint/Atom/hkpSimpleContactConstraintAtomUtil.h
Havok/Physics2012/Dynamics/Constraint/Contact/hkpContactPointProperties.h
Havok/Physics2012/Dynamics/Constraint/Contact/hkpDynamicsCpidMgr.h
Havok/Physics2012/Dynamics/Constraint/Contact/hkpSimpleContactConstraintData.h
Havok/Physics2012/Dynamics/Entity/hkpEntity.h
Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h
Havok/Physics2012/Dynamics/Entity/hkpRigidBodyCinfo.h
@ -173,6 +180,7 @@ add_library(hkStubs OBJECT
Havok/Physics2012/Dynamics/World/Simulation/hkpSimulation.h
Havok/Physics2012/Internal/Collide/Mopp/Code/hkpMoppCode.h
Havok/Physics2012/Internal/Solver/Contact/hkpSimpleContactConstraintDataInfo.h
Havok/Physics2012/Utilities/CharacterControl/CharacterRigidBody/hkpCharacterRigidBody.h
Havok/Physics2012/Utilities/Collide/ShapeUtils/ShapeScaling/hkpShapeScalingUtility.h

View File

@ -1,6 +1,6 @@
#include <Havok/Common/Base/Object/hkReferencedObject.h>
const void* hkReferencedObject::getClassType() const {
const hkClass* hkReferencedObject::getClassType() const {
return nullptr;
}

View File

@ -5,6 +5,8 @@
#include <Havok/Common/Base/Types/hkBaseTypes.h>
#include "Havok/Common/Base/Thread/Atomic/hkAtomicPrimitives.h"
class hkClass;
class hkReferencedObject : public hkBaseObject {
public:
inline hkReferencedObject();
@ -17,7 +19,7 @@ public:
~hkReferencedObject() override = default;
virtual const void* getClassType() const;
virtual const hkClass* getClassType() const;
inline int getReferenceCount() const;
inline void setReferenceCount(int newRefCount);

View File

@ -216,6 +216,11 @@ HK_FORCE_INLINE hkLong hkGetByteOffset(const void* base, const void* pntr) {
return hkLong(pntr) - hkLong(base);
}
template <typename T>
HK_ALWAYS_INLINE const T* hkAddByteOffsetConst(const T* base, hkLong offset) {
return reinterpret_cast<const T*>(reinterpret_cast<hkUlong>(base) + offset);
}
template <typename T>
using hkAddConstPointer =
std::conditional_t<std::is_pointer_v<T>,

View File

@ -0,0 +1,15 @@
#pragma once
#include <Havok/Common/Base/hkBase.h>
class hkpCollidable;
struct hkpCollisionInput;
class hkpContactMgr;
class hkpContactMgrFactory : public hkReferencedObject {
public:
HK_DECLARE_CLASS_ALLOCATOR(hkpContactMgrFactory)
virtual hkpContactMgr* createContactMgr(const hkpCollidable& a, const hkpCollidable& b,
const hkpCollisionInput& input) = 0;
};

View File

@ -6,7 +6,6 @@ class hkContactPoint;
class hkpContactPointProperties;
class hkpWorld;
/// An interface to access contact point information.
class hkpDynamicsContactMgr : public hkpContactMgr {
public:
HK_DECLARE_CLASS_ALLOCATOR(hkpDynamicsContactMgr)

View File

@ -0,0 +1,112 @@
#pragma once
#include <Havok/Common/Base/hkBase.h>
#include <Havok/Physics2012/Collide/Dispatch/ContactMgr/hkpContactMgrFactory.h>
#include <Havok/Physics2012/Dynamics/Collide/hkpDynamicsContactMgr.h>
#include <Havok/Physics2012/Dynamics/Constraint/Atom/hkpModifierConstraintAtom.h>
#include <Havok/Physics2012/Dynamics/Constraint/Contact/hkpSimpleContactConstraintData.h>
#include <Havok/Physics2012/Dynamics/Constraint/hkpConstraintInstance.h>
class hkpRigidBody;
extern const hkClass hkpSimpleConstraintContactMgrClass;
class hkpSimpleConstraintContactMgr : public hkpDynamicsContactMgr {
public:
HK_DECLARE_CLASS_ALLOCATOR(hkpSimpleConstraintContactMgr)
hkpSimpleConstraintContactMgr(hkpWorld* world, hkpRigidBody* bodyA, hkpRigidBody* bodyB);
~hkpSimpleConstraintContactMgr() override;
explicit hkpSimpleConstraintContactMgr(hkFinishLoadedObjectFlag f)
: hkpDynamicsContactMgr(hkpContactMgr::TYPE_SIMPLE_CONSTRAINT_CONTACT_MGR),
m_contactConstraintData(f), m_constraint(f) {
m_constraint.m_uid = 0xffffffff;
}
hkContactPoint* getContactPoint(hkContactPointId id) override;
hkpContactPointProperties* getContactPointProperties(hkContactPointId id) override;
hkContactPointId addContactPointImpl(const hkpCdBody& a, const hkpCdBody& b,
const hkpProcessCollisionInput& input,
hkpProcessCollisionOutput& output,
const hkpGskCache* contactCache,
hkContactPoint& cp) override;
hkResult reserveContactPointsImpl(int numPoints) override;
void removeContactPointImpl(hkContactPointId cpId,
hkCollisionConstraintOwner& constraintOwner) override;
void processContactImpl(const hkpCollidable& a, const hkpCollidable& b,
const hkpProcessCollisionInput& input,
hkpProcessCollisionData& collisionData) override;
ToiAccept addToiImpl(const hkpCdBody& a, const hkpCdBody& b,
const hkpProcessCollisionInput& input, hkpProcessCollisionOutput& output,
hkTime toi, hkContactPoint& cp, const hkpGskCache* gskCache,
hkReal& projectedVelocity, hkpContactPointProperties& properties) override;
void removeToiImpl(class hkCollisionConstraintOwner& constraintOwner,
hkpContactPointProperties& properties) override;
hkBool fireCallbacksForEarliestToi(struct hkpToiEvent& event, hkReal& rotateNormal) override;
void confirmToi(struct hkpToiEvent& event, hkReal rotateNormal,
class hkArray<class hkpEntity*>& outToBeActivated) override;
void cleanup() override { delete this; }
Type getType() const override { return TYPE_SIMPLE_CONSTRAINT_CONTACT_MGR; }
void getAllContactPointIds(hkArray<hkContactPointId>& contactPointIds) const override;
HK_FORCE_INLINE hkpSimpleContactConstraintAtom* getAtom() {
return m_contactConstraintData.m_atom;
}
HK_FORCE_INLINE const hkpSimpleContactConstraintAtom* getAtom() const {
return m_contactConstraintData.m_atom;
}
hkpConstraintInstance* getConstraintInstance() override;
virtual const hkpConstraintInstance* getConstraintInstance() const;
void toiCollisionResponseBeginCallback(const hkContactPoint& cp,
struct hkpSimpleConstraintInfoInitInput& inA,
struct hkpBodyVelocity& velA,
hkpSimpleConstraintInfoInitInput& inB,
hkpBodyVelocity& velB) override;
void toiCollisionResponseEndCallback(const hkContactPoint& cp, hkReal impulseApplied,
struct hkpSimpleConstraintInfoInitInput& inA,
struct hkpBodyVelocity& velA,
hkpSimpleConstraintInfoInitInput& inB,
hkpBodyVelocity& velB) override;
inline hkBool isConstraintDisabled() const {
return m_constraint.getConstraintModifiers() &&
(m_constraint.getConstraintModifiers()->getType() ==
hkpConstraintAtom::TYPE_MODIFIER_IGNORE_CONSTRAINT);
}
protected:
inline hkpRigidBody* setContactPointProperties(const hkpCdBody& a, const hkpCdBody& b,
int maxNumExtraDataInEvent,
hkpContactPointProperties* cpi);
const hkClass* getClassType() const override { return &hkpSimpleConstraintContactMgrClass; }
public:
class Factory : public hkpContactMgrFactory {
public:
HK_DECLARE_CLASS_ALLOCATOR(Factory)
explicit Factory(hkpWorld* mgr);
hkpContactMgr* createContactMgr(const hkpCollidable& a, const hkpCollidable& b,
const hkpCollisionInput& input) override;
protected:
hkpWorld* m_world;
};
public:
hkUint16 m_reservedContactPoints;
hkUint16 m_contactPointCallbackDelay;
hkpSimpleContactConstraintData m_contactConstraintData;
hkpConstraintInstance m_constraint;
hkUint32 m_pad[1];
};

View File

@ -0,0 +1,28 @@
#pragma once
#include <Havok/Physics/Constraint/Atom/hkpConstraintAtom.h>
struct hkpConstraintInfo;
struct hkpModifierConstraintAtom : public hkpConstraintAtom {
public:
HK_DECLARE_CLASS_ALLOCATOR(hkpModifierConstraintAtom)
HK_DECLARE_REFLECTION()
explicit hkpModifierConstraintAtom(hkFinishLoadedObjectFlag f) : hkpConstraintAtom(f) {}
int addModifierDataToConstraintInfo(hkpConstraintInfo& cinfo, hkUint8& usedFlagsOut) const;
static int addAllModifierDataToConstraintInfo(hkpModifierConstraintAtom* firstModifier,
hkpConstraintInfo& cinfo, hkUint8& usedFlagsOut);
protected:
hkpModifierConstraintAtom(AtomType type, int size)
: hkpConstraintAtom(type), m_modifierAtomSize(static_cast<hkUint16>(size)) {}
public:
alignas(16) hkUint16 m_modifierAtomSize;
hkUint16 m_childSize;
hkpConstraintAtom* m_child;
hkUint32 m_pad[2];
};

View File

@ -0,0 +1,47 @@
#pragma once
#include <Havok/Common/Base/Types/Physics/ContactPoint/hkContactPoint.h>
#include <Havok/Common/Base/hkBase.h>
#include <Havok/Physics/Constraint/Atom/hkpConstraintAtom.h>
#include <Havok/Physics/Constraint/Data/hkpConstraintInfo.h>
#include <Havok/Physics2012/Internal/Solver/Contact/hkpSimpleContactConstraintDataInfo.h>
class hkpContactPointProperties;
struct hkpSimpleContactConstraintAtom : public hkpConstraintAtom {
public:
HK_DECLARE_REFLECTION()
HK_DECLARE_CLASS_ALLOCATOR(hkpSimpleContactConstraintAtom)
hkpSimpleContactConstraintAtom() : hkpConstraintAtom(TYPE_CONTACT) {}
explicit hkpSimpleContactConstraintAtom(hkFinishLoadedObjectFlag f);
HK_FORCE_INLINE hkContactPoint* getContactPoints() const {
return const_cast<hkContactPoint*>(reinterpret_cast<const hkContactPoint*>(this + 1));
}
HK_FORCE_INLINE int getContactPointPropertiesStriding() const;
HK_FORCE_INLINE hkpContactPointProperties* getContactPointPropertiesStream() const {
return const_cast<hkpContactPointProperties*>(
reinterpret_cast<const hkpContactPointProperties*>(hkAddByteOffsetConst(
getContactPoints(), sizeof(hkContactPoint) * m_numReservedContactPoints)));
}
HK_FORCE_INLINE hkpContactPointProperties* getContactPointPropertiesStream(int i) const;
HK_FORCE_INLINE hkpConstraintAtom* next() const { return nullptr; }
HK_FORCE_INLINE int numSolverResults() const { return m_numContactPoints + 3; }
HK_FORCE_INLINE void addToConstraintInfo(hkpConstraintInfo& infoOut) const;
hkUint16 m_sizeOfAllAtoms;
hkUint16 m_numContactPoints;
hkUint16 m_numReservedContactPoints;
hkUint8 m_numUserDatasForBodyA;
hkUint8 m_numUserDatasForBodyB;
hkUint8 m_contactPointPropertiesStriding;
hkUint16 m_maxNumContactPoints;
alignas(16) hkpSimpleContactConstraintDataInfo m_info;
};

View File

@ -0,0 +1,33 @@
#pragma once
#include <Havok/Physics2012/Dynamics/Constraint/Atom/hkpSimpleContactConstraintAtom.h>
class hkpSimpleContactConstraintAtomUtil {
public:
static hkpSimpleContactConstraintAtom*
expandOne(hkpSimpleContactConstraintAtom* oldAtom_mightGetDeallocated, bool& atomReallocated);
inline static void removeAtAndCopy(hkpSimpleContactConstraintAtom* atom, int index);
static hkpSimpleContactConstraintAtom*
optimizeCapacity(hkpSimpleContactConstraintAtom* oldAtom_mightGetDeallocated,
int numFreeElemsLeft, bool& atomReallocated);
static hkpSimpleContactConstraintAtom* allocateAtom(int numReservedContactPoints,
int numExtraUserDatasA,
int numExtraUserDatasB,
int maxNumContactPoints);
static void copyContents(hkpSimpleContactConstraintAtom* dst,
const hkpSimpleContactConstraintAtom* src);
static inline void deallocateAtom(hkpSimpleContactConstraintAtom* atom);
static inline int calculateAtomSize(int numReservedContactPoints, int numExtraUserDatas);
};
void hkpSimpleContactConstraintAtomUtil::deallocateAtom(hkpSimpleContactConstraintAtom* atom) {
extern int atomSizeRoundUp(int);
int allocsize = atomSizeRoundUp(atom->m_sizeOfAllAtoms);
hkDeallocateChunk(reinterpret_cast<char*>(atom), allocsize);
}

View File

@ -4,7 +4,7 @@
#include <Havok/Common/Base/hkBase.h>
#include <Havok/Physics/ConstraintSolver/Solve/hkpSolverResults.h>
class hkpSimpleContactConstraintAtom;
struct hkpSimpleContactConstraintAtom;
class hkpContactPointProperties : public hkpSolverResults, public hkContactPointMaterial {
public:

View File

@ -0,0 +1,29 @@
#pragma once
#include <Havok/Common/Base/Types/Physics/ContactPoint/hkContactPoint.h>
#include <Havok/Common/Base/hkBase.h>
class hkpDynamicsCpIdMgr {
public:
HK_DECLARE_CLASS_ALLOCATOR(hkpDynamicsCpIdMgr)
using hkpValueType = hkUchar;
static constexpr int HK_MAX_IDS_PER_OBJECT = 8;
static constexpr hkpValueType FREE_VALUE = 0xff;
inline hkpDynamicsCpIdMgr();
inline ~hkpDynamicsCpIdMgr();
inline int newId(int value);
inline int indexOf(int value) const;
inline void freeId(int id);
inline void decrementValuesGreater(int relIndex);
inline void getAllUsedIds(hkArray<hkContactPointId>& ids) const;
inline hkpValueType getValueAt(int id) const;
hkInplaceArray<hkpValueType, HK_MAX_IDS_PER_OBJECT> m_values;
};
inline hkpDynamicsCpIdMgr::hkpDynamicsCpIdMgr() = default;
inline hkpDynamicsCpIdMgr::~hkpDynamicsCpIdMgr() = default;

View File

@ -0,0 +1,72 @@
#pragma once
#include <Havok/Common/Base/Types/Physics/ContactPoint/hkContactPoint.h>
#include <Havok/Physics/Constraint/Data/hkpConstraintData.h>
#include <Havok/Physics2012/Dynamics/Constraint/Atom/hkpSimpleContactConstraintAtomUtil.h>
#include <Havok/Physics2012/Dynamics/Constraint/Contact/hkpDynamicsCpidMgr.h>
class hkpConstraintInstance;
class hkpConstraintOwner;
class hkpContactPointProperties;
class hkpRigidBody;
class hkpSimpleConstraintContactMgr;
struct hkpSimpleContactConstraintAtom;
class hkpSimpleContactConstraintData : public hkpConstraintData {
public:
HK_DECLARE_CLASS_ALLOCATOR(hkpSimpleContactConstraintData)
explicit hkpSimpleContactConstraintData(hkFinishLoadedObjectFlag f) {}
inline ~hkpSimpleContactConstraintData();
inline int getNumContactPoints() const;
inline hkContactPointId getContactPointIdAt(int index) const;
inline const hkContactPoint& getContactPoint(int id) const;
inline hkContactPoint& getContactPoint(int id);
inline hkpContactPointProperties* getContactPointProperties(int id);
hkContactPointId allocateContactPoint(hkpConstraintOwner& constraintOwner,
hkContactPoint** cpOut,
hkpContactPointProperties** cpPropsOut);
int freeContactPoint(hkpConstraintOwner& constraintOwner, hkContactPointId id);
hkBool isValid() const override;
void getConstraintInfo(hkpConstraintData::ConstraintInfo& infoOut) const override;
void getRuntimeInfo(hkBool wantRuntime, hkpConstraintData::RuntimeInfo& infoOut) const override;
hkpSolverResults* getSolverResults(hkpConstraintRuntime* runtime) const override;
int getType() const override;
virtual void collisionResponseBeginCallback(const hkContactPoint& cp,
struct hkpSimpleConstraintInfoInitInput& inA,
struct hkpBodyVelocity& velA,
hkpSimpleConstraintInfoInitInput& inB,
hkpBodyVelocity& velB);
virtual void collisionResponseEndCallback(const hkContactPoint& cp, hkReal impulseApplied,
struct hkpSimpleConstraintInfoInitInput& inA,
struct hkpBodyVelocity& velA,
hkpSimpleConstraintInfoInitInput& inB,
hkpBodyVelocity& velB);
hkpSimpleConstraintContactMgr* getSimpleConstraintContactMgr() const;
private:
hkpSimpleContactConstraintData(hkpConstraintInstance* constraint, hkpRigidBody* bodyA,
hkpRigidBody* bodyB);
friend class hkpSimpleConstraintContactMgr;
public:
hkpDynamicsCpIdMgr m_idMgrA;
void* m_clientData;
hkpConstraintInstance* m_constraint;
hkpSimpleContactConstraintAtom* m_atom;
int m_atomSize;
};
hkpSimpleContactConstraintData::~hkpSimpleContactConstraintData() {
if (m_atom) {
hkpSimpleContactConstraintAtomUtil::deallocateAtom(m_atom);
}
}

View File

@ -25,7 +25,7 @@ public:
inline int getMemUsageForIntegration();
const void* getClassType() const override { return &hkpSimulationIslandClass; }
const hkClass* getClassType() const override { return &hkpSimulationIslandClass; }
protected:
friend class hkpAddModifierUtil;

View File

@ -0,0 +1,39 @@
#pragma once
#include <Havok/Common/Base/hkBase.h>
class hkpSimpleContactConstraintDataInfo {
public:
HK_DECLARE_REFLECTION()
HK_DECLARE_CLASS_ALLOCATOR(hkpSimpleContactConstraintDataInfo)
enum {
HK_FLAG_OK = 0,
HK_FLAG_POINT_REMOVED = 1 << 0,
HK_FLAG_AREA_CHANGED = 1 << 2,
};
hkpSimpleContactConstraintDataInfo() { init(); }
explicit hkpSimpleContactConstraintDataInfo(hkFinishLoadedObjectFlag f) {}
void init() {
m_flags = HK_FLAG_OK;
m_biNormalAxis = 3;
m_contactRadius = 0.0f;
m_internalData1.setZero();
m_rhsRolling[0].setZero();
m_rhsRolling[1].setZero();
m_rollingFrictionMultiplier.setZero();
for (int i = 0; i < 4; ++i) {
m_data[i] = 0;
}
}
alignas(16) hkUint16 m_flags;
hkUint16 m_biNormalAxis;
hkHalf m_rollingFrictionMultiplier;
hkHalf m_internalData1;
hkHalf m_rhsRolling[2];
hkReal m_contactRadius;
hkReal m_data[4];
};