Small rewrite of waypoints parsing fix to move global list to the globals.hxx
file.
This commit is contained in:
parent
4a41f96631
commit
be7e5e4990
4 changed files with 64 additions and 89 deletions
|
@ -140,7 +140,7 @@ SG_USING_STD(string);
|
|||
class Sound;
|
||||
|
||||
extern const char *default_root;
|
||||
extern string_list waypoints;
|
||||
|
||||
|
||||
#ifdef FG_USE_CLOUDS_3D
|
||||
SkySceneLoader *sgCloud3d;
|
||||
|
@ -1003,42 +1003,22 @@ static bool fgSetPosFromFix( const string& id ) {
|
|||
|
||||
static bool parseWaypoints()
|
||||
{
|
||||
vector<string>::iterator i;
|
||||
for (i = waypoints.begin();
|
||||
i != waypoints.end();
|
||||
i++)
|
||||
string_list *waypoints = globals->get_initial_waypoints();
|
||||
if (waypoints)
|
||||
{
|
||||
NewWaypoint(*i);
|
||||
// string arg = *i;
|
||||
// string id, alt_str;
|
||||
// double alt = 0.0;
|
||||
|
||||
// string::size_type pos = arg.find( "@" );
|
||||
// if ( pos != string::npos ) {
|
||||
// id = arg.substr( 0, pos );
|
||||
// alt_str = arg.substr( pos + 1 );
|
||||
// cout << "id str = " << id << " alt str = " << alt_str << endl;
|
||||
// alt = atof( alt_str.c_str() );
|
||||
// if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
|
||||
// alt *= SG_FEET_TO_METER;
|
||||
// }
|
||||
// } else {
|
||||
// id = arg;
|
||||
// }
|
||||
|
||||
// FGAirport a;
|
||||
// if ( fgFindAirportID( id, &a ) ) {
|
||||
// FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
|
||||
// SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
|
||||
// rm->add_waypoint( wp );
|
||||
|
||||
// //return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// // waypoints.begin() = waypoints.erase(waypoints.begin());
|
||||
// return true;
|
||||
vector<string>::iterator i;
|
||||
for (i = waypoints->begin();
|
||||
i != waypoints->end();
|
||||
i++)
|
||||
{
|
||||
NewWaypoint(*i);
|
||||
}
|
||||
// Now were done using the way points we can deallocate the
|
||||
// memory they used
|
||||
while (waypoints->begin() != waypoints->end())
|
||||
waypoints->pop_back();
|
||||
delete waypoints;
|
||||
globals->set_initial_waypoints(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,8 @@ FGGlobals::FGGlobals() :
|
|||
channel_options_list( NULL ),
|
||||
scenery( NULL ),
|
||||
tile_mgr( NULL ),
|
||||
io( new FGIO )
|
||||
io( new FGIO ),
|
||||
initial_waypoints(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -87,6 +88,11 @@ FGGlobals::~FGGlobals()
|
|||
delete props;
|
||||
delete commands;
|
||||
delete io;
|
||||
|
||||
// make sure only to delete the initial waypoints list if it acually
|
||||
// still exists.
|
||||
if (initial_waypoints)
|
||||
delete initial_waypoints;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -178,6 +178,10 @@ private:
|
|||
// list of serial port-like configurations
|
||||
string_list *channel_options_list;
|
||||
|
||||
// A list of initial waypoints that are read from the command line
|
||||
// and or flight-plan file during initialization
|
||||
string_list *initial_waypoints;
|
||||
|
||||
// FlightGear scenery manager
|
||||
FGScenery *scenery;
|
||||
|
||||
|
@ -327,6 +331,14 @@ public:
|
|||
channel_options_list = l;
|
||||
}
|
||||
|
||||
inline string_list *get_initial_waypoints () {
|
||||
return initial_waypoints;
|
||||
}
|
||||
|
||||
inline void set_initial_waypoints (string_list *list) {
|
||||
initial_waypoints = list;
|
||||
}
|
||||
|
||||
inline FGScenery * get_scenery () const { return scenery; }
|
||||
inline void set_scenery ( FGScenery *s ) { scenery = s; }
|
||||
|
||||
|
|
|
@ -67,8 +67,6 @@ SG_USING_NAMESPACE(std);
|
|||
|
||||
#define NEW_DEFAULT_MODEL_HZ 120
|
||||
|
||||
string_list waypoints;
|
||||
|
||||
enum
|
||||
{
|
||||
FG_OPTIONS_OK = 0,
|
||||
|
@ -543,34 +541,11 @@ add_channel( const string& type, const string& channel_str ) {
|
|||
// Parse --wp=ID[@alt]
|
||||
static bool
|
||||
parse_wp( const string& arg ) {
|
||||
//string id, alt_str;
|
||||
//double alt = 0.0;
|
||||
//
|
||||
//string::size_type pos = arg.find( "@" );
|
||||
//if ( pos != string::npos ) {
|
||||
//id = arg.substr( 0, pos );
|
||||
//alt_str = arg.substr( pos + 1 );
|
||||
//// cout << "id str = " << id << " alt str = " << alt_str << endl;
|
||||
//alt = atof( alt_str.c_str() );
|
||||
//if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
|
||||
// alt *= SG_FEET_TO_METER;
|
||||
//}
|
||||
//} else {
|
||||
//id = arg;
|
||||
//}
|
||||
//
|
||||
//FGAirport a;
|
||||
//if ( fgFindAirportID( id, &a ) ) {
|
||||
// FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
|
||||
//SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
|
||||
//rm->add_waypoint( wp );
|
||||
//
|
||||
//return true;
|
||||
//} else {
|
||||
//return false;
|
||||
//}
|
||||
//}
|
||||
waypoints.push_back(arg);
|
||||
string_list *waypoints = globals->get_initial_waypoints();
|
||||
if (!waypoints)
|
||||
waypoints = new string_list;
|
||||
waypoints->push_back(arg);
|
||||
globals->set_initial_waypoints(waypoints);
|
||||
}
|
||||
|
||||
|
||||
|
@ -578,32 +553,34 @@ parse_wp( const string& arg ) {
|
|||
static bool
|
||||
parse_flightplan(const string& arg)
|
||||
{
|
||||
sg_gzifstream in(arg.c_str());
|
||||
if ( !in.is_open() ) {
|
||||
return false;
|
||||
}
|
||||
while ( true ) {
|
||||
string line;
|
||||
|
||||
string_list *waypoints = globals->get_initial_waypoints();
|
||||
if (!waypoints)
|
||||
waypoints = new string_list;
|
||||
sg_gzifstream in(arg.c_str());
|
||||
if ( !in.is_open() ) {
|
||||
return false;
|
||||
}
|
||||
while ( true ) {
|
||||
string line;
|
||||
|
||||
#if defined( macintosh )
|
||||
getline( in, line, '\r' );
|
||||
getline( in, line, '\r' );
|
||||
#else
|
||||
getline( in, line, '\n' );
|
||||
getline( in, line, '\n' );
|
||||
#endif
|
||||
|
||||
// catch extraneous (DOS) line ending character
|
||||
if ( line[line.length() - 1] < 32 ) {
|
||||
line = line.substr( 0, line.length()-1 );
|
||||
}
|
||||
|
||||
if ( in.eof() ) {
|
||||
break;
|
||||
}
|
||||
//parse_wp(line);
|
||||
waypoints.push_back(line);
|
||||
|
||||
// catch extraneous (DOS) line ending character
|
||||
if ( line[line.length() - 1] < 32 ) {
|
||||
line = line.substr( 0, line.length()-1 );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
if ( in.eof() ) {
|
||||
break;
|
||||
}
|
||||
waypoints->push_back(line);
|
||||
}
|
||||
globals->set_initial_waypoints(waypoints);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Reference in a new issue