Make subsystem init incremental.
(Requires latest SimGear!) Break fgInitSubsystems into several phases - subsystem creation, then binding and then init. Run init over multiple main-loop iterations so the application stays responsive to GUI/OS events during init. There should be no behaviour changes due to this, except that during init Windows and OS-X should no longer show the beach ball / 'application not responding feedback', hopefully.
This commit is contained in:
parent
9d30d622ae
commit
e2eea405a3
3 changed files with 50 additions and 56 deletions
|
@ -1050,9 +1050,9 @@ bool fgInitGeneral() {
|
|||
// initialization routines. If you are adding a subsystem to flight
|
||||
// gear, its initialization call should located in this routine.
|
||||
// Returns non-zero if a problem encountered.
|
||||
bool fgInitSubsystems() {
|
||||
void fgCreateSubsystems() {
|
||||
|
||||
SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
|
||||
SG_LOG( SG_GENERAL, SG_INFO, "Creating Subsystems");
|
||||
SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -1264,13 +1264,12 @@ bool fgInitSubsystems() {
|
|||
|
||||
globals->add_subsystem("tile-manager", globals->get_tile_mgr(),
|
||||
SGSubsystemMgr::DISPLAY);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Bind and initialize subsystems.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
globals->get_subsystem_mgr()->bind();
|
||||
globals->get_subsystem_mgr()->init();
|
||||
void fgPostInitSubsystems()
|
||||
{
|
||||
SGTimeStamp st;
|
||||
st.stamp();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Initialize the Nasal interpreter.
|
||||
|
@ -1279,9 +1278,12 @@ bool fgInitSubsystems() {
|
|||
FGNasalSys* nasal = new FGNasalSys();
|
||||
globals->add_subsystem("nasal", nasal, SGSubsystemMgr::INIT);
|
||||
nasal->init();
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Nasal init took:" << st.elapsedMSec());
|
||||
|
||||
// initialize methods that depend on other subsystems.
|
||||
st.stamp();
|
||||
globals->get_subsystem_mgr()->postinit();
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Subsystems postinit took:" << st.elapsedMSec());
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// TODO FIXME! UGLY KLUDGE!
|
||||
|
@ -1318,8 +1320,6 @@ bool fgInitSubsystems() {
|
|||
// Save the initial state for future
|
||||
// reference.
|
||||
globals->saveInitialState();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reset: this is what the 'reset' command (and hence, GUI) is attached to
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
|
||||
// forward decls
|
||||
class SGPropertyNode;
|
||||
class SGTime;
|
||||
class SGPath;
|
||||
|
||||
// Return the current base package version
|
||||
|
@ -52,11 +51,12 @@ bool fgInitNav ();
|
|||
bool fgInitGeneral ();
|
||||
|
||||
|
||||
// This is the top level init routine which calls all the other
|
||||
// initialization routines. If you are adding a subsystem to flight
|
||||
// gear, its initialization call should located in this routine.
|
||||
bool fgInitSubsystems();
|
||||
// Create all the subsystems needed by the sim
|
||||
void fgCreateSubsystems();
|
||||
|
||||
// called after the subsystems have been bound and initialised,
|
||||
// to peform final init
|
||||
void fgPostInitSubsystems();
|
||||
|
||||
// Reset: this is what the 'reset' command (and hence, GUI) is attached to
|
||||
void fgReInitSubsystems();
|
||||
|
|
|
@ -181,6 +181,7 @@ static void fgIdleFunction ( void ) {
|
|||
// our initializations out of the idle callback so that we can get a
|
||||
// splash screen up and running right away.
|
||||
static int idle_state = 0;
|
||||
static int spin_count = 0;
|
||||
|
||||
static osg::ref_ptr<GeneralInitOperation> genOp;
|
||||
if ( idle_state == 0 ) {
|
||||
|
@ -265,47 +266,40 @@ static void fgIdleFunction ( void ) {
|
|||
|
||||
} else if ( idle_state == 6 ) {
|
||||
idle_state++;
|
||||
fgSplashProgress("initializing subsystems");
|
||||
fgSplashProgress("creating subsystems");
|
||||
|
||||
} else if ( idle_state == 7 ) {
|
||||
idle_state++;
|
||||
// Initialize audio support
|
||||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
SGTimeStamp st;
|
||||
st.stamp();
|
||||
fgCreateSubsystems();
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Creating subsystems took:" << st.elapsedMSec());
|
||||
fgSplashProgress("binding subsystems");
|
||||
|
||||
// Start the intro music
|
||||
if ( fgGetBool("/sim/startup/intro-music") ) {
|
||||
SGPath mp3file( globals->get_fg_root() );
|
||||
mp3file.append( "Sounds/intro.mp3" );
|
||||
} else if ( idle_state == 8 ) {
|
||||
idle_state++;
|
||||
SGTimeStamp st;
|
||||
st.stamp();
|
||||
globals->get_subsystem_mgr()->bind();
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Binding subsystems took:" << st.elapsedMSec());
|
||||
|
||||
SG_LOG( SG_GENERAL, SG_INFO,
|
||||
"Starting intro music: " << mp3file.str() );
|
||||
|
||||
# if defined( __CYGWIN__ )
|
||||
string command = "start /m `cygpath -w " + mp3file.str() + "`";
|
||||
# elif defined( _WIN32 )
|
||||
string command = "start /m " + mp3file.str();
|
||||
# else
|
||||
string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
|
||||
# endif
|
||||
|
||||
if (0 != system ( command.c_str() ))
|
||||
{
|
||||
SG_LOG( SG_SOUND, SG_WARN,
|
||||
"Failed to play mp3 file " << mp3file.str() << ". Maybe mp3 player is not installed." );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// This is the top level init routine which calls all the
|
||||
// other subsystem initialization routines. If you are adding
|
||||
// a subsystem to flightgear, its initialization call should be
|
||||
// located in this routine.
|
||||
if( !fgInitSubsystems()) {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT,
|
||||
"Subsystem initialization failed ..." );
|
||||
exit(-1);
|
||||
fgSplashProgress("initing subsystems");
|
||||
} else if ( idle_state == 9 ) {
|
||||
SGSubsystem::InitStatus status = globals->get_subsystem_mgr()->incrementalInit();
|
||||
if ( status == SGSubsystem::INIT_DONE) {
|
||||
++idle_state;
|
||||
fgSplashProgress("finishing subsystem init");
|
||||
} else {
|
||||
const char* spinChars = "-\\|/";
|
||||
string msg = string("initing subsystems ") + spinChars[spin_count++ % 4];
|
||||
fgSplashProgress(msg.c_str());
|
||||
}
|
||||
|
||||
// Torsten Dreyer:
|
||||
} else if ( idle_state == 10 ) {
|
||||
idle_state = 900;
|
||||
fgPostInitSubsystems();
|
||||
|
||||
// Torsten Dreyer:
|
||||
// ugly hack for automatic runway selection on startup based on
|
||||
// metar data. Makes startup.nas obsolete and guarantees the same
|
||||
// runway selection as for AI traffic. However, this code belongs to
|
||||
|
@ -335,7 +329,7 @@ static void fgIdleFunction ( void ) {
|
|||
|
||||
fgSplashProgress("initializing graphics engine");
|
||||
|
||||
} else if ( idle_state == 8 ) {
|
||||
} else if ( idle_state == 900 ) {
|
||||
idle_state = 1000;
|
||||
|
||||
// setup OpenGL view parameters
|
||||
|
|
Loading…
Add table
Reference in a new issue