Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::time::Duration;
use ggrs::{Config, InputStatus, P2PSession, PlayerHandle, SpectatorSession, SyncTestSession};
use serde::{Deserialize, Serialize};
use std::{fmt::Debug, hash::Hash, marker::PhantomData, net::SocketAddr};

use bevy::ecs::intern::Interned;
pub use ggrs;

pub use snapshot::*;
Expand Down Expand Up @@ -103,6 +103,9 @@ pub struct LocalPlayers(pub Vec<PlayerHandle>);
#[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
Expand Down Expand Up @@ -144,13 +147,26 @@ pub struct ReadInputs;
/// # }
/// ```
pub struct GgrsPlugin<C: Config> {
schedule: Interned<dyn ScheduleLabel>,
/// phantom marker for ggrs config
_marker: PhantomData<C>,
}

impl<C: Config> GgrsPlugin<C> {
pub fn new(schedule: Interned<dyn ScheduleLabel>) -> Self {
Self {
schedule,
_marker: default()
}
}
}

impl<C: Config> Default for GgrsPlugin<C> {
fn default() -> Self {
Self { _marker: default() }
Self {
schedule: PreUpdate.intern(),
_marker: default()
}
}
}

Expand Down Expand Up @@ -178,8 +194,10 @@ impl<C: Config> Plugin for GgrsPlugin<C> {
.in_set(AdvanceWorldSystems::Main),
)
.add_systems(
PreUpdate,
schedule_systems::run_ggrs_schedules::<C>.after(InputSystems),
self.schedule,
schedule_systems::run_ggrs_schedules::<C>
.in_set(RunGgrsSystems)
.after(InputSystems), // If we are in PreUpdate, run after input is read
)
.add_plugins((ChecksumPlugin, EntityChecksumPlugin, GgrsTimePlugin));
}
Expand Down
Loading