]> git.mxchange.org Git - flightgear.git/commitdiff
Added FGEnvironmentMgr to provide information on the environment in
authordavid <david>
Fri, 22 Feb 2002 22:51:34 +0000 (22:51 +0000)
committerdavid <david>
Fri, 22 Feb 2002 22:51:34 +0000 (22:51 +0000)
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.

src/Environment/Makefile.am
src/Environment/environment.cxx
src/Environment/environment.hxx
src/Environment/environment_mgr.cxx [new file with mode: 0644]
src/Environment/environment_mgr.hxx [new file with mode: 0644]
src/FDM/UIUCModel/uiuc_wrapper.cpp
src/Main/fg_init.cxx
src/Main/globals.hxx
src/Main/main.cxx
src/Scenery/tilemgr.cxx

index 2c9f44b2f5f0cf1f9cf4ae60f7a51d9447e5cb71..7b01218f62fda664a2d127779592f9f64fe2ecb0 100644 (file)
@@ -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
index 6fd317a744cf74bf8230a217c0b6c480b7425358..59a26ec11aa6247b13f2c71384816777f7b1122f 100644 (file)
 #  include <windows.h>                     
 #endif
 
-#include <GL/glut.h>
-#include <GL/gl.h>
-
 #include <math.h>
 
 #include <simgear/debug/logstream.hxx>
-#include <simgear/math/sg_random.h>
 
 #include <Main/fg_props.hxx>
-#include <Aircraft/aircraft.hxx>
 #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
index f485c16f96317f21a1f6482c1357afb0893dc2da..0b29970aa7a8cf8ba00ccf1b249c2f06fd22a14f 100644 (file)
@@ -26,8 +26,6 @@
 
 #include <simgear/compiler.h>
 
-#include <GL/gl.h>
-
 #include <Main/fgfs.hxx>
 
 #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 (file)
index 0000000..9840d6d
--- /dev/null
@@ -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 <simgear/debug/logstream.hxx>
+
+#include <Main/fg_props.hxx>
+#include <Aircraft/aircraft.hxx>
+
+#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 (file)
index 0000000..3238c9b
--- /dev/null
@@ -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 <simgear/compiler.h>
+
+#include <Main/fgfs.hxx>
+
+#ifdef SG_HAVE_STD_INCLUDES
+#  include <cmath>
+#else
+#  include <math.h>
+#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
index e8308a4028870a64a6ee3c156579c7aefacb78ef..1fa2b40e62e6673770160c2f481abe5275e4a2e5 100644 (file)
 #include <simgear/compiler.h>
 #include <simgear/misc/sg_path.hxx>
 #include <Aircraft/aircraft.hxx>
-
-#ifndef FG_NEW_ENVIRONMENT
-#include <WeatherCM/FGLocalWeatherDatabase.h>
-#else
-#include <Environment/environment.hxx>
-#endif
+#include <Main/fg_props.hxx>
 
 #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);
    }
  
 
index f12755289841ef145dc185eaa9099abaf3b577fe..787e9869ec1d8a1b9b03764ac314171a1cf0786b 100644 (file)
@@ -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
 
     ////////////////////////////////////////////////////////////////////
index 2b15a3bda172fc84ede34179a3ea1432b1eac86f..b2e1001091ec08a1daa7801b28c38592937ea6a1 100644 (file)
@@ -42,8 +42,12 @@ SG_USING_STD( string );
 
 typedef vector<string> string_list;
 
+#include <Environment/environment_mgr.hxx>
+
 
 // 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; }
 
index 82b5ecfc21ab860ae75d468b7add2628ab750c64..697e0e7306594fa49932f4edfb1ea08193e3eb61 100644 (file)
@@ -139,7 +139,7 @@ sgVec3 rway_ols;
 #ifndef FG_NEW_ENVIRONMENT
 #  include <WeatherCM/FGLocalWeatherDatabase.h>
 #else
-#  include <Environment/environment.hxx>
+#  include <Environment/environment_mgr.hxx>
 #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();
 
index b2cae1215aff9102b03b187b4ff885c6050fbbca..6d6d4f045d6e1c4bbc5add9539dc31b544e47574 100644 (file)
@@ -41,6 +41,7 @@
 #include <simgear/math/vector.hxx>
 
 #include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
 #include <Main/viewer.hxx>
 #include <Objects/obj.hxx>
 
@@ -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