veloren_common_net/sync/
net_sync.rs

1//! Types of syncing:
2//! * synced from any entity (within range)
3//! * synced only from the client's entity
4//!
5//! Types of updating
6//! * Plain copy of the new component state
7//! * (unimplemented) Diff to update component, two variants
8//!   * Keep a full copy of the component and generate diff from that
9//!   * Intercept changes to the component (no need to compute diff or keep a
10//!     full copy)
11//!
12//! NOTE: rapidly updated components like Pos/Vel/Ori are not covered here
13
14/// Trait that must be implemented for most components that are synced over the
15/// network.
16pub trait NetSync: specs::Component + Clone + Send + Sync
17where
18    Self::Storage: specs::storage::Tracked,
19{
20    // TODO: this scheme theoretically supports diffing withing the
21    // impl of `From<UpdateFrom> for Update` but there is no automatic
22    // machinery to provide the `UpdateFrom` value yet. Might need to
23    // rework this when actuall implementing though.
24    //
25    //type UpdateFrom = Self;
26    //type Update: From<Self::UpdateFrom> = Self;
27
28    /// Determines what for entities this component is synced to the client.
29    ///
30    /// For example, [`SyncFrom::ClientEntity`] can be used to only sync the
31    /// components for the client's own entity.
32    const SYNC_FROM: SyncFrom;
33
34    // sync::handle_modify(comp, entity, world)
35
36    /// Allows making modifications before the synced component is inserted on
37    /// the client.
38    fn pre_insert(&mut self, world: &specs::World) { let _world = world; }
39
40    /// Allows making modifications before the synced component is overwritten
41    /// with this version on the client.
42    fn pre_modify(&mut self, world: &specs::World) { let _world = world; }
43}
44
45/// Whether a component is synced to the client for any entity or for just the
46/// client's own entity.
47pub enum SyncFrom {
48    AnyEntity,
49    ClientEntity,
50}