mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Use more of our propper types in the planner
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
8e5eb71e0b
commit
9eeeba468a
3 changed files with 12 additions and 11 deletions
17
planner.c
17
planner.c
|
@ -94,12 +94,12 @@ void set_display_transitions(bool display)
|
||||||
plan_display_transitions = display;
|
plan_display_transitions = display;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_gas_from_events(struct divecomputer *dc, int time, struct gasmix *gas)
|
void get_gas_from_events(struct divecomputer *dc, duration_t time, struct gasmix *gas)
|
||||||
{
|
{
|
||||||
// we don't modify the values passed in if nothing is found
|
// we don't modify the values passed in if nothing is found
|
||||||
// so don't call with uninitialized gasmix !
|
// so don't call with uninitialized gasmix !
|
||||||
struct event *event = dc->events;
|
struct event *event = dc->events;
|
||||||
while (event && event->time.seconds <= time) {
|
while (event && event->time.seconds <= time.seconds) {
|
||||||
if (!strcmp(event->name, "gaschange"))
|
if (!strcmp(event->name, "gaschange"))
|
||||||
*gas = *get_gasmix_from_event(event);
|
*gas = *get_gasmix_from_event(event);
|
||||||
event = event->next;
|
event = event->next;
|
||||||
|
@ -133,7 +133,9 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
|
||||||
{
|
{
|
||||||
struct divecomputer *dc;
|
struct divecomputer *dc;
|
||||||
struct sample *sample, *psample;
|
struct sample *sample, *psample;
|
||||||
int i, t0, t1, gasidx, lastdepth;
|
int i, gasidx;
|
||||||
|
depth_t lastdepth = {};
|
||||||
|
duration_t t0 = {}, t1 = {};
|
||||||
double tissue_tolerance;
|
double tissue_tolerance;
|
||||||
struct gasmix gas;
|
struct gasmix gas;
|
||||||
|
|
||||||
|
@ -149,19 +151,18 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
|
||||||
if (!dc->samples)
|
if (!dc->samples)
|
||||||
return tissue_tolerance;
|
return tissue_tolerance;
|
||||||
psample = sample = dc->sample;
|
psample = sample = dc->sample;
|
||||||
lastdepth = t0 = 0;
|
|
||||||
/* we always start with gas 0 (unless an event tells us otherwise) */
|
/* we always start with gas 0 (unless an event tells us otherwise) */
|
||||||
gas = dive->cylinder[0].gasmix;
|
gas = dive->cylinder[0].gasmix;
|
||||||
for (i = 0; i < dc->samples; i++, sample++) {
|
for (i = 0; i < dc->samples; i++, sample++) {
|
||||||
t1 = sample->time.seconds;
|
t1 = sample->time;
|
||||||
get_gas_from_events(&dive->dc, t0, &gas);
|
get_gas_from_events(&dive->dc, t0, &gas);
|
||||||
if ((gasidx = get_gasidx(dive, &gas)) == -1) {
|
if ((gasidx = get_gasidx(dive, &gas)) == -1) {
|
||||||
report_error(translate("gettextFromC", "Can't find gas %s"), gasname(&gas));
|
report_error(translate("gettextFromC", "Can't find gas %s"), gasname(&gas));
|
||||||
gasidx = 0;
|
gasidx = 0;
|
||||||
}
|
}
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
lastdepth = psample->depth.mm;
|
lastdepth = psample->depth;
|
||||||
tissue_tolerance = interpolate_transition(dive, t0, t1, lastdepth, sample->depth.mm, &dive->cylinder[gasidx].gasmix, sample->po2.mbar);
|
tissue_tolerance = interpolate_transition(dive, t0.seconds, t1.seconds, lastdepth.mm, sample->depth.mm, &dive->cylinder[gasidx].gasmix, sample->po2.mbar);
|
||||||
psample = sample;
|
psample = sample;
|
||||||
t0 = t1;
|
t0 = t1;
|
||||||
}
|
}
|
||||||
|
@ -756,7 +757,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
|
||||||
sample = &displayed_dive.dc.sample[displayed_dive.dc.samples - 1];
|
sample = &displayed_dive.dc.sample[displayed_dive.dc.samples - 1];
|
||||||
/* we start with gas 0, then check if that was changed */
|
/* we start with gas 0, then check if that was changed */
|
||||||
gas = displayed_dive.cylinder[0].gasmix;
|
gas = displayed_dive.cylinder[0].gasmix;
|
||||||
get_gas_from_events(&displayed_dive.dc, sample->time.seconds, &gas);
|
get_gas_from_events(&displayed_dive.dc, sample->time, &gas);
|
||||||
po2 = displayed_dive.dc.sample[displayed_dive.dc.samples - 1].po2.mbar;
|
po2 = displayed_dive.dc.sample[displayed_dive.dc.samples - 1].po2.mbar;
|
||||||
if ((current_cylinder = get_gasidx(&displayed_dive, &gas)) == -1) {
|
if ((current_cylinder = get_gasidx(&displayed_dive, &gas)) == -1) {
|
||||||
report_error(translate("gettextFromC", "Can't find gas %s"), gasname(&gas));
|
report_error(translate("gettextFromC", "Can't find gas %s"), gasname(&gas));
|
||||||
|
|
|
@ -15,7 +15,7 @@ extern void set_verbatim(bool verbatim);
|
||||||
extern void set_display_runtime(bool display);
|
extern void set_display_runtime(bool display);
|
||||||
extern void set_display_duration(bool display);
|
extern void set_display_duration(bool display);
|
||||||
extern void set_display_transitions(bool display);
|
extern void set_display_transitions(bool display);
|
||||||
extern void get_gas_from_events(struct divecomputer *dc, int time, struct gasmix *gas);
|
extern void get_gas_from_events(struct divecomputer *dc, duration_t time, struct gasmix *gas);
|
||||||
extern int get_gasidx(struct dive *dive, struct gasmix *mix);
|
extern int get_gasidx(struct dive *dive, struct gasmix *mix);
|
||||||
extern bool diveplan_empty(struct diveplan *diveplan);
|
extern bool diveplan_empty(struct diveplan *diveplan);
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ void DivePlannerPointsModel::setupStartTime()
|
||||||
void DivePlannerPointsModel::loadFromDive(dive *d)
|
void DivePlannerPointsModel::loadFromDive(dive *d)
|
||||||
{
|
{
|
||||||
CylindersModel::instance()->updateDive();
|
CylindersModel::instance()->updateDive();
|
||||||
int lasttime = 0;
|
duration_t lasttime = {};
|
||||||
// we start with the first gas and see if it was changed
|
// we start with the first gas and see if it was changed
|
||||||
struct gasmix gas = d->cylinder[0].gasmix;
|
struct gasmix gas = d->cylinder[0].gasmix;
|
||||||
for (int i = 0; i < d->dc.samples - 1; i++) {
|
for (int i = 0; i < d->dc.samples - 1; i++) {
|
||||||
|
@ -114,7 +114,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
|
||||||
continue;
|
continue;
|
||||||
get_gas_from_events(&d->dc, lasttime, &gas);
|
get_gas_from_events(&d->dc, lasttime, &gas);
|
||||||
plannerModel->addStop(s.depth.mm, s.time.seconds, &gas, 0, true);
|
plannerModel->addStop(s.depth.mm, s.time.seconds, &gas, 0, true);
|
||||||
lasttime = s.time.seconds;
|
lasttime = s.time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue