Refactoring - no actual change
This commit is contained in:
parent
6769d7974c
commit
6d1418ff12
2 changed files with 456 additions and 433 deletions
|
@ -265,8 +265,69 @@ void FGTower::Update(double dt) {
|
||||||
|
|
||||||
// sortConficts() !!!
|
// sortConficts() !!!
|
||||||
|
|
||||||
// Do one plane from the hold list
|
|
||||||
if(update_count == 4) {
|
if(update_count == 4) {
|
||||||
|
CheckHoldList(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uggh - HACK - why have we got rwyOccupied - wouldn't simply testing rwyList.size() do?
|
||||||
|
if(rwyList.size()) {
|
||||||
|
rwyOccupied = true;
|
||||||
|
} else {
|
||||||
|
rwyOccupied = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(update_count == 5 && rwyOccupied) {
|
||||||
|
CheckRunwayList(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(update_count == 6) {
|
||||||
|
CheckCircuitList(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(update_count == 7) {
|
||||||
|
CheckApproachList(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - do one plane from the departure list and set departed = false when out of consideration
|
||||||
|
|
||||||
|
//doCommunication();
|
||||||
|
|
||||||
|
if(!separateGround) {
|
||||||
|
// The display stuff might have to get more clever than this when not separate
|
||||||
|
// since the tower and ground might try communicating simultaneously even though
|
||||||
|
// they're mean't to be the same contoller/frequency!!
|
||||||
|
if(display) {
|
||||||
|
ground->SetDisplay();
|
||||||
|
} else {
|
||||||
|
ground->SetNoDisplay();
|
||||||
|
}
|
||||||
|
ground->Update(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
++update_count;
|
||||||
|
// How big should ii get - ie how long should the update cycle interval stretch?
|
||||||
|
if(update_count >= update_count_max) {
|
||||||
|
update_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the base class update for the response time handling.
|
||||||
|
FGATC::Update(dt);
|
||||||
|
|
||||||
|
if(ident == "KEMT") {
|
||||||
|
// For AI debugging convienience - may be removed
|
||||||
|
Point3D user_pos;
|
||||||
|
user_pos.setlon(user_lon_node->getDoubleValue());
|
||||||
|
user_pos.setlat(user_lat_node->getDoubleValue());
|
||||||
|
user_pos.setelev(user_elev_node->getDoubleValue());
|
||||||
|
Point3D user_ortho_pos = ortho.ConvertToLocal(user_pos);
|
||||||
|
fgSetDouble("/AI/user/ortho-x", user_ortho_pos.x());
|
||||||
|
fgSetDouble("/AI/user/ortho-y", user_ortho_pos.y());
|
||||||
|
fgSetDouble("/AI/user/elev", user_elev_node->getDoubleValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do one plane from the hold list
|
||||||
|
void FGTower::CheckHoldList(double dt) {
|
||||||
//cout << "ug\n";
|
//cout << "ug\n";
|
||||||
if(holdList.size()) {
|
if(holdList.size()) {
|
||||||
//cout << "*holdListItr = " << *holdListItr << endl;
|
//cout << "*holdListItr = " << *holdListItr << endl;
|
||||||
|
@ -465,65 +526,8 @@ void FGTower::Update(double dt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uggh - HACK - why have we got rwyOccupied - wouldn't simply testing rwyList.size() do?
|
|
||||||
if(rwyList.size()) {
|
|
||||||
rwyOccupied = true;
|
|
||||||
} else {
|
|
||||||
rwyOccupied = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do the runway list - we'll do the whole runway list since it's important and there'll never be many planes on the rwy at once!!
|
|
||||||
// FIXME - at the moment it looks like we're only doing the first plane from the rwy list.
|
|
||||||
// (However, at the moment there should only be one airplane on the rwy at once, until we
|
|
||||||
// start allowing planes to line up whilst previous arrival clears the rwy.)
|
|
||||||
if(update_count == 5) {
|
|
||||||
if(rwyOccupied) {
|
|
||||||
if(!rwyList.size()) {
|
|
||||||
rwyOccupied = false;
|
|
||||||
} else {
|
|
||||||
rwyListItr = rwyList.begin();
|
|
||||||
TowerPlaneRec* t = *rwyListItr;
|
|
||||||
if(t->isUser) {
|
|
||||||
t->pos.setlon(user_lon_node->getDoubleValue());
|
|
||||||
t->pos.setlat(user_lat_node->getDoubleValue());
|
|
||||||
t->pos.setelev(user_elev_node->getDoubleValue());
|
|
||||||
} else {
|
|
||||||
t->pos = t->planePtr->GetPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
|
|
||||||
}
|
|
||||||
bool on_rwy = OnActiveRunway(t->pos);
|
|
||||||
if(!on_rwy) {
|
|
||||||
if((t->opType == INBOUND) || (t->opType == STRAIGHT_IN)) {
|
|
||||||
rwyList.pop_front();
|
|
||||||
delete t;
|
|
||||||
// TODO - tell it to taxi / contact ground / don't delete it etc!
|
|
||||||
} else if(t->opType == OUTBOUND) {
|
|
||||||
depList.push_back(t);
|
|
||||||
rwyList.pop_front();
|
|
||||||
departed = true;
|
|
||||||
timeSinceLastDeparture = 0.0;
|
|
||||||
} else if(t->opType == CIRCUIT) {
|
|
||||||
circuitList.push_back(t);
|
|
||||||
AddToTrafficList(t);
|
|
||||||
rwyList.pop_front();
|
|
||||||
departed = true;
|
|
||||||
timeSinceLastDeparture = 0.0;
|
|
||||||
} else if(t->opType == TTT_UNKNOWN) {
|
|
||||||
depList.push_back(t);
|
|
||||||
circuitList.push_back(t);
|
|
||||||
AddToTrafficList(t);
|
|
||||||
rwyList.pop_front();
|
|
||||||
departed = true;
|
|
||||||
timeSinceLastDeparture = 0.0; // TODO - we need to take into account that the user might taxi-in when flagged opType UNKNOWN - check speed/altitude etc to make decision as to what user is up to.
|
|
||||||
} else {
|
|
||||||
// HELP - we shouldn't ever get here!!!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// do the ciruit list
|
// do the ciruit list
|
||||||
if(update_count == 6) {
|
void FGTower::CheckCircuitList(double dt) {
|
||||||
// Clear the constraints - we recalculate here.
|
// Clear the constraints - we recalculate here.
|
||||||
base_leg_pos = 0.0;
|
base_leg_pos = 0.0;
|
||||||
downwind_leg_pos = 0.0;
|
downwind_leg_pos = 0.0;
|
||||||
|
@ -692,8 +696,58 @@ void FGTower::Update(double dt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do the runway list - we'll do the whole runway list since it's important and there'll never be many planes on the rwy at once!!
|
||||||
|
// FIXME - at the moment it looks like we're only doing the first plane from the rwy list.
|
||||||
|
// (However, at the moment there should only be one airplane on the rwy at once, until we
|
||||||
|
// start allowing planes to line up whilst previous arrival clears the rwy.)
|
||||||
|
void FGTower::CheckRunwayList(double dt) {
|
||||||
|
if(rwyOccupied) {
|
||||||
|
if(!rwyList.size()) {
|
||||||
|
rwyOccupied = false;
|
||||||
|
} else {
|
||||||
|
rwyListItr = rwyList.begin();
|
||||||
|
TowerPlaneRec* t = *rwyListItr;
|
||||||
|
if(t->isUser) {
|
||||||
|
t->pos.setlon(user_lon_node->getDoubleValue());
|
||||||
|
t->pos.setlat(user_lat_node->getDoubleValue());
|
||||||
|
t->pos.setelev(user_elev_node->getDoubleValue());
|
||||||
|
} else {
|
||||||
|
t->pos = t->planePtr->GetPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
|
||||||
|
}
|
||||||
|
bool on_rwy = OnActiveRunway(t->pos);
|
||||||
|
if(!on_rwy) {
|
||||||
|
if((t->opType == INBOUND) || (t->opType == STRAIGHT_IN)) {
|
||||||
|
rwyList.pop_front();
|
||||||
|
delete t;
|
||||||
|
// TODO - tell it to taxi / contact ground / don't delete it etc!
|
||||||
|
} else if(t->opType == OUTBOUND) {
|
||||||
|
depList.push_back(t);
|
||||||
|
rwyList.pop_front();
|
||||||
|
departed = true;
|
||||||
|
timeSinceLastDeparture = 0.0;
|
||||||
|
} else if(t->opType == CIRCUIT) {
|
||||||
|
circuitList.push_back(t);
|
||||||
|
AddToTrafficList(t);
|
||||||
|
rwyList.pop_front();
|
||||||
|
departed = true;
|
||||||
|
timeSinceLastDeparture = 0.0;
|
||||||
|
} else if(t->opType == TTT_UNKNOWN) {
|
||||||
|
depList.push_back(t);
|
||||||
|
circuitList.push_back(t);
|
||||||
|
AddToTrafficList(t);
|
||||||
|
rwyList.pop_front();
|
||||||
|
departed = true;
|
||||||
|
timeSinceLastDeparture = 0.0; // TODO - we need to take into account that the user might taxi-in when flagged opType UNKNOWN - check speed/altitude etc to make decision as to what user is up to.
|
||||||
|
} else {
|
||||||
|
// HELP - we shouldn't ever get here!!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Do one plane from the approach list
|
// Do one plane from the approach list
|
||||||
if(update_count == 7) {
|
void FGTower::CheckApproachList(double dt) {
|
||||||
if(appList.size()) {
|
if(appList.size()) {
|
||||||
if(appListItr == appList.end()) {
|
if(appListItr == appList.end()) {
|
||||||
appListItr = appList.begin();
|
appListItr = appList.begin();
|
||||||
|
@ -715,45 +769,6 @@ void FGTower::Update(double dt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - do one plane from the departure list and set departed = false when out of consideration
|
|
||||||
|
|
||||||
//doCommunication();
|
|
||||||
|
|
||||||
if(!separateGround) {
|
|
||||||
// The display stuff might have to get more clever than this when not separate
|
|
||||||
// since the tower and ground might try communicating simultaneously even though
|
|
||||||
// they're mean't to be the same contoller/frequency!!
|
|
||||||
if(display) {
|
|
||||||
ground->SetDisplay();
|
|
||||||
} else {
|
|
||||||
ground->SetNoDisplay();
|
|
||||||
}
|
|
||||||
ground->Update(dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
++update_count;
|
|
||||||
// How big should ii get - ie how long should the update cycle interval stretch?
|
|
||||||
if(update_count >= update_count_max) {
|
|
||||||
update_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the base class update for the response time handling.
|
|
||||||
FGATC::Update(dt);
|
|
||||||
|
|
||||||
if(ident == "KEMT") {
|
|
||||||
// For AI debugging convienience - may be removed
|
|
||||||
Point3D user_pos;
|
|
||||||
user_pos.setlon(user_lon_node->getDoubleValue());
|
|
||||||
user_pos.setlat(user_lat_node->getDoubleValue());
|
|
||||||
user_pos.setelev(user_elev_node->getDoubleValue());
|
|
||||||
Point3D user_ortho_pos = ortho.ConvertToLocal(user_pos);
|
|
||||||
fgSetDouble("/AI/user/ortho-x", user_ortho_pos.x());
|
|
||||||
fgSetDouble("/AI/user/ortho-y", user_ortho_pos.y());
|
|
||||||
fgSetDouble("/AI/user/elev", user_elev_node->getDoubleValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Returns true if positions of crosswind/downwind/base leg turns should be constrained by previous traffic
|
// Returns true if positions of crosswind/downwind/base leg turns should be constrained by previous traffic
|
||||||
// plus the constraint position as a rwy orientated orthopos (meters)
|
// plus the constraint position as a rwy orientated orthopos (meters)
|
||||||
bool FGTower::GetCrosswindConstraint(double& cpos) {
|
bool FGTower::GetCrosswindConstraint(double& cpos) {
|
||||||
|
|
|
@ -152,6 +152,14 @@ private:
|
||||||
FGATCMgr* ATCmgr;
|
FGATCMgr* ATCmgr;
|
||||||
// This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
|
// This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
|
||||||
|
|
||||||
|
void CheckHoldList(double dt);
|
||||||
|
|
||||||
|
void CheckCircuitList(double dt);
|
||||||
|
|
||||||
|
void CheckRunwayList(double dt);
|
||||||
|
|
||||||
|
void CheckApproachList(double dt);
|
||||||
|
|
||||||
// Figure out if a given position lies on the active runway
|
// Figure out if a given position lies on the active runway
|
||||||
// Might have to change when we consider more than one active rwy.
|
// Might have to change when we consider more than one active rwy.
|
||||||
bool OnActiveRunway(Point3D pt);
|
bool OnActiveRunway(Point3D pt);
|
||||||
|
|
Loading…
Add table
Reference in a new issue