Skip to content

Commit

Permalink
Add event for mutate tick confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Nov 21, 2024
1 parent 52bca7e commit 78cc506
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bevy::{ecs::world::CommandQueue, prelude::*};
use bincode::{DefaultOptions, Options};
use bytes::Bytes;
use integer_encoding::{FixedIntReader, VarIntReader, VarIntWriter};
use server_mutate_ticks::ServerMutateTicks;
use server_mutate_ticks::{MutateTickConfirmed, ServerMutateTicks};

use crate::core::{
channels::{ReplicationChannel, RepliconChannels},
Expand Down Expand Up @@ -330,6 +330,9 @@ fn apply_mutate_messages(

if let Some(mutate_ticks) = &mut params.mutate_ticks {
mutate_ticks.confirm(mutate.message_tick, mutate.messages_count);
world.trigger(MutateTickConfirmed {
tick: mutate.message_tick,
});
}

false
Expand Down
11 changes: 10 additions & 1 deletion src/client/server_mutate_ticks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::core::replicon_tick::RepliconTick;
/// [`TrackAppExt::track_mutate_messages`](crate::core::replication::track_mutate_messages::TrackAppExt::track_mutate_messages)
/// were called.
///
/// See also [`ServerChangeTick`](super::ServerChangeTick).
/// See also [`MutateTickConfirmed`] and [`ServerChangeTick`](super::ServerChangeTick).
#[derive(Debug, Resource)]
pub struct ServerMutateTicks {
ticks: [TickMessages; 64],
Expand Down Expand Up @@ -159,6 +159,15 @@ impl TickMessages {
}
}

/// Triggered when all mutate messages are received for a tick.
///
/// See also [`ServerMutateTicks`].
#[derive(Event)]
pub struct MutateTickConfirmed {
/// Message(s) tick.
pub tick: RepliconTick,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 78cc506

Please sign in to comment.