Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

TimeManager.h

Go to the documentation of this file.
00001 /*
00002  * TimeManager.h
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00028 #ifndef TIMEMANAGER_H
00029 #define TIMEMANAGER_H
00030 
00031 #include <time.h>
00032 #include "FlyLegacy.h"
00033 
00034 // Check that exactly one precision timer method is defined
00035 #if defined(PRECISION_TIMER_PLIB) && defined(PRECISION_TIMER_WIN32)
00036 #error Main/TimeManager.cpp : Multiple precision timer methods defined!!
00037 #endif
00038 
00039 #if !(defined(PRECISION_TIMER_PLIB) || defined(PRECISION_TIMER_WIN32))
00040 #error Main/TimeManager.cpp : No precision timer method defined!!
00041 #endif
00042 
00043 
00044 class CTimeManager {
00045 public:
00046   CTimeManager ();
00047 
00048   // CTimeManager methods
00049   void    Prepare (void);
00050   void    Update (void);
00051   float   GetElapsedSimTime (void);
00052   float   GetDeltaRealTime (void);
00053   float   GetDeltaSimTime (void);
00054 
00055   void    SetUTCDateTime (SDateTime dt);
00056   void    SetLocalDateTime (SDateTime dt);
00057   void    SetTimeZoneDelta (bool subtract, SDateTimeDelta delta);
00058   void    SetTimeZoneOffset (float offset);
00059   void    GetTimeZoneDelta (SDateTimeDelta &delta, bool &subtract);
00060   float   GetTimeZoneOffset (void);
00061 
00062   void    SetTimeScale (float scale);
00063   float   GetTimeScale (void);
00064   bool    GetPauseState (void);
00065   void    Pause (void);
00066   void    Unpause (void);
00067 
00068   SDateTime GetUTCDateTime (void);
00069   SDateTime GetLocalDateTime (void);
00070   double    GetJulianDate (void);
00071   double    GetModifiedJulianDate (void);
00072   double    GetGreenwichSiderealTime (void);
00073   double    GetLocalSiderealTime (double lon);
00074 
00075   void    Print (FILE *f);
00076 
00077 
00078   // Static methods for general purpose time-related utilities
00079   static void SunriseSunset (SPosition pos, SDate date, float zenith,
00080                  STime &rise, STime &set,
00081                  bool &neverRises, bool& neverSets);
00082 
00083   static int            DaysInMonth (int month, int year);
00084   static double         JulianDate (SDateTime dt);
00085   static SDateTime      CalendarDate (double j);
00086   static SDateTimeDelta SecondsToDateTimeDelta (float s);
00087   static SDateTimeDelta DaysToDateTimeDelta (double d);
00088 //  static SDateTimeDelta   DateTimeDelta (SDateTime from, SDateTime to);
00089   static double         DateTimeDeltaToDays (SDateTimeDelta delta);
00090   static SDateTime      AddTimeDelta (SDateTime dt, SDateTimeDelta delta);
00091   static SDateTime      SubtractTimeDelta (SDateTime dt, SDateTimeDelta delta);
00092   static SDateTimeDelta SubtractTime (SDateTime from, SDateTime to);
00093 
00094 protected:
00095   // Master elapsed time (in seconds) since the simulation was started
00096   float   elapsed;
00097 
00098   // Delta time between calls to Update() in seconds
00099   float   dRealTime;
00100   float   dSimTime;
00101 
00102   // Time scale is the realtime scaling factor
00103   float   scale;
00104 
00105   // Whether simulation time is paused or not
00106   bool    paused;
00107 
00108   // Local time zone settings
00109   //  tzDelta   represents number of hours to be subtracted or added to UTC
00110   //  tzSubtract  indicates whether the delta should be subtracted from UTC
00111   SDateTimeDelta    tzDelta;
00112   bool        tzSubtract;
00113 
00114   // "Zero" date/time, i.e. the calendar date and time when the simulation
00115   //   was started.  This base value is used in conjunction with the simulation
00116   //   elapsed time to derive the current simulation date/time
00117   SDateTime epoch;
00118 
00119 #ifdef PRECISION_TIMER_WIN32
00120   // CTimeManager uses the Win32 functions QueryPerformanceFrequency
00121   //   and QueryPerformanceCounter as its high-resolution counters on
00122   //   the Windows platform
00123   float     freq;         // Counter frequency
00124   LARGE_INTEGER count, prev_count;    // Counter values
00125 #endif
00126 
00127 #ifdef PRECISION_TIMER_PLIB
00128   // Use platform-independent PLIB utility timer
00129   ulClock *clock;
00130 #endif
00131 };
00132 
00133 
00134 #endif // TIMEMANAGER_H
00135 
SourceForge.net Logo Documentation generated by doxygen