char Buffer[numberofbytes];
- // set valid time for this record
- stamp_time();
-
printf("\nInitialising UDP sockets\n");
// initialise a "udp" socket
fdmsock = new SGSocket( "reddy_pc", "5001", "udp" );
// for each subsequent iteration through the EOM
void FGExternal::init() {
// cout << "FGExternal::init()" << endl;
-
- // set valid time for this record
- stamp_time();
}
FGLaRCsim::FGLaRCsim( double dt ) {
set_delta_t( dt );
+ cout << "dt = " << get_delta_t() << endl;
ls_toplevel_init( 0.0,
(char *)fgGetString("/sim/aircraft").c_str() );
if ( save_alt < -9000.0 ) {
set_Altitude( save_alt );
}
-
- // set valid time for this record
- stamp_time();
}
// Initialize the Magic Carpet flight model, dt is the time increment
// for each subsequent iteration through the EOM
void FGMagicCarpet::init() {
- // set valid time for this record
- stamp_time();
}
{
// Time management
fgTie("/fdm/time/delta_t", this,
- &(FGInterface::get_delta_t),
- &(FGInterface::set_delta_t));
+ &(FGInterface::get_delta_t));
// The following two can't be uncommented until we have support for
// the "long" data type in the property manager
/* fgTie("/fdm/time/elapsed", this,
- &(FGInterface::get_elapsed),
- &(FGInterface::set_elapsed));
+ &(FGInterface::get_elapsed));
fgTie("/fdm/time/remainder", this,
- &(FGInterface::get_remainder),
- &(FGInterface::set_remainder)); */
+ &(FGInterface::get_remainder); */
fgTie("/fdm/time/multi_loop", this,
- &(FGInterface::get_multi_loop),
- &(FGInterface::set_multi_loop));
+ &(FGInterface::get_multi_loop));
// Aircraft position
fgTie("/position/latitude", this,
// 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
// Engine list
engine_list engines;
- SGTimeStamp valid_stamp; // time this record is valid
- SGTimeStamp next_stamp; // time this record is valid
+ // SGTimeStamp valid_stamp; // time this record is valid
+ // SGTimeStamp next_stamp; // time this record is valid
protected:
- void _busdump(void);
+ void _busdump(void);
void _updatePosition( double lat_geoc, double lon, double alt );
void _updateWeather( void );
// 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 double get_Climb_Rate() const { return climb_rate; }
- inline SGTimeStamp get_time_stamp() const { return valid_stamp; }
- inline void stamp_time() { valid_stamp = next_stamp; next_stamp.stamp(); }
+ // inline SGTimeStamp get_time_stamp() const { return valid_stamp; }
+ // inline void stamp_time() { valid_stamp = next_stamp; next_stamp.stamp(); }
// Extrapolate FDM based on time_offset (in usec)
void extrapolate( int time_offset );
scenery.cur_elev );
double dt = 1.0 / fgGetInt("/sim/model-hz");
+ // cout << "dt = " << dt << endl;
const string &model = fgGetString("/sim/flight-model");
if (model == "larcsim") {
<< ", can't init aircraft");
exit(-1);
}
+ cur_fdm_state->stamp();
+ cur_fdm_state->set_remainder( 0 );
// allocates structures so must happen before any of the flight
// model or control parameters are set
// Update internal time dependent calculations (i.e. flight model)
-void fgUpdateTimeDepCalcs(int multi_loop, int remainder) {
- static fdm_state_list fdm_list;
+void fgUpdateTimeDepCalcs() {
fgLIGHT *l = &cur_light_params;
int i;
- // update the flight model
- if ( multi_loop < 0 ) {
- multi_loop = 1;
- }
+ int multi_loop = 1;
if ( !globals->get_freeze() && !initial_freeze ) {
- // run Autopilot system
- current_autopilot->run();
-
- cur_fdm_state->update( multi_loop *
- fgGetInt("/sim/speed-up") );
+ 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 = (int)(((double)elapsed * 0.000001) /
+ cur_fdm_state->get_delta_t() );
+ cur_fdm_state->set_multi_loop( multi_loop );
+ long remainder = elapsed - ( (multi_loop*1000000) *
+ cur_fdm_state->get_delta_t() );
+ cur_fdm_state->set_remainder( remainder );
+
+ // cout << "multi_loop = " << multi_loop << endl;
+ for ( i = 0; i < multi_loop; ++i ) {
+ // run Autopilot system
+ current_autopilot->run();
+
+ // update autopiot
+ cur_fdm_state->update( 1 * fgGetInt("/sim/speed-up") );
+ }
FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") );
} else {
cur_fdm_state->update( 0 );
}
}
- fdm_list.push_back( *cur_fdm_state );
- while ( fdm_list.size() > 15 ) {
- fdm_list.pop_front();
- }
-
if ( fgGetString("/sim/view-mode") == "pilot" ) {
cur_view_fdm = *cur_fdm_state;
// do nothing
- } else if ( fgGetString("/sim/view-mode") == "follow" )
- {
- cur_view_fdm = fdm_list.front();
}
// update the view angle
// flight model
if ( global_multi_loop > 0 ) {
- fgUpdateTimeDepCalcs(global_multi_loop, remainder);
+ fgUpdateTimeDepCalcs();
} else {
FG_LOG( FG_ALL, FG_DEBUG,
"Elapsed time is zero ... we're zinging" );
void fgLoadDCS(void) {
- ssgEntity *ship_obj;
- double bz[3];
- int j=0;
+ ssgEntity *ship_obj = NULL;
+ // double bz[3];
+ // int j=0;
char obj_filename[25];
for (int k=0;k<32;k++)
void fgUpdateDCS (void) {
- double eye_lat,eye_lon,eye_alt;
- static double obj_head;
+ // double eye_lat,eye_lon,eye_alt;
+ // static double obj_head;
double sl_radius,obj_latgc;
- float nresultmat[4][4];
- sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
+ // float nresultmat[4][4];
+ // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
double bz[3];
// Instantaneous Geodetic Lat/Lon/Alt of moving object