mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
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>
This commit is contained in:
parent
97a43003c4
commit
d2f9ee8d45
2 changed files with 4 additions and 2 deletions
1
dive.h
1
dive.h
|
@ -647,6 +647,7 @@ struct divedatapoint {
|
||||||
|
|
||||||
struct diveplan {
|
struct diveplan {
|
||||||
timestamp_t when;
|
timestamp_t when;
|
||||||
|
int lastdive_nr;
|
||||||
int surface_pressure; /* mbar */
|
int surface_pressure; /* mbar */
|
||||||
int bottomsac; /* ml/min */
|
int bottomsac; /* ml/min */
|
||||||
int decosac; /* ml/min */
|
int decosac; /* ml/min */
|
||||||
|
|
|
@ -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
|
/* we alway make this relative - either from the current time or from the
|
||||||
* end of the last dive, whichever is later */
|
* end of the last dive, whichever is later */
|
||||||
timestamp_t cur = current_time_notz();
|
timestamp_t cur = current_time_notz();
|
||||||
if (dive_table.nr) {
|
if (diveplan.lastdive_nr >= 0) {
|
||||||
struct dive *last_dive = get_dive(dive_table.nr - 1);
|
struct dive *last_dive = get_dive(diveplan.lastdive_nr);
|
||||||
if (last_dive && last_dive->when + last_dive->dc.duration.seconds > cur)
|
if (last_dive && last_dive->when + last_dive->dc.duration.seconds > cur)
|
||||||
cur = last_dive->when + last_dive->dc.duration.seconds;
|
cur = last_dive->when + last_dive->dc.duration.seconds;
|
||||||
}
|
}
|
||||||
|
@ -1285,6 +1285,7 @@ void input_plan()
|
||||||
if (diveplan.dp)
|
if (diveplan.dp)
|
||||||
free_dps(diveplan.dp);
|
free_dps(diveplan.dp);
|
||||||
memset(&diveplan, 0, sizeof(diveplan));
|
memset(&diveplan, 0, sizeof(diveplan));
|
||||||
|
diveplan.lastdive_nr = dive_table.nr - 1;
|
||||||
free(cache_data);
|
free(cache_data);
|
||||||
cache_data = NULL;
|
cache_data = NULL;
|
||||||
planned_dive = NULL;
|
planned_dive = NULL;
|
||||||
|
|
Loading…
Reference in a new issue