1
0
Fork 0

Merge branch 'next' of git://gitorious.org/fg/flightgear into next

This commit is contained in:
Frederic Bouvier 2010-09-05 16:59:26 +02:00
commit 4175619392
6 changed files with 2020 additions and 1882 deletions

View file

@ -101,6 +101,80 @@ using namespace osg;
static osg::ref_ptr<osgViewer::Viewer> viewer; static osg::ref_ptr<osgViewer::Viewer> viewer;
static osg::ref_ptr<osg::Camera> mainCamera; static osg::ref_ptr<osg::Camera> mainCamera;
static void setStereoMode( const char * mode )
{
DisplaySettings::StereoMode stereoMode;
bool stereoOn = true;
if (strcmp(mode,"QUAD_BUFFER")==0)
{
stereoMode = DisplaySettings::QUAD_BUFFER;
}
else if (strcmp(mode,"ANAGLYPHIC")==0)
{
stereoMode = DisplaySettings::ANAGLYPHIC;
}
else if (strcmp(mode,"HORIZONTAL_SPLIT")==0)
{
stereoMode = DisplaySettings::HORIZONTAL_SPLIT;
}
else if (strcmp(mode,"VERTICAL_SPLIT")==0)
{
stereoMode = DisplaySettings::VERTICAL_SPLIT;
}
else if (strcmp(mode,"LEFT_EYE")==0)
{
stereoMode = DisplaySettings::LEFT_EYE;
}
else if (strcmp(mode,"RIGHT_EYE")==0)
{
stereoMode = DisplaySettings::RIGHT_EYE;
}
else if (strcmp(mode,"HORIZONTAL_INTERLACE")==0)
{
stereoMode = DisplaySettings::HORIZONTAL_INTERLACE;
}
else if (strcmp(mode,"VERTICAL_INTERLACE")==0)
{
stereoMode = DisplaySettings::VERTICAL_INTERLACE;
}
else if (strcmp(mode,"CHECKERBOARD")==0)
{
stereoMode = DisplaySettings::CHECKERBOARD;
} else {
stereoOn = false;
}
DisplaySettings::instance()->setStereo( stereoOn );
DisplaySettings::instance()->setStereoMode( stereoMode );
}
static const char * getStereoMode()
{
DisplaySettings::StereoMode stereoMode = DisplaySettings::instance()->getStereoMode();
bool stereoOn = DisplaySettings::instance()->getStereo();
if( !stereoOn ) return "OFF";
if( stereoMode == DisplaySettings::QUAD_BUFFER ) {
return "QUAD_BUFFER";
} else if( stereoMode == DisplaySettings::ANAGLYPHIC ) {
return "ANAGLYPHIC";
} else if( stereoMode == DisplaySettings::HORIZONTAL_SPLIT ) {
return "HORIZONTAL_SPLIT";
} else if( stereoMode == DisplaySettings::VERTICAL_SPLIT ) {
return "VERTICAL_SPLIT";
} else if( stereoMode == DisplaySettings::LEFT_EYE ) {
return "LEFT_EYE";
} else if( stereoMode == DisplaySettings::RIGHT_EYE ) {
return "RIGHT_EYE";
} else if( stereoMode == DisplaySettings::HORIZONTAL_INTERLACE ) {
return "HORIZONTAL_INTERLACE";
} else if( stereoMode == DisplaySettings::VERTICAL_INTERLACE ) {
return "VERTICAL_INTERLACE";
} else if( stereoMode == DisplaySettings::CHECKERBOARD ) {
return "CHECKERBOARD";
}
return "OFF";
}
void fgOSOpenWindow(bool stencil) void fgOSOpenWindow(bool stencil)
{ {
viewer = new osgViewer::Viewer; viewer = new osgViewer::Viewer;
@ -175,8 +249,19 @@ void fgOSOpenWindow(bool stencil)
viewer->setSceneData(new osg::Group); viewer->setSceneData(new osg::Group);
globals->get_renderer()->setViewer(viewer.get()); globals->get_renderer()->setViewer(viewer.get());
CameraGroup::setDefault(cameraGroup); CameraGroup::setDefault(cameraGroup);
DisplaySettings * displaySettings = DisplaySettings::instance();
fgTie("/sim/rendering/osg-displaysettings/eye-separation", displaySettings, &DisplaySettings::getEyeSeparation, &DisplaySettings::setEyeSeparation );
fgTie("/sim/rendering/osg-displaysettings/screen-distance", displaySettings, &DisplaySettings::getScreenDistance, &DisplaySettings::setScreenDistance );
fgTie("/sim/rendering/osg-displaysettings/screen-width", displaySettings, &DisplaySettings::getScreenWidth, &DisplaySettings::setScreenWidth );
fgTie("/sim/rendering/osg-displaysettings/screen-height", displaySettings, &DisplaySettings::getScreenHeight, &DisplaySettings::setScreenHeight );
fgTie("/sim/rendering/osg-displaysettings/stereo-mode", getStereoMode, setStereoMode );
fgTie("/sim/rendering/osg-displaysettings/double-buffer", displaySettings, &DisplaySettings::getDoubleBuffer, &DisplaySettings::setDoubleBuffer );
fgTie("/sim/rendering/osg-displaysettings/depth-buffer", displaySettings, &DisplaySettings::getDepthBuffer, &DisplaySettings::setDepthBuffer );
fgTie("/sim/rendering/osg-displaysettings/rgb", displaySettings, &DisplaySettings::getRGB, &DisplaySettings::setRGB );
} }
static int status = 0; static int status = 0;
void fgOSExit(int code) void fgOSExit(int code)

