From adbcd5e474bad15d2a6f41c21fd58f6b77f0e7b0 Mon Sep 17 00:00:00 2001 From: SuperB3333 Date: Mon, 20 Jul 2026 21:20:10 +0200 Subject: [PATCH 1/7] Keep only one column and replaced -1 sentinels with NULL for compression --- inserter/src/generate_csv.rs | 18 ++++++------ inserter/src/init.sql | 56 +++++++++--------------------------- lookup/score_seeds.py | 2 +- 3 files changed, 23 insertions(+), 53 deletions(-) diff --git a/inserter/src/generate_csv.rs b/inserter/src/generate_csv.rs index afd7411..4c060bd 100644 --- a/inserter/src/generate_csv.rs +++ b/inserter/src/generate_csv.rs @@ -86,32 +86,30 @@ pub fn gen_formatted(seed: i32) -> Result<(String, String), Box; 16] = [None; 16]; + let mut vein_map: [Option<&data::vein::ActualVein>; 16] = [None; 16]; for v in veins.iter() { vein_map[v.vein_type as usize] = Some(v); } if planet.get_type() == &PlanetType::Gas { - for _ in 0..41 { - planets.push_str("-1,"); + for _ in 0..13 { + planets.push_str("NULL,"); } - planets.push_str("-1\n"); + planets.push_str("NULL\n"); } else { for (index, ore) in ORES[1..15].iter().enumerate() { if let Some(vein) = vein_map[*ore as usize] { - planets.push_str(format!("{},{},{}{}", - vein.min(), - vein.max(), - vein.estimate(), + planets.push_str(format!("{}{}", + vein.amount, if index == 13 { "\n" } else { "," } ).as_str()); } else { - planets.push_str(format!("-1,-1,-1{}", if index == 13 { "\n" } else { "," }).as_str()); + planets.push_str(format!("NULL{}", if index == 13 { "\n" } else { "," }).as_str()); } } } diff --git a/inserter/src/init.sql b/inserter/src/init.sql index 67707e8..088d25c 100644 --- a/inserter/src/init.sql +++ b/inserter/src/init.sql @@ -27,48 +27,20 @@ CREATE UNLOGGED TABLE stars ( CREATE UNLOGGED TABLE planets ( star_id INT, - estimate_iron INT, - estimate_copper INT, - estimate_silicium INT, - estimate_titanium INT, - estimate_stone INT, - estimate_coal INT, - estimate_oil INT, - estimate_fireice INT, - estimate_diamond INT, - estimate_fractal INT, - estimate_crysrub INT, - estimate_grat INT, - estimate_bamboo INT, - estimate_mag INT, - min_iron INT, - min_copper INT, - min_silicium INT, - min_titanium INT, - min_stone INT, - min_coal INT, - min_oil INT, - min_fireice INT, - min_diamond INT, - min_fractal INT, - min_crysrub INT, - min_grat INT, - min_bamboo INT, - min_mag INT, - max_iron INT, - max_copper INT, - max_silicium INT, - max_titanium INT, - max_stone INT, - max_coal INT, - max_oil INT, - max_fireice INT, - max_diamond INT, - max_fractal INT, - max_crysrub INT, - max_grat INT, - max_bamboo INT, - max_mag INT, + ore_iron INT, + ore_copper INT, + ore_silicium INT, + ore_titanium INT, + ore_stone INT, + ore_coal INT, + ore_oil INT, + ore_fireice INT, + ore_diamond INT, + ore_fractal INT, + ore_crysrub INT, + ore_grat INT, + ore_bamboo INT, + ore_mag INT, sun_distance REAL, temperature REAL, diff --git a/lookup/score_seeds.py b/lookup/score_seeds.py index 99f84fe..349d7a3 100644 --- a/lookup/score_seeds.py +++ b/lookup/score_seeds.py @@ -51,7 +51,7 @@ def _build_metrics(): metrics = {} for vein in veins: metrics[f"ore_{vein}"] = ( - f"SUM(GREATEST(p.estimate_{vein}, 0))", + f"SUM(COALESCE(p.estimate_{vein}))", f"Total estimated {vein} ore across the seed's planets " "(sentinel-guarded).", ) From e940a37f526690a1e2f5d04109080c6e54ace990 Mon Sep 17 00:00:00 2001 From: SuperB3333 Date: Mon, 20 Jul 2026 22:17:37 +0200 Subject: [PATCH 2/7] Small cleanup --- inserter/src/algorithm/data/planet.rs | 19 ++++++++++--------- inserter/src/algorithm/data/random.rs | 15 +++++++++++++++ inserter/src/algorithm/data/star.rs | 2 +- inserter/src/algorithm/worldgen/galaxy_gen.rs | 14 +------------- inserter/src/generate_csv.rs | 4 ++-- server/server.py | 1 + 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/inserter/src/algorithm/data/planet.rs b/inserter/src/algorithm/data/planet.rs index e00bec3..1c9edd4 100644 --- a/inserter/src/algorithm/data/planet.rs +++ b/inserter/src/algorithm/data/planet.rs @@ -286,6 +286,7 @@ impl<'a> Planet<'a> { } } + #[inline] pub fn is_tidal_locked(&self) -> bool { self.get_rotation_period() == self.get_orbital_period() } @@ -554,12 +555,12 @@ impl<'a> Planet<'a> { } let mut output: Vec = Vec::with_capacity(14); let mut rand1 = DspRandom::new(self.seed); - rand1.next_f64(); - rand1.next_f64(); - rand1.next_f64(); - rand1.next_f64(); - rand1.next_f64(); - rand1.next_f64(); + rand1.advance(); + rand1.advance(); + rand1.advance(); + rand1.advance(); + rand1.advance(); + rand1.advance(); let theme_proto = self.get_theme(); let mut vein_spots: Vec = (0..15_i32) .map(|i| *theme_proto.vein_spot.get((i - 1) as usize).unwrap_or(&0)) @@ -655,7 +656,7 @@ impl<'a> Planet<'a> { for index3 in 1..15 { let vein_spot_count = vein_spots[index3 as usize]; if vein_spot_count > 0 { - let vein_type: VeinType = unsafe { ::std::mem::transmute(index3) }; + let vein_type: VeinType = unsafe { std::mem::transmute(index3) }; let mut vein = EstimatedVein::new(); vein.vein_type = vein_type; vein.min_group = vein_spot_count - 1; @@ -999,7 +1000,7 @@ impl<'a> Planet<'a> { if vein_spot_count > 1 { vein_spot_count += rand2.next_i32(3) - 1; } - let vein_type: VeinType = unsafe { ::std::mem::transmute(index3) }; + let vein_type: VeinType = unsafe { std::mem::transmute(index3) }; let min_sq_dist = min_vein_spacing_sq * (if vein_type == VeinType::Oil { 100_f64 @@ -1136,7 +1137,7 @@ impl<'a> Planet<'a> { .enumerate() .filter(|(_, &amount)| amount > 0) .map(|(i, &amount)| ActualVein { - vein_type: unsafe { ::std::mem::transmute(i as i32) }, + vein_type: unsafe { std::mem::transmute(i as i32) }, amount, }) .collect() diff --git a/inserter/src/algorithm/data/random.rs b/inserter/src/algorithm/data/random.rs index 34343dd..d6118e5 100644 --- a/inserter/src/algorithm/data/random.rs +++ b/inserter/src/algorithm/data/random.rs @@ -82,6 +82,21 @@ impl DspRandom { self.seed_array[self.inext] = num; (num as f64) * (1.0 / (i32::MAX as f64)) } + pub fn advance(&mut self) { + self.inext += 1; + if self.inext >= 56 { + self.inext = 1 + } + self.inextp += 1; + if self.inextp >= 56 { + self.inextp = 1 + } + let mut num = self.seed_array[self.inext] - self.seed_array[self.inextp]; + if num < 0 { + num += i32::MAX; + } + self.seed_array[self.inext] = num; + } #[inline] pub fn next_f64(&mut self) -> f64 { diff --git a/inserter/src/algorithm/data/star.rs b/inserter/src/algorithm/data/star.rs index abb4388..0e23c63 100644 --- a/inserter/src/algorithm/data/star.rs +++ b/inserter/src/algorithm/data/star.rs @@ -321,7 +321,7 @@ impl<'a> Star<'a> { SpectrType::X } else { unsafe { - ::std::mem::transmute::( + std::mem::transmute::( self.get_class_factor().round_ties_even() as i32, ) } diff --git a/inserter/src/algorithm/worldgen/galaxy_gen.rs b/inserter/src/algorithm/worldgen/galaxy_gen.rs index 998d6e7..56941bd 100644 --- a/inserter/src/algorithm/worldgen/galaxy_gen.rs +++ b/inserter/src/algorithm/worldgen/galaxy_gen.rs @@ -202,16 +202,4 @@ pub fn create_galaxy<'a>( } Galaxy { seed, stars } -} - -pub fn find_stars(seed: i32, game_desc: &GameDesc, rule: &Box) -> u64 { - let habitable_count = Cell::new(0_i32); - let galaxy = Galaxy { - seed, - stars: generate_stars(seed, game_desc, &habitable_count), - }; - - let evaluation = Evaluation::new(game_desc.star_count); - let result = rule.evaluate(&galaxy, &evaluation); - result -} +} \ No newline at end of file diff --git a/inserter/src/generate_csv.rs b/inserter/src/generate_csv.rs index 4c060bd..8a623b3 100644 --- a/inserter/src/generate_csv.rs +++ b/inserter/src/generate_csv.rs @@ -3,7 +3,7 @@ use crate::algorithm::data::enums::{PlanetType, ORES}; use crate::algorithm::data::game_desc::GameDesc; use crate::algorithm::worldgen::galaxy_gen::create_galaxy; -pub fn gen_formatted(seed: i32) -> Result<(String, String), Box> { +pub fn gen_formatted(seed: i32) -> anyhow::Result<(String, String)> { let game_desc: GameDesc = GameDesc { star_count: crate::STAR_COUNT, resource_multiplier: crate::REC_MULTIPLIER, @@ -83,7 +83,7 @@ pub fn gen_formatted(seed: i32) -> Result<(String, String), Box Date: Mon, 20 Jul 2026 22:18:50 +0200 Subject: [PATCH 3/7] Small cleanup --- inserter/src/misc.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inserter/src/misc.rs b/inserter/src/misc.rs index 57d55d3..dcc05ec 100644 --- a/inserter/src/misc.rs +++ b/inserter/src/misc.rs @@ -134,6 +134,9 @@ impl Timer { pub fn is_ready(&self) -> bool { Instant::now().duration_since(self.last) >= self.interval } + + // no inspection for the function taking a mutable reference + //noinspection ALL pub fn is_ready_autoreset(&mut self) -> bool { if !self.is_ready() { return false } self.reset(); From 5a5b6044d3b27e61a2ed1da8a813e261edda0421 Mon Sep 17 00:00:00 2001 From: SuperB3333 Date: Thu, 23 Jul 2026 10:55:34 +0200 Subject: [PATCH 4/7] Removed serde dependency and removed name generation and dead rule.rs file. Should achieve smaller binary --- inserter/Cargo.toml | 1 - inserter/src/algorithm/data/enums.rs | 12 +- inserter/src/algorithm/data/galaxy.rs | 8 - inserter/src/algorithm/data/game_desc.rs | 22 +- inserter/src/algorithm/data/mod.rs | 2 - inserter/src/algorithm/data/planet.rs | 31 +- inserter/src/algorithm/data/random.rs | 2 +- inserter/src/algorithm/data/rule.rs | 141 ---- inserter/src/algorithm/data/star.rs | 25 - inserter/src/algorithm/data/star_planets.rs | 22 +- inserter/src/algorithm/data/theme_proto.rs | 17 +- inserter/src/algorithm/data/vector2.rs | 4 +- inserter/src/algorithm/data/vector3.rs | 4 +- inserter/src/algorithm/data/vein.rs | 7 +- inserter/src/algorithm/worldgen/galaxy_gen.rs | 23 +- inserter/src/algorithm/worldgen/mod.rs | 1 - inserter/src/algorithm/worldgen/name_gen.rs | 728 ------------------ inserter/src/generate_csv.rs | 6 +- 18 files changed, 18 insertions(+), 1038 deletions(-) delete mode 100644 inserter/src/algorithm/data/galaxy.rs delete mode 100644 inserter/src/algorithm/data/rule.rs delete mode 100644 inserter/src/algorithm/worldgen/name_gen.rs diff --git a/inserter/Cargo.toml b/inserter/Cargo.toml index 17da83e..ee10a2c 100644 --- a/inserter/Cargo.toml +++ b/inserter/Cargo.toml @@ -27,7 +27,6 @@ crate-type = ["cdylib"] # Dependencies for all builds [dependencies] once_cell = "1.19.0" -serde = { version = "1.0.193", features = ["derive", "rc"] } # Dependencies for binary crossbeam-channel = { version = "0.5.15", optional = true } diff --git a/inserter/src/algorithm/data/enums.rs b/inserter/src/algorithm/data/enums.rs index 67e0095..3a1bb36 100644 --- a/inserter/src/algorithm/data/enums.rs +++ b/inserter/src/algorithm/data/enums.rs @@ -1,8 +1,6 @@ -use serde::{Deserialize, Serialize}; - #[allow(dead_code)] #[repr(i32)] -#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum StarType { MainSeqStar, GiantStar, @@ -19,7 +17,7 @@ impl Default for StarType { #[allow(dead_code)] #[repr(i32)] -#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum SpectrType { M = -4, K = -3, @@ -33,7 +31,7 @@ pub enum SpectrType { #[allow(dead_code)] #[repr(i32)] -#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum PlanetType { None, Volcano, @@ -51,7 +49,7 @@ impl Default for PlanetType { #[allow(dead_code)] #[repr(i32)] -#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum ThemeDistribute { Default, Birth, @@ -67,7 +65,7 @@ impl Default for ThemeDistribute { #[allow(dead_code)] #[repr(i32)] -#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum VeinType { None, Iron, diff --git a/inserter/src/algorithm/data/galaxy.rs b/inserter/src/algorithm/data/galaxy.rs deleted file mode 100644 index 0757c9c..0000000 --- a/inserter/src/algorithm/data/galaxy.rs +++ /dev/null @@ -1,8 +0,0 @@ -use super::star_planets::StarWithPlanets; -use serde::Serialize; - -#[derive(Debug, Serialize)] -pub struct Galaxy<'a> { - pub seed: i32, - pub stars: Vec>, -} diff --git a/inserter/src/algorithm/data/game_desc.rs b/inserter/src/algorithm/data/game_desc.rs index c075c98..fa9ebc0 100644 --- a/inserter/src/algorithm/data/game_desc.rs +++ b/inserter/src/algorithm/data/game_desc.rs @@ -1,33 +1,13 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] +#[derive(Debug, Clone, Copy)] pub struct GameDesc { - #[serde(default = "GameDesc::default_star_count")] pub star_count: usize, - #[serde(default = "GameDesc::default_resource_multiplier")] pub resource_multiplier: f32, - #[serde(default = "GameDesc::default_hive_initial_colonize")] pub hive_initial_colonize: f64, - #[serde(default = "GameDesc::default_hive_max_density")] pub hive_max_density: f64, - #[serde(default)] pub use_actual_veins: bool, } impl GameDesc { - pub fn default_star_count() -> usize { - 64 - } - pub fn default_resource_multiplier() -> f32 { - 1.0 - } - pub fn default_hive_initial_colonize() -> f64 { - 1.0 - } - pub fn default_hive_max_density() -> f64 { - 1.0 - } pub fn is_infinite_resource(&self) -> bool { self.resource_multiplier >= 99.5 diff --git a/inserter/src/algorithm/data/mod.rs b/inserter/src/algorithm/data/mod.rs index 1665ad4..dfc1781 100644 --- a/inserter/src/algorithm/data/mod.rs +++ b/inserter/src/algorithm/data/mod.rs @@ -1,6 +1,5 @@ pub mod birth_points; pub mod enums; -pub mod galaxy; pub mod game_desc; pub mod math; pub mod planet; @@ -11,7 +10,6 @@ pub mod pose; pub mod quaternion; pub mod random; pub mod random_table; -pub mod rule; pub mod simplex_noise; pub mod star; pub mod star_planets; diff --git a/inserter/src/algorithm/data/planet.rs b/inserter/src/algorithm/data/planet.rs index 1c9edd4..98a07ea 100644 --- a/inserter/src/algorithm/data/planet.rs +++ b/inserter/src/algorithm/data/planet.rs @@ -11,7 +11,6 @@ use super::star::Star; use super::theme_proto::{ThemeProto, THEME_PROTOS}; use super::vector_f3::VectorF3; use super::vein::{ActualVein, EstimatedVein}; -use serde::ser::{Serialize, SerializeStruct, Serializer}; use std::cell::{Cell, OnceCell, RefCell}; use std::f64::consts::PI; use std::rc::Rc; @@ -1215,32 +1214,4 @@ const SEGMENT_TABLE: [i32; 512] = [ 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, -]; - -impl Serialize for Planet<'_> { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut state = serializer.serialize_struct("Planet", 15)?; - state.serialize_field("index", &self.index)?; - state.serialize_field("orbitAround", &self.orbit_around.borrow().map(|p| p.index))?; - state.serialize_field("orbitIndex", &self.orbit_index)?; - state.serialize_field("orbitRadius", &self.get_orbital_radius())?; - state.serialize_field("orbitInclination", &self.get_orbit_inclination())?; - state.serialize_field("orbitLongitude", &self.orbit_longitude)?; - state.serialize_field("orbitalPeriod", &self.get_orbital_period())?; - state.serialize_field("obliquity", &self.get_obliquity())?; - state.serialize_field("rotationPeriod", &self.get_rotation_period())?; - state.serialize_field("type", &self.get_type())?; - state.serialize_field("luminosity", &self.get_luminosity())?; - state.serialize_field("theme", &self.get_theme())?; - state.serialize_field("gases", &self.get_gases())?; - if self.game_desc.use_actual_veins { - state.serialize_field("actualVeins", &self.get_actual_veins())?; - } else { - state.serialize_field("veins", &self.get_estimated_veins())?; - } - state.end() - } -} +]; \ No newline at end of file diff --git a/inserter/src/algorithm/data/random.rs b/inserter/src/algorithm/data/random.rs index d6118e5..fca5822 100644 --- a/inserter/src/algorithm/data/random.rs +++ b/inserter/src/algorithm/data/random.rs @@ -1,4 +1,4 @@ -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub struct DspRandom { inext: usize, inextp: usize, diff --git a/inserter/src/algorithm/data/rule.rs b/inserter/src/algorithm/data/rule.rs deleted file mode 100644 index 4624951..0000000 --- a/inserter/src/algorithm/data/rule.rs +++ /dev/null @@ -1,141 +0,0 @@ -use super::galaxy::Galaxy; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -#[serde(tag = "type", content = "value")] -pub enum Condition { - Eq(f32), - Neq(f32), - Lt(f32), - Lte(f32), - Gt(f32), - Gte(f32), - Between(f32, f32), - NotBetween(f32, f32), -} - -impl Condition { - pub fn eval(&self, value: f32) -> bool { - match self { - Condition::Eq(f) => value == *f, - Condition::Neq(f) => value != *f, - Condition::Lt(f) => value < *f, - Condition::Lte(f) => value <= *f, - Condition::Gt(f) => value > *f, - Condition::Gte(f) => value >= *f, - Condition::Between(f1, f2) => *f1 <= value && value <= *f2, - Condition::NotBetween(f1, f2) => *f1 > value || value > *f2, - } - } -} - -#[macro_export] -macro_rules! evaluate_safe { - ($galaxy:expr, $evaluation:expr, |$sp:ident| $logic:expr) => {{ - let mut result: u64 = 0; - for (index, $sp) in $galaxy.stars.iter().take($evaluation.get_len()).enumerate() { - if $evaluation.is_known(index) { - continue; - } - if $logic { - result |= 1 << index; - } - } - result - }}; -} - -#[macro_export] -macro_rules! evaluate_unsafe { - ($galaxy:expr, $evaluation:expr, |$sp:ident| $logic:expr) => {{ - let mut result: u64 = 0; - for (index, $sp) in $galaxy.stars.iter().take($evaluation.get_len()).enumerate() { - if $evaluation.is_known(index) { - if !$sp.is_safe() { - $sp.load_planets() - } - continue; - } - - if $logic { - result |= 1 << index; - } - $sp.mark_safe(); - } - result - }}; -} - -#[allow(unused_variables)] -pub trait Rule { - fn get_priority(&self) -> i32 { - 0 - } - - fn evaluate(&self, galaxy: &Galaxy, evaluation: &Evaluation) -> u64 { - 0 - } -} - -#[derive(Debug, Clone, Copy)] -pub struct Evaluation { - value: u64, - unknown: u64, - max_len: usize, -} - -impl Evaluation { - pub fn new(size: usize) -> Self { - Self { - value: 0, - unknown: u64::MAX >> (u64::BITS - size as u32), - max_len: size, - } - } - - #[inline] - pub fn is_known(&self, index: usize) -> bool { - (self.unknown & (1 << index)) == 0 - } - - /// Returns the minium number of stars that still needs to be evaluated - /// Useful for unsafe rules - #[inline] - pub fn get_len(&self) -> usize { - self.max_len - } - - #[inline] - fn load_max_len(&mut self) { - self.max_len = (u64::BITS - self.unknown.leading_zeros()) as usize; - } - - #[inline] - pub fn accept_many(&mut self, indices: u64) { - self.value |= self.unknown & indices; - self.unknown &= !indices; - self.load_max_len(); - } - - #[inline] - pub fn reject_others(&mut self, indices: u64) { - self.value &= !self.unknown | indices; - self.unknown &= indices; - self.load_max_len(); - } - - #[inline] - pub fn collect_known(&self) -> u64 { - !self.unknown & self.value - } - - #[inline] - pub fn collect_unknown(&self) -> u64 { - self.unknown | self.value - } - - #[inline] - pub fn is_done(&self) -> bool { - self.max_len == 0 - } -} diff --git a/inserter/src/algorithm/data/star.rs b/inserter/src/algorithm/data/star.rs index 0e23c63..a4280d4 100644 --- a/inserter/src/algorithm/data/star.rs +++ b/inserter/src/algorithm/data/star.rs @@ -2,7 +2,6 @@ use super::enums::{SpectrType, StarType}; use super::game_desc::GameDesc; use super::random::DspRandom; use super::vector3::Vector3; -use serde::ser::{Serialize, SerializeStruct, Serializer}; use std::cell::{OnceCell, RefCell}; use std::f64::consts::PI; @@ -594,30 +593,6 @@ impl<'a> Star<'a> { } } -impl Serialize for Star<'_> { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut state = serializer.serialize_struct("Star", 14)?; - state.serialize_field("index", &self.index)?; - state.serialize_field("position", &self.position)?; - state.serialize_field("mass", &self.get_mass())?; - state.serialize_field("lifetime", &self.get_lifetime())?; - state.serialize_field("age", &self.get_age())?; - state.serialize_field("temperature", &self.get_temperature())?; - state.serialize_field("type", &self.star_type)?; - state.serialize_field("spectr", &self.get_spectr())?; - state.serialize_field("luminosity", &self.get_luminosity())?; - state.serialize_field("radius", &self.get_radius())?; - state.serialize_field("dysonRadius", &self.get_dyson_radius())?; - state.serialize_field("initialHiveCount", &self.get_initial_hive_count())?; - state.serialize_field("maxHiveCount", &self.get_max_hive_count())?; - state.serialize_field("color", &self.get_color())?; - state.end() - } -} - fn rand_normal(average_value: f32, standard_deviation: f32, r1: f64, r2: f64) -> f32 { average_value + standard_deviation * ((-2.0 * (1.0 - r1).ln()).sqrt() * (2.0 * PI * r2).sin()) as f32 diff --git a/inserter/src/algorithm/data/star_planets.rs b/inserter/src/algorithm/data/star_planets.rs index b443823..e70c77f 100644 --- a/inserter/src/algorithm/data/star_planets.rs +++ b/inserter/src/algorithm/data/star_planets.rs @@ -7,37 +7,18 @@ use super::enums::{SpectrType, StarType, VeinType}; use super::planet::Planet; use super::random::DspRandom; use super::star::Star; -use serde::Serialize; - -pub fn serialize_planets( - planets: &UnsafeCell>>, - serializer: S, -) -> Result -where - S: serde::Serializer, -{ - unsafe { &*planets.get() }.serialize(serializer) -} const MAX_VEIN_COUNT: usize = VeinType::Max as usize; -#[derive(Debug, Serialize)] +#[derive(Debug)] pub struct StarWithPlanets<'a> { - pub name: String, - #[serde(flatten)] pub star: Rc>, - #[serde(serialize_with = "serialize_planets")] planets: UnsafeCell>>, - #[serde(skip)] safe: UnsafeCell, - #[serde(skip)] avg_veins: UnsafeCell<[f32; MAX_VEIN_COUNT]>, - #[serde(skip)] actual_veins: UnsafeCell<[f32; MAX_VEIN_COUNT]>, - #[serde(skip)] game_desc: &'a GameDesc, - #[serde(skip)] habitable_count: &'a Cell, } @@ -53,7 +34,6 @@ impl<'a> StarWithPlanets<'a> { safe: UnsafeCell::new(false), avg_veins: UnsafeCell::new([f32::NAN; MAX_VEIN_COUNT]), actual_veins: UnsafeCell::new([f32::NAN; MAX_VEIN_COUNT]), - name: Default::default(), game_desc, habitable_count, } diff --git a/inserter/src/algorithm/data/theme_proto.rs b/inserter/src/algorithm/data/theme_proto.rs index 61e0038..6f2abbf 100644 --- a/inserter/src/algorithm/data/theme_proto.rs +++ b/inserter/src/algorithm/data/theme_proto.rs @@ -2,40 +2,25 @@ use crate::algorithm::data::vector2::Vector2; use super::enums::{PlanetType, ThemeDistribute, VeinType}; use once_cell::sync::Lazy; -use serde::Serialize; -#[derive(Debug, Clone, Serialize)] -#[serde(rename_all = "camelCase")] +#[derive(Debug, Clone)] pub struct ThemeProto { pub id: i32, pub name: &'static str, pub wind: f32, pub water_item_id: i32, - #[serde(skip)] pub distribute: ThemeDistribute, - #[serde(skip)] pub temperature: f32, - #[serde(skip)] pub planet_type: PlanetType, - #[serde(skip)] pub vein_spot: Vec, - #[serde(skip)] pub vein_count: Vec, - #[serde(skip)] pub vein_opacity: Vec, - #[serde(skip)] pub rare_veins: Vec, - #[serde(skip)] pub rare_settings: Vec, - #[serde(skip)] pub gas_items: Vec, - #[serde(skip)] pub gas_speeds: Vec, - #[serde(skip)] pub algos: Vec, - #[serde(skip)] pub mod_x: Vector2, - #[serde(skip)] pub mod_y: Vector2, } diff --git a/inserter/src/algorithm/data/vector2.rs b/inserter/src/algorithm/data/vector2.rs index c280122..0edc7c2 100644 --- a/inserter/src/algorithm/data/vector2.rs +++ b/inserter/src/algorithm/data/vector2.rs @@ -1,4 +1,2 @@ -use serde::Serialize; - -#[derive(Debug, PartialEq, Clone, Copy, Serialize)] +#[derive(Debug, PartialEq, Clone, Copy)] pub struct Vector2(pub f64, pub f64); diff --git a/inserter/src/algorithm/data/vector3.rs b/inserter/src/algorithm/data/vector3.rs index 44cb648..76f68f6 100644 --- a/inserter/src/algorithm/data/vector3.rs +++ b/inserter/src/algorithm/data/vector3.rs @@ -1,6 +1,4 @@ -use serde::Serialize; - -#[derive(Debug, PartialEq, Clone, Copy, Serialize)] +#[derive(Debug, PartialEq, Clone, Copy)] pub struct Vector3(pub f64, pub f64, pub f64); impl Vector3 { diff --git a/inserter/src/algorithm/data/vein.rs b/inserter/src/algorithm/data/vein.rs index 1fc81a8..9275332 100644 --- a/inserter/src/algorithm/data/vein.rs +++ b/inserter/src/algorithm/data/vein.rs @@ -1,8 +1,6 @@ use super::enums::VeinType; -use serde::Serialize; -#[derive(Debug, Clone, Serialize)] -#[serde(rename_all = "camelCase")] +#[derive(Debug, Clone)] pub struct EstimatedVein { pub vein_type: VeinType, pub min_group: i32, @@ -45,8 +43,7 @@ impl EstimatedVein { } } -#[derive(Debug, Clone, Serialize)] -#[serde(rename_all = "camelCase")] +#[derive(Debug, Clone)] pub struct ActualVein { pub vein_type: VeinType, pub amount: i32, // times 4e-5 for oil diff --git a/inserter/src/algorithm/worldgen/galaxy_gen.rs b/inserter/src/algorithm/worldgen/galaxy_gen.rs index 56941bd..50e7906 100644 --- a/inserter/src/algorithm/worldgen/galaxy_gen.rs +++ b/inserter/src/algorithm/worldgen/galaxy_gen.rs @@ -1,9 +1,6 @@ -use super::name_gen::random_name; use crate::algorithm::data::enums::{SpectrType, StarType}; -use crate::algorithm::data::galaxy::Galaxy; use crate::algorithm::data::game_desc::GameDesc; use crate::algorithm::data::random::DspRandom; -use crate::algorithm::data::rule::{Evaluation, Rule}; use crate::algorithm::data::star::Star; use crate::algorithm::data::star_planets::StarWithPlanets; use crate::algorithm::data::vector3::Vector3; @@ -102,7 +99,7 @@ fn check_collision(tmp_poses: &Vec, pt: &Vector3) -> bool { .any(|existing_point| existing_point.distance_sq_from(pt) < MIN_DIST_SQ) } -fn generate_stars<'a>( +pub fn generate_stars<'a>( seed: i32, game_desc: &'a GameDesc, habitable_count: &'a Cell, @@ -185,21 +182,3 @@ fn generate_stars<'a>( } stars } - -pub fn create_galaxy<'a>( - seed: i32, - game_desc: &'a GameDesc, - habitable_count: &'a Cell, -) -> Galaxy<'a> { - let mut stars = generate_stars(seed, game_desc, habitable_count); - let mut names: Vec<&str> = Vec::with_capacity(game_desc.star_count); - - for sp in stars.iter_mut() { - let name = random_name(sp.star.name_seed, &sp.star, names.iter()); - sp.name = name; - names.push(&sp.name); - sp.load_planets(); - } - - Galaxy { seed, stars } -} \ No newline at end of file diff --git a/inserter/src/algorithm/worldgen/mod.rs b/inserter/src/algorithm/worldgen/mod.rs index 738ba9a..9d71d3e 100644 --- a/inserter/src/algorithm/worldgen/mod.rs +++ b/inserter/src/algorithm/worldgen/mod.rs @@ -1,2 +1 @@ pub mod galaxy_gen; -mod name_gen; diff --git a/inserter/src/algorithm/worldgen/name_gen.rs b/inserter/src/algorithm/worldgen/name_gen.rs deleted file mode 100644 index 2c5b93d..0000000 --- a/inserter/src/algorithm/worldgen/name_gen.rs +++ /dev/null @@ -1,728 +0,0 @@ -use crate::algorithm::data::enums::StarType; -use crate::algorithm::data::random::DspRandom; -use crate::algorithm::data::star::Star; - -fn gen_random_name(seed: i32, star: &Star) -> String { - let mut rand = DspRandom::new(seed); - let seed1 = rand.next_seed(); - let num1 = rand.next_f64(); - if star.star_type == StarType::GiantStar { - let num2 = rand.next_f64(); - if num2 < 0.4 { - random_giant_star_name_from_raw_names(seed1) - } else if num2 < 0.7 { - random_giant_star_name_with_constellation_alpha(seed1) - } else { - random_giant_star_name_with_format(seed1) - } - } else if star.star_type == StarType::NeutronStar { - random_neutron_star_name_with_format(seed1) - } else if star.star_type == StarType::BlackHole { - random_black_hole_name_with_format(seed1) - } else if num1 < 0.6 { - random_star_name_from_raw_names(seed1) - } else if num1 < 0.93 { - random_star_name_with_constellation_alpha(seed1) - } else { - random_star_name_with_constellation_number(seed1) - } -} - -pub fn random_name<'a>( - seed: i32, - star: &Star, - mut names: impl Iterator, -) -> String { - let mut rand = DspRandom::new(seed); - for _ in 0..256 { - let str = gen_random_name(rand.next_seed(), star); - if names.all(|s| *s != str) { - return str; - } - } - return "XStar".to_owned(); -} - -fn random_giant_star_name_with_constellation_alpha(seed: i32) -> String { - let mut rand = DspRandom::new(seed); - let num1 = rand.next_usize(); - let num2 = rand.next_i32(11) + 15; - let num3 = rand.next_i32(26); - let index = num1 % CONSTELLATIONS.len(); - (130 + num2 + num3).to_string() + " " + CONSTELLATIONS[index] -} - -fn random_giant_star_name_with_format(seed: i32) -> String { - let mut rand = DspRandom::new(seed); - let num1 = rand.next_usize(); - let num2 = rand.next_i32(10000); - let num3 = rand.next_i32(100); - let index = num1 % GIANT_NAME_FORMATS.len(); - GIANT_NAME_FORMATS[index](num2, num3) -} - -fn random_neutron_star_name_with_format(seed: i32) -> String { - let mut rand = DspRandom::new(seed); - let num1 = rand.next_usize(); - let num2 = rand.next_i32(24); - let num3 = rand.next_i32(60); - let num4 = rand.next_i32(60); - let index = num1 % NEUTRON_STAR_NAME_FORMATS.len(); - NEUTRON_STAR_NAME_FORMATS[index](num2, num3, num4) -} - -fn random_black_hole_name_with_format(seed: i32) -> String { - let mut rand = DspRandom::new(seed); - let num1 = rand.next_usize(); - let num2 = rand.next_i32(24); - let num3 = rand.next_i32(60); - let num4 = rand.next_i32(60); - let index = num1 % BLACK_HOLE_NAME_FORMATS.len(); - BLACK_HOLE_NAME_FORMATS[index](num2, num3, num4) -} - -fn random_star_name_from_raw_names(seed: i32) -> String { - let mut rand = DspRandom::new(seed); - let index = (rand.next_usize()) % RAW_STAR_NAMES.len(); - RAW_STAR_NAMES[index].to_owned() -} - -fn random_star_name_with_constellation_alpha(seed: i32) -> String { - let mut rand = DspRandom::new(seed); - let num1 = rand.next_usize(); - let num2 = rand.next_usize(); - let index1 = num1 % CONSTELLATIONS.len(); - let index2 = num2 % ALPHABETA.len(); - let constellation = CONSTELLATIONS[index1]; - if constellation.len() > 10 { - ALPHABETA_LETTER[index2].to_owned() + " " + constellation - } else { - ALPHABETA[index2].to_owned() + " " + constellation - } -} - -fn random_star_name_with_constellation_number(seed: i32) -> String { - let mut rand = DspRandom::new(seed); - let num1 = rand.next_usize(); - let num2 = rand.next_i32(48) + 27; - let index = num1 % CONSTELLATIONS.len(); - num2.to_string() + " " + CONSTELLATIONS[index] -} - -fn random_giant_star_name_from_raw_names(seed: i32) -> String { - let mut rand = DspRandom::new(seed); - let index = (rand.next_usize()) % RAW_GIANT_NAMES.len(); - RAW_GIANT_NAMES[index].to_owned() -} - -type Fn2 = fn(i1: i32, i2: i32) -> String; -type Fn3 = fn(i1: i32, i2: i32, i3: i32) -> String; - -const GIANT_NAME_FORMATS: &'static [Fn2] = &[ - |i1, i2| format!("HD {:04}{:02}", i1, i2), - |i1, i2| format!("HDE {:04}{:02}", i1, i2), - |i1, _| format!("HR {:04}", i1), - |i1, _| format!("HV {:04}", i1), - |i1, i2| format!("LBV {:04}-{:02}", i1, i2), - |i1, _| format!("NSV {:04}", i1), - |i1, i2| format!("YSC {:04}-{:02}", i1, i2), -]; - -const NEUTRON_STAR_NAME_FORMATS: &'static [Fn3] = &[ - |i1, i2, i3| format!("NTR J{:02}{:02}+{:02}", i1, i2, i3), - |i1, i2, i3| format!("NTR J{:02}{:02}-{:02}", i1, i2, i3), -]; - -const BLACK_HOLE_NAME_FORMATS: &'static [Fn3] = &[ - |i1, i2, i3| format!("DSR J{:02}{:02}+{:02}", i1, i2, i3), - |i1, i2, i3| format!("DSR J{:02}{:02}-{:02}", i1, i2, i3), -]; - -const RAW_GIANT_NAMES: &'static [&'static str] = &[ - "AH Scorpii", - "Aldebaran", - "Alpha Herculis", - "Antares", - "Arcturus", - "AV Persei", - "BC Cygni", - "Betelgeuse", - "BI Cygni", - "BO Carinae", - "Canopus", - "CE Tauri", - "CK Carinae", - "CW Leonis", - "Deneb", - "Epsilon Aurigae", - "Eta Carinae", - "EV Carinae", - "IX Carinae", - "KW Sagittarii", - "KY Cygni", - "Mira", - "Mu Cephei", - "NML Cygni", - "NR Vulpeculae", - "PZ Cassiopeiae", - "R Doradus", - "R Leporis", - "Rho Cassiopeiae", - "Rigel", - "RS Persei", - "RT Carinae", - "RU Virginis", - "RW Cephei", - "S Cassiopeiae", - "S Cephei", - "S Doradus", - "S Persei", - "SU Persei", - "TV Geminorum", - "U Lacertae", - "UY Scuti", - "V1185 Scorpii", - "V354 Cephei", - "V355 Cepheus", - "V382 Carinae", - "V396 Centauri", - "V437 Scuti", - "V509 Cassiopeiae", - "V528 Carinae", - "V602 Carinae", - "V648 Cassiopeiae", - "V669 Cassiopeiae", - "V838 Monocerotis", - "V915 Scorpii", - "VV Cephei", - "VX Sagittarii", - "VY Canis Majoris", - "WOH G64", - "XX Persei", -]; - -const ALPHABETA: &'static [&'static str] = &[ - "Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa", "Lambda", -]; - -const ALPHABETA_LETTER: &'static [&'static str] = - &["α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ"]; - -const CONSTELLATIONS: &'static [&'static str] = &[ - "Andromedae", - "Antliae", - "Apodis", - "Aquarii", - "Aquilae", - "Arae", - "Arietis", - "Aurigae", - "Bootis", - "Caeli", - "Camelopardalis", - "Cancri", - "Canum Venaticorum", - "Canis Majoris", - "Canis Minoris", - "Capricorni", - "Carinae", - "Cassiopeiae", - "Centauri", - "Cephei", - "Ceti", - "Chamaeleontis", - "Circini", - "Columbae", - "Comae Berenices", - "Coronae Australis", - "Coronae Borealis", - "Corvi", - "Crateris", - "Crucis", - "Cygni", - "Delphini", - "Doradus", - "Draconis", - "Equulei", - "Eridani", - "Fornacis", - "Geminorum", - "Gruis", - "Herculis", - "Horologii", - "Hydrae", - "Hydri", - "Indi", - "Lacertae", - "Leonis", - "Leonis Minoris", - "Leporis", - "Librae", - "Lupi", - "Lyncis", - "Lyrae", - "Mensae", - "Microscopii", - "Monocerotis", - "Muscae", - "Normae", - "Octantis", - "Ophiuchii", - "Orionis", - "Pavonis", - "Pegasi", - "Persei", - "Phoenicis", - "Pictoris", - "Piscium", - "Piscis Austrini", - "Puppis", - "Pyxidis", - "Reticuli", - "Sagittae", - "Sagittarii", - "Scorpii", - "Sculptoris", - "Scuti", - "Serpentis", - "Sextantis", - "Tauri", - "Telescopii", - "Trianguli", - "Trianguli Australis", - "Tucanae", - "Ursae Majoris", - "Ursae Minoris", - "Velorum", - "Virginis", - "Volantis", - "Vulpeculae", -]; - -const RAW_STAR_NAMES: &'static [&'static str] = &[ - "Acamar", - "Achernar", - "Achird", - "Acrab", - "Acrux", - "Acubens", - "Adhafera", - "Adhara", - "Adhil", - "Agena", - "Aladfar", - "Albaldah", - "Albali", - "Albireo", - "Alchiba", - "Alcor", - "Alcyone", - "Alderamin", - "Aldhibain", - "Aldib", - "Alfecca", - "Alfirk", - "Algedi", - "Algenib", - "Algenubi", - "Algieba", - "Algjebbath", - "Algol", - "Algomeyla", - "Algorab", - "Alhajoth", - "Alhena", - "Alifa", - "Alioth", - "Alkaid", - "Alkalurops", - "Alkaphrah", - "Alkes", - "Alkhiba", - "Almach", - "Almeisan", - "Almuredin", - "AlNa'ir", - "Alnasl", - "Alnilam", - "Alnitak", - "Alniyat", - "Alphard", - "Alphecca", - "Alpheratz", - "Alrakis", - "Alrami", - "Alrescha", - "AlRijil", - "Alsahm", - "Alsciaukat", - "Alshain", - "Alshat", - "Alshemali", - "Alsuhail", - "Altair", - "Altais", - "Alterf", - "Althalimain", - "AlTinnin", - "Aludra", - "AlulaAustralis", - "AlulaBorealis", - "Alwaid", - "Alwazn", - "Alya", - "Alzirr", - "AmazonStar", - "Ancha", - "Anchat", - "AngelStern", - "Angetenar", - "Ankaa", - "Anser", - "Antecanis", - "Apollo", - "Arich", - "Arided", - "Arietis", - "Arkab", - "ArkebPrior", - "Arneb", - "Arrioph", - "AsadAustralis", - "Ascella", - "Aschere", - "AsellusAustralis", - "AsellusBorealis", - "AsellusPrimus", - "Ashtaroth", - "Asmidiske", - "Aspidiske", - "Asterion", - "Asterope", - "Asuia", - "Athafiyy", - "Atik", - "Atlas", - "Atria", - "Auva", - "Avior", - "Azelfafage", - "Azha", - "Azimech", - "BatenKaitos", - "Becrux", - "Beid", - "Bellatrix", - "Benatnasch", - "Biham", - "Botein", - "Brachium", - "Bunda", - "Cajam", - "Calbalakrab", - "Calx", - "Canicula", - "Capella", - "Caph", - "Castor", - "Castula", - "Cebalrai", - "Ceginus", - "Celaeno", - "Chara", - "Chertan", - "Choo", - "Clava", - "CorCaroli", - "CorHydrae", - "CorLeonis", - "Cornu", - "CorScorpii", - "CorSepentis", - "CorTauri", - "Coxa", - "Cursa", - "Cymbae", - "Cynosaura", - "Dabih", - "DenebAlgedi", - "DenebDulfim", - "DenebelOkab", - "DenebKaitos", - "DenebOkab", - "Denebola", - "Dhalim", - "Dhur", - "Diadem", - "Difda", - "DifdaalAuwel", - "Dnoces", - "Dubhe", - "Dziban", - "Dzuba", - "Edasich", - "ElAcola", - "Elacrab", - "Electra", - "Elgebar", - "Elgomaisa", - "ElKaprah", - "ElKaridab", - "Elkeid", - "ElKhereb", - "Elmathalleth", - "Elnath", - "ElPhekrah", - "Eltanin", - "Enif", - "Erakis", - "Errai", - "FalxItalica", - "Fidis", - "Fomalhaut", - "Fornacis", - "FumAlSamakah", - "Furud", - "Gacrux", - "Gallina", - "GarnetStar", - "Gemma", - "Genam", - "Giausar", - "GiedePrime", - "Giedi", - "Gienah", - "Gienar", - "Gildun", - "Girtab", - "Gnosia", - "Gomeisa", - "Gorgona", - "Graffias", - "Hadar", - "Hamal", - "Haris", - "Hasseleh", - "Hastorang", - "Hatysa", - "Heka", - "Hercules", - "Heze", - "Hoedus", - "Homam", - "HyadumPrimus", - "Icalurus", - "Iclarkrav", - "Izar", - "Jabbah", - "Jewel", - "Jugum", - "Juza", - "Kabeleced", - "Kaff", - "Kaffa", - "Kaffaljidma", - "Kaitain", - "KalbalAkrab", - "Kat", - "KausAustralis", - "KausBorealis", - "KausMedia", - "Keid", - "KeKouan", - "Kelb", - "Kerb", - "Kerbel", - "KiffaBoraelis", - "Kitalpha", - "Kochab", - "Kornephoros", - "Kraz", - "Ksora", - "Kuma", - "Kurhah", - "Kursa", - "Lesath", - "Maasym", - "Maaz", - "Mabsuthat", - "Maia", - "Marfik", - "Markab", - "Marrha", - "Matar", - "Mebsuta", - "Megres", - "Meissa", - "Mekbuda", - "Menkalinan", - "Menkar", - "Menkent", - "Menkib", - "Merak", - "Meres", - "Merga", - "Meridiana", - "Merope", - "Mesartim", - "Metallah", - "Miaplacidus", - "Mimosa", - "Minelauva", - "Minkar", - "Mintaka", - "Mirac", - "Mirach", - "Miram", - "Mirfak", - "Mirzam", - "Misam", - "Mismar", - "Mizar", - "Muhlifain", - "Muliphein", - "Muphrid", - "Muscida", - "NairalSaif", - "NairalZaurak", - "Naos", - "Nash", - "Nashira", - "Navi", - "Nekkar", - "Nicolaus", - "Nihal", - "Nodus", - "Nunki", - "Nusakan", - "OculusBoreus", - "Okda", - "Osiris", - "OsPegasi", - "Palilicium", - "Peacock", - "Phact", - "Phecda", - "Pherkad", - "PherkadMinor", - "Pherkard", - "Phoenice", - "Phurad", - "Pishpai", - "Pleione", - "Polaris", - "Pollux", - "Porrima", - "Postvarta", - "Praecipua", - "Procyon", - "Propus", - "Protrygetor", - "Pulcherrima", - "Rana", - "RanaSecunda", - "Rasalas", - "Rasalgethi", - "Rasalhague", - "Rasalmothallah", - "RasHammel", - "Rastaban", - "Reda", - "Regor", - "Regulus", - "Rescha", - "RigilKentaurus", - "RiglalAwwa", - "Rotanen", - "Ruchba", - "Ruchbah", - "Rukbat", - "Rutilicus", - "Saak", - "Sabik", - "Sadachbia", - "Sadalbari", - "Sadalmelik", - "Sadalsuud", - "Sadatoni", - "Sadira", - "Sadr", - "Saidak", - "Saiph", - "Salm", - "Sargas", - "Sarin", - "Sartan", - "Sceptrum", - "Scheat", - "Schedar", - "Scheddi", - "Schemali", - "Scutulum", - "SeatAlpheras", - "Segin", - "Seginus", - "Shaula", - "Shedir", - "Sheliak", - "Sheratan", - "Singer", - "Sirius", - "Sirrah", - "Situla", - "Skat", - "Spica", - "Sterope", - "Subra", - "Suha", - "Suhail", - "SuhailHadar", - "SuhailRadar", - "Suhel", - "Sulafat", - "Superba", - "Svalocin", - "Syrma", - "Tabit", - "Tais", - "Talitha", - "TaniaAustralis", - "TaniaBorealis", - "Tarazed", - "Tarf", - "TaTsun", - "Taygeta", - "Tegmen", - "Tejat", - "TejatPrior", - "Terebellum", - "Theemim", - "Thuban", - "Tolimann", - "Tramontana", - "Tsih", - "Tureis", - "Unukalhai", - "Vega", - "Venabulum", - "Venator", - "Vendemiatrix", - "Vespertilio", - "Vildiur", - "Vindemiatrix", - "Wasat", - "Wazn", - "YedPosterior", - "YedPrior", - "Zaniah", - "Zaurak", - "Zavijava", - "ZenithStar", - "Zibel", - "Zosma", - "Zubenelakrab", - "ZubenElgenubi", - "Zubeneschamali", - "ZubenHakrabi", - "Zubra", -]; diff --git a/inserter/src/generate_csv.rs b/inserter/src/generate_csv.rs index 8a623b3..7b6c3f3 100644 --- a/inserter/src/generate_csv.rs +++ b/inserter/src/generate_csv.rs @@ -1,7 +1,7 @@ use crate::algorithm::data; use crate::algorithm::data::enums::{PlanetType, ORES}; use crate::algorithm::data::game_desc::GameDesc; -use crate::algorithm::worldgen::galaxy_gen::create_galaxy; +use crate::algorithm::worldgen::galaxy_gen::generate_stars; pub fn gen_formatted(seed: i32) -> anyhow::Result<(String, String)> { let game_desc: GameDesc = GameDesc { @@ -12,12 +12,12 @@ pub fn gen_formatted(seed: i32) -> anyhow::Result<(String, String)> { use_actual_veins: false }; let hab_count = std::cell::Cell::new(0i32); - let galaxy = create_galaxy(seed, &game_desc, &hab_count); + let galaxy = generate_stars(seed, &game_desc, &hab_count); let mut stars: String = String::with_capacity(crate::STAR_COUNT * 128); let mut planets: String = String::with_capacity(crate::STAR_COUNT * 256 * 5); - for solar_system in galaxy.stars { + for solar_system in galaxy { let star = solar_system.star.clone(); let star_id = star.index as i32 + seed * 100; From 99771f42abc1549cac8f5fdabcca507a2dfdc07b Mon Sep 17 00:00:00 2001 From: SuperB3333 Date: Thu, 23 Jul 2026 11:09:55 +0200 Subject: [PATCH 5/7] Removed bython target, cleaned up algo structure and removed dead wasm.rs file --- inserter/Cargo.toml | 34 +--- inserter/src/algorithm/data/planet.rs | 2 +- inserter/src/algorithm/data/vein.rs | 18 -- inserter/src/algorithm/mod.rs | 188 +++++++++++++++++- inserter/src/algorithm/worldgen/galaxy_gen.rs | 184 ----------------- inserter/src/algorithm/worldgen/mod.rs | 1 - inserter/src/generate_csv.rs | 2 +- inserter/src/python.rs | 31 --- inserter/src/wasm.rs | 79 -------- server/server.py | 4 +- 10 files changed, 197 insertions(+), 346 deletions(-) delete mode 100644 inserter/src/algorithm/worldgen/galaxy_gen.rs delete mode 100644 inserter/src/algorithm/worldgen/mod.rs delete mode 100644 inserter/src/python.rs delete mode 100644 inserter/src/wasm.rs diff --git a/inserter/Cargo.toml b/inserter/Cargo.toml index ee10a2c..89ab8e0 100644 --- a/inserter/Cargo.toml +++ b/inserter/Cargo.toml @@ -14,36 +14,14 @@ debug = true [[bin]] name = "dsp_seed_finder" path = "src/main.rs" -required-features = ["binary"] -[lib] -required-features = ["python"] -name = "dsp_generator" -path = "src/python.rs" -module-name = "dsp_generator" -crate-type = ["cdylib"] - -# Dependencies for all builds [dependencies] once_cell = "1.19.0" +crossbeam-channel = "0.5.15" +postgres = "0.19.13" +crossterm = "0.29.0" +anyhow = "1.0.103" +lazy_static = "1.5.0" +itertools = "0.15.0" -# Dependencies for binary -crossbeam-channel = { version = "0.5.15", optional = true } -postgres = { version = "0.19.13", optional = true } -crossterm = { version = "0.29.0", optional = true } -anyhow = { version = "1.0.103", optional = true } -lazy_static = { version = "1.5.0", optional = true } -itertools = { version = "0.15.0", optional = true } - - -# Dependencies for Python build -pyo3 = { version = "0.29.0", features = ["full"], optional = true} -pythonize = { version = "0.29.0", optional = true } - - - -[features] -default = ["binary"] -binary = ["crossbeam-channel", "postgres", "crossterm", "anyhow", "lazy_static", "itertools"] -python = ["pyo3", "pythonize"] diff --git a/inserter/src/algorithm/data/planet.rs b/inserter/src/algorithm/data/planet.rs index 98a07ea..b9f643f 100644 --- a/inserter/src/algorithm/data/planet.rs +++ b/inserter/src/algorithm/data/planet.rs @@ -656,7 +656,7 @@ impl<'a> Planet<'a> { let vein_spot_count = vein_spots[index3 as usize]; if vein_spot_count > 0 { let vein_type: VeinType = unsafe { std::mem::transmute(index3) }; - let mut vein = EstimatedVein::new(); + let mut vein = EstimatedVein::default(); vein.vein_type = vein_type; vein.min_group = vein_spot_count - 1; vein.max_group = vein_spot_count + 1; diff --git a/inserter/src/algorithm/data/vein.rs b/inserter/src/algorithm/data/vein.rs index 9275332..e08d556 100644 --- a/inserter/src/algorithm/data/vein.rs +++ b/inserter/src/algorithm/data/vein.rs @@ -25,24 +25,6 @@ impl Default for EstimatedVein { } } -impl EstimatedVein { - pub fn new() -> Self { - Default::default() - } - pub fn min(&self) -> i32 { - self.min_group * self.min_amount * self.min_patch - } - pub fn max(&self) -> i32 { - self.max_group * self.max_amount * self.max_patch - } - pub fn estimate(&self) -> i64 { - (self.min_group + self.max_group) as i64 - * (self.min_amount + self.max_amount) as i64 - * (self.min_patch + self.max_patch) as i64 - / 8i64 - } -} - #[derive(Debug, Clone)] pub struct ActualVein { pub vein_type: VeinType, diff --git a/inserter/src/algorithm/mod.rs b/inserter/src/algorithm/mod.rs index e2567f7..7874b30 100644 --- a/inserter/src/algorithm/mod.rs +++ b/inserter/src/algorithm/mod.rs @@ -1,2 +1,188 @@ pub mod data; -pub mod worldgen; + +use data::{ + enums::{SpectrType, StarType}, + game_desc::GameDesc, + random::DspRandom, + star::Star, + star_planets::StarWithPlanets, + vector3::Vector3 +}; +use std::cell::Cell; +use std::rc::Rc; + +const ITER_COUNT: usize = 4; +const MIN_DIST: f64 = 2.0; +const MIN_DIST_SQ: f64 = MIN_DIST * MIN_DIST; +const STEP_DIFF: f64 = 3.5 - 2.3; +const FLATTEN: f64 = 0.18; +const MIN_DRUNK_NUM: i32 = 6; +const MAX_DRUNK_NUM: i32 = 8; +const DRUNK_NUM_RANGE: f64 = (MAX_DRUNK_NUM - MIN_DRUNK_NUM) as f64; + +fn generate_temp_poses(seed: i32, target_count: usize) -> Vec { + let max_count = target_count * ITER_COUNT; + let mut tmp_poses = Vec::with_capacity(max_count); + random_poses(&mut tmp_poses, seed, max_count); + + for index in (0..tmp_poses.len()).rev() { + if index % ITER_COUNT != 0 { + tmp_poses.remove(index); + } + if tmp_poses.len() <= target_count { + break; + } + } + + tmp_poses +} + +fn random_poses(tmp_poses: &mut Vec, seed: i32, max_count: usize) { + let mut rand = DspRandom::new(seed); + let drunk_walk_count_rand = rand.next_f64(); + let mut tmp_drunk: Vec = Vec::with_capacity(max_count); + tmp_poses.push(Vector3::zero()); + let drunk_num = (drunk_walk_count_rand * DRUNK_NUM_RANGE + (MIN_DRUNK_NUM as f64)) as i32; + for _ in 0..drunk_num { + for _ in 0..256 { + let u = rand.next_f64() * 2.0 - 1.0; + let w = (rand.next_f64() * 2.0 - 1.0) * FLATTEN; + let v = rand.next_f64() * 2.0 - 1.0; + let first_step_len_rand = rand.next_f64(); + let squared_length = u * u + w * w + v * v; + if squared_length <= 1.0 && squared_length >= 1e-8 { + let distance = squared_length.sqrt(); + let step_len_mult = (first_step_len_rand * STEP_DIFF + MIN_DIST) / distance; + let pt = Vector3(u * step_len_mult, w * step_len_mult, v * step_len_mult); + if !check_collision(tmp_poses, &pt) { + tmp_drunk.push(pt); + tmp_poses.push(pt); + if tmp_poses.len() >= max_count { + return; + } + break; + } + } + } + } + for _ in 0..256 { + for pt in tmp_drunk.iter_mut() { + if rand.next_f64() <= 0.7 { + for _ in 0..256 { + let u = rand.next_f64() * 2.0 - 1.0; + let w = (rand.next_f64() * 2.0 - 1.0) * FLATTEN; + let v = rand.next_f64() * 2.0 - 1.0; + let step_len_rand = rand.next_f64(); + let squared_length2 = u * u + w * w + v * v; + if squared_length2 <= 1.0 && squared_length2 >= 1e-8 { + let distance = squared_length2.sqrt(); + let step_len_mult = (step_len_rand * STEP_DIFF + MIN_DIST) / distance; + let new_pt = Vector3( + pt.0 + u * step_len_mult, + pt.1 + w * step_len_mult, + pt.2 + v * step_len_mult, + ); + if !check_collision(tmp_poses, &new_pt) { + *pt = new_pt; + tmp_poses.push(new_pt); + if tmp_poses.len() >= max_count { + return; + } + break; + } + } + } + } + } + } +} + +fn check_collision(tmp_poses: &Vec, pt: &Vector3) -> bool { + tmp_poses + .iter() + .any(|existing_point| existing_point.distance_sq_from(pt) < MIN_DIST_SQ) +} + +pub fn generate_stars<'a>( + seed: i32, + game_desc: &'a GameDesc, + habitable_count: &'a Cell, +) -> Vec> { + let mut rand = DspRandom::new(seed); + let tmp_poses = generate_temp_poses(rand.next_seed(), game_desc.star_count); + let star_count = tmp_poses.len(); + + let black_hole_count_rand = rand.next_f32(); + let neutron_star_count_rand = rand.next_f32(); + let white_dwarf_count_rand = rand.next_f32(); + let giant_star_count_rand = rand.next_f32(); + let black_hole_num = ((0.01 * (star_count as f64) + (black_hole_count_rand as f64) * 0.3) + as f32) + .ceil() as usize; + let neutro_star_num = ((0.01 * (star_count as f64) + (neutron_star_count_rand as f64) * 0.3) + as f32) + .ceil() as usize; + let white_dwarf_num = ((0.016 * (star_count as f64) + (white_dwarf_count_rand as f64) * 0.4) + as f32) + .ceil() as usize; + let giant_star_num = ((0.013 * (star_count as f64) + (giant_star_count_rand as f64) * 1.4) + as f32) + .ceil() as usize; + let black_hole_start = star_count - black_hole_num; + let neutron_star_start = black_hole_start - neutro_star_num; + let white_dwarf_start = neutron_star_start - white_dwarf_num; + let giant_group_num = (white_dwarf_start - 1) / giant_star_num; + let giant_offset = giant_group_num / 2; + + let mut stars: Vec = Vec::with_capacity(star_count); + + for (index, position) in tmp_poses.into_iter().enumerate() { + let seed = rand.next_seed(); + if index == 0 { + stars.push(StarWithPlanets::new( + Rc::new(Star::new( + game_desc, + 0, + seed, + Vector3::zero(), + StarType::MainSeqStar, + &SpectrType::X, + )), + game_desc, + habitable_count, + )); + } else { + let need_spectr = if index == 3 { + SpectrType::M + } else if index == white_dwarf_start - 1 { + SpectrType::O + } else { + SpectrType::X + }; + let need_type = if index >= black_hole_start { + StarType::BlackHole + } else if index >= neutron_star_start { + StarType::NeutronStar + } else if index >= white_dwarf_start { + StarType::WhiteDwarf + } else if index % giant_group_num == giant_offset { + StarType::GiantStar + } else { + StarType::MainSeqStar + }; + stars.push(StarWithPlanets::new( + Rc::new(Star::new( + game_desc, + index, + seed, + position, + need_type, + &need_spectr, + )), + game_desc, + habitable_count, + )); + } + } + stars +} \ No newline at end of file diff --git a/inserter/src/algorithm/worldgen/galaxy_gen.rs b/inserter/src/algorithm/worldgen/galaxy_gen.rs deleted file mode 100644 index 50e7906..0000000 --- a/inserter/src/algorithm/worldgen/galaxy_gen.rs +++ /dev/null @@ -1,184 +0,0 @@ -use crate::algorithm::data::enums::{SpectrType, StarType}; -use crate::algorithm::data::game_desc::GameDesc; -use crate::algorithm::data::random::DspRandom; -use crate::algorithm::data::star::Star; -use crate::algorithm::data::star_planets::StarWithPlanets; -use crate::algorithm::data::vector3::Vector3; -use std::cell::Cell; -use std::rc::Rc; - -const ITER_COUNT: usize = 4; -const MIN_DIST: f64 = 2.0; -const MIN_DIST_SQ: f64 = MIN_DIST * MIN_DIST; -const STEP_DIFF: f64 = 3.5 - 2.3; -const FLATTEN: f64 = 0.18; -const MIN_DRUNK_NUM: i32 = 6; -const MAX_DRUNK_NUM: i32 = 8; -const DRUNK_NUM_RANGE: f64 = (MAX_DRUNK_NUM - MIN_DRUNK_NUM) as f64; - -fn generate_temp_poses(seed: i32, target_count: usize) -> Vec { - let max_count = target_count * ITER_COUNT; - let mut tmp_poses = Vec::with_capacity(max_count); - random_poses(&mut tmp_poses, seed, max_count); - - for index in (0..tmp_poses.len()).rev() { - if index % ITER_COUNT != 0 { - tmp_poses.remove(index); - } - if tmp_poses.len() <= target_count { - break; - } - } - - tmp_poses -} - -fn random_poses(tmp_poses: &mut Vec, seed: i32, max_count: usize) { - let mut rand = DspRandom::new(seed); - let drunk_walk_count_rand = rand.next_f64(); - let mut tmp_drunk: Vec = Vec::with_capacity(max_count); - tmp_poses.push(Vector3::zero()); - let drunk_num = (drunk_walk_count_rand * DRUNK_NUM_RANGE + (MIN_DRUNK_NUM as f64)) as i32; - for _ in 0..drunk_num { - for _ in 0..256 { - let u = rand.next_f64() * 2.0 - 1.0; - let w = (rand.next_f64() * 2.0 - 1.0) * FLATTEN; - let v = rand.next_f64() * 2.0 - 1.0; - let first_step_len_rand = rand.next_f64(); - let squared_length = u * u + w * w + v * v; - if squared_length <= 1.0 && squared_length >= 1e-8 { - let distance = squared_length.sqrt(); - let step_len_mult = (first_step_len_rand * STEP_DIFF + MIN_DIST) / distance; - let pt = Vector3(u * step_len_mult, w * step_len_mult, v * step_len_mult); - if !check_collision(tmp_poses, &pt) { - tmp_drunk.push(pt); - tmp_poses.push(pt); - if tmp_poses.len() >= max_count { - return; - } - break; - } - } - } - } - for _ in 0..256 { - for pt in tmp_drunk.iter_mut() { - if rand.next_f64() <= 0.7 { - for _ in 0..256 { - let u = rand.next_f64() * 2.0 - 1.0; - let w = (rand.next_f64() * 2.0 - 1.0) * FLATTEN; - let v = rand.next_f64() * 2.0 - 1.0; - let step_len_rand = rand.next_f64(); - let squared_length2 = u * u + w * w + v * v; - if squared_length2 <= 1.0 && squared_length2 >= 1e-8 { - let distance = squared_length2.sqrt(); - let step_len_mult = (step_len_rand * STEP_DIFF + MIN_DIST) / distance; - let new_pt = Vector3( - pt.0 + u * step_len_mult, - pt.1 + w * step_len_mult, - pt.2 + v * step_len_mult, - ); - if !check_collision(tmp_poses, &new_pt) { - *pt = new_pt; - tmp_poses.push(new_pt); - if tmp_poses.len() >= max_count { - return; - } - break; - } - } - } - } - } - } -} - -fn check_collision(tmp_poses: &Vec, pt: &Vector3) -> bool { - tmp_poses - .iter() - .any(|existing_point| existing_point.distance_sq_from(pt) < MIN_DIST_SQ) -} - -pub fn generate_stars<'a>( - seed: i32, - game_desc: &'a GameDesc, - habitable_count: &'a Cell, -) -> Vec> { - let mut rand = DspRandom::new(seed); - let tmp_poses = generate_temp_poses(rand.next_seed(), game_desc.star_count); - let star_count = tmp_poses.len(); - - let black_hole_count_rand = rand.next_f32(); - let neutron_star_count_rand = rand.next_f32(); - let white_dwarf_count_rand = rand.next_f32(); - let giant_star_count_rand = rand.next_f32(); - let black_hole_num = ((0.01 * (star_count as f64) + (black_hole_count_rand as f64) * 0.3) - as f32) - .ceil() as usize; - let neutro_star_num = ((0.01 * (star_count as f64) + (neutron_star_count_rand as f64) * 0.3) - as f32) - .ceil() as usize; - let white_dwarf_num = ((0.016 * (star_count as f64) + (white_dwarf_count_rand as f64) * 0.4) - as f32) - .ceil() as usize; - let giant_star_num = ((0.013 * (star_count as f64) + (giant_star_count_rand as f64) * 1.4) - as f32) - .ceil() as usize; - let black_hole_start = star_count - black_hole_num; - let neutron_star_start = black_hole_start - neutro_star_num; - let white_dwarf_start = neutron_star_start - white_dwarf_num; - let giant_group_num = (white_dwarf_start - 1) / giant_star_num; - let giant_offset = giant_group_num / 2; - - let mut stars: Vec = Vec::with_capacity(star_count); - - for (index, position) in tmp_poses.into_iter().enumerate() { - let seed = rand.next_seed(); - if index == 0 { - stars.push(StarWithPlanets::new( - Rc::new(Star::new( - game_desc, - 0, - seed, - Vector3::zero(), - StarType::MainSeqStar, - &SpectrType::X, - )), - game_desc, - habitable_count, - )); - } else { - let need_spectr = if index == 3 { - SpectrType::M - } else if index == white_dwarf_start - 1 { - SpectrType::O - } else { - SpectrType::X - }; - let need_type = if index >= black_hole_start { - StarType::BlackHole - } else if index >= neutron_star_start { - StarType::NeutronStar - } else if index >= white_dwarf_start { - StarType::WhiteDwarf - } else if index % giant_group_num == giant_offset { - StarType::GiantStar - } else { - StarType::MainSeqStar - }; - stars.push(StarWithPlanets::new( - Rc::new(Star::new( - game_desc, - index, - seed, - position, - need_type, - &need_spectr, - )), - game_desc, - habitable_count, - )); - } - } - stars -} diff --git a/inserter/src/algorithm/worldgen/mod.rs b/inserter/src/algorithm/worldgen/mod.rs deleted file mode 100644 index 9d71d3e..0000000 --- a/inserter/src/algorithm/worldgen/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod galaxy_gen; diff --git a/inserter/src/generate_csv.rs b/inserter/src/generate_csv.rs index 7b6c3f3..7d6c714 100644 --- a/inserter/src/generate_csv.rs +++ b/inserter/src/generate_csv.rs @@ -1,7 +1,7 @@ use crate::algorithm::data; use crate::algorithm::data::enums::{PlanetType, ORES}; use crate::algorithm::data::game_desc::GameDesc; -use crate::algorithm::worldgen::galaxy_gen::generate_stars; +use crate::algorithm::generate_stars; pub fn gen_formatted(seed: i32) -> anyhow::Result<(String, String)> { let game_desc: GameDesc = GameDesc { diff --git a/inserter/src/python.rs b/inserter/src/python.rs deleted file mode 100644 index ce7ffa6..0000000 --- a/inserter/src/python.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![cfg(feature="python")] -mod algorithm; - -use pyo3::prelude::*; - - - - -#[pymodule] -mod dsp_generator { - use pyo3::{IntoPyObjectExt}; - use pyo3::types::*; - use pyo3::exceptions::*; - use pyo3::prelude::*; - use pythonize::pythonize; - use crate::algorithm::data::game_desc::GameDesc; - - use crate::algorithm::worldgen::galaxy_gen::create_galaxy; - - /// Generates a dsp galaxy and returns a dictionary - #[pyfunction] - #[allow(non_snake_case)] - pub fn generate(py: Python, seed: i32, star_count: usize, resource_multiplier: f32) -> PyResult> { - let mut game_desc: GameDesc = GameDesc::default(); - game_desc.seed = seed; game_desc.star_count = star_count; game_desc.resource_multiplier = resource_multiplier; - let galaxy = create_galaxy(&game_desc); - pythonize(py, &galaxy.stars).map_err(|e| { - PyErr::new::(format!("Failed to pythonize galaxy: {}", e)) - }) - } -} \ No newline at end of file diff --git a/inserter/src/wasm.rs b/inserter/src/wasm.rs deleted file mode 100644 index cc75385..0000000 --- a/inserter/src/wasm.rs +++ /dev/null @@ -1,79 +0,0 @@ -#![cfg(target_arch = "wasm32")] - -mod data; -mod rules; -mod transform_rules; -mod worldgen; - -use data::game_desc::GameDesc; -use serde::Serialize; -use std::cell::Cell; -use wasm_bindgen::prelude::*; -use wasm_bindgen_futures::spawn_local; -use worldgen::galaxy_gen::{create_galaxy, find_stars}; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(js_namespace = worldgen)] - async fn found(value: JsValue) -> JsValue; -} - -#[wasm_bindgen] -#[allow(non_snake_case)] -pub fn generate(seed: JsValue, gameDesc: JsValue) -> Result { - let seed: i32 = serde_wasm_bindgen::from_value(seed)?; - let game_desc: GameDesc = serde_wasm_bindgen::from_value(gameDesc)?; - let habitable_count = Cell::new(0_i32); - let galaxy = create_galaxy(seed, &game_desc, &habitable_count); - galaxy.serialize(&serde_wasm_bindgen::Serializer::json_compatible()) -} - -#[wasm_bindgen] -#[allow(non_snake_case)] -pub fn searchStar( - seed: JsValue, - gameDesc: JsValue, - rule: JsValue, -) -> Result { - let seed: i32 = serde_wasm_bindgen::from_value(seed)?; - let game_desc: GameDesc = serde_wasm_bindgen::from_value(gameDesc)?; - let rule = serde_wasm_bindgen::from_value(rule).unwrap(); - let transformed = transform_rules::transform_rules(rule); - let star_indexes = find_stars(seed, &game_desc, &transformed); - let indexes: Vec = (0..64) - .filter(|&i| (star_indexes & (1_u64 << i)) != 0) - .collect(); - serde_wasm_bindgen::to_value(&indexes) -} - -#[wasm_bindgen] -#[allow(non_snake_case)] -pub fn findStars(gameDesc: JsValue, rule: JsValue, seeds: JsValue) { - spawn_local(async { - let game_desc: GameDesc = serde_wasm_bindgen::from_value(gameDesc).unwrap(); - let mut seeds: Vec = serde_wasm_bindgen::from_value(seeds).unwrap(); - let rule = serde_wasm_bindgen::from_value(rule).unwrap(); - let transformed = transform_rules::transform_rules(rule); - loop { - let mut results: Vec = vec![]; - for seed in seeds { - let star_indexes = find_stars(seed, &game_desc, &transformed); - if star_indexes != 0 { - results.push(seed); - } - } - let result = serde_wasm_bindgen::to_value(&results).unwrap(); - let next_batch: JsValue = found(result).await; - let next_seeds: Result, serde_wasm_bindgen::Error> = - serde_wasm_bindgen::from_value(next_batch); - match next_seeds { - Ok(f) => { - seeds = f; - } - Err(_) => { - break; - } - } - } - }) -} diff --git a/server/server.py b/server/server.py index 1cfd0f0..151e020 100644 --- a/server/server.py +++ b/server/server.py @@ -4,7 +4,6 @@ from parse_rule import parse as parse_rule -from dsp_generator import generate as generate_galaxy DB_CONFIG = { "host": "localhost", @@ -14,7 +13,8 @@ } def create_galaxy(game): - return generate_galaxy(game["seed"], 8, 8) #todo input star_count and resource_multiplier as well + return {} + #return generate_galaxy(game["seed"], 8, 8) #todo implement this server in rust or ditch it def find_stars(options): From b40e9da0e66704f711c2cc0d7c23f0e0e65053e4 Mon Sep 17 00:00:00 2001 From: SuperB3333 Date: Thu, 23 Jul 2026 12:01:21 +0200 Subject: [PATCH 6/7] Removed lots of dead code --- inserter/src/algorithm/data/enums.rs | 28 +- inserter/src/algorithm/data/game_desc.rs | 14 - inserter/src/algorithm/data/math.rs | 14 +- inserter/src/algorithm/data/planet.rs | 16 +- inserter/src/algorithm/data/quaternion.rs | 15 +- inserter/src/algorithm/data/random.rs | 5 - inserter/src/algorithm/data/star.rs | 270 +----------------- inserter/src/algorithm/data/star_planets.rs | 40 +-- inserter/src/algorithm/data/theme_proto.rs | 80 +----- inserter/src/algorithm/data/vector3.rs | 15 - inserter/src/algorithm/data/vector_f2.rs | 35 --- inserter/src/algorithm/data/vector_f3.rs | 6 - inserter/src/algorithm/mod.rs | 7 +- inserter/src/algorithm/tests/worldgen_test.rs | 12 +- inserter/src/generate_csv.rs | 3 - inserter/src/main.rs | 2 - inserter/src/threads.rs | 2 +- 17 files changed, 23 insertions(+), 541 deletions(-) diff --git a/inserter/src/algorithm/data/enums.rs b/inserter/src/algorithm/data/enums.rs index 3a1bb36..b8741fd 100644 --- a/inserter/src/algorithm/data/enums.rs +++ b/inserter/src/algorithm/data/enums.rs @@ -1,4 +1,3 @@ -#[allow(dead_code)] #[repr(i32)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum StarType { @@ -9,15 +8,9 @@ pub enum StarType { BlackHole, } -impl Default for StarType { - fn default() -> Self { - Self::MainSeqStar - } -} - -#[allow(dead_code)] #[repr(i32)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] +#[allow(dead_code)] pub enum SpectrType { M = -4, K = -3, @@ -29,11 +22,9 @@ pub enum SpectrType { X = 3, } -#[allow(dead_code)] #[repr(i32)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum PlanetType { - None, Volcano, Ocean, Desert, @@ -41,20 +32,14 @@ pub enum PlanetType { Gas, } -impl Default for PlanetType { - fn default() -> Self { - Self::None - } -} -#[allow(dead_code)] + #[repr(i32)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum ThemeDistribute { Default, Birth, - Interstellar, - Rare, + Interstellar } impl Default for ThemeDistribute { @@ -63,7 +48,6 @@ impl Default for ThemeDistribute { } } -#[allow(dead_code)] #[repr(i32)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum VeinType { @@ -85,12 +69,6 @@ pub enum VeinType { Max, } -impl Default for VeinType { - fn default() -> Self { - Self::None - } -} - impl VeinType { pub fn is_rare(&self) -> bool { matches!( diff --git a/inserter/src/algorithm/data/game_desc.rs b/inserter/src/algorithm/data/game_desc.rs index fa9ebc0..47a0478 100644 --- a/inserter/src/algorithm/data/game_desc.rs +++ b/inserter/src/algorithm/data/game_desc.rs @@ -2,9 +2,6 @@ pub struct GameDesc { pub star_count: usize, pub resource_multiplier: f32, - pub hive_initial_colonize: f64, - pub hive_max_density: f64, - pub use_actual_veins: bool, } impl GameDesc { @@ -32,15 +29,4 @@ impl GameDesc { 1.0 } } -} -impl Default for GameDesc { - fn default() -> Self { - Self { - star_count: 64, - resource_multiplier: 1.0, - hive_initial_colonize: 1.0, - hive_max_density: 1.0, - use_actual_veins: false - } - } } \ No newline at end of file diff --git a/inserter/src/algorithm/data/math.rs b/inserter/src/algorithm/data/math.rs index 825d8e1..8843414 100644 --- a/inserter/src/algorithm/data/math.rs +++ b/inserter/src/algorithm/data/math.rs @@ -1,22 +1,10 @@ /// Mathematical utility functions ported from Maths.cs /// These are used by PlanetAlgorithm implementations. -/// Clamp a value between min and max (inclusive). -#[inline] -pub fn clamp(value: T, min: T, max: T) -> T { - if value < min { - min - } else if value > max { - max - } else { - value - } -} - /// Clamp a value between 0.0 and 1.0. #[inline] pub fn clamp01(value: f64) -> f64 { - clamp(value, 0.0, 1.0) + value.clamp(0.0, 1.0) } /// C# Levelize: smoothstep-based levelize diff --git a/inserter/src/algorithm/data/planet.rs b/inserter/src/algorithm/data/planet.rs index b9f643f..7864857 100644 --- a/inserter/src/algorithm/data/planet.rs +++ b/inserter/src/algorithm/data/planet.rs @@ -18,7 +18,7 @@ use std::rc::Rc; #[derive(Debug)] pub struct Planet<'a> { game_desc: &'a GameDesc, - pub star: Rc>, + pub star: Rc, pub index: usize, habitable_count: &'a Cell, pub seed: i32, @@ -63,7 +63,7 @@ const ORBIT_RADIUS: &'static [f32] = &[ impl<'a> Planet<'a> { pub fn new( game_desc: &'a GameDesc, - star: Rc>, + star: Rc, index: usize, habitable_count: &'a Cell, orbit_index: usize, @@ -224,17 +224,6 @@ impl<'a> Planet<'a> { } } - fn get_luminosity(&self) -> f32 { - let mut luminosity = - (self.star.get_light_balance_radius() / (self.get_sun_distance() + 0.01)).powf(0.6); - if luminosity > 1.0 { - luminosity = luminosity.ln() + 1.0; - luminosity = luminosity.ln() + 1.0; - luminosity = luminosity.ln() + 1.0; - } - (luminosity * 100.0).round_ties_even() / 100.0 - } - fn increment_habitable_count(&self) { self.habitable_count.set(self.habitable_count.get() + 1); } @@ -1124,7 +1113,6 @@ impl<'a> Planet<'a> { } let surface_height = raw_data.query_height(&pos); if surface_height >= self.radius { - // println!("{:?},{:?},{}", pos * surface_height, vein_type, amount); amount_map[*vein_type as usize] += amount; } } diff --git a/inserter/src/algorithm/data/quaternion.rs b/inserter/src/algorithm/data/quaternion.rs index a250ab6..ca0d940 100644 --- a/inserter/src/algorithm/data/quaternion.rs +++ b/inserter/src/algorithm/data/quaternion.rs @@ -11,19 +11,6 @@ pub struct Quaternion { } impl Quaternion { - pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self { - Self { x, y, z, w } - } - - pub fn identity() -> Self { - Self { - x: 0.0, - y: 0.0, - z: 0.0, - w: 1.0, - } - } - /// Port of Unity's `Quaternion.AngleAxis(angle_degrees, axis)`. /// `angle_degrees` is in degrees (same as Unity's AngleAxis). pub fn angle_axis(angle_degrees: f32, axis: &VectorF3) -> Self { @@ -60,7 +47,7 @@ impl Quaternion { let from_mag_sq = from.magnitude_sq(); let to_mag_sq = to.magnitude_sq(); if from_mag_sq < 1e-10 || to_mag_sq < 1e-10 { - return Self::identity(); + return Self { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }; } let from_norm = from.normalized(); diff --git a/inserter/src/algorithm/data/random.rs b/inserter/src/algorithm/data/random.rs index fca5822..b8f03c5 100644 --- a/inserter/src/algorithm/data/random.rs +++ b/inserter/src/algorithm/data/random.rs @@ -117,11 +117,6 @@ impl DspRandom { } } - #[inline] - pub fn next_usize(&mut self) -> usize { - (self.sample() * (i32::MAX as f64)) as usize - } - #[inline] pub fn next_seed(&mut self) -> i32 { (self.sample() * (i32::MAX as f64)) as i32 diff --git a/inserter/src/algorithm/data/star.rs b/inserter/src/algorithm/data/star.rs index a4280d4..358200d 100644 --- a/inserter/src/algorithm/data/star.rs +++ b/inserter/src/algorithm/data/star.rs @@ -1,60 +1,48 @@ use super::enums::{SpectrType, StarType}; -use super::game_desc::GameDesc; use super::random::DspRandom; use super::vector3::Vector3; use std::cell::{OnceCell, RefCell}; use std::f64::consts::PI; #[derive(Debug)] -pub struct Star<'a> { - pub game_desc: &'a GameDesc, +pub struct Star { pub used_theme_ids: RefCell>, pub index: usize, - pub name_seed: i32, pub position: Vector3, pub level: f32, pub star_type: StarType, age_factor: f64, age_num1: f32, age_num2: f32, - age_num3: f32, - lifetime_factor: f64, radius_factor: f64, pub planets_seed: i32, - safety_factor_modifier: f64, - max_hive_count_modifier: i32, mass_params: (f64, f64, f64, f64, f32), unmodified_mass: OnceCell, resource_coef: OnceCell, age: OnceCell, temperature_factor: OnceCell, unmodified_temperature: OnceCell, - temperature: OnceCell, class_factor: OnceCell, spectr: OnceCell, luminosity: OnceCell, radius: OnceCell, - light_balance_radius: OnceCell, habitable_radius: OnceCell, mass: OnceCell, orbit_scaler: OnceCell, dyson_radius: OnceCell, - hive_rand: RefCell, - max_hive_count: OnceCell, - initial_hive_count: OnceCell, } -impl<'a> Star<'a> { +impl Star { pub fn new( - game_desc: &'a GameDesc, index: usize, seed: i32, position: Vector3, need_type: StarType, need_spectr: &SpectrType, + star_count: usize, ) -> Self { let mut rand1 = DspRandom::new(seed); - let name_seed = rand1.next_seed(); + rand1.next_seed(); let mut rand2 = DspRandom::new(rand1.next_seed()); rand1.next_f64(); let planets_seed = rand1.next_seed(); @@ -65,15 +53,9 @@ impl<'a> Star<'a> { let age_factor_rand = rand2.next_f64(); let age_num1 = (age_num1_rand * 0.1 + 0.95) as f32; let age_num2 = (age_factor_rand * 0.4 + 0.8) as f32; - let age_num3 = (age_factor_rand * 9.0 + 1.0) as f32; let mass_factor = if index == 0 { 0.0 } else { rand2.next_f64() }; - let lifetime_factor = rand2.next_f64(); let radius_exponent = rand2.next_f64() * 0.4 - 0.2; let radius_factor = 2_f64.powf(radius_exponent); - let hive_seed = rand2.next_seed(); - let mut hive_rand = DspRandom::new(hive_seed); - let safety_factor_modifier = hive_rand.next_f64(); - let max_hive_count_modifier = hive_rand.next_i32(1000); let mass_params = ( mass_random1, mass_random2, @@ -87,41 +69,30 @@ impl<'a> Star<'a> { ); Self { - game_desc, used_theme_ids: RefCell::new(vec![]), index, - name_seed, position, - level: (index as f32) / ((game_desc.star_count - 1) as f32), + level: (index as f32) / ((star_count - 1) as f32), star_type: need_type, age_factor, age_num1, age_num2, - age_num3, - lifetime_factor, radius_factor, planets_seed, mass_params, - safety_factor_modifier, - max_hive_count_modifier, unmodified_mass: OnceCell::new(), resource_coef: OnceCell::new(), age: OnceCell::new(), temperature_factor: OnceCell::new(), unmodified_temperature: OnceCell::new(), - temperature: OnceCell::new(), class_factor: OnceCell::new(), spectr: OnceCell::new(), luminosity: OnceCell::new(), radius: OnceCell::new(), - light_balance_radius: OnceCell::new(), habitable_radius: OnceCell::new(), mass: OnceCell::new(), orbit_scaler: OnceCell::new(), dyson_radius: OnceCell::new(), - hive_rand: RefCell::new(hive_rand), - max_hive_count: OnceCell::new(), - initial_hive_count: OnceCell::new(), } } @@ -199,49 +170,6 @@ impl<'a> Star<'a> { }) } - fn get_lifetime(&self) -> f32 { - let unmodified_mass = self.get_unmodified_mass(); - let lifetime_exponent_base = if unmodified_mass < 2.0 { - 2.0 + 0.4 * (1.0 - (unmodified_mass as f64)) - } else { - 5.0 - }; - let mass_multiplier = if self.star_type == StarType::GiantStar { - 0.58 - } else { - 0.5 - }; - let lifetime_delta = match self.star_type { - StarType::WhiteDwarf => 10000.0, - StarType::NeutronStar => 1000.0, - _ => 0.0, - }; - let lifetime = (10000.0 - * 0.1_f64.powf( - ((self.get_unmodified_mass() as f64) * mass_multiplier).log(lifetime_exponent_base) - + 1.0, - ) - * (self.lifetime_factor * 0.2 + 0.9)) - + lifetime_delta; - - if self.is_birth() { - lifetime as f32 - } else { - let age = self.get_age(); - let mut adjusted_lifetime = (lifetime as f32) * age; - if adjusted_lifetime > 5000.0 { - adjusted_lifetime = - (((adjusted_lifetime / 5000.0).ln() as f64 + 1.0) * 5000.0) as f32; - } - if adjusted_lifetime > 8000.0 { - adjusted_lifetime = - (((((adjusted_lifetime / 8000.0).ln() + 1.0).ln() + 1.0).ln() as f64 + 1.0) - * 8000.0) as f32; - } - adjusted_lifetime / age - } - } - pub fn get_age(&self) -> f32 { *self.age.get_or_init(|| { (if self.is_birth() { @@ -283,23 +211,6 @@ impl<'a> Star<'a> { }) } - pub fn get_temperature(&self) -> f32 { - *self.temperature.get_or_init(|| match self.star_type { - StarType::BlackHole => 0.0, - StarType::NeutronStar => self.age_num3 * 1e+7, - StarType::WhiteDwarf => self.age_num2 * 150000.0, - _ => { - let temperature = self.get_unmodified_temperature(); - if self.star_type == StarType::GiantStar { - let age_mass_factor = 1.0 - self.get_age().powf(30.0) * 0.5; - temperature * age_mass_factor - } else { - temperature - } - } - }) - } - pub fn get_class_factor(&self) -> f64 { *self.class_factor.get_or_init(|| { let temperature = self.get_unmodified_temperature() as f64; @@ -328,14 +239,6 @@ impl<'a> Star<'a> { }) } - fn get_color(&self) -> f32 { - match self.star_type { - StarType::BlackHole | StarType::NeutronStar => 1.0, - StarType::WhiteDwarf => 0.7, - _ => (((self.get_class_factor() + 3.5) * 0.2) as f32).clamp(0.0, 1.0), - } - } - pub fn get_luminosity(&self) -> f32 { *self.luminosity.get_or_init(|| { let base = self.get_temperature_factor().powf(0.7); @@ -373,23 +276,6 @@ impl<'a> Star<'a> { }) } - pub fn get_light_balance_radius(&self) -> f32 { - *self.light_balance_radius.get_or_init(|| { - if self.star_type == StarType::GiantStar { - 3.0 * self.get_habitable_radius() - } else { - let r = 1.7_f32.powf((self.get_class_factor() as f32) + 2.0); - let factor = match self.star_type { - StarType::BlackHole => 0.4 * self.age_num1, - StarType::NeutronStar => 3.0 * self.age_num1, - StarType::WhiteDwarf => 0.2 * self.age_num1, - _ => 1.0, - }; - r * factor - } - }) - } - pub fn get_habitable_radius(&self) -> f32 { *self.habitable_radius.get_or_init(|| { let factor = match self.star_type { @@ -445,152 +331,6 @@ impl<'a> Star<'a> { }) } - fn get_safety_factor(&self) -> f32 { - if self.is_birth() { - return (0.847 + self.safety_factor_modifier * 0.026) as f32; - } - let mut adjusted_distance = - (((self.position.magnitude() - 2.0) / 20.0) as f32).clamp(0.0, 2.5); - if adjusted_distance > 1.0 { - adjusted_distance = (adjusted_distance.ln() + 1.0).ln() + 1.0 - } - let normalized_distance = adjusted_distance / 1.4; - let star_type_color_factor: f32 = match self.star_type { - StarType::BlackHole => 5.0, - StarType::NeutronStar => 1.7, - StarType::WhiteDwarf => 1.2, - _ => { - let base_color_factor = self.get_color().powf(1.3); - if self.star_type == StarType::GiantStar { - base_color_factor.max(0.6) - } else if self.get_spectr() == SpectrType::O { - base_color_factor + 0.05 - } else { - base_color_factor - } - } - }; - ((1.0 - - ((star_type_color_factor * 0.9 + 0.07).powf(0.73) as f64) - * (normalized_distance.powf(0.27) as f64) - + self.safety_factor_modifier * 0.08 - - 0.04) as f32) - .clamp(0.0, 1.0) - } - - pub fn get_max_hive_count(&self) -> i32 { - *self.max_hive_count.get_or_init(|| { - let star_type_hive_multiplier = match self.star_type { - StarType::BlackHole | StarType::NeutronStar => 2.0, - _ => 1.0, - }; - ((self.game_desc.hive_max_density * star_type_hive_multiplier * 1000.0 - + (self.max_hive_count_modifier as f64) - + 0.5) as i32) - / 1000 - }) - } - - pub fn get_initial_hive_count(&self) -> i32 { - *self.initial_hive_count.get_or_init(|| { - let initial_colonize = self.game_desc.hive_initial_colonize; - if initial_colonize < 0.015 { - return 0; - } - let max_hive_count = self.get_max_hive_count(); - if self.is_birth() { - let birth_min_hives = if initial_colonize * (max_hive_count as f64) < 0.7 { - 0 - } else { - 1 - }; - let mut birth_avg_hives = 0.6 * (initial_colonize as f32) * (max_hive_count as f32); - let mut birth_std_dev = 0.5; - if birth_avg_hives < 1.0 { - birth_std_dev = ((birth_avg_hives.sqrt() as f64) * 0.29 + 0.21) as f32; - } else if birth_avg_hives > max_hive_count as f32 { - birth_avg_hives = max_hive_count as f32; - } - let mut rand3 = self.hive_rand.borrow_mut(); - let mut initial_hive_count: i32 = -1; - for _ in 0..17 { - let r1_2 = rand3.next_f64(); - let r2_2 = rand3.next_f64(); - initial_hive_count = - (rand_normal(birth_avg_hives, birth_std_dev, r1_2, r2_2) + 0.5) as i32; - if initial_hive_count >= 0 && initial_hive_count <= max_hive_count { - break; - } - } - return initial_hive_count.clamp(birth_min_hives, max_hive_count); - } - let hive_probability_base = ((1.0 - - (((self.get_safety_factor() * 1.05 - 0.15) as f32) - .clamp(0.0, 1.0) - .powf(0.82) as f64) - - (((max_hive_count - 1) as f64) * 0.05)) - as f32) - .clamp(0.0, 1.0) - * ((1.1 - (max_hive_count as f64) * 0.1) as f32); - let raw_probability = if initial_colonize > 1.0 { - lerp( - hive_probability_base, - (1.0 + (initial_colonize - 1.0) * 0.2) as f32, - ((initial_colonize - 1.0) * 0.5) as f32, - ) - } else { - hive_probability_base * (initial_colonize as f32) - }; - let star_type_adjusted_probability = match self.star_type { - StarType::GiantStar => raw_probability * 1.2, - StarType::WhiteDwarf => raw_probability * 1.4, - StarType::NeutronStar => raw_probability * 1.6, - StarType::BlackHole => raw_probability * 1.8, - _ => { - if self.get_spectr() == SpectrType::O { - raw_probability * 1.1 - } else { - raw_probability - } - } - }; - let expected_hive_count: f32 = (star_type_adjusted_probability - * (max_hive_count as f32)) - .min((max_hive_count as f32) + 0.75); - let hive_std_dev: f32 = if expected_hive_count <= 0.01 { - 0.0 - } else if expected_hive_count < 1.0 { - expected_hive_count.sqrt() * 2.9 + 2.1 - } else if expected_hive_count > 1.0 { - 0.3 + 0.2 * expected_hive_count - } else { - 0.5 - }; - let mut rand3 = self.hive_rand.borrow_mut(); - let mut initial_hive_count: i32 = -1; - for _ in 0..65 { - let r1_2 = rand3.next_f64(); - let r2_2 = rand3.next_f64(); - initial_hive_count = - (rand_normal(expected_hive_count, hive_std_dev, r1_2, r2_2) + 0.5) as i32; - if initial_hive_count >= 0 && initial_hive_count <= max_hive_count { - break; - } - } - initial_hive_count = initial_hive_count.clamp(0, max_hive_count); - - if self.star_type == StarType::BlackHole { - (((self.game_desc.hive_max_density * 1000.0 - + (self.max_hive_count_modifier as f64) - + 0.5) as i32) - / 1000) - .max(initial_hive_count) - .max(1) - } else { - initial_hive_count - } - }) - } } fn rand_normal(average_value: f32, standard_deviation: f32, r1: f64, r2: f64) -> f32 { diff --git a/inserter/src/algorithm/data/star_planets.rs b/inserter/src/algorithm/data/star_planets.rs index e70c77f..276d3d9 100644 --- a/inserter/src/algorithm/data/star_planets.rs +++ b/inserter/src/algorithm/data/star_planets.rs @@ -12,19 +12,18 @@ const MAX_VEIN_COUNT: usize = VeinType::Max as usize; #[derive(Debug)] pub struct StarWithPlanets<'a> { - pub star: Rc>, + pub star: Rc, planets: UnsafeCell>>, safe: UnsafeCell, avg_veins: UnsafeCell<[f32; MAX_VEIN_COUNT]>, - actual_veins: UnsafeCell<[f32; MAX_VEIN_COUNT]>, game_desc: &'a GameDesc, habitable_count: &'a Cell, } impl<'a> StarWithPlanets<'a> { pub fn new( - star: Rc>, + star: Rc, game_desc: &'a GameDesc, habitable_count: &'a Cell, ) -> Self { @@ -33,7 +32,6 @@ impl<'a> StarWithPlanets<'a> { planets: UnsafeCell::new(Vec::with_capacity(6)), safe: UnsafeCell::new(false), avg_veins: UnsafeCell::new([f32::NAN; MAX_VEIN_COUNT]), - actual_veins: UnsafeCell::new([f32::NAN; MAX_VEIN_COUNT]), game_desc, habitable_count, } @@ -103,40 +101,6 @@ impl<'a> StarWithPlanets<'a> { count } - pub fn get_actual_vein(&self, vein_type: &VeinType) -> f32 { - if vein_type == &VeinType::Mag - && self.star.star_type != StarType::BlackHole - && self.star.star_type != StarType::NeutronStar - { - if !self.is_safe() { - self.load_planets(); - } - return 0.0; - } - let index = *vein_type as usize; - let cached_value = unsafe { - let arr = &mut *self.actual_veins.get(); - arr.get_unchecked_mut(index) - }; - if !cached_value.is_nan() { - return *cached_value; - } - let mut count = 0; - for planet in self.get_planets() { - if !planet.can_have_vein(vein_type) { - continue; - } - for vein in planet.get_actual_veins() { - if &vein.vein_type == vein_type { - count += vein.amount; - } - } - } - *cached_value = count as f32; - self.mark_safe(); - count as f32 - } - pub fn get_planets(&self) -> &Vec> { let planets = unsafe { &mut *self.planets.get() }; if !planets.is_empty() { diff --git a/inserter/src/algorithm/data/theme_proto.rs b/inserter/src/algorithm/data/theme_proto.rs index 6f2abbf..d7449f9 100644 --- a/inserter/src/algorithm/data/theme_proto.rs +++ b/inserter/src/algorithm/data/theme_proto.rs @@ -6,8 +6,6 @@ use once_cell::sync::Lazy; #[derive(Debug, Clone)] pub struct ThemeProto { pub id: i32, - pub name: &'static str, - pub wind: f32, pub water_item_id: i32, pub distribute: ThemeDistribute, pub temperature: f32, @@ -24,39 +22,11 @@ pub struct ThemeProto { pub mod_y: Vector2, } -pub const DEFAULT_THEME_PROTO: &'static ThemeProto = &ThemeProto { - id: 0, - name: "", - water_item_id: 0, - wind: 0.0, - distribute: ThemeDistribute::Default, - temperature: 0.0, - planet_type: PlanetType::None, - vein_spot: vec![], - vein_count: vec![], - vein_opacity: vec![], - rare_veins: vec![], - rare_settings: vec![], - gas_items: vec![], - gas_speeds: vec![], - algos: vec![], - mod_x: Vector2(0.0, 0.0), - mod_y: Vector2(0.0, 0.0), -}; - -impl Default for ThemeProto { - fn default() -> Self { - DEFAULT_THEME_PROTO.clone() - } -} - pub static THEME_PROTOS: Lazy> = Lazy::new(|| { vec![ ThemeProto { id: 1, - name: "Ocean 1", water_item_id: 1000, - wind: 1.0, distribute: ThemeDistribute::Birth, temperature: 0.0, planet_type: PlanetType::Ocean, @@ -73,9 +43,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 2, - name: "Gas 1", water_item_id: 0, - wind: 0.0, distribute: ThemeDistribute::Default, temperature: 2.0, planet_type: PlanetType::Gas, @@ -92,9 +60,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 3, - name: "Gas 2", water_item_id: 0, - wind: 0.0, distribute: ThemeDistribute::Default, temperature: 1.0, planet_type: PlanetType::Gas, @@ -111,9 +77,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 4, - name: "Gas 3", water_item_id: 0, - wind: 0.0, distribute: ThemeDistribute::Default, temperature: -1.0, planet_type: PlanetType::Gas, @@ -130,9 +94,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 5, - name: "Gas 4", water_item_id: 0, - wind: 0.0, distribute: ThemeDistribute::Default, temperature: -2.0, planet_type: PlanetType::Gas, @@ -149,9 +111,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 6, - name: "Desert 1", water_item_id: 0, - wind: 1.5, distribute: ThemeDistribute::Default, temperature: 2.0, planet_type: PlanetType::Desert, @@ -168,9 +128,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 7, - name: "Desert 2", water_item_id: 0, - wind: 0.4, distribute: ThemeDistribute::Default, temperature: -1.0, planet_type: PlanetType::Desert, @@ -187,9 +145,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 8, - name: "Ocean 2", water_item_id: 1000, - wind: 1.0, distribute: ThemeDistribute::Interstellar, temperature: 0.0, planet_type: PlanetType::Ocean, @@ -206,9 +162,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 9, - name: "Lava 1", water_item_id: -1, - wind: 0.7, distribute: ThemeDistribute::Default, temperature: 5.0, planet_type: PlanetType::Volcano, @@ -225,9 +179,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 10, - name: "Ice 1", water_item_id: 1000, - wind: 0.7, distribute: ThemeDistribute::Default, temperature: -5.0, planet_type: PlanetType::Ice, @@ -244,9 +196,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 11, - name: "Desert 3", water_item_id: 0, - wind: 0.0, distribute: ThemeDistribute::Default, temperature: -2.0, planet_type: PlanetType::Desert, @@ -270,9 +220,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 12, - name: "Desert 4", water_item_id: 0, - wind: 0.8, distribute: ThemeDistribute::Default, temperature: 1.0, planet_type: PlanetType::Desert, @@ -289,9 +237,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 13, - name: "Volcanic 1", water_item_id: 1116, - wind: 0.8, distribute: ThemeDistribute::Interstellar, temperature: 4.0, planet_type: PlanetType::Volcano, @@ -308,9 +254,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 14, - name: "Ocean 3", water_item_id: 1000, - wind: 1.0, distribute: ThemeDistribute::Interstellar, temperature: 0.0, planet_type: PlanetType::Ocean, @@ -327,9 +271,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 15, - name: "Ocean 4", water_item_id: 1000, - wind: 1.1, distribute: ThemeDistribute::Interstellar, temperature: 0.0, planet_type: PlanetType::Ocean, @@ -346,9 +288,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 16, - name: "Ocean 5", water_item_id: 1000, - wind: 1.1, distribute: ThemeDistribute::Interstellar, temperature: 0.0, planet_type: PlanetType::Ocean, @@ -365,9 +305,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 17, - name: "Desert 5", water_item_id: 0, - wind: 1.1, distribute: ThemeDistribute::Default, temperature: 1.0, planet_type: PlanetType::Desert, @@ -384,9 +322,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 18, - name: "Ocean 6", water_item_id: 1000, - wind: 1.0, distribute: ThemeDistribute::Interstellar, temperature: 0.0, planet_type: PlanetType::Ocean, @@ -403,9 +339,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 19, - name: "Desert 6", water_item_id: 0, - wind: 1.6, distribute: ThemeDistribute::Interstellar, temperature: 1.0, planet_type: PlanetType::Desert, @@ -422,9 +356,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 20, - name: "Desert 7", water_item_id: -2, - wind: 0.7, distribute: ThemeDistribute::Default, temperature: -2.0, planet_type: PlanetType::Desert, @@ -441,9 +373,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 21, - name: "Gas 5", water_item_id: 0, - wind: 0.0, distribute: ThemeDistribute::Interstellar, temperature: 1.0, planet_type: PlanetType::Gas, @@ -460,9 +390,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 22, - name: "Desert 8", water_item_id: 1000, - wind: 1.1, distribute: ThemeDistribute::Interstellar, temperature: 0.0, planet_type: PlanetType::Ocean, @@ -479,9 +407,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 23, - name: "Desert 9", water_item_id: 0, - wind: 1.5, distribute: ThemeDistribute::Interstellar, temperature: 0.08, planet_type: PlanetType::Desert, @@ -498,9 +424,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 24, - name: "Desert 10", water_item_id: 0, - wind: 1.3, distribute: ThemeDistribute::Default, temperature: -4.0, planet_type: PlanetType::Ice, @@ -517,9 +441,7 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { }, ThemeProto { id: 25, - name: "Desert 11", water_item_id: 0, - wind: 1.0, distribute: ThemeDistribute::Interstellar, temperature: 0.0, planet_type: PlanetType::Ocean, @@ -535,4 +457,4 @@ pub static THEME_PROTOS: Lazy> = Lazy::new(|| { mod_y: Vector2(3.0, 3.0), }, ] -}); +}); \ No newline at end of file diff --git a/inserter/src/algorithm/data/vector3.rs b/inserter/src/algorithm/data/vector3.rs index 76f68f6..76b3d32 100644 --- a/inserter/src/algorithm/data/vector3.rs +++ b/inserter/src/algorithm/data/vector3.rs @@ -13,10 +13,6 @@ impl Vector3 { dx * dx + dy * dy + dz * dz } - pub fn distance_from(&self, pt: &Self) -> f64 { - self.distance_sq_from(pt).sqrt() - } - pub fn magnitude_sq(&self) -> f64 { self.0 * self.0 + self.1 * self.1 + self.2 * self.2 } @@ -35,17 +31,6 @@ impl Vector3 { return self; } - pub fn dot(&self, rhs: &Vector3) -> f64 { - return self.0 * rhs.0 + self.1 * rhs.1 + self.2 * rhs.2; - } - - pub fn slerp(lhs: &Vector3, rhs: &Vector3, percent: f64) -> Vector3 { - let dot = lhs.dot(rhs).clamp(-1.0, 1.0); - let theta = dot.acos() * percent; - let mut relative_vec = rhs - &(lhs * dot); - relative_vec.normalize(); - &(lhs * theta.cos()) + &(&relative_vec * theta.sin()) - } } impl std::ops::Add<&Vector3> for &Vector3 { diff --git a/inserter/src/algorithm/data/vector_f2.rs b/inserter/src/algorithm/data/vector_f2.rs index cbacb7f..e210f78 100644 --- a/inserter/src/algorithm/data/vector_f2.rs +++ b/inserter/src/algorithm/data/vector_f2.rs @@ -13,22 +13,6 @@ impl VectorF2 { Self(0.0, 0.0) } - pub fn up() -> Self { - Self(0.0, 1.0) - } - - pub fn down() -> Self { - Self(0.0, -1.0) - } - - pub fn right() -> Self { - Self(1.0, 0.0) - } - - pub fn left() -> Self { - Self(-1.0, 0.0) - } - pub fn magnitude_sq(&self) -> f32 { self.0 * self.0 + self.1 * self.1 } @@ -47,19 +31,6 @@ impl VectorF2 { self } - pub fn normalized(&self) -> Self { - let mag = self.magnitude(); - if mag > 1e-10 { - *self / mag - } else { - Self::zero() - } - } - - pub fn dot(a: &Self, b: &Self) -> f32 { - a.0 * b.0 + a.1 * b.1 - } - pub fn distance_sq_from(&self, pt: &Self) -> f32 { let dx = pt.0 - self.0; let dy = pt.1 - self.1; @@ -196,9 +167,3 @@ impl Neg for VectorF2 { VectorF2(-self.0, -self.1) } } - -impl std::fmt::Display for VectorF2 { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "({}, {})", self.0, self.1) - } -} diff --git a/inserter/src/algorithm/data/vector_f3.rs b/inserter/src/algorithm/data/vector_f3.rs index e14104a..64d3ae4 100644 --- a/inserter/src/algorithm/data/vector_f3.rs +++ b/inserter/src/algorithm/data/vector_f3.rs @@ -227,9 +227,3 @@ impl Neg for VectorF3 { VectorF3(-self.0, -self.1, -self.2) } } - -impl std::fmt::Display for VectorF3 { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "({}, {}, {})", self.0, self.1, self.2) - } -} diff --git a/inserter/src/algorithm/mod.rs b/inserter/src/algorithm/mod.rs index 7874b30..893185a 100644 --- a/inserter/src/algorithm/mod.rs +++ b/inserter/src/algorithm/mod.rs @@ -39,10 +39,9 @@ fn generate_temp_poses(seed: i32, target_count: usize) -> Vec { fn random_poses(tmp_poses: &mut Vec, seed: i32, max_count: usize) { let mut rand = DspRandom::new(seed); - let drunk_walk_count_rand = rand.next_f64(); let mut tmp_drunk: Vec = Vec::with_capacity(max_count); tmp_poses.push(Vector3::zero()); - let drunk_num = (drunk_walk_count_rand * DRUNK_NUM_RANGE + (MIN_DRUNK_NUM as f64)) as i32; + let drunk_num = (rand.next_f64() * DRUNK_NUM_RANGE + (MIN_DRUNK_NUM as f64)) as i32; for _ in 0..drunk_num { for _ in 0..256 { let u = rand.next_f64() * 2.0 - 1.0; @@ -141,12 +140,12 @@ pub fn generate_stars<'a>( if index == 0 { stars.push(StarWithPlanets::new( Rc::new(Star::new( - game_desc, 0, seed, Vector3::zero(), StarType::MainSeqStar, &SpectrType::X, + game_desc.star_count, )), game_desc, habitable_count, @@ -172,12 +171,12 @@ pub fn generate_stars<'a>( }; stars.push(StarWithPlanets::new( Rc::new(Star::new( - game_desc, index, seed, position, need_type, &need_spectr, + game_desc.star_count, )), game_desc, habitable_count, diff --git a/inserter/src/algorithm/tests/worldgen_test.rs b/inserter/src/algorithm/tests/worldgen_test.rs index e345868..a1c4dfb 100644 --- a/inserter/src/algorithm/tests/worldgen_test.rs +++ b/inserter/src/algorithm/tests/worldgen_test.rs @@ -2,23 +2,19 @@ mod tests { use std::cell::Cell; - use crate::data::game_desc::GameDesc; - use crate::worldgen::galaxy_gen::create_galaxy; + use crate::algorithm::data::game_desc::GameDesc; + use crate::algorithm::generate_stars; #[test] fn test_worldgen() { let game = GameDesc { star_count: 64, resource_multiplier: 1.0, - hive_initial_colonize: 1.0, - hive_max_density: 1.0, - use_actual_veins: true, }; let habitable_count = Cell::new(0_i32); - let galaxy = create_galaxy(1, &game, &habitable_count); + let galaxy = generate_stars(1, &game, &habitable_count); let _result = galaxy - .stars - .get(0) + .first() .unwrap() .get_planets() .get(3) diff --git a/inserter/src/generate_csv.rs b/inserter/src/generate_csv.rs index 7d6c714..f5257f3 100644 --- a/inserter/src/generate_csv.rs +++ b/inserter/src/generate_csv.rs @@ -7,9 +7,6 @@ pub fn gen_formatted(seed: i32) -> anyhow::Result<(String, String)> { let game_desc: GameDesc = GameDesc { star_count: crate::STAR_COUNT, resource_multiplier: crate::REC_MULTIPLIER, - hive_initial_colonize: crate::INITIAL_COLONIZE, - hive_max_density: crate::DF_MAX_DENSITY, - use_actual_veins: false }; let hab_count = std::cell::Cell::new(0i32); let galaxy = generate_stars(seed, &game_desc, &hab_count); diff --git a/inserter/src/main.rs b/inserter/src/main.rs index 27b08dd..ce2f924 100644 --- a/inserter/src/main.rs +++ b/inserter/src/main.rs @@ -31,8 +31,6 @@ use crate::metrics::TUIMode; const MAIN_INTERVAL: u64 = 100; // in in millisecs const STAR_COUNT: usize = 64; const REC_MULTIPLIER: f32 = 1.0; -const INITIAL_COLONIZE: f64 = 1.0; -const DF_MAX_DENSITY: f64 = 1.0; // The maximum amount of workers the binary supports. 32 should be way higher than what is reasonable on most machines const MAX_WORKERS: usize = 32; diff --git a/inserter/src/threads.rs b/inserter/src/threads.rs index ecc4f61..9f6ac2f 100644 --- a/inserter/src/threads.rs +++ b/inserter/src/threads.rs @@ -6,7 +6,7 @@ use crossbeam_channel::{Receiver, RecvTimeoutError, Sender}; use postgres::{Client, NoTls}; use anyhow::Result; use crate::generate_csv::gen_formatted; -use crate::{log_info, COMMITTED_SEEDS, COMMIT_COUNT, DB_STR, PROGRESS_WORKERS, REC_MULTIPLIER, STAR_COUNT}; +use crate::{log_info, COMMITTED_SEEDS, COMMIT_COUNT, DB_STR, PROGRESS_WORKERS}; use crate::misc::{COPY_PLANET, COPY_STAR}; pub fn worker_thread(seeds: Range, send: Sender<(String, String)>, id: usize) -> Result<()> { From 3288f99190cddcaef0cfed3b45712c023538f30e Mon Sep 17 00:00:00 2001 From: SuperB3333 Date: Thu, 23 Jul 2026 12:38:32 +0200 Subject: [PATCH 7/7] Removed unnecessary unsafe blocks --- inserter/src/algorithm/data/enums.rs | 16 +++++++++- inserter/src/algorithm/data/planet.rs | 6 ++-- inserter/src/algorithm/data/planet_grid.rs | 2 +- inserter/src/algorithm/data/random.rs | 34 +++++++++------------ inserter/src/algorithm/data/star.rs | 6 +--- inserter/src/algorithm/data/star_planets.rs | 30 ++++++++---------- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/inserter/src/algorithm/data/enums.rs b/inserter/src/algorithm/data/enums.rs index b8741fd..222789d 100644 --- a/inserter/src/algorithm/data/enums.rs +++ b/inserter/src/algorithm/data/enums.rs @@ -21,7 +21,21 @@ pub enum SpectrType { O = 2, X = 3, } - +impl From for SpectrType { + fn from(i: i32) -> Self { + match i { + -4 => SpectrType::M, + -3 => SpectrType::K, + -2 => SpectrType::G, + -1 => SpectrType::F, + 0 => SpectrType::A, + 1 => SpectrType::B, + 2 => SpectrType::O, + 3 => SpectrType::X, + _ => unreachable!(), // or return a default + } + } +} #[repr(i32)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum PlanetType { diff --git a/inserter/src/algorithm/data/planet.rs b/inserter/src/algorithm/data/planet.rs index 7864857..843f7df 100644 --- a/inserter/src/algorithm/data/planet.rs +++ b/inserter/src/algorithm/data/planet.rs @@ -644,7 +644,7 @@ impl<'a> Planet<'a> { for index3 in 1..15 { let vein_spot_count = vein_spots[index3 as usize]; if vein_spot_count > 0 { - let vein_type: VeinType = unsafe { std::mem::transmute(index3) }; + let vein_type: VeinType = super::enums::ORES[index3 as usize]; let mut vein = EstimatedVein::default(); vein.vein_type = vein_type; vein.min_group = vein_spot_count - 1; @@ -988,7 +988,7 @@ impl<'a> Planet<'a> { if vein_spot_count > 1 { vein_spot_count += rand2.next_i32(3) - 1; } - let vein_type: VeinType = unsafe { std::mem::transmute(index3) }; + let vein_type: VeinType = super::enums::ORES[index3 as usize]; let min_sq_dist = min_vein_spacing_sq * (if vein_type == VeinType::Oil { 100_f64 @@ -1124,7 +1124,7 @@ impl<'a> Planet<'a> { .enumerate() .filter(|(_, &amount)| amount > 0) .map(|(i, &amount)| ActualVein { - vein_type: unsafe { std::mem::transmute(i as i32) }, + vein_type: super::enums::ORES[i], amount, }) .collect() diff --git a/inserter/src/algorithm/data/planet_grid.rs b/inserter/src/algorithm/data/planet_grid.rs index b7d28b9..f78503f 100644 --- a/inserter/src/algorithm/data/planet_grid.rs +++ b/inserter/src/algorithm/data/planet_grid.rs @@ -32,7 +32,7 @@ pub struct PlanetGrid { impl PlanetGrid { pub fn get_vertex(&self, index: usize) -> &VectorF3 { - unsafe { &self.vertices.get_unchecked(index) } + &self.vertices[index] } } diff --git a/inserter/src/algorithm/data/random.rs b/inserter/src/algorithm/data/random.rs index b8f03c5..e84dc8e 100644 --- a/inserter/src/algorithm/data/random.rs +++ b/inserter/src/algorithm/data/random.rs @@ -25,27 +25,21 @@ impl DspRandom { num1 = seed_array[index2] } - let ptr = seed_array.as_mut_ptr(); - - let (chunk1_lhs, chunk1_rhs, chunk2_lhs, chunk2_rhs) = unsafe { - ( - &mut *ptr.add(1).cast::<[i32; 24]>(), - &*ptr.add(32).cast::<[i32; 24]>(), - &mut *ptr.add(25).cast::<[i32; 31]>(), - &*ptr.add(1).cast::<[i32; 31]>(), - ) - }; - - let update = |(lhs, rhs): (&mut i32, &i32)| { - *lhs = lhs.wrapping_sub(*rhs); - if lhs.is_negative() { - *lhs += i32::MAX; - } - }; - for _ in 1..5 { - chunk1_lhs.iter_mut().zip(chunk1_rhs).for_each(update); - chunk2_lhs.iter_mut().zip(chunk2_rhs).for_each(update); + for i in 0..24 { + let rhs = seed_array[32 + i]; + seed_array[1 + i] = seed_array[1 + i].wrapping_sub(rhs); + if seed_array[1 + i].is_negative() { + seed_array[1 + i] += i32::MAX; + } + } + for i in 0..31 { + let rhs = seed_array[1 + i]; + seed_array[25 + i] = seed_array[25 + i].wrapping_sub(rhs); + if seed_array[25 + i].is_negative() { + seed_array[25 + i] += i32::MAX; + } + } } Self { diff --git a/inserter/src/algorithm/data/star.rs b/inserter/src/algorithm/data/star.rs index 358200d..7d47779 100644 --- a/inserter/src/algorithm/data/star.rs +++ b/inserter/src/algorithm/data/star.rs @@ -230,11 +230,7 @@ impl Star { ) { SpectrType::X } else { - unsafe { - std::mem::transmute::( - self.get_class_factor().round_ties_even() as i32, - ) - } + (self.get_class_factor().round_ties_even() as i32).into() } }) } diff --git a/inserter/src/algorithm/data/star_planets.rs b/inserter/src/algorithm/data/star_planets.rs index 276d3d9..73c7c1a 100644 --- a/inserter/src/algorithm/data/star_planets.rs +++ b/inserter/src/algorithm/data/star_planets.rs @@ -15,8 +15,8 @@ pub struct StarWithPlanets<'a> { pub star: Rc, planets: UnsafeCell>>, - safe: UnsafeCell, - avg_veins: UnsafeCell<[f32; MAX_VEIN_COUNT]>, + safe: Cell, + avg_veins: Cell<[f32; MAX_VEIN_COUNT]>, game_desc: &'a GameDesc, habitable_count: &'a Cell, } @@ -30,21 +30,17 @@ impl<'a> StarWithPlanets<'a> { Self { star, planets: UnsafeCell::new(Vec::with_capacity(6)), - safe: UnsafeCell::new(false), - avg_veins: UnsafeCell::new([f32::NAN; MAX_VEIN_COUNT]), + safe: Cell::new(false), + avg_veins: Cell::new([f32::NAN; MAX_VEIN_COUNT]), game_desc, habitable_count, } } - pub fn is_safe(&self) -> bool { - unsafe { *self.safe.get() } - } + pub fn is_safe(&self) -> bool { self.safe.get() } pub fn mark_safe(&self) { - unsafe { - *self.safe.get() = true; - } + self.safe.set(true); } pub fn load_planets(&self) { @@ -66,10 +62,8 @@ impl<'a> StarWithPlanets<'a> { return 0.0; } let index = *vein_type as usize; - let cached_value = unsafe { - let arr = &mut *self.avg_veins.get(); - arr.get_unchecked_mut(index) - }; + let mut veins = self.avg_veins.get(); + let cached_value = &mut veins[index]; if !cached_value.is_nan() { return *cached_value; } @@ -96,7 +90,8 @@ impl<'a> StarWithPlanets<'a> { } } } - *cached_value = count; + veins[index] = count; + self.avg_veins.set(veins); self.mark_safe(); count } @@ -334,8 +329,9 @@ impl<'a> StarWithPlanets<'a> { } else { 0.45_f32 }; - let orbit_skip_threshold = - remaining_ratio + (1.0 - remaining_ratio) * skip_chance_base + 0.01; + let orbit_skip_threshold = remaining_ratio + + (1.0 - remaining_ratio) * skip_chance_base + + 0.01; if rand2.next_f64() < orbit_skip_threshold as f64 { broke_from_loop = true; break;