author | Wuzzy <Wuzzy2@mail.ru> |
Wed, 19 Jun 2019 20:37:02 +0200 | |
changeset 15180 | 061a3085d6d8 |
parent 14705 | 19122a329774 |
child 15265 | 07e909ba4203 |
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 |
||
14705 | 6 |
use integral_geometry::{Point, Rect, Size}; |
14702 | 7 |
use landgen::outline_template::OutlineTemplate; |
14293 | 8 |
|
14272 | 9 |
use super::{ipc::IPC, world::World}; |
10 |
||
11 |
pub struct EngineInstance { |
|
12 |
pub world: World, |
|
13 |
pub ipc: IPC, |
|
14 |
} |
|
15 |
||
16 |
impl EngineInstance { |
|
17 |
pub fn new() -> Self { |
|
14702 | 18 |
let mut world = World::new(); |
19 |
||
20 |
fn template() -> OutlineTemplate { |
|
14705 | 21 |
let mut template = OutlineTemplate::new(Size::new(4096 * 1, 2048 * 1)); |
14702 | 22 |
template.islands = vec![vec![ |
23 |
Rect::from_size_coords(100, 2050, 1, 1), |
|
24 |
Rect::from_size_coords(100, 500, 400, 1200), |
|
25 |
Rect::from_size_coords(3600, 500, 400, 1200), |
|
26 |
Rect::from_size_coords(3900, 2050, 1, 1), |
|
27 |
]]; |
|
28 |
template.fill_points = vec![Point::new(1, 0)]; |
|
29 |
||
30 |
template |
|
31 |
} |
|
14705 | 32 |
|
14702 | 33 |
world.init(template()); |
14705 | 34 |
|
14272 | 35 |
Self { |
36 |
world, |
|
37 |
ipc: IPC::new(), |
|
38 |
} |
|
39 |
} |
|
40 |
||
14704 | 41 |
pub fn render(&mut self) { |
42 |
self.world.render(); |
|
14272 | 43 |
} |
44 |
||
45 |
fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) { |
|
46 |
match message { |
|
47 |
Pong => println!("Pong!"), |
|
48 |
_ => unimplemented!(), |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
fn process_config_message(&mut self, message: &ConfigEngineMessage) { |
|
53 |
match message { |
|
54 |
SetSeed(seed) => self.world.set_seed(seed.as_bytes()), |
|
55 |
_ => unimplemented!(), |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
pub fn process_ipc_queue(&mut self) { |
|
60 |
let messages: Vec<EngineMessage> = self.ipc.iter().collect(); |
|
61 |
||
62 |
for message in messages { |
|
63 |
println!("Processing message: {:?}", message); |
|
64 |
match message { |
|
65 |
Unknown => println!("Unknown message"), |
|
14294
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14293
diff
changeset
|
66 |
Empty => println!("Empty message"), |
14272 | 67 |
Synced(_, _) => unimplemented!(), |
68 |
Unsynced(_) => unimplemented!(), |
|
69 |
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
|
70 |
Config(config_message) => self.process_config_message(&config_message), |
14272 | 71 |
} |
72 |
} |
|
73 |
} |
|
74 |
} |