Samples

Two sample projects live in the Samples repository. Each also has short worked examples in its Examples folder.

Icebreaker #

A small C++ sample with no level and no assets. Capsules with an owner authoritative pose, a server written colour and a bonk counter, messages (W waves, G bonks) and LAN discovery. Host with H and join with J. It has 6 tests, and it has been run by a person on two machines.

Arena #

Lua, prefabs and generated data, with no C++. Two teams, a server that never sends you what a wall hides, a server authoritative Pawn with prediction and correction, an authoritative crate and a stress pen. scripts/arena-verify.sh runs six headless server and client runs over UDP loopback (clean, lag, loss, nudge, pilot, pilot moving) and checks the predicted position matches the server’s. Its arena.netschema and arena.netaccess are good worked examples.

This is what a passing run looks like:

$ scripts/arena-verify.sh
== clean
    ok     the client has its own Pawn, predicted here
    ok     the server moves that player's Pawn from its inputs
    ok     no script errors, refused calls or refused inputs
    ok     enough inputs compared between the client and the server   (38 of them, ticks 60 to 2280)
    info   corrections 0, inputs not yet processed up to 7, largest gap 0.000 m, mean 0.000 m
    ok     the client's predicted place and the server's agree at every compared input   (largest 0.000 m)
    ok     the player is never corrected   (0 corrections)
    ok     and they stay bounded   (up to 7)
== lag
    ok     the client has its own Pawn, predicted here
    ok     the server moves that player's Pawn from its inputs
    ok     no script errors, refused calls or refused inputs
    ok     enough inputs compared between the client and the server   (38 of them, ticks 60 to 2280)
    info   corrections 0, inputs not yet processed up to 11, largest gap 0.000 m, mean 0.000 m
    ok     the client's predicted place and the server's agree at every compared input   (largest 0.000 m)
    ok     the player is never corrected   (0 corrections)
    ok     the delay shows as unprocessed inputs (the player ran ahead of the server)   (up to 11)
    ok     and they stay bounded   (up to 11)
== loss
    ok     the client has its own Pawn, predicted here
    ok     the server moves that player's Pawn from its inputs
    ok     no script errors, refused calls or refused inputs
    ok     enough inputs compared between the client and the server   (38 of them, ticks 60 to 2280)
    info   corrections 0, inputs not yet processed up to 10, largest gap 0.000 m, mean 0.000 m
    ok     the run completed with corrections counted   (0)
    ok     the client stays near the server (mean gap in the second half)   (0.000 m)
    ok     and never far from it   (largest 0.000 m)
== nudge
    ok     the client has its own Pawn, predicted here
    ok     the server moves that player's Pawn from its inputs
    ok     no script errors, refused calls or refused inputs
    ok     enough inputs compared between the client and the server   (38 of them, ticks 60 to 2280)
    info   corrections 7, inputs not yet processed up to 7, largest gap 0.800 m, mean 0.147 m
    ok     the server pushed the Pawn several times   (7)
    ok     each push was a correction on the player's machine   (7 corrections for 7 pushes)
    ok     30 inputs after a push the player and the server agree again   (largest 0.000 m)
== pilot
    ok     the client has its own Pawn, predicted here
    ok     the server moves that player's Pawn from its inputs
    ok     no script errors, refused calls or refused inputs
    ok     enough inputs compared between the client and the server   (38 of them, ticks 60 to 2280)
    info   corrections 0, inputs not yet processed up to 6, largest gap 0.000 m, mean 0.000 m
    ok     the server handed the crate to the player
    ok     and took it back when the player put it down
    ok     the pilot reached its last waypoint
    ok     the server's crate was held for a few seconds   (4 samples)
    ok     and travelled with the player (left its starting place while held)   (2 samples away from the middle)
    ok     the crate never jumps in a frame (not when picked up, carried or put down)
    ok     it is back with the server at the end on both peers   (server holder -2, client holder -2)
    ok     and both peers see it in the same place   (0.000 m apart at (7.61, 2.87))
    ok     where the player put it down (not back in the middle)   (x 7.61)
== pilotmoving
    ok     the client has its own Pawn, predicted here
    ok     the server moves that player's Pawn from its inputs
    ok     no script errors, refused calls or refused inputs
    ok     enough inputs compared between the client and the server   (38 of them, ticks 60 to 2280)
    info   corrections 0, inputs not yet processed up to 15, largest gap 0.000 m, mean 0.000 m
    ok     the server handed the crate to the player
    ok     and took it back when the player put it down
    ok     the pilot reached its last waypoint
    ok     the server's crate was held for a few seconds   (4 samples)
    ok     and travelled with the player (left its starting place while held)   (2 samples away from the middle)
    ok     the crate never jumps in a frame (not when picked up, carried or put down)
    ok     it is back with the server at the end on both peers   (server holder -2, client holder -2)
    ok     and both peers see it in the same place   (0.000 m apart at (6.31, 2.87))
    ok     where the player put it down (not back in the middle)   (x 6.31)
ARENA VERIFIED

Short examples #

  • Foundation: host and join from settings, load a level for everyone, sync a transform.
  • Samples: add a message, add a replicated value, change what a player sees, count the cost of many records, hand over ownership in Lua, keep a score in Lua, move a pawn with prediction, test under a bad network.

Measured cost #

On the development machine, with 16 Clients and 1,000 NetRecords, a typical send phase took 604 microseconds and a Client’s receive took 104 microseconds. These are numbers from one machine, not a promise about yours.

Rate This Article!