summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2017-02-02 15:31:52 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-02-02 12:36:08 -0800
commita031dbbbd8fbd8a913e517cf1bea5d61311bf266 (patch)
tree9bea6f05989e47d7640366ed0cd974541f4d97db /core
parent99595542ec61a28153ce9d39ef47e913961c1dfc (diff)
downloadsubsurface-a031dbbbd8fbd8a913e517cf1bea5d61311bf266.tar.gz
When merging planned dives keep all cylinders
When merging a real dive with a planned dive (for comparison), we should not try to be clever in merging similar cylinders, rather keep the union of both cylinder sets as the two versions of the dive might differ in exctly which gas and how much of it was used. Increase MAX_CYLINDERS to 20 to make room for this. Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'core')
-rw-r--r--core/dive.c53
-rw-r--r--core/dive.h2
2 files changed, 40 insertions, 15 deletions
diff --git a/core/dive.c b/core/dive.c
index 772b556e5..19a950482 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -2028,23 +2028,43 @@ static void merge_cylinders(struct dive *res, struct dive *a, struct dive *b)
memcpy(res->cylinder, a->cylinder, sizeof(res->cylinder));
memset(a->cylinder, 0, sizeof(a->cylinder));
- for (i = 0; i < MAX_CYLINDERS; i++) {
- int j;
- cylinder_t *cyl = b->cylinder + i;
+ if (strcmp(b->dc.model, "planned dive")) {
+ // We merge two actual dive
+ for (i = 0; i < MAX_CYLINDERS; i++) {
+ int j;
+ cylinder_t *cyl = b->cylinder + i;
- j = find_cylinder_match(cyl, res->cylinder, used);
- mapping[i] = j;
- if (j < 0)
- continue;
- used |= 1 << j;
- merge_cylinder_info(cyl, res->cylinder + j);
+ j = find_cylinder_match(cyl, res->cylinder, used);
+ mapping[i] = j;
+ if (j < 0)
+ continue;
+ used |= 1 << j;
+ merge_cylinder_info(cyl, res->cylinder + j);
- /* If that renumbered the cylinders, fix it up! */
- if (i != j)
- renumber = 1;
- }
- if (renumber)
+ /* If that renumbered the cylinders, fix it up! */
+ if (i != j)
+ renumber = 1;
+ }
+ if (renumber)
+ cylinder_renumber(b, mapping);
+ } else {
+ int j=0;
+ for (i = 0; i < MAX_CYLINDERS && j < MAX_CYLINDERS; i++) {
+ if (is_cylinder_used(res, i))
+ continue;
+
+ while (!is_cylinder_used(b, j) && j < MAX_CYLINDERS - 1) {
+ mapping[j] = 0;
+ ++j;
+ }
+ memcpy(&res->cylinder[i], &b->cylinder[j], sizeof (b->cylinder[j]));
+ mapping[j] = i;
+ ++j;
+ }
+ while (j < MAX_CYLINDERS)
+ mapping[j++] = 0;
cylinder_renumber(b, mapping);
+ }
}
static void merge_equipment(struct dive *res, struct dive *a, struct dive *b)
@@ -3000,6 +3020,11 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer
dl = b;
}
+ if (!strcmp(a->dc.model, "planneed dive")) {
+ struct dive *tmp = a;
+ a = b;
+ b = tmp;
+ }
res->when = dl ? dl->when : a->when;
res->selected = a->selected || b->selected;
merge_trip(res, a, b);
diff --git a/core/dive.h b/core/dive.h
index 2578850a6..c9d176920 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -290,7 +290,7 @@ struct divecomputer {
struct divecomputer *next;
};
-#define MAX_CYLINDERS (8)
+#define MAX_CYLINDERS (20)
#define MAX_WEIGHTSYSTEMS (6)
#define W_IDX_PRIMARY 0
#define W_IDX_SECONDARY 1