Commit a223c1a
authored
Make it easier to write tests involving fixed timesteps (#21705)
# Objective
- For running tests involving fixed timesteps, I want to advance the
time so that every call to `app.update()` triggers a fixed update
- Right now, the most precise way to do that to my knowledge is
```rust
app.insert_resource(TimeUpdateStrategy::ManualDuration(Time::<Fixed>::default().timestep()))
```
- But this is a bit clumsy, and also doesn't work when the fixed
timestep isn't at the default. Some more boilerplate would be needed in
the test setup to deal with that:
```rust
app.insert_resource(TimeUpdateStrategy::ManualDuration(app.world().resource::<Time<Fixed>>().timestep()))
```
- Good luck adapting this for the case when the fixed timestep ever
changes at runtime lol
## Solution
- Create an alternative strategy called
`TimeUpdateStrategy::FixedTimesteps` that advances time by the fixed
timestep automatically:
```rust
// Now `app.update()` will run the fixed loop exactly once!
app.insert_resource(TimeUpdateStrategy::FixedTimesteps(1))
```
## Testing
- None, as this is trivial1 parent ae60d84 commit a223c1a
2 files changed
+8
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
| |||
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| 150 | + | |
147 | 151 | | |
148 | 152 | | |
149 | 153 | | |
| |||
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
178 | 185 | | |
179 | 186 | | |
180 | 187 | | |
| |||
0 commit comments