From: david Date: Fri, 22 Feb 2002 22:51:34 +0000 (+0000) Subject: Added FGEnvironmentMgr to provide information on the environment in X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=eaf9fa762180182c4af7a877f4e6865726dd8e5f;p=flightgear.git Added FGEnvironmentMgr to provide information on the environment in different locations, and hitched it into FGGlobals. FGEnvironmentMgr has taken over as the subsystem, while FGEnvironment is simple the information that it returns. I've removed current_environment completely -- everything now uses properties or goes through FGGlobals. FGGlobals itself has a couple of useful methods: const FGEnvironment * get_environment (); const FGEnvironment * get_environment (double lat, double lon, double alt); The first one returns the environment data for the plane's current position, while the second returns the environment data for any arbitrary location. Currently, they both return the same information, but that will change soon. --- diff --git a/src/Environment/Makefile.am b/src/Environment/Makefile.am index 2c9f44b2f..7b01218f6 100644 --- a/src/Environment/Makefile.am +++ b/src/Environment/Makefile.am @@ -4,7 +4,8 @@ noinst_LIBRARIES = libEnvironment.a -libEnvironment_a_SOURCES = environment.cxx environment.hxx +libEnvironment_a_SOURCES = environment.cxx environment.hxx \ + environment_mgr.cxx environment_mgr.hxx if OLD_AUTOMAKE INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Environment/environment.cxx b/src/Environment/environment.cxx index 6fd317a74..59a26ec11 100644 --- a/src/Environment/environment.cxx +++ b/src/Environment/environment.cxx @@ -29,32 +29,21 @@ # include #endif -#include -#include - #include #include -#include #include
-#include #include "environment.hxx" -// This is a record containing current environment info -FGEnvironment current_environment; - - FGEnvironment::FGEnvironment() : visibility_m(32000), wind_from_heading_deg(0), wind_speed_kt(0), wind_from_north_fps(0), wind_from_east_fps(0), - wind_from_down_fps(0), - fog_exp_density(0), - fog_exp2_density(0) + wind_from_down_fps(0) { } @@ -64,78 +53,10 @@ FGEnvironment::~FGEnvironment() } -// Initialize the environment modeling subsystem -void FGEnvironment::init () -{ - SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem"); -} - - -void -FGEnvironment::bind () -{ - fgTie("/environment/visibility-m", this, - &FGEnvironment::get_visibility_m, &FGEnvironment::set_visibility_m); - fgSetArchivable("/environment/visibility-m"); - fgTie("/environment/wind-from-heading-deg", this, - &FGEnvironment::get_wind_from_heading_deg, - &FGEnvironment::set_wind_from_heading_deg); - fgTie("/environment/wind-speed-kt", this, - &FGEnvironment::get_wind_speed_kt, &FGEnvironment::set_wind_speed_kt); - fgTie("/environment/wind-from-north-fps", this, - &FGEnvironment::get_wind_from_north_fps, - &FGEnvironment::set_wind_from_north_fps); - fgSetArchivable("/environment/wind-from-north-fps"); - fgTie("/environment/wind-from-east-fps", this, - &FGEnvironment::get_wind_from_east_fps, - &FGEnvironment::set_wind_from_east_fps); - fgSetArchivable("/environment/wind-from-east-fps"); - fgTie("/environment/wind-from-down-fps", this, - &FGEnvironment::get_wind_from_down_fps, - &FGEnvironment::set_wind_from_down_fps); - fgSetArchivable("/environment/wind-from-down-fps"); -} - -void -FGEnvironment::unbind () -{ - fgUntie("/environment/visibility-m"); - fgUntie("/environment/wind-from-heading-deg"); - fgUntie("/environment/wind-speed-kt"); - fgUntie("/environment/wind-from-north-fps"); - fgUntie("/environment/wind-from-east-fps"); - fgUntie("/environment/wind-from-down-fps"); -} - -void FGEnvironment::update (int dt) -{ - // FIXME: the FDMs should update themselves - current_aircraft.fdm_state - ->set_Velocities_Local_Airmass(wind_from_north_fps, - wind_from_east_fps, - wind_from_down_fps); -} - void FGEnvironment::set_visibility_m (double v) { - glMatrixMode(GL_MODELVIEW); - // in meters - visibility_m = v; - - // for GL_FOG_EXP - fog_exp_density = -log(0.01 / visibility_m); - - // for GL_FOG_EXP2 - fog_exp2_density = sqrt( -log(0.01) ) / visibility_m; - - // Set correct opengl fog density - glFogf (GL_FOG_DENSITY, fog_exp2_density); - glFogi( GL_FOG_MODE, GL_EXP2 ); - - // SG_LOG( SG_INPUT, SG_DEBUG, "Fog density = " << fog_density ); - // SG_LOG( SG_INPUT, SG_INFO, - // "Fog exp2 density = " << fog_exp2_density ); + visibility_m = v; } void diff --git a/src/Environment/environment.hxx b/src/Environment/environment.hxx index f485c16f9..0b29970aa 100644 --- a/src/Environment/environment.hxx +++ b/src/Environment/environment.hxx @@ -26,8 +26,6 @@ #include -#include - #include
#ifdef SG_HAVE_STD_INCLUDES @@ -45,7 +43,7 @@ * * This class should eventually move to SimGear. */ -class FGEnvironment : public FGSubsystem +class FGEnvironment { public: @@ -53,11 +51,6 @@ public: FGEnvironment(); virtual ~FGEnvironment(); - virtual void init (); - virtual void bind (); - virtual void unbind (); - virtual void update (int dt); - inline virtual double get_visibility_m () const { return visibility_m; } inline virtual double get_wind_from_heading_deg () const { return wind_from_heading_deg; @@ -95,12 +88,11 @@ private: double wind_from_down_fps; // Do these belong here? +#if 0 GLfloat fog_exp_density; GLfloat fog_exp2_density; +#endif }; -// FIXME: move to FGGlobals. -extern FGEnvironment current_environment; - #endif // _ENVIRONMENT_HXX diff --git a/src/Environment/environment_mgr.cxx b/src/Environment/environment_mgr.cxx new file mode 100644 index 000000000..9840d6de2 --- /dev/null +++ b/src/Environment/environment_mgr.cxx @@ -0,0 +1,108 @@ +// environment-mgr.cxx -- manager for natural environment information. +// +// Written by David Megginson, started February 2002. +// +// Copyright (C) 2002 David Megginson - david@megginson.com +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + +#include + +#include
+#include + +#include "environment_mgr.hxx" + + +FGEnvironmentMgr::FGEnvironmentMgr () +{ + _environment = new FGEnvironment(); +} + +FGEnvironmentMgr::~FGEnvironmentMgr () +{ + delete _environment; +} + +void +FGEnvironmentMgr::init () +{ + SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem"); +} + +void +FGEnvironmentMgr::bind () +{ + fgTie("/environment/visibility-m", _environment, + &FGEnvironment::get_visibility_m, &FGEnvironment::set_visibility_m); + fgSetArchivable("/environment/visibility-m"); + fgTie("/environment/wind-from-heading-deg", _environment, + &FGEnvironment::get_wind_from_heading_deg, + &FGEnvironment::set_wind_from_heading_deg); + fgTie("/environment/wind-speed-kt", _environment, + &FGEnvironment::get_wind_speed_kt, &FGEnvironment::set_wind_speed_kt); + fgTie("/environment/wind-from-north-fps", _environment, + &FGEnvironment::get_wind_from_north_fps, + &FGEnvironment::set_wind_from_north_fps); + fgSetArchivable("/environment/wind-from-north-fps"); + fgTie("/environment/wind-from-east-fps", _environment, + &FGEnvironment::get_wind_from_east_fps, + &FGEnvironment::set_wind_from_east_fps); + fgSetArchivable("/environment/wind-from-east-fps"); + fgTie("/environment/wind-from-down-fps", _environment, + &FGEnvironment::get_wind_from_down_fps, + &FGEnvironment::set_wind_from_down_fps); + fgSetArchivable("/environment/wind-from-down-fps"); +} + +void +FGEnvironmentMgr::unbind () +{ + fgUntie("/environment/visibility-m"); + fgUntie("/environment/wind-from-heading-deg"); + fgUntie("/environment/wind-speed-kt"); + fgUntie("/environment/wind-from-north-fps"); + fgUntie("/environment/wind-from-east-fps"); + fgUntie("/environment/wind-from-down-fps"); +} + +void +FGEnvironmentMgr::update (int dt) +{ + // FIXME: the FDMs should update themselves + current_aircraft.fdm_state + ->set_Velocities_Local_Airmass(_environment->get_wind_from_north_fps(), + _environment->get_wind_from_east_fps(), + _environment->get_wind_from_down_fps()); +} + +const FGEnvironment * +FGEnvironmentMgr::getEnvironment () const +{ + return _environment; +} + +const FGEnvironment * +FGEnvironmentMgr::getEnvironment (double lat, double lon, double alt) const +{ + // Always returns the same environment + // for now; we'll make it interesting + // later. + return _environment; +} + +// end of environment-mgr.cxx diff --git a/src/Environment/environment_mgr.hxx b/src/Environment/environment_mgr.hxx new file mode 100644 index 000000000..3238c9bf9 --- /dev/null +++ b/src/Environment/environment_mgr.hxx @@ -0,0 +1,73 @@ +// environment-mgr.hxx -- manager for natural environment information. +// +// Written by David Megginson, started February 2002. +// +// Copyright (C) 2002 David Megginson - david@megginson.com +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + +#ifndef _ENVIRONMENT_MGR_HXX +#define _ENVIRONMENT_MGR_HXX + +#include + +#include
+ +#ifdef SG_HAVE_STD_INCLUDES +# include +#else +# include +#endif + +#include "environment.hxx" + + +/** + * Manage environment information. + */ +class FGEnvironmentMgr : public FGSubsystem +{ + +public: + + FGEnvironmentMgr (); + virtual ~FGEnvironmentMgr (); + + virtual void init (); + virtual void bind (); + virtual void unbind (); + virtual void update (int dt); + + /** + * Get the environment information for the plane's current position. + */ + virtual const FGEnvironment * getEnvironment () const; + + + /** + * Get the environment information for another location. + */ + virtual const FGEnvironment * getEnvironment (double lat, double lon, + double alt) const; + +private: + + FGEnvironment * _environment; // always the same, for now + +}; + +#endif // _ENVIRONMENT_MGR_HXX diff --git a/src/FDM/UIUCModel/uiuc_wrapper.cpp b/src/FDM/UIUCModel/uiuc_wrapper.cpp index e8308a402..1fa2b40e6 100644 --- a/src/FDM/UIUCModel/uiuc_wrapper.cpp +++ b/src/FDM/UIUCModel/uiuc_wrapper.cpp @@ -74,12 +74,7 @@ #include #include #include - -#ifndef FG_NEW_ENVIRONMENT -#include -#else -#include -#endif +#include
#include "uiuc_aircraft.h" #include "uiuc_aircraftdir.h" @@ -222,21 +217,12 @@ void uiuc_force_moment(double dt) double vis; if (Fog != 0) { - #ifndef FG_NEW_ENVIRONMENT - vis = WeatherDatabase->getWeatherVisibility(); - if (Fog > 0) - vis /= 1.01; - else - vis *= 1.01; - WeatherDatabase->setWeatherVisibility( vis ); - #else - vis = current_environment.get_visibility_m(); + vis = fgGetDouble("/environment/visibility-m"); if (Fog > 0) vis /= 1.01; else vis *= 1.01; - current_environment.set_visibility_m( vis ); - #endif + fgSetDouble("/environment/visibility-m", vis); } diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index f12755289..787e9869e 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -832,8 +832,8 @@ bool fgInitSubsystems( void ) { global_events.Register( "weather update", fgUpdateWeatherDatabase, fgEVENT::FG_EVENT_READY, 30000); #else - current_environment.init(); - current_environment.bind(); + globals->get_environment_mgr()->init(); + globals->get_environment_mgr()->bind(); #endif //////////////////////////////////////////////////////////////////// diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 2b15a3bda..b2e100109 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -42,8 +42,12 @@ SG_USING_STD( string ); typedef vector string_list; +#include + // Forward declarations +class FGEnvironmentMgr; +class FGEnvironment; class FGControls; class FGSoundMgr; class FGFX; @@ -96,6 +100,9 @@ private: // sound-effects manager FGFX *fx; + // environment information + FGEnvironmentMgr * environment_mgr; + // control input state FGControls *controls; @@ -155,6 +162,20 @@ public: inline SGRoute *get_route() const { return route; } inline void set_route( SGRoute *r ) { route = r; } + inline FGEnvironmentMgr * get_environment_mgr() { + return environment_mgr; + } + inline void set_environment_mgr(FGEnvironmentMgr * mgr) { + environment_mgr = mgr; + } + inline const FGEnvironment * get_environment() const { + return environment_mgr->getEnvironment(); + } + inline const FGEnvironment * get_environment(double lat, double lon, + double alt) const { + return environment_mgr->getEnvironment(lat, lon, alt); + } + inline FGSoundMgr *get_soundmgr() const { return soundmgr; } inline void set_soundmgr( FGSoundMgr *sm ) { soundmgr = sm; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 82b5ecfc2..697e0e730 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -139,7 +139,7 @@ sgVec3 rway_ols; #ifndef FG_NEW_ENVIRONMENT # include #else -# include +# include #endif #include "version.h" @@ -553,11 +553,7 @@ void fgRenderFrame( void ) { default_state->force(); // update fog params if visibility has changed -#ifndef FG_NEW_ENVIRONMENT - thesky->set_visibility( WeatherDatabase->getWeatherVisibility() ); -#else - thesky->set_visibility( current_environment.get_visibility_m() ); -#endif + thesky->set_visibility(fgGetDouble("/environment/visibility-m")); thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, ( global_multi_loop * fgGetInt("/sim/speed-up") ) @@ -673,9 +669,6 @@ void fgRenderFrame( void ) { double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER - scenery.get_cur_elev(); - // SG_LOG( SG_ALL, SG_INFO, "visibility is " - // << current_environment.get_visibility() ); - if ( agl > 10.0 ) { ssgSetNearFar( 10.0f, 120000.0f ); } else { @@ -1043,7 +1036,7 @@ static void fgMainLoop( void ) { #endif #ifdef FG_NEW_ENVIRONMENT - current_environment.update(0); // FIXME: use real delta time + globals->get_environment_mgr()->update(0); // FIXME: use real delta time #endif // Fix elevation. I'm just sticking this here for now, it should @@ -1457,6 +1450,8 @@ int mainLoop( int argc, char **argv ) { globals = new FGGlobals; + globals->set_environment_mgr(new FGEnvironmentMgr); + // seed the random number generater sg_srandom_time(); diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index b2cae1215..6d6d4f045 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -41,6 +41,7 @@ #include #include
+#include
#include
#include @@ -169,16 +170,7 @@ void FGTileMgr::schedule_needed() { SG_LOG( SG_TERRAIN, SG_INFO, "scheduling needed tiles for " << longitude << " " << latitude ); -#ifndef FG_NEW_ENVIRONMENT - if ( WeatherDatabase != NULL ) { - vis = WeatherDatabase->getWeatherVisibility(); - } else { - vis = 16000; - } -#else - vis = current_environment.get_visibility_m(); -#endif - // cout << "visibility = " << vis << endl; + vis = fgGetDouble("/environment/visibility-m"); double tile_width = current_bucket.get_width_m(); double tile_height = current_bucket.get_height_m(); @@ -439,16 +431,7 @@ int FGTileMgr::update( double lon, double lat ) { void FGTileMgr::prep_ssg_nodes() { float vis = 0.0; -#ifndef FG_NEW_ENVIRONMENT - if ( WeatherDatabase ) { - vis = WeatherDatabase->getWeatherVisibility(); - } else { - vis = 16000; - } -#else - vis = current_environment.get_visibility_m(); -#endif - // cout << "visibility = " << vis << endl; + vis = fgGetDouble("/environment/visibility-m"); // traverse the potentially viewable tile list and update range // selector and transform