Refactor Physics Colliders to use auto serialization.

This commit is contained in:
Chandler Cox
2023-12-02 12:01:32 -06:00
parent 712c400e43
commit 73d33e4af0
14 changed files with 7 additions and 162 deletions

View File

@@ -116,24 +116,6 @@ bool BoxCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& norm
return _bounds.Intersects(ray, distance, normal);
}
void BoxCollider::Serialize(SerializeStream& stream, const void* otherObj)
{
// Base
Collider::Serialize(stream, otherObj);
SERIALIZE_GET_OTHER_OBJ(BoxCollider);
SERIALIZE_MEMBER(Size, _size);
}
void BoxCollider::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
{
// Base
Collider::Deserialize(stream, modifier);
DESERIALIZE_MEMBER(Size, _size);
}
void BoxCollider::UpdateBounds()
{
// Cache bounds

View File

@@ -12,6 +12,7 @@
API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Colliders/Box Collider\"), ActorToolbox(\"Physics\")")
class FLAXENGINE_API BoxCollider : public Collider
{
API_AUTO_SERIALIZATION();
DECLARE_SCENE_OBJECT(BoxCollider);
private:
Float3 _size;
@@ -49,8 +50,6 @@ public:
void OnDebugDrawSelected() override;
#endif
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
protected:
// [Collider]

View File

@@ -81,26 +81,6 @@ bool CapsuleCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3&
return _orientedBox.Intersects(ray, distance, normal);
}
void CapsuleCollider::Serialize(SerializeStream& stream, const void* otherObj)
{
// Base
Collider::Serialize(stream, otherObj);
SERIALIZE_GET_OTHER_OBJ(CapsuleCollider);
SERIALIZE_MEMBER(Radius, _radius);
SERIALIZE_MEMBER(Height, _height);
}
void CapsuleCollider::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
{
// Base
Collider::Deserialize(stream, modifier);
DESERIALIZE_MEMBER(Radius, _radius);
DESERIALIZE_MEMBER(Height, _height);
}
void CapsuleCollider::UpdateBounds()
{
// Cache bounds

View File

@@ -13,6 +13,7 @@
API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Colliders/Capsule Collider\"), ActorToolbox(\"Physics\")")
class FLAXENGINE_API CapsuleCollider : public Collider
{
API_AUTO_SERIALIZATION();
DECLARE_SCENE_OBJECT(CapsuleCollider);
private:
float _radius;
@@ -58,8 +59,6 @@ public:
void OnDebugDrawSelected() override;
#endif
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
protected:
// [Collider]

View File

@@ -387,33 +387,3 @@ void CharacterController::OnPhysicsSceneChanged(PhysicsScene* previous)
DeleteController();
CreateController();
}
void CharacterController::Serialize(SerializeStream& stream, const void* otherObj)
{
// Base
Collider::Serialize(stream, otherObj);
SERIALIZE_GET_OTHER_OBJ(CharacterController);
SERIALIZE_MEMBER(StepOffset, _stepOffset);
SERIALIZE_MEMBER(SlopeLimit, _slopeLimit);
SERIALIZE_MEMBER(NonWalkableMode, _nonWalkableMode);
SERIALIZE_MEMBER(Radius, _radius);
SERIALIZE_MEMBER(Height, _height);
SERIALIZE_MEMBER(MinMoveDistance, _minMoveDistance);
SERIALIZE_MEMBER(UpDirection, _upDirection);
}
void CharacterController::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
{
// Base
Collider::Deserialize(stream, modifier);
DESERIALIZE_MEMBER(StepOffset, _stepOffset);
DESERIALIZE_MEMBER(SlopeLimit, _slopeLimit);
DESERIALIZE_MEMBER(NonWalkableMode, _nonWalkableMode);
DESERIALIZE_MEMBER(Radius, _radius);
DESERIALIZE_MEMBER(Height, _height);
DESERIALIZE_MEMBER(MinMoveDistance, _minMoveDistance);
DESERIALIZE_MEMBER(UpDirection, _upDirection);
}

View File

