Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9288b0f
Move towards more flexible animation looping
SUPERCILEX May 30, 2022
30b077a
Don't use nightly stuff
SUPERCILEX May 30, 2022
c01b3ea
Merge remote-tracking branch 'upstream/main' into loop
SUPERCILEX Jun 7, 2022
3df8870
Get rid of is_looping and finish implementing stuff
SUPERCILEX Jun 7, 2022
4e15064
Reformat all comments using rustfmt
SUPERCILEX Jun 7, 2022
31ef21f
Merge branch 'comments' into loop
SUPERCILEX Jun 7, 2022
178db98
Final cleanup
SUPERCILEX Jun 7, 2022
351c180
Merge remote-tracking branch 'upstream/main' into loop
SUPERCILEX Jun 14, 2022
e119f73
Tidy
SUPERCILEX Jun 14, 2022
2f96f06
Use repeat and mirrored repeat terminology
SUPERCILEX Jul 2, 2022
90bd931
Scootch duration to a place that makes more sense
SUPERCILEX Jul 3, 2022
7e2aac1
Merge remote-tracking branch 'upstream/main' into loop
SUPERCILEX Jul 11, 2022
af67aaa
Start implementing plan
SUPERCILEX Jul 11, 2022
74a79cc
Fix very odd failure that doesn't occur on nightly
SUPERCILEX Jul 11, 2022
595c2f9
Remove debug statement
SUPERCILEX Jul 11, 2022
035c8cc
Address feedback
SUPERCILEX Jul 12, 2022
23acc28
Attempt to improve testing
SUPERCILEX Aug 3, 2022
712e4f5
Restore rewind test
SUPERCILEX Aug 3, 2022
9ff395d
Progress
SUPERCILEX Aug 3, 2022
583e5a4
Merge remote-tracking branch 'upstream/main' into tests
SUPERCILEX Aug 4, 2022
7967a02
Restore undone changes
SUPERCILEX Aug 4, 2022
9f7839d
Simplify events
SUPERCILEX Aug 4, 2022
8c96a96
Finish converting basic tween tests
SUPERCILEX Aug 4, 2022
282300f
Add a test of RepeatCount::For
SUPERCILEX Aug 4, 2022
3babed5
Use zip_eq instead of custom asserts
SUPERCILEX Aug 4, 2022
a97116d
Use as_nanos
SUPERCILEX Aug 4, 2022
c2c80bb
Merge remote-tracking branch 'upstream/main' into tests
SUPERCILEX Aug 6, 2022
024033c
Address feedback
SUPERCILEX Aug 6, 2022
4c4706a
Add more rewind tests
SUPERCILEX Aug 6, 2022
85beb8a
Use typed API
SUPERCILEX Aug 10, 2022
f335432
Address feedback
SUPERCILEX Aug 12, 2022
3c16b02
Slightly simplify generics
SUPERCILEX Sep 20, 2022
c5fb7f7
Fix potential length mismatch between test iterators
SUPERCILEX Sep 20, 2022
ca952ff
Merge branch 'main' into tests
SUPERCILEX Sep 20, 2022
7690f20
Re-write tests again using goldens
SUPERCILEX Sep 21, 2022
179192e
Show lens
SUPERCILEX Sep 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.stdout text eol=lf
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ bevy = { version = "0.8", default-features = false }

[dev-dependencies]
bevy-inspector-egui = "0.12"
goldenfile = "1.4.3"
rstest = "0.15.0"

[[example]]
name = "menu"
Expand Down
7 changes: 7 additions & 0 deletions src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
//! [`Quat::slerp()`]: https://docs.rs/bevy/0.8.0/bevy/math/struct.Quat.html#method.slerp

use bevy::prelude::*;
use std::fmt::Debug;

