14277
|
1 |
use hedgewars_engine_messages::messages::{
|
|
2 |
ConfigEngineMessage::*, EngineMessage::*, KeystrokeAction::*, SyncedEngineMessage::*,
|
|
3 |
UnorderedEngineMessage::*, UnsyncedEngineMessage::*, *
|
|
4 |
};
|
|
5 |
|
14298
|
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 |
|
14277
|
15 |
use super::{ipc::IPC, world::World};
|
|
16 |
|
14298
|
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 |
|
14277
|
25 |
pub struct EngineInstance {
|
|
26 |
pub world: World,
|
|
27 |
pub ipc: IPC,
|
14298
|
28 |
pub gl_context: Option<EngineGlContext>
|
14277
|
29 |
}
|
|
30 |
|
|
31 |
impl EngineInstance {
|
|
32 |
pub fn new() -> Self {
|
|
33 |
let world = World::new();
|
|
34 |
Self {
|
|
35 |
world,
|
|
36 |
ipc: IPC::new(),
|
14298
|
37 |
gl_context: None
|
14277
|
38 |
}
|
|
39 |
}
|
|
40 |
|
|
41 |
pub fn render<R, C>(
|
|
42 |
&self,
|
14298
|
43 |
command_buffer: &mut gfx::Encoder<R, C>,
|
|
44 |
render_target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>,
|
14277
|
45 |
) where
|
|
46 |
R: gfx::Resources,
|
|
47 |
C: gfx::CommandBuffer<R>,
|
|
48 |
{
|
14298
|
49 |
command_buffer.clear(render_target, [0.0, 0.5, 0.0, 1.0]);
|
14277
|
50 |
}
|
|
51 |
|
|
52 |
fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) {
|
|
53 |
match message {
|
|
54 |
Pong => println!("Pong!"),
|
|
55 |
_ => unimplemented!(),
|
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
fn process_config_message(&mut self, message: &ConfigEngineMessage) {
|
|
60 |
match message {
|
|
61 |
SetSeed(seed) => self.world.set_seed(seed.as_bytes()),
|
|
62 |
_ => unimplemented!(),
|
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
pub fn process_ipc_queue(&mut self) {
|
|
67 |
let messages: Vec<EngineMessage> = self.ipc.iter().collect();
|
|
68 |
|
|
69 |
for message in messages {
|
|
70 |
println!("Processing message: {:?}", message);
|
|
71 |
match message {
|
|
72 |
Unknown => println!("Unknown message"),
|
|
73 |
Empty => println!("Empty message") ,
|
|
74 |
Synced(_, _) => unimplemented!(),
|
|
75 |
Unsynced(_) => unimplemented!(),
|
|
76 |
Unordered(unordered_message) => self.process_unordered_message(&unordered_message),
|
|
77 |
Config(config_message) => self.process_config_message(&config_message)
|
|
78 |
}
|
|
79 |
}
|
|
80 |
}
|
|
81 |
}
|