pub struct DeterministicSimulation {
pub world: PhysicsWorld,
/* private fields */
}Expand description
Frame-based deterministic simulation wrapper.
Wraps PhysicsWorld with:
- Frame counter
- Input application pipeline
- State checksum computation
- Snapshot save/restore for rollback
§Determinism Guarantee
Given identical NetcodeConfig, identical add_body() calls, and identical
advance_frame() input sequences, two DeterministicSimulation instances
will produce bit-exact identical states on any platform.
Fields§
§world: PhysicsWorldThe underlying physics world
Implementations§
Source§impl DeterministicSimulation
impl DeterministicSimulation
Sourcepub fn new(config: NetcodeConfig) -> Self
pub fn new(config: NetcodeConfig) -> Self
Create a new deterministic simulation
Sourcepub fn add_body(&mut self, body: RigidBody) -> usize
pub fn add_body(&mut self, body: RigidBody) -> usize
Add a rigid body to the simulation. Returns the body index.
Sourcepub fn assign_player_body(&mut self, player_id: u8, body_index: usize)
pub fn assign_player_body(&mut self, player_id: u8, body_index: usize)
Assign a player to control a specific body.
Sourcepub fn advance_frame(&mut self, inputs: &[FrameInput]) -> SimulationChecksum
pub fn advance_frame(&mut self, inputs: &[FrameInput]) -> SimulationChecksum
Advance one frame with the given player inputs.
- Apply inputs to player-controlled bodies
- Step physics
- Compute and record checksum
Returns the checksum for this frame.
Sourcepub fn advance_frame_with_applicator(
&mut self,
inputs: &[FrameInput],
applicator: &dyn InputApplicator,
) -> SimulationChecksum
pub fn advance_frame_with_applicator( &mut self, inputs: &[FrameInput], applicator: &dyn InputApplicator, ) -> SimulationChecksum
Advance one frame with a custom input applicator.
Sourcepub fn save_snapshot(&mut self) -> &SimulationSnapshot
pub fn save_snapshot(&mut self) -> &SimulationSnapshot
Save a snapshot of the current state for rollback.
§Panics
Panics if the snapshot deque is empty after push (should never happen).
Sourcepub fn load_snapshot(&mut self, frame: u64) -> bool
pub fn load_snapshot(&mut self, frame: u64) -> bool
Restore state from a snapshot (for rollback).
Returns true if the snapshot was found and loaded. Rotations are
restored as stored (PhysicsWorld::deserialize_state) and brought to
unit length by the next step.
Sourcepub fn get_snapshot(&self, frame: u64) -> Option<&SimulationSnapshot>
pub fn get_snapshot(&self, frame: u64) -> Option<&SimulationSnapshot>
Get a snapshot for a specific frame (if available).
Sourcepub fn checksum(&self) -> SimulationChecksum
pub fn checksum(&self) -> SimulationChecksum
Compute the current state checksum.
Sourcepub fn checksum_at(&self, frame: u64) -> Option<SimulationChecksum>
pub fn checksum_at(&self, frame: u64) -> Option<SimulationChecksum>
Get checksum for a specific frame from history.
Sourcepub fn verify_checksum(
&self,
frame: u64,
remote: SimulationChecksum,
) -> Option<bool>
pub fn verify_checksum( &self, frame: u64, remote: SimulationChecksum, ) -> Option<bool>
Verify a remote checksum against local history.
Returns:
Noneif the frame is not in local history (too old or future)Some(true)if checksums match (clients in sync)Some(false)if checksums differ (DESYNC detected!)
Sourcepub fn snapshot_count(&self) -> usize
pub fn snapshot_count(&self) -> usize
Number of snapshots currently stored.
Auto Trait Implementations§
impl !Freeze for DeterministicSimulation
impl !RefUnwindSafe for DeterministicSimulation
impl !UnwindSafe for DeterministicSimulation
impl Send for DeterministicSimulation
impl Sync for DeterministicSimulation
impl Unpin for DeterministicSimulation
impl UnsafeUnpin for DeterministicSimulation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more