New traffic manager initialization. Search for all files
data/AI/Aircraft/*/*.xml and read traffic information from these files. Current code still mimicks old behavior by reading data/Traffic/fgtraffic.xml The latter functionality will be disabled once we have some traffic containing files in data/AI/Aircraft.
This commit is contained in:
parent
0547e72d17
commit
e48409d136
2 changed files with 52 additions and 2 deletions
src/Traffic
|
@ -235,6 +235,7 @@ bool FGAISchedule::update(time_t now)
|
||||||
if (!deptime)
|
if (!deptime)
|
||||||
deptime = (*flights.begin())->getDepartureTime();
|
deptime = (*flights.begin())->getDepartureTime();
|
||||||
FGScheduledFlightVecIterator i = flights.begin();
|
FGScheduledFlightVecIterator i = flights.begin();
|
||||||
|
SG_LOG (SG_GENERAL, SG_INFO,"Processing registration " << registration << " with callsign " << (*i)->getCallSign())
|
||||||
if (AIManagerRef)
|
if (AIManagerRef)
|
||||||
{
|
{
|
||||||
// Check if this aircraft has been released.
|
// Check if this aircraft has been released.
|
||||||
|
@ -263,7 +264,6 @@ bool FGAISchedule::update(time_t now)
|
||||||
// object for it.
|
// object for it.
|
||||||
//if ((i->getDepartureTime() < now) && (i->getArrivalTime() > now))
|
//if ((i->getDepartureTime() < now) && (i->getArrivalTime() > now))
|
||||||
|
|
||||||
|
|
||||||
// Part of this flight is in the future.
|
// Part of this flight is in the future.
|
||||||
if ((*i)->getArrivalTime() > now)
|
if ((*i)->getArrivalTime() > now)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <plib/sg.h>
|
#include <plib/sg.h>
|
||||||
|
#include <plib/ul.h>
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include <simgear/math/polar3d.hxx>
|
#include <simgear/math/polar3d.hxx>
|
||||||
|
@ -114,6 +115,51 @@ void FGTrafficManager::init()
|
||||||
// }
|
// }
|
||||||
// Sort by points: Aircraft with frequent visits to the
|
// Sort by points: Aircraft with frequent visits to the
|
||||||
// startup airport will be processed first
|
// startup airport will be processed first
|
||||||
|
ulDir* d, *d2;
|
||||||
|
ulDirEnt* dent, *dent2;
|
||||||
|
SGPath aircraftDir = globals->get_fg_root();
|
||||||
|
|
||||||
|
/* keep the following three lines (which mimicks the old "fixed path" behavior)
|
||||||
|
* until we have some AI models with traffic in the base package
|
||||||
|
*/
|
||||||
|
SGPath path = aircraftDir;
|
||||||
|
path.append("/Traffic/fgtraffic.xml");
|
||||||
|
readXML(path.str(),*this);
|
||||||
|
|
||||||
|
aircraftDir.append("AI/Aircraft/");
|
||||||
|
if (aircraftDir.exists())
|
||||||
|
{
|
||||||
|
if((d = ulOpenDir(aircraftDir.c_str())) == NULL)
|
||||||
|
return;
|
||||||
|
while((dent = ulReadDir(d)) != NULL) {
|
||||||
|
//cerr << "Scanning : " << dent->d_name << endl;
|
||||||
|
if (string(dent->d_name) != string(".") &&
|
||||||
|
string(dent->d_name) != string("..") &&
|
||||||
|
dent->d_isdir)
|
||||||
|
{
|
||||||
|
SGPath currACDir = aircraftDir;
|
||||||
|
currACDir.append(dent->d_name);
|
||||||
|
if ((d2 = ulOpenDir(currACDir.c_str())) == NULL)
|
||||||
|
return;
|
||||||
|
while ((dent2 = ulReadDir(d2)) != NULL) {
|
||||||
|
SGPath currFile = currACDir;
|
||||||
|
currFile.append(dent2->d_name);
|
||||||
|
if (currFile.extension() == string("xml"))
|
||||||
|
{
|
||||||
|
//cerr << "found " << dent2->d_name << " for parsing" << endl;
|
||||||
|
SGPath currFile = currACDir;
|
||||||
|
currFile.append(dent2->d_name);
|
||||||
|
SG_LOG(SG_GENERAL, SG_INFO, "Scanning " << currFile.str() << " for traffic");
|
||||||
|
readXML(currFile.str(),*this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ulCloseDir(d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ulCloseDir(d);
|
||||||
|
}
|
||||||
|
// Sort by points: Aircraft with frequent visits to the
|
||||||
|
// startup airport will be processed first
|
||||||
sort(scheduledAircraft.begin(), scheduledAircraft.end(), compareSchedules);
|
sort(scheduledAircraft.begin(), scheduledAircraft.end(), compareSchedules);
|
||||||
currAircraft = scheduledAircraft.begin();
|
currAircraft = scheduledAircraft.begin();
|
||||||
currAircraftClosest = scheduledAircraft.begin();
|
currAircraftClosest = scheduledAircraft.begin();
|
||||||
|
@ -122,14 +168,17 @@ void FGTrafficManager::init()
|
||||||
|
|
||||||
void FGTrafficManager::update(double something)
|
void FGTrafficManager::update(double something)
|
||||||
{
|
{
|
||||||
|
//SG_LOG( SG_GENERAL, SG_INFO, "Running TrafficManager::Update() ");
|
||||||
if (runCount < 1000)
|
if (runCount < 1000)
|
||||||
{
|
{
|
||||||
runCount++;
|
runCount++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
||||||
if (scheduledAircraft.size() == 0)
|
if (scheduledAircraft.size() == 0) {
|
||||||
|
//SG_LOG( SG_GENERAL, SG_INFO, "Returned Running TrafficManager::Update() ");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if(currAircraft == scheduledAircraft.end())
|
if(currAircraft == scheduledAircraft.end())
|
||||||
{
|
{
|
||||||
//cerr << "resetting schedule " << endl;
|
//cerr << "resetting schedule " << endl;
|
||||||
|
@ -142,6 +191,7 @@ void FGTrafficManager::update(double something)
|
||||||
cerr << "Failed to update aircraft schedule in traffic manager" << endl;
|
cerr << "Failed to update aircraft schedule in traffic manager" << endl;
|
||||||
}
|
}
|
||||||
currAircraft++;
|
currAircraft++;
|
||||||
|
//SG_LOG( SG_GENERAL, SG_INFO, "Done Running TrafficManager::Update() ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGTrafficManager::release(int id)
|
void FGTrafficManager::release(int id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue