mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: use std::vector<> to store divecomputer samples
This is a hairy one, because the sample code is rather tricky. There was a pattern of looping through pairs of adjacent samples, for interpolation purposes. Add an range adapter to generalize such loops. Removes the finish_sample() function: The code would call prepare_sample() to start parsing of samples and then finish_sample() to actuall add it. I.e. a kind of commit(). Since, with one exception, all users of prepare_sample() called finish_sample() in all code paths, we might just add the sample in the first place. The exception was sample_end() in parse.cpp. This brings a small change: samples are now added, even if they could only be parsed partially. I doubt that this makes any difference, since it will only happen for broken divelogs anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
bc761344d4
commit
f120fecccb
28 changed files with 588 additions and 715 deletions
|
@ -494,10 +494,6 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
|||
while (offset + config.sample_size < size) {
|
||||
s = samples + offset;
|
||||
|
||||
// Start with an empty sample
|
||||
sample = prepare_sample(dc);
|
||||
sample->time.seconds = sample_cnt * profile_period;
|
||||
|
||||
// Check for event
|
||||
if (s[0] & 0x80) {
|
||||
cochran_dive_event(dc, s, sample_cnt * profile_period, &in_deco, &deco_ceiling, &deco_time);
|
||||
|
@ -505,6 +501,10 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
|||
continue;
|
||||
}
|
||||
|
||||
// Start with an empty sample
|
||||
sample = prepare_sample(dc);
|
||||
sample->time.seconds = sample_cnt * profile_period;
|
||||
|
||||
// Depth is in every sample
|
||||
depth_sample = (double)(s[0] & 0x3F) / 4 * (s[0] & 0x40 ? -1 : 1);
|
||||
depth += depth_sample;
|
||||
|
@ -591,8 +591,6 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
|
|||
sample->sensor[0] = 0;
|
||||
sample->pressure[0].mbar = lrint(psi * PSI / 100);
|
||||
|
||||
finish_sample(dc);
|
||||
|
||||
offset += config.sample_size;
|
||||
sample_cnt++;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue