1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use std::any::Any;
use naia_serde::{BitReader, BitWrite, SerdeErr};
use crate::{
component::{
component_kinds::{ComponentKind, ComponentKinds},
component_update::ComponentUpdate,
diff_mask::DiffMask,
property_mutate::PropertyMutator,
replica_ref::{ReplicaDynMut, ReplicaDynRef},
},
entity::{entity_handle::EntityHandle, entity_property::NetEntityHandleConverter},
messages::named::Named,
};
pub trait ReplicateBuilder: Send + Sync + Named {
fn read(
&self,
reader: &mut BitReader,
converter: &dyn NetEntityHandleConverter,
) -> Result<Box<dyn Replicate>, SerdeErr>;
fn read_create_update(&self, reader: &mut BitReader) -> Result<ComponentUpdate, SerdeErr>;
}
pub trait Replicate: ReplicateInner + Named + Any {
fn kind(&self) -> ComponentKind;
fn to_any(&self) -> &dyn Any;
fn to_any_mut(&mut self) -> &mut dyn Any;
fn to_boxed_any(self: Box<Self>) -> Box<dyn Any>;
fn copy_to_box(&self) -> Box<dyn Replicate>;
fn create_builder() -> Box<dyn ReplicateBuilder>
where
Self: Sized;
fn diff_mask_size(&self) -> u8;
fn dyn_ref(&self) -> ReplicaDynRef<'_>;
fn dyn_mut(&mut self) -> ReplicaDynMut<'_>;
fn mirror(&mut self, other: &dyn Replicate);
fn set_mutator(&mut self, mutator: &PropertyMutator);
fn write(
&self,
component_kinds: &ComponentKinds,
writer: &mut dyn BitWrite,
converter: &dyn NetEntityHandleConverter,
);
fn write_update(
&self,
diff_mask: &DiffMask,
writer: &mut dyn BitWrite,
converter: &dyn NetEntityHandleConverter,
);
fn read_apply_update(
&mut self,
converter: &dyn NetEntityHandleConverter,
update: ComponentUpdate,
) -> Result<(), SerdeErr>;
fn has_entity_properties(&self) -> bool;
fn entities(&self) -> Vec<EntityHandle>;
}
cfg_if! {
if #[cfg(feature = "bevy_support")]
{
use bevy_ecs::component::{TableStorage, Component};
pub trait ReplicateInner: Component<Storage = TableStorage> + Sync + Send + 'static {}
impl<T> ReplicateInner for T
where T: Component<Storage = TableStorage> + Sync + Send + 'static {
}
}
else
{
pub trait ReplicateInner: Sync + Send + 'static {}
impl<T> ReplicateInner for T
where T: Sync + Send + 'static {
}
}
}