author | nemo |
Sun, 16 Dec 2018 10:25:36 -0500 | |
changeset 14463 | 99117df5a3d3 |
parent 14299 | 21be7838a127 |
child 14707 | 29dbe9ce8b7d |
permissions | -rw-r--r-- |
14277 | 1 |
use hedgewars_engine_messages::messages::{ |
2 |
ConfigEngineMessage::*, EngineMessage::*, KeystrokeAction::*, SyncedEngineMessage::*, |
|
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14298
diff
changeset
|
3 |
UnorderedEngineMessage::*, UnsyncedEngineMessage::*, *, |
14277 | 4 |
}; |
5 |
||
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14298
diff
changeset
|
6 |
use self::gfx_gl::{CommandBuffer, Resources}; |
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14298
diff
changeset
|
7 |
use gfx::format::{Unorm, D24, R8_G8_B8_A8}; |
14298 | 8 |
use gfx_device_gl as gfx_gl; |
9 |
||
14277 | 10 |
use super::{ipc::IPC, world::World}; |
11 |
||
14298 | 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)>, |
|
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14298
diff
changeset
|
17 |
pub command_buffer: gfx::Encoder<Resources, CommandBuffer>, |
14298 | 18 |
} |
19 |
||
14277 | 20 |
pub struct EngineInstance { |
21 |
pub world: World, |
|
22 |
pub ipc: IPC, |
|
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14298
diff
changeset
|
23 |
pub gl_context: Option<EngineGlContext>, |
14277 | 24 |
} |
25 |
||
26 |
impl EngineInstance { |
|
27 |
pub fn new() -> Self { |
|
28 |
let world = World::new(); |
|
29 |
Self { |
|
30 |
world, |
|
31 |
ipc: IPC::new(), |
|
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14298
diff
changeset
|
32 |
gl_context: None, |
14277 | 33 |
} |
34 |
} |
|
35 |
||
36 |
pub fn render<R, C>( |
|
37 |
&self, |
|
14298 | 38 |
command_buffer: &mut gfx::Encoder<R, C>, |
39 |
render_target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>, |
|
14277 | 40 |
) where |
41 |
R: gfx::Resources, |
|
42 |
C: gfx::CommandBuffer<R>, |
|
43 |
{ |
|
14298 | 44 |
command_buffer.clear(render_target, [0.0, 0.5, 0.0, 1.0]); |
14277 | 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"), |
|
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14298
diff
changeset
|
68 |
Empty => println!("Empty message"), |
14277 | 69 |
Synced(_, _) => unimplemented!(), |
70 |
Unsynced(_) => unimplemented!(), |
|
71 |
Unordered(unordered_message) => self.process_unordered_message(&unordered_message), |
|
14299
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14298
diff
changeset
|
72 |
Config(config_message) => self.process_config_message(&config_message), |
14277 | 73 |
} |
74 |
} |
|
75 |
} |
|
76 |
} |