-
-
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
[Merged by Bors] - Add TimeUpdateStrategy
resource for manual Time
updating
#6159
Conversation
crates/bevy_time/src/lib.rs
Outdated
/// | ||
/// See [`update_with_interval`](self::TimeUpdater::update_with_instant) for more details. | ||
#[derive(Resource)] | ||
struct DesiredTime(Instant); |
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.
Is there a reason this isn't pub
?
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.
Not really. I just assumed since it was going to be inserted from the method that it didn't need to be accessed externally. Now that I think about it, there's probably some use cases where you might want to access it externally so I'll go ahead and make it public.
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 think a doc test on update_with_instant would be nice, but I'm okay if we merge this as is.
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.
Is it OK that the TimeReceiver
channel interaction has precedence over the manual time setting?
If the answer is yes, then this all seems fine to me.
I think so. I wasn't 100% sure how important |
Ping @hymm; do you have opinions on this? |
Overall it feels weird to only update time once instead of taking over the machinery completely. Are there use cases for only updating the time once and then going back to using the Instant::now()? Seems like something that would be problematic with frames reporting zero time for multiple frames or an extra long frame time once. I feel like a better approach would be to somehow not use the time_system and just do everything (including updating the Res) in the app.update_with_instant function. |
When reproducing tricky bugs, you may want to immediately "fast forward" time to the recorded problem state, and then play through as normal. I don't think it's common though.
Agreed, this feels like the more coherent strategy overall. |
I agree as well. I would've preferred to not do it the way I did but I didn't think it was possible. Given the information in the issue, time should only be changed after |
Can we have a config resource that controls whether time is updated? This resource could even supply the "next time", and then get reset after that Instant is consumed. |
Something like this? pub struct TimeConfig {
pub should_update: bool,
pub next_time: Instant,
} If so, would it be best to set |
Yep, that's the basic strategy I had in mind :)
I think just setting the
In my use case, the pattern is actually to set the exact time that was previously observed :) However when testing, you'll often want to increment it by a #[derive(Resource, Default)
pub enum TimeUpdateStrategy {
#[default]
Automatic,
ManualInstant(Instant),
ManualDuration(Duration),
} |
If it's going to be a config resource, is there still a reason to have the if let Some(TimeUpdateStrategy::ManualInstant(mut instant)) = app.world.get_resource::<TimeUpdateStrategy>() {
instant = prev_instant;
app.update();
}
// or
app.insert_resource(TimeUpdateStrategy::ManualInstant(prev_instant));
app.update(); Maybe |
I think we can cut it; the insert_resource strategy is very clear and idiomatic. Then we can point to the |
time.update(); | ||
} | ||
} | ||
TimeUpdateStrategy::ManualInstant(instant) => time.update_with_instant(*instant), |
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.
You probably want to try_recv on the channel in the manual cases too and discard the value. The time channel only can have 2 times in it and will panic if the channel gets full.
warn!("time_system did not receive the time from the render world! Calculations depending on the time may be incorrect."); | ||
Instant::now() |
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.
Not sure if this matters, but this is a change in behavior from before. This is updating the time with Instant::now(), while the old code was skipping updating the time if nothing was received. I'm not sure if either way is more right or wrong as skipping an update could be just as bad as assuming Instant::now() depending on what caused the time not to be sent.
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 not sure either but it's probably not expected behavior. I think it might be safer to skip updating like before because at least then future delta time values will remain some what accurate. Then again I don't really know. Thoughts?
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 think we can keep the current behavior for now. With the way bevy is sending the time from render right now this shouldn't ever be hit. Issues would only arise when people are doing custom stuff. In those cases, I'm not sure what the better behavior would be. We can just punt that into the future when we have more concrete evidence of what is better. It'll be easy to change things to skip the update if this is found to be problematic.
Can you update the PR description and title to reflect the new changes? |
update_with_instant
method to App
TimeUpdateStrategy
resource for manual Time
updating
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.
The PR description is still outdated and the comments should be resolved. Do fix that for us if you notice to make writing patch notes easier? I won't block on it though.
bors r+
# Objective - Addresses #6146 by allowing manual `Time` updating ## Solution - Create `TimeUpdateStrategy` config resource - Allow users to specify a manual `Instant/Duration` or leave as default (automatic) - Get resource in `bevy_time::time_system`and update time with desired value --- ## Changelog - Add `TimeUpdateStrategy` resource - Update `bevy_time::time_system` to use optional manual values Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: Lucidus115 <92978847+Lucidus115@users.noreply.github.com>
Build failed (retrying...): |
# Objective - Addresses #6146 by allowing manual `Time` updating ## Solution - Create `TimeUpdateStrategy` config resource - Allow users to specify a manual `Instant/Duration` or leave as default (automatic) - Get resource in `bevy_time::time_system`and update time with desired value --- ## Changelog - Add `TimeUpdateStrategy` resource - Update `bevy_time::time_system` to use optional manual values Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: Lucidus115 <92978847+Lucidus115@users.noreply.github.com>
TimeUpdateStrategy
resource for manual Time
updatingTimeUpdateStrategy
resource for manual Time
updating
Might be worth adding the breaking change label to this PR as it changes the behavior of Before it would be [0, 0, correct] and this PR changes it to be [0, "approximately the time between the time_system and present_frame", correct]. |
…ine#6159) # Objective - Addresses bevyengine#6146 by allowing manual `Time` updating ## Solution - Create `TimeUpdateStrategy` config resource - Allow users to specify a manual `Instant/Duration` or leave as default (automatic) - Get resource in `bevy_time::time_system`and update time with desired value --- ## Changelog - Add `TimeUpdateStrategy` resource - Update `bevy_time::time_system` to use optional manual values Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: Lucidus115 <92978847+Lucidus115@users.noreply.github.com>
# Objective - Fixes bevyengine#6355 ## Solution - Add the removed local bool from bevyengine#6159
…ine#6159) # Objective - Addresses bevyengine#6146 by allowing manual `Time` updating ## Solution - Create `TimeUpdateStrategy` config resource - Allow users to specify a manual `Instant/Duration` or leave as default (automatic) - Get resource in `bevy_time::time_system`and update time with desired value --- ## Changelog - Add `TimeUpdateStrategy` resource - Update `bevy_time::time_system` to use optional manual values Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: Lucidus115 <92978847+Lucidus115@users.noreply.github.com>
# Objective - Fixes bevyengine#6355 ## Solution - Add the removed local bool from bevyengine#6159
…ine#6159) # Objective - Addresses bevyengine#6146 by allowing manual `Time` updating ## Solution - Create `TimeUpdateStrategy` config resource - Allow users to specify a manual `Instant/Duration` or leave as default (automatic) - Get resource in `bevy_time::time_system`and update time with desired value --- ## Changelog - Add `TimeUpdateStrategy` resource - Update `bevy_time::time_system` to use optional manual values Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: Lucidus115 <92978847+Lucidus115@users.noreply.github.com>
# Objective - Fixes bevyengine#6355 ## Solution - Add the removed local bool from bevyengine#6159
Objective
app.update_with_instant
#6146 by allowing manualTime
updatingSolution
TimeUpdateStrategy
config resourceInstant/Duration
or leave as default (automatic)bevy_time::time_system
and update time with desired valueChangelog
TimeUpdateStrategy
resourcebevy_time::time_system
to use optional manual values