diff --git a/src/lib.rs b/src/lib.rs index e50634b..2d46539 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ //! See [`GgrsPlugin`] for getting started. #![allow(clippy::type_complexity)] // Suppress warnings around Query +use bevy::ecs::intern::Interned; use bevy::{ ecs::schedule::{ExecutorKind, LogLevel, ScheduleBuildSettings, ScheduleLabel}, input::InputSystems, @@ -10,12 +11,11 @@ use bevy::{ prelude::*, }; use core::time::Duration; +pub use ggrs; use ggrs::{Config, InputStatus, P2PSession, PlayerHandle, SpectatorSession, SyncTestSession}; use serde::{Deserialize, Serialize}; use std::{fmt::Debug, hash::Hash, marker::PhantomData, net::SocketAddr}; -pub use ggrs; - pub use snapshot::*; pub use time::*; @@ -103,6 +103,9 @@ pub struct LocalPlayers(pub Vec); #[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone)] pub struct ReadInputs; +#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)] +pub struct RunGgrsSystems; + /// GGRS plugin for bevy. /// /// # Rollback @@ -144,13 +147,26 @@ pub struct ReadInputs; /// # } /// ``` pub struct GgrsPlugin { + schedule: Interned, /// phantom marker for ggrs config _marker: PhantomData, } +impl GgrsPlugin { + pub fn new(schedule: impl ScheduleLabel) -> Self { + Self { + schedule: schedule.intern(), + _marker: default(), + } + } +} + impl Default for GgrsPlugin { fn default() -> Self { - Self { _marker: default() } + Self { + schedule: PreUpdate.intern(), + _marker: default(), + } } } @@ -178,8 +194,10 @@ impl Plugin for GgrsPlugin { .in_set(AdvanceWorldSystems::Main), ) .add_systems( - PreUpdate, - schedule_systems::run_ggrs_schedules::.after(InputSystems), + self.schedule, + schedule_systems::run_ggrs_schedules:: + .in_set(RunGgrsSystems) + .after(InputSystems), // If we are in PreUpdate, run after input is read ) .add_plugins((ChecksumPlugin, EntityChecksumPlugin, GgrsTimePlugin)); }