Mercurial > touhou
diff 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 |
line wrap: on
line diff
--- a/examples/stagerunner.rs +++ b/examples/stagerunner.rs @@ -92,24 +92,32 @@ fn main() { // Parse arguments. let args: Vec<_> = env::args().collect(); if args.len() != 4 { - eprintln!("Usage: {} <ECL file> <ANM file> <easy|normal|hard|lunatic>", args[0]); + eprintln!("Usage: {} <unarchived ST.DAT directory> <stage number> <easy|normal|hard|lunatic>", args[0]); return; } - let ecl_filename = Path::new(&args[1]); - let anm_filename = Path::new(&args[2]); + let directory = Path::new(&args[1]); + let stage_number: u8 = args[2].parse().expect("stage"); let rank: Rank = args[3].parse().expect("rank"); // Open the ECL file. - let buf = load_file_into_vec(ecl_filename); + let buf = load_file_into_vec(directory.join(format!("ecldata{}.ecl", stage_number))); let (_, ecl) = Ecl::from_slice(&buf).unwrap(); assert_eq!(ecl.mains.len(), 1); let main = ecl.mains[0].clone(); // Open the ANM file. - let buf = load_file_into_vec(anm_filename); + let anm_filename = directory.join(format!("stg{}enm.anm", stage_number)); + let buf = load_file_into_vec(&anm_filename); let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); let anm0 = anms.pop().unwrap(); - let anm0 = Rc::new(RefCell::new(anm0)); + + // Open the second ANM file. + let anm2_filename = directory.join(format!("stg{}enm2.anm", stage_number)); + let buf = load_file_into_vec(&anm2_filename); + let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); + let anm0_bis = anms.pop().unwrap(); + + let anms = [anm0, anm0_bis]; // Get the time since January 1970 as a seed for the PRNG. let time = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap(); @@ -125,7 +133,15 @@ fn main() { let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); // Open the image atlas matching this ANM. - let tex = load_anm_image(&mut surface, &anm0.borrow(), anm_filename).expect("image loading"); + let mut textures = vec![]; + for anm0 in anms.iter() { + let tex = load_anm_image(&mut surface, &anm0, &anm_filename).expect("image loading"); + textures.push(tex); + } + + let anms = Rc::new(RefCell::new(anms)); + let tex = textures.pop().unwrap(); + let tex = textures.pop().unwrap(); // set the uniform interface to our type so that we can read textures from the shader let program = @@ -171,7 +187,7 @@ fn main() { MainInstruction::SpawnEnemyMirroredRandom(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, true), _ => continue, }; - let enemy = Enemy::new(Position::new(x, y), life, bonus, score, mirror, Rc::downgrade(&anm0), Rc::downgrade(&game)); + let enemy = Enemy::new(Position::new(x, y), life, bonus, score, mirror, Rc::downgrade(&anms), Rc::downgrade(&game)); let runner = EclRunner::new(&ecl, enemy, sub); ecl_runners.push(runner); }