]> git.mxchange.org Git - flightgear.git/blobdiff - src/Aircraft/FlightHistory.cxx
Interim windows build fix
[flightgear.git] / src / Aircraft / FlightHistory.cxx
index 82304fdd434ca768bfd55d01864a33b5fc52700e..8d2b6ae82680e8284a91a792d98277c328bc6496 100644 (file)
@@ -70,6 +70,7 @@ void FGFlightHistory::init()
     
     // force bucket re-allocation
     m_validSampleCount = SAMPLE_BUCKET_WIDTH;
+    m_lastCaptureTime = globals->get_sim_time_sec();
 }
 
 void FGFlightHistory::shutdown()
@@ -97,6 +98,15 @@ void FGFlightHistory::update(double dt)
         }
     } // of rest-on-takeoff enabled
     
+// spatial check - moved at least 1m since last capture
+    if (!m_buckets.empty()) {
+        SGVec3d lastCaptureCart(SGVec3d::fromGeod(m_buckets.back()->samples[m_validSampleCount - 1].position));
+        double d2 = distSqr(lastCaptureCart, globals->get_aircraft_position_cart());
+        if (d2 <= 1.0) {
+            return;
+        }
+    }
+    
     double elapsed = globals->get_sim_time_sec() - m_lastCaptureTime;
     if (elapsed > m_sampleInterval) {
         capture();
@@ -127,7 +137,7 @@ void FGFlightHistory::capture()
     m_lastCaptureTime = globals->get_sim_time_sec();
     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();
     
     double heading, pitch, roll;
@@ -139,6 +149,40 @@ void FGFlightHistory::capture()
     ++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 result;