{
}
+SGSubsystem::InitStatus
+SGSubsystem::incrementalInit ()
+{
+ init();
+ return INIT_DONE;
+}
+
void
SGSubsystem::postinit ()
{
double elapsed_sec;
bool collectTimeStats;
int exceptionCount;
+ int initTime;
};
SGSubsystemGroup::SGSubsystemGroup () :
_fixedUpdateTime(-1.0),
- _updateTimeRemainder(0.0)
+ _updateTimeRemainder(0.0),
+ _initPosition(-1)
{
}
_members[i]->subsystem->init();
}
+SGSubsystem::InitStatus
+SGSubsystemGroup::incrementalInit()
+{
+ if (_initPosition < 0)
+ _initPosition = 0;
+
+ 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 ()
{
// reverse order to prevent order dependency problems
for (unsigned int i = _members.size(); i > 0; i--)
_members[i-1]->subsystem->shutdown();
+ _initPosition = -1;
}
void
subsystem(0),
min_step_sec(0),
elapsed_sec(0),
- exceptionCount(0)
+ exceptionCount(0),
+ initTime(0)
{
}
////////////////////////////////////////////////////////////////////////
-SGSubsystemMgr::SGSubsystemMgr ()
+SGSubsystemMgr::SGSubsystemMgr () :
+ _initPosition(-1)
{
for (int i = 0; i < MAX_GROUPS; i++) {
_groups[i] = new SGSubsystemGroup;
_groups[i]->init();
}
+SGSubsystem::InitStatus
+SGSubsystemMgr::incrementalInit()
+{
+ if (_initPosition < 0)
+ _initPosition = 0;
+
+ if (_initPosition >= MAX_GROUPS)
+ return INIT_DONE;
+
+ InitStatus memberStatus = _groups[_initPosition]->incrementalInit();
+ if (memberStatus == INIT_DONE)
+ ++_initPosition;
+
+ return INIT_CONTINUE;
+}
+
void
SGSubsystemMgr::postinit ()
{
// reverse order to prevent order dependency problems
for (int i = MAX_GROUPS-1; i >= 0; i--)
_groups[i]->shutdown();
+
+ _initPosition = -1;
}
*/
virtual void init ();
+ typedef enum
+ {
+ INIT_DONE, ///< subsystem is fully initialised
+ INIT_CONTINUE ///< init should be called again
+ } InitStatus;
+
+ virtual InitStatus incrementalInit ();
/**
* Initialize parts that depend on other subsystems having been initialized.
SGSubsystemGroup ();
virtual ~SGSubsystemGroup ();
- virtual void init ();
+ virtual void init();
+ virtual InitStatus incrementalInit ();
virtual void postinit ();
virtual void reinit ();
virtual void shutdown ();
double _fixedUpdateTime;
double _updateTimeRemainder;
+
+ /// index of the member we are currently init-ing
+ int _initPosition;
};
virtual ~SGSubsystemMgr ();
virtual void init ();
+ virtual InitStatus incrementalInit ();
virtual void postinit ();
virtual void reinit ();
virtual void shutdown ();
private:
SGSubsystemGroup* _groups[MAX_GROUPS];
-
+ int _initPosition;
+
typedef std::map<std::string, SGSubsystem*> SubsystemDict;
SubsystemDict _subsystem_map;
};