@@ -12,6 +12,7 @@
API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Character Controller\"), ActorToolbox(\"Physics\")")
class FLAXENGINE_API CharacterController : public Collider, public IPhysicsActor
{
API_AUTO_SERIALIZATION();
DECLARE_SCENE_OBJECT(CharacterController);
public:
/// <summary>
@@ -198,8 +199,6 @@ public:
#if USE_EDITOR
void OnDebugDrawSelected() override;
#endif
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
void CreateShape() override;
void UpdateBounds() override;
void AddMovement(const Vector3& translation, const Quaternion& rotation) override;

View File

@@ -292,30 +292,6 @@ void Collider::OnMaterialChanged()
PhysicsBackend::SetShapeMaterial(_shape, Material.Get());
}
void Collider::Serialize(SerializeStream& stream, const void* otherObj)
{
// Base
PhysicsColliderActor::Serialize(stream, otherObj);
SERIALIZE_GET_OTHER_OBJ(Collider);
SERIALIZE_MEMBER(IsTrigger, _isTrigger);
SERIALIZE_MEMBER(Center, _center);
SERIALIZE_MEMBER(ContactOffset, _contactOffset);
SERIALIZE(Material);
}
void Collider::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
{
// Base
PhysicsColliderActor::Deserialize(stream, modifier);
DESERIALIZE_MEMBER(IsTrigger, _isTrigger);
DESERIALIZE_MEMBER(Center, _center);
DESERIALIZE_MEMBER(ContactOffset, _contactOffset);
DESERIALIZE(Material);
}
void Collider::BeginPlay(SceneBeginData* data)
{
// Check if has no shape created (it means no rigidbody requested it but also collider may be spawned at runtime)

View File

@@ -17,6 +17,7 @@ class RigidBody;
/// <seealso cref="PhysicsColliderActor" />
API_CLASS(Abstract) class FLAXENGINE_API Collider : public PhysicsColliderActor
{
API_AUTO_SERIALIZATION();
DECLARE_SCENE_OBJECT_ABSTRACT(Collider);
protected:
Vector3 _center;
@@ -196,8 +197,6 @@ private:
public:
// [PhysicsColliderActor]
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
RigidBody* GetAttachedRigidBody() const override;
protected:

View File

@@ -117,24 +117,6 @@ bool MeshCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& nor
return _box.Intersects(ray, distance, normal);
}
void MeshCollider::Serialize(SerializeStream& stream, const void* otherObj)
{
// Base
Collider::Serialize(stream, otherObj);
SERIALIZE_GET_OTHER_OBJ(MeshCollider);
SERIALIZE(CollisionData);
}
void MeshCollider::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
{
// Base
Collider::Deserialize(stream, modifier);
DESERIALIZE(CollisionData);
}
void MeshCollider::UpdateBounds()
{
// Cache bounds

View File

@@ -13,6 +13,7 @@
API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Colliders/Mesh Collider\"), ActorToolbox(\"Physics\")")
class FLAXENGINE_API MeshCollider : public Collider
{
API_AUTO_SERIALIZATION();
DECLARE_SCENE_OBJECT(MeshCollider);
public:
/// <summary>
@@ -33,8 +34,6 @@ public:
void OnDebugDrawSelected() override;
#endif
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
protected:
// [Collider]

View File

@@ -58,24 +58,6 @@ bool SphereCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& n
return _sphere.Intersects(ray, distance, normal);
}
void SphereCollider::Serialize(SerializeStream& stream, const void* otherObj)
{
// Base
Collider::Serialize(stream, otherObj);
SERIALIZE_GET_OTHER_OBJ(SphereCollider);
SERIALIZE_MEMBER(Radius, _radius);
}
void SphereCollider::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
{
// Base
Collider::Deserialize(stream, modifier);
DESERIALIZE_MEMBER(Radius, _radius);
}
void SphereCollider::UpdateBounds()
{
// Cache bounds

View File

@@ -11,6 +11,7 @@
API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Colliders/Sphere Collider\"), ActorToolbox(\"Physics\")")
class FLAXENGINE_API SphereCollider : public Collider
{
API_AUTO_SERIALIZATION();
DECLARE_SCENE_OBJECT(SphereCollider);
private:
float _radius;
@@ -38,8 +39,6 @@ public:
void OnDebugDrawSelected() override;
#endif
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
protected:
// [Collider]

View File

@@ -124,26 +124,6 @@ bool SplineCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& n
return _box.Intersects(ray, distance, normal);
}
void SplineCollider::Serialize(SerializeStream& stream, const void* otherObj)
{
// Base
Collider::Serialize(stream, otherObj);
SERIALIZE_GET_OTHER_OBJ(SplineCollider);
SERIALIZE(CollisionData);
SERIALIZE_MEMBER(PreTransform, _preTransform)
}
void SplineCollider::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
{
// Base
Collider::Deserialize(stream, modifier);
DESERIALIZE(CollisionData);
DESERIALIZE_MEMBER(PreTransform, _preTransform);
}
void SplineCollider::OnParentChanged()
{
if (_spline)

View File

@@ -15,6 +15,7 @@ class Spline;
/// <seealso cref="Spline" />
API_CLASS() class FLAXENGINE_API SplineCollider : public Collider
{
API_AUTO_SERIALIZATION();
DECLARE_SCENE_OBJECT(SplineCollider);
private:
Spline* _spline = nullptr;
@@ -61,8 +62,6 @@ public:
void OnDebugDrawSelected() override;
#endif
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
void OnParentChanged() override;
void EndPlay() override;