Mercurial > touhou
comparison examples/eclrenderer.rs @ 700:ccb739c5b66c
examples: factorise file reading into a buffer.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 23 Aug 2019 13:05:48 +0200 |
parents | 7ae576a418ff |
children | b6c351ca0a35 |
comparison
equal
deleted
inserted
replaced
699:2a60f12bd5bd | 700:ccb739c5b66c |
---|---|
86 | 86 |
87 #[uniform(name = "mvp")] | 87 #[uniform(name = "mvp")] |
88 mvp: Uniform<[[f32; 4]; 4]>, | 88 mvp: Uniform<[[f32; 4]; 4]>, |
89 } | 89 } |
90 | 90 |
91 fn load_file_into_vec(filename: &str) -> Vec<u8> { | |
92 let file = File::open(filename).unwrap(); | |
93 let mut file = BufReader::new(file); | |
94 let mut buf = vec![]; | |
95 file.read_to_end(&mut buf).unwrap(); | |
96 buf | |
97 } | |
98 | |
91 fn main() { | 99 fn main() { |
92 // Parse arguments. | 100 // Parse arguments. |
93 let args: Vec<_> = env::args().collect(); | 101 let args: Vec<_> = env::args().collect(); |
94 if args.len() != 6 { | 102 if args.len() != 6 { |
95 eprintln!("Usage: {} <ECL file> <ANM file> <PNG file> <easy|normal|hard|lunatic> <sub number>", args[0]); | 103 eprintln!("Usage: {} <ECL file> <ANM file> <PNG file> <easy|normal|hard|lunatic> <sub number>", args[0]); |
100 let png_filename = &args[3]; | 108 let png_filename = &args[3]; |
101 let rank: Rank = args[4].parse().expect("rank"); | 109 let rank: Rank = args[4].parse().expect("rank"); |
102 let sub: u16 = args[5].parse().expect("number"); | 110 let sub: u16 = args[5].parse().expect("number"); |
103 | 111 |
104 // Open the ECL file. | 112 // Open the ECL file. |
105 let file = File::open(ecl_filename).unwrap(); | 113 let buf = load_file_into_vec(ecl_filename); |
106 let mut file = BufReader::new(file); | |
107 let mut buf = vec![]; | |
108 file.read_to_end(&mut buf).unwrap(); | |
109 let (_, ecl) = Ecl::from_slice(&buf).unwrap(); | 114 let (_, ecl) = Ecl::from_slice(&buf).unwrap(); |
110 | 115 |
111 // Open the ANM file. | 116 // Open the ANM file. |
112 let file = File::open(anm_filename).unwrap(); | 117 let buf = load_file_into_vec(anm_filename); |
113 let mut file = BufReader::new(file); | |
114 let mut buf = vec![]; | |
115 file.read_to_end(&mut buf).unwrap(); | |
116 let anm0 = Anm0::from_slice(&buf).unwrap(); | 118 let anm0 = Anm0::from_slice(&buf).unwrap(); |
117 let anm0 = Rc::new(RefCell::new(anm0)); | 119 let anm0 = Rc::new(RefCell::new(anm0)); |
118 | 120 |
119 if ecl.subs.len() < sub as usize { | 121 if ecl.subs.len() < sub as usize { |
120 eprintln!("This ecl doesn’t contain a sub named {}.", sub); | 122 eprintln!("This ecl doesn’t contain a sub named {}.", sub); |