]> git.mxchange.org Git - flightgear.git/commitdiff
Support partial all-within-range spatial queries.
authorJames Turner <zakalawe@mac.com>
Tue, 18 Dec 2012 10:23:44 +0000 (10:23 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 18 Dec 2012 10:23:44 +0000 (10:23 +0000)
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
src/Navaids/PositionedOctree.cxx
src/Navaids/PositionedOctree.hxx
src/Navaids/positioned.cxx
src/Navaids/positioned.hxx

index 41525cde25059a85facca8b132e48f7e95951a63..004207e7108120f7644781b8011baf2e08462ea4 100644 (file)
@@ -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<apts.size(); ++i) {
     drawAirport((FGAirport*) apts[i].get());
   }
index 4f342a82479066ca2d07e82be738f87fbd69ac58..9f6908f831433d76a1c51126257c09baf333e0b9 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <simgear/debug/logstream.hxx>
 #include <simgear/structure/exception.hxx>
+#include <simgear/timing/timestamp.hxx>
 
 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<Node*>(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<numResults; ++r) {
     aResults[r] = results[r].get();
   }
+      
+  return !pq.empty();
 }
       
 } // of namespace Octree
index db1a774e4f28e1a8a3618bbfa400b9877bee5a11..747ce985b5aa6944c4843a38845c760b9bf2c9e3 100644 (file)
@@ -216,7 +216,7 @@ namespace Octree
   };
 
   void findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPositioned::Filter* aFilter, FGPositioned::List& aResults);
-  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);
 } // of namespace Octree
 
   
index bced11728b6064a703689c3fb499dbddb75c5e30..e7a1e58c53d8a30c0e4028834ad8b4839258eb36 100644 (file)
@@ -202,7 +202,20 @@ FGPositioned::findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilt
 
   List result;
   Octree::findAllWithinRange(SGVec3d::fromGeod(aPos), 
-    aRangeNm * SG_NM_TO_METER, aFilter, result);
+    aRangeNm * SG_NM_TO_METER, aFilter, result, 0xffffff);
+  return result;
+}
+
+FGPositioned::List
+FGPositioned::findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter* aFilter, bool& aPartial)
+{
+  validateSGGeod(aPos);
+  
+  int limitMsec = 32;
+  List result;
+  aPartial = Octree::findAllWithinRange(SGVec3d::fromGeod(aPos),
+                             aRangeNm * SG_NM_TO_METER, aFilter, result,
+                                        limitMsec);
   return result;
 }
 
index e76ab83f674ddafc618a237d13291605a1a588b9..f4707cbc26a28de3604217df17bb9f3f70ace567 100644 (file)
@@ -164,8 +164,10 @@ public:
     std::vector<Type> 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);