annotate src/th06/anm0_vm.rs @ 639:a8e0219162b6

Implement AnmRunner.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 04 Jul 2019 15:21:46 +0200
parents
children 37d151fe000b
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
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 #[derive(Debug, Clone)]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 struct Interpolator;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 /// Base visual element.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 #[derive(Debug, Clone, Default)]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 pub struct Sprite {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 blendfunc: u32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 frame: u16,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 width_override: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 height_override: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 angle: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 removed: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 changed: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 visible: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 force_rotation: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 automatic_orientation: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 allow_dest_offset: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 mirrored: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 corner_relative_placement: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 scale_interpolator: Option<Interpolator>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 fade_interpolator: Option<Interpolator>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 offset_interpolator: Option<Interpolator>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 rotation_interpolator: Option<Interpolator>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 color_interpolator: Option<Interpolator>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 anm: Option<Anm0>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 dest_offset: [f32; 3],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 texcoords: [f32; 4],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 texoffsets: [f32; 2],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 rescale: [f32; 2],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 scale_speed: [f32; 2],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 rotations_3d: [f32; 3],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 rotations_speed_3d: [f32; 3],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 color: [u8; 4],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 impl Sprite {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 /// Create a new sprite.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 pub fn new() -> Sprite {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 Default::default()
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 /// Update sprite values from the interpolators.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 pub fn update(&mut self) {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 self.changed = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 /// Interpreter for `Anm0` instructions to update a `Sprite`.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 pub struct AnmRunner {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 anm: Anm0,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 sprite: Rc<RefCell<Sprite>>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 running: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 sprite_index_offset: u32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 script: Script,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 instruction_pointer: usize,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 frame: u16,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 waiting: bool,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 variables: ([i32; 4], [f32; 4], [i32; 4]),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 timeout: Option<u16>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 impl AnmRunner {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 /// Create a new `AnmRunner`.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 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
81 let mut runner = AnmRunner {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 anm: anm.clone(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 sprite: sprite,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 running: true,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 waiting: false,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 script: anm.scripts[&script_id].clone(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 frame: 0,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 timeout: None,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 instruction_pointer: 0,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 variables: ([0, 0, 0, 0 ],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 [0., 0., 0., 0.],
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 [0, 0, 0, 0 ]),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 sprite_index_offset: sprite_index_offset,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 };
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 runner.run_frame();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 runner.sprite_index_offset = 0;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 runner
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 /// Trigger an interrupt.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 pub fn interrupt(&mut self, interrupt: i32) -> bool {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 let mut new_ip = self.script.interrupts.get(&interrupt);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 if new_ip.is_none() {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 new_ip = self.script.interrupts.get(&-1);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 let new_ip = if let Some(new_ip) = new_ip {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 *new_ip as usize
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 } else {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 return false;
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 self.instruction_pointer = new_ip;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 let Call { time: frame, instr: _ } = &self.script.instructions[self.instruction_pointer];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 self.frame = *frame;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 self.waiting = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 self.sprite.borrow_mut().visible = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 true
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 /// Advance the Anm of a single frame.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 pub fn run_frame(&mut self) -> bool {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 if !self.running {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 return false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 while self.running && !self.waiting {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 let Call { time: frame, instr } = self.script.instructions[self.instruction_pointer];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 let frame = frame.clone();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 if frame > self.frame {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 break;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 } else {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 self.instruction_pointer += 1;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 if frame == self.frame {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 self.run_instruction(instr);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 self.sprite.borrow_mut().changed = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 if !self.waiting {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144 self.frame += 1;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 } else if let Some(timeout) = self.timeout {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 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
147 self.waiting = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 self.sprite.borrow_mut().update();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 self.running
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 fn run_instruction(&mut self, instruction: Instruction) {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 let mut sprite = self.sprite.borrow_mut();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 match instruction {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 Instruction::Delete() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 sprite.removed = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 self.running = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 Instruction::LoadSprite(sprite_index) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 sprite.anm = Some(self.anm.clone());
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 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
166 sprite.texcoords = [texcoords.x, texcoords.y, texcoords.width, texcoords.height];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 Instruction::SetScale(sx, sy) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 sprite.rescale = [sx, sy];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 Instruction::SetAlpha(alpha) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 // TODO: check this modulo.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 sprite.color[3] = (alpha % 256) as u8;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 Instruction::SetColor(b, g, r) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 if sprite.fade_interpolator.is_none() {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 sprite.color[0] = r;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 sprite.color[1] = g;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 sprite.color[2] = b;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 Instruction::Jump(pointer) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 // TODO: is that really how it works?
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 self.instruction_pointer = pointer as usize;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 self.frame = self.script.instructions[pointer as usize].time;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 Instruction::ToggleMirrored() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 sprite.mirrored = !sprite.mirrored;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190 Instruction::SetRotations3d(rx, ry, rz) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 sprite.rotations_3d = [rx, ry, rz];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193 Instruction::SetRotationsSpeed3d(srx, sry, srz) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 sprite.rotations_speed_3d = [srx, sry, srz];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 Instruction::SetScaleSpeed(ssx, ssy) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197 sprite.scale_speed = [ssx, ssy];
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 Instruction::Fade(new_alpha, duration) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 // XXX: implement fade().
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201 //sprite.fade(duration, new_alpha)
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 Instruction::SetBlendmodeAlphablend() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204 sprite.blendfunc = 1;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206 Instruction::SetBlendmodeAdd() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 sprite.blendfunc = 0;
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 Instruction::KeepStill() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 self.running = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212 Instruction::LoadRandomSprite(min_index, amplitude) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 //self.load_sprite(min_index + randrange(amp))
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215 Instruction::Move(x, y, z) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216 sprite.dest_offset = [x, y, z];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 Instruction::MoveToLinear(x, y, z, duration) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219 // XXX: implement move_in().
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
220 //sprite.move_in(duration, x, y, z);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222 Instruction::MoveToDecel(x, y, z, duration) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223 // XXX: implement move_in().
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224 //sprite.move_in(duration, x, y, z, 2*x - x**2);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226 Instruction::MoveToAccel(x, y, z, duration) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 // XXX: implement move_in().
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 //sprite.move_in(duration, x, y, z, x**2);
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 Instruction::Wait() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 self.waiting = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233 // There is nothing to do here.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 Instruction::InterruptLabel(label) => (),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 Instruction::SetCornerRelativePlacement() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236 sprite.corner_relative_placement = true;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
237 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
238 Instruction::WaitEx() => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 sprite.visible = false;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240 self.waiting = 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 Instruction::SetAllowOffset(value) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 sprite.allow_dest_offset = value == 1
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 Instruction::SetAutomaticOrientation(value) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 sprite.automatic_orientation = value == 1
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 Instruction::ShiftTextureX(dx) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249 let [tox, toy] = sprite.texoffsets;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250 sprite.texoffsets = [tox + dx, toy];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
251 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252 Instruction::ShiftTextureY(dy) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 let [tox, toy] = sprite.texoffsets;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
254 sprite.texoffsets = [tox, toy + dy];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 Instruction::SetVisible(visible) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257 sprite.visible = (visible & 1) != 0;
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 Instruction::ScaleIn(sx, sy, duration) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 // TODO: implement scale_in().
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 //sprite.scale_in(duration, sx, sy)
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 Instruction::Todo(todo) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264 // TODO.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
267 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
268 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
269
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270 #[cfg(test)]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
271 mod tests {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
272 use super::*;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273 use std::io::{self, Read};
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274 use std::fs::File;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
276 #[test]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277 fn anm_runner() {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
278 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
279 let mut file = io::BufReader::new(file);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
280 let mut buf = vec![];
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
281 file.read_to_end(&mut buf).unwrap();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
282 let anm0 = Anm0::from_slice(&buf).unwrap();
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
283 assert_eq!(anm0.size, (256, 256));
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
284 assert_eq!(anm0.format, 5);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
285 let sprite = Rc::new(RefCell::new(Sprite::new()));
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
286 let mut anm_runner = AnmRunner::new(&anm0, 1, sprite.clone(), 0);
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
287 for _ in 0..50 {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
288 anm_runner.run_frame();
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 }
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
291 }