From 1e8cdd58297d5cde5cd80a20174b2122d98d1626 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 18 Dec 2012 10:23:44 +0000 Subject: [PATCH] Support partial all-within-range spatial queries. As an opt-in API, allow clients to request partial results, with a time-bounded cutoff. Use this to keep the MapWidget responsive even when many airports are being added to the cache (e.g., zooming out or panning rapidly when zoomed out) --- src/GUI/MapWidget.cxx | 3 ++- src/Navaids/PositionedOctree.cxx | 10 ++++++++-- src/Navaids/PositionedOctree.hxx | 2 +- src/Navaids/positioned.cxx | 15 ++++++++++++++- src/Navaids/positioned.hxx | 4 +++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/GUI/MapWidget.cxx b/src/GUI/MapWidget.cxx index 41525cde2..004207e71 100644 --- a/src/GUI/MapWidget.cxx +++ b/src/GUI/MapWidget.cxx @@ -936,7 +936,8 @@ private: void MapWidget::drawAirports() { MapAirportFilter af(_root); - FGPositioned::List apts = FGPositioned::findWithinRange(_projectionCenter, _drawRangeNm, &af); + bool partial = false; + FGPositioned::List apts = FGPositioned::findWithinRangePartial(_projectionCenter, _drawRangeNm, &af, partial); for (unsigned int i=0; i #include +#include namespace flightgear { @@ -258,7 +259,7 @@ void findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPosit } } -void findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filter* aFilter, FGPositioned::List& aResults) +bool findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filter* aFilter, FGPositioned::List& aResults, int aCutoffMsec) { aResults.clear(); FindNearestPQueue pq; @@ -266,7 +267,10 @@ void findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filte pq.push(Ordered(global_spatialOctree, 0)); double rng = aRangeM; - while (!pq.empty()) { + SGTimeStamp tm; + tm.stamp(); + + while (!pq.empty() && (tm.elapsedMSec() < aCutoffMsec)) { Node* nd = pq.top().get(); pq.pop(); @@ -279,6 +283,8 @@ void findAllWithinRange(const SGVec3d& aPos, double aRangeM, FGPositioned::Filte for (unsigned int r=0; r types; Type mMinType, mMaxType; }; - + static List findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter = NULL); + + static List findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter* aFilter, bool& aPartial); static FGPositionedRef findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter = NULL);