game/src/net/arena.rs#
Source: lib/game/src/net/arena.rs
arena -- the netcode's reference game: a square arena with walls and crates, walking figures
(walker::Walker), props (some move along circles) and a hitscan weapon with lag compensation. The
tests, the bots and the measurements of G7e run it; G7h can read it as an example of a RoomSim
ArenaConfig its size, the props and how many of them move, the rate, the lag compensation's limit
schema() KIND_PLAYER (13 fields: the walker's 7, yaw, pitch, health, kills, deaths, the tick of the
last shot) and KIND_PROP (7: the position, the rotation's smallest three)
map(cfg) the static map as a physics::World (the same on the server and every client)
baseline(cfg) the props as the map places them (the clients' first base)
Arena the RoomSim: join (a figure at a spawn point), leave, step (move every figure with its
input, move the props, remember the hit volumes, fire: rewind the others to the shooter's
view time, cast the ray), snapshot, priority (figures over props, near over far)
The props are not in the physics world: they do not block the figures in this first part, so the map
every client predicts against stays the server's.
/// the kind of a figure
KIND_PLAYER: u8 = 1
/// the kind of a prop
KIND_PROP: u8 = 2
/// a figure's fields
PLAYER_FIELDS: usize = 13
/// a prop's fields
PROP_FIELDS: usize = 7
/// the fields of a figure after the walker's: yaw, pitch, health, kills, deaths, shot
F_YAW: usize = 7
/// see F_YAW
F_PITCH: usize = 8
/// see F_YAW
F_HEALTH: usize = 9
/// see F_YAW
F_KILLS: usize = 10
/// see F_YAW
F_DEATHS: usize = 11
/// see F_YAW
F_SHOT: usize = 12
/// the first net id of the props (figures have 1 ..= 255)
FIRST_PROP: u16 = 1000
/// a hit's damage, a figure's health
DAMAGE: i32 = 25
/// see DAMAGE
HEALTH: i32 = 100
/// ticks between two shots
FIRE_TICKS: u32 = 6
/// how far a shot reaches (m)
RANGE: f64 = 100.0
struct ArenaConfigthe arena's settingshalf: f64-- half the side of the square (m)props: usize-- propsmoving: usize-- of those, how many move (the first ones)displaced: usize-- of the others, how many stand away from the map's place from the start (moved earlier in a round: they make the full state of a join larger, not the snapshots after it)crates: usize-- crates on the floor (static, in the map)rate: u32-- ticks a second (the props' motion)max_rewind: u32-- how far back hits are rewound at most (ticks; 18 unless set: 300 ms at 60 Hz, as ServerOptions::max_rewind_ms)fire: bool-- figures may shoot
fn schema() -> Schemathe schema of the arena's entitiesfn crates(cfg: &ArenaConfig) -> Vec<(Vec3, Vec3)>the crates of the map: (centre, half extents)fn map(cfg: &ArenaConfig) -> physics::Worldthe static map: a floor (its top at y = 0), four walls, the cratesfn spawn_point(cfg: &ArenaConfig, k: u32) -> Vec3where the k-th figure appears (a ring round the middle)fn baseline(cfg: &ArenaConfig) -> Snapshotthe props as the map places them: every client's first basestruct Figurea figure of the arenaname: String-- its namestate: WalkState-- the walker's stateyaw: u16-- the view (quant steps)pitch: i16-- see yawhealth: i32-- health 0 ..= 100kills: i32-- hits that ended another figuredeaths: i32-- how often it was endedshot: u32-- the tick of its last shotgeneration: u8-- its generation (the net id's)
struct ArenaStatswhat the arena countedshots: u64-- shots firedhits: u64-- of those, hits on a figureclamped: u64-- shots whose view time lay further back than max_rewind (clamped)kills: u64-- figures endedview_sum: u64-- the shooters' view lag summed over the shots (1/256 ticks) and the largestview_max: u32-- see view_sum
struct Arenathe reference RoomSim (see the module header)
impl Arena
fn new(cfg: ArenaConfig) -> Arenaan arena with these settingsfn config(&self) -> &ArenaConfigthe settingsfn map(&self) -> &physics::Worldthe mapfn walker(&self) -> &Walkerthe movementfn figures(&self) -> &BTreeMap<u16, Figure>the figures by net idfn history(&self) -> &HitHistorythe remembered hit volumesfn stats(&self) -> ArenaStatswhat it countedfn teleport(&mut self, id: u16, feet: Vec3)put a figure somewhere else (a teleport: its client reconciles)fn figure_state(&self, f: &Figure) -> NetStatea figure's replicated state