From 09b87e3ce034b8bdcfd91b8c961c06aa3ae5f080 Mon Sep 17 00:00:00 2001 From: Robin Leroy Date: Sun, 18 Aug 2024 19:03:36 +0200 Subject: [PATCH 1/2] Remove rxHome and txHome from the jobs, use [tr]xIsTracking or [tr]xInAtmosphere as appropriate. --- src/RealAntennasProject/Precompute/Jobs.cs | 17 ++++++------ .../Precompute/Precompute.cs | 26 +++++++++++-------- src/RealAntennasProject/RealAntenna.cs | 4 ++- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/RealAntennasProject/Precompute/Jobs.cs b/src/RealAntennasProject/Precompute/Jobs.cs index 501c998..f60a9c5 100644 --- a/src/RealAntennasProject/Precompute/Jobs.cs +++ b/src/RealAntennasProject/Precompute/Jobs.cs @@ -17,14 +17,14 @@ public struct ExtractDataJob : IJobParallelForDefer [WriteOnly] public NativeArray txFreq; [WriteOnly] public NativeArray txGain; [WriteOnly] public NativeArray txBeamwidth; - [WriteOnly] public NativeArray txHome; + [WriteOnly] public NativeArray txInAtmosphere; [WriteOnly] public NativeArray txPos; [WriteOnly] public NativeArray txDir; [WriteOnly] public NativeArray rxFreq; [WriteOnly] public NativeArray rxGain; [WriteOnly] public NativeArray rxBeamwidth; - [WriteOnly] public NativeArray rxHome; + [WriteOnly] public NativeArray rxInAtmosphere; [WriteOnly] public NativeArray rxTracking; [WriteOnly] public NativeArray rxPos; [WriteOnly] public NativeArray rxDir; @@ -46,14 +46,14 @@ public void Execute(int index) txFreq[index] = tx.freq; txGain[index] = tx.gain; txBeamwidth[index] = tx.beamwidth; - txHome[index] = tx.isHome; + txInAtmosphere[index] = tx.inAtmosphere; txPos[index] = tx.position; txDir[index] = tx.isTracking ? (float3) (rx.position - tx.position) : tx.dir; rxFreq[index] = rx.freq; rxGain[index] = rx.gain; rxBeamwidth[index] = rx.beamwidth; - rxHome[index] = rx.isHome; + txInAtmosphere[index] = rx.inAtmosphere; rxTracking[index] = rx.isTracking; rxPos[index] = rx.position; rxDir[index] = rx.isTracking ? (float3) (tx.position - rx.position) : rx.dir; @@ -61,7 +61,8 @@ public void Execute(int index) } } - // Derive the noise temp of an antenna. Skip homes, since they do not have valid pointing yet. + // Derive the noise temp of an antenna. Skip antennas that are considered + // to track everything at once, since they do not have valid pointing yet. [BurstCompile] public struct PreCalcAntennaNoise : IJobParallelFor { @@ -72,7 +73,7 @@ public struct PreCalcAntennaNoise : IJobParallelFor public void Execute(int index) { AntennaData ant = antennas[index]; - noiseTemp[index] = ant.isHome ? 0 : Precompute.NoiseFromOccluders(ant, occluders); + noiseTemp[index] = ant.isTracking ? 0 : Precompute.NoiseFromOccluders(ant, occluders); } } @@ -98,7 +99,7 @@ public void Execute(int index) public struct CalcAntennaAtmoNoise : IJobParallelForDefer { [ReadOnly] public NativeArray rxPos; - [ReadOnly] public NativeArray rxHome; + [ReadOnly] public NativeArray rxInAtmosphere; [ReadOnly] public NativeArray rxFreq; [ReadOnly] public NativeArray txPos; [ReadOnly] public NativeArray rxSurfaceNormal; @@ -108,7 +109,7 @@ public struct CalcAntennaAtmoNoise : IJobParallelForDefer public void Execute(int index) { float el = MathUtils.ElevationAngle(rxPos[index], rxSurfaceNormal[index], txPos[index]); - atmoNoise[index] = rxHome[index] ? Physics.AtmosphereNoiseTemperature(el, rxFreq[index]) : 0; + atmoNoise[index] = rxInAtmosphere[index] ? Physics.AtmosphereNoiseTemperature(el, rxFreq[index]) : 0; elevation[index] = el; } } diff --git a/src/RealAntennasProject/Precompute/Precompute.cs b/src/RealAntennasProject/Precompute/Precompute.cs index 846c68f..199ff00 100644 --- a/src/RealAntennasProject/Precompute/Precompute.cs +++ b/src/RealAntennasProject/Precompute/Precompute.cs @@ -13,7 +13,7 @@ public struct AntennaData internal float freq; internal float gain; internal float beamwidth; - internal bool isHome; + internal bool inAtmosphere; internal bool isTracking; internal double3 position; internal float3 dir; @@ -76,14 +76,14 @@ internal class Precompute private NativeArray txFreq; private NativeArray txGain; private NativeArray txBeamwidth; - private NativeArray txHome; + private NativeArray txInAtmosphere; private NativeArray txPos; private NativeArray txDir; private NativeArray rxFreq; private NativeArray rxGain; private NativeArray rxBeamwidth; - private NativeArray rxHome; + private NativeArray rxInAtmosphere; private NativeArray rxTracking; private NativeArray rxPos; private NativeArray rxDir; @@ -223,14 +223,14 @@ public void DoThings(List bodies = null, List n txFreq = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); txGain = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); txBeamwidth = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); - txHome = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); + txInAtmosphere = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); txPos = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); txDir = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); rxFreq = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); rxGain = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); rxBeamwidth = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); - rxHome = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); + rxInAtmosphere = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); rxTracking = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); rxPos = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); rxDir = new NativeArray(allAntennaPairs.Length, Allocator.TempJob); @@ -252,8 +252,8 @@ public void DoThings(List bodies = null, List n rxGain = rxGain, txBeamwidth = txBeamwidth, rxBeamwidth = rxBeamwidth, - txHome = txHome, - rxHome = rxHome, + txInAtmosphere = txInAtmosphere, + rxInAtmosphere = rxInAtmosphere, rxTracking = rxTracking, txFreq = txFreq, rxFreq = rxFreq, @@ -344,7 +344,7 @@ public void DoThings(List bodies = null, List n txPos = txPos, rxPos = rxPos, rxFreq = rxFreq, - rxHome = rxHome, + rxInAtmosphere = rxInAtmosphere, rxSurfaceNormal = rxSurfaceNormal, atmoNoise = atmosphereNoise, elevation = antennaElevation, @@ -615,14 +615,14 @@ private void DisposeJobData() txFreq.Dispose(); txGain.Dispose(); txBeamwidth.Dispose(); - txHome.Dispose(); + txInAtmosphere.Dispose(); txPos.Dispose(); txDir.Dispose(); rxFreq.Dispose(); rxGain.Dispose(); rxBeamwidth.Dispose(); - rxHome.Dispose(); + rxInAtmosphere.Dispose(); rxTracking.Dispose(); rxPos.Dispose(); rxDir.Dispose(); @@ -732,7 +732,11 @@ private NativeArray GatherAllAntennas(Dictionary freq = ra.Frequency, gain = ra.Gain, beamwidth = ra.Beamwidth, - isHome = node.isHome, + // TODO(egg): We could also say apply that to a + // ParentVessel deep enough in the atmosphere. + // It might make sense to take the altitude into + // account eventually. + inAtmosphere = node.ParentBody != null, isTracking = ra.IsTracking, AMW = Physics.AntennaMicrowaveTemp(ra), encoder = new Encoder(ra.Encoder), diff --git a/src/RealAntennasProject/RealAntenna.cs b/src/RealAntennasProject/RealAntenna.cs index a5046d3..fe6ed17 100644 --- a/src/RealAntennasProject/RealAntenna.cs +++ b/src/RealAntennasProject/RealAntenna.cs @@ -28,7 +28,7 @@ public class RealAntenna public virtual float AMWTemp { get; set; } public virtual float Beamwidth => Physics.Beamwidth(Gain); - public Antenna.Encoder Encoder => Antenna.Encoder.GetFromTechLevel(TechLevelInfo.Level); + public Antenna.Encoder Encoder => Antenna.Encoder.GetFromTechLevel(TechLevelInfo.Level); public virtual float RequiredCI => Encoder.RequiredEbN0; public ModuleRealAntenna Parent { get; internal set; } @@ -38,6 +38,8 @@ public class RealAntenna public Vector3d PrecisePosition => ParentNode.precisePosition; public Vector3d TransformPosition => ParentNode.position; public virtual AntennaShape Shape => Gain <= Physics.MaxOmniGain ? AntennaShape.Omni : AntennaShape.Dish; + // Whether the antenna is a dish considered to be tracking everything at + // once. This is typically used for ground stations. public bool IsTracking => Shape != AntennaShape.Omni && Target == null; public virtual bool CanTarget => Shape != AntennaShape.Omni && !IsTracking; public Vector3 ToTarget => (CanTarget && Target != null) ? (Vector3) (Target.transform.position - Position) : Vector3.zero; From edcd6884aca07b177ed1c8d0b72d5f8008efb07b Mon Sep 17 00:00:00 2001 From: Robin Leroy Date: Tue, 20 Aug 2024 16:52:46 +0200 Subject: [PATCH 2/2] Fix a bug, add scoping to try to avoid more of those, and show the parents in the debugger. --- .../Network/ConnectionDebugger.cs | 16 +++++-- src/RealAntennasProject/Precompute/Jobs.cs | 42 ++++++++++--------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/RealAntennasProject/Network/ConnectionDebugger.cs b/src/RealAntennasProject/Network/ConnectionDebugger.cs index 4821c0d..e9f7c04 100644 --- a/src/RealAntennasProject/Network/ConnectionDebugger.cs +++ b/src/RealAntennasProject/Network/ConnectionDebugger.cs @@ -2,7 +2,7 @@ using UnityEngine; using Unity.Mathematics; using ClickThroughFix; - +using System.ComponentModel; namespace RealAntennas.Network { @@ -72,7 +72,12 @@ private void GUIDisplay(int windowID) // Display Tx box style.alignment = TextAnchor.UpperRight; GUILayout.BeginVertical("Transmitter", style, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true)); - GUILayout.Label($"Antenna: {data.tx.Name}"); + var txParentNode = data.tx.ParentNode as RACommNode; + string txParentName = + txParentNode?.ParentVessel?.GetDisplayName() ?? + txParentNode?.ParentBody?.GetDisplayName() ?? + "(null)"; + GUILayout.Label($"Antenna: {data.tx.Name} on {txParentName}"); GUILayout.Label($"Power: {data.txPower}dBm"); GUILayout.Label($"Target: {data.tx.Target}"); GUILayout.Label($"Position: {data.txPos.x:F0}, {data.txPos.y:F0}, {data.txPos.z:F0}"); @@ -81,7 +86,12 @@ private void GUIDisplay(int windowID) GUILayout.EndVertical(); // Display Rx box GUILayout.BeginVertical("Receiver", style, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true)); - GUILayout.Label($"Antenna: {data.rx.Name}"); + var rxParentNode = data.rx.ParentNode as RACommNode; + string rxParentName = + rxParentNode?.ParentVessel?.GetDisplayName() ?? + rxParentNode?.ParentBody?.GetDisplayName() ?? + "(null)"; + GUILayout.Label($"Antenna: {data.rx.Name} on {rxParentName}"); GUILayout.Label($"Received Power: {data.rxPower}dBm"); GUILayout.Label($"Target: {data.rx.Target}"); GUILayout.Label($"Position: {data.rxPos.x:F0}, {data.rxPos.y:F0}, {data.rxPos.z:F0}"); diff --git a/src/RealAntennasProject/Precompute/Jobs.cs b/src/RealAntennasProject/Precompute/Jobs.cs index f60a9c5..796ed92 100644 --- a/src/RealAntennasProject/Precompute/Jobs.cs +++ b/src/RealAntennasProject/Precompute/Jobs.cs @@ -37,27 +37,31 @@ public void Execute(int index) { int4 k = pairs[index]; CNInfo rxNode = nodes[k.y]; - AntennaData tx = antennas[k.z]; - AntennaData rx = antennas[k.w]; rxPrecalcNoise[index] = antennaNoise[k.w]; rxSurfaceNormal[index] = rxNode.surfaceNormal; - - txPower[index] = tx.txPower; - txFreq[index] = tx.freq; - txGain[index] = tx.gain; - txBeamwidth[index] = tx.beamwidth; - txInAtmosphere[index] = tx.inAtmosphere; - txPos[index] = tx.position; - txDir[index] = tx.isTracking ? (float3) (rx.position - tx.position) : tx.dir; - - rxFreq[index] = rx.freq; - rxGain[index] = rx.gain; - rxBeamwidth[index] = rx.beamwidth; - txInAtmosphere[index] = rx.inAtmosphere; - rxTracking[index] = rx.isTracking; - rxPos[index] = rx.position; - rxDir[index] = rx.isTracking ? (float3) (tx.position - rx.position) : rx.dir; - rxAMW[index] = rx.AMW; + { + AntennaData tx = antennas[k.z]; + txPower[index] = tx.txPower; + txFreq[index] = tx.freq; + txGain[index] = tx.gain; + txBeamwidth[index] = tx.beamwidth; + txInAtmosphere[index] = tx.inAtmosphere; + txPos[index] = tx.position; + AntennaData rx = antennas[k.w]; + txDir[index] = tx.isTracking ? (float3) (rx.position - tx.position) : tx.dir; + } + { + AntennaData rx = antennas[k.w]; + rxFreq[index] = rx.freq; + rxGain[index] = rx.gain; + rxBeamwidth[index] = rx.beamwidth; + rxInAtmosphere[index] = rx.inAtmosphere; + rxTracking[index] = rx.isTracking; + rxPos[index] = rx.position; + rxAMW[index] = rx.AMW; + AntennaData tx = antennas[k.z]; + rxDir[index] = rx.isTracking ? (float3) (tx.position - rx.position) : rx.dir; + } } }