Compare commits

...

7 Commits

Author SHA1 Message Date
Redrover1760 eebcb303f0 and better 2026-05-07 21:12:27 -04:00
Redrover1760 2ccf6d95b6 makes it even better 2026-05-07 21:12:16 -04:00
Redrover1760 1b953cf4cb ide said so 2026-05-07 21:10:20 -04:00
Redrover1760 9ddc145cc1 aaa 2026-05-07 18:21:30 -04:00
Redrover1760 8e59b16718 throw on bad usage 2026-05-07 17:25:18 -04:00
Redrover1760 bbaeab61b5 blip optimizations round 2 2026-05-07 17:18:49 -04:00
Redrover1760 97e11f66d1 next 2026-05-07 16:42:14 -04:00
3 changed files with 59 additions and 36 deletions
+10 -3
View File
@@ -17,6 +17,7 @@ public sealed partial class RadarBlipsSystem : EntitySystem
private static readonly TimeSpan RequestThrottle = TimeSpan.FromMilliseconds(500);
private TimeSpan _lastUpdatedTime;
private static readonly List<HitscanNetData> EmptyHitscans = new();
private List<BlipNetData> _blips = new();
private List<HitscanNetData> _hitscans = new();
private List<BlipConfig> _configPalette = new();
@@ -41,8 +42,14 @@ public sealed partial class RadarBlipsSystem : EntitySystem
private void RemoveBlip(BlipRemovalEvent args)
{
var blipid = _blips.FirstOrDefault(x => x.Uid == args.NetBlipUid);
_blips.Remove(blipid);
for (var i = 0; i < _blips.Count; i++)
{
if (_blips[i].Uid == args.NetBlipUid)
{
_blips.RemoveAt(i);
return;
}
}
}
public void RequestBlips(EntityUid console)
@@ -107,7 +114,7 @@ public sealed partial class RadarBlipsSystem : EntitySystem
public List<HitscanNetData> GetHitscanLines()
{
if (_timing.CurTime.TotalSeconds - _lastUpdatedTime.TotalSeconds > BlipStaleSeconds)
return new();
return EmptyHitscans;
return _hitscans;
}
+13 -19
View File
@@ -18,13 +18,15 @@ public sealed partial class RadarBlipSystem : EntitySystem
private readonly List<HitscanNetData> _tempHitscansCache = new();
private readonly List<EntityUid> _tempSourcesCache = new();
private readonly List<BlipConfig> _tempPaletteCache = new();
private readonly Dictionary<BlipConfig, ushort> _paletteIndex = new();
private EntityQuery<PhysicsComponent> _physicsQuery;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RequestBlipsEvent>(OnBlipsRequested);
SubscribeLocalEvent<RadarBlipComponent, ComponentShutdown>(OnBlipShutdown);
_physicsQuery = GetEntityQuery<PhysicsComponent>();
}
private void OnBlipsRequested(RequestBlipsEvent ev, EntitySessionEventArgs args)
@@ -55,7 +57,6 @@ public sealed partial class RadarBlipSystem : EntitySystem
_tempHitscansCache.Clear();
_tempSourcesCache.Clear();
_tempPaletteCache.Clear();
_paletteIndex.Clear();
}
private void OnBlipShutdown(EntityUid blipUid, RadarBlipComponent component, ComponentShutdown args)
@@ -65,11 +66,8 @@ public sealed partial class RadarBlipSystem : EntitySystem
RaiseNetworkEvent(removalEv);
}
private void AssembleBlipsReport(EntityUid uid, List<EntityUid> sources, RadarConsoleComponent? component = null)
private void AssembleBlipsReport(EntityUid uid, List<EntityUid> sources, RadarConsoleComponent component)
{
if (!Resolve(uid, ref component))
return;
var radarXform = Transform(uid);
var radarGrid = radarXform.GridUid;
var radarMapId = radarXform.MapID;
@@ -107,7 +105,7 @@ public sealed partial class RadarBlipSystem : EntitySystem
if (blipGrid != null)
{
var gridXform = Transform(blipGrid.Value);
if (TryComp<PhysicsComponent>(blipGrid.Value, out var gridBody)) // prevent log spam
if (_physicsQuery.TryComp(blipGrid.Value, out var gridBody)) // prevent log spam
blipVelocity -= _physics.GetLinearVelocity(blipGrid.Value, coord.Position, gridBody);
// it's local-frame velocity so rotate it too
blipVelocity = (-gridXform.LocalRotation).RotateVec(blipVelocity);
@@ -135,31 +133,27 @@ public sealed partial class RadarBlipSystem : EntitySystem
/// </summary>
private ushort GetOrAddConfig(BlipConfig config)
{
if (_paletteIndex.TryGetValue(config, out var index))
return index;
for (var i = 0; i < _tempPaletteCache.Count; i++)
{
if (_tempPaletteCache[i] == config)
return (ushort)i;
}
if (_tempPaletteCache.Count >= ushort.MaxValue)
{
Log.Error($"Blip config count overflow! Reached max {ushort.MaxValue}, but trying to add more.");
return 0;
}
index = (ushort)_tempPaletteCache.Count;
var index = (ushort)_tempPaletteCache.Count;
_tempPaletteCache.Add(config);
_paletteIndex[config] = index;
return index;
}
/// <summary>
/// Assembles trajectory information for hitscan projectiles to be displayed on radar
/// </summary>
private void AssembleHitscanReport(EntityUid uid, List<EntityUid> sources, RadarConsoleComponent? component = null)
private void AssembleHitscanReport(EntityUid uid, List<EntityUid> sources, RadarConsoleComponent component)
{
if (!Resolve(uid, ref component))
return;
var radarXform = Transform(uid);
var hitscanQuery = EntityQueryEnumerator<HitscanRadarComponent>();
while (hitscanQuery.MoveNext(out var hitscanUid, out var hitscan))
@@ -167,7 +161,7 @@ public sealed partial class RadarBlipSystem : EntitySystem
if (!hitscan.Enabled)
continue;
if (!NearAnySources(hitscan.StartPosition, sources, component.MaxRange) && NearAnySources(hitscan.EndPosition, sources, component.MaxRange))
if (!NearAnySources(hitscan.StartPosition, sources, component.MaxRange) && !NearAnySources(hitscan.EndPosition, sources, component.MaxRange))
continue;
_tempHitscansCache.Add(new(hitscan.StartPosition, hitscan.EndPosition, hitscan.LineThickness, hitscan.RadarColor));
+36 -14
View File
@@ -1,5 +1,6 @@
using System.Linq;
using System.Numerics;
using System.Xml;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
@@ -49,24 +50,15 @@ public sealed class GiveBlipsEvent : EntityEventArgs
}
[Serializable, NetSerializable]
public sealed class RequestBlipsEvent : EntityEventArgs
public sealed class RequestBlipsEvent(NetEntity radar) : EntityEventArgs
{
public NetEntity Radar;
public RequestBlipsEvent(NetEntity radar)
{
Radar = radar;
}
public readonly NetEntity Radar = radar;
}
[Serializable, NetSerializable]
public sealed class BlipRemovalEvent : EntityEventArgs
public sealed class BlipRemovalEvent(NetEntity netBlipUid) : EntityEventArgs
{
public NetEntity NetBlipUid { get; set; }
public BlipRemovalEvent(NetEntity netBlipUid)
{
NetBlipUid = netBlipUid;
}
public readonly NetEntity NetBlipUid = netBlipUid;
}
[Serializable, NetSerializable]
@@ -78,13 +70,14 @@ public record struct BlipNetData
Angle Rotation,
ushort ConfigIndex,
ushort? OnGridConfigIndex
);
[Serializable, NetSerializable]
public record struct HitscanNetData(Vector2 Start, Vector2 End, float Thickness, Color Color);
[Serializable, NetSerializable, DataDefinition]
public partial record struct BlipConfig
public partial struct BlipConfig : IEquatable<BlipConfig>
{
[DataField]
public Box2 Bounds = new Box2(-0.5f, -0.5f, 0.5f, 0.5f);
@@ -102,4 +95,33 @@ public partial record struct BlipConfig
public bool Rotate = false;
public BlipConfig() { }
public readonly override bool Equals(object? obj)
{
return obj is BlipConfig other && Equals(other);
}
public readonly bool Equals(BlipConfig other)
{
return Shape == other.Shape
&& RespectZoom == other.RespectZoom
&& Rotate == other.Rotate
&& Color == other.Color
&& Bounds == other.Bounds;
}
public override readonly int GetHashCode()
{
throw new NotSupportedException("BlipConfig is not supported with GetHashCode().");
}
public static bool operator ==(BlipConfig left, BlipConfig right)
{
return left.Equals(right);
}
public static bool operator !=(BlipConfig left, BlipConfig right)
{
return !(left == right);
}
}