From 32bab8aa1063b836ee955ffc0b308a46427f5289 Mon Sep 17 00:00:00 2001 From: curt <curt> Date: Wed, 1 Sep 1999 20:24:54 +0000 Subject: [PATCH] Setup a user definable model hertz. --- src/FDM/flight.cxx | 3 ++- src/Include/fg_constants.h | 4 +--- src/Main/fg_init.cxx | 4 ++-- src/Main/main.cxx | 16 +++++++++++----- src/Main/options.cxx | 5 +++++ src/Main/options.hxx | 2 ++ 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index ccc3f908c..6bb94eec4 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -27,6 +27,7 @@ #include <FDM/External/external.hxx> #include <FDM/LaRCsim/ls_interface.h> #include <Include/fg_constants.h> +#include <Main/options.hxx> #include <Math/fg_geodesy.hxx> #include <Time/timestamp.hxx> @@ -137,7 +138,7 @@ int fgFDMUpdate(int model, FGInterface& f, int multiloop, int time_offset) { // set valid time for this record base_fdm_state.stamp_time(); - time_step = (1.0 / DEFAULT_MODEL_HZ) * multiloop; + time_step = (1.0 / current_options.get_model_hz()) * multiloop; start_elev = base_fdm_state.get_Altitude(); if ( model == FGInterface::FG_SLEW ) { diff --git a/src/Include/fg_constants.h b/src/Include/fg_constants.h index c925c7843..ad8ee5dbd 100644 --- a/src/Include/fg_constants.h +++ b/src/Include/fg_constants.h @@ -153,9 +153,7 @@ // Timing constants for Flight Model updates -#define DEFAULT_TIMER_HZ 20 -#define DEFAULT_MULTILOOP 6 -#define DEFAULT_MODEL_HZ (DEFAULT_TIMER_HZ * DEFAULT_MULTILOOP) +#define NEW_DEFAULT_MODEL_HZ 120 // Field of view limits diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 78418ce72..82842d392 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -444,7 +444,7 @@ bool fgInitSubsystems( void ) { // above values fgFDMInit( current_options.get_flight_model(), cur_fdm_state, - 1.0 / DEFAULT_MODEL_HZ ); + 1.0 / current_options.get_model_hz() ); // I'm just sticking this here for now, it should probably move // eventually @@ -562,7 +562,7 @@ void fgReInitSubsystems( void ) // v->UpdateWorldToEye(f); fgFDMInit( current_options.get_flight_model(), cur_fdm_state, - 1.0 / DEFAULT_MODEL_HZ ); + 1.0 / current_options.get_model_hz() ); scenery.cur_elev = f->get_Runway_altitude() * FEET_TO_METER; diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 8820f7f6d..fae72031e 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -463,7 +463,7 @@ void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { // update the flight model if ( multi_loop < 0 ) { - multi_loop = DEFAULT_MULTILOOP; + multi_loop = 1; } if ( !t->getPause() ) { @@ -527,13 +527,16 @@ void fgInitTimeDepCalcs( void ) { // initialize timer // #ifdef HAVE_SETITIMER - // fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs ); + // fgTimerInit( 1.0 / current_options.get_model_hz(), + // fgUpdateTimeDepCalcs ); // #endif HAVE_SETITIMER } + static const double alt_adjust_ft = 3.758099; static const double alt_adjust_m = alt_adjust_ft * FEET_TO_METER; + // What should we do when we have nothing else to do? Let's get ready // for the next move and update the display? static void fgMainLoop( void ) { @@ -646,8 +649,10 @@ static void fgMainLoop( void ) { // Calculate model iterations needed for next frame elapsed += remainder; - multi_loop = (int)(((double)elapsed * 0.000001) * DEFAULT_MODEL_HZ); - remainder = elapsed - ((multi_loop*1000000) / DEFAULT_MODEL_HZ); + multi_loop = (int)(((double)elapsed * 0.000001) * + current_options.get_model_hz()); + remainder = elapsed - ( (multi_loop*1000000) / + current_options.get_model_hz() ); FG_LOG( FG_ALL, FG_DEBUG, "Model iterations needed = " << multi_loop << ", new remainder = " << remainder ); @@ -656,7 +661,8 @@ static void fgMainLoop( void ) { if ( multi_loop > 0 ) { fgUpdateTimeDepCalcs(multi_loop, remainder); } else { - FG_LOG( FG_ALL, FG_INFO, "Elapsed time is zero ... we're zinging" ); + FG_LOG( FG_ALL, FG_DEBUG, + "Elapsed time is zero ... we're zinging" ); } } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 8e9470973..13832655c 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -161,6 +161,7 @@ fgOPTIONS::fgOPTIONS() : // Flight Model options flight_model( FGInterface::FG_LARCSIM ), + model_hz( NEW_DEFAULT_MODEL_HZ ), speed_up( 1 ), // Rendering options @@ -639,6 +640,9 @@ int fgOPTIONS::parse_option( const string& arg ) { fg_root = arg.substr( 10 ); } else if ( arg.find( "--fdm=" ) != string::npos ) { flight_model = parse_fdm( arg.substr(6) ); + } else if ( arg.find( "--model-hz=" ) != string::npos ) { + model_hz = atoi( arg.substr(11) ); + cout << "model hz = " << model_hz << endl; } else if ( arg.find( "--speed=" ) != string::npos ) { speed_up = atoi( arg.substr(8) ); } else if ( arg == "--fog-disable" ) { @@ -819,6 +823,7 @@ void fgOPTIONS::usage ( void ) { printf("Flight Model:\n"); printf("\t--fdm=abcd: one of slew, jsb, larcsim, or external\n"); + printf("\t--model-hz=n: run the FDM this rate (iterations per second)\n"); printf("\t--speed=n: run the FDM this much faster than real time\n"); printf("\n"); diff --git a/src/Main/options.hxx b/src/Main/options.hxx index 671d40837..919e49ce9 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -126,6 +126,7 @@ private: // Flight Model options int flight_model; // Flight Model: FG_SLEW, FG_LARCSIM, etc. + int model_hz; // number of FDM iterations per second int speed_up; // Sim mechanics run this much faster than normal speed // Rendering options @@ -207,6 +208,7 @@ public: inline bool get_panel_status() const { return panel_status; } inline bool get_sound() const { return sound; } inline int get_flight_model() const { return flight_model; } + inline int get_model_hz() const { return model_hz; } inline int get_speed_up() const { return speed_up; } inline void set_speed_up( int speed ) { speed_up = speed; } inline bool fog_enabled() const { return fog != FG_FOG_DISABLED; }