From d80b718039e7a6c4b7686014b785d78b26085d3e Mon Sep 17 00:00:00 2001 From: mfranz Date: Fri, 6 May 2005 09:08:44 +0000 Subject: [PATCH] - implement progress information (enabled by default; can be turned off via /sim/startup/splash-progress) - a string in /sim/startup/splash-title is displayed on top of the screen and by default empty - the splash image is scaled down if 512x512 is too big - code cleanup --- src/Main/fg_init.cxx | 5 -- src/Main/main.cxx | 44 ++++++++--------- src/Main/splash.cxx | 115 ++++++++++++++++++++++++++++++++----------- src/Main/splash.hxx | 7 ++- 4 files changed, 113 insertions(+), 58 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index c2bc2bc9d..59f54da02 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -133,7 +133,6 @@ #include "options.hxx" #include "globals.hxx" #include "logger.hxx" -#include "splash.hxx" #include "viewmgr.hxx" #if defined(FX) && defined(XMESA) @@ -1060,8 +1059,6 @@ fgInitNav () fgAirportDBLoad( airports, runways, aptdb.str(), p_metar.str() ); - fgSplashUpdate( 1.0 ); - FGNavList *navlist = new FGNavList; FGNavList *loclist = new FGNavList; FGNavList *gslist = new FGNavList; @@ -1079,8 +1076,6 @@ fgInitNav () "Problems loading one or more navigational database" ); } - fgSplashUpdate( 1.0 ); - if ( fgGetBool("/sim/navdb/localizers/auto-align", true) ) { // align all the localizers with their corresponding runways // since data sources are good for cockpit navigation diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 83fe5dbd6..9f6739d24 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -648,11 +648,13 @@ static void fgMainLoop( void ) { // then on. static void fgIdleFunction ( void ) { - // printf("idle state == %d\n", idle_state); - if ( idle_state == 0 ) { idle_state++; + fgSplashProgress("setting up scenegraph & user interface"); + + } else if ( idle_state == 1 ) { + idle_state++; // 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. :-( @@ -678,9 +680,10 @@ static void fgIdleFunction ( void ) { // passing off control to the OS main loop and before // fgInitGeneral to get our fonts !!! guiInit(); + fgSplashProgress("reading aircraft list"); - } else if ( idle_state == 1 ) { + } else if ( idle_state == 2 ) { idle_state++; // Read the list of available aircrafts fgReadAircraft(); @@ -707,14 +710,16 @@ static void fgIdleFunction ( void ) { } else glPointParameterIsSupported = false; } + fgSplashProgress("reading navigation data"); - } else if ( idle_state == 2 ) { + } else if ( idle_state == 3 ) { idle_state++; fgInitNav(); + fgSplashProgress("setting up scenery"); - } else if ( idle_state == 3 ) { + } else if ( idle_state == 4 ) { idle_state++; // based on the requested presets, calculate the true starting // lon, lat @@ -758,9 +763,10 @@ static void fgIdleFunction ( void ) { globals->set_model_mgr(new FGModelMgr); globals->get_model_mgr()->init(); globals->get_model_mgr()->bind(); + fgSplashProgress("loading aircraft"); - } else if ( idle_state == 4 ) { + } else if ( idle_state == 5 ) { idle_state++; //////////////////////////////////////////////////////////////////// // Initialize the 3D aircraft model subsystem (has a dependency on @@ -777,9 +783,10 @@ static void fgIdleFunction ( void ) { globals->set_viewmgr( viewmgr ); viewmgr->init(); viewmgr->bind(); + fgSplashProgress("generating sky elements"); - } else if ( idle_state == 5 ) { + } else if ( idle_state == 6 ) { idle_state++; // Initialize the sky SGPath ephem_data_path( globals->get_fg_root() ); @@ -842,9 +849,10 @@ static void fgIdleFunction ( void ) { // build our custom render states globals->get_renderer()->build_states(); + fgSplashProgress("initializing subsystems"); - } else if ( idle_state == 6 ) { + } else if ( idle_state == 7 ) { idle_state++; // Initialize audio support #ifdef ENABLE_AUDIO_SUPPORT @@ -887,10 +895,11 @@ static void fgIdleFunction ( void ) { "Subsystem initializations failed ..." ); exit(-1); } + fgSplashProgress("setup time & renderer"); - } else if ( idle_state == 7 ) { - idle_state++; + } else if ( idle_state == 8 ) { + idle_state = 1000; // Initialize the time offset (warp) after fgInitSubsystem // (which initializes the lighting interpolation tables.) fgInitTimeOffset(); @@ -898,27 +907,18 @@ static void fgIdleFunction ( void ) { // setup OpenGL view parameters globals->get_renderer()->init(); - // Read the list of available aircrafts - fgReadAircraft(); - - - } else if ( idle_state == 8 ) { - idle_state = 1000; - SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() ); globals->get_renderer()->resize( fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize") ); + fgSplashProgress("loading scenery objects"); } - if ( idle_state < 1000 ) { - fgSplashUpdate( 1.0 ); - - } else { + if ( idle_state == 1000 ) { // We've finished all our initialization steps, from now on we // run the main loop. - fgSetBool("sim/sceneryloaded",false); + fgSetBool("sim/sceneryloaded", false); fgRegisterIdleHandler( fgMainLoop ); } } diff --git a/src/Main/splash.cxx b/src/Main/splash.cxx index 9c93de2d4..23b470510 100644 --- a/src/Main/splash.cxx +++ b/src/Main/splash.cxx @@ -30,12 +30,13 @@ # include #endif -#ifdef HAVE_WINDOWS_H +#ifdef HAVE_WINDOWS_H # include #endif #include +#include #include #include SG_GLU_H @@ -50,18 +51,43 @@ #include "splash.hxx" #include "fg_os.hxx" +static const int fontsize = 19; +static const char fontname[] = "default.txf"; +static const char *text = 0; static SGTexture splash; +static fntTexFont font; +static fntRenderer info; // Initialize the splash screen void fgSplashInit ( const char *splash_texture ) { + fgRequestRedraw(); + if (!fgGetBool("/sim/startup/splash-screen")) return; SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" ); + + SGPath fontpath; + char* envp = ::getenv("FG_FONTS"); + if (envp != NULL) { + fontpath.set(envp); + } else { + fontpath.set(globals->get_fg_root()); + fontpath.append("Fonts"); + } + SGPath path(fontpath); + path.append(fontname); + + font.load((char *)path.c_str()); + + info.setFont(&font); + info.setPointSize(fontsize); + + splash.bind(); SGPath tpath( globals->get_fg_root() ); @@ -80,45 +106,54 @@ void fgSplashInit ( const char *splash_texture ) { splash.read_rgb_texture(tpath.c_str()); if (!splash.usable()) { - // Try compressed - SGPath fg_tpath = tpath; - fg_tpath.concat( ".gz" ); + // Try compressed + SGPath fg_tpath = tpath; + fg_tpath.concat( ".gz" ); splash.read_rgb_texture(fg_tpath.c_str()); - if ( !splash.usable() ) - { - SG_LOG( SG_GENERAL, SG_ALERT, - "Error in loading splash screen texture " << tpath.str() ); - exit(-1); - } - } + if ( !splash.usable() ) + { + SG_LOG( SG_GENERAL, SG_ALERT, + "Error in loading splash screen texture " << tpath.str() ); + exit(-1); + } + } splash.select(); } +void fgSplashProgress ( const char *s ) +{ + text = s; + fgRequestRedraw(); +} + + // Update the splash screen with alpha specified from 0.0 to 1.0 void fgSplashUpdate ( float alpha ) { - int xmin, ymin, xmax, ymax; - int xsize = 512; - int ysize = 512; + int screen_width = fgGetInt("/sim/startup/xsize", 0); + int screen_height = fgGetInt("/sim/startup/ysize", 0); - if ( !fgGetInt("/sim/startup/xsize") - || !fgGetInt("/sim/startup/ysize") ) { - return; - } + if (!screen_width || !screen_height) + return; - xmin = (fgGetInt("/sim/startup/xsize") - xsize) / 2; - xmax = xmin + xsize; + int size = screen_width < (screen_height - 5 * fontsize) + ? screen_width : screen_height - 5 * fontsize; + if (size > 512) + size = 512; - ymin = (fgGetInt("/sim/startup/ysize") - ysize) / 2; - ymax = ymin + ysize; + int xmin, ymin, xmax, ymax; + xmin = (screen_width - size) / 2; + xmax = xmin + size; + + ymin = (screen_height - size) / 2; + ymax = ymin + size; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - gluOrtho2D(0, fgGetInt("/sim/startup/xsize"), - 0, fgGetInt("/sim/startup/ysize")); + gluOrtho2D(0, screen_width, 0, screen_height); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); @@ -130,13 +165,13 @@ void fgSplashUpdate ( float alpha ) { glColor4f( 0.0, 0.0, 0.0, alpha ); glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); - glVertex2f(fgGetInt("/sim/startup/xsize"), 0.0); - glVertex2f(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize")); - glVertex2f(0.0, fgGetInt("/sim/startup/ysize")); + glVertex2f(screen_width, 0.0); + glVertex2f(screen_width, screen_height); + glVertex2f(0.0, screen_height); glEnd(); // now draw the logo - if (fgGetBool("/sim/startup/splash-screen") && splash.usable()) { + if (fgGetBool("/sim/startup/splash-screen", true)) { glEnable(GL_TEXTURE_2D); splash.bind(); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -146,10 +181,32 @@ void fgSplashUpdate ( float alpha ) { glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin); glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin); glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax); - glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); + glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); glEnd(); } + if (text && fgGetBool("/sim/startup/splash-progress", true)) { + glEnable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glAlphaFunc(GL_GREATER, 0.1f); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + + float left, right, bot, top; + + info.begin(); + glColor3f(1.0, 0.9, 0.0); + font.getBBox(text, fontsize, 0, &left, &right, &bot, &top); + info.start2f((screen_width - right) / 2.0, 10.0 - bot); + info.puts(text); + + const char *s = fgGetString("/sim/startup/splash-title", ""); + font.getBBox(s, fontsize, 0, &left, &right, &bot, &top); + info.start2f((screen_width - right) / 2.0, screen_height - top - bot - 10.0); + info.puts(s); + info.end(); + } + glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); diff --git a/src/Main/splash.hxx b/src/Main/splash.hxx index 31e1bca27..260c57c1b 100644 --- a/src/Main/splash.hxx +++ b/src/Main/splash.hxx @@ -26,9 +26,9 @@ #define _SPLASH_HXX -#ifndef __cplusplus +#ifndef __cplusplus # error This library requires C++ -#endif +#endif // Initialize the splash screen @@ -37,6 +37,9 @@ void fgSplashInit ( const char *splash_texture ); // Update the splash screen with alpha specified from 0.0 to 1.0 void fgSplashUpdate ( float alpha ); +// Set progress information +void fgSplashProgress( const char *text ); + #endif // _SPLASH_HXX -- 2.39.5