]> git.mxchange.org Git - flightgear.git/commitdiff
Simplify code for taxiways.
authorStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Thu, 20 Sep 2012 20:53:31 +0000 (21:53 +0100)
committerStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Thu, 20 Sep 2012 20:53:31 +0000 (21:53 +0100)
src/Airports/simple.cxx
src/Airports/simple.hxx
src/Scripting/NasalPositioned.cxx

index adfc3cb9170c98beb7fa5dbbdba1134e8ddd3186..63e28c9e6d66f4500881e41ecebddd1b259b2abc 100644 (file)
@@ -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();
index dafe33496b5216fb4912b1d633d68e0189052cb3..3ee46ea7b45e6273646d173df9c634da7cb237c4 100644 (file)
@@ -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;
     
index e322ff20c4a4c66ee0bd54e481016769c95a37bc..3ec918cbdd92b9e9d3480c6766f4b3ab8e1fdae0 100644 (file)
@@ -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,45 +720,33 @@ 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;
-  
-  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());
-  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")) {
-    *out = ghostForNavaid(c, rwy->ILS());
+  FGRunwayBase* base = (FGRunwayBase*) g;
+  
+  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, "ils_frequency_mhz")) {
+      *out = rwy->ILS() ? naNum(rwy->ILS()->get_freq() / 100.0) : naNil();
+    } else if (!strcmp(fieldName, "ils")) {
+      *out = ghostForNavaid(c, rwy->ILS());
+    } else {
+      return 0;
+    }
   } else {
-    return 0;
+    return 0;    
   }
   
   return "";
 }
 
-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 "";
-}
-
 static const char* navaidGhostGetMember(naContext c, void* g, naRef field, naRef* out)
 {
   const char* fieldName = naStr_data(field);
@@ -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)