forked from SpaceStation14-Shenanigans/Monolith
Compare commits
9 Commits
main
...
bliplag-fix-real
| Author | SHA1 | Date | |
|---|---|---|---|
| 0123c844da | |||
| e1ab88c51d | |||
| bba8e08b99 | |||
| 12bc451100 | |||
| c166d47d53 | |||
| 210dca1f89 | |||
| 3763a960c3 | |||
| ccb9f992ba | |||
| 848f671108 |
@@ -1,10 +1,14 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Server.Alert.Commands;
|
||||
using Content.Shared._Mono.Radar;
|
||||
using Content.Shared.Projectiles;
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server._Mono.Radar;
|
||||
|
||||
@@ -19,6 +23,14 @@ public sealed partial class RadarBlipSystem : EntitySystem
|
||||
private readonly List<EntityUid> _tempSourcesCache = new();
|
||||
private readonly List<BlipConfig> _tempPaletteCache = new();
|
||||
private readonly Dictionary<BlipConfig, ushort> _paletteIndex = new();
|
||||
private readonly Dictionary<ICommonSession, List<BlipNetData>> _cachedBliplist = new();
|
||||
private readonly Dictionary<ICommonSession, List<BlipNetData>> _sentBliplist = new();
|
||||
private readonly Dictionary<ICommonSession, List<BlipNetData>> _unionedBliplist = new();
|
||||
private readonly Dictionary<ICommonSession, List<EntityUid>> _sessionUpdateList = new();
|
||||
|
||||
private static readonly float UpdateInterval = 0.5f;
|
||||
private float _lastUpdated = 0;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -27,6 +39,60 @@ public sealed partial class RadarBlipSystem : EntitySystem
|
||||
SubscribeLocalEvent<RadarBlipComponent, ComponentShutdown>(OnBlipShutdown);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
_lastUpdated += frameTime;
|
||||
|
||||
if (UpdateInterval <= _lastUpdated)
|
||||
return;
|
||||
|
||||
_lastUpdated -= UpdateInterval;
|
||||
|
||||
// MAIN Update Method
|
||||
|
||||
// Run once per interval.
|
||||
|
||||
// Get all Sessions requesting blips (Method)
|
||||
|
||||
// For each session, get all entities within RANGE of the target with EQE blip component (Method)
|
||||
|
||||
// Return as Dictionary
|
||||
|
||||
// COMPARE TO OLD CACHE (Method)
|
||||
|
||||
// For static blips, a simple Union of both lists will do.
|
||||
|
||||
// But for moving blips, we must calculate the expected updated position of blips by the velocity.
|
||||
|
||||
// For new blips, send them to the client for client to cache.
|
||||
|
||||
// For old blips, remove them from the Cache and send a removal event.
|
||||
|
||||
// Use dictionary, for each Session, return list. Send indivdiual list per client.
|
||||
|
||||
_sentBliplist.Clear();
|
||||
|
||||
// Calculate new positions for all blips with velocity > 0 with frametime and velocity vector. Replace old positions with new.
|
||||
|
||||
// Compare cached blip list with created bliplist
|
||||
|
||||
// Output those that do not match.
|
||||
|
||||
// For those that have a moving velocity, apply specialcase matching.
|
||||
|
||||
//but then if a blip moves it might not update
|
||||
//need to check if new position is consistent with velocity
|
||||
//If it is, remove from _unionedBliplist.
|
||||
//Send the Union of _sentBlipList and _cachedBlipList to client. "_unionedBliplist"
|
||||
|
||||
// Client should no longer remove blips on their own.
|
||||
|
||||
// Send removal requests to blips that have left the client's range, as determined by blipcomponent.
|
||||
|
||||
}
|
||||
|
||||
private void OnBlipsRequested(RequestBlipsEvent ev, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!TryGetEntity(ev.Radar, out var radarUid)
|
||||
@@ -37,16 +103,24 @@ public sealed partial class RadarBlipSystem : EntitySystem
|
||||
var sourcesEv = new GetRadarSourcesEvent();
|
||||
RaiseLocalEvent(radarUid.Value, ref sourcesEv);
|
||||
|
||||
// Reuse pooled sources list
|
||||
|
||||
_tempSourcesCache.Clear();
|
||||
if (sourcesEv.Sources != null)
|
||||
_tempSourcesCache.AddRange(sourcesEv.Sources);
|
||||
else
|
||||
_tempSourcesCache.Add(radarUid.Value);
|
||||
|
||||
// Ensure that we do not duplicate our values or keys, since we only clear after update() is called.
|
||||
if (_sessionUpdateList.ContainsKey(args.SenderSession))
|
||||
_sessionUpdateList[args.SenderSession] = _tempSourcesCache;
|
||||
else
|
||||
_sessionUpdateList.Add(args.SenderSession, _tempSourcesCache);
|
||||
|
||||
AssembleBlipsReport((EntityUid)radarUid, _tempSourcesCache, radar);
|
||||
AssembleHitscanReport((EntityUid)radarUid, _tempSourcesCache, radar);
|
||||
|
||||
_sentBliplist.Add(args.SenderSession, _tempBlipsCache);
|
||||
|
||||
// Combine the blips and hitscan lines
|
||||
var giveEv = new GiveBlipsEvent(_tempPaletteCache, _tempBlipsCache, _tempHitscansCache);
|
||||
RaiseNetworkEvent(giveEv, args.SenderSession);
|
||||
@@ -167,7 +241,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));
|
||||
|
||||
Reference in New Issue
Block a user