mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
During multi-dive deco calculations don't look at dives from other trips
Previously the code in init_decompression() would mindlessly walk back the dive_table until it found a gap of at least 48h and take all those dives into consideration when calculating tissue saturation. This goes horribly wrong if you load dives from two divers into the same data file. With this commit things will still turn out correctly, as long as the dives are in separate trips in for each of the divers. So with this I can load both Linus' and my divelog and things stay sane even on our shared dive trips. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
23ce727e62
commit
b94a93d061
1 changed files with 26 additions and 6 deletions
32
divelist.c
32
divelist.c
|
@ -847,9 +847,10 @@ static struct gasmix air = { .o2.permille = 209 };
|
|||
double init_decompression(struct dive *dive)
|
||||
{
|
||||
int i, divenr = -1;
|
||||
timestamp_t when;
|
||||
unsigned int surface_time;
|
||||
timestamp_t when, lasttime = 0;
|
||||
gboolean deco_init = FALSE;
|
||||
double tissue_tolerance;
|
||||
double tissue_tolerance, surface_pressure;
|
||||
|
||||
if (!dive)
|
||||
return 0.0;
|
||||
|
@ -859,16 +860,21 @@ double init_decompression(struct dive *dive)
|
|||
i = divenr;
|
||||
while (--i) {
|
||||
struct dive* pdive = get_dive(i);
|
||||
/* we don't want to mix dives from different trips as we keep looking
|
||||
* for how far back we need to go */
|
||||
if (dive->divetrip && pdive->divetrip != dive->divetrip)
|
||||
continue;
|
||||
if (!pdive || pdive->when > when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when)
|
||||
break;
|
||||
when = pdive->when;
|
||||
lasttime = when + pdive->duration.seconds;
|
||||
}
|
||||
|
||||
while (++i < divenr) {
|
||||
struct dive* pdive = get_dive(i);
|
||||
double surface_pressure = pdive->surface_pressure.mbar ? pdive->surface_pressure.mbar / 1000.0 : 1.013;
|
||||
unsigned int surface_time = get_dive(i+1)->when - pdive->when - pdive->duration.seconds;
|
||||
|
||||
/* again skip dives from different trips */
|
||||
if (dive->divetrip && dive->divetrip != pdive->divetrip)
|
||||
continue;
|
||||
surface_pressure = pdive->surface_pressure.mbar ? pdive->surface_pressure.mbar / 1000.0 : 1.013;
|
||||
if (!deco_init) {
|
||||
clear_deco(surface_pressure);
|
||||
deco_init = TRUE;
|
||||
|
@ -881,6 +887,20 @@ double init_decompression(struct dive *dive)
|
|||
printf("added dive #%d\n", pdive->number);
|
||||
dump_tissues();
|
||||
#endif
|
||||
if (pdive->when > lasttime) {
|
||||
surface_time = pdive->when - lasttime;
|
||||
lasttime = pdive->when + pdive->duration.seconds;
|
||||
tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0.0, dive);
|
||||
#if DECO_CALC_DEBUG & 2
|
||||
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));
|
||||
dump_tissues();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/* add the final surface time */
|
||||
if (lasttime && dive->when > lasttime) {
|
||||
surface_time = dive->when - lasttime;
|
||||
surface_pressure = dive->surface_pressure.mbar ? dive->surface_pressure.mbar / 1000.0 : 1.013;
|
||||
tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0.0, dive);
|
||||
#if DECO_CALC_DEBUG & 2
|
||||
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));
|
||||
|
|
Loading…
Reference in a new issue