]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGLocalWeatherDatabase.h
817ea34b7b6985469dbd3daaf6c9194969d84808
[flightgear.git] / src / WeatherCM / FGLocalWeatherDatabase.h
1 /*****************************************************************************
2
3  Header:       FGLocalWeatherDatabase.h 
4  Author:       Christian Mayer
5  Date started: 28.05.99
6
7  -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Database for the local weather
29 This database is the only one that gets called from FG
30
31 HISTORY
32 ------------------------------------------------------------------------------
33 28.05.1999 Christian Mayer      Created
34 16.06.1999 Durk Talsma          Portability for Linux
35 20.06.1999 Christian Mayer      added lots of consts
36 30.06.1999 Christian Mayer      STL portability
37 11.10.1999 Christian Mayer      changed set<> to map<> on Bernie Bright's 
38                                 suggestion
39 19.10.1999 Christian Mayer      change to use PLIB's sg instead of Point[2/3]D
40                                 and lots of wee code cleaning
41 14.12.1999 Christian Mayer      Changed the internal structure to use Dave
42                                 Eberly's spherical interpolation code. This
43                                 stops our dependancy on the (ugly) voronoi
44                                 code and simplyfies the code structure a lot.
45 *****************************************************************************/
46
47 /****************************************************************************/
48 /* SENTRY                                                                   */
49 /****************************************************************************/
50 #ifndef FGLocalWeatherDatabase_H
51 #define FGLocalWeatherDatabase_H
52
53 /****************************************************************************/
54 /* INCLUDES                                                                 */
55 /****************************************************************************/
56 #include <vector>
57
58 #include <sg.h>
59
60 #include <Math/sphrintp.h>
61
62 #include "FGPhysicalProperties.h"
63 #include "FGPhysicalProperty.h"
64
65
66 #include "FGWeatherFeature.h"
67 #include "FGWeatherDefs.h"
68 #include "FGThunderstorm.h"
69
70 /****************************************************************************/
71 /* DEFINES                                                                  */
72 /****************************************************************************/
73 FG_USING_STD(vector);
74 FG_USING_NAMESPACE(std);
75
76 /****************************************************************************/
77 /* CLASS DECLARATION                                                        */
78 /****************************************************************************/
79 class FGLocalWeatherDatabase
80 {
81 private:
82 protected:
83     SphereInterpolate<FGPhysicalProperties> *database;
84
85     typedef vector<sgVec2>      pointVector;
86     typedef vector<pointVector> tileVector;
87
88     /************************************************************************/
89     /* make tiles out of points on a 2D plane                               */
90     /************************************************************************/
91     WeatherPrecision WeatherVisibility; //how far do I need to simulate the
92                                         //local weather? Unit: metres
93     sgVec3 last_known_position;
94
95     bool Thunderstorm;                  //is there a thunderstorm near by?
96     FGThunderstorm *theThunderstorm;    //pointer to the thunderstorm.
97
98 public:
99     static FGLocalWeatherDatabase *theFGLocalWeatherDatabase;  
100     
101     enum DatabaseWorkingType {
102         use_global,     //use global database for data !!obsolete!!
103         use_internet,   //use the weather data that came from the internet
104         manual,         //use only user inputs
105         distant,        //use distant information, e.g. like LAN when used in
106                         //a multiplayer environment
107         random,         //generate weather randomly
108         default_mode    //use only default values
109     };
110
111     DatabaseWorkingType DatabaseStatus;
112
113     void init( const WeatherPrecision visibility, const DatabaseWorkingType type );
114
115     /************************************************************************/
116     /* Constructor and Destructor                                           */
117     /************************************************************************/
118     FGLocalWeatherDatabase(
119         const sgVec3&             position,
120         const WeatherPrecision    visibility = DEFAULT_WEATHER_VISIBILITY,
121         const DatabaseWorkingType type       = PREFERED_WORKING_TYPE)
122     {
123         sgCopyVec3( last_known_position, position );
124
125         init( visibility, type );
126
127         theFGLocalWeatherDatabase = this;
128     }
129
130     FGLocalWeatherDatabase(
131         const WeatherPrecision    position_lat,
132         const WeatherPrecision    position_lon,
133         const WeatherPrecision    position_alt,
134         const WeatherPrecision    visibility = DEFAULT_WEATHER_VISIBILITY,
135         const DatabaseWorkingType type       = PREFERED_WORKING_TYPE)
136     {
137         sgSetVec3( last_known_position, position_lat, position_lon, position_alt );
138
139         init( visibility, type );
140
141         theFGLocalWeatherDatabase = this;
142     }
143
144     ~FGLocalWeatherDatabase();
145
146     /************************************************************************/
147     /* reset the whole database                                             */
148     /************************************************************************/
149     void reset(const DatabaseWorkingType type = PREFERED_WORKING_TYPE);
150
151     /************************************************************************/
152     /* update the database. Since the last call we had dt seconds           */
153     /************************************************************************/
154     void update(const WeatherPrecision dt);                     //time has changed
155     void update(const sgVec3& p);                               //position has  changed
156     void update(const sgVec3& p, const WeatherPrecision dt);    //time and/or position has changed
157
158     /************************************************************************/
159     /* Get the physical properties on the specified point p                 */
160     /************************************************************************/
161     FGPhysicalProperties get(const sgVec2& p) const;
162     FGPhysicalProperty   get(const sgVec3& p) const;
163
164     WeatherPrecision     getAirDensity(const sgVec3& p) const;
165     
166     /************************************************************************/
167     /* Add a weather feature at the point p and surrounding area            */
168     /************************************************************************/
169     // !! Adds aren't supported anymore !!
170
171     void setSnowRainIntensity   (const WeatherPrecision x, const sgVec2& p);
172     void setSnowRainType        (const SnowRainType x,     const sgVec2& p);
173     void setLightningProbability(const WeatherPrecision x, const sgVec2& p);
174
175     void setProperties(const FGPhysicalProperties2D& x);    //change a property
176
177     /************************************************************************/
178     /* get/set weather visibility                                           */
179     /************************************************************************/
180     void             setWeatherVisibility(const WeatherPrecision visibility);
181     WeatherPrecision getWeatherVisibility(void) const;
182
183     /************************************************************************/
184     /* figure out if there's a thunderstorm that has to be taken care of    */
185     /************************************************************************/
186     void updateThunderstorm(const float dt)
187     {
188         if (Thunderstorm == false)
189             return;
190
191         theThunderstorm->update( dt );
192     }
193 };
194
195 extern FGLocalWeatherDatabase *WeatherDatabase;
196 void fgUpdateWeatherDatabase(void);
197
198 /****************************************************************************/
199 /* get/set weather visibility                                               */
200 /****************************************************************************/
201 void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecision visibility)
202 {
203     if (visibility >= MINIMUM_WEATHER_VISIBILITY)
204         WeatherVisibility = visibility;
205     else
206         WeatherVisibility = MINIMUM_WEATHER_VISIBILITY;
207 }
208
209 WeatherPrecision inline FGLocalWeatherDatabase::getWeatherVisibility(void) const
210 {
211     return WeatherVisibility;
212 }
213
214
215 /****************************************************************************/
216 #endif /*FGLocalWeatherDatabase_H*/