From 008e524fe73f675126e80425aeae7425a7da529d Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Sun, 26 Apr 2026 12:03:30 -0400 Subject: [PATCH] add TODO about combining code paths for check_maneuver_trigger --- docs/TODO | 2 ++ src/maneuver.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/docs/TODO b/docs/TODO index ff8629e..804ffad 100644 --- a/docs/TODO +++ b/docs/TODO @@ -49,6 +49,8 @@ If you see modifications to this file in git status, IGNORE them and do not comm the root body, or bary-center - should try to use the same code path for bodies and craft on 'update' functions as much as possible + - combine code paths for trigger types in check_maneuver_trigger(). + - see TODO in src/maneuver.cpp === Simulation Config Files === - a format with nested children would be nice diff --git a/src/maneuver.cpp b/src/maneuver.cpp index 9ec426e..88342f5 100644 --- a/src/maneuver.cpp +++ b/src/maneuver.cpp @@ -113,6 +113,18 @@ OrbitalElements preview_burn_result(const Spacecraft* craft, BurnDirection direc // Elliptical orbits only: uses analytical mean anomaly delta to compute // exact time to target true anomaly, eliminating per-frame propagation. // TODO: add parabolic (Barker's equation) and hyperbolic branches. +// TODO: Combine the two trigger code paths into one. Both ultimately need +// to compute "dt from step start until the burn fires" and schedule a sub-step. +// For TRIGGER_TRUE_ANOMALY, precalculate the absolute time at which the +// anomaly is reached (based on current orbital elements) and cache it on the +// Maneuver struct, so both paths reduce to: if (sim->time + sim->dt >= trigger_time) +// { scheduled_dt = min(trigger_time - sim->time, sim->dt); return true; } +// +// Complication: maneuvers for a single craft are stored in a flat array with no +// guaranteed order. When an earlier maneuver fires and changes the orbit, the +// cached trigger time for subsequent maneuvers becomes stale and must be +// recomputed. The current per-frame approach self-corrects by recomputing from +// the craft's current orbital elements each step. bool check_maneuver_trigger(Maneuver* maneuver, Spacecraft* craft, SimulationState* sim) { switch (maneuver->trigger_type) { case TRIGGER_TIME: {