Mercurial > touhou
annotate src/th06/std.rs @ 679:6020e33d4fc4
Implement a .std renderer, and its associated VM.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 16 Aug 2019 13:40:38 +0200 |
parents | 266911c0ccfd |
children | ef2dbd676a91 |
rev | line source |
---|---|
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 //! STD background format support. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 use nom::{ |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 IResult, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 bytes::complete::{tag, take_while_m_n}, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 number::complete::{le_u8, le_u16, le_u32, le_i32, le_f32}, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 sequence::tuple, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 combinator::map, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 use encoding_rs::SHIFT_JIS; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 use std::collections::HashMap; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 /// A float position in the 3D space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 pub struct Position { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 /// X component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 pub x: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 /// Y component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 pub y: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 /// Z component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 pub z: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 /// A 3D box around something. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 struct Box3D { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 width: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 height: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 depth: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 /// A 2D box around something. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 pub struct Box2D { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 width: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 height: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 /// A quad in the 3D space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 pub struct Quad { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 /// The anm script to run for this quad. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 pub anm_script: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 /// The position of this quad in the 3D space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 pub pos: Position, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 /// The size of this quad. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 pub size_override: Box2D, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 /// A model formed of multiple quads in space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 pub struct Model { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 /// TODO: find what that is. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 pub unknown: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 /// The bounding box around this model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 pub bounding_box: [f32; 6], |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 /// The quads composing this model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 pub quads: Vec<Quad>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 /// An instance of a model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 pub struct Instance { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 /// The instance identifier. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 pub id: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 /// Where to position the instance of this model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 pub pos: Position, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 /// A single instruction, part of a `Script`. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 pub struct Call { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 /// Time at which this instruction will be called. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 pub time: u32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 /// The instruction to call. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 pub instr: Instruction, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 /// Parse a SHIFT_JIS byte string of length 128 into a String. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 let data = i.splitn(2, |c| *c == b'\0').nth(0).unwrap(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 let (string, encoding, replaced) = SHIFT_JIS.decode(data); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 Ok((&i[128..], string.into_owned())) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 /// Main struct of the STD stage format. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 pub struct Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 /// The name of the stage. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 pub name: String, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 /// A list of (name, path) of background music. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 // TODO: there are maximum four of them, and in practice never more than 2. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 pub musics: Vec<Option<(String, String)>>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 /// List of models. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 pub models: Vec<Model>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 /// List of instances. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 pub instances: Vec<Instance>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 /// List of instructions in the script. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 pub script: Vec<Call>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 impl Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 /// Parse a slice of bytes into an `Stage` struct. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 pub fn from_slice(data: &[u8]) -> IResult<&[u8], Stage> { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 parse_stage(data) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 macro_rules! declare_stage_instructions { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 /// Available instructions in an `Stage`. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 #[allow(missing_docs)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 #[derive(Debug, Clone, Copy)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 pub enum Instruction { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 $name($($arg_type),*) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 ),* |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 fn parse_instruction_args(input: &[u8], opcode: u16) -> IResult<&[u8], Instruction> { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 let mut i = &input[..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
134 let instr = match opcode { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 $opcode => { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 let (i2, $arg) = concat_idents!(le_, $arg_type)(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 i = i2; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 )* |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 Instruction::$name($($arg),*) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
143 )* |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 _ => unreachable!() |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 Ok((i, instr)) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
151 declare_stage_instructions!{ |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 0 => fn SetViewpos(x: f32, y: f32, z: f32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 1 => fn SetFog(r: u8, g: u8, b: u8, a: u8, near: f32, far: f32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 2 => fn SetViewpos2(x: f32, y: f32, z: f32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 3 => fn StartInterpolatingViewpos2(frame: i32, _unused: i32, _unused: i32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
156 4 => fn StartInterpolatingFog(frame: i32, _unused: i32, _unused: i32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 5 => fn Unknown(_unused: i32, _unused: i32, _unused: i32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 fn parse_stage(input: &[u8]) -> IResult<&[u8], Stage> { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
161 let start_offset = 0; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 let i = &input[start_offset..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 let (i, (num_models, num_faces, object_instances_offset, script_offset, _)) = tuple((le_u16, le_u16, le_u32, le_u32, tag(b"\0\0\0\0")))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 let object_instances_offset = object_instances_offset as usize; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 let script_offset = script_offset as usize; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
167 let (i, name) = le_String(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 let (i, music_names) = map(tuple((le_String, le_String, le_String, le_String)), |(a, b, c, d)| [a, b, c, d])(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 let (mut i, music_paths) = map(tuple((le_String, le_String, le_String, le_String)), |(a, b, c, d)| [a, b, c, d])(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
170 let musics = music_names.iter().zip(&music_paths).map(|(name, path)| if name == " " { None } else { Some((name.clone(), path.clone())) }).collect(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
171 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 let mut offsets = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 for _ in 0..num_models { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 let (i2, offset) = le_u32(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 offsets.push(offset as usize); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 i = i2; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
179 // Read model definitions. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 let mut models = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 for offset in offsets { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
182 let i = &input[offset..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
183 let (mut i, (id, unknown, x, y, z, width, height, depth)) = tuple((le_u16, le_u16, le_f32, le_f32, le_f32, le_f32, le_f32, le_f32))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
184 let bounding_box = [x, y, z, width, height, depth]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
185 let mut quads = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
186 loop { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
187 let (i2, (unk1, size)) = tuple((le_u16, le_u16))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 if unk1 == 0xffff { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 break; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
191 assert_eq!(size, 0x1c); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 let (i2, (anm_script, _, x, y, z, width, height)) = tuple((le_u16, tag(b"\0\0"), le_f32, le_f32, le_f32, le_f32, le_f32))(i2)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
193 let quad = Quad { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
194 anm_script, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
195 pos: Position { x, y, z }, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
196 size_override: Box2D { width, height }, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
198 quads.push(quad); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
199 i = i2; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
200 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
201 let model = Model { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
202 unknown, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
203 bounding_box, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 quads, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
205 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 models.push(model); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
207 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
209 // Read object usage. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
210 let mut instances = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
211 let mut i = &input[object_instances_offset..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
212 loop { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
213 let (i2, (id, unknown, x, y, z)) = tuple((le_u16, le_u16, le_f32, le_f32, le_f32))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 if id == 0xffff && unknown == 0xffff { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 break; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
216 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
217 assert_eq!(unknown, 0x100); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
218 let instance = Instance { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
219 id, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 pos: Position { x, y, z }, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
221 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 instances.push(instance); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
223 i = i2; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 // Read the script. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 let mut script = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 let mut i = &input[script_offset..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 loop { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 let (i2, (time, opcode, size)) = tuple((le_u32, le_u16, le_u16))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 if time == 0xffffffff && opcode == 0xffff && size == 0xffff { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 break; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 assert_eq!(size, 12); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 let data = &i2[..12]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 let (data, instr) = parse_instruction_args(data, opcode)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
237 assert_eq!(data.len(), 0); |
679
6020e33d4fc4
Implement a .std renderer, and its associated VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
671
diff
changeset
|
238 println!("{} {:?}", time, instr); |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
239 script.push(Call { time, instr }); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 i = &i2[12..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
241 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
242 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 let stage = Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 name, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 musics, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 models, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 instances, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 script, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
250 Ok((b"", stage)) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
251 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
252 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
253 #[cfg(test)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
254 mod tests { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
255 use super::*; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 use std::io::{self, Read}; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
257 use std::fs::File; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
258 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
259 #[test] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
260 fn std() { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
261 let file = File::open("EoSD/ST/stage1.std").unwrap(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
262 let mut file = io::BufReader::new(file); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
263 let mut buf = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
264 file.read_to_end(&mut buf).unwrap(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
265 let (_, stage) = Stage::from_slice(&buf).unwrap(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
266 assert_eq!(stage.name, "夢幻夜行絵巻 ~ Mystic Flier"); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
267 assert_eq!(stage.musics.len(), 4); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
268 assert_eq!(stage.models.len(), 13); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
269 assert_eq!(stage.instances.len(), 90); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
270 assert_eq!(stage.script.len(), 21); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
271 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
272 } |