diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-06-01 14:17:06 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-01 14:19:19 -0700 |
commit | 2bf46381a82fd6ae514b014b8d32954693bca346 (patch) | |
tree | e3a6778c9476748419b359a184b0e7f93832bc52 | |
parent | c539c8f861928c637f6b3e790b05e89914e2be8f (diff) | |
download | subsurface-2bf46381a82fd6ae514b014b8d32954693bca346.tar.gz |
Use proper types
This is step one of many to use gasmix instead of int o2/he.
Right now some of these changes look ridiculous because after changing a
few lines we immediately go back to o2 = get_o2(gas). The reason is that I
wanted to convert a hand full of functions at a time. So in this commit I
only change validate_gas(), get_gas_from_events() and get_gasidx() to use
a struct gasmix instead of int o2, int he.
This state builds and survived some mild testing. Let's continue on top of
that.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | planner.c | 66 | ||||
-rw-r--r-- | planner.h | 6 | ||||
-rw-r--r-- | qt-ui/diveplanner.cpp | 16 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 6 |
4 files changed, 47 insertions, 47 deletions
@@ -71,34 +71,24 @@ void set_last_stop(bool last_stop_6m) decostoplevels[1] = 3000; } -void get_gas_from_events(struct divecomputer *dc, int time, int *o2, int *he) +void get_gas_from_events(struct divecomputer *dc, int time, struct gasmix *gas) { // we don't modify the values passed in if nothing is found - // so don't call with uninitialized o2/he ! + // so don't call with uninitialized gasmix ! struct event *event = dc->events; while (event && event->time.seconds <= time) { - if (!strcmp(event->name, "gaschange")) { - struct gasmix *g = get_gasmix_from_event(event); - *o2 = get_o2(g); - *he = get_he(g); - } + if (!strcmp(event->name, "gaschange")) + *gas = *get_gasmix_from_event(event); event = event->next; } } -int get_gasidx(struct dive *dive, int o2, int he) +int get_gasidx(struct dive *dive, struct gasmix *mix) { int gasidx = -1; - struct gasmix mix; - - mix.o2.permille = o2; - mix.he.permille = he; - /* we treat air as 0/0 because it is special */ - //if (is_air(o2, he)) - // o2 = 0; while (++gasidx < MAX_CYLINDERS) - if (gasmix_distance(&dive->cylinder[gasidx].gasmix, &mix) < 200) + if (gasmix_distance(&dive->cylinder[gasidx].gasmix, mix) < 200) return gasidx; return -1; } @@ -133,6 +123,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap) int i, t0, t1, gasidx, lastdepth; int o2, he; double tissue_tolerance; + struct gasmix gas; if (!dive) return 0.0; @@ -148,13 +139,14 @@ double tissue_at_end(struct dive *dive, char **cached_datap) psample = sample = dc->sample; lastdepth = t0 = 0; /* we always start with gas 0 (unless an event tells us otherwise) */ - o2 = get_o2(&dive->cylinder[0].gasmix); - he = get_he(&dive->cylinder[0].gasmix); + gas = dive->cylinder[0].gasmix; for (i = 0; i < dc->samples; i++, sample++) { t1 = sample->time.seconds; - get_gas_from_events(&dive->dc, t0, &o2, &he); - if ((gasidx = get_gasidx(dive, o2, he)) == -1) { - report_error(translate("gettextFromC", "Can't find gas %d/%d"), (o2 + 5) / 10, (he + 5) / 10); + get_gas_from_events(&dive->dc, t0, &gas); + if ((gasidx = get_gasidx(dive, &gas)) == -1) { + char gas_string[50]; + get_gas_string(gas.o2.permille, gas.he.permille, gas_string, sizeof(gas_string)); + report_error(translate("gettextFromC", "Can't find gas %s"), gas_string); gasidx = 0; } if (i > 0) @@ -425,12 +417,15 @@ struct gaschanges { static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive *dive, int *gaschangenr, int depth, int *asc_cylinder) { + struct gasmix gas; int nr = 0; struct gaschanges *gaschanges = NULL; struct divedatapoint *dp = diveplan->dp; int best_depth = dive->cylinder[*asc_cylinder].depth.mm; while (dp) { if (dp->time == 0) { + gas.o2.permille = dp->o2; + gas.he.permille = dp->he; if (dp->depth <= depth) { int i = 0; nr++; @@ -443,13 +438,13 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive i++; } gaschanges[i].depth = dp->depth; - gaschanges[i].gasidx = get_gasidx(dive, dp->o2, dp->he); + gaschanges[i].gasidx = get_gasidx(dive, &gas); assert(gaschanges[i].gasidx != -1); } else { /* is there a better mix to start deco? */ if (dp->depth < best_depth) { best_depth = dp->depth; - *asc_cylinder = get_gasidx(dive, dp->o2, dp->he); + *asc_cylinder = get_gasidx(dive, &gas); } } } @@ -539,6 +534,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool translate("gettextFromC", "%s\nSubsurface dive plan\nbased on GFlow = %d and GFhigh = %d\n\n"), disclaimer, diveplan->gflow, diveplan->gfhigh); do { + struct gasmix gasmix; const char *depth_unit; char gas[64]; double depthvalue; @@ -569,7 +565,9 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool if (!dp->entered && o2 == newo2 && he == newhe && nextdp && dp->depth != lastdepth && nextdp->depth != dp->depth) continue; get_gas_string(o2, he, gas, sizeof(gas)); - gasidx = get_gasidx(dive, o2, he); + gasmix.he.permille = he; + gasmix.o2.permille = o2; + gasidx = get_gasidx(dive, &gasmix); len = strlen(buffer); if (dp->depth != lastdepth) snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s\n"), @@ -655,6 +653,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s int avg_depth, bottom_time; int last_ascend_rate; int best_first_ascend_cylinder; + struct gasmix gas; set_gf(diveplan->gflow, diveplan->gfhigh, default_prefs.gf_low_at_maxdepth); if (!diveplan->surface_pressure) @@ -669,12 +668,15 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s /* Let's start at the last 'sample', i.e. the last manually entered waypoint. */ sample = &dive->dc.sample[dive->dc.samples - 1]; /* we start with gas 0, then check if that was changed */ - o2 = get_o2(&dive->cylinder[0].gasmix); - he = get_he(&dive->cylinder[0].gasmix); - get_gas_from_events(&dive->dc, sample->time.seconds, &o2, &he); + gas = dive->cylinder[0].gasmix; + get_gas_from_events(&dive->dc, sample->time.seconds, &gas); + o2 = get_o2(&gas); + he = get_he(&gas); po2 = dive->dc.sample[dive->dc.samples - 1].po2; - if ((current_cylinder = get_gasidx(dive, o2, he)) == -1) { - report_error(translate("gettextFromC", "Can't find gas %d/%d"), (o2 + 5) / 10, (he + 5) / 10); + if ((current_cylinder = get_gasidx(dive, &gas)) == -1) { + char gas_string[50]; + get_gas_string(gas.o2.permille, gas.he.permille, gas_string, sizeof(gas_string)); + report_error(translate("gettextFromC", "Can't find gas %s"), gas_string); current_cylinder = 0; } depth = dive->dc.sample[dive->dc.samples - 1].depth.mm; @@ -866,7 +868,7 @@ static int get_permille(const char *begin, const char **end) return value; } -int validate_gas(const char *text, int *o2_p, int *he_p) +int validate_gas(const char *text, struct gasmix *gas) { int o2, he; @@ -904,8 +906,8 @@ int validate_gas(const char *text, int *o2_p, int *he_p) return 0; /* Let it rip */ - *o2_p = o2; - *he_p = he; + gas->o2.permille = o2; + gas->he.permille = he; return 1; } @@ -6,13 +6,13 @@ extern "C" { #endif -extern int validate_gas(const char *text, int *o2_p, int *he_p); +extern int validate_gas(const char *text, struct gasmix *gas); extern int validate_po2(const char *text, int *mbar_po2); extern timestamp_t current_time_notz(void); extern void show_planned_dive(char **error_string_p); extern void set_last_stop(bool last_stop_6m); -extern void get_gas_from_events(struct divecomputer *dc, int time, int *o2, int *he); -extern int get_gasidx(struct dive *dive, int o2, int he); +extern void get_gas_from_events(struct divecomputer *dc, int time, struct gasmix *gas); +extern int get_gasidx(struct dive *dive, struct gasmix *mix); extern bool diveplan_empty(struct diveplan *diveplan); extern struct dive *planned_dive; diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 1c6c05702..830848987 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -89,14 +89,13 @@ void DivePlannerPointsModel::loadFromDive(dive *d) CylindersModel::instance()->setDive(stagingDive); int lasttime = 0; // we start with the first gas and see if it was changed - int o2 = get_o2(&backupDive.cylinder[0].gasmix); - int he = get_he(&backupDive.cylinder[0].gasmix); + struct gasmix gas = backupDive.cylinder[0].gasmix; for (int i = 0; i < backupDive.dc.samples - 1; i++) { const sample &s = backupDive.dc.sample[i]; if (s.time.seconds == 0) continue; - get_gas_from_events(&backupDive.dc, lasttime, &o2, &he); - plannerModel->addStop(s.depth.mm, s.time.seconds, o2, he, 0, true); + get_gas_from_events(&backupDive.dc, lasttime, &gas); + plannerModel->addStop(s.depth.mm, s.time.seconds, get_o2(&gas), get_he(&gas), 0, true); lasttime = s.time.seconds; } } @@ -390,8 +389,7 @@ QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &value, int role) { - int o2 = 0; - int he = 0; + struct gasmix gas = { 0 }; int i, shift; if (role == Qt::EditRole) { divedatapoint &p = divepoints[index.row()]; @@ -419,9 +417,9 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v } break; case GAS: QByteArray gasv = value.toByteArray(); - if (validate_gas(gasv.data(), &o2, &he)) { - p.o2 = o2; - p.he = he; + if (validate_gas(gasv.data(), &gas)) { + p.o2 = get_o2(&gas); + p.he = get_he(&gas); } break; } diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 73df4f99d..4cfd295f8 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -992,12 +992,12 @@ void ProfileWidget2::changeGas() // backup the things on the dataModel, since we will clear that out. unsigned int diveComputer = dataModel->dcShown(); int diveId = dataModel->id(); - int o2, he; + struct gasmix gasmix; int seconds = timeAxis->valueAt(scenePos); struct dive *d = get_dive_by_uniq_id(diveId); - validate_gas(gas.toUtf8().constData(), &o2, &he); - add_gas_switch_event(d, get_dive_dc(d, diveComputer), seconds, get_gasidx(d, o2, he)); + validate_gas(gas.toUtf8().constData(), &gasmix); + add_gas_switch_event(d, get_dive_dc(d, diveComputer), seconds, get_gasidx(d, &gasmix)); // this means we potentially have a new tank that is being used and needs to be shown fixup_dive(d); MainWindow::instance()->information()->updateDiveInfo(selected_dive); |