]> git.mxchange.org Git - flightgear.git/blob - src/Time/fg_time.hxx
Added first stab at a socket class.
[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 "Include/compiler.h"
44 #ifdef FG_HAVE_STD_INCLUDES
45 #  include <ctime>
46 #else
47 #  include <time.h>
48 #endif
49
50 #include <FDM/flight.hxx>
51
52 #include "timezone.h"
53 #include "lowleveltime.h"
54
55 // Define a structure containing global time parameters
56 class FGTime {
57
58 private:
59     // tzContainer stores all the current Timezone control points/
60     TimezoneContainer* tzContainer;
61
62     //Store the current local timezone name;
63     char *zonename;
64
65     // Unix "calendar" time in seconds
66     time_t cur_time;
67
68     // Break down of GMT time
69     struct tm *gmt;
70
71     // Julian date
72     double jd;
73
74     // modified Julian date
75     double mjd;
76
77     double last_mjd, last_dy;
78     int last_mn, last_yr;
79
80     // side real time at prime meridian
81     double gst;
82
83     // local sidereal time
84     double lst;
85
86     // local offset to GMT
87     time_t localOffset;
88
89     // the difference between the precise sidereal time algorithm
90     // result and the course result.  course + diff has good accuracy
91     // for the short term
92     double gst_diff;
93
94     // An offset in seconds from the true time.  Allows us to adjust
95     // the effective time of day.
96     long int warp;
97
98     // How much to change the value of warp each iteration.  Allows us
99     // to make time progress faster than normal.
100     long int warp_delta;
101
102     // Paused?
103     bool pause;
104                                      
105     void local_update_sky_and_lighting_params( void );
106
107 public:
108
109     FGTime();
110     ~FGTime();
111
112     inline double getMjd() const { return mjd; };
113     inline double getLst() const { return lst; };
114     inline double getGst() const { return gst; };
115     inline time_t get_cur_time() const { return cur_time; };
116     inline struct tm* getGmt()const { return gmt; };
117     inline bool getPause() const { return pause; };
118   
119     void adjust_warp(int val) { warp += val; };
120     void adjust_warp_delta(int val) { warp_delta += val; };
121     void togglePauseMode() { pause = !pause; }; 
122
123     // Initialize the time dependent variables
124     void init(const FGInterface& f);
125
126     // Update the time dependent variables
127     void update(const FGInterface& f);
128     void updateLocal();
129
130     void cal_mjd (int mn, double dy, int yr);
131     void utc_gst(); 
132     double sidereal_precise (double lng);
133     double sidereal_course(double lng); 
134     static FGTime *cur_time_params;
135
136     // Some other stuff which were changed to FGTime members on
137     // questionable grounds -:)
138     // time_t get_start_gmt(int year);
139     time_t get_gmt(int year, int month, int day, 
140                    int hour, int minute, int second);
141     time_t get_gmt(struct tm* the_time);
142   
143     char* format_time( const struct tm* p, char* buf );
144     long int fix_up_timezone( long int timezone_orig );
145 };
146
147
148 inline time_t FGTime::get_gmt(struct tm* the_time) // this is just a wrapper
149 {
150   //printf("Using: %24s as input\n", asctime(the_time));
151   return get_gmt(the_time->tm_year,
152           the_time->tm_mon,
153           the_time->tm_mday,
154           the_time->tm_hour,
155           the_time->tm_min,
156           the_time->tm_sec);
157 }
158
159
160 #endif // _FG_TIME_HXX