]> git.mxchange.org Git - flightgear.git/blob - src/Time/fg_time.hxx
Changes contributed by Tony Peden to put wind data "on the bus".
[flightgear.git] / src / Time / fg_time.hxx
1 // fg_time.hxx -- data structures and routines for managing time related stuff.
2 //
3 // Written by Curtis Olson, started August 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _FG_TIME_HXX
25 #define _FG_TIME_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <GL/glut.h>
42
43 #include <simgear/compiler.h>
44
45 #ifdef FG_HAVE_STD_INCLUDES
46 #  include <ctime>
47 #else
48 #  include <time.h>
49 #endif
50
51 #include <FDM/flight.hxx>
52
53 #include "timezone.h"
54 #include "lowleveltime.h"
55
56 // Define a structure containing global time parameters
57 class FGTime {
58
59 private:
60     // tzContainer stores all the current Timezone control points/
61     TimezoneContainer* tzContainer;
62
63     //Store the current local timezone name;
64     char *zonename;
65
66     // Unix "calendar" time in seconds
67     time_t cur_time;
68
69     // Break down of GMT time
70     struct tm *gmt;
71
72     // Julian date
73     double jd;
74
75     // modified Julian date
76     double mjd;
77
78     double last_mjd, last_dy;
79     int last_mn, last_yr;
80
81     // side real time at prime meridian
82     double gst;
83
84     // local sidereal time
85     double lst;
86
87     // local offset to GMT
88     time_t localOffset;
89
90     // the difference between the precise sidereal time algorithm
91     // result and the course result.  course + diff has good accuracy
92     // for the short term
93     double gst_diff;
94
95     // An offset in seconds from the true time.  Allows us to adjust
96     // the effective time of day.
97     long int warp;
98
99     // How much to change the value of warp each iteration.  Allows us
100     // to make time progress faster than normal.
101     long int warp_delta;
102
103     // Paused?
104     bool pause;
105
106     // Local magnetic variation and dip in radians
107     double magvar;
108     double magdip;
109
110     void local_update_sky_and_lighting_params( void );
111
112 public:
113
114     FGTime();
115     ~FGTime();
116
117     inline double getJD() const { return jd; };
118     inline double getMjd() const { return mjd; };
119     inline double getLst() const { return lst; };
120     inline double getGst() const { return gst; };
121     inline time_t get_cur_time() const { return cur_time; };
122     inline struct tm* getGmt()const { return gmt; };
123     inline bool getPause() const { return pause; };
124   
125     void adjust_warp(int val) { warp += val; };
126     void adjust_warp_delta(int val) { warp_delta += val; };
127     void togglePauseMode() { pause = !pause; }; 
128
129     // Initialize the time dependent variables
130     void init( double lon, double lat );
131
132     // Update the time dependent variables
133     void update( double lon, double lat, double alt_m );
134     void updateLocal();
135
136     void cal_mjd (int mn, double dy, int yr);
137     void utc_gst(); 
138     double sidereal_precise (double lng);
139     double sidereal_course(double lng); 
140     static FGTime *cur_time_params;
141
142     // Some other stuff which were changed to FGTime members on
143     // questionable grounds -:)
144     // time_t get_start_gmt(int year);
145     time_t get_gmt(int year, int month, int day, 
146                    int hour, int minute, int second);
147     time_t get_gmt(struct tm* the_time);
148   
149     char* format_time( const struct tm* p, char* buf );
150     long int fix_up_timezone( long int timezone_orig );
151
152     // Return magnetic variations
153     double getMagVar() const { return magvar; }
154     double getMagDip() const { return magdip; }
155 };
156
157
158 inline time_t FGTime::get_gmt(struct tm* the_time) // this is just a wrapper
159 {
160   //printf("Using: %24s as input\n", asctime(the_time));
161   return get_gmt(the_time->tm_year,
162           the_time->tm_mon,
163           the_time->tm_mday,
164           the_time->tm_hour,
165           the_time->tm_min,
166           the_time->tm_sec);
167 }
168
169
170 #endif // _FG_TIME_HXX