From aca56351ffc166899787c75c5533642e0db45273 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Thu, 22 Jan 2026 10:21:33 -0500 Subject: [PATCH] Fix: Remove duplicate maneuver execution code Remove duplicate code blocks that were executing maneuvers twice. Fix ensures correct update order: 1. Body RK4 updates 2. Body global coords 3. Spacecraft RK4 updates 4. Maneuver execution (once, with executed flag check) 5. Spacecraft global coords (from updated local_velocity) This eliminates the redundant 'execute pending maneuvers' and 'compute spacecraft globals' blocks that were duplicated in the code. --- src/simulation.cpp | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/simulation.cpp b/src/simulation.cpp index 5300027..f5f999e 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -251,42 +251,10 @@ void update_simulation(SimulationState* sim) { } } - // Execute pending maneuvers (before computing globals) - for (int i = 0; i < sim->maneuver_count; i++) { - Maneuver* maneuver = &sim->maneuvers[i]; - - if (maneuver->executed) { - continue; - } - - if (maneuver->craft_index < 0 || maneuver->craft_index >= sim->craft_count) { - continue; - } - - Spacecraft* craft = &sim->spacecraft[maneuver->craft_index]; - - if (check_maneuver_trigger(maneuver, craft, sim)) { - execute_maneuver(maneuver, craft, sim->time); - } - } - - // Compute spacecraft global coordinates (after maneuvers) - for (int i = 0; i < sim->craft_count; i++) { - Spacecraft* craft = &sim->spacecraft[i]; - - if (craft->parent_index >= 0 && craft->parent_index < sim->body_count) { - CelestialBody* parent = &sim->bodies[craft->parent_index]; - craft->position = vec3_add(parent->position, craft->local_position); - craft->velocity = vec3_add(parent->velocity, craft->local_velocity); - } else { - craft->position = craft->local_position; - craft->velocity = craft->local_velocity; - } - } - sim->time += sim->dt; } + // Calculate orbital velocity using vis-viva equation // Returns velocity vector for body relative to parent static Vec3 calc_orbital_velocity(CelestialBody* body, CelestialBody* parent) {