52template <
typename Component>
56 if (!(radius >= 0.0F)) {
63 std::vector<std::tuple<float, float, Entity>> ranked;
64 ranked.reserve(out.size());
65 for (
const Entity entity : out) {
66 if (!registry.
alive(entity) || !registry.
has<Component>(entity)) {
74 const float distance = (offset.x * offset.x) + (offset.y * offset.y);
75 if (!(distance <= radius * radius)) {
79 ranked.emplace_back(distance, 0.0F, entity);
82 ranked.emplace_back(follower ?
remaining(follower->get())
83 : std::numeric_limits<float>::infinity(),
87 std::ranges::sort(ranked);
89 for (
const auto& [first, second, entity] : ranked) {
90 out.push_back(entity);
Broad phase of collision detection: a uniform grid over the play area.
Definition collision.hpp:120
void query(const Aabb &area, std::vector< Entity > &out) const
Entities recorded in the cells an area touches.
Handle to an entity: 32 bits made of a 24-bit index and an 8-bit generation.
Definition entity.hpp:23
Entry point of the ECS: creates entities and stores their components.
Definition registry.hpp:34
std::optional< std::reference_wrapper< Component > > try_get(Entity entity)
Component of an entity, if it has one.
Definition registry.hpp:147
bool has(Entity entity) const
Tells whether an entity has every listed component.
Definition registry.hpp:114
bool alive(Entity entity) const noexcept
Tells whether a handle designates a living entity.
Collision detection: a uniform grid finds the entities close enough to collide (broad phase),...
Components shared by the client and the server.
Generational entity handle: an index into the component pools plus a generation.
Vector and matrix types of the engine (GLM behind engine names).
Entity-Component-System used by client and server.
Definition animation.hpp:13
float remaining(const PathFollower &follower) noexcept
Distance a follower still has to walk.
Definition path_following.hpp:91
void find_targets(const Registry ®istry, const CollisionGrid &grid, Vec2 center, float radius, TargetOrder order, std::vector< Entity > &out)
Lists the entities with a component whose center is within a radius of a point, in the order asked.
Definition targeting.hpp:53
TargetOrder
Which targets come first in find_targets().
Definition targeting.hpp:21
@ Nearest
The closest to the point first.
@ MostAdvanced
The furthest along its path first: the least PathFollower remaining(), then the closest; entities tha...
glm::vec2 Vec2
2D vector of floats: positions, velocities, sizes (glm::vec2).
Definition math.hpp:19
Path following: entities that walk along waypoints at a steady speed, and tell when they reach the en...
Registry: owns the entities and one component pool per component type.
Axis-aligned box given by its two corners, in logical pixels.
Definition collision.hpp:20
Vec2 min
Top-left corner (smallest x and y).
Definition collision.hpp:22
An entity that walks along waypoints, such as an enemy of a tower defense on the path found by NavGri...
Definition path_following.hpp:26