-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Contextually clearing gizmos #10973
Contextually clearing gizmos #10973
Conversation
I believe it's two different axis of control here, we could use the same generic since this uses it purely as a marker but I don't personally think it's worthwhile. In most cases this should default to Fixed or Update depending on system position and users shouldn't even know its there. |
1443c40
to
4c76b5c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a clean solution to me. Technically less flexible for extension than the approach of exposing , but I think that's sufficient. 👍GizmoBuffer
as users can only store gizmo buffers based on their type instead of as values
Was gonna point out that dropping the swap allocation isn't necessary but it got fixed under my nose :3
Could you also mention in the doc comment of update_gizmo_meshes
that this clears GizmoStorage<Update>
? Just for making the data flow clear as other gizmo storages persist.
I see the similarities, and it could be integrated into my config groups, but I do not think it should be. Ideally the gizmos should behave the same regardless of where they are used. Linking gizmo appearance settings and where they can be used doesn't seem right to me. I think this PR is a step in the right direction. A future retained gizmo API could solve this problem as well, but that would probably require a major refactoring of the entire gizmo code. |
crates/bevy_gizmos/src/lib.rs
Outdated
.init_resource::<GizmoStorage>() | ||
.add_systems(Last, update_gizmo_meshes) | ||
.init_resource::<GizmoStorage<Swap>>() | ||
.init_resource::<GizmoStorage<()>>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like initially, the default buffer had the Update
type, now it uses ()
. What's the reasoning behind changing it? I thought it was clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I don't really care much either way. This one gets swapped out for other buffers, so someone looking at that might get confused now that gizmos requested in a GizmoStorage<Update>
are cleared in FixedMain
.
Ideally I guess it'd be that we have both ()
and Update
but I don't think the complexity of adding that is worthwhile. Maybe if we wanted to add the ability to query Gizmos<Update>
inside other contexts I suppose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a couple questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the user interface, seems pretty robust for custom contexts, persistent gizmos #9178 should cover other cases.
The internals are a bit weird, but I don't have a better idea than introducing GizmoStorage<Update>
like you mention.
One question.
The current context uses ()
(which doubles as Update
) and we store the Update
in Swap
when using FixedUpdate
.
Wouldn't another level of context, say FixedUpdateTurn
(in some imaginary turn-based game) break this?
Since the previous context of FixedUpdate
would need to move from ()
to Swap
, which currently holds Update
?
If so, it's probably worth noting, it'd be pretty hard to debug.
Definitely is a bit hardcoded to just 1 layer of context at the moment. We could solve that by making this stack-based, but I was a bit hesitant about going down that path because I was worried about over-engineering it. I'll add a comment regardless, I could also add a hard panic by making the swap buffer never overwrite. |
I agree that adding stack machinery insn't necessary – if a user nests a context, they can store it in another buffer the same way this PR does it. I'd say the better solution is to clarify that Edit: |
ad64888
to
feba79f
Compare
Yeah this seems like a better idea, I'll make the stash/pop take a generic for a swap buffer. I can't make |
e294f3d
to
9a9be66
Compare
Shouldn't be merged quite yet given some changes with the config stuff. |
Should be ready for merging/final reviews now |
6c47917
to
f71152a
Compare
Fix bug of strips getting extended by list Document GizmoStorage Don't import bevy_internal Formatting Move clearing the gizmos to FixedLast Fix some ordering issues with clearing/collecting Rename Context to Clear Formatting Use mem::swap for changing clear context contents Revert examples Improve documentation, explain how to setup a custom context Hide Swap buffer, improve documentation for update_gizmo_meshes Reword again more rewording
da6d59d
to
659a117
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm more convinced now: the added complexity isn't too bad, and it's worth it for the consistency in developer experience.
@Aceeri once this is passing CI I'll merge. Looks like it just needs formatting currently. |
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1301 if you'd like to help out. |
It looks like your PR is a breaking change, but you didn't provide a migration guide. Could you add some context on what users should update when this change get released in a new version of Bevy? |
Just marking this as a breaking change so the migration guide tool picks it up. ( |
Objective
Allow
Gizmos
to work inFixedUpdate
without any changes needed. This changesGizmos
from being a purely immediate mode api, but allows the user to use it as if it were an immediate mode API regardless of schedule context.Also allows for extending by other custom schedules by adding their own
GizmoStorage<Clear>
and the requisite systems:propagate_gizmos::<Clear>
beforeupdate_gizmo_meshes
stash_default_gizmos
when starting a clear contextpop_default_gizmos
when ending a clear contextcollect_default_gizmos
when grabbing the requested gizmosclear_gizmos
for clearing the context's gizmosSolution
Adds a generic to
Gizmos
that defaults toUpdate
(the current way gizmos works). When entering a new clear context the defaultGizmos
gets swapped out for that context's duration so the context can collect the gizmos requested.Prior work: #9153
To do
FixedUpdate
should probably get its own First, Pre, Update, Post, Last system sets for this. Otherwise users will need to make sure to order their systems beforeclear_gizmos
. This could alternatively be fixed by moving the setup of this tobevy_time::fixed
?PR to fix this issue: Add First/Pre/Post/Last schedules to the Fixed timestep #10977
Context
generic on gizmos?Clear
?Changelog
FixedMain
now last until the nextFixedMain
iteration runs.