Skip to content

Commit

Permalink
feat(collisions): implement reflection for components
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Oct 8, 2023
1 parent 425d370 commit 255c8d5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ set(CUBOS_ENGINE_SOURCE
"src/cubos/engine/voxels/palette.cpp"

"src/cubos/engine/collisions/plugin.cpp"
"src/cubos/engine/collisions/collider.cpp"
"src/cubos/engine/collisions/shapes/box.cpp"
"src/cubos/engine/collisions/shapes/capsule.cpp"
"src/cubos/engine/collisions/broad_phase/plugin.cpp"
"src/cubos/engine/collisions/broad_phase/sweep_and_prune.cpp"
"src/cubos/engine/collisions/broad_phase/candidates.cpp"
Expand Down
3 changes: 3 additions & 0 deletions engine/include/cubos/engine/collisions/collider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
#include <glm/mat4x4.hpp>

#include <cubos/core/geom/aabb.hpp>
#include <cubos/core/reflection/reflect.hpp>

namespace cubos::engine
{
/// @brief Component which adds a collider to an entity.
/// @ingroup collisions-plugin
struct [[cubos::component("cubos/collider", VecStorage)]] Collider
{
CUBOS_REFLECT;

glm::mat4 transform{1.0F}; ///< Transform of the collider.

core::geom::AABB localAABB{}; ///< Local space AABB of the collider.
Expand Down
3 changes: 3 additions & 0 deletions engine/include/cubos/engine/collisions/shapes/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
#pragma once

#include <cubos/core/geom/box.hpp>
#include <cubos/core/reflection/reflect.hpp>

namespace cubos::engine
{
/// @brief Component which adds a box collision shape to an entity, used with a @ref Collider component.
/// @ingroup collisions-plugin
struct [[cubos::component("cubos/box_collision_shape", VecStorage)]] BoxCollisionShape
{
CUBOS_REFLECT;

cubos::core::geom::Box box; ///< Box shape.
};
} // namespace cubos::engine
3 changes: 3 additions & 0 deletions engine/include/cubos/engine/collisions/shapes/capsule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
#pragma once

#include <cubos/core/geom/capsule.hpp>
#include <cubos/core/reflection/reflect.hpp>

namespace cubos::engine
{
/// @brief Component which adds a capsule collision shape to an entity, used with a @ref Collider component.
/// @ingroup collisions-plugin
struct [[cubos::component("cubos/capsule_collision_shape", VecStorage)]] CapsuleCollisionShape
{
CUBOS_REFLECT;

cubos::core::geom::Capsule capsule; ///< Capsule shape.
};
} // namespace cubos::engine
11 changes: 11 additions & 0 deletions engine/src/cubos/engine/collisions/collider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <cubos/core/ecs/component/reflection.hpp>
#include <cubos/core/reflection/external/glm.hpp>

#include <cubos/engine/collisions/collider.hpp>

CUBOS_REFLECT_IMPL(cubos::engine::Collider)
{
return core::ecs::ComponentTypeBuilder<Collider>("cubos::engine::Collider")
.withField("transform", &Collider::transform)
.build();
}
10 changes: 10 additions & 0 deletions engine/src/cubos/engine/collisions/shapes/box.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <cubos/core/ecs/component/reflection.hpp>

#include <cubos/engine/collisions/shapes/box.hpp>

CUBOS_REFLECT_IMPL(cubos::engine::BoxCollisionShape)
{
return core::ecs::ComponentTypeBuilder<BoxCollisionShape>("cubos::engine::BoxCollisionShape")
.withField("box", &BoxCollisionShape::box)
.build();
}
10 changes: 10 additions & 0 deletions engine/src/cubos/engine/collisions/shapes/capsule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <cubos/core/ecs/component/reflection.hpp>

#include <cubos/engine/collisions/shapes/capsule.hpp>

CUBOS_REFLECT_IMPL(cubos::engine::CapsuleCollisionShape)
{
return core::ecs::ComponentTypeBuilder<CapsuleCollisionShape>("cubos::engine::CapsuleCollisionShape")
.withField("capsule", &CapsuleCollisionShape::capsule)
.build();
}

0 comments on commit 255c8d5

Please sign in to comment.