Crate bevy_backroll
source · [−]Expand description
A Bevy plugin that adds support for running Backroll sessions.
Installing the plugin:
use backroll::*;
use bytemuck::*;
use bevy::prelude::*;
use bevy_backroll::*;
// Create your Backroll input type
#[repr(C)]
#[derive(Clone, Copy, Eq, PartialEq, Pod, Zeroable)]
pub struct PlayerInput {
// Input data...
pub buttons_pressed: u8,
}
// Create your state. Must implement Clone.
#[derive(Component, Clone)]
pub struct PlayerState {
pub handle: PlayerHandle,
pub current_value: u64,
}
// Sample input from the local player's controller.
fn sample_player_input(player: In<PlayerHandle>) -> PlayerInput {
// Sample input data...
PlayerInput {
buttons_pressed: 1,
}
}
// Use input to advance the game simulation.
fn simulate_game(
input: Res<GameInput<PlayerInput>>,
mut query: Query<&mut PlayerState>
) {
for mut player in query.iter_mut() {
if let Ok(input) = input.get(player.handle) {
player.current_value += input.buttons_pressed as u64;
}
}
}
fn main() {
App::new()
.add_plugin(BackrollPlugin)
.register_rollback_input(sample_player_input.system())
.register_rollback_component::<PlayerState>()
.add_rollback_system(simulate_game)
.run();
}
Re-exports
pub use backroll;
Structs
A Bevy plugin that adds a BackrollStage to the app.
A Stage that transparently runs and handles Backroll sessions.
The SystemLabel used by the BackrollStage added by BackrollPlugin.
The Backroll config type for bevy_backroll sessions.
A provider resource of new, globally unique NetworkId
components.
Traits
Extension trait for configuring Apps using a BackrollPlugin.
Extension trait for Commands to start and stop Backroll sessions.
Type Definitions
A P2PSession
alias for bevy_backroll sessions. Uses BevyBackrollConfig
as the config type.