Browse Source

Move components and systems to ecs namespace

master
C. J. Howard 1 year ago
parent
commit
9de00878ac
83 changed files with 817 additions and 566 deletions
  1. +0
    -1
      CMakeLists.txt
  2. +0
    -0
      src/ecs/archetype.hpp
  3. +43
    -43
      src/ecs/commands.cpp
  4. +49
    -0
      src/ecs/commands.hpp
  5. +0
    -0
      src/ecs/components/behavior-component.hpp
  6. +0
    -0
      src/ecs/components/brush-component.hpp
  7. +0
    -0
      src/ecs/components/camera-follow-component.hpp
  8. +0
    -0
      src/ecs/components/cavity-component.hpp
  9. +0
    -0
      src/ecs/components/celestial-body-component.hpp
  10. +2
    -1
      src/ecs/components/chamber-component.hpp
  11. +1
    -2
      src/ecs/components/collision-component.hpp
  12. +5
    -5
      src/ecs/components/copy-rotation-component.hpp
  13. +5
    -5
      src/ecs/components/copy-scale-component.hpp
  14. +5
    -5
      src/ecs/components/copy-transform-component.hpp
  15. +5
    -5
      src/ecs/components/copy-translation-component.hpp
  16. +0
    -0
      src/ecs/components/locomotion-component.hpp
  17. +0
    -0
      src/ecs/components/marker-component.hpp
  18. +0
    -0
      src/ecs/components/model-component.hpp
  19. +2
    -2
      src/ecs/components/nest-component.hpp
  20. +0
    -0
      src/ecs/components/orbit-component.hpp
  21. +3
    -1
      src/ecs/components/parent-component.hpp
  22. +2
    -2
      src/ecs/components/render-component.hpp
  23. +0
    -0
      src/ecs/components/samara-component.hpp
  24. +0
    -0
      src/ecs/components/snap-component.hpp
  25. +0
    -0
      src/ecs/components/terrain-component.hpp
  26. +0
    -0
      src/ecs/components/tool-component.hpp
  27. +0
    -0
      src/ecs/components/trackable-component.hpp
  28. +0
    -0
      src/ecs/components/transform-component.hpp
  29. +29
    -0
      src/ecs/ecs.hpp
  30. +32
    -0
      src/ecs/entity.hpp
  31. +32
    -0
      src/ecs/registry.hpp
  32. +10
    -8
      src/ecs/systems/astronomy-system.cpp
  33. +13
    -8
      src/ecs/systems/astronomy-system.hpp
  34. +7
    -5
      src/ecs/systems/behavior-system.cpp
  35. +8
    -4
      src/ecs/systems/behavior-system.hpp
  36. +8
    -5
      src/ecs/systems/camera-system.cpp
  37. +8
    -4
      src/ecs/systems/camera-system.hpp
  38. +7
    -6
      src/ecs/systems/collision-system.cpp
  39. +13
    -8
      src/ecs/systems/collision-system.hpp
  40. +17
    -15
      src/ecs/systems/constraint-system.cpp
  41. +8
    -4
      src/ecs/systems/constraint-system.hpp
  42. +16
    -12
      src/ecs/systems/control-system.cpp
  43. +16
    -10
      src/ecs/systems/control-system.hpp
  44. +5
    -1
      src/ecs/systems/entity-system.cpp
  45. +10
    -6
      src/ecs/systems/entity-system.hpp
  46. +8
    -6
      src/ecs/systems/locomotion-system.cpp
  47. +7
    -4
      src/ecs/systems/locomotion-system.hpp
  48. +5
    -4
      src/ecs/systems/nest-system.cpp
  49. +11
    -7
      src/ecs/systems/nest-system.hpp
  50. +12
    -10
      src/ecs/systems/painting-system.cpp
  51. +10
    -5
      src/ecs/systems/painting-system.hpp
  52. +10
    -9
      src/ecs/systems/render-system.cpp
  53. +20
    -15
      src/ecs/systems/render-system.hpp
  54. +7
    -5
      src/ecs/systems/samara-system.cpp
  55. +8
    -4
      src/ecs/systems/samara-system.hpp
  56. +12
    -9
      src/ecs/systems/snapping-system.cpp
  57. +8
    -4
      src/ecs/systems/snapping-system.hpp
  58. +8
    -5
      src/ecs/systems/solar-system.cpp
  59. +8
    -4
      src/ecs/systems/solar-system.hpp
  60. +12
    -10
      src/ecs/systems/spatial-system.cpp
  61. +7
    -4
      src/ecs/systems/spatial-system.hpp
  62. +13
    -11
      src/ecs/systems/subterrain-system.cpp
  63. +12
    -7
      src/ecs/systems/subterrain-system.hpp
  64. +10
    -8
      src/ecs/systems/terrain-system.cpp
  65. +12
    -7
      src/ecs/systems/terrain-system.hpp
  66. +14
    -12
      src/ecs/systems/tool-system.cpp
  67. +13
    -8
      src/ecs/systems/tool-system.hpp
  68. +10
    -8
      src/ecs/systems/tracking-system.cpp
  69. +14
    -13
      src/ecs/systems/tracking-system.hpp
  70. +4
    -0
      src/ecs/systems/ui-system.cpp
  71. +7
    -3
      src/ecs/systems/ui-system.hpp
  72. +0
    -0
      src/ecs/systems/updatable-system.cpp
  73. +7
    -3
      src/ecs/systems/updatable-system.hpp
  74. +8
    -6
      src/ecs/systems/vegetation-system.cpp
  75. +12
    -11
      src/ecs/systems/vegetation-system.hpp
  76. +6
    -2
      src/ecs/systems/weather-system.cpp
  77. +8
    -4
      src/ecs/systems/weather-system.hpp
  78. +1
    -1
      src/game/behavior/ebt.cpp
  79. +46
    -46
      src/game/bootloader.cpp
  80. +0
    -44
      src/game/entity-commands.hpp
  81. +58
    -51
      src/game/game-context.hpp
  82. +38
    -38
      src/game/states/play-state.cpp
  83. +10
    -10
      src/resources/entity-archetype-loader.cpp

