From ea9f90f60de8e22ebfc320708b6188ec9ec7bcdd Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Fri, 28 Oct 2022 19:39:39 +0800 Subject: [PATCH] Serialize Collider Component done --- .../Components/SHColliderComponent.cpp | 10 ++++++- .../Physics/Components/SHColliderComponent.h | 1 + .../Serialization/SHSerializationHelper.hpp | 27 ++++++------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/SHADE_Engine/src/Physics/Components/SHColliderComponent.cpp b/SHADE_Engine/src/Physics/Components/SHColliderComponent.cpp index fb999847..c7e327fa 100644 --- a/SHADE_Engine/src/Physics/Components/SHColliderComponent.cpp +++ b/SHADE_Engine/src/Physics/Components/SHColliderComponent.cpp @@ -146,4 +146,12 @@ namespace SHADE system->RemoveCollisionShape(GetEID(), index); } -} // namespace SHADE \ No newline at end of file +} // namespace SHADE + +RTTR_REGISTRATION +{ + using namespace rttr; + using namespace SHADE; + + registration::class_("Collider Component"); +} \ No newline at end of file diff --git a/SHADE_Engine/src/Physics/Components/SHColliderComponent.h b/SHADE_Engine/src/Physics/Components/SHColliderComponent.h index af726b51..7ce272a9 100644 --- a/SHADE_Engine/src/Physics/Components/SHColliderComponent.h +++ b/SHADE_Engine/src/Physics/Components/SHColliderComponent.h @@ -100,5 +100,6 @@ namespace SHADE SHQuaternion orientation; Colliders colliders; + RTTR_ENABLE() }; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index b81a6e46..80362e8d 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -169,24 +169,12 @@ namespace YAML { case SHCollider::Type::BOX: { - if(auto const bb = dynamic_cast(rhs.GetShape()); bb) - { - if (node[HalfExtents]) - { - bb->SetHalfExtents(node[HalfExtents].as()); - } - } + rhs.SetBoundingBox(node[HalfExtents].as()); } break; case SHCollider::Type::SPHERE: { - if(auto const bs = dynamic_cast(rhs.GetShape()); bs) - { - if (node[Radius]) - { - bs->SetRadius(node[Radius].as()); - } - } + rhs.SetBoundingSphere(node[Radius].as()); } break; case SHCollider::Type::CAPSULE: break; @@ -200,7 +188,7 @@ namespace YAML rhs.SetDensity(node[Density].as()); if (node[PositionOffset]) rhs.SetPositionOffset(node[PositionOffset].as()); - + return true; } }; @@ -237,6 +225,7 @@ namespace YAML const SHCollider::Type colliderType = enumAlign.name_to_value(colliderNode[convert::Type].as()).convert(&ok); if (!ok) return false; + switch (colliderType) { case SHCollider::Type::BOX: rhs.AddBoundingBox(); break; @@ -244,7 +233,7 @@ namespace YAML case SHCollider::Type::CAPSULE: break; default:; } - rhs.GetCollider(numColliders++) = colliderNode.as(); + YAML::convert::decode(colliderNode, rhs.GetCollider(numColliders++)); } } } @@ -279,13 +268,13 @@ namespace YAML propNode = rhs.GetProperty(VARIABLE->offset); break; case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2: - propNode = SHSerializationTools::ValToYAML(rhs.GetProperty(VARIABLE->offset)); + propNode = rhs.GetProperty(VARIABLE->offset); break; case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR3: - propNode = SHSerializationTools::ValToYAML(rhs.GetProperty(VARIABLE->offset)); + propNode = rhs.GetProperty(VARIABLE->offset); break; case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR4: - propNode = SHSerializationTools::ValToYAML(rhs.GetProperty(VARIABLE->offset)); + propNode = rhs.GetProperty(VARIABLE->offset); break; case SHADE::SHShaderBlockInterface::Variable::Type::OTHER: default: