1999-08-10 03:40:34 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
|
|
|
Header: FGLocalWeatherDatabase.h
|
|
|
|
Author: Christian Mayer
|
|
|
|
Date started: 28.05.99
|
|
|
|
|
1999-10-20 22:19:07 +00:00
|
|
|
-------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
|
1999-08-10 03:40:34 +00:00
|
|
|
|
|
|
|
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., 59 Temple
|
|
|
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
Further information about the GNU General Public License can also be found on
|
|
|
|
the world wide web at http://www.gnu.org.
|
|
|
|
|
|
|
|
FUNCTIONAL DESCRIPTION
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
Database for the local weather
|
|
|
|
This database is the only one that gets called from FG
|
|
|
|
|
|
|
|
HISTORY
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
28.05.1999 Christian Mayer Created
|
|
|
|
16.06.1999 Durk Talsma Portability for Linux
|
|
|
|
20.06.1999 Christian Mayer added lots of consts
|
|
|
|
30.06.1999 Christian Mayer STL portability
|
1999-10-14 20:30:54 +00:00
|
|
|
11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
|
|
|
|
suggestion
|
1999-10-20 22:19:07 +00:00
|
|
|
19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
|
|
|
|
and lots of wee code cleaning
|
1999-12-23 16:54:54 +00:00
|
|
|
14.12.1999 Christian Mayer Changed the internal structure to use Dave
|
|
|
|
Eberly's spherical interpolation code. This
|
|
|
|
stops our dependancy on the (ugly) voronoi
|
|
|
|
code and simplyfies the code structure a lot.
|
1999-08-10 03:40:34 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* SENTRY */
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifndef FGLocalWeatherDatabase_H
|
|
|
|
#define FGLocalWeatherDatabase_H
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* INCLUDES */
|
|
|
|
/****************************************************************************/
|
1999-10-12 03:30:24 +00:00
|
|
|
#include <vector>
|
2000-07-06 22:13:24 +00:00
|
|
|
#include STL_STRING
|
1999-10-20 22:19:07 +00:00
|
|
|
|
2000-02-04 22:50:04 +00:00
|
|
|
#include <plib/sg.h>
|
1999-12-23 16:54:54 +00:00
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
#include "sphrintp.h"
|
1999-10-12 03:30:24 +00:00
|
|
|
|
1999-08-10 03:40:34 +00:00
|
|
|
#include "FGPhysicalProperties.h"
|
1999-12-23 16:54:54 +00:00
|
|
|
#include "FGPhysicalProperty.h"
|
|
|
|
|
|
|
|
|
1999-08-10 03:40:34 +00:00
|
|
|
#include "FGWeatherFeature.h"
|
|
|
|
#include "FGWeatherDefs.h"
|
1999-11-03 18:06:52 +00:00
|
|
|
#include "FGThunderstorm.h"
|
1999-08-10 03:40:34 +00:00
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* DEFINES */
|
|
|
|
/****************************************************************************/
|
|
|
|
FG_USING_STD(vector);
|
2000-07-06 22:13:24 +00:00
|
|
|
FG_USING_STD(string);
|
1999-08-10 03:40:34 +00:00
|
|
|
FG_USING_NAMESPACE(std);
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* CLASS DECLARATION */
|
|
|
|
/****************************************************************************/
|
|
|
|
class FGLocalWeatherDatabase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
protected:
|
1999-12-23 16:54:54 +00:00
|
|
|
SphereInterpolate<FGPhysicalProperties> *database;
|
1999-08-10 03:40:34 +00:00
|
|
|
|
1999-10-20 22:19:07 +00:00
|
|
|
typedef vector<sgVec2> pointVector;
|
1999-08-10 03:40:34 +00:00
|
|
|
typedef vector<pointVector> tileVector;
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* make tiles out of points on a 2D plane */
|
|
|
|
/************************************************************************/
|
1999-10-20 22:19:07 +00:00
|
|
|
WeatherPrecision WeatherVisibility; //how far do I need to simulate the
|
1999-08-10 03:40:34 +00:00
|
|
|
//local weather? Unit: metres
|
1999-10-20 22:19:07 +00:00
|
|
|
sgVec3 last_known_position;
|
|
|
|
|
1999-11-03 18:06:52 +00:00
|
|
|
bool Thunderstorm; //is there a thunderstorm near by?
|
|
|
|
FGThunderstorm *theThunderstorm; //pointer to the thunderstorm.
|
1999-10-20 22:19:07 +00:00
|
|
|
|
1999-08-10 03:40:34 +00:00
|
|
|
public:
|
|
|
|
static FGLocalWeatherDatabase *theFGLocalWeatherDatabase;
|
|
|
|
|
|
|
|
enum DatabaseWorkingType {
|
1999-12-23 16:54:54 +00:00
|
|
|
use_global, //use global database for data !!obsolete!!
|
1999-11-03 18:06:52 +00:00
|
|
|
use_internet, //use the weather data that came from the internet
|
1999-08-10 03:40:34 +00:00
|
|
|
manual, //use only user inputs
|
|
|
|
distant, //use distant information, e.g. like LAN when used in
|
|
|
|
//a multiplayer environment
|
|
|
|
random, //generate weather randomly
|
|
|
|
default_mode //use only default values
|
|
|
|
};
|
|
|
|
|
|
|
|
DatabaseWorkingType DatabaseStatus;
|
|
|
|
|
2000-07-06 22:13:24 +00:00
|
|
|
void init( const WeatherPrecision visibility,
|
|
|
|
const DatabaseWorkingType type,
|
|
|
|
const string& root );
|
1999-11-03 18:06:52 +00:00
|
|
|
|
1999-08-10 03:40:34 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* Constructor and Destructor */
|
|
|
|
/************************************************************************/
|
|
|
|
FGLocalWeatherDatabase(
|
1999-10-21 22:53:12 +00:00
|
|
|
const sgVec3& position,
|
2000-07-06 22:13:24 +00:00
|
|
|
const string& root,
|
1999-10-21 22:53:12 +00:00
|
|
|
const WeatherPrecision visibility = DEFAULT_WEATHER_VISIBILITY,
|
1999-11-03 18:06:52 +00:00
|
|
|
const DatabaseWorkingType type = PREFERED_WORKING_TYPE)
|
|
|
|
{
|
|
|
|
sgCopyVec3( last_known_position, position );
|
|
|
|
|
2000-07-06 22:13:24 +00:00
|
|
|
init( visibility, type, root );
|
1999-11-03 18:06:52 +00:00
|
|
|
|
|
|
|
theFGLocalWeatherDatabase = this;
|
|
|
|
}
|
1999-10-20 22:19:07 +00:00
|
|
|
|
|
|
|
FGLocalWeatherDatabase(
|
1999-10-21 22:53:12 +00:00
|
|
|
const WeatherPrecision position_lat,
|
|
|
|
const WeatherPrecision position_lon,
|
|
|
|
const WeatherPrecision position_alt,
|
2000-07-06 22:13:24 +00:00
|
|
|
const string& root,
|
1999-10-21 22:53:12 +00:00
|
|
|
const WeatherPrecision visibility = DEFAULT_WEATHER_VISIBILITY,
|
1999-10-20 22:19:07 +00:00
|
|
|
const DatabaseWorkingType type = PREFERED_WORKING_TYPE)
|
|
|
|
{
|
1999-11-03 18:06:52 +00:00
|
|
|
sgSetVec3( last_known_position, position_lat, position_lon, position_alt );
|
1999-10-21 22:53:12 +00:00
|
|
|
|
2000-07-06 22:13:24 +00:00
|
|
|
init( visibility, type, root );
|
1999-10-20 22:19:07 +00:00
|
|
|
|
1999-11-03 18:06:52 +00:00
|
|
|
theFGLocalWeatherDatabase = this;
|
1999-10-20 22:19:07 +00:00
|
|
|
}
|
|
|
|
|
1999-08-10 03:40:34 +00:00
|
|
|
~FGLocalWeatherDatabase();
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* reset the whole database */
|
|
|
|
/************************************************************************/
|
1999-10-20 22:19:07 +00:00
|
|
|
void reset(const DatabaseWorkingType type = PREFERED_WORKING_TYPE);
|
1999-08-10 03:40:34 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* update the database. Since the last call we had dt seconds */
|
|
|
|
/************************************************************************/
|
1999-10-20 22:19:07 +00:00
|
|
|
void update(const WeatherPrecision dt); //time has changed
|
|
|
|
void update(const sgVec3& p); //position has changed
|
|
|
|
void update(const sgVec3& p, const WeatherPrecision dt); //time and/or position has changed
|
1999-08-10 03:40:34 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Get the physical properties on the specified point p */
|
|
|
|
/************************************************************************/
|
2000-02-10 23:37:56 +00:00
|
|
|
#ifdef MACOS
|
|
|
|
/* fix a problem with mw compilers in that they don't know the
|
|
|
|
difference between the next two methods. Since the first one
|
|
|
|
doesn't seem to be used anywhere, I commented it out. This is
|
|
|
|
supposed to be fixed in the forthcoming CodeWarrior Release
|
|
|
|
6. */
|
|
|
|
#else
|
1999-10-14 20:30:54 +00:00
|
|
|
FGPhysicalProperties get(const sgVec2& p) const;
|
2000-02-10 23:37:56 +00:00
|
|
|
#endif
|
1999-10-20 22:19:07 +00:00
|
|
|
FGPhysicalProperty get(const sgVec3& p) const;
|
1999-10-12 03:30:24 +00:00
|
|
|
|
1999-10-20 22:19:07 +00:00
|
|
|
WeatherPrecision getAirDensity(const sgVec3& p) const;
|
1999-08-10 03:40:34 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Add a weather feature at the point p and surrounding area */
|
|
|
|
/************************************************************************/
|
1999-12-23 16:54:54 +00:00
|
|
|
// !! Adds aren't supported anymore !!
|
1999-08-10 03:40:34 +00:00
|
|
|
|
1999-10-20 22:19:07 +00:00
|
|
|
void setSnowRainIntensity (const WeatherPrecision x, const sgVec2& p);
|
|
|
|
void setSnowRainType (const SnowRainType x, const sgVec2& p);
|
|
|
|
void setLightningProbability(const WeatherPrecision x, const sgVec2& p);
|
1999-08-10 03:40:34 +00:00
|
|
|
|
|
|
|
void setProperties(const FGPhysicalProperties2D& x); //change a property
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* get/set weather visibility */
|
|
|
|
/************************************************************************/
|
1999-10-20 22:19:07 +00:00
|
|
|
void setWeatherVisibility(const WeatherPrecision visibility);
|
|
|
|
WeatherPrecision getWeatherVisibility(void) const;
|
1999-11-03 18:06:52 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* figure out if there's a thunderstorm that has to be taken care of */
|
|
|
|
/************************************************************************/
|
|
|
|
void updateThunderstorm(const float dt)
|
|
|
|
{
|
|
|
|
if (Thunderstorm == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
theThunderstorm->update( dt );
|
|
|
|
}
|
1999-08-10 03:40:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern FGLocalWeatherDatabase *WeatherDatabase;
|
|
|
|
void fgUpdateWeatherDatabase(void);
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* get/set weather visibility */
|
|
|
|
/****************************************************************************/
|
1999-10-20 22:19:07 +00:00
|
|
|
void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecision visibility)
|
1999-08-10 03:40:34 +00:00
|
|
|
{
|
1999-10-21 22:53:12 +00:00
|
|
|
if (visibility >= MINIMUM_WEATHER_VISIBILITY)
|
1999-08-10 03:40:34 +00:00
|
|
|
WeatherVisibility = visibility;
|
|
|
|
else
|
1999-10-21 22:53:12 +00:00
|
|
|
WeatherVisibility = MINIMUM_WEATHER_VISIBILITY;
|
1999-08-10 03:40:34 +00:00
|
|
|
}
|
|
|
|
|
1999-10-20 22:19:07 +00:00
|
|
|
WeatherPrecision inline FGLocalWeatherDatabase::getWeatherVisibility(void) const
|
1999-08-10 03:40:34 +00:00
|
|
|
{
|
|
|
|
return WeatherVisibility;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
#endif /*FGLocalWeatherDatabase_H*/
|