26 const Aabb& area)
noexcept {
27 const auto axis = [](
float center,
float extent,
float speed,
float low,
float high) {
28 const bool beyond_high = center - extent >= high && speed >= 0.0F;
29 const bool beyond_low = center + extent <= low && speed <= 0.0F;
30 return beyond_high || beyond_low;
32 return axis(position.x, half.x, velocity.x, area.min.x, area.max.x) ||
33 axis(position.y, half.y, velocity.y, area.min.y, area.max.y);
57 const Aabb bounds{.
min = area.
min - margin, .max = area.
max + margin};
59 despawned.push_back(entity);
62 for (
const Entity entity : despawned) {
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 destroy(Entity entity)
Destroys an entity and removes all its components.
View< Components... > view()
View on the entities that own all the listed components.
Definition registry.hpp:222
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).
Movement: the direction of a player's input, velocities applied each tick, sine motions on top of the...
Entity-Component-System used by client and server.
Definition animation.hpp:13
Vec2 half_extent_of(const Registry ®istry, Entity entity)
Half size of what must stay visible of an entity.
Definition movement.hpp:98
bool left_for_good(Vec2 position, Vec2 half, Vec2 velocity, const Aabb &area) noexcept
Tells whether a moving box has left an area and will not come back.
Definition despawn.hpp:25
void despawn_outside(Registry ®istry, const Aabb &area, std::vector< Entity > &despawned)
Destroys the entities that have left the play area for good.
Definition despawn.hpp:48
glm::vec2 Vec2
2D vector of floats: positions, velocities, sizes (glm::vec2).
Definition math.hpp:19
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 max
Bottom-right corner (largest x and y).
Definition collision.hpp:24
Vec2 min
Top-left corner (smallest x and y).
Definition collision.hpp:22
Entity destroyed once it has left the play area for good.
Definition components.hpp:217
float margin
Distance beyond each edge of the area, in logical pixels, before the entity counts as gone.
Definition components.hpp:220
How fast an entity moves.
Definition components.hpp:25
Vec2 value
Speed in logical pixels per second.
Definition components.hpp:27