1 use hedgewars_engine_messages::messages::{ |
1 use hedgewars_engine_messages::messages::{ |
2 ConfigEngineMessage::*, EngineMessage::*, KeystrokeAction::*, SyncedEngineMessage::*, |
2 ConfigEngineMessage::*, EngineMessage::*, KeystrokeAction::*, SyncedEngineMessage::*, |
3 UnorderedEngineMessage::*, UnsyncedEngineMessage::*, *, |
3 UnorderedEngineMessage::*, UnsyncedEngineMessage::*, *, |
4 }; |
4 }; |
5 |
5 |
6 use self::gfx_gl::{CommandBuffer, Resources}; |
6 use landgen::outline_template::OutlineTemplate; |
7 use gfx::format::{Unorm, D24, R8_G8_B8_A8}; |
7 use integral_geometry::{Point, Rect, Size}; |
8 use gfx_device_gl as gfx_gl; |
|
9 |
8 |
10 use super::{ipc::IPC, world::World}; |
9 use super::{ipc::IPC, world::World}; |
11 |
|
12 pub struct EngineGlContext { |
|
13 pub device: gfx_gl::Device, |
|
14 pub factory: gfx_gl::Factory, |
|
15 pub render_target: gfx::handle::RenderTargetView<Resources, (R8_G8_B8_A8, Unorm)>, |
|
16 pub depth_buffer: gfx::handle::DepthStencilView<Resources, (D24, Unorm)>, |
|
17 pub command_buffer: gfx::Encoder<Resources, CommandBuffer>, |
|
18 } |
|
19 |
10 |
20 pub struct EngineInstance { |
11 pub struct EngineInstance { |
21 pub world: World, |
12 pub world: World, |
22 pub ipc: IPC, |
13 pub ipc: IPC, |
23 pub gl_context: Option<EngineGlContext>, |
|
24 } |
14 } |
25 |
15 |
26 impl EngineInstance { |
16 impl EngineInstance { |
27 pub fn new() -> Self { |
17 pub fn new() -> Self { |
28 let world = World::new(); |
18 let mut world = World::new(); |
|
19 |
|
20 fn template() -> OutlineTemplate { |
|
21 let mut template = OutlineTemplate::new(Size::new(4096*1, 2048*1)); |
|
22 template.islands = vec![vec![ |
|
23 Rect::from_size_coords(100, 2050, 1, 1), |
|
24 Rect::from_size_coords(100, 500, 400, 1200), |
|
25 Rect::from_size_coords(3600, 500, 400, 1200), |
|
26 Rect::from_size_coords(3900, 2050, 1, 1), |
|
27 ]]; |
|
28 template.fill_points = vec![Point::new(1, 0)]; |
|
29 |
|
30 template |
|
31 } |
|
32 |
|
33 world.init(template()); |
|
34 |
29 Self { |
35 Self { |
30 world, |
36 world, |
31 ipc: IPC::new(), |
37 ipc: IPC::new(), |
32 gl_context: None, |
|
33 } |
38 } |
34 } |
39 } |
35 |
40 |
36 pub fn render<R, C>( |
41 pub fn render(&mut self, x: f32, y: f32, w: f32, h: f32) { |
37 &self, |
42 self.world.render(x, y, w, h); |
38 command_buffer: &mut gfx::Encoder<R, C>, |
|
39 render_target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>, |
|
40 ) where |
|
41 R: gfx::Resources, |
|
42 C: gfx::CommandBuffer<R>, |
|
43 { |
|
44 command_buffer.clear(render_target, [0.0, 0.5, 0.0, 1.0]); |
|
45 } |
43 } |
46 |
44 |
47 fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) { |
45 fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) { |
48 match message { |
46 match message { |
49 Pong => println!("Pong!"), |
47 Pong => println!("Pong!"), |