aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-09 17:28:23 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-10 15:57:39 -0800
commit09287809ebb76541a31af94e60856f731e3e9d37 (patch)
tree97d3509d528108e89db0c582854f3961b5060cf9 /core
parent9bfc6d2520b83b8151a84e23cbab082ab460532e (diff)
downloadsubsurface-09287809ebb76541a31af94e60856f731e3e9d37.tar.gz
profile: move adding of ceiling-violation-event
The profile item that shows the ceilings adds a warning event if the ceiling is violated. This is very unfortunate. Improve this situation by adding the event up to the function that calculates the ceiling. This is still not how it should be - the display layer should not modify the dive that it displays. To make this clear, add a comment that details that this is a contract between planner and display layer: The planner uses a dive that can be trampled upon by the profile. Still, this should be solved differently. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/display.h1
-rw-r--r--core/profile.c18
2 files changed, 18 insertions, 1 deletions
diff --git a/core/display.h b/core/display.h
index 8fbe34261..a8ceb1484 100644
--- a/core/display.h
+++ b/core/display.h
@@ -21,6 +21,7 @@ struct plot_info {
enum {AIR, NITROX, TRIMIX, FREEDIVING} dive_type;
double endtempcoord;
double maxpp;
+ bool waypoint_above_ceiling;
struct plot_data *entry;
struct plot_pressure_data *pressures; /* cylinders.nr blocks of nr entries. */
};
diff --git a/core/profile.c b/core/profile.c
index 997b4bb57..3ddd2300b 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -1026,7 +1026,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
for (i = 1; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
int j, t0 = (entry - 1)->sec, t1 = entry->sec;
- int time_stepsize = 20;
+ int time_stepsize = 20, max_ceiling = -1;
current_divemode = get_current_divemode(dc, entry->sec, &evd, &current_divemode);
gasmix = get_gasmix(dive, dc, t1, &ev, gasmix);
@@ -1096,6 +1096,8 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
double m_value = ds->buehlmann_inertgas_a[j] + entry->ambpressure / ds->buehlmann_inertgas_b[j];
double surface_m_value = ds->buehlmann_inertgas_a[j] + surface_pressure / ds->buehlmann_inertgas_b[j];
entry->ceilings[j] = deco_allowed_depth(ds->tolerated_by_tissue[j], surface_pressure, dive, 1);
+ if (entry->ceilings[j] > max_ceiling)
+ max_ceiling = entry->ceilings[j];
double current_gf = (ds->tissue_inertgas_saturation[j] - entry->ambpressure) / (m_value - entry->ambpressure);
entry->percentages[j] = ds->tissue_inertgas_saturation[j] < entry->ambpressure ?
lrint(ds->tissue_inertgas_saturation[j] / entry->ambpressure * AMB_PERCENTAGE) :
@@ -1107,6 +1109,20 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
entry->surface_gf = surface_gf;
}
+ // In the planner, if the ceiling is violated, add an event.
+ // TODO: This *really* shouldn't be done here. This is a contract
+ // between the planner and the profile that the planner uses a dive
+ // that can be trampled upon. But ultimately, the ceiling-violation
+ // marker should be handled differently!
+ // Don't scream if we violate the ceiling by a few cm.
+ if (planner_ds && !pi->waypoint_above_ceiling &&
+ entry->depth < max_ceiling - 100 && entry->sec > 0) {
+ struct dive *non_const_dive = (struct dive *)dive; // cast away const!
+ add_event(&non_const_dive->dc, entry->sec, SAMPLE_EVENT_CEILING, -1, max_ceiling / 1000,
+ translate("gettextFromC", "planned waypoint above ceiling"));
+ pi->waypoint_above_ceiling = true;
+ }
+
/* should we do more calculations?
* We don't for print-mode because this info doesn't show up there
* If the ceiling hasn't cleared by the last data point, we need tts for VPM-B CVA calculation