fix(simulation): use non-blocking TCP to prevent game loop stall

read_framed() called read_exact() which blocked the entire bevy Update
schedule waiting for client input — no systems ran until a keystroke
arrived. Switch TcpStream to non-blocking mode so receive_inputs()
returns Ok(vec![]) on WouldBlock instead of blocking. Toggle to
blocking for snapshot writes (reliable delivery). Add 50ms frame
throttle (~20 ticks/sec) since the non-blocking loop would otherwise
spin. Downgrade input receive logging to trace, add error logging for
missing bridge resource and failed observer queries.

Fixes bug #1 (server never sends snapshots) and #2 (camera doesn't
center until first keystroke).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-16 23:25:45 +01:00
co-authored by Claude Opus 4.6
parent 686c89170a
commit d1aba3d554
5 changed files with 69 additions and 19 deletions
+5 -2
View File
@@ -73,7 +73,7 @@ pub fn receive_bridge_inputs(
match bridge.receive_inputs() {
Ok(inputs) => {
for input in &inputs {
tracing::debug!(
tracing::trace!(
"Received input: tick={} action={:?}",
input.tick,
input.action
@@ -115,7 +115,10 @@ pub fn send_bridge_snapshot(
mut buffer: ResMut<SnapshotBuffer>,
mut running: ResMut<ServerRunning>,
) {
let Some(bridge) = bridge else { return };
let Some(bridge) = bridge else {
tracing::error!("send_bridge_snapshot: no BridgeResource");
return;
};
if let Some(snapshot) = buffer.snapshot.take() {
if let Err(e) = bridge.send_snapshot(&snapshot) {
match &e {