From 6e5d22789b420291593c8c8a044220372801e454 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 7 Apr 2002 15:24:32 +0000 Subject: [PATCH] Patches from Norm Vine to improve framerate and add a new #ifdef'ed-out mode for syncing fullscreen with user settings in Windows. --- src/GUI/apt_dlg.cxx | 4 ++- src/GUI/gui_local.cxx | 3 +- src/Main/fg_commands.cxx | 4 ++- src/Main/fg_init.cxx | 5 ++- src/Main/main.cxx | 65 +++++++++++++++++++++++++++------------ src/Network/atc610x.cxx | 4 +-- src/Network/net_fdm.hxx | 2 ++ src/Scenery/tileentry.cxx | 14 ++++++--- src/Scenery/tileentry.hxx | 2 +- src/Scenery/tilemgr.cxx | 24 +++++++++------ src/Scenery/tilemgr.hxx | 6 ++-- 11 files changed, 89 insertions(+), 44 deletions(-) diff --git a/src/GUI/apt_dlg.cxx b/src/GUI/apt_dlg.cxx index 41d2e21c5..4d45d8291 100644 --- a/src/GUI/apt_dlg.cxx +++ b/src/GUI/apt_dlg.cxx @@ -100,8 +100,10 @@ void AptDialog_OK (puObject *) SGD_RADIANS_TO_DEGREES); // BusyCursor(0); fgReInitSubsystems(); + double visibility_meters = + fgGetDouble("/environment/visibility-m"); global_tile_mgr.update( longitude->getDoubleValue(), - latitude->getDoubleValue() ); + latitude->getDoubleValue(),visibility_meters ); // BusyCursor(1); } else { AptId += " not in database."; diff --git a/src/GUI/gui_local.cxx b/src/GUI/gui_local.cxx index f537d6089..df6ac67e1 100644 --- a/src/GUI/gui_local.cxx +++ b/src/GUI/gui_local.cxx @@ -88,8 +88,9 @@ void reInit(puObject *cb) fgReInitSubsystems(); // reduntant(fgReInitSubsystems) ? + double visibility_meters = fgGetDouble("/environment/visibility-m"); global_tile_mgr.update( fgGetDouble("/position/longitude-deg"), - fgGetDouble("/position/latitude-deg") ); + fgGetDouble("/position/latitude-deg"),visibility_meters ); cur_light_params.Update(); diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index d8677b50f..09e0d029d 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -307,8 +307,10 @@ do_tile_cache_reload (const SGPropertyNode * arg, SGCommandState ** state) // BusyCursor(0); if ( global_tile_mgr.init() ) { // Load the local scenery data + double visibility_meters = fgGetDouble("/environment/visibility-m"); global_tile_mgr.update(fgGetDouble("/position/longitude-deg"), - fgGetDouble("/position/latitude-deg")); + fgGetDouble("/position/latitude-deg"), + visibility_meters); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" ); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 14b537639..deace4519 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -712,8 +712,11 @@ bool fgInitSubsystems( void ) { if ( global_tile_mgr.init() ) { // Load the local scenery data + double visibility_meters = fgGetDouble("/environment/visibility-m"); + global_tile_mgr.update( longitude->getDoubleValue(), - latitude->getDoubleValue() ); + latitude->getDoubleValue(), + visibility_meters ); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" ); exit(-1); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index e83f4b706..ef3071dc8 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -419,6 +419,8 @@ void fgRenderFrame( void ) { // Update the default (kludged) properties. fgUpdateProps(); + FGViewer *current__view = globals->get_current_view(); + fgLIGHT *l = &cur_light_params; static double last_visibility = -9999; @@ -492,13 +494,14 @@ void fgRenderFrame( void ) { // ssg does to set up the model view matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - ssgSetCamera( (sgVec4 *)globals->get_current_view()->get_VIEW() ); + ssgSetCamera( (sgVec4 *)current__view->get_VIEW() ); // set the opengl state to known default values default_state->force(); // update fog params if visibility has changed - thesky->set_visibility(fgGetDouble("/environment/visibility-m")); + double visibility_meters = fgGetDouble("/environment/visibility-m"); + thesky->set_visibility(visibility_meters); thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, ( global_multi_loop * fgGetInt("/sim/speed-up") ) @@ -544,9 +547,9 @@ void fgRenderFrame( void ) { << " moon ra = " << globals->get_ephem()->getMoonRightAscension() << " moon dec = " << globals->get_ephem()->getMoonDeclination() << endl; */ - thesky->reposition( globals->get_current_view()->get_view_pos(), - globals->get_current_view()->get_zero_elev(), - globals->get_current_view()->get_world_up(), + thesky->reposition( current__view->get_view_pos(), + current__view->get_zero_elev(), + current__view->get_world_up(), longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS, latitude->getDoubleValue() @@ -591,8 +594,8 @@ void fgRenderFrame( void ) { // glMatrixMode( GL_PROJECTION ); // glLoadIdentity(); - ssgSetFOV( globals->get_current_view()->get_h_fov(), - globals->get_current_view()->get_v_fov() ); + ssgSetFOV( current__view->get_h_fov(), + current__view->get_v_fov() ); double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER - scenery.get_cur_elev(); @@ -614,7 +617,8 @@ void fgRenderFrame( void ) { current_model.update(dt_ms); // $$$ begin - added VS Renganthan 17 Oct 2K - fgUpdateDCS(); + if(objc) + fgUpdateDCS(); // $$$ end - added VS Renganthan 17 Oct 2K # ifdef FG_NETWORK_OLK @@ -639,7 +643,7 @@ void fgRenderFrame( void ) { # endif // position tile nodes and update range selectors - global_tile_mgr.prep_ssg_nodes(); + global_tile_mgr.prep_ssg_nodes(visibility_meters); if ( fgGetBool("/sim/rendering/skyblend") ) { // draw the sky backdrop @@ -724,7 +728,7 @@ void fgRenderFrame( void ) { } // if in cockpit view adjust nearfar... - if (globals->get_current_view()->getType() == 0 ) { + if (current__view->getType() == 0 ) { glClearDepth(1); glClear(GL_DEPTH_BUFFER_BIT); ssgSetNearFar( cockpit_nearplane, cockpit_farplane ); @@ -1088,8 +1092,9 @@ static void fgMainLoop( void ) { #endif // see if we need to load any new scenery tiles + double visibility_meters = fgGetDouble("/environment/visibility-m"); global_tile_mgr.update( longitude->getDoubleValue(), - latitude->getDoubleValue() ); + latitude->getDoubleValue(), visibility_meters ); // see if we need to load any deferred-load textures material_lib.load_next_deferred(); @@ -1216,7 +1221,7 @@ static void fgIdleFunction ( void ) { // We've finished all our initialization steps, from now on we // run the main loop. - fgMainLoop(); + glutIdleFunc(fgMainLoop); } else { if ( fgGetBool("/sim/startup/splash-screen") ) { fgSplashUpdate(0.0); @@ -1238,9 +1243,10 @@ void fgReshape( int width, int height ) { } // for all views - for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) { - globals->get_viewmgr()->get_view(i)-> - set_aspect_ratio((float)view_h / (float)width); + FGViewMgr *viewmgr = globals->get_viewmgr(); + for ( int i = 0; i < viewmgr->size(); ++i ) { + viewmgr->get_view(i)-> + set_aspect_ratio((float)view_h / (float)width); } glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) ); @@ -1249,13 +1255,12 @@ void fgReshape( int width, int height ) { fgSetInt("/sim/startup/ysize", height); guiInitMouse(width, height); - ssgSetFOV( globals->get_current_view()->get_h_fov(), - globals->get_current_view()->get_v_fov() ); + ssgSetFOV( viewmgr->get_current_view()->get_h_fov(), + viewmgr->get_current_view()->get_v_fov() ); fgHUDReshape(); } - // Initialize GLUT and define a main window int fgGlutInit( int *argc, char **argv ) { @@ -1284,16 +1289,38 @@ int fgGlutInit( int *argc, char **argv ) { } else { // Open the cool new 'game mode' window char game_mode_str[256]; +//#define SYNC_OPENGL_WITH_DESKTOP_SETTINGS +#if defined(WIN32) && defined(SYNC_OPENGL_WITH_DESKTOP_SETTINGS) +#ifndef ENUM_CURRENT_SETTINGS +#define ENUM_CURRENT_SETTINGS ((DWORD)-1) +#define ENUM_REGISTRY_SETTINGS ((DWORD)-2) +#endif + + DEVMODE dm; + dm.dmSize = sizeof(DEVMODE); + EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm); + fgSetInt("/sim/startup/xsize", dm.dmPelsWidth); + fgSetInt("/sim/startup/ysize", dm.dmPelsHeight); + glutInitWindowSize( fgGetInt("/sim/startup/xsize"), + fgGetInt("/sim/startup/ysize") ); + sprintf( game_mode_str, "%dx%d:%d@%d", + dm.dmPelsWidth, + dm.dmPelsHeight, + dm.dmBitsPerPel, + dm.dmDisplayFrequency ); +#else + // Open the cool new 'game mode' window sprintf( game_mode_str, "width=%d height=%d bpp=%d", fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize"), fgGetInt("/sim/rendering/bits-per-pixel")); +#endif // HAVE_WINDOWS_H SG_LOG( SG_GENERAL, SG_INFO, "game mode params = " << game_mode_str ); glutGameModeString( game_mode_str ); glutEnterGameMode(); -#endif +#endif // GLUT_WRONG_VERSION } // This seems to be the absolute earliest in the init sequence diff --git a/src/Network/atc610x.cxx b/src/Network/atc610x.cxx index a0e0c808e..ae0c3bcee 100644 --- a/src/Network/atc610x.cxx +++ b/src/Network/atc610x.cxx @@ -32,7 +32,7 @@ #include #include #include //snprintf -#if defined( _MSC_VER ) +#if defined( _MSC_VER ) || defined(__MINGW32__) # include //lseek, read, write #endif @@ -52,7 +52,7 @@ SG_USING_STD(string); -#if defined( _MSC_VER ) +#if defined( _MSC_VER ) || defined(__MINGW32__) # define snprintf _snprintf #endif diff --git a/src/Network/net_fdm.hxx b/src/Network/net_fdm.hxx index ad7bbda06..cb1aacbae 100644 --- a/src/Network/net_fdm.hxx +++ b/src/Network/net_fdm.hxx @@ -30,6 +30,8 @@ # error This library requires C++ #endif +#include // time_t + const int FG_NET_FDM_VERSION = 5; // Define a structure containing the top level flight dynamics model diff --git a/src/Scenery/tileentry.cxx b/src/Scenery/tileentry.cxx index 3d3b8c6ca..75203de9d 100644 --- a/src/Scenery/tileentry.cxx +++ b/src/Scenery/tileentry.cxx @@ -750,7 +750,7 @@ void FGTileEntry::free_tile() { // Update the ssg transform node for this tile so it can be // properly drawn relative to our (0,0,0) point -void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) { +void FGTileEntry::prep_ssg_node( const Point3D& p, sgVec3 up, float vis) { if ( !loaded ) return; SetOffset( p ); @@ -759,10 +759,14 @@ void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) { #ifdef USE_UP_AND_COMING_PLIB_FEATURE terra_range->setRange( 0, SG_ZERO ); terra_range->setRange( 1, vis + bounding_radius ); + if ( gnd_lights_range ) { gnd_lights_range->setRange( 0, SG_ZERO ); gnd_lights_range->setRange( 1, vis * 1.5 + bounding_radius ); - rwy_lights_range->setRange( 0, SG_ZERO ); - rwy_lights_range->setRange( 1, vis * 1.5 + bounding_radius ); + } + if ( rwy_lights_range ) { + rwy_lights_range->setRange( 0, SG_ZERO ); + rwy_lights_range->setRange( 1, vis * 1.5 + bounding_radius ); + } #else float ranges[2]; ranges[0] = SG_ZERO; @@ -786,8 +790,8 @@ void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) { // z-buffer fighting. We do this based on our altitude and // the distance this tile is away from scenery center. - sgVec3 up; - sgCopyVec3( up, globals->get_current_view()->get_world_up() ); +// sgVec3 up; +// sgCopyVec3( up, globals->get_current_view()->get_world_up() ); double agl; if ( current_aircraft.fdm_state ) { diff --git a/src/Scenery/tileentry.hxx b/src/Scenery/tileentry.hxx index e1fe1d35b..d29f761b0 100644 --- a/src/Scenery/tileentry.hxx +++ b/src/Scenery/tileentry.hxx @@ -224,7 +224,7 @@ public: // Update the ssg transform node for this tile so it can be // properly drawn relative to our (0,0,0) point - void prep_ssg_node( const Point3D& p, float vis); + void prep_ssg_node( const Point3D& p, sgVec3 up, float vis); /** * Load tile data from a file. diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index 1ef594afc..0847248d4 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -150,7 +150,7 @@ void FGTileMgr::sched_tile( const SGBucket& b ) { // schedule a needed buckets for loading -void FGTileMgr::schedule_needed() { +void FGTileMgr::schedule_needed( double vis) { // sanity check (unfortunately needed!) if ( longitude < -180.0 || longitude > 180.0 || latitude < -90.0 || latitude > 90.0 ) @@ -165,7 +165,7 @@ void FGTileMgr::schedule_needed() { SG_LOG( SG_TERRAIN, SG_INFO, "scheduling needed tiles for " << longitude << " " << latitude ); - vis = fgGetDouble("/environment/visibility-m"); +// vis = fgGetDouble("/environment/visibility-m"); double tile_width = current_bucket.get_width_m(); double tile_height = current_bucket.get_height_m(); @@ -227,7 +227,8 @@ void FGTileMgr::initialize_queue() // start with the center tile and work out in concentric // "rings" - schedule_needed(); + double visibility_meters = fgGetDouble("/environment/visibility-m"); + schedule_needed(visibility_meters); // do we really want to lose this? CLO #if 0 @@ -251,7 +252,7 @@ void FGTileMgr::initialize_queue() // given the current lon/lat (in degrees), fill in the array of local // chunks. If the chunk isn't already in the cache, then read it from // disk. -int FGTileMgr::update( double lon, double lat ) { +int FGTileMgr::update( double lon, double lat, double visibility_meters ) { // SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update() for " // << lon << " " << lat ); @@ -276,7 +277,7 @@ int FGTileMgr::update( double lon, double lat ) { if ( !(current_bucket == previous_bucket) ) { // We've moved to a new bucket, we need to schedule any // needed tiles for loading. - schedule_needed(); + schedule_needed(visibility_meters); } } else if ( state == Start || state == Inited ) { SG_LOG( SG_TERRAIN, SG_INFO, "State == Start || Inited" ); @@ -360,7 +361,7 @@ int FGTileMgr::update( double lon, double lat ) { sgdSetVec3( tmp_abs_view_pos, tmp.x(), tmp.y(), tmp.z() ); // cout << "abs_view_pos = " << tmp_abs_view_pos << endl; - prep_ssg_nodes(); + prep_ssg_nodes(visibility_meters); double tmp_elev; if ( fgCurrentElev(tmp_abs_view_pos, sc, &hit_list, @@ -431,10 +432,10 @@ int FGTileMgr::update( double lon, double lat ) { } -void FGTileMgr::prep_ssg_nodes() { - float vis = 0.0; +void FGTileMgr::prep_ssg_nodes(float vis) { +// float vis = 0.0; - vis = fgGetDouble("/environment/visibility-m"); +// vis = fgGetDouble("/environment/visibility-m"); // traverse the potentially viewable tile list and update range // selector and transform @@ -442,10 +443,13 @@ void FGTileMgr::prep_ssg_nodes() { FGTileEntry *e; tile_cache.reset_traversal(); + sgVec3 up; + sgCopyVec3( up, globals->get_current_view()->get_world_up() ); + while ( ! tile_cache.at_end() ) { // cout << "processing a tile" << endl; if ( (e = tile_cache.get_current()) ) { - e->prep_ssg_node( scenery.get_center(), vis); + e->prep_ssg_node( scenery.get_center(), up, vis); } else { SG_LOG(SG_INPUT, SG_ALERT, "warning ... empty tile in cache"); } diff --git a/src/Scenery/tilemgr.hxx b/src/Scenery/tilemgr.hxx index ff5fe42ba..c1955f7db 100644 --- a/src/Scenery/tilemgr.hxx +++ b/src/Scenery/tilemgr.hxx @@ -78,7 +78,7 @@ private: void sched_tile( const SGBucket& b ); // schedule a needed buckets for loading - void schedule_needed(); + void schedule_needed(double visibility_meters); // see comment at prep_ssg_nodes() void prep_ssg_node( int idx ); @@ -162,7 +162,7 @@ public: // given the current lon/lat (in degrees), fill in the array of // local chunks. If the chunk isn't already in the cache, then // read it from disk. - int update( double lon, double lat ); + int update( double lon, double lat, double visibility_meters ); // Determine scenery altitude. Normally this just happens when we // render the scene, but we'd also like to be able to do this @@ -178,7 +178,7 @@ public: // Prepare the ssg nodes ... for each tile, set it's proper // transform and update it's range selector based on current // visibilty - void prep_ssg_nodes(); + void prep_ssg_nodes(float visibility_meters); };