Multiplayer client relay bridge and match lobby menu: WebSocket bridge, match lobby page, order relay, confirmed turns, checksums, chat, abort/resume

This commit is contained in:
Richard Zink committed 2026-11-04 12:47:34 +01:00
1 parent 848ab0f677
commit 583c3fcdaf
9 files changed
+1063 -6

No files matched your search

+27
View File
@@ -14,6 +14,7 @@ pub const STEPS_PER_TURN: usize = 5;
pub struct Netplay {
pub turn: u32, // turns applied so far
pub desync: bool, // a peer reported a different world
pub last_sum: u32, // last turn whose checksum was sent
}
const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
@@ -59,6 +60,11 @@ impl Game {
self.netplay.is_some()
}
// the relay ended a match, or the player leaves it: the world stops being a turn-based match
pub fn end_match(&mut self) {
self.netplay = None;
}
// what the local master ordered since the last turn: these go to the server
pub fn take_orders(&mut self) -> Vec<Command> {
std::mem::take(&mut self.pending)
@@ -98,6 +104,27 @@ impl Game {
false
}
pub fn checksum_due(&mut self) -> Option<u32> {
let turn = match &self.netplay {
Some(np) => np.turn,
None => return None,
};
if turn < 10 {
return None;
}
let due = match &self.netplay {
Some(np) => turn.saturating_sub(np.last_sum) >= 10,
None => false,
};
if !due {
return None;
}
if let Some(np) = self.netplay.as_mut() {
np.last_sum = turn;
}
Some(turn)
}
// the part of the world every client of a match has to agree on: the map, the creatures, the
// economy of every master, the wave and the random state. Fog, particles and the camera are
// local and stay out of it.