From 05a19018aaad9889126309dfaf04352587ef5d6e Mon Sep 17 00:00:00 2001 From: SrGesus <108523575+SrGesus@users.noreply.github.com> Date: Sat, 4 Jan 2025 22:15:52 +0000 Subject: [PATCH 1/2] feat(data): Allow wrapped fields to be read as normal object with a single field --- core/CMakeLists.txt | 1 + core/include/cubos/core/ecs/reflection.hpp | 16 ++++- .../cubos/core/reflection/traits/wrapper.hpp | 64 +++++++++++++++++++ core/src/data/des/binary.cpp | 11 ++++ core/src/data/des/json.cpp | 20 +++--- core/src/data/ser/binary.cpp | 12 ++++ core/src/data/ser/debug.cpp | 11 ++++ core/src/data/ser/json.cpp | 24 ++++--- core/src/data/ser/serializer.cpp | 1 + core/src/reflection/traits/wrapper.cpp | 11 ++++ 10 files changed, 145 insertions(+), 26 deletions(-) create mode 100644 core/include/cubos/core/reflection/traits/wrapper.hpp create mode 100644 core/src/reflection/traits/wrapper.cpp diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e89c6b19dc..df1e5102e9 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -60,6 +60,7 @@ set(CUBOS_CORE_SOURCE "src/reflection/traits/enum.cpp" "src/reflection/traits/mask.cpp" "src/reflection/traits/inherits.cpp" + "src/reflection/traits/wrapper.cpp" "src/reflection/external/primitives.cpp" "src/reflection/external/cstring.cpp" "src/reflection/external/string.cpp" diff --git a/core/include/cubos/core/ecs/reflection.hpp b/core/include/cubos/core/ecs/reflection.hpp index 48024d13dc..f22c0079dc 100644 --- a/core/include/cubos/core/ecs/reflection.hpp +++ b/core/include/cubos/core/ecs/reflection.hpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace cubos::core::ecs @@ -88,7 +89,7 @@ namespace cubos::core::ecs /// @param pointer Field pointer. /// @return Builder. template - TypeBuilder&& withField(std::string name, F T::*pointer) && + TypeBuilder&& withField(std::string name, F T::* pointer) && { mFields.addField(std::move(name), pointer); return std::move(*this); @@ -102,6 +103,19 @@ namespace cubos::core::ecs return mType; } + /// @brief Creates a type with a single field. + /// @tparam F Field type. + /// @param pointer Field pointer. + /// @return Type. + template + reflection::Type& wrap(F T::* pointer) && + { + CUBOS_ASSERT(mFields.size() == 0); + mType.with(reflection::WrapperTrait(pointer)); + CUBOS_ERROR("We wrapping"); + return mType; + } + private: reflection::Type& mType; reflection::FieldsTrait mFields; diff --git a/core/include/cubos/core/reflection/traits/wrapper.hpp b/core/include/cubos/core/reflection/traits/wrapper.hpp new file mode 100644 index 0000000000..563a7f9e3e --- /dev/null +++ b/core/include/cubos/core/reflection/traits/wrapper.hpp @@ -0,0 +1,64 @@ +/// @file +/// @brief Class @ref cubos::core::reflection::WrapperTrait. +/// @ingroup core-reflection + +#pragma once + +#include +#include + +#include +#include +#include +#include + +namespace cubos::core::reflection +{ + /// @brief Describes the single field of a reflected type. + /// @ingroup core-reflection + class CUBOS_CORE_API WrapperTrait + { + public: + CUBOS_REFLECT; + + ~WrapperTrait() + { + delete mAddressOf; + }; + + /// @brief Constructs. + WrapperTrait(WrapperTrait&& other) + : mType(other.mType) + , mAddressOf(other.mAddressOf) + { + other.mAddressOf = nullptr; + } + + /// @brief Constructs. + template + WrapperTrait(F O::* pointer) + : mType(reflect()) + , mAddressOf(new FieldsTrait::AddressOfImpl(pointer)) + { + } + + /// @brief Gets the type of the single field. + /// @return Type. + const Type& type() const + { + return mType; + } + + /// @brief Gets a pointer to the field on a given instance of the reflected type. + /// @param instance Pointer to the instance. + /// @return Pointer to the field on the given instance. + void* value(const void* instance) const + { + return reinterpret_cast(this->mAddressOf->get(instance)); + } + + private: + const Type& mType; + const FieldsTrait::AddressOf* mAddressOf; + }; +} // namespace cubos::core::reflection \ No newline at end of file diff --git a/core/src/data/des/binary.cpp b/core/src/data/des/binary.cpp index cd377f0074..574973ad2e 100644 --- a/core/src/data/des/binary.cpp +++ b/core/src/data/des/binary.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,7 @@ using cubos::core::reflection::FieldsTrait; using cubos::core::reflection::MaskTrait; using cubos::core::reflection::StringConversionTrait; using cubos::core::reflection::Type; +using cubos::core::reflection::WrapperTrait; // NOLINTBEGIN(bugprone-macro-parentheses) #define AUTO_HOOK(casted, type) \ @@ -193,6 +195,15 @@ bool BinaryDeserializer::decompose(const Type& type, void* value) } } } + else if (type.has()) + { + const auto& trait = type.get(); + CUBOS_ERROR("Try"); + if (!this->read(trait.type(), trait.value(value))) { + CUBOS_ERROR("Could not deserialize wrapper of type {}", trait.type().name()); + return false; + } + } else if (type.has()) { const auto& trait = type.get(); diff --git a/core/src/data/des/json.cpp b/core/src/data/des/json.cpp index c5e66d3e90..6ab2e83e70 100644 --- a/core/src/data/des/json.cpp +++ b/core/src/data/des/json.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,7 @@ using cubos::core::reflection::FieldsTrait; using cubos::core::reflection::NullableTrait; using cubos::core::reflection::StringConversionTrait; using cubos::core::reflection::Type; +using cubos::core::reflection::WrapperTrait; // NOLINTBEGIN(bugprone-macro-parentheses) #define AUTO_HOOK(T, fromString) \ @@ -120,6 +122,12 @@ bool JSONDeserializer::decompose(const Type& type, void* value) return true; } + if (type.has()) + { + const auto& wrapper = type.get(); + return this->read(wrapper.type(), wrapper.value(value)); + } + if (type.has() && mIterator->is_null()) { const auto& trait = type.get(); @@ -242,18 +250,6 @@ bool JSONDeserializer::decompose(const Type& type, void* value) const auto& trait = type.get(); auto view = trait.view(value); - if (trait.size() == 1) - { - // If there's a single field, read it directly. - if (!this->read(trait.begin()->type(), view.begin()->value)) - { - CUBOS_WARN("Couldn't deserialize wrapped field {}", trait.begin()->name()); - return false; - } - - return true; - } - if (!mIterator->is_object()) { CUBOS_WARN("Expected an object of type {}, found a {}", type.name(), mIterator->type_name()); diff --git a/core/src/data/ser/binary.cpp b/core/src/data/ser/binary.cpp index 73ef60aa84..d681345d50 100644 --- a/core/src/data/ser/binary.cpp +++ b/core/src/data/ser/binary.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,7 @@ using cubos::core::reflection::FieldsTrait; using cubos::core::reflection::MaskTrait; using cubos::core::reflection::StringConversionTrait; using cubos::core::reflection::Type; +using cubos::core::reflection::WrapperTrait; #define AUTO_HOOK(casted, type) \ this->hook([this](const type& value) { \ @@ -151,6 +153,16 @@ bool BinarySerializer::decompose(const Type& type, const void* value) } } } + else if (type.has()) + { + const auto& trait = type.get(); + CUBOS_ERROR("Try"); + if (!this->write(trait.type(), trait.value(value))) + { + CUBOS_ERROR("Could not serialize wrapper of type {}", trait.type().name()); + return false; + } + } else if (type.has()) { const auto& trait = type.get(); diff --git a/core/src/data/ser/debug.cpp b/core/src/data/ser/debug.cpp index baa2d75d6c..ff63ce6b3e 100644 --- a/core/src/data/ser/debug.cpp +++ b/core/src/data/ser/debug.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -16,6 +17,7 @@ using cubos::core::reflection::EnumTrait; using cubos::core::reflection::FieldsTrait; using cubos::core::reflection::StringConversionTrait; using cubos::core::reflection::Type; +using cubos::core::reflection::WrapperTrait; #define AUTO_HOOK(type, ...) \ this->hook([this](const type& value) { \ @@ -169,6 +171,15 @@ bool DebugSerializer::decompose(const Type& type, const void* value) this->separate(true); mStream.put(')'); } + else if (type.has()) + { + const auto& trait = type.get(); + if (!this->write(trait.type(), trait.value(value))) + { + CUBOS_ERROR("Could not serialize wrapper of type {}", trait.type().name()); + return false; + } + } else if (type.has()) { const auto& trait = type.get(); diff --git a/core/src/data/ser/json.cpp b/core/src/data/ser/json.cpp index 92538b1969..74c46e09c2 100644 --- a/core/src/data/ser/json.cpp +++ b/core/src/data/ser/json.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,7 @@ using cubos::core::reflection::NullableTrait; using cubos::core::reflection::reflect; using cubos::core::reflection::StringConversionTrait; using cubos::core::reflection::Type; +using cubos::core::reflection::WrapperTrait; // Macro used to reduce code duplication for primitive type hooks. #define AUTO_HOOK(type, ...) \ @@ -65,6 +67,12 @@ nlohmann::json JSONSerializer::output() bool JSONSerializer::decompose(const Type& type, const void* value) { + if (type.has()) + { + const auto& wrapper = type.get(); + return this->write(wrapper.type(), wrapper.value(value)); + } + if (type.has()) { const auto& trait = type.get(); @@ -112,21 +120,11 @@ bool JSONSerializer::decompose(const Type& type, const void* value) if (type.has()) { - if (type.get().size() == 1) - { - // If there's a single field, write it directly. - if (!this->write(type.get().begin()->type(), - type.get().view(value).begin()->value)) - { - CUBOS_WARN("Couldn't serialize wrapped field {}", type.get().begin()->name()); - return false; - } - - return true; - } + const auto& trait = type.get(); + auto view = trait.view(value); auto jsonObj = nlohmann::json::object(); - for (const auto& [field, fieldValue] : type.get().view(value)) + for (const auto& [field, fieldValue] : view) { if (!this->write(field->type(), fieldValue)) { diff --git a/core/src/data/ser/serializer.cpp b/core/src/data/ser/serializer.cpp index 3b87091821..5596007257 100644 --- a/core/src/data/ser/serializer.cpp +++ b/core/src/data/ser/serializer.cpp @@ -17,6 +17,7 @@ bool Serializer::write(const reflection::Type& type, const void* value) } else if (!this->decompose(type, value)) { + CUBOS_WARN("Serialization decomposition for type {} failed", type.name()); return false; } diff --git a/core/src/reflection/traits/wrapper.cpp b/core/src/reflection/traits/wrapper.cpp new file mode 100644 index 0000000000..b1627c4140 --- /dev/null +++ b/core/src/reflection/traits/wrapper.cpp @@ -0,0 +1,11 @@ +#include +#include +#include +#include + +using namespace cubos::core::reflection; + +CUBOS_REFLECT_IMPL(WrapperTrait) +{ + return Type::create("cubos::core::ecs::WrapperTrait"); +} From 3fee7d4f2ffd25c11db8610ce62ca642d62f3c49 Mon Sep 17 00:00:00 2001 From: SrGesus <108523575+SrGesus@users.noreply.github.com> Date: Thu, 30 Jan 2025 12:47:35 +0000 Subject: [PATCH 2/2] chore: Change chosen single field types to wrappers --- core/src/ecs/cubos.cpp | 4 ++-- core/src/geom/box.cpp | 4 ++-- .../games/cubosurfers/assets/scenes/main.cubos | 4 +++- engine/samples/render/main/assets/main.cubos | 8 ++++++-- engine/samples/render/shadows/assets/main.cubos | 4 +++- engine/src/assets/asset.cpp | 5 +++-- engine/src/collisions/interface/contact_manifold.cpp | 4 +--- engine/src/collisions/interface/shapes/box.cpp | 3 +-- engine/src/collisions/interface/shapes/capsule.cpp | 3 +-- engine/src/collisions/interface/shapes/voxel.cpp | 3 +-- engine/src/input/action.cpp | 6 +++--- engine/src/physics/fixed_substep/substeps.cpp | 2 +- engine/src/physics/plugin.cpp | 12 +++--------- engine/src/render/voxels/palette.cpp | 3 +-- engine/src/tools/selection/selection.cpp | 4 +--- engine/src/transform/local_to_parent.cpp | 5 +---- engine/src/transform/local_to_world.cpp | 5 +---- engine/src/transform/position.cpp | 2 +- engine/src/transform/rotation.cpp | 2 +- engine/src/transform/scale.cpp | 2 +- 20 files changed, 37 insertions(+), 48 deletions(-) diff --git a/core/src/ecs/cubos.cpp b/core/src/ecs/cubos.cpp index 08fd574528..419aa4cb5e 100644 --- a/core/src/ecs/cubos.cpp +++ b/core/src/ecs/cubos.cpp @@ -38,12 +38,12 @@ CUBOS_REFLECT_IMPL(DeltaTime) CUBOS_REFLECT_IMPL(ShouldQuit) { - return TypeBuilder("cubos::core::ecs::ShouldQuit").withField("value", &ShouldQuit::value).build(); + return TypeBuilder("cubos::core::ecs::ShouldQuit").wrap(&ShouldQuit::value); } CUBOS_REFLECT_IMPL(Arguments) { - return TypeBuilder("cubos::core::ecs::Arguments").withField("value", &Arguments::value).build(); + return TypeBuilder("cubos::core::ecs::Arguments").wrap(&Arguments::value); } struct Cubos::State diff --git a/core/src/geom/box.cpp b/core/src/geom/box.cpp index 11d049540e..7ca1c1f539 100644 --- a/core/src/geom/box.cpp +++ b/core/src/geom/box.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include CUBOS_REFLECT_IMPL(cubos::core::geom::Box) @@ -10,5 +10,5 @@ CUBOS_REFLECT_IMPL(cubos::core::geom::Box) return Type::create("cubos::core::geom::Box") .with(ConstructibleTrait::typed().withBasicConstructors().build()) - .with(FieldsTrait().withField("halfSize", &Box::halfSize)); + .with(WrapperTrait(&Box::halfSize)); } diff --git a/engine/samples/games/cubosurfers/assets/scenes/main.cubos b/engine/samples/games/cubosurfers/assets/scenes/main.cubos index d3e6f462bb..6a3b8ecfd7 100644 --- a/engine/samples/games/cubosurfers/assets/scenes/main.cubos +++ b/engine/samples/games/cubosurfers/assets/scenes/main.cubos @@ -91,7 +91,9 @@ } }, "camera": { - "cubos::engine::PerspectiveCamera": 60.0, + "cubos::engine::PerspectiveCamera": { + "fovY": 60.0 + }, "cubos::engine::DrawsTo@render-target": {}, "cubos::engine::Position": { "x": 0, diff --git a/engine/samples/render/main/assets/main.cubos b/engine/samples/render/main/assets/main.cubos index c6325a40a6..b81263215f 100644 --- a/engine/samples/render/main/assets/main.cubos +++ b/engine/samples/render/main/assets/main.cubos @@ -4,7 +4,9 @@ "cubos::engine::RenderTargetDefaults": {} }, "camera": { - "cubos::engine::PerspectiveCamera": 60.0, + "cubos::engine::PerspectiveCamera": { + "fovY": 60.0 + }, "cubos::engine::DrawsTo@render-target": {}, "cubos::engine::Position": { "x": 0, @@ -13,7 +15,9 @@ } }, "camera2": { - "cubos::engine::PerspectiveCamera": 60.0, + "cubos::engine::PerspectiveCamera": { + "fovY": 60.0 + }, "cubos::engine::DrawsTo@render-target": {}, "cubos::engine::Position": { "x": 3, diff --git a/engine/samples/render/shadows/assets/main.cubos b/engine/samples/render/shadows/assets/main.cubos index 24446ba872..57bf83ab1c 100644 --- a/engine/samples/render/shadows/assets/main.cubos +++ b/engine/samples/render/shadows/assets/main.cubos @@ -4,7 +4,9 @@ "cubos::engine::RenderTargetDefaults": {} }, "camera": { - "cubos::engine::PerspectiveCamera": 60.0, + "cubos::engine::PerspectiveCamera": { + "fovY": 60.0 + }, "cubos::engine::DrawsTo@render-target": {}, "cubos::engine::Position": { "x": 0, diff --git a/engine/src/assets/asset.cpp b/engine/src/assets/asset.cpp index 73cfce0cd4..9b715d8244 100644 --- a/engine/src/assets/asset.cpp +++ b/engine/src/assets/asset.cpp @@ -1,8 +1,9 @@ +#include #include #include #include #include -#include +#include #include #include @@ -158,7 +159,7 @@ cubos::core::reflection::Type& AnyAsset::makeType(std::string name) return Type::create(std::move(name)) .with(ConstructibleTrait::typed().withBasicConstructors().build()) - .with(FieldsTrait().withField("id", &AnyAsset::pathOrId)); + .with(WrapperTrait(&AnyAsset::pathOrId)); } void AnyAsset::incRef() const diff --git a/engine/src/collisions/interface/contact_manifold.cpp b/engine/src/collisions/interface/contact_manifold.cpp index 48b785f8d7..9aa185f11f 100644 --- a/engine/src/collisions/interface/contact_manifold.cpp +++ b/engine/src/collisions/interface/contact_manifold.cpp @@ -7,9 +7,7 @@ CUBOS_REFLECT_IMPL(cubos::engine::ContactFeatureId) { - return core::ecs::TypeBuilder("cubos::engine::ContactFeatureId") - .withField("id", &ContactFeatureId::id) - .build(); + return core::ecs::TypeBuilder("cubos::engine::ContactFeatureId").wrap(&ContactFeatureId::id); } CUBOS_REFLECT_IMPL(cubos::engine::ContactPointData) diff --git a/engine/src/collisions/interface/shapes/box.cpp b/engine/src/collisions/interface/shapes/box.cpp index c02ddb7cee..4d5feb9f94 100644 --- a/engine/src/collisions/interface/shapes/box.cpp +++ b/engine/src/collisions/interface/shapes/box.cpp @@ -6,6 +6,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::BoxCollisionShape) { return core::ecs::TypeBuilder("cubos::engine::BoxCollisionShape") - .withField("box", &BoxCollisionShape::box) - .build(); + .wrap(&BoxCollisionShape::box); } diff --git a/engine/src/collisions/interface/shapes/capsule.cpp b/engine/src/collisions/interface/shapes/capsule.cpp index b6ad4c663b..8d96c968db 100644 --- a/engine/src/collisions/interface/shapes/capsule.cpp +++ b/engine/src/collisions/interface/shapes/capsule.cpp @@ -5,6 +5,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::CapsuleCollisionShape) { return core::ecs::TypeBuilder("cubos::engine::CapsuleCollisionShape") - .withField("capsule", &CapsuleCollisionShape::capsule) - .build(); + .wrap(&CapsuleCollisionShape::capsule); } diff --git a/engine/src/collisions/interface/shapes/voxel.cpp b/engine/src/collisions/interface/shapes/voxel.cpp index 0d97379917..823f54f373 100644 --- a/engine/src/collisions/interface/shapes/voxel.cpp +++ b/engine/src/collisions/interface/shapes/voxel.cpp @@ -5,6 +5,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::VoxelCollisionShape) { return core::ecs::TypeBuilder("cubos::engine::VoxelCollisionShape") - .withField("grid", &VoxelCollisionShape::grid) - .build(); + .wrap(&VoxelCollisionShape::grid); } diff --git a/engine/src/input/action.cpp b/engine/src/input/action.cpp index 7440f41b2a..678cb3460a 100644 --- a/engine/src/input/action.cpp +++ b/engine/src/input/action.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,9 +9,8 @@ using namespace cubos::engine; CUBOS_REFLECT_IMPL(cubos::engine::InputAction) { - using namespace cubos::core::reflection; - return Type::create("cubos::engine::InputAction") - .with(FieldsTrait{}.withField("combinations", &InputAction::mCombinations)); + return cubos::core::ecs::TypeBuilder("cubos::engine::InputAction") + .wrap(&InputAction::mCombinations); } const std::vector& InputAction::combinations() const diff --git a/engine/src/physics/fixed_substep/substeps.cpp b/engine/src/physics/fixed_substep/substeps.cpp index aa05bb153f..876a3025fa 100644 --- a/engine/src/physics/fixed_substep/substeps.cpp +++ b/engine/src/physics/fixed_substep/substeps.cpp @@ -5,5 +5,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::Substeps) { - return core::ecs::TypeBuilder("cubos::engine::Substeps").withField("value", &Substeps::value).build(); + return core::ecs::TypeBuilder("cubos::engine::Substeps").wrap(&Substeps::value); } diff --git a/engine/src/physics/plugin.cpp b/engine/src/physics/plugin.cpp index d7d055346d..3380fc9ca0 100644 --- a/engine/src/physics/plugin.cpp +++ b/engine/src/physics/plugin.cpp @@ -33,9 +33,7 @@ CUBOS_REFLECT_IMPL(Mass) CUBOS_REFLECT_IMPL(CenterOfMass) { - return cubos::core::ecs::TypeBuilder("cubos::engine::CenterOfMass") - .withField("vec", &CenterOfMass::vec) - .build(); + return cubos::core::ecs::TypeBuilder("cubos::engine::CenterOfMass").wrap(&CenterOfMass::vec); } CUBOS_REFLECT_IMPL(Inertia) @@ -49,16 +47,12 @@ CUBOS_REFLECT_IMPL(Inertia) CUBOS_REFLECT_IMPL(Velocity) { - return cubos::core::ecs::TypeBuilder("cubos::engine::Velocity") - .withField("velocity", &Velocity::vec) - .build(); + return cubos::core::ecs::TypeBuilder("cubos::engine::Velocity").wrap(&Velocity::vec); } CUBOS_REFLECT_IMPL(AngularVelocity) { - return cubos::core::ecs::TypeBuilder("cubos::engine::AngularVelocity") - .withField("vec", &AngularVelocity::vec) - .build(); + return cubos::core::ecs::TypeBuilder("cubos::engine::AngularVelocity").wrap(&AngularVelocity::vec); } CUBOS_REFLECT_IMPL(Force) diff --git a/engine/src/render/voxels/palette.cpp b/engine/src/render/voxels/palette.cpp index 21c6899fe7..4062a33625 100644 --- a/engine/src/render/voxels/palette.cpp +++ b/engine/src/render/voxels/palette.cpp @@ -5,6 +5,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::RenderPalette) { return core::ecs::TypeBuilder("cubos::engine::RenderPalette") - .withField("asset", &RenderPalette::asset) - .build(); + .wrap(&RenderPalette::asset); } diff --git a/engine/src/tools/selection/selection.cpp b/engine/src/tools/selection/selection.cpp index 3214cf5684..97db24f9e5 100644 --- a/engine/src/tools/selection/selection.cpp +++ b/engine/src/tools/selection/selection.cpp @@ -4,7 +4,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::Selection) { - return cubos::core::ecs::TypeBuilder("cubos::engine::::Selection") - .withField("entity", &Selection::entity) - .build(); + return cubos::core::ecs::TypeBuilder("cubos::engine::::Selection").wrap(&Selection::entity); } diff --git a/engine/src/transform/local_to_parent.cpp b/engine/src/transform/local_to_parent.cpp index 3cb2fd3309..09802dc9bf 100644 --- a/engine/src/transform/local_to_parent.cpp +++ b/engine/src/transform/local_to_parent.cpp @@ -5,8 +5,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::LocalToParent) { - return core::ecs::TypeBuilder("cubos::engine::LocalToParent") - .ephemeral() - .withField("mat", &LocalToParent::mat) - .build(); + return core::ecs::TypeBuilder("cubos::engine::LocalToParent").ephemeral().wrap(&LocalToParent::mat); } diff --git a/engine/src/transform/local_to_world.cpp b/engine/src/transform/local_to_world.cpp index a050e03166..7fbbc81659 100644 --- a/engine/src/transform/local_to_world.cpp +++ b/engine/src/transform/local_to_world.cpp @@ -7,10 +7,7 @@ CUBOS_REFLECT_IMPL(cubos::engine::LocalToWorld) { - return core::ecs::TypeBuilder("cubos::engine::LocalToWorld") - .ephemeral() - .withField("mat", &LocalToWorld::mat) - .build(); + return core::ecs::TypeBuilder("cubos::engine::LocalToWorld").ephemeral().wrap(&LocalToWorld::mat); } glm::mat4 cubos::engine::LocalToWorld::inverse() const diff --git a/engine/src/transform/position.cpp b/engine/src/transform/position.cpp index ae1458a855..efe25fef3e 100644 --- a/engine/src/transform/position.cpp +++ b/engine/src/transform/position.cpp @@ -5,5 +5,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::Position) { - return core::ecs::TypeBuilder("cubos::engine::Position").withField("vec", &Position::vec).build(); + return core::ecs::TypeBuilder("cubos::engine::Position").wrap(&Position::vec); } diff --git a/engine/src/transform/rotation.cpp b/engine/src/transform/rotation.cpp index 751283d5fd..4fe4cda063 100644 --- a/engine/src/transform/rotation.cpp +++ b/engine/src/transform/rotation.cpp @@ -5,7 +5,7 @@ CUBOS_REFLECT_IMPL(cubos::engine::Rotation) { - return core::ecs::TypeBuilder("cubos::engine::Rotation").withField("quat", &Rotation::quat).build(); + return core::ecs::TypeBuilder("cubos::engine::Rotation").wrap(&Rotation::quat); } auto cubos::engine::Rotation::lookingAt(glm::vec3 direction, glm::vec3 up) -> Rotation diff --git a/engine/src/transform/scale.cpp b/engine/src/transform/scale.cpp index 0481cc763a..7f977ac8b2 100644 --- a/engine/src/transform/scale.cpp +++ b/engine/src/transform/scale.cpp @@ -5,5 +5,5 @@ CUBOS_REFLECT_IMPL(cubos::engine::Scale) { - return core::ecs::TypeBuilder("cubos::engine::Scale").withField("mat", &Scale::factor).build(); + return core::ecs::TypeBuilder("cubos::engine::Scale").wrap(&Scale::factor); }