author | unC0Rr |
Wed, 20 Nov 2024 21:37:47 +0100 | |
branch | transitional_engine |
changeset 16067 | d903f8d2395a |
parent 16051 | 2003b466b279 |
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}; |
15954 | 8 |
use landgen::outline_template_based::outline_template::OutlineTemplate; |
14314 | 9 |
|
15919 | 10 |
use std::path::Path; |
11 |
||
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
12 |
use super::{ipc::*, world::World}; |
14293 | 13 |
|
14 |
pub struct EngineInstance { |
|
15 |
pub world: World, |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
16 |
pub ipc_channel: Channel, |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
17 |
ipc_queue: MessagesQueue, |
14293 | 18 |
} |
19 |
||
20 |
impl EngineInstance { |
|
15919 | 21 |
pub fn new(data_path: &Path) -> Self { |
22 |
let mut world = World::new(data_path); |
|
14723 | 23 |
|
24 |
fn template() -> OutlineTemplate { |
|
14726 | 25 |
let mut template = OutlineTemplate::new(Size::new(4096 * 1, 2048 * 1)); |
14723 | 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 |
} |
|
14726 | 36 |
|
14723 | 37 |
world.init(template()); |
16046
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16040
diff
changeset
|
38 |
world.init_renderer(); |
14726 | 39 |
|
14293 | 40 |
Self { |
41 |
world, |
|
15286
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
42 |
ipc_channel: Channel::new(), |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
43 |
ipc_queue: MessagesQueue::new(QueueChatStrategy::LocalGame), |
14293 | 44 |
} |
45 |
} |
|
46 |
||
14725 | 47 |
pub fn render(&mut self) { |
48 |
self.world.render(); |
|
14293 | 49 |
} |
50 |
||
51 |
fn process_unordered_message(&mut self, message: &UnorderedEngineMessage) { |
|
52 |
match message { |
|
53 |
Pong => println!("Pong!"), |
|
54 |
_ => unimplemented!(), |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
fn process_config_message(&mut self, message: &ConfigEngineMessage) { |
|
59 |
match message { |
|
60 |
SetSeed(seed) => self.world.set_seed(seed.as_bytes()), |
|
15831
c3971b38bbfa
hedgewars-engine (rust)/preview: recognise feature_size cmd and do something with it
sheepluva
parents:
15305
diff
changeset
|
61 |
SetFeatureSize(feature_size) => self.world.set_feature_size(*feature_size), |
14293 | 62 |
_ => unimplemented!(), |
63 |
} |
|
64 |
} |
|
65 |
||
66 |
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
|
67 |
for message in self.ipc_channel.iter() { |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
68 |
self.ipc_queue.push(message); |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
69 |
} |
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
70 |
|
07e909ba4203
Implement ipc queue which takes care of message ordering and timestamps
unC0Rr
parents:
14726
diff
changeset
|
71 |
let messages: Vec<EngineMessage> = self.ipc_queue.iter(0).collect(); |
14293 | 72 |
|
73 |
for message in messages { |
|
74 |
println!("Processing message: {:?}", message); |
|
75 |
match message { |
|
16040 | 76 |
Unknown(data) => println!("Unknown message: {:?}", data), |
14315
21be7838a127
Add advance_simulation() function to engine lib, some WIP on frontend
unc0rr
parents:
14314
diff
changeset
|
77 |
Empty => println!("Empty message"), |
14293 | 78 |
Synced(_, _) => unimplemented!(), |
79 |
Unsynced(_) => unimplemented!(), |
|
80 |
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
|
81 |
Config(config_message) => self.process_config_message(&config_message), |
14293 | 82 |
} |
83 |
} |
|
84 |
} |
|
85 |
} |