From 2107cf1ace4e7c34ea306328bfd372227c61cdad Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Wed, 7 Jan 2026 15:07:23 -0500 Subject: [PATCH] Fix formatting issues in TOML config loader --- configs/example_binary_star.txt | 20 ----------------- configs/solar_system.txt | 31 ------------------------- configs/test_simple.txt | 40 --------------------------------- src/config_loader.cpp | 12 +++++----- 4 files changed, 6 insertions(+), 97 deletions(-) delete mode 100644 configs/example_binary_star.txt delete mode 100644 configs/solar_system.txt delete mode 100644 configs/test_simple.txt diff --git a/configs/example_binary_star.txt b/configs/example_binary_star.txt deleted file mode 100644 index dea2d18..0000000 --- a/configs/example_binary_star.txt +++ /dev/null @@ -1,20 +0,0 @@ -# Binary Star System with Planets -# A simple example of two stars orbiting each other with planets around them - -# Star A (yellow, index 0) - positioned to the right -StarA 1.5e30 8.0e8 3.0e11 0 0 -1 1.0 1.0 0.2 - -# Star B (blue, index 1) - positioned to the left -StarB 1.2e30 7.0e8 -3.7e11 0 0 -1 0.3 0.5 1.0 - -# Planet orbiting Star A (index 2, parent is StarA at index 0) -PlanetA1 6.0e24 7.0e6 3.5e11 0 0 0 0.8 0.3 0.2 - -# Planet orbiting Star B (index 3, parent is StarB at index 1) -PlanetB1 4.0e24 6.0e6 -4.2e11 0 0 1 0.2 0.8 0.6 - -# Moon orbiting PlanetA1 (index 4, parent is PlanetA1 at index 2) -MoonA1 1.0e23 2.0e6 3.52e11 0 0 2 0.7 0.7 0.7 - -# Second planet orbiting Star A (index 5, parent is StarA at index 0) -PlanetA2 8.0e24 8.0e6 4.0e11 0 0 0 0.5 0.6 0.3 diff --git a/configs/solar_system.txt b/configs/solar_system.txt deleted file mode 100644 index 9df58d2..0000000 --- a/configs/solar_system.txt +++ /dev/null @@ -1,31 +0,0 @@ -# Solar System Configuration -# Format: name mass(kg) radius(m) x(m) y(m) z(m) parent_index r g b -# parent_index: -1 for Sun, 0 for Sun's children, etc. -# Colors are RGB values from 0.0 to 1.0 - -# The Sun (index 0) -Sun 1.989e30 6.96e8 0 0 0 -1 1.0 1.0 0.0 - -# Inner planets -Mercury 3.285e23 2.4397e6 5.791e10 0 0 0 0.5 0.5 0.5 -Venus 4.867e24 6.0518e6 1.082e11 0 0 0 0.9 0.7 0.3 -Earth 5.972e24 6.371e6 1.496e11 0 0 0 0.0 0.5 1.0 -Mars 6.39e23 3.3895e6 2.279e11 0 0 0 0.8 0.3 0.1 - -# Outer planets -Jupiter 1.898e27 6.9911e7 7.785e11 0 0 0 0.9 0.7 0.5 -Saturn 5.683e26 5.8232e7 1.434e12 0 0 0 0.9 0.8 0.6 -Uranus 8.681e25 2.5362e7 2.871e12 0 0 0 0.5 0.8 0.9 -Neptune 1.024e26 2.4622e7 4.495e12 0 0 0 0.2 0.4 0.9 - -# Earth's Moon (index 9, parent is Earth at index 3) -Moon 7.342e22 1.737e6 1.500e11 0 0 3 0.7 0.7 0.7 - -# Jupiter's major moons (parent is Jupiter at index 5) -Io 8.93e22 1.822e6 8.207e11 0 0 5 0.9 0.9 0.3 -Europa 4.80e22 1.561e6 8.456e11 0 0 5 0.8 0.8 0.7 -Ganymede 1.48e23 2.634e6 8.853e11 0 0 5 0.6 0.6 0.5 -Callisto 1.08e23 2.410e6 9.670e11 0 0 5 0.5 0.5 0.4 - -# Saturn's largest moon (parent is Saturn at index 6) -Titan 1.345e23 2.575e6 1.556e12 0 0 6 0.9 0.6 0.3 diff --git a/configs/test_simple.txt b/configs/test_simple.txt deleted file mode 100644 index 5321f03..0000000 --- a/configs/test_simple.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Simple Test Configuration -# Planets in circular and eccentric orbits -# -# Orbital periods (for verification): -# Earth: ~365 days -# Mars: ~687 days -# Comet: ~1444 days -# -# At t=0: -# Earth starts at (1.0 AU, 0, 0) = (1.496e11 m, 0, 0) -# Mars starts at (1.5 AU, 0, 0) = (2.244e11 m, 0, 0) -# Comet starts at perihelion (0.75 AU, 0, 0) = (1.122e11 m, 0, 0) -# All orbit counter-clockwise when viewed from +Z -# -# Format: name mass(kg) radius(m) x(m) y(m) z(m) parent_index r g b eccentricity semi_major_axis(m) - -# Sun at origin (index 0) -Sun 1.989e30 6.96e8 0 0 0 -1 1.0 1.0 0.0 0 0 - -# Earth at 1 AU - circular orbit (index 1, parent Sun) -Earth 5.972e24 6.371e6 1.496e11 0 0 0 0.0 0.5 1.0 0 1.496e11 - -# Mars at 1.5 AU - circular orbit (index 2, parent Sun) -Mars 6.39e23 3.3895e6 2.244e11 0 0 0 0.8 0.3 0.1 0 2.244e11 - -# Comet - eccentric orbit (e=0.7, a=2.5 AU) -# At perihelion: 0.75 AU, aphelion: 4.25 AU -Comet 1e14 5e3 1.122e11 0 0 0 0.5 0.8 1.0 0.7 3.74e11 - -# Parabolic object - escape trajectory (e=1.0, at perihelion 0.5 AU) -# Exactly at escape velocity -Parabolic 1e13 3e3 7.48e10 0 0 0 1.0 1.0 0.5 1.0 7.48e10 - -# Inclined asteroid - circular orbit at 1.2 AU, 30 deg inclination -# Position: x=1.2AU*cos(0)=1.2AU, y=0, z=1.2AU*sin(30deg)=0.6AU -Inclined 1e12 2e3 1.795e11 0 3.114e10 0 0.8 0.8 0.0 0 1.795e11 - -# Hyperbolic visitor - incoming from interstellar space (e=1.5, a=-1.0 AU) -# At perihelion 0.5 AU with high velocity -Hyperbolic 1e13 3e3 7.48e10 0 0 0 0.3 1.0 0.3 1.5 -1.496e11 diff --git a/src/config_loader.cpp b/src/config_loader.cpp index a21bdce..cd57745 100644 --- a/src/config_loader.cpp +++ b/src/config_loader.cpp @@ -8,14 +8,14 @@ bool extract_vec3_from_table(toml_datum_t table, Vec3* pos) { toml_datum_t x = toml_get(table, "x"); toml_datum_t y = toml_get(table, "y"); toml_datum_t z = toml_get(table, "z"); - + // Accept both INT64 and FP64 for coordinates (TOML may parse integers as floats) if ((x.type != TOML_FP64 && x.type != TOML_INT64) || (y.type != TOML_FP64 && y.type != TOML_INT64) || (z.type != TOML_FP64 && z.type != TOML_INT64)) { return false; } - + pos->x = x.type == TOML_FP64 ? x.u.fp64 : (double)x.u.int64; pos->y = y.type == TOML_FP64 ? y.u.fp64 : (double)y.u.int64; pos->z = z.type == TOML_FP64 ? z.u.fp64 : (double)z.u.int64; @@ -27,7 +27,7 @@ bool extract_color_from_table(toml_datum_t table, float* color) { toml_datum_t r = toml_get(table, "r"); toml_datum_t g = toml_get(table, "g"); toml_datum_t b = toml_get(table, "b"); - + // Accept both INT64 and FP64 for color components if ((r.type != TOML_FP64 && r.type != TOML_INT64) || (g.type != TOML_FP64 && g.type != TOML_INT64) || @@ -59,8 +59,8 @@ bool parse_toml_body(toml_datum_t body_table, CelestialBody* body) { toml_datum_t semi_major = toml_get(body_table, "semi_major_axis"); // Accept both INT64 and FP64 for parent_index (TOML may parse integers as floats) - if (mass.type != TOML_FP64 || radius.type != TOML_FP64 || - (parent_idx.type != TOML_INT64 && parent_idx.type != TOML_FP64) || + if (mass.type != TOML_FP64 || radius.type != TOML_FP64 || + (parent_idx.type != TOML_INT64 && parent_idx.type != TOML_FP64) || eccentricity.type != TOML_FP64 || semi_major.type != TOML_FP64) { return false; @@ -326,4 +326,4 @@ void calculate_soi_radii(SimulationState* sim) { update_soi(body, parent, body->semi_major_axis); } } -} +} \ No newline at end of file