annotate src/th06/anm0_vm.rs @ 641:a58103f2f264

Implement and use interpolators.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 07 Jul 2019 12:17:42 +0200
parents 37d151fe000b
children 9e40bd5cc26d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 //! Animation runner.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 use crate::th06::anm0::{
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 Script,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 Anm0,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 Call,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 Instruction,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 };
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 use std::cell::RefCell;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 use std::rc::Rc;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
12 #[derive(Debug, Clone, Copy, PartialEq)]
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
13 enum Formula {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
14 Linear,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
15 Power2,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
16 InvertPower2,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
17 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
18
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
19 impl Formula {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
20 fn apply(&self, x: f32) -> f32 {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
21 match self {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
22 Formula::Linear => x,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
23 Formula::Power2 => x * x,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
24 Formula::InvertPower2 => 2. * x - x * x,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
25 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
26 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
27 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
28
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
29 macro_rules! generate_interpolator {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
30 ($name:ident, $n:tt) => {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
31 #[derive(Debug, Clone)]
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
32 struct $name<T> {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
33 start_values: [T; $n],
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
34 end_values: [T; $n],
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
35 start_frame: u16,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
36 end_frame: u16,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
37 formula: Formula,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
38 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
39
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
40 impl<T> $name<T>
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
41 where f32: From<T>,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
42 T: From<f32>,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
43 T: std::ops::Sub<Output = T>,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
44 T: std::ops::Add<Output = T>,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
45 T: Copy,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
46 T: Default,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
47 {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
48 pub fn new(start_values: [T; $n], start_frame: u16, end_values: [T; $n], end_frame: u16, formula: Formula) -> $name<T> {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
49 $name {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
50 start_values,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
51 end_values,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
52 start_frame,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
53 end_frame,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
54 formula,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
55 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
56 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
57
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
58 // XXX: Make it return [T; $n] instead, we don’t want to only do f32 here.
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
59 pub fn values(&self, frame: u16) -> [f32; $n] {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
60 if frame + 1 >= self.end_frame {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
61 // XXX: skip the last interpolation step.
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
62 // This bug is replicated from the original game.
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
63 //self.start_frame = self.end_frame;
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
64 //self.end_values
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
65 let mut values: [f32; $n] = [Default::default(); $n];
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
66 for (i, value) in self.end_values.iter().enumerate() {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
67 values[i] = f32::from(*value);
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
68 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
69 values
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
70 } else {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
71 let mut coeff = (frame - self.start_frame) as f32 / (self.end_frame - self.start_frame) as f32;
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
72 coeff = self.formula.apply(coeff);
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
73 let mut values: [f32; $n] = [Default::default(); $n];
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
74 for (i, (start, end)) in self.start_values.iter().zip(&self.end_values).enumerate() {
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
75 values[i] = f32::from(*start + T::from(coeff * f32::from(*end - *start)));
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
76 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
77 values
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
78 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
79 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
80 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
81 };
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
82 }
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
83
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
84 generate_interpolator!(Interpolator1, 1);
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
85 generate_interpolator!(Interpolator2, 2);
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
86 generate_interpolator!(Interpolator3, 3);
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 /// Base visual element.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 #[derive(Debug, Clone, Default)]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 pub struct Sprite {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 blendfunc: u32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 frame: u16,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 width_override: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 height_override: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 angle: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 removed: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 changed: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 visible: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 force_rotation: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 automatic_orientation: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 allow_dest_offset: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 mirrored: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 corner_relative_placement: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
107 scale_interpolator: Option<Interpolator2<f32>>,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
108 fade_interpolator: Option<Interpolator1<f32>>, // XXX: should be u8!
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
109 offset_interpolator: Option<Interpolator3<f32>>,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
110 rotation_interpolator: Option<Interpolator3<f32>>,
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
111 color_interpolator: Option<Interpolator3<f32>>, // XXX: should be u8!
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 anm: Option<Anm0>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 dest_offset: [f32; 3],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 texcoords: [f32; 4],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 texoffsets: [f32; 2],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 rescale: [f32; 2],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 scale_speed: [f32; 2],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 rotations_3d: [f32; 3],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 rotations_speed_3d: [f32; 3],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 color: [u8; 4],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 impl Sprite {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 /// Create a new sprite.
640
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
127 pub fn new(width_override: f32, height_override: f32) -> Sprite {
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
128 Sprite {
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
129 width_override,
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
130 height_override,
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
131 changed: true,
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
132 visible: true,
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
133 rescale: [1., 1.],
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
134 color: [255, 255, 255, 255],
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
135 ..Default::default()
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
136 }
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 /// Update sprite values from the interpolators.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140 pub fn update(&mut self) {
640
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
141 self.frame += 1;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
142
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
143 let [sax, say, saz] = self.rotations_speed_3d;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
144 if sax != 0. || say != 0. || saz != 0. {
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
145 let [ax, ay, az] = self.rotations_3d;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
146 self.rotations_3d = [ax + sax, ay + say, az + saz];
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
147 self.changed = true;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
148 } else if let Some(ref interpolator) = self.rotation_interpolator {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
149 self.rotations_3d = interpolator.values(self.frame);
640
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
150 self.changed = true;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
151 }
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
152
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
153 let [rsx, rsy] = self.scale_speed;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
154 if rsx != 0. || rsy != 0. {
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
155 let [rx, ry] = self.rescale;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
156 self.rescale = [rx + rsx, ry + rsy];
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
157 self.changed = true;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
158 }
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
159
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
160 if let Some(ref interpolator) = self.fade_interpolator {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
161 self.color[3] = interpolator.values(self.frame)[0] as u8;
640
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
162 self.changed = true;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
163 }
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
164
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
165 if let Some(ref interpolator) = self.scale_interpolator {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
166 self.rescale = interpolator.values(self.frame);
640
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
167 self.changed = true;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
168 }
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
169
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
170 if let Some(ref interpolator) = self.offset_interpolator {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
171 self.dest_offset = interpolator.values(self.frame);
640
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
172 self.changed = true;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
173 }
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
174
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
175 if let Some(ref interpolator) = self.color_interpolator {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
176 let color = interpolator.values(self.frame);
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
177 // TODO: this can probably be made to look nicer.
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
178 self.color[0] = color[0] as u8;
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
179 self.color[1] = color[1] as u8;
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
180 self.color[2] = color[2] as u8;
640
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
181 self.changed = true;
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
182 }
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 /// Interpreter for `Anm0` instructions to update a `Sprite`.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 pub struct AnmRunner {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 anm: Anm0,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189 sprite: Rc<RefCell<Sprite>>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190 running: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 sprite_index_offset: u32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 script: Script,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193 instruction_pointer: usize,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 frame: u16,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 waiting: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 variables: ([i32; 4], [f32; 4], [i32; 4]),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197 timeout: Option<u16>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
199
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 impl AnmRunner {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201 /// Create a new `AnmRunner`.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 pub fn new(anm: &Anm0, script_id: u8, sprite: Rc<RefCell<Sprite>>, sprite_index_offset: u32) -> AnmRunner {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 let mut runner = AnmRunner {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204 anm: anm.clone(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205 sprite: sprite,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206 running: true,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 waiting: false,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
208
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
209 script: anm.scripts[&script_id].clone(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 frame: 0,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 timeout: None,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212 instruction_pointer: 0,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 variables: ([0, 0, 0, 0 ],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 [0., 0., 0., 0.],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215 [0, 0, 0, 0 ]),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 sprite_index_offset: sprite_index_offset,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 };
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219 runner.run_frame();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
220 runner.sprite_index_offset = 0;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221 runner
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224 /// Trigger an interrupt.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 pub fn interrupt(&mut self, interrupt: i32) -> bool {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226 let mut new_ip = self.script.interrupts.get(&interrupt);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 if new_ip.is_none() {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 new_ip = self.script.interrupts.get(&-1);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
229 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
230 let new_ip = if let Some(new_ip) = new_ip {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 *new_ip as usize
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232 } else {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233 return false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 };
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 self.instruction_pointer = new_ip;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236 let Call { time: frame, instr: _ } = &self.script.instructions[self.instruction_pointer];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
237 self.frame = *frame;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
238 self.waiting = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 self.sprite.borrow_mut().visible = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240 true
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 /// Advance the Anm of a single frame.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 pub fn run_frame(&mut self) -> bool {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 if !self.running {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 return false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
247 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
248
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249 while self.running && !self.waiting {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250 let Call { time: frame, instr } = self.script.instructions[self.instruction_pointer];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
251 let frame = frame.clone();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 if frame > self.frame {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
254 break;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255 } else {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 self.instruction_pointer += 1;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
258
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
259 if frame == self.frame {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 self.run_instruction(instr);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 self.sprite.borrow_mut().changed = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
262 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
263 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265 if !self.waiting {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266 self.frame += 1;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
267 } else if let Some(timeout) = self.timeout {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
268 if timeout == self.sprite.borrow().frame { // TODO: check if it’s happening at the correct frame.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
269 self.waiting = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
271 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
272
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273 self.sprite.borrow_mut().update();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275 self.running
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
276 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
278 fn run_instruction(&mut self, instruction: Instruction) {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
279 let mut sprite = self.sprite.borrow_mut();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
280 match instruction {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
281 Instruction::Delete() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
282 sprite.removed = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
283 self.running = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
284 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
285 Instruction::LoadSprite(sprite_index) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
286 sprite.anm = Some(self.anm.clone());
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
287 let texcoords = &self.anm.sprites[(sprite_index + self.sprite_index_offset) as usize];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
288 sprite.texcoords = [texcoords.x, texcoords.y, texcoords.width, texcoords.height];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
289 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
290 Instruction::SetScale(sx, sy) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
291 sprite.rescale = [sx, sy];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
292 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
293 Instruction::SetAlpha(alpha) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
294 // TODO: check this modulo.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
295 sprite.color[3] = (alpha % 256) as u8;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
296 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
297 Instruction::SetColor(b, g, r) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
298 if sprite.fade_interpolator.is_none() {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
299 sprite.color[0] = r;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
300 sprite.color[1] = g;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
301 sprite.color[2] = b;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
302 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
303 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
304 Instruction::Jump(pointer) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
305 // TODO: is that really how it works?
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
306 self.instruction_pointer = pointer as usize;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
307 self.frame = self.script.instructions[pointer as usize].time;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
308 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
309 Instruction::ToggleMirrored() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
310 sprite.mirrored = !sprite.mirrored;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
311 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
312 Instruction::SetRotations3d(rx, ry, rz) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
313 sprite.rotations_3d = [rx, ry, rz];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
314 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
315 Instruction::SetRotationsSpeed3d(srx, sry, srz) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
316 sprite.rotations_speed_3d = [srx, sry, srz];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
317 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
318 Instruction::SetScaleSpeed(ssx, ssy) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
319 sprite.scale_speed = [ssx, ssy];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
320 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
321 Instruction::Fade(new_alpha, duration) => {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
322 sprite.fade_interpolator = Some(Interpolator1::new([sprite.color[3] as f32], sprite.frame, [new_alpha as f32], sprite.frame + duration as u16, Formula::Linear));
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
323 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
324 Instruction::SetBlendmodeAlphablend() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
325 sprite.blendfunc = 1;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
326 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
327 Instruction::SetBlendmodeAdd() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
328 sprite.blendfunc = 0;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
329 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
330 Instruction::KeepStill() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
331 self.running = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
332 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
333 Instruction::LoadRandomSprite(min_index, amplitude) => {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
334 let sprite_index = min_index; // XXX: + randrange(amplitude);
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
335
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
336 // TODO: refactor that with Instruction::LoadSprite.
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
337 sprite.anm = Some(self.anm.clone());
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
338 let texcoords = &self.anm.sprites[(sprite_index + self.sprite_index_offset) as usize];
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
339 sprite.texcoords = [texcoords.x, texcoords.y, texcoords.width, texcoords.height];
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
340 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
341 Instruction::Move(x, y, z) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
342 sprite.dest_offset = [x, y, z];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
343 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
344 Instruction::MoveToLinear(x, y, z, duration) => {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
345 sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration as u16, Formula::Linear));
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
346 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
347 Instruction::MoveToDecel(x, y, z, duration) => {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
348 sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration as u16, Formula::InvertPower2));
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
349 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
350 Instruction::MoveToAccel(x, y, z, duration) => {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
351 sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration as u16, Formula::Power2));
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
352 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
353 Instruction::Wait() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
354 self.waiting = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
355 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
356 // There is nothing to do here.
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
357 Instruction::InterruptLabel(_label) => (),
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
358 Instruction::SetCornerRelativePlacement() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
359 sprite.corner_relative_placement = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
360 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
361 Instruction::WaitEx() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
362 sprite.visible = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
363 self.waiting = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
364 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
365 Instruction::SetAllowOffset(value) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
366 sprite.allow_dest_offset = value == 1
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
367 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
368 Instruction::SetAutomaticOrientation(value) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
369 sprite.automatic_orientation = value == 1
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
370 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
371 Instruction::ShiftTextureX(dx) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
372 let [tox, toy] = sprite.texoffsets;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
373 sprite.texoffsets = [tox + dx, toy];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
374 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
375 Instruction::ShiftTextureY(dy) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
376 let [tox, toy] = sprite.texoffsets;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
377 sprite.texoffsets = [tox, toy + dy];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
378 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
379 Instruction::SetVisible(visible) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
380 sprite.visible = (visible & 1) != 0;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
381 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
382 Instruction::ScaleIn(sx, sy, duration) => {
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
383 sprite.scale_interpolator = Some(Interpolator2::new(sprite.rescale, sprite.frame, [sx, sy], sprite.frame + duration as u16, Formula::Linear));
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
384 }
641
a58103f2f264 Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 640
diff changeset
385 Instruction::Todo(_todo) => {
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
386 // TODO.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
387 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
388 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
389 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
390 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
391
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
392 #[cfg(test)]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
393 mod tests {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
394 use super::*;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
395 use std::io::{self, Read};
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
396 use std::fs::File;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
397
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
398 #[test]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
399 fn anm_runner() {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
400 let file = File::open("/home/linkmauve/games/pc/東方/TH06 ~ The Embodiment of Scarlet Devil/CM/player01.anm").unwrap();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
401 let mut file = io::BufReader::new(file);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
402 let mut buf = vec![];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
403 file.read_to_end(&mut buf).unwrap();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
404 let anm0 = Anm0::from_slice(&buf).unwrap();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
405 assert_eq!(anm0.size, (256, 256));
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
406 assert_eq!(anm0.format, 5);
640
37d151fe000b Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 639
diff changeset
407 let sprite = Rc::new(RefCell::new(Sprite::new(0., 0.)));
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
408 let mut anm_runner = AnmRunner::new(&anm0, 1, sprite.clone(), 0);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
409 for _ in 0..50 {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
410 anm_runner.run_frame();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
411 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
412 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
413 }