/// A lens over a subset of a component.
///
Expand Down Expand Up @@ -65,6 +66,7 @@ use bevy::prelude::*;
/// }
/// }
/// ```
#[cfg(not(test))]
pub trait Lens<T> {
/// Perform a linear interpolation (lerp) over the subset of fields of a
/// component or asset the lens focuses on, based on the linear ratio
Expand All @@ -74,6 +76,11 @@ pub trait Lens<T> {
fn lerp(&mut self, target: &mut T, ratio: f32);
}

#[cfg(test)]
pub trait Lens<T>: Debug {
fn lerp(&mut self, target: &mut T, ratio: f32);
}

/// A lens to manipulate the [`color`] field of a section of a [`Text`]
/// component.
///
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ mod tests {

use super::{lens::*, *};

#[derive(Debug)]
struct DummyLens {
start: f32,
end: f32,
Expand Down
547 changes: 284 additions & 263 deletions src/tweenable.rs

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions testdata/tween_tick_loop_finite.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Initial tween state:
Lens=TransformPositionLens {
start: Vec3(
0.0,
0.0,
0.0,
),
end: Vec3(
1.0,
1.0,
1.0,
),
}
Clock=AnimClock {
elapsed: 0ns,
duration: 1s,
times_completed: 0,
total_duration: Finite(
3s,
),
strategy: Repeat,
}
Direction=Forward

Tick by 0ns:
0ns/1s elapsed
Direction: Forward
State: Active
Progress: 0.0
Total completions: 0
Transform: Transform { translation: Vec3(0.0, 0.0, 0.0), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 333.333333ms:
333.333333ms/1s elapsed
Direction: Forward
State: Active
Progress: 0.33333334
Total completions: 0
Transform: Transform { translation: Vec3(0.33333334, 0.33333334, 0.33333334), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 333.333333ms:
666.666666ms/1s elapsed
Direction: Forward
State: Active
Progress: 0.6666667
Total completions: 0
Transform: Transform { translation: Vec3(0.6666667, 0.6666667, 0.6666667), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 333.333333ms:
999.999999ms/1s elapsed
Direction: Forward
State: Active
Progress: 1.0
Total completions: 0
Transform: Transform { translation: Vec3(1.0, 1.0, 1.0), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 333.333333ms:
Completion received for 42v0
1.333333332s/1s elapsed
Direction: Forward
State: Active
Progress: 1.3333334
Total completions: 1
Transform: Transform { translation: Vec3(1.3333334, 1.3333334, 1.3333334), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }

Tick by 333.333333ms:
1.666666665s/1s elapsed
Direction: Forward
State: Active
Progress: 1.6666667
Total completions: 1
Transform: Transform { translation: Vec3(1.6666667, 1.6666667, 1.6666667), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 333.333333ms:
1.999999998s/1s elapsed
Direction: Forward
State: Active
Progress: 2.0
Total completions: 1
Transform: Transform { translation: Vec3(2.0, 2.0, 2.0), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 333.333333ms:
Completion received for 42v0
2.333333331s/1s elapsed
Direction: Forward
State: Active
Progress: 2.3333333
Total completions: 2
Transform: Transform { translation: Vec3(2.3333333, 2.3333333, 2.3333333), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }

Tick by 333.333333ms:
2.666666664s/1s elapsed
Direction: Forward
State: Active
Progress: 2.6666667
Total completions: 2
Transform: Transform { translation: Vec3(2.6666667, 2.6666667, 2.6666667), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 333.333333ms:
2.999999997s/1s elapsed
Direction: Forward
State: Active
Progress: 3.0
Total completions: 2
Transform: Transform { translation: Vec3(3.0, 3.0, 3.0), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 333.333333ms:
Completion received for 42v0
3.33333333s/1s elapsed
Direction: Forward
State: Completed
Progress: 3.0
Total completions: 3
Transform: Transform { translation: Vec3(3.0, 3.0, 3.0), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }
51 changes: 51 additions & 0 deletions testdata/tween_tick_loop_finite_large_jump.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Initial tween state:
Lens=TransformPositionLens {
start: Vec3(
0.0,
0.0,
0.0,
),
end: Vec3(
1.0,
1.0,
1.0,
),
}
Clock=AnimClock {
elapsed: 0ns,
duration: 1.333333333s,
times_completed: 0,
total_duration: Finite(
133.3333333s,
),
strategy: Repeat,
}
Direction=Forward

Tick by 13.33333333s:
Completion received for 42v0
13.33333333s/1.333333333s elapsed
Direction: Forward
State: Active
Progress: 9.999999
Total completions: 10
Transform: Transform { translation: Vec3(9.999999, 9.999999, 9.999999), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }

Tick by 18446744073709551615.999999999s:
Completion received for 42v0
18446744073709551615.999999999s/1.333333333s elapsed
Direction: Forward
State: Completed
Progress: 99.99999
Total completions: 100
Transform: Transform { translation: Vec3(99.99999, 99.99999, 99.99999), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }

Tick by 18446744073709551615.999999999s:
18446744073709551615.999999999s/1.333333333s elapsed
Direction: Forward
State: Completed
Progress: 99.99999
Total completions: 100
Transform: Transform { translation: Vec3(99.99999, 99.99999, 99.99999), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
49 changes: 49 additions & 0 deletions testdata/tween_tick_loop_infinite_large_jump.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Initial tween state:
Lens=TransformPositionLens {
start: Vec3(
0.0,
0.0,
0.0,
),
end: Vec3(
1.0,
1.0,
1.0,
),
}
Clock=AnimClock {
elapsed: 0ns,
duration: 1.333333333s,
times_completed: 0,
total_duration: Infinite,
strategy: Repeat,
}
Direction=Forward

Tick by 13.33333333s:
Completion received for 42v0
13.33333333s/1.333333333s elapsed
Direction: Forward
State: Active
Progress: 9.999999
Total completions: 10
Transform: Transform { translation: Vec3(9.999999, 9.999999, 9.999999), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }

Tick by 18446744073709551615.999999999s:
Completion received for 42v0
18446744073709551615.999999999s/1.333333333s elapsed
Direction: Forward
State: Active
Progress: 1.3835058e19
Total completions: 3458764514
Transform: Transform { translation: Vec3(1.3835058e19, 1.3835058e19, 1.3835058e19), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }

Tick by 18446744073709551615.999999999s:
18446744073709551615.999999999s/1.333333333s elapsed
Direction: Forward
State: Active
Progress: 1.3835058e19
Total completions: 3458764514
Transform: Transform { translation: Vec3(1.3835058e19, 1.3835058e19, 1.3835058e19), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
59 changes: 59 additions & 0 deletions testdata/tween_tick_loop_partial_completion.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Initial tween state:
Lens=TransformPositionLens {
start: Vec3(
0.0,
0.0,
0.0,
),
end: Vec3(
1.0,
1.0,
1.0,
),
}
Clock=AnimClock {
elapsed: 0ns,
duration: 666.666666ms,
times_completed: 0,
total_duration: Finite(
1.42s,
),
strategy: Repeat,
}
Direction=Forward

Tick by 400ms:
400ms/666.666666ms elapsed
Direction: Forward
State: Active
Progress: 0.59999996
Total completions: 0
Transform: Transform { translation: Vec3(0.59999996, 0.59999996, 0.59999996), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 400ms:
Completion received for 42v0
800ms/666.666666ms elapsed
Direction: Forward
State: Active
Progress: 1.1999999
Total completions: 1
Transform: Transform { translation: Vec3(1.1999999, 1.1999999, 1.1999999), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }

Tick by 400ms:
1.2s/666.666666ms elapsed
Direction: Forward
State: Active
Progress: 1.8000001
Total completions: 1
Transform: Transform { translation: Vec3(1.8000001, 1.8000001, 1.8000001), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 400ms:
Completion received for 42v0
1.6s/666.666666ms elapsed
Direction: Forward
State: Completed
Progress: 2.1299999
Total completions: 2
Transform: Transform { translation: Vec3(2.1299999, 2.1299999, 2.1299999), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }
57 changes: 57 additions & 0 deletions testdata/tween_tick_loop_ping_pong.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Initial tween state:
Lens=TransformPositionLens {
start: Vec3(
0.0,
0.0,
0.0,
),
end: Vec3(
1.0,
1.0,
1.0,
),
}
Clock=AnimClock {
elapsed: 0ns,
duration: 333.333333ms,
times_completed: 0,
total_duration: Infinite,
strategy: MirroredRepeat,
}
Direction=Forward

Tick by 200ms:
200ms/333.333333ms elapsed
Direction: Forward
State: Active
Progress: 0.59999996
Total completions: 0
Transform: Transform { translation: Vec3(0.59999996, 0.59999996, 0.59999996), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 200ms:
Completion received for 42v0
400ms/333.333333ms elapsed
Direction: Backward
State: Active
Progress: 1.1999999
Total completions: 1
Transform: Transform { translation: Vec3(-0.19999993, -0.19999993, -0.19999993), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }

Tick by 200ms:
600ms/333.333333ms elapsed
Direction: Backward
State: Active
Progress: 1.8000001
Total completions: 1
Transform: Transform { translation: Vec3(-0.8000001, -0.8000001, -0.8000001), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Tick by 200ms:
Completion received for 42v0
800ms/333.333333ms elapsed
Direction: Forward
State: Active
Progress: 2.3999999
Total completions: 2
Transform: Transform { translation: Vec3(2.3999999, 2.3999999, 2.3999999), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Event received: TweenCompleted { entity: 42v0, user_data: 69420 }
Loading