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

Update to Bevy 0.10 #168

Merged
merged 9 commits into from Mar 14, 2023
Merged

Update to Bevy 0.10 #168

merged 9 commits into from Mar 14, 2023

Conversation

geieredgar
Copy link
Contributor

@geieredgar geieredgar commented Mar 6, 2023

Currently blocked by

BEGIN_COMMIT_OVERRIDE
feat!: upgrade to bevy 0.10 (#168)

BREAKING CHANGE: In addition to updating to bevy 0.10, users may need define order between LdtkSystemSet::ProcessApi and other 3rd party system sets, like rapier.
END_COMMIT_OVERRIDE

@geieredgar geieredgar changed the title Update to bevy 0.10 Update to Bevy 0.10 Mar 6, 2023
Copy link
Owner

@Trouv Trouv left a comment

Choose a reason for hiding this comment

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

Thanks for your hard work updating this and bevy_ecs_tilemap. It really made my already-busy week so much easier

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@geieredgar
Copy link
Contributor Author

geieredgar commented Mar 11, 2023

I've addressed all of the requested changes. Unfortunately, I've encountered what I believe is some race condition between systems of bevy_ecs_ldtk and bevy_rapier in the platformer example. I've seen them before, but hoped this was an issue with the then WIP bevy_rapier update. I will investigate them later today.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@geieredgar
Copy link
Contributor Author

geieredgar commented Mar 11, 2023

Here are my investigation results about the race condition in the platformer example:

Without any explicit ordering between LdtkSystemSet::ProcessApi and PhysicsSet::SyncBackend, the platformer example quite often crashes at startup with the following error:

thread 'main' panicked at 'error[B0003]: Could not insert a bundle (of type `bevy_rapier2d::dynamics::rigid_body::RapierRigidBodyHandle`) for entity 3814v0 because it doesn't exist in this World.

The system that issues the command to insert the bundle is init_rigid_bodies which is part of the PhysicsSet::SyncBackend set.

Even if the example does not crash, the player is sometimes spawned at the wrong position, see

Wrong spawn position

Ordering PhysicsSet::SyncBackend before LdtkSystemSet::ProcessApi didn't crash anymore, but the wrong spawn position did also happen occasionally (like about 1 of 30 times). Sometimes the player didn't spawn at all (maybe it was only invisible/occluded by the level), see

Player didn't spawn

Therefore, I changed the platformer example to explicitly schedule PhysicsSet::SyncBackend after LdtkSystemSet::ProcessApi. With this I didn't encounter any crashes or wrong spawn positions, but this doesn't prove it cannot happen.

Side note

As a side note, I've run the platformer example in release mode and looked at the first few frames using renderdoc. The frames looked the same between all configurations but there was a difference to the current main branch: In the main branch, the first frame was completely gray, the second completely blue. With the updates, the first three frames looked like this:

Frame 1:
Frame 1
Frame 2:
Frame 2
Frame 3:
Frame 3

In main "Frame 2" was often the third frame, sometimes "Frame 1" was the third frame, followed by "Frame 2".

I believe that this is related to #140.

@Trouv
Copy link
Owner

Trouv commented Mar 11, 2023

I see, it makes sense that we'd have to be explicit in the ordering of our systems vs rapiers now. I'm guessing with this explicit scheduling that the issue is truly gone, but it's hard to be sure. It's a bit of a shame to require users to do that - but I'm also okay with it for now. I think we could keep 0.6 focused on faithfully recreating the old schedule, and then later make more serious changes to the schedule with this issue and #140 in mind.

@geieredgar
Copy link
Contributor Author

geieredgar commented Mar 11, 2023

Yeah, I believe this is something bevy_ecs's ambiguity checker should be able to catch, but I think it is currently disabled by default because of the many false positives it reports. Improvements there might change that, so the user is at least warned about the race conditions. But this still leaves the question open which systems should run first, so I think it is important to document that somewhere.

Another solution might be to add a bevy_rapier feature that adds the scheduling constraint automatically in LdtkPlugin::build.

@Trouv
Copy link
Owner

Trouv commented Mar 11, 2023

Another solution might be to add a bevy_rapier feature that adds the scheduling constraint automatically in LdtkPlugin::build.

Hmm, I think this could be cool if we had more integration with bevy_rapier as part of such a feature. For example, more LdtkEntity attribute macros for collisions, or something. My gut reaction to this is that users will see that feature listed and expect it to be more in depth than one scheduling constraint.

I think making users responsible for the scheduling constraint is fine for now but I definitely want to announce it in the release and have it documented somewhere like you've already done. I'm interested in reworking the scheduling a bit after this release anyway, so the requirement may disappear at that point

Copy link
Owner

@Trouv Trouv left a comment

Choose a reason for hiding this comment

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

A few more small things

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
geieredgar and others added 2 commits March 12, 2023 23:25
Co-authored-by: Trevor Lovell <trevorlovelldesign@gmail.com>
Copy link
Owner

@Trouv Trouv left a comment

Choose a reason for hiding this comment

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

LGTM - I think I will merge this now just so people can depend on the main branch of the main repo rather than yours. We can fix the dependency once bevy_ecs_tilemap is updated.

@Trouv Trouv merged commit 5b8f17c into Trouv:main Mar 14, 2023
4 checks passed
Trouv added a commit that referenced this pull request Mar 31, 2023
🤖 I have created a release *beep* *boop*
---


##
[0.6.0](v0.5.0...v0.6.0)
(2023-03-31)


### ⚠ BREAKING CHANGES

* In addition to updating to bevy 0.10, users may need define order
between `LdtkSystemSet::ProcessApi` and other 3rd party system sets,
like
[rapier](https://github.com/Trouv/bevy_ecs_ldtk/blob/5b8f17cc51f91ff9aedbed8afca560e750b557c8/examples/platformer/main.rs#L17).
* change LdtkEntity's #[with] attribute to borrow EntityInstance
([#158](#158))
* split `RegisterLdtkObjects` into two new traits with a different
naming convention
([#155](#155))
* change #[from_entity_instance] to use references
([#149](#149))

### Features

* add `#[sprite_sheet_bundle(no_grid)]` attribute for generating a
single-texture `TextureAtlas` instead of a grid
([#161](#161))
([d6d3c9c](d6d3c9c))
* add `with` attribute for LdtkIntCell derive macro
([#157](#157))
([d3fbd3c](d3fbd3c))
* add LevelSet::from_iid method
([#144](#144))
([fb17ae1](fb17ae1))
* add render feature for headless mode (tilemaps only)
([#159](#159))
([2f8000e](2f8000e))
* change #[from_entity_instance] to use references
([#149](#149))
([246880f](246880f))
* change LdtkEntity's #[with] attribute to borrow EntityInstance
([#158](#158))
([c052b31](c052b31))
* register TileMetadata and TileEnumTags types
([#153](#153))
([26cae15](26cae15))
* register types `GridCoords` and `LayerMetadata`
([#146](#146))
([ed4a0f9](ed4a0f9))
* upgrade to bevy 0.10
([#168](#168))
([5b8f17c](5b8f17c))


### Bug Fixes

* use normal sprite for background color instead of tile
([#171](#171))
([b22b11d](b22b11d))


### Example Changes

* improve ground detection in platformer example
([#137](#137))
([cafba57](cafba57))
* use rect_builder buffer instead of row-specific current_rects in
spawn_wall_collisions
([#147](#147))
([45303f3](45303f3))


### Code Refactors

* split `RegisterLdtkObjects` into two new traits with a different
naming convention
([#155](#155))
([156ae8c](156ae8c))


### Documentation Changes

* explain feature flags in crate-level documentation
([#164](#164))
([a832da0](a832da0))
* explain that sprite_bundle should not be used with tilemap editor
visuals ([#142](#142))
([1a7a8a1](1a7a8a1))
* repair doc links to bevy in app module
([#154](#154))
([0f928e8](0f928e8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Trevor Lovell <trevorlovelldesign@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants