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
# 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)
{
}
}
-// 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
#include <simgear/compiler.h>
-#include <GL/gl.h>
-
#include <Main/fgfs.hxx>
#ifdef SG_HAVE_STD_INCLUDES
*
* This class should eventually move to SimGear.
*/
-class FGEnvironment : public FGSubsystem
+class FGEnvironment
{
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;
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
--- /dev/null
+// 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
--- /dev/null
+// 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
#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"
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);
}
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
////////////////////////////////////////////////////////////////////
typedef vector<string> string_list;
+#include <Environment/environment_mgr.hxx>
+
// Forward declarations
+class FGEnvironmentMgr;
+class FGEnvironment;
class FGControls;
class FGSoundMgr;
class FGFX;
// sound-effects manager
FGFX *fx;
+ // environment information
+ FGEnvironmentMgr * environment_mgr;
+
// control input state
FGControls *controls;
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; }
#ifndef FG_NEW_ENVIRONMENT
# include <WeatherCM/FGLocalWeatherDatabase.h>
#else
-# include <Environment/environment.hxx>
+# include <Environment/environment_mgr.hxx>
#endif
#include "version.h"
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") )
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 {
#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
globals = new FGGlobals;
+ globals->set_environment_mgr(new FGEnvironmentMgr);
+
// seed the random number generater
sg_srandom_time();
#include <simgear/math/vector.hxx>
#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include <Main/viewer.hxx>
#include <Objects/obj.hxx>
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();
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