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
use naia_socket_shared::PacketReader;
use super::{
diff_mask::DiffMask,
protocol_type::{ProtocolInserter, ProtocolType},
replica_ref::{ReplicaDynRefWrapper, ReplicaMutWrapper, ReplicaRefWrapper},
replicate::{Replicate, ReplicateSafe},
};
pub trait WorldRefType<P: ProtocolType, E> {
fn has_entity(&self, entity: &E) -> bool;
fn entities(&self) -> Vec<E>;
fn has_component<R: ReplicateSafe<P>>(&self, entity: &E) -> bool;
fn has_component_of_kind(&self, entity: &E, component_kind: &P::Kind) -> bool;
fn get_component<'a, R: ReplicateSafe<P>>(
&'a self,
entity: &E,
) -> Option<ReplicaRefWrapper<'a, P, R>>;
fn get_component_of_kind(
&self,
entity: &E,
component_kind: &P::Kind,
) -> Option<ReplicaDynRefWrapper<'_, P>>;
}
pub trait WorldMutType<P: ProtocolType, E>: WorldRefType<P, E> + ProtocolInserter<P, E> {
fn spawn_entity(&mut self) -> E;
fn despawn_entity(&mut self, entity: &E);
fn get_component_kinds(&mut self, entity: &E) -> Vec<P::Kind>;
fn get_component_mut<'a, R: ReplicateSafe<P>>(
&'a mut self,
entity: &E,
) -> Option<ReplicaMutWrapper<'a, P, R>>;
fn component_read_partial(
&mut self,
entity: &E,
component_kind: &P::Kind,
diff_mask: &DiffMask,
reader: &mut PacketReader,
packet_index: u16,
);
fn mirror_components(
&mut self,
mutable_entity: &E,
immutable_entity: &E,
component_kind: &P::Kind,
);
fn insert_component<R: ReplicateSafe<P>>(&mut self, entity: &E, component_ref: R);
fn remove_component<R: Replicate<P>>(&mut self, entity: &E) -> Option<R>;
fn remove_component_of_kind(&mut self, entity: &E, component_kind: &P::Kind) -> Option<P>;
}