From b77526a748a026c9ef3accee5a70fc29b7c8af0b Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Mon, 12 Oct 2015 22:03:50 +0200 Subject: [PATCH] Don't do a negative time step in recreational mode when beyond NDL In recreational mode, we keep adding time at the last depth until an ascent does violate the ceiling. Then we roll back the last added time step and record the ascent. The test for the ceiling violated was before adding the time so if it alreay failed the first time we tried to unroll a time step that was never added which resulted in a small kink in the pressure graph. This patch corrects this logic by changin a while to a do {} while. Furthermore, it removes the computation of deco state during the final ascent since that is not used anywhere later. Signed-off-by: Robert C. Helling --- planner.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/planner.c b/planner.c index 05fd26e..22d3716 100644 --- a/planner.c +++ b/planner.c @@ -1070,15 +1070,21 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool bool safety_stop = prefs.safetystop && max_depth >= 10000; track_ascent_gas(depth, &displayed_dive.cylinder[current_cylinder], avg_depth, bottom_time, safety_stop); // How long can we stay at the current depth and still directly ascent to the surface? - while (trial_ascent(depth, 0, avg_depth, bottom_time, &displayed_dive.cylinder[current_cylinder].gasmix, - po2, diveplan->surface_pressure / 1000.0) && - enough_gas(current_cylinder)) { + do { add_segment(depth_to_bar(depth, &displayed_dive), - &displayed_dive.cylinder[current_cylinder].gasmix, - DECOTIMESTEP, po2, &displayed_dive, prefs.bottomsac); + &displayed_dive.cylinder[current_cylinder].gasmix, + DECOTIMESTEP, po2, &displayed_dive, prefs.bottomsac); update_cylinder_pressure(&displayed_dive, depth, depth, DECOTIMESTEP, prefs.bottomsac, &displayed_dive.cylinder[current_cylinder], false); clock += DECOTIMESTEP; - } + } while (trial_ascent(depth, 0, avg_depth, bottom_time, &displayed_dive.cylinder[current_cylinder].gasmix, + po2, diveplan->surface_pressure / 1000.0) && + enough_gas(current_cylinder)); + + // We did stay one DECOTIMESTEP too many. + // In the best of all worlds, we would roll back also the last add_segment in terms of caching deco state, but + // let's ignore that since for the eventual ascent in recreational mode, nobody looks at the ceiling anymore, + // so we don't really have to compute the deco state. + update_cylinder_pressure(&displayed_dive, depth, depth, -DECOTIMESTEP, prefs.bottomsac, &displayed_dive.cylinder[current_cylinder], false); clock -= DECOTIMESTEP; plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, true); previous_point_time = clock; @@ -1093,9 +1099,6 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool if (depth - deltad < 0) deltad = depth; - add_segment(depth_to_bar(depth, &displayed_dive), - &displayed_dive.cylinder[current_cylinder].gasmix, - TIMESTEP, po2, &displayed_dive, prefs.decosac); clock += TIMESTEP; depth -= deltad; if (depth <= 5000 && depth >= (5000 - deltad) && safety_stop) { -- 1.9.5 (Apple Git-50.3)