Use SGTime instead of time() in traffic/AI code
- avoids manual handling of /sim/time/warp in many places
This commit is contained in:
parent
ac146f5658
commit
540d4c2111
7 changed files with 31 additions and 14 deletions
|
@ -1397,7 +1397,7 @@ time_t FGAIAircraft::checkForArrivalTime(const string& wptName) {
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
time_t arrivalTime = fp->getArrivalTime();
|
time_t arrivalTime = fp->getArrivalTime();
|
||||||
|
|
||||||
time_t ete = tracklength / ((speed * SG_NM_TO_METER) / 3600.0);
|
time_t ete = tracklength / ((speed * SG_NM_TO_METER) / 3600.0);
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
@ -192,7 +193,7 @@ void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
|
||||||
const string& acType,
|
const string& acType,
|
||||||
const string& airline)
|
const string& airline)
|
||||||
{
|
{
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
time_t timeDiff = now-start;
|
time_t timeDiff = now-start;
|
||||||
leg = 1;
|
leg = 1;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
|
||||||
#include <Airports/airport.hxx>
|
#include <Airports/airport.hxx>
|
||||||
#include <Airports/runways.hxx>
|
#include <Airports/runways.hxx>
|
||||||
|
@ -694,7 +695,8 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
|
||||||
double turnDistance = (2 * M_PI * initialTurnRadius) * (side / 360.0);
|
double turnDistance = (2 * M_PI * initialTurnRadius) * (side / 360.0);
|
||||||
time_t remaining =
|
time_t remaining =
|
||||||
(turnDistance + distance) / ((vDescent * SG_NM_TO_METER) / 3600.0);
|
(turnDistance + distance) / ((vDescent * SG_NM_TO_METER) / 3600.0);
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
|
|
||||||
//if (ac->getTrafficRef()->getCallSign() == fgGetString("/ai/track-callsign")) {
|
//if (ac->getTrafficRef()->getCallSign() == fgGetString("/ai/track-callsign")) {
|
||||||
// cerr << " Arrival time estimation: turn angle " << side << ". Turn distance " << turnDistance << ". Linear distance " << distance << ". Time to go " << remaining << endl;
|
// cerr << " Arrival time estimation: turn angle " << side << ". Turn distance " << turnDistance << ". Linear distance " << distance << ". Time to go " << remaining << endl;
|
||||||
// //exit(1);
|
// //exit(1);
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <simgear/scene/util/OsgMath.hxx>
|
#include <simgear/scene/util/OsgMath.hxx>
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
#include <simgear/timing/timestamp.hxx>
|
#include <simgear/timing/timestamp.hxx>
|
||||||
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
|
||||||
#include <Airports/airport.hxx>
|
#include <Airports/airport.hxx>
|
||||||
#include <Airports/dynamics.hxx>
|
#include <Airports/dynamics.hxx>
|
||||||
|
@ -263,7 +264,8 @@ void FGGroundController::updateAircraftInformation(int id, double lat, double lo
|
||||||
} else {
|
} else {
|
||||||
current->setHoldPosition(true);
|
current->setHoldPosition(true);
|
||||||
int state = current->getState();
|
int state = current->getState();
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
|
|
||||||
if ((now - lastTransmission) > 15) {
|
if ((now - lastTransmission) > 15) {
|
||||||
available = true;
|
available = true;
|
||||||
}
|
}
|
||||||
|
@ -467,7 +469,8 @@ void FGGroundController::checkHoldPosition(int id, double lat,
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
|
||||||
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT,
|
SG_LOG(SG_GENERAL, SG_ALERT,
|
||||||
"AI error: Trying to access non-existing aircraft in FGGroundNetwork::checkHoldPosition at " << SG_ORIGIN);
|
"AI error: Trying to access non-existing aircraft in FGGroundNetwork::checkHoldPosition at " << SG_ORIGIN);
|
||||||
|
@ -778,7 +781,8 @@ void FGGroundController::render(bool visible)
|
||||||
FGScenery * local_scenery = globals->get_scenery();
|
FGScenery * local_scenery = globals->get_scenery();
|
||||||
// double elevation_meters = 0.0;
|
// double elevation_meters = 0.0;
|
||||||
// double elevation_feet = 0.0;
|
// double elevation_feet = 0.0;
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
|
|
||||||
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
|
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
|
||||||
//double dx = 0;
|
//double dx = 0;
|
||||||
|
|
||||||
|
@ -951,7 +955,7 @@ string FGGroundController::getName() {
|
||||||
|
|
||||||
void FGGroundController::update(double dt)
|
void FGGroundController::update(double dt)
|
||||||
{
|
{
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
FGGroundNetwork* network = dynamics->getGroundNetwork();
|
FGGroundNetwork* network = dynamics->getGroundNetwork();
|
||||||
network->unblockAllSegments(now);
|
network->unblockAllSegments(now);
|
||||||
int priority = 1;
|
int priority = 1;
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
#include <simgear/scene/material/mat.hxx>
|
#include <simgear/scene/material/mat.hxx>
|
||||||
#include <simgear/scene/util/OsgMath.hxx>
|
#include <simgear/scene/util/OsgMath.hxx>
|
||||||
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
|
|
||||||
#include "trafficcontrol.hxx"
|
#include "trafficcontrol.hxx"
|
||||||
|
@ -132,7 +134,9 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
|
||||||
estimatedArrivalTimes.push_back(newEta);
|
estimatedArrivalTimes.push_back(newEta);
|
||||||
sort(estimatedArrivalTimes.begin(), estimatedArrivalTimes.end());
|
sort(estimatedArrivalTimes.begin(), estimatedArrivalTimes.end());
|
||||||
// do some housekeeping : remove any timestamps that are past
|
// do some housekeeping : remove any timestamps that are past
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
|
||||||
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
|
|
||||||
TimeVectorIterator i = estimatedArrivalTimes.begin();
|
TimeVectorIterator i = estimatedArrivalTimes.begin();
|
||||||
while (i != estimatedArrivalTimes.end()) {
|
while (i != estimatedArrivalTimes.end()) {
|
||||||
if ((*i) < now) {
|
if ((*i) < now) {
|
||||||
|
@ -431,7 +435,7 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net,
|
||||||
|
|
||||||
bool FGTrafficRecord::isActive(int margin) const
|
bool FGTrafficRecord::isActive(int margin) const
|
||||||
{
|
{
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
time_t deptime = aircraft->getTrafficRef()->getDepartureTime();
|
time_t deptime = aircraft->getTrafficRef()->getDepartureTime();
|
||||||
return ((now + margin) > deptime);
|
return ((now + margin) > deptime);
|
||||||
}
|
}
|
||||||
|
@ -1269,7 +1273,8 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
|
||||||
// The user controlled aircraft should have crased here, because it doesn't have a traffic reference.
|
// The user controlled aircraft should have crased here, because it doesn't have a traffic reference.
|
||||||
// NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight.
|
// NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight.
|
||||||
time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime();
|
time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime();
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
|
|
||||||
//cerr << i->getAircraft()->getTrafficRef()->getCallSign()
|
//cerr << i->getAircraft()->getTrafficRef()->getCallSign()
|
||||||
// << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
|
// << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
|
||||||
// << " at parking " << getGateName(i->getAircraft()) << endl;
|
// << " at parking " << getGateName(i->getAircraft()) << endl;
|
||||||
|
@ -1352,7 +1357,8 @@ void FGStartupController::render(bool visible)
|
||||||
|
|
||||||
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
|
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
|
||||||
double dx = 0;
|
double dx = 0;
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
|
|
||||||
for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
|
for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
|
||||||
if (i->isActive(300)) {
|
if (i->isActive(300)) {
|
||||||
// Handle start point
|
// Handle start point
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
#include <simgear/xml/easyxml.hxx>
|
#include <simgear/xml/easyxml.hxx>
|
||||||
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
|
||||||
#include <AIModel/AIFlightPlan.hxx>
|
#include <AIModel/AIFlightPlan.hxx>
|
||||||
#include <AIModel/AIManager.hxx>
|
#include <AIModel/AIManager.hxx>
|
||||||
|
@ -557,7 +558,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDesti
|
||||||
const string &req,
|
const string &req,
|
||||||
time_t min, time_t max)
|
time_t min, time_t max)
|
||||||
{
|
{
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
|
|
||||||
FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("traffic-manager");
|
FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("traffic-manager");
|
||||||
FGScheduledFlightVecIterator fltBegin, fltEnd;
|
FGScheduledFlightVecIterator fltBegin, fltEnd;
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
#include <simgear/timing/sg_time.hxx>
|
||||||
|
|
||||||
#include <simgear/xml/easyxml.hxx>
|
#include <simgear/xml/easyxml.hxx>
|
||||||
#include <simgear/threads/SGThread.hxx>
|
#include <simgear/threads/SGThread.hxx>
|
||||||
|
@ -719,17 +720,19 @@ void FGTrafficManager::update(double dt)
|
||||||
finishInit();
|
finishInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
|
||||||
if (scheduledAircraft.empty()) {
|
if (scheduledAircraft.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGVec3d userCart = globals->get_aircraft_position_cart();
|
SGVec3d userCart = globals->get_aircraft_position_cart();
|
||||||
|
|
||||||
if (currAircraft == scheduledAircraft.end()) {
|
if (currAircraft == scheduledAircraft.end()) {
|
||||||
currAircraft = scheduledAircraft.begin();
|
currAircraft = scheduledAircraft.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t now = globals->get_time_params()->get_cur_time();
|
||||||
|
|
||||||
//cerr << "Processing << " << (*currAircraft)->getRegistration() << " with score " << (*currAircraft)->getScore() << endl;
|
//cerr << "Processing << " << (*currAircraft)->getRegistration() << " with score " << (*currAircraft)->getScore() << endl;
|
||||||
if ((*currAircraft)->update(now, userCart)) {
|
if ((*currAircraft)->update(now, userCart)) {
|
||||||
// schedule is done - process another aircraft in next iteration
|
// schedule is done - process another aircraft in next iteration
|
||||||
|
|
Loading…
Add table
Reference in a new issue