//! # Server thrust handling //! The thrust solver runs on the client and sends a `ThrustSolution` message; //! this file receives it and applies it to the physics simulation. use crate::client::components::Me; use crate::shared::ecs::{Part, Temperature}; use crate::shared::ecs::thruster::{Thruster, ThrusterOfPart}; use crate::prelude::*; use crate::shared::attachment::Parts; use crate::shared::thrust::ThrustSolution; pub fn server_thrust_plugin(app: &mut App) { app .add_systems(Update, process_thrust_events) .add_systems(FixedUpdate, apply_thrust_solutions); } fn process_thrust_events( mut events: MessageReader, me_entity: Query>, mut commands: Commands, ) { for thrust_solution in events.read() { let Ok(player_entity) = me_entity.single() else { return }; commands.entity(player_entity).insert(thrust_solution.clone()); } } /// Find all players, and apply their current `ThrustSolution`s fn apply_thrust_solutions( players: Query<(Entity, &ThrustSolution, Option<&Parts>)>, thrusters: Query<(&Thruster, &ThrusterOfPart, &GlobalTransform)>, mut parts: Query<(Forces, &mut Temperature), With>, time: Res