1
0
Fork 0

Refactor SGSky handling and ownership - sink into Renderer, remove global variable 'the sky', and hence clean up main loop and subsystem creation a little more.

This commit is contained in:
James Turner 2011-11-05 13:18:36 +00:00
parent a4a8d08392
commit c1eca1ff6b
11 changed files with 113 additions and 144 deletions

View file

@ -31,6 +31,7 @@
#include <simgear/structure/event_mgr.hxx> #include <simgear/structure/event_mgr.hxx>
#include <Main/main.hxx> #include <Main/main.hxx>
#include <Main/renderer.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <FDM/flight.hxx> #include <FDM/flight.hxx>
@ -45,9 +46,6 @@
#include "Airports/simple.hxx" #include "Airports/simple.hxx"
#include "gravity.hxx" #include "gravity.hxx"
class SGSky;
extern SGSky *thesky;
class FG3DCloudsListener : public SGPropertyChangeListener { class FG3DCloudsListener : public SGPropertyChangeListener {
public: public:
FG3DCloudsListener( FGClouds * fgClouds ); FG3DCloudsListener( FGClouds * fgClouds );
@ -91,7 +89,8 @@ 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 )),
_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("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 );
@ -171,7 +170,7 @@ FGEnvironmentMgr::bind ()
_tiedProperties.setRoot( fgGetNode( "/environment", true ) ); _tiedProperties.setRoot( fgGetNode( "/environment", true ) );
_tiedProperties.Tie( "effective-visibility-m", thesky, _tiedProperties.Tie( "effective-visibility-m", _sky,
&SGSky::get_visibility ); &SGSky::get_visibility );
_tiedProperties.Tie("rebuild-layers", fgClouds, _tiedProperties.Tie("rebuild-layers", fgClouds,
@ -220,15 +219,15 @@ FGEnvironmentMgr::bind ()
_tiedProperties.setRoot( fgGetNode("/sim/rendering", true ) ); _tiedProperties.setRoot( fgGetNode("/sim/rendering", true ) );
_tiedProperties.Tie( "clouds3d-density", thesky, _tiedProperties.Tie( "clouds3d-density", _sky,
&SGSky::get_3dCloudDensity, &SGSky::get_3dCloudDensity,
&SGSky::set_3dCloudDensity); &SGSky::set_3dCloudDensity);
_tiedProperties.Tie("clouds3d-vis-range", thesky, _tiedProperties.Tie("clouds3d-vis-range", _sky,
&SGSky::get_3dCloudVisRange, &SGSky::get_3dCloudVisRange,
&SGSky::set_3dCloudVisRange); &SGSky::set_3dCloudVisRange);
_tiedProperties.Tie("clouds3d-wrap", thesky, _tiedProperties.Tie("clouds3d-wrap", _sky,
&SGSky::get_3dCloudWrap, &SGSky::get_3dCloudWrap,
&SGSky::set_3dCloudWrap); &SGSky::set_3dCloudWrap);
@ -325,19 +324,19 @@ FGEnvironmentMgr::getEnvironment(const SGGeod& aPos) const
double double
FGEnvironmentMgr::get_cloud_layer_span_m (int index) const 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 void
FGEnvironmentMgr::set_cloud_layer_span_m (int index, double span_m) 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 double
FGEnvironmentMgr::get_cloud_layer_elevation_ft (int index) const 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 void
@ -346,88 +345,88 @@ FGEnvironmentMgr::set_cloud_layer_elevation_ft (int index, double elevation_ft)
FGEnvironment env = *_environment; FGEnvironment env = *_environment;
env.set_elevation_ft(elevation_ft); env.set_elevation_ft(elevation_ft);
thesky->get_cloud_layer(index) _sky->get_cloud_layer(index)
->setElevation_m(elevation_ft * SG_FEET_TO_METER); ->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 ->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()); ->setDirection(env.get_wind_from_heading_deg());
} }
double double
FGEnvironmentMgr::get_cloud_layer_thickness_ft (int index) const 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 void
FGEnvironmentMgr::set_cloud_layer_thickness_ft (int index, double thickness_ft) 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); ->setThickness_m(thickness_ft * SG_FEET_TO_METER);
} }
double double
FGEnvironmentMgr::get_cloud_layer_transition_ft (int index) const 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 void
FGEnvironmentMgr::set_cloud_layer_transition_ft (int index, FGEnvironmentMgr::set_cloud_layer_transition_ft (int index,
double transition_ft) double transition_ft)
{ {
thesky->get_cloud_layer(index) _sky->get_cloud_layer(index)
->setTransition_m(transition_ft * SG_FEET_TO_METER); ->setTransition_m(transition_ft * SG_FEET_TO_METER);
} }
const char * const char *
FGEnvironmentMgr::get_cloud_layer_coverage (int index) const 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 void
FGEnvironmentMgr::set_cloud_layer_coverage (int index, FGEnvironmentMgr::set_cloud_layer_coverage (int index,
const char * coverage_name) const char * coverage_name)
{ {
if( thesky->get_cloud_layer(index)->getCoverageString() == coverage_name ) if( _sky->get_cloud_layer(index)->getCoverageString() == coverage_name )
return; return;
thesky->get_cloud_layer(index)->setCoverageString(coverage_name); _sky->get_cloud_layer(index)->setCoverageString(coverage_name);
_cloudLayersDirty = true; _cloudLayersDirty = true;
} }
int int
FGEnvironmentMgr::get_cloud_layer_coverage_type (int index) const FGEnvironmentMgr::get_cloud_layer_coverage_type (int index) const
{ {
return thesky->get_cloud_layer(index)->getCoverage(); return _sky->get_cloud_layer(index)->getCoverage();
} }
double double
FGEnvironmentMgr::get_cloud_layer_visibility_m (int index) const 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 void
FGEnvironmentMgr::set_cloud_layer_visibility_m (int index, double visibility_m) 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 double
FGEnvironmentMgr::get_cloud_layer_maxalpha (int index ) const FGEnvironmentMgr::get_cloud_layer_maxalpha (int index ) const
{ {
return thesky->get_cloud_layer(index)->getMaxAlpha(); return _sky->get_cloud_layer(index)->getMaxAlpha();
} }
void void
FGEnvironmentMgr::set_cloud_layer_maxalpha (int index, double maxalpha) FGEnvironmentMgr::set_cloud_layer_maxalpha (int index, double maxalpha)
{ {
thesky->get_cloud_layer(index)->setMaxAlpha(maxalpha); _sky->get_cloud_layer(index)->setMaxAlpha(maxalpha);
} }
void void
@ -438,10 +437,10 @@ FGEnvironmentMgr::set_cloud_layer_coverage_type (int index, int type )
return; 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; 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; _cloudLayersDirty = true;
} }

