Crate bevy_roll_safe

Crate bevy_roll_safe 

Source
Expand description

§bevy_roll_safe

crates.io MIT/Apache 2.0 docs.rs

Rollback-safe implementations and utilities for Bevy Engine.

§Motivation

Some of Bevy’s features can’t be used in a rollback context (with crates such as bevy_ggrs). This is either because they behave non-deterministically, rely on inaccessible local system state, or are tightly coupled to the Main schedule.

§Roadmap

  • States
    • Basic freely mutable states
    • OnEnter/OnLeave/OnTransition
  • FrameCount
  • Rollback-safe “Main”/default schedules
  • Audio playback
    • Support all PlaybackModes
    • Support for seeking in “time-critical” audio
    • Support for formats that don’t report sound durations (mp3/ogg)
  • Events

§States

Bevy states when added through app.init_state::<FooState>() have two big problems:

  1. They happen in the StateTransition schedule within the MainSchedule
  2. If rolled back to the first frame, OnEnter(InitialState) is not re-run.

This crate provides an extension method, init_roll_state_in_schedule::<S>(schedule), which lets you add a state to the schedule you want, and a resource, InitialStateEntered<S> which can be rolled back and tracks whether the initial OnEnter should be run (or re-run on rollbacks to the initial frame).

If you are using the rollback schedule plugin as well. Adding a rollback safe state is a simple as app.init_roll_state::<YourState>().

See the states example for usage with bevy_ggrs.

§Default rollback schedule

RollbackSchedulePlugin adds rollback-specific alternatives to the schedules in Bevy’s FixedMain/Main schedules.

The plugin takes a parent schedule as input, so it can easily be added to the ggrs schedule or any other schedule you want.

§Rollback audio

RollbackAudioPlugin lets you easily play sound effects from a rollback world without duplicate sounds playing over each other. It depends on the RollbackSchedulePlugin, or you need to add the maintenance system in a similar order to your own schedules.

§Cargo features

  • audio: Enable rollback-safe wrapper for bevy_audio
  • bevy_ggrs: Enable integration with bevy_ggrs
  • math_determinism: Enable cross-platform determinism for operations on Bevy’s (glam) math types.

§Bevy Version Support

bevybevy_roll_safe
0.170.6, main
0.160.5
0.150.4
0.140.3
0.130.2
0.120.1

§License

bevy_roll_safe is dual-licensed under either

at your option.

§Contributions

PRs welcome!

Modules§

prelude

Structs§

InitialStateEntered
RollFrameCount
Replacement for Bevy’s FrameCount, not tied to rendering
RollbackAudioPlayer
Rollback-safe wrapper around AudioPlayer.
RollbackAudioPlayerInstance
Represents an instance of a rollback sound effect that is currently playing
RollbackAudioPlugin
Plugin for managing rollback audio effects in a Bevy application.
RollbackPostUpdate
The schedule that contains logic that must run after RollbackUpdate.
RollbackPreUpdate
The schedule that contains logic that must run before RollbackUpdate. For example, a system that reads raw keyboard input OS events into an Events resource. This enables systems in RollbackUpdate to consume the events from the Events resource without actually knowing about (or taking a direct scheduler dependency on) the “os-level keyboard event system”.
RollbackSchedulePlugin
RollbackStateTransition
Runs rollback-safe state transitions
RollbackUpdate
The schedule that contains most gameplay logic

Traits§

RollApp

Functions§

apply_state_transition
If a new state is queued in NextState<S>, this system:
increase_frame_count
remove_finished_sounds
run_enter_schedule
Run the enter schedule (if it exists) for the current state.
start_rollback_sounds
Starts the rollback sounds by recording the current time as the start time
sync_rollback_sounds
Updates playing sounds to match the desired state spawns any missing sounds that should be playing. and despawns any sounds that should not be playing.