#include <simgear/math/vector.hxx>
#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+#include <Main/viewer.hxx>
#include <Objects/obj.hxx>
-#ifndef FG_OLD_WEATHER
-# include <WeatherCM/FGLocalWeatherDatabase.h>
-#else
-# include <Weather/weather.hxx>
-#endif
-
#include "newcache.hxx"
#include "scenery.hxx"
#include "tilemgr.hxx"
#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;
// Constructor
FGTileMgr::FGTileMgr():
state( Start ),
+ current_tile( NULL ),
vis( 16000 ),
counter_hack(0)
{
// 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();
// 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] <<
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
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;
// 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;
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;
}
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
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;
}