author | sheepluva |
Sat, 04 Jul 2020 03:11:41 +0200 | |
changeset 15665 | 63e2b7b2ec47 |
parent 15284 | ae8e14d14596 |
child 15809 | c3971b38bbfa |
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 |
}; |
15284
ae8e14d14596
Move messages queue to hedgewars-engine-messages lib
unc0rr
parents:
15265
diff
changeset
|
5 |
use hedgewars_engine_messages::queue::*; |
14272 | 6 |
|
14705 | 7 |
use integral_geometry::{Point, Rect, Size}; |
14702 | 8 |
use landgen::outline_template::OutlineTemplate; |
14293 | 9 |
|
15265
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
10 |
use super::{ipc::*, world::World}; |
14272 | 11 |
|
12 |
pub struct EngineInstance { |
|
13 |
pub world: World, |
|
15265
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
14 |
pub ipc_channel: Channel, |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
15 |
ipc_queue: MessagesQueue, |
14272 | 16 |
} |
17 |
||
18 |
impl EngineInstance { |
|
19 |
pub fn new() -> Self { |
|
14702 | 20 |
let mut world = World::new(); |
21 |
||
22 |
fn template() -> OutlineTemplate { |
|
14705 | 23 |
let mut template = OutlineTemplate::new(Size::new(4096 * 1, 2048 * 1)); |
14702 | 24 |
template.islands = vec![vec![ |
25 |
Rect::from_size_coords(100, 2050, 1, 1), |
|
26 |
Rect::from_size_coords(100, 500, 400, 1200), |
|
27 |
Rect::from_size_coords(3600, 500, 400, 1200), |
|
28 |
Rect::from_size_coords(3900, 2050, 1, 1), |
|
29 |
]]; |
|
30 |
template.fill_points = vec![Point::new(1, 0)]; |
|
31 |
||
32 |
template |
|
33 |
} |
|
14705 | 34 |
|
14702 | 35 |
world.init(template()); |
14705 | 36 |
|
14272 | 37 |
Self { |
38 |
world, |
|
15265
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
39 |
ipc_channel: Channel::new(), |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
40 |
ipc_queue: MessagesQueue::new(QueueChatStrategy::LocalGame), |
14272 | 41 |
} |
42 |
} |
|
43 |
||
14704 | 44 |
pub fn render(&mut self) { |
45 |
self.world.render(); |
|
14272 | 46 |
} |
47 |
||
48 |
fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) { |
|
49 |
match message { |
|
50 |
Pong => println!("Pong!"), |
|
51 |
_ => unimplemented!(), |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
fn process_config_message(&mut self, message: &ConfigEngineMessage) { |
|
56 |
match message { |
|
57 |
SetSeed(seed) => self.world.set_seed(seed.as_bytes()), |
|
58 |
_ => unimplemented!(), |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
pub fn process_ipc_queue(&mut self) { |
|
15265
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
63 |
for message in self.ipc_channel.iter() { |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
64 |
self.ipc_queue.push(message); |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
65 |
} |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
66 |
|
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14705
diff
changeset
|
67 |
let messages: Vec<EngineMessage> = self.ipc_queue.iter(0).collect(); |
14272 | 68 |
|
69 |
for message in messages { |
|
70 |
println!("Processing message: {:?}", message); |
|
71 |
match message { |
|
72 |
Unknown => println!("Unknown message"), |
|
14294
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14293
diff
changeset
|
73 |
Empty => println!("Empty message"), |
14272 | 74 |
Synced(_, _) => unimplemented!(), |
75 |
Unsynced(_) => unimplemented!(), |
|
76 |
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
|
77 |
Config(config_message) => self.process_config_message(&config_message), |
14272 | 78 |
} |
79 |
} |
|
80 |
} |
|
81 |
} |