FlightHistory: add pagedPathForHistory
pathForHistory() halts the sim for a few seconds when called on long flights. pagePathForHistory allows to retrieve the complete history in chunks
This commit is contained in:
parent
2e5db3ce85
commit
265c99a149
2 changed files with 46 additions and 2 deletions
|
@ -137,7 +137,7 @@ void FGFlightHistory::capture()
|
||||||
m_lastCaptureTime = globals->get_sim_time_sec();
|
m_lastCaptureTime = globals->get_sim_time_sec();
|
||||||
Sample* sample = m_buckets.back()->samples + m_validSampleCount;
|
Sample* sample = m_buckets.back()->samples + m_validSampleCount;
|
||||||
|
|
||||||
sample->simTimeMSec = static_cast<int>(m_lastCaptureTime * 1000.0);
|
sample->simTimeMSec = static_cast<size_t>(m_lastCaptureTime * 1000.0);
|
||||||
sample->position = globals->get_aircraft_position();
|
sample->position = globals->get_aircraft_position();
|
||||||
|
|
||||||
double heading, pitch, roll;
|
double heading, pitch, roll;
|
||||||
|
@ -149,6 +149,40 @@ void FGFlightHistory::capture()
|
||||||
++m_validSampleCount;
|
++m_validSampleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PagedPathForHistory_ptr FGFlightHistory::pagedPathForHistory(size_t max_entries, size_t newerThan ) const
|
||||||
|
{
|
||||||
|
PagedPathForHistory_ptr result = new PagedPathForHistory();
|
||||||
|
if (m_buckets.empty()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FOREACH(SampleBucket* bucket, m_buckets) {
|
||||||
|
unsigned int count = (bucket == m_buckets.back() ? m_validSampleCount : SAMPLE_BUCKET_WIDTH);
|
||||||
|
|
||||||
|
// iterate over all the valid samples in the bucket
|
||||||
|
for (unsigned int index = 0; index < count; ++index) {
|
||||||
|
// skip older entries
|
||||||
|
// TODO: bisect!
|
||||||
|
if( bucket->samples[index].simTimeMSec <= newerThan )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( max_entries ) {
|
||||||
|
max_entries--;
|
||||||
|
SGGeod g = bucket->samples[index].position;
|
||||||
|
result->path.push_back(g);
|
||||||
|
result->last_seen = bucket->samples[index].simTimeMSec;
|
||||||
|
} else {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // of samples iteration
|
||||||
|
} // of buckets iteration
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SGGeodVec FGFlightHistory::pathForHistory(double minEdgeLengthM) const
|
SGGeodVec FGFlightHistory::pathForHistory(double minEdgeLengthM) const
|
||||||
{
|
{
|
||||||
SGGeodVec result;
|
SGGeodVec result;
|
||||||
|
|
|
@ -32,6 +32,15 @@
|
||||||
|
|
||||||
typedef std::vector<SGGeod> SGGeodVec;
|
typedef std::vector<SGGeod> SGGeodVec;
|
||||||
|
|
||||||
|
class PagedPathForHistory : public SGReferenced {
|
||||||
|
public:
|
||||||
|
PagedPathForHistory() : last_seen(0) {}
|
||||||
|
virtual ~PagedPathForHistory() {}
|
||||||
|
SGGeodVec path;
|
||||||
|
time_t last_seen;
|
||||||
|
};
|
||||||
|
typedef SGSharedPtr<PagedPathForHistory> PagedPathForHistory_ptr;
|
||||||
|
|
||||||
const unsigned int SAMPLE_BUCKET_WIDTH = 1024;
|
const unsigned int SAMPLE_BUCKET_WIDTH = 1024;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,6 +61,7 @@ public:
|
||||||
virtual void reinit();
|
virtual void reinit();
|
||||||
virtual void update(double dt);
|
virtual void update(double dt);
|
||||||
|
|
||||||
|
PagedPathForHistory_ptr pagedPathForHistory(size_t max_entries, size_t newerThan = 0) const;
|
||||||
/**
|
/**
|
||||||
* retrieve the path, collapsing segments shorter than
|
* retrieve the path, collapsing segments shorter than
|
||||||
* the specified minimum length
|
* the specified minimum length
|
||||||
|
@ -75,7 +85,7 @@ private:
|
||||||
/// heading, pitch and roll can be recorded at lower precision
|
/// heading, pitch and roll can be recorded at lower precision
|
||||||
/// than a double - actually 16 bits might be sufficient
|
/// than a double - actually 16 bits might be sufficient
|
||||||
float heading, pitch, roll;
|
float heading, pitch, roll;
|
||||||
int simTimeMSec;
|
size_t simTimeMSec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue