1
0
Fork 0

Major overhaul:

- changed FGSubsystem::update(int) to
  FGSubsystem::update(delta_time_sec); the argument is now delta time
  in seconds rather than milliseconds

- added FGSubsystem::suspend(), FGSubsystem::suspend(bool),
  FGSubsystem::resume(), and FGSubsystem::is_suspended(), all with
  default implementations; is_suspended takes account of the master
  freeze as well as the subsystem's individual suspended state

- the FDMs now use the delta time argument the same as the rest of
  FlightGear; formerly, main.cxx made a special case and passed a
  multiloop argument

- FDMs now calculate multiloop internally instead of relying on
  main.cxx

There are probably some problems -- I've done basic testing with the
major FDMs and subsystems, but we'll probably need a few weeks to
sniff out bugs.
This commit is contained in:
david 2002-05-11 16:28:50 +00:00
parent 1ce573908c
commit 5a849b66e8
70 changed files with 356 additions and 206 deletions

View file

@ -54,7 +54,7 @@ void FGATCDisplay::unbind() {
}
// update - this actually draws the visuals and should be called from the main Flightgear rendering loop.
void FGATCDisplay::update(int dt) {
void FGATCDisplay::update(double dt) {
// These strings are used for temporary storage of the transmission string in order
// that the string we view only changes when the next repetition starts scrolling

View file

@ -71,7 +71,7 @@ public:
void unbind();
// Display any registered messages
void update(int dt);
void update(double dt);
// Register a single message for display after a delay of delay seconds
// Will automatically stop displaying after a suitable interval.

View file

@ -88,7 +88,7 @@ void FGATCMgr::init() {
airport_atc_map[(string)"KEMT"] = a;
}
void FGATCMgr::update(int dt) {
void FGATCMgr::update(double dt) {
//Traverse the list of active stations.
//Only update one class per update step to avoid the whole ATC system having to calculate between frames.
//Eventually we should only update every so many steps.

View file

@ -154,7 +154,7 @@ public:
void unbind();
void update(int dt);
void update(double dt);
// Returns true if the airport is found in the map
bool GetAirportATCDetails(string icao, AirportATC* a);

View file

@ -421,7 +421,7 @@ static double LinearExtrapolate( double x, double x1, double y1, double x2, doub
void
FGAutopilot::update (int dt)
FGAutopilot::update (double dt)
{
// Remove the following lines when the calling funcitons start
// passing in the data pointer

View file

@ -152,7 +152,7 @@ public:
void init ();
void bind ();
void unbind ();
void update (int dt);
void update (double dt);
// Reset the autopilot system
void reset(void);

View file

@ -269,7 +269,7 @@ FGPanel::unbind ()
* Update the panel.
*/
void
FGPanel::update (int dt)
FGPanel::update (double dt)
{
// TODO: cache the nodes
_visibility = fgGetBool("/sim/panel/visibility");

View file

@ -141,7 +141,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
virtual void update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh);
// transfer pointer ownership!!!

View file

@ -143,7 +143,7 @@ FGRadioStack::init ()
blink.stamp();
search();
update(1); // FIXME: use dt
update(0); // FIXME: use dt
// Search radio database once per second
global_events.Register( "fgRadioSearch()",
@ -404,7 +404,7 @@ double FGRadioStack::adjustILSRange( double stationElev, double aircraftElev,
// Update the various nav values based on position and valid tuned in navs
void
FGRadioStack::update(int dt)
FGRadioStack::update(double dt)
{
double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;

View file

@ -212,7 +212,7 @@ public:
void init ();
void bind ();
void unbind ();
void update (int dt);
void update (double dt);
// Update nav/adf radios based on current postition
void search ();

View file

@ -98,8 +98,9 @@ int FGSteam::_UpdatesPending = 1000000; /* Forces filter to reset */
// FIXME: no need to use static
// functions any longer.
void FGSteam::update ( int timesteps )
void FGSteam::update (double dt)
{
int timesteps = int(dt * 1000);
if (!isTied) {
isTied = true;
fgTie("/steam/airspeed-kt", FGSteam::get_ASI_kias);

View file

@ -53,7 +53,7 @@ class FGSteam
{
public:
static void update ( int timesteps );
static void update ( double dt );
// Position
static double get_ALT_ft ();

View file

@ -206,7 +206,7 @@ FGControls::unbind ()
void
FGControls::update (int dt)
FGControls::update (double dt)
{
}

View file

@ -83,7 +83,7 @@ public:
void init ();
void bind ();
void unbind ();
void update (int dt);
void update (double dt);
// Reset function
void reset_all(void);

View file

@ -116,7 +116,7 @@ FGUserDefEnvironmentCtrl::init ()
}
void
FGUserDefEnvironmentCtrl::update (int dt)
FGUserDefEnvironmentCtrl::update (double dt)
{
double base_wind_speed = _base_wind_speed_node->getDoubleValue();
double gust_wind_speed = _gust_wind_speed_node->getDoubleValue();

View file

@ -62,7 +62,7 @@ public:
virtual double getElevationFt () const { return _elev_ft; }
virtual void init () = 0;
virtual void update (int dt) = 0;
virtual void update (double dt) = 0;
protected:
@ -85,7 +85,7 @@ public:
virtual ~FGUserDefEnvironmentCtrl ();
virtual void init ();
virtual void update (int dt);
virtual void update (double dt);
private:

View file

@ -95,7 +95,7 @@ FGEnvironmentMgr::unbind ()
}
void
FGEnvironmentMgr::update (int dt)
FGEnvironmentMgr::update (double dt)
{
_controller->update(dt);
// FIXME: the FDMs should update themselves

View file

@ -51,7 +51,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
/**
* Get the environment information for the plane's current position.

View file

@ -156,7 +156,7 @@ struct {
FGADA::FGADA( double dt ) {
set_delta_t( dt );
// set_delta_t( dt );
}
@ -198,9 +198,12 @@ void FGADA::init() {
// Run an iteration of the EOM. This is essentially a NOP here
// because these values are getting filled in elsewhere based on
// external input.
void FGADA::update( int multiloop ) {
void FGADA::update( double dt ) {
// cout << "FGADA::update()" << endl;
if (is_suspended())
return;
char Buffer[numberofbytes];
char OutBuffer[nbytes];

View file

@ -79,7 +79,7 @@ public:
void init();
// update position based on inputs, positions, velocities, etc.
void update(int dt);
void update(double dt);
};

View file

@ -113,9 +113,14 @@ void FGBalloonSim::init() {
// Run an iteration of the EOM (equations of motion)
void FGBalloonSim::update( int multiloop ) {
void FGBalloonSim::update( double dt ) {
double save_alt = 0.0;
if (is_suspended())
return;
int multiloop = _calc_multiloop(dt);
// lets try to avoid really screwing up the BalloonSim model
if ( get_Altitude() < -9000 ) {
save_alt = get_Altitude();

View file

@ -75,7 +75,7 @@ public:
void init();
// update position based on inputs, positions, velocities, etc.
void update( int multiloop );
void update( double dt );
};

View file

@ -25,7 +25,7 @@
FGExternal::FGExternal( double dt ) {
set_delta_t( dt );
// set_delta_t( dt );
}
@ -47,7 +47,7 @@ void FGExternal::init() {
// Run an iteration of the EOM. This is essentially a NOP here
// because these values are getting filled in elsewhere based on
// external input.
void FGExternal::update( int multiloop ) {
void FGExternal::update( double dt ) {
// cout << "FGExternal::update()" << endl;
// double time_step = (1.0 / fgGetInt("/sim/model-hz"))

View file

@ -38,7 +38,7 @@ public:
void init();
// update position based on inputs, positions, velocities, etc.
void update( int multiloop );
void update( double dt );
};

View file

@ -234,7 +234,7 @@ static void net2global( FGNetFDM *net ) {
FGExternalNet::FGExternalNet( double dt, string host, int dop, int dip, int cp )
{
set_delta_t( dt );
// set_delta_t( dt );
valid = true;
@ -330,10 +330,13 @@ void FGExternalNet::init() {
// Run an iteration of the EOM. This is a NOP here because the flight
// model values are getting filled in elsewhere (most likely from some
// external source.)
void FGExternalNet::update( int multiloop ) {
void FGExternalNet::update( double dt ) {
int length;
int result;
if (is_suspended())
return;
// Send control positions to remote fdm
length = sizeof(ctrls);
global2raw( &ctrls );

View file

@ -87,7 +87,7 @@ public:
void init();
// update the fdm
void update( int multiloop );
void update( double dt );
};

View file

@ -98,7 +98,6 @@ FGJSBsim::FGJSBsim( double dt )
SGPath engine_path( globals->get_fg_root() );
engine_path.append( "Engine" );
set_delta_t( dt );
State->Setdt( dt );
result = fdmex->LoadModel( aircraft_path.str(),
@ -261,7 +260,12 @@ void FGJSBsim::init() {
// Run an iteration of the EOM (equations of motion)
void
FGJSBsim::update( int multiloop ) {
FGJSBsim::update( double dt ) {
if (is_suspended())
return;
int multiloop = _calc_multiloop(dt);
int i;

View file

@ -207,9 +207,8 @@ public:
/** Update the position based on inputs, positions, velocities, etc.
@param multiloop number of times to loop through the FDM
@return true if successful */
void update( int multiloop );
@param dt delta time in seconds. */
void update(double dt);
bool ToggleDataLogging(bool state);
bool ToggleDataLogging(void);
void do_trim(void);

View file

@ -41,7 +41,7 @@
#include "LaRCsim.hxx"
FGLaRCsim::FGLaRCsim( double dt ) {
set_delta_t( dt );
// set_delta_t( dt );
speed_up = fgGetNode("/sim/speed-up", true);
aero = fgGetNode("/sim/aero", true);
@ -60,10 +60,10 @@ FGLaRCsim::FGLaRCsim( double dt ) {
I_xz = 0.000000E+00;
}
ls_set_model_dt( get_delta_t() );
ls_set_model_dt(dt);
// Initialize our little engine that hopefully might
eng.init( get_delta_t() );
eng.init(dt);
// dcl - in passing dt to init rather than update I am assuming
// that the LaRCsim dt is fixed at one value (yes it is 120hz CLO)
}
@ -84,7 +84,12 @@ void FGLaRCsim::init() {
// Run an iteration of the EOM (equations of motion)
void FGLaRCsim::update( int multiloop ) {
void FGLaRCsim::update( double dt ) {
if (is_suspended())
return;
int multiloop = _calc_multiloop(dt);
if ( !strcmp(aero->getStringValue(), "c172") ) {
// set control inputs
@ -142,11 +147,11 @@ void FGLaRCsim::update( int multiloop ) {
fgSetDouble("/consumables/fuel/tank[0]/level-gal_us",
fgGetDouble("/consumables/fuel/tank[0]/level-gal_us")
- (eng.get_fuel_flow_gals_hr() / (2 * 3600))
* get_delta_t());
* dt);
fgSetDouble("/consumables/fuel/tank[1]/level-gal_us",
fgGetDouble("/consumables/fuel/tank[1]/level-gal_us")
- (eng.get_fuel_flow_gals_hr() / (2 * 3600))
* get_delta_t());
* dt);
}
F_X_engine = eng.get_prop_thrust_lbs();

View file

@ -58,7 +58,7 @@ public:
void init();
// update position based on inputs, positions, velocities, etc.
void update( int multiloop );
void update( double dt );
// Positions
void set_Latitude(double lat); //geocentric

View file

@ -33,7 +33,7 @@
FGMagicCarpet::FGMagicCarpet( double dt ) {
set_delta_t( dt );
// set_delta_t( dt );
}
@ -49,10 +49,15 @@ void FGMagicCarpet::init() {
// Run an iteration of the EOM (equations of motion)
void FGMagicCarpet::update( int multiloop ) {
void FGMagicCarpet::update( double dt ) {
// cout << "FGLaRCsim::update()" << endl;
double time_step = get_delta_t() * multiloop;
if (is_suspended())
return;
int multiloop = _calc_multiloop(dt);
double time_step = dt * multiloop;
// speed and distance traveled
double speed = globals->get_controls()->get_throttle( 0 ) * 2000; // meters/sec

View file

@ -38,7 +38,7 @@ public:
void init();
// update position based on inputs, positions, velocities, etc.
void update( int multiloop );
void update( double dt );
};

View file

@ -25,7 +25,7 @@
FGNullFDM::FGNullFDM( double dt ) {
set_delta_t( dt );
// set_delta_t( dt );
}
@ -43,6 +43,6 @@ void FGNullFDM::init() {
// Run an iteration of the EOM. This is a NOP here because the flight
// model values are getting filled in elsewhere (most likely from some
// external source.)
void FGNullFDM::update( int multiloop ) {
void FGNullFDM::update( double dt ) {
// cout << "FGNullFDM::update()" << endl;
}

View file

@ -39,7 +39,7 @@ public:
void init();
// update position based on inputs, positions, velocities, etc.
void update( int multiloop );
void update( double dt );
};

View file

@ -40,7 +40,7 @@ FGUFO::FGUFO( double dt )
Aileron(0.0),
Elevator(0.0)
{
set_delta_t( dt );
// set_delta_t( dt );
}
@ -56,10 +56,15 @@ void FGUFO::init() {
// Run an iteration of the EOM (equations of motion)
void FGUFO::update( int multiloop ) {
void FGUFO::update( double dt ) {
// cout << "FGLaRCsim::update()" << endl;
double time_step = get_delta_t() * multiloop;
if (is_suspended())
return;
int multiloop = _calc_multiloop(dt);
double time_step = dt * multiloop;
// read the throttle
double th = globals->get_controls()->get_throttle( 0 );

View file

@ -40,7 +40,7 @@ public:
void init();
// update position based on inputs, positions, velocities, etc.
void update( int multiloop );
void update( double dt );
};

View file

@ -57,7 +57,7 @@ void YASim::printDEBUG()
YASim::YASim(double dt)
{
set_delta_t(dt);
// set_delta_t(dt);
_fdm = new FGFDM();
_dt = dt;
@ -194,8 +194,13 @@ void YASim::init()
set_inited(true);
}
void YASim::update(int iterations)
void YASim::update(double dt)
{
if (is_suspended())
return;
int iterations = _calc_multiloop(dt);
// If we're crashed, then we don't care
if(_fdm->getAirplane()->getModel()->isCrashed())
return;

View file

@ -14,7 +14,7 @@ public:
virtual void bind();
// Run an iteration
virtual void update(int iterations);
virtual void update(double dt);
private:
void report();

View file

@ -57,8 +57,9 @@ FGInterface::FGInterface() {
FGInterface::FGInterface( double dt ) {
_setup();
delta_t = dt;
remainder = elapsed = multi_loop = 0;
// delta_t = dt;
// remainder = elapsed = multi_loop = 0;
remainder = 0;
}
// Destructor
@ -67,6 +68,21 @@ FGInterface::~FGInterface() {
}
int
FGInterface::_calc_multiloop (double dt)
{
int hz = fgGetInt("/sim/model-hz");
int speedup = fgGetInt("/sim/speed-up");
dt += remainder;
remainder = 0;
double ml = dt * hz;
int multiloop = int(floor(ml));
remainder = (ml - multiloop) / hz;
return (multiloop * speedup);
}
/**
* Set default values for the state of the FDM.
*
@ -163,8 +179,8 @@ FGInterface::common_init ()
set_inited( true );
stamp();
set_remainder( 0 );
// stamp();
// set_remainder( 0 );
// Set initial position
SG_LOG( SG_FLIGHT, SG_INFO, "...initializing position..." );
@ -254,14 +270,14 @@ FGInterface::bind ()
bound = true;
// Time management (read-only)
fgTie("/fdm/time/delta_t", this,
&FGInterface::get_delta_t); // read-only
fgTie("/fdm/time/elapsed", this,
&FGInterface::get_elapsed); // read-only
fgTie("/fdm/time/remainder", this,
&FGInterface::get_remainder); // read-only
fgTie("/fdm/time/multi_loop", this,
&FGInterface::get_multi_loop); // read-only
// fgTie("/fdm/time/delta_t", this,
// &FGInterface::get_delta_t); // read-only
// fgTie("/fdm/time/elapsed", this,
// &FGInterface::get_elapsed); // read-only
// fgTie("/fdm/time/remainder", this,
// &FGInterface::get_remainder); // read-only
// fgTie("/fdm/time/multi_loop", this,
// &FGInterface::get_multi_loop); // read-only
// Aircraft position
fgTie("/position/latitude-deg", this,
@ -405,7 +421,7 @@ FGInterface::unbind ()
* Update the state of the FDM (i.e. run the equations of motion).
*/
void
FGInterface::update (int dt)
FGInterface::update (double dt)
{
SG_LOG(SG_FLIGHT, SG_ALERT, "dummy update() ... SHOULDN'T BE CALLED!");
}

View file

@ -90,7 +90,7 @@
#include <string>
#include <simgear/constants.h>
#include <simgear/timing/timestamp.hxx>
// #include <simgear/timing/timestamp.hxx>
#include <Main/fgfs.hxx>
@ -124,11 +124,11 @@ private:
// next elapsed time. This yields a small amount of temporal
// jitter ( < dt ) but in practice seems to work well.
double delta_t; // delta "t"
SGTimeStamp time_stamp; // time stamp of last run
long elapsed; // time elapsed since last run
long remainder; // remainder time from last run
int multi_loop; // number of iterations of "delta_t" to run
// double delta_t; // delta "t"
// SGTimeStamp time_stamp; // time stamp of last run
// long elapsed; // time elapsed since last run
double remainder; // remainder time from last run
// int multi_loop; // number of iterations of "delta_t" to run
// Pilot location rel to ref pt
FG_VECTOR_3 d_pilot_rp_body_v;
@ -224,7 +224,10 @@ private:
// SGTimeStamp valid_stamp; // time this record is valid
// SGTimeStamp next_stamp; // time this record is valid
// protected:
protected:
int _calc_multiloop (double dt);
public:
// deliberately not virtual so that
@ -400,7 +403,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update(int dt);
virtual void update(double dt);
virtual bool ToggleDataLogging(bool state) { return false; }
virtual bool ToggleDataLogging(void) { return false; }
@ -443,17 +446,17 @@ public:
void common_init();
// time and update management values
inline double get_delta_t() const { return delta_t; }
inline void set_delta_t( double dt ) { delta_t = dt; }
inline SGTimeStamp get_time_stamp() const { return time_stamp; }
inline void set_time_stamp( SGTimeStamp s ) { time_stamp = s; }
inline void stamp() { time_stamp.stamp(); }
inline long get_elapsed() const { return elapsed; }
inline void set_elapsed( long e ) { elapsed = e; }
inline long get_remainder() const { return remainder; }
inline void set_remainder( long r ) { remainder = r; }
inline int get_multi_loop() const { return multi_loop; }
inline void set_multi_loop( int ml ) { multi_loop = ml; }
// inline double get_delta_t() const { return delta_t; }
// inline void set_delta_t( double dt ) { delta_t = dt; }
// inline SGTimeStamp get_time_stamp() const { return time_stamp; }
// inline void set_time_stamp( SGTimeStamp s ) { time_stamp = s; }
// inline void stamp() { time_stamp.stamp(); }
// inline long get_elapsed() const { return elapsed; }
// inline void set_elapsed( long e ) { elapsed = e; }
// inline long get_remainder() const { return remainder; }
// inline void set_remainder( long r ) { remainder = r; }
// inline int get_multi_loop() const { return multi_loop; }
// inline void set_multi_loop( int ml ) { multi_loop = ml; }
// Positions
virtual void set_Latitude(double lat); // geocentric

View file

@ -217,7 +217,7 @@ FGInput::unbind ()
}
void
FGInput::update (int dt)
FGInput::update (double dt)
{
_update_keyboard();
_update_joystick();

View file

@ -191,7 +191,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
/**

View file

@ -265,9 +265,9 @@ setAircraftDir (const char * dir)
* Return the number of milliseconds elapsed since simulation started.
*/
static double
getElapsedTime_ms ()
getElapsedTime_sec ()
{
return globals->get_sim_time_ms();
return globals->get_sim_time_sec();
}
@ -580,7 +580,7 @@ fgInitProps ()
fgTie("/sim/freeze/master", getFreeze, setFreeze);
fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
fgTie("/sim/time/elapsed-ms", getElapsedTime_ms);
fgTie("/sim/time/elapsed-sec", getElapsedTime_sec);
fgTie("/sim/time/gmt", getDateString, setDateString);
fgSetArchivable("/sim/time/gmt");
fgTie("/sim/time/gmt-string", getGMTString);

View file

@ -3,6 +3,7 @@
#include <simgear/debug/logstream.hxx>
#include "globals.hxx"
#include "fg_props.hxx"
@ -11,10 +12,39 @@
////////////////////////////////////////////////////////////////////////
FGSubsystem::~FGSubsystem ()
FGSubsystem::FGSubsystem ()
: _suspended(false)
{
// NO-OP
}
FGSubsystem::~FGSubsystem ()
{
}
void
FGSubsystem::suspend ()
{
_suspended = true;
}
void
FGSubsystem::suspend (bool suspended)
{
_suspended = suspended;
}
void
FGSubsystem::resume ()
{
_suspended = false;
}
bool
FGSubsystem::is_suspended () const
{
if (!_freeze_master_node.valid())
_freeze_master_node = fgGetNode("/sim/freeze/master", true);
return _suspended || _freeze_master_node->getBoolValue();
}
// end of fgfs.cxx

View file

@ -38,6 +38,8 @@
# include <float.h>
#endif
#include <simgear/misc/props.hxx>
/**
@ -91,7 +93,7 @@
* _errorNode = fgGetNode("/display/error-margin-pct", true);
* }
*
* void MySubsystem::update ()
* void MySubsystem::update (double delta_time_sec)
* {
* do_something(_errorNode.getFloatValue());
* }
@ -100,11 +102,23 @@
* <p>The node returned will always be a pointer to SGPropertyNode,
* and the subsystem should <em>not</em> delete it in its destructor
* (the pointer belongs to the property tree, not the subsystem).</p>
*
* <p>The program may ask the subsystem to suspend or resume
* sim-time-dependent operations; by default, the suspend() and
* resume() methods set the protected variable <var>_suspended</var>,
* which the subsystem can reference in its update() method, but
* subsystems may also override the suspend() and resume() methods to
* take different actions.</p>
*/
class FGSubsystem
{
public:
/**
* Default constructor.
*/
FGSubsystem ();
/**
* Virtual destructor to ensure that subclass destructors are called.
*/
@ -147,10 +161,61 @@ public:
* Update the subsystem.
*
* <p>FlightGear invokes this method every time the subsystem should
* update its state. If the subsystem requires delta time information,
* it should track it itself.</p>
* update its state.</p>
*
* @param delta_time_sec The delta time, in seconds, since the last
* update. On first update, delta time will be 0.
*/
virtual void update (int dt) = 0;
virtual void update (double delta_time_sec) = 0;
/**
* Suspend operation of this subsystem.
*
* <p>This method instructs the subsystem to suspend
* sim-time-dependent operations until asked to resume. The update
* method will still be invoked so that the subsystem can take any
* non-time-dependent actions, such as updating the display.</p>
*
* <p>It is not an error for the suspend method to be invoked when
* the subsystem is already suspended; the invocation should simply
* be ignored.</p>
*/
virtual void suspend ();
/**
* Suspend or resum operation of this subsystem.
*
* @param suspended true if the subsystem should be suspended, false
* otherwise.
*/
virtual void suspend (bool suspended);
/**
* Resume operation of this subsystem.
*
* <p>This method instructs the subsystem to resume
* sim-time-depended operations. It is not an error for the resume
* method to be invoked when the subsystem is not suspended; the
* invocation should simply be ignored.</p>
*/
virtual void resume ();
/**
* Test whether this subsystem is suspended.
*
* @return true if the subsystem is suspended, false if it is not.
*/
virtual bool is_suspended () const;
protected:
mutable SGPropertyNode_ptr _freeze_master_node;
bool _suspended;
};

View file

@ -42,7 +42,7 @@ FGGlobals *globals;
// Constructor
FGGlobals::FGGlobals() :
sim_time_ms(0.0),
sim_time_sec(0.0),
#if defined(FX) && defined(XMESA)
fullscreen( true ),
#endif

View file

@ -80,7 +80,7 @@ class FGGlobals
private:
// Number of milliseconds elapsed since the start of the program.
double sim_time_ms;
double sim_time_sec;
// Root of FlightGear data tree
string fg_root;
@ -174,9 +174,9 @@ public:
FGGlobals();
~FGGlobals();
inline double get_sim_time_ms () const { return sim_time_ms; }
inline void inc_sim_time_ms (double dt) { sim_time_ms += dt; }
inline void set_sim_time_ms (double t) { sim_time_ms = t; }
inline double get_sim_time_sec () const { return sim_time_sec; }
inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
inline void set_sim_time_sec (double t) { sim_time_sec = t; }
inline const string &get_fg_root () const { return fg_root; }
inline void set_fg_root (const string &root) { fg_root = root; }

View file

@ -77,13 +77,13 @@ FGLogger::unbind ()
}
void
FGLogger::update (int dt)
FGLogger::update (double dt)
{
double sim_time_ms = globals->get_sim_time_ms();
double sim_time_ms = globals->get_sim_time_sec() * 1000;
for (unsigned int i = 0; i < _logs.size(); i++) {
if ((sim_time_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) {
_logs[i].last_time_ms = sim_time_ms;
(*_logs[i].output) << globals->get_sim_time_ms();
(*_logs[i].output) << sim_time_ms;
for (unsigned int j = 0; j < _logs[i].nodes.size(); j++) {
(*_logs[i].output) << _logs[i].delimiter
<< _logs[i].nodes[j]->getStringValue();

View file

@ -44,7 +44,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
private:

View file

@ -148,6 +148,8 @@ sgVec3 rway_ols;
float scene_nearplane = 0.5f;
float scene_farplane = 120000.0f;
static double delta_time_sec = 0;
#ifndef FG_NEW_ENVIRONMENT
# include <WeatherCM/FGLocalWeatherDatabase.h>
@ -391,16 +393,10 @@ void trRenderFrame( void ) {
// Update all Visuals (redraws anything graphics related)
void fgRenderFrame( void ) {
void fgRenderFrame() {
// Update the elapsed time.
current_time_stamp.stamp();
int dt_ms = (current_time_stamp - last_time_stamp) / 1000L;
globals->inc_sim_time_ms( dt_ms );
last_time_stamp = current_time_stamp;
// Process/manage pending events
global_events.update( dt_ms );
global_events.update( delta_time_sec );
static const SGPropertyNode *longitude
= fgGetNode("/position/longitude-deg");
@ -442,7 +438,7 @@ void fgRenderFrame( void ) {
fgSplashUpdate(0.0);
}
// Keep resetting sim time while the sim is initializing
globals->set_sim_time_ms( 0.0 );
globals->set_sim_time_sec( 0.0 );
} else {
// idle_state is now 1000 meaning we've finished all our
// initializations and are running the main loop, so this will
@ -722,21 +718,21 @@ void fgRenderFrame( void ) {
// glDisable( GL_TEXTURE_2D );
// update the input subsystem
current_input.update(dt_ms);
current_input.update(delta_time_sec);
// update the controls subsystem
globals->get_controls()->update(dt_ms);
globals->get_controls()->update(delta_time_sec);
hud_and_panel->apply();
fgCockpitUpdate();
// Use the hud_and_panel ssgSimpleState for rendering the ATC output
// This only works properly if called before the panel call
globals->get_ATC_display()->update(dt_ms);
globals->get_ATC_display()->update(delta_time_sec);
// update the panel subsystem
if ( current_panel != NULL ) {
current_panel->update(dt_ms);
current_panel->update(delta_time_sec);
}
// We can do translucent menus, so why not. :-)
@ -747,7 +743,7 @@ void fgRenderFrame( void ) {
// glEnable( GL_FOG );
globals->get_logger()->update(dt_ms);
globals->get_logger()->update(delta_time_sec);
}
glutSwapBuffers();
@ -787,51 +783,45 @@ void fgUpdateTimeDepCalcs() {
// instance ...
if ( !cur_fdm_state->get_inited() ) {
// do nothing, fdm isn't inited yet
} else if ( master_freeze->getBoolValue() ) {
// we are frozen, run the fdm's with 0 time slices in case
// they want to do something with that.
cur_fdm_state->update( 0 );
FGSteam::update( 0 );
} else {
// we have been inited, and we are not frozen, we are good to go ...
// we have been inited, and we are good to go ...
if ( !inited ) {
cur_fdm_state->stamp();
// cur_fdm_state->stamp();
inited = true;
}
SGTimeStamp current;
current.stamp();
long elapsed = current - cur_fdm_state->get_time_stamp();
cur_fdm_state->set_time_stamp( current );
elapsed += cur_fdm_state->get_remainder();
// cout << "elapsed = " << elapsed << endl;
// cout << "dt = " << cur_fdm_state->get_delta_t() << endl;
multi_loop = (long)(((double)elapsed * 0.000001) /
cur_fdm_state->get_delta_t() );
cur_fdm_state->set_multi_loop( multi_loop );
long remainder = elapsed - (long)( (multi_loop*1000000) *
cur_fdm_state->get_delta_t() );
cur_fdm_state->set_remainder( remainder );
// cout << "remainder = " << remainder << endl;
// SGTimeStamp current;
// current.stamp();
// long elapsed = current - cur_fdm_state->get_time_stamp();
// cur_fdm_state->set_time_stamp( current );
// elapsed += cur_fdm_state->get_remainder();
// // cout << "elapsed = " << elapsed << endl;
// // cout << "dt = " << cur_fdm_state->get_delta_t() << endl;
// multi_loop = (long)(((double)elapsed * 0.000001) /
// cur_fdm_state->get_delta_t() );
// cur_fdm_state->set_multi_loop( multi_loop );
// long remainder = elapsed - (long)( (multi_loop*1000000) *
// cur_fdm_state->get_delta_t() );
// cur_fdm_state->set_remainder( remainder );
// // cout << "remainder = " << remainder << endl;
// chop max interations to something reasonable if the sim was
// delayed for an excesive amount of time
if ( multi_loop > 2.0 / cur_fdm_state->get_delta_t() ) {
multi_loop = (int)(2.0 / cur_fdm_state->get_delta_t());
cur_fdm_state->set_remainder( 0 );
}
// // chop max interations to something reasonable if the sim was
// // delayed for an excesive amount of time
// if ( multi_loop > 2.0 / cur_fdm_state->get_delta_t() ) {
// multi_loop = (int)(2.0 / cur_fdm_state->get_delta_t());
// cur_fdm_state->set_remainder( 0 );
// }
// cout << "multi_loop = " << multi_loop << endl;
for ( i = 0; i < multi_loop * fgGetInt("/sim/speed-up"); ++i ) {
// run Autopilot system
globals->get_autopilot()->update(0); // FIXME: use real dt
// // cout << "multi_loop = " << multi_loop << endl;
// for ( i = 0; i < multi_loop * fgGetInt("/sim/speed-up"); ++i ) {
// // run Autopilot system
globals->get_autopilot()->update(delta_time_sec);
// update FDM
cur_fdm_state->update( 1 );
}
FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") );
cur_fdm_state->update(delta_time_sec);
// }
FGSteam::update(delta_time_sec);
}
if ( !strcmp(fgGetString("/sim/view-mode"), "pilot") ) {
@ -840,11 +830,11 @@ void fgUpdateTimeDepCalcs() {
}
globals->get_model_mgr()->update(multi_loop);
globals->get_aircraft_model()->update(multi_loop);
globals->get_model_mgr()->update(delta_time_sec);
globals->get_aircraft_model()->update(delta_time_sec);
// update the view angle
globals->get_viewmgr()->update(multi_loop);
globals->get_viewmgr()->update(delta_time_sec);
l->UpdateAdjFog();
@ -854,7 +844,7 @@ void fgUpdateTimeDepCalcs() {
cur_fdm_state->get_Latitude() );
// Update radio stack model
current_radiostack->update(multi_loop);
current_radiostack->update(delta_time_sec);
}
@ -870,6 +860,13 @@ static const double alt_adjust_m = alt_adjust_ft * SG_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 ) {
// Update the elapsed time.
current_time_stamp.stamp();
delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
last_time_stamp = current_time_stamp;
globals->inc_sim_time_sec( delta_time_sec );
static const SGPropertyNode *longitude
= fgGetNode("/position/longitude-deg");
static const SGPropertyNode *latitude
@ -1035,10 +1032,10 @@ static void fgMainLoop( void ) {
#endif
// Run ATC subsystem
globals->get_ATC_mgr()->update(1); // FIXME - use real dt.
globals->get_ATC_mgr()->update(delta_time_sec);
// Run the AI subsystem
// globals->get_AI_mgr()->update(1); // FIXME - use real dt.
// globals->get_AI_mgr()->update(delta_time_sec);
// Run flight model

View file

@ -722,10 +722,11 @@ FGViewer::get_v_fov()
}
void
FGViewer::update (int dt)
FGViewer::update (double dt)
{
int i;
for ( i = 0; i < dt; i++ ) {
int dt_ms = int(dt * 1000);
for ( i = 0; i < dt_ms; i++ ) {
if ( fabs( _goal_heading_offset_deg - _heading_offset_deg) < 1 ) {
setHeadingOffset_deg( _goal_heading_offset_deg );
break;
@ -754,7 +755,7 @@ FGViewer::update (int dt)
}
}
for ( i = 0; i < dt; i++ ) {
for ( i = 0; i < dt_ms; i++ ) {
if ( fabs( _goal_pitch_offset_deg - _pitch_offset_deg ) < 1 ) {
setPitchOffset_deg( _goal_pitch_offset_deg );
break;

View file

@ -76,7 +76,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
void update (int dt);
void update (double dt);
//////////////////////////////////////////////////////////////////////

View file

@ -172,7 +172,7 @@ FGViewMgr::unbind ()
}
void
FGViewMgr::update (int dt)
FGViewMgr::update (double dt)
{
char stridx [20];
double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;

View file

@ -59,7 +59,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
// getters
inline int size() const { return views.size(); }

View file

@ -70,7 +70,7 @@ FGAircraftModel::unbind ()
}
void
FGAircraftModel::update (int dt)
FGAircraftModel::update (double dt)
{
int view_number = globals->get_viewmgr()->get_current();

View file

@ -34,7 +34,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
virtual void draw ();
virtual FG3DModel * get3DModel() { return _aircraft; }

View file

@ -242,7 +242,7 @@ FG3DModel::init (const string &path)
}
void
FG3DModel::update (int dt)
FG3DModel::update (double dt)
{
unsigned int i;
@ -412,7 +412,7 @@ FG3DModel::NullAnimation::init (ssgEntity * object,
}
void
FG3DModel::NullAnimation::update (int dt)
FG3DModel::NullAnimation::update (double dt)
{
}
@ -445,7 +445,7 @@ FG3DModel::RangeAnimation::init (ssgEntity * object,
}
void
FG3DModel::RangeAnimation::update (int dt)
FG3DModel::RangeAnimation::update (double dt)
{
}
@ -477,7 +477,7 @@ FG3DModel::BillboardAnimation::init (ssgEntity * object,
}
void
FG3DModel::BillboardAnimation::update (int dt)
FG3DModel::BillboardAnimation::update (double dt)
{
}
@ -512,7 +512,7 @@ FG3DModel::SelectAnimation::init (ssgEntity * object,
}
void
FG3DModel::SelectAnimation::update (int dt)
FG3DModel::SelectAnimation::update (double dt)
{
if (_condition != 0 && _condition->test())
_selector->select(0xffff);
@ -559,9 +559,9 @@ FG3DModel::SpinAnimation::init (ssgEntity * object,
}
void
FG3DModel::SpinAnimation::update (int dt)
FG3DModel::SpinAnimation::update (double dt)
{
float velocity_rpms = (_prop->getDoubleValue() * _factor / 60000.0);
float velocity_rpms = (_prop->getDoubleValue() * _factor / 60.0);
_position_deg += (dt * velocity_rpms * 360);
while (_position_deg < 0)
_position_deg += 360.0;
@ -627,7 +627,7 @@ FG3DModel::RotateAnimation::init (ssgEntity * object,
}
void
FG3DModel::RotateAnimation::update (int dt)
FG3DModel::RotateAnimation::update (double dt)
{
if (_table == 0) {
_position_deg = (_prop->getDoubleValue() + _offset_deg) * _factor;
@ -695,7 +695,7 @@ FG3DModel::TranslateAnimation::init (ssgEntity * object,
}
void
FG3DModel::TranslateAnimation::update (int dt)
FG3DModel::TranslateAnimation::update (double dt)
{
if (_table == 0) {
_position_m = (_prop->getDoubleValue() + _offset_m) * _factor;

View file

@ -47,7 +47,7 @@ public:
virtual ~FG3DModel ();
virtual void init (const string &path);
virtual void update (int dt);
virtual void update (double dt);
virtual bool getVisible () const;
virtual void setVisible (bool visible);
@ -130,9 +130,9 @@ private:
/**
* Update the animation.
*
* @param dt The elapsed time in milliseconds since the last call.
* @param dt The elapsed time in seconds since the last call.
*/
virtual void update (int dt) = 0;
virtual void update (double dt) = 0;
};
@ -146,7 +146,7 @@ private:
NullAnimation ();
virtual ~NullAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
virtual void update (double dt);
private:
ssgBranch * _branch;
};
@ -161,7 +161,7 @@ private:
RangeAnimation ();
virtual ~RangeAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
virtual void update (double dt);
private:
ssgRangeSelector * _branch;
};
@ -176,7 +176,7 @@ private:
BillboardAnimation ();
virtual ~BillboardAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
virtual void update (double dt);
private:
ssgCutout * _branch;
};
@ -191,7 +191,7 @@ private:
SelectAnimation ();
virtual ~SelectAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
virtual void update (double dt);
private:
FGCondition * _condition;
ssgSelector * _selector;
@ -209,7 +209,7 @@ private:
SpinAnimation ();
virtual ~SpinAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
virtual void update (double dt);
private:
SGPropertyNode * _prop;
double _factor;
@ -232,7 +232,7 @@ private:
RotateAnimation ();
virtual ~RotateAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
virtual void update (double dt);
private:
SGPropertyNode * _prop;
double _offset_deg;
@ -259,7 +259,7 @@ private:
TranslateAnimation ();
virtual ~TranslateAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
virtual void update (int dt);
virtual void update (double dt);
private:
SGPropertyNode * _prop;
double _offset_m;

View file

@ -97,7 +97,7 @@ FGModelMgr::unbind ()
}
void
FGModelMgr::update (int dt)
FGModelMgr::update (double dt)
{
for (int i = 0; i < _instances.size(); i++) {
Instance * instance = _instances[i];

View file

@ -36,7 +36,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
virtual void draw ();

View file

@ -61,7 +61,7 @@ FGScenery::~FGScenery() {
void FGScenery::init() {
}
void FGScenery::update(int dt) {
void FGScenery::update(double dt) {
}
void FGScenery::bind() {

View file

@ -67,7 +67,7 @@ public:
void init ();
void bind ();
void unbind ();
void update (int dt);
void update (double dt);
inline double get_cur_elev() const { return cur_elev; }
inline void set_cur_elev( double e ) { cur_elev = e; }

View file

@ -95,7 +95,7 @@ FGFX::unbind ()
}
void
FGFX::update (int dt)
FGFX::update (double dt)
{
for (unsigned int i = 0; i < _sound.size(); i++ )
_sound[i]->update(dt);

View file

@ -47,7 +47,7 @@ public:
virtual void init ();
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
private:

View file

@ -251,7 +251,7 @@ FGSound::unbind ()
}
void
FGSound::update (int dt)
FGSound::update (double dt)
{
double curr_value = 0.0;

View file

@ -48,7 +48,7 @@ public:
virtual void init (SGPropertyNode *);
virtual void bind ();
virtual void unbind ();
virtual void update (int dt);
virtual void update (double dt);
protected:

View file

@ -191,7 +191,8 @@ void FGSoundMgr::unbind ()
// run the audio scheduler
void FGSoundMgr::update(int dt) {
void FGSoundMgr::update(double dt) {
// FIXME: use dt supplied (seconds)
SGTimeStamp current;
current.stamp();

View file

@ -144,7 +144,7 @@ public:
/**
* Run the audio scheduler.
*/
void update(int dt);
void update(double dt);
/**

View file

@ -142,9 +142,11 @@ FGEventMgr::unbind()
}
void
FGEventMgr::update( int dt )
FGEventMgr::update( double dt )
{
if (dt < 0)
int dt_ms = int(dt * 1000);
if (dt_ms < 0)
{
SG_LOG( SG_GENERAL, SG_ALERT,
"FGEventMgr::update() called with negative delta T" );
@ -159,7 +161,7 @@ FGEventMgr::update( int dt )
// Scan all events. Run one whose interval has expired.
while (first != last)
{
if (first->update( dt ))
if (first->update( dt_ms ))
{
if (first->value() < min_value)
{

View file

@ -129,9 +129,9 @@ public:
/*
* Update the elapsed time for all events.
* @param dt elapsed time in milliseconds.
* @param dt elapsed time in seconds.
*/
void update( int dt );
void update( double dt );
/**
* Register a free standing function to be executed some time in the future.