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 {
|
||||
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 ete = tracklength / ((speed * SG_NM_TO_METER) / 3600.0);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <simgear/constants.h>
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
@ -192,7 +193,7 @@ void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
|
|||
const string& acType,
|
||||
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;
|
||||
leg = 1;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <simgear/math/sg_geodesy.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
||||
#include <Airports/airport.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);
|
||||
time_t remaining =
|
||||
(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")) {
|
||||
// cerr << " Arrival time estimation: turn angle " << side << ". Turn distance " << turnDistance << ". Linear distance " << distance << ". Time to go " << remaining << endl;
|
||||
// //exit(1);
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <simgear/scene/util/OsgMath.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <simgear/timing/timestamp.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
||||
#include <Airports/airport.hxx>
|
||||
#include <Airports/dynamics.hxx>
|
||||
|
@ -263,7 +264,8 @@ void FGGroundController::updateAircraftInformation(int id, double lat, double lo
|
|||
} else {
|
||||
current->setHoldPosition(true);
|
||||
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) {
|
||||
available = true;
|
||||
}
|
||||
|
@ -467,7 +469,8 @@ void FGGroundController::checkHoldPosition(int id, double lat,
|
|||
} else {
|
||||
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)) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT,
|
||||
"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();
|
||||
// double elevation_meters = 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++) {
|
||||
//double dx = 0;
|
||||
|
||||
|
@ -951,7 +955,7 @@ string FGGroundController::getName() {
|
|||
|
||||
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();
|
||||
network->unblockAllSegments(now);
|
||||
int priority = 1;
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include <simgear/scene/material/matlib.hxx>
|
||||
#include <simgear/scene/material/mat.hxx>
|
||||
#include <simgear/scene/util/OsgMath.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
||||
#include <Scenery/scenery.hxx>
|
||||
|
||||
#include "trafficcontrol.hxx"
|
||||
|
@ -132,7 +134,9 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
|
|||
estimatedArrivalTimes.push_back(newEta);
|
||||
sort(estimatedArrivalTimes.begin(), estimatedArrivalTimes.end());
|
||||
// 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();
|
||||
while (i != estimatedArrivalTimes.end()) {
|
||||
if ((*i) < now) {
|
||||
|
@ -431,7 +435,7 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net,
|
|||
|
||||
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();
|
||||
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.
|
||||
// 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 now = time(NULL) + fgGetLong("/sim/time/warp");
|
||||
time_t now = globals->get_time_params()->get_cur_time();
|
||||
|
||||
//cerr << i->getAircraft()->getTrafficRef()->getCallSign()
|
||||
// << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
|
||||
// << " at parking " << getGateName(i->getAircraft()) << endl;
|
||||
|
@ -1352,7 +1357,8 @@ void FGStartupController::render(bool visible)
|
|||
|
||||
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
|
||||
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++) {
|
||||
if (i->isActive(300)) {
|
||||
// Handle start point
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/xml/easyxml.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
||||
#include <AIModel/AIFlightPlan.hxx>
|
||||
#include <AIModel/AIManager.hxx>
|
||||
|
@ -557,7 +558,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDesti
|
|||
const string &req,
|
||||
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");
|
||||
FGScheduledFlightVecIterator fltBegin, fltEnd;
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
||||
#include <simgear/xml/easyxml.hxx>
|
||||
#include <simgear/threads/SGThread.hxx>
|
||||
|
@ -719,7 +720,7 @@ void FGTrafficManager::update(double dt)
|
|||
finishInit();
|
||||
}
|
||||
|
||||
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
|
||||
|
||||
if (scheduledAircraft.empty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -730,6 +731,8 @@ void FGTrafficManager::update(double dt)
|
|||
currAircraft = scheduledAircraft.begin();
|
||||
}
|
||||
|
||||
time_t now = globals->get_time_params()->get_cur_time();
|
||||
|
||||
//cerr << "Processing << " << (*currAircraft)->getRegistration() << " with score " << (*currAircraft)->getScore() << endl;
|
||||
if ((*currAircraft)->update(now, userCart)) {
|
||||
// schedule is done - process another aircraft in next iteration
|
||||
|
|
Loading…
Add table
Reference in a new issue