comparison examples/stdrenderer.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 ef2dbd676a91
children b6c351ca0a35
comparison
equal deleted inserted replaced
699:2a60f12bd5bd 700:ccb739c5b66c
105 105
106 #[uniform(name = "fog_color")] 106 #[uniform(name = "fog_color")]
107 fog_color: Uniform<[f32; 4]>, 107 fog_color: Uniform<[f32; 4]>,
108 } 108 }
109 109
110 fn load_file_into_vec(filename: &str) -> Vec<u8> {
111 let file = File::open(filename).unwrap();
112 let mut file = BufReader::new(file);
113 let mut buf = vec![];
114 file.read_to_end(&mut buf).unwrap();
115 buf
116 }
117
110 fn main() { 118 fn main() {
111 // Parse arguments. 119 // Parse arguments.
112 let args: Vec<_> = env::args().collect(); 120 let args: Vec<_> = env::args().collect();
113 if args.len() != 4 { 121 if args.len() != 4 {
114 eprintln!("Usage: {} <STD file> <ANM file> <PNG file>", args[0]); 122 eprintln!("Usage: {} <STD file> <ANM file> <PNG file>", args[0]);
117 let std_filename = &args[1]; 125 let std_filename = &args[1];
118 let anm_filename = &args[2]; 126 let anm_filename = &args[2];
119 let png_filename = &args[3]; 127 let png_filename = &args[3];
120 128
121 // Open the STD file. 129 // Open the STD file.
122 let file = File::open(std_filename).unwrap(); 130 let buf = load_file_into_vec(std_filename);
123 let mut file = BufReader::new(file);
124 let mut buf = vec![];
125 file.read_to_end(&mut buf).unwrap();
126 let (_, stage) = Stage::from_slice(&buf).unwrap(); 131 let (_, stage) = Stage::from_slice(&buf).unwrap();
127 132
128 // Open the ANM file. 133 // Open the ANM file.
129 let file = File::open(anm_filename).unwrap(); 134 let buf = load_file_into_vec(anm_filename);
130 let mut file = BufReader::new(file);
131 let mut buf = vec![];
132 file.read_to_end(&mut buf).unwrap();
133 let anm0 = Anm0::from_slice(&buf).unwrap(); 135 let anm0 = Anm0::from_slice(&buf).unwrap();
134 136
135 // TODO: seed this PRNG with a valid seed. 137 // TODO: seed this PRNG with a valid seed.
136 let prng = Rc::new(RefCell::new(Prng::new(0))); 138 let prng = Rc::new(RefCell::new(Prng::new(0)));
137 139