Navmap rework (#26713)
* Optimized the drawing of lines and tracked entities * Optimized nav map updating and added thin wall support * Added support for thin doors * Removed floor tile seams, more line drawing optimizations * Fixed split grids not updating correctly * Cleaned up NavMapControl code * Fix nav map header * Converted nav map updates from system network messages to delta-states * Addressed review comments * Fixed timing issue where NavMapSystem would update before AirtightSystem did
This commit is contained in:
@@ -1,36 +1,33 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Server.Warps;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Localizations;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Pinpointer;
|
||||
using Content.Shared.Tag;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Server.Pinpointer;
|
||||
|
||||
/// <summary>
|
||||
/// Handles data to be used for in-grid map displays.
|
||||
/// </summary>
|
||||
public sealed class NavMapSystem : SharedNavMapSystem
|
||||
public sealed partial class NavMapSystem : SharedNavMapSystem
|
||||
{
|
||||
[Dependency] private readonly IAdminLogManager _adminLog = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly TagSystem _tags = default!;
|
||||
[Dependency] private readonly MapSystem _map = default!;
|
||||
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
private EntityQuery<TagComponent> _tagQuery;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public const float CloseDistance = 15f;
|
||||
public const float FarDistance = 30f;
|
||||
@@ -39,153 +36,34 @@ public sealed class NavMapSystem : SharedNavMapSystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
_tagQuery = GetEntityQuery<TagComponent>();
|
||||
|
||||
SubscribeLocalEvent<AnchorStateChangedEvent>(OnAnchorChange);
|
||||
SubscribeLocalEvent<ReAnchorEvent>(OnReAnchor);
|
||||
// Initialization events
|
||||
SubscribeLocalEvent<StationGridAddedEvent>(OnStationInit);
|
||||
SubscribeLocalEvent<NavMapComponent, ComponentStartup>(OnNavMapStartup);
|
||||
SubscribeLocalEvent<NavMapComponent, ComponentGetState>(OnGetState);
|
||||
|
||||
// Grid change events
|
||||
SubscribeLocalEvent<GridSplitEvent>(OnNavMapSplit);
|
||||
SubscribeLocalEvent<TileChangedEvent>(OnTileChanged);
|
||||
|
||||
// Airtight structure change event
|
||||
SubscribeLocalEvent<AirtightChanged>(OnAirtightChanged);
|
||||
|
||||
// Beacon events
|
||||
SubscribeLocalEvent<NavMapBeaconComponent, MapInitEvent>(OnNavMapBeaconMapInit);
|
||||
SubscribeLocalEvent<NavMapBeaconComponent, ComponentStartup>(OnNavMapBeaconStartup);
|
||||
SubscribeLocalEvent<NavMapBeaconComponent, AnchorStateChangedEvent>(OnNavMapBeaconAnchor);
|
||||
|
||||
SubscribeLocalEvent<NavMapDoorComponent, ComponentStartup>(OnNavMapDoorStartup);
|
||||
SubscribeLocalEvent<NavMapDoorComponent, AnchorStateChangedEvent>(OnNavMapDoorAnchor);
|
||||
|
||||
SubscribeLocalEvent<ConfigurableNavMapBeaconComponent, NavMapBeaconConfigureBuiMessage>(OnConfigureMessage);
|
||||
SubscribeLocalEvent<ConfigurableNavMapBeaconComponent, MapInitEvent>(OnConfigurableMapInit);
|
||||
SubscribeLocalEvent<ConfigurableNavMapBeaconComponent, ExaminedEvent>(OnConfigurableExamined);
|
||||
}
|
||||
|
||||
#region: Initialization event handling
|
||||
private void OnStationInit(StationGridAddedEvent ev)
|
||||
{
|
||||
var comp = EnsureComp<NavMapComponent>(ev.GridId);
|
||||
RefreshGrid(ev.GridId, comp, Comp<MapGridComponent>(ev.GridId));
|
||||
}
|
||||
|
||||
private void OnNavMapBeaconMapInit(EntityUid uid, NavMapBeaconComponent component, MapInitEvent args)
|
||||
{
|
||||
if (component.DefaultText == null || component.Text != null)
|
||||
return;
|
||||
#endregion
|
||||
|
||||
component.Text = Loc.GetString(component.DefaultText);
|
||||
Dirty(uid, component);
|
||||
RefreshNavGrid(uid);
|
||||
}
|
||||
|
||||
private void OnNavMapBeaconStartup(EntityUid uid, NavMapBeaconComponent component, ComponentStartup args)
|
||||
{
|
||||
RefreshNavGrid(uid);
|
||||
}
|
||||
|
||||
private void OnNavMapBeaconAnchor(EntityUid uid, NavMapBeaconComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
UpdateBeaconEnabledVisuals((uid, component));
|
||||
RefreshNavGrid(uid);
|
||||
}
|
||||
|
||||
private void OnNavMapDoorStartup(Entity<NavMapDoorComponent> ent, ref ComponentStartup args)
|
||||
{
|
||||
RefreshNavGrid(ent);
|
||||
}
|
||||
|
||||
private void OnNavMapDoorAnchor(Entity<NavMapDoorComponent> ent, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
RefreshNavGrid(ent);
|
||||
}
|
||||
|
||||
private void OnConfigureMessage(Entity<ConfigurableNavMapBeaconComponent> ent, ref NavMapBeaconConfigureBuiMessage args)
|
||||
{
|
||||
if (args.Session.AttachedEntity is not { } user)
|
||||
return;
|
||||
|
||||
if (!TryComp<NavMapBeaconComponent>(ent, out var navMap))
|
||||
return;
|
||||
|
||||
if (navMap.Text == args.Text &&
|
||||
navMap.Color == args.Color &&
|
||||
navMap.Enabled == args.Enabled)
|
||||
return;
|
||||
|
||||
_adminLog.Add(LogType.Action, LogImpact.Medium,
|
||||
$"{ToPrettyString(user):player} configured NavMapBeacon \'{ToPrettyString(ent):entity}\' with text \'{args.Text}\', color {args.Color.ToHexNoAlpha()}, and {(args.Enabled ? "enabled" : "disabled")} it.");
|
||||
|
||||
if (TryComp<WarpPointComponent>(ent, out var warpPoint))
|
||||
{
|
||||
warpPoint.Location = args.Text;
|
||||
}
|
||||
|
||||
navMap.Text = args.Text;
|
||||
navMap.Color = args.Color;
|
||||
navMap.Enabled = args.Enabled;
|
||||
UpdateBeaconEnabledVisuals((ent, navMap));
|
||||
Dirty(ent, navMap);
|
||||
RefreshNavGrid(ent);
|
||||
}
|
||||
|
||||
private void OnConfigurableMapInit(Entity<ConfigurableNavMapBeaconComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
if (!TryComp<NavMapBeaconComponent>(ent, out var navMap))
|
||||
return;
|
||||
|
||||
// We set this on mapinit just in case the text was edited via VV or something.
|
||||
if (TryComp<WarpPointComponent>(ent, out var warpPoint))
|
||||
{
|
||||
warpPoint.Location = navMap.Text;
|
||||
}
|
||||
|
||||
UpdateBeaconEnabledVisuals((ent, navMap));
|
||||
}
|
||||
|
||||
private void OnConfigurableExamined(Entity<ConfigurableNavMapBeaconComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange || !TryComp<NavMapBeaconComponent>(ent, out var navMap))
|
||||
return;
|
||||
|
||||
args.PushMarkup(Loc.GetString("nav-beacon-examine-text",
|
||||
("enabled", navMap.Enabled),
|
||||
("color", navMap.Color.ToHexNoAlpha()),
|
||||
("label", navMap.Text ?? string.Empty)));
|
||||
}
|
||||
|
||||
private void UpdateBeaconEnabledVisuals(Entity<NavMapBeaconComponent> ent)
|
||||
{
|
||||
_appearance.SetData(ent, NavMapBeaconVisuals.Enabled, ent.Comp.Enabled && Transform(ent).Anchored);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the grid for the corresponding beacon.
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
private void RefreshNavGrid(EntityUid uid)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
|
||||
if (!TryComp<NavMapComponent>(xform.GridUid, out var navMap))
|
||||
return;
|
||||
|
||||
Dirty(xform.GridUid.Value, navMap);
|
||||
}
|
||||
|
||||
private bool CanBeacon(EntityUid uid, TransformComponent? xform = null)
|
||||
{
|
||||
if (!Resolve(uid, ref xform))
|
||||
return false;
|
||||
|
||||
return xform.GridUid != null && xform.Anchored;
|
||||
}
|
||||
|
||||
private void OnNavMapStartup(EntityUid uid, NavMapComponent component, ComponentStartup args)
|
||||
{
|
||||
if (!TryComp<MapGridComponent>(uid, out var grid))
|
||||
return;
|
||||
|
||||
RefreshGrid(uid, component, grid);
|
||||
}
|
||||
#region: Grid change event handling
|
||||
|
||||
private void OnNavMapSplit(ref GridSplitEvent args)
|
||||
{
|
||||
@@ -203,180 +81,258 @@ public sealed class NavMapSystem : SharedNavMapSystem
|
||||
RefreshGrid(args.Grid, comp, gridQuery.GetComponent(args.Grid));
|
||||
}
|
||||
|
||||
private void RefreshGrid(EntityUid uid, NavMapComponent component, MapGridComponent grid)
|
||||
private void OnTileChanged(ref TileChangedEvent ev)
|
||||
{
|
||||
component.Chunks.Clear();
|
||||
|
||||
var tiles = grid.GetAllTilesEnumerator();
|
||||
|
||||
while (tiles.MoveNext(out var tile))
|
||||
{
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile.Value.GridIndices, ChunkSize);
|
||||
|
||||
if (!component.Chunks.TryGetValue(chunkOrigin, out var chunk))
|
||||
{
|
||||
chunk = new NavMapChunk(chunkOrigin);
|
||||
component.Chunks[chunkOrigin] = chunk;
|
||||
}
|
||||
|
||||
RefreshTile(uid, grid, component, chunk, tile.Value.GridIndices);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, NavMapComponent component, ref ComponentGetState args)
|
||||
{
|
||||
if (!TryComp<MapGridComponent>(uid, out var mapGrid))
|
||||
if (!TryComp<NavMapComponent>(ev.NewTile.GridUid, out var navMap))
|
||||
return;
|
||||
|
||||
var data = new Dictionary<Vector2i, int>(component.Chunks.Count);
|
||||
foreach (var (index, chunk) in component.Chunks)
|
||||
{
|
||||
data.Add(index, chunk.TileData);
|
||||
}
|
||||
|
||||
var beaconQuery = AllEntityQuery<NavMapBeaconComponent, TransformComponent>();
|
||||
var beacons = new List<NavMapBeacon>();
|
||||
|
||||
while (beaconQuery.MoveNext(out var beaconUid, out var beacon, out var xform))
|
||||
{
|
||||
if (!beacon.Enabled || xform.GridUid != uid || !CanBeacon(beaconUid, xform))
|
||||
continue;
|
||||
|
||||
// TODO: Make warp points use metadata name instead.
|
||||
string? name = beacon.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
if (TryComp<WarpPointComponent>(beaconUid, out var warpPoint) && warpPoint.Location != null)
|
||||
{
|
||||
name = warpPoint.Location;
|
||||
}
|
||||
else
|
||||
{
|
||||
name = MetaData(beaconUid).EntityName;
|
||||
}
|
||||
}
|
||||
|
||||
beacons.Add(new NavMapBeacon(beacon.Color, name, xform.LocalPosition));
|
||||
}
|
||||
|
||||
var airlockQuery = EntityQueryEnumerator<NavMapDoorComponent, TransformComponent>();
|
||||
var airlocks = new List<NavMapAirlock>();
|
||||
while (airlockQuery.MoveNext(out _, out _, out var xform))
|
||||
{
|
||||
if (xform.GridUid != uid || !xform.Anchored)
|
||||
continue;
|
||||
|
||||
var pos = _map.TileIndicesFor(uid, mapGrid, xform.Coordinates);
|
||||
var enumerator = _map.GetAnchoredEntitiesEnumerator(uid, mapGrid, pos);
|
||||
|
||||
var wallPresent = false;
|
||||
while (enumerator.MoveNext(out var ent))
|
||||
{
|
||||
if (!_physicsQuery.TryGetComponent(ent, out var body) ||
|
||||
!body.CanCollide ||
|
||||
!body.Hard ||
|
||||
body.BodyType != BodyType.Static ||
|
||||
!_tags.HasTag(ent.Value, "Wall", _tagQuery) &&
|
||||
!_tags.HasTag(ent.Value, "Window", _tagQuery))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
wallPresent = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (wallPresent)
|
||||
continue;
|
||||
|
||||
airlocks.Add(new NavMapAirlock(xform.LocalPosition));
|
||||
}
|
||||
|
||||
// TODO: Diffs
|
||||
args.State = new NavMapComponentState()
|
||||
{
|
||||
TileData = data,
|
||||
Beacons = beacons,
|
||||
Airlocks = airlocks
|
||||
};
|
||||
}
|
||||
|
||||
private void OnReAnchor(ref ReAnchorEvent ev)
|
||||
{
|
||||
if (TryComp<MapGridComponent>(ev.OldGrid, out var oldGrid) &&
|
||||
TryComp<NavMapComponent>(ev.OldGrid, out var navMap))
|
||||
{
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(ev.TilePos, ChunkSize);
|
||||
|
||||
if (navMap.Chunks.TryGetValue(chunkOrigin, out var chunk))
|
||||
{
|
||||
RefreshTile(ev.OldGrid, oldGrid, navMap, chunk, ev.TilePos);
|
||||
}
|
||||
}
|
||||
|
||||
HandleAnchor(ev.Xform);
|
||||
}
|
||||
|
||||
private void OnAnchorChange(ref AnchorStateChangedEvent ev)
|
||||
{
|
||||
HandleAnchor(ev.Transform);
|
||||
}
|
||||
|
||||
private void HandleAnchor(TransformComponent xform)
|
||||
{
|
||||
if (!TryComp<NavMapComponent>(xform.GridUid, out var navMap) ||
|
||||
!TryComp<MapGridComponent>(xform.GridUid, out var grid))
|
||||
return;
|
||||
|
||||
var tile = grid.LocalToTile(xform.Coordinates);
|
||||
var tile = ev.NewTile.GridIndices;
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
|
||||
|
||||
if (!navMap.Chunks.TryGetValue(chunkOrigin, out var chunk))
|
||||
{
|
||||
chunk = new NavMapChunk(chunkOrigin);
|
||||
navMap.Chunks[chunkOrigin] = chunk;
|
||||
}
|
||||
if (!navMap.Chunks.TryGetValue((NavMapChunkType.Floor, chunkOrigin), out var chunk))
|
||||
chunk = new(chunkOrigin);
|
||||
|
||||
RefreshTile(xform.GridUid.Value, grid, navMap, chunk, tile);
|
||||
// This could be easily replaced in the future to accommodate diagonal tiles
|
||||
if (ev.NewTile.IsSpace())
|
||||
chunk = UnsetAllEdgesForChunkTile(chunk, tile);
|
||||
|
||||
else
|
||||
chunk = SetAllEdgesForChunkTile(chunk, tile);
|
||||
|
||||
chunk.LastUpdate = _gameTiming.CurTick;
|
||||
navMap.Chunks[(NavMapChunkType.Floor, chunkOrigin)] = chunk;
|
||||
|
||||
Dirty(ev.NewTile.GridUid, navMap);
|
||||
}
|
||||
|
||||
private void RefreshTile(EntityUid uid, MapGridComponent grid, NavMapComponent component, NavMapChunk chunk, Vector2i tile)
|
||||
private void OnAirtightChanged(ref AirtightChanged ev)
|
||||
{
|
||||
var gridUid = ev.Position.Grid;
|
||||
|
||||
if (!TryComp<NavMapComponent>(gridUid, out var navMap) ||
|
||||
!TryComp<MapGridComponent>(gridUid, out var mapGrid))
|
||||
return;
|
||||
|
||||
// Refresh the affected tile
|
||||
var tile = ev.Position.Tile;
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
|
||||
|
||||
RefreshTileEntityContents(gridUid, navMap, mapGrid, chunkOrigin, tile);
|
||||
|
||||
// Update potentially affected chunks
|
||||
foreach (var category in EntityChunkTypes)
|
||||
{
|
||||
if (!navMap.Chunks.TryGetValue((category, chunkOrigin), out var chunk))
|
||||
continue;
|
||||
|
||||
chunk.LastUpdate = _gameTiming.CurTick;
|
||||
navMap.Chunks[(category, chunkOrigin)] = chunk;
|
||||
}
|
||||
|
||||
Dirty(gridUid, navMap);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region: Beacon event handling
|
||||
|
||||
private void OnNavMapBeaconMapInit(EntityUid uid, NavMapBeaconComponent component, MapInitEvent args)
|
||||
{
|
||||
if (component.DefaultText == null || component.Text != null)
|
||||
return;
|
||||
|
||||
component.Text = Loc.GetString(component.DefaultText);
|
||||
Dirty(uid, component);
|
||||
|
||||
UpdateNavMapBeaconData(uid, component);
|
||||
}
|
||||
|
||||
private void OnNavMapBeaconAnchor(EntityUid uid, NavMapBeaconComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
UpdateBeaconEnabledVisuals((uid, component));
|
||||
UpdateNavMapBeaconData(uid, component);
|
||||
}
|
||||
|
||||
private void OnConfigureMessage(Entity<ConfigurableNavMapBeaconComponent> ent, ref NavMapBeaconConfigureBuiMessage args)
|
||||
{
|
||||
if (args.Session.AttachedEntity is not { } user)
|
||||
return;
|
||||
|
||||
if (!TryComp<NavMapBeaconComponent>(ent, out var beacon))
|
||||
return;
|
||||
|
||||
if (beacon.Text == args.Text &&
|
||||
beacon.Color == args.Color &&
|
||||
beacon.Enabled == args.Enabled)
|
||||
return;
|
||||
|
||||
_adminLog.Add(LogType.Action, LogImpact.Medium,
|
||||
$"{ToPrettyString(user):player} configured NavMapBeacon \'{ToPrettyString(ent):entity}\' with text \'{args.Text}\', color {args.Color.ToHexNoAlpha()}, and {(args.Enabled ? "enabled" : "disabled")} it.");
|
||||
|
||||
if (TryComp<WarpPointComponent>(ent, out var warpPoint))
|
||||
{
|
||||
warpPoint.Location = args.Text;
|
||||
}
|
||||
|
||||
beacon.Text = args.Text;
|
||||
beacon.Color = args.Color;
|
||||
beacon.Enabled = args.Enabled;
|
||||
|
||||
UpdateBeaconEnabledVisuals((ent, beacon));
|
||||
UpdateNavMapBeaconData(ent, beacon);
|
||||
}
|
||||
|
||||
private void OnConfigurableMapInit(Entity<ConfigurableNavMapBeaconComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
if (!TryComp<NavMapBeaconComponent>(ent, out var navMap))
|
||||
return;
|
||||
|
||||
// We set this on mapinit just in case the text was edited via VV or something.
|
||||
if (TryComp<WarpPointComponent>(ent, out var warpPoint))
|
||||
warpPoint.Location = navMap.Text;
|
||||
|
||||
UpdateBeaconEnabledVisuals((ent, navMap));
|
||||
}
|
||||
|
||||
private void OnConfigurableExamined(Entity<ConfigurableNavMapBeaconComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange || !TryComp<NavMapBeaconComponent>(ent, out var navMap))
|
||||
return;
|
||||
|
||||
args.PushMarkup(Loc.GetString("nav-beacon-examine-text",
|
||||
("enabled", navMap.Enabled),
|
||||
("color", navMap.Color.ToHexNoAlpha()),
|
||||
("label", navMap.Text ?? string.Empty)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region: Grid functions
|
||||
|
||||
private void RefreshGrid(EntityUid uid, NavMapComponent component, MapGridComponent mapGrid)
|
||||
{
|
||||
// Clear stale data
|
||||
component.Chunks.Clear();
|
||||
component.Beacons.Clear();
|
||||
|
||||
// Loop over all tiles
|
||||
var tileRefs = _mapSystem.GetAllTiles(uid, mapGrid);
|
||||
|
||||
foreach (var tileRef in tileRefs)
|
||||
{
|
||||
var tile = tileRef.GridIndices;
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
|
||||
|
||||
if (!component.Chunks.TryGetValue((NavMapChunkType.Floor, chunkOrigin), out var chunk))
|
||||
chunk = new(chunkOrigin);
|
||||
|
||||
chunk.LastUpdate = _gameTiming.CurTick;
|
||||
|
||||
// Refresh the floor tile
|
||||
component.Chunks[(NavMapChunkType.Floor, chunkOrigin)] = SetAllEdgesForChunkTile(chunk, tile);
|
||||
|
||||
// Refresh the contents of the tile
|
||||
RefreshTileEntityContents(uid, component, mapGrid, chunkOrigin, tile);
|
||||
}
|
||||
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void RefreshTileEntityContents(EntityUid uid, NavMapComponent component, MapGridComponent mapGrid, Vector2i chunkOrigin, Vector2i tile)
|
||||
{
|
||||
var relative = SharedMapSystem.GetChunkRelative(tile, ChunkSize);
|
||||
var existing = chunk.TileData;
|
||||
var flag = GetFlag(relative);
|
||||
var flag = (ushort) GetFlag(relative);
|
||||
var invFlag = (ushort) ~flag;
|
||||
|
||||
chunk.TileData &= ~flag;
|
||||
// Clear stale data from the tile across all entity associated chunks
|
||||
foreach (var category in EntityChunkTypes)
|
||||
{
|
||||
if (!component.Chunks.TryGetValue((category, chunkOrigin), out var chunk))
|
||||
chunk = new(chunkOrigin);
|
||||
|
||||
var enumerator = grid.GetAnchoredEntitiesEnumerator(tile);
|
||||
// TODO: Use something to get convex poly.
|
||||
foreach (var (direction, _) in chunk.TileData)
|
||||
chunk.TileData[direction] &= invFlag;
|
||||
|
||||
chunk.LastUpdate = _gameTiming.CurTick;
|
||||
component.Chunks[(category, chunkOrigin)] = chunk;
|
||||
}
|
||||
|
||||
// Update the tile data based on what entities are still anchored to the tile
|
||||
var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, mapGrid, tile);
|
||||
|
||||
while (enumerator.MoveNext(out var ent))
|
||||
{
|
||||
if (!_physicsQuery.TryGetComponent(ent, out var body) ||
|
||||
!body.CanCollide ||
|
||||
!body.Hard ||
|
||||
body.BodyType != BodyType.Static ||
|
||||
!_tags.HasTag(ent.Value, "Wall", _tagQuery) &&
|
||||
!_tags.HasTag(ent.Value, "Window", _tagQuery))
|
||||
{
|
||||
if (!TryComp<AirtightComponent>(ent, out var entAirtight))
|
||||
continue;
|
||||
|
||||
var category = GetAssociatedEntityChunkType(ent.Value);
|
||||
|
||||
if (!component.Chunks.TryGetValue((category, chunkOrigin), out var chunk))
|
||||
continue;
|
||||
|
||||
foreach (var (direction, _) in chunk.TileData)
|
||||
{
|
||||
if ((direction & entAirtight.AirBlockedDirection) > 0)
|
||||
chunk.TileData[direction] |= flag;
|
||||
}
|
||||
|
||||
chunk.TileData |= flag;
|
||||
break;
|
||||
chunk.LastUpdate = _gameTiming.CurTick;
|
||||
component.Chunks[(category, chunkOrigin)] = chunk;
|
||||
}
|
||||
|
||||
if (chunk.TileData == 0)
|
||||
// Remove walls that intersect with doors (unless they can both physically fit on the same tile)
|
||||
if (component.Chunks.TryGetValue((NavMapChunkType.Wall, chunkOrigin), out var wallChunk) &&
|
||||
component.Chunks.TryGetValue((NavMapChunkType.Airlock, chunkOrigin), out var airlockChunk))
|
||||
{
|
||||
component.Chunks.Remove(chunk.Origin);
|
||||
}
|
||||
foreach (var (direction, _) in wallChunk.TileData)
|
||||
{
|
||||
var airlockInvFlag = (ushort) ~airlockChunk.TileData[direction];
|
||||
wallChunk.TileData[direction] &= airlockInvFlag;
|
||||
}
|
||||
|
||||
if (existing == chunk.TileData)
|
||||
wallChunk.LastUpdate = _gameTiming.CurTick;
|
||||
component.Chunks[(NavMapChunkType.Wall, chunkOrigin)] = wallChunk;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region: Beacon functions
|
||||
|
||||
private void UpdateNavMapBeaconData(EntityUid uid, NavMapBeaconComponent component, TransformComponent? xform = null)
|
||||
{
|
||||
if (!Resolve(uid, ref xform))
|
||||
return;
|
||||
|
||||
Dirty(uid, component);
|
||||
if (xform.GridUid == null)
|
||||
return;
|
||||
|
||||
if (!TryComp<NavMapComponent>(xform.GridUid, out var navMap))
|
||||
return;
|
||||
|
||||
var netEnt = GetNetEntity(uid);
|
||||
var oldBeacon = navMap.Beacons.FirstOrNull(x => x.NetEnt == netEnt);
|
||||
var changed = false;
|
||||
|
||||
if (oldBeacon != null)
|
||||
{
|
||||
navMap.Beacons.Remove(oldBeacon.Value);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (TryCreateNavMapBeaconData(uid, component, xform, out var beaconData))
|
||||
{
|
||||
navMap.Beacons.Add(beaconData.Value);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
Dirty(xform.GridUid.Value, navMap);
|
||||
}
|
||||
|
||||
private void UpdateBeaconEnabledVisuals(Entity<NavMapBeaconComponent> ent)
|
||||
{
|
||||
_appearance.SetData(ent, NavMapBeaconVisuals.Enabled, ent.Comp.Enabled && Transform(ent).Anchored);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -389,9 +345,6 @@ public sealed class NavMapSystem : SharedNavMapSystem
|
||||
|
||||
comp.Enabled = enabled;
|
||||
UpdateBeaconEnabledVisuals((uid, comp));
|
||||
Dirty(uid, comp);
|
||||
|
||||
RefreshNavGrid(uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -419,7 +372,7 @@ public sealed class NavMapSystem : SharedNavMapSystem
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return false;
|
||||
|
||||
return TryGetNearestBeacon(_transform.GetMapCoordinates(ent, ent.Comp), out beacon, out beaconCoords);
|
||||
return TryGetNearestBeacon(_transformSystem.GetMapCoordinates(ent, ent.Comp), out beacon, out beaconCoords);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -446,7 +399,7 @@ public sealed class NavMapSystem : SharedNavMapSystem
|
||||
if (coordinates.MapId != xform.MapID)
|
||||
continue;
|
||||
|
||||
var coords = _transform.GetWorldPosition(xform);
|
||||
var coords = _transformSystem.GetWorldPosition(xform);
|
||||
var distanceSquared = (coordinates.Position - coords).LengthSquared();
|
||||
if (!float.IsInfinity(minDistance) && distanceSquared >= minDistance)
|
||||
continue;
|
||||
@@ -465,7 +418,7 @@ public sealed class NavMapSystem : SharedNavMapSystem
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return Loc.GetString("nav-beacon-pos-no-beacons");
|
||||
|
||||
return GetNearestBeaconString(_transform.GetMapCoordinates(ent, ent.Comp));
|
||||
return GetNearestBeaconString(_transformSystem.GetMapCoordinates(ent, ent.Comp));
|
||||
}
|
||||
|
||||
public string GetNearestBeaconString(MapCoordinates coordinates)
|
||||
@@ -494,11 +447,13 @@ public sealed class NavMapSystem : SharedNavMapSystem
|
||||
? Loc.GetString("nav-beacon-pos-format-direction-mod-far")
|
||||
: string.Empty;
|
||||
|
||||
// we can null suppress the text being null because TRyGetNearestVisibleStationBeacon always gives us a beacon with not-null text.
|
||||
// we can null suppress the text being null because TryGetNearestVisibleStationBeacon always gives us a beacon with not-null text.
|
||||
return Loc.GetString("nav-beacon-pos-format-direction",
|
||||
("modifier", modifier),
|
||||
("direction", ContentLocalizationManager.FormatDirection(adjustedDir).ToLowerInvariant()),
|
||||
("color", beacon.Value.Comp.Color),
|
||||
("marker", beacon.Value.Comp.Text!));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user