From 8e2d0d2a762f74ce258e1ac8635aca9949739d6d Mon Sep 17 00:00:00 2001 From: Durk Talsma Date: Fri, 15 May 2015 13:30:16 +0200 Subject: [PATCH] Reinstate the backbone of the "I" part of the Interactive traffic system. --- src/AIModel/AIFlightPlanCreate.cxx | 20 ++++++++--------- src/AIModel/AIFlightPlanCreatePushBack.cxx | 16 ++++++++----- src/Airports/groundnetwork.cxx | 26 +++++++++++++++++----- src/Airports/groundnetwork.hxx | 16 ++++++++++--- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/AIModel/AIFlightPlanCreate.cxx b/src/AIModel/AIFlightPlanCreate.cxx index 308f87d00..e39fb57ca 100644 --- a/src/AIModel/AIFlightPlanCreate.cxx +++ b/src/AIModel/AIFlightPlanCreate.cxx @@ -211,7 +211,7 @@ bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight, const string & acType, const string & airline) { - + int route; // If this function is called during initialization, // make sure we obtain a valid gate ID first // and place the model at the location of the gate. @@ -298,24 +298,24 @@ bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight, // but make sure we always keep two active waypoints // to prevent a segmentation fault for (int i = 0; i < nrWaypointsToSkip - 3; i++) { - taxiRoute.next(&node); + taxiRoute.next(&node, &route); } gate.release(); // free up our gate as required } else { if (taxiRoute.size() > 1) { - taxiRoute.next(&node); // chop off the first waypoint, because that is already the last of the pushback route + taxiRoute.next(&node, &route); // chop off the first waypoint, because that is already the last of the pushback route } } // push each node on the taxi route as a waypoint - // int route; + //cerr << "Building taxi route" << endl; // Note that the line wpt->setRouteIndex was commented out by revision [afcdbd] 2012-01-01, // which breaks the rendering functions. // These can probably be generated on the fly however. - while (taxiRoute.next(&node)) { + while (taxiRoute.next(&node, &route)) { char buffer[10]; snprintf(buffer, 10, "%lld", (long long int) node); FGTaxiNode *tn = @@ -323,8 +323,7 @@ bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight, FGAIWaypoint *wpt = createOnGround(ac, buffer, tn->geod(), apt->getElevation(), ac->getPerformance()->vTaxi()); - // TODO: find an alternative way to pass route information to the waypoint. - //wpt->setRouteIndex(route); + wpt->setRouteIndex(route); //cerr << "Nodes left " << taxiRoute->nodesLeft() << " "; if (taxiRoute.nodesLeft() == 1) { // Note that we actually have hold points in the ground network, but this is just an initial test. @@ -376,6 +375,7 @@ bool FGAIFlightPlan::createLandingTaxi(FGAIAircraft * ac, FGAirport * apt, const string & acType, const string & airline) { + int route; gate = apt->getDynamics()->getAvailableParking(radius, fltType, acType, airline); @@ -414,15 +414,15 @@ bool FGAIFlightPlan::createLandingTaxi(FGAIAircraft * ac, FGAirport * apt, // those are created by createParking() // int route; for (int i = 0; i < size - 2; i++) { - taxiRoute.next(&node); + taxiRoute.next(&node, &route); char buffer[10]; snprintf(buffer, 10, "%lld", (long long int) node); FGTaxiNode *tn = gn->findNode(node); FGAIWaypoint *wpt = createOnGround(ac, buffer, tn->geod(), apt->getElevation(), ac->getPerformance()->vTaxi()); - //TODO: find an alternative way to pass route information to the waypoint. - //wpt->setRouteIndex(route); + + wpt->setRouteIndex(route); pushBackWaypoint(wpt); } return true; diff --git a/src/AIModel/AIFlightPlanCreatePushBack.cxx b/src/AIModel/AIFlightPlanCreatePushBack.cxx index 0e7efc80c..d19f61e55 100644 --- a/src/AIModel/AIFlightPlanCreatePushBack.cxx +++ b/src/AIModel/AIFlightPlanCreatePushBack.cxx @@ -51,6 +51,7 @@ bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac, double vTaxi = ac->getPerformance()->vTaxi(); double vTaxiBackward = vTaxi * (-2.0/3.0); double vTaxiReduced = vTaxi * (2.0/3.0); + // Active runway can be conditionally set by ATC, so at the start of a new flight, this // must be reset. activeRunway.clear(); @@ -95,15 +96,17 @@ bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac, } route.first(); - PositionedID node, previous= 0; + PositionedID node; + int rte; - while (route.next(&node)) + while (route.next(&node, &rte)) { char buffer[10]; snprintf (buffer, 10, "%lld", (long long int) node); FGTaxiNode *tn = groundNet->findNode(node); FGAIWaypoint *wpt = createOnGround(ac, string(buffer), tn->geod(), dep->getElevation(), vTaxiBackward); - + + /* if (previous) { FGTaxiSegment* segment = groundNet->findSegment(previous, node); wpt->setRouteIndex(segment->getIndex()); @@ -111,10 +114,11 @@ bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac, // not on the route yet, make up a unique segment ID int x = (int) tn->guid(); wpt->setRouteIndex(x); - } - + }*/ + + wpt->setRouteIndex(rte); pushBackWaypoint(wpt); - previous = node; + //previous = node; } // some special considerations for the last point: waypoints.back()->setName(string("PushBackPoint")); diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index bb66cfbb1..9edfef37f 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -145,13 +145,22 @@ void FGTaxiSegment::unblock(time_t now) /*************************************************************************** * FGTaxiRoute **************************************************************************/ -bool FGTaxiRoute::next(PositionedID *nde) +bool FGTaxiRoute::next(PositionedID *nde, int *rte) { + if (nodes.size() != (routes.size()) + 1) { + SG_LOG(SG_GENERAL, SG_ALERT, "ALERT: Misconfigured TaxiRoute : " << nodes.size() << " " << routes.size()); + throw sg_range_exception("Misconfigured taxi route"); + } if (currNode == nodes.end()) return false; - *nde = *(currNode); - + if (currNode != nodes.begin()) { + *rte = *(currRoute); + currRoute++; + } else { + // Handle special case for the first node. + *rte = -1 * *(currRoute); + } currNode++; return true; }; @@ -255,7 +264,7 @@ void FGGroundNetwork::init(FGAirport* pr) segment->setIndex(index++); if (segment->oppositeDirection) { - continue; // already establish + continue; // already established } FGTaxiSegment* opp = findSegment(segment->endNode, segment->startNode); @@ -469,14 +478,21 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(PositionedID start, PositionedID // assemble route from backtrace information PositionedIDVec nodes; + intVec routes; FGTaxiNode *bt = lastNode; + while (searchData[bt].previousNode != 0) { nodes.push_back(bt->guid()); + FGTaxiSegment *segment = findSegment(searchData[bt].previousNode->guid(), bt->guid()); + int idx = segment->getIndex(); + routes.push_back(idx); bt = searchData[bt].previousNode; + } nodes.push_back(start); reverse(nodes.begin(), nodes.end()); - return FGTaxiRoute(nodes, searchData[lastNode].score, 0); + reverse(routes.begin(), routes.end()); + return FGTaxiRoute(nodes, routes, searchData[lastNode].score, 0); } /* ATC Related Functions */ diff --git a/src/Airports/groundnetwork.hxx b/src/Airports/groundnetwork.hxx index 76eaa899e..80b7e0256 100644 --- a/src/Airports/groundnetwork.hxx +++ b/src/Airports/groundnetwork.hxx @@ -108,32 +108,41 @@ class FGTaxiRoute { private: PositionedIDVec nodes; + intVec routes; double distance; PositionedIDVec::iterator currNode; + intVec::iterator currRoute; public: FGTaxiRoute() { distance = 0; currNode = nodes.begin(); + currRoute = routes.begin(); }; - FGTaxiRoute(const PositionedIDVec& nds, double dist, int dpth) { + FGTaxiRoute(const PositionedIDVec& nds, intVec rts, double dist, int dpth) { nodes = nds; + routes = rts; distance = dist; currNode = nodes.begin(); + currRoute = routes.begin(); }; FGTaxiRoute& operator= (const FGTaxiRoute &other) { nodes = other.nodes; + routes = other.routes; distance = other.distance; currNode = nodes.begin(); + currRoute = routes.begin(); return *this; }; FGTaxiRoute(const FGTaxiRoute& copy) : nodes(copy.nodes), + routes(copy.routes), distance(copy.distance), - currNode(nodes.begin()) + currNode(nodes.begin()), + currRoute(routes.begin()) {}; bool operator< (const FGTaxiRoute &other) const { @@ -142,10 +151,11 @@ public: bool empty () { return nodes.empty(); }; - bool next(PositionedID *nde); + bool next(PositionedID *nde, int *rte); void first() { currNode = nodes.begin(); + currRoute = routes.begin(); }; int size() { return nodes.size(); -- 2.39.5