aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.c35
-rw-r--r--dive.h2
-rw-r--r--divelist.c12
-rw-r--r--info.c2
-rw-r--r--print.c4
-rw-r--r--statistics.c8
6 files changed, 32 insertions, 31 deletions
diff --git a/dive.c b/dive.c
index ef05c51fe..d66c30826 100644
--- a/dive.c
+++ b/dive.c
@@ -219,17 +219,6 @@ static void update_duration(duration_t *duration, int new)
duration->seconds = new;
}
-int get_duration_in_sec(struct dive *dive)
-{
- int duration = 0;
- struct divecomputer *dc = &dive->dc;
- do {
- duration = MAX(duration, dc->duration.seconds);
- dc = dc->next;
- } while (dc);
- return duration;
-}
-
static void update_temperature(temperature_t *temperature, int new)
{
if (new) {
@@ -469,6 +458,17 @@ static void fixup_meandepth(struct dive *dive)
dive->meandepth.mm = (sum + nr / 2) / nr;
}
+static void fixup_duration(struct dive *dive)
+{
+ struct divecomputer *dc;
+ int duration = 0;
+
+ for_each_dc(dive, dc)
+ duration = MAX(duration, dc->duration.seconds);
+
+ dive->duration.seconds = duration;
+}
+
/*
* events are stored as a linked list, so the concept of
* "consecutive, identical events" is somewhat hard to
@@ -661,6 +661,7 @@ struct dive *fixup_dive(struct dive *dive)
fixup_water_salinity(dive);
fixup_surface_pressure(dive);
fixup_meandepth(dive);
+ fixup_duration(dive);
for_each_dc(dive, dc)
fixup_dive_dc(dive, dc);
@@ -1302,9 +1303,9 @@ static int likely_same_dive(struct dive *a, struct dive *b)
* Do some basic sanity testing of the values we
* have filled in during 'fixup_dive()'
*/
- if (!similar(a->dc.maxdepth.mm, b->dc.maxdepth.mm, 1000) ||
- !similar(a->dc.meandepth.mm, b->dc.meandepth.mm, 1000) ||
- !similar(get_duration_in_sec(a), get_duration_in_sec(b), 5*60))
+ if (!similar(a->maxdepth.mm, b->maxdepth.mm, 1000) ||
+ !similar(a->meandepth.mm, b->meandepth.mm, 1000) ||
+ !similar(a->duration.seconds, b->duration.seconds, 5*60))
return 0;
/* See if we can get an exact match on the dive computer */
@@ -1316,7 +1317,7 @@ static int likely_same_dive(struct dive *a, struct dive *b)
* Allow a time difference due to dive computer time
* setting etc. Check if they overlap.
*/
- fuzz = MAX(get_duration_in_sec(a), get_duration_in_sec(b)) / 2;
+ fuzz = MAX(a->duration.seconds, b->duration.seconds) / 2;
if (fuzz < 60)
fuzz = 60;
@@ -1604,7 +1605,7 @@ struct dive *find_dive_including(timestamp_t when)
* also we always use the duration from the first divecomputer
* could this ever be a problem? */
for_each_dive(i, dive) {
- if (dive->when <= when && when <= dive->when + get_duration_in_sec(dive))
+ if (dive->when <= when && when <= dive->when + dive->duration.seconds)
return dive;
}
return NULL;
@@ -1612,7 +1613,7 @@ struct dive *find_dive_including(timestamp_t when)
gboolean dive_within_time_range(struct dive *dive, timestamp_t when, timestamp_t offset)
{
- return when - offset <= dive->when && dive->when + get_duration_in_sec(dive) <= when + offset;
+ return when - offset <= dive->when && dive->when + dive->duration.seconds <= when + offset;
}
/* find the n-th dive that is part of a group of dives within the offset around 'when'.
diff --git a/dive.h b/dive.h
index 830fcce7d..ace1c9fc2 100644
--- a/dive.h
+++ b/dive.h
@@ -323,6 +323,7 @@ struct dive {
temperature_t mintemp, maxtemp;
depth_t maxdepth, meandepth;
pressure_t surface_pressure;
+ duration_t duration;
int salinity; // kg per 10000 l
struct divecomputer dc;
@@ -557,7 +558,6 @@ extern void report_dives(gboolean imported, gboolean prefer_imported);
extern struct dive *fixup_dive(struct dive *dive);
extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean prefer_downloaded);
extern struct dive *try_to_merge(struct dive *a, struct dive *b, gboolean prefer_downloaded);
-extern int get_duration_in_sec(struct dive *dive);
extern void renumber_dives(int nr);
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
diff --git a/divelist.c b/divelist.c
index 7d887d353..70a99f9c6 100644
--- a/divelist.c
+++ b/divelist.c
@@ -780,10 +780,10 @@ double init_decompression(struct dive *dive)
* for how far back we need to go */
if (dive->divetrip && pdive->divetrip != dive->divetrip)
continue;
- if (!pdive || pdive->when > when || pdive->when + get_duration_in_sec(pdive) + 48 * 60 * 60 < when)
+ if (!pdive || pdive->when > when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when)
break;
when = pdive->when;
- lasttime = when + get_duration_in_sec(pdive);
+ lasttime = when + pdive->duration.seconds;
}
while (++i < divenr) {
struct dive* pdive = get_dive(i);
@@ -805,7 +805,7 @@ double init_decompression(struct dive *dive)
#endif
if (pdive->when > lasttime) {
surface_time = pdive->when - lasttime;
- lasttime = pdive->when + get_duration_in_sec(pdive);
+ lasttime = pdive->when + pdive->duration.seconds;
tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0, dive);
#if DECO_CALC_DEBUG & 2
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));
@@ -1318,7 +1318,7 @@ static void fill_dive_list(void)
DIVE_NR, dive->number,
DIVE_DATE, dive->when,
DIVE_DEPTH, dive->maxdepth,
- DIVE_DURATION, get_duration_in_sec(dive),
+ DIVE_DURATION, dive->duration.seconds,
DIVE_LOCATION, dive->location,
DIVE_LOC_ICON, icon,
DIVE_RATING, dive->rating,
@@ -1331,7 +1331,7 @@ static void fill_dive_list(void)
DIVE_NR, dive->number,
DIVE_DATE, dive->when,
DIVE_DEPTH, dive->maxdepth,
- DIVE_DURATION, get_duration_in_sec(dive),
+ DIVE_DURATION, dive->duration.seconds,
DIVE_LOCATION, dive->location,
DIVE_LOC_ICON, icon,
DIVE_RATING, dive->rating,
@@ -2361,7 +2361,7 @@ static void add_dive_merge_label(int idx, GtkMenuShell *menu)
return;
/* .. and if the surface interval is excessive, you must be kidding us */
- if (b->when > a->when + get_duration_in_sec(a) + 30*60)
+ if (b->when > a->when + a->duration.seconds + 30*60)
return;
/* If so, we can add a "merge dive" menu entry */
diff --git a/info.c b/info.c
index d64b4775c..47cca5621 100644
--- a/info.c
+++ b/info.c
@@ -1151,7 +1151,7 @@ static timestamp_t dive_time_widget(struct dive *dive)
*/
if (amount_selected == 1) {
timestamp_t when = current_dive->when;
- when += get_duration_in_sec(current_dive);
+ when += current_dive->duration.seconds;
when += 60*60;
utc_mkdate(when, &tm);
time = &tm;
diff --git a/print.c b/print.c
index 928fbb4d4..ec37675ac 100644
--- a/print.c
+++ b/print.c
@@ -101,7 +101,7 @@ static void show_dive_header(struct dive *dive, cairo_t *cr, double w,
snprintf(buffer, sizeof(buffer),
_("Max depth: %.*f %s\nDuration: %d min\n%s"),
decimals, depth, unit,
- (dive->dc.duration.seconds+59) / 60,
+ (dive->duration.seconds+59) / 60,
people);
set_font(layout, font, FONT_NORMAL*(1.5/w_scale_factor), PANGO_ALIGN_RIGHT);
pango_layout_set_text(layout, buffer, -1);
@@ -597,7 +597,7 @@ static void show_dive_table(struct dive *dive, cairo_t *cr, double w,
// Col 4: Time
len = snprintf(buffer, sizeof(buffer),
- _("%d min"),(dive->dc.duration.seconds+59) / 60);
+ _("%d min"),(dive->duration.seconds + 59) / 60);
cairo_move_to(cr, curwidth / PANGO_SCALE, 0);
pango_layout_set_width(layout, colwidth/ (double) 2);
pango_layout_set_text(layout, buffer, len);
diff --git a/statistics.c b/statistics.c
index 43e12efed..d87353b7f 100644
--- a/statistics.c
+++ b/statistics.c
@@ -127,7 +127,7 @@ static void process_temperatures(struct dive *dp, stats_t *stats)
static void process_dive(struct dive *dp, stats_t *stats)
{
int old_tt, sac_time = 0;
- int duration = get_duration_in_sec(dp);
+ int duration = dp->duration.seconds;
old_tt = stats->total_time.seconds;
stats->total_time.seconds += duration;
@@ -414,7 +414,7 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive)
*prev_dive = NULL;
memset(&stats, 0, sizeof(stats));
if (dive_table.nr > 0) {
- stats.shortest_time.seconds = get_duration_in_sec(dive_table.dives[0]);
+ stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds;
stats.min_depth.mm = dive_table.dives[0]->maxdepth.mm;
stats.selection_size = dive_table.nr;
}
@@ -553,10 +553,10 @@ static void show_single_dive_stats(struct dive *dive)
tm.tm_hour, tm.tm_min);
set_label(single_w.date, buf);
- set_label(single_w.dive_time, _("%d min"), (get_duration_in_sec(dive) + 30) / 60);
+ set_label(single_w.dive_time, _("%d min"), (dive->duration.seconds + 30) / 60);
if (prev_dive)
set_label(single_w.surf_intv,
- get_time_string(dive->when - (prev_dive->when + get_duration_in_sec(prev_dive)), 4));
+ get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4));
else
set_label(single_w.surf_intv, _("unknown"));
value = get_depth_units(dc->maxdepth.mm, &decimals, &unit);