ass_renderer/animation/
timing.rs1#[cfg(feature = "nostd")]
4use alloc::{string::String, vec::Vec};
5#[cfg(not(feature = "nostd"))]
6use std::{string::String, vec::Vec};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum AnimationInterpolation {
11 Linear,
13 Smooth,
15 Smoother,
17}
18
19#[derive(Debug, Clone)]
21pub struct AnimationTag {
22 pub t1: Option<u32>,
24 pub t2: Option<u32>,
26 pub accel: Option<f32>,
28 pub modifiers: Vec<String>,
30}
31
32pub type InterpolationFn = fn(f32) -> f32;
34
35#[derive(Debug, Clone)]
37pub struct AnimationTiming {
38 pub start_cs: u32,
40 pub end_cs: u32,
42 pub accel: f32,
44}
45
46impl AnimationTiming {
47 pub fn new(start_cs: u32, end_cs: u32, accel: f32) -> Self {
49 Self {
50 start_cs,
51 end_cs,
52 accel,
53 }
54 }
55
56 pub fn progress(&self, time_cs: u32) -> f32 {
58 if time_cs <= self.start_cs {
59 return 0.0;
60 }
61 if time_cs >= self.end_cs {
62 return 1.0;
63 }
64
65 let duration = (self.end_cs - self.start_cs) as f32;
66 let elapsed = (time_cs - self.start_cs) as f32;
67 let linear_progress = elapsed / duration;
68
69 if (self.accel - 1.0).abs() < 0.001 {
71 linear_progress
72 } else {
73 linear_progress.powf(self.accel)
74 }
75 }
76}