You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Store connected clients and their data as entities (#423)
This PR replaces `ConnectedEntities`, `ReplicatedEntities`, `ClientEntityMap`, and `Messages` resources with entities and data stored as components.
Connected clients are now represented by entities with a `ConnectedEntity` component. Connected entities become replicated after the insertion of `ReplicatedClient` (which replaces the `StartReplication` trigger). It's just a marker now, I've split the original `ReplicatedClient` into multiple components. Visibility and statistics are now accessible via the `ClientVisibility` and `ClientStats` components on replicated entities. The `ClientEntityMap` is now a component on replicated entities that stores mappings for them. `ClientTicks` is no longer accessible to users, but it isn't needed for the public API - even prediction crates don't use it.
`UpdateMessage` and `MutateMessages` are now crate-private components, just to speed up iteration. Using `zip` is slower, but if everything is on an entity, the performance is similar to what we had before this PR. It's still a bit slower, but I believe the improved ergonomics are worth it.
Since connected clients now have a unique identifier (`Entity`). This also gives us both fast iteration and fast lookup (closes#326). Users will mostly interact with entities, and plugins can use `ClientId` if they need a persistent identifier.
The server ID is now `SERVER` constant which equal to `Entity::PLACEHOLDER`.
I also removed the `ClientConnected` and `ClientDisconnected` events. Users can observe for `Trigger<OnAdd, ConnectedClient>` or `Trigger<OnRemove, ConnectedClient>`. `DisconnectReason` is also gone. We don't care about it in Replicon and can't provide a nice representation for it anyway. Users can access proper information from the used backend. There is no need to duplicate it for us.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
12
12
- Derive `Debug` for `FnsId`.
13
13
- Derive `Deref` and `DerefMut` to underlying event in `ToClients` and `FromClient`.
14
+
- Derive `PartialEq` for `RepliconClientStatus`.
14
15
15
16
### Changed
16
17
18
+
- Connected clients are now represented as entities with `ConnectedClient` components. Backends are responsible for spawning and despawning entities with this component. `ClientId` is accessible from `ConnectedClient::id` in case you need an identifier that is persistent across reconnects.
19
+
- Statistics for connected clients now accessible via `ClientStats` component.
20
+
- Replicated entities now represented by connected clients with `ReplicatedClient` component.
21
+
- To access visibility, use `ClientVisibility` component on replicated entities.
22
+
-`ServerEntityMap` resource now a component on replicated entities. It now accepts entity to entity mappings directly instead of `ClientId` to `ClientMapping`.
23
+
- Replace statistic methods on `RepliconClient` with `RepliconClient::stats()` method that returns `ClientStats` struct.
24
+
- Move `VisibilityPolicy` to `server` module.
25
+
- Move `ClientId` to `connected_client` module and remove from `prelude`.
26
+
- Use `TestClientEntity` instead of `ClientId` resource on clients in `ServerTestAppExt` to identify client entity.
27
+
- Rename `FromClient::client_id` into `FromClient::client_entity`.
17
28
- Replace `bincode` with `postcard`. It has more suitable variable integer encoding and potentially unlocks `no_std` support. If you use custom ser/de functions, replace `DefaultOptions::new().serialize_into(message, event)` with `postcard_utils::to_extend_mut(event, message)` and `DefaultOptions::new().deserialize_from(cursor)` with `postcard_utils::from_buf(message)`.
18
29
- All serde methods now use `postcard::Result` instead of `bincode::Result`.
19
30
- All deserialization methods now accept `Bytes` instead of `std::io::Cursor` because deserialization from `std::io::Read` requires a temporary buffer. `Bytes` already provide cursor-like functionality. The crate now re-exported under `bevy_replicon::bytes`.
@@ -26,6 +37,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
26
37
27
38
- Local re-trigger for listen server mode.
28
39
40
+
### Removed
41
+
42
+
-`ClientId` from `prelude`. Most operations now done using `Entity` as identifier. But it could be useful
43
+
-`StartReplication` trigger. Just insert `ReplicatedClient` to enable replication.
44
+
-`ConnectedClients` and `ReplicatedClients` resources. Use components on connected clients instead.
45
+
-`ClientConnected` and `ClientDisconnected` triggers. Just observe for `Trigger<OnAdd, ConnectedClient>` or `Trigger<OnRemove, ConnectedClient>`. To get disconnect reason, obtain it from the ued backend.
46
+
-`ServerSet::TriggerConnectionEvents` variant. We no longer use events for connections.
0 commit comments