1
0
Fork 0

This set of changes touches a *lot* of files. The main goal here is to

fix startup sequence problems where we initialize the FDM before we know
the desired starting altitude.

These changes delay fdm initialization until the local tile has been loaded
and we can do a real intersection and find the true ground elevation.

In order to do this, I depend more on the property manager as glue, rather
than the FGInterface.

There are some glitches still when switching to a new airport or reseting
the sim.  I will work on addressing these, but I need to commit the changes
so far to keep in sync with other developers.
This commit is contained in:
curt 2001-10-28 16:16:30 +00:00
parent eacec814e1
commit 2b056c8452
21 changed files with 361 additions and 191 deletions

2
aclocal.m4 vendored
View file

@ -1,4 +1,4 @@
dnl aclocal.m4 generated automatically by aclocal 1.4 dnl aclocal.m4 generated automatically by aclocal 1.4-p4
dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation

View file

@ -913,7 +913,7 @@ static inline double fgAPget_agl( void ) {
double agl; double agl;
agl = cur_fdm_state->get_Altitude() * SG_FEET_TO_METER agl = cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
- scenery.cur_elev; - scenery.get_cur_elev();
return( agl ); return( agl );
} }
@ -929,8 +929,8 @@ void FGAutopilot::AltitudeSet( double new_altitude ) {
target_alt = new_altitude * SG_FEET_TO_METER; target_alt = new_altitude * SG_FEET_TO_METER;
} }
if( target_alt < scenery.cur_elev ) { if( target_alt < scenery.get_cur_elev() ) {
target_alt = scenery.cur_elev; target_alt = scenery.get_cur_elev();
} }
TargetAltitude = target_alt; TargetAltitude = target_alt;

View file

@ -198,10 +198,10 @@ float get_agl( void )
if ( fgGetString("/sim/startup/units") == "feet" ) { if ( fgGetString("/sim/startup/units") == "feet" ) {
agl = (current_aircraft.fdm_state->get_Altitude() agl = (current_aircraft.fdm_state->get_Altitude()
- scenery.cur_elev * SG_METER_TO_FEET); - scenery.get_cur_elev() * SG_METER_TO_FEET);
} else { } else {
agl = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER agl = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- scenery.cur_elev); - scenery.get_cur_elev());
} }
return agl; return agl;

View file

@ -228,8 +228,7 @@ bool FGADA::update( int multiloop ) {
// Convert from the FGInterface struct to the FGADA struct (output) // Convert from the FGInterface struct to the FGADA struct (output)
bool FGADA::copy_to_FGADA () { bool FGADA::copy_to_FGADA () {
ground_elevation = scenery.get_cur_elev();
ground_elevation = scenery.cur_elev;
return true; return true;
} }

View file

@ -294,7 +294,7 @@ bool FGJSBsim::copy_to_JSBsim() {
} }
Position->SetSeaLevelRadius( get_Sea_level_radius() ); Position->SetSeaLevelRadius( get_Sea_level_radius() );
Position->SetRunwayRadius( scenery.cur_elev*SG_METER_TO_FEET Position->SetRunwayRadius( scenery.get_cur_elev()*SG_METER_TO_FEET
+ get_Sea_level_radius() ); + get_Sea_level_radius() );
Atmosphere->SetExTemperature(get_Static_temperature()); Atmosphere->SetExTemperature(get_Static_temperature());

View file

