Extend SGSubsystemGroup, to allow running a fixed dt time, internally

This commit is contained in:
James Turner
2010-06-16 18:02:41 +01:00
parent ae22321d9c
commit cc9b817f0e
2 changed files with 41 additions and 12 deletions
+33 -12
View File
@@ -104,7 +104,9 @@ void SGSubsystem::stamp(const string& name)
// Implementation of SGSubsystemGroup. // Implementation of SGSubsystemGroup.
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
SGSubsystemGroup::SGSubsystemGroup () SGSubsystemGroup::SGSubsystemGroup () :
_fixedUpdateTime(-1.0),
_updateTimeRemainder(0.0)
{ {
} }
@@ -157,18 +159,31 @@ SGSubsystemGroup::unbind ()
void void
SGSubsystemGroup::update (double delta_time_sec) SGSubsystemGroup::update (double delta_time_sec)
{ {
for (unsigned int i = 0; i < _members.size(); i++) int loopCount = 1;
{ // if dt == 0.0, we are paused, so we need to run one iteration
SGTimeStamp timeStamp = SGTimeStamp::now(); // of our members; if we have a fixed update time, we compute a
_members[i]->update(delta_time_sec); // indirect call // loop count, and locally adjust dt
timeStamp = timeStamp - SGTimeStamp::now(); if ((delta_time_sec > 0.0) && (_fixedUpdateTime > 0.0)) {
double b = timeStamp.toUSecs(); double localDelta = delta_time_sec + _updateTimeRemainder;
_members[i]->updateExecutionTime(b); loopCount = SGMiscd::roundToInt(localDelta / _fixedUpdateTime);
double threshold = _members[i]->getTimeWarningThreshold(); _updateTimeRemainder = delta_time_sec - (loopCount * _fixedUpdateTime);
if (( b > threshold ) && (b > 10000)) { delta_time_sec = _fixedUpdateTime;
_members[i]->printTimingInformation(b);
}
} }
while (loopCount-- > 0) {
for (unsigned int i = 0; i < _members.size(); i++)
{
SGTimeStamp timeStamp = SGTimeStamp::now();
_members[i]->update(delta_time_sec); // indirect call
timeStamp = timeStamp - SGTimeStamp::now();
double b = timeStamp.toUSecs();
_members[i]->updateExecutionTime(b);
double threshold = _members[i]->getTimeWarningThreshold();
if (( b > threshold ) && (b > 10000)) {
_members[i]->printTimingInformation(b);
}
}
} // of multiple update loop
} }
void void
@@ -233,6 +248,12 @@ SGSubsystemGroup::remove_subsystem (const string &name)
} }
} }
void
SGSubsystemGroup::set_fixed_update_time(double dt)
{
_fixedUpdateTime = dt;
}
void void
SGSubsystemGroup::Member::printTimingStatistics () SGSubsystemGroup::Member::printTimingStatistics ()
{ {
+8
View File
@@ -317,6 +317,10 @@ public:
void collectDebugTiming(bool collect); void collectDebugTiming(bool collect);
/**
*
*/
void set_fixed_update_time(double fixed_dt);
private: private:
class Member { class Member {
@@ -345,6 +349,9 @@ private:
Member * get_member (const string &name, bool create = false); Member * get_member (const string &name, bool create = false);
vector<Member *> _members; vector<Member *> _members;
double _fixedUpdateTime;
double _updateTimeRemainder;
}; };
@@ -376,6 +383,7 @@ public:
enum GroupType { enum GroupType {
INIT = 0, INIT = 0,
GENERAL, GENERAL,
FDM, ///< flight model, autopilot, instruments that run coupled
MAX_GROUPS MAX_GROUPS
}; };