author | unc0rr |
Sun, 25 Nov 2018 22:32:49 +0100 | |
changeset 14315 | 21be7838a127 |
parent 14314 | b8871dd33ec4 |
child 14723 | 29dbe9ce8b7d |
permissions | -rw-r--r-- |
14293 | 1 |
use hedgewars_engine_messages::messages::{ |
2 |
ConfigEngineMessage::*, EngineMessage::*, KeystrokeAction::*, SyncedEngineMessage::*, |
|
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
3 |
UnorderedEngineMessage::*, UnsyncedEngineMessage::*, *, |
14293 | 4 |
}; |
5 |
||
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
6 |
use self::gfx_gl::{CommandBuffer, Resources}; |
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
7 |
use gfx::format::{Unorm, D24, R8_G8_B8_A8}; |
14314 | 8 |
use gfx_device_gl as gfx_gl; |
9 |
||
14293 | 10 |
use super::{ipc::IPC, world::World}; |
11 |
||
14314 | 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)>, |
|
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
17 |
pub command_buffer: gfx::Encoder<Resources, CommandBuffer>, |
14314 | 18 |
} |
19 |
||
14293 | 20 |
pub struct EngineInstance { |
21 |
pub world: World, |
|
22 |
pub ipc: IPC, |
|
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
23 |
pub gl_context: Option<EngineGlContext>, |
14293 | 24 |
} |
25 |
||
26 |
impl EngineInstance { |
|
27 |
pub fn new() -> Self { |
|
28 |
let world = World::new(); |
|
29 |
Self { |
|
30 |
world, |
|
31 |
ipc: IPC::new(), |
|
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
32 |
gl_context: None, |
14293 | 33 |
} |
34 |
} |
|
35 |
||
36 |
pub fn render<R, C>( |
|
37 |
&self, |
|
14314 | 38 |
command_buffer: &mut gfx::Encoder<R, C>, |
39 |
render_target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>, |
|
14293 | 40 |
) where |
41 |
R: gfx::Resources, |
|
42 |
C: gfx::CommandBuffer<R>, |
|
43 |
{ |
|
14314 | 44 |
command_buffer.clear(render_target, [0.0, 0.5, 0.0, 1.0]); |
14293 | 45 |
} |
46 |
||
47 |
fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) { |
|
48 |
match message { |
|
49 |
Pong => println!("Pong!"), |
|
50 |
_ => unimplemented!(), |
|
51 |
} |
|
52 |
} |
|
53 |
||
54 |
fn process_config_message(&mut self, message: &ConfigEngineMessage) { |
|
55 |
match message { |
|
56 |
SetSeed(seed) => self.world.set_seed(seed.as_bytes()), |
|
57 |
_ => unimplemented!(), |
|
58 |
} |
|
59 |
} |
|
60 |
||
61 |
pub fn process_ipc_queue(&mut self) { |
|
62 |
let messages: Vec<EngineMessage> = self.ipc.iter().collect(); |
|
63 |
||
64 |
for message in messages { |
|
65 |
println!("Processing message: {:?}", message); |
|
66 |
match message { |
|
67 |
Unknown => println!("Unknown message"), |
|
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
68 |
Empty => println!("Empty message"), |
14293 | 69 |
Synced(_, _) => unimplemented!(), |
70 |
Unsynced(_) => unimplemented!(), |
|
71 |
Unordered(unordered_message) => self.process_unordered_message(&unordered_message), |
|
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
72 |
Config(config_message) => self.process_config_message(&config_message), |
14293 | 73 |
} |
74 |
} |
|
75 |
} |
|
76 |
} |