mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 22:16:16 +00:00
Simplify the bailout detection functions.
Function peek_next_divemodechange() is redundant if get_next_divemodechange() has one additional parameter. Calls to get_next_divemodechange() were updated in divelist.c, plannernotes.c and profile.c. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
This commit is contained in:
parent
c1d04ef7dc
commit
0e08c0870a
5 changed files with 17 additions and 46 deletions
49
core/dive.c
49
core/dive.c
|
@ -241,59 +241,29 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
|
|||
}
|
||||
}
|
||||
|
||||
struct event *get_next_divemodechange(struct event **evd)
|
||||
struct event *get_next_divemodechange(struct event **evd, bool update_pointer)
|
||||
{ /* Starting at the event pointed to by evd, find the next divemode change event and initialise its
|
||||
* type and divemode. Requires an external pointer (evd) to a divemode change event, usually
|
||||
* a copy of dc->events. This function is self-tracking and the value of evd needs no
|
||||
* setting or manipulation outside of this function. */
|
||||
* a copy of dc->events. This function is self-tracking if update_pointer is TRUE and the value
|
||||
* of evd needs no manipulation outside of this function. If update_pointer is FALSE, pointer evd
|
||||
* is NOT updated with the address of the last examined event in the while() loop. */
|
||||
struct event *ev = *evd;
|
||||
while (ev) { // Step through the events.
|
||||
for (int i=0; i<3; i++) { // For each event name search for one of the above strings
|
||||
if (!strcmp(ev->name,divemode_text[i])) { // if the event name is one of the divemode names
|
||||
ev->divemode = i; // set the event type to the dive mode
|
||||
*evd = ev->next;
|
||||
if (update_pointer)
|
||||
*evd = ev->next;
|
||||
return (ev);
|
||||
}
|
||||
}
|
||||
ev = ev->next;
|
||||
}
|
||||
*evd = NULL;
|
||||
if (update_pointer)
|
||||
*evd = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
struct event *peek_next_divemodechange(struct event *evd)
|
||||
{ // Starting at event evd, return the subsequent divemode change event, remembering its divemode.
|
||||
struct event *ev = evd;
|
||||
while (ev) { // Step through the events.
|
||||
for (int i=0; i<3; i++) { // For each event name search for one of the above strings
|
||||
if (!strcmp(ev->name,divemode_text[i])) { // if the event name is one of the divemode names
|
||||
ev->divemode = i;
|
||||
return (ev); // ... then return the event.
|
||||
}
|
||||
}
|
||||
ev = ev->next;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int divetime, struct event **ev_dmc)
|
||||
{ // The dummy version of this function, call parameters compatible with self-tracking version.
|
||||
return dc->divemode;
|
||||
}
|
||||
|
||||
enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int divetime, struct event **ev_dmc)
|
||||
{ // The non-self-tracking version of this function, call parameters compatible with self-tracking version.
|
||||
struct event *ev, *ev_ndc = dc->events;
|
||||
enum dive_comp_type mode = dc->divemode;
|
||||
ev = get_next_divemodechange(&ev_ndc);
|
||||
while (ev && (divetime >= ev->time.seconds)) {
|
||||
mode = ev->divemode;
|
||||
ev = get_next_divemodechange(&ev_ndc);
|
||||
}
|
||||
return mode;
|
||||
} */
|
||||
|
||||
enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int dtime, struct event **ev_dmc)
|
||||
{ /* For a particular dive computer and its linked list of events, find the divemode dtime seconds
|
||||
* into the dive. Requires an external pointer (ev_dmc) to a divemode change event, usually
|
||||
|
@ -304,7 +274,8 @@ enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int dtime, str
|
|||
while (ev && (dtime >= ev->time.seconds)) { // If dtime is AFTER this event time, store divemode
|
||||
mode = ev->divemode;
|
||||
ev_last = ev;
|
||||
ev = peek_next_divemodechange(ev->next); // peek at the time of the following divemode change event
|
||||
// ev = peek_next_divemodechange(ev->next); // peek at the time of the following divemode change event
|
||||
ev = get_next_divemodechange(&ev->next, FALSE);
|
||||
}
|
||||
*ev_dmc = ev_last;
|
||||
return (mode);
|
||||
|
|
|
@ -362,7 +362,7 @@ struct dive_components {
|
|||
unsigned int weights : 1;
|
||||
};
|
||||
|
||||
extern struct event *get_next_divemodechange(struct event **evd);
|
||||
extern struct event *get_next_divemodechange(struct event **evd, bool update_pointer);
|
||||
extern enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int dtime, struct event **ev_dmc);
|
||||
|
||||
/* picture list and methods related to dive picture handling */
|
||||
|
|
|
@ -415,7 +415,7 @@ static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
|
|||
struct divecomputer *dc = &dive->dc;
|
||||
struct gasmix *gasmix = NULL;
|
||||
struct event *ev = NULL;
|
||||
struct event *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc);
|
||||
struct event *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc, TRUE);
|
||||
int i;
|
||||
|
||||
if (!dc)
|
||||
|
|
|
@ -542,7 +542,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
|||
struct event *nextev, *evd = dive->dc.events;
|
||||
|
||||
current_divemode = dive->dc.divemode;
|
||||
nextev = get_next_divemodechange(&evd);
|
||||
nextev = get_next_divemodechange(&evd, TRUE);
|
||||
|
||||
if (dive->dc.divemode != CCR) {
|
||||
while (dp) {
|
||||
|
@ -552,7 +552,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
|||
|
||||
if (nextev && (dp->time >= nextev->time.seconds)) { // If there are divemode changes and divedatapoint time
|
||||
current_divemode = nextev->divemode; // has reached that of the current divemode event, then set the
|
||||
nextev = get_next_divemodechange(&evd); // current divemode and find the next divemode event
|
||||
nextev = get_next_divemodechange(&evd, TRUE); // current divemode and find the next divemode event
|
||||
}
|
||||
|
||||
amb = depth_to_atm(dp->depth.mm, dive);
|
||||
|
|
|
@ -1018,7 +1018,7 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne
|
|||
if (decoMode() == VPMB)
|
||||
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
||||
struct gasmix *gasmix = NULL;
|
||||
struct event *ev = NULL, *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc);
|
||||
struct event *ev = NULL, *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc, TRUE);
|
||||
|
||||
for (i = 1; i < pi->nr; i++) {
|
||||
struct plot_data *entry = pi->entry + i;
|
||||
|
@ -1211,7 +1211,7 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer
|
|||
struct event *nextev, *evg = NULL, *evd = dc->events;
|
||||
|
||||
current_divemode = dc->divemode;
|
||||
nextev = get_next_divemodechange(&evd);
|
||||
nextev = get_next_divemodechange(&evd, TRUE);
|
||||
|
||||
for (i = 1; i < pi->nr; i++) {
|
||||
int fn2, fhe;
|
||||
|
@ -1220,7 +1220,7 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer
|
|||
gasmix = get_gasmix(dive, dc, entry->sec, &evg, gasmix);
|
||||
if (nextev && (entry->sec > nextev->time.seconds)) { // If there are divemode changes and sample time
|
||||
current_divemode = nextev->divemode; // has reached that of the current divemode event, then set the
|
||||
nextev = get_next_divemodechange(&evd); // current divemode and find the next divemode event
|
||||
nextev = get_next_divemodechange(&evd, TRUE); // current divemode and find the next divemode event
|
||||
}
|
||||
amb_pressure = depth_to_bar(entry->depth, dive);
|
||||
fill_pressures(&entry->pressures, amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry->o2pressure.mbar / 1000.0, current_divemode);
|
||||
|
|
Loading…
Add table
Reference in a new issue