JFLib

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 ArenaConfig the arena's settings

    • half: f64 -- half the side of the square (m)
    • props: usize -- props
    • moving: 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() -> Schema the schema of the arena's entities

  • fn crates(cfg: &ArenaConfig) -> Vec<(Vec3, Vec3)> the crates of the map: (centre, half extents)

  • fn map(cfg: &ArenaConfig) -> physics::World the static map: a floor (its top at y = 0), four walls, the crates

  • fn spawn_point(cfg: &ArenaConfig, k: u32) -> Vec3 where the k-th figure appears (a ring round the middle)

  • fn baseline(cfg: &ArenaConfig) -> Snapshot the props as the map places them: every client's first base

  • struct Figure a figure of the arena

    • name: String -- its name
    • state: WalkState -- the walker's state
    • yaw: u16 -- the view (quant steps)
    • pitch: i16 -- see yaw
    • health: i32 -- health 0 ..= 100
    • kills: i32 -- hits that ended another figure
    • deaths: i32 -- how often it was ended
    • shot: u32 -- the tick of its last shot
    • generation: u8 -- its generation (the net id's)
  • struct ArenaStats what the arena counted

    • shots: u64 -- shots fired
    • hits: u64 -- of those, hits on a figure
    • clamped: u64 -- shots whose view time lay further back than max_rewind (clamped)
    • kills: u64 -- figures ended
    • view_sum: u64 -- the shooters' view lag summed over the shots (1/256 ticks) and the largest
    • view_max: u32 -- see view_sum
  • struct Arena the reference RoomSim (see the module header)

impl Arena

  • fn new(cfg: ArenaConfig) -> Arena an arena with these settings
  • fn config(&self) -> &ArenaConfig the settings
  • fn map(&self) -> &physics::World the map
  • fn walker(&self) -> &Walker the movement
  • fn figures(&self) -> &BTreeMap<u16, Figure> the figures by net id
  • fn history(&self) -> &HitHistory the remembered hit volumes
  • fn stats(&self) -> ArenaStats what it counted
  • fn teleport(&mut self, id: u16, feet: Vec3) put a figure somewhere else (a teleport: its client reconciles)
  • fn figure_state(&self, f: &Figure) -> NetState a figure's replicated state

Source: docs/API.md in the JFLib repository.