Mercurial > touhou
annotate interpreters/src/th06/anm0.rs @ 761:f506ad5c9b17
formats: Replace unwrap() with proper io::Error.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 06 Jan 2021 01:47:06 +0100 |
parents | 21b186be2590 |
children |
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 |
757
21b186be2590
Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
744
diff
changeset
|
3 use touhou_formats::th06::anm0::{ |
639
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 }; |
642
9e40bd5cc26d
Move interpolators in another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
641
diff
changeset
|
9 use crate::th06::interpolator::{Interpolator1, Interpolator2, Interpolator3, Formula}; |
757
21b186be2590
Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
744
diff
changeset
|
10 use touhou_utils::math::Mat4; |
21b186be2590
Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
744
diff
changeset
|
11 use touhou_utils::prng::Prng; |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 use std::cell::RefCell; |
646
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
13 use std::rc::{Rc, Weak}; |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
643
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
15 /// TODO |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
16 #[repr(C)] |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
17 #[derive(Debug)] |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
18 pub struct Vertex { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
19 /// XXX |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
20 pub pos: [i16; 3], |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
21 /// XXX |
744
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
22 pub layer: u16, |
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
23 /// XXX |
643
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
24 pub uv: [f32; 2], |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
25 /// XXX |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
26 pub color: [u8; 4], |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
27 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
28 |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 /// Base visual element. |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 #[derive(Debug, Clone, Default)] |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 pub struct Sprite { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 blendfunc: u32, |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
33 frame: u32, |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 width_override: f32, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 height_override: f32, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 angle: f32, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 removed: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 changed: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 visible: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 force_rotation: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 automatic_orientation: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 allow_dest_offset: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 mirrored: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 corner_relative_placement: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 |
641
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
48 scale_interpolator: Option<Interpolator2<f32>>, |
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
49 fade_interpolator: Option<Interpolator1<f32>>, // XXX: should be u8! |
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
50 offset_interpolator: Option<Interpolator3<f32>>, |
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
51 rotation_interpolator: Option<Interpolator3<f32>>, |
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
52 color_interpolator: Option<Interpolator3<f32>>, // XXX: should be u8! |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 anm: Option<Anm0>, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 dest_offset: [f32; 3], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 texcoords: [f32; 4], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 texoffsets: [f32; 2], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 rescale: [f32; 2], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 scale_speed: [f32; 2], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 rotations_3d: [f32; 3], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 rotations_speed_3d: [f32; 3], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 color: [u8; 4], |
744
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
64 layer: u16, |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 impl Sprite { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 /// Create a new sprite. |
656
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
69 pub fn new() -> Sprite { |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
70 Sprite { |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
71 changed: true, |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
72 visible: true, |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
73 rescale: [1., 1.], |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
74 color: [255, 255, 255, 255], |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
75 ..Default::default() |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
76 } |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
77 } |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
78 |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
79 /// Create a new sprite overriding its size. |
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
80 pub fn with_size(width_override: f32, height_override: f32) -> Sprite { |
640
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
81 Sprite { |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
82 width_override, |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
83 height_override, |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
84 changed: true, |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
85 visible: true, |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
86 rescale: [1., 1.], |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
87 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
|
88 ..Default::default() |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
89 } |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 |
643
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
92 /// TODO |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
93 pub fn fill_vertices(&self, vertices: &mut [Vertex; 4], x: f32, y: f32, z: f32) { |
643
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
94 let mut mat = Mat4::new([[-0.5, 0.5, 0.5, -0.5], |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
95 [-0.5, -0.5, 0.5, 0.5], |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
96 [0., 0., 0., 0.], |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
97 [1., 1., 1., 1.]]); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
98 |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
99 let [tx, ty, tw, th] = self.texcoords; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
100 let [sx, sy] = self.rescale; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
101 let width = if self.width_override > 0. { self.width_override } else { tw * sx }; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
102 let height = if self.height_override > 0. { self.height_override } else { th * sy }; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
103 |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
104 mat.scale2d(width, height); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
105 if self.mirrored { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
106 mat.flip(); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
107 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
108 |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
109 let [rx, ry, mut rz] = self.rotations_3d; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
110 if self.automatic_orientation { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
111 rz += std::f32::consts::PI / 2. - self.angle; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
112 } else if self.force_rotation { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
113 rz += self.angle; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
114 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
115 |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
116 if rx != 0. { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
117 mat.rotate_x(-rx); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
118 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
119 if ry != 0. { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
120 mat.rotate_y(ry); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
121 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
122 if rz != 0. { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
123 mat.rotate_z(-rz); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
124 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
125 |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
126 if self.allow_dest_offset { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
127 mat.translate(self.dest_offset); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
128 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
129 if self.corner_relative_placement { |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
130 mat.translate_2d(width / 2., height / 2.); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
131 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
132 |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
133 mat.translate([x, y, z]); |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
134 |
643
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
135 let mat = mat.borrow_inner(); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
136 vertices[0].pos[0] = mat[0][0] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
137 vertices[0].pos[1] = mat[1][0] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
138 vertices[0].pos[2] = mat[2][0] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
139 vertices[1].pos[0] = mat[0][1] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
140 vertices[1].pos[1] = mat[1][1] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
141 vertices[1].pos[2] = mat[2][1] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
142 vertices[2].pos[0] = mat[0][2] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
143 vertices[2].pos[1] = mat[1][2] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
144 vertices[2].pos[2] = mat[2][2] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
145 vertices[3].pos[0] = mat[0][3] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
146 vertices[3].pos[1] = mat[1][3] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
147 vertices[3].pos[2] = mat[2][3] as i16; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
148 |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
149 // XXX: don’t clone here. |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
150 let (x_1, y_1) = self.anm.clone().unwrap().inv_size(); |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
151 let [tox, toy] = self.texoffsets; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
152 let left = tx * x_1 + tox; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
153 let right = (tx + tw) * x_1 + tox; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
154 let bottom = ty * y_1 + toy; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
155 let top = (ty + th) * y_1 + toy; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
156 |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
157 vertices[0].uv[0] = left; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
158 vertices[0].uv[1] = bottom; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
159 vertices[1].uv[0] = right; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
160 vertices[1].uv[1] = bottom; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
161 vertices[2].uv[0] = right; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
162 vertices[2].uv[1] = top; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
163 vertices[3].uv[0] = left; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
164 vertices[3].uv[1] = top; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
165 |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
166 vertices[0].color = self.color; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
167 vertices[1].color = self.color; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
168 vertices[2].color = self.color; |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
169 vertices[3].color = self.color; |
744
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
170 |
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
171 vertices[0].layer = self.layer; |
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
172 vertices[1].layer = self.layer; |
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
173 vertices[2].layer = self.layer; |
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
174 vertices[3].layer = self.layer; |
643
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
175 } |
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
176 |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 /// Update sprite values from the interpolators. |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 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
|
179 self.frame += 1; |
643
01849ffd0180
Add an anmrenderer binary.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
642
diff
changeset
|
180 self.corner_relative_placement = true; |
640
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
181 |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 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
|
186 self.changed = true; |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
187 } 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
|
188 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
|
189 self.changed = true; |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
190 } |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
191 |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 self.changed = true; |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
197 } |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
198 |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
199 if let Some(ref interpolator) = self.fade_interpolator { |
641
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
200 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
|
201 self.changed = true; |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
202 } |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
203 |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
204 if let Some(ref interpolator) = self.scale_interpolator { |
641
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
205 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
|
206 self.changed = true; |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
207 } |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
208 |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
209 if let Some(ref interpolator) = self.offset_interpolator { |
641
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
210 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
|
211 self.changed = true; |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
212 } |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
213 |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
214 if let Some(ref interpolator) = self.color_interpolator { |
641
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
215 let color = interpolator.values(self.frame); |
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
216 // TODO: this can probably be made to look nicer. |
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
217 self.color[0] = color[0] as u8; |
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
218 self.color[1] = color[1] as u8; |
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
219 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
|
220 self.changed = true; |
37d151fe000b
Implement better defaults for Sprite, and a beginning of
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
639
diff
changeset
|
221 } |
639
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 |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
225 struct Anms { |
742
0a250ddfae79
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
741
diff
changeset
|
226 inner: Rc<RefCell<[Anm0]>>, |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
227 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
228 |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
229 impl Anms { |
742
0a250ddfae79
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
741
diff
changeset
|
230 fn new(anms: Rc<RefCell<[Anm0]>>) -> Anms { |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
231 Anms { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
232 inner: anms, |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
233 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
234 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
235 |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
236 fn load_sprite(&self, sprite: &mut Sprite, id: u8) { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
237 let anms = self.inner.borrow(); |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
238 let mut anm = None; |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
239 let mut texcoords = None; |
744
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
240 let mut layer = 0; |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
241 'anm: for anm0 in anms.iter() { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
242 for sp in anm0.sprites.iter() { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
243 if sp.index == id as u32 { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
244 texcoords = Some(sp); |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
245 anm = Some(anm0.clone()); |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
246 break 'anm; |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
247 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
248 } |
744
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
249 layer += 1; |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
250 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
251 sprite.anm = anm; |
744
3687205fe620
anm0_vm: Use the unused u16 to store the anm layer to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
252 sprite.layer = layer; |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
253 if let Some(texcoords) = texcoords { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
254 sprite.texcoords = [texcoords.x, texcoords.y, texcoords.width, texcoords.height]; |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
255 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
256 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
257 |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
258 fn get_script(&self, id: u8) -> Script { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
259 let anms = self.inner.borrow(); |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
260 for anm0 in anms.iter() { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
261 if anm0.scripts.contains_key(&id) { |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
262 return anm0.scripts[&id].clone(); |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
263 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
264 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
265 unreachable!(); |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
266 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
267 } |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
268 |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
269 /// Interpreter for `Anm0` instructions to update a `Sprite`. |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
270 pub struct AnmRunner { |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
271 anms: Anms, |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
272 sprite: Rc<RefCell<Sprite>>, |
646
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
273 prng: Weak<RefCell<Prng>>, |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
274 running: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
275 sprite_index_offset: u32, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
276 script: Script, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
277 instruction_pointer: usize, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
278 frame: u16, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
279 waiting: bool, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
280 variables: ([i32; 4], [f32; 4], [i32; 4]), |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
281 timeout: Option<u32>, |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
282 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
283 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
284 impl AnmRunner { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
285 /// Create a new `AnmRunner`. |
742
0a250ddfae79
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
741
diff
changeset
|
286 pub fn new(anms: Rc<RefCell<[Anm0]>>, script_id: u8, sprite: Rc<RefCell<Sprite>>, prng: Weak<RefCell<Prng>>, sprite_index_offset: u32) -> AnmRunner { |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
287 let anms = Anms::new(anms); |
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
288 let script = anms.get_script(script_id); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
289 let mut runner = AnmRunner { |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
290 anms, |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
291 sprite: sprite, |
646
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
292 prng, |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
293 running: true, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
294 waiting: false, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
295 |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
296 script, |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
297 frame: 0, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
298 timeout: None, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
299 instruction_pointer: 0, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
300 variables: ([0, 0, 0, 0 ], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
301 [0., 0., 0., 0.], |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
302 [0, 0, 0, 0 ]), |
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 sprite_index_offset: sprite_index_offset, |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
305 }; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
306 runner.run_frame(); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
307 runner.sprite_index_offset = 0; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
308 runner |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
309 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
310 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
656
diff
changeset
|
311 /// Get a Rc from the inner Sprite. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
656
diff
changeset
|
312 pub fn get_sprite(&self) -> Rc<RefCell<Sprite>> { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
656
diff
changeset
|
313 self.sprite.clone() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
656
diff
changeset
|
314 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
656
diff
changeset
|
315 |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
316 /// Trigger an interrupt. |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
317 pub fn interrupt(&mut self, interrupt: i32) -> bool { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
318 let mut new_ip = self.script.interrupts.get(&interrupt); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
319 if new_ip.is_none() { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
320 new_ip = self.script.interrupts.get(&-1); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
321 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
322 let new_ip = if let Some(new_ip) = new_ip { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
323 *new_ip as usize |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
324 } else { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
325 return false; |
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 self.instruction_pointer = new_ip; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
328 let Call { time: frame, instr: _ } = &self.script.instructions[self.instruction_pointer]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
329 self.frame = *frame; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
330 self.waiting = false; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
331 self.sprite.borrow_mut().visible = true; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
332 true |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
333 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
334 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
335 /// Advance the Anm of a single frame. |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
336 pub fn run_frame(&mut self) -> bool { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
337 if !self.running { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
338 return false; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
339 } |
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 while self.running && !self.waiting { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
342 let Call { time: frame, instr } = self.script.instructions[self.instruction_pointer]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
343 let frame = frame.clone(); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
344 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
345 if frame > self.frame { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
346 break; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
347 } else { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
348 self.instruction_pointer += 1; |
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 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
351 if frame == self.frame { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
352 self.run_instruction(instr); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
353 self.sprite.borrow_mut().changed = true; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
354 } |
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 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
357 if !self.waiting { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
358 self.frame += 1; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
359 } else if let Some(timeout) = self.timeout { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
360 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
|
361 self.waiting = false; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
362 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
363 } |
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 self.sprite.borrow_mut().update(); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
366 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
367 self.running |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
368 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
369 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
370 fn run_instruction(&mut self, instruction: Instruction) { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
371 let mut sprite = self.sprite.borrow_mut(); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
372 match instruction { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
373 Instruction::Delete() => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
374 sprite.removed = true; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
375 self.running = false; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
376 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
377 Instruction::LoadSprite(sprite_index) => { |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
378 self.anms.load_sprite(&mut sprite, (sprite_index + self.sprite_index_offset) as u8); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
379 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
380 Instruction::SetScale(sx, sy) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
381 sprite.rescale = [sx, sy]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
382 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
383 Instruction::SetAlpha(alpha) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
384 // TODO: check this modulo. |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
385 sprite.color[3] = (alpha % 256) as u8; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
386 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
387 Instruction::SetColor(b, g, r) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
388 if sprite.fade_interpolator.is_none() { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
389 sprite.color[0] = r; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
390 sprite.color[1] = g; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
391 sprite.color[2] = b; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
392 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
393 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
394 Instruction::Jump(pointer) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
395 // TODO: is that really how it works? |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
396 self.instruction_pointer = pointer as usize; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
397 self.frame = self.script.instructions[pointer as usize].time; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
398 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
399 Instruction::ToggleMirrored() => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
400 sprite.mirrored = !sprite.mirrored; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
401 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
402 Instruction::SetRotations3d(rx, ry, rz) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
403 sprite.rotations_3d = [rx, ry, rz]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
404 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
405 Instruction::SetRotationsSpeed3d(srx, sry, srz) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
406 sprite.rotations_speed_3d = [srx, sry, srz]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
407 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
408 Instruction::SetScaleSpeed(ssx, ssy) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
409 sprite.scale_speed = [ssx, ssy]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
410 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
411 Instruction::Fade(new_alpha, duration) => { |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
412 sprite.fade_interpolator = Some(Interpolator1::new([sprite.color[3] as f32], sprite.frame, [new_alpha as f32], sprite.frame + duration, Formula::Linear)); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
413 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
414 Instruction::SetBlendmodeAlphablend() => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
415 sprite.blendfunc = 1; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
416 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
417 Instruction::SetBlendmodeAdd() => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
418 sprite.blendfunc = 0; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
419 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
420 Instruction::KeepStill() => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
421 self.running = false; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
422 } |
646
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
423 Instruction::LoadRandomSprite(min_index, mut amplitude) => { |
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
424 if amplitude > 0 { |
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
425 let prng = self.prng.upgrade().unwrap(); |
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
426 let rand = prng.borrow_mut().get_u16(); |
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
427 amplitude = (rand as u32) % amplitude; |
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
428 } |
7d92730bf543
Add a PRNG and use it for anm0 instruction 16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
645
diff
changeset
|
429 let sprite_index = min_index + amplitude; |
741
3555845f8cf4
Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
430 self.anms.load_sprite(&mut sprite, (sprite_index + self.sprite_index_offset) as u8); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
431 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
432 Instruction::Move(x, y, z) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
433 sprite.dest_offset = [x, y, z]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
434 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
435 Instruction::MoveToLinear(x, y, z, duration) => { |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
436 sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration, Formula::Linear)); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
437 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
438 Instruction::MoveToDecel(x, y, z, duration) => { |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
439 sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration, Formula::InvertPower2)); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
440 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
441 Instruction::MoveToAccel(x, y, z, duration) => { |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
442 sprite.offset_interpolator = Some(Interpolator3::new(sprite.dest_offset, sprite.frame, [x, y, z], sprite.frame + duration, Formula::Power2)); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
443 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
444 Instruction::Wait() => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
445 self.waiting = true; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
446 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
447 // There is nothing to do here. |
641
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
448 Instruction::InterruptLabel(_label) => (), |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
449 Instruction::SetCornerRelativePlacement() => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
450 sprite.corner_relative_placement = true; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
451 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
452 Instruction::WaitEx() => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
453 sprite.visible = false; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
454 self.waiting = true; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
455 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
456 Instruction::SetAllowOffset(value) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
457 sprite.allow_dest_offset = value == 1 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
458 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
459 Instruction::SetAutomaticOrientation(value) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
460 sprite.automatic_orientation = value == 1 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
461 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
462 Instruction::ShiftTextureX(dx) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
463 let [tox, toy] = sprite.texoffsets; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
464 sprite.texoffsets = [tox + dx, toy]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
465 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
466 Instruction::ShiftTextureY(dy) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
467 let [tox, toy] = sprite.texoffsets; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
468 sprite.texoffsets = [tox, toy + dy]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
469 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
470 Instruction::SetVisible(visible) => { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
471 sprite.visible = (visible & 1) != 0; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
472 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
473 Instruction::ScaleIn(sx, sy, duration) => { |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
474 sprite.scale_interpolator = Some(Interpolator2::new(sprite.rescale, sprite.frame, [sx, sy], sprite.frame + duration, Formula::Linear)); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
475 } |
641
a58103f2f264
Implement and use interpolators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
640
diff
changeset
|
476 Instruction::Todo(_todo) => { |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
477 // TODO. |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
478 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
479 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
480 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
481 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
482 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
483 #[cfg(test)] |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
484 mod tests { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
485 use super::*; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
486 use std::io::{self, Read}; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
487 use std::fs::File; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
488 |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
489 #[test] |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
490 fn anm_runner() { |
645
7bde50132735
Don’t hardcode my home directory in tests.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
643
diff
changeset
|
491 let file = File::open("EoSD/CM/player01.anm").unwrap(); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
492 let mut file = io::BufReader::new(file); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
493 let mut buf = vec![]; |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
494 file.read_to_end(&mut buf).unwrap(); |
701
b6c351ca0a35
anm0: return the nom IResult and the list of Anm0s.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
495 let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); |
b6c351ca0a35
anm0: return the nom IResult and the list of Anm0s.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
496 let anm0 = anms.pop().unwrap(); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
497 assert_eq!(anm0.size, (256, 256)); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
498 assert_eq!(anm0.format, 5); |
656
988e5130fb00
Add a simpler Sprite::new() which doesn’t override width/height.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
648
diff
changeset
|
499 let sprite = Rc::new(RefCell::new(Sprite::new())); |
648
3331eb7389b3
Fix AnmRunner instance in test (requires Prng).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
646
diff
changeset
|
500 let prng = Rc::new(RefCell::new(Prng::new(0))); |
3331eb7389b3
Fix AnmRunner instance in test (requires Prng).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
646
diff
changeset
|
501 let mut anm_runner = AnmRunner::new(&anm0, 1, sprite.clone(), Rc::downgrade(&prng), 0); |
639
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
502 for _ in 0..50 { |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
503 anm_runner.run_frame(); |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
504 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
505 } |
a8e0219162b6
Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
506 } |