Centralize world and viewport game loops
Some checks failed
CI / rust-skia (Rust only) (push) Has been cancelled
CI / required (push) Has been cancelled

This commit is contained in:
2026-08-23 13:42:01 +02:00
parent cb9233c59c
commit 33d1cf6827
18 changed files with 2541 additions and 287 deletions

View File

@@ -12,7 +12,7 @@ use std::pin::Pin;
use std::sync::atomic::{AtomicU8, AtomicU64, Ordering};
use std::sync::{Arc, Mutex};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tokio::sync::{mpsc, oneshot};
use tokio::sync::{mpsc, oneshot, watch};
use tokio::task::JoinHandle;
use tokio::time::Instant;
@@ -25,6 +25,39 @@ const MAX_SHUTDOWN: Duration = Duration::from_mins(1);
pub type SessionFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
/// Generation-scoped gate between transport readiness and autonomous agent readiness.
pub struct FrameworkReadiness {
generation: watch::Sender<u64>,
}
impl Default for FrameworkReadiness {
fn default() -> Self {
let (generation, _) = watch::channel(0);
Self { generation }
}
}
impl FrameworkReadiness {
pub fn mark_ready(&self, generation: u64) {
if generation != 0 {
self.generation.send_replace(generation);
}
}
pub async fn wait_ready(&self, generation: u64, cancellation: CancellationToken) -> bool {
let mut ready = self.generation.subscribe();
loop {
if *ready.borrow() == generation {
return true;
}
tokio::select! {
() = cancellation.cancelled() => return false,
changed = ready.changed() => if changed.is_err() { return false; },
}
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum SessionState {
@@ -215,7 +248,7 @@ impl Default for ReconnectPolicy {
Self {
initial_delay: Duration::from_secs(1),
maximum_delay: Duration::from_mins(1),
readiness_timeout: Duration::from_secs(30),
readiness_timeout: Duration::from_mins(2),
stable_reset_after: Duration::from_mins(2),
shutdown_deadline: Duration::from_secs(10),
jitter_basis_points: 2_000,