Mercurial > touhou
annotate examples/eclrenderer.rs @ 752:5e5e7136ac92
examples: Return a Result for load_file_into_vec()
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 29 Jan 2020 17:45:25 +0100 |
parents | 0fed350d1778 |
children | a662dddd4a2b |
rev | line source |
---|---|
706
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
1 use luminance::blending::{Equation, Factor}; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
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:
717
diff
changeset
|
3 use luminance::pipeline::{BoundTexture, PipelineState}; |
708
3954801b6299
examples: Update to luminance 0.32.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
707
diff
changeset
|
4 use luminance::pixel::NormUnsigned; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 use luminance::render_state::RenderState; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 use luminance::shader::program::{Program, Uniform}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 use luminance::tess::{Mode, TessBuilder}; |
706
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
8 use luminance::texture::{Dim2, Flat}; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 use luminance_derive::{Semantics, Vertex, UniformInterface}; |
707
987409d48991
Switch to versioned luminance now that it got released, not hardcoded paths.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
706
diff
changeset
|
10 use luminance_glfw::{Action, Key, WindowEvent, GlfwSurface, Surface, WindowDim, WindowOpt}; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 use touhou::th06::anm0::Anm0; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 use touhou::th06::anm0_vm::{Sprite, Vertex as FakeVertex}; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
662
diff
changeset
|
13 use touhou::th06::ecl::{Ecl, Rank}; |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
14 use touhou::th06::ecl_vm::EclRunner; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 use touhou::th06::enemy::{Enemy, Game, Position}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 use touhou::util::math::{perspective, setup_camera}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 use touhou::util::prng::Prng; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 use std::cell::RefCell; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 use std::rc::Rc; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 use std::env; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 use std::path::Path; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 |
706
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
23 #[path = "common.rs"] |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
24 mod common; |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
25 use common::{load_file_into_vec, load_anm_image, LoadedTexture}; |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
26 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 const VS: &str = r#" |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 in ivec3 in_position; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 in vec2 in_texcoord; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 in uvec4 in_color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 uniform mat4 mvp; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 out vec2 texcoord; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 out vec4 color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 void main() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 gl_Position = mvp * vec4(vec3(in_position), 1.0); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 texcoord = vec2(in_texcoord); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 // Normalized from the u8 being passed. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 color = vec4(in_color) / 255.; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 "#; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 const FS: &str = r#" |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 in vec2 texcoord; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 in vec4 color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 uniform sampler2D color_map; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 out vec4 frag_color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 void main() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 frag_color = texture(color_map, texcoord) * color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 "#; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 #[derive(Clone, Copy, Debug, Eq, PartialEq, Semantics)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 pub enum Semantics { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 #[sem(name = "in_position", repr = "[i16; 3]", wrapper = "VertexPosition")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 Position, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 #[sem(name = "in_texcoord", repr = "[f32; 2]", wrapper = "VertexTexcoord")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 Texcoord, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 #[sem(name = "in_color", repr = "[u8; 4]", wrapper = "VertexColor")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 Color, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 #[repr(C)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 #[derive(Clone, Copy, Debug, PartialEq, Vertex)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 #[vertex(sem = "Semantics")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 struct Vertex { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 pos: VertexPosition, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 uv: VertexTexcoord, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 rgba: VertexColor, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 #[derive(UniformInterface)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 struct ShaderInterface { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 // the 'static lifetime acts as “anything” here |
708
3954801b6299
examples: Update to luminance 0.32.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
707
diff
changeset
|
85 color_map: Uniform<&'static BoundTexture<'static, Flat, Dim2, NormUnsigned>>, |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 #[uniform(name = "mvp")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 mvp: Uniform<[[f32; 4]; 4]>, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 fn main() { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 // Parse arguments. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 let args: Vec<_> = env::args().collect(); |
706
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
94 if args.len() != 5 { |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
95 eprintln!("Usage: {} <ECL file> <ANM file> <easy|normal|hard|lunatic> <sub number>", args[0]); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 return; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 } |
706
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
98 let ecl_filename = Path::new(&args[1]); |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
99 let anm_filename = Path::new(&args[2]); |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
100 let rank: Rank = args[3].parse().expect("rank"); |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
101 let sub: u16 = args[4].parse().expect("number"); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 // 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
|
104 let buf = load_file_into_vec(ecl_filename).unwrap(); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 let (_, ecl) = Ecl::from_slice(&buf).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 // Open the ANM file. |
752
5e5e7136ac92
examples: Return a Result for load_file_into_vec()
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
743
diff
changeset
|
108 let buf = load_file_into_vec(anm_filename).unwrap(); |
701
b6c351ca0a35
anm0: return the nom IResult and the list of Anm0s.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
700
diff
changeset
|
109 let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); |
b6c351ca0a35
anm0: return the nom IResult and the list of Anm0s.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
700
diff
changeset
|
110 let anm0 = anms.pop().unwrap(); |
742
0a250ddfae79
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
717
diff
changeset
|
111 let anm0 = Rc::new(RefCell::new([anm0.clone(), anm0])); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 |
662
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
113 if ecl.subs.len() < sub as usize { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 eprintln!("This ecl doesn’t contain a sub named {}.", sub); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 return; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 |
687
ac092b70c39a
Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
670
diff
changeset
|
118 // Get the time since January 1970 as a seed for the PRNG. |
ac092b70c39a
Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
670
diff
changeset
|
119 let time = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap(); |
ac092b70c39a
Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
670
diff
changeset
|
120 let prng = Rc::new(RefCell::new(Prng::new(time.subsec_micros() as u16))); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 // Create the Game god object. |
670
cdb484115c5b
Use the requested rank in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
123 let game = Game::new(prng, rank); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 let game = Rc::new(RefCell::new(game)); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 // And the enemy object. |
742
0a250ddfae79
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
717
diff
changeset
|
127 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, false, Rc::downgrade(&anm0), Rc::downgrade(&game)); |
662
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
128 let mut ecl_runner = EclRunner::new(&ecl, enemy.clone(), sub); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 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
|
131 let vertices: [Vertex; 4] = { |
0fed350d1778
examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
132 let data = std::mem::MaybeUninit::uninit(); |
0fed350d1778
examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
133 unsafe { data.assume_init() } |
0fed350d1778
examples: Remove deprecated std::mem::uninitialized().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
742
diff
changeset
|
134 }; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 // Open the image atlas matching this ANM. |
742
0a250ddfae79
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
717
diff
changeset
|
139 let tex = load_anm_image(&mut surface, &anm0.borrow()[0], &anm_filename).expect("image loading"); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 // set the uniform interface to our type so that we can read textures from the shader |
715
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
142 let program = |
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
143 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 let mut tess = TessBuilder::new(&mut surface) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 .add_vertices(vertices) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 .set_mode(Mode::TriangleFan) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 .build() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 .unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 |
715
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
151 let mut back_buffer = surface.back_buffer().unwrap(); |
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
152 let mut resize = false; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 'app: loop { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 for event in surface.poll_events() { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
156 match event { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 |
715
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
159 WindowEvent::FramebufferSize(..) => { |
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
160 resize = true; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
161 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 _ => (), |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 |
715
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
167 if resize { |
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
168 back_buffer = surface.back_buffer().unwrap(); |
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
169 resize = false; |
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
170 } |
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
171 |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
172 if ecl_runner.running == false { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 break; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 let mut slice = tess |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 .as_slice_mut() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
179 .unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
181 ecl_runner.run_frame(); |
662
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
182 { |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
183 let mut enemy = enemy.borrow_mut(); |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
184 enemy.update(); |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
185 } |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
186 let mut game = game.borrow_mut(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
187 game.run_frame(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 let sprites = game.get_sprites(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 fill_vertices_ptr(sprites, slice.as_mut_ptr()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
191 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
193 // and use it in the shader |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
194 surface |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
195 .pipeline_builder() |
742
0a250ddfae79
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
717
diff
changeset
|
196 .pipeline(&back_buffer, &PipelineState::default(), |pipeline, mut shd_gate| { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader |
706
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
198 let bound_tex = match &tex { |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
199 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
200 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
201 }; |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
202 |
715
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
203 shd_gate.shade(&program, |iface, mut rdr_gate| { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
205 // to use the texture passed as argument (no allocation or copy is performed) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 iface.color_map.update(&bound_tex); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
207 //let mvp = ortho_2d(0., 384., 448., 0.); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 let proj = perspective(0.5235987755982988, 384. / 448., 101010101./2010101., 101010101./10101.); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
209 let view = setup_camera(0., 0., 1.); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
210 let mvp = view * proj; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
211 //println!("{:#?}", mvp); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
212 // TODO: check how to pass by reference. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
213 iface.mvp.update(*mvp.borrow_inner()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 |
706
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
215 let render_state = RenderState::default() |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
216 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); |
bca515da9047
examples: use common module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
217 |
742
0a250ddfae79
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
717
diff
changeset
|
218 rdr_gate.render(&render_state, |mut tess_gate| { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
219 // render the tessellation to the surface the regular way and let the vertex shader’s |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 // magic do the rest! |
715
2b2376811f46
examples: Update luminance.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
708
diff
changeset
|
221 tess_gate.render(&tess); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 }); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
223 }); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 }); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 surface.swap_buffers(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
230 fn fill_vertices_ptr(sprites: Vec<(f32, f32, f32, Rc<RefCell<Sprite>>)>, vertices: *mut Vertex) { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 let mut fake_vertices = unsafe { std::mem::transmute::<*mut Vertex, &mut [FakeVertex; 4]>(vertices) }; |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
232 for (x, y, z, sprite) in sprites { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 let sprite = sprite.borrow(); |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
234 sprite.fill_vertices(&mut fake_vertices, x, y, z); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 } |