Skip to content

Commit

Permalink
don't anticipate double-buffering in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snendev committed Aug 21, 2024
1 parent 432c5a7 commit 0252fc0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tests/input_playback.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// BLOCKED: add time strategy tests: https://github.com/bevyengine/bevy/issues/6146

use bevy::ecs::event::EventRegistry;
use bevy::input::keyboard::Key;
use bevy::input::keyboard::KeyboardInput;
use bevy::input::ButtonState;
Expand Down Expand Up @@ -40,6 +41,9 @@ fn playback_app(strategy: PlaybackStrategy) -> App {
InputPlugin,
InputPlaybackPlugin,
));

let mut registry = app.world_mut().resource_mut::<EventRegistry>();
registry.should_update = ShouldUpdateEvents::Always;
*app.world_mut().resource_mut::<PlaybackStrategy>() = strategy;

app
Expand Down Expand Up @@ -67,23 +71,21 @@ fn complex_timestamped_input() -> TimestampedInputs {
#[test]
fn minimal_playback() {
let mut app = playback_app(PlaybackStrategy::FrameCount);

let input_events = app.world().resource::<Events<KeyboardInput>>();
assert_eq!(input_events.len(), 0);

*app.world_mut().resource_mut::<TimestampedInputs>() = simple_timestamped_input();

app.update();

// By default, only events up to the current frame are played back
let input_events = app.world().resource::<Events<KeyboardInput>>();
assert_eq!(input_events.len(), 1);
let input = app.world().resource::<ButtonInput<KeyCode>>();
assert!(input.pressed(KeyCode::KeyF));

app.update();
let input_events = app.world().resource::<Events<KeyboardInput>>();
// Events are double-buffered
assert_eq!(input_events.len(), 2);
assert_eq!(input_events.len(), 1);
let input = app.world().resource::<ButtonInput<KeyCode>>();
assert!(!input.pressed(KeyCode::KeyF));
}
Expand Down Expand Up @@ -168,6 +170,7 @@ fn playback_strategy_paused() {
#[test]
fn playback_strategy_frame() {
let mut app = playback_app(PlaybackStrategy::FrameCount);

*app.world_mut().resource_mut::<TimestampedInputs>() = complex_timestamped_input();

let timestamped_input = app.world().resource::<TimestampedInputs>();
Expand Down Expand Up @@ -208,13 +211,13 @@ fn playback_strategy_frame_range_once() {
// Frame 3 (events are double buffered)
app.update();
let input_events = app.world().resource::<Events<KeyboardInput>>();
assert_eq!(input_events.len(), 3);
assert_eq!(input_events.len(), 1);

// Frame 4 (events are double buffered)
app.update();
let input_events = app.world().resource::<Events<KeyboardInput>>();
assert_eq!(*app.world().resource::<PlaybackStrategy>(), strategy);
assert_eq!(input_events.len(), 1);
assert_eq!(input_events.len(), 0);

// Paused
app.update();
Expand Down Expand Up @@ -246,13 +249,13 @@ fn playback_strategy_frame_range_loop() {
// Frame 3 (events are double buffered)
app.update();
let input_events = app.world().resource::<Events<KeyboardInput>>();
assert_eq!(input_events.len(), 3);
assert_eq!(input_events.len(), 1);

// Frame 4 (events are double buffered)
app.update();
let input_events = app.world().resource::<Events<KeyboardInput>>();
assert_eq!(*app.world().resource::<PlaybackStrategy>(), strategy);
assert_eq!(input_events.len(), 1);
assert_eq!(input_events.len(), 0);

// Spacing frame
app.update();
Expand Down

0 comments on commit 0252fc0

Please sign in to comment.