hedgewars-engine (rust)/preview: recognise feature_size cmd and do something with it
authorsheepluva
Sat, 26 Jun 2021 00:13:28 +0200
changeset 15809 c3971b38bbfa
parent 15808 1fa2f38c5700
child 15810 ee84e417d8d0
hedgewars-engine (rust)/preview: recognise feature_size cmd and do something with it
rust/hedgewars-engine-messages/src/parser.rs
rust/lib-hedgewars-engine/src/instance.rs
rust/lib-hedgewars-engine/src/world.rs
--- a/rust/hedgewars-engine-messages/src/parser.rs	Fri Jun 25 22:34:26 2021 +0200
+++ b/rust/hedgewars-engine-messages/src/parser.rs	Sat Jun 26 00:13:28 2021 +0200
@@ -81,6 +81,7 @@
 named!(config_message<&[u8], ConfigEngineMessage>, alt!(
     do_parse!(tag!("C") >> (ConfigRequest))
     | do_parse!(tag!("eseed ") >> s: string_tail >> ( SetSeed(s)) )
+    | do_parse!(tag!("e$feature_size ") >> s: string_tail >> ( SetFeatureSize(s.parse::<u8>().unwrap())) )
 ));
 
 named!(timestamped_message<&[u8], (SyncedEngineMessage, u16)>,
--- a/rust/lib-hedgewars-engine/src/instance.rs	Fri Jun 25 22:34:26 2021 +0200
+++ b/rust/lib-hedgewars-engine/src/instance.rs	Sat Jun 26 00:13:28 2021 +0200
@@ -55,6 +55,7 @@
     fn process_config_message(&mut self, message: &ConfigEngineMessage) {
         match message {
             SetSeed(seed) => self.world.set_seed(seed.as_bytes()),
+            SetFeatureSize(feature_size) => self.world.set_feature_size(*feature_size),
             _ => unimplemented!(),
         }
     }
--- a/rust/lib-hedgewars-engine/src/world.rs	Fri Jun 25 22:34:26 2021 +0200
+++ b/rust/lib-hedgewars-engine/src/world.rs	Sat Jun 26 00:13:28 2021 +0200
@@ -27,6 +27,7 @@
 
 pub struct World {
     random_numbers_gen: LaggedFibonacciPRNG,
+    feature_size: u8,
     preview: Option<Land2D<u8>>,
     game_state: Option<GameState>,
     map_renderer: Option<MapRenderer>,
@@ -39,6 +40,7 @@
     pub fn new() -> Self {
         Self {
             random_numbers_gen: LaggedFibonacciPRNG::new(&[]),
+            feature_size: 5,
             preview: None,
             game_state: None,
             map_renderer: None,
@@ -73,6 +75,10 @@
         self.random_numbers_gen = LaggedFibonacciPRNG::new(seed);
     }
 
+    pub fn set_feature_size(&mut self, feature_size: u8) {
+        self.feature_size = feature_size;
+    }
+
     pub fn preview(&self) -> &Option<Land2D<u8>> {
         &self.preview
     }
@@ -91,7 +97,10 @@
             template
         }
 
-        let params = LandGenerationParameters::new(0u8, u8::max_value(), 5, false, false);
+        // based on old engine min_distance... dunno if this is the correct place tho
+        let distance_divisor = (self.feature_size as u32).pow(2) / 8 + 10;
+
+        let params = LandGenerationParameters::new(0u8, u8::max_value(), distance_divisor, false, false);
         let landgen = TemplatedLandGenerator::new(template());
         self.preview = Some(landgen.generate_land(&params, &mut self.random_numbers_gen));
     }