Skip to content
Merged
Changes from all commits
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
28 changes: 23 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
//! 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,
platform::collections::HashMap,
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::*;

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: impl ScheduleLabel) -> Self {
Self {
schedule: schedule.intern(),
_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