# HG changeset patch # User Emmanuel Gil Peyrot # Date 1567957993 -7200 # Node ID 6d4802abe1346c69a0e8e7556007f4b1aacba6a9 # Parent 3954801b6299bd039d64408de30dcb55988794a0 Make interpolators use u32 instead of u16. diff --git a/src/th06/anm0_vm.rs b/src/th06/anm0_vm.rs --- a/src/th06/anm0_vm.rs +++ b/src/th06/anm0_vm.rs @@ -28,7 +28,7 @@ pub struct Vertex { #[derive(Debug, Clone, Default)] pub struct Sprite { blendfunc: u32, - frame: u16, + frame: u32, width_override: f32, height_override: f32, @@ -226,7 +226,7 @@ pub struct AnmRunner { frame: u16, waiting: bool, variables: ([i32; 4], [f32; 4], [i32; 4]), - timeout: Option, + timeout: Option, } impl AnmRunner { @@ -357,7 +357,7 @@ impl AnmRunner { sprite.scale_speed = [ssx, ssy]; } Instruction::Fade(new_alpha, duration) => { - sprite.fade_interpolator = Some(Interpolator1::new([sprite.color[3] as f32], sprite.frame, [new_alpha as f32], sprite.frame + duration as u16, Formula::Linear)); + sprite.fade_interpolator = Some(Interpolator1::new([sprite.color[3] as f32], sprite.frame, [new_alpha as f32], sprite.frame + duration, Formula::Linear)); } Instruction::SetBlendmodeAlphablend() => { sprite.blendfunc = 1; @@ -385,13 +385,13 @@ impl AnmRunner { sprite.dest_offset = [x, y, z]; } Instruction::MoveToLinear(x, y, z, duration) => { - sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration as u16, Formula::Linear)); + sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration, Formula::Linear)); } Instruction::MoveToDecel(x, y, z, duration) => { - sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration as u16, Formula::InvertPower2)); + sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration, Formula::InvertPower2)); } Instruction::MoveToAccel(x, y, z, duration) => { - sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration as u16, Formula::Power2)); + sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration, Formula::Power2)); } Instruction::Wait() => { self.waiting = true; @@ -423,7 +423,7 @@ impl AnmRunner { sprite.visible = (visible & 1) != 0; } Instruction::ScaleIn(sx, sy, duration) => { - sprite.scale_interpolator = Some(Interpolator2::new(sprite.rescale, sprite.frame, [sx, sy], sprite.frame + duration as u16, Formula::Linear)); + sprite.scale_interpolator = Some(Interpolator2::new(sprite.rescale, sprite.frame, [sx, sy], sprite.frame + duration, Formula::Linear)); } Instruction::Todo(_todo) => { // TODO. diff --git a/src/th06/enemy.rs b/src/th06/enemy.rs --- a/src/th06/enemy.rs +++ b/src/th06/enemy.rs @@ -400,12 +400,12 @@ impl Enemy { let speed = if self.update_mode == 1 { let mut speed = 0.; if let Some(interpolator) = &self.interpolator { - let values = interpolator.values(self.frame as u16); + let values = interpolator.values(self.frame); x = values[0]; y = values[1]; } if let Some(interpolator) = &self.speed_interpolator { - let values = interpolator.values(self.frame as u16); + let values = interpolator.values(self.frame); speed = values[0]; } speed diff --git a/src/th06/interpolator.rs b/src/th06/interpolator.rs --- a/src/th06/interpolator.rs +++ b/src/th06/interpolator.rs @@ -23,8 +23,8 @@ macro_rules! generate_interpolator { pub(crate) struct $name { start_values: [T; $n], end_values: [T; $n], - start_frame: u16, - end_frame: u16, + start_frame: u32, + end_frame: u32, formula: Formula, } @@ -36,7 +36,7 @@ macro_rules! generate_interpolator { T: Copy, T: Default, { - pub fn new(start_values: [T; $n], start_frame: u16, end_values: [T; $n], end_frame: u16, formula: Formula) -> $name { + pub fn new(start_values: [T; $n], start_frame: u32, end_values: [T; $n], end_frame: u32, formula: Formula) -> $name { $name { start_values, end_values, @@ -46,8 +46,26 @@ macro_rules! generate_interpolator { } } + pub fn set_start(&mut self, frame: u32, values: [T; $n]) { + self.start_values = values; + self.start_frame = frame; + } + + pub fn set_end(&mut self, frame: u32, values: [T; $n]) { + self.end_values = values; + self.end_frame = frame; + } + + pub fn set_end_values(&mut self, values: [T; $n]) { + self.end_values = values; + } + + pub fn set_end_frame(&mut self, frame: u32) { + self.end_frame = frame; + } + // XXX: Make it return [T; $n] instead, we don’t want to only do f32 here. - pub fn values(&self, frame: u16) -> [f32; $n] { + pub fn values(&self, frame: u32) -> [f32; $n] { if frame + 1 >= self.end_frame { // XXX: skip the last interpolation step. // This bug is replicated from the original game.