Optimize slot checking routines so unneeded code is not run, document function
This commit is contained in:
parent
97ca43a52a
commit
8268cdc5e0
6 changed files with 138 additions and 96 deletions
|
@ -125,6 +125,7 @@ void FGAIAircraft::readFromScenario(SGPropertyNode* scFileNode) {
|
|||
|
||||
FGAIBase::readFromScenario(scFileNode);
|
||||
|
||||
//acwakecategory = scFileNode->getStringValue("class", "jet_transport");
|
||||
setPerformance("", scFileNode->getStringValue("class", "jet_transport"));
|
||||
setFlightPlan(scFileNode->getStringValue("flightplan"),
|
||||
scFileNode->getBoolValue("repeat", false));
|
||||
|
|
|
@ -101,6 +101,7 @@ public:
|
|||
inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
|
||||
inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
|
||||
const std::string& atGate();
|
||||
std::string acwakecategory;
|
||||
|
||||
int getTakeOffStatus() { return takeOffStatus; };
|
||||
|
||||
|
|
|
@ -357,7 +357,7 @@ void FGATCManager::update ( double time ) {
|
|||
// render the path for the present controller if the ground network is set to visible
|
||||
controller->render(networkVisible);
|
||||
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Adding ground network to the scenegraph::update");
|
||||
SG_LOG(SG_ATC, SG_BULK, "Adding ground network to the scenegraph::update");
|
||||
|
||||
// reset previous controller for next update() iteration
|
||||
prevController = controller;
|
||||
|
|
|
@ -71,29 +71,54 @@ void clearTrafficControllers(TrafficVector& vec)
|
|||
/***************************************************************************
|
||||
* ActiveRunway
|
||||
**************************************************************************/
|
||||
/*
|
||||
* Fetch next slot for the active runway
|
||||
* @param eta time of slot requested
|
||||
* @return newEta: next slot available; starts at eta paramater
|
||||
* and adds separation as needed
|
||||
*/
|
||||
time_t ActiveRunway::requestTimeSlot(time_t eta)
|
||||
{
|
||||
time_t newEta;
|
||||
time_t separation = 90;
|
||||
// default separation - 60 seconds
|
||||
time_t separation = 60;
|
||||
//if (wakeCategory == "heavy_jet") {
|
||||
// SG_LOG(SG_ATC, SG_DEBUG, "Heavy jet, using extra separation");
|
||||
// time_t separation = 120;
|
||||
//}
|
||||
bool found = false;
|
||||
|
||||
// if the aircraft is the first arrival, add to the vector and return eta directly
|
||||
if (estimatedArrivalTimes.empty()) {
|
||||
estimatedArrivalTimes.push_back(eta);
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Checked eta slots, using" << eta);
|
||||
return eta;
|
||||
} else {
|
||||
// First check the already assigned slots to see where we need to fit the flight in
|
||||
TimeVectorIterator i = estimatedArrivalTimes.begin();
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Checking eta slots " << eta << ": ");
|
||||
|
||||
// is this needed - just a debug output?
|
||||
for (i = estimatedArrivalTimes.begin();
|
||||
i != estimatedArrivalTimes.end(); i++) {
|
||||
SG_LOG(SG_ATC, SG_BULK, "Stored time : " << (*i));
|
||||
}
|
||||
|
||||
// if the flight is before the first scheduled slot + separation
|
||||
i = estimatedArrivalTimes.begin();
|
||||
if ((eta + separation) < (*i)) {
|
||||
newEta = eta;
|
||||
found = true;
|
||||
SG_LOG(SG_ATC, SG_BULK, "Storing at beginning");
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Done. New ETA : " << newEta);
|
||||
slotHousekeeping(newEta);
|
||||
return newEta;
|
||||
}
|
||||
|
||||
// else, look through the rest of the slots
|
||||
while ((i != estimatedArrivalTimes.end()) && (!found)) {
|
||||
TimeVectorIterator j = i + 1;
|
||||
|
||||
// if the flight is after the last scheduled slot check if separation is needed
|
||||
if (j == estimatedArrivalTimes.end()) {
|
||||
if (((*i) + separation) < eta) {
|
||||
SG_LOG(SG_ATC, SG_BULK, "Storing at end");
|
||||
|
@ -102,12 +127,17 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
|
|||
newEta = (*i) + separation;
|
||||
SG_LOG(SG_ATC, SG_BULK, "Storing at end + separation");
|
||||
}
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Done. New ETA : " << newEta);
|
||||
slotHousekeeping(newEta);
|
||||
return newEta;
|
||||
} else {
|
||||
if ((((*j) - (*i)) > (separation * 2))) { // found a potential slot
|
||||
// potential slot found
|
||||
// check the distance between the previous and next slots
|
||||
// distance msut be greater than 2* separation
|
||||
if ((((*j) - (*i)) > (separation * 2))) {
|
||||
// now check whether this slot is usable:
|
||||
// 1) eta should fall between the two points
|
||||
// eta should fall between the two points
|
||||
// i.e. eta > i AND eta < j
|
||||
//
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Found potential slot after " << (*i));
|
||||
if (eta > (*i) && (eta < (*j))) {
|
||||
found = true;
|
||||
|
@ -139,12 +169,19 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
|
|||
i++;
|
||||
}
|
||||
}
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Done. New ETA : " << newEta);
|
||||
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Done. New ETA : " << newEta);
|
||||
slotHousekeeping(newEta);
|
||||
return newEta;
|
||||
}
|
||||
|
||||
void ActiveRunway::slotHousekeeping(time_t newEta)
|
||||
{
|
||||
// add the slot to the vector and resort the vector
|
||||
estimatedArrivalTimes.push_back(newEta);
|
||||
sort(estimatedArrivalTimes.begin(), estimatedArrivalTimes.end());
|
||||
// do some housekeeping : remove any timestamps that are past
|
||||
|
||||
// do some housekeeping : remove any slots that are past
|
||||
time_t now = globals->get_time_params()->get_cur_time();
|
||||
|
||||
TimeVectorIterator i = estimatedArrivalTimes.begin();
|
||||
|
@ -157,7 +194,6 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
|
|||
i++;
|
||||
}
|
||||
}
|
||||
return newEta;
|
||||
}
|
||||
|
||||
void ActiveRunway::printDepartureCue()
|
||||
|
@ -206,10 +242,11 @@ void FGTrafficRecord::setPositionAndIntentions(int pos,
|
|||
FGAIFlightPlan * route)
|
||||
{
|
||||
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Position: " << pos);
|
||||
currentPos = pos;
|
||||
if (! intentions.empty()) {
|
||||
intVecIterator i = intentions.begin();
|
||||
if ((*i) != pos) {
|
||||
if ((*i) != currentPos) {
|
||||
SG_LOG(SG_ATC, SG_ALERT,
|
||||
"Error in FGTrafficRecord::setPositionAndIntentions at " << SG_ORIGIN);
|
||||
}
|
||||
|
@ -217,7 +254,7 @@ void FGTrafficRecord::setPositionAndIntentions(int pos,
|
|||
} else {
|
||||
//FGAIFlightPlan::waypoint* const wpt= route->getCurrentWaypoint();
|
||||
int size = route->getNrOfWayPoints();
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Setting pos" << pos);
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Setting pos" << currentPos);
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Setting intentions");
|
||||
for (int i = 2; i < size; i++) {
|
||||
int val = route->getRouteIndex(i);
|
||||
|
@ -247,7 +284,7 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other)
|
|||
bool result = false;
|
||||
SG_LOG(SG_ATC, SG_BULK, "Start check 1");
|
||||
if (currentPos == other.currentPos) {
|
||||
SG_LOG(SG_ATC, SG_DEBUG, ": Check Position and intentions: we are on the same taxiway; Index = " << currentPos);
|
||||
SG_LOG(SG_ATC, SG_BULK, ": Check Position and intentions: we are on the same taxiway; Index = " << currentPos);
|
||||
result = true;
|
||||
}
|
||||
// else if (! other.intentions.empty())
|
||||
|
@ -271,7 +308,7 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other)
|
|||
i++;
|
||||
}
|
||||
if (i != intentions.end()) {
|
||||
SG_LOG(SG_ATC, SG_DEBUG, ": Check Position and intentions: .other.current matches Index = " << (*i));
|
||||
SG_LOG(SG_ATC, SG_BULK, ": Check Position and intentions: .other.current matches Index = " << (*i));
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
@ -988,6 +1025,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
|
|||
// only bother with aircraft that have a takeoff status of 2, since those are essentially under tower control
|
||||
FGAIAircraft* ac= rwy->getFirstAircraftInDepartureCue();
|
||||
if (ac->getTakeOffStatus() == 1) {
|
||||
// transmit takeoff clearance
|
||||
ac->setTakeOffStatus(2);
|
||||
}
|
||||
if (current.getAircraft()->getTakeOffStatus() == 2) {
|
||||
|
@ -1006,6 +1044,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
|
|||
FGAIAircraft *ac = rwy->getFirstOfStatus(1);
|
||||
if (ac)
|
||||
ac->setTakeOffStatus(2);
|
||||
// transmit takeoff clearacne? But why twice?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -352,7 +352,8 @@ public:
|
|||
currentlyCleared = number;
|
||||
};
|
||||
time_t requestTimeSlot(time_t eta);
|
||||
|
||||
//time_t requestTimeSlot(time_t eta, std::string wakeCategory);
|
||||
void slotHousekeeping(time_t newEta);
|
||||
int getDepartureCueSize() {
|
||||
return departureCue.size();
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue