X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FScenery%2Ftilemgr.cxx;h=4b6cffc7400c8ab19d27c29974c58ac529193f68;hb=73b92a697d023daf128110ac96ec0d630155b6b1;hp=a8a078a09c579b81743785d2d6e92b01b98d429f;hpb=fe82a3d31fdf9f15257c57688c055f6877cf2281;p=flightgear.git diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index a8a078a09..4b6cffc74 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -41,14 +41,10 @@ #include #include
+#include
+#include
#include -#ifndef FG_OLD_WEATHER -# include -#else -# include -#endif - #include "newcache.hxx" #include "scenery.hxx" #include "tilemgr.hxx" @@ -56,8 +52,9 @@ #define TEST_LAST_HIT_CACHE extern ssgRoot *scene; -extern ssgBranch *terrain; -extern ssgBranch *ground; +extern ssgBranch *terrain_branch; // branch that holds world geometry +extern ssgBranch *gnd_lights_branch; // branch that holds ground lighting +extern ssgBranch *rwy_lights_branch; // branch that holds runway lighting // the tile manager FGTileMgr global_tile_mgr; @@ -75,6 +72,7 @@ queue FGTileMgr::model_queue; // Constructor FGTileMgr::FGTileMgr(): state( Start ), + current_tile( NULL ), vis( 16000 ), counter_hack(0) { @@ -153,16 +151,21 @@ void FGTileMgr::sched_tile( const SGBucket& b ) { // schedule a needed buckets for loading void FGTileMgr::schedule_needed() { -#ifndef FG_OLD_WEATHER - if ( WeatherDatabase != NULL ) { - vis = WeatherDatabase->getWeatherVisibility(); - } else { - vis = 16000; + // sanity check (unfortunately needed!) + if ( longitude < -180.0 || longitude > 180.0 + || latitude < -90.0 || latitude > 90.0 ) + { + SG_LOG( SG_TERRAIN, SG_ALERT, + "Attempting to schedule tiles for bogus latitude and" ); + SG_LOG( SG_TERRAIN, SG_ALERT, + "longitude. This is a FATAL error. Exiting!" ); + exit(-1); } -#else - vis = current_weather.get_visibility(); -#endif - // cout << "visibility = " << vis << endl; + + SG_LOG( SG_TERRAIN, SG_INFO, + "scheduling needed tiles for " << longitude << " " << latitude ); + + vis = fgGetDouble("/environment/visibility-m"); double tile_width = current_bucket.get_width_m(); double tile_height = current_bucket.get_height_m(); @@ -249,13 +252,9 @@ void FGTileMgr::initialize_queue() // chunks. If the chunk isn't already in the cache, then read it from // disk. int FGTileMgr::update( double lon, double lat ) { - SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update()" ); - - // FGInterface *f = current_aircraft.fdm_state; + // SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update() for " + // << lon << " " << lat ); - // lonlat for this update - // longitude = f->get_Longitude() * SGD_RADIANS_TO_DEGREES; - // latitude = f->get_Latitude() * SGD_RADIANS_TO_DEGREES; longitude = lon; latitude = lat; // SG_LOG( SG_TERRAIN, SG_DEBUG, "lon "<< lonlat[LON] << @@ -266,25 +265,28 @@ int FGTileMgr::update( double lon, double lat ) { if ( tile_cache.exists( current_bucket ) ) { current_tile = tile_cache.get_tile( current_bucket ); - scenery.next_center = current_tile->center; + scenery.set_next_center( current_tile->center ); } else { SG_LOG( SG_TERRAIN, SG_WARN, "Tile not found (Ok if initializing)" ); + scenery.set_next_center( Point3D(0.0) ); } if ( state == Running ) { + SG_LOG( SG_TERRAIN, SG_DEBUG, "State == Running" ); if ( !(current_bucket == previous_bucket) ) { // We've moved to a new bucket, we need to schedule any // needed tiles for loading. schedule_needed(); } } else if ( state == Start || state == Inited ) { + SG_LOG( SG_TERRAIN, SG_INFO, "State == Start || Inited" ); initialize_queue(); state = Running; - } - // load the next tile in the load queue (or authorize the next - // load in the case of the threaded tile pager) - loader.update(); + // load the next tile in the load queue (or authorize the next + // load in the case of the threaded tile pager) + loader.update(); + } // load the next model in the load queue. Currently this must // happen in the render thread because model loading can trigger @@ -310,7 +312,7 @@ int FGTileMgr::update( double lon, double lat ) { delete dm; } - // cout << "current elevation (ssg) == " << scenery.cur_elev << endl; + // cout << "current elevation (ssg) == " << scenery.get_cur_elev() << endl; previous_bucket = current_bucket; last_longitude = longitude; @@ -319,23 +321,32 @@ int FGTileMgr::update( double lon, double lat ) { // activate loader thread one out of every 5 frames if ( counter_hack == 0 ) { // Notify the tile loader that it can load another tile - // loader.update(); - if ( !attach_queue.empty() ) { + loader.update(); + + } + counter_hack = (counter_hack + 1) % 5; + + if ( !attach_queue.empty() ) { #ifdef ENABLE_THREADS - FGTileEntry* e = attach_queue.pop(); + FGTileEntry* e = attach_queue.pop(); #else - FGTileEntry* e = attach_queue.front(); - attach_queue.pop(); + FGTileEntry* e = attach_queue.front(); + attach_queue.pop(); #endif - e->add_ssg_nodes( terrain, ground ); - // cout << "Adding ssg nodes for " - } + e->add_ssg_nodes( terrain_branch, + gnd_lights_branch, + rwy_lights_branch ); + // cout << "Adding ssg nodes for " } - counter_hack = (counter_hack + 1) % 5; + sgdVec3 sc; - sgdSetVec3( sc, scenery.center[0], scenery.center[1], scenery.center[2] ); + sgdSetVec3( sc, + scenery.get_center()[0], + scenery.get_center()[1], + scenery.get_center()[2] ); +#if 0 if ( scenery.center == Point3D(0.0) ) { // initializing cout << "initializing scenery current elevation ... " << endl; @@ -355,24 +366,60 @@ int FGTileMgr::update( double lon, double lat ) { if ( fgCurrentElev(tmp_abs_view_pos, sc, &hit_list, &tmp_elev, &scenery.cur_radius, scenery.cur_normal) ) { - scenery.cur_elev = tmp_elev; + scenery.set_cur_elev( tmp_elev ); } else { - scenery.cur_elev = 0.0; + scenery.set_cur_elev( 0.0 ); } - cout << "result = " << scenery.cur_elev << endl; + cout << "result = " << scenery.get_cur_elev() << endl; } else { - // cout << "abs view pos = " << current_view.abs_view_pos - // << " view pos = " << current_view.view_pos << endl; - double tmp_elev; - if ( fgCurrentElev(globals->get_current_view()->get_abs_view_pos(), - sc, &hit_list, - &tmp_elev, &scenery.cur_radius, scenery.cur_normal) ) - { - scenery.cur_elev = tmp_elev; - } else { - scenery.cur_elev = 0.0; - } +#endif + /* + cout << "abs view pos = " + << globals->get_current_view()->get_abs_view_pos()[0] << "," + << globals->get_current_view()->get_abs_view_pos()[1] << "," + << globals->get_current_view()->get_abs_view_pos()[2] + << " view pos = " + << globals->get_current_view()->get_view_pos()[0] << "," + << globals->get_current_view()->get_view_pos()[1] << "," + << globals->get_current_view()->get_view_pos()[2] + << endl; + cout << "current_tile = " << current_tile << endl; + cout << "Scenery center = " << sc[0] << "," << sc[1] << "," << sc[2] + << endl; + */ + + // overridden with actual values if a terrain intersection is + // found + double hit_elev = -9999.0; + double hit_radius = 0.0; + sgdVec3 hit_normal = { 0.0, 0.0, 0.0 }; + + bool hit = false; + if ( fabs(sc[0]) > 1.0 || fabs(sc[1]) > 1.0 || fabs(sc[2]) > 1.0 ) { + // scenery center has been properly defined so any hit + // should be valid (and not just luck) + hit = fgCurrentElev(globals->get_current_view()->get_abs_view_pos(), + sc, + &hit_list, + &hit_elev, + &hit_radius, + hit_normal); + } + + if ( hit ) { + scenery.set_cur_elev( hit_elev ); + scenery.set_cur_radius( hit_radius ); + scenery.set_cur_normal( hit_normal ); + } else { + scenery.set_cur_elev( -9999.0 ); + scenery.set_cur_radius( 0.0 ); + scenery.set_cur_normal( hit_normal ); + } + + // cout << "Current elevation = " << scenery.get_cur_elev() << endl; +#if 0 } +#endif return 1; } @@ -381,16 +428,7 @@ int FGTileMgr::update( double lon, double lat ) { void FGTileMgr::prep_ssg_nodes() { float vis = 0.0; -#ifndef FG_OLD_WEATHER - if ( WeatherDatabase ) { - vis = WeatherDatabase->getWeatherVisibility(); - } else { - vis = 16000; - } -#else - vis = current_weather.get_visibility(); -#endif - // cout << "visibility = " << vis << endl; + vis = fgGetDouble("/environment/visibility-m"); // traverse the potentially viewable tile list and update range // selector and transform @@ -401,7 +439,7 @@ void FGTileMgr::prep_ssg_nodes() { while ( ! tile_cache.at_end() ) { // cout << "processing a tile" << endl; if ( (e = tile_cache.get_current()) ) { - e->prep_ssg_node( scenery.center, vis); + e->prep_ssg_node( scenery.get_center(), vis); } else { cout << "warning ... empty tile in cache" << endl; }