1
0
Fork 0

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:
James Turner 2012-09-19 18:17:44 +01:00
parent 32248bf576
commit 029012b8b9
6 changed files with 41 additions and 100 deletions

View file

@ -710,13 +710,8 @@ void fgCreateSubsystems() {
// ordering here is important : Nasal (via events), then models, then views
globals->add_subsystem("events", globals->get_event_mgr(), SGSubsystemMgr::DISPLAY);
FGAircraftModel* acm = new FGAircraftModel;
globals->set_aircraft_model(acm);
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);
globals->add_subsystem("aircraft-model", new FGAircraftModel, SGSubsystemMgr::DISPLAY);
globals->add_subsystem("model-manager", new FGModelMgr, SGSubsystemMgr::DISPLAY);
FGViewMgr *viewmgr = new FGViewMgr;
globals->set_viewmgr( viewmgr );

View file

@ -39,7 +39,6 @@
#include <simgear/misc/ResourceManager.hxx>
#include <simgear/props/propertyObject.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/scene/model/placement.hxx>
#include <Aircraft/controls.hxx>
#include <Airports/runways.hxx>
@ -47,8 +46,6 @@
#include <Autopilot/route_mgr.hxx>
#include <GUI/FGFontCache.hxx>
#include <GUI/gui.h>
#include <Model/acmodel.hxx>
#include <Model/modelmgr.hxx>
#include <MultiPlayer/multiplaymgr.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
@ -136,24 +133,24 @@ FGGlobals::FGGlobals() :
controls( NULL ),
viewmgr( NULL ),
commands( SGCommandMgr::instance() ),
acmodel( NULL ),
model_mgr( NULL ),
channel_options_list( NULL ),
initial_waypoints( NULL ),
scenery( NULL ),
tile_mgr( NULL ),
fontcache ( new FGFontCache ),
navlist( NULL ),
loclist( NULL ),
gslist( NULL ),
dmelist( NULL ),
tacanlist( NULL ),
carrierlist( NULL ),
channellist( NULL ),
haveUserSettings(false)
{
simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
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
@ -199,12 +196,6 @@ FGGlobals::~FGGlobals()
delete scenery;
delete fontcache;
delete navlist;
delete loclist;
delete gslist;
delete dmelist;
delete tacanlist;
delete carrierlist;
delete channellist;
delete sound;
@ -389,18 +380,9 @@ FGGlobals::get_event_mgr () const
SGGeod
FGGlobals::get_aircraft_position() const
{
if( acmodel != NULL ) {
SGModelPlacement * mp = acmodel->get3DModel();
if( mp != NULL )
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"));
return SGGeod::fromDegFt(positionLon->getDoubleValue(),
positionLat->getDoubleValue(),
positionAlt->getDoubleValue());
}
SGVec3d
@ -409,6 +391,13 @@ FGGlobals::get_aircraft_positon_cart() const
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.
void

View file

@ -55,13 +55,9 @@ class SGSubsystem;
class SGSoundMgr;
class FGATISMgr;
class FGAircraftModel;
class FGControls;
class FGFlightPlanDispatcher;
class FGNavList;
class FGTACANList;
class FGLocale;
class FGModelMgr;
class FGRouteMgr;
class FGScenery;
class FGTileMgr;
@ -128,12 +124,6 @@ private:
SGCommandMgr *commands;
//FGFlightPlanDispatcher *fpDispatcher;
FGAircraftModel *acmodel;
FGModelMgr * model_mgr;
// list of serial port-like configurations
string_list *channel_options_list;
@ -150,12 +140,6 @@ private:
FGFontCache *fontcache;
// Navigational Aids
FGNavList *navlist;
FGNavList *loclist;
FGNavList *gslist;
FGNavList *dmelist;
FGNavList *tacanlist;
FGNavList *carrierlist;
FGTACANList *channellist;
/// roots of Aircraft trees
@ -163,6 +147,8 @@ private:
bool haveUserSettings;
SGPropertyNode_ptr positionLon, positionLat, positionAlt;
SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
public:
FGGlobals();
@ -261,23 +247,11 @@ public:
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;
SGVec3d get_aircraft_positon_cart() const;
inline FGModelMgr *get_model_mgr () { return model_mgr; }
inline void set_model_mgr (FGModelMgr * mgr)
{
model_mgr = mgr;
}
void get_aircraft_orientation(double& heading, double& pitch, double& roll);
inline string_list *get_channel_options_list () {
return channel_options_list;
@ -302,21 +276,6 @@ public:
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 void set_channellist( FGTACANList *c ) { channellist = c; }

View file

@ -370,12 +370,8 @@ FGViewer::recalcLookFrom ()
{
// Update location data ...
if ( _from_model ) {
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
_position = placement->getPosition();
_heading_deg = placement->getHeadingDeg();
_pitch_deg = placement->getPitchDeg();
_roll_deg = placement->getRollDeg();
_position = globals->get_aircraft_position();
globals->get_aircraft_orientation(_heading_deg, _pitch_deg, _roll_deg);
}
double head = _heading_deg;
@ -419,11 +415,10 @@ FGViewer::recalcLookAt ()
{
// The geodetic position of our target to look at
if ( _at_model ) {
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
_target = placement->getPosition();
_target_heading_deg = placement->getHeadingDeg();
_target_pitch_deg = placement->getPitchDeg();
_target_roll_deg = placement->getRollDeg();
_target = globals->get_aircraft_position();
globals->get_aircraft_orientation(_target_heading_deg,
_target_pitch_deg,
_target_roll_deg);
} else {
// if not model then calculate our own target position...
setDampTarget(_target_roll_deg, _target_pitch_deg, _target_heading_deg);
@ -437,11 +432,8 @@ FGViewer::recalcLookAt ()
if ( _from_model ) {
SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel();
_position = placement->getPosition();
_heading_deg = placement->getHeadingDeg();
_pitch_deg = placement->getPitchDeg();
_roll_deg = placement->getRollDeg();
_position = globals->get_aircraft_position();
globals->get_aircraft_orientation(_heading_deg, _pitch_deg, _roll_deg);
} else {
// update from our own data, just the rotation here...
setDampTarget(_roll_deg, _pitch_deg, _heading_deg);

View file

@ -31,7 +31,6 @@
#include <simgear/compiler.h>
#include <simgear/sound/soundmgr_openal.hxx>
#include <Model/acmodel.hxx>
#include <Main/fg_props.hxx>
#include "viewer.hxx"
@ -181,6 +180,10 @@ FGViewMgr::bind()
void
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
_tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
_tiedProperties.Tie("heading-offset-deg", this,
@ -338,7 +341,9 @@ FGViewMgr::update (double dt)
// get the model velocity
SGVec3d velocity = SGVec3d::zeros();
if ( !stationary() ) {
velocity = globals->get_aircraft_model()->getVelocity();
velocity = SGVec3d( velocityNorthFPS->getDoubleValue(),
velocityEastFPS->getDoubleValue(),
velocityDownFPS->getDoubleValue() );
}
smgr->set_velocity( velocity );
}

View file

@ -150,6 +150,7 @@ private:
SGSoundMgr *smgr;
SGPropertyNode_ptr velocityNorthFPS, velocityEastFPS, velocityDownFPS;
};
// This takes the conventional aviation XYZ body system