]> git.mxchange.org Git - flightgear.git/blobdiff - Time/fg_time.cxx
Modifications to incorporate Jon S. Berndts flight model code.
[flightgear.git] / Time / fg_time.cxx
index d872690f8527740df34ed58c8ddb3de26176c727..f7a1c6e40af2f0113bb70de2e6f446eb3ce26c04 100644 (file)
 #  include <config.h>
 #endif
 
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
+#include "Include/compiler.h"
+
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <cmath>
+#  include <cstdio>
+#  include <cstdlib>
+#  include <ctime>
+#else
+#  include <math.h>
+#  include <stdio.h>
+#  include <stdlib.h>
+#  include <time.h>
+#endif
 
 #ifdef HAVE_SYS_TIMEB_H
 #  include <sys/timeb.h> // for ftime() and struct timeb
 #  include <sys/time.h>  // for get/setitimer, gettimeofday, struct timeval
 #endif
 
-#ifdef  WIN32
-#  include <windows.h>
-#  if defined( __CYGWIN__ ) || defined( __CYGWIN32__ )
-#    define NEAR /* */
-#    define FAR  /* */
-#  endif
-#  include <mmsystem.h>
-#endif
-
 #include <Astro/sky.hxx>
 #include <Astro/solarsystem.hxx>
 #include <Debug/logstream.hxx>
-#include <Flight/flight.hxx>
+#include <FDM/flight.hxx>
 #include <Include/fg_constants.h>
 #include <Main/options.hxx>
 #include <Time/light.hxx>
@@ -97,61 +97,6 @@ void fgTimeInit(fgTIME *t) {
 }
 
 
-/*
-// Portability wrap to get current time.
-void timestamp(fg_timestamp *timestamp) {
-#if defined( WIN32 )
-    unsigned int t;
-    t = timeGetTime();
-    timestamp->seconds = 0;
-    timestamp->millis =  t;
-#elif defined( HAVE_GETTIMEOFDAY )
-    struct timeval current;
-    struct timezone tz;
-    // fg_timestamp currtime;
-    gettimeofday(&current, &tz);
-    timestamp->seconds = current.tv_sec;
-    timestamp->millis = current.tv_usec / 1000;
-#elif defined( HAVE_GETLOCALTIME )
-    SYSTEMTIME current;
-    GetLocalTime(&current);
-    timestamp->seconds = current.wSecond;
-    timestamp->millis = current.wMilliseconds;
-#elif defined( HAVE_FTIME )
-    struct timeb current;
-    ftime(&current);
-    timestamp->seconds = current.time;
-    timestamp->millis = current.millitm;
-#else
-# error Port me
-#endif
-}
-
-
-// Return duration in millis from first to last
-long timediff(fg_timestamp *first, fg_timestamp *last) {
-#if defined( WIN32 )
-    return (last->millis - first->millis);
-#else
-    return ( 1000 * (last->seconds - first->seconds) + 
-            (last->millis - first->millis) );
-#endif
-}
-
-
-// Return new timestamp given a time stamp and an interval to add in
-void timesum(fg_timestamp *res, fg_timestamp *start, long millis) {
-#ifdef WIN32
-    res->seconds = 0;
-    res->millis = ( start->millis + millis );
-#else
-    res->seconds = start->seconds + 
-       ( start->millis + millis ) / 1000;
-    res->millis = ( start->millis + millis ) % 1000;
-#endif
-}
-*/
-
 // given a date in months, mn, days, dy, years, yr, return the
 // modified Julian date (number of days elapsed since 1900 jan 0.5),
 // mjd.  Adapted from Xephem.
