1998-04-24 00:52:24 +00:00
|
|
|
// fg_time.hxx -- data structures and routines for managing time related stuff.
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started August 1997.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _FG_TIME_HXX
|
|
|
|
#define _FG_TIME_HXX
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <GL/glut.h>
|
1999-01-07 20:25:32 +00:00
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
1999-01-07 20:25:32 +00:00
|
|
|
#ifdef FG_HAVE_STD_INCLUDES
|
|
|
|
# include <ctime>
|
|
|
|
#else
|
|
|
|
# include <time.h>
|
|
|
|
#endif
|
1998-04-24 00:52:24 +00:00
|
|
|
|
1999-02-01 21:33:23 +00:00
|
|
|
#include <FDM/flight.hxx>
|
1998-04-24 00:52:24 +00:00
|
|
|
|
1999-09-07 23:11:22 +00:00
|
|
|
#include "timezone.h"
|
|
|
|
#include "lowleveltime.h"
|
1998-04-24 00:52:24 +00:00
|
|
|
|
|
|
|
// Define a structure containing global time parameters
|
1999-04-08 19:53:46 +00:00
|
|
|
class FGTime {
|
|
|
|
|
|
|
|
private:
|
1999-09-07 23:11:22 +00:00
|
|
|
// tzContainer stores all the current Timezone control points/
|
|
|
|
TimezoneContainer* tzContainer;
|
|
|
|
|
|
|
|
//Store the current local timezone name;
|
|
|
|
char *zonename;
|
1999-04-08 19:53:46 +00:00
|
|
|
|
1998-04-24 00:52:24 +00:00
|
|
|
// Unix "calendar" time in seconds
|
|
|
|
time_t cur_time;
|
|
|
|
|
|
|
|
// Break down of GMT time
|
|
|
|
struct tm *gmt;
|
|
|
|
|
|
|
|
// Julian date
|
|
|
|
double jd;
|
|
|
|
|
|
|
|
// modified Julian date
|
|
|
|
double mjd;
|
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
double last_mjd, last_dy;
|
|
|
|
int last_mn, last_yr;
|
|
|
|
|
1998-04-24 00:52:24 +00:00
|
|
|
// side real time at prime meridian
|
|
|
|
double gst;
|
|
|
|
|
1999-10-22 00:27:49 +00:00
|
|
|
// local sidereal time
|
1998-04-24 00:52:24 +00:00
|
|
|
double lst;
|
|
|
|
|
1999-10-22 00:27:49 +00:00
|
|
|
// local offset to GMT
|
|
|
|
time_t localOffset;
|
|
|
|
|
1998-04-24 00:52:24 +00:00
|
|
|
// the difference between the precise sidereal time algorithm
|
1999-04-08 19:53:46 +00:00
|
|
|
// result and the course result. course + diff has good accuracy
|
|
|
|
// for the short term
|
1998-04-24 00:52:24 +00:00
|
|
|
double gst_diff;
|
|
|
|
|
|
|
|
// An offset in seconds from the true time. Allows us to adjust
|
|
|
|
// the effective time of day.
|
|
|
|
long int warp;
|
|
|
|
|
|
|
|
// How much to change the value of warp each iteration. Allows us
|
|
|
|
// to make time progress faster than normal.
|
1999-04-08 19:53:46 +00:00
|
|
|
long int warp_delta;
|
1998-07-27 18:42:22 +00:00
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
// Paused?
|
|
|
|
bool pause;
|
2000-03-29 00:15:58 +00:00
|
|
|
|
|
|
|
// Local magnetic variation and dip in radians
|
|
|
|
double magvar;
|
|
|
|
double magdip;
|
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
void local_update_sky_and_lighting_params( void );
|
1998-04-24 00:52:24 +00:00
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
public:
|
1998-04-24 00:52:24 +00:00
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
FGTime();
|
|
|
|
~FGTime();
|
1998-04-24 00:52:24 +00:00
|
|
|
|
2000-03-29 00:15:58 +00:00
|
|
|
inline double getJD() const { return jd; };
|
1999-04-08 19:53:46 +00:00
|
|
|
inline double getMjd() const { return mjd; };
|
|
|
|
inline double getLst() const { return lst; };
|
|
|
|
inline double getGst() const { return gst; };
|
|
|
|
inline time_t get_cur_time() const { return cur_time; };
|
|
|
|
inline struct tm* getGmt()const { return gmt; };
|
|
|
|
inline bool getPause() const { return pause; };
|
|
|
|
|
|
|
|
void adjust_warp(int val) { warp += val; };
|
|
|
|
void adjust_warp_delta(int val) { warp_delta += val; };
|
|
|
|
void togglePauseMode() { pause = !pause; };
|
1998-04-24 00:52:24 +00:00
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
// Initialize the time dependent variables
|
2000-03-16 04:18:24 +00:00
|
|
|
void init( double lon, double lat );
|
1998-04-24 00:52:24 +00:00
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
// Update the time dependent variables
|
2000-03-29 00:15:58 +00:00
|
|
|
void update( double lon, double lat, double alt_m );
|
1999-10-22 00:27:49 +00:00
|
|
|
void updateLocal();
|
1998-04-24 00:52:24 +00:00
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
void cal_mjd (int mn, double dy, int yr);
|
|
|
|
void utc_gst();
|
|
|
|
double sidereal_precise (double lng);
|
|
|
|
double sidereal_course(double lng);
|
|
|
|
static FGTime *cur_time_params;
|
1998-04-24 00:52:24 +00:00
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
// Some other stuff which were changed to FGTime members on
|
|
|
|
// questionable grounds -:)
|
1999-04-11 13:19:29 +00:00
|
|
|
// time_t get_start_gmt(int year);
|
|
|
|
time_t get_gmt(int year, int month, int day,
|
|
|
|
int hour, int minute, int second);
|
1999-09-07 23:11:22 +00:00
|
|
|
time_t get_gmt(struct tm* the_time);
|
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
char* format_time( const struct tm* p, char* buf );
|
|
|
|
long int fix_up_timezone( long int timezone_orig );
|
2000-03-29 00:15:58 +00:00
|
|
|
|
|
|
|
// Return magnetic variations
|
|
|
|
double getMagVar() const { return magvar; }
|
|
|
|
double getMagDip() const { return magdip; }
|
1999-04-08 19:53:46 +00:00
|
|
|
};
|
1998-04-24 00:52:24 +00:00
|
|
|
|
|
|
|
|
1999-09-07 23:11:22 +00:00
|
|
|
inline time_t FGTime::get_gmt(struct tm* the_time) // this is just a wrapper
|
|
|
|
{
|
|
|
|
//printf("Using: %24s as input\n", asctime(the_time));
|
|
|
|
return get_gmt(the_time->tm_year,
|
|
|
|
the_time->tm_mon,
|
|
|
|
the_time->tm_mday,
|
|
|
|
the_time->tm_hour,
|
|
|
|
the_time->tm_min,
|
|
|
|
the_time->tm_sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-08 19:53:46 +00:00
|
|
|
#endif // _FG_TIME_HXX
|