Browse Source

Rename ecs namespace to entity, move components to entity::component namespace, move systems into entity::system namespace

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

+ 0
- 143
src/ecs/commands.cpp View File

@ -1,143 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ecs/commands.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/copy-transform-component.hpp"
#include "ecs/components/snap-component.hpp"
#include "ecs/components/parent-component.hpp"
#include <limits>
namespace ecs {
namespace command {
void translate(ecs::registry& registry, ecs::entity entity, const float3& translation)
{
if (registry.has<transform_component>(entity))
{
transform_component& transform = registry.get<transform_component>(entity);
transform.local.translation += translation;
}
}
void move_to(ecs::registry& registry, ecs::entity entity, const float3& position)
{
if (registry.has<transform_component>(entity))
{
transform_component& transform = registry.get<transform_component>(entity);
transform.local.translation = position;
}
}
void warp_to(ecs::registry& registry, ecs::entity entity, const float3& position)
{
if (registry.has<transform_component>(entity))
{
transform_component& transform = registry.get<transform_component>(entity);
transform.local.translation = position;
transform.warp = true;
}
}
void set_scale(ecs::registry& registry, ecs::entity entity, const float3& scale)
{
if (registry.has<transform_component>(entity))
{
transform_component& transform = registry.get<transform_component>(entity);
transform.local.scale = scale;
}
}
void set_transform(ecs::registry& registry, ecs::entity entity, const math::transform<float>& transform, bool warp)
{
if (registry.has<transform_component>(entity))
{
transform_component& component = registry.get<transform_component>(entity);
component.local = transform;
component.warp = warp;
}
}
void place(ecs::registry& registry, ecs::entity entity, const float2& translation)
{
snap_component component;
component.warp = true;
component.relative = false;
component.autoremove = true;
component.ray.origin = {translation[0], 10000.0f, translation[1]};
component.ray.direction = {0.0f, -1.0f, 0.0f};
registry.assign_or_replace<snap_component>(entity, component);
}
void assign_render_layers(ecs::registry& registry, ecs::entity entity, unsigned int layers)
{
if (registry.has<model_component>(entity))
{
model_component model = registry.get<model_component>(entity);
model.layers = layers;
registry.replace<model_component>(entity, model);
// Apply to child layers
registry.view<parent_component>().each(
[&](ecs::entity entity, auto& component)
{
if (component.parent == entity)
assign_render_layers(registry, entity, layers);
});
}
}
void bind_transform(ecs::registry& registry, entity source, entity target)
{
copy_transform_component copy_transform = {target};
registry.assign_or_replace<copy_transform_component>(source, copy_transform);
}
math::transform<float> get_local_transform(ecs::registry& registry, ecs::entity entity)
{
if (registry.has<transform_component>(entity))
{
const transform_component& component = registry.get<transform_component>(entity);
return component.local;
}
return math::identity_transform<float>;
}
math::transform<float> get_world_transform(ecs::registry& registry, ecs::entity entity)
{
if (registry.has<transform_component>(entity))
{
const transform_component& component = registry.get<transform_component>(entity);
return component.world;
}
return math::identity_transform<float>;
}
void parent(ecs::registry& registry, entity child, entity parent)
{
parent_component component;
component.parent = parent;
registry.assign_or_replace<parent_component>(child, component);
}
} // namespace command
} // namespace ecs

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

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

+ 0
- 34
src/ecs/components/copy-transform-component.hpp View File

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

+ 0
- 34
src/ecs/components/ephemeris-component.hpp View File

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

+ 0
- 34
src/ecs/components/parent-component.hpp View File

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

+ 0
- 45
src/ecs/systems/collision-system.cpp View File

