Make environment-manager closest airport updating quieter, and use an event instead of a manual time counter.
This commit is contained in:
parent
9c04b2c1ad
commit
43bc61d131
2 changed files with 34 additions and 27 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/scene/sky/sky.hxx>
|
#include <simgear/scene/sky/sky.hxx>
|
||||||
#include <simgear/scene/model/particles.hxx>
|
#include <simgear/scene/model/particles.hxx>
|
||||||
|
#include <simgear/structure/event_mgr.hxx>
|
||||||
|
|
||||||
#include <Main/main.hxx>
|
#include <Main/main.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
@ -90,7 +91,6 @@ FGEnvironmentMgr::FGEnvironmentMgr () :
|
||||||
_altitude_n(fgGetNode("/position/altitude-ft", true)),
|
_altitude_n(fgGetNode("/position/altitude-ft", true)),
|
||||||
_longitude_n(fgGetNode( "/position/longitude-deg", true )),
|
_longitude_n(fgGetNode( "/position/longitude-deg", true )),
|
||||||
_latitude_n( fgGetNode( "/position/latitude-deg", true )),
|
_latitude_n( fgGetNode( "/position/latitude-deg", true )),
|
||||||
_positionTimeToLive(0.0),
|
|
||||||
_3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) )
|
_3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) )
|
||||||
{
|
{
|
||||||
set_subsystem("controller", Environment::LayerInterpolateController::createInstance( fgGetNode("/environment/config", true ) ));
|
set_subsystem("controller", Environment::LayerInterpolateController::createInstance( fgGetNode("/environment/config", true ) ));
|
||||||
|
@ -145,6 +145,15 @@ FGEnvironmentMgr::init ()
|
||||||
_altitude_n->setDoubleValue(fgGetDouble("/sim/presets/altitude-ft"));
|
_altitude_n->setDoubleValue(fgGetDouble("/sim/presets/altitude-ft"));
|
||||||
_longitude_n->setDoubleValue(fgGetDouble("/sim/presets/longitude-deg"));
|
_longitude_n->setDoubleValue(fgGetDouble("/sim/presets/longitude-deg"));
|
||||||
_latitude_n->setDoubleValue(fgGetDouble("/sim/presets/latitude-deg"));
|
_latitude_n->setDoubleValue(fgGetDouble("/sim/presets/latitude-deg"));
|
||||||
|
|
||||||
|
globals->get_event_mgr()->addTask("updateClosestAirport", this,
|
||||||
|
&FGEnvironmentMgr::updateClosestAirport, 30 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FGEnvironmentMgr::shutdown()
|
||||||
|
{
|
||||||
|
globals->get_event_mgr()->removeTask("updateClosestAirport");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -258,33 +267,30 @@ FGEnvironmentMgr::update (double dt)
|
||||||
_latitude_n->getDoubleValue(),
|
_latitude_n->getDoubleValue(),
|
||||||
_altitude_n->getDoubleValue()
|
_altitude_n->getDoubleValue()
|
||||||
)));
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
_positionTimeToLive -= dt;
|
void
|
||||||
if( _positionTimeToLive <= 0.0 )
|
FGEnvironmentMgr::updateClosestAirport()
|
||||||
|
{
|
||||||
|
SG_LOG(SG_ENVIRONMENT, SG_DEBUG, "FGEnvironmentMgr::update: updating closest airport");
|
||||||
|
|
||||||
|
SGGeod pos = globals->get_aircraft_position();
|
||||||
|
FGAirport * nearestAirport = FGAirport::findClosest(pos, 100.0);
|
||||||
|
if( nearestAirport == NULL )
|
||||||
{
|
{
|
||||||
// update closest airport information
|
SG_LOG(SG_ENVIRONMENT,SG_WARN,"FGEnvironmentMgr::update: No airport within 100NM range");
|
||||||
_positionTimeToLive = 30.0;
|
|
||||||
|
|
||||||
SG_LOG(SG_ENVIRONMENT, SG_INFO, "FGEnvironmentMgr::update: updating closest airport");
|
|
||||||
|
|
||||||
SGGeod pos = SGGeod::fromDeg(_longitude_n->getDoubleValue(),
|
|
||||||
_latitude_n->getDoubleValue());
|
|
||||||
|
|
||||||
FGAirport * nearestAirport = FGAirport::findClosest(pos, 100.0);
|
|
||||||
if( nearestAirport == NULL )
|
|
||||||
{
|
|
||||||
SG_LOG(SG_ENVIRONMENT,SG_WARN,"FGEnvironmentMgr::update: No airport within 100NM range");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const string currentId = fgGetString("/sim/airport/closest-airport-id", "");
|
|
||||||
if (currentId != nearestAirport->ident())
|
|
||||||
{
|
|
||||||
fgSetString("/sim/airport/closest-airport-id",
|
|
||||||
nearestAirport->ident().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const string currentId = fgGetString("/sim/airport/closest-airport-id", "");
|
||||||
|
if (currentId != nearestAirport->ident())
|
||||||
|
{
|
||||||
|
SG_LOG(SG_ENVIRONMENT, SG_INFO, "FGEnvironmentMgr::updateClosestAirport: selected:" << nearestAirport->ident());
|
||||||
|
fgSetString("/sim/airport/closest-airport-id",
|
||||||
|
nearestAirport->ident().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FGEnvironment
|
FGEnvironment
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
|
|
||||||
virtual void init ();
|
virtual void init ();
|
||||||
virtual void reinit ();
|
virtual void reinit ();
|
||||||
|
virtual void shutdown ();
|
||||||
virtual void bind ();
|
virtual void bind ();
|
||||||
virtual void unbind ();
|
virtual void unbind ();
|
||||||
virtual void update (double dt);
|
virtual void update (double dt);
|
||||||
|
@ -74,7 +75,8 @@ public:
|
||||||
|
|
||||||
virtual FGEnvironment getEnvironment(const SGGeod& aPos) const;
|
virtual FGEnvironment getEnvironment(const SGGeod& aPos) const;
|
||||||
private:
|
private:
|
||||||
|
void updateClosestAirport();
|
||||||
|
|
||||||
double get_cloud_layer_span_m (int index) const;
|
double get_cloud_layer_span_m (int index) const;
|
||||||
void set_cloud_layer_span_m (int index, double span_m);
|
void set_cloud_layer_span_m (int index, double span_m);
|
||||||
double get_cloud_layer_elevation_ft (int index) const;
|
double get_cloud_layer_elevation_ft (int index) const;
|
||||||
|
@ -98,7 +100,6 @@ private:
|
||||||
SGPropertyNode_ptr _altitude_n;
|
SGPropertyNode_ptr _altitude_n;
|
||||||
SGPropertyNode_ptr _longitude_n;
|
SGPropertyNode_ptr _longitude_n;
|
||||||
SGPropertyNode_ptr _latitude_n;
|
SGPropertyNode_ptr _latitude_n;
|
||||||
double _positionTimeToLive;
|
|
||||||
simgear::TiedPropertyList _tiedProperties;
|
simgear::TiedPropertyList _tiedProperties;
|
||||||
SGPropertyChangeListener * _3dCloudsEnableListener;
|
SGPropertyChangeListener * _3dCloudsEnableListener;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue