Skip to content

Commit

Permalink
Add plugin via extension trait in spectator and synctest examples
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Jun 22, 2023
1 parent 49a8425 commit f52434f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/box_game/box_game.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion examples/box_game/box_game_p2p.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
30 changes: 14 additions & 16 deletions examples/box_game/box_game_spectator.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -36,21 +36,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.with_num_players(opt.num_players)
.start_spectator_session(opt.host, socket);

let mut app = App::new();
GgrsPlugin::<GgrsConfig>::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::<Transform>()
.register_rollback_component::<Velocity>()
.register_rollback_resource::<FrameCount>()
// 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::<GgrsConfig>::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::<Transform>()
.register_rollback_component::<Velocity>()
.register_rollback_resource::<FrameCount>(),
)
.insert_resource(opt)
.add_plugins(DefaultPlugins)
.add_startup_system(setup_system)
// these systems will be executed as part of the advance frame update
Expand Down
30 changes: 14 additions & 16 deletions examples/box_game/box_game_synctest.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -36,21 +36,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// start the GGRS session
let sess = sess_build.start_synctest_session()?;

let mut app = App::new();
GgrsPlugin::<GgrsConfig>::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::<Transform>()
.register_rollback_component::<Velocity>()
.register_rollback_resource::<FrameCount>()
// 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::<GgrsConfig>::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::<Transform>()
.register_rollback_component::<Velocity>()
.register_rollback_resource::<FrameCount>(),
)
.insert_resource(opt)
.add_plugins(DefaultPlugins)
.add_startup_system(setup_system)
// these systems will be executed as part of the advance frame update
Expand Down

0 comments on commit f52434f

Please sign in to comment.