Automatic tower positioning
New "auto-position" switch to always use closest tower for tower-view. Exposes new "/sim/airport/closest-airport-id" property. Display closest airport on groundradar by default.
This commit is contained in:
parent
9c3571da5f
commit
e42a8f597c
4 changed files with 114 additions and 47 deletions
|
@ -42,6 +42,7 @@
|
||||||
#include "precipitation_mgr.hxx"
|
#include "precipitation_mgr.hxx"
|
||||||
#include "ridge_lift.hxx"
|
#include "ridge_lift.hxx"
|
||||||
#include "terrainsampler.hxx"
|
#include "terrainsampler.hxx"
|
||||||
|
#include "Airports/simple.hxx"
|
||||||
|
|
||||||
class SGSky;
|
class SGSky;
|
||||||
extern SGSky *thesky;
|
extern SGSky *thesky;
|
||||||
|
@ -49,8 +50,11 @@ extern SGSky *thesky;
|
||||||
FGEnvironmentMgr::FGEnvironmentMgr () :
|
FGEnvironmentMgr::FGEnvironmentMgr () :
|
||||||
_environment(new FGEnvironment()),
|
_environment(new FGEnvironment()),
|
||||||
fgClouds(new FGClouds()),
|
fgClouds(new FGClouds()),
|
||||||
|
_cloudLayersDirty(true),
|
||||||
_altitudeNode(fgGetNode("/position/altitude-ft", true)),
|
_altitudeNode(fgGetNode("/position/altitude-ft", true)),
|
||||||
_cloudLayersDirty(true)
|
_longitude_n(fgGetNode( "/position/longitude-deg", true )),
|
||||||
|
_latitude_n( fgGetNode( "/position/latitude-deg", true )),
|
||||||
|
_positionTimeToLive(0.0)
|
||||||
{
|
{
|
||||||
set_subsystem("controller", Environment::LayerInterpolateController::createInstance( fgGetNode("/environment/config", true ) ));
|
set_subsystem("controller", Environment::LayerInterpolateController::createInstance( fgGetNode("/environment/config", true ) ));
|
||||||
set_subsystem("realwx", Environment::RealWxController::createInstance( fgGetNode("/environment/realwx", true ) ), 1.0 );
|
set_subsystem("realwx", Environment::RealWxController::createInstance( fgGetNode("/environment/realwx", true ) ), 1.0 );
|
||||||
|
@ -203,6 +207,33 @@ FGEnvironmentMgr::update (double dt)
|
||||||
_cloudLayersDirty = false;
|
_cloudLayersDirty = false;
|
||||||
fgClouds->set_update_event( fgClouds->get_update_event()+1 );
|
fgClouds->set_update_event( fgClouds->get_update_event()+1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_positionTimeToLive -= dt;
|
||||||
|
if( _positionTimeToLive <= 0.0 )
|
||||||
|
{
|
||||||
|
// update closest airport information
|
||||||
|
_positionTimeToLive = 30.0;
|
||||||
|
|
||||||
|
SG_LOG(SG_ALL, 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_ALL,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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FGEnvironment
|
FGEnvironment
|
||||||
|
|
|
@ -94,8 +94,11 @@ private:
|
||||||
|
|
||||||
FGEnvironment * _environment; // always the same, for now
|
FGEnvironment * _environment; // always the same, for now
|
||||||
FGClouds *fgClouds;
|
FGClouds *fgClouds;
|
||||||
SGPropertyNode_ptr _altitudeNode;
|
|
||||||
bool _cloudLayersDirty;
|
bool _cloudLayersDirty;
|
||||||
|
SGPropertyNode_ptr _altitudeNode;
|
||||||
|
SGPropertyNode_ptr _longitude_n;
|
||||||
|
SGPropertyNode_ptr _latitude_n;
|
||||||
|
double _positionTimeToLive;
|
||||||
simgear::TiedPropertyList _tiedProperties;
|
simgear::TiedPropertyList _tiedProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
#include "groundradar.hxx"
|
#include "groundradar.hxx"
|
||||||
|
|
||||||
static const char* airport_source_node_name = "airport-id-source";
|
static const char* airport_source_node_name = "airport-id-source";
|
||||||
static const char* default_airport_node_name = "/sim/tower/airport-id";
|
static const char* default_airport_node_name = "/sim/airport/closest-airport-id";
|
||||||
static const char* texture_node_name = "texture-name";
|
static const char* texture_node_name = "texture-name";
|
||||||
static const char* default_texture_name = "Aircraft/Instruments/Textures/od_groundradar.rgb";
|
static const char* default_texture_name = "Aircraft/Instruments/Textures/od_groundradar.rgb";
|
||||||
static const char* range_source_node_name = "range-source";
|
static const char* range_source_node_name = "range-source";
|
||||||
|
|
|
@ -793,14 +793,44 @@ static bool fgSetTowerPosFromAirportID( const string& id) {
|
||||||
|
|
||||||
struct FGTowerLocationListener : SGPropertyChangeListener {
|
struct FGTowerLocationListener : SGPropertyChangeListener {
|
||||||
void valueChanged(SGPropertyNode* node) {
|
void valueChanged(SGPropertyNode* node) {
|
||||||
const string id(node->getStringValue());
|
string id(node->getStringValue());
|
||||||
|
if (fgGetBool("/sim/tower/auto-position",true))
|
||||||
|
{
|
||||||
|
// enforce using closest airport when auto-positioning is enabled
|
||||||
|
const char* closest_airport = fgGetString("/sim/airport/closest-airport-id", "");
|
||||||
|
if (closest_airport && (id != closest_airport))
|
||||||
|
{
|
||||||
|
id = closest_airport;
|
||||||
|
node->setStringValue(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
fgSetTowerPosFromAirportID(id);
|
fgSetTowerPosFromAirportID(id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FGClosestTowerLocationListener : SGPropertyChangeListener
|
||||||
|
{
|
||||||
|
void valueChanged(SGPropertyNode* )
|
||||||
|
{
|
||||||
|
// closest airport has changed
|
||||||
|
if (fgGetBool("/sim/tower/auto-position",true))
|
||||||
|
{
|
||||||
|
// update tower position
|
||||||
|
const char* id = fgGetString("/sim/airport/closest-airport-id", "");
|
||||||
|
if (id && *id!=0)
|
||||||
|
fgSetString("/sim/tower/airport-id", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void fgInitTowerLocationListener() {
|
void fgInitTowerLocationListener() {
|
||||||
fgGetNode("/sim/tower/airport-id", true)
|
fgGetNode("/sim/tower/airport-id", true)
|
||||||
->addChangeListener( new FGTowerLocationListener(), true );
|
->addChangeListener( new FGTowerLocationListener(), true );
|
||||||
|
FGClosestTowerLocationListener* ntcl = new FGClosestTowerLocationListener();
|
||||||
|
fgGetNode("/sim/airport/closest-airport-id", true)
|
||||||
|
->addChangeListener(ntcl , true );
|
||||||
|
fgGetNode("/sim/tower/auto-position", true)
|
||||||
|
->addChangeListener(ntcl, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double aTargetHeading = HUGE_VAL)
|
static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double aTargetHeading = HUGE_VAL)
|
||||||
|
@ -1163,6 +1193,7 @@ bool fgInitPosition() {
|
||||||
// An airport + parking position is requested
|
// An airport + parking position is requested
|
||||||
if ( fgSetPosFromAirportIDandParkpos( apt, parkpos ) ) {
|
if ( fgSetPosFromAirportIDandParkpos( apt, parkpos ) ) {
|
||||||
// set tower position
|
// set tower position
|
||||||
|
fgSetString("/sim/airport/closest-airport-id", apt.c_str());
|
||||||
fgSetString("/sim/tower/airport-id", apt.c_str());
|
fgSetString("/sim/tower/airport-id", apt.c_str());
|
||||||
set_pos = true;
|
set_pos = true;
|
||||||
}
|
}
|
||||||
|
@ -1173,6 +1204,7 @@ bool fgInitPosition() {
|
||||||
if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) {
|
if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) {
|
||||||
// set tower position (a little off the heading for single
|
// set tower position (a little off the heading for single
|
||||||
// runway airports)
|
// runway airports)
|
||||||
|
fgSetString("/sim/airport/closest-airport-id", apt.c_str());
|
||||||
fgSetString("/sim/tower/airport-id", apt.c_str());
|
fgSetString("/sim/tower/airport-id", apt.c_str());
|
||||||
set_pos = true;
|
set_pos = true;
|
||||||
}
|
}
|
||||||
|
@ -1183,6 +1215,7 @@ bool fgInitPosition() {
|
||||||
if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
|
if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
|
||||||
// set tower position (a little off the heading for single
|
// set tower position (a little off the heading for single
|
||||||
// runway airports)
|
// runway airports)
|
||||||
|
fgSetString("/sim/airport/closest-airport-id", apt.c_str());
|
||||||
fgSetString("/sim/tower/airport-id", apt.c_str());
|
fgSetString("/sim/tower/airport-id", apt.c_str());
|
||||||
set_pos = true;
|
set_pos = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue