]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scenery/tilemgr.cxx
Further restructuring of the scenery loading code.
[flightgear.git] / src / Scenery / tilemgr.cxx
index 59f3c5fba60467e37cf22d265480056b82a6bfc0..4b6cffc7400c8ab19d27c29974c58ac529193f68 100644 (file)
 #include <simgear/math/vector.hxx>
 
 #include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
 #include <Main/viewer.hxx>
 #include <Objects/obj.hxx>
 
-#ifndef FG_NEW_ENVIRONMENT
-#  include <WeatherCM/FGLocalWeatherDatabase.h>
-#else
-#  include <Environment/environment.hxx>
-#endif
-
 #include "newcache.hxx"
 #include "scenery.hxx"
 #include "tilemgr.hxx"
@@ -57,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;
@@ -76,6 +72,7 @@ queue<FGDeferredModel *> FGTileMgr::model_queue;
 // Constructor
 FGTileMgr::FGTileMgr():
     state( Start ),
+    current_tile( NULL ),
     vis( 16000 ),
     counter_hack(0)
 {
@@ -168,16 +165,7 @@ void FGTileMgr::schedule_needed() {
    SG_LOG( SG_TERRAIN, SG_INFO,
            "scheduling needed tiles for " << longitude << " " << latitude );
 
-#ifndef FG_NEW_ENVIRONMENT
-    if ( WeatherDatabase != NULL ) {
-       vis = WeatherDatabase->getWeatherVisibility();
-    } else {
-       vis = 16000;
-    }
-#else
-    vis = current_environment.get_visibility_m();
-#endif
-    // cout << "visibility = " << vis << endl;
+   vis = fgGetDouble("/environment/visibility-m");
 
     double tile_width = current_bucket.get_width_m();
     double tile_height = current_bucket.get_height_m();
@@ -280,6 +268,7 @@ int FGTileMgr::update( double lon, double lat ) {
         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 ) {
@@ -345,15 +334,17 @@ int FGTileMgr::update( double lon, double lat ) {
        FGTileEntry* e = attach_queue.front();
        attach_queue.pop();
 #endif
-       e->add_ssg_nodes( terrain, ground );
+       e->add_ssg_nodes( terrain_branch,
+                         gnd_lights_branch,
+                         rwy_lights_branch );
        // cout << "Adding ssg nodes for "
     }
 
     sgdVec3 sc;
     sgdSetVec3( sc,
-               scenery.get_center()[0],
-               scenery.get_center()[1],
-               scenery.get_center()[2] );
+                scenery.get_center()[0],
+                scenery.get_center()[1],
+                scenery.get_center()[2] );
 
 #if 0
     if ( scenery.center == Point3D(0.0) ) {
@@ -382,21 +373,49 @@ int FGTileMgr::update( double lon, double lat ) {
        cout << "result = " << scenery.get_cur_elev() << endl;
     } else {
 #endif
-       // cout << "abs view pos = " << current_view.abs_view_pos
-       //      << " view pos = " << current_view.view_pos << endl;
-       double tmp_elev;
-       double tmp_radius;
-       sgdVec3 tmp_normal;
-       if ( fgCurrentElev(globals->get_current_view()->get_abs_view_pos(),
-                          sc, &hit_list,
-                          &tmp_elev, &tmp_radius, tmp_normal) )
-       {
-           scenery.set_cur_elev( tmp_elev );
-           scenery.set_cur_radius( tmp_radius );
-           scenery.set_cur_normal( tmp_normal );
-       } else {
-           scenery.set_cur_elev( -9999.0 );
-       }
+        /*
+       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
     }
@@ -409,16 +428,7 @@ int FGTileMgr::update( double lon, double lat ) {
 void FGTileMgr::prep_ssg_nodes() {
     float vis = 0.0;
 
-#ifndef FG_NEW_ENVIRONMENT
-    if ( WeatherDatabase ) {
-       vis = WeatherDatabase->getWeatherVisibility();
-    } else {
-       vis = 16000;
-    }
-#else
-    vis = current_environment.get_visibility_m();
-#endif
-    // cout << "visibility = " << vis << endl;
+    vis = fgGetDouble("/environment/visibility-m");
 
     // traverse the potentially viewable tile list and update range
     // selector and transform