Setup a user definable model hertz.
This commit is contained in:
parent
87e3a7decb
commit
32bab8aa10
6 changed files with 23 additions and 11 deletions
|
@ -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 ) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
|
Loading…
Add table
Reference in a new issue