-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rooms #15
Comments
naia uses a Room resource which allows entities to be members of multiple rooms. At this time I think it would be best to just duplicate naia's design (with some adjustments for Room-based events). |
Yeah, this is exactly what |
Here is a sketch of a solution for rooms (incomplete: it doesn't specify how to handle 'gained/lost visibility').
|
In my proposal above, 'gained visibility' and 'lost visibility' are only detected in the tick where they occur. Since the replication diff from that tick may fail to reach the client, we need to re-replicate those spawns/despawns until they have been acked. To do that I think we need a spawn tracker that caches diffs for entities that each client gained visibility on. The logic for that cache will be a little hairy to account for entity and visibility changes that occur after entities were cached. [edit: caching diffs for clients instead of recreating diffs should be a good way to handle this (we need to cache diffs for sync events)] We also need to be careful about visibility-related spawns and despawns that occur between client acks. Those events cannot be 'cross-merged' (i.e. cancel out a despawn with a subsequent spawn) since a visibility despawn sent in one tick may be acked by the client and so the following visibility spawn needs to also be sent to resurrect the entity (multiple duplicates can be merged though, we only need the latest spawn/despawn). Additionally, spawns and despawns must be strictly ordered on the client to ensure any sequence of visibility spawns/despawns will have the correct final result. |
Another problem to consider: a child entity should only be visible to a client if it and all its parents are also visible to that client. |
I would prefer a more flexible, sole server approach, where a function taking mutable world access, the player id and a specific entity returns a bool whether to replicate to client or not. This way I can encode "chunking" (like minecraft does it, I presume) however I want to. From my perspective, not having contributed to This is a slow implementation, but I think configuring a function (signature) to decide which entities are replicated is the most powerful, flexible and easiest to integrate approach |
Rooms have the same amount of flexibility and more ECS-friendly. |
Yeah you're right, its more ECS friendly. Can't wait until this is finalised! |
The design we are considering assigns one room per entity. For this use-case you'd chunk the entities into rooms (as small as one or zero entities per room), then adjust which rooms each player is a member of. |
Working on rooms right now. In the proposed solution, we essentially assign an ID (room) to each object, and then specify which IDs each client sees. |
This would be one room per entity. I think it is an API question. With distinct rooms you can separately assign entities to rooms and assign clients to rooms, with per-entity visibility you have to explicitly assign/remove entities from clients (which I imagine would be way more bug prone and laborious). |
I wouldn't say "way more", but I agree that for some games it would be less convenient. |
Ok let's see how it looks.
We should make sure the 'how to extend it' story is figured out before releasing this. And add examples/tests for the various scenarios:
|
Agree, consider this as a quick prototype.
I want to showcase the working design first. |
Let's move discussion about possible rooms API on top from the PR here.
I think that a About events. How about to provide an extension trait for |
I like this idea :) |
Sometimes you replicate only part of the world. Commonly used for things like fog of war or card games.
To solve this
@koe
from Bevy discord server suggested to implement rooms.Assign each entity a room ID (inspired by naia's rooms). Each client is a member of an arbitrary number of rooms (e.g. using a hashset of ids). By default entities are in room ‘0’ which means global (or maybe have no room IDs). All other room ids are user-defined. Replicon just needs a resource to track client room membership, and some updates to the replication logic to only replicate an entity for a given client if they are in the same room (and also to ‘despawn’ an entity if it stops being visible to a client).
The text was updated successfully, but these errors were encountered: