annotate runners/src/bin/stagerunner.rs @ 763:468dab1dd683

Python: Fix video argument (thanks Doomfan!)
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 09 Feb 2021 22:50:18 +0100
parents 21b186be2590
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 use luminance::blending::{Equation, Factor};
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 use luminance::context::GraphicsContext;
742
0a250ddfae79 examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 741
diff changeset
3 use luminance::pipeline::{BoundTexture, PipelineState};
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 use luminance::pixel::NormUnsigned;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 use luminance::render_state::RenderState;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 use luminance::shader::program::{Program, Uniform};
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 use luminance::tess::{Mode, TessBuilder};
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
8 use luminance::texture::Dim2Array;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 use luminance_derive::{Semantics, Vertex, UniformInterface};
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 use luminance_glfw::{Action, Key, WindowEvent, GlfwSurface, Surface, WindowDim, WindowOpt};
757
21b186be2590 Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 753
diff changeset
11 use touhou_formats::th06::anm0::Anm0;
21b186be2590 Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 753
diff changeset
12 use touhou_formats::th06::ecl::{Ecl, Rank, MainInstruction};
21b186be2590 Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 753
diff changeset
13 use touhou_interpreters::th06::anm0::Vertex as FakeVertex;
21b186be2590 Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 753
diff changeset
14 use touhou_interpreters::th06::ecl::EclRunner;
21b186be2590 Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 753
diff changeset
15 use touhou_interpreters::th06::enemy::{Enemy, Game, Position};
21b186be2590 Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 753
diff changeset
16 use touhou_utils::math::{perspective, setup_camera};
21b186be2590 Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 753
diff changeset
17 use touhou_utils::prng::Prng;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 use std::cell::RefCell;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 use std::rc::Rc;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 use std::env;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 use std::path::Path;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
757
21b186be2590 Split the Rust version into multiple crates.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 753
diff changeset
23 use touhou_runners::common::{load_file_into_vec, load_multiple_anm_images, LoadedTexture};
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 const VS: &str = r#"
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 in ivec3 in_position;
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
27 in uint in_layer;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 in vec2 in_texcoord;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 in uvec4 in_color;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 uniform mat4 mvp;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
33 flat out uint layer;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 out vec2 texcoord;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 out vec4 color;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 void main()
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 gl_Position = mvp * vec4(vec3(in_position), 1.0);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 texcoord = vec2(in_texcoord);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 // Normalized from the u8 being passed.
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 color = vec4(in_color) / 255.;
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
44
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
45 layer = in_layer;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 "#;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 const FS: &str = r#"
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
50 flat in uint layer;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 in vec2 texcoord;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 in vec4 color;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
54 uniform sampler2DArray color_map;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 out vec4 frag_color;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 void main()
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 {
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
60 frag_color = texture(color_map, vec3(texcoord, layer)) * color;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 "#;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 #[derive(Clone, Copy, Debug, Eq, PartialEq, Semantics)]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 pub enum Semantics {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 #[sem(name = "in_position", repr = "[i16; 3]", wrapper = "VertexPosition")]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 Position,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
69 #[sem(name = "in_layer", repr = "u16", wrapper = "VertexLayer")]
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
70 Layer,
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
71
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 #[sem(name = "in_texcoord", repr = "[f32; 2]", wrapper = "VertexTexcoord")]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 Texcoord,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 #[sem(name = "in_color", repr = "[u8; 4]", wrapper = "VertexColor")]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 Color,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 #[repr(C)]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 #[derive(Clone, Copy, Debug, PartialEq, Vertex)]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 #[vertex(sem = "Semantics")]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 struct Vertex {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 pos: VertexPosition,
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
84 layer: VertexLayer,
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 uv: VertexTexcoord,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 rgba: VertexColor,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 #[derive(UniformInterface)]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 struct ShaderInterface {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 // the 'static lifetime acts as “anything” here
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
92 color_map: Uniform<&'static BoundTexture<'static, Dim2Array, NormUnsigned>>,
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 #[uniform(name = "mvp")]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 mvp: Uniform<[[f32; 4]; 4]>,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 fn main() {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 // Parse arguments.
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 let args: Vec<_> = env::args().collect();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 if args.len() != 4 {
741
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
102 eprintln!("Usage: {} <unarchived ST.DAT directory> <stage number> <easy|normal|hard|lunatic>", args[0]);
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 return;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 }
741
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
105 let directory = Path::new(&args[1]);
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
106 let stage_number: u8 = args[2].parse().expect("stage");
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 let rank: Rank = args[3].parse().expect("rank");
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 // Open the ECL file.
752
5e5e7136ac92 examples: Return a Result for load_file_into_vec()
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 743
diff changeset
110 let buf = load_file_into_vec(directory.join(format!("ecldata{}.ecl", stage_number))).unwrap();
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 let (_, ecl) = Ecl::from_slice(&buf).unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112 assert_eq!(ecl.mains.len(), 1);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 let main = ecl.mains[0].clone();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 // Open the ANM file.
741
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
116 let anm_filename = directory.join(format!("stg{}enm.anm", stage_number));
752
5e5e7136ac92 examples: Return a Result for load_file_into_vec()
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 743
diff changeset
117 let buf = load_file_into_vec(&anm_filename).unwrap();
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 let anm0 = anms.pop().unwrap();
741
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
120
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
121 // Open the second ANM file.
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
122 let anm2_filename = directory.join(format!("stg{}enm2.anm", stage_number));
752
5e5e7136ac92 examples: Return a Result for load_file_into_vec()
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 743
diff changeset
123 let buf = load_file_into_vec(&anm2_filename).unwrap();
741
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
124 let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
125 let anm0_bis = anms.pop().unwrap();
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
126
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
127 let anms = [anm0, anm0_bis];
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 // Get the time since January 1970 as a seed for the PRNG.
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 let time = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 let prng = Rc::new(RefCell::new(Prng::new(time.subsec_micros() as u16)));
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 // Create the Game god object.
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 let game = Game::new(prng, rank);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 let game = Rc::new(RefCell::new(game));
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>());
743
0fed350d1778 examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 742
diff changeset
138 let vertices: [Vertex; 4] = {
0fed350d1778 examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 742
diff changeset
139 let data = std::mem::MaybeUninit::uninit();
0fed350d1778 examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 742
diff changeset
140 unsafe { data.assume_init() }
0fed350d1778 examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 742
diff changeset
141 };
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 // Open the image atlas matching this ANM.
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
146 let tex = load_multiple_anm_images(&mut surface, &anms, &anm_filename).expect("image loading");
741
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
147 let anms = Rc::new(RefCell::new(anms));
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 // set the uniform interface to our type so that we can read textures from the shader
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 let program =
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 let mut tess = TessBuilder::new(&mut surface)
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 .add_vertices(vertices)
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 .set_mode(Mode::TriangleFan)
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 .build()
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 .unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 let mut back_buffer = surface.back_buffer().unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 let mut resize = false;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 let mut frame = 0;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 let mut ecl_runners = vec![];
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 'app: loop {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 for event in surface.poll_events() {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 match event {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 WindowEvent::FramebufferSize(..) => {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 resize = true;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 _ => (),
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 if resize {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 back_buffer = surface.back_buffer().unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 resize = false;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 for call in main.instructions.iter() {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 if call.time == frame {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 let sub = call.sub;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 let instr = call.instr;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 let (x, y, _z, life, bonus, score, mirror) = match instr {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 MainInstruction::SpawnEnemy(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, false),
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 MainInstruction::SpawnEnemyMirrored(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, true),
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189 MainInstruction::SpawnEnemyRandom(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, false),
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190 MainInstruction::SpawnEnemyMirroredRandom(x, y, z, life, bonus, score) => (x, y, z, life, bonus, score, true),
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 _ => continue,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 };
741
3555845f8cf4 Make it so we can use more than a single anm0 in an EclRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 738
diff changeset
193 let enemy = Enemy::new(Position::new(x, y), life, bonus, score, mirror, Rc::downgrade(&anms), Rc::downgrade(&game));
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 let runner = EclRunner::new(&ecl, enemy, sub);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 ecl_runners.push(runner);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
199 for runner in ecl_runners.iter_mut() {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 runner.run_frame();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201 let mut enemy = runner.enemy.borrow_mut();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 enemy.update();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206 // and use it in the shader
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 surface
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
208 .pipeline_builder()
742
0a250ddfae79 examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 741
diff changeset
209 .pipeline(&back_buffer, &PipelineState::default(), |pipeline, mut shd_gate| {
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 let bound_tex = match &tex {
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
212 LoadedTexture::Rgb(tex) => unreachable!(),
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
213 LoadedTexture::Rgba(tex) => unreachable!(),
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
214 LoadedTexture::RgbaArray(tex) => pipeline.bind_texture(tex),
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215 };
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 shd_gate.shade(&program, |iface, mut rdr_gate| {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219 // to use the texture passed as argument (no allocation or copy is performed)
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
220 iface.color_map.update(&bound_tex);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221 //let mvp = ortho_2d(0., 384., 448., 0.);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222 let proj = perspective(0.5235987755982988, 384. / 448., 101010101./2010101., 101010101./10101.);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223 let view = setup_camera(0., 0., 1.);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224 let mvp = view * proj;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 //println!("{:#?}", mvp);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226 // TODO: check how to pass by reference.
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 iface.mvp.update(*mvp.borrow_inner());
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
229 let render_state = RenderState::default()
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
230 .set_depth_test(None)
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement));
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232
742
0a250ddfae79 examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 741
diff changeset
233 rdr_gate.render(&render_state, |mut tess_gate| {
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 let mut game = game.borrow_mut();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 game.run_frame();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
237 for (x, y, z, sprite) in game.get_sprites() {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
238 {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 let mut slice = tess
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240 .as_slice_mut()
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 .unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 let sprite = sprite.borrow();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 let fake_vertices = unsafe { std::mem::transmute::<*mut Vertex, &mut [FakeVertex; 4]>(slice.as_mut_ptr()) };
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 sprite.fill_vertices(fake_vertices, x, y, z);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
247
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
248 // render the tessellation to the surface the regular way and let the vertex shader’s
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249 // magic do the rest!
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250 tess_gate.render(&tess);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
251 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252 });
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 });
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
254 });
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 surface.swap_buffers();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257 frame += 1;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
258 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
259 }