summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2015-10-12 22:03:50 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-12 13:46:51 -0700
commit1c7bc14af9a2ce29cb0f4bebbe3755ce46f31ef4 (patch)
treed1954eebd00d4bc85eb2f403829c2212c6050d5d /planner.c
parentb2deb28f58483122f31bfee64c3f7b23644bf8a3 (diff)
downloadsubsurface-1c7bc14af9a2ce29cb0f4bebbe3755ce46f31ef4.tar.gz
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 <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/planner.c b/planner.c
index 05fd26e31..22d37165a 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) {