-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Replace the local text queues in the text systems with flags stored in a component #8549
Conversation
…s(&entity)` which just add all unqueued text. Fixed it so that only changed and unqueued text nodes are added to the queue.
…re_text_system` and `text_system`
* Added the `TextFlags` component to `TextBundle`.
…onent to schedule text computations.
* removed unused imports
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.
This is a much nicer implementation, and the performance benefits are non-trivial.
Yep, really pleased with how this PR turned out. I'd rather not have added yet another UI component but there isn't really anywhere to put the flag variables that makes sense and doesn't get filtered for changes. |
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.
One comment on terminology. Otherwise looks good to me.
crates/bevy_ui/src/widget/text.rs
Outdated
pub struct TextFlags { | ||
/// create a new measure for the text | ||
remeasure: bool, | ||
/// recompute the text | ||
recompute: bool, | ||
} |
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 feel like remeasure
should be called regenerate_measure_function
or similar. "measuring" is when you call the measure function not when you generate it. recompute
could then be called remeasure
, but I think recompute
is also fine.
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.
Yeah the terminology everywhere needs to be tightened up. I've been loose with it because I'm not really
clear on what's going to be intuitive for users etc, so just used short easy names. Even regenerate_measure_function
is a bit misleading, since the flag is most commonly going to be used when a new text node entity is spawned but its fonts haven't loaded, so it is rescheduling the initial creation of a measure function until the next frame, not regenerating an existing measure function.
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.
Changed it to generate_measure_function
, seems okay.
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.
Thought about this again, and I think these renamings are better as they capture the correct semantics:
generate_measure_func
->needs_new_measure_func
recompute
->needs_recompute
* `generate_measure_func` -> `needs_new_measure_func` * `recompute` -> `needs_recompute`
It's outside of the scope of this PR and I don't want to add any more changes, but it seems like it should be impossible for |
Objective
text_system
andmeasure_text_system
both keep local queues to keep track of text node entities that need recomputations/remeasurement, which scales very badly with large numbers of text entities (O(n^2)) and makes the code quite difficult to understand.Also
text_system
filters forChanged<Text>
, this isn't something that it should do. When a text node entity fails to be processed bymeasure_text_system
because a font can't be found, the text node will still be added totext_system
's local queue for recomputation.Text
should only ever be queued bytext_system
when a text node's geometry is modified or a new measure is added.Solution
Remove the local text queues and use a component
TextFlags
to schedule remeasurements and recomputations.Changelog
TextFlags
with fieldsremeasure
andrecompute
, which can be used to schedule a textremeasure
orrecomputation
respectively and added it toTextBundle
.measure_text_system
andtext_system
and instead use theTextFlags
component to schedule remeasurements and recomputations.Migration Guide
The component
TextFlags
has been added toTextBundle
.