mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Planner: correctly track gas used
This part of the algorithm was off as part of it (but not all of it - crazy, I know) assumed the old semantic for gas changes where the new gas was introduced at the end of the segment and not at the beginning. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
2a871d7fe5
commit
fb4d9b34f8
1 changed files with 7 additions and 10 deletions
17
planner.c
17
planner.c
|
@ -246,6 +246,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
int oldo2, oldhe;
|
int oldo2, oldhe;
|
||||||
int oldpo2 = 0;
|
int oldpo2 = 0;
|
||||||
int lasttime = 0;
|
int lasttime = 0;
|
||||||
|
int lastdepth = 0;
|
||||||
|
|
||||||
if (!diveplan || !diveplan->dp)
|
if (!diveplan || !diveplan->dp)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -307,15 +308,12 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
int idx;
|
int idx;
|
||||||
if ((idx = verify_gas_exists(dive, plano2, planhe)) < 0)
|
if ((idx = verify_gas_exists(dive, plano2, planhe)) < 0)
|
||||||
goto gas_error_exit;
|
goto gas_error_exit;
|
||||||
add_gas_switch_event(dive, dc, lasttime, idx);
|
/* need to insert a first sample for the new gas */
|
||||||
/* need to insert a last sample for the old gas */
|
add_gas_switch_event(dive, dc, lasttime + 1, idx);
|
||||||
sample = prepare_sample(dc);
|
sample = prepare_sample(dc);
|
||||||
sample[-1].po2 = po2;
|
sample[-1].po2 = po2;
|
||||||
sample->time.seconds = time - 1;
|
sample->time.seconds = lasttime + 1;
|
||||||
sample->depth.mm = depth;
|
sample->depth.mm = lastdepth;
|
||||||
update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds,
|
|
||||||
dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl);
|
|
||||||
sample->cylinderpressure.mbar = cyl->end.mbar;
|
|
||||||
finish_sample(dc);
|
finish_sample(dc);
|
||||||
cyl = &dive->cylinder[idx];
|
cyl = &dive->cylinder[idx];
|
||||||
oldo2 = o2;
|
oldo2 = o2;
|
||||||
|
@ -327,13 +325,12 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
/* and keep it valid for last sample - where it likely doesn't matter */
|
/* and keep it valid for last sample - where it likely doesn't matter */
|
||||||
sample[-1].po2 = po2;
|
sample[-1].po2 = po2;
|
||||||
sample->po2 = po2;
|
sample->po2 = po2;
|
||||||
sample->time.seconds = time;
|
sample->time.seconds = lasttime = time;
|
||||||
sample->depth.mm = depth;
|
sample->depth.mm = lastdepth = depth;
|
||||||
update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds,
|
update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds,
|
||||||
dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl);
|
dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl);
|
||||||
sample->cylinderpressure.mbar = cyl->end.mbar;
|
sample->cylinderpressure.mbar = cyl->end.mbar;
|
||||||
finish_sample(dc);
|
finish_sample(dc);
|
||||||
lasttime = time;
|
|
||||||
dp = dp->next;
|
dp = dp->next;
|
||||||
}
|
}
|
||||||
if (dc->samples <= 1) {
|
if (dc->samples <= 1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue