annotate examples/stagerunner.rs @ 753:a662dddd4a2b

examples: Use array textures for enemy PNGs This requires luminance 0.39.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 25 Feb 2020 21:03:44 +0100
parents 5e5e7136ac92
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};
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 use touhou::th06::anm0::Anm0;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 use touhou::th06::anm0_vm::Vertex as FakeVertex;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 use touhou::th06::ecl::{Ecl, Rank, MainInstruction};
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 use touhou::th06::ecl_vm::EclRunner;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 use touhou::th06::enemy::{Enemy, Game, Position};
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 use touhou::util::math::{perspective, setup_camera};
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 use touhou::util::prng::Prng;
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
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 #[path = "common.rs"]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 mod common;
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
25 use 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
26
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 const VS: &str = r#"
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 in ivec3 in_position;
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
29 in uint in_layer;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 in vec2 in_texcoord;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 in uvec4 in_color;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 uniform mat4 mvp;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
35 flat out uint layer;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 out vec2 texcoord;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 out vec4 color;
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 void main()
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 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
42 texcoord = vec2(in_texcoord);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 // 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
45 color = vec4(in_color) / 255.;
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
46
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
47 layer = in_layer;
738
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 "#;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 const FS: &str = r#"
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
52 flat in uint layer;
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 in vec2 texcoord;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 in vec4 color;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
56 uniform sampler2DArray color_map;
738
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 out vec4 frag_color;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 void main()
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 {
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
62 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
63 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 "#;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 #[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
67 pub enum Semantics {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 #[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
69 Position,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
71 #[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
72 Layer,
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
73
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 #[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
75 Texcoord,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 #[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
78 Color,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 #[repr(C)]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 #[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
83 #[vertex(sem = "Semantics")]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 struct Vertex {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 pos: VertexPosition,
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
86 layer: VertexLayer,
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 uv: VertexTexcoord,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 rgba: VertexColor,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 #[derive(UniformInterface)]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 struct ShaderInterface {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 // 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
94 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
95
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 #[uniform(name = "mvp")]
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 mvp: Uniform<[[f32; 4]; 4]>,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 fn main() {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 // Parse arguments.
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 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
103 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
104 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
105 return;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 }
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
107 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
108 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
109 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
110
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 // 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
112 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
113 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
114 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
115 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
116
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 // 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
118 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
119 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
120 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
121 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
122
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
123 // 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
124 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
125 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
126 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
127 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
128
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
129 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
130
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 // 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
132 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
133 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
134
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 // Create the Game god object.
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 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
137 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
138
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 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
140 let vertices: [Vertex; 4] = {
0fed350d1778 examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 742
diff changeset
141 let data = std::mem::MaybeUninit::uninit();
0fed350d1778 examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 742
diff changeset
142 unsafe { data.assume_init() }
0fed350d1778 examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 742
diff changeset
143 };
738
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 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
146
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147 // 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
148 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
149 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
150
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 // 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
152 let program =
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 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
154
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 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
156 .add_vertices(vertices)
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 .set_mode(Mode::TriangleFan)
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 .build()
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 .unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 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
162 let mut resize = false;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 let mut frame = 0;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 let mut ecl_runners = vec![];
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 'app: loop {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 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
168 match event {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 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
170
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 WindowEvent::FramebufferSize(..) => {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 resize = true;
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 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 if resize {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 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
181 resize = false;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 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
185 if call.time == frame {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 let sub = call.sub;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 let instr = call.instr;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 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
189 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
190 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
191 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
192 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
193 _ => continue,
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 };
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
195 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
196 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
197 ecl_runners.push(runner);
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 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201 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
202 runner.run_frame();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 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
204 enemy.update();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 // 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
208 // 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
209 surface
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 .pipeline_builder()
742
0a250ddfae79 examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 741
diff changeset
211 .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
212 // 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
213 let bound_tex = match &tex {
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
214 LoadedTexture::Rgb(tex) => unreachable!(),
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
215 LoadedTexture::Rgba(tex) => unreachable!(),
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
216 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
217 };
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219 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
220 // 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
221 // 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
222 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
223 //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
224 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
225 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
226 let mvp = view * proj;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 //println!("{:#?}", mvp);
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 // 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
229 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
230
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 let render_state = RenderState::default()
753
a662dddd4a2b examples: Use array textures for enemy PNGs
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 752
diff changeset
232 .set_depth_test(None)
738
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233 .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
234
742
0a250ddfae79 examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 741
diff changeset
235 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
236 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
237 game.run_frame();
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 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
240 {
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 let mut slice = tess
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242 .as_slice_mut()
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 .unwrap();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 let sprite = sprite.borrow();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 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
247 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
248 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250 // 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
251 // magic do the rest!
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252 tess_gate.render(&tess);
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 });
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
258 surface.swap_buffers();
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
259 frame += 1;
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 }
817c453b7223 stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 }