From 0d3b0f27ba051be764c35b7df754f4e9e6c6975b Mon Sep 17 00:00:00 2001 From: david Date: Tue, 12 Mar 2002 16:30:27 +0000 Subject: [PATCH] Add support for elapsed time and logging. --- src/Main/globals.cxx | 2 ++ src/Main/globals.hxx | 13 +++++++++++++ src/Main/main.cxx | 42 +++++++++++------------------------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index e26abf694..1540d7a61 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -38,11 +38,13 @@ FGGlobals *globals; // Constructor FGGlobals::FGGlobals() : + elapsed_time_ms(0L), #if defined(FX) && defined(XMESA) fullscreen( true ), #endif warp( 0 ), warp_delta( 0 ), + logger(0), props(new SGPropertyNode), initial_state(0), commands(new SGCommandMgr) diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 02bf0bd55..bbfe63939 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -44,6 +44,7 @@ typedef vector string_list; // Forward declarations +class FGLogger; class FGEnvironmentMgr; class FGEnvironment; class FGControls; @@ -58,6 +59,9 @@ class FGGlobals { private: + // Number of milliseconds elapsed since the start of the program. + long elapsed_time_ms; + // Root of FlightGear data tree string fg_root; @@ -82,6 +86,9 @@ private: // to make time progress faster than normal (or even run in reverse.) long int warp_delta; + // Logger + FGLogger * logger; + // Time structure SGTime *time_params; @@ -130,6 +137,9 @@ public: FGGlobals(); ~FGGlobals(); + inline long get_elapsed_time_ms () const { return elapsed_time_ms; } + inline void set_elapsed_time_ms (long t) { elapsed_time_ms = t; } + inline const string &get_fg_root () const { return fg_root; } inline void set_fg_root (const string &root) { fg_root = root; } @@ -156,6 +166,9 @@ public: inline void set_warp_delta( long int d ) { warp_delta = d; } inline void inc_warp_delta( long int d ) { warp_delta += d; } + inline FGLogger * get_logger () { return logger; } + inline void set_logger (FGLogger * l) { logger = l; } + inline SGTime *get_time_params() const { return time_params; } inline void set_time_params( SGTime *t ) { time_params = t; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index e2372561e..21c2c5ed9 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -152,6 +152,7 @@ sgVec3 rway_ols; #include "splash.hxx" #include "viewmgr.hxx" #include "options.hxx" +#include "logger.hxx" #include "model.hxx" #ifdef macintosh @@ -225,6 +226,9 @@ ssgSimpleState *default_state; ssgSimpleState *hud_and_panel; ssgSimpleState *menus; +SGTimeStamp start_time_stamp; +SGTimeStamp current_time_stamp; + void fgBuildRenderStates( void ) { default_state = new ssgSimpleState; default_state->ref(); @@ -423,22 +427,19 @@ void fgRenderFrame( void ) { if ( fgGetBool("/sim/startup/splash-screen") ) { fgSplashUpdate(0.0); } + start_time_stamp.stamp(); // Keep resetting the start time } else { // idle_state is now 1000 meaning we've finished all our // initializations and are running the main loop, so this will // now work without seg faulting the system. - // printf("Ground = %.2f Altitude = %.2f\n", scenery.get_cur_elev(), - // FG_Altitude * SG_FEET_TO_METER); - - // this is just a temporary hack, to make me understand Pui - // timerText -> setLabel (ctime (&t->cur_time)); - // end of hack + // Update the elapsed time. + current_time_stamp.stamp(); + globals->set_elapsed_time_ms((current_time_stamp - start_time_stamp) + / 1000L); // calculate our current position in cartesian space scenery.set_center( scenery.get_next_center() ); - // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x(), - // scenery.center.y(), scenery.center.z()); FGViewerRPH *pilot_view = (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 ); @@ -485,29 +486,6 @@ void fgRenderFrame( void ) { chase_view->set_view_forward( pilot_view->get_view_pos() ); chase_view->set_view_up( wup ); -#if 0 - sgMat4 rph; - sgCopyMat4( rph, pilot_view->get_VIEW() ); - cout << "RPH Matrix = " << endl; - int i, j; - for ( i = 0; i < 4; i++ ) { - for ( j = 0; j < 4; j++ ) { - printf("%10.4f ", rph[i][j]); - } - cout << endl; - } - - sgMat4 la; - sgCopyMat4( la, chase_view->get_VIEW() ); - cout << "LookAt Matrix = " << endl; - for ( i = 0; i < 4; i++ ) { - for ( j = 0; j < 4; j++ ) { - printf("%10.4f ", la[i][j]); - } - cout << endl; - } -#endif - // update view port fgReshape( fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize") ); @@ -810,6 +788,8 @@ void fgRenderFrame( void ) { // glDisable ( GL_BLEND ) ; // glEnable( GL_FOG ); + + globals->get_logger()->update(0); // FIXME: use real dt } glutSwapBuffers();