summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-27 10:22:51 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-27 10:22:51 -0800
commitd2f9ee8d45ef9c87f0981f7b786a757f631b792b (patch)
tree17bffd80c9bd07752e474775d713da8cb02f4570 /planner.c
parent97a43003c461427b99e1aa0dfc165841bdeaf90e (diff)
downloadsubsurface-d2f9ee8d45ef9c87f0981f7b786a757f631b792b.tar.gz
Planner: don't use the planned dive for relative start time
The existing code has an embarrassing error in its logic. It picked the last dive in the table and made sure that the relative start time was either N minutes after 'now' or N minutes after the last dive ends, whichever is later. But once the planned dive has been added to the dive list (so once we have a first depth and time entry, that last dive now is the planned dive. And every time focus left the start time field the start time would be recalculated relative to the end of the dive we are currently planning. With this patch we instead simply remember the number of the last dive just as we create the dive plan and use that to look up the end time of previous dive. I could have just stored that end time but I figured maybe there could be other reasons to go back to the last dive before the planned dive, so this seemed cleaner. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/planner.c b/planner.c
index b6c4d521c..d5a733e6e 100644
--- a/planner.c
+++ b/planner.c
@@ -1138,8 +1138,8 @@ static gboolean starttime_focus_out_cb(GtkWidget *entry, GdkEvent * event, gpoin
/* we alway make this relative - either from the current time or from the
* end of the last dive, whichever is later */
timestamp_t cur = current_time_notz();
- if (dive_table.nr) {
- struct dive *last_dive = get_dive(dive_table.nr - 1);
+ if (diveplan.lastdive_nr >= 0) {
+ struct dive *last_dive = get_dive(diveplan.lastdive_nr);
if (last_dive && last_dive->when + last_dive->dc.duration.seconds > cur)
cur = last_dive->when + last_dive->dc.duration.seconds;
}
@@ -1285,6 +1285,7 @@ void input_plan()
if (diveplan.dp)
free_dps(diveplan.dp);
memset(&diveplan, 0, sizeof(diveplan));
+ diveplan.lastdive_nr = dive_table.nr - 1;
free(cache_data);
cache_data = NULL;
planned_dive = NULL;