Debugging FlightGear - Note C

back

// Main top level initialization
bool fgMainInit( int argc, char **argv ) {

#if defined( macintosh )
{ freopen ("stdout.txt", "w", stdout );freopen ("stderr.txt", "w", stderr );argc = ccommand( &argv ); }#endif
sglog().setLogLevels( SG_ALL, SG_ALERT ); // set default log levels
string version = FLIGHTGEAR_VERSION;
SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version " << version );
SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
globals = new FGGlobals; // Allocate global data structures. This needs to happen before we parse command line options
sg_srandom_time(); // seed the random number generater
FGControls *controls = new FGControls; globals->set_controls( controls );
string_list *col = new string_list; globals->set_channel_options_list( col );
fgInitFGRoot(argc, argv); // Scan the config file(s) and command line options to see if fg_root was specified (ignore all other options for now)
static char required_version[] = "0.9.8";
string base_version = fgBasePackageVersion(); // Check for the correct base package version
if ( !(base_version == required_version) ) { // tell the operator how to use this application, and EXIT(-1) }
sgUseDisplayList = fgGetBool( "/sim/rendering/use-display-list", true );
aircraft_dir = ""; // Initialize the Aircraft directory to "" (UIUC)
if ( !fgInitConfig(argc, argv) ) {SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );exit(-1);} // Load the configuration parameters. (Command line options overrides config file options. Config file options override defaults.)
// Initialize the Window/Graphics environment.
#if !defined(__APPLE__) || defined(OSX_BUNDLE) { // Mac OS X command line ("non-bundle") applications call this from main(), in bootstrap.cxx. Andy doesn't know why, someone feel free to add comments... fgOSInit(&argc, argv); _bootstrap_OSInit++; #endif

fgRegisterWindowResizeHandler( &FGRenderer::resize );
fgRegisterIdleHandler( &fgIdleFunction );
fgRegisterDrawHandler( &FGRenderer::update );

#ifdef FG_ENABLE_MULTIPASS_CLOUDS
bool get_stencil_buffer = true;
#else
bool get_stencil_buffer = false;
#endif

// Clouds3D requires an alpha channel
// clouds may require stencil buffer
fgOSOpenWindow( fgGetInt("/sim/startup/xsize"),
fgGetInt("/sim/startup/ysize"),
fgGetInt("/sim/rendering/bits-per-pixel"),
fgGetBool("/sim/rendering/clouds3d"),
get_stencil_buffer,
fgGetBool("/sim/startup/fullscreen") );

// This seems to be the absolute earliest in the init sequence
// that these calls will return valid info. Too bad it's after
// we've already created and sized out window. :-(
general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );

GLint tmp;
glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
general.set_glMaxTexSize( tmp );
SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );

glGetIntegerv( GL_DEPTH_BITS, &tmp );
general.set_glDepthBits( tmp );
SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );

// Initialize plib net interface
netInit( &argc, argv );

// Initialize ssg (from plib). Needs to come before we do any
// other ssg stuff, but after opengl has been initialized.
ssgInit();

// Initialize the user interface (we need to do this before
// passing off control to the OS main loop and before
// fgInitGeneral to get our fonts !!!
guiInit();

// Read the list of available aircrafts
fgReadAircraft();

#ifdef GL_EXT_texture_lod_bias
glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
#endif

// get the address of our OpenGL extensions
if ( fgGetBool("/sim/rendering/distance-attenuation") )
{
if (SGIsOpenGLExtensionSupported("GL_EXT_point_parameters") ) {
glPointParameterIsSupported = true;
glPointParameterfPtr = (glPointParameterfProc)
SGLookupFunction("glPointParameterfEXT");
glPointParameterfvPtr = (glPointParameterfvProc)
SGLookupFunction("glPointParameterfvEXT");

} else if ( SGIsOpenGLExtensionSupported("GL_ARB_point_parameters") ) {
glPointParameterIsSupported = true;
glPointParameterfPtr = (glPointParameterfProc)
SGLookupFunction("glPointParameterfARB");
glPointParameterfvPtr = (glPointParameterfvProc)
SGLookupFunction("glPointParameterfvARB");
} else
glPointParameterIsSupported = false;
}

