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:
parent
a4a8d08392
commit
c1eca1ff6b
11 changed files with 113 additions and 144 deletions
|
@ -31,6 +31,7 @@
|
|||
#include <simgear/structure/event_mgr.hxx>
|
||||
|
||||
#include <Main/main.hxx>
|
||||
#include <Main/renderer.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
|
||||
|
@ -45,9 +46,6 @@
|
|||
#include "Airports/simple.hxx"
|
||||
#include "gravity.hxx"
|
||||
|
||||
class SGSky;
|
||||
extern SGSky *thesky;
|
||||
|
||||
class FG3DCloudsListener : public SGPropertyChangeListener {
|
||||
public:
|
||||
FG3DCloudsListener( FGClouds * fgClouds );
|
||||
|
@ -91,7 +89,8 @@ FGEnvironmentMgr::FGEnvironmentMgr () :
|
|||
_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 );
|
||||
|
@ -171,7 +170,7 @@ FGEnvironmentMgr::bind ()
|
|||
|
||||
_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,
|
||||
|
@ -220,15 +219,15 @@ FGEnvironmentMgr::bind ()
|
|||
|
||||
_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);
|
||||
|
||||
|
@ -325,19 +324,19 @@ FGEnvironmentMgr::getEnvironment(const SGGeod& aPos) const
|
|||
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
|
||||
|
@ -346,88 +345,88 @@ FGEnvironmentMgr::set_cloud_layer_elevation_ft (int index, double elevation_ft)
|
|||
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
|
||||
|
@ -438,10 +437,10 @@ FGEnvironmentMgr::set_cloud_layer_coverage_type (int index, int type )
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ class FGMetarCtrl;
|
|||
class FGMetarFetcher;
|
||||
class FGClouds;
|
||||
class FGPrecipitationMgr;
|
||||
class SGSky;
|
||||
|
||||
/**
|
||||
* Manage environment information.
|
||||
|
@ -102,6 +103,8 @@ private:
|
|||
SGPropertyNode_ptr _latitude_n;
|
||||
simgear::TiedPropertyList _tiedProperties;
|
||||
SGPropertyChangeListener * _3dCloudsEnableListener;
|
||||
SGSky* _sky;
|
||||
|
||||
};
|
||||
|
||||
#endif // _ENVIRONMENT_MGR_HXX
|
||||
|
|
|
@ -32,6 +32,10 @@ Ephemeris::Ephemeris() :
|
|||
_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()
|
||||
|
@ -41,15 +45,6 @@ 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);
|
||||
}
|
||||
|
|
|
@ -38,13 +38,12 @@
|
|||
#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);
|
||||
|
@ -182,6 +181,8 @@ void FGClouds::buildLayer(int iLayer, const string& name, double coverage) {
|
|||
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);
|
||||
|
@ -274,6 +275,7 @@ void FGClouds::buildCloudLayers(void) {
|
|||
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);
|
||||
|
||||
|
@ -366,7 +368,7 @@ bool FGClouds::get_3dClouds() const
|
|||
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());
|
||||
|
@ -392,6 +394,7 @@ bool FGClouds::get_3dClouds() const
|
|||
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);
|
||||
}
|
||||
|
@ -410,7 +413,8 @@ bool FGClouds::get_3dClouds() const
|
|||
{
|
||||
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);
|
||||
|
|
|
@ -39,13 +39,11 @@
|
|||
|
||||
#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
|
||||
*
|
||||
|
@ -141,6 +139,8 @@ float FGPrecipitationMgr::getPrecipitationAtAltitudeMax(void)
|
|||
max = SGCloudLayer::SG_MAX_CLOUD_COVERAGES;
|
||||
result = 0;
|
||||
|
||||
SGSky* thesky = globals->get_renderer()->getSky();
|
||||
|
||||
// To avoid messing up
|
||||
if (thesky == NULL)
|
||||
return result;
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
#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"
|
||||
|
@ -1176,12 +1176,6 @@ bool fgInitGeneral() {
|
|||
// 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, "========== ==========");
|
||||
|
@ -1239,7 +1233,8 @@ bool fgInitSubsystems() {
|
|||
|
||||
// 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.)
|
||||
|
@ -1287,9 +1282,7 @@ bool fgInitSubsystems() {
|
|||
// 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
|
||||
|
|
|
@ -160,10 +160,7 @@ FGGlobals::FGGlobals() :
|
|||
|
||||
// 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
|
||||
|
@ -180,6 +177,9 @@ FGGlobals::~FGGlobals()
|
|||
subsystem_mgr->unbind();
|
||||
delete subsystem_mgr;
|
||||
|
||||
delete renderer;
|
||||
renderer = NULL;
|
||||
|
||||
delete time_params;
|
||||
delete mag;
|
||||
delete matlib;
|
||||
|
|
|
@ -67,7 +67,6 @@
|
|||
#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>
|
||||
|
@ -104,21 +103,8 @@ extern int _bootstrap_OSInit;
|
|||
|
||||
// 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);
|
||||
|
||||
|
@ -145,16 +131,9 @@ static void fgMainLoop( void ) {
|
|||
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
|
||||
|
@ -410,63 +389,27 @@ static void fgIdleFunction ( void ) {
|
|||
|
||||
} 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 ) {
|
||||
|
|
|
@ -93,6 +93,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"
|
||||
|
@ -374,9 +375,6 @@ public:
|
|||
|
||||
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;
|
||||
|
||||
|
@ -391,7 +389,8 @@ static void updateRenderer()
|
|||
}
|
||||
#endif
|
||||
|
||||
FGRenderer::FGRenderer()
|
||||
FGRenderer::FGRenderer() :
|
||||
_sky(NULL)
|
||||
{
|
||||
#ifdef FG_JPEG_SERVER
|
||||
jpgRenderFrame = updateRenderer;
|
||||
|
@ -404,6 +403,7 @@ FGRenderer::~FGRenderer()
|
|||
#ifdef FG_JPEG_SERVER
|
||||
jpgRenderFrame = NULL;
|
||||
#endif
|
||||
delete _sky;
|
||||
}
|
||||
|
||||
// Initialize various GL/view parameters
|
||||
|
@ -411,7 +411,7 @@ FGRenderer::~FGRenderer()
|
|||
// 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();
|
||||
|
@ -454,6 +454,20 @@ FGRenderer::init( void )
|
|||
|
||||
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
|
||||
|
@ -472,6 +486,17 @@ FGRenderer::setupView( 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);
|
||||
|
||||
|
@ -547,15 +572,17 @@ FGRenderer::setupView( void )
|
|||
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);
|
||||
|
@ -594,7 +621,7 @@ FGRenderer::setupView( void )
|
|||
// 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.
|
||||
|
@ -644,7 +671,7 @@ FGRenderer::update( ) {
|
|||
// 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();
|
||||
}
|
||||
|
@ -673,10 +700,10 @@ FGRenderer::update( ) {
|
|||
|
||||
// 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 ) {
|
||||
|
@ -720,8 +747,8 @@ FGRenderer::update( ) {
|
|||
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(
|
||||
|
|
|
@ -35,7 +35,6 @@ class FGEventHandler;
|
|||
}
|
||||
|
||||
class SGSky;
|
||||
extern SGSky *thesky;
|
||||
|
||||
class FGRenderer {
|
||||
|
||||
|
@ -73,6 +72,8 @@ public:
|
|||
*/
|
||||
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;
|
||||
|
@ -85,6 +86,7 @@ protected:
|
|||
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);
|
||||
|
|
|
@ -290,6 +290,8 @@ void FGLight::update_sky_color () {
|
|||
_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;
|
||||
|
@ -361,6 +363,7 @@ void FGLight::update_adj_fog_color () {
|
|||
|
||||
// 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 );
|
||||
|
|
Loading…
Reference in a new issue