]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/groundcache.hxx
Improve timing statistics
[flightgear.git] / src / FDM / groundcache.hxx
index ea8cc16d76d6c7082be0a945e2d5039155d5ffd6..145561a9c571589b47f1075e8d7be5735de6de2b 100644 (file)
@@ -23,9 +23,6 @@
 #ifndef _GROUNDCACHE_HXX
 #define _GROUNDCACHE_HXX
 
-#include <osg/Group>
-#include <osg/ref_ptr>
-
 #include <simgear/compiler.h>
 #include <simgear/constants.h>
 #include <simgear/math/SGMath.hxx>
 #include <simgear/scene/bvh/BVHNode.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 
+// #define GROUNDCACHE_DEBUG
+#ifdef GROUNDCACHE_DEBUG
+#include <osg/Group>
+#include <osg/ref_ptr>
+#include <simgear/timing/timestamp.hxx>
+#endif
+
 class SGMaterial;
 namespace simgear {
 class BVHLineGeometry;
@@ -50,14 +54,28 @@ public:
     // Prepare the ground cache for the wgs84 position pt_*.
     // That is take all vertices in the ball with radius rad around the
     // position given by the pt_* and store them in a local scene graph.
-    bool prepare_ground_cache(double ref_time, const SGVec3d& pt,
-                              double rad);
+    bool prepare_ground_cache(double startSimTime, double endSimTime,
+                              const SGVec3d& pt, double rad);
 
     // Returns true if the cache is valid.
     // Also the reference time, point and radius values where the cache
     // is valid for are returned.
     bool is_valid(double& ref_time, SGVec3d& pt, double& rad);
 
+    // Returns the unit down vector at the ground cache
+    const SGVec3d& get_down() const
+    { return down; }
+
+    // The time offset that originates from a simtime different than zero
+    // at initialization time of the fdm.
+    double get_cache_time_offset() const
+    { return cache_time_offset; }
+    void set_cache_time_offset(double time_offset)
+    { cache_time_offset = time_offset; }
+
+    bool get_body(double t, SGMatrixd& bodyToWorld, SGVec3d& linearVel,
+                  SGVec3d& angularVel, simgear::BVHNode::Id id);
+
     // Return the nearest catapult to the given point
     // pt in wgs84 coordinates.
     double get_cat(double t, const SGVec3d& pt,
@@ -66,13 +84,16 @@ public:
 
     // Return the altitude above ground below the wgs84 point pt
     // Search for highest triangle not higher than pt + max_altoff.
-    // Return ground properties like the ground type, the maximum load
+    // Return ground properties like the maximum load
     // this kind kind of ground can carry, the friction factor between
-    // 0 and 1 which can be used to model lower friction with wet runways
-    // and finally the altitude above ground.
-    bool get_agl(double t, const SGVec3d& pt, double max_altoff,
-                 SGVec3d& contact, SGVec3d& normal, SGVec3d& vel,
-                 int *type, const SGMaterial** material, double *agl);
+    // 0 and 1 which can be used to model lower friction with wet runways.
+    bool get_agl(double t, const SGVec3d& pt, SGVec3d& contact,
+                 SGVec3d& normal, SGVec3d& linearVel, SGVec3d& angularVel,
+                 simgear::BVHNode::Id& id, const SGMaterial*& material);
+
+    bool get_nearest(double t, const SGVec3d& pt, double maxDist,
+                     SGVec3d& contact, SGVec3d& linearVel, SGVec3d& angularVel,
+                     simgear::BVHNode::Id& id, const SGMaterial*& material);
 
     // Return 1 if the hook intersects with a wire.
     // That test is done by checking if the quad spanned by the points pt*
@@ -90,6 +111,7 @@ public:
 
 private:
     class CacheFill;
+    class BodyFinder;
     class CatapultFinder;
     class WireIntersector;
     class WireFinder;
@@ -97,13 +119,13 @@ private:
     // Approximate ground radius.
     // In case the aircraft is too high above ground.
     double _altitude;
-    // Ground type
-    int _type;
     // the simgear material reference, contains friction coeficients ...
     const SGMaterial* _material;
     // The time reference for later call to intersection test routines.
     // Is required since we will have moving triangles in carriers.
     double cache_ref_time;
+    // The time the cache was initialized.
+    double cache_time_offset;
     // The wire to track.
     const simgear::BVHLineGeometry* _wire;
 
@@ -115,6 +137,15 @@ private:
     bool found_ground;
 
     SGSharedPtr<simgear::BVHNode> _localBvhTree;
+
+#ifdef GROUNDCACHE_DEBUG
+    SGTimeStamp _lookupTime;
+    unsigned _lookupCount;
+    SGTimeStamp _buildTime;
+    unsigned _buildCount;
+
+    osg::ref_ptr<osg::Group> _group;
+#endif
 };
 
 #endif