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

Implementation of Ord on Entity #317

Closed
LPGhatguy opened this issue Apr 18, 2023 · 2 comments
Closed

Implementation of Ord on Entity #317

LPGhatguy opened this issue Apr 18, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@LPGhatguy
Copy link

Currently, the Ord implementation on Entity behaves the same way as the to_bits representation of the entity: sorted by generation first, then by ID. That parity is nice, but I am unsure if this is the right default order.

I think it might make sense to sort entities by their ID first and then their generation. This makes the behavior of data structures like BTreeMap with entity keys behave more deterministically.

In our game, we have a WireNetwork component that holds a BTreeMap<EntityHandle, Connections>, where EntityHandle is a new-typed wrapper around Entity with custom serialization behavior. We were deriving Ord on that type, but I was surprised when the entries in the map would get shuffled around. This ended up being due to generations sometimes being different between runs, reordering the map!

We were able to solve that issue by manually implementing Ord to compare the entity's ID first. Doing that made me wonder whether the same change would be right for hecs itself.

@Ralith
Copy link
Owner

Ralith commented Apr 19, 2023

That sounds like a reasonable change to me! I wonder if we should flip the bit representation around to match?

@Ralith Ralith added enhancement New feature or request good first issue Good for newcomers labels Aug 28, 2023
@Ralith
Copy link
Owner

Ralith commented Mar 27, 2024

Fixed by #357.

@Ralith Ralith closed this as completed Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants