R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
rtype::PositionHistory Class Reference

The positions of the enemies over the last tuning::position_history_ticks ticks. More...

#include <rtype/position_history.hpp>

Public Member Functions

void record (std::uint64_t tick, aegis2d::ecs::Registry &registry)
 Keeps the positions of the enemies after a tick.
 
std::optional< aegis2d::Vec2 > position (aegis2d::ecs::Entity entity, std::uint64_t tick) const
 Where an enemy was at a past tick.
 
std::vector< std::pair< aegis2d::ecs::Entity, aegis2d::Vec2 > > enemies (std::uint64_t tick) const
 The enemies at a past tick.
 
std::optional< std::uint64_t > oldest () const noexcept
 Oldest tick kept.
 
std::optional< std::uint64_t > newest () const noexcept
 Newest tick kept.
 
std::size_t size () const noexcept
 Number of ticks kept.
 
void clear () noexcept
 Forgets every tick.
 

Static Public Attributes

static constexpr std::size_t capacity = tuning::position_history_ticks
 Ticks kept: 500 ms at 60 ticks per second.
 

Detailed Description

The positions of the enemies over the last tuning::position_history_ticks ticks.

record() keeps, after a tick, the center of every entity of the enemy collision layer; position() gives back where one was at a past tick. A player's missiles can then be checked against the enemies as that player saw them, its round trip time and interpolation delay ago (lag compensation). Older ticks are forgotten. Not thread-safe: use it from the simulation thread.

Member Function Documentation

◆ clear()

void rtype::PositionHistory::clear ( )
noexcept

Forgets every tick.

◆ enemies()

std::vector< std::pair< aegis2d::ecs::Entity, aegis2d::Vec2 > > rtype::PositionHistory::enemies ( std::uint64_t  tick) const

The enemies at a past tick.

Parameters
tickTick to read.
Returns
Their handles and centers, by increasing Entity::id(); empty if the tick is not kept.

◆ newest()

std::optional< std::uint64_t > rtype::PositionHistory::newest ( ) const
noexcept

Newest tick kept.

Returns
It, or nothing before the first record().

◆ oldest()

std::optional< std::uint64_t > rtype::PositionHistory::oldest ( ) const
noexcept

Oldest tick kept.

Returns
It, or nothing before the first record().

◆ position()

std::optional< aegis2d::Vec2 > rtype::PositionHistory::position ( aegis2d::ecs::Entity  entity,
std::uint64_t  tick 
) const

Where an enemy was at a past tick.

Parameters
entityThe enemy, as its handle was then (a reused slot is another entity).
tickTick to read, one of the last capacity recorded.
Returns
Its center, or nothing if the tick is not kept or the enemy was not there.

◆ record()

void rtype::PositionHistory::record ( std::uint64_t  tick,
aegis2d::ecs::Registry &  registry 
)

Keeps the positions of the enemies after a tick.

A tick not newer than the last one recorded starts the history again (a new game); beyond capacity, the oldest tick is forgotten.

Parameters
tickNumber of the tick, ServerGame::ticks() once it ran.
registryWorld of the game: every entity with an ecs::Collider of layer::enemy and an ecs::Transform. Only read, but Registry::view() needs it mutable.

◆ size()

std::size_t rtype::PositionHistory::size ( ) const
noexcept

Number of ticks kept.

Returns
0 to capacity.

Member Data Documentation

◆ capacity

constexpr std::size_t rtype::PositionHistory::capacity = tuning::position_history_ticks
staticconstexpr

Ticks kept: 500 ms at 60 ticks per second.


The documentation for this class was generated from the following file: