]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGLocalWeatherDatabase.h
Updated so load/save will work.
[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 #include STL_STRING
58
59 #include <plib/sg.h>
60
61 #include "sphrintp.h"
62
63 #include "FGPhysicalProperties.h"
64 #include "FGPhysicalProperty.h"
65
66
67 #include "FGWeatherFeature.h"
68 #include "FGWeatherDefs.h"
69 #include "FGThunderstorm.h"
70
71 /****************************************************************************/
72 /* DEFINES                                                                  */
73 /****************************************************************************/
74 SG_USING_STD(vector);
75 SG_USING_STD(string);
76 SG_USING_NAMESPACE(std);
77
78 /****************************************************************************/
79 /* CLASS DECLARATION                                                        */
80 /****************************************************************************/
81 class FGLocalWeatherDatabase
82 {
83 private:
84 protected:
85     SphereInterpolate<FGPhysicalProperties> *database;
86
87     typedef vector<sgVec2>      pointVector;
88     typedef vector<pointVector> tileVector;
89
90     /************************************************************************/
91     /* make tiles out of points on a 2D plane                               */
92     /************************************************************************/
93     WeatherPrecision WeatherVisibility; //how far do I need to simulate the
94                                         //local weather? Unit: metres
95     sgVec3 last_known_position;
96
97     bool Thunderstorm;                  //is there a thunderstorm near by?
98     FGThunderstorm *theThunderstorm;    //pointer to the thunderstorm.
99
100 public:
101     static FGLocalWeatherDatabase *theFGLocalWeatherDatabase;  
102     
103     enum DatabaseWorkingType {
104         use_global,     //use global database for data !!obsolete!!
105         use_internet,   //use the weather data that came from the internet
106         manual,         //use only user inputs
107         distant,        //use distant information, e.g. like LAN when used in
108                         //a multiplayer environment
109         random,         //generate weather randomly
110         default_mode    //use only default values
111     };
112
113     DatabaseWorkingType DatabaseStatus;
114
115     void init( const WeatherPrecision visibility,
116                const DatabaseWorkingType type,
117                const string &root );
118
119     /************************************************************************/
120     /* Constructor and Destructor                                           */
121     /************************************************************************/
122     FGLocalWeatherDatabase(
123         const sgVec3&             position,
124         const string&             root,
125         const WeatherPrecision    visibility = DEFAULT_WEATHER_VISIBILITY,
126         const DatabaseWorkingType type       = PREFERED_WORKING_TYPE)
127     {
128         sgCopyVec3( last_known_position, position );
129
130         init( visibility, type, root );
131
132         theFGLocalWeatherDatabase = this;
133     }
134
135     FGLocalWeatherDatabase(
136         const WeatherPrecision    position_lat,
137         const WeatherPrecision    position_lon,
138         const WeatherPrecision    position_alt,
139         const string&             root,
140         const WeatherPrecision    visibility = DEFAULT_WEATHER_VISIBILITY,
141         const DatabaseWorkingType type       = PREFERED_WORKING_TYPE)
142     {
143         sgSetVec3( last_known_position, position_lat, position_lon, position_alt );
144
145         init( visibility, type, root );
146
147         theFGLocalWeatherDatabase = this;
148     }
149
150     ~FGLocalWeatherDatabase();
151
152     /************************************************************************/
153     /* reset the whole database                                             */
154     /************************************************************************/
155     void reset(const DatabaseWorkingType type = PREFERED_WORKING_TYPE);
156
157     /************************************************************************/
158     /* update the database. Since the last call we had dt seconds           */
159     /************************************************************************/
160     void update(const WeatherPrecision dt);                     //time has changed
161     void update(const sgVec3& p);                               //position has  changed
162     void update(const sgVec3& p, const WeatherPrecision dt);    //time and/or position has changed
163
164     /************************************************************************/
165     /* Get the physical properties on the specified point p                 */
166     /************************************************************************/
167 #ifdef macintosh
168     /* fix a problem with mw compilers in that they don't know the
169        difference between the next two methods. Since the first one
170        doesn't seem to be used anywhere, I commented it out. This is
171        supposed to be fixed in the forthcoming CodeWarrior Release
172        6. */
173 #else
174     FGPhysicalProperties get(const sgVec2& p) const;
175 #endif
176     FGPhysicalProperty   get(const sgVec3& p) const;
177
178     WeatherPrecision     getAirDensity(const sgVec3& p) const;
179     
180     /************************************************************************/
181     /* Add a weather feature at the point p and surrounding area            */
182     /************************************************************************/
183     // !! Adds aren't supported anymore !!
184
185     void setSnowRainIntensity   (const WeatherPrecision x, const sgVec2& p);
186     void setSnowRainType        (const SnowRainType x,     const sgVec2& p);
187     void setLightningProbability(const WeatherPrecision x, const sgVec2& p);
188
189     void setProperties(const FGPhysicalProperties2D& x);    //change a property
190
191     /************************************************************************/
192     /* get/set weather visibility                                           */
193     /************************************************************************/
194     void             setWeatherVisibility(const WeatherPrecision visibility);
195     WeatherPrecision getWeatherVisibility(void) const;
196
197     /************************************************************************/
198     /* figure out if there's a thunderstorm that has to be taken care of    */
199     /************************************************************************/
200     void updateThunderstorm(const float dt)
201     {
202         if (Thunderstorm == false)
203             return;
204
205         theThunderstorm->update( dt );
206     }
207 };
208
209 extern FGLocalWeatherDatabase *WeatherDatabase;
210 void fgUpdateWeatherDatabase(void);
211
212 /****************************************************************************/
213 /* get/set weather visibility                                               */
214 /****************************************************************************/
215 void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecision visibility)
216 {
217     if (visibility >= MINIMUM_WEATHER_VISIBILITY)
218         WeatherVisibility = visibility;
219     else
220         WeatherVisibility = MINIMUM_WEATHER_VISIBILITY;
221 }
222
223 WeatherPrecision inline FGLocalWeatherDatabase::getWeatherVisibility(void) const
224 {
225     return WeatherVisibility;
226 }
227
228
229 /****************************************************************************/
230 #endif /*FGLocalWeatherDatabase_H*/