From f52434f962eee035ba02f0d5233bc43b7c85cfe3 Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Thu, 22 Jun 2023 10:15:30 +0200 Subject: [PATCH] Add plugin via extension trait in spectator and synctest examples --- examples/box_game/box_game.rs | 2 +- examples/box_game/box_game_p2p.rs | 2 +- examples/box_game/box_game_spectator.rs | 30 ++++++++++++------------- examples/box_game/box_game_synctest.rs | 30 ++++++++++++------------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/examples/box_game/box_game.rs b/examples/box_game/box_game.rs index 143fde9..7ac1b4e 100644 --- a/examples/box_game/box_game.rs +++ b/examples/box_game/box_game.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy_ggrs::{PlayerInputs, Session, Rollback, AddRollbackCommandExtension}; +use bevy_ggrs::{AddRollbackCommandExtension, PlayerInputs, Rollback, Session}; use bytemuck::{Pod, Zeroable}; use ggrs::{Config, PlayerHandle}; use std::{hash::Hash, net::SocketAddr}; diff --git a/examples/box_game/box_game_p2p.rs b/examples/box_game/box_game_p2p.rs index 3d2388d..a6f3b72 100644 --- a/examples/box_game/box_game_p2p.rs +++ b/examples/box_game/box_game_p2p.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; use bevy::{prelude::*, window::WindowResolution}; -use bevy_ggrs::{GgrsPlugin, GgrsSchedule, GgrsAppExtension, Session}; +use bevy_ggrs::{GgrsAppExtension, GgrsPlugin, GgrsSchedule, Session}; use ggrs::{GGRSEvent as GgrsEvent, PlayerType, SessionBuilder, UdpNonBlockingSocket}; use structopt::StructOpt; diff --git a/examples/box_game/box_game_spectator.rs b/examples/box_game/box_game_spectator.rs index 61310eb..a0ca07d 100644 --- a/examples/box_game/box_game_spectator.rs +++ b/examples/box_game/box_game_spectator.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; use bevy::prelude::*; -use bevy_ggrs::{GgrsPlugin, GgrsSchedule, Session}; +use bevy_ggrs::{GgrsAppExtension, GgrsPlugin, GgrsSchedule, Session}; use ggrs::{SessionBuilder, UdpNonBlockingSocket}; use structopt::StructOpt; @@ -36,21 +36,19 @@ fn main() -> Result<(), Box> { .with_num_players(opt.num_players) .start_spectator_session(opt.host, socket); - let mut app = App::new(); - GgrsPlugin::::new() - // define frequency of rollback game logic update - .with_update_frequency(FPS) - // define system that returns inputs given a player handle, so GGRS can send the inputs around - .with_input_system(input) - // register types of components AND resources you want to be rolled back - .register_rollback_component::() - .register_rollback_component::() - .register_rollback_resource::() - // make it happen in the bevy app - .build(&mut app); - - // continue building/running the app like you normally would - app.insert_resource(opt) + App::new() + .add_ggrs_plugin( + GgrsPlugin::::new() + // define frequency of rollback game logic update + .with_update_frequency(FPS) + // define system that returns inputs given a player handle, so GGRS can send the inputs around + .with_input_system(input) + // register types of components AND resources you want to be rolled back + .register_rollback_component::() + .register_rollback_component::() + .register_rollback_resource::(), + ) + .insert_resource(opt) .add_plugins(DefaultPlugins) .add_startup_system(setup_system) // these systems will be executed as part of the advance frame update diff --git a/examples/box_game/box_game_synctest.rs b/examples/box_game/box_game_synctest.rs index c4adb71..45fe488 100644 --- a/examples/box_game/box_game_synctest.rs +++ b/examples/box_game/box_game_synctest.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy_ggrs::{GgrsPlugin, GgrsSchedule, Session}; +use bevy_ggrs::{GgrsAppExtension, GgrsPlugin, GgrsSchedule, Session}; use ggrs::{PlayerType, SessionBuilder}; use structopt::StructOpt; @@ -36,21 +36,19 @@ fn main() -> Result<(), Box> { // start the GGRS session let sess = sess_build.start_synctest_session()?; - let mut app = App::new(); - GgrsPlugin::::new() - // define frequency of rollback game logic update - .with_update_frequency(FPS) - // define system that returns inputs given a player handle, so GGRS can send the inputs around - .with_input_system(input) - // register types of components AND resources you want to be rolled back - .register_rollback_component::() - .register_rollback_component::() - .register_rollback_resource::() - // make it happen in the bevy app - .build(&mut app); - - // continue building/running the app like you normally would - app.insert_resource(opt) + App::new() + .add_ggrs_plugin( + GgrsPlugin::::new() + // define frequency of rollback game logic update + .with_update_frequency(FPS) + // define system that returns inputs given a player handle, so GGRS can send the inputs around + .with_input_system(input) + // register types of components AND resources you want to be rolled back + .register_rollback_component::() + .register_rollback_component::() + .register_rollback_resource::(), + ) + .insert_resource(opt) .add_plugins(DefaultPlugins) .add_startup_system(setup_system) // these systems will be executed as part of the advance frame update