mirror of https://github.com/zeldaret/botw.git
Havok: Add hkpPhysicsData and hkpPhysicsSystem
This commit is contained in:
parent
297c26972a
commit
fb6d464665
|
@ -17,6 +17,7 @@ add_library(hkStubs OBJECT
|
|||
Havok/Common/Base/Memory/Allocator/hkMemoryAllocator.h
|
||||
Havok/Common/Base/Memory/Allocator/Lifo/hkLifoAllocator.h
|
||||
Havok/Common/Base/Memory/Router/hkMemoryRouter.h
|
||||
Havok/Common/Base/Memory/Util/hkMemUtil.h
|
||||
|
||||
Havok/Common/Base/Object/hkBaseObject.h
|
||||
Havok/Common/Base/Object/hkReferencedObject.cpp
|
||||
|
@ -73,6 +74,7 @@ add_library(hkStubs OBJECT
|
|||
|
||||
Havok/Physics2012/Dynamics/Entity/hkpEntity.h
|
||||
Havok/Physics2012/Dynamics/Entity/hkpRigidBody.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
|
||||
|
@ -81,6 +83,8 @@ add_library(hkStubs OBJECT
|
|||
Havok/Physics2012/Dynamics/World/hkpWorldObject.h
|
||||
Havok/Physics2012/Dynamics/World/Memory/hkpWorldMemoryAvailableWatchDog.h
|
||||
Havok/Physics2012/Dynamics/World/Memory/Default/hkpDefaultWorldMemoryWatchDog.h
|
||||
|
||||
Havok/Physics2012/Utilities/Serialize/hkpPhysicsData.h
|
||||
)
|
||||
|
||||
target_compile_options(hkStubs PRIVATE -fno-exceptions)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <Havok/Common/Base/Container/Array/hkArrayUtil.h>
|
||||
#include <Havok/Common/Base/Container/hkContainerAllocators.h>
|
||||
#include <Havok/Common/Base/Memory/Util/hkMemUtil.h>
|
||||
#include <Havok/Common/Base/Types/hkBaseDefs.h>
|
||||
#include <Havok/Common/Base/Types/hkBaseTypes.h>
|
||||
#include <type_traits>
|
||||
|
@ -188,6 +189,27 @@ inline void hkArrayBase<T>::_clearAndDeallocate(hkMemoryAllocator& allocator) {
|
|||
m_capacityAndFlags = DONT_DEALLOCATE_FLAG;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayBase<T>::removeAt(int index) {
|
||||
hkArrayUtil::destruct(&m_data[index], 1);
|
||||
m_size--;
|
||||
if (m_size != index)
|
||||
hkMemUtil::memCpyOneAligned<sizeof(T), alignof(T)>(m_data + index, m_data + m_size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayBase<T>::removeAtAndCopy(int index) {
|
||||
removeAtAndCopy(index, 1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayBase<T>::removeAtAndCopy(int index, int numToRemove) {
|
||||
hkArrayUtil::destruct(m_data + index, numToRemove);
|
||||
m_size -= numToRemove;
|
||||
hkMemUtil::memCpy<alignof(T)>(m_data + index, m_data + index + numToRemove,
|
||||
(m_size - index) * sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void hkArrayBase<T>::popBack(int numElemsToRemove) {
|
||||
hkArrayUtil::destruct(m_data + m_size - numElemsToRemove, numElemsToRemove);
|
||||
|
|
|
@ -11,6 +11,7 @@ public:
|
|||
};
|
||||
|
||||
hkStringPtr();
|
||||
explicit hkStringPtr(hkFinishLoadedObjectFlag f);
|
||||
|
||||
inline const char* cString() const;
|
||||
inline operator const char*() const;
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
|
||||
namespace hkMemUtil {
|
||||
|
||||
template <unsigned int NBYTES>
|
||||
struct TypeFromAlign;
|
||||
|
||||
template <>
|
||||
struct TypeFromAlign<1> {
|
||||
using type = char;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TypeFromAlign<2> {
|
||||
using type = hkInt16;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TypeFromAlign<4> {
|
||||
using type = hkInt32;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TypeFromAlign<8> {
|
||||
using type = hkInt64;
|
||||
};
|
||||
|
||||
template <unsigned int NBYTES>
|
||||
struct TypeFromAlign : public TypeFromAlign<NBYTES / 2> {};
|
||||
|
||||
template <unsigned int ELEMENTSIZE, unsigned int ELEMENTALIGN>
|
||||
HK_FORCE_INLINE void memCpyOneAligned(void* dst, const void* src);
|
||||
|
||||
template <unsigned int ELEMENTALIGN>
|
||||
HK_FORCE_INLINE void memCpy(void* dst, const void* src, int nbytes);
|
||||
|
||||
void memCpy(void* dst, const void* src, int nbytes);
|
||||
void memCpyBackwards(void* dst, const void* src, int nbytes);
|
||||
void memMove(void* dst, const void* src, int nbytes);
|
||||
void memSet(void* dst, int c, int n);
|
||||
|
||||
template <unsigned int ELEMENTSIZE, unsigned int ELEMENTALIGN>
|
||||
inline void memCpyOneAligned(void* dst, const void* src) {
|
||||
using CopyType = typename TypeFromAlign<ELEMENTALIGN>::type;
|
||||
unsigned int i = 0;
|
||||
do {
|
||||
static_cast<CopyType*>(dst)[i] = static_cast<const CopyType*>(src)[i];
|
||||
} while (++i < ELEMENTSIZE / sizeof(CopyType));
|
||||
}
|
||||
|
||||
template <unsigned int ELEMENTALIGN>
|
||||
inline void memCpy(void* dst, const void* src, int nbytes) {
|
||||
using CopyType = typename TypeFromAlign<ELEMENTALIGN>::type;
|
||||
for (int i = 0, j = 0; i < nbytes; i += sizeof(CopyType), ++j) {
|
||||
static_cast<CopyType*>(dst)[j] = static_cast<const CopyType*>(src)[j];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace hkMemUtil
|
|
@ -0,0 +1,115 @@
|
|||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
|
||||
class hkTransform;
|
||||
class hkpRigidBody;
|
||||
class hkpConstraintInstance;
|
||||
class hkpAction;
|
||||
class hkpPhantom;
|
||||
|
||||
class hkpPhysicsSystem : public hkReferencedObject {
|
||||
public:
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkpPhysicsSystem)
|
||||
HK_DECLARE_REFLECTION()
|
||||
|
||||
hkpPhysicsSystem();
|
||||
|
||||
explicit hkpPhysicsSystem(hkFinishLoadedObjectFlag f)
|
||||
: hkReferencedObject(f), m_rigidBodies(f), m_constraints(f), m_actions(f), m_phantoms(f),
|
||||
m_name(f) {}
|
||||
|
||||
~hkpPhysicsSystem() override;
|
||||
|
||||
enum CloneConstraintMode {
|
||||
CLONE_SHALLOW_IF_NOT_CONSTRAINED_TO_WORLD = 0,
|
||||
CLONE_DEEP_WITH_MOTORS = 1,
|
||||
CLONE_FORCE_SHALLOW = 2,
|
||||
CLONE_DEFAULT = 0,
|
||||
};
|
||||
|
||||
virtual hkpPhysicsSystem* clone(CloneConstraintMode cloneMode = CLONE_DEFAULT) const;
|
||||
|
||||
void removeAll();
|
||||
|
||||
void copy(const hkpPhysicsSystem& toCopy);
|
||||
|
||||
void addRigidBody(hkpRigidBody* rb);
|
||||
void addPhantom(hkpPhantom* p);
|
||||
void addConstraint(hkpConstraintInstance* c);
|
||||
void addAction(hkpAction* a);
|
||||
|
||||
void removeRigidBody(int i);
|
||||
void removePhantom(int i);
|
||||
void removeConstraint(int i);
|
||||
void removeAction(int i);
|
||||
|
||||
void removeNullPhantoms();
|
||||
|
||||
inline const hkArray<hkpRigidBody*>& getRigidBodies() const;
|
||||
inline const hkArray<hkpPhantom*>& getPhantoms() const;
|
||||
inline const hkArray<hkpConstraintInstance*>& getConstraints() const;
|
||||
inline const hkArray<hkpAction*>& getActions() const;
|
||||
|
||||
inline const char* getName() const;
|
||||
inline void setName(const char* name);
|
||||
|
||||
inline hkUlong getUserData() const;
|
||||
inline void setUserData(hkUlong d);
|
||||
|
||||
inline hkBool isActive() const;
|
||||
inline void setActive(hkBool active);
|
||||
|
||||
virtual hkBool hasContacts() { return false; }
|
||||
|
||||
void transform(const hkTransform& transformation);
|
||||
|
||||
protected:
|
||||
hkArray<hkpRigidBody*> m_rigidBodies;
|
||||
hkArray<hkpConstraintInstance*> m_constraints;
|
||||
hkArray<hkpAction*> m_actions;
|
||||
hkArray<hkpPhantom*> m_phantoms;
|
||||
hkStringPtr m_name;
|
||||
hkUlong m_userData;
|
||||
hkBool m_active;
|
||||
};
|
||||
|
||||
inline const hkArray<hkpRigidBody*>& hkpPhysicsSystem::getRigidBodies() const {
|
||||
return m_rigidBodies;
|
||||
}
|
||||
|
||||
inline const hkArray<hkpPhantom*>& hkpPhysicsSystem::getPhantoms() const {
|
||||
return m_phantoms;
|
||||
}
|
||||
|
||||
inline const hkArray<hkpConstraintInstance*>& hkpPhysicsSystem::getConstraints() const {
|
||||
return m_constraints;
|
||||
}
|
||||
|
||||
inline const hkArray<hkpAction*>& hkpPhysicsSystem::getActions() const {
|
||||
return m_actions;
|
||||
}
|
||||
|
||||
inline const char* hkpPhysicsSystem::getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
inline void hkpPhysicsSystem::setName(const char* name) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
inline hkUlong hkpPhysicsSystem::getUserData() const {
|
||||
return m_userData;
|
||||
}
|
||||
|
||||
inline void hkpPhysicsSystem::setUserData(hkUlong d) {
|
||||
m_userData = d;
|
||||
}
|
||||
|
||||
inline hkBool hkpPhysicsSystem::isActive() const {
|
||||
return m_active;
|
||||
}
|
||||
|
||||
inline void hkpPhysicsSystem::setActive(hkBool active) {
|
||||
m_active = active;
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
#include <Havok/Physics2012/Dynamics/World/hkpPhysicsSystem.h>
|
||||
#include <Havok/Physics2012/Dynamics/World/hkpWorldCinfo.h>
|
||||
|
||||
class hkpRigidBody;
|
||||
class hkpWorld;
|
||||
|
||||
class hkpPhysicsData : public hkReferencedObject {
|
||||
public:
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkpPhysicsData)
|
||||
HK_DECLARE_REFLECTION()
|
||||
|
||||
hkpPhysicsData();
|
||||
explicit hkpPhysicsData(hkFinishLoadedObjectFlag f) : hkReferencedObject(f), m_systems(f) {}
|
||||
|
||||
~hkpPhysicsData() override;
|
||||
|
||||
inline hkpWorldCinfo* getWorldCinfo();
|
||||
inline void setWorldCinfo(hkpWorldCinfo* info);
|
||||
|
||||
inline void addPhysicsSystem(hkpPhysicsSystem* system);
|
||||
inline void removePhysicsSystem(int i);
|
||||
inline const hkArray<hkpPhysicsSystem*>& getPhysicsSystems() const;
|
||||
|
||||
hkpPhysicsSystem* findPhysicsSystemByName(const char* name) const;
|
||||
/// Look for a rigid body by name (case insensitive)
|
||||
hkpRigidBody* findRigidBodyByName(const char* name) const;
|
||||
|
||||
void populateFromWorld(const hkpWorld* world, bool saveContactPoints = false);
|
||||
|
||||
hkpWorld* createWorld(hkBool registerAllAgents = true);
|
||||
|
||||
struct SplitPhysicsSystemsOutput {
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkpPhysicsData::SplitPhysicsSystemsOutput)
|
||||
|
||||
hkpPhysicsSystem* m_unconstrainedFixedBodies;
|
||||
hkpPhysicsSystem* m_unconstrainedKeyframedBodies;
|
||||
hkpPhysicsSystem* m_unconstrainedMovingBodies;
|
||||
hkpPhysicsSystem* m_phantoms;
|
||||
hkArray<hkpPhysicsSystem*> m_constrainedSystems;
|
||||
};
|
||||
|
||||
static void splitPhysicsSystems(const hkpPhysicsSystem* inputSystemConst,
|
||||
SplitPhysicsSystemsOutput& output);
|
||||
|
||||
protected:
|
||||
hkpWorldCinfo* m_worldCinfo;
|
||||
hkArray<hkpPhysicsSystem*> m_systems;
|
||||
};
|
||||
|
||||
inline hkpWorldCinfo* hkpPhysicsData::getWorldCinfo() {
|
||||
return m_worldCinfo;
|
||||
}
|
||||
|
||||
inline void hkpPhysicsData::setWorldCinfo(hkpWorldCinfo* info) {
|
||||
if (info != nullptr)
|
||||
info->addReference();
|
||||
if (m_worldCinfo != nullptr)
|
||||
m_worldCinfo->removeReference();
|
||||
|
||||
m_worldCinfo = info;
|
||||
}
|
||||
|
||||
inline void hkpPhysicsData::addPhysicsSystem(hkpPhysicsSystem* system) {
|
||||
system->addReference();
|
||||
m_systems.pushBack(system);
|
||||
}
|
||||
|
||||
inline void hkpPhysicsData::removePhysicsSystem(int i) {
|
||||
m_systems[i]->removeReference();
|
||||
m_systems.removeAt(i);
|
||||
}
|
||||
|
||||
inline const hkArray<hkpPhysicsSystem*>& hkpPhysicsData::getPhysicsSystems() const {
|
||||
return m_systems;
|
||||
}
|
Loading…
Reference in New Issue