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 gfx::{ |
|
7 format::{R8_G8_B8_A8, D24, Unorm} |
|
8 }; |
|
9 use gfx_device_gl as gfx_gl; |
|
10 use self::gfx_gl::{ |
|
11 Resources, |
|
12 CommandBuffer |
|
13 }; |
|
14 |
6 use super::{ipc::IPC, world::World}; |
15 use super::{ipc::IPC, world::World}; |
7 |
16 |
8 #[repr(C)] |
17 pub struct EngineGlContext { |
|
18 pub device: gfx_gl::Device, |
|
19 pub factory: gfx_gl::Factory, |
|
20 pub render_target: gfx::handle::RenderTargetView<Resources, (R8_G8_B8_A8, Unorm)>, |
|
21 pub depth_buffer: gfx::handle::DepthStencilView<Resources, (D24, Unorm)>, |
|
22 pub command_buffer: gfx::Encoder<Resources, CommandBuffer> |
|
23 } |
|
24 |
9 pub struct EngineInstance { |
25 pub struct EngineInstance { |
10 pub world: World, |
26 pub world: World, |
11 pub ipc: IPC, |
27 pub ipc: IPC, |
|
28 pub gl_context: Option<EngineGlContext> |
12 } |
29 } |
13 |
30 |
14 impl EngineInstance { |
31 impl EngineInstance { |
15 pub fn new() -> Self { |
32 pub fn new() -> Self { |
16 let world = World::new(); |
33 let world = World::new(); |
17 Self { |
34 Self { |
18 world, |
35 world, |
19 ipc: IPC::new(), |
36 ipc: IPC::new(), |
|
37 gl_context: None |
20 } |
38 } |
21 } |
39 } |
22 |
40 |
23 pub fn render<R, C>( |
41 pub fn render<R, C>( |
24 &self, |
42 &self, |
25 context: &mut gfx::Encoder<R, C>, |
43 command_buffer: &mut gfx::Encoder<R, C>, |
26 target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>, |
44 render_target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>, |
27 ) where |
45 ) where |
28 R: gfx::Resources, |
46 R: gfx::Resources, |
29 C: gfx::CommandBuffer<R>, |
47 C: gfx::CommandBuffer<R>, |
30 { |
48 { |
31 context.clear(target, [0.0, 0.5, 0.0, 1.0]); |
49 command_buffer.clear(render_target, [0.0, 0.5, 0.0, 1.0]); |
32 } |
50 } |
33 |
51 |
34 fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) { |
52 fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) { |
35 match message { |
53 match message { |
36 Pong => println!("Pong!"), |
54 Pong => println!("Pong!"), |