use bevy_ecs::prelude::*;
use bevy_ecs::resource::Resource;
use bevy_replicon::prelude::{FilterScope, RepliconTick};
use lightyear_core::tick::Tick;
use lightyear_inputs::input_message::ActionStateSequence;
use serde::{Deserialize, Serialize};
#[derive(Event, Serialize, Deserialize, Clone, Debug, Default)]
pub struct CatchUpRequest {
pub input_safe_tick: Tick,
}
#[derive(Event, Serialize, Deserialize, Clone, Debug)]
pub struct CatchUpSnapshotReady {
pub replicon_tick: RepliconTick,
pub server_tick: Tick,
}
impl CatchUpSnapshotReady {
pub fn not_required() -> Self {
Self {
replicon_tick: RepliconTick::new(u32::MAX),
server_tick: Tick(u32::MAX),
}
}
pub fn is_not_required(&self) -> bool {
self.replicon_tick.get() == u32::MAX && self.server_tick == Tick(u32::MAX)
}
}
#[derive(Resource, Default)]
pub struct CatchUpRegistry {
pub(crate) initialized: bool,
}
impl CatchUpRegistry {
pub fn is_initialized(&self) -> bool {
self.initialized
}
}
pub trait AppCatchUpExt {
fn register_catchup<T, S>(&mut self) -> &mut Self
where
T: CatchUpComponentScope + Send + Sync + 'static,
S: ActionStateSequence;
}
#[doc(hidden)]
pub trait CatchUpComponentScope: FilterScope {}
impl<T: FilterScope> CatchUpComponentScope for T {}
#[derive(Component, Debug, Default)]
#[component(immutable)]
pub struct HasCaughtUp;
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
pub enum CatchUpSystems {
HandleRequests,
SendCatchUpRequest,
TriggerCatchUpRollback,
}