From c147c5eb55f415bd4840af3bef97f7e072768486 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Thu, 4 Mar 2021 21:00:12 +0000 Subject: [PATCH] WS30 - Move expensive conversion to loading thread --- simgear/scene/tgdb/LineFeatureBin.cxx | 9 ++++++--- simgear/scene/tgdb/LineFeatureBin.hxx | 5 ++--- simgear/scene/tgdb/VPBTechnique.cxx | 12 ++---------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/simgear/scene/tgdb/LineFeatureBin.cxx b/simgear/scene/tgdb/LineFeatureBin.cxx index ddf9fbe3..769bb49b 100644 --- a/simgear/scene/tgdb/LineFeatureBin.cxx +++ b/simgear/scene/tgdb/LineFeatureBin.cxx @@ -28,6 +28,8 @@ #include #include +#include +#include #include "LineFeatureBin.hxx" @@ -72,7 +74,7 @@ LineFeatureBin::LineFeatureBin(const SGPath& absoluteFileName, const std::string float w = 0.0f; int attributes = 0; float a=0, b=0, c=0, d=0; - std::list nodes; + std::list nodes; in >> w >> attributes >> a >> b >> c >> d; @@ -89,8 +91,9 @@ LineFeatureBin::LineFeatureBin(const SGPath& absoluteFileName, const std::string break; } - const SGGeod node = SGGeod::fromDeg(lon, lat); - nodes.push_back(node); + SGVec3d tmp; + SGGeodesy::SGGeodToCart(SGGeod::fromDeg(lon, lat), tmp); + nodes.push_back(toOsg(tmp)); } if (nodes.size() > 1) { diff --git a/simgear/scene/tgdb/LineFeatureBin.hxx b/simgear/scene/tgdb/LineFeatureBin.hxx index 13b7cde6..88b0312d 100644 --- a/simgear/scene/tgdb/LineFeatureBin.hxx +++ b/simgear/scene/tgdb/LineFeatureBin.hxx @@ -30,7 +30,6 @@ #include #include -#include namespace simgear { @@ -42,14 +41,14 @@ public: ~LineFeatureBin() = default; struct LineFeature { - const std::list _nodes; + const std::list _nodes; const float _width; const int _attributes; const float _a; const float _b; const float _c; const float _d; - LineFeature(const std::list nodes, const float w, const int attributes, const float a, const float b, const float c, const float d) : + LineFeature(const std::list nodes, const float w, const int attributes, const float a, const float b, const float c, const float d) : _nodes(nodes), _width(w), _attributes(attributes), _a(a), _b(b), _c(c), _d(d) { } diff --git a/simgear/scene/tgdb/VPBTechnique.cxx b/simgear/scene/tgdb/VPBTechnique.cxx index f76af7c0..d8078261 100644 --- a/simgear/scene/tgdb/VPBTechnique.cxx +++ b/simgear/scene/tgdb/VPBTechnique.cxx @@ -1861,15 +1861,11 @@ void VPBTechnique::generateLineFeature(BufferData& buffer, Locator* masterLocato return; } - SGVec3d tmp; osg::Vec3d ma, mb; std::list roadPoints; auto road_iter = road._nodes.begin(); - - // This is expensive. - SGGeodesy::SGGeodToCart(SGGeod(*road_iter), tmp); - ma = toOsg(tmp) - modelCenter; + ma = *road_iter - modelCenter; osg::Vec3d intersect = getMeshIntersection(buffer, masterLocator, ma); @@ -1879,10 +1875,7 @@ void VPBTechnique::generateLineFeature(BufferData& buffer, Locator* masterLocato road_iter++; for (; road_iter != road._nodes.end(); road_iter++) { - - // This is expensive. - SGGeodesy::SGGeodToCart(SGGeod(*road_iter), tmp); - mb = toOsg(tmp) - modelCenter; + mb = *road_iter - modelCenter; intersect = getMeshIntersection(buffer, masterLocator, mb); if (intersect != mb) roadPoints.push_back(intersect); @@ -1960,7 +1953,6 @@ void VPBTechnique::generateLineFeature(BufferData& buffer, Locator* masterLocato // Find the intersection of a given SGGeod with the terrain mesh osg::Vec3d VPBTechnique::getMeshIntersection(BufferData& buffer, Locator* masterLocator, osg::Vec3d pt) { - SGVec3d tmp; osg::Vec3d local, origin, top; // Get a vertical line segment.