@ -1,45 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "collision-system.hpp"
#include "ecs/components/transform-component.hpp"
namespace ecs {
collision_system::collision_system(ecs::registry& registry):
entity_system(registry)
{
registry.on_construct<collision_component>().connect<&collision_system::on_collision_construct>(this);
registry.on_replace<collision_component>().connect<&collision_system::on_collision_replace>(this);
registry.on_destroy<collision_component>().connect<&collision_system::on_collision_destroy>(this);
}
void collision_system::update(double t, double dt)
{}
void collision_system::on_collision_construct(ecs::registry& registry, ecs::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(ecs::registry& registry, ecs::entity entity)
{}
} // namespace ecs

+ 0
- 43
src/ecs/systems/entity-system.hpp View File

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

+ 0
- 75
src/ecs/systems/render-system.hpp View File

@ -1,75 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_RENDER_SYSTEM_HPP
#define ANTKEEPER_ECS_RENDER_SYSTEM_HPP
#include "entity-system.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "scene/light.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/light-component.hpp"
#include "ecs/entity.hpp"
#include <unordered_map>
#include <vector>
class renderer;
namespace ecs {
class render_system: public entity_system
{
public:
render_system(ecs::registry& registry);
virtual void update(double t, double dt);
void render(double alpha);
void add_layer(scene::collection* layer);
void remove_layers();
void set_renderer(::renderer* renderer);
scene::model_instance* get_model_instance(ecs::entity entity);
scene::light* get_light(ecs::entity entity);
private:
void update_model_and_materials(ecs::entity entity, ecs::model_component& model);
void update_light(ecs::entity entity, ecs::light_component& component);
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_light_construct(ecs::registry& registry, ecs::entity entity, ecs::light_component& light);
void on_light_replace(ecs::registry& registry, ecs::entity entity, ecs::light_component& light);
void on_light_destroy(ecs::registry& registry, ecs::entity entity);
renderer* renderer;
std::vector<scene::collection*> layers;
std::unordered_map<entity, scene::model_instance*> model_instances;
std::unordered_map<entity, scene::light*> lights;
};
} // namespace ecs
#endif // ANTKEEPER_ECS_RENDER_SYSTEM_HPP

+ 0
- 37
src/ecs/systems/spatial-system.hpp View File

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

+ 0
- 22
src/ecs/systems/updatable-system.cpp View File

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

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

@ -17,16 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_ARCHETYPE_HPP
#define ANTKEEPER_ECS_ARCHETYPE_HPP
#ifndef ANTKEEPER_ENTITY_ARCHETYPE_HPP
#define ANTKEEPER_ENTITY_ARCHETYPE_HPP
#include <entt/entt.hpp>
namespace ecs {
namespace entity {
typedef entt::prototype archetype;
} // namespace ecs
} // namespace entity
#endif // ANTKEEPER_ECS_ARCHETYPE_HPP
#endif // ANTKEEPER_ENTITY_ARCHETYPE_HPP

+ 143
- 0
src/entity/commands.cpp View File

@ -0,0 +1,143 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "entity/commands.hpp"
#include "entity/components/model.hpp"
#include "entity/components/transform.hpp"
#include "entity/components/copy-transform.hpp"
#include "entity/components/snap.hpp"
#include "entity/components/parent.hpp"
#include <limits>
namespace entity {
namespace command {
void translate(entity::registry& registry, entity::id entity_id, const float3& translation)
{
if (registry.has<component::transform>(entity_id))
{
component::transform& transform = registry.get<component::transform>(entity_id);
transform.local.translation += translation;
}
}
void move_to(entity::registry& registry, entity::id entity_id, const float3& position)
{
if (registry.has<component::transform>(entity_id))
{
component::transform& transform = registry.get<component::transform>(entity_id);
transform.local.translation = position;
}
}
void warp_to(entity::registry& registry, entity::id entity_id, const float3& position)
{
if (registry.has<component::transform>(entity_id))
{
component::transform& transform = registry.get<component::transform>(entity_id);
transform.local.translation = position;
transform.warp = true;
}
}
void set_scale(entity::registry& registry, entity::id entity_id, const float3& scale)
{
if (registry.has<component::transform>(entity_id))
{
component::transform& transform = registry.get<component::transform>(entity_id);
transform.local.scale = scale;
}
}
void set_transform(entity::registry& registry, entity::id entity_id, const math::transform<float>& transform, bool warp)
{
if (registry.has<component::transform>(entity_id))
{
component::transform& component = registry.get<component::transform>(entity_id);
component.local = transform;
component.warp = warp;
}
}
void place(entity::registry& registry, entity::id entity_id, const float2& translation)
{
component::snap component;
component.warp = true;
component.relative = false;
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<component::snap>(entity_id, component);
}
void assign_render_layers(entity::registry& registry, entity::id entity_id, unsigned int layers)
{
if (registry.has<component::model>(entity_id))
{
component::model model = registry.get<component::model>(entity_id);
model.layers = layers;
registry.replace<component::model>(entity_id, model);
// Apply to child layers
registry.view<component::parent>().each(
[&](entity::id entity_id, auto& component)
{
if (component.parent == entity_id)
assign_render_layers(registry, entity_id, layers);
});
}
}
void bind_transform(entity::registry& registry, entity::id source, entity::id target)
{
component::copy_transform copy_transform = {target};
registry.assign_or_replace<component::copy_transform>(source, copy_transform);
}
math::transform<float> get_local_transform(entity::registry& registry, entity::id entity_id)
{
if (registry.has<component::transform>(entity_id))
{
const component::transform& component = registry.get<component::transform>(entity_id);
return component.local;
}
return math::identity_transform<float>;
}
math::transform<float> get_world_transform(entity::registry& registry, entity::id entity_id)
{
if (registry.has<component::transform>(entity_id))
{
const component::transform& component = registry.get<component::transform>(entity_id);
return component.world;
}
return math::identity_transform<float>;
}
void parent(entity::registry& registry, entity::id child, entity::id parent)
{
component::parent component;
component.parent = parent;
registry.assign_or_replace<component::parent>(child, component);
}
} // namespace command
} // namespace entity

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

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

src/ecs/components/atmosphere-component.hpp → src/entity/components/atmosphere.hpp View File

@ -17,15 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_ATMOSPHERE_COMPONENT_HPP
#define ANTKEEPER_ECS_ATMOSPHERE_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_ATMOSPHERE_HPP
#define ANTKEEPER_ENTITY_COMPONENT_ATMOSPHERE_HPP
#include "utility/fundamental-types.hpp"
namespace ecs {
namespace entity {
namespace component {
/// Atmosphere
struct atmosphere_component
struct atmosphere
{
/// Altitude of the outer atmosphere, in meters.
double exosphere_altitude;
@ -55,6 +56,7 @@ struct atmosphere_component
double3 mie_scattering;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_ATMOSPHERE_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_ATMOSPHERE_HPP

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

@ -17,19 +17,21 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_BEHAVIOR_COMPONENT_HPP
#define ANTKEEPER_ECS_BEHAVIOR_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_BEHAVIOR_HPP
#define ANTKEEPER_ENTITY_COMPONENT_BEHAVIOR_HPP
#include "ecs/ebt.hpp"
#include "entity/ebt.hpp"
namespace ecs {
namespace entity {
namespace component {
struct behavior_component
struct behavior
{
const ebt::node* behavior_tree;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_BEHAVIOR_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_BEHAVIOR_HPP

src/ecs/components/blackbody-component.hpp → src/entity/components/blackbody.hpp View File

@ -17,13 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_BLACKBODY_COMPONENT_HPP
#define ANTKEEPER_ECS_BLACKBODY_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_BLACKBODY_HPP
#define ANTKEEPER_ENTITY_COMPONENT_BLACKBODY_HPP
namespace ecs {
namespace entity {
namespace component {
/// Blackbody radiator
struct blackbody_component
struct blackbody
{
/// Effective temperature, in Kelvin.
double temperature;
@ -32,6 +33,7 @@ struct blackbody_component
double3 luminous_intensity;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_BLACKBODY_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_BLACKBODY_HPP

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

@ -17,16 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_BRUSH_COMPONENT_HPP
#define ANTKEEPER_ECS_BRUSH_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_BRUSH_HPP
#define ANTKEEPER_ENTITY_COMPONENT_BRUSH_HPP
namespace ecs {
namespace entity {
namespace component {
struct brush_component
struct brush
{
float radius;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_BRUSH_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_BRUSH_HPP

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

@ -17,17 +17,19 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_CAMERA_FOLLOW_COMPONENT_HPP
#define ANTKEEPER_ECS_CAMERA_FOLLOW_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_CAMERA_FOLLOW_HPP
#define ANTKEEPER_ENTITY_COMPONENT_CAMERA_FOLLOW_HPP
namespace ecs {
namespace entity {
namespace component {
struct camera_follow_component
struct camera_follow
{
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_CAMERA_FOLLOW_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_CAMERA_FOLLOW_HPP

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

@ -17,20 +17,22 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_CAVITY_COMPONENT_HPP
#define ANTKEEPER_ECS_CAVITY_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_CAVITY_HPP
#define ANTKEEPER_ENTITY_COMPONENT_CAVITY_HPP
#include "math/math.hpp"
namespace ecs {
namespace entity {
namespace component {
struct cavity_component
struct cavity
{
float3 position;
float radius;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_CAVITY_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_CAVITY_HPP

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

@ -17,13 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_CELESTIAL_BODY_COMPONENT_HPP
#define ANTKEEPER_ECS_CELESTIAL_BODY_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_CELESTIAL_BODY_HPP
#define ANTKEEPER_ENTITY_COMPONENT_CELESTIAL_BODY_HPP
namespace ecs {
namespace entity {
namespace component {
/// A simple celestial body.
struct celestial_body_component
struct celestial_body
{
/// Body radius, in meters.
double radius;
@ -38,6 +39,7 @@ struct celestial_body_component
double angular_frequency;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_CELESTIAL_BODY_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_CELESTIAL_BODY_HPP

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

@ -17,16 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_CHAMBER_COMPONENT_HPP
#define ANTKEEPER_ECS_CHAMBER_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_CHAMBER_HPP
#define ANTKEEPER_ENTITY_COMPONENT_CHAMBER_HPP
#include <array>
#include <unordered_set>
#include "ecs/entity.hpp"
#include "entity/id.hpp"
namespace ecs {
namespace entity {
namespace component {
struct chamber_component
struct chamber
{
entity nest;
float depth;
@ -37,6 +38,7 @@ struct chamber_component
std::unordered_set<std::array<int, 2>> tiles;
}
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_CHAMBER_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_CHAMBER_HPP

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

@ -17,23 +17,25 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_COLLISION_COMPONENT_HPP
#define ANTKEEPER_ECS_COLLISION_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_COLLISION_HPP
#define ANTKEEPER_ENTITY_COMPONENT_COLLISION_HPP
#include "geom/aabb.hpp"
#include "geom/mesh.hpp"
#include "geom/mesh-accelerator.hpp"
namespace ecs {
namespace entity {
namespace component {
struct collision_component
struct collision
{
geom::mesh* mesh;
geom::aabb<float> bounds;
geom::mesh_accelerator mesh_accelerator;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_COLLISION_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_COLLISION_HPP

+ 36
- 0
src/entity/components/copy-rotation.hpp View File

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

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

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

+ 36
- 0
src/entity/components/copy-transform.hpp View File

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

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

@ -17,16 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_COPY_TRANSLATION_COMPONENT_HPP
#define ANTKEEPER_ECS_COPY_TRANSLATION_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_COPY_TRANSLATION_HPP
#define ANTKEEPER_ENTITY_COMPONENT_COPY_TRANSLATION_HPP
#include "ecs/entity.hpp"
#include "entity/id.hpp"
namespace ecs {
namespace entity {
namespace component {
struct copy_translation_component
struct copy_translation
{
entity target;
entity::id target;
bool use_x;
bool use_y;
bool use_z;
@ -35,6 +36,7 @@ struct copy_translation_component
bool invert_z;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_COPY_TRANSLATION_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_COPY_TRANSLATION_HPP

src/ecs/components/diffuse-reflector-component.hpp → src/entity/components/diffuse-reflector.hpp View File

@ -17,16 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_DIFFUSE_REFLECTOR_COMPONENT_HPP
#define ANTKEEPER_ECS_DIFFUSE_REFLECTOR_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_DIFFUSE_REFLECTOR_HPP
#define ANTKEEPER_ENTITY_COMPONENT_DIFFUSE_REFLECTOR_HPP
namespace ecs {
namespace entity {
namespace component {
struct diffuse_reflector_component
struct diffuse_reflector
{
double albedo;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_DIFFUSE_REFLECTOR_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_DIFFUSE_REFLECTOR_HPP

src/ecs/components/light-component.hpp → src/entity/components/light.hpp View File

@ -17,15 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_LIGHT_COMPONENT_HPP
#define ANTKEEPER_ECS_LIGHT_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_LIGHT_HPP
#define ANTKEEPER_ENTITY_COMPONENT_LIGHT_HPP
#include "utility/fundamental-types.hpp"
#include "scene/light.hpp"
namespace ecs {
namespace entity {
namespace component {
struct light_component
struct light
{
scene::light_type type;
float3 color;
@ -34,7 +35,8 @@ struct light_component
float2 cutoff;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_LIGHT_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_LIGHT_HPP

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

@ -17,21 +17,23 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP
#define ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_PLACEMENT_HPP
#define ANTKEEPER_ENTITY_COMPONENT_PLACEMENT_HPP
#include "geom/mesh.hpp"
#include "utility/fundamental-types.hpp"
namespace ecs {
namespace entity {
namespace component {
struct locomotion_component
struct locomotion
{
const geom::mesh::face* triangle;
float3 barycentric_position;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_PLACEMENT_HPP

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

@ -17,16 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_MARKER_COMPONENT_HPP
#define ANTKEEPER_ECS_MARKER_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_MARKER_HPP
#define ANTKEEPER_ENTITY_COMPONENT_MARKER_HPP
namespace ecs {
namespace entity {
namespace component {
struct marker_component
struct marker
{
int color;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_MARKER_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_MARKER_HPP

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

@ -17,23 +17,25 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_MODEL_COMPONENT_HPP
#define ANTKEEPER_ECS_MODEL_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_MODEL_HPP
#define ANTKEEPER_ENTITY_COMPONENT_MODEL_HPP
#include "renderer/model.hpp"
#include <unordered_map>
namespace ecs {
namespace entity {
namespace component {
struct model_component
struct model
{
model* model;
::model* render_model;
std::unordered_map<int, material*> materials;
int instance_count;
unsigned int layers;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_MODEL_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_MODEL_HPP

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

@ -17,23 +17,25 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_NEST_COMPONENT_HPP
#define ANTKEEPER_ECS_NEST_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_NEST_HPP
#define ANTKEEPER_ENTITY_COMPONENT_NEST_HPP
#include <vector>
#include "ecs/entity.hpp"
#include "entity/id.hpp"
namespace ecs {
namespace entity {
namespace component {
struct nest_component
struct nest
{
std::vector<entity> chambers;
std::vector<entity::id> chambers;
float helix_radius;
float helix_pitch;
float helix_chirality;
float helix_turns;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_NEST_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_NEST_HPP

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

@ -17,20 +17,22 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_ORBIT_COMPONENT_HPP
#define ANTKEEPER_ECS_ORBIT_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_ORBIT_HPP
#define ANTKEEPER_ENTITY_COMPONENT_ORBIT_HPP
#include "physics/orbit/elements.hpp"
#include "physics/orbit/state.hpp"
namespace ecs {
namespace entity {
namespace component {
struct orbit_component
struct orbit
{
physics::orbit::elements<double> elements;
physics::orbit::state<double> state;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_ORBIT_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_ORBIT_HPP

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

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

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

@ -17,21 +17,23 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_SAMARA_COMPONENT_HPP
#define ANTKEEPER_ECS_SAMARA_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_SAMARA_HPP
#define ANTKEEPER_ENTITY_COMPONENT_SAMARA_HPP
#include "utility/fundamental-types.hpp"
namespace ecs {
namespace entity {
namespace component {
struct samara_component
struct samara
{
float3 direction;
float angle;
float chirality;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_SAMARA_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_SAMARA_HPP

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

@ -17,14 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_SNAP_COMPONENT_HPP
#define ANTKEEPER_ECS_SNAP_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_SNAP_HPP
#define ANTKEEPER_ENTITY_COMPONENT_SNAP_HPP
#include "geom/ray.hpp"
namespace ecs {
namespace entity {
namespace component {
struct snap_component
struct snap
{
geom::ray<float> ray;
bool relative;
@ -32,7 +33,8 @@ struct snap_component
bool autoremove;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_SNAP_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_SNAP_HPP

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

@ -17,19 +17,21 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_TERRAIN_COMPONENT_HPP
#define ANTKEEPER_ECS_TERRAIN_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_TERRAIN_HPP
#define ANTKEEPER_ENTITY_COMPONENT_TERRAIN_HPP
namespace ecs {
namespace entity {
namespace component {
struct terrain_component
struct terrain
{
int subdivisions;
int x;
int z;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_TERRAIN_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_TERRAIN_HPP

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

@ -17,12 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_TOOL_COMPONENT_HPP
#define ANTKEEPER_ECS_TOOL_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_TOOL_HPP
#define ANTKEEPER_ENTITY_COMPONENT_TOOL_HPP
namespace ecs {
namespace entity {
namespace component {
struct tool_component
struct tool
{
bool active;
float idle_distance;
@ -33,7 +34,8 @@ struct tool_component
//float activation_speed;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_TOOL_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_TOOL_HPP

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

@ -17,18 +17,20 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_TRACKABLE_COMPONENT_HPP
#define ANTKEEPER_ECS_TRACKABLE_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_TRACKABLE_HPP
#define ANTKEEPER_ENTITY_COMPONENT_TRACKABLE_HPP
#include "utility/fundamental-types.hpp"
namespace ecs {
namespace entity {
namespace component {
struct trackable_component
struct trackable
{
float distance;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_TRACKABLE_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_TRACKABLE_HPP

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

@ -17,21 +17,23 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_TRANSFORM_COMPONENT_HPP
#define ANTKEEPER_ECS_TRANSFORM_COMPONENT_HPP
#ifndef ANTKEEPER_ENTITY_COMPONENT_TRANSFORM_HPP
#define ANTKEEPER_ENTITY_COMPONENT_TRANSFORM_HPP
#include "math/math.hpp"
namespace ecs {
namespace entity {
namespace component {
struct transform_component
struct transform
{
math::transform<float> local;
math::transform<float> world;
bool warp;
};
} // namespace ecs
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ECS_TRANSFORM_COMPONENT_HPP
#endif // ANTKEEPER_ENTITY_COMPONENT_TRANSFORM_HPP

src/ecs/ebt.cpp → src/entity/ebt.cpp View File

@ -17,11 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ecs/ebt.hpp"
#include "ecs/components/transform-component.hpp"
#include "entity/ebt.hpp"
#include "entity/components/transform.hpp"
#include <iostream>
namespace ecs {
namespace entity {
namespace ebt {
status print(context& context, const std::string& text)
@ -32,13 +32,13 @@ status print(context& context, const std::string& text)
status print_eid(context& context)
{
std::cout << static_cast<std::size_t>(context.entity) << std::endl;
std::cout << static_cast<std::size_t>(context.entity_id) << std::endl;
return status::success;
}
status warp_to(context& context, float x, float y, float z)
{
auto& transform = context.registry->get<transform_component>(context.entity);
auto& transform = context.registry->get<component::transform>(context.entity_id);
transform.local.translation = {x, y, z};
transform.warp = true;
return status::success;
@ -50,4 +50,4 @@ bool is_carrying_food(const context& context)
}
} // namespace ebt
} // namespace ecs
} // namespace entity

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

@ -17,14 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_EBT_HPP
#define ANTKEEPER_ECS_EBT_HPP
#ifndef ANTKEEPER_ENTITY_EBT_HPP
#define ANTKEEPER_ENTITY_EBT_HPP
#include "ai/behavior-tree.hpp"
#include "ecs/entity.hpp"
#include "ecs/registry.hpp"
#include "entity/id.hpp"
#include "entity/registry.hpp"
namespace ecs {
namespace entity {
/// Entity behavior tree (EBT) nodes and context.
namespace ebt {
@ -34,8 +34,8 @@ namespace ebt {
*/
struct context
{
ecs::registry* registry;
ecs::entity entity;
entity::registry* registry;
entity::id entity_id;
};
typedef ai::bt::status status;
@ -60,7 +60,7 @@ status warp_to(context& context, float x, float y, float z);
bool is_carrying_food(const context& context);
} // namespace ebt
} // namespace ecs
} // namespace entity
#endif // ANTKEEPER_ECS_EBT_HPP
#endif // ANTKEEPER_ENTITY_EBT_HPP

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

@ -17,15 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_HPP
#define ANTKEEPER_ECS_HPP
#ifndef ANTKEEPER_ENTITY_HPP
#define ANTKEEPER_ENTITY_HPP
/// Entity-component-system (ECS)
namespace ecs {}
namespace entity {}
#include "archetype.hpp"
#include "commands.hpp"
#include "entity.hpp"
#include "id.hpp"
#include "registry.hpp"
#endif // ANTKEEPER_ECS_HPP
#endif // ANTKEEPER_ENTITY_HPP

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

@ -17,16 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_ENTITY_HPP
#define ANTKEEPER_ECS_ENTITY_HPP
#ifndef ANTKEEPER_ENTITY_ID_HPP
#define ANTKEEPER_ENTITY_ID_HPP
#include <entt/entt.hpp>
namespace ecs {
namespace entity {
/// Entity ID type
typedef entt::entity entity;
typedef entt::entity id;
} // namespace ecs
} // namespace entity
#endif // ANTKEEPER_ECS_ENTITY_HPP
#endif // ANTKEEPER_ENTITY_ID_HPP

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

@ -17,16 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_REGISTRY_HPP
#define ANTKEEPER_ECS_REGISTRY_HPP
#ifndef ANTKEEPER_ENTITY_REGISTRY_HPP
#define ANTKEEPER_ENTITY_REGISTRY_HPP
#include <entt/entt.hpp>
namespace ecs {
namespace entity {
/// Component registry type
typedef entt::registry registry;
} // namespace ecs
} // namespace entity
#endif // ANTKEEPER_ECS_REGISTRY_HPP
#endif // ANTKEEPER_ENTITY_REGISTRY_HPP

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

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ecs/systems/astronomy-system.hpp"
#include "entity/systems/astronomy.hpp"
#include "astro/apparent-size.hpp"
#include "ecs/components/blackbody-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "entity/components/blackbody.hpp"
#include "entity/components/transform.hpp"
#include "geom/intersection.hpp"
#include "color/color.hpp"
#include "physics/orbit/orbit.hpp"
@ -32,7 +32,8 @@
#include "geom/cartesian.hpp"
#include <iostream>
namespace ecs {
namespace entity {
namespace system {
template <class T>
math::vector3<T> transmittance(T depth_r, T depth_m, T depth_o, const math::vector3<T>& beta_r, const math::vector3<T>& beta_m)
@ -49,8 +50,8 @@ math::vector3 transmittance(T depth_r, T depth_m, T depth_o, const math::vect
return t;
}
astronomy_system::astronomy_system(ecs::registry& registry):
entity_system(registry),
astronomy::astronomy(entity::registry& registry):
updatable(registry),
universal_time(0.0),
time_scale(1.0),
reference_entity(entt::null),
@ -75,11 +76,11 @@ astronomy_system::astronomy_system(ecs::registry& registry):
// Construct reference frame which transforms coordinates from EZS to SEZ
ezs_to_sez = sez_to_ezs.inverse();
registry.on_construct<ecs::celestial_body_component>().connect<&astronomy_system::on_celestial_body_construct>(this);
registry.on_replace<ecs::celestial_body_component>().connect<&astronomy_system::on_celestial_body_replace>(this);
registry.on_construct<entity::component::celestial_body>().connect<&astronomy::on_celestial_body_construct>(this);
registry.on_replace<entity::component::celestial_body>().connect<&astronomy::on_celestial_body_replace>(this);
}
void astronomy_system::update(double t, double dt)
void astronomy::update(double t, double dt)
{
// Add scaled timestep to current time
set_universal_time(universal_time + dt * time_scale);
@ -104,8 +105,8 @@ void astronomy_system::update(double t, double dt)
inertial_to_topocentric = inertial_to_bcbf * bcbf_to_topocentric;
// Set the transform component translations of orbiting bodies to their topocentric positions
registry.view<celestial_body_component, orbit_component, transform_component>().each(
[&](ecs::entity entity, const auto& celestial_body, const auto& orbit, auto& transform)
registry.view<component::celestial_body, component::orbit, component::transform>().each(
[&](entity::id entity_id, const auto& celestial_body, const auto& orbit, auto& transform)
{
// Transform Cartesian position vector (r) from inertial space to topocentric space
const math::vector3<double> r_topocentric = inertial_to_topocentric * orbit.state.r;
@ -115,8 +116,8 @@ void astronomy_system::update(double t, double dt)
});
// Update blackbody lighting
registry.view<celestial_body_component, orbit_component, blackbody_component>().each(
[&](ecs::entity entity, const auto& celestial_body, const auto& orbit, const auto& blackbody)
registry.view<component::celestial_body, component::orbit, component::blackbody>().each(
[&](entity::id entity_id, const auto& celestial_body, const auto& orbit, const auto& blackbody)
{
// Calculate blackbody inertial basis
double3 blackbody_forward_inertial = math::normalize(reference_orbit->state.r - orbit.state.r);
@ -219,67 +220,67 @@ void astronomy_system::update(double t, double dt)
}
}
void astronomy_system::set_universal_time(double time)
void astronomy::set_universal_time(double time)
{
universal_time = time;
}
void astronomy_system::set_time_scale(double scale)
void astronomy::set_time_scale(double scale)
{
time_scale = scale;
}
void astronomy_system::set_reference_body(ecs::entity entity)
void astronomy::set_reference_body(entity::id entity_id)
{
reference_entity = entity;
reference_entity = entity_id;
reference_orbit = nullptr;
reference_body = nullptr;
reference_atmosphere = nullptr;
if (reference_entity != entt::null)
{
if (registry.has<ecs::orbit_component>(reference_entity))
reference_orbit = &registry.get<ecs::orbit_component>(reference_entity);
if (registry.has<entity::component::orbit>(reference_entity))
reference_orbit = &registry.get<entity::component::orbit>(reference_entity);
if (registry.has<ecs::celestial_body_component>(reference_entity))
reference_body = &registry.get<ecs::celestial_body_component>(reference_entity);
if (registry.has<entity::component::celestial_body>(reference_entity))
reference_body = &registry.get<entity::component::celestial_body>(reference_entity);
if (registry.has<ecs::atmosphere_component>(reference_entity))
reference_atmosphere = &registry.get<ecs::atmosphere_component>(reference_entity);
if (registry.has<entity::component::atmosphere>(reference_entity))
reference_atmosphere = &registry.get<entity::component::atmosphere>(reference_entity);
}
update_bcbf_to_topocentric();
}
void astronomy_system::set_observer_location(const double3& location)
void astronomy::set_observer_location(const double3& location)
{
observer_location = location;
update_bcbf_to_topocentric();
}
void astronomy_system::set_sun_light(scene::directional_light* light)
void astronomy::set_sun_light(scene::directional_light* light)
{
sun_light = light;
}
void astronomy_system::set_sky_pass(::sky_pass* pass)
void astronomy::set_sky_pass(::sky_pass* pass)
{
this->sky_pass = pass;
}
void astronomy_system::on_celestial_body_construct(ecs::registry& registry, ecs::entity entity, ecs::celestial_body_component& celestial_body)
void astronomy::on_celestial_body_construct(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body)
{
if (entity == reference_entity)
if (entity_id == reference_entity)
update_bcbf_to_topocentric();
}
void astronomy_system::on_celestial_body_replace(ecs::registry& registry, ecs::entity entity, ecs::celestial_body_component& celestial_body)
void astronomy::on_celestial_body_replace(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body)
{
if (entity == reference_entity)
if (entity_id == reference_entity)
update_bcbf_to_topocentric();
}
void astronomy_system::update_bcbf_to_topocentric()
void astronomy::update_bcbf_to_topocentric()
{
double radial_distance = observer_location[0];
@ -297,4 +298,5 @@ void astronomy_system::update_bcbf_to_topocentric()
) * sez_to_ezs;
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,29 +17,30 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP
#define ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_ASTRONOMY_HPP
#define ANTKEEPER_ENTITY_SYSTEM_ASTRONOMY_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/updatable.hpp"
#include "entity/id.hpp"
#include "scene/directional-light.hpp"
#include "utility/fundamental-types.hpp"
#include "physics/frame.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "ecs/components/atmosphere-component.hpp"
#include "ecs/components/celestial-body-component.hpp"
#include "ecs/components/orbit-component.hpp"
#include "entity/components/atmosphere.hpp"
#include "entity/components/celestial-body.hpp"
#include "entity/components/orbit.hpp"
namespace ecs {
namespace entity {
namespace system {
/**
* Calculates apparent properties of celestial bodies relative to an observer.
*/
class astronomy_system:
public entity_system
class astronomy:
public updatable
{
public:
astronomy_system(ecs::registry& registry);
astronomy(entity::registry& registry);
/**
* Scales then adds the timestep `dt` to the current time, then recalculates the positions of celestial bodies.
@ -68,7 +69,7 @@ public:
*
* @param entity Entity of the reference body.
*/
void set_reference_body(ecs::entity entity);
void set_reference_body(entity::id entity_id);
/**
* Sets the location of the observer using spherical coordinates in BCBF space.
@ -82,18 +83,18 @@ public:
void set_sky_pass(sky_pass* pass);
private:
void on_celestial_body_construct(ecs::registry& registry, ecs::entity entity, ecs::celestial_body_component& celestial_body);
void on_celestial_body_replace(ecs::registry& registry, ecs::entity entity, ecs::celestial_body_component& celestial_body);
void on_celestial_body_construct(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body);
void on_celestial_body_replace(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body);
void update_bcbf_to_topocentric();
double universal_time;
double time_scale;
ecs::entity reference_entity;
const ecs::orbit_component* reference_orbit;
const ecs::celestial_body_component* reference_body;
const ecs::atmosphere_component* reference_atmosphere;
entity::id reference_entity;
const entity::component::orbit* reference_orbit;
const entity::component::celestial_body* reference_body;
const entity::component::atmosphere* reference_atmosphere;
double3 observer_location;
@ -107,6 +108,7 @@ private:
sky_pass* sky_pass;
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_ASTRONOMY_HPP

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

@ -17,37 +17,38 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ecs/systems/atmosphere-system.hpp"
#include "entity/systems/atmosphere.hpp"
#include "physics/atmosphere.hpp"
namespace ecs {
namespace entity {
namespace system {
atmosphere_system::atmosphere_system(ecs::registry& registry):
entity_system(registry),
atmosphere::atmosphere(entity::registry& registry):
updatable(registry),
rgb_wavelengths_nm{0, 0, 0},
rgb_wavelengths_m{0, 0, 0}
{
registry.on_construct<ecs::atmosphere_component>().connect<&atmosphere_system::on_atmosphere_construct>(this);
registry.on_replace<ecs::atmosphere_component>().connect<&atmosphere_system::on_atmosphere_replace>(this);
registry.on_construct<entity::component::atmosphere>().connect<&atmosphere::on_atmosphere_construct>(this);
registry.on_replace<entity::component::atmosphere>().connect<&atmosphere::on_atmosphere_replace>(this);
}
void atmosphere_system::update(double t, double dt)
void atmosphere::update(double t, double dt)
{}
void atmosphere_system::set_rgb_wavelengths(const double3& wavelengths)
void atmosphere::set_rgb_wavelengths(const double3& wavelengths)
{
rgb_wavelengths_nm = wavelengths;
rgb_wavelengths_m = wavelengths * 1e-9;
}
void atmosphere_system::update_coefficients(ecs::entity entity)
void atmosphere::update_coefficients(entity::id entity_id)
{
// Abort if entity has no atmosphere component
if (!registry.has<atmosphere_component>(entity))
if (!registry.has<component::atmosphere>(entity_id))
return;
// Get atmosphere component of the entity
atmosphere_component& atmosphere = registry.get<atmosphere_component>(entity);
component::atmosphere& atmosphere = registry.get<component::atmosphere>(entity_id);
// Calculate polarization factors
const double rayleigh_polarization = physics::atmosphere::polarization(atmosphere.index_of_refraction, atmosphere.rayleigh_density);
@ -71,14 +72,15 @@ void atmosphere_system::update_coefficients(ecs::entity entity)
};
}
void atmosphere_system::on_atmosphere_construct(ecs::registry& registry, ecs::entity entity, ecs::atmosphere_component& atmosphere)
void atmosphere::on_atmosphere_construct(entity::registry& registry, entity::id entity_id, entity::component::atmosphere& atmosphere)
{
update_coefficients(entity);
update_coefficients(entity_id);
}
void atmosphere_system::on_atmosphere_replace(ecs::registry& registry, ecs::entity entity, ecs::atmosphere_component& atmosphere)
void atmosphere::on_atmosphere_replace(entity::registry& registry, entity::id entity_id, entity::component::atmosphere& atmosphere)
{
update_coefficients(entity);
update_coefficients(entity_id);
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,24 +17,25 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_ATMOSPHERE_SYSTEM_HPP
#define ANTKEEPER_ECS_ATMOSPHERE_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_ATMOSPHERE_HPP
#define ANTKEEPER_ENTITY_SYSTEM_ATMOSPHERE_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/updatable.hpp"
#include "entity/id.hpp"
#include "utility/fundamental-types.hpp"
#include "ecs/components/atmosphere-component.hpp"
#include "entity/components/atmosphere.hpp"
namespace ecs {
namespace entity {
namespace system {
/**
* Updates variables related to atmospheric scattering.
*/
class atmosphere_system:
public entity_system
class atmosphere:
public updatable
{
public:
atmosphere_system(ecs::registry& registry);
atmosphere(entity::registry& registry);
virtual void update(double t, double dt);
@ -46,15 +47,16 @@ public:
void set_rgb_wavelengths(const double3& wavelengths);
private:
void update_coefficients(ecs::entity entity);
void update_coefficients(entity::id entity_id);
void on_atmosphere_construct(ecs::registry& registry, ecs::entity entity, ecs::atmosphere_component& atmosphere);
void on_atmosphere_replace(ecs::registry& registry, ecs::entity entity, ecs::atmosphere_component& atmosphere);
void on_atmosphere_construct(entity::registry& registry, entity::id entity_id, entity::component::atmosphere& atmosphere);
void on_atmosphere_replace(entity::registry& registry, entity::id entity_id, entity::component::atmosphere& atmosphere);
double3 rgb_wavelengths_nm;
double3 rgb_wavelengths_m;
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_ATMOSPHERE_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_ATMOSPHERE_HPP

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

@ -17,30 +17,32 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ecs/systems/behavior-system.hpp"
#include "ecs/components/behavior-component.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/behavior.hpp"
#include "entity/components/behavior.hpp"
#include "entity/id.hpp"
namespace ecs {
namespace entity {
namespace system {
behavior_system::behavior_system(ecs::registry& registry):
entity_system(registry)
behavior::behavior(entity::registry& registry):
updatable(registry)
{}
void behavior_system::update(double t, double dt)
void behavior::update(double t, double dt)
{
ebt::context context;
context.registry = &registry;
registry.view<behavior_component>().each(
[&](ecs::entity entity, auto& behavior)
registry.view<component::behavior>().each(
[&](entity::id entity_id, auto& behavior)
{
if (behavior.behavior_tree)
{
context.entity = entity;
context.entity_id = entity_id;
behavior.behavior_tree->execute(context);
}
});
}
} // namespace ecs
} // namespace system
} // namespace entity

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

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

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

@ -17,16 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ecs/systems/blackbody-system.hpp"
#include "entity/systems/blackbody.hpp"
#include "color/color.hpp"
#include "physics/light/blackbody.hpp"
#include "physics/light/photometry.hpp"
#include "math/quadrature.hpp"
namespace ecs {
namespace entity {
namespace system {
blackbody_system::blackbody_system(ecs::registry& registry):
entity_system(registry),
blackbody::blackbody(entity::registry& registry):
updatable(registry),
rgb_wavelengths_nm{0, 0, 0},
rgb_wavelengths_m{0, 0, 0}
{
@ -34,40 +35,40 @@ blackbody_system::blackbody_system(ecs::registry& registry):
visible_wavelengths_nm.resize(780 - 280);
std::iota(visible_wavelengths_nm.begin(), visible_wavelengths_nm.end(), 280);
registry.on_construct<ecs::blackbody_component>().connect<&blackbody_system::on_blackbody_construct>(this);
registry.on_replace<ecs::blackbody_component>().connect<&blackbody_system::on_blackbody_replace>(this);
registry.on_construct<entity::component::blackbody>().connect<&blackbody::on_blackbody_construct>(this);
registry.on_replace<entity::component::blackbody>().connect<&blackbody::on_blackbody_replace>(this);
registry.on_construct<ecs::celestial_body_component>().connect<&blackbody_system::on_celestial_body_construct>(this);
registry.on_replace<ecs::celestial_body_component>().connect<&blackbody_system::on_celestial_body_replace>(this);
registry.on_construct<entity::component::celestial_body>().connect<&blackbody::on_celestial_body_construct>(this);
registry.on_replace<entity::component::celestial_body>().connect<&blackbody::on_celestial_body_replace>(this);
}
void blackbody_system::update(double t, double dt)
void blackbody::update(double t, double dt)
{}
void blackbody_system::set_rgb_wavelengths(const double3& wavelengths)
void blackbody::set_rgb_wavelengths(const double3& wavelengths)
{
rgb_wavelengths_nm = wavelengths;
rgb_wavelengths_m = wavelengths * 1e-9;
}
void blackbody_system::update_luminous_intensity(ecs::entity entity)
void blackbody::update_luminous_intensity(entity::id entity_id)
{
// Abort if entity has no blackbody component
if (!registry.has<blackbody_component>(entity))
if (!registry.has<component::blackbody>(entity_id))
return;
// Get blackbody component of the entity
blackbody_component& blackbody = registry.get<blackbody_component>(entity);
component::blackbody& blackbody = registry.get<component::blackbody>(entity_id);
// Clear luminous intensity
blackbody.luminous_intensity = {0, 0, 0};
// Abort if entity has no celestial body component
if (!registry.has<celestial_body_component>(entity))
if (!registry.has<component::celestial_body>(entity_id))
return;
// Get celestial body component of the entity
const celestial_body_component& celestial_body = registry.get<celestial_body_component>(entity);
const component::celestial_body& celestial_body = registry.get<component::celestial_body>(entity_id);
// Calculate (spherical) surface area of the celestial body
const double surface_area = 4.0 * math::pi<double> * celestial_body.radius * celestial_body.radius;
@ -92,24 +93,25 @@ void blackbody_system::update_luminous_intensity(ecs::entity entity)
blackbody.luminous_intensity = math::quadrature::simpson(rgb_luminous_intensity, visible_wavelengths_nm.begin(), visible_wavelengths_nm.end());
}
void blackbody_system::on_blackbody_construct(ecs::registry& registry, ecs::entity entity, ecs::blackbody_component& blackbody)
void blackbody::on_blackbody_construct(entity::registry& registry, entity::id entity_id, entity::component::blackbody& blackbody)
{
update_luminous_intensity(entity);
update_luminous_intensity(entity_id);
}
void blackbody_system::on_blackbody_replace(ecs::registry& registry, ecs::entity entity, ecs::blackbody_component& blackbody)
void blackbody::on_blackbody_replace(entity::registry& registry, entity::id entity_id, entity::component::blackbody& blackbody)
{
update_luminous_intensity(entity);
update_luminous_intensity(entity_id);
}
void blackbody_system::on_celestial_body_construct(ecs::registry& registry, ecs::entity entity, ecs::celestial_body_component& celestial_body)
void blackbody::on_celestial_body_construct(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body)
{
update_luminous_intensity(entity);
update_luminous_intensity(entity_id);
}
void blackbody_system::on_celestial_body_replace(ecs::registry& registry, ecs::entity entity, ecs::celestial_body_component& celestial_body)
void blackbody::on_celestial_body_replace(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body)
{
update_luminous_intensity(entity);
update_luminous_intensity(entity_id);
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,26 +17,27 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_BLACKBODY_SYSTEM_HPP
#define ANTKEEPER_ECS_BLACKBODY_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_BLACKBODY_HPP
#define ANTKEEPER_ENTITY_SYSTEM_BLACKBODY_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/updatable.hpp"
#include "entity/id.hpp"
#include "utility/fundamental-types.hpp"
#include "ecs/components/blackbody-component.hpp"
#include "ecs/components/celestial-body-component.hpp"
#include "entity/components/blackbody.hpp"
#include "entity/components/celestial-body.hpp"
#include <vector>
namespace ecs {
namespace entity {
namespace system {
/**
* Calculates the RGB luminous intensity of blackbody radiators.
*/
class blackbody_system:
public entity_system
class blackbody:
public updatable
{
public:
blackbody_system(ecs::registry& registry);
blackbody(entity::registry& registry);
virtual void update(double t, double dt);
@ -48,19 +49,20 @@ public:
void set_rgb_wavelengths(const double3& wavelengths);
private:
void update_luminous_intensity(ecs::entity entity);
void update_luminous_intensity(entity::id entity_id);
void on_blackbody_construct(ecs::registry& registry, ecs::entity entity, ecs::blackbody_component& blackbody);
void on_blackbody_replace(ecs::registry& registry, ecs::entity entity, ecs::blackbody_component& blackbody);
void on_blackbody_construct(entity::registry& registry, entity::id entity_id, entity::component::blackbody& blackbody);
void on_blackbody_replace(entity::registry& registry, entity::id entity_id, entity::component::blackbody& blackbody);
void on_celestial_body_construct(ecs::registry& registry, ecs::entity entity, ecs::celestial_body_component& celestial_body);
void on_celestial_body_replace(ecs::registry& registry, ecs::entity entity, ecs::celestial_body_component& celestial_body);
void on_celestial_body_construct(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body);
void on_celestial_body_replace(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body);
double3 rgb_wavelengths_nm;
double3 rgb_wavelengths_m;
std::vector<double> visible_wavelengths_nm;
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_BLACKBODY_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_BLACKBODY_HPP

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

@ -17,19 +17,20 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "camera-system.hpp"
#include "ecs/components/camera-follow-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/entity.hpp"
#include "camera.hpp"
#include "entity/components/camera-follow.hpp"
#include "entity/components/transform.hpp"
#include "entity/id.hpp"
#include "math/math.hpp"
#include <algorithm>
#include <cmath>
namespace ecs {
namespace entity {
namespace system {
camera_system::camera_system(ecs::registry& registry):
entity_system(registry),
camera(nullptr),
camera::camera(entity::registry& registry):
updatable(registry),
active_camera(nullptr),
viewport{0, 0, 0, 0},
mouse_position{0, 0}
{
@ -53,16 +54,16 @@ camera_system::camera_system(ecs::registry& registry):
orbit_cam.reset_springs();
}
void camera_system::update(double t, double dt)
void camera::update(double t, double dt)
{
if (!camera)
if (!active_camera)
return;
// Determine target focal point
int subject_count = 0;
float3 target_focal_point = {0, 0, 0};
registry.view<camera_follow_component, transform_component>().each(
[&](ecs::entity entity, auto& follow, auto& transform)
registry.view<component::camera_follow, component::transform>().each(
[&](entity::id entity_id, auto& follow, auto& transform)
{
target_focal_point += transform.local.translation;
++subject_count;
@ -80,27 +81,27 @@ void camera_system::update(double t, double dt)
orbit_cam.update(static_cast<float>(dt));
}
void camera_system::pan(float angle)
void camera::pan(float angle)
{
orbit_cam.pan(angle);
}
void camera_system::tilt(float angle)
void camera::tilt(float angle)
{
orbit_cam.tilt(angle);
}
void camera_system::zoom(float factor)
void camera::zoom(float factor)
{
orbit_cam.zoom(factor);
}
void camera_system::set_camera(scene::camera* camera)
void camera::set_camera(scene::camera* active_camera)
{
this->camera = camera;
if (camera)
this->active_camera = active_camera;
if (active_camera)
{
orbit_cam.attach(camera);
orbit_cam.attach(active_camera);
}
else
{
@ -108,21 +109,22 @@ void camera_system::set_camera(scene::camera* camera)
}
}
void camera_system::set_viewport(const float4& viewport)
void camera::set_viewport(const float4& viewport)
{
this->viewport = viewport;
orbit_cam.set_aspect_ratio(viewport[2] / viewport[3]);
}
void camera_system::handle_event(const mouse_moved_event& event)
void camera::handle_event(const mouse_moved_event& event)
{
mouse_position[0] = event.x;
mouse_position[1] = event.y;
}
void camera_system::handle_event(const window_resized_event& event)
void camera::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_CAMERA_SYSTEM_HPP
#define ANTKEEPER_ECS_CAMERA_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_CAMERA_HPP
#define ANTKEEPER_ENTITY_SYSTEM_CAMERA_HPP
#include "entity-system.hpp"
#include "entity/systems/updatable.hpp"
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
@ -32,10 +32,11 @@
class orbit_cam;
namespace ecs {
namespace entity {
namespace system {
class camera_system:
public entity_system,
class camera:
public updatable,
public event_handler<mouse_moved_event>,
public event_handler<window_resized_event>
{
@ -43,14 +44,14 @@ public:
typedef math::quaternion<float> quaternion_type;
typedef math::transform<float> transform_type;
camera_system(ecs::registry& registry);
camera(entity::registry& registry);
virtual void update(double t, double dt);
void pan(float angle);
void tilt(float angle);
void zoom(float factor);
void set_camera(scene::camera* camera);
void set_camera(scene::camera* active_camera);
void set_viewport(const float4& viewport);
const orbit_cam* get_orbit_cam() const;
@ -62,29 +63,30 @@ private:
virtual void handle_event(const mouse_moved_event& event);
virtual void handle_event(const window_resized_event& event);
scene::camera* camera;
scene::camera* active_camera;
float4 viewport;
float2 mouse_position;
orbit_cam orbit_cam;
};
inline const orbit_cam* camera_system::get_orbit_cam() const
inline const orbit_cam* camera::get_orbit_cam() const
{
return &orbit_cam;
}
inline orbit_cam* camera_system::get_orbit_cam()
inline orbit_cam* camera::get_orbit_cam()
{
return &orbit_cam;
}
inline scene::camera* camera_system::get_camera()
inline scene::camera* camera::get_camera()
{
return camera;
return active_camera;
}
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_CAMERA_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_CAMERA_HPP

+ 47
- 0
src/entity/systems/collision.cpp View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "collision.hpp"
#include "entity/components/transform.hpp"
namespace entity {
namespace system {
collision::collision(entity::registry& registry):
updatable(registry)
{
registry.on_construct<component::collision>().connect<&collision::on_collision_construct>(this);
registry.on_replace<component::collision>().connect<&collision::on_collision_replace>(this);
registry.on_destroy<component::collision>().connect<&collision::on_collision_destroy>(this);
}
void collision::update(double t, double dt)
{}
void collision::on_collision_construct(entity::registry& registry, entity::id entity_id, component::collision& collision)
{}
void collision::on_collision_replace(entity::registry& registry, entity::id entity_id, component::collision& collision)
{}
void collision::on_collision_destroy(entity::registry& registry, entity::id entity_id)
{}
} // namespace system
} // namespace entity

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

@ -17,31 +17,33 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_COLLISION_SYSTEM_HPP
#define ANTKEEPER_ECS_COLLISION_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_COLLISION_HPP
#define ANTKEEPER_ENTITY_SYSTEM_COLLISION_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "ecs/components/collision-component.hpp"
#include "entity/systems/updatable.hpp"
#include "entity/id.hpp"
#include "entity/components/collision.hpp"
namespace ecs {
namespace entity {
namespace system {
/**
* 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.
*/
class collision_system: public entity_system
class collision: public updatable
{
public:
collision_system(ecs::registry& registry);
collision(entity::registry& registry);
virtual void update(double t, double dt);
private:
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);
void on_collision_construct(entity::registry& registry, entity::id entity_id, entity::component::collision& collision);
void on_collision_replace(entity::registry& registry, entity::id entity_id, entity::component::collision& collision);
void on_collision_destroy(entity::registry& registry, entity::id entity_id);
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_COLLISION_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_COLLISION_HPP

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

@ -17,30 +17,31 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "constraint-system.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 "constraint.hpp"
#include "entity/components/copy-translation.hpp"
#include "entity/components/copy-rotation.hpp"
#include "entity/components/copy-scale.hpp"
#include "entity/components/copy-transform.hpp"
#include "entity/components/transform.hpp"
#include "utility/fundamental-types.hpp"
namespace ecs {
namespace entity {
namespace system {
constraint_system::constraint_system(ecs::registry& registry):
entity_system(registry)
constraint::constraint(entity::registry& registry):
updatable(registry)
{}
void constraint_system::update(double t, double dt)
void constraint::update(double t, double dt)
{
auto transforms_view = registry.view<transform_component>();
auto transforms_view = registry.view<component::transform>();
// Handle copy translation constraints
registry.view<copy_translation_component, transform_component>().each
registry.view<component::copy_translation, component::transform>().each
(
[&](ecs::entity entity, auto& constraint, auto& transform)
[&](entity::id entity_id, auto& constraint, auto& transform)
{
if (this->registry.has<transform_component>(constraint.target))
if (this->registry.has<component::transform>(constraint.target))
{
const float3& target_translation = transforms_view.get(constraint.target).world.translation;
if (constraint.use_x)
@ -54,11 +55,11 @@ void constraint_system::update(double t, double dt)
);
// Handle copy rotation constraints
registry.view<copy_rotation_component, transform_component>().each
registry.view<component::copy_rotation, component::transform>().each
(
[&](ecs::entity entity, auto& constraint, auto& transform)
[&](entity::id entity_id, auto& constraint, auto& transform)
{
if (this->registry.has<transform_component>(constraint.target))
if (this->registry.has<component::transform>(constraint.target))
{
transform.world.rotation = transforms_view.get(constraint.target).world.rotation;
}
@ -66,11 +67,11 @@ void constraint_system::update(double t, double dt)
);
// Handle copy scale constraints
registry.view<copy_scale_component, transform_component>().each
registry.view<component::copy_scale, component::transform>().each
(
[&](ecs::entity entity, auto& constraint, auto& transform)
[&](entity::id entity_id, auto& constraint, auto& transform)
{
if (this->registry.has<transform_component>(constraint.target))
if (this->registry.has<component::transform>(constraint.target))
{
const float3& target_scale = transforms_view.get(constraint.target).world.scale;
if (constraint.use_x)
@ -84,11 +85,11 @@ void constraint_system::update(double t, double dt)
);
// Handle copy transform constraints
registry.view<copy_transform_component, transform_component>().each
registry.view<component::copy_transform, component::transform>().each
(
[&](ecs::entity entity, auto& constraint, auto& transform)
[&](entity::id entity_id, auto& constraint, auto& transform)
{
if (this->registry.has<transform_component>(constraint.target))
if (this->registry.has<component::transform>(constraint.target))
{
transform.world = transforms_view.get(constraint.target).world;
}
@ -96,4 +97,5 @@ void constraint_system::update(double t, double dt)
);
}
} // namespace ecs
} // namespace system
} // namespace entity

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

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

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

@ -17,21 +17,22 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "control-system.hpp"
#include "control.hpp"
#include "input/control.hpp"
#include "geom/intersection.hpp"
#include "animation/ease.hpp"
#include "nest.hpp"
#include "math/math.hpp"
#include "ecs/commands.hpp"
#include "ecs/systems/camera-system.hpp"
#include "entity/commands.hpp"
#include "entity/systems/camera.hpp"
#include "animation/orbit-cam.hpp"
#include "../../nest.hpp"
#include <iostream>
namespace ecs {
namespace entity {
namespace system {
control_system::control_system(ecs::registry& registry):
entity_system(registry),
control::control(entity::registry& registry):
updatable(registry),
timestep(0.0f),
zoom(0.0f),
tool(nullptr),
@ -97,7 +98,7 @@ control_system::control_system(ecs::registry& registry):
flashlight_turns_f = 0.0f;
}
void control_system::update(double t, double dt)
void control::update(double t, double dt)
{
timestep = dt;
@ -193,42 +194,42 @@ void control_system::update(double t, double dt)
}
}
void control_system::set_camera_system(ecs::camera_system* camera_system)
void control::set_camera_system(system::camera* camera_system)
{
this->camera_system = camera_system;
}
void control_system::set_nest(::nest* nest)
void control::set_nest(::nest* nest)
{
this->nest = nest;
}
void control_system::set_tool(scene::model_instance* tool)
void control::set_tool(scene::model_instance* tool)
{
this->tool = tool;
}
void control_system::set_flashlight(ecs::entity entity)
void control::set_flashlight(entity::id entity_id)
{
flashlight_entity = entity;
flashlight_entity = entity_id;
}
void control_system::set_camera_subject(ecs::entity entity)
void control::set_camera_subject(entity::id entity_id)
{
camera_subject_entity = entity;
camera_subject_entity = entity_id;
}
void control_system::set_viewport(const float4& viewport)
void control::set_viewport(const float4& viewport)
{
this->viewport = viewport;
}
void control_system::set_underworld_camera(scene::camera* camera)
void control::set_underworld_camera(scene::camera* camera)
{
this->underworld_camera = camera;
}
void control_system::handle_event(const mouse_moved_event& event)
void control::handle_event(const mouse_moved_event& event)
{
if (adjust_camera_control.is_active())
{
@ -261,9 +262,10 @@ void control_system::handle_event(const mouse_moved_event& event)
}
}
void control_system::handle_event(const window_resized_event& event)
void control::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,11 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_CONTROL_SYSTEM_HPP
#define ANTKEEPER_ECS_CONTROL_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP
#define ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP
#include "ecs/systems/entity-system.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/updatable.hpp"
#include "entity/id.hpp"
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
@ -33,28 +33,29 @@
class nest;
namespace ecs {
namespace entity {
namespace system {
class camera_system;
class camera;
class control_system:
public entity_system,
class control:
public updatable,
public event_handler<mouse_moved_event>,
public event_handler<window_resized_event>
{
public:
control_system(ecs::registry& registry);
control(entity::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(ecs::camera_system* camera_system);
void set_camera_system(system::camera* camera_system);
void set_nest(::nest* nest);
void set_tool(scene::model_instance* tool);
void set_flashlight(ecs::entity entity);
void set_camera_subject(ecs::entity entity);
void set_flashlight(entity::id entity_id);
void set_camera_subject(entity::id entity_id);
void set_viewport(const float4& viewport);
void set_underworld_camera(scene::camera* camera);
@ -139,14 +140,14 @@ private:
float timestep;
float zoom;
camera_system* camera_system;
system::camera* camera_system;
::nest* nest;
scene::model_instance* tool;
float2 mouse_position;
float4 viewport;
entity flashlight_entity;
entity camera_subject_entity;
entity::id flashlight_entity;
entity::id camera_subject_entity;
scene::camera* underworld_camera;
float mouse_angle;
@ -156,152 +157,153 @@ private:
float flashlight_turns_f;
};
inline input::control_set* control_system::get_control_set()
inline input::control_set* control::get_control_set()
{
return &control_set;
}
inline input::control* control_system::get_move_forward_control()
inline input::control* control::get_move_forward_control()
{
return &move_forward_control;
}
inline input::control* control_system::get_move_back_control()
inline input::control* control::get_move_back_control()
{
return &move_back_control;
}
inline input::control* control_system::get_move_left_control()
inline input::control* control::get_move_left_control()
{
return &move_left_control;
}
inline input::control* control_system::get_move_right_control()
inline input::control* control::get_move_right_control()
{
return &move_right_control;
}
inline input::control* control_system::get_rotate_ccw_control()
inline input::control* control::get_rotate_ccw_control()
{
return &rotate_ccw_control;
}
inline input::control* control_system::get_rotate_cw_control()
inline input::control* control::get_rotate_cw_control()
{
return &rotate_cw_control;
}
inline input::control* control_system::get_tilt_up_control()
inline input::control* control::get_tilt_up_control()
{
return &tilt_up_control;
}
inline input::control* control_system::get_tilt_down_control()
inline input::control* control::get_tilt_down_control()
{
return &tilt_down_control;
}
inline input::control* control_system::get_zoom_in_control()
inline input::control* control::get_zoom_in_control()
{
return &zoom_in_control;
}
inline input::control* control_system::get_zoom_out_control()
inline input::control* control::get_zoom_out_control()
{
return &zoom_out_control;
}
inline input::control* control_system::get_adjust_camera_control()
inline input::control* control::get_adjust_camera_control()
{
return &adjust_camera_control;
}
inline input::control* control_system::get_ascend_control()
inline input::control* control::get_ascend_control()
{
return &ascend_control;
}
inline input::control* control_system::get_descend_control()
inline input::control* control::get_descend_control()
{
return &descend_control;
}
inline input::control* control_system::get_toggle_view_control()
inline input::control* control::get_toggle_view_control()
{
return &toggle_view_control;
}
inline input::control* control_system::get_tool_menu_control()
inline input::control* control::get_tool_menu_control()
{
return &tool_menu_control;
}
inline input::control* control_system::get_equip_lens_control()
inline input::control* control::get_equip_lens_control()
{
return &equip_lens_control;
}
inline input::control* control_system::get_equip_brush_control()
inline input::control* control::get_equip_brush_control()
{
return &equip_brush_control;
}
inline input::control* control_system::get_equip_forceps_control()
inline input::control* control::get_equip_forceps_control()
{
return &equip_forceps_control;
}
inline input::control* control_system::get_equip_marker_control()
inline input::control* control::get_equip_marker_control()
{
return &equip_marker_control;
}
inline input::control* control_system::get_equip_container_control()
inline input::control* control::get_equip_container_control()
{
return &equip_container_control;
}
inline input::control* control_system::get_equip_twig_control()
inline input::control* control::get_equip_twig_control()
{
return &equip_twig_control;
}
inline input::control* control_system::get_next_marker_control()
inline input::control* control::get_next_marker_control()
{
return &next_marker_control;
}
inline input::control* control_system::get_previous_marker_control()
inline input::control* control::get_previous_marker_control()
{
return &previous_marker_control;
}
inline input::control* control_system::get_use_tool_control()
inline input::control* control::get_use_tool_control()
{
return &use_tool_control;
}
inline input::control* control_system::get_fast_forward_control()
inline input::control* control::get_fast_forward_control()
{
return &fast_forward_control;
}
inline input::control* control_system::get_rewind_control()
inline input::control* control::get_rewind_control()
{
return &rewind_control;
}
inline input::control* control_system::get_exposure_increase_control()
inline input::control* control::get_exposure_increase_control()
{
return &exposure_increase_control;
}
inline input::control* control_system::get_exposure_decrease_control()
inline input::control* control::get_exposure_decrease_control()
{
return &exposure_decrease_control;
}
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_CONTROL_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_CONTROL_HPP

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

@ -17,24 +17,26 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "locomotion-system.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/locomotion-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/entity.hpp"
#include "locomotion.hpp"
#include "entity/components/collision.hpp"
#include "entity/components/locomotion.hpp"
#include "entity/components/transform.hpp"
#include "entity/id.hpp"
namespace ecs {
namespace entity {
namespace system {
locomotion_system::locomotion_system(ecs::registry& registry):
entity_system(registry)
locomotion::locomotion(entity::registry& registry):
updatable(registry)
{}
void locomotion_system::update(double t, double dt)
void locomotion::update(double t, double dt)
{
registry.view<transform_component, locomotion_component>().each(
[&](ecs::entity entity, auto& transform, auto& locomotion)
registry.view<component::transform, component::locomotion>().each(
[&](entity::id entity_id, auto& transform, auto& locomotion)
{
});
}
} // namespace ecs
} // namespace system
} // namespace entity

+ 39
- 0
src/entity/systems/locomotion.hpp View File

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

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

@ -17,30 +17,32 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nest-system.hpp"
#include "nest.hpp"
#include "../../nest.hpp"
#include "math/math.hpp"
namespace ecs {
namespace entity {
namespace system {
nest_system::nest_system(ecs::registry& registry, ::resource_manager* resource_manager):
entity_system(registry),
nest::nest(entity::registry& registry, ::resource_manager* resource_manager):
updatable(registry),
resource_manager(resource_manager)
{
registry.on_construct<nest_component>().connect<&nest_system::on_nest_construct>(this);
registry.on_destroy<nest_component>().connect<&nest_system::on_nest_destroy>(this);
registry.on_construct<component::nest>().connect<&nest::on_nest_construct>(this);
registry.on_destroy<component::nest>().connect<&nest::on_nest_destroy>(this);
}
nest_system::~nest_system()
nest::~nest()
{}
void nest_system::update(double t, double dt)
void nest::update(double t, double dt)
{}
void nest_system::on_nest_construct(ecs::registry& registry, ecs::entity entity, nest_component& component)
void nest::on_nest_construct(entity::registry& registry, entity::id entity_id, component::nest& component)
{
/*
// Allocate a nest
nest* nest = new ::nest();
::nest* nest = new ::nest();
// Setup initial nest parameters
nest->set_tunnel_radius(1.15f);
@ -62,9 +64,11 @@ void nest_system::on_nest_construct(ecs::registry& registry, ecs::entity entity,
chamber.outer_radius = 10.0f;
central_shaft->chambers.push_back(chamber);
}
*/
}
void nest_system::on_nest_destroy(ecs::registry& registry, ecs::entity entity)
void nest::on_nest_destroy(entity::registry& registry, entity::id entity_id)
{}
} // namespace ecs
} // namespace system
} // namespace entity

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

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

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

@ -17,29 +17,30 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ecs/systems/orbit-system.hpp"
#include "ecs/components/orbit-component.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/orbit.hpp"
#include "entity/components/orbit.hpp"
#include "entity/id.hpp"
#include "physics/orbit/orbit.hpp"
namespace ecs {
namespace entity {
namespace system {
orbit_system::orbit_system(ecs::registry& registry):
entity_system(registry),
orbit::orbit(entity::registry& registry):
updatable(registry),
universal_time(0.0),
time_scale(1.0),
ke_iterations(10),
ke_tolerance(1e-6)
{}
void orbit_system::update(double t, double dt)
void orbit::update(double t, double dt)
{
// Add scaled timestep to current time
set_universal_time(universal_time + dt * time_scale);
// Update the orbital state of orbiting bodies
registry.view<orbit_component>().each(
[&](ecs::entity entity, auto& orbit)
registry.view<component::orbit>().each(
[&](entity::id entity_id, auto& orbit)
{
// Calculate semi-minor axis (b)
const double b = physics::orbit::derive_semiminor_axis(orbit.elements.a, orbit.elements.e);
@ -78,14 +79,15 @@ void orbit_system::update(double t, double dt)
});
}
void orbit_system::set_universal_time(double time)
void orbit::set_universal_time(double time)
{
universal_time = time;
}
void orbit_system::set_time_scale(double scale)
void orbit::set_time_scale(double scale)
{
time_scale = scale;
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,22 +17,23 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_SOLAR_SYSTEM_HPP
#define ANTKEEPER_ECS_SOLAR_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_SOLAR_HPP
#define ANTKEEPER_ENTITY_SYSTEM_SOLAR_HPP
#include "entity-system.hpp"
#include "entity/systems/updatable.hpp"
#include "utility/fundamental-types.hpp"
namespace ecs {
namespace entity {
namespace system {
/**
* Updates the Cartesian position and velocity of orbiting bodies given their Keplerian orbital elements and the current time.
*/
class orbit_system:
public entity_system
class orbit:
public updatable
{
public:
orbit_system(ecs::registry& registry);
orbit(entity::registry& registry);
/**
* Scales then adds the timestep `dt` to the current time, then recalculates the positions of orbiting bodies.
@ -63,6 +64,7 @@ private:
double ke_tolerance;
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_SOLAR_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_SOLAR_HPP

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

@ -17,33 +17,34 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "painting-system.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/brush-component.hpp"
#include "ecs/components/tool-component.hpp"
#include "painting.hpp"
#include "entity/components/transform.hpp"
#include "entity/components/brush.hpp"
#include "entity/components/tool.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 "ecs/commands.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "entity/commands.hpp"
#include "entity/components/collision.hpp"
#include "entity/components/transform.hpp"
#include "gl/vertex-buffer.hpp"
#include "gl/vertex-attribute-type.hpp"
#include "renderer/vertex-attributes.hpp"
#include "geom/mesh-functions.hpp"
#include <limits>
namespace ecs {
namespace entity {
namespace system {
painting_system::painting_system(ecs::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
entity_system(registry),
painting::painting(entity::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
updatable(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
scene_collection(nullptr),
painting(false)
is_painting(false)
{
event_dispatcher->subscribe<tool_pressed_event>(this);
event_dispatcher->subscribe<tool_released_event>(this);
@ -87,17 +88,17 @@ painting_system::painting_system(ecs::registry& registry, ::event_dispatcher* ev
midstroke = false;
}
painting_system::~painting_system()
painting::~painting()
{
event_dispatcher->unsubscribe<tool_pressed_event>(this);
event_dispatcher->unsubscribe<tool_released_event>(this);
}
void painting_system::update(double t, double dt)
void painting::update(double t, double dt)
{
if (painting)
if (is_painting)
{
const tool_component& tool = registry.get<tool_component>(brush_entity);
const component::tool& tool = registry.get<component::tool>(brush_entity);
auto cast_result = cast_ray(tool.cursor);
if (cast_result.has_value())
@ -265,22 +266,22 @@ void painting_system::update(double t, double dt)
}
}
void painting_system::set_scene(scene::collection* collection)
void painting::set_scene(scene::collection* collection)
{
this->scene_collection = collection;
scene_collection->add_object(stroke_model_instance);
}
void painting_system::handle_event(const tool_pressed_event& event)
void painting::handle_event(const tool_pressed_event& event)
{
if (registry.has<brush_component>(event.entity))
if (registry.has<component::brush>(event.entity_id))
{
auto cast_result = cast_ray(event.position);
if (cast_result.has_value())
{
brush_entity = event.entity;
painting = true;
brush_entity = event.entity_id;
is_painting = true;
stroke_start = std::get<0>(cast_result.value());
stroke_end = stroke_start;
p0 = stroke_start;
@ -291,11 +292,11 @@ void painting_system::handle_event(const tool_pressed_event& event)
}
}
void painting_system::handle_event(const tool_released_event& event)
void painting::handle_event(const tool_released_event& event)
{
if (registry.has<brush_component>(event.entity))
if (registry.has<component::brush>(event.entity_id))
{
auto cast_result = cast_ray(command::get_world_transform(registry, event.entity).translation);
auto cast_result = cast_ray(command::get_world_transform(registry, event.entity_id).translation);
if (cast_result.has_value())
{
@ -303,11 +304,11 @@ void painting_system::handle_event(const tool_released_event& event)
}
brush_entity = entt::null;
painting = false;
is_painting = false;
}
}
std::optional<std::tuple<float3, float3>> painting_system::cast_ray(const float3& position) const
std::optional<std::tuple<float3, float3>> painting::cast_ray(const float3& position) const
{
std::optional<std::tuple<float3, float3>> result;
@ -318,8 +319,8 @@ std::optional> painting_system::cast_ray(const float3
geom::ray<float> untransformed_ray = {position + float3{0.0f, 10000.0f, 0.0f}, {0, -1, 0}};
float min_distance = std::numeric_limits<float>::infinity();
registry.view<transform_component, collision_component>().each(
[&](ecs::entity entity, auto& collision_transform, auto& collision)
registry.view<component::transform, component::collision>().each(
[&](entity::id entity_id, auto& collision_transform, auto& collision)
{
// Transform ray into local space of collision component
math::transform<float> inverse_transform = math::inverse(collision_transform.local);
@ -356,4 +357,5 @@ std::optional> painting_system::cast_ray(const float3
return result;
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,11 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_PAINTING_SYSTEM_HPP
#define ANTKEEPER_ECS_PAINTING_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_PAINTING_HPP
#define ANTKEEPER_ENTITY_SYSTEM_PAINTING_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/updatable.hpp"
#include "entity/id.hpp"
#include "event/event-handler.hpp"
#include "game/events/tool-events.hpp"
#include "utility/fundamental-types.hpp"
@ -37,15 +37,16 @@ class resource_manager;
class model;
class model_group;
namespace ecs {
namespace entity {
namespace system {
class painting_system: public entity_system,
class painting: public updatable,
public event_handler<tool_pressed_event>,
public event_handler<tool_released_event>
{
public:
painting_system(ecs::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
virtual ~painting_system();
painting(entity::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
virtual ~painting();
virtual void update(double t, double dt);
void set_scene(scene::collection* collection);
@ -60,8 +61,8 @@ private:
resource_manager* resource_manager;
scene::collection* scene_collection;
bool painting;
entity brush_entity;
bool is_painting;
entity::id brush_entity;
float3 stroke_start;
float3 stroke_end;
float min_stroke_length;
@ -89,6 +90,7 @@ private:
scene::model_instance* stroke_model_instance;
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_PAINTING_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_PAINTING_HPP

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

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "render-system.hpp"
#include "ecs/components/transform-component.hpp"
#include "render.hpp"
#include "entity/components/transform.hpp"
#include "renderer/renderer.hpp"
#include "scene/point-light.hpp"
#include "scene/directional-light.hpp"
@ -26,29 +26,30 @@
#include "scene/spot-light.hpp"
#include <iostream>
namespace ecs {
namespace entity {
namespace system {
render_system::render_system(ecs::registry& registry):
entity_system(registry),
render::render(entity::registry& registry):
updatable(registry),
renderer(nullptr)
{
registry.on_construct<model_component>().connect<&render_system::on_model_construct>(this);
registry.on_replace<model_component>().connect<&render_system::on_model_replace>(this);
registry.on_destroy<model_component>().connect<&render_system::on_model_destroy>(this);
registry.on_construct<component::model>().connect<&render::on_model_construct>(this);
registry.on_replace<component::model>().connect<&render::on_model_replace>(this);
registry.on_destroy<component::model>().connect<&render::on_model_destroy>(this);
registry.on_construct<light_component>().connect<&render_system::on_light_construct>(this);
registry.on_replace<light_component>().connect<&render_system::on_light_replace>(this);
registry.on_destroy<light_component>().connect<&render_system::on_light_destroy>(this);
registry.on_construct<component::light>().connect<&render::on_light_construct>(this);
registry.on_replace<component::light>().connect<&render::on_light_replace>(this);
registry.on_destroy<component::light>().connect<&render::on_light_destroy>(this);
}
void render_system::update(double t, double dt)
void render::update(double t, double dt)
{
// Update model instance transforms
registry.view<transform_component, model_component>().each
registry.view<component::transform, component::model>().each
(
[this](ecs::entity entity, auto& transform, auto& model)
[this](entity::id entity_id, auto& transform, auto& model)
{
scene::model_instance* instance = model_instances[entity];
scene::model_instance* instance = model_instances[entity_id];
instance->set_transform(transform.world);
if (transform.warp)
@ -61,11 +62,11 @@ void render_system::update(double t, double dt)
);
// Update light transforms
registry.view<transform_component, light_component>().each
registry.view<component::transform, component::light>().each
(
[this](ecs::entity entity, auto& transform, auto& light)
[this](entity::id entity_id, auto& transform, auto& light)
{
scene::light* light_object = lights[entity];
scene::light* light_object = lights[entity_id];
light_object->set_transform(transform.world);
if (transform.warp)
@ -78,7 +79,7 @@ void render_system::update(double t, double dt)
);
}
void render_system::render(double alpha)
void render::draw(double alpha)
{
if (renderer)
{
@ -89,40 +90,40 @@ void render_system::render(double alpha)
}
}
void render_system::add_layer(scene::collection* layer)
void render::add_layer(scene::collection* layer)
{
layers.push_back(layer);
}
void render_system::remove_layers()
void render::remove_layers()
{
layers.clear();
}
void render_system::set_renderer(::renderer* renderer)
void render::set_renderer(::renderer* renderer)
{
this->renderer = renderer;
}
scene::model_instance* render_system::get_model_instance(ecs::entity entity)
scene::model_instance* render::get_model_instance(entity::id entity_id)
{
if (auto it = model_instances.find(entity); it != model_instances.end())
if (auto it = model_instances.find(entity_id); it != model_instances.end())
return it->second;
return nullptr;
}
scene::light* render_system::get_light(ecs::entity entity)
scene::light* render::get_light(entity::id entity_id)
{
if (auto it = lights.find(entity); it != lights.end())
if (auto it = lights.find(entity_id); it != lights.end())
return it->second;
return nullptr;
}
void render_system::update_model_and_materials(ecs::entity entity, model_component& model)
void render::update_model_and_materials(entity::id entity_id, component::model& model)
{
if (auto model_it = model_instances.find(entity); model_it != model_instances.end())
if (auto model_it = model_instances.find(entity_id); model_it != model_instances.end())
{
model_it->second->set_model(model.model);
model_it->second->set_model(model.render_model);
model_it->second->set_instanced((model.instance_count > 0), model.instance_count);
for (auto material_it = model.materials.begin(); material_it != model.materials.end(); ++material_it)
@ -143,9 +144,9 @@ void render_system::update_model_and_materials(ecs::entity entity, model_compone
}
}
void render_system::update_light(ecs::entity entity, ecs::light_component& component)
void render::update_light(entity::id entity_id, entity::component::light& component)
{
if (auto light_it = lights.find(entity); light_it != lights.end())
if (auto light_it = lights.find(entity_id); light_it != lights.end())
{
scene::light* light = light_it->second;
@ -175,21 +176,21 @@ void render_system::update_light(ecs::entity entity, ecs::light_component& compo
}
}
void render_system::on_model_construct(ecs::registry& registry, ecs::entity entity, model_component& model)
void render::on_model_construct(entity::registry& registry, entity::id entity_id, component::model& model)
{
scene::model_instance* model_instance = new scene::model_instance();
model_instances[entity] = model_instance;
update_model_and_materials(entity, model);
model_instances[entity_id] = model_instance;
update_model_and_materials(entity_id, model);
}
void render_system::on_model_replace(ecs::registry& registry, ecs::entity entity, model_component& model)
void render::on_model_replace(entity::registry& registry, entity::id entity_id, component::model& model)
{
update_model_and_materials(entity, model);
update_model_and_materials(entity_id, model);
}
void render_system::on_model_destroy(ecs::registry& registry, ecs::entity entity)
void render::on_model_destroy(entity::registry& registry, entity::id entity_id)
{
if (auto it = model_instances.find(entity); it != model_instances.end())
if (auto it = model_instances.find(entity_id); it != model_instances.end())
{
scene::model_instance* model_instance = it->second;
@ -202,7 +203,7 @@ void render_system::on_model_destroy(ecs::registry& registry, ecs::entity entity
}
}
void render_system::on_light_construct(ecs::registry& registry, ecs::entity entity, light_component& component)
void render::on_light_construct(entity::registry& registry, entity::id entity_id, component::light& component)
{
scene::light* light = nullptr;
@ -230,22 +231,22 @@ void render_system::on_light_construct(ecs::registry& registry, ecs::entity enti
if (light)
{
lights[entity] = light;
lights[entity_id] = light;
for (scene::collection* layer: layers)
layer->add_object(light);
update_light(entity, component);
update_light(entity_id, component);
}
}
void render_system::on_light_replace(ecs::registry& registry, ecs::entity entity, light_component& light)
void render::on_light_replace(entity::registry& registry, entity::id entity_id, component::light& light)
{
update_light(entity, light);
update_light(entity_id, light);
}
void render_system::on_light_destroy(ecs::registry& registry, ecs::entity entity)
void render::on_light_destroy(entity::registry& registry, entity::id entity_id)
{
if (auto it = lights.find(entity); it != lights.end())
if (auto it = lights.find(entity_id); it != lights.end())
{
scene::light* light = it->second;
@ -257,4 +258,5 @@ void render_system::on_light_destroy(ecs::registry& registry, ecs::entity entity
}
}
} // namespace ecs
} // namespace system
} // namespace entity

+ 77
- 0
src/entity/systems/render.hpp View File

@ -0,0 +1,77 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ENTITY_SYSTEM_RENDER_HPP
#define ANTKEEPER_ENTITY_SYSTEM_RENDER_HPP
#include "entity/systems/updatable.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "scene/light.hpp"
#include "entity/components/model.hpp"
#include "entity/components/light.hpp"
#include "entity/id.hpp"
#include <unordered_map>
#include <vector>
class renderer;
namespace entity {
namespace system {
class render: public updatable
{
public:
render(entity::registry& registry);
virtual void update(double t, double dt);
void draw(double alpha);
void add_layer(scene::collection* layer);
void remove_layers();
void set_renderer(::renderer* renderer);
scene::model_instance* get_model_instance(entity::id entity_id);
scene::light* get_light(entity::id entity_id);
private:
void update_model_and_materials(entity::id entity_id, entity::component::model& model);
void update_light(entity::id entity_id, entity::component::light& component);
void on_model_construct(entity::registry& registry, entity::id entity_id, entity::component::model& model);
void on_model_replace(entity::registry& registry, entity::id entity_id, entity::component::model& model);
void on_model_destroy(entity::registry& registry, entity::id entity_id);
void on_light_construct(entity::registry& registry, entity::id entity_id, entity::component::light& light);
void on_light_replace(entity::registry& registry, entity::id entity_id, entity::component::light& light);
void on_light_destroy(entity::registry& registry, entity::id entity_id);
renderer* renderer;
std::vector<scene::collection*> layers;
std::unordered_map<entity::id, scene::model_instance*> model_instances;
std::unordered_map<entity::id, scene::light*> lights;
};
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ENTITY_SYSTEM_RENDER_HPP

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

@ -17,23 +17,24 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "samara-system.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/samara-component.hpp"
#include "ecs/entity.hpp"
#include "samara.hpp"
#include "entity/components/transform.hpp"
#include "entity/components/samara.hpp"
#include "entity/id.hpp"
#include "math/math.hpp"
#include "utility/fundamental-types.hpp"
namespace ecs {
namespace entity {
namespace system {
samara_system::samara_system(ecs::registry& registry):
entity_system(registry)
samara::samara(entity::registry& registry):
updatable(registry)
{}
void samara_system::update(double t, double dt)
void samara::update(double t, double dt)
{
registry.view<samara_component, transform_component>().each(
[&](ecs::entity entity, auto& samara, auto& transform)
registry.view<component::samara, component::transform>().each(
[&](entity::id entity_id, auto& samara, auto& transform)
{
samara.angle += samara.chirality * math::radians(360.0f * 6.0f) * dt;
@ -56,4 +57,5 @@ void samara_system::update(double t, double dt)
});
}
} // namespace ecs
} // namespace system
} // namespace entity

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

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

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

@ -17,23 +17,24 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "snapping-system.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/snap-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/entity.hpp"
#include "snapping.hpp"
#include "entity/components/collision.hpp"
#include "entity/components/snap.hpp"
#include "entity/components/transform.hpp"
#include "entity/id.hpp"
#include "utility/fundamental-types.hpp"
namespace ecs {
namespace entity {
namespace system {
snapping_system::snapping_system(ecs::registry& registry):
entity_system(registry)
snapping::snapping(entity::registry& registry):
updatable(registry)
{}
void snapping_system::update(double t, double dt)
void snapping::update(double t, double dt)
{
registry.view<transform_component, snap_component>().each(
[&](ecs::entity entity, auto& snap_transform, auto& snap)
registry.view<component::transform, component::snap>().each(
[&](entity::id entity_id, auto& snap_transform, auto& snap)
{
bool intersection = false;
float a = std::numeric_limits<float>::infinity();
@ -46,8 +47,8 @@ void snapping_system::update(double t, double dt)
snap_ray.direction = snap_transform.local.rotation * snap_ray.direction;
}
this->registry.view<transform_component, collision_component>().each(
[&](ecs::entity entity, auto& collision_transform, auto& collision)
this->registry.view<component::transform, component::collision>().each(
[&](entity::id entity_id, auto& collision_transform, auto& collision)
{
// Transform ray into local space of collision component
math::transform<float> inverse_transform = math::inverse(collision_transform.local);
@ -82,10 +83,11 @@ void snapping_system::update(double t, double dt)
if (snap.autoremove)
{
this->registry.remove<snap_component>(entity);
this->registry.remove<component::snap>(entity_id);
}
}
});
}
} // namespace ecs
} // namespace system
} // namespace entity

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

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

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

@ -17,42 +17,44 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "spatial-system.hpp"
#include "ecs/components/parent-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "spatial.hpp"
#include "entity/components/parent.hpp"
#include "entity/components/transform.hpp"
namespace ecs {
namespace entity {
namespace system {
spatial_system::spatial_system(ecs::registry& registry):
entity_system(registry)
spatial::spatial(entity::registry& registry):
updatable(registry)
{}
void spatial_system::update(double t, double dt)
void spatial::update(double t, double dt)
{
/// @TODO: sort transforms by parent, for more multi-level hierarchies
// Process parent transforms first
registry.view<transform_component>().each(
[&](ecs::entity entity, auto& transform)
registry.view<component::transform>().each(
[&](entity::id entity_id, auto& transform)
{
if (!this->registry.has<parent_component>(entity))
if (!this->registry.has<component::parent>(entity_id))
{
transform.world = transform.local;
}
});
// Process child transforms second
registry.view<transform_component>().each(
[&](ecs::entity entity, auto& transform)
registry.view<component::transform>().each(
[&](entity::id entity_id, auto& transform)
{
if (this->registry.has<parent_component>(entity))
if (this->registry.has<component::parent>(entity_id))
{
ecs::entity parent = this->registry.get<parent_component>(entity).parent;
const transform_component& parent_transform = this->registry.get<transform_component>(parent);
entity::id parent = this->registry.get<component::parent>(entity_id).parent;
const component::transform& parent_transform = this->registry.get<component::transform>(parent);
transform.world = parent_transform.world * transform.local;
transform.warp = parent_transform.warp;
}
});
}
} // namespace ecs
} // namespace system
} // namespace entity

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

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

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

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "subterrain-system.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/cavity-component.hpp"
#include "ecs/entity.hpp"
#include "subterrain.hpp"
#include "entity/components/model.hpp"
#include "entity/components/cavity.hpp"
#include "entity/id.hpp"
#include "renderer/model.hpp"
#include "renderer/material.hpp"
#include "geom/mesh-functions.hpp"
@ -35,7 +35,8 @@
#include <array>
#include <limits>
namespace ecs {
namespace entity {
namespace system {
/**
* An octree containing cubes for the marching cubes algorithm.
@ -188,8 +189,8 @@ void cube_tree::subdivide()
}
}
subterrain_system::subterrain_system(ecs::registry& registry, ::resource_manager* resource_manager):
entity_system(registry),
subterrain::subterrain(entity::registry& registry, ::resource_manager* resource_manager):
updatable(registry),
resource_manager(resource_manager)
{
@ -244,7 +245,7 @@ subterrain_system::subterrain_system(ecs::registry& registry, ::resource_manager
subterrain_model->set_bounds(subterrain_bounds);
// Allocate cube tree
cube_tree = new ecs::cube_tree(subterrain_bounds, octree_depth);
cube_tree = new entity::system::cube_tree(subterrain_bounds, octree_depth);
// Allocate mesh
subterrain_mesh = new geom::mesh();
@ -252,19 +253,19 @@ subterrain_system::subterrain_system(ecs::registry& registry, ::resource_manager
first_run = true;
}
subterrain_system::~subterrain_system()
subterrain::~subterrain()
{
delete subterrain_model;
delete subterrain_mesh;
}
void subterrain_system::update(double t, double dt)
void subterrain::update(double t, double dt)
{
if (first_run)
{
first_run = false;
//auto subterrain_entity = registry.create();
//registry.assign<model_component>(subterrain_entity, subterrain_model);
//registry.assign<component::model>(subterrain_entity, subterrain_model);
subterrain_model_instance = new scene::model_instance(subterrain_model);
collection->add_object(subterrain_model_instance);
@ -272,11 +273,11 @@ void subterrain_system::update(double t, double dt)
bool digging = false;
registry.view<cavity_component>().each(
[this, &digging](ecs::entity entity, auto& cavity)
registry.view<component::cavity>().each(
[this, &digging](entity::id entity_id, auto& cavity)
{
this->dig(cavity.position, cavity.radius);
this->registry.destroy(entity);
this->registry.destroy(entity_id);
digging = true;
});
@ -294,12 +295,12 @@ void subterrain_system::update(double t, double dt)
}
}
void subterrain_system::set_scene(scene::collection* collection)
void subterrain::set_scene(scene::collection* collection)
{
this->collection = collection;
}
void subterrain_system::regenerate_subterrain_mesh()
void subterrain::regenerate_subterrain_mesh()
{
delete subterrain_mesh;
subterrain_mesh = new geom::mesh();
@ -321,11 +322,11 @@ void subterrain_system::regenerate_subterrain_mesh()
//std::cout << "creating mesh... done\n";
}
void subterrain_system::march(ecs::cube_tree* node)
void subterrain::march(entity::system::cube_tree* node)
{
if (!node->is_leaf())
{
for (ecs::cube_tree* child: node->children)
for (entity::system::cube_tree* child: node->children)
march(child);
return;
}
@ -377,7 +378,7 @@ void subterrain_system::march(ecs::cube_tree* node)
}
}
void subterrain_system::regenerate_subterrain_model()
void subterrain::regenerate_subterrain_model()
{
float3* face_normals = new float3[subterrain_mesh->get_faces().size()];
calculate_face_normals(face_normals, *subterrain_mesh);
@ -450,7 +451,7 @@ void subterrain_system::regenerate_subterrain_model()
subterrain_outside_group->set_index_count(subterrain_mesh->get_faces().size() * 3);
}
void subterrain_system::dig(const float3& position, float radius)
void subterrain::dig(const float3& position, float radius)
{
// Construct region containing the cavity sphere
geom::aabb<float> region = {position, position};
@ -464,9 +465,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<ecs::cube_tree*> nodes;
std::list<entity::system::cube_tree*> nodes;
cube_tree->visit_leaves(region,
[&position, radius](ecs::cube_tree& node)
[&position, radius](entity::system::cube_tree& node)
{
for (int i = 0; i < 8; ++i)
{
@ -481,4 +482,5 @@ void subterrain_system::dig(const float3& position, float radius)
});
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_SUBTERRAIN_SYSTEM_HPP
#define ANTKEEPER_ECS_SUBTERRAIN_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_SUBTERRAIN_HPP
#define ANTKEEPER_ENTITY_SYSTEM_SUBTERRAIN_HPP
#include "entity-system.hpp"
#include "entity/systems/updatable.hpp"
#include "geom/mesh.hpp"
#include "geom/aabb.hpp"
#include "scene/collection.hpp"
@ -33,7 +33,8 @@ class model;
class model_group;
class material;
namespace ecs {
namespace entity {
namespace system {
struct cube_tree;
@ -85,21 +86,21 @@ struct vector_equals
}
};
class subterrain_system: public entity_system
class subterrain: public updatable
{
public:
subterrain_system(ecs::registry& registry, ::resource_manager* resource_manager);
~subterrain_system();
subterrain(entity::registry& registry, ::resource_manager* resource_manager);
~subterrain();
virtual void update(double t, double dt);
void set_scene(scene::collection* collection);
private:
void regenerate_subterrain_mesh();
void march(ecs::cube_tree* node);
void march(cube_tree* node);
void regenerate_subterrain_model();
void dig(const float3&position, float radius);
float distance(const ecs::cube_tree& node, const float3& sample) const;
float distance(const cube_tree& node, const float3& sample) const;
resource_manager* resource_manager;
geom::mesh* subterrain_mesh;
@ -111,7 +112,7 @@ private:
int subterrain_model_vertex_size;
int subterrain_model_vertex_stride;
geom::aabb<float> subterrain_bounds;
ecs::cube_tree* cube_tree;
cube_tree* cube_tree;
std::vector<float3> subterrain_vertices;
std::vector<std::array<std::uint_fast32_t, 3>> subterrain_triangles;
float isosurface_resolution;
@ -128,7 +129,8 @@ private:
scene::model_instance* subterrain_model_instance;
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_SUBTERRAIN_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_SUBTERRAIN_HPP

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

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "terrain-system.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "terrain.hpp"
#include "entity/components/model.hpp"
#include "entity/components/collision.hpp"
#include "entity/components/transform.hpp"
#include "cart/relief-map.hpp"
#include "renderer/model.hpp"
#include "geom/mesh.hpp"
@ -34,39 +34,40 @@
#include "utility/fundamental-types.hpp"
#include <limits>
namespace ecs {
namespace entity {
namespace system {
terrain_system::terrain_system(ecs::registry& registry, ::resource_manager* resource_manager):
entity_system(registry),
terrain::terrain(entity::registry& registry, ::resource_manager* resource_manager):
updatable(registry),
resource_manager(resource_manager)
{
registry.on_construct<terrain_component>().connect<&terrain_system::on_terrain_construct>(this);
registry.on_destroy<terrain_component>().connect<&terrain_system::on_terrain_destroy>(this);
registry.on_construct<component::terrain>().connect<&terrain::on_terrain_construct>(this);
registry.on_destroy<component::terrain>().connect<&terrain::on_terrain_destroy>(this);
heightmap = resource_manager->load<image>("grassland-heightmap.png");
heightmap_size = 2000.0f;
heightmap_scale = 150.0f;
}
terrain_system::~terrain_system()
terrain::~terrain()
{}
void terrain_system::update(double t, double dt)
void terrain::update(double t, double dt)
{
registry.view<terrain_component, transform_component>().each(
[this](ecs::entity entity, auto& terrain, auto& transform)
registry.view<component::terrain, component::transform>().each(
[this](entity::id entity_id, auto& terrain, auto& transform)
{
transform.local.translation = float3{(float)terrain.x * patch_size, 0.0f, (float)terrain.z * patch_size};
transform.warp = true;
});
}
void terrain_system::set_patch_size(float size)
void terrain::set_patch_size(float size)
{
patch_size = size;
}
geom::mesh* terrain_system::generate_terrain_mesh(float size, int subdivisions)
geom::mesh* terrain::generate_terrain_mesh(float size, int subdivisions)
{
auto elevation = [](float u, float v) -> float
{
@ -76,7 +77,7 @@ geom::mesh* terrain_system::generate_terrain_mesh(float size, int subdivisions)
return cart::map_elevation(elevation, size, subdivisions);
}
model* terrain_system::generate_terrain_model(geom::mesh* terrain_mesh)
model* terrain::generate_terrain_model(geom::mesh* terrain_mesh)
{
// Allocate model
model* terrain_model = new model();
@ -113,7 +114,7 @@ model* terrain_system::generate_terrain_model(geom::mesh* terrain_mesh)
return terrain_model;
}
void terrain_system::project_terrain_mesh(geom::mesh* terrain_mesh, const terrain_component& component)
void terrain::project_terrain_mesh(geom::mesh* terrain_mesh, const component::terrain& component)
{
float offset_x = (float)component.x * patch_size;
@ -136,7 +137,7 @@ void terrain_system::project_terrain_mesh(geom::mesh* terrain_mesh, const terrai
}
void terrain_system::update_terrain_model(model* terrain_model, geom::mesh* terrain_mesh)
void terrain::update_terrain_model(model* terrain_model, geom::mesh* terrain_mesh)
{
const std::vector<geom::mesh::face*>& faces = terrain_mesh->get_faces();
const std::vector<geom::mesh::vertex*>& vertices = terrain_mesh->get_vertices();
@ -256,7 +257,7 @@ void terrain_system::update_terrain_model(model* terrain_model, geom::mesh* terr
delete[] vertex_data;
}
void terrain_system::on_terrain_construct(ecs::registry& registry, ecs::entity entity, terrain_component& component)
void terrain::on_terrain_construct(entity::registry& registry, entity::id entity_id, component::terrain& component)
{
geom::mesh* terrain_mesh = generate_terrain_mesh(patch_size, component.subdivisions);
model* terrain_model = generate_terrain_model(terrain_mesh);
@ -264,31 +265,31 @@ void terrain_system::on_terrain_construct(ecs::registry& registry, ecs::entity e
update_terrain_model(terrain_model, terrain_mesh);
// Assign the entity a collision component with the terrain mesh
collision_component collision;
component::collision collision;
collision.mesh = terrain_mesh;
collision.bounds = calculate_bounds(*terrain_mesh);
collision.mesh_accelerator.build(*collision.mesh);
registry.assign_or_replace<collision_component>(entity, collision);
registry.assign_or_replace<component::collision>(entity_id, collision);
// Assign the entity a model component with the terrain model
model_component model;
model.model = terrain_model;
component::model model;
model.render_model = terrain_model;
model.instance_count = 0;
model.layers = 1;
registry.assign_or_replace<model_component>(entity, model);
registry.assign_or_replace<component::model>(entity_id, model);
// Assign the entity a transform component
transform_component transform;
component::transform transform;
transform.local = math::identity_transform<float>;
transform.local.translation = float3{(float)component.x * patch_size, 0.0f, (float)component.z * patch_size};
transform.warp = true;
registry.assign_or_replace<transform_component>(entity, transform);
registry.assign_or_replace<component::transform>(entity_id, transform);
}
void terrain_system::on_terrain_destroy(ecs::registry& registry, ecs::entity entity)
void terrain::on_terrain_destroy(entity::registry& registry, entity::id entity_id)
{
/*
if (auto it = terrain_map.find(entity); it != terrain_map.end())
if (auto it = terrain_map.find(entity_id); it != terrain_map.end())
{
delete std::get<0>(it->second);
delete std::get<1>(it->second);
@ -297,4 +298,5 @@ void terrain_system::on_terrain_destroy(ecs::registry& registry, ecs::entity ent
*/
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,12 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_TERRAIN_SYSTEM_HPP
#define ANTKEEPER_ECS_TERRAIN_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_TERRAIN_HPP
#define ANTKEEPER_ENTITY_SYSTEM_TERRAIN_HPP
#include "entity-system.hpp"
#include "ecs/components/terrain-component.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/updatable.hpp"
#include "entity/components/terrain.hpp"
#include "entity/id.hpp"
#include "geom/mesh.hpp"
class terrain;
@ -30,13 +30,14 @@ class resource_manager;
class model;
class image;
namespace ecs {
namespace entity {
namespace system {
class terrain_system: public entity_system
class terrain: public updatable
{
public:
terrain_system(ecs::registry& registry, ::resource_manager* resource_manager);
~terrain_system();
terrain(entity::registry& registry, ::resource_manager* resource_manager);
~terrain();
virtual void update(double t, double dt);
/**
@ -47,11 +48,11 @@ public:
private:
geom::mesh* generate_terrain_mesh(float size, int subdivisions);
model* generate_terrain_model(geom::mesh* terrain_mesh);
void project_terrain_mesh(geom::mesh* terrain_mesh, const ecs::terrain_component& component);
void project_terrain_mesh(geom::mesh* terrain_mesh, const entity::component::terrain& component);
void update_terrain_model(model* terrain_model, geom::mesh* terrain_mesh);
void on_terrain_construct(ecs::registry& registry, ecs::entity entity, ecs::terrain_component& component);
void on_terrain_destroy(ecs::registry& registry, ecs::entity entity);
void on_terrain_construct(entity::registry& registry, entity::id entity_id, entity::component::terrain& component);
void on_terrain_destroy(entity::registry& registry, entity::id entity_id);
resource_manager* resource_manager;
float patch_size;
@ -60,7 +61,8 @@ private:
image* heightmap;
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_TERRAIN_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_TERRAIN_HPP

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

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tool-system.hpp"
#include "ecs/components/collision-component.hpp"
#include "ecs/components/tool-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "tool.hpp"
#include "entity/components/collision.hpp"
#include "entity/components/tool.hpp"
#include "entity/components/transform.hpp"
#include "event/event-dispatcher.hpp"
#include "game/events/tool-events.hpp"
#include "animation/orbit-cam.hpp"
@ -28,12 +28,13 @@
#include "geom/mesh.hpp"
#include "geom/intersection.hpp"
#include "math/math.hpp"
#include "ecs/commands.hpp"
#include "entity/commands.hpp"
namespace ecs {
namespace entity {
namespace system {
tool_system::tool_system(ecs::registry& registry, ::event_dispatcher* event_dispatcher):
entity_system(registry),
tool::tool(entity::registry& registry, ::event_dispatcher* event_dispatcher):
updatable(registry),
event_dispatcher(event_dispatcher),
camera(nullptr),
orbit_cam(orbit_cam),
@ -86,13 +87,13 @@ tool_system::tool_system(ecs::registry& registry, ::event_dispatcher* event_disp
event_dispatcher->subscribe<window_resized_event>(this);
}
tool_system::~tool_system()
tool::~tool()
{
event_dispatcher->unsubscribe<mouse_moved_event>(this);
event_dispatcher->unsubscribe<window_resized_event>(this);
}
void tool_system::update(double t, double dt)
void tool::update(double t, double dt)
{
if (active_tool == entt::null)
return;
@ -115,8 +116,8 @@ void tool_system::update(double t, double dt)
float3 pick;
// Cast ray from cursor to collision components to find closest intersection
registry.view<transform_component, collision_component>().each(
[&](ecs::entity entity, auto& transform, auto& collision)
registry.view<component::transform, component::collision>().each(
[&](entity::id entity_id, auto& transform, auto& collision)
{
math::transform<float> inverse_transform = math::inverse(transform.local);
float3 origin = inverse_transform * pick_origin;
@ -170,11 +171,11 @@ void tool_system::update(double t, double dt)
pick_spring.x0 = pick_spring.x1;
// Move active tools to intersection location
registry.view<tool_component, transform_component>().each(
[&](ecs::entity entity, auto& tool, auto& transform)
registry.view<component::tool, component::transform>().each(
[&](entity::id entity_id, auto& tool, auto& transform)
{
/*
if (registry.has<model_component>(entity))
if (registry.has<component::model>(entity_id))
{
}*/
@ -182,7 +183,7 @@ void tool_system::update(double t, double dt)
if (!tool.active)
return;
active_tool = entity;
active_tool = entity_id;
float tool_distance = active_tool_distance;//(tool_active) ? tool.active_distance : tool.idle_distance;
@ -222,36 +223,36 @@ void tool_system::update(double t, double dt)
was_pick_enabled = pick_enabled;
}
void tool_system::set_camera(const scene::camera* camera)
void tool::set_camera(const scene::camera* camera)
{
this->camera = camera;
}
void tool_system::set_orbit_cam(const ::orbit_cam* orbit_cam)
void tool::set_orbit_cam(const ::orbit_cam* orbit_cam)
{
this->orbit_cam = orbit_cam;
}
void tool_system::set_viewport(const float4& viewport)
void tool::set_viewport(const float4& viewport)
{
this->viewport = viewport;
mouse_position.x = viewport[2] * 0.5f;
mouse_position.y = viewport[3] * 0.5f;
}
void tool_system::set_pick(bool enabled)
void tool::set_pick(bool enabled)
{
pick_enabled = enabled;
}
void tool_system::set_sun_direction(const float3& direction)
void tool::set_sun_direction(const float3& direction)
{
sun_direction = direction;
}
void tool_system::set_active_tool(ecs::entity entity)
void tool::set_active_tool(entity::id entity_id)
{
if (active_tool == entity)
if (active_tool == entity_id)
return;
const float descent_time = 0.1f;
@ -259,16 +260,16 @@ void tool_system::set_active_tool(ecs::entity entity)
if (active_tool != entt::null)
{
auto& tool = registry.get<tool_component>(active_tool);
auto& tool = registry.get<component::tool>(active_tool);
tool.active = false;
command::assign_render_layers(registry, active_tool, 0);
}
active_tool = entity;
active_tool = entity_id;
if (active_tool != entt::null)
{
auto& tool = registry.get<tool_component>(active_tool);
auto& tool = registry.get<component::tool>(active_tool);
tool.active = true;
active_tool_distance = tool.idle_distance;
@ -290,7 +291,7 @@ void tool_system::set_active_tool(ecs::entity entity)
warp = true;
}
void tool_system::set_tool_active(bool active)
void tool::set_tool_active(bool active)
{
if (active_tool == entt::null)
return;
@ -304,7 +305,7 @@ void tool_system::set_tool_active(bool active)
// Queue tool pressed event
tool_pressed_event event;
event.entity = active_tool;
event.entity_id = active_tool;
event.position = pick_spring.x0;
event_dispatcher->queue(event);
}
@ -315,13 +316,13 @@ void tool_system::set_tool_active(bool active)
// Queue tool pressed event
tool_released_event event;
event.entity = active_tool;
event.entity_id = active_tool;
event.position = pick_spring.x0;
event_dispatcher->queue(event);
}
}
void tool_system::handle_event(const mouse_moved_event& event)
void tool::handle_event(const mouse_moved_event& event)
{
if (pick_enabled && was_pick_enabled)
{
@ -330,9 +331,10 @@ void tool_system::handle_event(const mouse_moved_event& event)
}
}
void tool_system::handle_event(const window_resized_event& event)
void tool::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,11 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_TOOL_SYSTEM_HPP
#define ANTKEEPER_ECS_TOOL_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_TOOL_HPP
#define ANTKEEPER_ENTITY_SYSTEM_TOOL_HPP
#include "entity-system.hpp"
#include "ecs/entity.hpp"
#include "entity/systems/updatable.hpp"
#include "entity/id.hpp"
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
@ -33,16 +33,17 @@
class orbit_cam;
class event_dispatcher;
namespace ecs {
namespace entity {
namespace system {
class tool_system:
public entity_system,
class tool:
public updatable,
public event_handler<mouse_moved_event>,
public event_handler<window_resized_event>
{
public:
tool_system(ecs::registry& registry, event_dispatcher* event_dispatcher);
virtual ~tool_system();
tool(entity::registry& registry, event_dispatcher* event_dispatcher);
virtual ~tool();
virtual void update(double t, double dt);
void set_camera(const scene::camera* camera);
@ -51,11 +52,11 @@ public:
void set_pick(bool enabled);
void set_sun_direction(const float3& direction);
void set_active_tool(ecs::entity entity);
void set_active_tool(entity::id entity_id);
void set_tool_active(bool active);
entity get_active_tool() const;
entity::id get_active_tool() const;
private:
virtual void handle_event(const mouse_moved_event& event);
@ -69,7 +70,7 @@ private:
bool was_pick_enabled;
bool pick_enabled;
float3 sun_direction;
entity active_tool;
entity::id active_tool;
bool warp;
bool tool_active;
@ -82,11 +83,12 @@ private:
float active_tool_distance;
};
inline entity tool_system::get_active_tool() const
inline entity::id tool::get_active_tool() const
{
return active_tool;
}
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_TOOL_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_TOOL_HPP

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

@ -17,9 +17,9 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tracking-system.hpp"
#include "ecs/components/transform-component.hpp"
#include "ecs/components/marker-component.hpp"
#include "tracking.hpp"
#include "entity/components/transform.hpp"
#include "entity/components/marker.hpp"
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "scene/collection.hpp"
@ -28,18 +28,19 @@
#include "renderer/material.hpp"
#include "renderer/model.hpp"
#include "utility/fundamental-types.hpp"
#include "ecs/commands.hpp"
#include "entity/commands.hpp"
namespace ecs {
namespace entity {
namespace system {
tracking_system::tracking_system(ecs::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
entity_system(registry),
tracking::tracking(entity::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
updatable(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
scene_collection(nullptr)
{
registry.on_construct<trackable_component>().connect<&tracking_system::on_component_construct>(this);
registry.on_destroy<trackable_component>().connect<&tracking_system::on_component_destroy>(this);
registry.on_construct<component::trackable>().connect<&tracking::on_component_construct>(this);
registry.on_destroy<component::trackable>().connect<&tracking::on_component_destroy>(this);
// Load paint ball model
paint_ball_model = resource_manager->load<model>("paint-ball.mdl");
@ -61,7 +62,7 @@ tracking_system::tracking_system(ecs::registry& registry, ::event_dispatcher* ev
event_dispatcher->subscribe<tool_released_event>(this);
}
tracking_system::~tracking_system()
tracking::~tracking()
{
event_dispatcher->unsubscribe<tool_pressed_event>(this);
event_dispatcher->unsubscribe<tool_released_event>(this);
@ -75,11 +76,11 @@ tracking_system::~tracking_system()
}
void tracking_system::update(double t, double dt)
void tracking::update(double t, double dt)
{
for (auto it = trackers.begin(); it != trackers.end(); ++it)
{
const transform_component& transform = registry.get<transform_component>(it->first);
const component::transform& transform = registry.get<component::transform>(it->first);
// Project world coordinates to screen coordinates
@ -92,19 +93,19 @@ void tracking_system::update(double t, double dt)
}
}
void tracking_system::set_scene(scene::collection* collection)
void tracking::set_scene(scene::collection* collection)
{
this->scene_collection = collection;
}
void tracking_system::on_component_construct(ecs::registry& registry, ecs::entity entity, trackable_component& component)
void tracking::on_component_construct(entity::registry& registry, entity::id entity_id, component::trackable& component)
{
}
void tracking_system::on_component_destroy(ecs::registry& registry, ecs::entity entity)
void tracking::on_component_destroy(entity::registry& registry, entity::id entity_id)
{
if (auto it = trackers.find(entity); it != trackers.end())
if (auto it = trackers.find(entity_id); it != trackers.end())
{
// Remove model instance from all layers
/*
@ -119,13 +120,13 @@ void tracking_system::on_component_destroy(ecs::registry& registry, ecs::entity
}
}
void tracking_system::handle_event(const tool_pressed_event& event)
void tracking::handle_event(const tool_pressed_event& event)
{
if (registry.has<marker_component>(event.entity))
if (registry.has<component::marker>(event.entity_id))
{
math::transform<float> transform = command::get_world_transform(registry, event.entity);
math::transform<float> transform = command::get_world_transform(registry, event.entity_id);
int marker_index = registry.get<marker_component>(event.entity).color;
int marker_index = registry.get<component::marker>(event.entity_id).color;
if (marker_index > 0)
{
@ -151,9 +152,10 @@ void tracking_system::handle_event(const tool_pressed_event& event)
}
}
void tracking_system::handle_event(const tool_released_event& event)
void tracking::handle_event(const tool_released_event& event)
{
}
} // namespace ecs
} // namespace system
} // namespace entity

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

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

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

@ -17,12 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ui-system.hpp"
#include "ui.hpp"
#include "resources/resource-manager.hpp"
namespace ecs {
namespace entity {
namespace system {
ui_system::ui_system(::resource_manager* resource_manager):
ui::ui(::resource_manager* resource_manager):
resource_manager(resource_manager),
tool_menu_control(nullptr),
camera(nullptr),
@ -53,10 +54,10 @@ ui_system::ui_system(::resource_manager* resource_manager):
//scene.add_object(&direct_light);
}
void ui_system::update(float dt)
void ui::update(float dt)
{}
void ui_system::set_viewport(const float4& viewport)
void ui::set_viewport(const float4& viewport)
{
this->viewport = viewport;
@ -72,14 +73,14 @@ void ui_system::set_viewport(const float4& viewport)
update_projection();
}
void ui_system::set_tool_menu_control(input::control* control)
void ui::set_tool_menu_control(input::control* control)
{
tool_menu_control = control;
tool_menu_control->set_activated_callback(std::bind(&ui_system::open_tool_menu, this));
tool_menu_control->set_deactivated_callback(std::bind(&ui_system::close_tool_menu, this));
tool_menu_control->set_activated_callback(std::bind(&ui::open_tool_menu, this));
tool_menu_control->set_deactivated_callback(std::bind(&ui::close_tool_menu, this));
}
void ui_system::set_camera(scene::camera* camera)
void ui::set_camera(scene::camera* camera)
{
this->camera = camera;
@ -90,12 +91,12 @@ void ui_system::set_camera(scene::camera* camera)
}
}
void ui_system::set_scene(scene::collection* collection)
void ui::set_scene(scene::collection* collection)
{
this->scene_collection = collection;
}
void ui_system::handle_event(const mouse_moved_event& event)
void ui::handle_event(const mouse_moved_event& event)
{
if (tool_menu_control->is_active())
{
@ -135,12 +136,12 @@ void ui_system::handle_event(const mouse_moved_event& event)
mouse_position[1] = event.y;
}
void ui_system::handle_event(const window_resized_event& event)
void ui::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}
void ui_system::update_projection()
void ui::update_projection()
{
if (camera)
{
@ -154,7 +155,7 @@ void ui_system::update_projection()
}
}
void ui_system::open_tool_menu()
void ui::open_tool_menu()
{
if (scene_collection)
{
@ -164,7 +165,7 @@ void ui_system::open_tool_menu()
tool_selection_vector = {0, 0};
}
void ui_system::close_tool_menu()
void ui::close_tool_menu()
{
if (scene_collection)
{
@ -173,14 +174,15 @@ void ui_system::close_tool_menu()
}
}
void ui_system::open_elevator_menu()
void ui::open_elevator_menu()
{
}
void ui_system::close_elevator_menu()
void ui::close_elevator_menu()
{
}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_UI_SYSTEM_HPP
#define ANTKEEPER_ECS_UI_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_UI_HPP
#define ANTKEEPER_ENTITY_SYSTEM_UI_HPP
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
@ -35,14 +35,15 @@
class resource_manager;
namespace ecs {
namespace entity {
namespace system {
class ui_system:
class ui:
public event_handler<mouse_moved_event>,
public event_handler<window_resized_event>
{
public:
ui_system(::resource_manager* resource_manager);
ui(::resource_manager* resource_manager);
void update(float dt);
@ -82,6 +83,7 @@ private:
input::control* tool_menu_control;
};
} // namespace ecs
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ECS_UI_SYSTEM_HPP
#endif // ANTKEEPER_ENTITY_SYSTEM_UI_HPP

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

@ -17,13 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "entity-system.hpp"
#include "updatable.hpp"
namespace ecs {
namespace entity {
namespace system {
entity_system::entity_system(ecs::registry& registry):
updatable::updatable(entity::registry& registry):
registry(registry)
{}
} // namespace ecs
} // namespace system
} // namespace entity

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

@ -17,17 +17,27 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_UPDATABLE_SYSTEM_HPP
#define ANTKEEPER_ECS_UPDATABLE_SYSTEM_HPP
#ifndef ANTKEEPER_ENTITY_SYSTEM_UPDATABLE_HPP
#define ANTKEEPER_ENTITY_SYSTEM_UPDATABLE_HPP
namespace ecs {
#include "entity/registry.hpp"
namespace entity {
namespace system {
/**
* Abstract base class for updatable systems.
*/
class updatable_system
class updatable
{
public:
/**
* Creates an updatable system.
*
* @param registry Reference to the registry on which the system will operate.
*/
updatable(entity::registry& registry);
/**
* Perform's a system's update() function.
*
@ -36,9 +46,13 @@ public:
* @param registry Entity registry.
*/
virtual void update(double t, double dt) = 0;
protected:
/// Registry on which the system operate
entity::registry& registry;
};
} // namespace ecs
#endif // ANTKEEPER_ECS_UPDATABLE_SYSTEM_HPP
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ENTITY_SYSTEM_UPDATABLE_HPP

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

@ -17,9 +17,9 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "vegetation-system.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "vegetation.hpp"
#include "entity/components/model.hpp"
#include "entity/components/transform.hpp"
#include "scene/model-instance.hpp"
#include "scene/lod-group.hpp"
#include "scene/collection.hpp"
@ -28,10 +28,11 @@
#include "utility/fundamental-types.hpp"
#include <cmath>
namespace ecs {
namespace entity {
namespace system {
vegetation_system::vegetation_system(ecs::registry& registry):
entity_system(registry),
vegetation::vegetation(entity::registry& registry):
updatable(registry),
terrain_patch_size(1.0f),
vegetation_patch_size(1.0f),
vegetation_patch_columns(1),
@ -39,23 +40,23 @@ vegetation_system::vegetation_system(ecs::registry& registry):
vegetation_density(1.0f),
vegetation_model(nullptr)
{
registry.on_construct<terrain_component>().connect<&vegetation_system::on_terrain_construct>(this);
registry.on_destroy<terrain_component>().connect<&vegetation_system::on_terrain_destroy>(this);
registry.on_construct<component::terrain>().connect<&vegetation::on_terrain_construct>(this);
registry.on_destroy<component::terrain>().connect<&vegetation::on_terrain_destroy>(this);
}
vegetation_system::~vegetation_system()
vegetation::~vegetation()
{}
void vegetation_system::update(double t, double dt)
void vegetation::update(double t, double dt)
{}
void vegetation_system::set_terrain_patch_size(float size)
void vegetation::set_terrain_patch_size(float size)
{
terrain_patch_size = size;
vegetation_patch_size = terrain_patch_size / static_cast<float>(vegetation_patch_columns);
}
void vegetation_system::set_vegetation_patch_resolution(int subdivisions)
void vegetation::set_vegetation_patch_resolution(int subdivisions)
{
// Determine number of vegetation patch columns and rows per terrain patch
vegetation_patch_columns = static_cast<int>(std::pow(2, subdivisions));
@ -63,22 +64,22 @@ void vegetation_system::set_vegetation_patch_resolution(int subdivisions)
vegetation_patch_size = terrain_patch_size / static_cast<float>(vegetation_patch_columns);
}
void vegetation_system::set_vegetation_density(float density)
void vegetation::set_vegetation_density(float density)
{
vegetation_density = density;
}
void vegetation_system::set_vegetation_model(::model* model)
void vegetation::set_vegetation_model(::model* model)
{
vegetation_model = model;
}
void vegetation_system::set_scene(scene::collection* collection)
void vegetation::set_scene(scene::collection* collection)
{
this->scene_collection = collection;
}
void vegetation_system::on_terrain_construct(ecs::registry& registry, ecs::entity entity, terrain_component& component)
void vegetation::on_terrain_construct(entity::registry& registry, entity::id entity_id, component::terrain& component)
{
// Find corner of terrain patch
float terrain_patch_min_x = static_cast<float>(component.x) * terrain_patch_size - terrain_patch_size * 0.5f;
@ -94,17 +95,17 @@ void vegetation_system::on_terrain_construct(ecs::registry& registry, ecs::entit
auto vegetation_patch_entity = registry.create();
// Assign a transform component
transform_component transform;
component::transform transform;
transform.local = math::identity_transform<float>;
transform.local.translation = float3{vegetation_patch_x, 0.0f, vegetation_patch_z};
transform.warp = true;
registry.assign_or_replace<transform_component>(vegetation_patch_entity, transform);
registry.assign_or_replace<component::transform>(vegetation_patch_entity, transform);
// Assign a model component
model_component model;
component::model model;
model.model = vegetation_model;
model.instance_count = 500;
registry.assign_or_replace<model_component>(vegetation_patch_entity, model);
registry.assign_or_replace<component::model>(vegetation_patch_entity, model);
*/
// Find patch translation
@ -171,7 +172,8 @@ void vegetation_system::on_terrain_construct(ecs::registry& registry, ecs::entit
}
}
void vegetation_system::on_terrain_destroy(ecs::registry& registry, ecs::entity entity)
void vegetation::on_terrain_destroy(entity::registry& registry, entity::id entity_id)
{}
} // namespace ecs
} // namespace system
} // namespace entity

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

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

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

@ -55,30 +55,30 @@
#include "resources/resource-manager.hpp"
#include "scene/scene.hpp"
#include "game/states/game-states.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/astronomy-system.hpp"
#include "ecs/systems/blackbody-system.hpp"
#include "ecs/systems/atmosphere-system.hpp"
#include "ecs/systems/orbit-system.hpp"
#include "ecs/components/marker-component.hpp"
#include "ecs/commands.hpp"
#include "entity/systems/behavior.hpp"
#include "entity/systems/camera.hpp"
#include "entity/systems/collision.hpp"
#include "entity/systems/constraint.hpp"
#include "entity/systems/control.hpp"
#include "entity/systems/locomotion.hpp"
#include "entity/systems/nest.hpp"
#include "entity/systems/snapping.hpp"
#include "entity/systems/render.hpp"
#include "entity/systems/samara.hpp"
#include "entity/systems/subterrain.hpp"
#include "entity/systems/terrain.hpp"
#include "entity/systems/tool.hpp"
#include "entity/systems/ui.hpp"
#include "entity/systems/vegetation.hpp"
#include "entity/systems/spatial.hpp"
#include "entity/systems/tracking.hpp"
#include "entity/systems/painting.hpp"
#include "entity/systems/astronomy.hpp"
#include "entity/systems/blackbody.hpp"
#include "entity/systems/atmosphere.hpp"
#include "entity/systems/orbit.hpp"
#include "entity/components/marker.hpp"
#include "entity/commands.hpp"
#include "utility/paths.hpp"
#include "event/event-dispatcher.hpp"
#include "input/event-router.hpp"
@ -768,18 +768,18 @@ void setup_animation(game_context* ctx)
void setup_entities(game_context* ctx)
{
// Create ECS registry
ctx->ecs_registry = new entt::registry();
// Create entity registry
ctx->entity_registry = new entt::registry();
// Reserve named entities
ctx->brush_entity = ctx->ecs_registry->create();
ctx->flashlight_entity = ctx->ecs_registry->create();
ctx->forceps_entity = ctx->ecs_registry->create();
ctx->lens_entity = ctx->ecs_registry->create();
ctx->marker_entity = ctx->ecs_registry->create();
ctx->container_entity = ctx->ecs_registry->create();
ctx->twig_entity = ctx->ecs_registry->create();
ctx->focal_point_entity = ctx->ecs_registry->create();
ctx->brush_entity = ctx->entity_registry->create();
ctx->flashlight_entity = ctx->entity_registry->create();
ctx->forceps_entity = ctx->entity_registry->create();
ctx->lens_entity = ctx->entity_registry->create();
ctx->marker_entity = ctx->entity_registry->create();
ctx->container_entity = ctx->entity_registry->create();
ctx->twig_entity = ctx->entity_registry->create();
ctx->focal_point_entity = ctx->entity_registry->create();
}
void setup_systems(game_context* ctx)
@ -793,11 +793,11 @@ void setup_systems(game_context* ctx)
const double3 rgb_wavelengths_nm = {602.224, 541.069, 448.143};
// Setup terrain system
ctx->terrain_system = new ecs::terrain_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->terrain_system = new entity::system::terrain(*ctx->entity_registry, ctx->resource_manager);
ctx->terrain_system->set_patch_size(TERRAIN_PATCH_SIZE);
// Setup vegetation system
//ctx->vegetation_system = new ecs::vegetation_system(*ctx->ecs_registry);
//ctx->vegetation_system = new entity::system::vegetation(*ctx->entity_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);
@ -805,38 +805,38 @@ void setup_systems(game_context* ctx)
//ctx->vegetation_system->set_scene(ctx->overworld_scene);
// Setup camera system
ctx->camera_system = new ecs::camera_system(*ctx->ecs_registry);
ctx->camera_system = new entity::system::camera(*ctx->entity_registry);
ctx->camera_system->set_viewport(viewport);
event_dispatcher->subscribe<mouse_moved_event>(ctx->camera_system);
event_dispatcher->subscribe<window_resized_event>(ctx->camera_system);
// Setup tool system
ctx->tool_system = new ecs::tool_system(*ctx->ecs_registry, event_dispatcher);
ctx->tool_system = new entity::system::tool(*ctx->entity_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 ecs::subterrain_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->subterrain_system = new entity::system::subterrain(*ctx->entity_registry, ctx->resource_manager);
ctx->subterrain_system->set_scene(ctx->underworld_scene);
// Setup nest system
ctx->nest_system = new ecs::nest_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->nest_system = new entity::system::nest(*ctx->entity_registry, ctx->resource_manager);
// Setup collision system
ctx->collision_system = new ecs::collision_system(*ctx->ecs_registry);
ctx->collision_system = new entity::system::collision(*ctx->entity_registry);
// Setup samara system
ctx->samara_system = new ecs::samara_system(*ctx->ecs_registry);
ctx->samara_system = new entity::system::samara(*ctx->entity_registry);
// Setup snapping system
ctx->snapping_system = new ecs::snapping_system(*ctx->ecs_registry);
ctx->snapping_system = new entity::system::snapping(*ctx->entity_registry);
// Setup behavior system
ctx->behavior_system = new ecs::behavior_system(*ctx->ecs_registry);
ctx->behavior_system = new entity::system::behavior(*ctx->entity_registry);
// Setup locomotion system
ctx->locomotion_system = new ecs::locomotion_system(*ctx->ecs_registry);
ctx->locomotion_system = new entity::system::locomotion(*ctx->entity_registry);
// Setup pheromone system
ctx->pheromones = new pheromone_matrix();
@ -849,32 +849,32 @@ void setup_systems(game_context* ctx)
//diffuse(ctx->pheromones);
// Setup spatial system
ctx->spatial_system = new ecs::spatial_system(*ctx->ecs_registry);
ctx->spatial_system = new entity::system::spatial(*ctx->entity_registry);
// Setup constraint system
ctx->constraint_system = new ecs::constraint_system(*ctx->ecs_registry);
ctx->constraint_system = new entity::system::constraint(*ctx->entity_registry);
// Setup tracking system
ctx->tracking_system = new ecs::tracking_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager);
ctx->tracking_system = new entity::system::tracking(*ctx->entity_registry, event_dispatcher, ctx->resource_manager);
ctx->tracking_system->set_scene(ctx->overworld_scene);
// Setup painting system
ctx->painting_system = new ecs::painting_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager);
ctx->painting_system = new entity::system::painting(*ctx->entity_registry, event_dispatcher, ctx->resource_manager);
ctx->painting_system->set_scene(ctx->overworld_scene);
// Setup solar system
ctx->orbit_system = new ecs::orbit_system(*ctx->ecs_registry);
ctx->orbit_system = new entity::system::orbit(*ctx->entity_registry);
// Setup blackbody system
ctx->blackbody_system = new ecs::blackbody_system(*ctx->ecs_registry);
ctx->blackbody_system = new entity::system::blackbody(*ctx->entity_registry);
ctx->blackbody_system->set_rgb_wavelengths(rgb_wavelengths_nm);
// Setup atmosphere system
ctx->atmosphere_system = new ecs::atmosphere_system(*ctx->ecs_registry);
ctx->atmosphere_system = new entity::system::atmosphere(*ctx->entity_registry);
ctx->atmosphere_system->set_rgb_wavelengths(rgb_wavelengths_nm);
// Setup astronomy system
ctx->astronomy_system = new ecs::astronomy_system(*ctx->ecs_registry);
ctx->astronomy_system = new entity::system::astronomy(*ctx->entity_registry);
// Set time scale
float time_scale = 60.0f;
@ -887,14 +887,14 @@ void setup_systems(game_context* ctx)
ctx->astronomy_system->set_time_scale(time_scale / seconds_per_day);
// Setup render system
ctx->render_system = new ecs::render_system(*ctx->ecs_registry);
ctx->render_system = new entity::system::render(*ctx->entity_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 ecs::control_system(*ctx->ecs_registry);
ctx->control_system = new entity::system::control(*ctx->entity_registry);
ctx->control_system->set_viewport(viewport);
ctx->control_system->set_underworld_camera(ctx->underworld_camera);
ctx->control_system->set_tool(nullptr);
@ -908,7 +908,7 @@ void setup_systems(game_context* ctx)
event_dispatcher->subscribe<window_resized_event>(ctx->control_system);
// Setup UI system
ctx->ui_system = new ecs::ui_system(ctx->resource_manager);
ctx->ui_system = new entity::system::ui(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);
@ -1141,9 +1141,9 @@ void setup_controls(game_context* ctx)
(
[ctx]()
{
auto& marker_component = ctx->ecs_registry->get<ecs::marker_component>(ctx->marker_entity);
marker_component.color = (marker_component.color + 1) % 8;
const gl::texture_2d* marker_albedo_texture = ctx->marker_albedo_textures[marker_component.color];
auto& marker = ctx->entity_registry->get<entity::component::marker>(ctx->marker_entity);
marker.color = (marker.color + 1) % 8;
const gl::texture_2d* marker_albedo_texture = ctx->marker_albedo_textures[marker.color];
model* marker_model = ctx->render_system->get_model_instance(ctx->marker_entity)->get_model();
for (::model_group* group: *marker_model->get_groups())
@ -1161,9 +1161,9 @@ void setup_controls(game_context* ctx)
(
[ctx]()
{
auto& marker_component = ctx->ecs_registry->get<ecs::marker_component>(ctx->marker_entity);
marker_component.color = (marker_component.color + 7) % 8;
const gl::texture_2d* marker_albedo_texture = ctx->marker_albedo_textures[marker_component.color];
auto& marker = ctx->entity_registry->get<entity::component::marker>(ctx->marker_entity);
marker.color = (marker.color + 7) % 8;
const gl::texture_2d* marker_albedo_texture = ctx->marker_albedo_textures[marker.color];
model* marker_model = ctx->render_system->get_model_instance(ctx->marker_entity)->get_model();
for (::model_group* group: *marker_model->get_groups())
@ -1279,10 +1279,10 @@ void setup_callbacks(game_context* ctx)
//(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point();
auto xf = ecs::command::get_world_transform(*ctx->ecs_registry, ctx->lens_entity);
auto xf = entity::command::get_world_transform(*ctx->entity_registry, ctx->lens_entity);
//ctx->lens_spot_light->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0});
xf = ecs::command::get_world_transform(*ctx->ecs_registry, ctx->flashlight_entity);
xf = entity::command::get_world_transform(*ctx->entity_registry, ctx->flashlight_entity);
//ctx->flashlight_spot_light->set_transform(xf);
ctx->flashlight_spot_light->look_at(xf.translation, xf.translation + xf.rotation * float3{0, 0, 1}, {0, 0, -1});
@ -1303,7 +1303,7 @@ void setup_callbacks(game_context* ctx)
(
[ctx](double alpha)
{
ctx->render_system->render(alpha);
ctx->render_system->draw(alpha);
}
);
}

+ 2
- 2
src/game/events/tool-events.cpp View File

@ -22,7 +22,7 @@
event_base* tool_pressed_event::clone() const
{
tool_pressed_event* event = new tool_pressed_event();
event->entity = entity;
event->entity_id = entity_id;
event->position = position;
return event;
}
@ -30,7 +30,7 @@ event_base* tool_pressed_event::clone() const
event_base* tool_released_event::clone() const
{
tool_released_event* event = new tool_released_event();
event->entity = entity;
event->entity_id = entity_id;
event->position = position;
return event;
}

+ 3
- 3
src/game/events/tool-events.hpp View File

@ -22,13 +22,13 @@
#include "event/event.hpp"
#include "utility/fundamental-types.hpp"
#include <entt/entt.hpp>
#include "entity/id.hpp"
class tool_pressed_event: public event<tool_pressed_event>
{
public:
virtual event_base* clone() const;
entt::entity entity;
entity::id entity_id;
float3 position;
};
@ -36,7 +36,7 @@ class tool_released_event: public event
{
public:
virtual event_base* clone() const;
entt::entity entity;
entity::id entity_id;
float3 position;
};

+ 59
- 56
src/game/game-context.hpp View File

@ -22,8 +22,8 @@
#include "utility/fundamental-types.hpp"
#include "resources/string-table.hpp"
#include "ecs/entity.hpp"
#include "ecs/registry.hpp"
#include "entity/id.hpp"
#include "entity/registry.hpp"
#include "geom/aabb.hpp"
#include "gl/vertex-array.hpp"
#include "gl/vertex-buffer.hpp"
@ -73,30 +73,33 @@ namespace debug
class logger;
}
namespace ecs
namespace entity
{
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 astronomy_system;
class blackbody_system;
class atmosphere_system;
class orbit_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;
namespace system
{
class subterrain;
class terrain;
class vegetation;
class tool;
class ui;
class spatial;
class tracking;
class painting;
class astronomy;
class blackbody;
class atmosphere;
class orbit;
class behavior;
class collision;
class constraint;
class locomotion;
class control;
class snapping;
class camera;
class nest;
class render;
class samara;
}
}
/**
@ -219,39 +222,39 @@ struct game_context
input::control* toggle_fullscreen_control;
// Entities
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;
entity::registry* entity_registry;
entity::id brush_entity;
entity::id flashlight_entity;
entity::id forceps_entity;
entity::id lens_entity;
entity::id marker_entity;
entity::id container_entity;
entity::id twig_entity;
entity::id focal_point_entity;
// Systems
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::blackbody_system* blackbody_system;
ecs::atmosphere_system* atmosphere_system;
ecs::astronomy_system* astronomy_system;
ecs::orbit_system* orbit_system;
entity::system::behavior* behavior_system;
entity::system::camera* camera_system;
entity::system::collision* collision_system;
entity::system::constraint* constraint_system;
entity::system::control* control_system;
entity::system::locomotion* locomotion_system;
entity::system::nest* nest_system;
entity::system::snapping* snapping_system;
entity::system::render* render_system;
entity::system::samara* samara_system;
entity::system::subterrain* subterrain_system;
entity::system::terrain* terrain_system;
entity::system::tool* tool_system;
entity::system::ui* ui_system;
entity::system::vegetation* vegetation_system;
entity::system::spatial* spatial_system;
entity::system::tracking* tracking_system;
entity::system::painting* painting_system;
entity::system::blackbody* blackbody_system;
entity::system::atmosphere* atmosphere_system;
entity::system::astronomy* astronomy_system;
entity::system::orbit* orbit_system;
// Game
biome* biome;

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

@ -21,22 +21,22 @@
#include "animation/screen-transition.hpp"
#include "configuration.hpp"
#include "debug/logger.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/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/components/blackbody-component.hpp"
#include "ecs/components/celestial-body-component.hpp"
#include "ecs/components/atmosphere-component.hpp"
#include "ecs/components/light-component.hpp"
#include "ecs/commands.hpp"
#include "entity/archetype.hpp"
#include "entity/components/cavity.hpp"
#include "entity/components/copy-transform.hpp"
#include "entity/components/copy-translation.hpp"
#include "entity/components/model.hpp"
#include "entity/components/snap.hpp"
#include "entity/components/terrain.hpp"
#include "entity/components/tool.hpp"
#include "entity/components/transform.hpp"
#include "entity/components/camera-follow.hpp"
#include "entity/components/orbit.hpp"
#include "entity/components/blackbody.hpp"
#include "entity/components/celestial-body.hpp"
#include "entity/components/atmosphere.hpp"
#include "entity/components/light.hpp"
#include "entity/commands.hpp"
#include "game/game-context.hpp"
#include "game/states/game-states.hpp"
#include "math/math.hpp"
@ -54,12 +54,12 @@
#include "scene/camera.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.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/orbit-system.hpp"
#include "ecs/systems/astronomy-system.hpp"
#include "entity/systems/control.hpp"
#include "entity/systems/camera.hpp"
#include "entity/systems/render.hpp"
#include "entity/systems/tool.hpp"
#include "entity/systems/orbit.hpp"
#include "entity/systems/astronomy.hpp"
#include "game/biome.hpp"
#include "utility/fundamental-types.hpp"
@ -76,7 +76,7 @@ void play_state_enter(game_context* ctx)
logger->push_task("Entering play state");
resource_manager* resource_manager = ctx->resource_manager;
entt::registry& ecs_registry = *ctx->ecs_registry;
entt::registry& entity_registry = *ctx->entity_registry;
// Load biome
if (ctx->option_biome.has_value())
@ -95,15 +95,15 @@ void play_state_enter(game_context* ctx)
sky_pass->set_moon_model(ctx->resource_manager->load<model>("moon.mdl"));
// Create sun
auto sun_entity = ecs_registry.create();
auto sun_entity = entity_registry.create();
{
ecs::celestial_body_component body;
entity::component::celestial_body body;
body.radius = 6.957e+8;
body.axial_tilt = math::radians(0.0);
body.axial_rotation = math::radians(0.0);
body.angular_frequency = math::radians(0.0);
ecs::orbit_component orbit;
entity::component::orbit orbit;
orbit.elements.a = 0.0;
orbit.elements.e = 0.0;
orbit.elements.i = math::radians(0.0);
@ -111,29 +111,29 @@ void play_state_enter(game_context* ctx)
orbit.elements.w = math::radians(0.0);
orbit.elements.ta = math::radians(0.0);
ecs::blackbody_component blackbody;
entity::component::blackbody blackbody;
blackbody.temperature = 5778.0;
ecs::transform_component transform;
entity::component::transform transform;
transform.local = math::identity_transform<float>;
transform.warp = true;
ecs_registry.assign<ecs::celestial_body_component>(sun_entity, body);
ecs_registry.assign<ecs::orbit_component>(sun_entity, orbit);
ecs_registry.assign<ecs::blackbody_component>(sun_entity, blackbody);
ecs_registry.assign<ecs::transform_component>(sun_entity, transform);
entity_registry.assign<entity::component::celestial_body>(sun_entity, body);
entity_registry.assign<entity::component::orbit>(sun_entity, orbit);
entity_registry.assign<entity::component::blackbody>(sun_entity, blackbody);
entity_registry.assign<entity::component::transform>(sun_entity, transform);
}
// Create Earth
auto earth_entity = ecs_registry.create();
auto earth_entity = entity_registry.create();
{
ecs::celestial_body_component body;
entity::component::celestial_body body;
body.radius = 6.3781e6;
body.axial_tilt = math::radians(23.4393);
body.axial_rotation = math::radians(280.46061837504);
body.angular_frequency = math::radians(360.9856122880876128);
ecs::orbit_component orbit;
entity::component::orbit orbit;
orbit.elements.a = 1.496e+11;
orbit.elements.e = 0.01671123;
orbit.elements.i = math::radians(-0.00001531);
@ -142,7 +142,7 @@ void play_state_enter(game_context* ctx)
orbit.elements.w = longitude_periapsis - orbit.elements.raan;
orbit.elements.ta = math::radians(100.46457166) - longitude_periapsis;
ecs::atmosphere_component atmosphere;
entity::component::atmosphere atmosphere;
atmosphere.exosphere_altitude = 65e3;
atmosphere.index_of_refraction = 1.000293;
atmosphere.rayleigh_density = 2.545e25;
@ -151,14 +151,14 @@ void play_state_enter(game_context* ctx)
atmosphere.mie_scale_height = 1200.0;
atmosphere.mie_anisotropy = 0.8;
ecs::transform_component transform;
entity::component::transform transform;
transform.local = math::identity_transform<float>;
transform.warp = true;
ecs_registry.assign<ecs::celestial_body_component>(earth_entity, body);
ecs_registry.assign<ecs::orbit_component>(earth_entity, orbit);
ecs_registry.assign<ecs::atmosphere_component>(earth_entity, atmosphere);
ecs_registry.assign<ecs::transform_component>(earth_entity, transform);
entity_registry.assign<entity::component::celestial_body>(earth_entity, body);
entity_registry.assign<entity::component::orbit>(earth_entity, orbit);
entity_registry.assign<entity::component::atmosphere>(earth_entity, atmosphere);
entity_registry.assign<entity::component::transform>(earth_entity, transform);
}
scene::ambient_light* ambient = new scene::ambient_light();
@ -189,36 +189,36 @@ void play_state_enter(game_context* ctx)
ctx->astronomy_system->set_sky_pass(ctx->overworld_sky_pass);
// Load entity archetypes
ecs::archetype* ant_hill_archetype = resource_manager->load<ecs::archetype>("ant-hill.ent");
ecs::archetype* nest_archetype = resource_manager->load<ecs::archetype>("harvester-nest.ent");
ecs::archetype* redwood_archetype = resource_manager->load<ecs::archetype>("redwood.ent");
ecs::archetype* forceps_archetype = resource_manager->load<ecs::archetype>("forceps.ent");
ecs::archetype* lens_archetype = resource_manager->load<ecs::archetype>("lens.ent");
ecs::archetype* brush_archetype = resource_manager->load<ecs::archetype>("brush.ent");
ecs::archetype* marker_archetype = resource_manager->load<ecs::archetype>("marker.ent");
ecs::archetype* container_archetype = resource_manager->load<ecs::archetype>("container.ent");
ecs::archetype* twig_archetype = resource_manager->load<ecs::archetype>("twig.ent");
ecs::archetype* larva_archetype = resource_manager->load<ecs::archetype>("ant-larva.ent");
ecs::archetype* flashlight_archetype = resource_manager->load<ecs::archetype>("flashlight.ent");
ecs::archetype* flashlight_light_cone_archetype = resource_manager->load<ecs::archetype>("flashlight-light-cone.ent");
ecs::archetype* lens_light_cone_archetype = resource_manager->load<ecs::archetype>("lens-light-cone.ent");
ecs::archetype* cube_archetype = resource_manager->load<ecs::archetype>("unit-cube.ent");
ecs::archetype* color_checker_archetype = resource_manager->load<ecs::archetype>("color-checker.ent");
entity::archetype* ant_hill_archetype = resource_manager->load<entity::archetype>("ant-hill.ent");
entity::archetype* nest_archetype = resource_manager->load<entity::archetype>("harvester-nest.ent");
entity::archetype* redwood_archetype = resource_manager->load<entity::archetype>("redwood.ent");
entity::archetype* forceps_archetype = resource_manager->load<entity::archetype>("forceps.ent");
entity::archetype* lens_archetype = resource_manager->load<entity::archetype>("lens.ent");
entity::archetype* brush_archetype = resource_manager->load<entity::archetype>("brush.ent");
entity::archetype* marker_archetype = resource_manager->load<entity::archetype>("marker.ent");
entity::archetype* container_archetype = resource_manager->load<entity::archetype>("container.ent");
entity::archetype* twig_archetype = resource_manager->load<entity::archetype>("twig.ent");
entity::archetype* larva_archetype = resource_manager->load<entity::archetype>("ant-larva.ent");
entity::archetype* flashlight_archetype = resource_manager->load<entity::archetype>("flashlight.ent");
entity::archetype* flashlight_light_cone_archetype = resource_manager->load<entity::archetype>("flashlight-light-cone.ent");
entity::archetype* lens_light_cone_archetype = resource_manager->load<entity::archetype>("lens-light-cone.ent");
entity::archetype* cube_archetype = resource_manager->load<entity::archetype>("unit-cube.ent");
entity::archetype* color_checker_archetype = resource_manager->load<entity::archetype>("color-checker.ent");
// Create tools
forceps_archetype->assign(ecs_registry, ctx->forceps_entity);
lens_archetype->assign(ecs_registry, ctx->lens_entity);
brush_archetype->assign(ecs_registry, ctx->brush_entity);
marker_archetype->assign(ecs_registry, ctx->marker_entity);
container_archetype->assign(ecs_registry, ctx->container_entity);
twig_archetype->assign(ecs_registry, ctx->twig_entity);
forceps_archetype->assign(entity_registry, ctx->forceps_entity);
lens_archetype->assign(entity_registry, ctx->lens_entity);
brush_archetype->assign(entity_registry, ctx->brush_entity);
marker_archetype->assign(entity_registry, ctx->marker_entity);
container_archetype->assign(entity_registry, ctx->container_entity);
twig_archetype->assign(entity_registry, ctx->twig_entity);
// 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);
ecs::command::parent(ecs_registry, flashlight_light_cone, ctx->flashlight_entity);
ecs::command::assign_render_layers(ecs_registry, ctx->flashlight_entity, 2);
ecs::command::assign_render_layers(ecs_registry, flashlight_light_cone, 2);
flashlight_archetype->assign(entity_registry, ctx->flashlight_entity);
auto flashlight_light_cone = flashlight_light_cone_archetype->create(entity_registry);
entity::command::parent(entity_registry, flashlight_light_cone, ctx->flashlight_entity);
entity::command::assign_render_layers(entity_registry, ctx->flashlight_entity, 2);
entity::command::assign_render_layers(entity_registry, flashlight_light_cone, 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);
@ -228,27 +228,27 @@ 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);
ecs::command::bind_transform(ecs_registry, lens_light_cone, ctx->lens_entity);
ecs::command::parent(ecs_registry, lens_light_cone, ctx->lens_entity);
auto lens_light_cone = lens_light_cone_archetype->create(entity_registry);
entity::command::bind_transform(entity_registry, lens_light_cone, ctx->lens_entity);
entity::command::parent(entity_registry, lens_light_cone, ctx->lens_entity);
// Hide inactive tools
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);
entity::command::assign_render_layers(entity_registry, ctx->forceps_entity, 0);
entity::command::assign_render_layers(entity_registry, ctx->brush_entity, 0);
entity::command::assign_render_layers(entity_registry, ctx->lens_entity, 0);
entity::command::assign_render_layers(entity_registry, ctx->marker_entity, 0);
entity::command::assign_render_layers(entity_registry, ctx->container_entity, 0);
entity::command::assign_render_layers(entity_registry, ctx->twig_entity, 0);
// Activate brush tool
//ctx->tool_system->set_active_tool(ctx->brush_entity);
// Create ant-hill
auto ant_hill_entity = ant_hill_archetype->create(ecs_registry);
ecs::command::place(ecs_registry, ant_hill_entity, {0, -40});
auto ant_hill_entity = ant_hill_archetype->create(entity_registry);
entity::command::place(entity_registry, ant_hill_entity, {0, -40});
// Creat nest
auto nest_entity = nest_archetype->create(ecs_registry);
auto nest_entity = nest_archetype->create(entity_registry);
// Create terrain
int terrain_radius = 0;//6;
@ -256,49 +256,49 @@ void play_state_enter(game_context* ctx)
{
for (int z = -terrain_radius; z <= terrain_radius; ++z)
{
ecs::terrain_component terrain_component;
terrain_component.subdivisions = TERRAIN_PATCH_RESOLUTION;
terrain_component.x = x;
terrain_component.z = z;
auto terrain_entity = ecs_registry.create();
ecs_registry.assign<ecs::terrain_component>(terrain_entity, terrain_component);
entity::component::terrain terrain;
terrain.subdivisions = TERRAIN_PATCH_RESOLUTION;
terrain.x = x;
terrain.z = z;
auto terrain_entity = entity_registry.create();
entity_registry.assign<entity::component::terrain>(terrain_entity, terrain);
}
}
// Create trees
for (int i = 0; i < 0; ++i)
{
auto redwood = redwood_archetype->create(ecs_registry);
auto redwood = redwood_archetype->create(entity_registry);
auto& transform = ecs_registry.get<ecs::transform_component>(redwood);
auto& transform = entity_registry.get<entity::component::transform>(redwood);
float zone = 500.0f;
ecs::command::place(ecs_registry, redwood, {math::random(-zone, zone), math::random(-zone, zone)});
entity::command::place(entity_registry, redwood, {math::random(-zone, zone), math::random(-zone, zone)});
}
// Create unit cube
auto cube = cube_archetype->create(ecs_registry);
ecs::command::place(ecs_registry, cube, {10, 10});
auto cube = cube_archetype->create(entity_registry);
entity::command::place(entity_registry, cube, {10, 10});
// Create color checker
auto color_checker = color_checker_archetype->create(ecs_registry);
ecs::command::place(ecs_registry, color_checker, {-10, -10});
auto& cc_transform = ecs_registry.get<ecs::transform_component>(color_checker);
auto color_checker = color_checker_archetype->create(entity_registry);
entity::command::place(entity_registry, color_checker, {-10, -10});
auto& cc_transform = entity_registry.get<entity::component::transform>(color_checker);
cc_transform.local.scale *= 10.0f;
cc_transform.local.rotation = math::angle_axis(math::radians(-90.0f), {1, 0, 0});
// Setup camera focal point
ecs::transform_component focal_point_transform;
entity::component::transform focal_point_transform;
focal_point_transform.local = math::identity_transform<float>;
focal_point_transform.warp = true;
ecs::camera_follow_component focal_point_follow;
ecs::snap_component focal_point_snap;
entity::component::camera_follow focal_point_follow;
entity::component::snap focal_point_snap;
focal_point_snap.ray = {float3{0, 10000, 0}, float3{0, -1, 0}};
focal_point_snap.warp = false;
focal_point_snap.relative = true;
focal_point_snap.autoremove = false;
ecs_registry.assign_or_replace<ecs::transform_component>(ctx->focal_point_entity, focal_point_transform);
ecs_registry.assign_or_replace<ecs::camera_follow_component>(ctx->focal_point_entity, focal_point_follow);
ecs_registry.assign_or_replace<ecs::snap_component>(ctx->focal_point_entity, focal_point_snap);
entity_registry.assign_or_replace<entity::component::transform>(ctx->focal_point_entity, focal_point_transform);
entity_registry.assign_or_replace<entity::component::camera_follow>(ctx->focal_point_entity, focal_point_follow);
entity_registry.assign_or_replace<entity::component::snap>(ctx->focal_point_entity, focal_point_snap);
// Setup camera
ctx->overworld_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
@ -336,12 +336,12 @@ void play_state_enter(game_context* ctx)
float shift = 0.1f;
for (int i = 0; i < 800; ++i)
{
ecs::cavity_component cavity;
entity::component::cavity cavity;
cavity.position = nest->extend_shaft(*nest->get_central_shaft());
cavity.position += float3{math::random(-shift, shift), math::random(-shift, shift), math::random(-shift, shift)};
cavity.radius = tunnel_radius * math::random(1.0f, 1.1f);
ecs_registry.assign<ecs::cavity_component>(ecs_registry.create(), cavity);
entity_registry.assign<entity::component::cavity>(entity_registry.create(), cavity);
}
// Dig nest chambers
@ -350,28 +350,28 @@ void play_state_enter(game_context* ctx)
{
for (int j = 0; j < 150; ++j)
{
ecs::cavity_component cavity;
entity::component::cavity cavity;
cavity.position = nest->expand_chamber(central_shaft->chambers[i]);
cavity.position += float3{math::random(-shift, shift), math::random(-shift, shift), math::random(-shift, shift)};
cavity.radius = tunnel_radius * math::random(1.0f, 1.1f);
ecs_registry.assign<ecs::cavity_component>(ecs_registry.create(), cavity);
entity_registry.assign<entity::component::cavity>(entity_registry.create(), cavity);
}
}
*/
// Place larva in chamber
{
auto larva = larva_archetype->create(ecs_registry);
ecs::command::assign_render_layers(ecs_registry, larva, 1);
ecs::command::warp_to(ecs_registry, larva, {50, 0.1935f, 0});
//auto& transform = ecs_registry.get<ecs::transform_component>(larva_entity);
auto larva = larva_archetype->create(entity_registry);
entity::command::assign_render_layers(entity_registry, larva, 1);
entity::command::warp_to(entity_registry, larva, {50, 0.1935f, 0});
//auto& transform = entity_registry.get<entity::component::transform>(larva_entity);
//transform.transform = math::identity_transform<float>;
//transform.transform.translation = nest->get_shaft_position(*central_shaft, central_shaft->depth[1]);
//transform.transform.translation.y -= 1.0f;
}
ecs::control_system* control_system = ctx->control_system;
entity::system::control* control_system = ctx->control_system;
control_system->update(0.0, 0.0);
control_system->set_nest(nest);

+ 0
- 1
src/nest.hpp View File

@ -87,4 +87,3 @@ inline nest::shaft* nest::get_central_shaft()
}
#endif // ANTKEEPER_NEST_HPP

+ 22
- 22
src/resources/behavior-tree-loader.cpp View File

@ -19,7 +19,7 @@
#include "resource-loader.hpp"
#include "resource-manager.hpp"
#include "ecs/ebt.hpp"
#include "entity/ebt.hpp"
#include <nlohmann/json.hpp>
#include <functional>
#include <map>
@ -43,7 +43,7 @@ void parse_argument(std::string& value, const std::string& string)
}
template <class T, class... Args>
std::function<ecs::ebt::status(ecs::ebt::context&)> pack_function(T (*function)(ecs::ebt::context&, Args...), std::list<std::string> argv)
std::function<entity::ebt::status(entity::ebt::context&)> pack_function(T (*function)(entity::ebt::context&, Args...), std::list<std::string> argv)
{
//if (argv.size() != sizeof...(Args))
@ -60,18 +60,18 @@ std::function pack_function(T (*function)(
}
return std::bind(
[function, arguments](ecs::ebt::context& context) -> ecs::ebt::status
[function, arguments](entity::ebt::context& context) -> entity::ebt::status
{
return std::apply(function, std::tuple_cat(std::make_tuple(context), arguments));
},
std::placeholders::_1);
}
static ecs::ebt::node* load_node(const nlohmann::json::const_iterator& json, resource_manager* resource_manager);
static void load_node_child(ecs::ebt::decorator_node* node, const nlohmann::json& json, resource_manager* resource_manager);
static void load_node_children(ecs::ebt::composite_node* node, const nlohmann::json& json, resource_manager* resource_manager);
static entity::ebt::node* load_node(const nlohmann::json::const_iterator& json, resource_manager* resource_manager);
static void load_node_child(entity::ebt::decorator_node* node, const nlohmann::json& json, resource_manager* resource_manager);
static void load_node_children(entity::ebt::composite_node* node, const nlohmann::json& json, resource_manager* resource_manager);
static ecs::ebt::node* load_action_node(const nlohmann::json& json, resource_manager* resource_manager)
static entity::ebt::node* load_action_node(const nlohmann::json& json, resource_manager* resource_manager)
{
// Get function name
auto function_it = json.find("function");
@ -85,31 +85,31 @@ static ecs::ebt::node* load_action_node(const nlohmann::json& json, resource_man
for (auto it = arguments_it.value().cbegin(); it != arguments_it.value().cend(); ++it)
arguments.push_back(it.value().get<std::string>());
ecs::ebt::action* action_node = new ecs::ebt::action();
if (function_name == "print") action_node->function = pack_function(ecs::ebt::print, arguments);
else if (function_name == "print_eid") action_node->function = pack_function(ecs::ebt::print_eid, arguments);
else if (function_name == "warp_to") action_node->function = pack_function(ecs::ebt::warp_to, arguments);
entity::ebt::action* action_node = new entity::ebt::action();
if (function_name == "print") action_node->function = pack_function(entity::ebt::print, arguments);
else if (function_name == "print_eid") action_node->function = pack_function(entity::ebt::print_eid, arguments);
else if (function_name == "warp_to") action_node->function = pack_function(entity::ebt::warp_to, arguments);
return action_node;
}
static ecs::ebt::node* load_selector_node(const nlohmann::json& json, resource_manager* resource_manager)
static entity::ebt::node* load_selector_node(const nlohmann::json& json, resource_manager* resource_manager)
{
ecs::ebt::selector* selector_node = new ecs::ebt::selector();
entity::ebt::selector* selector_node = new entity::ebt::selector();
load_node_children(selector_node, json, resource_manager);
return selector_node;
}
static ecs::ebt::node* load_sequence_node(const nlohmann::json& json, resource_manager* resource_manager)
static entity::ebt::node* load_sequence_node(const nlohmann::json& json, resource_manager* resource_manager)
{
ecs::ebt::sequence* sequence_node = new ecs::ebt::sequence();
entity::ebt::sequence* sequence_node = new entity::ebt::sequence();
load_node_children(sequence_node, json, resource_manager);
return sequence_node;
}
static ecs::ebt::node* load_node(const nlohmann::json::const_iterator& json, resource_manager* resource_manager)
static entity::ebt::node* load_node(const nlohmann::json::const_iterator& json, resource_manager* resource_manager)
{
static const std::map<std::string, std::function<ecs::ebt::node*(const nlohmann::json&, ::resource_manager*)>> node_loaders =
static const std::map<std::string, std::function<entity::ebt::node*(const nlohmann::json&, ::resource_manager*)>> node_loaders =
{
{"action", &load_action_node},
{"selector", &load_selector_node},
@ -125,24 +125,24 @@ static ecs::ebt::node* load_node(const nlohmann::json::const_iterator& json, res
return node_loader->second(json.value(), resource_manager);
}
static void load_node_child(ecs::ebt::decorator_node* node, const nlohmann::json& json, resource_manager* resource_manager)
static void load_node_child(entity::ebt::decorator_node* node, const nlohmann::json& json, resource_manager* resource_manager)
{
auto it = json.find("child");
node->child = load_node(it.value().cbegin(), resource_manager);
}
static void load_node_children(ecs::ebt::composite_node* node, const nlohmann::json& json, resource_manager* resource_manager)
static void load_node_children(entity::ebt::composite_node* node, const nlohmann::json& json, resource_manager* resource_manager)
{
auto children_it = json.find("children");
for (auto it = children_it.value().cbegin(); it != children_it.value().cend(); ++it)
{
ecs::ebt::node* child = load_node(it.value().begin(), resource_manager);
entity::ebt::node* child = load_node(it.value().begin(), resource_manager);
node->children.push_back(child);
}
}
template <>
ecs::ebt::node* resource_loader<ecs::ebt::node>::load(resource_manager* resource_manager, PHYSFS_File* file)
entity::ebt::node* resource_loader<entity::ebt::node>::load(resource_manager* resource_manager, PHYSFS_File* file)
{
// Read file into buffer
std::size_t size = static_cast<int>(PHYSFS_fileLength(file));
@ -155,7 +155,7 @@ ecs::ebt::node* resource_loader::load(resource_manager* resource
if (json.size() != 1)
{
throw std::runtime_error("resource_loader<ecs::ebt::node>::load(): Behavior tree must have exactly one root node.");
throw std::runtime_error("resource_loader<entity::ebt::node>::load(): Behavior tree must have exactly one root node.");
}
return load_node(json.cbegin(), resource_manager);

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

@ -21,161 +21,159 @@
#include "resource-manager.hpp"
#include "string-table.hpp"
#include "renderer/model.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 "ecs/ebt.hpp"
#include "entity/components/behavior.hpp"
#include "entity/components/collision.hpp"
#include "entity/components/terrain.hpp"
#include "entity/components/transform.hpp"
#include "entity/components/model.hpp"
#include "entity/components/nest.hpp"
#include "entity/components/tool.hpp"
#include "entity/components/marker.hpp"
#include "entity/components/brush.hpp"
#include "entity/archetype.hpp"
#include "entity/ebt.hpp"
#include <sstream>
#include <stdexcept>
using namespace ecs;
static bool load_behavior_component(archetype& archetype, resource_manager& resource_manager, const std::vector<std::string>& parameters)
static bool load_component_behavior(entity::archetype& archetype, resource_manager& resource_manager, const std::vector<std::string>& parameters)
{
if (parameters.size() != 2)
{
throw std::runtime_error("load_behavior_component(): Invalid parameter count.");
throw std::runtime_error("load_component_behavior(): Invalid parameter count.");
}
std::string filename = parameters[1];
behavior_component component;
component.behavior_tree = resource_manager.load<ecs::ebt::node>(filename);
entity::component::behavior component;
component.behavior_tree = resource_manager.load<entity::ebt::node>(filename);
if (!component.behavior_tree)
{
std::string message = std::string("load_behavior_component(): Failed to load behavior tree \"") + filename + std::string("\"");
std::string message = std::string("load_component_behavior(): Failed to load behavior tree \"") + filename + std::string("\"");
throw std::runtime_error(message);
}
archetype.set<behavior_component>(component);
archetype.set<entity::component::behavior>(component);
return true;
}
static bool load_collision_component(archetype& archetype, resource_manager& resource_manager, const std::vector<std::string>& parameters)
static bool load_component_collision(entity::archetype& archetype, resource_manager& resource_manager, const std::vector<std::string>& parameters)
{
if (parameters.size() != 2)
{
throw std::runtime_error("load_collision_component(): Invalid parameter count.");
throw std::runtime_error("load_component_collision(): Invalid parameter count.");
}
std::string filename = parameters[1];
collision_component component;
entity::component::collision component;
component.mesh = resource_manager.load<geom::mesh>(filename);
if (!component.mesh)
{
std::string message = std::string("load_collision_component(): Failed to load model \"") + filename + std::string("\"");
std::string message = std::string("load_component_collision(): Failed to load model \"") + filename + std::string("\"");
throw std::runtime_error(message);
}
archetype.set<collision_component>(component);
archetype.set<entity::component::collision>(component);
return true;
}
static bool load_model_component(archetype& archetype, resource_manager& resource_manager, const std::vector<std::string>& parameters)
static bool load_component_model(entity::archetype& archetype, resource_manager& resource_manager, const std::vector<std::string>& parameters)
{
if (parameters.size() != 2)
{
throw std::runtime_error("load_model_component(): Invalid parameter count.");
throw std::runtime_error("load_component_model(): Invalid parameter count.");
}
std::string filename = parameters[1];
model_component component;
component.model = resource_manager.load<model>(filename);
entity::component::model component;
component.render_model = resource_manager.load<model>(filename);
component.instance_count = 0;
component.layers = 1;
if (!component.model)
if (!component.render_model)
{
std::string message = std::string("load_model_component(): Failed to load model \"") + filename + std::string("\"");
std::string message = std::string("load_component_model(): Failed to load model \"") + filename + std::string("\"");
throw std::runtime_error(message);
}
archetype.set<model_component>(component);
archetype.set<entity::component::model>(component);
return true;
}
static bool load_nest_component(archetype& archetype, const std::vector<std::string>& parameters)
static bool load_component_nest(entity::archetype& archetype, const std::vector<std::string>& parameters)
{
nest_component component;
archetype.set<nest_component>(component);
entity::component::nest component;
archetype.set<entity::component::nest>(component);
return true;
}
static bool load_marker_component(archetype& archetype, const std::vector<std::string>& parameters)
static bool load_component_marker(entity::archetype& archetype, const std::vector<std::string>& parameters)
{
if (parameters.size() != 2)
{
throw std::runtime_error("load_marker_component(): Invalid parameter count.");
throw std::runtime_error("load_component_marker(): Invalid parameter count.");
}
marker_component component;
entity::component::marker component;
component.color = std::stoi(parameters[1]);
archetype.set<marker_component>(component);
archetype.set<entity::component::marker>(component);
return true;
}
static bool load_brush_component(archetype& archetype, const std::vector<std::string>& parameters)
static bool load_component_brush(entity::archetype& archetype, const std::vector<std::string>& parameters)
{
if (parameters.size() != 2)
{
throw std::runtime_error("load_brush_component(): Invalid parameter count.");
throw std::runtime_error("load_component_brush(): Invalid parameter count.");
}
brush_component component;
entity::component::brush component;
component.radius = std::stof(parameters[1]);
archetype.set<brush_component>(component);
archetype.set<entity::component::brush>(component);
return true;
}
static bool load_terrain_component(archetype& archetype, const std::vector<std::string>& parameters)
static bool load_component_terrain(entity::archetype& archetype, const std::vector<std::string>& parameters)
{
if (parameters.size() != 4)
{
throw std::runtime_error("load_terrain_component(): Invalid parameter count.");
throw std::runtime_error("load_component_terrain(): Invalid parameter count.");
}
terrain_component component;
entity::component::terrain component;
component.subdivisions = std::stoi(parameters[1]);
component.x = std::stoi(parameters[2]);
component.z = std::stoi(parameters[3]);
archetype.set<terrain_component>(component);
archetype.set<entity::component::terrain>(component);
return true;
}
static bool load_tool_component(archetype& archetype, const std::vector<std::string>& parameters)
static bool load_component_tool(entity::archetype& archetype, const std::vector<std::string>& parameters)
{
if (parameters.size() != 5)
{
throw std::runtime_error("load_tool_component(): Invalid parameter count.");
throw std::runtime_error("load_component_tool(): Invalid parameter count.");
}
tool_component component;
entity::component::tool component;
component.active = static_cast<bool>(std::stoi(parameters[1]));
component.idle_distance = std::stof(parameters[2]);
component.active_distance = std::stof(parameters[3]);
component.heliotropic = static_cast<bool>(std::stoi(parameters[4]));
archetype.set<tool_component>(component);
archetype.set<entity::component::tool>(component);
return true;
}
static bool load_transform_component(archetype& archetype, const std::vector<std::string>& parameters)
static bool load_component_transform(entity::archetype& archetype, const std::vector<std::string>& parameters)
{
if (parameters.size() != 11)
{
throw std::runtime_error("load_transform_component(): Invalid parameter count.");
throw std::runtime_error("load_component_transform(): Invalid parameter count.");
}
std::stringstream stream;
@ -186,7 +184,7 @@ static bool load_transform_component(archetype& archetype, const std::vector
stream << ' ';
}
transform_component component;
entity::component::transform component;
stream >> component.local.translation.x;
stream >> component.local.translation.y;
stream >> component.local.translation.z;
@ -199,31 +197,31 @@ static bool load_transform_component(archetype& archetype, const std::vector
stream >> component.local.scale.z;
component.warp = true;
archetype.set<transform_component>(component);
archetype.set<entity::component::transform>(component);
return true;
}
static bool load_component(archetype& archetype, resource_manager& resource_manager, const std::vector<std::string>& parameters)
static bool load_component(entity::archetype& archetype, resource_manager& resource_manager, const std::vector<std::string>& parameters)
{
if (parameters[0] == "behavior") return load_behavior_component(archetype, resource_manager, parameters);
if (parameters[0] == "collision") return load_collision_component(archetype, resource_manager, parameters);
if (parameters[0] == "model") return load_model_component(archetype, resource_manager, parameters);
if (parameters[0] == "nest") return load_nest_component(archetype, parameters);
if (parameters[0] == "terrain") return load_terrain_component(archetype, parameters);
if (parameters[0] == "tool") return load_tool_component(archetype, parameters);
if (parameters[0] == "transform") return load_transform_component(archetype, parameters);
if (parameters[0] == "marker") return load_marker_component(archetype, parameters);
if (parameters[0] == "brush") return load_brush_component(archetype, parameters);
if (parameters[0] == "behavior") return load_component_behavior(archetype, resource_manager, parameters);
if (parameters[0] == "collision") return load_component_collision(archetype, resource_manager, parameters);
if (parameters[0] == "model") return load_component_model(archetype, resource_manager, parameters);
if (parameters[0] == "nest") return load_component_nest(archetype, parameters);
if (parameters[0] == "terrain") return load_component_terrain(archetype, parameters);
if (parameters[0] == "tool") return load_component_tool(archetype, parameters);
if (parameters[0] == "transform") return load_component_transform(archetype, parameters);
if (parameters[0] == "marker") return load_component_marker(archetype, parameters);
if (parameters[0] == "brush") return load_component_brush(archetype, parameters);
std::string message = std::string("load_component(): Unknown component type \"") + parameters[0] + std::string("\"");
throw std::runtime_error(message);
}
template <>
archetype* resource_loader<archetype>::load(resource_manager* resource_manager, PHYSFS_File* file)
entity::archetype* resource_loader<entity::archetype>::load(resource_manager* resource_manager, PHYSFS_File* file)
{
ecs::archetype* archetype = new ecs::archetype(resource_manager->get_archetype_registry());
entity::archetype* archetype = new entity::archetype(resource_manager->get_archetype_registry());
// Load string table from input stream
string_table* table = resource_loader<string_table>::load(resource_manager, file);

Loading…
Cancel
Save