tasks: use new animations api

This commit is contained in:
2026-02-28 16:59:29 +01:00
parent e8a7a18539
commit 816cc20087
4 changed files with 39 additions and 44 deletions

View File

@@ -104,6 +104,9 @@ impl Animation<Fract8> {
}
}
const MIN_ANIMATION_RATE: Duration = Duration::from_millis(5);
impl Animation<Fract8> {
pub async fn apply<const ACTOR_COUNT: usize>(&self, actors: [&mut dyn AnimationActor<Fract8>; ACTOR_COUNT]) {
@@ -126,9 +129,11 @@ impl Animation<Fract8> {
let steps = to.abs_diff(from);
let step_time = if steps == Fract8::MIN {
// Zero ticks is an 'invalid' animator that shouldn't get processed because start == end already
Duration::from_ticks(0)
} else {
(self.duration / steps.to_raw().into()).max(Duration::from_millis(1))
// FIXME: if the resulting duration is less than the animation rate, we also need to re-scale the number added to animator.cur_step further down below. Otherwise a 0-255 animation with a 100ms duration actually ends up running for 255ms
(self.duration / steps.to_raw().into()).max(MIN_ANIMATION_RATE)
};
Slot {
from,
@@ -163,10 +168,6 @@ impl Animation<Fract8> {
finished = true;
}
/*if animator.cur_step == animator.from || animator.cur_step == animator.to {
finished = true;
}*/
animator.target.set_value(animator.cur_step);
}
@@ -180,7 +181,7 @@ impl Animation<Fract8> {
}
let keyframe_delay = next_keyframe_time - now;
trace!("delay {keyframe_delay:?}");
trace!("delay {:?}", keyframe_delay.as_millis());
Timer::after(keyframe_delay).await;
now += keyframe_delay;
}