X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAircraft%2Freplay.cxx;h=84663cc9328060989f7103b520b41c147b663834;hb=1ae2b59333dc914d10bcc726bc94e71cbf3e411e;hp=e650a8b315856d06396d523797705a4f89a0ac83;hpb=0e48d96118c39ac739e3151bc2b34ae6014ecb29;p=flightgear.git diff --git a/src/Aircraft/replay.cxx b/src/Aircraft/replay.cxx index e650a8b31..84663cc93 100644 --- a/src/Aircraft/replay.cxx +++ b/src/Aircraft/replay.cxx @@ -16,10 +16,13 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include @@ -53,7 +56,26 @@ FGReplay::FGReplay() { */ FGReplay::~FGReplay() { - // no dynamically allocated memory to free + while ( !short_term.empty() ) { + //cerr << "Deleting Short term" <getBoolValue() ) { // don't record the replay session return; } - + //cerr << "Recording replay" << endl; sim_time += dt; // build the replay record - FGNetFDM f; - FGProps2NetFDM( &f, false ); + //FGNetFDM f; + //FGProps2NetFDM( &f, false ); // sanity check, don't collect data if FDM data isn't good if ( !cur_fdm_state->get_inited() ) { return; } - - FGNetCtrls c; - FGProps2NetCtrls( &c, false, false ); - - FGReplayData r; - r.sim_time = sim_time; - r.ctrls = c; - r.fdm = f; + //FGNetCtrls c; + //FGProps2NetCtrls( &c, false, false ); + //stamp("point_04ba"); + FGReplayData *r; + //stamp("point_04bb"); + if (!recycler.size()) { + stamp("Replay_01"); + r = new FGReplayData; + stamp("Replay_02"); + } else { + r = recycler.front(); + recycler.pop_front(); + //stamp("point_04be"); + } + r->sim_time = sim_time; + //r->ctrls = c; + //stamp("point_04e"); + FGProps2NetFDM( &(r->fdm), false ); + FGProps2NetCtrls( &(r->ctrls), false, false ); + //r->fdm = f; + //stamp("point_05"); // update the short term list + //stamp("point_06"); short_term.push_back( r ); - - FGReplayData st_front = short_term.front(); - if ( sim_time - st_front.sim_time > st_list_time ) { - while ( sim_time - st_front.sim_time > st_list_time ) { + //stamp("point_07"); + FGReplayData *st_front = short_term.front(); + if ( sim_time - st_front->sim_time > st_list_time ) { + while ( sim_time - st_front->sim_time > st_list_time ) { st_front = short_term.front(); + recycler.push_back(st_front); short_term.pop_front(); } - + //stamp("point_08"); // update the medium term list if ( sim_time - last_mt_time > mt_dt ) { last_mt_time = sim_time; + st_front = short_term.front(); medium_term.push_back( st_front ); + short_term.pop_front(); - FGReplayData mt_front = medium_term.front(); - if ( sim_time - mt_front.sim_time > mt_list_time ) { - while ( sim_time - mt_front.sim_time > mt_list_time ) { + FGReplayData *mt_front = medium_term.front(); + if ( sim_time - mt_front->sim_time > mt_list_time ) { + //stamp("point_09"); + while ( sim_time - mt_front->sim_time > mt_list_time ) { mt_front = medium_term.front(); + recycler.push_back(mt_front); medium_term.pop_front(); } - // update the long term list if ( sim_time - last_lt_time > lt_dt ) { last_lt_time = sim_time; + mt_front = medium_term.front(); long_term.push_back( mt_front ); + medium_term.pop_front(); - FGReplayData lt_front = long_term.front(); - if ( sim_time - lt_front.sim_time > lt_list_time ) { - while ( sim_time - lt_front.sim_time > lt_list_time ) { + FGReplayData *lt_front = long_term.front(); + if ( sim_time - lt_front->sim_time > lt_list_time ) { + //stamp("point_10"); + while ( sim_time - lt_front->sim_time > lt_list_time ) { lt_front = long_term.front(); + recycler.push_back(lt_front); long_term.pop_front(); } } @@ -187,6 +248,7 @@ void FGReplay::update( double dt ) { << " time = " << sim_time - long_term.front().sim_time << endl; #endif + //stamp("point_finished"); } @@ -275,6 +337,8 @@ static FGReplayData interpolate( double time, FGReplayData f1, FGReplayData f2 ) result.fdm.rpm[i] = weight( fdm1.rpm[i], fdm2.rpm[i], ratio ); result.fdm.fuel_flow[i] = weight( fdm1.fuel_flow[i], fdm2.fuel_flow[i], ratio ); + result.fdm.fuel_px[i] + = weight( fdm1.fuel_px[i], fdm2.fuel_px[i], ratio ); result.fdm.egt[i] = weight( fdm1.egt[i], fdm2.egt[i], ratio ); result.fdm.cht[i] = weight( fdm1.cht[i], fdm2.cht[i], ratio ); result.fdm.mp_osi[i] = weight( fdm1.mp_osi[i], fdm2.mp_osi[i], ratio ); @@ -404,7 +468,7 @@ static void interpolate( double time, const replay_list_type &list ) { return; } else if ( list.size() == 1 ) { // handle list size == 1 - update_fdm( list[0] ); + update_fdm( (*list[0]) ); return; } @@ -418,11 +482,11 @@ static void interpolate( double time, const replay_list_type &list ) { // cout << " " << first << " <=> " << last << endl; if ( last == first ) { done = true; - } else if ( list[mid].sim_time < time && list[mid+1].sim_time < time ) { + } else if ( list[mid]->sim_time < time && list[mid+1]->sim_time < time ) { // too low first = mid; mid = ( last + first ) / 2; - } else if ( list[mid].sim_time > time && list[mid+1].sim_time > time ) { + } else if ( list[mid]->sim_time > time && list[mid+1]->sim_time > time ) { // too high last = mid; mid = ( last + first ) / 2; @@ -431,7 +495,7 @@ static void interpolate( double time, const replay_list_type &list ) { } } - FGReplayData result = interpolate( time, list[mid], list[mid+1] ); + FGReplayData result = interpolate( time, (*list[mid]), (*list[mid+1]) ); update_fdm( result ); } @@ -448,60 +512,60 @@ void FGReplay::replay( double time ) { double t1, t2; if ( short_term.size() > 0 ) { - t1 = short_term.back().sim_time; - t2 = short_term.front().sim_time; + t1 = short_term.back()->sim_time; + t2 = short_term.front()->sim_time; if ( time > t1 ) { // replay the most recent frame - update_fdm( short_term.back() ); + update_fdm( (*short_term.back()) ); // cout << "first frame" << endl; } else if ( time <= t1 && time >= t2 ) { interpolate( time, short_term ); // cout << "from short term" << endl; } else if ( medium_term.size() > 0 ) { - t1 = short_term.front().sim_time; - t2 = medium_term.back().sim_time; + t1 = short_term.front()->sim_time; + t2 = medium_term.back()->sim_time; if ( time <= t1 && time >= t2 ) { FGReplayData result = interpolate( time, - medium_term.back(), - short_term.front() ); + (*medium_term.back()), + (*short_term.front()) ); update_fdm( result ); // cout << "from short/medium term" << endl; } else { - t1 = medium_term.back().sim_time; - t2 = medium_term.front().sim_time; + t1 = medium_term.back()->sim_time; + t2 = medium_term.front()->sim_time; if ( time <= t1 && time >= t2 ) { interpolate( time, medium_term ); // cout << "from medium term" << endl; } else if ( long_term.size() > 0 ) { - t1 = medium_term.front().sim_time; - t2 = long_term.back().sim_time; + t1 = medium_term.front()->sim_time; + t2 = long_term.back()->sim_time; if ( time <= t1 && time >= t2 ) { FGReplayData result = interpolate( time, - long_term.back(), - medium_term.front()); + (*long_term.back()), + (*medium_term.front())); update_fdm( result ); // cout << "from medium/long term" << endl; } else { - t1 = long_term.back().sim_time; - t2 = long_term.front().sim_time; + t1 = long_term.back()->sim_time; + t2 = long_term.front()->sim_time; if ( time <= t1 && time >= t2 ) { interpolate( time, long_term ); // cout << "from long term" << endl; } else { // replay the oldest long term frame - update_fdm( long_term.front() ); + update_fdm( (*long_term.front()) ); // cout << "oldest long term frame" << endl; } } } else { // replay the oldest medium term frame - update_fdm( medium_term.front() ); + update_fdm( (*medium_term.front()) ); // cout << "oldest medium term frame" << endl; } } } else { // replay the oldest short term frame - update_fdm( short_term.front() ); + update_fdm( (*short_term.front()) ); // cout << "oldest short term frame" << endl; } } else { @@ -512,11 +576,11 @@ void FGReplay::replay( double time ) { double FGReplay::get_start_time() { if ( long_term.size() > 0 ) { - return long_term.front().sim_time; + return (*long_term.front()).sim_time; } else if ( medium_term.size() > 0 ) { - return medium_term.front().sim_time; + return (*medium_term.front()).sim_time; } else if ( short_term.size() ) { - return short_term.front().sim_time; + return (*short_term.front()).sim_time; } else { return 0.0; } @@ -524,7 +588,7 @@ double FGReplay::get_start_time() { double FGReplay::get_end_time() { if ( short_term.size() ) { - return short_term.back().sim_time; + return (*short_term.back()).sim_time; } else { return 0.0; }