diff --git a/simgear/scene/sky/sky.cxx b/simgear/scene/sky/sky.cxx index 389d8bf4..25df35d7 100644 --- a/simgear/scene/sky/sky.cxx +++ b/simgear/scene/sky/sky.cxx @@ -94,7 +94,7 @@ void SGSky::build( double h_radius_m, planets = new SGStars; _ephTransform->addChild( planets->build(eph.getNumPlanets(), eph.getPlanets(), h_radius_m) ); - stars = new SGStars; + stars = new SGStars(property_tree_node); _ephTransform->addChild( stars->build(eph.getNumStars(), eph.getStars(), h_radius_m) ); moon = new SGMoon; diff --git a/simgear/scene/sky/stars.cxx b/simgear/scene/sky/stars.cxx index d4611e01..6eb70fa1 100644 --- a/simgear/scene/sky/stars.cxx +++ b/simgear/scene/sky/stars.cxx @@ -30,9 +30,11 @@ #include #include #include +#include #include #include +#include #include #include @@ -47,9 +49,14 @@ #include "stars.hxx" // Constructor -SGStars::SGStars( void ) : -old_phase(-1) +SGStars::SGStars( SGPropertyNode* props ) : + old_phase(-1) { + if (props) { + // don't create here - if it's not defined, we won't use the cutoff + // from a property + _cutoffProperty = props->getNode("star-magnitude-cutoff"); + } } @@ -161,10 +168,17 @@ bool SGStars::repaint( double sun_angle, int num, const SGVec3d star_data[] ) { cutoff = 0.0; phase = 7; } - - if( phase != old_phase ) { + + if (_cutoffProperty) { + double propCutoff = _cutoffProperty->getDoubleValue(); + cutoff = std::min(propCutoff, cutoff); + } + + if ((phase != old_phase) || (cutoff != _cachedCutoff)) { // cout << " phase change, repainting stars, num = " << num << endl; old_phase = phase; + _cachedCutoff = cutoff; + for ( int i = 0; i < num; ++i ) { // if ( star_data[i][2] < min ) { min = star_data[i][2]; } // if ( star_data[i][2] > max ) { max = star_data[i][2]; } @@ -190,11 +204,8 @@ bool SGStars::repaint( double sun_angle, int num, const SGVec3d star_data[] ) { if (alpha < 0.0) { alpha = 0.0; } (*cl)[i] = osg::Vec4(1, 1, 1, alpha); - // cout << "alpha[" << i << "] = " << alpha << endl; } cl->dirty(); - } else { - // cout << " no phase change, skipping" << endl; } // cout << "min = " << min << " max = " << max << " count = " << num diff --git a/simgear/scene/sky/stars.hxx b/simgear/scene/sky/stars.hxx index bf311e31..10b0140c 100644 --- a/simgear/scene/sky/stars.hxx +++ b/simgear/scene/sky/stars.hxx @@ -33,18 +33,20 @@ #include #include - +#include class SGStars : public SGReferenced { osg::ref_ptr cl; int old_phase; // data for optimization - + + double _cachedCutoff = 0.0; + SGPropertyNode_ptr _cutoffProperty; public: // Constructor - SGStars( void ); + SGStars( SGPropertyNode* props = nullptr); // Destructor ~SGStars( void );