author | Wuzzy <Wuzzy2@mail.ru> |
Fri, 11 Oct 2019 18:59:48 +0200 | |
changeset 15493 | b56c04fac6f9 |
parent 15305 | ae8e14d14596 |
child 15831 | c3971b38bbfa |
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 |
}; |
15305
ae8e14d14596
Move messages queue to hedgewars-engine-messages lib
unc0rr
parents:
15286
diff
changeset
|
5 |
use hedgewars_engine_messages::queue::*; |
14293 | 6 |
|
14726 | 7 |
use integral_geometry::{Point, Rect, Size}; |
14723 | 8 |
use landgen::outline_template::OutlineTemplate; |
14314 | 9 |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
10 |
use super::{ipc::*, world::World}; |
14293 | 11 |
|
12 |
pub struct EngineInstance { |
|
13 |
pub world: World, |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
14 |
pub ipc_channel: Channel, |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
15 |
ipc_queue: MessagesQueue, |
14293 | 16 |
} |
17 |
||
18 |
impl EngineInstance { |
|
19 |
pub fn new() -> Self { |
|
14723 | 20 |
let mut world = World::new(); |
21 |
||
22 |
fn template() -> OutlineTemplate { |
|
14726 | 23 |
let mut template = OutlineTemplate::new(Size::new(4096 * 1, 2048 * 1)); |
14723 | 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 |
} |
|
14726 | 34 |
|
14723 | 35 |
world.init(template()); |
14726 | 36 |
|
14293 | 37 |
Self { |
38 |
world, |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
39 |
ipc_channel: Channel::new(), |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
40 |
ipc_queue: MessagesQueue::new(QueueChatStrategy::LocalGame), |
14293 | 41 |
} |
42 |
} |
|
43 |
||
14725 | 44 |
pub fn render(&mut self) { |
45 |
self.world.render(); |
|
14293 | 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) { |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
63 |
for message in self.ipc_channel.iter() { |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
64 |
self.ipc_queue.push(message); |
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 |
|
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
67 |
let messages: Vec<EngineMessage> = self.ipc_queue.iter(0).collect(); |
14293 | 68 |
|
69 |
for message in messages { |
|
70 |
println!("Processing message: {:?}", message); |
|
71 |
match message { |
|
72 |
Unknown => println!("Unknown message"), |
|
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
73 |
Empty => println!("Empty message"), |
14293 | 74 |
Synced(_, _) => unimplemented!(), |
75 |
Unsynced(_) => unimplemented!(), |
|
76 |
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
|
77 |
Config(config_message) => self.process_config_message(&config_message), |
14293 | 78 |
} |
79 |
} |
|
80 |
} |
|
81 |
} |