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