View file

@ -38,6 +38,7 @@ class FGMetarCtrl;
class FGMetarFetcher; class FGMetarFetcher;
class FGClouds; class FGClouds;
class FGPrecipitationMgr; class FGPrecipitationMgr;
class SGSky;
/** /**
* Manage environment information. * Manage environment information.
@ -102,6 +103,8 @@ private:
SGPropertyNode_ptr _latitude_n; SGPropertyNode_ptr _latitude_n;
simgear::TiedPropertyList _tiedProperties; simgear::TiedPropertyList _tiedProperties;
SGPropertyChangeListener * _3dCloudsEnableListener; SGPropertyChangeListener * _3dCloudsEnableListener;
SGSky* _sky;
}; };
#endif // _ENVIRONMENT_MGR_HXX #endif // _ENVIRONMENT_MGR_HXX

View file

@ -32,6 +32,10 @@ Ephemeris::Ephemeris() :
_impl(NULL), _impl(NULL),
_latProp(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() Ephemeris::~Ephemeris()
@ -41,15 +45,6 @@ Ephemeris::~Ephemeris()
void Ephemeris::init() 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); _latProp = fgGetNode("/position/latitude-deg", true);
update(0.0); update(0.0);
} }

View file

@ -38,13 +38,12 @@
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/renderer.hxx>
#include <Airports/simple.hxx> #include <Airports/simple.hxx>
#include <Main/util.hxx> #include <Main/util.hxx>
#include "fgclouds.hxx" #include "fgclouds.hxx"
extern SGSky *thesky;
static bool do_delete_3Dcloud (const SGPropertyNode *arg); static bool do_delete_3Dcloud (const SGPropertyNode *arg);
static bool do_move_3Dcloud (const SGPropertyNode *arg); static bool do_move_3Dcloud (const SGPropertyNode *arg);
static bool do_add_3Dcloud (const SGPropertyNode *arg); static bool do_add_3Dcloud (const SGPropertyNode *arg);
@ -182,6 +181,8 @@ void FGClouds::buildLayer(int iLayer, const string& name, double coverage) {
int CloudVarietyCount = 0; int CloudVarietyCount = 0;
double totalCount = 0.0; double totalCount = 0.0;
SGSky* thesky = globals->get_renderer()->getSky();
SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false); SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false);
SGPropertyNode *box_def_root = fgGetNode("/environment/cloudlayers/boxes", false); SGPropertyNode *box_def_root = fgGetNode("/environment/cloudlayers/boxes", false);
SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false); SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false);
@ -274,6 +275,7 @@ void FGClouds::buildCloudLayers(void) {
double cumulus_base = 122.0 * (temperature_degc - dewpoint_degc); double cumulus_base = 122.0 * (temperature_degc - dewpoint_degc);
double stratus_base = 100.0 * (100.0 - rel_humidity) * SG_FEET_TO_METER; 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++) { for(int iLayer = 0 ; iLayer < thesky->get_cloud_layer_count(); iLayer++) {
SGPropertyNode *cloud_root = fgGetNode("/environment/clouds/layer", iLayer, true); SGPropertyNode *cloud_root = fgGetNode("/environment/clouds/layer", iLayer, true);
@ -366,7 +368,7 @@ bool FGClouds::get_3dClouds() const
float x = arg->getFloatValue("x-offset-m", 0.0f); float x = arg->getFloatValue("x-offset-m", 0.0f);
float y = arg->getFloatValue("y-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(); SGCloudField *layer = thesky->get_cloud_layer(l)->get_layer3D();
SGNewCloud cld = SGNewCloud(texture_root, arg); SGNewCloud cld = SGNewCloud(texture_root, arg);
bool success = layer->addCloud(lon, lat, alt, x, y, index, cld.genCloud()); bool success = layer->addCloud(lon, lat, alt, x, y, index, cld.genCloud());
@ -392,6 +394,7 @@ bool FGClouds::get_3dClouds() const
int l = arg->getIntValue("layer", 0); int l = arg->getIntValue("layer", 0);
int i = arg->getIntValue("index", 0); int i = arg->getIntValue("index", 0);
SGSky* thesky = globals->get_renderer()->getSky();
SGCloudField *layer = thesky->get_cloud_layer(l)->get_layer3D(); SGCloudField *layer = thesky->get_cloud_layer(l)->get_layer3D();
return layer->deleteCloud(i); return layer->deleteCloud(i);
} }
@ -410,6 +413,7 @@ bool FGClouds::get_3dClouds() const
{ {
int l = arg->getIntValue("layer", 0); int l = arg->getIntValue("layer", 0);
int i = arg->getIntValue("index", 0); int i = arg->getIntValue("index", 0);
SGSky* thesky = globals->get_renderer()->getSky();
float lon = arg->getFloatValue("lon-deg", 0.0f); float lon = arg->getFloatValue("lon-deg", 0.0f);
float lat = arg->getFloatValue("lat-deg", 0.0f); float lat = arg->getFloatValue("lat-deg", 0.0f);

View file

@ -39,13 +39,11 @@
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/renderer.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include "precipitation_mgr.hxx" #include "precipitation_mgr.hxx"
extern SGSky *thesky;
/** /**
* @brief FGPrecipitation Manager constructor * @brief FGPrecipitation Manager constructor
* *
@ -141,6 +139,8 @@ float FGPrecipitationMgr::getPrecipitationAtAltitudeMax(void)
max = SGCloudLayer::SG_MAX_CLOUD_COVERAGES; max = SGCloudLayer::SG_MAX_CLOUD_COVERAGES;
result = 0; result = 0;
SGSky* thesky = globals->get_renderer()->getSky();
// To avoid messing up // To avoid messing up
if (thesky == NULL) if (thesky == NULL)
return result; return result;

View file

@ -106,7 +106,7 @@
#include <Traffic/TrafficMgr.hxx> #include <Traffic/TrafficMgr.hxx>
#include <MultiPlayer/multiplaymgr.hxx> #include <MultiPlayer/multiplaymgr.hxx>
#include <FDM/fdm_shell.hxx> #include <FDM/fdm_shell.hxx>
#include <Environment/ephemeris.hxx>
#include <Environment/environment_mgr.hxx> #include <Environment/environment_mgr.hxx>
#include "fg_init.hxx" #include "fg_init.hxx"
@ -1176,12 +1176,6 @@ bool fgInitGeneral() {
// gear, its initialization call should located in this routine. // gear, its initialization call should located in this routine.
// Returns non-zero if a problem encountered. // Returns non-zero if a problem encountered.
bool fgInitSubsystems() { 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 Subsystems");
SG_LOG( SG_GENERAL, SG_INFO, "========== =========="); SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
@ -1239,6 +1233,7 @@ bool fgInitSubsystems() {
// Initialize the weather modeling subsystem // Initialize the weather modeling subsystem
globals->add_subsystem("environment", new FGEnvironmentMgr); globals->add_subsystem("environment", new FGEnvironmentMgr);
globals->add_subsystem("ephemeris", new Ephemeris);
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Initialize the aircraft systems and instrumentation (before the // Initialize the aircraft systems and instrumentation (before the
@ -1287,9 +1282,7 @@ bool fgInitSubsystems() {
// sub system infrastructure. // sub system infrastructure.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager"); globals->add_subsystem("Old ATC", new FGATCMgr, SGSubsystemMgr::INIT);
globals->set_ATC_mgr(new FGATCMgr);
globals->get_ATC_mgr()->init();
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Initialize the ATC subsystem // Initialize the ATC subsystem

View file

@ -161,9 +161,6 @@ FGGlobals::FGGlobals() :
// Destructor // Destructor
FGGlobals::~FGGlobals() FGGlobals::~FGGlobals()
{ {
delete renderer;
renderer = NULL;
// The AIModels manager performs a number of actions upon // The AIModels manager performs a number of actions upon
// Shutdown that implicitly assume that other subsystems // Shutdown that implicitly assume that other subsystems
// are still operational (Due to the dynamic allocation and // are still operational (Due to the dynamic allocation and
@ -180,6 +177,9 @@ FGGlobals::~FGGlobals()
subsystem_mgr->unbind(); subsystem_mgr->unbind();
delete subsystem_mgr; delete subsystem_mgr;
delete renderer;
renderer = NULL;
delete time_params; delete time_params;
delete mag; delete mag;
delete matlib; delete matlib;

View file

@ -67,7 +67,6 @@
#include <ATCDCL/ATCmgr.hxx> #include <ATCDCL/ATCmgr.hxx>
#include <Time/TimeManager.hxx> #include <Time/TimeManager.hxx>
#include <Environment/environment_mgr.hxx> #include <Environment/environment_mgr.hxx>
#include <Environment/ephemeris.hxx>
#include <GUI/gui.h> #include <GUI/gui.h>
#include <GUI/new_gui.hxx> #include <GUI/new_gui.hxx>
#include <MultiPlayer/multiplaymgr.hxx> #include <MultiPlayer/multiplaymgr.hxx>
@ -104,21 +103,8 @@ extern int _bootstrap_OSInit;
// What should we do when we have nothing else to do? Let's get ready // What should we do when we have nothing else to do? Let's get ready
// for the next move and update the display? // for the next move and update the display?
static void fgMainLoop( void ) { 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 SGPropertyNode_ptr frame_signal static SGPropertyNode_ptr frame_signal
= fgGetNode("/sim/signals/frame", true); = fgGetNode("/sim/signals/frame", true);
@ -145,16 +131,9 @@ static void fgMainLoop( void ) {
timeMgr->computeTimeDeltas(sim_dt, real_dt); timeMgr->computeTimeDeltas(sim_dt, real_dt);
// update magvar model // update magvar model
globals->get_mag()->update( longitude->getDoubleValue() globals->get_mag()->update( globals->get_aircraft_position(),
* SGD_DEGREES_TO_RADIANS,
latitude->getDoubleValue()
* SGD_DEGREES_TO_RADIANS,
altitude->getDoubleValue() * SG_FEET_TO_METER,
globals->get_time_params()->getJD() ); globals->get_time_params()->getJD() );
// Run ATC subsystem
globals->get_ATC_mgr()->update(sim_dt);
globals->get_subsystem_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 // Update the sound manager last so it can use the CPU while the GPU
@ -410,63 +389,27 @@ static void fgIdleFunction ( void ) {
} else if ( idle_state == 6 ) { } else if ( idle_state == 6 ) {
idle_state++; 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 // Initialize MagVar model
SGMagVar *magvar = new SGMagVar(); SGMagVar *magvar = new SGMagVar();
globals->set_mag( magvar ); globals->set_mag( magvar );
// kludge to initialize mag compass // kludge to initialize mag compass
// (should only be done for in-flight // (should only be done for in-flight
// startup) // startup)
// update magvar model // update magvar model
globals->get_mag()->update( fgGetDouble("/position/longitude-deg") globals->get_mag()->update( fgGetDouble("/position/longitude-deg")
* SGD_DEGREES_TO_RADIANS, * SGD_DEGREES_TO_RADIANS,
fgGetDouble("/position/latitude-deg") fgGetDouble("/position/latitude-deg")
* SGD_DEGREES_TO_RADIANS, * SGD_DEGREES_TO_RADIANS,
fgGetDouble("/position/altitude-ft") fgGetDouble("/position/altitude-ft")
* SG_FEET_TO_METER, * SG_FEET_TO_METER,
globals->get_time_params()->getJD() ); globals->get_time_params()->getJD() );
double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES; double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var); fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var);
fgSetDouble("/instrumentation/heading-indicator-fg/offset-deg", -var); fgSetDouble("/instrumentation/heading-indicator-fg/offset-deg", -var);
// airport = new ssgBranch;
// airport->setName( "Airport Lighting" );
// lighting->addKid( airport );
fgSplashProgress("initializing subsystems"); fgSplashProgress("initializing subsystems");
} else if ( idle_state == 7 ) { } else if ( idle_state == 7 ) {

View file

@ -93,6 +93,7 @@
#include <GUI/new_gui.hxx> #include <GUI/new_gui.hxx>
#include <Instrumentation/HUD/HUD.hxx> #include <Instrumentation/HUD/HUD.hxx>
#include <Environment/precipitation_mgr.hxx> #include <Environment/precipitation_mgr.hxx>
#include <Environment/environment_mgr.hxx>
#include "splash.hxx" #include "splash.hxx"
#include "renderer.hxx" #include "renderer.hxx"
@ -374,9 +375,6 @@ public:
bool FGScenerySwitchCallback::scenery_enabled = false; bool FGScenerySwitchCallback::scenery_enabled = false;
// Sky structures
SGSky *thesky;
static osg::ref_ptr<osg::FrameStamp> mFrameStamp = new osg::FrameStamp; static osg::ref_ptr<osg::FrameStamp> mFrameStamp = new osg::FrameStamp;
static osg::ref_ptr<SGUpdateVisitor> mUpdateVisitor= new SGUpdateVisitor; static osg::ref_ptr<SGUpdateVisitor> mUpdateVisitor= new SGUpdateVisitor;
@ -391,7 +389,8 @@ static void updateRenderer()
} }
#endif #endif
FGRenderer::FGRenderer() FGRenderer::FGRenderer() :
_sky(NULL)
{ {
#ifdef FG_JPEG_SERVER #ifdef FG_JPEG_SERVER
jpgRenderFrame = updateRenderer; jpgRenderFrame = updateRenderer;
@ -404,6 +403,7 @@ FGRenderer::~FGRenderer()
#ifdef FG_JPEG_SERVER #ifdef FG_JPEG_SERVER
jpgRenderFrame = NULL; jpgRenderFrame = NULL;
#endif #endif
delete _sky;
} }
// Initialize various GL/view parameters // Initialize various GL/view parameters
@ -411,7 +411,7 @@ FGRenderer::~FGRenderer()
// critical parts of the scene graph in addition to the splash screen. // critical parts of the scene graph in addition to the splash screen.
void void
FGRenderer::splashinit( void ) { FGRenderer::splashinit( void ) {
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer(); osgViewer::Viewer* viewer = getViewer();
mRealRoot = dynamic_cast<osg::Group*>(viewer->getSceneData()); mRealRoot = dynamic_cast<osg::Group*>(viewer->getSceneData());
mRealRoot->addChild(fgCreateSplashNode()); mRealRoot->addChild(fgCreateSplashNode());
mFrameStamp = viewer->getFrameStamp(); mFrameStamp = viewer->getFrameStamp();
@ -454,6 +454,20 @@ FGRenderer::init( void )
SGConfigureDirectionalLights( use_point_sprites, enhanced_lighting, SGConfigureDirectionalLights( use_point_sprites, enhanced_lighting,
distance_attenuation ); 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 void
@ -472,6 +486,17 @@ FGRenderer::setupView( void )
if ( fgGetBool("/sim/startup/fullscreen") ) if ( fgGetBool("/sim/startup/fullscreen") )
fgOSFullScreen(); 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() viewer->getCamera()
->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); ->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
@ -547,15 +572,17 @@ FGRenderer::setupView( void )
sunLight->setUpdateCallback(new FGLightSourceUpdateCallback(true)); sunLight->setUpdateCallback(new FGLightSourceUpdateCallback(true));
sunLight->setReferenceFrame(osg::LightSource::RELATIVE_RF); sunLight->setReferenceFrame(osg::LightSource::RELATIVE_RF);
sunLight->setLocalStateSetModes(osg::StateAttribute::ON); sunLight->setLocalStateSetModes(osg::StateAttribute::ON);
// Hang a StateSet above the sky subgraph in order to turn off // Hang a StateSet above the sky subgraph in order to turn off
// light 0 // light 0
Group* skyGroup = new Group; Group* skyGroup = new Group;
StateSet* skySS = skyGroup->getOrCreateStateSet(); StateSet* skySS = skyGroup->getOrCreateStateSet();
skySS->setMode(GL_LIGHT0, StateAttribute::OFF); skySS->setMode(GL_LIGHT0, StateAttribute::OFF);
skyGroup->addChild(thesky->getPreRoot()); skyGroup->addChild(_sky->getPreRoot());
sunLight->addChild(skyGroup); sunLight->addChild(skyGroup);
mRoot->addChild(sceneGroup); mRoot->addChild(sceneGroup);
mRoot->addChild(sunLight); mRoot->addChild(sunLight);
// Clouds are added to the scene graph later // Clouds are added to the scene graph later
stateSet = globals->get_scenery()->get_scene_graph()->getOrCreateStateSet(); stateSet = globals->get_scenery()->get_scene_graph()->getOrCreateStateSet();
stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON); stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
@ -594,7 +621,7 @@ FGRenderer::setupView( void )
// The clouds are attached directly to the scene graph root // The clouds are attached directly to the scene graph root
// because, in theory, they don't want the same default state set // 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. // as the rest of the scene. This may not be true in practice.
mRealRoot->addChild(thesky->getCloudRoot()); mRealRoot->addChild(_sky->getCloudRoot());
mRealRoot->addChild(FGCreateRedoutNode()); mRealRoot->addChild(FGCreateRedoutNode());
// Attach empty program to the scene root so that shader programs // Attach empty program to the scene root so that shader programs
// don't leak into state sets (effects) that shouldn't have one. // don't leak into state sets (effects) that shouldn't have one.
@ -644,7 +671,7 @@ FGRenderer::update( ) {
// update fog params // update fog params
double actual_visibility; double actual_visibility;
if (_cloud_status->getBoolValue()) { if (_cloud_status->getBoolValue()) {
actual_visibility = thesky->get_visibility(); actual_visibility = _sky->get_visibility();
} else { } else {
actual_visibility = _visibility_m->getDoubleValue(); actual_visibility = _visibility_m->getDoubleValue();
} }
@ -673,10 +700,10 @@ FGRenderer::update( ) {
// update fog params if visibility has changed // update fog params if visibility has changed
double visibility_meters = _visibility_m->getDoubleValue(); 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; 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 // update the sky dome
if ( skyblend ) { if ( skyblend ) {
@ -720,8 +747,8 @@ FGRenderer::update( ) {
scolor.moon_angle = l->get_moon_angle(); scolor.moon_angle = l->get_moon_angle();
double delta_time_sec = _sim_delta_sec->getDoubleValue(); double delta_time_sec = _sim_delta_sec->getDoubleValue();
thesky->reposition( sstate, *globals->get_ephem(), delta_time_sec ); _sky->reposition( sstate, *globals->get_ephem(), delta_time_sec );
thesky->repaint( scolor, *globals->get_ephem() ); _sky->repaint( scolor, *globals->get_ephem() );
//OSGFIXME //OSGFIXME
// shadows->setupShadows( // shadows->setupShadows(

View file

@ -35,7 +35,6 @@ class FGEventHandler;
} }
class SGSky; class SGSky;
extern SGSky *thesky;
class FGRenderer { class FGRenderer {
@ -73,6 +72,8 @@ public:
*/ */
void addCamera(osg::Camera* camera, bool useSceneData); void addCamera(osg::Camera* camera, bool useSceneData);
SGSky* getSky() const { return _sky; }
protected: protected:
osg::ref_ptr<osgViewer::Viewer> viewer; osg::ref_ptr<osgViewer::Viewer> viewer;
osg::ref_ptr<flightgear::FGEventHandler> eventHandler; osg::ref_ptr<flightgear::FGEventHandler> eventHandler;
@ -85,6 +86,7 @@ protected:
SGPropertyNode_ptr _panel_hotspots, _sim_delta_sec, _horizon_effect, _altitude_ft; SGPropertyNode_ptr _panel_hotspots, _sim_delta_sec, _horizon_effect, _altitude_ft;
SGPropertyNode_ptr _virtual_cockpit; SGPropertyNode_ptr _virtual_cockpit;
SGTimeStamp _splash_time; SGTimeStamp _splash_time;
SGSky* _sky;
}; };
bool fgDumpSceneGraphToFile(const char* filename); bool fgDumpSceneGraphToFile(const char* filename);

View file

@ -290,6 +290,8 @@ void FGLight::update_sky_color () {
_scene_ambient[3] = 1.0; _scene_ambient[3] = 1.0;
gamma_correct_rgb( _scene_ambient.data() ); gamma_correct_rgb( _scene_ambient.data() );
SGSky* thesky = globals->get_renderer()->getSky();
SGVec4f color = thesky->get_scene_color(); SGVec4f color = thesky->get_scene_color();
_scene_diffuse[0] = color[0] * diffuse; _scene_diffuse[0] = color[0] * diffuse;
_scene_diffuse[1] = color[1] * diffuse; _scene_diffuse[1] = color[1] * diffuse;
@ -361,6 +363,7 @@ void FGLight::update_adj_fog_color () {
// revert to unmodified values before using them. // revert to unmodified values before using them.
// //
SGSky* thesky = globals->get_renderer()->getSky();
SGVec4f color = thesky->get_scene_color(); SGVec4f color = thesky->get_scene_color();
gamma_restore_rgb( _fog_color.data(), gamma ); gamma_restore_rgb( _fog_color.data(), gamma );