Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions docs/engine/players.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ objects, the player's view and lock, the clock's ticks and every effect under it
effects the same way (`Drawn.Effects.show`), and takes single player's settings for how the game
shows things (`World.showAs`).

An object is set up the same way whoever makes it, a mission's script on the host or a scene page
on a client (`create.madeInWorld`): a planet is lit by the planets' light alone and gets its
An object is set up the same way whoever makes it, a mission's script on the host or the host's
objects on a client (`create.madeInWorld`): a planet is lit by the planets' light alone and gets its
atmosphere, a wreck burns, a gate opens its tunnel and the Dark Reign gets its hat. The flight
asks drawing for the atmospheres through cues of its own, as the game frames do (`main.cues`).
**Fix:** before, a client made these objects without setting them up, so a planet online was lit
Expand Down Expand Up @@ -197,8 +197,8 @@ counted in steps could not go below, would add its 20 ms to every input.
The host steps 50 times a second ([The step](loop.md#the-step)) and takes an input for every
step. It sends the flight view of every second step, 25 a second (`server.sendsFlightView`), so
its upload is what it was with the original's step. Each client flies the step between two views
itself. The scenery, the ordnance pages and the scene pages go out with the views, since a client
shows them as of its last view. The combat effects and the pilots' commands go out every step. An input repeats the six steps before it, and the host keeps 64 timed inputs for a pilot:
itself. The scenery, the ordnance pages and the mission's objects go out with the views, since a
client shows them as of its last view. The combat effects and the pilots' commands go out every step. An input repeats the six steps before it, and the host keeps 64 timed inputs for a pilot:
the 120 ms and 1.28 seconds that three and 32 of the original's steps covered.

A game a player hosts steps from its drawn frames. Each frame takes every step that is due
Expand All @@ -217,16 +217,40 @@ of a second, so a ship never jumps, however far ahead the clock runs. Only a dif
the ship's flight over that lead and three steps more, such as a ship back at a spawn point,
moves the drawn ship at once.

A co-op mission's other objects, such as its AI fighters and capital ships, travel in scene pages
(`wire.ScenePage`). A page covers 16 of the 400 object slots, and the host sends three pages with
each view, so each object comes round a few times a second. A page gives each object its place,
its velocity and its turn for one step, with the host's mission clock. The client gives the
object no orders and moves it by that velocity and turn every step (`motion.move`), so it flies on
between its pages, and the lead aim box has a velocity to lead. The client matches each page
against where it carried the object at the page's clock, and the difference fades as a ship's
does (`FlightFrame.correctLane`). Only a difference beyond the object's flight between two of its
pages and three steps more moves it at once. Every object slot has a lane of its own, so pilots'
ships, an arena's rocks and a mission's objects are corrected by the same code.
A co-op mission's other objects, such as its AI fighters and capital ships, are copied to each
client slot for slot (`mirror`), so a client holds the same state of each object as the host:
its armour and shields, its flags, its orders, whom it attacks and the rest. The copied fields
follow from the engine's types. Every field of an object's slot (`create.Slot`) is either sent
or kept by each machine, and a field added to the slot fails the build until it is put in one of
the two. A machine keeps what points into its own memory, the object's model and how it is drawn,
and the current order's own state, which clients have no use for while they run no orders.

The host takes the state of each object that changed with each view (`mirror.Sender.take`), and
sends each client what it doesn't hold yet, the nearest and the longest waiting objects first, in
up to three messages of 1,100 bytes per view (`mirror.Sender.page`). Each state goes as the change
from the last one the client said it holds, so an object that doesn't change costs nothing and
one whose armour drops costs a few bytes (Quake 3's snapshots, as Fiedler describes them in
"Snapshot Compression"). A state the client doesn't hold yet goes as the change from an object
whose bytes are all zero. Each input tells the host the serials of the last four messages the
client took (`wire.Input.mirror_acks`). When a change comes from a state the client no longer
holds, the client asks the host to start over (`wire.Input.mirror_lost`), and the host sends its
objects whole again, once for each request. The wing comes with the objects, and on each client
the pilot's own ship leads it, as `mission_start` puts the player's ship first, so the wing
window shows the same ships as in single player.

An object's motion, its place, its facing, its velocity and its turn each tick, doesn't go in its
state but as a pose (`mirror.Pose`), with the facing in the precision of the pilots' ships. The
client moves the object by that velocity and turn every step (`motion.move`), so it flies on
between messages, and the lead aim box has a velocity to lead. The client matches each pose
against where it carried the object at the host's mission clock, and the difference fades as a
ship's does (`FlightFrame.correctLane`). Only a difference beyond the object's flight between two
of its poses and three steps more moves it at once. Every object slot has a lane of its own, so
pilots' ships, an arena's rocks and a mission's objects are corrected by the same code.

Not done yet: the client runs none of the objects' orders, so it shows no explosion, spin-out or
cloak from them ([#1699](https://github.com/OpenReliant/openreliant/issues/1699)). Pilots' ships
and an arena's rocks still travel their own way, in the views
([#1700](https://github.com/OpenReliant/openreliant/issues/1700)).

A view is one datagram (`wire.capacity`). A dying ship's spin-out adds nine bytes to its ship, so
a full arena with most of its pilots dying at once can be more than a datagram holds. Such a view
Expand Down
4 changes: 2 additions & 2 deletions src/engine/game/create.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1623,8 +1623,8 @@ fn standStill(object: *GameObject) void {
const saladin_spin = "middle spin";

/// What an object needs once it is made where the world can see it, whoever made it: a mission's
/// script on the game's side (`executor.createShip`) or a host's scene page on a network client's
/// (`scene_page.Replica.apply`). Drawing hears of a planet for its atmosphere, and the planet, the
/// script on the game's side (`executor.createShip`), or a host's message of its objects on a
/// network client (`FlightFrame.presentMirror`). Drawing hears of a planet for its atmosphere, and the planet, the
/// gate, the wreck or the Dark Reign's hat is set up as `create_object` sets it up (`planetMade`,
/// `gateMade`, `wreckMade`, `extra.hatMade`).
pub fn madeInWorld(world: gameobj.World, index: u16) void {
Expand Down
25 changes: 14 additions & 11 deletions src/openreliant/network/client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ acked: ?i32 = null,
weapons: ?wire.ordnance.Order = null,
sent_aim: ?wire.ordnance.Aim = null,
projectiles: [wire.ordnance.Page.pages]?wire.ordnance.Page = @splat(null),
scene: [wire.ScenePage.count]?wire.ScenePage = @splat(null),
/// The host's messages of the mission's objects, until the flight takes them.
mirror: wire.mirror.Inbox = .{},
gates: ?wire.GatesPage = null,
jumps: ?wire.JumpPage = null,
presses: Presses = .{},
Expand Down Expand Up @@ -216,7 +217,8 @@ pub const Event = union(enum) {
wreck: wire.Wreck,
combat: wire.Combat,
projectiles,
scene_page,
/// A page of what a mission shows, or a message of its objects.
mission_page,
scenery,
campaign_line: wire.CampaignLine,
/// What happened to the pilot's own ship, for the flight to show (`wire.Feedback`).
Expand Down Expand Up @@ -280,6 +282,8 @@ fn sendInput(client: *Client, now: i64, command: flight.Command, tick: ?i32) !vo
// A step with a tick carries its own presses and trigger. Without one, the trigger is
// as it holds now, and the presses go by `flight_press` below.
.step = if (tick != null) client.flown_step else .{ .fire = client.fire_primary },
.mirror_acks = client.mirror.serials,
.mirror_lost = client.mirror.lost,
};
// Each input carries the steps before it, so the host loses none to a dropped packet
// (Overwatch GDC 2017).
Expand Down Expand Up @@ -368,7 +372,7 @@ fn clearFlightView(client: *Client) void {
client.pending_view = null;
client.pilot_pages = @splat(null);
client.projectiles = @splat(null);
client.scene = @splat(null);
client.mirror = .{};
client.gates = null;
client.jumps = null;
client.scenery = null;
Expand Down Expand Up @@ -435,7 +439,7 @@ fn keepMissionPage(client: *Client, kept: anytype, page: @typeInfo(@TypeOf(kept.
const view = &(client.latest orelse return .idle);
if (client.leaving or view.mission == null or page.tick <= client.campaign_floor) return .idle;
if (kept.* == null or page.tick > kept.*.?.tick) kept.* = page;
return .scene_page;
return .mission_page;
}

fn take(client: *Client, message: wire.Message, now: i64) !Event {
Expand Down Expand Up @@ -497,13 +501,12 @@ fn take(client: *Client, message: wire.Message, now: i64) !Event {
if (entry.* == null or page.tick > entry.*.?.tick) entry.* = page;
return .projectiles;
},
.scene_page => |page| {
.mirror => |bytes| {
const view = &(client.latest orelse return .idle);
// A reliable empty page can arrive before the matching pilot view.
if (client.leaving or view.mission == null or page.tick <= client.campaign_floor) return .idle;
const entry = &client.scene[page.number];
if (entry.* == null or page.tick > entry.*.?.tick) entry.* = page;
return .scene_page;
const tick = wire.mirror.Header.tickOf(bytes) orelse return error.InvalidMirror;
if (client.leaving or view.mission == null or tick <= client.campaign_floor) return .idle;
client.mirror.keep(bytes);
return .mission_page;
},
.gates_page => |page| return client.keepMissionPage(&client.gates, page),
.jump_page => |page| return client.keepMissionPage(&client.jumps, page),
Expand Down Expand Up @@ -818,7 +821,7 @@ pub fn drive(client: *Client, io: Io, controls: Controls, leave_after: ?u32) !vo
switch (event) {
.combat => std.debug.print("combat page\n", .{}),
.projectiles => std.debug.print("projectiles page\n", .{}),
.idle, .taken, .scene_page, .scenery, .campaign_line, .hit_feedback => {},
.idle, .taken, .mission_page, .scenery, .campaign_line, .hit_feedback => {},
.mission_music => |cue| {
_ = client.music.take();
std.debug.print("mission music {s} {s}\n", .{ if (cue.now) "now" else "fade", cue.track.slice() });
Expand Down
Loading
Loading