comparison src/th06/interpolator.rs @ 709:6d4802abe134

Make interpolators use u32 instead of u16.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 08 Sep 2019 17:53:13 +0200
parents 6020e33d4fc4
children 5016c09e5d7c
comparison
equal deleted inserted replaced
708:3954801b6299 709:6d4802abe134
21 ($name:ident, $n:tt) => { 21 ($name:ident, $n:tt) => {
22 #[derive(Debug, Clone)] 22 #[derive(Debug, Clone)]
23 pub(crate) struct $name<T> { 23 pub(crate) struct $name<T> {
24 start_values: [T; $n], 24 start_values: [T; $n],
25 end_values: [T; $n], 25 end_values: [T; $n],
26 start_frame: u16, 26 start_frame: u32,
27 end_frame: u16, 27 end_frame: u32,
28 formula: Formula, 28 formula: Formula,
29 } 29 }
30 30
31 impl<T> $name<T> 31 impl<T> $name<T>
32 where f32: From<T>, 32 where f32: From<T>,
34 T: std::ops::Sub<Output = T>, 34 T: std::ops::Sub<Output = T>,
35 T: std::ops::Add<Output = T>, 35 T: std::ops::Add<Output = T>,
36 T: Copy, 36 T: Copy,
37 T: Default, 37 T: Default,
38 { 38 {
39 pub fn new(start_values: [T; $n], start_frame: u16, end_values: [T; $n], end_frame: u16, formula: Formula) -> $name<T> { 39 pub fn new(start_values: [T; $n], start_frame: u32, end_values: [T; $n], end_frame: u32, formula: Formula) -> $name<T> {
40 $name { 40 $name {
41 start_values, 41 start_values,
42 end_values, 42 end_values,
43 start_frame, 43 start_frame,
44 end_frame, 44 end_frame,
45 formula, 45 formula,
46 } 46 }
47 } 47 }
48 48
49 pub fn set_start(&mut self, frame: u32, values: [T; $n]) {
50 self.start_values = values;
51 self.start_frame = frame;
52 }
53
54 pub fn set_end(&mut self, frame: u32, values: [T; $n]) {
55 self.end_values = values;
56 self.end_frame = frame;
57 }
58
59 pub fn set_end_values(&mut self, values: [T; $n]) {
60 self.end_values = values;
61 }
62
63 pub fn set_end_frame(&mut self, frame: u32) {
64 self.end_frame = frame;
65 }
66
49 // XXX: Make it return [T; $n] instead, we don’t want to only do f32 here. 67 // XXX: Make it return [T; $n] instead, we don’t want to only do f32 here.
50 pub fn values(&self, frame: u16) -> [f32; $n] { 68 pub fn values(&self, frame: u32) -> [f32; $n] {
51 if frame + 1 >= self.end_frame { 69 if frame + 1 >= self.end_frame {
52 // XXX: skip the last interpolation step. 70 // XXX: skip the last interpolation step.
53 // This bug is replicated from the original game. 71 // This bug is replicated from the original game.
54 //self.start_frame = self.end_frame; 72 //self.start_frame = self.end_frame;
55 //self.end_values 73 //self.end_values