1
0
Fork 0

Updates to move scenery initialization earlier in the initialization

sequence so that the FDM can know the current ground altitude when it is
initialized.
This commit is contained in:
curt 2000-07-23 21:32:59 +00:00
parent 0c8c3ac0d6
commit 941f27c9a0
8 changed files with 101 additions and 96 deletions

View file

@ -1042,6 +1042,8 @@ void AptDialog_OK (puObject *)
if ( airports.search( AptId, &a ) )
{
current_options.set_airport_id( AptId.c_str() );
current_options.set_altitude( -9999.0 );
fgSetPosFromAirportID( AptId );
BusyCursor(0);
fgReInitSubsystems();
BusyCursor(1);

View file

@ -188,17 +188,14 @@ bool fgInitPosition( void ) {
FGInterface *f = current_aircraft.fdm_state;
string id = current_options.get_airport_id();
if ( id.length() ) {
// set initial position from airport id
if ( ! fgSetPosFromAirportID( id ) ) {
exit(-1);
}
}
// set initial position from default or command line coordinates
f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
if ( scenery.cur_elev > current_options.get_altitude() - 2 ) {
current_options.set_altitude( scenery.cur_elev + 2 );
}
FG_LOG( FG_GENERAL, FG_INFO,
"starting altitude is = " << current_options.get_altitude() );
@ -266,6 +263,36 @@ bool fgInitSubsystems( void ) {
FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
// Initialize the material property lib
FGPath mpath( current_options.get_fg_root() );
mpath.append( "materials" );
if ( material_lib.load( mpath.str() ) ) {
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error loading material lib!" );
exit(-1);
}
// Initialize the Scenery Management subsystem
if ( fgSceneryInit() ) {
// Material lib initialized ok.
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
exit(-1);
}
if ( global_tile_mgr.init() ) {
// Load the local scenery data
global_tile_mgr.update( current_options.get_lon(),
current_options.get_lat() );
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
exit(-1);
}
FG_LOG( FG_GENERAL, FG_DEBUG,
"Current terrain elevation after tile mgr init " <<
scenery.cur_elev );
if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
cur_fdm_state = new FGLaRCsim;
} else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
@ -292,36 +319,6 @@ bool fgInitSubsystems( void ) {
// set the initial position
fgInitPosition();
// Initialize the material property lib
FGPath mpath( current_options.get_fg_root() );
mpath.append( "materials" );
if ( material_lib.load( mpath.str() ) ) {
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error loading material lib!" );
exit(-1);
}
// Initialize the Scenery Management subsystem
if ( fgSceneryInit() ) {
// Material lib initialized ok.
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
exit(-1);
}
if( global_tile_mgr.init() ) {
// Load the local scenery data
global_tile_mgr.update( cur_fdm_state->get_Longitude(),
cur_fdm_state->get_Latitude() );
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
exit(-1);
}
FG_LOG( FG_GENERAL, FG_DEBUG,
"Current terrain elevation after tile mgr init " <<
scenery.cur_elev );
// Calculate ground elevation at starting point (we didn't have
// tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
//
@ -613,15 +610,18 @@ void fgReInitSubsystems( void )
if( !freeze )
globals->set_freeze( true );
fgInitPosition();
if( global_tile_mgr.init() ) {
// Load the local scenery data
global_tile_mgr.update( cur_fdm_state->get_Longitude(),
cur_fdm_state->get_Latitude() );
global_tile_mgr.update( current_options.get_lon(),
current_options.get_lat() );
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
exit(-1);
}
// cout << "current scenery elev = " << scenery.cur_elev << endl;
fgInitPosition();
fgFDMSetGroundElevation( current_options.get_flight_model(),
scenery.cur_elev );

View file

@ -476,10 +476,11 @@ void GLUTspecialkey(int k, int x, int y) {
if ( !freeze )
globals->set_freeze( true );
BusyCursor(0);
if( global_tile_mgr.init() ) {
if ( global_tile_mgr.init() ) {
// Load the local scenery data
global_tile_mgr.update( cur_fdm_state->get_Longitude(),
cur_fdm_state->get_Latitude() );
global_tile_mgr.update(
cur_fdm_state->get_Longitude() * RAD_TO_DEG,
cur_fdm_state->get_Latitude() * RAD_TO_DEG );
} else {
FG_LOG( FG_GENERAL, FG_ALERT,
"Error in Tile Manager initialization!" );

View file

@ -879,8 +879,8 @@ static void fgMainLoop( void ) {
#endif
// see if we need to load any new scenery tiles
global_tile_mgr.update( cur_fdm_state->get_Longitude(),
cur_fdm_state->get_Latitude() );
global_tile_mgr.update( cur_fdm_state->get_Longitude() * RAD_TO_DEG,
cur_fdm_state->get_Latitude() * RAD_TO_DEG );
// Process/manage pending events
global_events.Process();

View file

@ -52,18 +52,11 @@ struct fgSCENERY scenery;
// Initialize the Scenery Management system
int fgSceneryInit( void ) {
fgOPTIONS *o;
// char path[1024], fgpath[1024];
// GLubyte *texbuf;
// int width, height;
o = &current_options;
FG_LOG( FG_TERRAIN, FG_INFO, "Initializing scenery subsystem" );
scenery.cur_elev = -9999;
return(1);
return 1;
}

View file

@ -114,7 +114,7 @@ FGTileCache::init( void )
// and ... just in case we missed something ...
terrain->removeAllKids();
FG_LOG( FG_TERRAIN, FG_DEBUG, " done with init()" );
FG_LOG( FG_TERRAIN, FG_INFO, " done with init()" );
}

View file

@ -39,7 +39,7 @@
#include <simgear/math/polar3d.hxx>
#include <simgear/math/vector.hxx>
#include <Aircraft/aircraft.hxx>
// #include <Aircraft/aircraft.hxx>
#include <Main/options.hxx>
#include <Main/views.hxx>
#include <Objects/obj.hxx>
@ -88,7 +88,7 @@ int FGTileMgr::init( void ) {
if ( state != Start ) {
FG_LOG( FG_TERRAIN, FG_INFO,
"ReInitializing the Tile Manager subsystem." );
"... Reinitializing." );
// This is necessay to keep bookeeping straight for the
// tile_cache -- which actually handles all the
@ -102,7 +102,7 @@ int FGTileMgr::init( void ) {
}
} else {
FG_LOG( FG_TERRAIN, FG_INFO,
"Initializing Tile Manager subsystem." );
"... First time through." );
}
global_tile_cache.init();
@ -304,13 +304,12 @@ void FGTileMgr::scroll( void )
}
void FGTileMgr::initialize_queue( void )
void FGTileMgr::initialize_queue()
{
// First time through or we have teleported, initialize the
// system and load all relavant tiles
FG_LOG( FG_TERRAIN, FG_INFO, "Updating Tile list for " << current_bucket );
FG_LOG( FG_TERRAIN, FG_INFO, " First time through ... " );
FG_LOG( FG_TERRAIN, FG_INFO, " Updating Tile list for " << current_bucket );
FG_LOG( FG_TERRAIN, FG_INFO, " Loading "
<< tile_diameter * tile_diameter << " tiles" );
@ -328,12 +327,6 @@ void FGTileMgr::initialize_queue( void )
// "rings"
sched_tile( current_bucket );
Point3D geod_view_center( current_bucket.get_center_lon(),
current_bucket.get_center_lat(),
cur_fdm_state->get_Altitude()*FEET_TO_METER + 3 );
current_view.abs_view_pos = fgGeodToCart( geod_view_center );
current_view.view_pos = current_view.abs_view_pos - scenery.next_center;
for ( i = 3; i <= tile_diameter; i = i + 2 ) {
int j;
@ -372,16 +365,19 @@ void FGTileMgr::initialize_queue( void )
}
// given the current lon/lat, 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 junk1, double junk2 ) {
// 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 ) {
// FG_LOG( FG_TERRAIN, FG_DEBUG, "FGTileMgr::update()" );
FGInterface *f = current_aircraft.fdm_state;
// FGInterface *f = current_aircraft.fdm_state;
// lonlat for this update
longitude = f->get_Longitude() * RAD_TO_DEG;
latitude = f->get_Latitude() * RAD_TO_DEG;
// longitude = f->get_Longitude() * RAD_TO_DEG;
// latitude = f->get_Latitude() * RAD_TO_DEG;
longitude = lon;
latitude = lat;
// FG_LOG( FG_TERRAIN, FG_DEBUG, "lon "<< lonlat[LON] <<
// " lat " << lonlat[LAT] );
@ -395,7 +391,7 @@ int FGTileMgr::update( double junk1, double junk2 ) {
current_tile = global_tile_cache.get_tile(tile_index);
scenery.next_center = current_tile->center;
} else {
FG_LOG( FG_TERRAIN, FG_WARN, "Tile not found" );
FG_LOG( FG_TERRAIN, FG_WARN, "Tile not found (Ok if initializing)" );
}
if ( state == Running ) {
@ -438,7 +434,7 @@ int FGTileMgr::update( double junk1, double junk2 ) {
scroll();
}
} else if ( (state == Start) || (state == Inited) ) {
} else if ( state == Start || state == Inited ) {
initialize_queue();
state = Running;
}
@ -451,19 +447,25 @@ int FGTileMgr::update( double junk1, double junk2 ) {
load_tile( pending.b, pending.cache_index );
}
// find our current elevation (feed in the current bucket to save work)
// Point3D geod_pos = Point3D( f->get_Longitude(), f->get_Latitude(), 0.0);
// Point3D tmp_abs_view_pos = fgGeodToCart(geod_pos);
if ( scenery.center == Point3D(0.0) ) {
// initializing
// cout << "initializing ... " << endl;
Point3D geod_pos = Point3D( longitude * DEG_TO_RAD,
latitude * DEG_TO_RAD,
0.0);
Point3D tmp_abs_view_pos = fgGeodToCart( geod_pos );
scenery.center = tmp_abs_view_pos;
// cout << "abs_view_pos = " << tmp_abs_view_pos << endl;
prep_ssg_nodes();
current_elev_ssg( tmp_abs_view_pos,
Point3D( 0.0 ) );
} else {
// cout << "abs view pos = " << current_view.abs_view_pos
// << " view pos = " << current_view.view_pos << endl;
current_elev_ssg( current_view.abs_view_pos,
current_view.view_pos );
}
// cout << "current elevation (old) == "
// << current_elev( f->get_Longitude(), f->get_Latitude(),
// tmp_abs_view_pos )
// << endl;
// set scenery.cur_elev and scenery.cur_radius
current_elev_ssg( current_view.abs_view_pos,
current_view.view_pos );
// cout << "current elevation (ssg) == " << scenery.cur_elev << endl;
previous_bucket = current_bucket;
@ -483,6 +485,18 @@ void FGTileMgr::prep_ssg_nodes( void ) {
FGTileEntry *t;
float ranges[2];
ranges[0] = 0.0f;
double vis = 0.0;
#ifndef FG_OLD_WEATHER
if ( WeatherDatabase != NULL ) {
vis = WeatherDatabase->getWeatherVisibility();
} else {
vis = 16000;
}
#else
vis = current_weather.get_visibility();
#endif
// cout << "visibility = " << vis << endl;
// traverse the potentially viewable tile list and update range
// selector and transform
@ -493,12 +507,7 @@ void FGTileMgr::prep_ssg_nodes( void ) {
// set range selector (LOD trick) to be distance to center
// of tile + bounding radius
#ifndef FG_OLD_WEATHER
ranges[1] = WeatherDatabase->getWeatherVisibility()
+ t->bounding_radius;
#else
ranges[1] = current_weather.get_visibility()+t->bounding_radius;
#endif
ranges[1] = vis + t->bounding_radius;
t->range_ptr->setRanges( ranges, 2 );
// calculate tile offset

View file

@ -94,7 +94,7 @@ private:
list < FGLoadRec > load_queue;
// initialize the cache
void initialize_queue( void );
void initialize_queue();
FGBucket BucketOffset( int dx, int dy );
@ -143,10 +143,10 @@ public:
// Initialize the Tile Manager subsystem
int init( void );
// given the current lon/lat, fill in the array of local chunks.
// If the chunk isn't already in the cache, then read it from
// disk.
int update( double junk1, double junk2 );
// 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 );
// Determine scenery altitude. Normally this just happens when we
// render the scene, but we'd also like to be able to do this