Skip to content
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

Allow seamless entity mapping #591

Merged
merged 3 commits into from
Aug 13, 2024
Merged

Allow seamless entity mapping #591

merged 3 commits into from
Aug 13, 2024

Conversation

cBournhonesque
Copy link
Owner

@cBournhonesque cBournhonesque commented Aug 13, 2024

Currently we only do entity mapping when we deserialize a message, by looking at the remote_to_local map.

We didn't do the reverse, which meant that sending a message referring to a local entity on the entity-receiver side was annoying on because the remote is the entity-sender so it wouldn't apply entity mapping.

Now we also apply entity mapping when we serialize a message, by using the local_to_remote map.

I didn't implement this previously because of potential conflicts but I think that the risk of those is pretty small. It would require a user to have both client->server and server->client in the same game.
In the long-term I want to solve those conflicts by using pre-defined ID ranges.
In the meantime we can greatly improve ergonomics by enabling this feature.

The conflicts could be for example:

  • Server spawns E1 and replicates to client who spawns E2. Client has E1 remote -> E2 local mapping.
  • Client spawns E1 and replicates to server who spawns E3, Server has E1 remote -> E3 local mapping.
    (basically the conflict happens if the server and client both spawn and replicate an entity with the same Entity)

Client sends a message containing E2.
It maps it from local to remote: E1
Server receives the message with E1, it maps it from remote_to_local -> E3. (instead of just using the original E1)

Solutions to avoid these kinds of conflicts:

  • avoid replicating in both directions
  • predefined entity ranges for networking
  • include a bit in the message that indicates that mapping was already done. If the mapping was already done on the sender, we don't do it again on the receiver. Maybe that bit can be included directly in the Entity, similar to what's described in https://ajmmertens.medium.com/doing-a-lot-with-a-little-ecs-identifiers-25a72bd2647
    On the receiving side we would check this bit to know it entity-mapping has already been applied or not?
    (or just 1 bit per message, but that seems expensive)

@cBournhonesque cBournhonesque merged commit aa302f5 into main Aug 13, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant