]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/subsystem_mgr.cxx
Tweak APi for GCC happiness.
[simgear.git] / simgear / structure / subsystem_mgr.cxx
index 6bd7b3945e8324c025a91911670982b9301a2ac4..1e1425528e1a94f595e7b4de4e088c188b15d9a3 100644 (file)
@@ -33,6 +33,8 @@
 
 const int SG_MAX_SUBSYSTEM_EXCEPTIONS = 4;
 
+using std::string;
+
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGSubsystem
 ////////////////////////////////////////////////////////////////////////
@@ -54,6 +56,13 @@ SGSubsystem::init ()
 {
 }
 
+SGSubsystem::InitStatus
+SGSubsystem::incrementalInit ()
+{
+  init();
+  return INIT_DONE;
+}
+
 void
 SGSubsystem::postinit ()
 {
@@ -133,13 +142,15 @@ public:
     double elapsed_sec;
     bool collectTimeStats;
     int exceptionCount;
+    int initTime;
 };
 
 
 
 SGSubsystemGroup::SGSubsystemGroup () :
   _fixedUpdateTime(-1.0),
-  _updateTimeRemainder(0.0)
+  _updateTimeRemainder(0.0),
+  _initPosition(0)
 {
 }
 
@@ -159,6 +170,23 @@ SGSubsystemGroup::init ()
         _members[i]->subsystem->init();
 }
 
+SGSubsystem::InitStatus
+SGSubsystemGroup::incrementalInit()
+{
+  if (_initPosition >= _members.size())
+    return INIT_DONE;
+  
+  SGTimeStamp st;
+  st.stamp();
+  InitStatus memberStatus = _members[_initPosition]->subsystem->incrementalInit();
+  _members[_initPosition]->initTime += st.elapsedMSec();
+  
+  if (memberStatus == INIT_DONE)
+    ++_initPosition;
+  
+  return INIT_CONTINUE;
+}
+
 void
 SGSubsystemGroup::postinit ()
 {
@@ -179,6 +207,7 @@ SGSubsystemGroup::shutdown ()
     // reverse order to prevent order dependency problems
     for (unsigned int i = _members.size(); i > 0; i--)
         _members[i-1]->subsystem->shutdown();
+  _initPosition = 0;
 }
 
 void
@@ -210,11 +239,11 @@ SGSubsystemGroup::update (double delta_time_sec)
       delta_time_sec = _fixedUpdateTime;
     }
 
+    bool recordTime = (reportTimingCb != NULL);
     SGTimeStamp timeStamp;
     while (loopCount-- > 0) {
       for (unsigned int i = 0; i < _members.size(); i++)
       {
-          bool recordTime = (reportTimingCb != NULL);
           if (recordTime)
               timeStamp = SGTimeStamp::now();
 
@@ -252,6 +281,16 @@ SGSubsystemGroup::resume ()
         _members[i]->subsystem->resume();
 }
 
+string_list
+SGSubsystemGroup::member_names() const
+{
+       string_list result;
+       for (unsigned int i = 0; i < _members.size(); i++)
+               result.push_back( _members[i]->name );
+       
+       return result;
+}
+
 bool
 SGSubsystemGroup::is_suspended () const
 {
@@ -331,7 +370,8 @@ SGSubsystemGroup::Member::Member ()
       subsystem(0),
       min_step_sec(0),
       elapsed_sec(0),
-      exceptionCount(0)
+      exceptionCount(0),
+      initTime(0)
 {
 }
 
@@ -378,7 +418,8 @@ SGSubsystemGroup::Member::update (double delta_time_sec)
 ////////////////////////////////////////////////////////////////////////
 
 
-SGSubsystemMgr::SGSubsystemMgr ()
+SGSubsystemMgr::SGSubsystemMgr () :
+  _initPosition(0)
 {
   for (int i = 0; i < MAX_GROUPS; i++) {
     _groups[i] = new SGSubsystemGroup;
@@ -403,6 +444,19 @@ SGSubsystemMgr::init ()
             _groups[i]->init();
 }
 
+SGSubsystem::InitStatus
+SGSubsystemMgr::incrementalInit()
+{
+  if (_initPosition >= MAX_GROUPS)
+    return INIT_DONE;
+  
+  InitStatus memberStatus = _groups[_initPosition]->incrementalInit();  
+  if (memberStatus == INIT_DONE)
+    ++_initPosition;
+  
+  return INIT_CONTINUE;
+}
+
 void
 SGSubsystemMgr::postinit ()
 {
@@ -423,6 +477,8 @@ SGSubsystemMgr::shutdown ()
     // reverse order to prevent order dependency problems
     for (int i = MAX_GROUPS-1; i >= 0; i--)
         _groups[i]->shutdown();
+  
+    _initPosition = 0;
 }