@ -185,7 +185,7 @@ bool FGLaRCsim::update( int multiloop ) {
// Inform LaRCsim of the local terrain altitude // Inform LaRCsim of the local terrain altitude
// Runway_altitude = get_Runway_altitude(); // Runway_altitude = get_Runway_altitude();
Runway_altitude = scenery.cur_elev * SG_METER_TO_FEET; Runway_altitude = scenery.get_cur_elev() * SG_METER_TO_FEET;
// Weather // Weather
/* V_north_airmass = get_V_north_airmass(); /* V_north_airmass = get_V_north_airmass();

View file

@ -78,7 +78,6 @@ FGInterface::FGInterface() {
} }
FGInterface::FGInterface( double dt ) { FGInterface::FGInterface( double dt ) {
_setup(); _setup();
delta_t = dt; delta_t = dt;
remainder = elapsed = multi_loop = 0; remainder = elapsed = multi_loop = 0;
@ -98,6 +97,9 @@ FGInterface::~FGInterface() {
void void
FGInterface::_setup () FGInterface::_setup ()
{ {
inited = false;
bound = false;
init_vec( d_pilot_rp_body_v ); init_vec( d_pilot_rp_body_v );
init_vec( d_cg_rp_body_v ); init_vec( d_cg_rp_body_v );
init_vec( f_body_total_v ); init_vec( f_body_total_v );
@ -179,6 +181,8 @@ FGInterface::init ()
{ {
SG_LOG(SG_FLIGHT, SG_INFO, "Start initializing FGInterface"); SG_LOG(SG_FLIGHT, SG_INFO, "Start initializing FGInterface");
inited = true;
stamp(); stamp();
set_remainder(0); set_remainder(0);
@ -186,7 +190,7 @@ FGInterface::init ()
SG_LOG(SG_FLIGHT, SG_INFO, "...initializing position..."); SG_LOG(SG_FLIGHT, SG_INFO, "...initializing position...");
set_Longitude(fgGetDouble("/position/longitude-deg") * SGD_DEGREES_TO_RADIANS); set_Longitude(fgGetDouble("/position/longitude-deg") * SGD_DEGREES_TO_RADIANS);
set_Latitude(fgGetDouble("/position/latitude-deg") * SGD_DEGREES_TO_RADIANS); set_Latitude(fgGetDouble("/position/latitude-deg") * SGD_DEGREES_TO_RADIANS);
double ground_elev_m = scenery.cur_elev + 1; double ground_elev_m = scenery.get_cur_elev() + 1;
double ground_elev_ft = ground_elev_m * METERS_TO_FEET; double ground_elev_ft = ground_elev_m * METERS_TO_FEET;
if (fgGetBool("/sim/startup/onground") || if (fgGetBool("/sim/startup/onground") ||
fgGetDouble("/position/altitude-ft") < ground_elev_ft) fgGetDouble("/position/altitude-ft") < ground_elev_ft)
@ -201,6 +205,8 @@ FGInterface::init ()
// Set sea-level radius // Set sea-level radius
SG_LOG(SG_FLIGHT, SG_INFO, "...initializing sea-level radius..."); SG_LOG(SG_FLIGHT, SG_INFO, "...initializing sea-level radius...");
SG_LOG(SG_FLIGHT, SG_INFO, " lat = " << get_Latitude() << " alt = "
<< get_Altitude() );
double sea_level_radius_meters; double sea_level_radius_meters;
double lat_geoc; double lat_geoc;
sgGeodToGeoc(get_Latitude(), get_Altitude(), sgGeodToGeoc(get_Latitude(), get_Altitude(),
@ -255,6 +261,8 @@ FGInterface::init ()
void void
FGInterface::bind () FGInterface::bind ()
{ {
bound = true;
// Time management (read-only) // Time management (read-only)
fgTie("/fdm/time/delta_t", this, fgTie("/fdm/time/delta_t", this,
&FGInterface::get_delta_t); // read-only &FGInterface::get_delta_t); // read-only
@ -364,6 +372,8 @@ FGInterface::bind ()
void void
FGInterface::unbind () FGInterface::unbind ()
{ {
bound = false;
fgUntie("/fdm/time/delta_t"); fgUntie("/fdm/time/delta_t");
fgUntie("/fdm/time/elapsed"); fgUntie("/fdm/time/elapsed");
fgUntie("/fdm/time/remainder"); fgUntie("/fdm/time/remainder");
@ -371,9 +381,10 @@ FGInterface::unbind ()
fgUntie("/position/latitude-deg"); fgUntie("/position/latitude-deg");
fgUntie("/position/longitude-deg"); fgUntie("/position/longitude-deg");
fgUntie("/position/altitude-ft"); fgUntie("/position/altitude-ft");
fgUntie("/position/heading"); fgUntie("/position/altitude-agl-ft");
fgUntie("/position/pitch"); fgUntie("/orientation/heading-deg");
fgUntie("/position/roll"); fgUntie("/orientation/pitch-deg");
fgUntie("/orientation/roll-deg");
fgUntie("/velocities/airspeed-kt"); fgUntie("/velocities/airspeed-kt");
fgUntie("/velocities/speed-north-fps"); fgUntie("/velocities/speed-north-fps");
fgUntie("/velocities/speed-east-fps"); fgUntie("/velocities/speed-east-fps");
@ -426,7 +437,7 @@ void FGInterface::_updatePosition( double lat_geoc, double lon, double alt ) {
_set_Geodetic_Position( lat_geod, lon, alt ); _set_Geodetic_Position( lat_geod, lon, alt );
_set_Sea_level_radius( sl_radius2 * SG_METER_TO_FEET ); _set_Sea_level_radius( sl_radius2 * SG_METER_TO_FEET );
_set_Runway_altitude( scenery.cur_elev*METERS_TO_FEET ); _set_Runway_altitude( scenery.get_cur_elev()*METERS_TO_FEET );
_set_sin_lat_geocentric( lat_geoc ); _set_sin_lat_geocentric( lat_geoc );
_set_cos_lat_geocentric( lat_geoc ); _set_cos_lat_geocentric( lat_geoc );

View file

@ -183,6 +183,14 @@ class FGInterface : public FGSubsystem {
private: private:
// Has the init() method been called. This is used to delay
// initialization until scenery can be loaded and we know the true
// ground elevation.
bool inited;
// Have we bound to the property system
bool bound;
// periodic update management variable. This is a scheme to run // periodic update management variable. This is a scheme to run
// the fdm with a fixed delta-t. We control how many iteration of // the fdm with a fixed delta-t. We control how many iteration of
// the fdm to run with the fixed dt based on the elapsed time from // the fdm to run with the fixed dt based on the elapsed time from
@ -507,6 +515,12 @@ public:
FG_EXTERNAL = 10 FG_EXTERNAL = 10
}; };
// initialization
inline bool get_inited() const { return inited; }
inline void set_inited( bool value ) { inited = value; }
inline bool get_bound() const { return bound; }
// time and update management values // time and update management values
inline double get_delta_t() const { return delta_t; } inline double get_delta_t() const { return delta_t; }
inline void set_delta_t( double dt ) { delta_t = dt; } inline void set_delta_t( double dt ) { delta_t = dt; }

View file

@ -51,6 +51,11 @@ void AptDialog_Cancel(puObject *)
void AptDialog_OK (puObject *) void AptDialog_OK (puObject *)
{ {
static const SGPropertyNode *longitude
= fgGetNode("/position/longitude-deg");
static const SGPropertyNode *latitude
= fgGetNode("/position/latitude-deg");
SGPath path( globals->get_fg_root() ); SGPath path( globals->get_fg_root() );
path.append( "Airports" ); path.append( "Airports" );
path.append( "simple.mk4" ); path.append( "simple.mk4" );
@ -78,6 +83,11 @@ void AptDialog_OK (puObject *)
if ( airports.search( AptId, &a ) ) if ( airports.search( AptId, &a ) )
{ {
// unbind the current fdm state so property changes
// don't get lost when we subsequently delete this fdm
// and create a new one.
cur_fdm_state->unbind();
AptId = a.id.c_str(); /// NHV fix wrong case crash AptId = a.id.c_str(); /// NHV fix wrong case crash
fgSetString("/sim/startup/airport-id", AptId.c_str() ); fgSetString("/sim/startup/airport-id", AptId.c_str() );
// fgSetDouble("/position/altitude-ft", -9999.0 ); // fgSetDouble("/position/altitude-ft", -9999.0 );
@ -87,26 +97,24 @@ void AptDialog_OK (puObject *)
SGD_RADIANS_TO_DEGREES); SGD_RADIANS_TO_DEGREES);
BusyCursor(0); BusyCursor(0);
fgReInitSubsystems(); fgReInitSubsystems();
if ( global_tile_mgr.init() ) { // if ( global_tile_mgr.init() ) {
// Load the local scenery data // Load the local scenery data
global_tile_mgr.update( global_tile_mgr.update( longitude->getDoubleValue(),
cur_fdm_state->get_Longitude() longitude->getDoubleValue() );
* SGD_RADIANS_TO_DEGREES, // } else {
cur_fdm_state->get_Latitude() // SG_LOG( SG_GENERAL, SG_ALERT,
* SGD_RADIANS_TO_DEGREES ); // "Error in Tile Manager initialization!" );
} else { // exit(-1);
SG_LOG( SG_GENERAL, SG_ALERT, // }
"Error in Tile Manager initialization!" );
exit(-1);
}
BusyCursor(1); BusyCursor(1);
} else { } else {
AptId += " not in database."; AptId += " not in database.";
mkDialog(AptId.c_str()); mkDialog(AptId.c_str());
} }
} }
if(!freeze) if ( !freeze ) {
globals->set_freeze( false ); globals->set_freeze( false );
}
} }

View file

@ -455,7 +455,7 @@ bool fgInitGeneral( void ) {
if ( ! root.length() ) { if ( ! root.length() ) {
// No root path set? Then bail ... // No root path set? Then bail ...
SG_LOG( SG_GENERAL, SG_ALERT, SG_LOG( SG_GENERAL, SG_ALERT,
"Cannot continue without environment variable FG_ROOT" "Cannot continue without a path to the base package "
<< "being defined." ); << "being defined." );
exit(-1); exit(-1);
} }
@ -508,12 +508,8 @@ bool fgInitSubsystems( void ) {
// Initialize the scenery management subsystem. // Initialize the scenery management subsystem.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
if ( fgSceneryInit() ) { scenery.init();
// Material lib initialized ok. scenery.bind();
} else {
SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
exit(-1);
}
if ( global_tile_mgr.init() ) { if ( global_tile_mgr.init() ) {
// Load the local scenery data // Load the local scenery data
@ -526,7 +522,7 @@ bool fgInitSubsystems( void ) {
SG_LOG( SG_GENERAL, SG_DEBUG, SG_LOG( SG_GENERAL, SG_DEBUG,
"Current terrain elevation after tile mgr init " << "Current terrain elevation after tile mgr init " <<
scenery.cur_elev ); scenery.get_cur_elev() );
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -562,8 +558,10 @@ bool fgInitSubsystems( void ) {
exit(-1); exit(-1);
} }
cur_fdm_state->init(); // Actual fdm initialization is delayed until we get a proper
cur_fdm_state->bind(); // scenery elevation hit. This is checked for in main.cxx
// cur_fdm_state->init();
// cur_fdm_state->bind();
// allocates structures so must happen before any of the flight // allocates structures so must happen before any of the flight
// model or control parameters are set // model or control parameters are set
@ -839,26 +837,61 @@ bool fgInitSubsystems( void ) {
void fgReInitSubsystems( void ) void fgReInitSubsystems( void )
{ {
static const SGPropertyNode *longitude
= fgGetNode("/position/longitude-deg");
static const SGPropertyNode *latitude
= fgGetNode("/position/latitude-deg");
static const SGPropertyNode *altitude
= fgGetNode("/position/altitude-ft");
SG_LOG( SG_GENERAL, SG_INFO, SG_LOG( SG_GENERAL, SG_INFO,
"/position/altitude = " << fgGetDouble("/position/altitude-ft") ); "/position/altitude = " << altitude->getDoubleValue() );
bool freeze = globals->get_freeze(); bool freeze = globals->get_freeze();
if( !freeze ) if( !freeze ) {
globals->set_freeze( true ); globals->set_freeze( true );
}
// Initialize the Scenery Management subsystem // Initialize the Scenery Management subsystem
if ( ! fgSceneryInit() ) { scenery.init();
SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
exit(-1);
}
if( global_tile_mgr.init() ) { // if( global_tile_mgr.init() ) {
// Load the local scenery data // Load the local scenery data
global_tile_mgr.update( fgGetDouble("/position/longitude-deg"), global_tile_mgr.update( longitude->getDoubleValue(),
fgGetDouble("/position/latitude-deg") ); latitude->getDoubleValue() );
} else { // } else {
SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" ); // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
exit(-1); // exit(-1);
// }
// Delete then Initialize the flight model subsystem.
delete cur_fdm_state;
double dt = 1.0 / fgGetInt("/sim/model-hz");
aircraft_dir = fgGetString("/sim/aircraft-dir");
const string &model = fgGetString("/sim/flight-model");
try {
if (model == "larcsim") {
cur_fdm_state = new FGLaRCsim( dt );
} else if (model == "jsb") {
cur_fdm_state = new FGJSBsim( dt );
} else if (model == "ada") {
cur_fdm_state = new FGADA( dt );
} else if (model == "balloon") {
cur_fdm_state = new FGBalloonSim( dt );
} else if (model == "magic") {
cur_fdm_state = new FGMagicCarpet( dt );
} else if (model == "external") {
cur_fdm_state = new FGExternal( dt );
} else {
SG_LOG(SG_GENERAL, SG_ALERT,
"Unrecognized flight model '" << model
<< ", can't init aircraft");
exit(-1);
}
} catch ( ... ) {
SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
exit(-1);
} }
// Initialize view parameters // Initialize view parameters
@ -868,12 +901,12 @@ void fgReInitSubsystems( void )
pilot_view->set_view_offset( 0.0 ); pilot_view->set_view_offset( 0.0 );
pilot_view->set_goal_view_offset( 0.0 ); pilot_view->set_goal_view_offset( 0.0 );
pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), pilot_view->set_geod_view_pos( longitude->getDoubleValue()
cur_fdm_state->get_Lat_geocentric(), * SGD_DEGREES_TO_RADIANS,
cur_fdm_state->get_Altitude() * latitude->getDoubleValue()
SG_FEET_TO_METER ); * SGD_DEGREES_TO_RADIANS,
pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() * cur_fdm_state->get_Altitude()
SG_FEET_TO_METER ); * SG_FEET_TO_METER );
pilot_view->set_rph( cur_fdm_state->get_Phi(), pilot_view->set_rph( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(), cur_fdm_state->get_Theta(),
cur_fdm_state->get_Psi() ); cur_fdm_state->get_Psi() );
@ -884,8 +917,6 @@ void fgReInitSubsystems( void )
SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = " SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
<< globals->get_current_view()->get_abs_view_pos()); << globals->get_current_view()->get_abs_view_pos());
cur_fdm_state->init();
globals->get_controls()->reset_all(); globals->get_controls()->reset_all();
current_autopilot->reset(); current_autopilot->reset();

View file

@ -394,7 +394,7 @@ getHeadingMag ()
static double static double
getRPM () getRPM ()
{ {
if ( current_aircraft.fdm_state->get_engine(0) != NULL ) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_RPM(); return current_aircraft.fdm_state->get_engine(0)->get_RPM();
} else { } else {
return 0.0; return 0.0;
@ -408,7 +408,7 @@ getRPM ()
static double static double
getEGT () getEGT ()
{ {
if ( current_aircraft.fdm_state->get_engine(0) != NULL ) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_EGT(); return current_aircraft.fdm_state->get_engine(0)->get_EGT();
} else { } else {
return 0.0; return 0.0;
@ -421,7 +421,7 @@ getEGT ()
static double static double
getCHT () getCHT ()
{ {
if ( current_aircraft.fdm_state->get_engine(0) != NULL ) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_CHT(); return current_aircraft.fdm_state->get_engine(0)->get_CHT();
} else { } else {
return 0.0; return 0.0;
@ -434,7 +434,7 @@ getCHT ()
static double static double
getOilTemp () getOilTemp ()
{ {
if ( current_aircraft.fdm_state->get_engine(0) != NULL ) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Oil_Temp(); return current_aircraft.fdm_state->get_engine(0)->get_Oil_Temp();
} else { } else {
return 0.0; return 0.0;
@ -447,7 +447,7 @@ getOilTemp ()
static double static double
getMP () getMP ()
{ {
if ( current_aircraft.fdm_state->get_engine(0) != NULL ) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure(); return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
} else { } else {
return 0.0; return 0.0;
@ -461,7 +461,7 @@ getMP ()
static double static double
getFuelFlow () getFuelFlow ()
{ {
if ( current_aircraft.fdm_state->get_engine(0) != NULL ) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Fuel_Flow(); return current_aircraft.fdm_state->get_engine(0)->get_Fuel_Flow();
} else { } else {
return 0.0; return 0.0;
@ -474,7 +474,7 @@ getFuelFlow ()
static bool static bool
getRunningFlag () getRunningFlag ()
{ {
if ( current_aircraft.fdm_state->get_engine(0) != NULL ) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Running_Flag(); return current_aircraft.fdm_state->get_engine(0)->get_Running_Flag();
} else { } else {
return false; return false;
@ -487,7 +487,7 @@ getRunningFlag ()
static bool static bool
getCrankingFlag () getCrankingFlag ()
{ {
if ( current_aircraft.fdm_state->get_engine(0) != NULL ) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Cranking_Flag(); return current_aircraft.fdm_state->get_engine(0)->get_Cranking_Flag();
} else { } else {
return false; return false;
@ -924,7 +924,7 @@ setWindDown (double speed)
static void static void
setRunningFlag (bool flag) setRunningFlag (bool flag)
{ {
if(current_aircraft.fdm_state->get_engine(0) != NULL) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
current_aircraft.fdm_state->get_engine(0)->set_Running_Flag( flag ); current_aircraft.fdm_state->get_engine(0)->set_Running_Flag( flag );
} }
} }
@ -938,7 +938,7 @@ setRunningFlag (bool flag)
static void static void
setCrankingFlag (bool flag) setCrankingFlag (bool flag)
{ {
if(current_aircraft.fdm_state->get_engine(0) != NULL) { if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
current_aircraft.fdm_state->get_engine(0)->set_Cranking_Flag( flag ); current_aircraft.fdm_state->get_engine(0)->set_Cranking_Flag( flag );
} }
} }

View file

@ -56,10 +56,6 @@
# include <unistd.h> // for stat() # include <unistd.h> // for stat()
#endif #endif
// #ifdef HAVE_LIBX11
// # include <GL/glext.h>
// #endif
#include <plib/netChat.h> #include <plib/netChat.h>
#include <plib/pu.h> #include <plib/pu.h>
#include <plib/ssg.h> #include <plib/ssg.h>
@ -161,9 +157,6 @@ FGGeneral general;
static int idle_state = 0; static int idle_state = 0;
static long global_multi_loop; static long global_multi_loop;
// attempt to avoid a large bounce at startup
static bool initial_freeze = true;
// forward declaration // forward declaration
void fgReshape( int width, int height ); void fgReshape( int width, int height );
@ -404,6 +397,13 @@ void trRenderFrame( void ) {
// Update all Visuals (redraws anything graphics related) // Update all Visuals (redraws anything graphics related)
void fgRenderFrame( void ) { void fgRenderFrame( void ) {
static const SGPropertyNode *longitude
= fgGetNode("/position/longitude-deg");
static const SGPropertyNode *latitude
= fgGetNode("/position/latitude-deg");
static const SGPropertyNode *altitude
= fgGetNode("/position/altitude-ft");
// Update the default (kludged) properties. // Update the default (kludged) properties.
fgUpdateProps(); fgUpdateProps();
@ -431,7 +431,7 @@ void fgRenderFrame( void ) {
// initializations and are running the main loop, so this will // initializations and are running the main loop, so this will
// now work without seg faulting the system. // now work without seg faulting the system.
// printf("Ground = %.2f Altitude = %.2f\n", scenery.cur_elev, // printf("Ground = %.2f Altitude = %.2f\n", scenery.get_cur_elev(),
// FG_Altitude * SG_FEET_TO_METER); // FG_Altitude * SG_FEET_TO_METER);
// this is just a temporary hack, to make me understand Pui // this is just a temporary hack, to make me understand Pui
@ -439,20 +439,19 @@ void fgRenderFrame( void ) {
// end of hack // end of hack
// calculate our current position in cartesian space // calculate our current position in cartesian space
scenery.center = scenery.next_center; scenery.set_center( scenery.get_next_center() );
// printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x(), // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x(),
// scenery.center.y(), scenery.center.z()); // scenery.center.y(), scenery.center.z());
FGViewerRPH *pilot_view = FGViewerRPH *pilot_view =
(FGViewerRPH *)globals->get_viewmgr()->get_view( 0 ); (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), pilot_view->set_geod_view_pos( longitude->getDoubleValue()
cur_fdm_state->get_Lat_geocentric(), * SGD_DEGREES_TO_RADIANS,
cur_fdm_state->get_Altitude() * latitude->getDoubleValue()
SG_FEET_TO_METER ); * SGD_DEGREES_TO_RADIANS,
pilot_view->set_sea_level_radius( cur_fdm_state-> altitude->getDoubleValue()
get_Sea_level_radius() * * SG_FEET_TO_METER );
SG_FEET_TO_METER );
pilot_view->set_rph( cur_fdm_state->get_Phi(), pilot_view->set_rph( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(), cur_fdm_state->get_Theta(),
cur_fdm_state->get_Psi() ); cur_fdm_state->get_Psi() );
@ -479,13 +478,12 @@ void fgRenderFrame( void ) {
sgXformVec3( po, *pPO, pilot_view->get_UP() ); sgXformVec3( po, *pPO, pilot_view->get_UP() );
sgXformVec3( npo, po, CXFM ); sgXformVec3( npo, po, CXFM );
chase_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), chase_view->set_geod_view_pos( longitude->getDoubleValue()
cur_fdm_state->get_Lat_geocentric(), * SGD_DEGREES_TO_RADIANS,
cur_fdm_state->get_Altitude() * latitude->getDoubleValue()
SG_FEET_TO_METER ); * SGD_DEGREES_TO_RADIANS,
chase_view->set_sea_level_radius( cur_fdm_state-> altitude->getDoubleValue()
get_Sea_level_radius() * * SG_FEET_TO_METER );
SG_FEET_TO_METER );
chase_view->set_pilot_offset( npo[0], npo[1], npo[2] ); chase_view->set_pilot_offset( npo[0], npo[1], npo[2] );
chase_view->set_view_forward( pilot_view->get_view_pos() ); chase_view->set_view_forward( pilot_view->get_view_pos() );
chase_view->set_view_up( wup ); chase_view->set_view_up( wup );
@ -643,9 +641,11 @@ void fgRenderFrame( void ) {
thesky->reposition( globals->get_current_view()->get_view_pos(), thesky->reposition( globals->get_current_view()->get_view_pos(),
globals->get_current_view()->get_zero_elev(), globals->get_current_view()->get_zero_elev(),
globals->get_current_view()->get_world_up(), globals->get_current_view()->get_world_up(),
cur_fdm_state->get_Longitude(), longitude->getDoubleValue()
cur_fdm_state->get_Latitude(), * SGD_DEGREES_TO_RADIANS,
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, latitude->getDoubleValue()
* SGD_DEGREES_TO_RADIANS,
altitude->getDoubleValue() * SG_FEET_TO_METER,
cur_light_params.sun_rotation, cur_light_params.sun_rotation,
globals->get_time_params()->getGst(), globals->get_time_params()->getGst(),
globals->get_ephem()->getSunRightAscension(), globals->get_ephem()->getSunRightAscension(),
@ -689,7 +689,7 @@ void fgRenderFrame( void ) {
ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio()); ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio());
double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- scenery.cur_elev; - scenery.get_cur_elev();
// SG_LOG( SG_ALL, SG_INFO, "visibility is " // SG_LOG( SG_ALL, SG_INFO, "visibility is "
// << current_weather.get_visibility() ); // << current_weather.get_visibility() );
@ -874,8 +874,9 @@ void fgRenderFrame( void ) {
fgCockpitUpdate(); fgCockpitUpdate();
// update the panel subsystem // update the panel subsystem
if (current_panel != 0) if ( current_panel != NULL ) {
current_panel->update(); current_panel->update();
}
// We can do translucent menus, so why not. :-) // We can do translucent menus, so why not. :-)
menus->apply(); menus->apply();
@ -894,13 +895,40 @@ void fgRenderFrame( void ) {
void fgUpdateTimeDepCalcs() { void fgUpdateTimeDepCalcs() {
static bool inited = false; static bool inited = false;
// cout << "Updating time dep calcs()" << endl;
fgLIGHT *l = &cur_light_params; fgLIGHT *l = &cur_light_params;
int i; int i;
long multi_loop = 1; long multi_loop = 1;
if ( !globals->get_freeze() && !initial_freeze ) { // Initialize the FDM here if it hasn't been and if we have a
// conceptually, this could be done for each fdm instance ... // scenery elevation hit.
// cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
// << " cur_elev = " << scenery.get_cur_elev() << endl;
if ( !cur_fdm_state->get_inited() && scenery.get_cur_elev() > -9990 ) {
cout << "Finally initializing fdm" << endl;
cur_fdm_state->init();
if ( cur_fdm_state->get_bound() ) {
cur_fdm_state->unbind();
}
cur_fdm_state->bind();
}
// conceptually, the following block could be done for each fdm
// instance ...
if ( !cur_fdm_state->get_inited() ) {
// do nothing, fdm isn't inited yet
} else if ( globals->get_freeze() ) {
// we are frozen, run the fdm's with 0 time slices in case
// they want to do something with that.
cur_fdm_state->update( 0 );
FGSteam::update( 0 );
} else {
// we have been inited, and we are not frozen, we are good to go ...
if ( !inited ) { if ( !inited ) {
cur_fdm_state->stamp(); cur_fdm_state->stamp();
@ -938,13 +966,6 @@ void fgUpdateTimeDepCalcs() {
cur_fdm_state->update( 1 ); cur_fdm_state->update( 1 );
} }
FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") ); FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") );
} else {
cur_fdm_state->update( 0 );
FGSteam::update( 0 );
//if ( global_tile_mgr.queue_size() == 0 ) {
initial_freeze = false;
//}
} }
if ( fgGetString("/sim/view-mode") == "pilot" ) { if ( fgGetString("/sim/view-mode") == "pilot" ) {
@ -1024,6 +1045,13 @@ static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
// What should we do when we have nothing else to do? Let's get ready // What should we do when we have nothing else to do? Let's get ready
// for the next move and update the display? // for the next move and update the display?
static void fgMainLoop( void ) { static void fgMainLoop( void ) {
static const SGPropertyNode *longitude
= fgGetNode("/position/longitude-deg");
static const SGPropertyNode *latitude
= fgGetNode("/position/latitude-deg");
static const SGPropertyNode *altitude
= fgGetNode("/position/altitude-ft");
static long remainder = 0; static long remainder = 0;
long elapsed; long elapsed;
#ifdef FANCY_FRAME_COUNTER #ifdef FANCY_FRAME_COUNTER
@ -1069,20 +1097,20 @@ static void fgMainLoop( void ) {
// probably move eventually // probably move eventually
/* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n", /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
scenery.cur_elev, scenery.get_cur_elev(),
cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER, cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */ cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
if ( scenery.cur_elev > -9990 ) { if ( scenery.get_cur_elev() > -9990 ) {
if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER < if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
(scenery.cur_elev + alt_adjust_m - 3.0) ) { (scenery.get_cur_elev() + alt_adjust_m - 3.0) ) {
// now set aircraft altitude above ground // now set aircraft altitude above ground
printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n", printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n",
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
scenery.cur_elev + alt_adjust_m - 3.0, scenery.get_cur_elev() + alt_adjust_m - 3.0,
scenery.cur_elev + alt_adjust_m ); scenery.get_cur_elev() + alt_adjust_m );
fgFDMForceAltitude( fgGetString("/sim/flight-model"), fgFDMForceAltitude( fgGetString("/sim/flight-model"),
scenery.cur_elev + alt_adjust_m ); scenery.get_cur_elev() + alt_adjust_m );
SG_LOG( SG_ALL, SG_DEBUG, SG_LOG( SG_ALL, SG_DEBUG,
"<*> resetting altitude to " "<*> resetting altitude to "
@ -1092,7 +1120,7 @@ static void fgMainLoop( void ) {
} }
/* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n", /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
scenery.cur_elev, scenery.get_cur_elev(),
cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER, cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */ cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
@ -1103,8 +1131,8 @@ static void fgMainLoop( void ) {
globals->inc_warp( globals->get_warp_delta() ); globals->inc_warp( globals->get_warp_delta() );
} }
t->update( cur_fdm_state->get_Longitude(), t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
cur_fdm_state->get_Latitude(), latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
globals->get_warp() ); globals->get_warp() );
if ( globals->get_warp_delta() != 0 ) { if ( globals->get_warp_delta() != 0 ) {
@ -1112,9 +1140,11 @@ static void fgMainLoop( void ) {
} }
// update magvar model // update magvar model
globals->get_mag()->update( cur_fdm_state->get_Longitude(), globals->get_mag()->update( longitude->getDoubleValue()
cur_fdm_state->get_Latitude(), * SGD_DEGREES_TO_RADIANS,
cur_fdm_state->get_Altitude()* SG_FEET_TO_METER, latitude->getDoubleValue()
* SGD_DEGREES_TO_RADIANS,
altitude->getDoubleValue() * SG_FEET_TO_METER,
globals->get_time_params()->getJD() ); globals->get_time_params()->getJD() );
// Get elapsed time (in usec) for this past frame // Get elapsed time (in usec) for this past frame
@ -1177,7 +1207,7 @@ static void fgMainLoop( void ) {
if ( global_multi_loop > 0 ) { if ( global_multi_loop > 0 ) {
fgUpdateTimeDepCalcs(); fgUpdateTimeDepCalcs();
} else { } else {
SG_LOG( SG_ALL, SG_DEBUG, SG_LOG( SG_ALL, SG_INFO,
"Elapsed time is zero ... we're zinging" ); "Elapsed time is zero ... we're zinging" );
} }
@ -1187,10 +1217,8 @@ static void fgMainLoop( void ) {
#endif #endif
// see if we need to load any new scenery tiles // see if we need to load any new scenery tiles
global_tile_mgr.update( cur_fdm_state->get_Longitude() global_tile_mgr.update( longitude->getDoubleValue(),
* SGD_RADIANS_TO_DEGREES, latitude->getDoubleValue() );
cur_fdm_state->get_Latitude()
* SGD_RADIANS_TO_DEGREES );
// see if we need to load any deferred-load textures // see if we need to load any deferred-load textures
material_lib.load_next_deferred(); material_lib.load_next_deferred();
@ -1512,7 +1540,6 @@ int fgGlutInitEvents( void ) {
// Main loop // Main loop
int mainLoop( int argc, char **argv ) { int mainLoop( int argc, char **argv ) {
#if defined( macintosh ) #if defined( macintosh )
freopen ("stdout.txt", "w", stdout ); freopen ("stdout.txt", "w", stdout );
freopen ("stderr.txt", "w", stderr ); freopen ("stderr.txt", "w", stderr );
@ -1629,11 +1656,21 @@ int mainLoop( int argc, char **argv ) {
fgGetDouble("/orientation/heading-deg") ); fgGetDouble("/orientation/heading-deg") );
} }
// Any time after globals is created we are ready to use the
// property system
static const SGPropertyNode *longitude
= fgGetNode("/position/longitude-deg", true);
static const SGPropertyNode *latitude
= fgGetNode("/position/latitude-deg", true);
// Initialize time // Initialize time
SGPath zone( globals->get_fg_root() ); SGPath zone( globals->get_fg_root() );
zone.append( "Timezone" ); zone.append( "Timezone" );
SGTime *t = new SGTime( fgGetDouble("/position/longitude-deg") * SGD_DEGREES_TO_RADIANS, SGTime *t = new SGTime( longitude->getDoubleValue()
fgGetDouble("/position/latitude-deg") * SGD_DEGREES_TO_RADIANS, * SGD_DEGREES_TO_RADIANS,
latitude->getDoubleValue()
* SGD_DEGREES_TO_RADIANS,
zone.str() ); zone.str() );
// Handle potential user specified time offsets // Handle potential user specified time offsets
@ -2099,7 +2136,7 @@ void fgUpdateDCS (void) {
Point3D obj_pos = sgGeodToCart( obj_posn ); Point3D obj_pos = sgGeodToCart( obj_posn );
// Translate moving object w.r.t eye // Translate moving object w.r.t eye
Point3D Objtrans = obj_pos-scenery.center; Point3D Objtrans = obj_pos-scenery.get_center();
bz[0]=Objtrans.x(); bz[0]=Objtrans.x();
bz[1]=Objtrans.y(); bz[1]=Objtrans.y();
bz[2]=Objtrans.z(); bz[2]=Objtrans.z();

View file

@ -34,6 +34,7 @@
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx> #include <simgear/math/polar3d.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/vector.hxx> #include <simgear/math/vector.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
@ -107,21 +108,24 @@ void FGViewerLookAt::update() {
Point3D tmp; Point3D tmp;
sgVec3 minus_z; sgVec3 minus_z;
// calculate the cartesion coords of the current lat/lon/0 elev // convert to geocentric coordinates
Point3D p = Point3D( geod_view_pos[0], double geoc_lat;
geod_view_pos[1], sgGeodToGeoc( geod_view_pos[1], geod_view_pos[2],
sea_level_radius ); &sea_level_radius, &geoc_lat );
tmp = sgPolarToCart3d(p) - scenery.center; // calculate the cartesion coords of the current lat/lon/0 elev
Point3D p = Point3D( geod_view_pos[0], geoc_lat, sea_level_radius );
tmp = sgPolarToCart3d(p) - scenery.get_center();
sgSetVec3( zero_elev, tmp[0], tmp[1], tmp[2] ); sgSetVec3( zero_elev, tmp[0], tmp[1], tmp[2] );
// calculate view position in current FG view coordinate system // calculate view position in current FG view coordinate system
// p.lon & p.lat are already defined earlier, p.radius was set to // p.lon & p.lat are already defined earlier, p.radius was set to
// the sea level radius, so now we add in our altitude. // the sea level radius, so now we add in our altitude.
if ( geod_view_pos[2] > (scenery.cur_elev + 0.5 * SG_METER_TO_FEET) ) { if ( geod_view_pos[2] > (scenery.get_cur_elev() + 0.5 * SG_METER_TO_FEET) ) {
p.setz( p.radius() + geod_view_pos[2] ); p.setz( p.radius() + geod_view_pos[2] );
} else { } else {
p.setz( p.radius() + scenery.cur_elev + 0.5 * SG_METER_TO_FEET ); p.setz( p.radius() + scenery.get_cur_elev() + 0.5 * SG_METER_TO_FEET );
} }
tmp = sgPolarToCart3d(p); tmp = sgPolarToCart3d(p);
@ -129,7 +133,10 @@ void FGViewerLookAt::update() {
// view_pos = abs_view_pos - scenery.center; // view_pos = abs_view_pos - scenery.center;
sgdVec3 sc; sgdVec3 sc;
sgdSetVec3( sc, scenery.center.x(), scenery.center.y(), scenery.center.z()); sgdSetVec3( sc,
scenery.get_center().x(),
scenery.get_center().y(),
scenery.get_center().z() );
sgdVec3 vp; sgdVec3 vp;
sgdSubVec3( vp, abs_view_pos, sc ); sgdSubVec3( vp, abs_view_pos, sc );
sgSetVec3( view_pos, vp ); sgSetVec3( view_pos, vp );

View file

@ -35,6 +35,7 @@
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx> #include <simgear/math/polar3d.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/vector.hxx> #include <simgear/math/vector.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
@ -159,21 +160,24 @@ void FGViewerRPH::update() {
sgVec3 minus_z, forward; sgVec3 minus_z, forward;
sgMat4 VIEWo; sgMat4 VIEWo;
// calculate the cartesion coords of the current lat/lon/0 elev // convert to geocentric coordinates
Point3D p = Point3D( geod_view_pos[0], double geoc_lat;
geod_view_pos[1], sgGeodToGeoc( geod_view_pos[1], geod_view_pos[2],
sea_level_radius ); &sea_level_radius, &geoc_lat );
tmp = sgPolarToCart3d(p) - scenery.center; // calculate the cartesion coords of the current lat/lon/0 elev
Point3D p = Point3D( geod_view_pos[0], geoc_lat, sea_level_radius );
tmp = sgPolarToCart3d(p) - scenery.get_center();
sgSetVec3( zero_elev, tmp[0], tmp[1], tmp[2] ); sgSetVec3( zero_elev, tmp[0], tmp[1], tmp[2] );
// calculate view position in current FG view coordinate system // calculate view position in current FG view coordinate system
// p.lon & p.lat are already defined earlier, p.radius was set to // p.lon & p.lat are already defined earlier, p.radius was set to
// the sea level radius, so now we add in our altitude. // the sea level radius, so now we add in our altitude.
if ( geod_view_pos[2] > (scenery.cur_elev + 0.5 * SG_METER_TO_FEET) ) { if ( geod_view_pos[2] > (scenery.get_cur_elev() + 0.5 * SG_METER_TO_FEET) ) {
p.setz( p.radius() + geod_view_pos[2] ); p.setz( p.radius() + geod_view_pos[2] );
} else { } else {
p.setz( p.radius() + scenery.cur_elev + 0.5 * SG_METER_TO_FEET ); p.setz( p.radius() + scenery.get_cur_elev() + 0.5 * SG_METER_TO_FEET );
} }
tmp = sgPolarToCart3d(p); tmp = sgPolarToCart3d(p);
@ -181,7 +185,10 @@ void FGViewerRPH::update() {
// view_pos = abs_view_pos - scenery.center; // view_pos = abs_view_pos - scenery.center;
sgdVec3 sc; sgdVec3 sc;
sgdSetVec3( sc, scenery.center.x(), scenery.center.y(), scenery.center.z()); sgdSetVec3( sc,
scenery.get_center().x(),
scenery.get_center().y(),
scenery.get_center().z() );
sgdVec3 vp; sgdVec3 vp;
sgdSubVec3( vp, abs_view_pos, sc ); sgdSubVec3( vp, abs_view_pos, sc );
sgSetVec3( view_pos, vp ); sgSetVec3( view_pos, vp );

View file

@ -75,7 +75,7 @@ static void global2raw( const FGControls *global, FGRawCtrls *raw ) {
raw->brake[i] = globals->get_controls()->get_brake(i); raw->brake[i] = globals->get_controls()->get_brake(i);
} }
raw->hground = scenery.cur_elev; raw->hground = scenery.get_cur_elev();
} }
@ -96,7 +96,7 @@ static void raw2global( const FGRawCtrls *raw, FGControls *global ) {
for ( i = 0; i < FG_MAX_WHEELS; ++i ) { for ( i = 0; i < FG_MAX_WHEELS; ++i ) {
globals->get_controls()->set_brake( i, raw->brake[i] ); globals->get_controls()->set_brake( i, raw->brake[i] );
} }
scenery.cur_elev = raw->hground; scenery.set_cur_elev( raw->hground );
} else { } else {
SG_LOG( SG_IO, SG_ALERT, "Error: version mismatch in raw2global()" ); SG_LOG( SG_IO, SG_ALERT, "Error: version mismatch in raw2global()" );
SG_LOG( SG_IO, SG_ALERT, SG_LOG( SG_IO, SG_ALERT,

View file

@ -37,19 +37,38 @@
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <Main/fg_props.hxx>
#include "scenery.hxx" #include "scenery.hxx"
// Shared structure to hold current scenery parameters // Shared structure to hold current scenery parameters
struct fgSCENERY scenery; FGScenery scenery;
// Initialize the Scenery Management system // Scenery Management system
int fgSceneryInit( void ) { FGScenery::FGScenery() {
SG_LOG( SG_TERRAIN, SG_INFO, "Initializing scenery subsystem" ); SG_LOG( SG_TERRAIN, SG_INFO, "Initializing scenery subsystem" );
scenery.center = Point3D(0.0); center = Point3D(0.0);
scenery.cur_elev = -9999; cur_elev = -9999;
}
return 1;
// Initialize the Scenery Management system
FGScenery::~FGScenery() {
}
void FGScenery::init() {
}
void FGScenery::update() {
}
void FGScenery::bind() {
fgTie("/environment/ground-elevation-m", this,
&FGScenery::get_cur_elev, &FGScenery::set_cur_elev);
}
void FGScenery::unbind() {
fgUntie("/environment/ground-elevation-m");
} }

View file

@ -33,9 +33,11 @@
#include <plib/sg.h> #include <plib/sg.h>
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
#include <Main/fgfs.hxx>
// Define a structure containing global scenery parameters // Define a structure containing global scenery parameters
struct fgSCENERY { class FGScenery : public FGSubsystem {
// center of current scenery chunk // center of current scenery chunk
Point3D center; Point3D center;
@ -55,9 +57,33 @@ struct fgSCENERY {
// unit normal at point used to determine current elevation // unit normal at point used to determine current elevation
sgdVec3 cur_normal; sgdVec3 cur_normal;
public:
FGScenery();
~FGScenery();
// Implementation of FGSubsystem.
void init ();
void bind ();
void unbind ();
void update ();
inline double get_cur_elev() const { return cur_elev; }
inline void set_cur_elev( double e ) { cur_elev = e; }
inline Point3D get_center() const { return center; }
inline void set_center( Point3D p ) { center = p; }
inline Point3D get_next_center() const { return next_center; }
inline void set_next_center( Point3D p ) { next_center = p; }
inline void set_cur_radius( double r ) { cur_radius = r; }
inline void set_cur_normal( sgdVec3 n ) { sgdCopyVec3( cur_normal, n ); }
}; };
extern struct fgSCENERY scenery;
extern FGScenery scenery;
// Initialize the Scenery Management system // Initialize the Scenery Management system

View file

@ -778,7 +778,7 @@ void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) {
double agl; double agl;
if ( current_aircraft.fdm_state ) { if ( current_aircraft.fdm_state ) {
agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- scenery.cur_elev; - scenery.get_cur_elev();
} else { } else {
agl = 0.0; agl = 0.0;
} }
@ -829,7 +829,7 @@ void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) {
double agl1; double agl1;
if ( current_aircraft.fdm_state ) { if ( current_aircraft.fdm_state ) {
agl1 = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER agl1 = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- scenery.cur_elev; - scenery.get_cur_elev();
} else { } else {
agl1 = 0.0; agl1 = 0.0;
} }
@ -1261,7 +1261,7 @@ FGTileEntry::load( const SGPath& base, bool is_base )
terra_transform->addKid( terra_range ); terra_transform->addKid( terra_range );
// calculate initial tile offset // calculate initial tile offset
SetOffset( scenery.center ); SetOffset( scenery.get_center() );
sgCoord sgcoord; sgCoord sgcoord;
sgSetCoord( &sgcoord, sgSetCoord( &sgcoord,
offset.x(), offset.y(), offset.z(), offset.x(), offset.y(), offset.z(),

View file

@ -154,6 +154,7 @@ void FGTileMgr::sched_tile( const SGBucket& b ) {
// schedule a needed buckets for loading // schedule a needed buckets for loading
void FGTileMgr::schedule_needed() { void FGTileMgr::schedule_needed() {
cout << "scheduling needed tiles for " << longitude << " " << latitude << endl;
#ifndef FG_OLD_WEATHER #ifndef FG_OLD_WEATHER
if ( WeatherDatabase != NULL ) { if ( WeatherDatabase != NULL ) {
vis = WeatherDatabase->getWeatherVisibility(); vis = WeatherDatabase->getWeatherVisibility();
@ -250,13 +251,8 @@ void FGTileMgr::initialize_queue()
// chunks. If the chunk isn't already in the cache, then read it from // chunks. If the chunk isn't already in the cache, then read it from
// disk. // disk.
int FGTileMgr::update( double lon, double lat ) { int FGTileMgr::update( double lon, double lat ) {
SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update()" ); SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update() for" << lon << " " << lat );
// FGInterface *f = current_aircraft.fdm_state;
// lonlat for this update
// longitude = f->get_Longitude() * SGD_RADIANS_TO_DEGREES;
// latitude = f->get_Latitude() * SGD_RADIANS_TO_DEGREES;
longitude = lon; longitude = lon;
latitude = lat; latitude = lat;
// SG_LOG( SG_TERRAIN, SG_DEBUG, "lon "<< lonlat[LON] << // SG_LOG( SG_TERRAIN, SG_DEBUG, "lon "<< lonlat[LON] <<
@ -267,25 +263,27 @@ int FGTileMgr::update( double lon, double lat ) {
if ( tile_cache.exists( current_bucket ) ) { if ( tile_cache.exists( current_bucket ) ) {
current_tile = tile_cache.get_tile( current_bucket ); current_tile = tile_cache.get_tile( current_bucket );
scenery.next_center = current_tile->center; scenery.set_next_center( current_tile->center );
} else { } else {
SG_LOG( SG_TERRAIN, SG_WARN, "Tile not found (Ok if initializing)" ); SG_LOG( SG_TERRAIN, SG_WARN, "Tile not found (Ok if initializing)" );
} }
if ( state == Running ) { if ( state == Running ) {
SG_LOG( SG_TERRAIN, SG_DEBUG, "State == Running" );
if ( !(current_bucket == previous_bucket) ) { if ( !(current_bucket == previous_bucket) ) {
// We've moved to a new bucket, we need to schedule any // We've moved to a new bucket, we need to schedule any
// needed tiles for loading. // needed tiles for loading.
schedule_needed(); schedule_needed();
} }
} else if ( state == Start || state == Inited ) { } else if ( state == Start || state == Inited ) {
SG_LOG( SG_TERRAIN, SG_INFO, "State == Start || Inited" );
initialize_queue(); initialize_queue();
state = Running; state = Running;
}
// load the next tile in the load queue (or authorize the next // load the next tile in the load queue (or authorize the next
// load in the case of the threaded tile pager) // load in the case of the threaded tile pager)
loader.update(); loader.update();
}
// load the next model in the load queue. Currently this must // load the next model in the load queue. Currently this must
// happen in the render thread because model loading can trigger // happen in the render thread because model loading can trigger
@ -311,7 +309,7 @@ int FGTileMgr::update( double lon, double lat ) {
delete dm; delete dm;
} }
// cout << "current elevation (ssg) == " << scenery.cur_elev << endl; // cout << "current elevation (ssg) == " << scenery.get_cur_elev() << endl;
previous_bucket = current_bucket; previous_bucket = current_bucket;
last_longitude = longitude; last_longitude = longitude;
@ -320,23 +318,29 @@ int FGTileMgr::update( double lon, double lat ) {
// activate loader thread one out of every 5 frames // activate loader thread one out of every 5 frames
if ( counter_hack == 0 ) { if ( counter_hack == 0 ) {
// Notify the tile loader that it can load another tile // Notify the tile loader that it can load another tile
// loader.update(); loader.update();
if ( !attach_queue.empty() ) {
#ifdef ENABLE_THREADS
FGTileEntry* e = attach_queue.pop();
#else
FGTileEntry* e = attach_queue.front();
attach_queue.pop();
#endif
e->add_ssg_nodes( terrain, ground );
// cout << "Adding ssg nodes for "
}
} }
counter_hack = (counter_hack + 1) % 5; counter_hack = (counter_hack + 1) % 5;
sgdVec3 sc;
sgdSetVec3( sc, scenery.center[0], scenery.center[1], scenery.center[2] );
if ( !attach_queue.empty() ) {
#ifdef ENABLE_THREADS
FGTileEntry* e = attach_queue.pop();
#else
FGTileEntry* e = attach_queue.front();
attach_queue.pop();
#endif
e->add_ssg_nodes( terrain, ground );
// cout << "Adding ssg nodes for "
}
sgdVec3 sc;
sgdSetVec3( sc,
scenery.get_center()[0],
scenery.get_center()[1],
scenery.get_center()[2] );
#if 0
if ( scenery.center == Point3D(0.0) ) { if ( scenery.center == Point3D(0.0) ) {
// initializing // initializing
cout << "initializing scenery current elevation ... " << endl; cout << "initializing scenery current elevation ... " << endl;
@ -356,24 +360,31 @@ int FGTileMgr::update( double lon, double lat ) {
if ( fgCurrentElev(tmp_abs_view_pos, sc, &hit_list, if ( fgCurrentElev(tmp_abs_view_pos, sc, &hit_list,
&tmp_elev, &scenery.cur_radius, scenery.cur_normal) ) &tmp_elev, &scenery.cur_radius, scenery.cur_normal) )
{ {
scenery.cur_elev = tmp_elev; scenery.set_cur_elev( tmp_elev );
} else { } 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 { } else {
#endif
// cout << "abs view pos = " << current_view.abs_view_pos // cout << "abs view pos = " << current_view.abs_view_pos
// << " view pos = " << current_view.view_pos << endl; // << " view pos = " << current_view.view_pos << endl;
double tmp_elev; double tmp_elev;
double tmp_radius;
sgdVec3 tmp_normal;
if ( fgCurrentElev(globals->get_current_view()->get_abs_view_pos(), if ( fgCurrentElev(globals->get_current_view()->get_abs_view_pos(),
sc, &hit_list, sc, &hit_list,
&tmp_elev, &scenery.cur_radius, scenery.cur_normal) ) &tmp_elev, &tmp_radius, tmp_normal) )
{ {
scenery.cur_elev = tmp_elev; scenery.set_cur_elev( tmp_elev );
scenery.set_cur_radius( tmp_radius );
scenery.set_cur_normal( tmp_normal );
} else { } else {
scenery.cur_elev = 0.0; scenery.set_cur_elev( -9999.0 );
} }
#if 0
} }
#endif
return 1; return 1;
} }
@ -402,7 +413,7 @@ void FGTileMgr::prep_ssg_nodes() {
while ( ! tile_cache.at_end() ) { while ( ! tile_cache.at_end() ) {
// cout << "processing a tile" << endl; // cout << "processing a tile" << endl;
if ( (e = tile_cache.get_current()) ) { if ( (e = tile_cache.get_current()) ) {
e->prep_ssg_node( scenery.center, vis); e->prep_ssg_node( scenery.get_center(), vis);
} else { } else {
cout << "warning ... empty tile in cache" << endl; cout << "warning ... empty tile in cache" << endl;
} }

View file

@ -399,7 +399,7 @@ void fgUpdateMoonPos( void ) {
Point3D vp( v->get_view_pos()[0], Point3D vp( v->get_view_pos()[0],
v->get_view_pos()[1], v->get_view_pos()[1],
v->get_view_pos()[2] ); v->get_view_pos()[2] );
rel_moonpos = l->fg_moonpos - ( vp + scenery.center ); rel_moonpos = l->fg_moonpos - ( vp + scenery.get_center() );
sgSetVec3( to_moon, rel_moonpos.x(), rel_moonpos.y(), rel_moonpos.z() ); sgSetVec3( to_moon, rel_moonpos.x(), rel_moonpos.y(), rel_moonpos.z() );
// printf( "Vector to moon = %.2f %.2f %.2f\n", // printf( "Vector to moon = %.2f %.2f %.2f\n",
// to_moon[0], to_moon[1], to_moon[2]); // to_moon[0], to_moon[1], to_moon[2]);

View file

@ -306,7 +306,7 @@ void fgUpdateSunPos( void ) {
Point3D vp( v->get_view_pos()[0], Point3D vp( v->get_view_pos()[0],
v->get_view_pos()[1], v->get_view_pos()[1],
v->get_view_pos()[2] ); v->get_view_pos()[2] );
rel_sunpos = l->fg_sunpos - ( vp + scenery.center ); rel_sunpos = l->fg_sunpos - ( vp + scenery.get_center() );
sgSetVec3( to_sun, rel_sunpos.x(), rel_sunpos.y(), rel_sunpos.z() ); sgSetVec3( to_sun, rel_sunpos.x(), rel_sunpos.y(), rel_sunpos.z() );
// printf( "Vector to sun = %.2f %.2f %.2f\n", // printf( "Vector to sun = %.2f %.2f %.2f\n",
// v->to_sun[0], v->to_sun[1], v->to_sun[2]); // v->to_sun[0], v->to_sun[1], v->to_sun[2]);