mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Refactor to use gaschage_before and gaschange_after
... for better readability. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
d071ab4537
commit
4094e6b233
1 changed files with 17 additions and 18 deletions
35
planner.c
35
planner.c
|
@ -524,7 +524,8 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0, lastprintsetpoint = -1;
|
int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0, lastprintsetpoint = -1;
|
||||||
struct gasmix lastprintgasmix = { -1, -1 };
|
struct gasmix lastprintgasmix = { -1, -1 };
|
||||||
struct divedatapoint *dp = diveplan->dp;
|
struct divedatapoint *dp = diveplan->dp;
|
||||||
bool gaschange = !plan_verbatim;
|
bool gaschange_after = !plan_verbatim;
|
||||||
|
bool gaschange_before;
|
||||||
struct divedatapoint *nextdp = NULL;
|
struct divedatapoint *nextdp = NULL;
|
||||||
|
|
||||||
disclaimer = translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN "
|
disclaimer = translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN "
|
||||||
|
@ -587,17 +588,18 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
dp->setpoint == nextdp->setpoint &&
|
dp->setpoint == nextdp->setpoint &&
|
||||||
dp->depth != lastdepth &&
|
dp->depth != lastdepth &&
|
||||||
nextdp->depth != dp->depth
|
nextdp->depth != dp->depth
|
||||||
&& !gaschange)
|
&& !gaschange_after)
|
||||||
continue;
|
continue;
|
||||||
if (dp->time - lasttime < 10 && !(gaschange && dp->next && dp->depth != dp->next->depth))
|
if (dp->time - lasttime < 10 && !(gaschange_after && dp->next && dp->depth != dp->next->depth))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
len = strlen(buffer);
|
len = strlen(buffer);
|
||||||
if (nextdp && (gasmix_distance(&gasmix, &newgasmix) || dp->setpoint != nextdp->setpoint))
|
if (nextdp && (gasmix_distance(&gasmix, &newgasmix) || dp->setpoint != nextdp->setpoint))
|
||||||
gaschange = true;
|
gaschange_after = true;
|
||||||
|
gaschange_before = (gasmix_distance(&lastprintgasmix, &gasmix) || lastprintsetpoint != dp->setpoint);
|
||||||
if (plan_verbatim) {
|
if (plan_verbatim) {
|
||||||
if (dp->depth != lastprintdepth) {
|
if (dp->depth != lastprintdepth) {
|
||||||
if (plan_display_transitions || dp->entered || !dp->next || (gaschange && nextdp && dp->next && dp->depth != nextdp->depth)) {
|
if (plan_display_transitions || dp->entered || !dp->next || (gaschange_after && dp->next && dp->depth != nextdp->depth)) {
|
||||||
if (dp->setpoint)
|
if (dp->setpoint)
|
||||||
snprintf(temp, sizeof(temp), translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"),
|
snprintf(temp, sizeof(temp), translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"),
|
||||||
decimals, depthvalue, depth_unit,
|
decimals, depthvalue, depth_unit,
|
||||||
|
@ -618,7 +620,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
newdepth = dp->depth;
|
newdepth = dp->depth;
|
||||||
lasttime = dp->time;
|
lasttime = dp->time;
|
||||||
} else {
|
} else {
|
||||||
if (nextdp && (dp->depth != nextdp->depth || gasmix_distance(&gasmix, &newgasmix) != 0 || dp->setpoint != nextdp->setpoint)) {
|
if ((nextdp && dp->depth != nextdp->depth) || gaschange_after) {
|
||||||
if (dp->setpoint)
|
if (dp->setpoint)
|
||||||
snprintf(temp, sizeof(temp), translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"),
|
snprintf(temp, sizeof(temp), translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"),
|
||||||
decimals, depthvalue, depth_unit,
|
decimals, depthvalue, depth_unit,
|
||||||
|
@ -639,12 +641,9 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((dp->depth == lastdepth && nextdp && dp->depth != nextdp->depth) ||
|
if (plan_display_transitions || dp->entered || !dp->next || (nextdp && dp->depth != nextdp->depth) ||
|
||||||
plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) {
|
!isascent && gaschange_before && ((nextdp && dp->depth != nextdp->depth) || gaschange_after) ||
|
||||||
if (plan_display_transitions || dp->entered || !dp->next || dp->depth != nextdp->depth ||
|
(isascent && gaschange_after && nextdp && dp->depth != nextdp->depth )) {
|
||||||
!isascent && (gasmix_distance(&lastprintgasmix, &gasmix) || lastprintsetpoint != dp->setpoint) &&
|
|
||||||
((nextdp && dp->depth != nextdp->depth) || gasmix_distance(&gasmix, &newgasmix) || (nextdp && dp->setpoint != nextdp->setpoint)) ||
|
|
||||||
(isascent && gaschange && nextdp && dp->depth != nextdp->depth )) {
|
|
||||||
snprintf(temp, sizeof(temp), translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit);
|
snprintf(temp, sizeof(temp), translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit);
|
||||||
len += snprintf(buffer + len, sizeof(buffer) - len, "<tr><td style='padding-left: 10px; float: right;'>%s</td>", temp);
|
len += snprintf(buffer + len, sizeof(buffer) - len, "<tr><td style='padding-left: 10px; float: right;'>%s</td>", temp);
|
||||||
if (plan_display_duration) {
|
if (plan_display_duration) {
|
||||||
|
@ -656,7 +655,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp);
|
len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isascent && gaschange && dp->next && nextdp && dp->depth != nextdp->depth) {
|
if (isascent && gaschange_after && dp->next && nextdp && dp->depth != nextdp->depth) {
|
||||||
if (dp->setpoint) {
|
if (dp->setpoint) {
|
||||||
snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) nextdp->setpoint / 1000.0);
|
snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) nextdp->setpoint / 1000.0);
|
||||||
len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&newgasmix),
|
len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&newgasmix),
|
||||||
|
@ -666,8 +665,8 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
}
|
}
|
||||||
lastprintsetpoint = nextdp->setpoint;
|
lastprintsetpoint = nextdp->setpoint;
|
||||||
lastprintgasmix = newgasmix;
|
lastprintgasmix = newgasmix;
|
||||||
gaschange = false;
|
gaschange_after = false;
|
||||||
} else if (gasmix_distance(&lastprintgasmix, &gasmix) != 0 || lastprintsetpoint != dp->setpoint) {
|
} else if (gaschange_before) {
|
||||||
if (dp->setpoint) {
|
if (dp->setpoint) {
|
||||||
snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0);
|
snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0);
|
||||||
len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&gasmix),
|
len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&gasmix),
|
||||||
|
@ -677,7 +676,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
}
|
}
|
||||||
lastprintsetpoint = dp->setpoint;
|
lastprintsetpoint = dp->setpoint;
|
||||||
lastprintgasmix = gasmix;
|
lastprintgasmix = gasmix;
|
||||||
gaschange = false;
|
gaschange_after = false;
|
||||||
} else {
|
} else {
|
||||||
len += snprintf(buffer + len, sizeof(buffer) - len, "<td> </td>");
|
len += snprintf(buffer + len, sizeof(buffer) - len, "<td> </td>");
|
||||||
}
|
}
|
||||||
|
@ -686,7 +685,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
lasttime = dp->time;
|
lasttime = dp->time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gaschange) {
|
if (gaschange_after) {
|
||||||
// gas switch at this waypoint
|
// gas switch at this waypoint
|
||||||
if (plan_verbatim) {
|
if (plan_verbatim) {
|
||||||
if (lastsetpoint >= 0) {
|
if (lastsetpoint >= 0) {
|
||||||
|
@ -697,7 +696,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
|
|
||||||
len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
|
len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
|
||||||
}
|
}
|
||||||
gaschange = false;
|
gaschange_after = false;
|
||||||
gasmix = newgasmix;
|
gasmix = newgasmix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue