14277
|
1 |
use hedgewars_engine_messages::messages::{
|
|
2 |
ConfigEngineMessage::*, EngineMessage::*, KeystrokeAction::*, SyncedEngineMessage::*,
|
|
3 |
UnorderedEngineMessage::*, UnsyncedEngineMessage::*, *
|
|
4 |
};
|
|
5 |
|
|
6 |
use super::{ipc::IPC, world::World};
|
|
7 |
|
|
8 |
#[repr(C)]
|
|
9 |
pub struct EngineInstance {
|
|
10 |
pub world: World,
|
|
11 |
pub ipc: IPC,
|
|
12 |
}
|
|
13 |
|
|
14 |
impl EngineInstance {
|
|
15 |
pub fn new() -> Self {
|
|
16 |
let world = World::new();
|
|
17 |
Self {
|
|
18 |
world,
|
|
19 |
ipc: IPC::new(),
|
|
20 |
}
|
|
21 |
}
|
|
22 |
|
|
23 |
pub fn render<R, C>(
|
|
24 |
&self,
|
|
25 |
context: &mut gfx::Encoder<R, C>,
|
|
26 |
target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>,
|
|
27 |
) where
|
|
28 |
R: gfx::Resources,
|
|
29 |
C: gfx::CommandBuffer<R>,
|
|
30 |
{
|
|
31 |
context.clear(target, [0.0, 0.5, 0.0, 1.0]);
|
|
32 |
}
|
|
33 |
|
|
34 |
fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) {
|
|
35 |
match message {
|
|
36 |
Pong => println!("Pong!"),
|
|
37 |
_ => unimplemented!(),
|
|
38 |
}
|
|
39 |
}
|
|
40 |
|
|
41 |
fn process_config_message(&mut self, message: &ConfigEngineMessage) {
|
|
42 |
match message {
|
|
43 |
SetSeed(seed) => self.world.set_seed(seed.as_bytes()),
|
|
44 |
_ => unimplemented!(),
|
|
45 |
}
|
|
46 |
}
|
|
47 |
|
|
48 |
pub fn process_ipc_queue(&mut self) {
|
|
49 |
let messages: Vec<EngineMessage> = self.ipc.iter().collect();
|
|
50 |
|
|
51 |
for message in messages {
|
|
52 |
println!("Processing message: {:?}", message);
|
|
53 |
match message {
|
|
54 |
Unknown => println!("Unknown message"),
|
|
55 |
Empty => println!("Empty message") ,
|
|
56 |
Synced(_, _) => unimplemented!(),
|
|
57 |
Unsynced(_) => unimplemented!(),
|
|
58 |
Unordered(unordered_message) => self.process_unordered_message(&unordered_message),
|
|
59 |
Config(config_message) => self.process_config_message(&config_message)
|
|
60 |
}
|
|
61 |
}
|
|
62 |
}
|
|
63 |
}
|