diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-01-08 13:48:36 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-08 13:53:57 -0800 |
commit | bad7882ae141efbee3a339046c4a8f5b51ef89c6 (patch) | |
tree | 37da181b06581bde28f20a350f193d06f7668253 /planner.c | |
parent | 77f4802ed66a3c2793199805100ece51056cbabf (diff) | |
download | subsurface-bad7882ae141efbee3a339046c4a8f5b51ef89c6.tar.gz |
Improve travel logic code for the ascent in the planner
This shouldn't change the the actual stops we do or the travel time how we
get there, but it makes the code more logical. From the end depth of the
planned dive we have ONE transition to the first stop depth (which may be
the surface). And then for every stop we (potentially) have a wait and
travel to the next stop.
Once we are in the while loop, we know that we are at a stop level, so
there is no point to keep checking if we first need to transition to the
stop.
It does create one additional improvement: if we don't need any stops at
all, then we don't transition to the first stop and then from there to the
surface. We do it in one step. The overall profile / traveltime remains
the same, we just drop one intermediate sample on the way.
This also improves a few ugly (and in one case, wrong) debug statements.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r-- | planner.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -307,32 +307,36 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep) #if DEBUG_PLAN & 2 printf("ceiling %5.2lfm\n", ceiling / 1000.0); #endif - for (stopidx = 1; stopidx < sizeof(stoplevels) / sizeof(int); stopidx++) + for (stopidx = 0; stopidx < sizeof(stoplevels) / sizeof(int); stopidx++) if (stoplevels[stopidx] >= ceiling) break; + /* now get us to the first stop - NOTE, this could be 0m! */ #if DEBUG_PLAN & 2 printf("first stop at %5.2lfm\n", stoplevels[stopidx] / 1000.0); #endif - while (stopidx > 0) { - depth = dive->dc.sample[dive->dc.samples - 1].depth.mm; - if (depth > stoplevels[stopidx]) { - transitiontime = (depth - stoplevels[stopidx]) / 150; - plan_add_segment(diveplan, transitiontime, stoplevels[stopidx], o2, he); - /* re-create the dive */ - delete_single_dive(dive_table.nr - 1); - *divep = dive = create_dive_from_plan(diveplan); - record_dive(dive); - } + depth = dive->dc.sample[dive->dc.samples - 1].depth.mm; + if (depth > stoplevels[stopidx]) { + transitiontime = (depth - stoplevels[stopidx]) / 150; +#if DEBUG_PLAN & 2 + printf("transitiontime %d:%02d to depth %5.2lfm\n", FRACTION(transitiontime, 60), stoplevels[stopidx] / 1000.0); +#endif + plan_add_segment(diveplan, transitiontime, stoplevels[stopidx], o2, he); + /* re-create the dive */ + delete_single_dive(dive_table.nr - 1); + *divep = dive = create_dive_from_plan(diveplan); + record_dive(dive); + } + while (stopidx > 0) { /* this indicates that we had a non-zero first ceiling */ wait_time = time_at_last_depth(dive, stoplevels[stopidx - 1], cached_datap); #if DEBUG_PLAN & 2 - printf("waittime %d:%2d\n", FRACTION(wait_time, 60)); + printf("waittime %d:%02d at depth %5.2lfm\n", FRACTION(wait_time, 60), stoplevels[stopidx] / 1000.0); #endif if (wait_time) plan_add_segment(diveplan, wait_time, stoplevels[stopidx], o2, he); transitiontime = (stoplevels[stopidx] - stoplevels[stopidx - 1]) / 150; #if DEBUG_PLAN & 2 - printf("transitiontime %d:%2d to depth %5.2lfm\n", FRACTION(wait_time, 60), stoplevels[stopidx - 1] / 1000.0); + printf("transitiontime %d:%02d to depth %5.2lfm\n", FRACTION(transitiontime, 60), stoplevels[stopidx - 1] / 1000.0); #endif plan_add_segment(diveplan, transitiontime, stoplevels[stopidx - 1], o2, he); /* re-create the dive */ |