author | unC0Rr |
Thu, 25 Jul 2019 15:18:00 +0200 | |
changeset 15286 | 07e909ba4203 |
parent 14726 | 19122a329774 |
child 15305 | ae8e14d14596 |
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 |
||
14726 | 6 |
use integral_geometry::{Point, Rect, Size}; |
14723 | 7 |
use landgen::outline_template::OutlineTemplate; |
14314 | 8 |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
9 |
use super::{ipc::*, world::World}; |
14293 | 10 |
|
11 |
pub struct EngineInstance { |
|
12 |
pub world: World, |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
13 |
pub ipc_channel: Channel, |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
14 |
ipc_queue: MessagesQueue, |
14293 | 15 |
} |
16 |
||
17 |
impl EngineInstance { |
|
18 |
pub fn new() -> Self { |
|
14723 | 19 |
let mut world = World::new(); |
20 |
||
21 |
fn template() -> OutlineTemplate { |
|
14726 | 22 |
let mut template = OutlineTemplate::new(Size::new(4096 * 1, 2048 * 1)); |
14723 | 23 |
template.islands = vec![vec![ |
24 |
Rect::from_size_coords(100, 2050, 1, 1), |
|
25 |
Rect::from_size_coords(100, 500, 400, 1200), |
|
26 |
Rect::from_size_coords(3600, 500, 400, 1200), |
|
27 |
Rect::from_size_coords(3900, 2050, 1, 1), |
|
28 |
]]; |
|
29 |
template.fill_points = vec![Point::new(1, 0)]; |
|
30 |
||
31 |
template |
|
32 |
} |
|
14726 | 33 |
|
14723 | 34 |
world.init(template()); |
14726 | 35 |
|
14293 | 36 |
Self { |
37 |
world, |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
38 |
ipc_channel: Channel::new(), |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
39 |
ipc_queue: MessagesQueue::new(QueueChatStrategy::LocalGame), |
14293 | 40 |
} |
41 |
} |
|
42 |
||
14725 | 43 |
pub fn render(&mut self) { |
44 |
self.world.render(); |
|
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) { |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
62 |
for message in self.ipc_channel.iter() { |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
63 |
self.ipc_queue.push(message); |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
64 |
} |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
65 |
|
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
66 |
let messages: Vec<EngineMessage> = self.ipc_queue.iter(0).collect(); |
14293 | 67 |
|
68 |
for message in messages { |
|
69 |
println!("Processing message: {:?}", message); |
|
70 |
match message { |
|
71 |
Unknown => println!("Unknown message"), |
|
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
72 |
Empty => println!("Empty message"), |
14293 | 73 |
Synced(_, _) => unimplemented!(), |
74 |
Unsynced(_) => unimplemented!(), |
|
75 |
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
|
76 |
Config(config_message) => self.process_config_message(&config_message), |
14293 | 77 |
} |
78 |
} |
|
79 |
} |
|
80 |
} |