// Bridge module - Client-server communication // Implements D-020 subprocess/IPC architecture // MessagePack serialization for Rust<->Godot communication use bevy_app::prelude::*; use bevy_ecs::prelude::*; pub mod framing; pub mod local; pub mod types; pub use types::*; /// Error type for bridge operations #[derive(Debug, thiserror::Error)] pub enum BridgeError { #[error("serialization error: {0}")] Serialization(#[from] rmp_serde::encode::Error), #[error("deserialization error: {0}")] Deserialization(#[from] rmp_serde::decode::Error), #[error("io error: {0}")] Io(#[from] std::io::Error), #[error("transport error: {0}")] Transport(String), } /// Abstracts transport layer (D-020) /// Implemented by LocalBridge (stdio) and future NetworkBridge pub trait SimBridge: Send + Sync { /// Send an observer snapshot to the client fn send_snapshot(&self, snapshot: &ObserverSnapshot) -> Result<(), BridgeError>; /// Receive player inputs from the client fn receive_inputs(&self) -> Result, BridgeError>; } /// BridgeResource: Bevy Resource wrapper for SimBridge trait object #[derive(Resource)] pub struct BridgeResource { inner: Box, } impl BridgeResource { pub fn new(bridge: impl SimBridge + 'static) -> Self { Self { inner: Box::new(bridge), } } pub fn send_snapshot(&self, snapshot: &ObserverSnapshot) -> Result<(), BridgeError> { self.inner.send_snapshot(snapshot) } pub fn receive_inputs(&self) -> Result, BridgeError> { self.inner.receive_inputs() } } /// Bridge plugin for client-server communication /// Abstracts transport layer (LocalBridge/NetworkBridge) pub struct BridgePlugin; impl Plugin for BridgePlugin { fn build(&self, _app: &mut App) { // Stub implementation - will be populated in phase 2 tracing::debug!("BridgePlugin initialized"); } }