Mercurial > touhou
changeset 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 | 3954801b6299 |
children | 377c241be559 |
files | src/th06/anm0_vm.rs src/th06/enemy.rs src/th06/interpolator.rs |
diffstat | 3 files changed, 31 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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<u16>, + timeout: Option<u32>, } 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.
--- 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
--- a/src/th06/interpolator.rs +++ b/src/th06/interpolator.rs @@ -23,8 +23,8 @@ macro_rules! generate_interpolator { pub(crate) struct $name<T> { 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<T> { + pub fn new(start_values: [T; $n], start_frame: u32, end_values: [T; $n], end_frame: u32, formula: Formula) -> $name<T> { $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.