1
0
Fork 0

Patch by Torsten Dryer: Remove the Ugly global dialog variable and remove rwy as a member variable from the AIFlightPlan class.

This commit is contained in:
Durk Talsma 2011-09-22 20:52:05 +02:00
parent e00157d4e8
commit 152fec1cb6
10 changed files with 36 additions and 27 deletions

View file

@ -71,7 +71,6 @@ bool FGAIWaypoint::contains(string target) {
FGAIFlightPlan::FGAIFlightPlan() FGAIFlightPlan::FGAIFlightPlan()
{ {
rwy = 0;
sid = 0; sid = 0;
repeat = false; repeat = false;
distance_to_go = 0; distance_to_go = 0;

View file

@ -166,7 +166,6 @@ public:
FGAIWaypoint *getLastWaypoint() { return waypoints.back(); }; FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
private: private:
FGRunway* rwy;
FGAIFlightPlan *sid; FGAIFlightPlan *sid;
typedef std::vector <FGAIWaypoint*> wpt_vector_type; typedef std::vector <FGAIWaypoint*> wpt_vector_type;
typedef wpt_vector_type::const_iterator wpt_vector_iterator; typedef wpt_vector_type::const_iterator wpt_vector_iterator;

View file

@ -226,7 +226,8 @@ bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight,
apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
depHeading); depHeading);
} }
rwy = apt->getRunwayByIdent(activeRunway); FGRunway * rwy = apt->getRunwayByIdent(activeRunway);
assert( rwy != NULL );
SGGeod runwayTakeoff = rwy->pointOnCenterline(5.0); SGGeod runwayTakeoff = rwy->pointOnCenterline(5.0);
FGGroundNetwork *gn = apt->getDynamics()->getGroundNetwork(); FGGroundNetwork *gn = apt->getDynamics()->getGroundNetwork();
@ -456,9 +457,8 @@ bool FGAIFlightPlan::createTakeOff(FGAIAircraft * ac, bool firstFlight,
apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading); heading);
} }
rwy = apt->getRunwayByIdent(activeRunway); FGRunway * rwy = apt->getRunwayByIdent(activeRunway);
assert( rwy != NULL );
double airportElev = apt->getElevation(); double airportElev = apt->getElevation();
@ -513,7 +513,6 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight,
double heading = ac->getTrafficRef()->getCourse(); double heading = ac->getTrafficRef()->getCourse();
apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading); heading);
rwy = apt->getRunwayByIdent(activeRunway);
} }
if (sid) { if (sid) {
for (wpt_vector_iterator i = sid->getFirstWayPoint(); for (wpt_vector_iterator i = sid->getFirstWayPoint();
@ -522,6 +521,9 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight,
//cerr << " Cloning waypoint " << endl; //cerr << " Cloning waypoint " << endl;
} }
} else { } else {
FGRunway * rwy = apt->getRunwayByIdent(activeRunway);
assert( rwy != NULL );
SGGeod climb1 = rwy->pointOnCenterline(10 * SG_NM_TO_METER); SGGeod climb1 = rwy->pointOnCenterline(10 * SG_NM_TO_METER);
wpt = createInAir(ac, "10000ft climb", climb1, vClimb, 10000); wpt = createInAir(ac, "10000ft climb", climb1, vClimb, 10000);
wpt->setGear_down(true); wpt->setGear_down(true);
@ -560,9 +562,8 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
double heading = ac->getTrafficRef()->getCourse(); double heading = ac->getTrafficRef()->getCourse();
apt->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway, apt->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway,
heading); heading);
rwy = apt->getRunwayByIdent(activeRunway); FGRunway * rwy = apt->getRunwayByIdent(activeRunway);
assert( rwy != NULL );
// Create a slow descent path that ends 250 lateral to the runway. // Create a slow descent path that ends 250 lateral to the runway.
double initialTurnRadius = getTurnRadius(vDescent, true); double initialTurnRadius = getTurnRadius(vDescent, true);
@ -859,6 +860,9 @@ bool FGAIFlightPlan::createLanding(FGAIAircraft * ac, FGAirport * apt,
char buffer[12]; char buffer[12];
for (int i = 1; i < 10; i++) { for (int i = 1; i < 10; i++) {
snprintf(buffer, 12, "wpt%d", i); snprintf(buffer, 12, "wpt%d", i);
FGRunway * rwy = apt->getRunwayByIdent(activeRunway);
assert( rwy != NULL );
coord = rwy->pointOnCenterline(rwy->lengthM() * (i / 10.0)); coord = rwy->pointOnCenterline(rwy->lengthM() * (i / 10.0));
wpt = createOnGround(ac, buffer, coord, aptElev, (vTouchdown / i)); wpt = createOnGround(ac, buffer, coord, aptElev, (vTouchdown / i));
wpt->setCrossat(apt->getElevation()); wpt->setCrossat(apt->getElevation());

View file

@ -299,7 +299,8 @@ bool FGAIFlightPlan::createCruise(FGAIAircraft *ac, bool firstFlight, FGAirport
string rwyClass = getRunwayClassFromTrafficType(fltType); string rwyClass = getRunwayClassFromTrafficType(fltType);
double heading = ac->getTrafficRef()->getCourse(); double heading = ac->getTrafficRef()->getCourse();
arr->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway, heading); arr->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway, heading);
rwy = arr->getRunwayByIdent(activeRunway); FGRunway* rwy = arr->getRunwayByIdent(activeRunway);
assert( rwy != NULL );
// begin descent 110km out // begin descent 110km out
SGGeod beginDescentPoint = rwy->pointOnCenterline(0); SGGeod beginDescentPoint = rwy->pointOnCenterline(0);
SGGeod secondaryDescentPoint = rwy->pointOnCenterline(-10000); SGGeod secondaryDescentPoint = rwy->pointOnCenterline(-10000);

View file

@ -46,8 +46,6 @@ FGATCManager::~FGATCManager() {
void FGATCManager::init() { void FGATCManager::init() {
SGSubsystem::init(); SGSubsystem::init();
currentATCDialog = new FGATCDialogNew;
currentATCDialog->init();
int leg = 0; int leg = 0;
@ -219,7 +217,7 @@ void FGATCManager::update ( double time ) {
ai_ac.setSpeed(speed); ai_ac.setSpeed(speed);
ai_ac.update(time); ai_ac.update(time);
controller = ai_ac.getATCController(); controller = ai_ac.getATCController();
currentATCDialog->update(time); FGATCDialogNew::instance()->update(time);
if (controller) { if (controller) {
//cerr << "name of previous waypoint : " << fp->getPreviousWaypoint()->getName() << endl; //cerr << "name of previous waypoint : " << fp->getPreviousWaypoint()->getName() << endl;

View file

@ -50,7 +50,6 @@ private:
AtcVec activeStations; AtcVec activeStations;
FGAIAircraft ai_ac; FGAIAircraft ai_ac;
FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft. FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft.
//FGATCDialogNew dialog; // note that this variable should really replace the ugly global "currentATCDialog();
bool networkVisible; bool networkVisible;
bool initSucceeded; bool initSucceeded;
@ -60,7 +59,6 @@ public:
void init(); void init();
void addController(FGATCController *controller); void addController(FGATCController *controller);
void update(double time); void update(double time);
FGATCDialogNew * getATCDialog() { return currentATCDialog; };
}; };
#endif // _ATC_MRG_HXX_ #endif // _ATC_MRG_HXX_

View file

@ -35,11 +35,12 @@
FGATCDialogNew *currentATCDialog; FGATCDialogNew *currentATCDialog;
static bool doATCDialog(const SGPropertyNode* arg) { /*static bool doATCDialog(const SGPropertyNode* arg) {
//cerr << "Running doATCDialog" << endl; //cerr << "Running doATCDialog" << endl;
currentATCDialog->PopupDialog(); currentATCDialog->PopupDialog();
return(true); return(true);
} }*/
FGATCDialogNew * FGATCDialogNew::_instance = NULL;
FGATCDialogNew::FGATCDialogNew() FGATCDialogNew::FGATCDialogNew()
{ {
@ -54,7 +55,7 @@ FGATCDialogNew::~FGATCDialogNew()
void FGATCDialogNew::init() { void FGATCDialogNew::init() {
// Add ATC-dialog to the command list // Add ATC-dialog to the command list
globals->get_commands()->addCommand("ATC-dialog", doATCDialog); globals->get_commands()->addCommand("ATC-dialog", FGATCDialogNew::popup );
// Add ATC-freq-search to the command list // Add ATC-freq-search to the command list
//globals->get_commands()->addCommand("ATC-freq-search", do_ATC_freq_search); //globals->get_commands()->addCommand("ATC-freq-search", do_ATC_freq_search);

View file

@ -43,13 +43,14 @@
typedef vector<string> StringVec; typedef vector<string> StringVec;
typedef vector<string>:: iterator StringVecIterator; typedef vector<string>:: iterator StringVecIterator;
static bool doATCDialog(const SGPropertyNode* arg);
class FGATCDialogNew { class FGATCDialogNew {
private: private:
NewGUI *_gui; NewGUI *_gui;
bool dialogVisible; bool dialogVisible;
StringVec commands; StringVec commands;
static FGATCDialogNew *_instance;
public: public:
FGATCDialogNew(); FGATCDialogNew();
@ -61,8 +62,19 @@ public:
void PopupDialog(); void PopupDialog();
void addEntry(int, string); void addEntry(int, string);
void removeEntry(int); void removeEntry(int);
static bool popup( const SGPropertyNode * ) {
instance()->PopupDialog();
return true;
}
inline static FGATCDialogNew * instance() {
if( _instance != NULL ) return _instance;
_instance = new FGATCDialogNew();
_instance->init();
return _instance;
}
}; };
extern FGATCDialogNew *currentATCDialog;
#endif // _ATC_DIALOG_HXX_ #endif // _ATC_DIALOG_HXX_

View file

@ -731,9 +731,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId,
} }
} }
} else { } else {
FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc"); FGATCDialogNew::instance()->addEntry(1, text);
atc->getATCDialog()->addEntry(1, text);
} }
} }
@ -1151,8 +1149,7 @@ bool FGStartupController::checkTransmissionState(int st, time_t now, time_t star
trans_num->setIntValue(-1); trans_num->setIntValue(-1);
// PopupCallback(n); // PopupCallback(n);
//cerr << "Selected transmission message " << n << endl; //cerr << "Selected transmission message " << n << endl;
FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc"); FGATCDialogNew::instance()->removeEntry(1);
atc->getATCDialog()->removeEntry(1);
} else { } else {
//cerr << "creading message for " << i->getAircraft()->getCallSign() << endl; //cerr << "creading message for " << i->getAircraft()->getCallSign() << endl;
transmit(&(*i), msgId, msgDir, false); transmit(&(*i), msgId, msgDir, false);

View file

@ -679,7 +679,7 @@ bool FGGroundNetwork::checkTransmissionState(int minState, int maxState, Traffic
// PopupCallback(n); // PopupCallback(n);
//cerr << "Selected transmission message " << n << endl; //cerr << "Selected transmission message " << n << endl;
FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc"); FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc");
atc->getATCDialog()->removeEntry(1); FGATCDialogNew::instance()->removeEntry(1);
} else { } else {
//cerr << "creating message for " << i->getAircraft()->getCallSign() << endl; //cerr << "creating message for " << i->getAircraft()->getCallSign() << endl;
transmit(&(*i), msgId, msgDir, false); transmit(&(*i), msgId, msgDir, false);