// based on the requested presets, calculate the true starting
// lon, lat
fgInitNav();
fgInitPosition();

SGTime *t = fgInitTime();
globals->set_time_params( t );

// Do some quick general initializations
if( !fgInitGeneral()) {
SG_LOG( SG_GENERAL, SG_ALERT,
"General initializations failed ..." );
exit(-1);
}

////////////////////////////////////////////////////////////////////
// Initialize the property-based built-in commands
////////////////////////////////////////////////////////////////////
fgInitCommands();

////////////////////////////////////////////////////////////////////
// Initialize the material manager
////////////////////////////////////////////////////////////////////
globals->set_matlib( new SGMaterialLib );

globals->set_model_lib(new SGModelLib);

////////////////////////////////////////////////////////////////////
// Initialize the TG scenery subsystem.
////////////////////////////////////////////////////////////////////
globals->set_scenery( new FGScenery );
globals->get_scenery()->init();
globals->get_scenery()->bind();
globals->set_tile_mgr( new FGTileMgr );

////////////////////////////////////////////////////////////////////
// Initialize the general model subsystem.
////////////////////////////////////////////////////////////////////
globals->set_model_mgr(new FGModelMgr);
globals->get_model_mgr()->init();
globals->get_model_mgr()->bind();

////////////////////////////////////////////////////////////////////
// Initialize the 3D aircraft model subsystem (has a dependency on
// the scenery subsystem.)
////////////////////////////////////////////////////////////////////
globals->set_aircraft_model(new FGAircraftModel);
globals->get_aircraft_model()->init();
globals->get_aircraft_model()->bind();

////////////////////////////////////////////////////////////////////
// Initialize the view manager subsystem.
////////////////////////////////////////////////////////////////////
FGViewMgr *viewmgr = new FGViewMgr;
globals->set_viewmgr( viewmgr );
viewmgr->init();
viewmgr->bind();

// Initialize the sky
SGPath ephem_data_path( globals->get_fg_root() );
ephem_data_path.append( "Astro" );
SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
ephem->update( globals->get_time_params()->getMjd(),
globals->get_time_params()->getLst(),
0.0 );
globals->set_ephem( ephem );

// TODO: move to environment mgr
thesky = new SGSky;
SGPath texture_path(globals->get_fg_root());
texture_path.append("Textures");
texture_path.append("Sky");
for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
thesky->add_cloud_layer(layer);
}

SGPath sky_tex_path( globals->get_fg_root() );
sky_tex_path.append( "Textures" );
sky_tex_path.append( "Sky" );
thesky->texture_path( sky_tex_path.str() );

// The sun and moon diameters are scaled down numbers of the
// actual diameters. This was needed to fit bot the sun and the
// moon within the distance to the far clip plane.
// Moon diameter: 3,476 kilometers
// Sun diameter: 1,390,000 kilometers
thesky->build( 80000.0, 80000.0,
463.3, 361.8,
globals->get_ephem()->getNumPlanets(),
globals->get_ephem()->getPlanets(),
globals->get_ephem()->getNumStars(),
globals->get_ephem()->getStars() );

// Initialize MagVar model
SGMagVar *magvar = new SGMagVar();
globals->set_mag( magvar );

// kludge to initialize mag compass
// (should only be done for in-flight
// startup)
// update magvar model
globals->get_mag()->update( fgGetDouble("/position/longitude-deg")
* SGD_DEGREES_TO_RADIANS,
fgGetDouble("/position/latitude-deg")
* SGD_DEGREES_TO_RADIANS,
fgGetDouble("/position/altitude-ft")
* SG_FEET_TO_METER,
globals->get_time_params()->getJD() );
double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var);

// airport = new ssgBranch;
// airport->setName( "Airport Lighting" );
// lighting->addKid( airport );

// build our custom render states
globals->get_renderer()->build_states();

// pass control off to the master event handler
fgOSMainLoop();

// we never actually get here ... but to avoid compiler warnings,
// etc.
return false;
}

back