Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 6 additions & 29 deletions inserter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +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"
serde = { version = "1.0.193", features = ["derive", "rc"] }

# 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 }


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"

[features]
default = ["binary"]
binary = ["crossbeam-channel", "postgres", "crossterm", "anyhow", "lazy_static", "itertools"]
python = ["pyo3", "pythonize"]
56 changes: 23 additions & 33 deletions inserter/src/algorithm/data/enums.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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,
Expand All @@ -11,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, Deserialize, Serialize)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
#[allow(dead_code)]
pub enum SpectrType {
M = -4,
K = -3,
Expand All @@ -30,33 +21,39 @@ pub enum SpectrType {
O = 2,
X = 3,
}

#[allow(dead_code)]
impl From<i32> 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, Deserialize, Serialize)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum PlanetType {
None,
Volcano,
Ocean,
Desert,
Ice,
Gas,
}

impl Default for PlanetType {
fn default() -> Self {
Self::None
}
}

#[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,
Interstellar,
Rare,
Interstellar
}

impl Default for ThemeDistribute {
Expand All @@ -65,9 +62,8 @@ 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,
Expand All @@ -87,12 +83,6 @@ pub enum VeinType {
Max,
}

impl Default for VeinType {
fn default() -> Self {
Self::None
}
}

impl VeinType {
pub fn is_rare(&self) -> bool {
matches!(
Expand Down
8 changes: 0 additions & 8 deletions inserter/src/algorithm/data/galaxy.rs

This file was deleted.

36 changes: 1 addition & 35 deletions inserter/src/algorithm/data/game_desc.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
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
Expand All @@ -52,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
}
}
}
14 changes: 1 addition & 13 deletions inserter/src/algorithm/data/math.rs
Original file line number Diff line number Diff line change
@@ -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<T: PartialOrd>(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
Expand Down
2 changes: 0 additions & 2 deletions inserter/src/algorithm/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod birth_points;
pub mod enums;
pub mod galaxy;
pub mod game_desc;
pub mod math;
pub mod planet;
Expand All @@ -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;
Expand Down
68 changes: 14 additions & 54 deletions inserter/src/algorithm/data/planet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ 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;

#[derive(Debug)]
pub struct Planet<'a> {
game_desc: &'a GameDesc,
pub star: Rc<Star<'a>>,
pub star: Rc<Star>,
pub index: usize,
habitable_count: &'a Cell<i32>,
pub seed: i32,
Expand Down Expand Up @@ -64,7 +63,7 @@ const ORBIT_RADIUS: &'static [f32] = &[
impl<'a> Planet<'a> {
pub fn new(
game_desc: &'a GameDesc,
star: Rc<Star<'a>>,
star: Rc<Star>,
index: usize,
habitable_count: &'a Cell<i32>,
orbit_index: usize,
Expand Down Expand Up @@ -225,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);
}
Expand Down Expand Up @@ -286,6 +274,7 @@ impl<'a> Planet<'a> {
}
}

#[inline]
pub fn is_tidal_locked(&self) -> bool {
self.get_rotation_period() == self.get_orbital_period()
}
Expand Down Expand Up @@ -554,12 +543,12 @@ impl<'a> Planet<'a> {
}
let mut output: Vec<EstimatedVein> = 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<i32> = (0..15_i32)
.map(|i| *theme_proto.vein_spot.get((i - 1) as usize).unwrap_or(&0))
Expand Down Expand Up @@ -655,8 +644,8 @@ 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 mut vein = EstimatedVein::new();
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;
vein.max_group = vein_spot_count + 1;
Expand Down Expand Up @@ -999,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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -1136,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()
Expand Down Expand Up @@ -1214,32 +1202,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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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()
}
}
];
Loading