#include <simgear/structure/event_mgr.hxx>
#include <Main/main.hxx>
+#include <Main/renderer.hxx>
#include <Main/fg_props.hxx>
#include <FDM/flight.hxx>
#include "Airports/simple.hxx"
#include "gravity.hxx"
-class SGSky;
-extern SGSky *thesky;
-
class FG3DCloudsListener : public SGPropertyChangeListener {
public:
FG3DCloudsListener( FGClouds * fgClouds );
_altitude_n(fgGetNode("/position/altitude-ft", true)),
_longitude_n(fgGetNode( "/position/longitude-deg", true )),
_latitude_n( fgGetNode( "/position/latitude-deg", true )),
- _3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) )
+ _3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) ),
+ _sky(globals->get_renderer()->getSky())
{
set_subsystem("controller", Environment::LayerInterpolateController::createInstance( fgGetNode("/environment/config", true ) ));
set_subsystem("realwx", Environment::RealWxController::createInstance( fgGetNode("/environment/realwx", true ) ), 1.0 );
_tiedProperties.setRoot( fgGetNode( "/environment", true ) );
- _tiedProperties.Tie( "effective-visibility-m", thesky,
+ _tiedProperties.Tie( "effective-visibility-m", _sky,
&SGSky::get_visibility );
_tiedProperties.Tie("rebuild-layers", fgClouds,
_tiedProperties.setRoot( fgGetNode("/sim/rendering", true ) );
- _tiedProperties.Tie( "clouds3d-density", thesky,
+ _tiedProperties.Tie( "clouds3d-density", _sky,
&SGSky::get_3dCloudDensity,
&SGSky::set_3dCloudDensity);
- _tiedProperties.Tie("clouds3d-vis-range", thesky,
+ _tiedProperties.Tie("clouds3d-vis-range", _sky,
&SGSky::get_3dCloudVisRange,
&SGSky::set_3dCloudVisRange);
- _tiedProperties.Tie("clouds3d-wrap", thesky,
+ _tiedProperties.Tie("clouds3d-wrap", _sky,
&SGSky::get_3dCloudWrap,
&SGSky::set_3dCloudWrap);
double
FGEnvironmentMgr::get_cloud_layer_span_m (int index) const
{
- return thesky->get_cloud_layer(index)->getSpan_m();
+ return _sky->get_cloud_layer(index)->getSpan_m();
}
void
FGEnvironmentMgr::set_cloud_layer_span_m (int index, double span_m)
{
- thesky->get_cloud_layer(index)->setSpan_m(span_m);
+ _sky->get_cloud_layer(index)->setSpan_m(span_m);
}
double
FGEnvironmentMgr::get_cloud_layer_elevation_ft (int index) const
{
- return thesky->get_cloud_layer(index)->getElevation_m() * SG_METER_TO_FEET;
+ return _sky->get_cloud_layer(index)->getElevation_m() * SG_METER_TO_FEET;
}
void
FGEnvironment env = *_environment;
env.set_elevation_ft(elevation_ft);
- thesky->get_cloud_layer(index)
+ _sky->get_cloud_layer(index)
->setElevation_m(elevation_ft * SG_FEET_TO_METER);
- thesky->get_cloud_layer(index)
+ _sky->get_cloud_layer(index)
->setSpeed(env.get_wind_speed_kt() * 0.5151); // 1 kt = 0.5151 m/s
- thesky->get_cloud_layer(index)
+ _sky->get_cloud_layer(index)
->setDirection(env.get_wind_from_heading_deg());
}
double
FGEnvironmentMgr::get_cloud_layer_thickness_ft (int index) const
{
- return thesky->get_cloud_layer(index)->getThickness_m() * SG_METER_TO_FEET;
+ return _sky->get_cloud_layer(index)->getThickness_m() * SG_METER_TO_FEET;
}
void
FGEnvironmentMgr::set_cloud_layer_thickness_ft (int index, double thickness_ft)
{
- thesky->get_cloud_layer(index)
+ _sky->get_cloud_layer(index)
->setThickness_m(thickness_ft * SG_FEET_TO_METER);
}
double
FGEnvironmentMgr::get_cloud_layer_transition_ft (int index) const
{
- return thesky->get_cloud_layer(index)->getTransition_m() * SG_METER_TO_FEET;
+ return _sky->get_cloud_layer(index)->getTransition_m() * SG_METER_TO_FEET;
}
void
FGEnvironmentMgr::set_cloud_layer_transition_ft (int index,
double transition_ft)
{
- thesky->get_cloud_layer(index)
+ _sky->get_cloud_layer(index)
->setTransition_m(transition_ft * SG_FEET_TO_METER);
}
const char *
FGEnvironmentMgr::get_cloud_layer_coverage (int index) const
{
- return thesky->get_cloud_layer(index)->getCoverageString().c_str();
+ return _sky->get_cloud_layer(index)->getCoverageString().c_str();
}
void
FGEnvironmentMgr::set_cloud_layer_coverage (int index,
const char * coverage_name)
{
- if( thesky->get_cloud_layer(index)->getCoverageString() == coverage_name )
+ if( _sky->get_cloud_layer(index)->getCoverageString() == coverage_name )
return;
- thesky->get_cloud_layer(index)->setCoverageString(coverage_name);
+ _sky->get_cloud_layer(index)->setCoverageString(coverage_name);
_cloudLayersDirty = true;
}
int
FGEnvironmentMgr::get_cloud_layer_coverage_type (int index) const
{
- return thesky->get_cloud_layer(index)->getCoverage();
+ return _sky->get_cloud_layer(index)->getCoverage();
}
double
FGEnvironmentMgr::get_cloud_layer_visibility_m (int index) const
{
- return thesky->get_cloud_layer(index)->getVisibility_m();
+ return _sky->get_cloud_layer(index)->getVisibility_m();
}
void
FGEnvironmentMgr::set_cloud_layer_visibility_m (int index, double visibility_m)
{
- thesky->get_cloud_layer(index)->setVisibility_m(visibility_m);
+ _sky->get_cloud_layer(index)->setVisibility_m(visibility_m);
}
double
FGEnvironmentMgr::get_cloud_layer_maxalpha (int index ) const
{
- return thesky->get_cloud_layer(index)->getMaxAlpha();
+ return _sky->get_cloud_layer(index)->getMaxAlpha();
}
void
FGEnvironmentMgr::set_cloud_layer_maxalpha (int index, double maxalpha)
{
- thesky->get_cloud_layer(index)->setMaxAlpha(maxalpha);
+ _sky->get_cloud_layer(index)->setMaxAlpha(maxalpha);
}
void
return;
}
- if( static_cast<SGCloudLayer::Coverage>(type) == thesky->get_cloud_layer(index)->getCoverage() )
+ if( static_cast<SGCloudLayer::Coverage>(type) == _sky->get_cloud_layer(index)->getCoverage() )
return;
- thesky->get_cloud_layer(index)->setCoverage(static_cast<SGCloudLayer::Coverage>(type));
+ _sky->get_cloud_layer(index)->setCoverage(static_cast<SGCloudLayer::Coverage>(type));
_cloudLayersDirty = true;
}
class FGMetarFetcher;
class FGClouds;
class FGPrecipitationMgr;
+class SGSky;
/**
* Manage environment information.
SGPropertyNode_ptr _latitude_n;
simgear::TiedPropertyList _tiedProperties;
SGPropertyChangeListener * _3dCloudsEnableListener;
+ SGSky* _sky;
+
};
#endif // _ENVIRONMENT_MGR_HXX
_impl(NULL),
_latProp(NULL)
{
+ SGPath ephem_data_path(globals->get_fg_root());
+ ephem_data_path.append("Astro");
+ _impl = new SGEphemeris(ephem_data_path.c_str());
+ globals->set_ephem(_impl);
}
Ephemeris::~Ephemeris()
void Ephemeris::init()
{
- if (_impl) {
- return;
- }
-
- SGPath ephem_data_path(globals->get_fg_root());
- ephem_data_path.append("Astro");
- _impl = new SGEphemeris(ephem_data_path.c_str());
- globals->set_ephem(_impl);
-
_latProp = fgGetNode("/position/latitude-deg", true);
update(0.0);
}
#include <simgear/props/props_io.hxx>
#include <Main/globals.hxx>
+#include <Main/renderer.hxx>
#include <Airports/simple.hxx>
#include <Main/util.hxx>
#include "fgclouds.hxx"
-extern SGSky *thesky;
-
static bool do_delete_3Dcloud (const SGPropertyNode *arg);
static bool do_move_3Dcloud (const SGPropertyNode *arg);
static bool do_add_3Dcloud (const SGPropertyNode *arg);
int CloudVarietyCount = 0;
double totalCount = 0.0;
+ SGSky* thesky = globals->get_renderer()->getSky();
+
SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false);
SGPropertyNode *box_def_root = fgGetNode("/environment/cloudlayers/boxes", false);
SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false);
double cumulus_base = 122.0 * (temperature_degc - dewpoint_degc);
double stratus_base = 100.0 * (100.0 - rel_humidity) * SG_FEET_TO_METER;
+ SGSky* thesky = globals->get_renderer()->getSky();
for(int iLayer = 0 ; iLayer < thesky->get_cloud_layer_count(); iLayer++) {
SGPropertyNode *cloud_root = fgGetNode("/environment/clouds/layer", iLayer, true);
float x = arg->getFloatValue("x-offset-m", 0.0f);
float y = arg->getFloatValue("y-offset-m", 0.0f);
-
+ SGSky* thesky = globals->get_renderer()->getSky();
SGCloudField *layer = thesky->get_cloud_layer(l)->get_layer3D();
SGNewCloud cld = SGNewCloud(texture_root, arg);
bool success = layer->addCloud(lon, lat, alt, x, y, index, cld.genCloud());
int l = arg->getIntValue("layer", 0);
int i = arg->getIntValue("index", 0);
+ SGSky* thesky = globals->get_renderer()->getSky();
SGCloudField *layer = thesky->get_cloud_layer(l)->get_layer3D();
return layer->deleteCloud(i);
}
{
int l = arg->getIntValue("layer", 0);
int i = arg->getIntValue("index", 0);
-
+ SGSky* thesky = globals->get_renderer()->getSky();
+
float lon = arg->getFloatValue("lon-deg", 0.0f);
float lat = arg->getFloatValue("lat-deg", 0.0f);
float alt = arg->getFloatValue("alt-ft", 0.0f);
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
+#include <Main/renderer.hxx>
#include <Scenery/scenery.hxx>
#include "precipitation_mgr.hxx"
-extern SGSky *thesky;
-
-
/**
* @brief FGPrecipitation Manager constructor
*
max = SGCloudLayer::SG_MAX_CLOUD_COVERAGES;
result = 0;
+ SGSky* thesky = globals->get_renderer()->getSky();
+
// To avoid messing up
if (thesky == NULL)
return result;
#include <Traffic/TrafficMgr.hxx>
#include <MultiPlayer/multiplaymgr.hxx>
#include <FDM/fdm_shell.hxx>
-
+#include <Environment/ephemeris.hxx>
#include <Environment/environment_mgr.hxx>
#include "fg_init.hxx"
// gear, its initialization call should located in this routine.
// Returns non-zero if a problem encountered.
bool fgInitSubsystems() {
- // static const SGPropertyNode *longitude
- // = fgGetNode("/sim/presets/longitude-deg");
- // static const SGPropertyNode *latitude
- // = fgGetNode("/sim/presets/latitude-deg");
- // static const SGPropertyNode *altitude
- // = fgGetNode("/sim/presets/altitude-ft");
SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
// Initialize the weather modeling subsystem
globals->add_subsystem("environment", new FGEnvironmentMgr);
-
+ globals->add_subsystem("ephemeris", new Ephemeris);
+
////////////////////////////////////////////////////////////////////
// Initialize the aircraft systems and instrumentation (before the
// autopilot.)
// sub system infrastructure.
////////////////////////////////////////////////////////////////////
- SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
- globals->set_ATC_mgr(new FGATCMgr);
- globals->get_ATC_mgr()->init();
+ globals->add_subsystem("Old ATC", new FGATCMgr, SGSubsystemMgr::INIT);
////////////////////////////////////////////////////////////////////
// Initialize the ATC subsystem
// Destructor
FGGlobals::~FGGlobals()
-{
- delete renderer;
- renderer = NULL;
-
+{
// The AIModels manager performs a number of actions upon
// Shutdown that implicitly assume that other subsystems
// are still operational (Due to the dynamic allocation and
subsystem_mgr->unbind();
delete subsystem_mgr;
+ delete renderer;
+ renderer = NULL;
+
delete time_params;
delete mag;
delete matlib;
#include <ATCDCL/ATCmgr.hxx>
#include <Time/TimeManager.hxx>
#include <Environment/environment_mgr.hxx>
-#include <Environment/ephemeris.hxx>
#include <GUI/gui.h>
#include <GUI/new_gui.hxx>
#include <MultiPlayer/multiplaymgr.hxx>
// What should we do when we have nothing else to do? Let's get ready
// for the next move and update the display?
-static void fgMainLoop( void ) {
-
- static SGConstPropertyNode_ptr longitude
- = fgGetNode("/position/longitude-deg");
- static SGConstPropertyNode_ptr latitude
- = fgGetNode("/position/latitude-deg");
- static SGConstPropertyNode_ptr altitude
- = fgGetNode("/position/altitude-ft");
- static SGConstPropertyNode_ptr vn_fps
- = fgGetNode("/velocities/speed-north-fps");
- static SGConstPropertyNode_ptr ve_fps
- = fgGetNode("/velocities/speed-east-fps");
- static SGConstPropertyNode_ptr vd_fps
- = fgGetNode("/velocities/speed-down-fps");
-
+static void fgMainLoop( void )
+{
static SGPropertyNode_ptr frame_signal
= fgGetNode("/sim/signals/frame", true);
timeMgr->computeTimeDeltas(sim_dt, real_dt);
// update magvar model
- globals->get_mag()->update( longitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- altitude->getDoubleValue() * SG_FEET_TO_METER,
+ globals->get_mag()->update( globals->get_aircraft_position(),
globals->get_time_params()->getJD() );
- // Run ATC subsystem
- globals->get_ATC_mgr()->update(sim_dt);
-
globals->get_subsystem_mgr()->update(sim_dt);
// Update the sound manager last so it can use the CPU while the GPU
} else if ( idle_state == 6 ) {
idle_state++;
- // Initialize the sky
-
- Ephemeris* eph = new Ephemeris;
- globals->add_subsystem("ephemeris", eph);
- eph->init(); // FIXME - remove this once SGSky code below is also a subsystem
- eph->bind();
-
- // TODO: move to environment mgr
- thesky = new SGSky;
- SGPath texture_path(globals->get_fg_root());
- texture_path.append("Textures");
- texture_path.append("Sky");
- for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
- SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
- thesky->add_cloud_layer(layer);
- }
-
- SGPath sky_tex_path( globals->get_fg_root() );
- sky_tex_path.append( "Textures" );
- sky_tex_path.append( "Sky" );
- thesky->texture_path( sky_tex_path.str() );
-
- // The sun and moon diameters are scaled down numbers of the
- // actual diameters. This was needed to fit both the sun and the
- // moon within the distance to the far clip plane.
- // Moon diameter: 3,476 kilometers
- // Sun diameter: 1,390,000 kilometers
- thesky->build( 80000.0, 80000.0,
- 463.3, 361.8,
- *globals->get_ephem(),
- fgGetNode("/environment", true));
-
+
// Initialize MagVar model
SGMagVar *magvar = new SGMagVar();
globals->set_mag( magvar );
-
-
- // kludge to initialize mag compass
- // (should only be done for in-flight
- // startup)
+
+
+ // kludge to initialize mag compass
+ // (should only be done for in-flight
+ // startup)
// update magvar model
globals->get_mag()->update( fgGetDouble("/position/longitude-deg")
- * SGD_DEGREES_TO_RADIANS,
- fgGetDouble("/position/latitude-deg")
- * SGD_DEGREES_TO_RADIANS,
- fgGetDouble("/position/altitude-ft")
- * SG_FEET_TO_METER,
- globals->get_time_params()->getJD() );
+ * SGD_DEGREES_TO_RADIANS,
+ fgGetDouble("/position/latitude-deg")
+ * SGD_DEGREES_TO_RADIANS,
+ fgGetDouble("/position/altitude-ft")
+ * SG_FEET_TO_METER,
+ globals->get_time_params()->getJD() );
double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var);
fgSetDouble("/instrumentation/heading-indicator-fg/offset-deg", -var);
-
- // airport = new ssgBranch;
- // airport->setName( "Airport Lighting" );
- // lighting->addKid( airport );
-
fgSplashProgress("initializing subsystems");
} else if ( idle_state == 7 ) {
#include <GUI/new_gui.hxx>
#include <Instrumentation/HUD/HUD.hxx>
#include <Environment/precipitation_mgr.hxx>
+#include <Environment/environment_mgr.hxx>
#include "splash.hxx"
#include "renderer.hxx"
bool FGScenerySwitchCallback::scenery_enabled = false;
-// Sky structures
-SGSky *thesky;
-
static osg::ref_ptr<osg::FrameStamp> mFrameStamp = new osg::FrameStamp;
static osg::ref_ptr<SGUpdateVisitor> mUpdateVisitor= new SGUpdateVisitor;
}
#endif
-FGRenderer::FGRenderer()
+FGRenderer::FGRenderer() :
+ _sky(NULL)
{
#ifdef FG_JPEG_SERVER
jpgRenderFrame = updateRenderer;
#ifdef FG_JPEG_SERVER
jpgRenderFrame = NULL;
#endif
+ delete _sky;
}
// Initialize various GL/view parameters
// critical parts of the scene graph in addition to the splash screen.
void
FGRenderer::splashinit( void ) {
- osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
+ osgViewer::Viewer* viewer = getViewer();
mRealRoot = dynamic_cast<osg::Group*>(viewer->getSceneData());
mRealRoot->addChild(fgCreateSplashNode());
mFrameStamp = viewer->getFrameStamp();
SGConfigureDirectionalLights( use_point_sprites, enhanced_lighting,
distance_attenuation );
+
+// create sky, but can't build until setupView, since we depend
+// on other subsystems to be inited, eg Ephemeris
+ _sky = new SGSky;
+
+ SGPath texture_path(globals->get_fg_root());
+ texture_path.append("Textures");
+ texture_path.append("Sky");
+ for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
+ SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
+ _sky->add_cloud_layer(layer);
+ }
+
+ _sky->texture_path( texture_path.str() );
}
void
if ( fgGetBool("/sim/startup/fullscreen") )
fgOSFullScreen();
+// build the sky
+ // The sun and moon diameters are scaled down numbers of the
+ // actual diameters. This was needed to fit both the sun and the
+ // moon within the distance to the far clip plane.
+ // Moon diameter: 3,476 kilometers
+ // Sun diameter: 1,390,000 kilometers
+ _sky->build( 80000.0, 80000.0,
+ 463.3, 361.8,
+ *globals->get_ephem(),
+ fgGetNode("/environment", true));
+
viewer->getCamera()
->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
sunLight->setUpdateCallback(new FGLightSourceUpdateCallback(true));
sunLight->setReferenceFrame(osg::LightSource::RELATIVE_RF);
sunLight->setLocalStateSetModes(osg::StateAttribute::ON);
+
// Hang a StateSet above the sky subgraph in order to turn off
// light 0
Group* skyGroup = new Group;
StateSet* skySS = skyGroup->getOrCreateStateSet();
skySS->setMode(GL_LIGHT0, StateAttribute::OFF);
- skyGroup->addChild(thesky->getPreRoot());
+ skyGroup->addChild(_sky->getPreRoot());
sunLight->addChild(skyGroup);
mRoot->addChild(sceneGroup);
mRoot->addChild(sunLight);
+
// Clouds are added to the scene graph later
stateSet = globals->get_scenery()->get_scene_graph()->getOrCreateStateSet();
stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
// The clouds are attached directly to the scene graph root
// because, in theory, they don't want the same default state set
// as the rest of the scene. This may not be true in practice.
- mRealRoot->addChild(thesky->getCloudRoot());
+ mRealRoot->addChild(_sky->getCloudRoot());
mRealRoot->addChild(FGCreateRedoutNode());
// Attach empty program to the scene root so that shader programs
// don't leak into state sets (effects) that shouldn't have one.
// update fog params
double actual_visibility;
if (_cloud_status->getBoolValue()) {
- actual_visibility = thesky->get_visibility();
+ actual_visibility = _sky->get_visibility();
} else {
actual_visibility = _visibility_m->getDoubleValue();
}
// update fog params if visibility has changed
double visibility_meters = _visibility_m->getDoubleValue();
- thesky->set_visibility(visibility_meters);
+ _sky->set_visibility(visibility_meters);
double altitude_m = _altitude_ft->getDoubleValue() * SG_FEET_TO_METER;
- thesky->modify_vis( altitude_m, 0.0 /* time factor, now unused */);
+ _sky->modify_vis( altitude_m, 0.0 /* time factor, now unused */);
// update the sky dome
if ( skyblend ) {
scolor.moon_angle = l->get_moon_angle();
double delta_time_sec = _sim_delta_sec->getDoubleValue();
- thesky->reposition( sstate, *globals->get_ephem(), delta_time_sec );
- thesky->repaint( scolor, *globals->get_ephem() );
+ _sky->reposition( sstate, *globals->get_ephem(), delta_time_sec );
+ _sky->repaint( scolor, *globals->get_ephem() );
//OSGFIXME
// shadows->setupShadows(
}
class SGSky;
-extern SGSky *thesky;
class FGRenderer {
*/
void addCamera(osg::Camera* camera, bool useSceneData);
+ SGSky* getSky() const { return _sky; }
+
protected:
osg::ref_ptr<osgViewer::Viewer> viewer;
osg::ref_ptr<flightgear::FGEventHandler> eventHandler;
SGPropertyNode_ptr _panel_hotspots, _sim_delta_sec, _horizon_effect, _altitude_ft;
SGPropertyNode_ptr _virtual_cockpit;
SGTimeStamp _splash_time;
+ SGSky* _sky;
};
bool fgDumpSceneGraphToFile(const char* filename);
_scene_ambient[3] = 1.0;
gamma_correct_rgb( _scene_ambient.data() );
+ SGSky* thesky = globals->get_renderer()->getSky();
+
SGVec4f color = thesky->get_scene_color();
_scene_diffuse[0] = color[0] * diffuse;
_scene_diffuse[1] = color[1] * diffuse;
// revert to unmodified values before using them.
//
+ SGSky* thesky = globals->get_renderer()->getSky();
SGVec4f color = thesky->get_scene_color();
gamma_restore_rgb( _fog_color.data(), gamma );