1
0
Fork 0

TrafficManager - check model paths when loading schedules, and ignore schedules with a missing mode completely.

This commit is contained in:
James Turner 2012-05-03 11:05:37 +01:00
parent 645b0ae588
commit 84beec9325
4 changed files with 91 additions and 69 deletions

View file

@ -314,6 +314,18 @@ bool FGAISchedule::update(time_t now, const SGVec3d& userCart)
return createAIAircraft(flight, speed, deptime); return createAIAircraft(flight, speed, deptime);
} }
bool FGAISchedule::validModelPath(const std::string& modelPath)
{
SGPath mp(globals->get_fg_root());
SGPath mp_ai = mp;
mp.append(modelPath);
mp_ai.append("AI");
mp_ai.append(modelPath);
return mp.exists() || mp_ai.exists();
}
bool FGAISchedule::createAIAircraft(FGScheduledFlight* flight, double speedKnots, time_t deptime) bool FGAISchedule::createAIAircraft(FGScheduledFlight* flight, double speedKnots, time_t deptime)
{ {
FGAirport* dep = flight->getDepartureAirport(); FGAirport* dep = flight->getDepartureAirport();

View file

@ -91,6 +91,8 @@ class FGAISchedule
~FGAISchedule(); //destructor ~FGAISchedule(); //destructor
static bool validModelPath(const std::string& model);
bool update(time_t now, const SGVec3d& userCart); bool update(time_t now, const SGVec3d& userCart);
bool init(); bool init();

View file

@ -390,7 +390,13 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
FlightType = tokens[9]; FlightType = tokens[9];
radius = atof(tokens[8].c_str()); radius = atof(tokens[8].c_str());
offset = atof(tokens[7].c_str());; offset = atof(tokens[7].c_str());;
SG_LOG(SG_GENERAL, SG_ALERT, "Adding Aircraft" << model << " " << livery << " " << homePort << " "
if (!FGAISchedule::validModelPath(model)) {
SG_LOG(SG_GENERAL, SG_WARN, "TrafficMgr: Missing model path:" <<
model << " from " << infileName.str());
} else {
SG_LOG(SG_GENERAL, SG_INFO, "Adding Aircraft" << model << " " << livery << " " << homePort << " "
<< registration << " " << flightReq << " " << isHeavy << registration << " " << flightReq << " " << isHeavy
<< " " << acType << " " << airline << " " << m_class << " " << acType << " " << airline << " " << m_class
<< " " << FlightType << " " << radius << " " << offset); << " " << FlightType << " " << radius << " " << offset);
@ -406,6 +412,7 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
FlightType, FlightType,
radius, radius,
offset)); offset));
} // of valid model path
} }
if (tokens[0] == string("FLIGHT")) { if (tokens[0] == string("FLIGHT")) {
//cerr << "Found flight " << buffString << " size is : " << tokens.size() << endl; //cerr << "Found flight " << buffString << " size is : " << tokens.size() << endl;
@ -642,37 +649,43 @@ void FGTrafficManager::endElement(const char *name)
requiredAircraft)); requiredAircraft));
requiredAircraft = ""; requiredAircraft = "";
} else if (!strcmp(name, "aircraft")) { } else if (!strcmp(name, "aircraft")) {
string isHeavy; endAircraft();
if (heavy) {
isHeavy = "true";
} else {
isHeavy = "false";
} }
/*
cerr << "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft elementValueStack.pop_back();
<< "," << acType << "," << livery << "," }
<< airline << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl << endl;*/
void FGTrafficManager::endAircraft()
{
string isHeavy = heavy ? "true" : "false";
if (missingModels.find(mdl) != missingModels.end()) {
// don't stat() or warn again
requiredAircraft = homePort = "";
return;
}
if (!FGAISchedule::validModelPath(mdl)) {
missingModels.insert(mdl);
SG_LOG(SG_GENERAL, SG_WARN, "TrafficMgr: Missing model path:" << mdl);
requiredAircraft = homePort = "";
return;
}
int proportion = int proportion =
(int) (fgGetDouble("/sim/traffic-manager/proportion") * 100); (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100);
int randval = rand() & 100; int randval = rand() & 100;
if (randval <= proportion) { if (randval > proportion) {
requiredAircraft = homePort = "";
return;
}
if (fgGetBool("/sim/traffic-manager/dumpdata") == true) { if (fgGetBool("/sim/traffic-manager/dumpdata") == true) {
SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft
<< "," << acType << "," << livery << "," << "," << acType << "," << livery << ","
<< airline << "," << m_class << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl); << airline << "," << m_class << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl);
} }
//scheduledAircraft.push_back(new FGAISchedule(mdl,
// livery,
// registration,
// heavy,
// acType,
// airline,
// m_class,
// flighttype,
// radius,
// offset,
// score,
// flights));
if (requiredAircraft == "") { if (requiredAircraft == "") {
char buffer[16]; char buffer[16];
snprintf(buffer, 16, "%d", acCounter); snprintf(buffer, 16, "%d", acCounter);
@ -681,6 +694,7 @@ void FGTrafficManager::endElement(const char *name)
if (homePort == "") { if (homePort == "") {
homePort = departurePort; homePort = departurePort;
} }
scheduledAircraft.push_back(new FGAISchedule(mdl, scheduledAircraft.push_back(new FGAISchedule(mdl,
livery, livery,
homePort, homePort,
@ -693,26 +707,13 @@ void FGTrafficManager::endElement(const char *name)
flighttype, flighttype,
radius, offset)); radius, offset));
// while(flights.begin() != flights.end()) {
// flights.pop_back();
// }
} else {
cerr << "Skipping : " << randval;
}
acCounter++; acCounter++;
requiredAircraft = ""; requiredAircraft = "";
homePort = ""; homePort = "";
//for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
// {
// delete (*flt);
// }
//flights.clear();
SG_LOG(SG_GENERAL, SG_BULK, "Reading aircraft : " SG_LOG(SG_GENERAL, SG_BULK, "Reading aircraft : "
<< registration << " with prioritization score " << score); << registration << " with prioritization score " << score);
score = 0; score = 0;
} }
elementValueStack.pop_back();
}
void FGTrafficManager::data(const char *s, int len) void FGTrafficManager::data(const char *s, int len)
{ {

View file

@ -46,6 +46,7 @@
#ifndef _TRAFFICMGR_HXX_ #ifndef _TRAFFICMGR_HXX_
#define _TRAFFICMGR_HXX_ #define _TRAFFICMGR_HXX_
#include <set>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/props/propertyObject.hxx> #include <simgear/props/propertyObject.hxx>
#include <simgear/xml/easyxml.hxx> #include <simgear/xml/easyxml.hxx>
@ -87,6 +88,10 @@ private:
ScheduleVectorIterator currAircraft, currAircraftClosest; ScheduleVectorIterator currAircraft, currAircraftClosest;
vector<string> elementValueStack; vector<string> elementValueStack;
// record model paths which are missing, to avoid duplicate
// warnings when parsing traffic schedules.
std::set<std::string> missingModels;
std::string mdl, livery, registration, callsign, fltrules, std::string mdl, livery, registration, callsign, fltrules,
port, timeString, departurePort, departureTime, arrivalPort, arrivalTime, port, timeString, departurePort, departureTime, arrivalPort, arrivalTime,
repeat, acType, airline, m_class, flighttype, requiredAircraft, homePort; repeat, acType, airline, m_class, flighttype, requiredAircraft, homePort;
@ -123,6 +128,8 @@ public:
FGScheduledFlightVecIterator getFirstFlight(const string &ref) { return flights[ref].begin(); } FGScheduledFlightVecIterator getFirstFlight(const string &ref) { return flights[ref].begin(); }
FGScheduledFlightVecIterator getLastFlight(const string &ref) { return flights[ref].end(); } FGScheduledFlightVecIterator getLastFlight(const string &ref) { return flights[ref].end(); }
void endAircraft();
// Some overloaded virtual XMLVisitor members // Some overloaded virtual XMLVisitor members
virtual void startXML (); virtual void startXML ();
virtual void endXML (); virtual void endXML ();