}
// 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
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.
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.
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);
void
-FGAutopilot::update (int dt)
+FGAutopilot::update (double dt)
{
// Remove the following lines when the calling funcitons start
// passing in the data pointer
void init ();
void bind ();
void unbind ();
- void update (int dt);
+ void update (double dt);
// Reset the autopilot system
void reset(void);
* Update the panel.
*/
void
-FGPanel::update (int dt)
+FGPanel::update (double dt)
{
// TODO: cache the nodes
_visibility = fgGetBool("/sim/panel/visibility");
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!!!
blink.stamp();
search();
- update(1); // FIXME: use dt
+ update(0); // FIXME: use dt
// Search radio database once per second
global_events.Register( "fgRadioSearch()",
// 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;
void init ();
void bind ();
void unbind ();
- void update (int dt);
+ void update (double dt);
// Update nav/adf radios based on current postition
void search ();
// 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);
{
public:
- static void update ( int timesteps );
+ static void update ( double dt );
// Position
static double get_ALT_ft ();
void
-FGControls::update (int dt)
+FGControls::update (double dt)
{
}
void init ();
void bind ();
void unbind ();
- void update (int dt);
+ void update (double dt);
// Reset function
void reset_all(void);
}
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();
virtual double getElevationFt () const { return _elev_ft; }
virtual void init () = 0;
- virtual void update (int dt) = 0;
+ virtual void update (double dt) = 0;
protected:
virtual ~FGUserDefEnvironmentCtrl ();
virtual void init ();
- virtual void update (int dt);
+ virtual void update (double dt);
private:
}
void
-FGEnvironmentMgr::update (int dt)
+FGEnvironmentMgr::update (double dt)
{
_controller->update(dt);
// FIXME: the FDMs should update themselves
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.
FGADA::FGADA( double dt ) {
- set_delta_t( dt );
+// set_delta_t( dt );
}
// 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];
void init();
// update position based on inputs, positions, velocities, etc.
- void update(int dt);
+ void update(double dt);
};
// 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();
void init();
// update position based on inputs, positions, velocities, etc.
- void update( int multiloop );
+ void update( double dt );
};
FGExternal::FGExternal( double dt ) {
- set_delta_t( dt );
+// set_delta_t( dt );
}
// 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"))
void init();
// update position based on inputs, positions, velocities, etc.
- void update( int multiloop );
+ void update( double dt );
};
FGExternalNet::FGExternalNet( double dt, string host, int dop, int dip, int cp )
{
- set_delta_t( dt );
+// set_delta_t( dt );
valid = true;
// 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 );
void init();
// update the fdm
- void update( int multiloop );
+ void update( 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(),
// 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;
/** 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);
#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);
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)
}
// 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
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();
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
FGMagicCarpet::FGMagicCarpet( double dt ) {
- set_delta_t( dt );
+// set_delta_t( dt );
}
// 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
void init();
// update position based on inputs, positions, velocities, etc.
- void update( int multiloop );
+ void update( double dt );
};
FGNullFDM::FGNullFDM( double dt ) {
- set_delta_t( dt );
+// set_delta_t( dt );
}
// 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;
}
void init();
// update position based on inputs, positions, velocities, etc.
- void update( int multiloop );
+ void update( double dt );
};
Aileron(0.0),
Elevator(0.0)
{
- set_delta_t( dt );
+// set_delta_t( dt );
}
// 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 );
void init();
// update position based on inputs, positions, velocities, etc.
- void update( int multiloop );
+ void update( double dt );
};
YASim::YASim(double dt)
{
- set_delta_t(dt);
+// set_delta_t(dt);
_fdm = new FGFDM();
_dt = dt;
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;
virtual void bind();
// Run an iteration
- virtual void update(int iterations);
+ virtual void update(double dt);
private:
void report();
FGInterface::FGInterface( double dt ) {
_setup();
- delta_t = dt;
- remainder = elapsed = multi_loop = 0;
+// delta_t = dt;
+// remainder = elapsed = multi_loop = 0;
+ remainder = 0;
}
// Destructor
}
+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.
*
set_inited( true );
- stamp();
- set_remainder( 0 );
+// stamp();
+// set_remainder( 0 );
// Set initial position
SG_LOG( SG_FLIGHT, SG_INFO, "...initializing position..." );
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,
* 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!");
}
#include <string>
#include <simgear/constants.h>
-#include <simgear/timing/timestamp.hxx>
+// #include <simgear/timing/timestamp.hxx>
#include <Main/fgfs.hxx>
// 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;
// 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
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; }
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
}
void
-FGInput::update (int dt)
+FGInput::update (double dt)
{
_update_keyboard();
_update_joystick();
virtual void init ();
virtual void bind ();
virtual void unbind ();
- virtual void update (int dt);
+ virtual void update (double dt);
/**
* 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();
}
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);
#include <simgear/debug/logstream.hxx>
#include "globals.hxx"
+#include "fg_props.hxx"
\f
////////////////////////////////////////////////////////////////////////
+FGSubsystem::FGSubsystem ()
+ : _suspended(false)
+{
+}
+
FGSubsystem::~FGSubsystem ()
{
- // NO-OP
}
+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
# include <float.h>
#endif
+#include <simgear/misc/props.hxx>
+
\f
/**
* _errorNode = fgGetNode("/display/error-margin-pct", true);
* }
*
- * void MySubsystem::update ()
+ * void MySubsystem::update (double delta_time_sec)
* {
* do_something(_errorNode.getFloatValue());
* }
* <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.
*/
* 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 (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 update (int dt) = 0;
+ 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;
};
// Constructor
FGGlobals::FGGlobals() :
- sim_time_ms(0.0),
+ sim_time_sec(0.0),
#if defined(FX) && defined(XMESA)
fullscreen( true ),
#endif
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;
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; }
}
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();
virtual void init ();
virtual void bind ();
virtual void unbind ();
- virtual void update (int dt);
+ virtual void update (double dt);
private:
float scene_nearplane = 0.5f;
float scene_farplane = 120000.0f;
+static double delta_time_sec = 0;
+
#ifndef FG_NEW_ENVIRONMENT
# include <WeatherCM/FGLocalWeatherDatabase.h>
// 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");
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
// 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. :-)
// glEnable( GL_FOG );
- globals->get_logger()->update(dt_ms);
+ globals->get_logger()->update(delta_time_sec);
}
glutSwapBuffers();
// 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;
-
- // 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
+// 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 );
+// }
+
+// // 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") ) {
}
- 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();
cur_fdm_state->get_Latitude() );
// Update radio stack model
- current_radiostack->update(multi_loop);
+ current_radiostack->update(delta_time_sec);
}
// 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
#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
}
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;
}
}
- 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;
virtual void init ();
virtual void bind ();
virtual void unbind ();
- void update (int dt);
+ void update (double dt);
//////////////////////////////////////////////////////////////////////
}
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;
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(); }
}
void
-FGAircraftModel::update (int dt)
+FGAircraftModel::update (double dt)
{
int view_number = globals->get_viewmgr()->get_current();
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; }
}
void
-FG3DModel::update (int dt)
+FG3DModel::update (double dt)
{
unsigned int i;
}
void
-FG3DModel::NullAnimation::update (int dt)
+FG3DModel::NullAnimation::update (double dt)
{
}
}
void
-FG3DModel::RangeAnimation::update (int dt)
+FG3DModel::RangeAnimation::update (double dt)
{
}
}
void
-FG3DModel::BillboardAnimation::update (int dt)
+FG3DModel::BillboardAnimation::update (double dt)
{
}
}
void
-FG3DModel::SelectAnimation::update (int dt)
+FG3DModel::SelectAnimation::update (double dt)
{
if (_condition != 0 && _condition->test())
_selector->select(0xffff);
}
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;
}
void
-FG3DModel::RotateAnimation::update (int dt)
+FG3DModel::RotateAnimation::update (double dt)
{
if (_table == 0) {
_position_deg = (_prop->getDoubleValue() + _offset_deg) * _factor;
}
void
-FG3DModel::TranslateAnimation::update (int dt)
+FG3DModel::TranslateAnimation::update (double dt)
{
if (_table == 0) {
_position_m = (_prop->getDoubleValue() + _offset_m) * _factor;
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);
/**
* 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;
};
NullAnimation ();
virtual ~NullAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
- virtual void update (int dt);
+ virtual void update (double dt);
private:
ssgBranch * _branch;
};
RangeAnimation ();
virtual ~RangeAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
- virtual void update (int dt);
+ virtual void update (double dt);
private:
ssgRangeSelector * _branch;
};
BillboardAnimation ();
virtual ~BillboardAnimation ();
virtual void init (ssgEntity * object, SGPropertyNode * props);
- virtual void update (int dt);
+ virtual void update (double dt);
private:
ssgCutout * _branch;
};
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;
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;
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;
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;
}
void
-FGModelMgr::update (int dt)
+FGModelMgr::update (double dt)
{
for (int i = 0; i < _instances.size(); i++) {
Instance * instance = _instances[i];
virtual void init ();
virtual void bind ();
virtual void unbind ();
- virtual void update (int dt);
+ virtual void update (double dt);
virtual void draw ();
void FGScenery::init() {
}
-void FGScenery::update(int dt) {
+void FGScenery::update(double dt) {
}
void FGScenery::bind() {
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; }
}
void
-FGFX::update (int dt)
+FGFX::update (double dt)
{
for (unsigned int i = 0; i < _sound.size(); i++ )
_sound[i]->update(dt);
virtual void init ();
virtual void bind ();
virtual void unbind ();
- virtual void update (int dt);
+ virtual void update (double dt);
private:
}
void
-FGSound::update (int dt)
+FGSound::update (double dt)
{
double curr_value = 0.0;
virtual void init (SGPropertyNode *);
virtual void bind ();
virtual void unbind ();
- virtual void update (int dt);
+ virtual void update (double dt);
protected:
// run the audio scheduler
-void FGSoundMgr::update(int dt) {
+void FGSoundMgr::update(double dt) {
+ // FIXME: use dt supplied (seconds)
SGTimeStamp current;
current.stamp();
/**
* Run the audio scheduler.
*/
- void update(int dt);
+ void update(double dt);
/**
}
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" );
// 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)
{
/*
* 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.