diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-04-02 15:06:54 -0500 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-04-04 22:37:18 -0700 |
commit | e0824ef9f3e2a0cc0fae435b8e3560b309d9708e (patch) | |
tree | 4597890128bc8ebee2dfb4335dc5c9b855e4a68e /core/profile.c | |
parent | 7a444c0210783b926c9f60dd7b436eb086e8f396 (diff) | |
download | subsurface-e0824ef9f3e2a0cc0fae435b8e3560b309d9708e.tar.gz |
Make gas change events always have a cylinder index
In commit df4e26c8757a ("Start sanitizing gaschange event information")
back about a year and a half ago, I started sanitizing the gas switch
event data, allowing gas switches to be associated with a particular
cylinder index rather than just the gas mix that is switched to.
But that initial step only _allowed_ a gas switch event to be associated
with a particular cylinder, the primary model was still to just specify
the mix.
This finally takes the next step, and *always* associates a gas switch
event with a particular cylinder. Instead of then looking up the
cylinder by trying to match gas mixes at runtime, subsurface now looks
it up when loading the dive initially as part of the dive fixup code.
The switch event still has an a separate gas mix associated with it, but
this patch also starts preparing for entirely relying on the gas mix in
the cylinder itself, by starting to pass in not just the event but also
the dive pointer to the routines that look up gas mix details.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/profile.c')
-rw-r--r-- | core/profile.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/core/profile.c b/core/profile.c index 6576f6453..72c5e0298 100644 --- a/core/profile.c +++ b/core/profile.c @@ -318,40 +318,23 @@ struct plot_info *analyze_plot_info(struct plot_info *pi) */ int get_cylinder_index(struct dive *dive, struct event *ev) { - int i; - int best = 0, score = INT_MAX; - int target_o2, target_he; - struct gasmix *g; + int best; + struct gasmix *mix; if (ev->gas.index >= 0) return ev->gas.index; - g = get_gasmix_from_event(ev); - target_o2 = get_o2(g); - target_he = get_he(g); - /* - * Try to find a cylinder that best matches the target gas - * mix. + * This should no longer happen! + * + * We now match up gas change events with their cylinders at dive + * event fixup time. */ - for (i = 0; i < MAX_CYLINDERS; i++) { - cylinder_t *cyl = dive->cylinder + i; - int delta_o2, delta_he, distance; + fprintf(stderr, "Still looking up cylinder based on gas mix in get_cylinder_index()!\n"); - if (cylinder_nodata(cyl)) - continue; - - delta_o2 = get_o2(&cyl->gasmix) - target_o2; - delta_he = get_he(&cyl->gasmix) - target_he; - distance = delta_o2 * delta_o2; - distance += delta_he * delta_he; - - if (distance >= score) - continue; - score = distance; - best = i; - } - return best; + mix = get_gasmix_from_event(dive, ev); + best = find_best_gasmix_match(mix, dive->cylinder, 0); + return best < 0 ? 0 : best; } struct event *get_next_event(struct event *event, const char *name) |