Skip to content

Commit

Permalink
Fix Time (#17504)
Browse files Browse the repository at this point in the history
# Objective

- Fix issue @mockersf identified with `example-showcase` where time was
not being received correctly from the render world.

## Solution

- Refactored to ensure `TimeReceiver` is always cleared even if it isn't
being used in the main world.

## Testing

- `cargo run -p example-showcase -- --page 1 --per-page 1 run
--screenshot-frame 200 --fixed-frame-time 0.0125 --stop-frame 450
--in-ci --show-logs`
  • Loading branch information
bushrat011899 authored Jan 23, 2025
1 parent 784a9d3 commit c7ddec5
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions crates/bevy_time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,28 @@ pub fn time_system(
#[cfg(feature = "std")] time_recv: Option<Res<TimeReceiver>>,
#[cfg(feature = "std")] mut has_received_time: Local<bool>,
) {
match update_strategy.as_ref() {
TimeUpdateStrategy::Automatic => {
#[cfg(feature = "std")]
let new_time = if let Some(time_recv) = time_recv {
// TODO: Figure out how to handle this when using pipelined rendering.
if let Ok(new_time) = time_recv.0.try_recv() {
*has_received_time = true;
new_time
} else {
if *has_received_time {
log::warn!("time_system did not receive the time from the render world! Calculations depending on the time may be incorrect.");
}
Instant::now()
}
} else {
Instant::now()
};
#[cfg(feature = "std")]
// TODO: Figure out how to handle this when using pipelined rendering.
let sent_time = match time_recv.map(|res| res.0.try_recv()) {
Some(Ok(new_time)) => {
*has_received_time = true;
Some(new_time)
}
Some(Err(_)) => {
if *has_received_time {
log::warn!("time_system did not receive the time from the render world! Calculations depending on the time may be incorrect.");
}
None
}
None => None,
};

#[cfg(not(feature = "std"))]
let new_time = Instant::now();
#[cfg(not(feature = "std"))]
let sent_time = None;

real_time.update_with_instant(new_time);
match update_strategy.as_ref() {
TimeUpdateStrategy::Automatic => {
real_time.update_with_instant(sent_time.unwrap_or_else(Instant::now));
}
TimeUpdateStrategy::ManualInstant(instant) => real_time.update_with_instant(*instant),
TimeUpdateStrategy::ManualDuration(duration) => real_time.update_with_duration(*duration),
Expand Down

0 comments on commit c7ddec5

Please sign in to comment.