Files
benilla-octo/crates/benilla-app/src/ui_net.rs
T
SamandClaude Fable 5.1 edec5b2207 settings live in one registry, and the net drain starts to peel
- the CVars are one engine-side table that outlives every interface reload: a change fires its observer, the eight latched rows wait for RestartGx, and /console gains set, cvar_reset, cvar_default, cvarlist and help (2303)
- every push into the interface runs in one feed phase after the net drain and before the tick, held by a structural test on the built schedule (2304)
- subsystems own their packet handlers, dispatched in packet order; the auction house is the first family out of the 273-arm drain (2305)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-17 16:47:09 +07:00

42 lines
2.0 KiB
Rust

//! The connection-telemetry feed — the app side of `benilla_ui::script::net_stats`' seam.
//!
//! One number: the latency `GetNetStats()` reports, which is the main bar's performance ("ping")
//! meter's whole input (stock `MainMenuBar.xml`'s `MainMenuBarPerformanceBarFrame` polls it every 10 s and
//! colors the bar green/yellow/red). The measurement itself belongs to the **net read thread** —
//! every `SMSG_PONG` is timed where it lands and filed in the connection clock's RTT history at the
//! reference's own depth — and this feed only carries its average across the engine boundary (decision
//! 0068 §3: the engine never reaches into ECS or the socket). Reading it takes the connection's
//! lock, exactly as the reference's `GetNetStats` takes the stats critical section; it is
//! uncontended (one writer every 30 s) and this is three words of copy a frame.
//!
//! The push is unconditional rather than change-gated, for the reason [`crate::minimap`]'s
//! containment feed documents: `UiScript` is created when the UI loads, which is *after* a
//! connection can already have settled, so a feed that only spoke on change could miss its only
//! edge and leave the meter reading 0 forever. Three words of copy a frame is nothing next to that.
use bevy::prelude::*;
use benilla_ui::script::UiScript;
use benilla_assets::LockRecover;
use crate::net::PingShared;
use crate::ui_script::UiFeed;
pub(crate) struct UiNetPlugin;
impl Plugin for UiNetPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, feed_net_stats.in_set(UiFeed));
}
}
/// Push the averaged round trip behind `GetNetStats()`.
fn feed_net_stats(script: Option<NonSendMut<UiScript>>, ping: Res<PingShared>) {
let Some(mut script) = script else { return };
// Recovered, not unwrapped: the net threads hold this lock too, and a panic there must end
// the connection, not the app (decision 2265 §B1).
let latency = ping.0.lock_recover().avg_latency_ms();
script.set_latency_ms(latency);
}