diff --git a/Cargo.toml b/Cargo.toml index a413f9d..ae7dbb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,5 @@ once_cell = "1.21.3" serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.140" bevy = "0.13" +serde_toml = "0.0.1" +toml = "0.8.23" diff --git a/config/planets.toml b/config/planets.toml new file mode 100644 index 0000000..eb0d589 --- /dev/null +++ b/config/planets.toml @@ -0,0 +1,30 @@ +# Simulation body configuration +[[bodies]] +name = "Mercury" +mass = 3.30104e23 # kg +position = [46000000000.0, 0.0, 0.0] # meters +velocity = [0.0, 58970.0, 0.0] # m/s + +[[bodies]] +name = "Venus" +mass = 4.867e24 +position = [108941000000.0, 0.0, 0.0] +velocity = [0.0, 34780.0, 0.0] + +[[bodies]] +name = "Earth" +mass = 5.972e24 +position = [147095000000.0, 0.0, 0.0] +velocity = [0.0, 29290.0, 0.0] + +[[bodies]] +name = "Moon" +mass = 7.34767309e22 +position = [149982270700.0, 0.0, 0.0] +velocity = [0.0, 30822.0, 0.0] + +[[bodies]] +name = "Sun" +mass = 1.989e30 +position = [0.0, 0.0, 0.0] +velocity = [0.0, 0.0, 0.0] diff --git a/src/bin/simulator.rs b/src/bin/simulator.rs index 2d47561..08080d4 100644 --- a/src/bin/simulator.rs +++ b/src/bin/simulator.rs @@ -1,6 +1,7 @@ // Standard library use std::error::Error; use std::fs::File; +use std::fs; use std::io::BufReader; use std::path::Path; use std::time::{Duration,Instant}; @@ -46,12 +47,10 @@ struct Args { } fn read_config>(path: P) -> Result> { - let file = File::open(path)?; - let reader = BufReader::new(file); + let content = fs::read_to_string(&path)?; + let conf = toml::from_str(&content)?; - let u = serde_json::from_reader(reader)?; - - Ok(u) + Ok(conf) } //fn parse_time(arg: &str) diff --git a/src/config.rs b/src/config.rs index 4182ec6..efb78ec 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,6 +13,17 @@ pub struct Body { pub acceleration: types::Acceleration, } +#[derive(Debug, Deserialize, Serialize)] +pub struct Normalization { + pub name: String, + pub mass: types::Mass, + pub position: types::Position, + pub velocity: types::Velocity, + + #[serde(default)] + pub acceleration: types::Acceleration, +} + #[derive(Debug, Deserialize)] pub struct ConfigFile { pub bodies: Vec,