naia_shared/world/publicity.rs
1/// Publication visibility of an entity — the shared axis used on both sides
2/// of the connection.
3///
4/// On the **server**, `Publicity` is embedded in `ReplicationConfig` and
5/// controls how an entity replicates to clients.
6/// On the **client**, `Publicity` is passed directly to
7/// `EntityMut::configure_replication`.
8///
9/// The three variants represent the full lifecycle of a client-authoritative
10/// entity:
11///
12/// ```text
13/// Server spawns → Delegated
14/// ↓ client requests authority
15/// Client holds → Private (not yet published)
16/// ↓ client publishes
17/// All peers see → Public
18/// ↓ client releases or server revokes
19/// Server resumes → Delegated / Public
20/// ```
21#[derive(Copy, Clone, PartialEq, Eq, Debug)]
22pub enum Publicity {
23 /// The entity is owned by a client but not yet visible to other peers.
24 ///
25 /// Used while a client is constructing or preparing an entity before
26 /// choosing to publish it. Server-spawned entities are never `Private`.
27 Private,
28 /// The entity replicates to all peers that share a room and scope with it.
29 ///
30 /// The default state for server-spawned entities. A client sets an entity
31 /// `Public` to make its own client-spawned entity visible to other clients.
32 Public,
33 /// The server can delegate authority over this entity to a client.
34 ///
35 /// When a server entity is configured `Delegated`, clients may call
36 /// `Client::entity_request_authority` to request ownership. The server
37 /// grants or denies the request via `EntityAuthGrantedEvent` or
38 /// `EntityAuthDeniedEvent`. While a client holds authority its
39 /// mutations replicate back to the server; the server can revoke at
40 /// any time.
41 Delegated,
42}
43
44impl Publicity {
45 /// Returns `true` if this is [`Publicity::Delegated`].
46 pub fn is_delegated(&self) -> bool {
47 matches!(self, Publicity::Delegated)
48 }
49}