Skip to content

Commit

Permalink
bugfix/1395 - Add _targetHeading and _targetGroundTrack
Browse files Browse the repository at this point in the history
  • Loading branch information
erikquinn committed Jul 20, 2019
1 parent 5858b7e commit 68c8b9e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
46 changes: 36 additions & 10 deletions src/assets/scripts/client/aircraft/AircraftModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,14 @@ export default class AircraftModel {
speed: 0
};

// TODO: Move all target properties here in order to utilize getters/setters
// this._targetAltitude = 0;
// this._targetAltitudeExpedite = false;
this._targetHeading = null;
this._targetGroundTrack = null;
// this._targetTurnDirection = null;
// this._targetIndicatedAirspeed = 0;

/**
* @for AircraftModel
* @property model
Expand Down Expand Up @@ -528,6 +536,24 @@ export default class AircraftModel {
}
}

get targetHeading() {
return this._targetHeading;
}

set targetHeading(heading) {
this._targetHeading = heading;
this._targetGroundTrack = null;
}

get targetGroundTrack() {
return this._targetGroundTrack;
}

set targetGroundTrack(groundTrack) {
this._targetGroundTrack = groundTrack;
this._targetHeading = null;
}

/**
* @for AircraftModel
* @property callsign
Expand Down Expand Up @@ -616,7 +642,7 @@ export default class AircraftModel {
this.destination = _get(data, 'destination', this.destination);

this.target.altitude = this.altitude;
this.target.heading = this.heading;
this.targetHeading = this.heading;
this.target.speed = this.speed;

// This assumes and arrival spawns outside the airspace
Expand Down Expand Up @@ -1332,7 +1358,7 @@ export default class AircraftModel {
updateTarget() {
this.target.expedite = _defaultTo(this.fms.currentWaypoint.expedite, false);
this.target.altitude = _defaultTo(this._calculateTargetedAltitude(), this.target.altitude);
this.target.heading = _defaultTo(this._calculateTargetedHeading(), this.target.heading);
this.targetHeading = _defaultTo(this._calculateTargetedHeading(), this.targetHeading);
this.target.speed = _defaultTo(this._calculateTargetedSpeed(), this.target.speed);

// TODO: this method may not be needed but could be leveraged for housekeeping if deemed appropriate
Expand All @@ -1349,7 +1375,7 @@ export default class AircraftModel {
// TODO: Is this needed?
// this.target.altitude = this.altitude;
// this.target.expedite = false;
// this.target.heading = this.heading;
// this.targetHeading = this.heading;
// this.target.speed = 0;

break;
Expand All @@ -1358,7 +1384,7 @@ export default class AircraftModel {
// TODO: Is this needed?
// this.target.altitude = this.altitude;
// this.target.expedite = false;
// this.target.heading = this.heading;
// this.targetHeading = this.heading;
// this.target.speed = 0;

break;
Expand All @@ -1367,7 +1393,7 @@ export default class AircraftModel {
// TODO: Is this needed?
// this.target.altitude = this.altitude;
// this.target.expedite = false;
// this.target.heading = this.heading;
// this.targetHeading = this.heading;
// this.target.speed = 0;

break;
Expand All @@ -1380,7 +1406,7 @@ export default class AircraftModel {
}

this.target.expedite = false;
this.target.heading = this.heading;
this.targetHeading = this.heading;
this.target.speed = this.model.speed.min;

if (this.mcp.heading === INVALID_NUMBER) {
Expand Down Expand Up @@ -2077,7 +2103,7 @@ export default class AircraftModel {

if (distanceOnFinal_nm > 0) {
const bearingFromAircaftToRunway = this.positionModel.bearingToPosition(runwayModel.positionModel);

return bearingFromAircaftToRunway;
}

Expand Down Expand Up @@ -2252,19 +2278,19 @@ export default class AircraftModel {
* @method updateAircraftTurnPhysics
*/
updateAircraftTurnPhysics() {
if (this.isOnGround() || this.heading === this.target.heading) {
if (this.isOnGround() || this.heading === this.targetHeading) {
this.target.turn = null;

return;
}

const secondsElapsed = TimeKeeper.getDeltaTimeForGameStateAndTimewarp();
const angle_diff = angle_offset(this.target.heading, this.heading);
const angle_diff = angle_offset(this.targetHeading, this.heading);
const angle_change = PERFORMANCE.TURN_RATE * secondsElapsed;

// TODO: clean this up if possible, there is a lot of branching logic here
if (abs(angle_diff) <= angle_change) {
this.heading = this.target.heading;
this.heading = this.targetHeading;
} else if (this.target.turn) {
if (this.target.turn === 'left') {
this.heading = radians_normalize(this.heading - angle_change);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class ModeController {
/**
* The current headingeMode
*
* This mode informs what value to use for `aircraft.target.headinge`
* This mode informs what value to use for `aircraft.targetHeading`
*
*
* @property headingMode
Expand Down
2 changes: 1 addition & 1 deletion src/assets/scripts/client/math/flightMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function calculateTurnInitiationDistance(aircraft, currentWaypointPositio
// use the target heading instead of the actual heading to take into account
// that we might be already turning and there might be no need to initiate
// a turn at the moment. see #935
let targetHeading = aircraft.target.heading;
let { targetHeading } = aircraft;

if (targetHeading < 0) {
targetHeading += tau();
Expand Down

0 comments on commit 68c8b9e

Please sign in to comment.