Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rxHome and txHome from the jobs #42

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/RealAntennasProject/Network/ConnectionDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using UnityEngine;
using Unity.Mathematics;
using ClickThroughFix;

using System.ComponentModel;

namespace RealAntennas.Network
{
Expand Down Expand Up @@ -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}");
Expand All @@ -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}");
Expand Down
55 changes: 30 additions & 25 deletions src/RealAntennasProject/Precompute/Jobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public struct ExtractDataJob : IJobParallelForDefer
[WriteOnly] public NativeArray<float> txFreq;
[WriteOnly] public NativeArray<float> txGain;
[WriteOnly] public NativeArray<float> txBeamwidth;
[WriteOnly] public NativeArray<bool> txHome;
[WriteOnly] public NativeArray<bool> txInAtmosphere;
[WriteOnly] public NativeArray<double3> txPos;
[WriteOnly] public NativeArray<float3> txDir;

[WriteOnly] public NativeArray<float> rxFreq;
[WriteOnly] public NativeArray<float> rxGain;
[WriteOnly] public NativeArray<float> rxBeamwidth;
[WriteOnly] public NativeArray<bool> rxHome;
[WriteOnly] public NativeArray<bool> rxInAtmosphere;
[WriteOnly] public NativeArray<bool> rxTracking;
[WriteOnly] public NativeArray<double3> rxPos;
[WriteOnly] public NativeArray<float3> rxDir;
Expand All @@ -37,31 +37,36 @@ 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;
txHome[index] = tx.isHome;
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;
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;
}
}
}

// 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
{
Expand All @@ -72,7 +77,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);
}
}

Expand All @@ -98,7 +103,7 @@ public void Execute(int index)
public struct CalcAntennaAtmoNoise : IJobParallelForDefer
{
[ReadOnly] public NativeArray<double3> rxPos;
[ReadOnly] public NativeArray<bool> rxHome;
[ReadOnly] public NativeArray<bool> rxInAtmosphere;
[ReadOnly] public NativeArray<float> rxFreq;
[ReadOnly] public NativeArray<double3> txPos;
[ReadOnly] public NativeArray<double3> rxSurfaceNormal;
Expand All @@ -108,7 +113,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;
}
}
Expand Down
26 changes: 15 additions & 11 deletions src/RealAntennasProject/Precompute/Precompute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,14 +76,14 @@ internal class Precompute
private NativeArray<float> txFreq;
private NativeArray<float> txGain;
private NativeArray<float> txBeamwidth;
private NativeArray<bool> txHome;
private NativeArray<bool> txInAtmosphere;
private NativeArray<double3> txPos;
private NativeArray<float3> txDir;

private NativeArray<float> rxFreq;
private NativeArray<float> rxGain;
private NativeArray<float> rxBeamwidth;
private NativeArray<bool> rxHome;
private NativeArray<bool> rxInAtmosphere;
private NativeArray<bool> rxTracking;
private NativeArray<double3> rxPos;
private NativeArray<float3> rxDir;
Expand Down Expand Up @@ -223,14 +223,14 @@ public void DoThings(List<CelestialBody> bodies = null, List<CommNet.CommNode> n
txFreq = new NativeArray<float>(allAntennaPairs.Length, Allocator.TempJob);
txGain = new NativeArray<float>(allAntennaPairs.Length, Allocator.TempJob);
txBeamwidth = new NativeArray<float>(allAntennaPairs.Length, Allocator.TempJob);
txHome = new NativeArray<bool>(allAntennaPairs.Length, Allocator.TempJob);
txInAtmosphere = new NativeArray<bool>(allAntennaPairs.Length, Allocator.TempJob);
txPos = new NativeArray<double3>(allAntennaPairs.Length, Allocator.TempJob);
txDir = new NativeArray<float3>(allAntennaPairs.Length, Allocator.TempJob);

rxFreq = new NativeArray<float>(allAntennaPairs.Length, Allocator.TempJob);
rxGain = new NativeArray<float>(allAntennaPairs.Length, Allocator.TempJob);
rxBeamwidth = new NativeArray<float>(allAntennaPairs.Length, Allocator.TempJob);
rxHome = new NativeArray<bool>(allAntennaPairs.Length, Allocator.TempJob);
rxInAtmosphere = new NativeArray<bool>(allAntennaPairs.Length, Allocator.TempJob);
rxTracking = new NativeArray<bool>(allAntennaPairs.Length, Allocator.TempJob);
rxPos = new NativeArray<double3>(allAntennaPairs.Length, Allocator.TempJob);
rxDir = new NativeArray<float3>(allAntennaPairs.Length, Allocator.TempJob);
Expand All @@ -252,8 +252,8 @@ public void DoThings(List<CelestialBody> bodies = null, List<CommNet.CommNode> n
rxGain = rxGain,
txBeamwidth = txBeamwidth,
rxBeamwidth = rxBeamwidth,
txHome = txHome,
rxHome = rxHome,
txInAtmosphere = txInAtmosphere,
rxInAtmosphere = rxInAtmosphere,
rxTracking = rxTracking,
txFreq = txFreq,
rxFreq = rxFreq,
Expand Down Expand Up @@ -344,7 +344,7 @@ public void DoThings(List<CelestialBody> bodies = null, List<CommNet.CommNode> n
txPos = txPos,
rxPos = rxPos,
rxFreq = rxFreq,
rxHome = rxHome,
rxInAtmosphere = rxInAtmosphere,
rxSurfaceNormal = rxSurfaceNormal,
atmoNoise = atmosphereNoise,
elevation = antennaElevation,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -732,7 +732,11 @@ private NativeArray<AntennaData> GatherAllAntennas(Dictionary<RealAntenna, int>
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),
Expand Down
4 changes: 3 additions & 1 deletion src/RealAntennasProject/RealAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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;
Expand Down
Loading