Kill off some globals.
Break some subsystem dependencies, by explicitly using properties to read the primary position, orientation and velocities. (Instead of directly accessing the primary model placement). This means a couple more globals can die.
This commit is contained in:
parent
32248bf576
commit
029012b8b9
6 changed files with 41 additions and 100 deletions
|
@ -710,13 +710,8 @@ void fgCreateSubsystems() {
|
||||||
// ordering here is important : Nasal (via events), then models, then views
|
// ordering here is important : Nasal (via events), then models, then views
|
||||||
globals->add_subsystem("events", globals->get_event_mgr(), SGSubsystemMgr::DISPLAY);
|
globals->add_subsystem("events", globals->get_event_mgr(), SGSubsystemMgr::DISPLAY);
|
||||||
|
|
||||||
FGAircraftModel* acm = new FGAircraftModel;
|
globals->add_subsystem("aircraft-model", new FGAircraftModel, SGSubsystemMgr::DISPLAY);
|
||||||
globals->set_aircraft_model(acm);
|
globals->add_subsystem("model-manager", new FGModelMgr, SGSubsystemMgr::DISPLAY);
|
||||||
globals->add_subsystem("aircraft-model", acm, SGSubsystemMgr::DISPLAY);
|
|
||||||
|
|
||||||
FGModelMgr* mm = new FGModelMgr;
|
|
||||||
globals->set_model_mgr(mm);
|
|
||||||
globals->add_subsystem("model-manager", mm, SGSubsystemMgr::DISPLAY);
|
|
||||||
|
|
||||||
FGViewMgr *viewmgr = new FGViewMgr;
|
FGViewMgr *viewmgr = new FGViewMgr;
|
||||||
globals->set_viewmgr( viewmgr );
|
globals->set_viewmgr( viewmgr );
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include <simgear/misc/ResourceManager.hxx>
|
#include <simgear/misc/ResourceManager.hxx>
|
||||||
#include <simgear/props/propertyObject.hxx>
|
#include <simgear/props/propertyObject.hxx>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
#include <simgear/scene/model/placement.hxx>
|
|
||||||
|
|
||||||
#include <Aircraft/controls.hxx>
|
#include <Aircraft/controls.hxx>
|
||||||
#include <Airports/runways.hxx>
|
#include <Airports/runways.hxx>
|
||||||
|
@ -47,8 +46,6 @@
|
||||||
#include <Autopilot/route_mgr.hxx>
|
#include <Autopilot/route_mgr.hxx>
|
||||||
#include <GUI/FGFontCache.hxx>
|
#include <GUI/FGFontCache.hxx>
|
||||||
#include <GUI/gui.h>
|
#include <GUI/gui.h>
|
||||||
#include <Model/acmodel.hxx>
|
|
||||||
#include <Model/modelmgr.hxx>
|
|
||||||
#include <MultiPlayer/multiplaymgr.hxx>
|
#include <MultiPlayer/multiplaymgr.hxx>
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
#include <Scenery/tilemgr.hxx>
|
#include <Scenery/tilemgr.hxx>
|
||||||
|
@ -136,24 +133,24 @@ FGGlobals::FGGlobals() :
|
||||||
controls( NULL ),
|
controls( NULL ),
|
||||||
viewmgr( NULL ),
|
viewmgr( NULL ),
|
||||||
commands( SGCommandMgr::instance() ),
|
commands( SGCommandMgr::instance() ),
|
||||||
acmodel( NULL ),
|
|
||||||
model_mgr( NULL ),
|
|
||||||
channel_options_list( NULL ),
|
channel_options_list( NULL ),
|
||||||
initial_waypoints( NULL ),
|
initial_waypoints( NULL ),
|
||||||
scenery( NULL ),
|
scenery( NULL ),
|
||||||
tile_mgr( NULL ),
|
tile_mgr( NULL ),
|
||||||
fontcache ( new FGFontCache ),
|
fontcache ( new FGFontCache ),
|
||||||
navlist( NULL ),
|
|
||||||
loclist( NULL ),
|
|
||||||
gslist( NULL ),
|
|
||||||
dmelist( NULL ),
|
|
||||||
tacanlist( NULL ),
|
|
||||||
carrierlist( NULL ),
|
|
||||||
channellist( NULL ),
|
channellist( NULL ),
|
||||||
haveUserSettings(false)
|
haveUserSettings(false)
|
||||||
{
|
{
|
||||||
simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
|
simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
|
||||||
simgear::PropertyObjectBase::setDefaultRoot(props);
|
simgear::PropertyObjectBase::setDefaultRoot(props);
|
||||||
|
|
||||||
|
positionLon = props->getNode("position/longitude-deg", true);
|
||||||
|
positionLat = props->getNode("position/latitude-deg", true);
|
||||||
|
positionAlt = props->getNode("position/altitude-ft", true);
|
||||||
|
|
||||||
|
orientPitch = props->getNode("orientation/pitch-deg", true);
|
||||||
|
orientHeading = props->getNode("orientation/heading-deg", true);
|
||||||
|
orientRoll = props->getNode("orientation/roll-deg", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
@ -199,12 +196,6 @@ FGGlobals::~FGGlobals()
|
||||||
delete scenery;
|
delete scenery;
|
||||||
delete fontcache;
|
delete fontcache;
|
||||||
|
|
||||||
delete navlist;
|
|
||||||
delete loclist;
|
|
||||||
delete gslist;
|
|
||||||
delete dmelist;
|
|
||||||
delete tacanlist;
|
|
||||||
delete carrierlist;
|
|
||||||
delete channellist;
|
delete channellist;
|
||||||
delete sound;
|
delete sound;
|
||||||
|
|
||||||
|
@ -389,18 +380,9 @@ FGGlobals::get_event_mgr () const
|
||||||
SGGeod
|
SGGeod
|
||||||
FGGlobals::get_aircraft_position() const
|
FGGlobals::get_aircraft_position() const
|
||||||
{
|
{
|
||||||
if( acmodel != NULL ) {
|
return SGGeod::fromDegFt(positionLon->getDoubleValue(),
|
||||||
SGModelPlacement * mp = acmodel->get3DModel();
|
positionLat->getDoubleValue(),
|
||||||
if( mp != NULL )
|
positionAlt->getDoubleValue());
|
||||||
return mp->getPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
// fall back to reading the property tree. this can occur during
|
|
||||||
// startup before the acmodel is initialised
|
|
||||||
|
|
||||||
return SGGeod::fromDegFt(fgGetDouble("/position/longitude-deg"),
|
|
||||||
fgGetDouble("/position/latitude-deg"),
|
|
||||||
fgGetDouble("/position/altitude-ft"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SGVec3d
|
SGVec3d
|
||||||
|
@ -409,6 +391,13 @@ FGGlobals::get_aircraft_positon_cart() const
|
||||||
return SGVec3d::fromGeod(get_aircraft_position());
|
return SGVec3d::fromGeod(get_aircraft_position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FGGlobals::get_aircraft_orientation(double& heading, double& pitch, double& roll)
|
||||||
|
{
|
||||||
|
heading = orientHeading->getDoubleValue();
|
||||||
|
pitch = orientPitch->getDoubleValue();
|
||||||
|
roll = orientRoll->getDoubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Save the current state as the initial state.
|
// Save the current state as the initial state.
|
||||||
void
|
void
|
||||||
|
|
|
@ -55,13 +55,9 @@ class SGSubsystem;
|
||||||
class SGSoundMgr;
|
class SGSoundMgr;
|
||||||
|
|
||||||
class FGATISMgr;
|
class FGATISMgr;
|
||||||
class FGAircraftModel;
|
|
||||||
class FGControls;
|
class FGControls;
|
||||||
class FGFlightPlanDispatcher;
|
|
||||||
class FGNavList;
|
|
||||||
class FGTACANList;
|
class FGTACANList;
|
||||||
class FGLocale;
|
class FGLocale;
|
||||||
class FGModelMgr;
|
|
||||||
class FGRouteMgr;
|
class FGRouteMgr;
|
||||||
class FGScenery;
|
class FGScenery;
|
||||||
class FGTileMgr;
|
class FGTileMgr;
|
||||||
|
@ -128,12 +124,6 @@ private:
|
||||||
|
|
||||||
SGCommandMgr *commands;
|
SGCommandMgr *commands;
|
||||||
|
|
||||||
//FGFlightPlanDispatcher *fpDispatcher;
|
|
||||||
|
|
||||||
FGAircraftModel *acmodel;
|
|
||||||
|
|
||||||
FGModelMgr * model_mgr;
|
|
||||||
|
|
||||||
// list of serial port-like configurations
|
// list of serial port-like configurations
|
||||||
string_list *channel_options_list;
|
string_list *channel_options_list;
|
||||||
|
|
||||||
|
@ -150,12 +140,6 @@ private:
|
||||||
FGFontCache *fontcache;
|
FGFontCache *fontcache;
|
||||||
|
|
||||||
// Navigational Aids
|
// Navigational Aids
|
||||||
FGNavList *navlist;
|
|
||||||
FGNavList *loclist;
|
|
||||||
FGNavList *gslist;
|
|
||||||
FGNavList *dmelist;
|
|
||||||
FGNavList *tacanlist;
|
|
||||||
FGNavList *carrierlist;
|
|
||||||
FGTACANList *channellist;
|
FGTACANList *channellist;
|
||||||
|
|
||||||
/// roots of Aircraft trees
|
/// roots of Aircraft trees
|
||||||
|
@ -163,6 +147,8 @@ private:
|
||||||
|
|
||||||
bool haveUserSettings;
|
bool haveUserSettings;
|
||||||
|
|
||||||
|
SGPropertyNode_ptr positionLon, positionLat, positionAlt;
|
||||||
|
SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGGlobals();
|
FGGlobals();
|
||||||
|
@ -261,23 +247,11 @@ public:
|
||||||
|
|
||||||
inline SGCommandMgr *get_commands () { return commands; }
|
inline SGCommandMgr *get_commands () { return commands; }
|
||||||
|
|
||||||
inline FGAircraftModel *get_aircraft_model () { return acmodel; }
|
|
||||||
|
|
||||||
inline void set_aircraft_model (FGAircraftModel * model)
|
|
||||||
{
|
|
||||||
acmodel = model;
|
|
||||||
}
|
|
||||||
|
|
||||||
SGGeod get_aircraft_position() const;
|
SGGeod get_aircraft_position() const;
|
||||||
|
|
||||||
SGVec3d get_aircraft_positon_cart() const;
|
SGVec3d get_aircraft_positon_cart() const;
|
||||||
|
|
||||||
inline FGModelMgr *get_model_mgr () { return model_mgr; }
|
void get_aircraft_orientation(double& heading, double& pitch, double& roll);
|
||||||
|
|
||||||
inline void set_model_mgr (FGModelMgr * mgr)
|
|
||||||
{
|
|
||||||
model_mgr = mgr;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline string_list *get_channel_options_list () {
|
inline string_list *get_channel_options_list () {
|
||||||
return channel_options_list;
|
return channel_options_list;
|
||||||
|
@ -302,21 +276,6 @@ public:
|
||||||
|
|
||||||
inline FGFontCache *get_fontcache() const { return fontcache; }
|
inline FGFontCache *get_fontcache() const { return fontcache; }
|
||||||
|
|
||||||
#if 0
|
|
||||||
inline FGNavList *get_navlist() const { return navlist; }
|
|
||||||
inline void set_navlist( FGNavList *n ) { navlist = n; }
|
|
||||||
inline FGNavList *get_loclist() const { return loclist; }
|
|
||||||
inline void set_loclist( FGNavList *n ) { loclist = n; }
|
|
||||||
inline FGNavList *get_gslist() const { return gslist; }
|
|
||||||
inline void set_gslist( FGNavList *n ) { gslist = n; }
|
|
||||||
inline FGNavList *get_dmelist() const { return dmelist; }
|
|
||||||
inline void set_dmelist( FGNavList *n ) { dmelist = n; }
|
|
||||||
inline FGNavList *get_tacanlist() const { return tacanlist; }
|
|
||||||
inline void set_tacanlist( FGNavList *n ) { tacanlist = n; }
|
|
||||||
inline FGNavList *get_carrierlist() const { return carrierlist; }
|
|
||||||
inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
inline FGTACANList *get_channellist() const { return channellist; }
|
inline FGTACANList *get_channellist() const { return channellist; }
|
||||||
inline void set_channellist( FGTACANList *c ) { channellist = c; }
|
inline void set_channellist( FGTACANList *c ) { channellist = c; }
|
||||||
|
|
||||||
|
|
|
@ -370,12 +370,8 @@ FGViewer::recalcLookFrom ()
|
||||||
{
|
{
|
||||||
// Update location data ...
|
// Update location data ...
|
||||||
if ( _from_model ) {
|
if ( _from_model ) {
|
||||||
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
_position = globals->get_aircraft_position();
|
||||||
_position = placement->getPosition();
|
globals->get_aircraft_orientation(_heading_deg, _pitch_deg, _roll_deg);
|
||||||
|
|
||||||
_heading_deg = placement->getHeadingDeg();
|
|
||||||
_pitch_deg = placement->getPitchDeg();
|
|
||||||
_roll_deg = placement->getRollDeg();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double head = _heading_deg;
|
double head = _heading_deg;
|
||||||
|
@ -419,11 +415,10 @@ FGViewer::recalcLookAt ()
|
||||||
{
|
{
|
||||||
// The geodetic position of our target to look at
|
// The geodetic position of our target to look at
|
||||||
if ( _at_model ) {
|
if ( _at_model ) {
|
||||||
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
_target = globals->get_aircraft_position();
|
||||||
_target = placement->getPosition();
|
globals->get_aircraft_orientation(_target_heading_deg,
|
||||||
_target_heading_deg = placement->getHeadingDeg();
|
_target_pitch_deg,
|
||||||
_target_pitch_deg = placement->getPitchDeg();
|
_target_roll_deg);
|
||||||
_target_roll_deg = placement->getRollDeg();
|
|
||||||
} else {
|
} else {
|
||||||
// if not model then calculate our own target position...
|
// if not model then calculate our own target position...
|
||||||
setDampTarget(_target_roll_deg, _target_pitch_deg, _target_heading_deg);
|
setDampTarget(_target_roll_deg, _target_pitch_deg, _target_heading_deg);
|
||||||
|
@ -437,11 +432,8 @@ FGViewer::recalcLookAt ()
|
||||||
|
|
||||||
|
|
||||||
if ( _from_model ) {
|
if ( _from_model ) {
|
||||||
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
|
_position = globals->get_aircraft_position();
|
||||||
_position = placement->getPosition();
|
globals->get_aircraft_orientation(_heading_deg, _pitch_deg, _roll_deg);
|
||||||
_heading_deg = placement->getHeadingDeg();
|
|
||||||
_pitch_deg = placement->getPitchDeg();
|
|
||||||
_roll_deg = placement->getRollDeg();
|
|
||||||
} else {
|
} else {
|
||||||
// update from our own data, just the rotation here...
|
// update from our own data, just the rotation here...
|
||||||
setDampTarget(_roll_deg, _pitch_deg, _heading_deg);
|
setDampTarget(_roll_deg, _pitch_deg, _heading_deg);
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include <simgear/sound/soundmgr_openal.hxx>
|
#include <simgear/sound/soundmgr_openal.hxx>
|
||||||
#include <Model/acmodel.hxx>
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include "viewer.hxx"
|
#include "viewer.hxx"
|
||||||
|
|
||||||
|
@ -181,6 +180,10 @@ FGViewMgr::bind()
|
||||||
void
|
void
|
||||||
FGViewMgr::do_bind()
|
FGViewMgr::do_bind()
|
||||||
{
|
{
|
||||||
|
velocityNorthFPS = fgGetNode("velocities/speed-north-fps", true);
|
||||||
|
velocityEastFPS = fgGetNode("velocities/speed-east-fps", true);
|
||||||
|
velocityDownFPS = fgGetNode("velocities/speed-down-fps", true);
|
||||||
|
|
||||||
// these are bound to the current view properties
|
// these are bound to the current view properties
|
||||||
_tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
|
_tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
|
||||||
_tiedProperties.Tie("heading-offset-deg", this,
|
_tiedProperties.Tie("heading-offset-deg", this,
|
||||||
|
@ -338,7 +341,9 @@ FGViewMgr::update (double dt)
|
||||||
// get the model velocity
|
// get the model velocity
|
||||||
SGVec3d velocity = SGVec3d::zeros();
|
SGVec3d velocity = SGVec3d::zeros();
|
||||||
if ( !stationary() ) {
|
if ( !stationary() ) {
|
||||||
velocity = globals->get_aircraft_model()->getVelocity();
|
velocity = SGVec3d( velocityNorthFPS->getDoubleValue(),
|
||||||
|
velocityEastFPS->getDoubleValue(),
|
||||||
|
velocityDownFPS->getDoubleValue() );
|
||||||
}
|
}
|
||||||
smgr->set_velocity( velocity );
|
smgr->set_velocity( velocity );
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,6 +150,7 @@ private:
|
||||||
|
|
||||||
SGSoundMgr *smgr;
|
SGSoundMgr *smgr;
|
||||||
|
|
||||||
|
SGPropertyNode_ptr velocityNorthFPS, velocityEastFPS, velocityDownFPS;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This takes the conventional aviation XYZ body system
|
// This takes the conventional aviation XYZ body system
|
||||||
|
|
Loading…
Reference in a new issue