Simplify code for taxiways.
This commit is contained in:
parent
ac1fc699b7
commit
a3a40af860
3 changed files with 26 additions and 59 deletions
|
@ -239,22 +239,6 @@ FGTaxiway* FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
|
|||
return (FGTaxiway*) flightgear::NavDataCache::instance()->loadById(mTaxiways[aIndex]);
|
||||
}
|
||||
|
||||
bool FGAirport::hasTaxiwayWithIdent(const string& aIdent) const
|
||||
{
|
||||
return flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent) != 0;
|
||||
}
|
||||
|
||||
FGTaxiway* FGAirport::getTaxiwayByIdent(const string& aIdent) const
|
||||
{
|
||||
PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent);
|
||||
if (id == 0) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
|
||||
throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getTaxiwayByIdent");
|
||||
}
|
||||
|
||||
return (FGTaxiway*) flightgear::NavDataCache::instance()->loadById(id);
|
||||
}
|
||||
|
||||
unsigned int FGAirport::numPavements() const
|
||||
{
|
||||
loadTaxiways();
|
||||
|
|
|
@ -123,9 +123,6 @@ public:
|
|||
unsigned int numTaxiways() const;
|
||||
FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
|
||||
|
||||
bool hasTaxiwayWithIdent(const std::string& aIdent) const;
|
||||
FGTaxiway* getTaxiwayByIdent(const std::string& aIdent) const;
|
||||
|
||||
unsigned int numPavements() const;
|
||||
FGPavement* getPavementByIndex(unsigned int aIndex) const;
|
||||
|
||||
|
|
|
@ -71,9 +71,7 @@ naGhostType NavaidGhostType = { positionedGhostDestroy, "navaid", navaidGhostGet
|
|||
|
||||
static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out);
|
||||
naGhostType RunwayGhostType = { positionedGhostDestroy, "runway", runwayGhostGetMember, 0 };
|
||||
|
||||
static const char* taxiwayGhostGetMember(naContext c, void* g, naRef field, naRef* out);
|
||||
naGhostType TaxiwayGhostType = { positionedGhostDestroy, "taxiway", taxiwayGhostGetMember, 0 };
|
||||
naGhostType TaxiwayGhostType = { positionedGhostDestroy, "taxiway", runwayGhostGetMember, 0 };
|
||||
|
||||
static const char* fixGhostGetMember(naContext c, void* g, naRef field, naRef* out);
|
||||
naGhostType FixGhostType = { positionedGhostDestroy, "fix", fixGhostGetMember, 0 };
|
||||
|
@ -722,17 +720,19 @@ static const char* procedureGhostGetMember(naContext c, void* g, naRef field, na
|
|||
static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out)
|
||||
{
|
||||
const char* fieldName = naStr_data(field);
|
||||
FGRunway* rwy = (FGRunway*) g;
|
||||
FGRunwayBase* base = (FGRunwayBase*) g;
|
||||
|
||||
if (!strcmp(fieldName, "id")) *out = stringToNasal(c, rwy->ident());
|
||||
else if (!strcmp(fieldName, "lat")) *out = naNum(rwy->latitude());
|
||||
else if (!strcmp(fieldName, "lon")) *out = naNum(rwy->longitude());
|
||||
else if (!strcmp(fieldName, "heading")) *out = naNum(rwy->headingDeg());
|
||||
else if (!strcmp(fieldName, "length")) *out = naNum(rwy->lengthM());
|
||||
else if (!strcmp(fieldName, "width")) *out = naNum(rwy->widthM());
|
||||
else if (!strcmp(fieldName, "threshold")) *out = naNum(rwy->displacedThresholdM());
|
||||
if (!strcmp(fieldName, "id")) *out = stringToNasal(c, base->ident());
|
||||
else if (!strcmp(fieldName, "lat")) *out = naNum(base->latitude());
|
||||
else if (!strcmp(fieldName, "lon")) *out = naNum(base->longitude());
|
||||
else if (!strcmp(fieldName, "heading")) *out = naNum(base->headingDeg());
|
||||
else if (!strcmp(fieldName, "length")) *out = naNum(base->lengthM());
|
||||
else if (!strcmp(fieldName, "width")) *out = naNum(base->widthM());
|
||||
else if (!strcmp(fieldName, "surface")) *out = naNum(base->surface());
|
||||
else if (base->type() == FGRunwayBase::RUNWAY) {
|
||||
FGRunway* rwy = (FGRunway*) g;
|
||||
if (!strcmp(fieldName, "threshold")) *out = naNum(rwy->displacedThresholdM());
|
||||
else if (!strcmp(fieldName, "stopway")) *out = naNum(rwy->stopwayM());
|
||||
else if (!strcmp(fieldName, "surface")) *out = naNum(rwy->surface());
|
||||
else if (!strcmp(fieldName, "ils_frequency_mhz")) {
|
||||
*out = rwy->ILS() ? naNum(rwy->ILS()->get_freq() / 100.0) : naNil();
|
||||
} else if (!strcmp(fieldName, "ils")) {
|
||||
|
@ -740,24 +740,10 @@ static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef
|
|||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return "";
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char* taxiwayGhostGetMember(naContext c, void* g, naRef field, naRef* out)
|
||||
{
|
||||
const char* fieldName = naStr_data(field);
|
||||
FGTaxiway* taxi = (FGTaxiway*) g;
|
||||
|
||||
if (!strcmp(fieldName, "id")) *out = stringToNasal(c, taxi->ident());
|
||||
else if (!strcmp(fieldName, "lat")) *out = naNum(taxi->latitude());
|
||||
else if (!strcmp(fieldName, "lon")) *out = naNum(taxi->longitude());
|
||||
else if (!strcmp(fieldName, "heading")) *out = naNum(taxi->headingDeg());
|
||||
else if (!strcmp(fieldName, "length")) *out = naNum(taxi->lengthM());
|
||||
else if (!strcmp(fieldName, "width")) *out = naNum(taxi->widthM());
|
||||
else if (!strcmp(fieldName, "surface")) *out = naNum(taxi->surface());
|
||||
else return 0;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -1197,13 +1183,13 @@ static naRef f_airport_taxiway(naContext c, naRef me, int argc, naRef* args)
|
|||
naRuntimeError(c, "airport.taxiway expects a taxiway ident argument");
|
||||
}
|
||||
|
||||
std::string ident(naStr_data(args[0]));
|
||||
boost::to_upper(ident);
|
||||
if (!apt->hasTaxiwayWithIdent(ident)) {
|
||||
return naNil();
|
||||
naRef taxiways = naNewVector(c);
|
||||
|
||||
for (unsigned int i = 0; i < apt->numTaxiways(); i++) {
|
||||
naVec_append(taxiways, ghostForTaxiway(c, apt->getTaxiwayByIndex(i)));
|
||||
}
|
||||
|
||||
return ghostForTaxiway(c, apt->getTaxiwayByIdent(ident));
|
||||
return taxiways;
|
||||
}
|
||||
|
||||
static naRef f_airport_sids(naContext c, naRef me, int argc, naRef* args)
|
||||
|
|
Loading…
Reference in a new issue