View file

@ -364,10 +364,12 @@ void FGAISchedule::scheduleFlights()
currentDestination = flight->getArrivalAirport()->getId(); currentDestination = flight->getArrivalAirport()->getId();
if (!initialized) { if (!initialized) {
string departurePort = flight->getDepartureAirport()->getId(); string departurePort = flight->getDepartureAirport()->getId();
//cerr << "Scheduled " << registration << " " << score << " for Flight "
// << flight-> getCallSign() << " from " << departurePort << " to " << currentDestination << endl;
if (fgGetString("/sim/presets/airport-id") == departurePort) { if (fgGetString("/sim/presets/airport-id") == departurePort) {
hits++; hits++;
} }
runCount++; //runCount++;
initialized = true; initialized = true;
} }
@ -508,6 +510,7 @@ void FGAISchedule::setScore ()
score = 0.0; score = 0.0;
} }
} }
runCount++;
} }
bool compareSchedules(FGAISchedule*a, FGAISchedule*b) bool compareSchedules(FGAISchedule*a, FGAISchedule*b)

View file

@ -78,12 +78,12 @@ using std::strcmp;
*****************************************************************************/ *****************************************************************************/
FGTrafficManager::FGTrafficManager() FGTrafficManager::FGTrafficManager()
{ {
//score = 0; //score = 0;
//runCount = 0; //runCount = 0;
acCounter = 0; acCounter = 0;
} }
FGTrafficManager:: ~FGTrafficManager() FGTrafficManager::~FGTrafficManager()
{ {
// Save the heuristics data // Save the heuristics data
bool saveData = false; bool saveData = false;
@ -93,10 +93,10 @@ FGTrafficManager:: ~FGTrafficManager()
cacheData.append("ai"); cacheData.append("ai");
string airport = fgGetString("/sim/presets/airport-id"); string airport = fgGetString("/sim/presets/airport-id");
if ((airport) != "") { if ((airport) != "") {
char buffer[128]; char buffer[128];
::snprintf(buffer, 128, "%c/%c/%c/", ::snprintf(buffer, 128, "%c/%c/%c/",
airport[0], airport[1], airport[2]); airport[0], airport[1], airport[2]);
cacheData.append(buffer); cacheData.append(buffer);
if (!cacheData.exists()) { if (!cacheData.exists()) {
cacheData.create_dir(0777); cacheData.create_dir(0777);
@ -106,60 +106,80 @@ FGTrafficManager:: ~FGTrafficManager()
saveData = true; saveData = true;
cachefile.open(cacheData.str().c_str()); cachefile.open(cacheData.str().c_str());
} }
}
for (ScheduleVectorIterator sched = scheduledAircraft.begin(); sched != scheduledAircraft.end(); sched++) {
if (saveData) {
cachefile << (*sched)->getRegistration() << " "
<< (*sched)-> getRunCount() << " "
<< (*sched)->getHits() << endl;
}
delete (*sched);
} }
if (saveData) { for (ScheduleVectorIterator sched = scheduledAircraft.begin();
cachefile.close(); sched != scheduledAircraft.end(); sched++) {
} if (saveData) {
scheduledAircraft.clear(); cachefile << (*sched)->getRegistration() << " "
flights.clear(); << (*sched)->getRunCount() << " "
<< (*sched)->getHits() << endl;
}
delete(*sched);
}
if (saveData) {
cachefile.close();
}
scheduledAircraft.clear();
flights.clear();
} }
void FGTrafficManager::init() void FGTrafficManager::init()
{ {
ulDir* d, *d2; ulDir *d, *d2;
ulDirEnt* dent, *dent2; ulDirEnt *dent, *dent2;
SGPath aircraftDir = globals->get_fg_root();
SGPath path = aircraftDir;
heuristicsVector heuristics;
HeuristicMap heurMap;
heuristicsVector heuristics;
HeuristicMap heurMap;
aircraftDir.append("AI/Traffic"); if (string(fgGetString("/sim/traffic-manager/datafile")) == string("")) {
if ((d = ulOpenDir(aircraftDir.c_str())) != NULL) SGPath aircraftDir = globals->get_fg_root();
{ SGPath path = aircraftDir;
while((dent = ulReadDir(d)) != NULL) {
if (string(dent->d_name) != string(".") && aircraftDir.append("AI/Traffic");
string(dent->d_name) != string("..") && if ((d = ulOpenDir(aircraftDir.c_str())) != NULL) {
dent->d_isdir) while ((dent = ulReadDir(d)) != NULL) {
{ if (string(dent->d_name) != string(".") &&
SGPath currACDir = aircraftDir; string(dent->d_name) != string("..") && dent->d_isdir) {
currACDir.append(dent->d_name); SGPath currACDir = aircraftDir;
if ((d2 = ulOpenDir(currACDir.c_str())) == NULL) currACDir.append(dent->d_name);
return; if ((d2 = ulOpenDir(currACDir.c_str())) == NULL)
while ((dent2 = ulReadDir(d2)) != NULL) { return;
SGPath currFile = currACDir; while ((dent2 = ulReadDir(d2)) != NULL) {
currFile.append(dent2->d_name); SGPath currFile = currACDir;
if (currFile.extension() == string("xml")) currFile.append(dent2->d_name);
{ if (currFile.extension() == string("xml")) {
SGPath currFile = currACDir; SGPath currFile = currACDir;
currFile.append(dent2->d_name); currFile.append(dent2->d_name);
SG_LOG(SG_GENERAL, SG_DEBUG, "Scanning " << currFile.str() << " for traffic"); SG_LOG(SG_GENERAL, SG_DEBUG,
readXML(currFile.str(),*this); "Scanning " << currFile.
} str() << " for traffic");
} readXML(currFile.str(), *this);
ulCloseDir(d2); }
} }
} ulCloseDir(d2);
ulCloseDir(d); }
}
ulCloseDir(d);
}
} else {
fgSetBool("/sim/traffic-manager/heuristics", false);
SGPath path = string(fgGetString("/sim/traffic-manager/datafile"));
string ext = path.extension();
if (path.extension() == "xml") {
if (path.exists()) {
readXML(path.str(), *this);
}
} else if (path.extension() == "conf") {
if (path.exists()) {
readTimeTableFromFile(path);
}
} else {
SG_LOG(SG_GENERAL, SG_ALERT,
"Unknown data format " << path.str()
<< " for traffic");
}
//exit(1);
} }
if (fgGetBool("/sim/traffic-manager/heuristics")) { if (fgGetBool("/sim/traffic-manager/heuristics")) {
//cerr << "Processing Heuristics" << endl; //cerr << "Processing Heuristics" << endl;
@ -170,97 +190,103 @@ void FGTrafficManager::init()
if ((airport) != "") { if ((airport) != "") {
char buffer[128]; char buffer[128];
::snprintf(buffer, 128, "%c/%c/%c/", ::snprintf(buffer, 128, "%c/%c/%c/",
airport[0], airport[1], airport[2]); airport[0], airport[1], airport[2]);
cacheData.append(buffer); cacheData.append(buffer);
cacheData.append(airport + "-cache.txt"); cacheData.append(airport + "-cache.txt");
if (cacheData.exists()) { if (cacheData.exists()) {
ifstream data(cacheData.c_str()); ifstream data(cacheData.c_str());
while (1) { while (1) {
Heuristic *h = new Heuristic; Heuristic h; // = new Heuristic;
data >> h->registration >> h->runCount >> h->hits; data >> h.registration >> h.runCount >> h.hits;
if (data.eof()) if (data.eof())
break; break;
heurMap[h->registration] = h; HeuristicMapIterator itr = heurMap.find(h.registration);
if (itr != heurMap.end()) {
SG_LOG(SG_GENERAL, SG_WARN,"Traffic Manager Warning: found duplicate tailnumber " <<
h.registration << " for AI aircraft");
}
heurMap[h.registration] = h;
heuristics.push_back(h); heuristics.push_back(h);
} }
} }
} }
for (currAircraft = scheduledAircraft.begin(); for (currAircraft = scheduledAircraft.begin();
currAircraft != scheduledAircraft.end(); currAircraft != scheduledAircraft.end(); currAircraft++) {
currAircraft++) {
string registration = (*currAircraft)->getRegistration(); string registration = (*currAircraft)->getRegistration();
HeuristicMapIterator itr = heurMap.find(registration); HeuristicMapIterator itr = heurMap.find(registration);
//cerr << "Processing heuristics for" << (*currAircraft)->getRegistration() << endl; //cerr << "Processing heuristics for" << (*currAircraft)->getRegistration() << endl;
if (itr == heurMap.end()) { if (itr == heurMap.end()) {
//cerr << "No heuristics found for " << registration << endl; //cerr << "No heuristics found for " << registration << endl;
} else { } else {
(*currAircraft)->setrunCount(itr->second->runCount); (*currAircraft)->setrunCount(itr->second.runCount);
(*currAircraft)->setHits (itr->second->hits); (*currAircraft)->setHits(itr->second.hits);
(*currAircraft)->setScore();
//cerr <<"Runcount " << itr->second->runCount << ".Hits " << itr->second->hits << endl; //cerr <<"Runcount " << itr->second->runCount << ".Hits " << itr->second->hits << endl;
} }
} }
//cerr << "Done" << endl; //cerr << "Done" << endl;
for (heuristicsVectorIterator hvi = heuristics.begin(); //for (heuristicsVectorIterator hvi = heuristics.begin();
hvi != heuristics.end(); // hvi != heuristics.end(); hvi++) {
hvi++) { // delete(*hvi);
delete (*hvi); //}
}
sort (scheduledAircraft.begin(), scheduledAircraft.end(), compareSchedules);
} }
// Do sorting and scoring separately, to take advantage of the "homeport| variable
for (currAircraft = scheduledAircraft.begin();
currAircraft != scheduledAircraft.end(); currAircraft++) {
(*currAircraft)->setScore();
}
sort(scheduledAircraft.begin(), scheduledAircraft.end(),
compareSchedules);
currAircraft = scheduledAircraft.begin(); currAircraft = scheduledAircraft.begin();
currAircraftClosest = scheduledAircraft.begin(); currAircraftClosest = scheduledAircraft.begin();
} }
void FGTrafficManager::update(double /*dt*/) void FGTrafficManager::update(double /*dt */ )
{ {
if (fgGetBool("/environment/metar/valid") == false) { if (fgGetBool("/environment/metar/valid") == false) {
return; return;
}
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
if (scheduledAircraft.size() == 0) {
return;
}
SGVec3d userCart = SGVec3d::fromGeod(SGGeod::fromDeg(
fgGetDouble("/position/longitude-deg"),
fgGetDouble("/position/latitude-deg")));
if(currAircraft == scheduledAircraft.end())
{
currAircraft = scheduledAircraft.begin();
} }
//cerr << "Processing << " << (*currAircraft)->getRegistration() << " with score " << (*currAircraft)->getScore() << endl; time_t now = time(NULL) + fgGetLong("/sim/time/warp");
if (!((*currAircraft)->update(now, userCart))) if (scheduledAircraft.size() == 0) {
{ return;
// NOTE: With traffic manager II, this statement below is no longer true
// after proper initialization, we shouldnt get here.
// But let's make sure
//SG_LOG( SG_GENERAL, SG_ALERT, "Failed to update aircraft schedule in traffic manager");
} }
currAircraft++;
SGVec3d userCart =
SGVec3d::fromGeod(SGGeod::
fromDeg(fgGetDouble("/position/longitude-deg"),
fgGetDouble("/position/latitude-deg")));
if (currAircraft == scheduledAircraft.end()) {
currAircraft = scheduledAircraft.begin();
}
//cerr << "Processing << " << (*currAircraft)->getRegistration() << " with score " << (*currAircraft)->getScore() << endl;
if (!((*currAircraft)->update(now, userCart))) {
// NOTE: With traffic manager II, this statement below is no longer true
// after proper initialization, we shouldnt get here.
// But let's make sure
//SG_LOG( SG_GENERAL, SG_ALERT, "Failed to update aircraft schedule in traffic manager");
}
currAircraft++;
} }
void FGTrafficManager::release(int id) void FGTrafficManager::release(int id)
{ {
releaseList.push_back(id); releaseList.push_back(id);
} }
bool FGTrafficManager::isReleased(int id) bool FGTrafficManager::isReleased(int id)
{ {
IdListIterator i = releaseList.begin(); IdListIterator i = releaseList.begin();
while (i != releaseList.end()) while (i != releaseList.end()) {
{ if ((*i) == id) {
if ((*i) == id) releaseList.erase(i);
{ return true;
releaseList.erase(i); }
return true; i++;
}
i++;
} }
return false; return false;
} }
/*
void FGTrafficManager::readTimeTableFromFile(SGPath infileName) void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
{ {
string model; string model;
@ -316,9 +342,10 @@ 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());;
//cerr << "Found AC string " << model << " " << livery << " " << homePort << " " SG_LOG(SG_GENERAL, SG_ALERT, "Adding Aircraft" << model << " " << livery << " " << homePort << " "
// << registration << " " << flightReq << " " << isHeavy << " " << acType << " " << airline << " " << m_class << registration << " " << flightReq << " " << isHeavy
// << " " << FlightType << " " << radius << " " << offset << endl; << " " << acType << " " << airline << " " << m_class
<< " " << FlightType << " " << radius << " " << offset);
scheduledAircraft.push_back(new FGAISchedule(model, scheduledAircraft.push_back(new FGAISchedule(model,
livery, livery,
homePort, homePort,
@ -350,7 +377,7 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
string requiredAircraft = tokens[9]; string requiredAircraft = tokens[9];
if (weekdays.size() != 7) { if (weekdays.size() != 7) {
cerr << "Found misconfigured weekdays string" << weekdays << endl; SG_LOG(SG_GENERAL, SG_ALERT, "Found misconfigured weekdays string" << weekdays);
exit(1); exit(1);
} }
depTime.clear(); depTime.clear();
@ -365,31 +392,32 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
arrivalWeekdayNeedsIncrement = true; arrivalWeekdayNeedsIncrement = true;
} }
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
int j = i+1;
if (weekdays[i] != '.') { if (weekdays[i] != '.') {
char buffer[4]; char buffer[4];
snprintf(buffer, 4, "%d/", i); snprintf(buffer, 4, "%d/", j);
string departureTime = string(buffer) + depTimeGen + string(":00"); string departureTime = string(buffer) + depTimeGen + string(":00");
string arrivalTime; string arrivalTime;
if (!arrivalWeekdayNeedsIncrement) { if (!arrivalWeekdayNeedsIncrement) {
arrivalTime = string(buffer) + arrTimeGen + string(":00"); arrivalTime = string(buffer) + arrTimeGen + string(":00");
} }
if (arrivalWeekdayNeedsIncrement && i != 6 ) { if (arrivalWeekdayNeedsIncrement && i != 6 ) {
snprintf(buffer, 4, "%d/", i+1); snprintf(buffer, 4, "%d/", j+1);
arrivalTime = string(buffer) + arrTimeGen + string(":00"); arrivalTime = string(buffer) + arrTimeGen + string(":00");
} }
if (arrivalWeekdayNeedsIncrement && i == 6 ) { if (arrivalWeekdayNeedsIncrement && i == 6 ) {
snprintf(buffer, 4, "%d/", 0); snprintf(buffer, 4, "%d/", 0);
arrivalTime = string(buffer) + arrTimeGen + string(":00"); arrivalTime = string(buffer) + arrTimeGen + string(":00");
} }
cerr << "Adding flight: " << callsign << " " SG_LOG(SG_GENERAL, SG_ALERT, "Adding flight " << callsign << " "
<< fltrules << " " << fltrules << " "
<< departurePort << " " << departurePort << " "
<< arrivalPort << " " << arrivalPort << " "
<< cruiseAlt << " " << cruiseAlt << " "
<< departureTime << " " << departureTime << " "
<< arrivalTime << " " << arrivalTime << " "
<< repeat << " " << repeat << " "
<< requiredAircraft << endl; << requiredAircraft);
flights[requiredAircraft].push_back(new FGScheduledFlight(callsign, flights[requiredAircraft].push_back(new FGScheduledFlight(callsign,
fltrules, fltrules,
@ -407,9 +435,9 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
} }
//exit(1); //exit(1);
}*/ }
/*
void FGTrafficManager::Tokenize(const string& str, void FGTrafficManager::Tokenize(const string& str,
vector<string>& tokens, vector<string>& tokens,
const string& delimiters) const string& delimiters)
@ -429,164 +457,182 @@ void FGTrafficManager::Tokenize(const string& str,
pos = str.find_first_of(delimiters, lastPos); pos = str.find_first_of(delimiters, lastPos);
} }
} }
*/
void FGTrafficManager::startXML () {
//cout << "Start XML" << endl; void FGTrafficManager::startXML()
requiredAircraft = ""; {
homePort = ""; //cout << "Start XML" << endl;
requiredAircraft = "";
homePort = "";
} }
void FGTrafficManager::endXML () { void FGTrafficManager::endXML()
//cout << "End XML" << endl; {
//cout << "End XML" << endl;
} }
void FGTrafficManager::startElement (const char * name, const XMLAttributes &atts) { void FGTrafficManager::startElement(const char *name,
const char * attval; const XMLAttributes & atts)
//cout << "Start element " << name << endl; {
//FGTrafficManager temp; const char *attval;
//for (int i = 0; i < atts.size(); i++) //cout << "Start element " << name << endl;
// if (string(atts.getName(i)) == string("include")) //FGTrafficManager temp;
attval = atts.getValue("include"); //for (int i = 0; i < atts.size(); i++)
if (attval != 0) // if (string(atts.getName(i)) == string("include"))
{ attval = atts.getValue("include");
//cout << "including " << attval << endl; if (attval != 0) {
SGPath path = //cout << "including " << attval << endl;
globals->get_fg_root(); SGPath path = globals->get_fg_root();
path.append("/Traffic/"); path.append("/Traffic/");
path.append(attval); path.append(attval);
readXML(path.str(), *this); readXML(path.str(), *this);
} }
elementValueStack.push_back( "" ); elementValueStack.push_back("");
// cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl; // cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
} }
void FGTrafficManager::endElement (const char * name) { void FGTrafficManager::endElement(const char *name)
//cout << "End element " << name << endl; {
const string& value = elementValueStack.back(); //cout << "End element " << name << endl;
const string & value = elementValueStack.back();
if (!strcmp(name, "model")) if (!strcmp(name, "model"))
mdl = value; mdl = value;
else if (!strcmp(name, "livery")) else if (!strcmp(name, "livery"))
livery = value; livery = value;
else if (!strcmp(name, "home-port")) else if (!strcmp(name, "home-port"))
homePort = value; homePort = value;
else if (!strcmp(name, "registration")) else if (!strcmp(name, "registration"))
registration = value; registration = value;
else if (!strcmp(name, "airline")) else if (!strcmp(name, "airline"))
airline = value; airline = value;
else if (!strcmp(name, "actype")) else if (!strcmp(name, "actype"))
acType = value; acType = value;
else if (!strcmp(name, "required-aircraft")) else if (!strcmp(name, "required-aircraft"))
requiredAircraft = value; requiredAircraft = value;
else if (!strcmp(name, "flighttype")) else if (!strcmp(name, "flighttype"))
flighttype = value; flighttype = value;
else if (!strcmp(name, "radius")) else if (!strcmp(name, "radius"))
radius = atoi(value.c_str()); radius = atoi(value.c_str());
else if (!strcmp(name, "offset")) else if (!strcmp(name, "offset"))
offset = atoi(value.c_str()); offset = atoi(value.c_str());
else if (!strcmp(name, "performance-class")) else if (!strcmp(name, "performance-class"))
m_class = value; m_class = value;
else if (!strcmp(name, "heavy")) else if (!strcmp(name, "heavy")) {
{ if (value == string("true"))
if(value == string("true")) heavy = true;
heavy = true; else
else heavy = false;
heavy = false; } else if (!strcmp(name, "callsign"))
} callsign = value;
else if (!strcmp(name, "callsign")) else if (!strcmp(name, "fltrules"))
callsign = value; fltrules = value;
else if (!strcmp(name, "fltrules")) else if (!strcmp(name, "port"))
fltrules = value; port = value;
else if (!strcmp(name, "port")) else if (!strcmp(name, "time"))
port = value; timeString = value;
else if (!strcmp(name, "time")) else if (!strcmp(name, "departure")) {
timeString = value; departurePort = port;
else if (!strcmp(name, "departure")) departureTime = timeString;
{ } else if (!strcmp(name, "cruise-alt"))
departurePort = port; cruiseAlt = atoi(value.c_str());
departureTime = timeString; else if (!strcmp(name, "arrival")) {
} arrivalPort = port;
else if (!strcmp(name, "cruise-alt")) arrivalTime = timeString;
cruiseAlt = atoi(value.c_str()); } else if (!strcmp(name, "repeat"))
else if (!strcmp(name, "arrival")) repeat = value;
{ else if (!strcmp(name, "flight")) {
arrivalPort = port; // We have loaded and parsed all the information belonging to this flight
arrivalTime = timeString; // so we temporarily store it.
} //cerr << "Pusing back flight " << callsign << endl;
else if (!strcmp(name, "repeat")) //cerr << callsign << " " << fltrules << " "<< departurePort << " " << arrivalPort << " "
repeat = value; // << cruiseAlt << " " << departureTime<< " "<< arrivalTime << " " << repeat << endl;
else if (!strcmp(name, "flight"))
{
// We have loaded and parsed all the information belonging to this flight
// so we temporarily store it.
//cerr << "Pusing back flight " << callsign << endl;
//cerr << callsign << " " << fltrules << " "<< departurePort << " " << arrivalPort << " "
// << cruiseAlt << " " << departureTime<< " "<< arrivalTime << " " << repeat << endl;
//Prioritize aircraft //Prioritize aircraft
string apt = fgGetString("/sim/presets/airport-id"); string apt = fgGetString("/sim/presets/airport-id");
//cerr << "Airport information: " << apt << " " << departurePort << " " << arrivalPort << endl; //cerr << "Airport information: " << apt << " " << departurePort << " " << arrivalPort << endl;
//if (departurePort == apt) score++; //if (departurePort == apt) score++;
//flights.push_back(new FGScheduledFlight(callsign, //flights.push_back(new FGScheduledFlight(callsign,
// fltrules, // fltrules,
// departurePort, // departurePort,
// arrivalPort, // arrivalPort,
// cruiseAlt, // cruiseAlt,
// departureTime, // departureTime,
// arrivalTime, // arrivalTime,
// repeat)); // repeat));
if (requiredAircraft == "") { if (requiredAircraft == "") {
char buffer[16]; char buffer[16];
snprintf(buffer, 16, "%d", acCounter); snprintf(buffer, 16, "%d", acCounter);
requiredAircraft = buffer; requiredAircraft = buffer;
} }
SG_LOG(SG_GENERAL, SG_DEBUG, "Adding flight: " << callsign << " " SG_LOG(SG_GENERAL, SG_DEBUG, "Adding flight: " << callsign << " "
<< fltrules << " " << fltrules << " "
<< departurePort << " " << departurePort << " "
<< arrivalPort << " " << arrivalPort << " "
<< cruiseAlt << " " << cruiseAlt << " "
<< departureTime << " " << departureTime << " "
<< arrivalTime << " " << arrivalTime << " " << repeat << " " << requiredAircraft);
<< repeat << " " // For database maintainance purposes, it may be convenient to
<< requiredAircraft); //
if (fgGetBool("/sim/traffic-manager/dumpdata") == true) {
flights[requiredAircraft].push_back(new FGScheduledFlight(callsign, SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump FLIGHT," << callsign << ","
fltrules, << fltrules << ","
departurePort, << departurePort << ","
arrivalPort, << arrivalPort << ","
cruiseAlt, << cruiseAlt << ","
departureTime, << departureTime << ","
arrivalTime, << arrivalTime << "," << repeat << "," << requiredAircraft);
repeat, }
requiredAircraft)); flights[requiredAircraft].push_back(new FGScheduledFlight(callsign,
requiredAircraft = ""; fltrules,
} departurePort,
else if (!strcmp(name, "aircraft")) arrivalPort,
{ cruiseAlt,
int proportion = (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100); departureTime,
int randval = rand() & 100; arrivalTime,
if (randval < proportion) { repeat,
//scheduledAircraft.push_back(new FGAISchedule(mdl, requiredAircraft));
// livery, requiredAircraft = "";
// registration, } else if (!strcmp(name, "aircraft")) {
// heavy, string isHeavy;
// acType, if (heavy) {
// airline, isHeavy = "true";
// m_class, } else {
// flighttype, isHeavy = "false";
// radius, }
// offset, /*
// score, cerr << "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft
// flights)); << "," << acType << "," << livery << ","
if (requiredAircraft == "") { << airline << "," << offset << "," << radius << "," << flighttype << "," << isHeavy << "," << mdl << endl;*/
char buffer[16]; int proportion =
snprintf(buffer, 16, "%d", acCounter); (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100);
requiredAircraft = buffer; int randval = rand() & 100;
} if (randval <= proportion) {
if (homePort == "") { if (fgGetBool("/sim/traffic-manager/dumpdata") == true) {
homePort = departurePort; SG_LOG(SG_GENERAL, SG_ALERT, "Traffic Dump AC," << homePort << "," << registration << "," << requiredAircraft
} << "," << acType << "," << livery << ","
<< airline << "," << 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 == "") {
char buffer[16];
snprintf(buffer, 16, "%d", acCounter);
requiredAircraft = buffer;
}
if (homePort == "") {
homePort = departurePort;
}
scheduledAircraft.push_back(new FGAISchedule(mdl, scheduledAircraft.push_back(new FGAISchedule(mdl,
livery, livery,
homePort, homePort,
@ -597,45 +643,49 @@ void FGTrafficManager::endElement (const char * name) {
airline, airline,
m_class, m_class,
flighttype, flighttype,
radius, radius, offset));
offset));
// while(flights.begin() != flights.end()) { // while(flights.begin() != flights.end()) {
// flights.pop_back(); // flights.pop_back();
// } // }
} else {
cerr << "Skipping : " << randval;
} }
acCounter++; acCounter++;
requiredAircraft = ""; requiredAircraft = "";
homePort = ""; homePort = "";
//for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++) //for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
// { // {
// delete (*flt); // delete (*flt);
// } // }
//flights.clear(); //flights.clear();
SG_LOG( SG_GENERAL, SG_BULK, "Reading aircraft : " SG_LOG(SG_GENERAL, SG_BULK, "Reading aircraft : "
<< registration << registration << " with prioritization score " << score);
<< " with prioritization score " score = 0;
<< score);
score = 0;
} }
elementValueStack.pop_back(); elementValueStack.pop_back();
} }
void FGTrafficManager::data (const char * s, int len) { void FGTrafficManager::data(const char *s, int len)
string token = string(s,len); {
//cout << "Character data " << string(s,len) << endl; string token = string(s, len);
elementValueStack.back() += token; //cout << "Character data " << string(s,len) << endl;
elementValueStack.back() += token;
} }
void FGTrafficManager::pi (const char * target, const char * data) { void FGTrafficManager::pi(const char *target, const char *data)
//cout << "Processing instruction " << target << ' ' << data << endl; {
//cout << "Processing instruction " << target << ' ' << data << endl;
} }
void FGTrafficManager::warning (const char * message, int line, int column) { void FGTrafficManager::warning(const char *message, int line, int column)
SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')'); {
SG_LOG(SG_IO, SG_WARN,
"Warning: " << message << " (" << line << ',' << column << ')');
} }
void FGTrafficManager::error (const char * message, int line, int column) { void FGTrafficManager::error(const char *message, int line, int column)
SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')'); {
SG_LOG(SG_IO, SG_ALERT,
"Error: " << message << " (" << line << ',' << column << ')');
} }

View file

@ -65,11 +65,11 @@ public:
unsigned int hits; unsigned int hits;
}; };
typedef vector<Heuristic*> heuristicsVector; typedef vector<Heuristic> heuristicsVector;
typedef vector<Heuristic*>::iterator heuristicsVectorIterator; typedef vector<Heuristic>::iterator heuristicsVectorIterator;
typedef std::map < std::string, Heuristic *> HeuristicMap; typedef std::map < std::string, Heuristic> HeuristicMap;
typedef HeuristicMap::iterator HeuristicMapIterator; typedef HeuristicMap::iterator HeuristicMapIterator;
@ -93,8 +93,8 @@ private:
FGScheduledFlightMap flights; FGScheduledFlightMap flights;
//void readTimeTableFromFile(SGPath infilename); void readTimeTableFromFile(SGPath infilename);
//void Tokenize(const string& str, vector<string>& tokens, const string& delimiters = " "); void Tokenize(const string& str, vector<string>& tokens, const string& delimiters = " ");
public: public:
FGTrafficManager(); FGTrafficManager();