Skip to content

Commit

Permalink
refactor: serialise traffic data for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
2hwk authored and aguther committed Feb 12, 2022
1 parent 3a268fd commit bea612d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/instruments/src/ND/elements/Traffic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const Traffic: FC<TcasProps> = ({ mapParams, mode }) => {
const x: number = 361.5;
const y: number = (mode === Mode.ARC) ? 606.5 : 368;

useCoherentEvent('A32NX_TCAS_TRAFFIC', (airTraffic: NdTraffic[]) => {
useCoherentEvent('A32NX_TCAS_TRAFFIC', (airTrafficString: string) => {
const airTraffic: NdTraffic[] = JSON.parse(airTrafficString);
displayTraffic.forEach((traffic: NdTraffic) => traffic.alive = false);
if (airTraffic) {
airTraffic.forEach((tf: NdTraffic) => {
Expand Down Expand Up @@ -136,13 +137,13 @@ export const Traffic: FC<TcasProps> = ({ mapParams, mode }) => {
{'DMOD: '}
</tspan>
<tspan fill="#e38c56">
{dmodTa}
{dmodTa.toFixed(3)}
</tspan>
<tspan fill="#ffffff">
{' | '}
</tspan>
<tspan fill="#ff0000">
{dmodRa}
{dmodRa.toFixed(3)}
</tspan>
<tspan x={290} dy={15} fill="#ffffff">
{'TAU THR: '}
Expand Down Expand Up @@ -352,4 +353,4 @@ const TrafficIndicatorDebug: FC<TrafficPropDebug> = memo(({ x, y, relativeAlt, v
</Layer>
</>
);
});
});
7 changes: 4 additions & 3 deletions src/tcas/src/components/TcasComputer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Inhibit, Limits,
} from '../lib/TcasConstants';
import { TcasSoundManager } from './TcasSoundManager';
import stringify from 'safe-stable-stringify';

export class NDTcasTraffic {
ID: string;
Expand Down Expand Up @@ -1026,7 +1027,7 @@ export class TcasComputer implements TcasComponent {
}
});

this.sendListener.triggerToAllSubscribers('A32NX_TCAS_TRAFFIC', this.sendAirTraffic);
this.sendListener.triggerToAllSubscribers('A32NX_TCAS_TRAFFIC', stringify(this.sendAirTraffic));
}

update(_deltaTime: number): void {
Expand All @@ -1042,7 +1043,7 @@ export class TcasComputer implements TcasComponent {
if (this.tcasMode.getVar() === TcasMode.STBY) {
if (this.sendAirTraffic.length !== 0) {
this.sendAirTraffic.length = 0;
this.sendListener.triggerToAllSubscribers('A32NX_TCAS_TRAFFIC', this.sendAirTraffic);
this.sendListener.triggerToAllSubscribers('A32NX_TCAS_TRAFFIC', stringify(this.sendAirTraffic));
}
return;
}
Expand All @@ -1052,4 +1053,4 @@ export class TcasComputer implements TcasComponent {
this.updateRa(deltaTime);
this.emitDisplay();
}
}
}

0 comments on commit bea612d

Please sign in to comment.