|
| void | apply (const GameEvent &event, Clock::time_point now) |
| | Applies an event.
|
| |
| void | apply (const Snapshot &snapshot) |
| | Applies the records of one Snapshot datagram.
|
| |
| void | apply (const Snapshot &snapshot, Clock::time_point received) |
| | Applies a Snapshot datagram and times its tick, for server_tick().
|
| |
| std::optional< double > | server_tick (Clock::time_point now) const |
| | Server tick at a time, estimated from the snapshots received.
|
| |
| std::optional< double > | render_tick (Clock::time_point now) const |
| | Tick at which to draw the world: server_tick() interpolation_delay(now) ago.
|
| |
| Clock::duration | interpolation_delay (Clock::time_point now) const noexcept |
| | How far behind the server the remote entities are drawn, following the jitter.
|
| |
| aegis2d::Vec2 | position_at (aegis2d::ecs::Entity entity, double tick) const |
| | Where to draw an entity at a tick: its trail interpolated (interpolate()).
|
| |
| std::vector< GameEvent > | take_events () |
| | Events applied since the last call, in order: those ignored (late, unknown kind) are not in it.
|
| |
| void | join (std::uint8_t player, std::string name) |
| | Records the local player, whose own PlayerJoined the server never sends (RFC section 4.6: it goes to the others).
|
| |
| void | prune (Clock::time_point now) |
| | Forgets the destroyed ids whose Destroy is forget_after old.
|
| |
| std::optional< aegis2d::ecs::Entity > | entity (std::uint32_t id) const |
| | Entity of a network id.
|
| |
| std::size_t | entities () const noexcept |
| | Number of entities alive.
|
| |
| const std::array< std::optional< RemotePlayer >, tuning::max_players > & | players () const noexcept |
| | The players of the game, by number.
|
| |
| aegis2d::ecs::Registry & | registry () noexcept |
| | The world, to draw it.
|
| |
| const aegis2d::ecs::Registry & | registry () const noexcept |
| | The world, to draw it.
|
| |
|
| static constexpr std::chrono::seconds | forget_after {10} |
| | Time after which a destroyed id is forgotten (RFC section 4.5).
|
| |
| static constexpr std::chrono::milliseconds | initial_interpolation_delay {100} |
| | How far behind the server the remote entities are drawn at first: two snapshot intervals at 20 Hz, until the snapshots' arrivals are measured.
|
| |
| static constexpr std::chrono::milliseconds | min_interpolation_delay {50} |
| | Shortest interpolation delay: one snapshot interval at 20 Hz, enough when every snapshot arrives on time.
|
| |
| static constexpr std::chrono::milliseconds | max_interpolation_delay {200} |
| | Longest interpolation delay, however late the snapshots.
|
| |
| static constexpr std::chrono::seconds | jitter_window {2} |
| | How long the lateness of the snapshots is remembered for the delay.
|
| |
| static constexpr double | delay_decrease = 0.01 |
| | Speed at which the delay goes down once the snapshots arrive more regularly: 10 ms per second, so the entities drawn speed up by 1 %, which no one sees.
|
| |
| static constexpr double | delay_increase = 0.5 |
| | Speed at which the delay goes up when the snapshots come later: half a millisecond per millisecond, so the entities drawn slow down to half speed for a moment, but never stop or go back.
|
| |
The world as the server describes it (RFC sections 4.3 to 4.5).
Events create and destroy the entities: a Spawn creates one with a Transform, a Velocity, a Sprite of its kind's size, a NetworkId and Replicated, and a Destroy removes it. Snapshots only update them (position, velocity, frame), never create or destroy one. As events and snapshots arrive in any order, the world keeps for each network id the tick of its last Spawn or Destroy, and:
- ignores a
Spawn or a Destroy older than the last one applied to the id, so a Destroy arriving before its Spawn wins;
- ignores the snapshot records of an id it does not know, or destroyed at the record's tick or later, or older than the last record applied to it;
- forgets a destroyed id forget_after its
Destroy, after which the id may be reused;
- ignores entities of a kind it does not know.
The players come from the player records of the snapshots, PlayerJoined, PlayerLeft and Death. Not thread-safe: use it from the client's thread.
| Clock::duration rtype::ClientWorld::interpolation_delay |
( |
Clock::time_point |
now | ) |
const |
|
noexcept |
How far behind the server the remote entities are drawn, following the jitter.
Each snapshot is timed against the fastest arrival (server_tick()): how late it came is its lateness. The delay aims at one snapshot interval (50 ms) plus 1.25 times the largest lateness of the last jitter_window, within min_interpolation_delay and max_interpolation_delay, so the tick drawn always has a snapshot after it: no entity stops for lack of snapshots. It moves towards its aim with time, up by delay_increase and down by delay_decrease, so the drawing slows down or speeds up but never jumps back in time.
- Parameters
-
- Returns
- The delay, initial_interpolation_delay before the first snapshot.