1
0
Fork 0

Small rewrite of waypoints parsing fix to move global list to the globals.hxx

file.
This commit is contained in:
curt 2004-04-18 18:01:10 +00:00
parent 4a41f96631
commit be7e5e4990
4 changed files with 64 additions and 89 deletions

View file

@ -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;
@ -1002,43 +1002,23 @@ static bool fgSetPosFromFix( const string& id ) {
}
static bool parseWaypoints()
{
string_list *waypoints = globals->get_initial_waypoints();
if (waypoints)
{
vector<string>::iterator i;
for (i = waypoints.begin();
i != waypoints.end();
for (i = waypoints->begin();
i != waypoints->end();
i++)
{
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;
}
// 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);
}
}

View file

@ -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;
}

View file

@ -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; }

View file

@ -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,6 +553,9 @@ parse_wp( const string& arg ) {
static bool
parse_flightplan(const string& arg)
{
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;
@ -599,10 +577,9 @@ parse_flightplan(const string& arg)
if ( in.eof() ) {
break;
}
//parse_wp(line);
waypoints.push_back(line);
waypoints->push_back(line);
}
globals->set_initial_waypoints(waypoints);
return true;
}