bool fgMainInit | ( int argc, char **argv ) | // Main top level initialization |
{ | ||
sglog().setLogLevels | (SG_ALL, SG_ALERT) | // set default log levels |
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) |
sgUseDisplayList = fgGetBool | ( "/sim/rendering/use-display-list", true ); | |
aircraft_dir = ""; | // Initialize the Aircraft directory to "" (UIUC) | |
if ( !fgInitConfig | (argc, argv) ) | // Load the configuration parameters. (Command line options overrides config file options. Config file options override defaults.) |
// Initialize the Window/Graphics environment. | ||
fgOSInit | (&argc, argv); | |
fgRegisterWindowResizeHandler | ( &FGRenderer::resize ); | |
fgRegisterIdleHandler | ( &fgIdleFunction ); | |
fgRegisterDrawHandler | ( &FGRenderer::update ); | |
bool get_stencil_buffer | true|false | |
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") ); |
// Clouds3D requires an alpha channel // clouds may require stencil buffer |
general.set_glVendor | ( (char *)glGetString ( GL_VENDOR ) ); | // 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. :-( |
netInit | ( &argc, argv ); | // Initialize plib net interface |
ssgInit(); | // Initialize ssg (from plib). Needs to come before we do any // other ssg stuff, but after opengl has been initialized. |
|
guiInit(); | // 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 !!! |
|
fgReadAircraft(); | // Read the list of available aircrafts | |
if ( fgGetBool("/sim/rendering/distance-attenuation") ) |
glPointParameterIsSupported = true; glPointParameterfPtr = (glPointParameterfProc) SGLookupFunction("glPointParameterfEXT"); glPointParameterfvPtr = (glPointParameterfvProc) SGLookupFunction("glPointParameterfvEXT"); |
// get the address of our OpenGL extensions |
fgInitNav(); | // based on the requested presets, calculate the true starting lon, lat | |
fgInitPosition(); | ||
SGTime *t = fgInitTime(); | globals->set_time_params( t ); | |
if( !fgInitGeneral()) { | exit(-1); | // Do some quick general initializations |
fgInitCommands(); | // Initialize the property-based built-in commands | |
globals->set_matlib( new SGMaterialLib ); | globals->set_model_lib(new SGModelLib); | // Initialize the material manager |
globals->set_scenery( new FGScenery ); | globals->get_scenery()->init(); globals->get_scenery()->bind(); globals->set_tile_mgr( new FGTileMgr ); |
// Initialize the TG scenery subsystem |
globals->set_model_mgr(new FGModelMgr); | globals->get_model_mgr()->init(); globals->get_model_mgr()->bind(); |
// Initialize the general model subsystem. |
globals->set_aircraft_model(new FGAircraftModel); | globals->get_aircraft_model()->init(); globals->get_aircraft_model()->bind(); |
// Initialize the 3D aircraft model subsystem (has a dependency on the scenery subsystem.) |
FGViewMgr *viewmgr = new FGViewMgr; | globals->set_viewmgr( viewmgr ); viewmgr->init(); viewmgr->bind(); |
// Initialize the view manager subsystem. |
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 ); |
// Initialize the sky |
thesky = new SGSky; |
SGPath texture_path(globals->get_fg_root()); |
// TODO: move to environment mgr // 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 |
SGMagVar *magvar = new SGMagVar(); | globals->set_mag( magvar ); 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); |
// Initialize MagVar model // kludge to initialize mag compass // (should only be done for in-flight startup) // update magvar model |
globals->get_renderer()->build_states(); | // build our custom render states | |
fgOSMainLoop(); | // pass control off to the master event handler | |
return false; | // we never actually get here ... but to avoid compiler warnings, etc. | |
} |