37 if (direction.x != 0.0F && direction.y != 0.0F) {
38 direction /= std::numbers::sqrt2_v<float>;
50 const float delta = tick.
delta();
62 if (motion.period <= 0.0F) {
65 const float angle = 2.0F * std::numbers::pi_v<float> * time / motion.period;
66 return motion.amplitude * std::sin(angle);
81 const float delta = tick.
delta();
86 if (motion.
period > 0.0F) {
100 return sprite->get().size * 0.5F;
103 return collider->get().size * 0.5F;
116 const auto axis = [](
float value,
float margin,
float low,
float high) {
117 const float first = low + margin;
118 const float last = high - margin;
120 return (low + high) * 0.5F;
122 return std::clamp(value, first, last);
124 return Vec2{axis(position.x, half.x, area.min.x, area.max.x),
125 axis(position.y, half.y, area.min.y, area.max.y)};
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
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).
Entity-Component-System used by client and server.
Definition animation.hpp:13
void apply_velocity(Registry ®istry, const Tick &tick)
Moves every entity by its velocity for one tick.
Definition movement.hpp:49
Vec2 sine_offset(const SineMotion &motion, float time) noexcept
Offset of a sine motion from its path at a time.
Definition movement.hpp:61
Vec2 direction_of(const PlayerInput &input) noexcept
Direction a player's input points to.
Definition movement.hpp:23
void apply_sine_motion(Registry ®istry, const Tick &tick)
Moves every entity with a sine motion along its wave for one tick.
Definition movement.hpp:80
Vec2 half_extent_of(const Registry ®istry, Entity entity)
Half size of what must stay visible of an entity.
Definition movement.hpp:98
@ Up
Move up (towards y = 0).
Vec2 clamp_into(Vec2 position, Vec2 half, const Aabb &area) noexcept
Keeps a position inside an area, with a margin on each side.
Definition movement.hpp:115
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
Axis-aligned box an entity collides with.
Definition components.hpp:101
Sine wave added to an entity's movement, like an enemy weaving up and down.
Definition components.hpp:230
float period
Seconds for one full wave; a period of zero or less does not move the entity.
Definition components.hpp:235
float elapsed
Seconds into the current wave, kept in [0, period). Starting above 0 shifts the phase,...
Definition components.hpp:238
What an entity looks like.
Definition components.hpp:34
One simulation step, as the systems see it.
Definition system.hpp:23
constexpr float delta() const noexcept
Duration of the step in seconds, to scale values given per second.
Definition system.hpp:32
How fast an entity moves.
Definition components.hpp:25
Vec2 value
Speed in logical pixels per second.
Definition components.hpp:27
Systems and the scheduler that updates them in order, once per tick.