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