diff --git a/CMakeLists.txt b/CMakeLists.txt index bc40e61..d4aa351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/entity/archetype.hpp b/src/ecs/archetype.hpp similarity index 100% rename from src/entity/archetype.hpp rename to src/ecs/archetype.hpp diff --git a/src/game/entity-commands.cpp b/src/ecs/commands.cpp similarity index 50% rename from src/game/entity-commands.cpp rename to src/ecs/commands.cpp index 34a319a..17cae12 100644 --- a/src/game/entity-commands.cpp +++ b/src/ecs/commands.cpp @@ -17,66 +17,65 @@ * along with Antkeeper source code. If not, see . */ -#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 -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(eid)) + if (registry.has(entity)) { - transform_component& transform = registry.get(eid); + transform_component& transform = registry.get(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(eid)) + if (registry.has(entity)) { - transform_component& transform = registry.get(eid); + transform_component& transform = registry.get(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(eid)) + if (registry.has(entity)) { - transform_component& transform = registry.get(eid); + transform_component& transform = registry.get(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(eid)) + if (registry.has(entity)) { - transform_component& transform = registry.get(eid); + transform_component& transform = registry.get(entity); transform.local.scale = scale; } } -void set_transform(entt::registry& registry, entt::entity eid, const math::transform& transform, bool warp) +void set_transform(ecs::registry& registry, ecs::entity entity, const math::transform& transform, bool warp) { - if (registry.has(eid)) + if (registry.has(entity)) { - transform_component& component = registry.get(eid); + transform_component& component = registry.get(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(eid, component); + registry.assign_or_replace(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(eid)) + if (registry.has(entity)) { - model_component model = registry.get(eid); + model_component model = registry.get(entity); model.layers = layers; - registry.replace(eid, model); + registry.replace(entity, model); // Apply to child layers registry.view().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(source_eid, copy_transform); + copy_transform_component copy_transform = {target}; + registry.assign_or_replace(source, copy_transform); } -math::transform get_local_transform(entt::registry& registry, entt::entity eid) +math::transform get_local_transform(ecs::registry& registry, ecs::entity entity) { - if (registry.has(eid)) + if (registry.has(entity)) { - const transform_component& component = registry.get(eid); + const transform_component& component = registry.get(entity); return component.local; } return math::identity_transform; } -math::transform get_world_transform(entt::registry& registry, entt::entity eid) +math::transform get_world_transform(ecs::registry& registry, ecs::entity entity) { - if (registry.has(eid)) + if (registry.has(entity)) { - const transform_component& component = registry.get(eid); + const transform_component& component = registry.get(entity); return component.world; } return math::identity_transform; } -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(child, component); } -} // namespace ec +} // namespace command +} // namespace ecs diff --git a/src/ecs/commands.hpp b/src/ecs/commands.hpp new file mode 100644 index 0000000..d559212 --- /dev/null +++ b/src/ecs/commands.hpp @@ -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 . + */ + +#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& 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 get_local_transform(ecs::registry& registry, ecs::entity entity); +math::transform 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 + diff --git a/src/game/components/behavior-component.hpp b/src/ecs/components/behavior-component.hpp similarity index 100% rename from src/game/components/behavior-component.hpp rename to src/ecs/components/behavior-component.hpp diff --git a/src/game/components/brush-component.hpp b/src/ecs/components/brush-component.hpp similarity index 100% rename from src/game/components/brush-component.hpp rename to src/ecs/components/brush-component.hpp diff --git a/src/game/components/camera-follow-component.hpp b/src/ecs/components/camera-follow-component.hpp similarity index 100% rename from src/game/components/camera-follow-component.hpp rename to src/ecs/components/camera-follow-component.hpp diff --git a/src/game/components/cavity-component.hpp b/src/ecs/components/cavity-component.hpp similarity index 100% rename from src/game/components/cavity-component.hpp rename to src/ecs/components/cavity-component.hpp diff --git a/src/game/components/celestial-body-component.hpp b/src/ecs/components/celestial-body-component.hpp similarity index 100% rename from src/game/components/celestial-body-component.hpp rename to src/ecs/components/celestial-body-component.hpp diff --git a/src/game/components/chamber-component.hpp b/src/ecs/components/chamber-component.hpp similarity index 96% rename from src/game/components/chamber-component.hpp rename to src/ecs/components/chamber-component.hpp index f1869a9..f4df393 100644 --- a/src/game/components/chamber-component.hpp +++ b/src/ecs/components/chamber-component.hpp @@ -22,12 +22,13 @@ #include #include +#include "ecs/entity.hpp" namespace ecs { struct chamber_component { - entt::entity nest; + entity nest; float depth; float outer_radius; float inner_radius; diff --git a/src/game/components/collision-component.hpp b/src/ecs/components/collision-component.hpp similarity index 97% rename from src/game/components/collision-component.hpp rename to src/ecs/components/collision-component.hpp index bafb8e1..6930f2c 100644 --- a/src/game/components/collision-component.hpp +++ b/src/ecs/components/collision-component.hpp @@ -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 diff --git a/src/game/components/copy-rotation-component.hpp b/src/ecs/components/copy-rotation-component.hpp similarity index 81% rename from src/game/components/copy-rotation-component.hpp rename to src/ecs/components/copy-rotation-component.hpp index 302b527..746eae6 100644 --- a/src/game/components/copy-rotation-component.hpp +++ b/src/ecs/components/copy-rotation-component.hpp @@ -17,18 +17,18 @@ * along with Antkeeper source code. If not, see . */ -#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 +#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 diff --git a/src/game/components/copy-scale-component.hpp b/src/ecs/components/copy-scale-component.hpp similarity index 82% rename from src/game/components/copy-scale-component.hpp rename to src/ecs/components/copy-scale-component.hpp index f520bff..a4f6f4f 100644 --- a/src/game/components/copy-scale-component.hpp +++ b/src/ecs/components/copy-scale-component.hpp @@ -17,16 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#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 +#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 diff --git a/src/game/components/copy-transform-component.hpp b/src/ecs/components/copy-transform-component.hpp similarity index 81% rename from src/game/components/copy-transform-component.hpp rename to src/ecs/components/copy-transform-component.hpp index 874b320..61e4818 100644 --- a/src/game/components/copy-transform-component.hpp +++ b/src/ecs/components/copy-transform-component.hpp @@ -17,18 +17,18 @@ * along with Antkeeper source code. If not, see . */ -#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 +#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 diff --git a/src/game/components/copy-translation-component.hpp b/src/ecs/components/copy-translation-component.hpp similarity index 82% rename from src/game/components/copy-translation-component.hpp rename to src/ecs/components/copy-translation-component.hpp index fe24567..f75ddb6 100644 --- a/src/game/components/copy-translation-component.hpp +++ b/src/ecs/components/copy-translation-component.hpp @@ -17,16 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#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 +#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 diff --git a/src/game/components/locomotion-component.hpp b/src/ecs/components/locomotion-component.hpp similarity index 100% rename from src/game/components/locomotion-component.hpp rename to src/ecs/components/locomotion-component.hpp diff --git a/src/game/components/marker-component.hpp b/src/ecs/components/marker-component.hpp similarity index 100% rename from src/game/components/marker-component.hpp rename to src/ecs/components/marker-component.hpp diff --git a/src/game/components/model-component.hpp b/src/ecs/components/model-component.hpp similarity index 100% rename from src/game/components/model-component.hpp rename to src/ecs/components/model-component.hpp diff --git a/src/game/components/nest-component.hpp b/src/ecs/components/nest-component.hpp similarity index 94% rename from src/game/components/nest-component.hpp rename to src/ecs/components/nest-component.hpp index 3218131..a672ba8 100644 --- a/src/game/components/nest-component.hpp +++ b/src/ecs/components/nest-component.hpp @@ -21,13 +21,13 @@ #define ANTKEEPER_ECS_NEST_COMPONENT_HPP #include -#include +#include "ecs/entity.hpp" namespace ecs { struct nest_component { - std::vector chambers; + std::vector chambers; float helix_radius; float helix_pitch; float helix_chirality; diff --git a/src/game/components/orbit-component.hpp b/src/ecs/components/orbit-component.hpp similarity index 100% rename from src/game/components/orbit-component.hpp rename to src/ecs/components/orbit-component.hpp diff --git a/src/game/components/parent-component.hpp b/src/ecs/components/parent-component.hpp similarity index 95% rename from src/game/components/parent-component.hpp rename to src/ecs/components/parent-component.hpp index bdead6f..9413c62 100644 --- a/src/game/components/parent-component.hpp +++ b/src/ecs/components/parent-component.hpp @@ -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 diff --git a/src/game/components/render-component.hpp b/src/ecs/components/render-component.hpp similarity index 94% rename from src/game/components/render-component.hpp rename to src/ecs/components/render-component.hpp index d64d2b6..586c50c 100644 --- a/src/game/components/render-component.hpp +++ b/src/ecs/components/render-component.hpp @@ -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; }; diff --git a/src/game/components/samara-component.hpp b/src/ecs/components/samara-component.hpp similarity index 100% rename from src/game/components/samara-component.hpp rename to src/ecs/components/samara-component.hpp diff --git a/src/game/components/snap-component.hpp b/src/ecs/components/snap-component.hpp similarity index 100% rename from src/game/components/snap-component.hpp rename to src/ecs/components/snap-component.hpp diff --git a/src/game/components/terrain-component.hpp b/src/ecs/components/terrain-component.hpp similarity index 100% rename from src/game/components/terrain-component.hpp rename to src/ecs/components/terrain-component.hpp diff --git a/src/game/components/tool-component.hpp b/src/ecs/components/tool-component.hpp similarity index 100% rename from src/game/components/tool-component.hpp rename to src/ecs/components/tool-component.hpp diff --git a/src/game/components/trackable-component.hpp b/src/ecs/components/trackable-component.hpp similarity index 100% rename from src/game/components/trackable-component.hpp rename to src/ecs/components/trackable-component.hpp diff --git a/src/game/components/transform-component.hpp b/src/ecs/components/transform-component.hpp similarity index 100% rename from src/game/components/transform-component.hpp rename to src/ecs/components/transform-component.hpp diff --git a/src/ecs/ecs.hpp b/src/ecs/ecs.hpp new file mode 100644 index 0000000..f1d10dc --- /dev/null +++ b/src/ecs/ecs.hpp @@ -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 . + */ + +#ifndef ANTKEEPER_ECS_HPP +#define ANTKEEPER_ECS_HPP + +/// Entity-component-system (ECS) +namespace ecs {} + +#include "archetype.hpp" +#include "entity.hpp" + +#endif // ANTKEEPER_ECS_HPP diff --git a/src/ecs/entity.hpp b/src/ecs/entity.hpp new file mode 100644 index 0000000..966bd4b --- /dev/null +++ b/src/ecs/entity.hpp @@ -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 . + */ + +#ifndef ANTKEEPER_ECS_ENTITY_HPP +#define ANTKEEPER_ECS_ENTITY_HPP + +#include + +namespace ecs { + +/// Entity ID type +typedef entt::entity entity; + +} // namespace ecs + +#endif // ANTKEEPER_ECS_ENTITY_HPP diff --git a/src/ecs/registry.hpp b/src/ecs/registry.hpp new file mode 100644 index 0000000..5a50d88 --- /dev/null +++ b/src/ecs/registry.hpp @@ -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 . + */ + +#ifndef ANTKEEPER_ECS_REGISTRY_HPP +#define ANTKEEPER_ECS_REGISTRY_HPP + +#include + +namespace ecs { + +/// Component registry type +typedef entt::registry registry; + +} // namespace ecs + +#endif // ANTKEEPER_ECS_REGISTRY_HPP diff --git a/src/game/systems/astronomy-system.cpp b/src/ecs/systems/astronomy-system.cpp similarity index 91% rename from src/game/systems/astronomy-system.cpp rename to src/ecs/systems/astronomy-system.cpp index 010ddd6..c2f9478 100644 --- a/src/game/systems/astronomy-system.cpp +++ b/src/ecs/systems/astronomy-system.cpp @@ -17,18 +17,18 @@ * along with Antkeeper source code. If not, see . */ -#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().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 diff --git a/src/game/systems/astronomy-system.hpp b/src/ecs/systems/astronomy-system.hpp similarity index 89% rename from src/game/systems/astronomy-system.hpp rename to src/ecs/systems/astronomy-system.hpp index 7d817a5..23ae416 100644 --- a/src/game/systems/astronomy-system.hpp +++ b/src/ecs/systems/astronomy-system.hpp @@ -17,14 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/behavior-system.cpp b/src/ecs/systems/behavior-system.cpp similarity index 81% rename from src/game/systems/behavior-system.cpp rename to src/ecs/systems/behavior-system.cpp index 02c0e65..485c491 100644 --- a/src/game/systems/behavior-system.cpp +++ b/src/ecs/systems/behavior-system.cpp @@ -17,12 +17,13 @@ * along with Antkeeper source code. If not, see . */ -#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 = ®istry; registry.view().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 diff --git a/src/game/systems/behavior-system.hpp b/src/ecs/systems/behavior-system.hpp similarity index 81% rename from src/game/systems/behavior-system.hpp rename to src/ecs/systems/behavior-system.hpp index a7b76bf..bd7c2ad 100644 --- a/src/game/systems/behavior-system.hpp +++ b/src/ecs/systems/behavior-system.hpp @@ -17,18 +17,22 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/camera-system.cpp b/src/ecs/systems/camera-system.cpp similarity index 92% rename from src/game/systems/camera-system.cpp rename to src/ecs/systems/camera-system.cpp index 2081c77..892a950 100644 --- a/src/game/systems/camera-system.cpp +++ b/src/ecs/systems/camera-system.cpp @@ -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 #include -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().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(event.w), static_cast(event.h)}); } + +} // namespace ecs diff --git a/src/game/systems/camera-system.hpp b/src/ecs/systems/camera-system.hpp similarity index 90% rename from src/game/systems/camera-system.hpp rename to src/ecs/systems/camera-system.hpp index 6d46395..d2fef8b 100644 --- a/src/game/systems/camera-system.hpp +++ b/src/ecs/systems/camera-system.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#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, @@ -41,7 +43,7 @@ public: typedef math::quaternion quaternion_type; typedef math::transform 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 diff --git a/src/game/systems/collision-system.cpp b/src/ecs/systems/collision-system.cpp similarity index 71% rename from src/game/systems/collision-system.cpp rename to src/ecs/systems/collision-system.cpp index 1d8def7..9084c62 100644 --- a/src/game/systems/collision-system.cpp +++ b/src/ecs/systems/collision-system.cpp @@ -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().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 diff --git a/src/game/systems/collision-system.hpp b/src/ecs/systems/collision-system.hpp similarity index 68% rename from src/game/systems/collision-system.hpp rename to src/ecs/systems/collision-system.hpp index 9db7ea6..3f35f98 100644 --- a/src/game/systems/collision-system.hpp +++ b/src/ecs/systems/collision-system.hpp @@ -17,11 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/constraint-system.cpp b/src/ecs/systems/constraint-system.cpp similarity index 73% rename from src/game/systems/constraint-system.cpp rename to src/ecs/systems/constraint-system.cpp index fe14d46..021ab70 100644 --- a/src/game/systems/constraint-system.cpp +++ b/src/ecs/systems/constraint-system.cpp @@ -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().each ( - [&](auto entity, auto& constraint, auto& transform) + [&](ecs::entity entity, auto& constraint, auto& transform) { - if (registry.has(constraint.target)) + if (this->registry.has(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().each ( - [&](auto entity, auto& constraint, auto& transform) + [&](ecs::entity entity, auto& constraint, auto& transform) { - if (registry.has(constraint.target)) + if (this->registry.has(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().each ( - [&](auto entity, auto& constraint, auto& transform) + [&](ecs::entity entity, auto& constraint, auto& transform) { - if (registry.has(constraint.target)) + if (this->registry.has(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().each ( - [&](auto entity, auto& constraint, auto& transform) + [&](ecs::entity entity, auto& constraint, auto& transform) { - if (registry.has(constraint.target)) + if (this->registry.has(constraint.target)) { transform.world = transforms_view.get(constraint.target).world; } } ); } + +} // namespace ecs diff --git a/src/game/systems/constraint-system.hpp b/src/ecs/systems/constraint-system.hpp similarity index 80% rename from src/game/systems/constraint-system.hpp rename to src/ecs/systems/constraint-system.hpp index f6b3693..3c673ba 100644 --- a/src/game/systems/constraint-system.hpp +++ b/src/ecs/systems/constraint-system.hpp @@ -17,17 +17,21 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/control-system.cpp b/src/ecs/systems/control-system.cpp similarity index 91% rename from src/game/systems/control-system.cpp rename to src/ecs/systems/control-system.cpp index 6b98fba..7782f14 100644 --- a/src/game/systems/control-system.cpp +++ b/src/ecs/systems/control-system.cpp @@ -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& 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; flashlight_turns = flashlight_turns_i - flashlight_turns_f; - if (flashlight_eid != entt::null && nest) + if (flashlight_entity != entt::null && nest) { math::transform flashlight_transform = math::identity_transform; @@ -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 + math::half_pi, {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(event.w), static_cast(event.h)}); } + +} // namespace ecs diff --git a/src/game/systems/control-system.hpp b/src/ecs/systems/control-system.hpp similarity index 93% rename from src/game/systems/control-system.hpp rename to src/ecs/systems/control-system.hpp index ae0993f..0392e5b 100644 --- a/src/game/systems/control-system.hpp +++ b/src/ecs/systems/control-system.hpp @@ -17,10 +17,11 @@ * along with Antkeeper source code. If not, see . */ -#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 { 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 diff --git a/src/game/systems/entity-system.cpp b/src/ecs/systems/entity-system.cpp similarity index 90% rename from src/game/systems/entity-system.cpp rename to src/ecs/systems/entity-system.cpp index 8a21113..8debe43 100644 --- a/src/game/systems/entity-system.cpp +++ b/src/ecs/systems/entity-system.cpp @@ -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 + diff --git a/src/game/systems/entity-system.hpp b/src/ecs/systems/entity-system.hpp similarity index 79% rename from src/game/systems/entity-system.hpp rename to src/ecs/systems/entity-system.hpp index c7890e0..1ae0192 100644 --- a/src/game/systems/entity-system.hpp +++ b/src/ecs/systems/entity-system.hpp @@ -17,11 +17,13 @@ * along with Antkeeper source code. If not, see . */ -#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 +#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 diff --git a/src/game/systems/locomotion-system.cpp b/src/ecs/systems/locomotion-system.cpp similarity index 74% rename from src/game/systems/locomotion-system.cpp rename to src/ecs/systems/locomotion-system.cpp index b0b7321..5153429 100644 --- a/src/game/systems/locomotion-system.cpp +++ b/src/ecs/systems/locomotion-system.cpp @@ -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().each( - [&](auto entity, auto& transform, auto& locomotion) + [&](ecs::entity entity, auto& transform, auto& locomotion) { }); } +} // namespace ecs diff --git a/src/game/systems/locomotion-system.hpp b/src/ecs/systems/locomotion-system.hpp similarity index 80% rename from src/game/systems/locomotion-system.hpp rename to src/ecs/systems/locomotion-system.hpp index 3bd15bb..c753b7e 100644 --- a/src/game/systems/locomotion-system.hpp +++ b/src/ecs/systems/locomotion-system.hpp @@ -17,18 +17,21 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/nest-system.cpp b/src/ecs/systems/nest-system.cpp similarity index 86% rename from src/game/systems/nest-system.cpp rename to src/ecs/systems/nest-system.cpp index 5341114..9464567 100644 --- a/src/game/systems/nest-system.cpp +++ b/src/ecs/systems/nest-system.cpp @@ -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 diff --git a/src/game/systems/nest-system.hpp b/src/ecs/systems/nest-system.hpp similarity index 69% rename from src/game/systems/nest-system.hpp rename to src/ecs/systems/nest-system.hpp index 4f19d63..9a84492 100644 --- a/src/game/systems/nest-system.hpp +++ b/src/ecs/systems/nest-system.hpp @@ -17,28 +17,32 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/painting-system.cpp b/src/ecs/systems/painting-system.cpp similarity index 95% rename from src/game/systems/painting-system.cpp rename to src/ecs/systems/painting-system.cpp index f6c0951..144d15d 100644 --- a/src/game/systems/painting-system.cpp +++ b/src/ecs/systems/painting-system.cpp @@ -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 -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(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::infinity(); registry.view().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 inverse_transform = math::inverse(collision_transform.local); @@ -355,3 +355,5 @@ std::optional> painting_system::cast_ray(const float3 return result; } + +} // namespace ecs diff --git a/src/game/systems/painting-system.hpp b/src/ecs/systems/painting-system.hpp similarity index 87% rename from src/game/systems/painting-system.hpp rename to src/ecs/systems/painting-system.hpp index e4e2aba..bb2d76c 100644 --- a/src/game/systems/painting-system.hpp +++ b/src/ecs/systems/painting-system.hpp @@ -17,10 +17,11 @@ * along with Antkeeper source code. If not, see . */ -#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, public event_handler { 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 diff --git a/src/game/systems/render-system.cpp b/src/ecs/systems/render-system.cpp similarity index 83% rename from src/game/systems/render-system.cpp rename to src/ecs/systems/render-system.cpp index 81ee074..ba92bce 100644 --- a/src/game/systems/render-system.cpp +++ b/src/ecs/systems/render-system.cpp @@ -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().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 diff --git a/src/game/systems/render-system.hpp b/src/ecs/systems/render-system.hpp similarity index 57% rename from src/game/systems/render-system.hpp rename to src/ecs/systems/render-system.hpp index 5f5851a..730867f 100644 --- a/src/game/systems/render-system.hpp +++ b/src/ecs/systems/render-system.hpp @@ -17,23 +17,26 @@ * along with Antkeeper source code. If not, see . */ -#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 #include 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 layers; - std::unordered_map model_instances; + std::unordered_map model_instances; }; -#endif // ANTKEEPER_RENDER_SYSTEM_HPP +} // namespace ecs + +#endif // ANTKEEPER_ECS_RENDER_SYSTEM_HPP diff --git a/src/game/systems/samara-system.cpp b/src/ecs/systems/samara-system.cpp similarity index 87% rename from src/game/systems/samara-system.cpp rename to src/ecs/systems/samara-system.cpp index f95ac80..dd5805f 100644 --- a/src/game/systems/samara-system.cpp +++ b/src/ecs/systems/samara-system.cpp @@ -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().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 diff --git a/src/game/systems/samara-system.hpp b/src/ecs/systems/samara-system.hpp similarity index 81% rename from src/game/systems/samara-system.hpp rename to src/ecs/systems/samara-system.hpp index 726bbe3..544427b 100644 --- a/src/game/systems/samara-system.hpp +++ b/src/ecs/systems/samara-system.hpp @@ -17,17 +17,21 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/snapping-system.cpp b/src/ecs/systems/snapping-system.cpp similarity index 81% rename from src/game/systems/snapping-system.cpp rename to src/ecs/systems/snapping-system.cpp index 7900da3..26fa922 100644 --- a/src/game/systems/snapping-system.cpp +++ b/src/ecs/systems/snapping-system.cpp @@ -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().each( - [&](auto entity, auto& snap_transform, auto& snap) + [&](ecs::entity entity, auto& snap_transform, auto& snap) { bool intersection = false; float a = std::numeric_limits::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().each( - [&](auto entity, auto& collision_transform, auto& collision) + this->registry.view().each( + [&](ecs::entity entity, auto& collision_transform, auto& collision) { // Transform ray into local space of collision component math::transform inverse_transform = math::inverse(collision_transform.local); @@ -81,8 +82,10 @@ void snapping_system::update(double t, double dt) if (snap.autoremove) { - registry.remove(entity); + this->registry.remove(entity); } } }); } + +} // namespace ecs diff --git a/src/game/systems/snapping-system.hpp b/src/ecs/systems/snapping-system.hpp similarity index 81% rename from src/game/systems/snapping-system.hpp rename to src/ecs/systems/snapping-system.hpp index f6152d6..a7279c6 100644 --- a/src/game/systems/snapping-system.hpp +++ b/src/ecs/systems/snapping-system.hpp @@ -17,18 +17,22 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/solar-system.cpp b/src/ecs/systems/solar-system.cpp similarity index 89% rename from src/game/systems/solar-system.cpp rename to src/ecs/systems/solar-system.cpp index ffbca49..4bd9596 100644 --- a/src/game/systems/solar-system.cpp +++ b/src/ecs/systems/solar-system.cpp @@ -17,17 +17,18 @@ * along with Antkeeper source code. If not, see . */ -#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().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 diff --git a/src/game/systems/solar-system.hpp b/src/ecs/systems/solar-system.hpp similarity index 89% rename from src/game/systems/solar-system.hpp rename to src/ecs/systems/solar-system.hpp index df9e522..dce98bf 100644 --- a/src/game/systems/solar-system.hpp +++ b/src/ecs/systems/solar-system.hpp @@ -17,12 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/spatial-system.cpp b/src/ecs/systems/spatial-system.cpp similarity index 70% rename from src/game/systems/spatial-system.cpp rename to src/ecs/systems/spatial-system.cpp index cf4e200..bf901cf 100644 --- a/src/game/systems/spatial-system.cpp +++ b/src/ecs/systems/spatial-system.cpp @@ -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().each( - [&](auto entity, auto& transform) + [&](ecs::entity entity, auto& transform) { - if (!registry.has(entity)) + if (!this->registry.has(entity)) { transform.world = transform.local; } @@ -43,14 +43,16 @@ void spatial_system::update(double t, double dt) // Process child transforms second registry.view().each( - [&](auto entity, auto& transform) + [&](ecs::entity entity, auto& transform) { - if (registry.has(entity)) + if (this->registry.has(entity)) { - entt::entity parent = registry.get(entity).parent; - const transform_component& parent_transform = registry.get(parent); + ecs::entity parent = this->registry.get(entity).parent; + const transform_component& parent_transform = this->registry.get(parent); transform.world = parent_transform.world * transform.local; transform.warp = parent_transform.warp; } }); } + +} // namespace ecs diff --git a/src/game/systems/spatial-system.hpp b/src/ecs/systems/spatial-system.hpp similarity index 81% rename from src/game/systems/spatial-system.hpp rename to src/ecs/systems/spatial-system.hpp index b703037..b9a4f79 100644 --- a/src/game/systems/spatial-system.hpp +++ b/src/ecs/systems/spatial-system.hpp @@ -17,18 +17,21 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/subterrain-system.cpp b/src/ecs/systems/subterrain-system.cpp similarity index 95% rename from src/game/systems/subterrain-system.cpp rename to src/ecs/systems/subterrain-system.cpp index 341349e..b041c96 100644 --- a/src/game/systems/subterrain-system.cpp +++ b/src/ecs/systems/subterrain-system.cpp @@ -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 #include -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().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 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 diff --git a/src/game/systems/subterrain-system.hpp b/src/ecs/systems/subterrain-system.hpp similarity index 89% rename from src/game/systems/subterrain-system.hpp rename to src/ecs/systems/subterrain-system.hpp index a925606..2cbcde2 100644 --- a/src/game/systems/subterrain-system.hpp +++ b/src/ecs/systems/subterrain-system.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#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 @@ -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 subterrain_bounds; - ::cube_tree* cube_tree; + ecs::cube_tree* cube_tree; std::vector subterrain_vertices; std::vector> 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 diff --git a/src/game/systems/terrain-system.cpp b/src/ecs/systems/terrain-system.cpp similarity index 94% rename from src/game/systems/terrain-system.cpp rename to src/ecs/systems/terrain-system.cpp index 3f72170..a6e2679 100644 --- a/src/game/systems/terrain-system.cpp +++ b/src/ecs/systems/terrain-system.cpp @@ -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 -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().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(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 diff --git a/src/game/systems/terrain-system.hpp b/src/ecs/systems/terrain-system.hpp similarity index 75% rename from src/game/systems/terrain-system.hpp rename to src/ecs/systems/terrain-system.hpp index 12b0292..a48d18a 100644 --- a/src/game/systems/terrain-system.hpp +++ b/src/ecs/systems/terrain-system.hpp @@ -17,11 +17,12 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/tool-system.cpp b/src/ecs/systems/tool-system.cpp similarity index 93% rename from src/game/systems/tool-system.cpp rename to src/ecs/systems/tool-system.cpp index e37164d..f9fdd79 100644 --- a/src/game/systems/tool-system.cpp +++ b/src/ecs/systems/tool-system.cpp @@ -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().each( - [&](auto entity, auto& transform, auto& collision) + [&](ecs::entity entity, auto& transform, auto& collision) { math::transform 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().each( - [&](auto entity, auto& tool, auto& transform) + [&](ecs::entity entity, auto& tool, auto& transform) { /* if (registry.has(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(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* 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(event.w), static_cast(event.h)}); } + +} // namespace ecs diff --git a/src/game/systems/tool-system.hpp b/src/ecs/systems/tool-system.hpp similarity index 84% rename from src/game/systems/tool-system.hpp rename to src/ecs/systems/tool-system.hpp index fdca6a6..9459de0 100644 --- a/src/game/systems/tool-system.hpp +++ b/src/ecs/systems/tool-system.hpp @@ -17,10 +17,11 @@ * along with Antkeeper source code. If not, see . */ -#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, public event_handler { 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 diff --git a/src/game/systems/tracking-system.cpp b/src/ecs/systems/tracking-system.cpp similarity index 88% rename from src/game/systems/tracking-system.cpp rename to src/ecs/systems/tracking-system.cpp index 0cb8918..bb2ec7c 100644 --- a/src/game/systems/tracking-system.cpp +++ b/src/ecs/systems/tracking-system.cpp @@ -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(event.entity)) { - math::transform transform = ec::get_world_transform(registry, event.entity); + math::transform transform = command::get_world_transform(registry, event.entity); int marker_index = registry.get(event.entity).color; @@ -155,3 +155,5 @@ void tracking_system::handle_event(const tool_released_event& event) { } + +} // namespace ecs diff --git a/src/game/systems/tracking-system.hpp b/src/ecs/systems/tracking-system.hpp similarity index 70% rename from src/game/systems/tracking-system.hpp rename to src/ecs/systems/tracking-system.hpp index caefacf..73ac5f6 100644 --- a/src/game/systems/tracking-system.hpp +++ b/src/ecs/systems/tracking-system.hpp @@ -17,32 +17,31 @@ * along with Antkeeper source code. If not, see . */ -#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 +#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, public event_handler { 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 trackers; + std::unordered_map trackers; }; -#endif // ANTKEEPER_TRACKING_SYSTEM_HPP +} // namespace ecs + +#endif // ANTKEEPER_ECS_TRACKING_SYSTEM_HPP diff --git a/src/game/systems/ui-system.cpp b/src/ecs/systems/ui-system.cpp similarity index 99% rename from src/game/systems/ui-system.cpp rename to src/ecs/systems/ui-system.cpp index 6001f8a..c001224 100644 --- a/src/game/systems/ui-system.cpp +++ b/src/ecs/systems/ui-system.cpp @@ -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 diff --git a/src/game/systems/ui-system.hpp b/src/ecs/systems/ui-system.hpp similarity index 94% rename from src/game/systems/ui-system.hpp rename to src/ecs/systems/ui-system.hpp index 63e1544..d144558 100644 --- a/src/game/systems/ui-system.hpp +++ b/src/ecs/systems/ui-system.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#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, public event_handler @@ -82,4 +84,6 @@ private: control* tool_menu_control; }; -#endif // ANTKEEPER_UI_SYSTEM_HPP +} // namespace ecs + +#endif // ANTKEEPER_ECS_UI_SYSTEM_HPP diff --git a/src/game/systems/updatable-system.cpp b/src/ecs/systems/updatable-system.cpp similarity index 100% rename from src/game/systems/updatable-system.cpp rename to src/ecs/systems/updatable-system.cpp diff --git a/src/game/systems/updatable-system.hpp b/src/ecs/systems/updatable-system.hpp similarity index 86% rename from src/game/systems/updatable-system.hpp rename to src/ecs/systems/updatable-system.hpp index 8f87266..de00dac 100644 --- a/src/game/systems/updatable-system.hpp +++ b/src/ecs/systems/updatable-system.hpp @@ -17,8 +17,10 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/vegetation-system.cpp b/src/ecs/systems/vegetation-system.cpp similarity index 94% rename from src/game/systems/vegetation-system.cpp rename to src/ecs/systems/vegetation-system.cpp index b639b96..a32b0b6 100644 --- a/src/game/systems/vegetation-system.cpp +++ b/src/ecs/systems/vegetation-system.cpp @@ -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 -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(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 diff --git a/src/game/systems/vegetation-system.hpp b/src/ecs/systems/vegetation-system.hpp similarity index 77% rename from src/game/systems/vegetation-system.hpp rename to src/ecs/systems/vegetation-system.hpp index 86ab979..9a1d160 100644 --- a/src/game/systems/vegetation-system.hpp +++ b/src/ecs/systems/vegetation-system.hpp @@ -17,18 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/systems/weather-system.cpp b/src/ecs/systems/weather-system.cpp similarity index 93% rename from src/game/systems/weather-system.cpp rename to src/ecs/systems/weather-system.cpp index 58b581d..bf93321 100644 --- a/src/game/systems/weather-system.cpp +++ b/src/ecs/systems/weather-system.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#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 +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 diff --git a/src/game/systems/weather-system.hpp b/src/ecs/systems/weather-system.hpp similarity index 91% rename from src/game/systems/weather-system.hpp rename to src/ecs/systems/weather-system.hpp index 30e76a6..3e90f9f 100644 --- a/src/game/systems/weather-system.hpp +++ b/src/ecs/systems/weather-system.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#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 diff --git a/src/game/behavior/ebt.cpp b/src/game/behavior/ebt.cpp index 06975de..b532945 100644 --- a/src/game/behavior/ebt.cpp +++ b/src/game/behavior/ebt.cpp @@ -18,7 +18,7 @@ */ #include "game/behavior/ebt.hpp" -#include "game/components/transform-component.hpp" +#include "ecs/components/transform-component.hpp" #include using namespace ecs; diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 07bf5e8..a97f103 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -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(viewport_dimensions[0]), static_cast(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(ctx->camera_system); event_dispatcher->subscribe(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(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}); diff --git a/src/game/entity-commands.hpp b/src/game/entity-commands.hpp deleted file mode 100644 index 13b3363..0000000 --- a/src/game/entity-commands.hpp +++ /dev/null @@ -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 . - */ - -#ifndef ANTKEEPER_ECS_ENTITY_COMMANDS_HPP -#define ANTKEEPER_ECS_ENTITY_COMMANDS_HPP - -#include "utility/fundamental-types.hpp" -#include "math/transform-type.hpp" -#include - -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& 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 get_local_transform(entt::registry& registry, entt::entity eid); -math::transform 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 - diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index 51a6977..9f4d06b 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -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 #include @@ -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 class animation; template 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; diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index 287d754..8a9b72a 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -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), {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(larva_entity); //transform.transform = math::identity_transform; //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); diff --git a/src/resources/entity-archetype-loader.cpp b/src/resources/entity-archetype-loader.cpp index 383be85..4dee43a 100644 --- a/src/resources/entity-archetype-loader.cpp +++ b/src/resources/entity-archetype-loader.cpp @@ -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 #include