@@ -328,12 +273,9 @@ time_t get_start_gmt(int year) {
 
     long int offset = -(timezone / 3600 - daylight);
 
-    FG_LOG( FG_EVENT, FG_DEBUG,
-           "  Raw time zone offset = " << timezone );
-    FG_LOG( FG_EVENT, FG_DEBUG,
-           "  Daylight Savings = " << daylight );
-    FG_LOG( FG_EVENT, FG_DEBUG,
-           "  Local hours from GMT = " << offset);
+    FG_LOG( FG_EVENT, FG_DEBUG, "  Raw time zone offset = " << timezone );
+    FG_LOG( FG_EVENT, FG_DEBUG, "  Daylight Savings = " << daylight );
+    FG_LOG( FG_EVENT, FG_DEBUG, "  Local hours from GMT = " << offset );
     
     long int start_gmt = start - timezone + (daylight * 3600);
     
@@ -344,24 +286,28 @@ time_t get_start_gmt(int year) {
 #   endif // ! defined ( MK_TIME_IS_GMT )
 }
 
+static char*
+format_time( const struct tm* p, char* buf )
+{
+    sprintf( buf, "%d/%d/%2d %d:%02d:%02d", 
+            p->tm_mon, p->tm_mday, p->tm_year,
+            p->tm_hour, p->tm_min, p->tm_sec);
+    return buf;
+}
 
 // return a courser but cheaper estimate of sidereal time
 double sidereal_course(fgTIME *t, double lng) {
     struct tm *gmt;
     time_t start_gmt, now;
     double diff, part, days, hours, lst;
+    char tbuf[64];
 
     gmt = t->gmt;
     now = t->cur_time;
     start_gmt = get_start_gmt(gmt->tm_year);
 
-    FG_LOG( FG_EVENT, FG_DEBUG, 
-           "  COURSE: GMT = "
-           << gmt->tm_mon << "/" << gmt->tm_mday << "/" << gmt->tm_year
-           << " "
-           << gmt->tm_hour << ":" << gmt->tm_min << ":" <<  gmt->tm_sec );
-
-    FG_LOG( FG_EVENT, FG_DEBUG, "  March 21 noon (GMT) = " << start_gmt);
+    FG_LOG( FG_EVENT, FG_DEBUG, "  COURSE: GMT = " << format_time(gmt, tbuf) );
+    FG_LOG( FG_EVENT, FG_DEBUG, "  March 21 noon (GMT) = " << start_gmt );
 
     diff = (now - start_gmt) / (3600.0 * 24.0);
     
@@ -387,7 +333,7 @@ double sidereal_course(fgTIME *t, double lng) {
 
 
 // Update time variables such as gmt, julian date, and sidereal time
-void fgTimeUpdate(fgFLIGHT *f, fgTIME *t) {
+void fgTimeUpdate(FGInterface *f, fgTIME *t) {
     double gst_precise, gst_course;
 
     FG_LOG( FG_EVENT, FG_DEBUG, "Updating time" );
@@ -453,6 +399,29 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t) {
 
 
 // $Log$
+// Revision 1.31  1999/02/05 21:29:18  curt
+// Modifications to incorporate Jon S. Berndts flight model code.
+//
+// Revision 1.30  1999/02/01 21:33:37  curt
+// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
+// Jon accepted my offer to do this and thought it was a good idea.
+//
+// Revision 1.29  1999/01/19 20:57:08  curt
+// MacOS portability changes contributed by "Robert Puyol" <puyol@abvent.fr>
+//
+// Revision 1.28  1999/01/07 20:25:34  curt
+// Portability changes and updates from Bernie Bright.
+//
+// Revision 1.27  1998/12/11 20:26:55  curt
+// #include tweaks.
+//
+// Revision 1.26  1998/12/05 15:54:28  curt
+// Renamed class fgFLIGHT to class FGState as per request by JSB.
+//
+// Revision 1.25  1998/12/05 14:21:30  curt
+// Moved struct fg_timestamp to class fgTIMESTAMP and moved it's definition
+// to it's own file, timestamp.hxx.
+//
 // Revision 1.24  1998/12/04 01:32:49  curt
 // Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
 // convenience inline operators.