Browse Source

Move components and systems to ecs namespace

master
C. J. Howard 3 years 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>
{
public:
painting_system(entt::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
painting_system(ecs::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
virtual ~painting_system();
virtual void update(double t, double dt);
@ -58,7 +61,7 @@ private:
scene::collection* scene_collection;
bool painting;
entt::entity brush_entity;
entity brush_entity;
float3 stroke_start;
float3 stroke_end;
float min_stroke_length;
@ -86,4 +89,6 @@ private:
scene::model_instance* stroke_model_instance;
};
#endif // ANTKEEPER_PAINTING_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_PAINTING_SYSTEM_HPP

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

@ -18,12 +18,12 @@
*/
#include "render-system.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "renderer/renderer.hpp"
using namespace ecs;
namespace ecs {
render_system::render_system(entt::registry& registry):
render_system::render_system(ecs::registry& registry):
entity_system(registry),
renderer(nullptr)
{
@ -36,7 +36,7 @@ void render_system::update(double t, double dt)
{
registry.view<transform_component, model_component>().each
(
[this](auto entity, auto& transform, auto& model)
[this](ecs::entity entity, auto& transform, auto& model)
{
scene::model_instance* instance = model_instances[entity];
@ -78,14 +78,14 @@ void render_system::set_renderer(::renderer* renderer)
this->renderer = renderer;
}
scene::model_instance* render_system::get_model_instance(entt::entity entity)
scene::model_instance* render_system::get_model_instance(ecs::entity entity)
{
if (auto it = model_instances.find(entity); it != model_instances.end())
return it->second;
return nullptr;
}
void render_system::update_model_and_materials(entt::entity entity, model_component& model)
void render_system::update_model_and_materials(ecs::entity entity, model_component& model)
{
if (auto model_it = model_instances.find(entity); model_it != model_instances.end())
{
@ -110,19 +110,19 @@ void render_system::update_model_and_materials(entt::entity entity, model_compon
}
}
void render_system::on_model_construct(entt::registry& registry, entt::entity entity, model_component& model)
void render_system::on_model_construct(ecs::registry& registry, ecs::entity entity, model_component& model)
{
scene::model_instance* model_instance = new scene::model_instance();
model_instances[entity] = model_instance;
update_model_and_materials(entity, model);
}
void render_system::on_model_replace(entt::registry& registry, entt::entity entity, model_component& model)
void render_system::on_model_replace(ecs::registry& registry, ecs::entity entity, model_component& model)
{
update_model_and_materials(entity, model);
}
void render_system::on_model_destroy(entt::registry& registry, entt::entity entity)
void render_system::on_model_destroy(ecs::registry& registry, ecs::entity entity)
{
if (auto it = model_instances.find(entity); it != model_instances.end())
{
@ -137,3 +137,4 @@ void render_system::on_model_destroy(entt::registry& registry, entt::entity enti
}
}
} // namespace ecs

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

@ -17,23 +17,26 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_RENDER_SYSTEM_HPP
#define ANTKEEPER_RENDER_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_RENDER_SYSTEM_HPP
#define ANTKEEPER_ECS_RENDER_SYSTEM_HPP
#include "entity-system.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "game/components/model-component.hpp"
#include "game/components/render-component.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/render-component.hpp"
#include "ecs/entity.hpp"
#include <unordered_map>
#include <vector>
class renderer;
namespace ecs {
class render_system: public entity_system
{
public:
render_system(entt::registry& registry);
render_system(ecs::registry& registry);
virtual void update(double t, double dt);
void render(double alpha);
@ -44,23 +47,25 @@ public:
void set_renderer(::renderer* renderer);
scene::model_instance* get_model_instance(entt::entity entity);
scene::model_instance* get_model_instance(ecs::entity entity);
private:
void update_model_and_materials(entt::entity entity, ecs::model_component& model);
void update_model_and_materials(ecs::entity entity, ecs::model_component& model);
void on_model_construct(entt::registry& registry, entt::entity entity, ecs::model_component& model);
void on_model_replace(entt::registry& registry, entt::entity entity, ecs::model_component& model);
void on_model_destroy(entt::registry& registry, entt::entity entity);
void on_model_construct(ecs::registry& registry, ecs::entity entity, ecs::model_component& model);
void on_model_replace(ecs::registry& registry, ecs::entity entity, ecs::model_component& model);
void on_model_destroy(ecs::registry& registry, ecs::entity entity);
void on_component_construct(entt::registry& registry, entt::entity entity, ecs::render_component& component);
void on_component_replace(entt::registry& registry, entt::entity entity, ecs::render_component& component);
void on_component_destroy(entt::registry& registry, entt::entity entity);
void on_component_construct(ecs::registry& registry, ecs::entity entity, ecs::render_component& component);
void on_component_replace(ecs::registry& registry, ecs::entity entity, ecs::render_component& component);
void on_component_destroy(ecs::registry& registry, ecs::entity entity);
renderer* renderer;
std::vector<scene::collection*> layers;
std::unordered_map<entt::entity, scene::model_instance*> model_instances;
std::unordered_map<entity, scene::model_instance*> model_instances;
};
#endif // ANTKEEPER_RENDER_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_RENDER_SYSTEM_HPP

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

@ -18,21 +18,22 @@
*/
#include "samara-system.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/samara-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/samara-component.hpp"
#include "ecs/entity.hpp"
#include "math/math.hpp"
#include "utility/fundamental-types.hpp"
using namespace ecs;
namespace ecs {
samara_system::samara_system(entt::registry& registry):
samara_system::samara_system(ecs::registry& registry):
entity_system(registry)
{}
void samara_system::update(double t, double dt)
{
registry.view<samara_component, transform_component>().each(
[&](auto entity, auto& samara, auto& transform)
[&](ecs::entity entity, auto& samara, auto& transform)
{
samara.angle += samara.chirality * math::radians(360.0f * 6.0f) * dt;
@ -55,3 +56,4 @@ void samara_system::update(double t, double dt)
});
}
} // namespace ecs

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

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

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

@ -18,21 +18,22 @@
*/
#include "snapping-system.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/snap-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/snap-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/entity.hpp"
#include "utility/fundamental-types.hpp"
using namespace ecs;
namespace ecs {
snapping_system::snapping_system(entt::registry& registry):
snapping_system::snapping_system(ecs::registry& registry):
entity_system(registry)
{}
void snapping_system::update(double t, double dt)
{
registry.view<transform_component, snap_component>().each(
[&](auto entity, auto& snap_transform, auto& snap)
[&](ecs::entity entity, auto& snap_transform, auto& snap)
{
bool intersection = false;
float a = std::numeric_limits<float>::infinity();
@ -45,8 +46,8 @@ void snapping_system::update(double t, double dt)
snap_ray.direction = snap_transform.local.rotation * snap_ray.direction;
}
registry.view<transform_component, collision_component>().each(
[&](auto entity, auto& collision_transform, auto& collision)
this->registry.view<transform_component, collision_component>().each(
[&](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);
@ -81,8 +82,10 @@ void snapping_system::update(double t, double dt)
if (snap.autoremove)
{
registry.remove<snap_component>(entity);
this->registry.remove<snap_component>(entity);
}
}
});
}
} // namespace ecs

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

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

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

@ -17,17 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "game/systems/solar-system.hpp"
#include "ecs/systems/solar-system.hpp"
#include "game/astronomy/celestial-coordinates.hpp"
#include "game/astronomy/celestial-mechanics.hpp"
#include "game/astronomy/astronomical-constants.hpp"
#include "game/components/celestial-body-component.hpp"
#include "ecs/components/celestial-body-component.hpp"
#include "ecs/entity.hpp"
using namespace ecs;
namespace ecs {
static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0;
solar_system::solar_system(entt::registry& registry):
solar_system::solar_system(ecs::registry& registry):
entity_system(registry),
universal_time(0.0),
days_per_timestep(1.0 / seconds_per_day),
@ -42,7 +43,7 @@ void solar_system::update(double t, double dt)
// Update orbital state of intrasolar celestial bodies
registry.view<celestial_body_component>().each(
[&](auto entity, auto& body)
[&](ecs::entity entity, auto& body)
{
ast::orbital_elements elements = body.orbital_elements;
elements.a += body.orbital_rate.a * universal_time;
@ -66,3 +67,5 @@ void solar_system::set_time_scale(double scale)
{
days_per_timestep = scale / seconds_per_day;
}
} // namespace ecs

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

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SOLAR_SYSTEM_HPP
#define ANTKEEPER_SOLAR_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_SOLAR_SYSTEM_HPP
#define ANTKEEPER_ECS_SOLAR_SYSTEM_HPP
#include "entity-system.hpp"
#include "utility/fundamental-types.hpp"
namespace ecs {
/**
* Updates positions, velocities, and rotations of intrasolar celestial bodies.
*/
@ -30,7 +32,7 @@ class solar_system:
public entity_system
{
public:
solar_system(entt::registry& registry);
solar_system(ecs::registry& registry);
/**
* Scales then adds the timestep `dt` to the current time, then recalculates the positions of celestial bodies.
@ -61,4 +63,6 @@ private:
std::size_t ke_iterations;
};
#endif // ANTKEEPER_SOLAR_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_SOLAR_SYSTEM_HPP

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

@ -18,12 +18,12 @@
*/
#include "spatial-system.hpp"
#include "game/components/parent-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/parent-component.hpp"
#include "ecs/components/transform-component.hpp"
using namespace ecs;
namespace ecs {
spatial_system::spatial_system(entt::registry& registry):
spatial_system::spatial_system(ecs::registry& registry):
entity_system(registry)
{}
@ -33,9 +33,9 @@ void spatial_system::update(double t, double dt)
// Process parent transforms first
registry.view<transform_component>().each(
[&](auto entity, auto& transform)
[&](ecs::entity entity, auto& transform)
{
if (!registry.has<parent_component>(entity))
if (!this->registry.has<parent_component>(entity))
{
transform.world = transform.local;
}
@ -43,14 +43,16 @@ void spatial_system::update(double t, double dt)
// Process child transforms second
registry.view<transform_component>().each(
[&](auto entity, auto& transform)
[&](ecs::entity entity, auto& transform)
{
if (registry.has<parent_component>(entity))
if (this->registry.has<parent_component>(entity))
{
entt::entity parent = registry.get<parent_component>(entity).parent;
const transform_component& parent_transform = registry.get<transform_component>(parent);
ecs::entity parent = this->registry.get<parent_component>(entity).parent;
const transform_component& parent_transform = this->registry.get<transform_component>(parent);
transform.world = parent_transform.world * transform.local;
transform.warp = parent_transform.warp;
}
});
}
} // namespace ecs

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

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

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

@ -18,8 +18,9 @@
*/
#include "subterrain-system.hpp"
#include "game/components/model-component.hpp"
#include "game/components/cavity-component.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/cavity-component.hpp"
#include "ecs/entity.hpp"
#include "renderer/model.hpp"
#include "renderer/material.hpp"
#include "geometry/mesh-functions.hpp"
@ -34,7 +35,7 @@
#include <array>
#include <limits>
using namespace ecs;
namespace ecs {
/**
* An octree containing cubes for the marching cubes algorithm.
@ -187,7 +188,7 @@ void cube_tree::subdivide()
}
}
subterrain_system::subterrain_system(entt::registry& registry, ::resource_manager* resource_manager):
subterrain_system::subterrain_system(ecs::registry& registry, ::resource_manager* resource_manager):
entity_system(registry),
resource_manager(resource_manager)
{
@ -243,7 +244,7 @@ subterrain_system::subterrain_system(entt::registry& registry, ::resource_manage
subterrain_model->set_bounds(subterrain_bounds);
// Allocate cube tree
cube_tree = new ::cube_tree(subterrain_bounds, octree_depth);
cube_tree = new ecs::cube_tree(subterrain_bounds, octree_depth);
// Allocate mesh
subterrain_mesh = new mesh();
@ -272,10 +273,10 @@ void subterrain_system::update(double t, double dt)
bool digging = false;
registry.view<cavity_component>().each(
[this, &digging](auto entity, auto& cavity)
[this, &digging](ecs::entity entity, auto& cavity)
{
this->dig(cavity.position, cavity.radius);
registry.destroy(entity);
this->registry.destroy(entity);
digging = true;
});
@ -320,11 +321,11 @@ void subterrain_system::regenerate_subterrain_mesh()
//std::cout << "creating mesh... done\n";
}
void subterrain_system::march(::cube_tree* node)
void subterrain_system::march(ecs::cube_tree* node)
{
if (!node->is_leaf())
{
for (::cube_tree* child: node->children)
for (ecs::cube_tree* child: node->children)
march(child);
return;
}
@ -463,9 +464,9 @@ void subterrain_system::dig(const float3& position, float radius)
cube_tree->subdivide_max(region);
// Query all octree leaf nodes within the region
std::list<::cube_tree*> nodes;
std::list<ecs::cube_tree*> nodes;
cube_tree->visit_leaves(region,
[&position, radius](::cube_tree& node)
[&position, radius](ecs::cube_tree& node)
{
for (int i = 0; i < 8; ++i)
{
@ -480,3 +481,4 @@ void subterrain_system::dig(const float3& position, float radius)
});
}
} // namespace ecs

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

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SUBTERRAIN_SYSTEM_HPP
#define ANTKEEPER_SUBTERRAIN_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_SUBTERRAIN_SYSTEM_HPP
#define ANTKEEPER_ECS_SUBTERRAIN_SYSTEM_HPP
#include "entity-system.hpp"
#include "geometry/mesh.hpp"
@ -32,6 +32,9 @@ class resource_manager;
class model;
class model_group;
class material;
namespace ecs {
struct cube_tree;
template <std::int64_t Mantissa, std::int64_t Exponent>
@ -85,7 +88,7 @@ struct vector_equals
class subterrain_system: public entity_system
{
public:
subterrain_system(entt::registry& registry, ::resource_manager* resource_manager);
subterrain_system(ecs::registry& registry, ::resource_manager* resource_manager);
~subterrain_system();
virtual void update(double t, double dt);
@ -93,10 +96,10 @@ public:
private:
void regenerate_subterrain_mesh();
void march(::cube_tree* node);
void march(ecs::cube_tree* node);
void regenerate_subterrain_model();
void dig(const float3&position, float radius);
float distance(const ::cube_tree& node, const float3& sample) const;
float distance(const ecs::cube_tree& node, const float3& sample) const;
resource_manager* resource_manager;
mesh* subterrain_mesh;
@ -108,7 +111,7 @@ private:
int subterrain_model_vertex_size;
int subterrain_model_vertex_stride;
aabb<float> subterrain_bounds;
::cube_tree* cube_tree;
ecs::cube_tree* cube_tree;
std::vector<float3> subterrain_vertices;
std::vector<std::array<std::uint_fast32_t, 3>> subterrain_triangles;
float isosurface_resolution;
@ -125,5 +128,7 @@ private:
scene::model_instance* subterrain_model_instance;
};
#endif // ANTKEEPER_SUBTERRAIN_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_SUBTERRAIN_SYSTEM_HPP

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

@ -18,9 +18,9 @@
*/
#include "terrain-system.hpp"
#include "game/components/model-component.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "game/cartography/relief-map.hpp"
#include "renderer/model.hpp"
#include "geometry/mesh.hpp"
@ -34,9 +34,9 @@
#include "utility/fundamental-types.hpp"
#include <limits>
using namespace ecs;
namespace ecs {
terrain_system::terrain_system(entt::registry& registry, ::resource_manager* resource_manager):
terrain_system::terrain_system(ecs::registry& registry, ::resource_manager* resource_manager):
entity_system(registry),
resource_manager(resource_manager)
{
@ -54,7 +54,7 @@ terrain_system::~terrain_system()
void terrain_system::update(double t, double dt)
{
registry.view<terrain_component, transform_component>().each(
[this](auto entity, auto& terrain, auto& transform)
[this](ecs::entity entity, auto& terrain, auto& transform)
{
transform.local.translation = float3{(float)terrain.x * patch_size, 0.0f, (float)terrain.z * patch_size};
transform.warp = true;
@ -256,7 +256,7 @@ void terrain_system::update_terrain_model(model* terrain_model, mesh* terrain_me
delete[] vertex_data;
}
void terrain_system::on_terrain_construct(entt::registry& registry, entt::entity entity, terrain_component& component)
void terrain_system::on_terrain_construct(ecs::registry& registry, ecs::entity entity, terrain_component& component)
{
mesh* terrain_mesh = generate_terrain_mesh(patch_size, component.subdivisions);
model* terrain_model = generate_terrain_model(terrain_mesh);
@ -285,7 +285,7 @@ void terrain_system::on_terrain_construct(entt::registry& registry, entt::entity
registry.assign_or_replace<transform_component>(entity, transform);
}
void terrain_system::on_terrain_destroy(entt::registry& registry, entt::entity entity)
void terrain_system::on_terrain_destroy(ecs::registry& registry, ecs::entity entity)
{
/*
if (auto it = terrain_map.find(entity); it != terrain_map.end())
@ -296,3 +296,5 @@ void terrain_system::on_terrain_destroy(entt::registry& registry, entt::entity e
}
*/
}
} // namespace ecs

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

@ -17,11 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_TERRAIN_SYSTEM_HPP
#define ANTKEEPER_TERRAIN_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_TERRAIN_SYSTEM_HPP
#define ANTKEEPER_ECS_TERRAIN_SYSTEM_HPP
#include "entity-system.hpp"
#include "game/components/terrain-component.hpp"
#include "ecs/components/terrain-component.hpp"
#include "ecs/entity.hpp"
class terrain;
class resource_manager;
@ -29,10 +30,12 @@ class mesh;
class model;
class image;
namespace ecs {
class terrain_system: public entity_system
{
public:
terrain_system(entt::registry& registry, ::resource_manager* resource_manager);
terrain_system(ecs::registry& registry, ::resource_manager* resource_manager);
~terrain_system();
virtual void update(double t, double dt);
@ -47,8 +50,8 @@ private:
void project_terrain_mesh(mesh* terrain_mesh, const ecs::terrain_component& component);
void update_terrain_model(model* terrain_model, mesh* terrain_mesh);
void on_terrain_construct(entt::registry& registry, entt::entity entity, ecs::terrain_component& component);
void on_terrain_destroy(entt::registry& registry, entt::entity entity);
void on_terrain_construct(ecs::registry& registry, ecs::entity entity, ecs::terrain_component& component);
void on_terrain_destroy(ecs::registry& registry, ecs::entity entity);
resource_manager* resource_manager;
float patch_size;
@ -57,5 +60,7 @@ private:
image* heightmap;
};
#endif // ANTKEEPER_TERRAIN_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_TERRAIN_SYSTEM_HPP

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

@ -18,9 +18,9 @@
*/
#include "tool-system.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/tool-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/tool-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "event/event-dispatcher.hpp"
#include "game/events/tool-events.hpp"
#include "animation/orbit-cam.hpp"
@ -28,11 +28,11 @@
#include "geometry/mesh.hpp"
#include "geometry/intersection.hpp"
#include "math/math.hpp"
#include "game/entity-commands.hpp"
#include "ecs/commands.hpp"
using namespace ecs;
namespace ecs {
tool_system::tool_system(entt::registry& registry, ::event_dispatcher* event_dispatcher):
tool_system::tool_system(ecs::registry& registry, ::event_dispatcher* event_dispatcher):
entity_system(registry),
event_dispatcher(event_dispatcher),
camera(nullptr),
@ -116,7 +116,7 @@ void tool_system::update(double t, double dt)
// Cast ray from cursor to collision components to find closest intersection
registry.view<transform_component, collision_component>().each(
[&](auto entity, auto& transform, auto& collision)
[&](ecs::entity entity, auto& transform, auto& collision)
{
math::transform<float> inverse_transform = math::inverse(transform.local);
float3 origin = inverse_transform * pick_origin;
@ -171,7 +171,7 @@ void tool_system::update(double t, double dt)
// Move active tools to intersection location
registry.view<tool_component, transform_component>().each(
[&](auto entity, auto& tool, auto& transform)
[&](ecs::entity entity, auto& tool, auto& transform)
{
/*
if (registry.has<model_component>(entity))
@ -208,7 +208,7 @@ void tool_system::update(double t, double dt)
if (warp)
{
transform.warp = true;
ec::assign_render_layers(registry, active_tool, 1);
command::assign_render_layers(registry, active_tool, 1);
warp = false;
}
@ -249,7 +249,7 @@ void tool_system::set_sun_direction(const float3& direction)
sun_direction = direction;
}
void tool_system::set_active_tool(entt::entity entity)
void tool_system::set_active_tool(ecs::entity entity)
{
if (active_tool == entity)
return;
@ -261,7 +261,7 @@ void tool_system::set_active_tool(entt::entity entity)
{
auto& tool = registry.get<tool_component>(active_tool);
tool.active = false;
ec::assign_render_layers(registry, active_tool, 0);
command::assign_render_layers(registry, active_tool, 0);
}
active_tool = entity;
@ -273,7 +273,7 @@ void tool_system::set_active_tool(entt::entity entity)
active_tool_distance = tool.idle_distance;
ec::warp_to(registry, active_tool, pick_spring.x0 + float3{0.0f, tool.idle_distance, 0.0f});
command::warp_to(registry, active_tool, pick_spring.x0 + float3{0.0f, tool.idle_distance, 0.0f});
// Adjust descend and ascend animations
animation_channel<float>* channel = descend_animation.get_channel(0);
@ -331,3 +331,5 @@ void tool_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/tool-system.hpp → src/ecs/systems/tool-system.hpp View File

@ -17,10 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_TOOL_SYSTEM_HPP
#define ANTKEEPER_TOOL_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_TOOL_SYSTEM_HPP
#define ANTKEEPER_ECS_TOOL_SYSTEM_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
@ -32,13 +33,15 @@
class orbit_cam;
class event_dispatcher;
namespace ecs {
class tool_system:
public entity_system,
public event_handler<mouse_moved_event>,
public event_handler<window_resized_event>
{
public:
tool_system(entt::registry& registry, event_dispatcher* event_dispatcher);
tool_system(ecs::registry& registry, event_dispatcher* event_dispatcher);
virtual ~tool_system();
virtual void update(double t, double dt);
@ -48,11 +51,11 @@ public:
void set_pick(bool enabled);
void set_sun_direction(const float3& direction);
void set_active_tool(entt::entity entity);
void set_active_tool(ecs::entity entity);
void set_tool_active(bool active);
entt::entity get_active_tool() const;
entity get_active_tool() const;
private:
virtual void handle_event(const mouse_moved_event& event);
@ -66,7 +69,7 @@ private:
bool was_pick_enabled;
bool pick_enabled;
float3 sun_direction;
entt::entity active_tool;
entity active_tool;
bool warp;
bool tool_active;
@ -79,9 +82,11 @@ private:
float active_tool_distance;
};
inline entt::entity tool_system::get_active_tool() const
inline entity tool_system::get_active_tool() const
{
return active_tool;
}
#endif // ANTKEEPER_TOOL_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_TOOL_SYSTEM_HPP

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

@ -18,8 +18,8 @@
*/
#include "tracking-system.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/marker-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/marker-component.hpp"
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "scene/collection.hpp"
@ -28,11 +28,11 @@
#include "renderer/material.hpp"
#include "renderer/model.hpp"
#include "utility/fundamental-types.hpp"
#include "game/entity-commands.hpp"
#include "ecs/commands.hpp"
using namespace ecs;
namespace ecs {
tracking_system::tracking_system(entt::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
tracking_system::tracking_system(ecs::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
entity_system(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
@ -97,12 +97,12 @@ void tracking_system::set_scene(scene::collection* collection)
this->scene_collection = collection;
}
void tracking_system::on_component_construct(entt::registry& registry, entt::entity entity, trackable_component& component)
void tracking_system::on_component_construct(ecs::registry& registry, ecs::entity entity, trackable_component& component)
{
}
void tracking_system::on_component_destroy(entt::registry& registry, entt::entity entity)
void tracking_system::on_component_destroy(ecs::registry& registry, ecs::entity entity)
{
if (auto it = trackers.find(entity); it != trackers.end())
{
@ -123,7 +123,7 @@ void tracking_system::handle_event(const tool_pressed_event& event)
{
if (registry.has<marker_component>(event.entity))
{
math::transform<float> transform = ec::get_world_transform(registry, event.entity);
math::transform<float> transform = command::get_world_transform(registry, event.entity);
int marker_index = registry.get<marker_component>(event.entity).color;
@ -155,3 +155,5 @@ void tracking_system::handle_event(const tool_released_event& event)
{
}
} // namespace ecs

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

@ -17,32 +17,31 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_TRACKING_SYSTEM_HPP
#define ANTKEEPER_TRACKING_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_TRACKING_SYSTEM_HPP
#define ANTKEEPER_ECS_TRACKING_SYSTEM_HPP
#include "entity-system.hpp"
#include "game/components/trackable-component.hpp"
#include "ecs/components/trackable-component.hpp"
#include "ecs/entity.hpp"
#include "event/event-handler.hpp"
#include "game/events/tool-events.hpp"
#include <unordered_map>
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
class material;
class event_dispatcher;
class resource_manager;
class model;
namespace scene
{
class collection;
class model_instance;
}
namespace ecs {
class tracking_system: public entity_system,
public event_handler<tool_pressed_event>,
public event_handler<tool_released_event>
{
public:
tracking_system(entt::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
tracking_system(ecs::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
virtual ~tracking_system();
virtual void update(double t, double dt);
@ -50,8 +49,8 @@ public:
void set_viewport(const float4& viewport);
private:
void on_component_construct(entt::registry& registry, entt::entity entity, ecs::trackable_component& component);
void on_component_destroy(entt::registry& registry, entt::entity entity);
void on_component_construct(ecs::registry& registry, ecs::entity entity, ecs::trackable_component& component);
void on_component_destroy(ecs::registry& registry, ecs::entity entity);
virtual void handle_event(const tool_pressed_event& event);
virtual void handle_event(const tool_released_event& event);
@ -61,7 +60,9 @@ private:
model* tracker_model;
model* paint_ball_model;
material** paint_ball_materials;
std::unordered_map<entt::entity, scene::model_instance*> trackers;
std::unordered_map<entity, scene::model_instance*> trackers;
};
#endif // ANTKEEPER_TRACKING_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_TRACKING_SYSTEM_HPP

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

@ -21,6 +21,8 @@
#include "input/control.hpp"
#include "resources/resource-manager.hpp"
namespace ecs {
ui_system::ui_system(::resource_manager* resource_manager):
resource_manager(resource_manager),
tool_menu_control(nullptr),
@ -193,3 +195,5 @@ void ui_system::close_elevator_menu()
{
}
} // namespace ecs

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

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_UI_SYSTEM_HPP
#define ANTKEEPER_UI_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_UI_SYSTEM_HPP
#define ANTKEEPER_ECS_UI_SYSTEM_HPP
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
@ -35,6 +35,8 @@
class control;
class resource_manager;
namespace ecs {
class ui_system:
public event_handler<mouse_moved_event>,
public event_handler<window_resized_event>
@ -82,4 +84,6 @@ private:
control* tool_menu_control;
};
#endif // ANTKEEPER_UI_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_UI_SYSTEM_HPP

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


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

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_UPDATABLE_SYSTEM_HPP
#define ANTKEEPER_UPDATABLE_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_UPDATABLE_SYSTEM_HPP
#define ANTKEEPER_ECS_UPDATABLE_SYSTEM_HPP
namespace ecs {
/**
* Abstract base class for updatable systems.
@ -36,5 +38,7 @@ public:
virtual void update(double t, double dt) = 0;
};
#endif // ANTKEEPER_UPDATABLE_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_UPDATABLE_SYSTEM_HPP

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

@ -18,8 +18,8 @@
*/
#include "vegetation-system.hpp"
#include "game/components/model-component.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "scene/model-instance.hpp"
#include "scene/lod-group.hpp"
#include "scene/collection.hpp"
@ -28,9 +28,9 @@
#include "utility/fundamental-types.hpp"
#include <cmath>
using namespace ecs;
namespace ecs {
vegetation_system::vegetation_system(entt::registry& registry):
vegetation_system::vegetation_system(ecs::registry& registry):
entity_system(registry),
terrain_patch_size(1.0f),
vegetation_patch_size(1.0f),
@ -78,7 +78,7 @@ void vegetation_system::set_scene(scene::collection* collection)
this->scene_collection = collection;
}
void vegetation_system::on_terrain_construct(entt::registry& registry, entt::entity entity, terrain_component& component)
void vegetation_system::on_terrain_construct(ecs::registry& registry, ecs::entity entity, terrain_component& component)
{
// Find corner of terrain patch
float terrain_patch_min_x = static_cast<float>(component.x) * terrain_patch_size - terrain_patch_size * 0.5f;
@ -171,5 +171,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
}
}
void vegetation_system::on_terrain_destroy(entt::registry& registry, entt::entity entity)
void vegetation_system::on_terrain_destroy(ecs::registry& registry, ecs::entity entity)
{}
} // namespace ecs

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

@ -17,18 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_VEGETATION_SYSTEM_HPP
#define ANTKEEPER_VEGETATION_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_VEGETATION_SYSTEM_HPP
#define ANTKEEPER_ECS_VEGETATION_SYSTEM_HPP
#include "entity-system.hpp"
#include "game/components/terrain-component.hpp"
#include "ecs/components/terrain-component.hpp"
#include "ecs/entity.hpp"
#include "scene/collection.hpp"
class model;
namespace scene
{
class collection;
}
namespace ecs {
/**
* Places vegetation patches on terrain.
@ -36,7 +35,7 @@ namespace scene
class vegetation_system: public entity_system
{
public:
vegetation_system(entt::registry& registry);
vegetation_system(ecs::registry& registry);
~vegetation_system();
virtual void update(double t, double dt);
@ -61,8 +60,8 @@ public:
void set_scene(scene::collection* collection);
private:
void on_terrain_construct(entt::registry& registry, entt::entity entity, ecs::terrain_component& component);
void on_terrain_destroy(entt::registry& registry, entt::entity entity);
void on_terrain_construct(ecs::registry& registry, ecs::entity entity, ecs::terrain_component& component);
void on_terrain_destroy(ecs::registry& registry, ecs::entity entity);
float terrain_patch_size;
float vegetation_patch_size;
@ -73,5 +72,7 @@ private:
scene::collection* scene_collection;
};
#endif // ANTKEEPER_VEGETATION_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_VEGETATION_SYSTEM_HPP

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

@ -17,7 +17,7 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "game/systems/weather-system.hpp"
#include "ecs/systems/weather-system.hpp"
#include "scene/directional-light.hpp"
#include "scene/ambient-light.hpp"
#include "renderer/passes/sky-pass.hpp"
@ -29,9 +29,11 @@
#include "game/astronomy/celestial-mechanics.hpp"
#include <cmath>
namespace ecs {
static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0;
weather_system::weather_system(entt::registry& registry):
weather_system::weather_system(ecs::registry& registry):
entity_system(registry),
sky_pass(nullptr),
shadow_map_pass(nullptr),
@ -71,3 +73,5 @@ void weather_system::set_time_scale(double scale)
{
days_per_timestep = scale / seconds_per_day;
}
} // namespace ecs

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

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_WEATHER_SYSTEM_HPP
#define ANTKEEPER_WEATHER_SYSTEM_HPP
#ifndef ANTKEEPER_ECS_WEATHER_SYSTEM_HPP
#define ANTKEEPER_ECS_WEATHER_SYSTEM_HPP
#include "entity-system.hpp"
#include "utility/fundamental-types.hpp"
@ -30,11 +30,13 @@ class ambient_light;
class directional_light;
class image;
namespace ecs {
class weather_system:
public entity_system
{
public:
weather_system(entt::registry& registry);
weather_system(ecs::registry& registry);
virtual void update(double t, double dt);
/**
@ -74,4 +76,6 @@ private:
material_pass* material_pass;
};
#endif // ANTKEEPER_WEATHER_SYSTEM_HPP
} // namespace ecs
#endif // ANTKEEPER_ECS_WEATHER_SYSTEM_HPP

+ 1
- 1
src/game/behavior/ebt.cpp View File

@ -18,7 +18,7 @@
*/
#include "game/behavior/ebt.hpp"
#include "game/components/transform-component.hpp"
#include "ecs/components/transform-component.hpp"
#include <iostream>
using namespace ecs;

+ 46
- 46
src/game/bootloader.cpp View File

@ -55,29 +55,29 @@
#include "resources/resource-manager.hpp"
#include "scene/scene.hpp"
#include "game/states/game-states.hpp"
#include "game/systems/behavior-system.hpp"
#include "game/systems/camera-system.hpp"
#include "game/systems/collision-system.hpp"
#include "game/systems/constraint-system.hpp"
#include "game/systems/control-system.hpp"
#include "game/systems/locomotion-system.hpp"
#include "game/systems/nest-system.hpp"
#include "game/systems/snapping-system.hpp"
#include "game/systems/render-system.hpp"
#include "game/systems/samara-system.hpp"
#include "game/systems/subterrain-system.hpp"
#include "game/systems/terrain-system.hpp"
#include "game/systems/tool-system.hpp"
#include "game/systems/ui-system.hpp"
#include "game/systems/vegetation-system.hpp"
#include "game/systems/spatial-system.hpp"
#include "game/systems/tracking-system.hpp"
#include "game/systems/painting-system.hpp"
#include "game/systems/weather-system.hpp"
#include "game/systems/astronomy-system.hpp"
#include "game/systems/solar-system.hpp"
#include "game/components/marker-component.hpp"
#include "game/entity-commands.hpp"
#include "ecs/systems/behavior-system.hpp"
#include "ecs/systems/camera-system.hpp"
#include "ecs/systems/collision-system.hpp"
#include "ecs/systems/constraint-system.hpp"
#include "ecs/systems/control-system.hpp"
#include "ecs/systems/locomotion-system.hpp"
#include "ecs/systems/nest-system.hpp"
#include "ecs/systems/snapping-system.hpp"
#include "ecs/systems/render-system.hpp"
#include "ecs/systems/samara-system.hpp"
#include "ecs/systems/subterrain-system.hpp"
#include "ecs/systems/terrain-system.hpp"
#include "ecs/systems/tool-system.hpp"
#include "ecs/systems/ui-system.hpp"
#include "ecs/systems/vegetation-system.hpp"
#include "ecs/systems/spatial-system.hpp"
#include "ecs/systems/tracking-system.hpp"
#include "ecs/systems/painting-system.hpp"
#include "ecs/systems/weather-system.hpp"
#include "ecs/systems/astronomy-system.hpp"
#include "ecs/systems/solar-system.hpp"
#include "ecs/components/marker-component.hpp"
#include "ecs/commands.hpp"
#include "utility/paths.hpp"
#include "event/event-dispatcher.hpp"
#include "input/input-event-router.hpp"
@ -805,11 +805,11 @@ void setup_systems(game_context* ctx)
float4 viewport = {0.0f, 0.0f, static_cast<float>(viewport_dimensions[0]), static_cast<float>(viewport_dimensions[1])};
// Setup terrain system
ctx->terrain_system = new ::terrain_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->terrain_system = new ecs::terrain_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->terrain_system->set_patch_size(TERRAIN_PATCH_SIZE);
// Setup vegetation system
ctx->vegetation_system = new ::vegetation_system(*ctx->ecs_registry);
ctx->vegetation_system = new ecs::vegetation_system(*ctx->ecs_registry);
ctx->vegetation_system->set_terrain_patch_size(TERRAIN_PATCH_SIZE);
ctx->vegetation_system->set_vegetation_patch_resolution(VEGETATION_PATCH_RESOLUTION);
ctx->vegetation_system->set_vegetation_density(1.0f);
@ -817,38 +817,38 @@ void setup_systems(game_context* ctx)
ctx->vegetation_system->set_scene(ctx->overworld_scene);
// Setup camera system
ctx->camera_system = new camera_system(*ctx->ecs_registry);
ctx->camera_system = new ecs::camera_system(*ctx->ecs_registry);
ctx->camera_system->set_viewport(viewport);
event_dispatcher->subscribe<mouse_moved_event>(ctx->camera_system);
event_dispatcher->subscribe<window_resized_event>(ctx->camera_system);
// Setup tool system
ctx->tool_system = new tool_system(*ctx->ecs_registry, event_dispatcher);
ctx->tool_system = new ecs::tool_system(*ctx->ecs_registry, event_dispatcher);
ctx->tool_system->set_camera(ctx->overworld_camera);
ctx->tool_system->set_orbit_cam(ctx->camera_system->get_orbit_cam());
ctx->tool_system->set_viewport(viewport);
// Setup subterrain system
ctx->subterrain_system = new ::subterrain_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->subterrain_system = new ecs::subterrain_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->subterrain_system->set_scene(ctx->underworld_scene);
// Setup nest system
ctx->nest_system = new nest_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->nest_system = new ecs::nest_system(*ctx->ecs_registry, ctx->resource_manager);
// Setup collision system
ctx->collision_system = new collision_system(*ctx->ecs_registry);
ctx->collision_system = new ecs::collision_system(*ctx->ecs_registry);
// Setup samara system
ctx->samara_system = new samara_system(*ctx->ecs_registry);
ctx->samara_system = new ecs::samara_system(*ctx->ecs_registry);
// Setup snapping system
ctx->snapping_system = new snapping_system(*ctx->ecs_registry);
ctx->snapping_system = new ecs::snapping_system(*ctx->ecs_registry);
// Setup behavior system
ctx->behavior_system = new behavior_system(*ctx->ecs_registry);
ctx->behavior_system = new ecs::behavior_system(*ctx->ecs_registry);
// Setup locomotion system
ctx->locomotion_system = new locomotion_system(*ctx->ecs_registry);
ctx->locomotion_system = new ecs::locomotion_system(*ctx->ecs_registry);
// Setup pheromone system
ctx->pheromones = new pheromone_matrix();
@ -861,30 +861,30 @@ void setup_systems(game_context* ctx)
//diffuse(ctx->pheromones);
// Setup spatial system
ctx->spatial_system = new spatial_system(*ctx->ecs_registry);
ctx->spatial_system = new ecs::spatial_system(*ctx->ecs_registry);
// Setup constraint system
ctx->constraint_system = new constraint_system(*ctx->ecs_registry);
ctx->constraint_system = new ecs::constraint_system(*ctx->ecs_registry);
// Setup tracking system
ctx->tracking_system = new tracking_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager);
ctx->tracking_system = new ecs::tracking_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager);
ctx->tracking_system->set_scene(ctx->overworld_scene);
// Setup painting system
ctx->painting_system = new painting_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager);
ctx->painting_system = new ecs::painting_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager);
ctx->painting_system->set_scene(ctx->overworld_scene);
// Setup weather system
ctx->weather_system = new weather_system(*ctx->ecs_registry);
ctx->weather_system = new ecs::weather_system(*ctx->ecs_registry);
ctx->weather_system->set_sky_pass(ctx->overworld_sky_pass);
ctx->weather_system->set_shadow_map_pass(ctx->overworld_shadow_map_pass);
ctx->weather_system->set_material_pass(ctx->overworld_material_pass);
// Setup solar system
ctx->solar_system = new solar_system(*ctx->ecs_registry);
ctx->solar_system = new ecs::solar_system(*ctx->ecs_registry);
// Setup astronomy system
ctx->astronomy_system = new astronomy_system(*ctx->ecs_registry);
ctx->astronomy_system = new ecs::astronomy_system(*ctx->ecs_registry);
ctx->astronomy_system->set_sky_pass(ctx->overworld_sky_pass);
// Set time scale
@ -898,14 +898,14 @@ void setup_systems(game_context* ctx)
ctx->astronomy_system->set_time_scale(time_scale);
// Setup render system
ctx->render_system = new ::render_system(*ctx->ecs_registry);
ctx->render_system = new ecs::render_system(*ctx->ecs_registry);
ctx->render_system->add_layer(ctx->overworld_scene);
ctx->render_system->add_layer(ctx->underworld_scene);
ctx->render_system->add_layer(ctx->ui_scene);
ctx->render_system->set_renderer(ctx->renderer);
// Setup control system
ctx->control_system = new ::control_system(*ctx->ecs_registry);
ctx->control_system = new ecs::control_system(*ctx->ecs_registry);
ctx->control_system->set_viewport(viewport);
ctx->control_system->set_underworld_camera(ctx->underworld_camera);
ctx->control_system->set_tool(nullptr);
@ -919,7 +919,7 @@ void setup_systems(game_context* ctx)
event_dispatcher->subscribe<window_resized_event>(ctx->control_system);
// Setup UI system
ctx->ui_system = new ui_system(ctx->resource_manager);
ctx->ui_system = new ecs::ui_system(ctx->resource_manager);
ctx->ui_system->set_camera(ctx->ui_camera);
ctx->ui_system->set_scene(ctx->ui_scene);
ctx->ui_system->set_viewport(viewport);
@ -1288,10 +1288,10 @@ void setup_callbacks(game_context* ctx)
//(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point();
auto xf = ec::get_world_transform(*ctx->ecs_registry, ctx->lens_entity);
auto xf = ecs::command::get_world_transform(*ctx->ecs_registry, ctx->lens_entity);
ctx->lens_spotlight->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0});
xf = ec::get_world_transform(*ctx->ecs_registry, ctx->flashlight_entity);
xf = ecs::command::get_world_transform(*ctx->ecs_registry, ctx->flashlight_entity);
//ctx->flashlight_spotlight->set_transform(xf);
ctx->flashlight_spotlight->look_at(xf.translation, xf.translation + xf.rotation * float3{0, 0, 1}, {0, 0, -1});

+ 0
- 44
src/game/entity-commands.hpp View File

@ -1,44 +0,0 @@
/*
* 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_COMMANDS_HPP
#define ANTKEEPER_ECS_ENTITY_COMMANDS_HPP
#include "utility/fundamental-types.hpp"
#include "math/transform-type.hpp"
#include <entt/entt.hpp>
namespace ec {
void translate(entt::registry& registry, entt::entity eid, const float3& translation);
void move_to(entt::registry& registry, entt::entity eid, const float3& position);
void warp_to(entt::registry& registry, entt::entity eid, const float3& position);
void set_scale(entt::registry& registry, entt::entity eid, const float3& scale);
void set_transform(entt::registry& registry, entt::entity eid, const math::transform<float>& transform, bool warp = false);
void place(entt::registry& registry, entt::entity eid, const float2& translation);
void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned int layers);
void bind_transform(entt::registry& registry, entt::entity source_eid, entt::entity target_eid);
math::transform<float> get_local_transform(entt::registry& registry, entt::entity eid);
math::transform<float> get_world_transform(entt::registry& registry, entt::entity eid);
void parent(entt::registry& registry, entt::entity child, entt::entity parent);
} // namespace ec
#endif // ANTKEEPER_ECS_ENTITY_COMMANDS_HPP

+ 58
- 51
src/game/game-context.hpp View File

@ -22,6 +22,8 @@
#include "utility/fundamental-types.hpp"
#include "resources/string-table.hpp"
#include "ecs/entity.hpp"
#include "ecs/registry.hpp"
#include "geometry/aabb.hpp"
#include <optional>
#include <entt/entt.hpp>
@ -31,54 +33,34 @@
// Forward declarations
class animator;
class application;
class behavior_system;
class bloom_pass;
class camera_system;
class clear_pass;
class collision_system;
class compositor;
class config_file;
class constraint_system;
class control;
class control_set;
class control_system;
class final_pass;
class framebuffer;
class locomotion_system;
class material;
class input_listener;
class material_pass;
class nest_system;
class orbit_cam;
class pheromone_matrix;
class snapping_system;
class rasterizer;
class render_system;
class resource_manager;
class samara_system;
class screen_transition;
class shadow_map_pass;
class simple_render_pass;
class sky_pass;
class subterrain_system;
class terrain_system;
class texture_2d;
class timeline;
class tool_system;
class ui_system;
class spatial_system;
class vegetation_system;
class vertex_array;
class vertex_buffer;
class renderer;
class input_event_router;
class input_mapper;
class outline_pass;
class tracking_system;
class painting_system;
class weather_system;
class astronomy_system;
class solar_system;
struct biome;
template <typename T> class animation;
template <typename T> class material_property;
@ -90,6 +72,31 @@ namespace debug
class logger;
}
namespace ecs
{
class subterrain_system;
class terrain_system;
class vegetation_system;
class tool_system;
class ui_system;
class spatial_system;
class tracking_system;
class painting_system;
class weather_system;
class astronomy_system;
class solar_system;
class behavior_system;
class collision_system;
class constraint_system;
class locomotion_system;
class control_system;
class snapping_system;
class camera_system;
class nest_system;
class render_system;
class samara_system;
}
#include "scene/scene.hpp"
/**
@ -214,38 +221,38 @@ struct game_context
control* toggle_fullscreen_control;
// Entities
entt::registry* ecs_registry;
entt::entity brush_entity;
entt::entity flashlight_entity;
entt::entity forceps_entity;
entt::entity lens_entity;
entt::entity marker_entity;
entt::entity container_entity;
entt::entity twig_entity;
entt::entity focal_point_entity;
ecs::registry* ecs_registry;
ecs::entity brush_entity;
ecs::entity flashlight_entity;
ecs::entity forceps_entity;
ecs::entity lens_entity;
ecs::entity marker_entity;
ecs::entity container_entity;
ecs::entity twig_entity;
ecs::entity focal_point_entity;
// Systems
behavior_system* behavior_system;
camera_system* camera_system;
collision_system* collision_system;
constraint_system* constraint_system;
control_system* control_system;
locomotion_system* locomotion_system;
nest_system* nest_system;
snapping_system* snapping_system;
render_system* render_system;
samara_system* samara_system;
subterrain_system* subterrain_system;
terrain_system* terrain_system;
tool_system* tool_system;
ui_system* ui_system;
vegetation_system* vegetation_system;
spatial_system* spatial_system;
tracking_system* tracking_system;
painting_system* painting_system;
weather_system* weather_system;
astronomy_system* astronomy_system;
solar_system* solar_system;
ecs::behavior_system* behavior_system;
ecs::camera_system* camera_system;
ecs::collision_system* collision_system;
ecs::constraint_system* constraint_system;
ecs::control_system* control_system;
ecs::locomotion_system* locomotion_system;
ecs::nest_system* nest_system;
ecs::snapping_system* snapping_system;
ecs::render_system* render_system;
ecs::samara_system* samara_system;
ecs::subterrain_system* subterrain_system;
ecs::terrain_system* terrain_system;
ecs::tool_system* tool_system;
ecs::ui_system* ui_system;
ecs::vegetation_system* vegetation_system;
ecs::spatial_system* spatial_system;
ecs::tracking_system* tracking_system;
ecs::painting_system* painting_system;
ecs::weather_system* weather_system;
ecs::astronomy_system* astronomy_system;
ecs::solar_system* solar_system;
// Game
biome* biome;

+ 38
- 38
src/game/states/play-state.cpp View File

@ -21,19 +21,19 @@
#include "animation/screen-transition.hpp"
#include "configuration.hpp"
#include "debug/logger.hpp"
#include "entity/archetype.hpp"
#include "game/components/cavity-component.hpp"
#include "game/components/copy-transform-component.hpp"
#include "game/components/copy-translation-component.hpp"
#include "game/components/model-component.hpp"
#include "game/components/snap-component.hpp"
#include "game/components/samara-component.hpp"
#include "game/components/terrain-component.hpp"
#include "game/components/tool-component.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/camera-follow-component.hpp"
#include "game/components/orbit-component.hpp"
#include "game/entity-commands.hpp"
#include "ecs/archetype.hpp"
#include "ecs/components/cavity-component.hpp"
#include "ecs/components/copy-transform-component.hpp"
#include "ecs/components/copy-translation-component.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/snap-component.hpp"
#include "ecs/components/samara-component.hpp"
#include "ecs/components/terrain-component.hpp"
#include "ecs/components/tool-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/camera-follow-component.hpp"
#include "ecs/components/orbit-component.hpp"
#include "ecs/commands.hpp"
#include "game/game-context.hpp"
#include "game/states/game-states.hpp"
#include "math/math.hpp"
@ -51,13 +51,13 @@
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/directional-light.hpp"
#include "game/systems/control-system.hpp"
#include "game/systems/camera-system.hpp"
#include "game/systems/render-system.hpp"
#include "game/systems/tool-system.hpp"
#include "game/systems/weather-system.hpp"
#include "game/systems/solar-system.hpp"
#include "game/systems/astronomy-system.hpp"
#include "ecs/systems/control-system.hpp"
#include "ecs/systems/camera-system.hpp"
#include "ecs/systems/render-system.hpp"
#include "ecs/systems/tool-system.hpp"
#include "ecs/systems/weather-system.hpp"
#include "ecs/systems/solar-system.hpp"
#include "ecs/systems/astronomy-system.hpp"
#include "game/biome.hpp"
#include "utility/fundamental-types.hpp"
#include "utility/gamma.hpp"
@ -196,8 +196,8 @@ void play_state_enter(game_context* ctx)
// Create flashlight and light cone, set light cone parent to flashlight, and move both to underworld scene
flashlight_archetype->assign(ecs_registry, ctx->flashlight_entity);
auto flashlight_light_cone = flashlight_light_cone_archetype->create(ecs_registry);
ec::parent(ecs_registry, flashlight_light_cone, ctx->flashlight_entity);
ec::assign_render_layers(ecs_registry, ctx->flashlight_entity, 2);
ecs::command::parent(ecs_registry, flashlight_light_cone, ctx->flashlight_entity);
ecs::command::assign_render_layers(ecs_registry, ctx->flashlight_entity, 2);
// Make lens tool's model instance unculled, so its shadow is always visible.
scene::model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
@ -208,18 +208,18 @@ void play_state_enter(game_context* ctx)
// Create lens light cone and set its parent to lens
auto lens_light_cone = lens_light_cone_archetype->create(ecs_registry);
//ec::bind_transform(ecs_registry, lens_light_cone, ctx->lens_entity);
ec::parent(ecs_registry, lens_light_cone, ctx->lens_entity);
//ecs::command::bind_transform(ecs_registry, lens_light_cone, ctx->lens_entity);
ecs::command::parent(ecs_registry, lens_light_cone, ctx->lens_entity);
// Hide inactive tools
ec::assign_render_layers(ecs_registry, ctx->forceps_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->brush_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->lens_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->marker_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->container_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->twig_entity, 0);
ecs::command::assign_render_layers(ecs_registry, ctx->forceps_entity, 0);
ecs::command::assign_render_layers(ecs_registry, ctx->brush_entity, 0);
ecs::command::assign_render_layers(ecs_registry, ctx->lens_entity, 0);
ecs::command::assign_render_layers(ecs_registry, ctx->marker_entity, 0);
ecs::command::assign_render_layers(ecs_registry, ctx->container_entity, 0);
ecs::command::assign_render_layers(ecs_registry, ctx->twig_entity, 0);
// Activate brush tool
ctx->tool_system->set_active_tool(ctx->brush_entity);
@ -240,7 +240,7 @@ void play_state_enter(game_context* ctx)
// Create ant-hill
auto ant_hill_entity = ant_hill_archetype->create(ecs_registry);
ec::place(ecs_registry, ant_hill_entity, {0, 0});
ecs::command::place(ecs_registry, ant_hill_entity, {0, 0});
// Generate pebbles
float pebble_radius = 300.0f;
@ -257,12 +257,12 @@ void play_state_enter(game_context* ctx)
transform.local.rotation = math::angle_axis(math::random(0.0f, math::two_pi<float>), {0, 1, 0});
transform.local.scale = float3{1, 1, 1} * math::random(0.75f, 1.25f);
ec::place(ecs_registry, pebble_entity, {x, z});
ecs::command::place(ecs_registry, pebble_entity, {x, z});
}
// Create maple tree
//auto maple_tree_entity = maple_tree_archetype->create(ecs_registry);
//ec::place(ecs_registry, maple_tree_entity, {300, 200});
//ecs::command::place(ecs_registry, maple_tree_entity, {300, 200});
// Creat nest
auto nest_entity = nest_archetype->create(ecs_registry);
@ -321,7 +321,7 @@ void play_state_enter(game_context* ctx)
ctx->camera_system->set_camera(ctx->overworld_camera);
auto ant_head = ant_head_archetype->create(ecs_registry);
ec::place(ecs_registry, ant_head, {50, 0});
ecs::command::place(ecs_registry, ant_head, {50, 0});
ctx->overworld_scene->update_tweens();
@ -381,8 +381,8 @@ void play_state_enter(game_context* ctx)
// Place larva in chamber
{
auto larva = larva_archetype->create(ecs_registry);
ec::assign_render_layers(ecs_registry, larva, 1);
ec::warp_to(ecs_registry, larva, {50, 0.1935f, 10});
ecs::command::assign_render_layers(ecs_registry, larva, 1);
ecs::command::warp_to(ecs_registry, larva, {50, 0.1935f, 10});
//auto& transform = ecs_registry.get<ecs::transform_component>(larva_entity);
//transform.transform = math::identity_transform<float>;
//transform.transform.translation = nest->get_shaft_position(*central_shaft, central_shaft->depth[1]);
@ -390,9 +390,9 @@ void play_state_enter(game_context* ctx)
}
auto dandelion_plant = dandelion_plant_archetype->create(ecs_registry);
ec::place(ecs_registry, dandelion_plant, {55, -30});
ecs::command::place(ecs_registry, dandelion_plant, {55, -30});
control_system* control_system = ctx->control_system;
ecs::control_system* control_system = ctx->control_system;
control_system->update(0.0, 0.0);
control_system->set_nest(nest);

+ 10
- 10
src/resources/entity-archetype-loader.cpp View File

@ -21,16 +21,16 @@
#include "resource-manager.hpp"
#include "string-table.hpp"
#include "renderer/model.hpp"
#include "game/components/behavior-component.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/terrain-component.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/model-component.hpp"
#include "game/components/nest-component.hpp"
#include "game/components/tool-component.hpp"
#include "game/components/marker-component.hpp"
#include "game/components/brush-component.hpp"
#include "entity/archetype.hpp"
#include "ecs/components/behavior-component.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/terrain-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/nest-component.hpp"
#include "ecs/components/tool-component.hpp"
#include "ecs/components/marker-component.hpp"
#include "ecs/components/brush-component.hpp"
#include "ecs/archetype.hpp"
#include "game/behavior/ebt.hpp"
#include <sstream>
#include <stdexcept>

Loading…
Cancel
Save