WS30 - Move expensive conversion to loading thread

This commit is contained in:
Stuart Buchanan
2021-03-04 21:00:12 +00:00
parent ce197ea828
commit c147c5eb55
3 changed files with 10 additions and 16 deletions
+6 -3
View File
@@ -28,6 +28,8 @@
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/io/iostreams/sgstream.hxx> #include <simgear/io/iostreams/sgstream.hxx>
#include <simgear/math/SGGeod.hxx>
#include <simgear/scene/util/OsgMath.hxx>
#include "LineFeatureBin.hxx" #include "LineFeatureBin.hxx"
@@ -72,7 +74,7 @@ LineFeatureBin::LineFeatureBin(const SGPath& absoluteFileName, const std::string
float w = 0.0f; float w = 0.0f;
int attributes = 0; int attributes = 0;
float a=0, b=0, c=0, d=0; float a=0, b=0, c=0, d=0;
std::list<SGGeod> nodes; std::list<osg::Vec3d> nodes;
in >> w >> attributes >> a >> b >> c >> d; in >> w >> attributes >> a >> b >> c >> d;
@@ -89,8 +91,9 @@ LineFeatureBin::LineFeatureBin(const SGPath& absoluteFileName, const std::string
break; break;
} }
const SGGeod node = SGGeod::fromDeg(lon, lat); SGVec3d tmp;
nodes.push_back(node); SGGeodesy::SGGeodToCart(SGGeod::fromDeg(lon, lat), tmp);
nodes.push_back(toOsg(tmp));
} }
if (nodes.size() > 1) { if (nodes.size() > 1) {
+2 -3
View File
@@ -30,7 +30,6 @@
#include <osg/Matrix> #include <osg/Matrix>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/math/SGGeod.hxx>
namespace simgear namespace simgear
{ {
@@ -42,14 +41,14 @@ public:
~LineFeatureBin() = default; ~LineFeatureBin() = default;
struct LineFeature { struct LineFeature {
const std::list<SGGeod> _nodes; const std::list<osg::Vec3d> _nodes;
const float _width; const float _width;
const int _attributes; const int _attributes;
const float _a; const float _a;
const float _b; const float _b;
const float _c; const float _c;
const float _d; const float _d;
LineFeature(const std::list<SGGeod> nodes, const float w, const int attributes, const float a, const float b, const float c, const float d) : LineFeature(const std::list<osg::Vec3d> 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) _nodes(nodes), _width(w), _attributes(attributes), _a(a), _b(b), _c(c), _d(d)
{ {
} }
+2 -10
View File
@@ -1861,15 +1861,11 @@ void VPBTechnique::generateLineFeature(BufferData& buffer, Locator* masterLocato
return; return;
} }
SGVec3d tmp;
osg::Vec3d ma, mb; osg::Vec3d ma, mb;
std::list<osg::Vec3d> roadPoints; std::list<osg::Vec3d> roadPoints;
auto road_iter = road._nodes.begin(); auto road_iter = road._nodes.begin();
ma = *road_iter - modelCenter;
// This is expensive.
SGGeodesy::SGGeodToCart(SGGeod(*road_iter), tmp);
ma = toOsg(tmp) - modelCenter;
osg::Vec3d intersect = getMeshIntersection(buffer, masterLocator, ma); osg::Vec3d intersect = getMeshIntersection(buffer, masterLocator, ma);
@@ -1879,10 +1875,7 @@ void VPBTechnique::generateLineFeature(BufferData& buffer, Locator* masterLocato
road_iter++; road_iter++;
for (; road_iter != road._nodes.end(); road_iter++) { for (; road_iter != road._nodes.end(); road_iter++) {
mb = *road_iter - modelCenter;
// This is expensive.
SGGeodesy::SGGeodToCart(SGGeod(*road_iter), tmp);
mb = toOsg(tmp) - modelCenter;
intersect = getMeshIntersection(buffer, masterLocator, mb); intersect = getMeshIntersection(buffer, masterLocator, mb);
if (intersect != mb) roadPoints.push_back(intersect); 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 // Find the intersection of a given SGGeod with the terrain mesh
osg::Vec3d VPBTechnique::getMeshIntersection(BufferData& buffer, Locator* masterLocator, osg::Vec3d pt) osg::Vec3d VPBTechnique::getMeshIntersection(BufferData& buffer, Locator* masterLocator, osg::Vec3d pt)
{ {
SGVec3d tmp;
osg::Vec3d local, origin, top; osg::Vec3d local, origin, top;
// Get a vertical line segment. // Get a vertical line segment.