Mercurial > touhou
comparison src/th06/anm0_vm.rs @ 640:37d151fe000b
Implement better defaults for Sprite, and a beginning of
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 04 Jul 2019 21:47:53 +0200 |
parents | a8e0219162b6 |
children | a58103f2f264 |
comparison
equal
deleted
inserted
replaced
639:a8e0219162b6 | 640:37d151fe000b |
---|---|
49 color: [u8; 4], | 49 color: [u8; 4], |
50 } | 50 } |
51 | 51 |
52 impl Sprite { | 52 impl Sprite { |
53 /// Create a new sprite. | 53 /// Create a new sprite. |
54 pub fn new() -> Sprite { | 54 pub fn new(width_override: f32, height_override: f32) -> Sprite { |
55 Default::default() | 55 Sprite { |
56 width_override, | |
57 height_override, | |
58 changed: true, | |
59 visible: true, | |
60 rescale: [1., 1.], | |
61 color: [255, 255, 255, 255], | |
62 ..Default::default() | |
63 } | |
56 } | 64 } |
57 | 65 |
58 /// Update sprite values from the interpolators. | 66 /// Update sprite values from the interpolators. |
59 pub fn update(&mut self) { | 67 pub fn update(&mut self) { |
60 self.changed = false; | 68 self.frame += 1; |
69 | |
70 let [sax, say, saz] = self.rotations_speed_3d; | |
71 if sax != 0. || say != 0. || saz != 0. { | |
72 let [ax, ay, az] = self.rotations_3d; | |
73 self.rotations_3d = [ax + sax, ay + say, az + saz]; | |
74 self.changed = true; | |
75 } else if let Some(ref interpolator) = self.rotation_interpolator { | |
76 unimplemented!(); | |
77 self.changed = true; | |
78 } | |
79 | |
80 let [rsx, rsy] = self.scale_speed; | |
81 if rsx != 0. || rsy != 0. { | |
82 let [rx, ry] = self.rescale; | |
83 self.rescale = [rx + rsx, ry + rsy]; | |
84 self.changed = true; | |
85 } | |
86 | |
87 if let Some(ref interpolator) = self.fade_interpolator { | |
88 unimplemented!(); | |
89 self.changed = true; | |
90 } | |
91 | |
92 if let Some(ref interpolator) = self.scale_interpolator { | |
93 unimplemented!(); | |
94 self.changed = true; | |
95 } | |
96 | |
97 if let Some(ref interpolator) = self.offset_interpolator { | |
98 unimplemented!(); | |
99 self.changed = true; | |
100 } | |
101 | |
102 if let Some(ref interpolator) = self.color_interpolator { | |
103 unimplemented!(); | |
104 self.changed = true; | |
105 } | |
61 } | 106 } |
62 } | 107 } |
63 | 108 |
64 /// Interpreter for `Anm0` instructions to update a `Sprite`. | 109 /// Interpreter for `Anm0` instructions to update a `Sprite`. |
65 pub struct AnmRunner { | 110 pub struct AnmRunner { |
280 let mut buf = vec![]; | 325 let mut buf = vec![]; |
281 file.read_to_end(&mut buf).unwrap(); | 326 file.read_to_end(&mut buf).unwrap(); |
282 let anm0 = Anm0::from_slice(&buf).unwrap(); | 327 let anm0 = Anm0::from_slice(&buf).unwrap(); |
283 assert_eq!(anm0.size, (256, 256)); | 328 assert_eq!(anm0.size, (256, 256)); |
284 assert_eq!(anm0.format, 5); | 329 assert_eq!(anm0.format, 5); |
285 let sprite = Rc::new(RefCell::new(Sprite::new())); | 330 let sprite = Rc::new(RefCell::new(Sprite::new(0., 0.))); |
286 let mut anm_runner = AnmRunner::new(&anm0, 1, sprite.clone(), 0); | 331 let mut anm_runner = AnmRunner::new(&anm0, 1, sprite.clone(), 0); |
287 for _ in 0..50 { | 332 for _ in 0..50 { |
288 anm_runner.run_frame(); | 333 anm_runner.run_frame(); |
289 } | 334 } |
290 } | 335 } |