]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGLocalWeatherDatabase.h
7155854ae70dcad9193ea2604a657c55b337cb9e
[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 <plib/sg.h>
59
60 #include "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 #ifdef MACOS
162     /* fix a problem with mw compilers in that they don't know the
163        difference between the next two methods. Since the first one
164        doesn't seem to be used anywhere, I commented it out. This is
165        supposed to be fixed in the forthcoming CodeWarrior Release
166        6. */
167 #else
168     FGPhysicalProperties get(const sgVec2& p) const;
169 #endif
170     FGPhysicalProperty   get(const sgVec3& p) const;
171
172     WeatherPrecision     getAirDensity(const sgVec3& p) const;
173     
174     /************************************************************************/
175     /* Add a weather feature at the point p and surrounding area            */
176     /************************************************************************/
177     // !! Adds aren't supported anymore !!
178
179     void setSnowRainIntensity   (const WeatherPrecision x, const sgVec2& p);
180     void setSnowRainType        (const SnowRainType x,     const sgVec2& p);
181     void setLightningProbability(const WeatherPrecision x, const sgVec2& p);
182
183     void setProperties(const FGPhysicalProperties2D& x);    //change a property
184
185     /************************************************************************/
186     /* get/set weather visibility                                           */
187     /************************************************************************/
188     void             setWeatherVisibility(const WeatherPrecision visibility);
189     WeatherPrecision getWeatherVisibility(void) const;
190
191     /************************************************************************/
192     /* figure out if there's a thunderstorm that has to be taken care of    */
193     /************************************************************************/
194     void updateThunderstorm(const float dt)
195     {
196         if (Thunderstorm == false)
197             return;
198
199         theThunderstorm->update( dt );
200     }
201 };
202
203 extern FGLocalWeatherDatabase *WeatherDatabase;
204 void fgUpdateWeatherDatabase(void);
205
206 /****************************************************************************/
207 /* get/set weather visibility                                               */
208 /****************************************************************************/
209 void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecision visibility)
210 {
211     if (visibility >= MINIMUM_WEATHER_VISIBILITY)
212         WeatherVisibility = visibility;
213     else
214         WeatherVisibility = MINIMUM_WEATHER_VISIBILITY;
215 }
216
217 WeatherPrecision inline FGLocalWeatherDatabase::getWeatherVisibility(void) const
218 {
219     return WeatherVisibility;
220 }
221
222
223 /****************************************************************************/
224 #endif /*FGLocalWeatherDatabase_H*/