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

[Merged by Bors] - bevy_scene: Stabilize entity order in DynamicSceneBuilder #6382

Closed
wants to merge 2 commits into from

Conversation

MrGVSV
Copy link
Member

@MrGVSV MrGVSV commented Oct 26, 2022

Objective

Currently, DynamicSceneBuilder keeps track of entities via a HashMap. This has an unintended side-effect in that, when building the full DynamicScene, we aren't guaranteed any particular order.

In other words, inserting Entity A then Entity B can result in either [A, B] or [B, A]. This can be rather annoying when running tests on scenes generated via the builder as it will work sometimes but not other times. There's also the potential that this might unnecessarily clutter up VCS diffs for scene files (assuming they had an intentional order).

Solution

Store DynamicSceneBuilder's entities in a Vec rather than a HashMap.


Changelog

  • Stablized entity order in DynamicSceneBuilder (0.9.0-dev)

@MrGVSV MrGVSV added C-Usability A simple quality-of-life change that makes Bevy easier to use A-Scenes Serialized ECS data stored on the disk labels Oct 26, 2022
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like we should be using a BTreeMap (which relies on the ordered nature of the keys) instead of a Vec with a HashSet?

@MrGVSV
Copy link
Member Author

MrGVSV commented Oct 27, 2022

This feels like we should be using a BTreeMap (which relies on the ordered nature of the keys) instead of a Vec with a HashSet?

Good point!

However, my one question with that is: do we want entities to be ordered by ID or by insertion? I feel like insertion might be nicer since you could give it two entities tied to particular data or relationship, and get the same result— regardless of which one happened to spawn first.

Although, for large groups of entities where order doesn't really matter, I suppose ordering by ID makes the output a little more readable (entity 1 always comes after entity 0)?

Any thoughts on this?

@alice-i-cecile
Copy link
Member

My feeling is that by ID is simpler and more repeatable. It also serves as a nice little checksum.

@MrGVSV
Copy link
Member Author

MrGVSV commented Oct 27, 2022

My feeling is that by ID is simpler and more repeatable. It also serves as a nice little checksum.

Makes sense. I'll push the BTreeMap changes for now unless someone else feels strongly that it should be based on insertion order. In which case we can always go back and revert that change.

Otherwise, this should be good to go!

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 27, 2022
bors bot pushed a commit that referenced this pull request Oct 27, 2022
# Objective

Currently, `DynamicSceneBuilder` keeps track of entities via a `HashMap`. This has an unintended side-effect in that, when building the full `DynamicScene`, we aren't guaranteed any particular order. 

In other words, inserting Entity A then Entity B can result in either `[A, B]` or `[B, A]`. This can be rather annoying when running tests on scenes generated via the builder as it will work sometimes but not other times. There's also the potential that this might unnecessarily clutter up VCS diffs for scene files (assuming they had an intentional order).

## Solution

Store `DynamicSceneBuilder`'s entities in a `Vec` rather than a `HashMap`.

---

## Changelog

* Stablized entity order in `DynamicSceneBuilder` (0.9.0-dev)
@bors bors bot changed the title bevy_scene: Stabilize entity order in DynamicSceneBuilder [Merged by Bors] - bevy_scene: Stabilize entity order in DynamicSceneBuilder Oct 27, 2022
@bors bors bot closed this Oct 27, 2022
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
…ne#6382)

# Objective

Currently, `DynamicSceneBuilder` keeps track of entities via a `HashMap`. This has an unintended side-effect in that, when building the full `DynamicScene`, we aren't guaranteed any particular order. 

In other words, inserting Entity A then Entity B can result in either `[A, B]` or `[B, A]`. This can be rather annoying when running tests on scenes generated via the builder as it will work sometimes but not other times. There's also the potential that this might unnecessarily clutter up VCS diffs for scene files (assuming they had an intentional order).

## Solution

Store `DynamicSceneBuilder`'s entities in a `Vec` rather than a `HashMap`.

---

## Changelog

* Stablized entity order in `DynamicSceneBuilder` (0.9.0-dev)
@mockersf mockersf added the hacktoberfest-accepted A PR that was accepted for Hacktoberfest, an annual open source event label Oct 30, 2022
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…ne#6382)

# Objective

Currently, `DynamicSceneBuilder` keeps track of entities via a `HashMap`. This has an unintended side-effect in that, when building the full `DynamicScene`, we aren't guaranteed any particular order. 

In other words, inserting Entity A then Entity B can result in either `[A, B]` or `[B, A]`. This can be rather annoying when running tests on scenes generated via the builder as it will work sometimes but not other times. There's also the potential that this might unnecessarily clutter up VCS diffs for scene files (assuming they had an intentional order).

## Solution

Store `DynamicSceneBuilder`'s entities in a `Vec` rather than a `HashMap`.

---

## Changelog

* Stablized entity order in `DynamicSceneBuilder` (0.9.0-dev)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Scenes Serialized ECS data stored on the disk C-Usability A simple quality-of-life change that makes Bevy easier to use hacktoberfest-accepted A PR that was accepted for Hacktoberfest, an annual open source event S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants