From 12dac83b214f61b99ae2745916b57202441ac361 Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 9 Jan 1999 13:37:32 +0000 Subject: [PATCH] Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. --- External/external.hxx | 5 +++- FDM/flight.cxx | 11 +++++--- FDM/flight.hxx | 5 +++- Main/GLUTmain.cxx | 23 +++++++++------- Time/event.cxx | 8 ++++-- Time/event.hxx | 9 ++++--- Time/fg_timer.cxx | 9 ++++--- Time/timestamp.hxx | 61 +++++++++++++++++++++++-------------------- 8 files changed, 78 insertions(+), 53 deletions(-) diff --git a/External/external.hxx b/External/external.hxx index bf65ad0c9..12b59b23d 100644 --- a/External/external.hxx +++ b/External/external.hxx @@ -44,7 +44,7 @@ public: // The time at which these values are correct (for extrapolating // later frames between position updates) - fgTIMESTAMP t; + FGTimeStamp t; // Positions @@ -97,6 +97,9 @@ void fgExternalUpdate( FGState& f, int multiloop ); // $Log$ +// Revision 1.4 1999/01/09 13:37:37 curt +// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. +// // Revision 1.3 1998/12/05 15:54:14 curt // Renamed class fgFLIGHT to class FGState as per request by JSB. // diff --git a/FDM/flight.cxx b/FDM/flight.cxx index 07f756fd2..ea70188a9 100644 --- a/FDM/flight.cxx +++ b/FDM/flight.cxx @@ -94,7 +94,7 @@ int fgFlightModelInit(int model, FGState& f, double dt) { static FGState extrapolate_fdm( FGState &base, int jitter ) { FGState result; - double dt = jitter / 1000.0; + double dt = jitter / 1000000.0; // cout << "dt = " << dt << endl; // start by making a straight up copy @@ -118,9 +118,9 @@ static FGState extrapolate_fdm( FGState &base, int jitter ) { double alt = base.get_Altitude() + base.get_Radius_dot() * dt; double radius = base.get_Radius_to_vehicle() + base.get_Radius_dot() * dt; - result.set_Longitude( lon ); - result.set_Latitude( lat ); - result.set_Altitude( alt ); + // result.set_Longitude( lon ); + // result.set_Latitude( lat ); + // result.set_Altitude( alt ); // result.set_Geocentric_Position( lon_geoc, lat_geoc, radius ); return result; @@ -184,6 +184,9 @@ void fgFlightModelSetAltitude(int model, double alt_meters) { // $Log$ +// Revision 1.10 1999/01/09 13:37:32 curt +// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. +// // Revision 1.9 1999/01/08 19:27:37 curt // Fixed AOA reading on HUD. // Continued work on time jitter compensation. diff --git a/FDM/flight.hxx b/FDM/flight.hxx index 9cd463723..331c96ec6 100644 --- a/FDM/flight.hxx +++ b/FDM/flight.hxx @@ -544,7 +544,7 @@ public: geocentric_position_v[2] = radius; } -// inline void set_Geocentric_Position( double lat, double lon, double rad ) { + inline void set_Geocentric_Position( double lat, double lon, double rad ) { geocentric_position_v[0] = lat; geocentric_position_v[1] = lon; geocentric_position_v[2] = rad; @@ -797,6 +797,9 @@ void fgFlightModelSetAltitude(int model, double alt_meters); // $Log$ +// Revision 1.10 1999/01/09 13:37:33 curt +// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. +// // Revision 1.9 1999/01/08 19:27:38 curt // Fixed AOA reading on HUD. // Continued work on time jitter compensation. diff --git a/Main/GLUTmain.cxx b/Main/GLUTmain.cxx index 1b25327f8..f1fba8050 100644 --- a/Main/GLUTmain.cxx +++ b/Main/GLUTmain.cxx @@ -450,8 +450,8 @@ static const double alt_adjust_m = alt_adjust_ft * FEET_TO_METER; static void fgMainLoop( void ) { FGState *f; fgTIME *t; - static int remainder = 0; - int elapsed, multi_loop; + static long remainder = 0; + long elapsed, multi_loop; // int i; // double accum; static time_t last_time = 0; @@ -508,15 +508,17 @@ static void fgMainLoop( void ) { // update "time" fgTimeUpdate(f, t); - // Get elapsed time for this past frame + // Get elapsed time (in usec) for this past frame elapsed = fgGetTimeInterval(); - FG_LOG( FG_ALL, FG_BULK, - "Time interval is = " << elapsed + FG_LOG( FG_ALL, FG_DEBUG, + "Elapsed time interval is = " << elapsed << ", previous remainder is = " << remainder ); // Calculate frame rate average if ( (t->cur_time != last_time) && (last_time > 0) ) { general.set_frame_rate( frames ); + FG_LOG( FG_ALL, FG_DEBUG, + "--> Frame rate is = " << general.get_frame_rate() ); frames = 0; } last_time = t->cur_time; @@ -541,13 +543,11 @@ static void fgMainLoop( void ) { // Run flight model if ( ! use_signals ) { // Calculate model iterations needed for next frame - FG_LOG( FG_ALL, FG_DEBUG, - "--> Frame rate is = " << general.get_frame_rate() ); elapsed += remainder; - multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ); - remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ); - FG_LOG( FG_ALL, FG_BULK, + multi_loop = (int)(((double)elapsed * 0.000001) * DEFAULT_MODEL_HZ); + remainder = elapsed - ((multi_loop*1000000) / DEFAULT_MODEL_HZ); + FG_LOG( FG_ALL, FG_DEBUG, "Model iterations needed = " << multi_loop << ", new remainder = " << remainder ); @@ -1000,6 +1000,9 @@ int main( int argc, char **argv ) { // $Log$ +// Revision 1.80 1999/01/09 13:37:40 curt +// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. +// // Revision 1.79 1999/01/08 03:23:56 curt // Beginning work on compensating for sim time vs. real world time "jitter". // diff --git a/Time/event.cxx b/Time/event.cxx index 1126e03dc..5f4d204dc 100644 --- a/Time/event.cxx +++ b/Time/event.cxx @@ -190,7 +190,8 @@ fgEVENT_MGR::Register( const string& desc, fgEVENT::EventState status, int interval ) { - fgEVENT* e = new fgEVENT( desc, cb, status, interval ); + // convert interval specified in milleseconds to usec + fgEVENT* e = new fgEVENT( desc, cb, status, interval * 1000 ); FG_LOG( FG_EVENT, FG_INFO, "Registering event: " << desc ); @@ -249,7 +250,7 @@ fgEVENT_MGR::PrintStats() // the queue void fgEVENT_MGR::Process( void ) { fgEVENT *e_ptr; - fgTIMESTAMP cur_time; + FGTimeStamp cur_time; unsigned int i, size; FG_LOG( FG_EVENT, FG_DEBUG, "Processing events" ); @@ -305,6 +306,9 @@ fgEVENT_MGR::~fgEVENT_MGR( void ) { // $Log$ +// Revision 1.15 1999/01/09 13:37:42 curt +// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. +// // Revision 1.14 1999/01/07 20:25:32 curt // Portability changes and updates from Bernie Bright. // diff --git a/Time/event.hxx b/Time/event.hxx index 57d81e81d..2ef1a8844 100644 --- a/Time/event.hxx +++ b/Time/event.hxx @@ -88,9 +88,9 @@ private: long interval; // interval in ms between each iteration of this event - fgTIMESTAMP last_run; - fgTIMESTAMP current; - fgTIMESTAMP next_run; + FGTimeStamp last_run; + FGTimeStamp current; + FGTimeStamp next_run; long cum_time; // cumulative processor time of this event long min_time; // time of quickest execution @@ -166,6 +166,9 @@ extern fgEVENT_MGR global_events; // $Log$ +// Revision 1.16 1999/01/09 13:37:43 curt +// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. +// // Revision 1.15 1999/01/07 20:25:33 curt // Portability changes and updates from Bernie Bright. // diff --git a/Time/fg_timer.cxx b/Time/fg_timer.cxx index c77cda5bf..074d90f5b 100644 --- a/Time/fg_timer.cxx +++ b/Time/fg_timer.cxx @@ -96,13 +96,13 @@ void fgTimerInit(float dt, void (*f)( int )) { #endif // HAVE_SETITIMER -// This function returns the number of milleseconds since the last +// This function returns the number of microseconds since the last // time it was called. int fgGetTimeInterval( void ) { int interval; static int inited = 0; - static fgTIMESTAMP last; - fgTIMESTAMP current; + static FGTimeStamp last; + FGTimeStamp current; if ( ! inited ) { inited = 1; @@ -119,6 +119,9 @@ int fgGetTimeInterval( void ) { // $Log$ +// Revision 1.6 1999/01/09 13:37:45 curt +// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. +// // Revision 1.5 1998/12/05 14:21:32 curt // Moved struct fg_timestamp to class fgTIMESTAMP and moved it's definition // to it's own file, timestamp.hxx. diff --git a/Time/timestamp.hxx b/Time/timestamp.hxx index 42f8734d4..b20b19f6c 100644 --- a/Time/timestamp.hxx +++ b/Time/timestamp.hxx @@ -67,94 +67,94 @@ #endif -class fgTIMESTAMP { +class FGTimeStamp { private: long seconds; - long millis; + long usec; public: - fgTIMESTAMP(); - fgTIMESTAMP( const long s, const long m ); - ~fgTIMESTAMP(); + FGTimeStamp(); + FGTimeStamp( const long s, const long m ); + ~FGTimeStamp(); // Set time to current time void stamp(); - fgTIMESTAMP& operator = ( const fgTIMESTAMP& t ); + FGTimeStamp& operator = ( const FGTimeStamp& t ); - friend fgTIMESTAMP operator + (const fgTIMESTAMP& t, const long& m); - friend long operator - (const fgTIMESTAMP& a, const fgTIMESTAMP& b); + friend FGTimeStamp operator + (const FGTimeStamp& t, const long& m); + friend long operator - (const FGTimeStamp& a, const FGTimeStamp& b); inline long get_seconds() const { return seconds; } - inline long get_millis() const { return millis; } + // inline long get_usec() const { return usec; } }; -inline fgTIMESTAMP::fgTIMESTAMP() { +inline FGTimeStamp::FGTimeStamp() { } -inline fgTIMESTAMP::fgTIMESTAMP( const long s, const long m ) { +inline FGTimeStamp::FGTimeStamp( const long s, const long u ) { seconds = s; - millis = m; + usec = u; } -inline fgTIMESTAMP::~fgTIMESTAMP() { +inline FGTimeStamp::~FGTimeStamp() { } -inline fgTIMESTAMP& fgTIMESTAMP::operator = (const fgTIMESTAMP& t) +inline FGTimeStamp& FGTimeStamp::operator = (const FGTimeStamp& t) { seconds = t.seconds; - millis = t.millis; + usec = t.usec; return *this; } -inline void fgTIMESTAMP::stamp() { +inline void FGTimeStamp::stamp() { #if defined( WIN32 ) unsigned int t; t = timeGetTime(); seconds = 0; - millis = t; + usec = t * 1000; #elif defined( HAVE_GETTIMEOFDAY ) struct timeval current; struct timezone tz; // fg_timestamp currtime; gettimeofday(¤t, &tz); seconds = current.tv_sec; - millis = current.tv_usec / 1000; + usec = current.tv_usec; #elif defined( HAVE_GETLOCALTIME ) SYSTEMTIME current; GetLocalTime(¤t); seconds = current.wSecond; - millis = current.wMilliseconds; + usec = current.wMilliseconds * 1000; #elif defined( HAVE_FTIME ) struct timeb current; ftime(¤t); seconds = current.time; - millis = current.millitm; + usec = current.millitm * 1000; #else # error Port me #endif } -// difference between time stamps in milliseconds -inline fgTIMESTAMP operator + (const fgTIMESTAMP& t, const long& m) { +// difference between time stamps in microseconds (usec) +inline FGTimeStamp operator + (const FGTimeStamp& t, const long& m) { #ifdef WIN32 - return fgTIMESTAMP( 0, t.millis + m ); + return FGTimeStamp( 0, t.usec + m ); #else - return fgTIMESTAMP( t.seconds + ( t.millis + m ) / 1000, - ( t.millis + m ) % 1000 ); + return FGTimeStamp( t.seconds + ( t.usec + m ) / 1000000, + ( t.usec + m ) % 1000000 ); #endif } -// difference between time stamps in milliseconds -inline long operator - (const fgTIMESTAMP& a, const fgTIMESTAMP& b) +// difference between time stamps in microseconds (usec) +inline long operator - (const FGTimeStamp& a, const FGTimeStamp& b) { #if defined( WIN32 ) - return a.millis - b.millis; + return a.usec - b.usec; #else - return 1000 * (a.seconds - b.seconds) + (a.millis - b.millis); + return 1000000 * (a.seconds - b.seconds) + (a.usec - b.usec); #endif } @@ -163,6 +163,9 @@ inline long operator - (const fgTIMESTAMP& a, const fgTIMESTAMP& b) // $Log$ +// Revision 1.4 1999/01/09 13:37:46 curt +// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms. +// // Revision 1.3 1999/01/07 20:25:39 curt // Portability changes and updates from Bernie Bright. // -- 2.39.2