comparison examples/stagerunner.rs @ 741:3555845f8cf4

Make it so we can use more than a single anm0 in an EclRunner.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 07 Jan 2020 00:06:18 +0100
parents 817c453b7223
children 0a250ddfae79
comparison
equal deleted inserted replaced
740:8d29dac12219 741:3555845f8cf4
90 90
91 fn main() { 91 fn main() {
92 // Parse arguments. 92 // Parse arguments.
93 let args: Vec<_> = env::args().collect(); 93 let args: Vec<_> = env::args().collect();
94 if args.len() != 4 { 94 if args.len() != 4 {
95 eprintln!("Usage: {} <ECL file> <ANM file> <easy|normal|hard|lunatic>", args[0]); 95 eprintln!("Usage: {} <unarchived ST.DAT directory> <stage number> <easy|normal|hard|lunatic>", args[0]);
96 return; 96 return;
97 } 97 }
98 let ecl_filename = Path::new(&args[1]); 98 let directory = Path::new(&args[1]);
99 let anm_filename = Path::new(&args[2]); 99 let stage_number: u8 = args[2].parse().expect("stage");
100 let rank: Rank = args[3].parse().expect("rank"); 100 let rank: Rank = args[3].parse().expect("rank");
101 101
102 // Open the ECL file. 102 // Open the ECL file.
103 let buf = load_file_into_vec(ecl_filename); 103 let buf = load_file_into_vec(directory.join(format!("ecldata{}.ecl", stage_number)));
104 let (_, ecl) = Ecl::from_slice(&buf).unwrap(); 104 let (_, ecl) = Ecl::from_slice(&buf).unwrap();
105 assert_eq!(ecl.mains.len(), 1); 105 assert_eq!(ecl.mains.len(), 1);
106 let main = ecl.mains[0].clone(); 106 let main = ecl.mains[0].clone();
107 107
108 // Open the ANM file. 108 // Open the ANM file.
109 let buf = load_file_into_vec(anm_filename); 109 let anm_filename = directory.join(format!("stg{}enm.anm", stage_number));
110 let buf = load_file_into_vec(&anm_filename);
110 let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); 111 let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
111 let anm0 = anms.pop().unwrap(); 112 let anm0 = anms.pop().unwrap();
112 let anm0 = Rc::new(RefCell::new(anm0)); 113
114 // Open the second ANM file.
115 let anm2_filename = directory.join(format!("stg{}enm2.anm", stage_number));
116 let buf = load_file_into_vec(&anm2_filename);
117 let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
118 let anm0_bis = anms.pop().unwrap();
119
120 let anms = [anm0, anm0_bis];
113 121
114 // Get the time since January 1970 as a seed for the PRNG. 122 // Get the time since January 1970 as a seed for the PRNG.
115 let time = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap(); 123 let time = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap();
116 let prng = Rc::new(RefCell::new(Prng::new(time.subsec_micros() as u16))); 124 let prng = Rc::new(RefCell::new(Prng::new(time.subsec_micros() as u16)));
117 125
123 let vertices: [Vertex; 4] = unsafe { std::mem::uninitialized() }; 131 let vertices: [Vertex; 4] = unsafe { std::mem::uninitialized() };
124 132
125 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); 133 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap();
126 134
127 // Open the image atlas matching this ANM. 135 // Open the image atlas matching this ANM.
128 let tex = load_anm_image(&mut surface, &anm0.borrow(), anm_filename).expect("image loading"); 136 let mut textures = vec![];
137 for anm0 in anms.iter() {
138 let tex = load_anm_image(&mut surface, &anm0, &anm_filename).expect("image loading");
139 textures.push(tex);
140 }
141
142 let anms = Rc::new(RefCell::new(anms));
143 let tex = textures.pop().unwrap();
144 let tex = textures.pop().unwrap();
129 145
130 // set the uniform interface to our type so that we can read textures from the shader 146 // set the uniform interface to our type so that we can read textures from the shader
131 let program = 147 let program =
132 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); 148 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings();
133 149
169 MainInstruction::SpawnEnemyMirrored(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, true), 185 MainInstruction::SpawnEnemyMirrored(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, true),
170 MainInstruction::SpawnEnemyRandom(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, false), 186 MainInstruction::SpawnEnemyRandom(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, false),
171 MainInstruction::SpawnEnemyMirroredRandom(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, true), 187 MainInstruction::SpawnEnemyMirroredRandom(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, true),
172 _ => continue, 188 _ => continue,
173 }; 189 };
174 let enemy = Enemy::new(Position::new(x, y), life, bonus, score, mirror, Rc::downgrade(&anm0), Rc::downgrade(&game)); 190 let enemy = Enemy::new(Position::new(x, y), life, bonus, score, mirror, Rc::downgrade(&anms), Rc::downgrade(&game));
175 let runner = EclRunner::new(&ecl, enemy, sub); 191 let runner = EclRunner::new(&ecl, enemy, sub);
176 ecl_runners.push(runner); 192 ecl_runners.push(runner);
177 } 193 }
178 } 194 }
179 195