+ 0
- 1
CMakeLists.txt View File

@ -14,7 +14,6 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies
set(STATIC_LIBS
dr_wav

src/entity/archetype.hpp → src/ecs/archetype.hpp View File


src/game/entity-commands.cpp → src/ecs/commands.cpp View File

@ -17,66 +17,65 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "game/entity-commands.hpp"
#include "game/components/model-component.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/copy-transform-component.hpp"
#include "game/components/snap-component.hpp"
#include "game/components/parent-component.hpp"
#include "ecs/commands.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/copy-transform-component.hpp"
#include "ecs/components/snap-component.hpp"
#include "ecs/components/parent-component.hpp"
#include <limits>
namespace ec {
using namespace ecs;
namespace ecs {
namespace command {
void translate(entt::registry& registry, entt::entity eid, const float3& translation)
void translate(ecs::registry& registry, ecs::entity entity, const float3& translation)
{
if (registry.has<transform_component>(eid))
if (registry.has<transform_component>(entity))
{
transform_component& transform = registry.get<transform_component>(eid);
transform_component& transform = registry.get<transform_component>(entity);
transform.local.translation += translation;
}
}
void move_to(entt::registry& registry, entt::entity eid, const float3& position)
void move_to(ecs::registry& registry, ecs::entity entity, const float3& position)
{
if (registry.has<transform_component>(eid))
if (registry.has<transform_component>(entity))
{
transform_component& transform = registry.get<transform_component>(eid);
transform_component& transform = registry.get<transform_component>(entity);
transform.local.translation = position;
}
}
void warp_to(entt::registry& registry, entt::entity eid, const float3& position)
void warp_to(ecs::registry& registry, ecs::entity entity, const float3& position)
{
if (registry.has<transform_component>(eid))
if (registry.has<transform_component>(entity))
{
transform_component& transform = registry.get<transform_component>(eid);
transform_component& transform = registry.get<transform_component>(entity);
transform.local.translation = position;
transform.warp = true;
}
}
void set_scale(entt::registry& registry, entt::entity eid, const float3& scale)
void set_scale(ecs::registry& registry, ecs::entity entity, const float3& scale)
{
if (registry.has<transform_component>(eid))
if (registry.has<transform_component>(entity))
{
transform_component& transform = registry.get<transform_component>(eid);
transform_component& transform = registry.get<transform_component>(entity);
transform.local.scale = scale;
}
}
void set_transform(entt::registry& registry, entt::entity eid, const math::transform<float>& transform, bool warp)
void set_transform(ecs::registry& registry, ecs::entity entity, const math::transform<float>& transform, bool warp)
{
if (registry.has<transform_component>(eid))
if (registry.has<transform_component>(entity))
{
transform_component& component = registry.get<transform_component>(eid);
transform_component& component = registry.get<transform_component>(entity);
component.local = transform;
component.warp = warp;
}
}
void place(entt::registry& registry, entt::entity eid, const float2& translation)
void place(ecs::registry& registry, ecs::entity entity, const float2& translation)
{
snap_component component;
component.warp = true;
@ -84,60 +83,61 @@ void place(entt::registry& registry, entt::entity eid, const float2& translation
component.autoremove = true;
component.ray.origin = {translation[0], 10000.0f, translation[1]};
component.ray.direction = {0.0f, -1.0f, 0.0f};
registry.assign_or_replace<snap_component>(eid, component);
registry.assign_or_replace<snap_component>(entity, component);
}
void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned int layers)
void assign_render_layers(ecs::registry& registry, ecs::entity entity, unsigned int layers)
{
if (registry.has<model_component>(eid))
if (registry.has<model_component>(entity))
{
model_component model = registry.get<model_component>(eid);
model_component model = registry.get<model_component>(entity);
model.layers = layers;
registry.replace<model_component>(eid, model);
registry.replace<model_component>(entity, model);
// Apply to child layers
registry.view<parent_component>().each(
[&](auto entity, auto& component)
[&](ecs::entity entity, auto& component)
{
if (component.parent == eid)
if (component.parent == entity)
assign_render_layers(registry, entity, layers);
});
}
}
void bind_transform(entt::registry& registry, entt::entity source_eid, entt::entity target_eid)
void bind_transform(ecs::registry& registry, entity source, entity target)
{
copy_transform_component copy_transform = {target_eid};
registry.assign_or_replace<copy_transform_component>(source_eid, copy_transform);
copy_transform_component copy_transform = {target};
registry.assign_or_replace<copy_transform_component>(source, copy_transform);
}
math::transform<float> get_local_transform(entt::registry& registry, entt::entity eid)
math::transform<float> get_local_transform(ecs::registry& registry, ecs::entity entity)
{
if (registry.has<transform_component>(eid))
if (registry.has<transform_component>(entity))
{
const transform_component& component = registry.get<transform_component>(eid);
const transform_component& component = registry.get<transform_component>(entity);
return component.local;
}
return math::identity_transform<float>;
}
math::transform<float> get_world_transform(entt::registry& registry, entt::entity eid)
math::transform<float> get_world_transform(ecs::registry& registry, ecs::entity entity)
{
if (registry.has<transform_component>(eid))
if (registry.has<transform_component>(entity))
{
const transform_component& component = registry.get<transform_component>(eid);
const transform_component& component = registry.get<transform_component>(entity);
return component.world;
}
return math::identity_transform<float>;
}
void parent(entt::registry& registry, entt::entity child, entt::entity parent)
void parent(ecs::registry& registry, entity child, entity parent)
{
parent_component component;
component.parent = parent;
registry.assign_or_replace<parent_component>(child, component);
}
} // namespace ec
} // namespace command
} // namespace ecs

+ 49
- 0
src/ecs/commands.hpp View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_COMMANDS_HPP
#define ANTKEEPER_ECS_COMMANDS_HPP
#include "ecs/entity.hpp"
#include "ecs/registry.hpp"
#include "utility/fundamental-types.hpp"
#include "math/transform-type.hpp"
namespace ecs {
/// Commands which operate on entity components
namespace command {
void translate(ecs::registry& registry, ecs::entity entity, const float3& translation);
void move_to(ecs::registry& registry, ecs::entity entity, const float3& position);
void warp_to(ecs::registry& registry, ecs::entity entity, const float3& position);
void set_scale(ecs::registry& registry, ecs::entity entity, const float3& scale);
void set_transform(ecs::registry& registry, ecs::entity entity, const math::transform<float>& transform, bool warp = false);
void place(ecs::registry& registry, ecs::entity entity, const float2& translation);
void assign_render_layers(ecs::registry& registry, ecs::entity entity, unsigned int layers);
void bind_transform(ecs::registry& registry, entity source_eid, entity target_eid);
math::transform<float> get_local_transform(ecs::registry& registry, ecs::entity entity);
math::transform<float> get_world_transform(ecs::registry& registry, ecs::entity entity);
void parent(ecs::registry& registry, entity child, entity parent);
} // namespace command
} // namespace ecs
#endif // ANTKEEPER_ECS_COMMANDS_HPP

src/game/components/behavior-component.hpp → src/ecs/components/behavior-component.hpp View File


src/game/components/brush-component.hpp → src/ecs/components/brush-component.hpp View File


src/game/components/camera-follow-component.hpp → src/ecs/components/camera-follow-component.hpp View File


src/game/components/cavity-component.hpp → src/ecs/components/cavity-component.hpp View File


src/game/components/celestial-body-component.hpp → src/ecs/components/celestial-body-component.hpp View File


src/game/components/chamber-component.hpp → src/ecs/components/chamber-component.hpp View File

@ -22,12 +22,13 @@
#include <array>
#include <unordered_set>
#include "ecs/entity.hpp"
namespace ecs {
struct chamber_component
{
entt::entity nest;
entity nest;
float depth;
float outer_radius;
float inner_radius;

src/game/components/collision-component.hpp → src/ecs/components/collision-component.hpp View File

@ -21,10 +21,9 @@
#define ANTKEEPER_ECS_COLLISION_COMPONENT_HPP
#include "geometry/aabb.hpp"
#include "geometry/mesh.hpp"
#include "geometry/mesh-accelerator.hpp"
class mesh;
namespace ecs {
struct collision_component

src/game/components/copy-rotation-component.hpp → src/ecs/components/copy-rotation-component.hpp View File

@ -17,18 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_COPY_ROTATION_COMPONENT_HPP
#define ANTKEEPER_COPY_ROTATION_COMPONENT_HPP
#ifndef ANTKEEPER_ECS_COPY_ROTATION_COMPONENT_HPP
#define ANTKEEPER_ECS_COPY_ROTATION_COMPONENT_HPP
#include <entt/entt.hpp>
#include "ecs/entity.hpp"
namespace ecs {
struct copy_rotation_component
{
entt::entity target;
entity target;
};
} // namespace ecs
#endif // ANTKEEPER_COPY_ROTATION_COMPONENT_HPP
#endif // ANTKEEPER_ECS_COPY_ROTATION_COMPONENT_HPP

src/game/components/copy-scale-component.hpp → src/ecs/components/copy-scale-component.hpp View File

@ -17,16 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_COPY_SCALE_COMPONENT_HPP
#define ANTKEEPER_COPY_SCALE_COMPONENT_HPP
#ifndef ANTKEEPER_ECS_COPY_SCALE_COMPONENT_HPP
#define ANTKEEPER_ECS_COPY_SCALE_COMPONENT_HPP
#include <entt/entt.hpp>
#include "ecs/entity.hpp"
namespace ecs {
struct copy_scale_component
{
entt::entity target;
entity target;
bool use_x;
bool use_y;
bool use_z;
@ -34,4 +34,4 @@ struct copy_scale_component
} // namespace ecs
#endif // ANTKEEPER_COPY_SCALE_COMPONENT_HPP
#endif // ANTKEEPER_ECS_COPY_SCALE_COMPONENT_HPP

src/game/components/copy-transform-component.hpp → src/ecs/components/copy-transform-component.hpp View File

@ -17,18 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_COPY_TRANSFORM_COMPONENT_HPP
#define ANTKEEPER_COPY_TRANSFORM_COMPONENT_HPP
#ifndef ANTKEEPER_ECS_COPY_TRANSFORM_COMPONENT_HPP
#define ANTKEEPER_ECS_COPY_TRANSFORM_COMPONENT_HPP
#include <entt/entt.hpp>
#include "ecs/entity.hpp"
namespace ecs {
struct copy_transform_component
{
entt::entity target;
entity target;
};
} // namespace ecs
#endif // ANTKEEPER_COPY_TRANSFORM_COMPONENT_HPP
#endif // ANTKEEPER_ECS_COPY_TRANSFORM_COMPONENT_HPP

src/game/components/copy-translation-component.hpp → src/ecs/components/copy-translation-component.hpp View File

@ -17,16 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_COPY_TRANSLATION_COMPONENT_HPP
#define ANTKEEPER_COPY_TRANSLATION_COMPONENT_HPP
#ifndef ANTKEEPER_ECS_COPY_TRANSLATION_COMPONENT_HPP
#define ANTKEEPER_ECS_COPY_TRANSLATION_COMPONENT_HPP
#include <entt/entt.hpp>
#include "ecs/entity.hpp"
namespace ecs {
struct copy_translation_component
{
entt::entity target;
entity target;
bool use_x;
bool use_y;
bool use_z;
@ -37,4 +37,4 @@ struct copy_translation_component
} // namespace ecs
#endif // ANTKEEPER_COPY_TRANSLATION_COMPONENT_HPP
#endif // ANTKEEPER_ECS_COPY_TRANSLATION_COMPONENT_HPP

src/game/components/locomotion-component.hpp → src/ecs/components/locomotion-component.hpp View File


src/game/components/marker-component.hpp → src/ecs/components/marker-component.hpp View File


src/game/components/model-component.hpp → src/ecs/components/model-component.hpp View File


src/game/components/nest-component.hpp → src/ecs/components/nest-component.hpp View File

@ -21,13 +21,13 @@
#define ANTKEEPER_ECS_NEST_COMPONENT_HPP
#include <vector>
#include <entt/entt.hpp>
#include "ecs/entity.hpp"
namespace ecs {
struct nest_component
{
std::vector<entt::entity> chambers;
std::vector<entity> chambers;
float helix_radius;
float helix_pitch;
float helix_chirality;

src/game/components/orbit-component.hpp → src/ecs/components/orbit-component.hpp View File


src/game/components/parent-component.hpp → src/ecs/components/parent-component.hpp View File

@ -20,11 +20,13 @@
#ifndef ANTKEEPER_ECS_PARENT_COMPONENT_HPP
#define ANTKEEPER_ECS_PARENT_COMPONENT_HPP
#include "ecs/entity.hpp"
namespace ecs {
struct parent_component
{
entt::entity parent;
entity parent;
};
} // namespace ecs

src/game/components/render-component.hpp → src/ecs/components/render-component.hpp View File

@ -20,13 +20,13 @@
#ifndef ANTKEEPER_ECS_RENDER_COMPONENT_HPP
#define ANTKEEPER_ECS_RENDER_COMPONENT_HPP
class scene_object_base;
#include "scene/object.hpp"
namespace ecs {
struct render_component
{
scene_object_base* object;
scene::object_base* object;
unsigned int layers;
};

src/game/components/samara-component.hpp → src/ecs/components/samara-component.hpp View File


src/game/components/snap-component.hpp → src/ecs/components/snap-component.hpp View File


src/game/components/terrain-component.hpp → src/ecs/components/terrain-component.hpp View File


src/game/components/tool-component.hpp → src/ecs/components/tool-component.hpp View File


src/game/components/trackable-component.hpp → src/ecs/components/trackable-component.hpp View File


src/game/components/transform-component.hpp → src/ecs/components/transform-component.hpp View File


+ 29
- 0
src/ecs/ecs.hpp View File

@ -0,0 +1,29 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_HPP
#define ANTKEEPER_ECS_HPP
/// Entity-component-system (ECS)
namespace ecs {}
#include "archetype.hpp"
#include "entity.hpp"
#endif // ANTKEEPER_ECS_HPP

+ 32
- 0
src/ecs/entity.hpp View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_ENTITY_HPP
#define ANTKEEPER_ECS_ENTITY_HPP
#include <entt/entt.hpp>
namespace ecs {
/// Entity ID type
typedef entt::entity entity;
} // namespace ecs
#endif // ANTKEEPER_ECS_ENTITY_HPP

+ 32
- 0
src/ecs/registry.hpp View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_REGISTRY_HPP
#define ANTKEEPER_ECS_REGISTRY_HPP
#include <entt/entt.hpp>
namespace ecs {
/// Component registry type
typedef entt::registry registry;
} // namespace ecs
#endif // ANTKEEPER_ECS_REGISTRY_HPP

src/game/systems/astronomy-system.cpp → src/ecs/systems/astronomy-system.cpp View File

@ -17,18 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "game/systems/astronomy-system.hpp"
#include "ecs/systems/astronomy-system.hpp"
#include "game/astronomy/celestial-coordinates.hpp"
#include "game/astronomy/apparent-size.hpp"
#include "game/components/celestial-body-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/celestial-body-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "renderer/passes/sky-pass.hpp"
using namespace ecs;
namespace ecs {
static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0;
astronomy_system::astronomy_system(entt::registry& registry):
astronomy_system::astronomy_system(ecs::registry& registry):
entity_system(registry),
universal_time(0.0),
days_per_timestep(1.0 / seconds_per_day),
@ -47,7 +47,7 @@ void astronomy_system::update(double t, double dt)
// Update horizontal (topocentric) positions of intrasolar celestial bodies
registry.view<celestial_body_component, transform_component>().each(
[&](auto entity, auto& body, auto& transform)
[&](ecs::entity entity, auto& body, auto& transform)
{
// Transform orbital position from ecliptic space to horizontal space
double3 horizontal = ecliptic_to_horizontal * body.orbital_state.r;
@ -121,12 +121,12 @@ void astronomy_system::set_sky_pass(::sky_pass* pass)
this->sky_pass = pass;
}
void astronomy_system::set_sun(entt::entity entity)
void astronomy_system::set_sun(ecs::entity entity)
{
sun = entity;
}
void astronomy_system::set_moon(entt::entity entity)
void astronomy_system::set_moon(ecs::entity entity)
{
moon = entity;
}
@ -147,3 +147,5 @@ void astronomy_system::update_ecliptic_to_horizontal()
{
ecliptic_to_horizontal = ast::ecliptic_to_horizontal(obliquity, observer_location[1], lst);
}
} // namespace ecs

src/game/systems/astronomy-system.hpp → src/ecs/systems/astronomy-system.hpp View File

@ -17,14 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ASTRONOMY_SYSTEM_HPP
#define ANTKEEPER_ASTRONOMY_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP
#define ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "utility/fundamental-types.hpp"
class sky_pass;
namespace ecs {
/**
* Calculates apparent properties of celestial bodies relative to an observer (magnitude, angular radius, horizontal coordinates) and modifies their model component and/or light component to render them accordingly.
*/
@ -32,7 +35,7 @@ class astronomy_system:
public entity_system
{
public:
astronomy_system(entt::registry& registry);
astronomy_system(ecs::registry& registry);
/**
* Scales then adds the timestep `dt` to the current time, then recalculates the positions of celestial bodies.
@ -81,8 +84,8 @@ public:
void set_sky_pass(::sky_pass* pass);
void set_sun(entt::entity entity);
void set_moon(entt::entity entity);
void set_sun(ecs::entity entity);
void set_moon(ecs::entity entity);
private:
/// Updates the axial rotation angle
@ -105,8 +108,10 @@ private:
double3x3 ecliptic_to_horizontal;
sky_pass* sky_pass;
entt::entity sun;
entt::entity moon;
entity sun;
entity moon;
};
#endif // ANTKEEPER_ASTRONOMY_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP

src/game/systems/behavior-system.cpp → src/ecs/systems/behavior-system.cpp View File

@ -17,12 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "game/systems/behavior-system.hpp"
#include "game/components/behavior-component.hpp"
#include "ecs/systems/behavior-system.hpp"
#include "ecs/components/behavior-component.hpp"
#include "ecs/entity.hpp"
using namespace ecs;
namespace ecs {
behavior_system::behavior_system(entt::registry& registry):
behavior_system::behavior_system(ecs::registry& registry):
entity_system(registry)
{}
@ -32,7 +33,7 @@ void behavior_system::update(double t, double dt)
context.registry = &registry;
registry.view<behavior_component>().each(
[&](auto entity, auto& behavior)
[&](ecs::entity entity, auto& behavior)
{
if (behavior.behavior_tree)
{
@ -42,3 +43,4 @@ void behavior_system::update(double t, double dt)
});
}
} // namespace ecs

src/game/systems/behavior-system.hpp → src/ecs/systems/behavior-system.hpp View File

@ -17,18 +17,22 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_BEHAVIOR_SYSTEM_HPP
#define ANTKEEPER_BEHAVIOR_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_BEHAVIOR_SYSTEM_HPP
#define ANTKEEPER_ECS_BEHAVIOR_SYSTEM_HPP
#include "entity-system.hpp"
namespace ecs {
class behavior_system:
public entity_system
{
public:
behavior_system(entt::registry& registry);
behavior_system(ecs::registry& registry);
virtual void update(double t, double dt);
};
#endif // ANTKEEPER_BEHAVIOR_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_BEHAVIOR_SYSTEM_HPP

src/game/systems/camera-system.cpp → src/ecs/systems/camera-system.cpp View File

@ -18,15 +18,16 @@
*/
#include "camera-system.hpp"
#include "game/components/camera-follow-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/camera-follow-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/entity.hpp"
#include "math/math.hpp"
#include <algorithm>
#include <cmath>
using namespace ecs;
namespace ecs {
camera_system::camera_system(entt::registry& registry):
camera_system::camera_system(ecs::registry& registry):
entity_system(registry),
camera(nullptr),
viewport{0, 0, 0, 0},
@ -61,7 +62,7 @@ void camera_system::update(double t, double dt)
int subject_count = 0;
float3 target_focal_point = {0, 0, 0};
registry.view<camera_follow_component, transform_component>().each(
[&](auto entity, auto& follow, auto& transform)
[&](ecs::entity entity, auto& follow, auto& transform)
{
target_focal_point += transform.local.translation;
++subject_count;
@ -123,3 +124,5 @@ void camera_system::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}
} // namespace ecs

src/game/systems/camera-system.hpp → src/ecs/systems/camera-system.hpp View File

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CAMERA_SYSTEM_HPP
#define ANTKEEPER_CAMERA_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_CAMERA_SYSTEM_HPP
#define ANTKEEPER_ECS_CAMERA_SYSTEM_HPP
#include "entity-system.hpp"
#include "event/event-handler.hpp"
@ -32,6 +32,8 @@
class orbit_cam;
namespace ecs {
class camera_system:
public entity_system,
public event_handler<mouse_moved_event>,
@ -41,7 +43,7 @@ public:
typedef math::quaternion<float> quaternion_type;
typedef math::transform<float> transform_type;
camera_system(entt::registry& registry);
camera_system(ecs::registry& registry);
virtual void update(double t, double dt);
void pan(float angle);
@ -75,5 +77,7 @@ inline orbit_cam* camera_system::get_orbit_cam()
return &orbit_cam;
}
#endif // ANTKEEPER_CAMERA_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_CAMERA_SYSTEM_HPP

src/game/systems/collision-system.cpp → src/ecs/systems/collision-system.cpp View File

@ -18,11 +18,11 @@
*/
#include "collision-system.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/transform-component.hpp"
using namespace ecs;
namespace ecs {
collision_system::collision_system(entt::registry& registry):
collision_system::collision_system(ecs::registry& registry):
entity_system(registry)
{
registry.on_construct<collision_component>().connect<&collision_system::on_collision_construct>(this);
@ -33,12 +33,13 @@ collision_system::collision_system(entt::registry& registry):
void collision_system::update(double t, double dt)
{}
void collision_system::on_collision_construct(entt::registry& registry, entt::entity entity, collision_component& collision)
void collision_system::on_collision_construct(ecs::registry& registry, ecs::entity entity, collision_component& collision)
{}
void collision_system::on_collision_replace(entt::registry& registry, entt::entity entity, collision_component& collision)
void collision_system::on_collision_replace(ecs::registry& registry, ecs::entity entity, collision_component& collision)
{}
void collision_system::on_collision_destroy(entt::registry& registry, entt::entity entity)
void collision_system::on_collision_destroy(ecs::registry& registry, ecs::entity entity)
{}
} // namespace ecs

src/game/systems/collision-system.hpp → src/ecs/systems/collision-system.hpp View File

@ -17,11 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_COLLISION_SYSTEM_HPP
#define ANTKEEPER_COLLISION_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_COLLISION_SYSTEM_HPP
#define ANTKEEPER_ECS_COLLISION_SYSTEM_HPP
#include "entity-system.hpp"
#include "game/components/collision-component.hpp"
#include "ecs/entity.hpp"
#include "ecs/components/collision-component.hpp"
namespace ecs {
/**
* Maintains a spatially partitioned set of collision meshes. The set of collision meshes isnot owned by the collision system, so it can be accessed by other systems as well.
@ -29,14 +32,16 @@
class collision_system: public entity_system
{
public:
collision_system(entt::registry& registry);
collision_system(ecs::registry& registry);
virtual void update(double t, double dt);
private:
void on_collision_construct(entt::registry& registry, entt::entity entity, ecs::collision_component& collision);
void on_collision_replace(entt::registry& registry, entt::entity entity, ecs::collision_component& collision);
void on_collision_destroy(entt::registry& registry, entt::entity entity);
void on_collision_construct(ecs::registry& registry, ecs::entity entity, ecs::collision_component& collision);
void on_collision_replace(ecs::registry& registry, ecs::entity entity, ecs::collision_component& collision);
void on_collision_destroy(ecs::registry& registry, ecs::entity entity);
};
#endif // ANTKEEPER_COLLISION_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_COLLISION_SYSTEM_HPP

src/game/systems/constraint-system.cpp → src/ecs/systems/constraint-system.cpp View File

@ -18,16 +18,16 @@
*/
#include "constraint-system.hpp"
#include "game/components/copy-translation-component.hpp"
#include "game/components/copy-rotation-component.hpp"
#include "game/components/copy-scale-component.hpp"
#include "game/components/copy-transform-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/copy-translation-component.hpp"
#include "ecs/components/copy-rotation-component.hpp"
#include "ecs/components/copy-scale-component.hpp"
#include "ecs/components/copy-transform-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "utility/fundamental-types.hpp"
using namespace ecs;
namespace ecs {
constraint_system::constraint_system(entt::registry& registry):
constraint_system::constraint_system(ecs::registry& registry):
entity_system(registry)
{}
@ -38,9 +38,9 @@ void constraint_system::update(double t, double dt)
// Handle copy translation constraints
registry.view<copy_translation_component, transform_component>().each
(
[&](auto entity, auto& constraint, auto& transform)
[&](ecs::entity entity, auto& constraint, auto& transform)
{
if (registry.has<transform_component>(constraint.target))
if (this->registry.has<transform_component>(constraint.target))
{
const float3& target_translation = transforms_view.get(constraint.target).world.translation;
if (constraint.use_x)
@ -56,9 +56,9 @@ void constraint_system::update(double t, double dt)
// Handle copy rotation constraints
registry.view<copy_rotation_component, transform_component>().each
(
[&](auto entity, auto& constraint, auto& transform)
[&](ecs::entity entity, auto& constraint, auto& transform)
{
if (registry.has<transform_component>(constraint.target))
if (this->registry.has<transform_component>(constraint.target))
{
transform.world.rotation = transforms_view.get(constraint.target).world.rotation;
}
@ -68,9 +68,9 @@ void constraint_system::update(double t, double dt)
// Handle copy scale constraints
registry.view<copy_scale_component, transform_component>().each
(
[&](auto entity, auto& constraint, auto& transform)
[&](ecs::entity entity, auto& constraint, auto& transform)
{
if (registry.has<transform_component>(constraint.target))
if (this->registry.has<transform_component>(constraint.target))
{
const float3& target_scale = transforms_view.get(constraint.target).world.scale;
if (constraint.use_x)
@ -86,12 +86,14 @@ void constraint_system::update(double t, double dt)
// Handle copy transform constraints
registry.view<copy_transform_component, transform_component>().each
(
[&](auto entity, auto& constraint, auto& transform)
[&](ecs::entity entity, auto& constraint, auto& transform)
{
if (registry.has<transform_component>(constraint.target))
if (this->registry.has<transform_component>(constraint.target))
{
transform.world = transforms_view.get(constraint.target).world;
}
}
);
}
} // namespace ecs

src/game/systems/constraint-system.hpp → src/ecs/systems/constraint-system.hpp View File

@ -17,17 +17,21 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CONSTRAINT_SYSTEM_HPP
#define ANTKEEPER_CONSTRAINT_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_CONSTRAINT_SYSTEM_HPP
#define ANTKEEPER_ECS_CONSTRAINT_SYSTEM_HPP
#include "entity-system.hpp"
namespace ecs {
class constraint_system:
public entity_system
{
public:
constraint_system(entt::registry& registry);
constraint_system(ecs::registry& registry);
virtual void update(double t, double dt);
};
#endif // ANTKEEPER_CONSTRAINT_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_CONSTRAINT_SYSTEM_HPP

src/game/systems/control-system.cpp → src/ecs/systems/control-system.cpp View File

@ -23,16 +23,18 @@
#include "animation/ease.hpp"
#include "nest.hpp"
#include "math/math.hpp"
#include "game/entity-commands.hpp"
#include "game/systems/camera-system.hpp"
#include "ecs/commands.hpp"
#include "ecs/systems/camera-system.hpp"
#include "animation/orbit-cam.hpp"
control_system::control_system(entt::registry& registry):
namespace ecs {
control_system::control_system(ecs::registry& registry):
entity_system(registry),
timestep(0.0f),
zoom(0.0f),
tool(nullptr),
flashlight_eid(entt::null),
flashlight_entity(entt::null),
underworld_camera(nullptr)
{
control_set.add_control(&move_forward_control);
@ -133,7 +135,7 @@ void control_system::update(double t, double dt)
const math::quaternion<float>& azimuth_rotation = camera_system->get_orbit_cam()->get_azimuth_rotation();
movement = azimuth_rotation * movement;
ec::translate(registry, camera_subject_eid, movement);
command::translate(registry, camera_subject_entity, movement);
}
// Turn flashlight
@ -152,7 +154,7 @@ void control_system::update(double t, double dt)
flashlight_turns_f = (mouse_angle) / math::two_pi<float>;
flashlight_turns = flashlight_turns_i - flashlight_turns_f;
if (flashlight_eid != entt::null && nest)
if (flashlight_entity != entt::null && nest)
{
math::transform<float> flashlight_transform = math::identity_transform<float>;
@ -161,7 +163,7 @@ void control_system::update(double t, double dt)
flashlight_transform.translation = {0.0f, -flashlight_depth, 0.0f};
flashlight_transform.rotation = math::angle_axis(-flashlight_turns * math::two_pi<float> + math::half_pi<float>, {0, 1, 0});
ec::set_transform(registry, flashlight_eid, flashlight_transform, false);
command::set_transform(registry, flashlight_entity, flashlight_transform, false);
if (underworld_camera)
{
@ -171,7 +173,7 @@ void control_system::update(double t, double dt)
}
}
void control_system::set_camera_system(::camera_system* camera_system)
void control_system::set_camera_system(ecs::camera_system* camera_system)
{
this->camera_system = camera_system;
}
@ -186,14 +188,14 @@ void control_system::set_tool(scene::model_instance* tool)
this->tool = tool;
}
void control_system::set_flashlight(entt::entity eid)
void control_system::set_flashlight(ecs::entity entity)
{
flashlight_eid = eid;
flashlight_entity = entity;
}
void control_system::set_camera_subject(entt::entity eid)
void control_system::set_camera_subject(ecs::entity entity)
{
camera_subject_eid = eid;
camera_subject_entity = entity;
}
void control_system::set_viewport(const float4& viewport)
@ -243,3 +245,5 @@ void control_system::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}
} // namespace ecs

src/game/systems/control-system.hpp → src/ecs/systems/control-system.hpp View File

@ -17,10 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CONTROL_SYSTEM_HPP
#define ANTKEEPER_CONTROL_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_CONTROL_SYSTEM_HPP
#define ANTKEEPER_ECS_CONTROL_SYSTEM_HPP
#include "game/systems/entity-system.hpp"
#include "ecs/systems/entity-system.hpp"
#include "ecs/entity.hpp"
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
@ -31,6 +32,9 @@
#include "scene/camera.hpp"
class nest;
namespace ecs {
class camera_system;
class control_system:
@ -39,18 +43,18 @@ class control_system:
public event_handler<window_resized_event>
{
public:
control_system(entt::registry& registry);
control_system(ecs::registry& registry);
virtual void update(double t, double dt);
void set_invert_mouse_x(bool invert);
void set_invert_mouse_y(bool invert);
void set_camera_system(camera_system* camera_system);
void set_camera_system(ecs::camera_system* camera_system);
void set_nest(::nest* nest);
void set_tool(scene::model_instance* tool);
void set_flashlight(entt::entity eid);
void set_camera_subject(entt::entity eid);
void set_flashlight(ecs::entity entity);
void set_camera_subject(ecs::entity entity);
void set_viewport(const float4& viewport);
void set_underworld_camera(scene::camera* camera);
@ -137,8 +141,8 @@ private:
float2 mouse_position;
float4 viewport;
entt::entity flashlight_eid;
entt::entity camera_subject_eid;
entity flashlight_entity;
entity camera_subject_entity;
scene::camera* underworld_camera;
float mouse_angle;
@ -283,5 +287,7 @@ inline control* control_system::get_rewind_control()
return &rewind_control;
}
#endif // ANTKEEPER_CONTROL_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_CONTROL_SYSTEM_HPP

src/game/systems/entity-system.cpp → src/ecs/systems/entity-system.cpp View File

@ -19,7 +19,11 @@
#include "entity-system.hpp"
entity_system::entity_system(entt::registry& registry):
namespace ecs {
entity_system::entity_system(ecs::registry& registry):
registry(registry)
{}
} // namespace ecs

src/game/systems/entity-system.hpp → src/ecs/systems/entity-system.hpp View File

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ENTITY_SYSTEM_HPP
#define ANTKEEPER_ENTITY_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_ENTITY_SYSTEM_HPP
#define ANTKEEPER_ECS_ENTITY_SYSTEM_HPP
#include "updatable-system.hpp"
#include <entt/entt.hpp>
#include "ecs/registry.hpp"
namespace ecs {
/**
* Abstract base class for updatable systems which operate on entities and entity components.
@ -29,11 +31,13 @@
class entity_system: public updatable_system
{
public:
entity_system(entt::registry& registry);
entity_system(ecs::registry& registry);
protected:
entt::registry& registry;
ecs::registry& registry;
};
#endif // ANTKEEPER_ENTITY_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_ENTITY_SYSTEM_HPP

src/game/systems/locomotion-system.cpp → src/ecs/systems/locomotion-system.cpp View File

@ -18,21 +18,23 @@
*/
#include "locomotion-system.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/locomotion-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/locomotion-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/entity.hpp"
using namespace ecs;
namespace ecs {
locomotion_system::locomotion_system(entt::registry& registry):
locomotion_system::locomotion_system(ecs::registry& registry):
entity_system(registry)
{}
void locomotion_system::update(double t, double dt)
{
registry.view<transform_component, locomotion_component>().each(
[&](auto entity, auto& transform, auto& locomotion)
[&](ecs::entity entity, auto& transform, auto& locomotion)
{
});
}
} // namespace ecs

src/game/systems/locomotion-system.hpp → src/ecs/systems/locomotion-system.hpp View File

@ -17,18 +17,21 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_LOCOMOTION_SYSTEM_HPP
#define ANTKEEPER_LOCOMOTION_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_LOCOMOTION_SYSTEM_HPP
#define ANTKEEPER_ECS_LOCOMOTION_SYSTEM_HPP
#include "entity-system.hpp"
namespace ecs {
class locomotion_system:
public entity_system
{
public:
locomotion_system(entt::registry& registry);
locomotion_system(ecs::registry& registry);
virtual void update(double t, double dt);
};
#endif // ANTKEEPER_LOCOMOTION_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_LOCOMOTION_SYSTEM_HPP

src/game/systems/nest-system.cpp → src/ecs/systems/nest-system.cpp View File

@ -21,9 +21,9 @@
#include "nest.hpp"
#include "math/math.hpp"
using namespace ecs;
namespace ecs {
nest_system::nest_system(entt::registry& registry, ::resource_manager* resource_manager):
nest_system::nest_system(ecs::registry& registry, ::resource_manager* resource_manager):
entity_system(registry),
resource_manager(resource_manager)
{
@ -37,7 +37,7 @@ nest_system::~nest_system()
void nest_system::update(double t, double dt)
{}
void nest_system::on_nest_construct(entt::registry& registry, entt::entity entity, nest_component& component)
void nest_system::on_nest_construct(ecs::registry& registry, ecs::entity entity, nest_component& component)
{
// Allocate a nest
nest* nest = new ::nest();
@ -64,6 +64,7 @@ void nest_system::on_nest_construct(entt::registry& registry, entt::entity entit
}
}
void nest_system::on_nest_destroy(entt::registry& registry, entt::entity entity)
void nest_system::on_nest_destroy(ecs::registry& registry, ecs::entity entity)
{}
} // namespace ecs

src/game/systems/nest-system.hpp → src/ecs/systems/nest-system.hpp View File

@ -17,28 +17,32 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_NEST_SYSTEM_HPP
#define ANTKEEPER_NEST_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_NEST_SYSTEM_HPP
#define ANTKEEPER_ECS_NEST_SYSTEM_HPP
#include "entity-system.hpp"
#include "game/components/nest-component.hpp"
#include "ecs/components/nest-component.hpp"
class nest;
class resource_manager;
namespace ecs {
class nest_system: public entity_system
{
public:
nest_system(entt::registry& registry, ::resource_manager* resource_manager);
nest_system(ecs::registry& registry, ::resource_manager* resource_manager);
~nest_system();
virtual void update(double t, double dt);
private:
resource_manager* resource_manager;
void on_nest_construct(entt::registry& registry, entt::entity entity, ecs::nest_component& component);
void on_nest_destroy(entt::registry& registry, entt::entity entity);
void on_nest_construct(ecs::registry& registry, ecs::entity entity, ecs::nest_component& component);
void on_nest_destroy(ecs::registry& registry, ecs::entity entity);
};
#endif // ANTKEEPER_NEST_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_NEST_SYSTEM_HPP

src/game/systems/painting-system.cpp → src/ecs/systems/painting-system.cpp View File

@ -18,27 +18,27 @@
*/
#include "painting-system.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/brush-component.hpp"
#include "game/components/tool-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/brush-component.hpp"
#include "ecs/components/tool-component.hpp"
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "math/math.hpp"
#include "renderer/material.hpp"
#include "renderer/model.hpp"
#include "utility/fundamental-types.hpp"
#include "game/entity-commands.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/commands.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "rasterizer/vertex-buffer.hpp"
#include "rasterizer/vertex-attribute-type.hpp"
#include "renderer/vertex-attributes.hpp"
#include "geometry/mesh-functions.hpp"
#include <limits>
using namespace ecs;
namespace ecs {
painting_system::painting_system(entt::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
painting_system::painting_system(ecs::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
entity_system(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
@ -295,7 +295,7 @@ void painting_system::handle_event(const tool_released_event& event)
{
if (registry.has<brush_component>(event.entity))
{
auto cast_result = cast_ray(ec::get_world_transform(registry, event.entity).translation);
auto cast_result = cast_ray(command::get_world_transform(registry, event.entity).translation);
if (cast_result.has_value())
{
@ -319,7 +319,7 @@ std::optional> painting_system::cast_ray(const float3
float min_distance = std::numeric_limits<float>::infinity();
registry.view<transform_component, collision_component>().each(
[&](auto entity, auto& collision_transform, auto& collision)
[&](ecs::entity entity, auto& collision_transform, auto& collision)
{
// Transform ray into local space of collision component
math::transform<float> inverse_transform = math::inverse(collision_transform.local);
@ -355,3 +355,5 @@ std::optional> painting_system::cast_ray(const float3
return result;
}
} // namespace ecs

src/game/systems/painting-system.hpp → src/ecs/systems/painting-system.hpp View File

@ -17,10 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_PAINTING_SYSTEM_HPP
#define ANTKEEPER_PAINTING_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_PAINTING_SYSTEM_HPP
#define ANTKEEPER_ECS_PAINTING_SYSTEM_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "event/event-handler.hpp"
#include "game/events/tool-events.hpp"
#include "utility/fundamental-types.hpp"
@ -36,12 +37,14 @@ class model;
class model_group;
class vertex_buffer;
namespace ecs {
class painting_system: public entity_system,
public event_handler<tool_pressed_event>,
public event_handler<tool_released_event>