Files
OldThink/Content.Shared/Pinpointer/SharedNavMapSystem.cs
Jabak 9f00d4b9aa Upstream (#148)
* Content changes for engine delta-state PR (#28134)

* Update GasTileOverlayState

* Update DecalGridState

* Update NavMapState

* poke

* poke2

* poke3

* Poke dem tests

* Update engine to v223.0.0 (#28239)

* Update RobustToolbox

* Improve InteractionSystem range & BUI checks (#27999)

* Improve InteractionSystem range & BUI checks

* Ghost fixes

* AAA

* Fix test

* fix nullable

* revert to broadcast event

* Fixes for eengine PR

* Ah buckle code

* )

* Update engine to v223.0.0

* Update engine to v223.1.0

* Update engine to v223.1.1

* Hotfix for crashes from bad item names (#28256)

* Fix weapon error logs (#28264)

* Update engine to v223.1.2 (#28273)

* Update RobustToolbox

* Update RobustToolbox

* Fix dud modular grenade visuals (#28265)

* Fix not networking whitelist and blacklist in storage component (#28238)

* fix id card console not updating records (#28237)

* fix id card console not updating records

* test

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>

* Remove the network tab (#28231)

It is useless and bloat, if a user needs to change these settings they are free to modify their cvars manually via the clientconfig.toml file or via the cvar command.

* antag objective issuing refactor (#28216)

* add AntagObjectives from GenericAntag

* add AntagRandomObjectives that traitor and thief can use

* make ObjectivesSystem use initial character name which AntagSelection passes

* make thief and traitor use AntagRandomObjectives

* remove now unused locale

* make sleeper agents rule use baseTraitorRule

* restore dragon rule oop

* bandaid for genericantag

* real

* typo

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>

* move nukie profile loading into its own rule (#28208)

* move profile loading out of nukeops rule

* make BaseNukeopsRule and use AntagLoadProfileRule

* untroll

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>

* fix antagSelect

* Objects ordered through cargo system shouldn't start anchored (#28115)

* Order normal space heater instead of anchored variant

* Make sure ordered objects don't spawn anchored

* Order space heater flatpack instead of a regular space heater

* Remove obsolete TODO

* Remove unnecessary name

---------

Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es>

* Move PendingZombieComponent to Shared (#28143)

* Move PendingZombieComponent to Shared

* network me boy

---------

Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>

* Make it possible to hide full health bars below a total damage threshold (#28127)

* Make it possible to hide full health bars below a total damage threshold

* Fix not setting state

* Fix storage UI interactions (#28291)

* Fix storage UI interactions

* Add VV support

* Fix stripping not marking interactions as handled (#28292)

* Make NetworkConfigurator use BoundUserInterfaceCheckRangeEvent (#28293)

* Fix hypodarts not injecting with people that have ANY outerclothing (#28301)

Update darts.yml

* fix borg ui mispredict opening (#28305)

move borg ui junk to shared

* Add loadout group check (#28311)

Forgot to add it back in one of the rewrites.

* fix mirror server crashes (#28318)

* Remove bogus C# finalizers (#28315)

Begging people to learn how this programming language works before throwing random syntax into a file.

None of these finalizers ever worked. I also checked whether they were memory leaks and needed *proper* shutdown logic, but they're all instantiated-once UI controls that last for the entire lifetime of the program so it's probably fine.

* Cleans up some entity-related spawnmenu stuff (#28234)

* cleans up a lot of stuff in the spawnmenu

* skibidi dode

* spawners update

* Revert "spawners update"

This reverts commit bc27d9f556b29f6fb1f89cebbe0ac37e28319fd0.

* fix antag selection being evil (#28197)

* fix antag selection being evil

* fix test

* untroll the other tests

* remove role timer troll

* Allow tests to modify antag preferences

* Fix antag selection

* Misc test fixes

* Add AntagPreferenceTest

* Fix lazy mistakes

* Test cleanup

* Try stop players in lobbies from being assigned mid-round antags

* ranting

* I am going insane

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>

* Revert "fix mirror server crashes (#28318)"

This reverts commit bcb0e555b058a4049d0cdb32d64eaf86c35a67be.

* fix

* Update engine to 223.2.0 (#28329)

* Update RobustToolbox

* Update RobustToolbox

---------

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: Vasilis <vasilis@pikachu.systems>
Co-authored-by: eoineoineoin <github@eoinrul.es>
Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es>
Co-authored-by: Ady4ik <141335742+Ady4ik@users.noreply.github.com>
Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: Flareguy <78941145+Flareguy@users.noreply.github.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
Co-authored-by: Kara <lunarautomaton6@gmail.com>
2024-10-22 20:47:03 +03:00

188 lines
5.9 KiB
C#

using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using Content.Shared.Tag;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Shared.Pinpointer;
public abstract class SharedNavMapSystem : EntitySystem
{
public const int Categories = 3;
public const int Directions = 4; // Not directly tied to number of atmos directions
public const int ChunkSize = 8;
public const int ArraySize = ChunkSize* ChunkSize;
public const int AllDirMask = (1 << Directions) - 1;
public const int AirlockMask = AllDirMask << (int) NavMapChunkType.Airlock;
public const int WallMask = AllDirMask << (int) NavMapChunkType.Wall;
public const int FloorMask = AllDirMask << (int) NavMapChunkType.Floor;
[Robust.Shared.IoC.Dependency] private readonly TagSystem _tagSystem = default!;
private readonly string[] _wallTags = ["Wall", "Window"];
private EntityQuery<NavMapDoorComponent> _doorQuery;
public override void Initialize()
{
base.Initialize();
// Data handling events
SubscribeLocalEvent<NavMapComponent, ComponentGetState>(OnGetState);
_doorQuery = GetEntityQuery<NavMapDoorComponent>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetTileIndex(Vector2i relativeTile)
{
return relativeTile.X * ChunkSize + relativeTile.Y;
}
/// <summary>
/// Inverse of <see cref="GetTileIndex"/>
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2i GetTileFromIndex(int index)
{
var x = index / ChunkSize;
var y = index % ChunkSize;
return new Vector2i(x, y);
}
public NavMapChunkType GetEntityType(EntityUid uid)
{
if (_doorQuery.HasComp(uid))
return NavMapChunkType.Airlock;
if (_tagSystem.HasAnyTag(uid, _wallTags))
return NavMapChunkType.Wall;
return NavMapChunkType.Invalid;
}
protected bool TryCreateNavMapBeaconData(EntityUid uid, NavMapBeaconComponent component, TransformComponent xform, MetaDataComponent meta, [NotNullWhen(true)] out NavMapBeacon? beaconData)
{
beaconData = null;
if (!component.Enabled || xform.GridUid == null || !xform.Anchored)
return false;
var name = component.Text;
if (string.IsNullOrEmpty(name))
name = meta.EntityName;
beaconData = new NavMapBeacon(meta.NetEntity, component.Color, name, xform.LocalPosition);
return true;
}
#region: Event handling
private void OnGetState(EntityUid uid, NavMapComponent component, ref ComponentGetState args)
{
Dictionary<Vector2i, int[]> chunks;
// Should this be a full component state or a delta-state?
if (args.FromTick <= component.CreationTick)
{
// Full state
chunks = new(component.Chunks.Count);
foreach (var (origin, chunk) in component.Chunks)
{
chunks.Add(origin, chunk.TileData);
}
args.State = new NavMapState(chunks, component.Beacons);
return;
}
chunks = new();
foreach (var (origin, chunk) in component.Chunks)
{
if (chunk.LastUpdate < args.FromTick)
continue;
chunks.Add(origin, chunk.TileData);
}
args.State = new NavMapDeltaState(chunks, component.Beacons, new(component.Chunks.Keys));
}
#endregion
#region: System messages
[Serializable, NetSerializable]
protected sealed class NavMapState(
Dictionary<Vector2i, int[]> chunks,
Dictionary<NetEntity, NavMapBeacon> beacons)
: ComponentState
{
public Dictionary<Vector2i, int[]> Chunks = chunks;
public Dictionary<NetEntity, NavMapBeacon> Beacons = beacons;
}
[Serializable, NetSerializable]
protected sealed class NavMapDeltaState(
Dictionary<Vector2i, int[]> modifiedChunks,
Dictionary<NetEntity, NavMapBeacon> beacons,
HashSet<Vector2i> allChunks)
: ComponentState, IComponentDeltaState<NavMapState>
{
public Dictionary<Vector2i, int[]> ModifiedChunks = modifiedChunks;
public Dictionary<NetEntity, NavMapBeacon> Beacons = beacons;
public HashSet<Vector2i> AllChunks = allChunks;
public void ApplyToFullState(NavMapState state)
{
foreach (var key in state.Chunks.Keys)
{
if (!AllChunks!.Contains(key))
state.Chunks.Remove(key);
}
foreach (var (index, data) in ModifiedChunks)
{
if (!state.Chunks.TryGetValue(index, out var stateValue))
state.Chunks[index] = stateValue = new int[data.Length];
Array.Copy(data, stateValue, data.Length);
}
state.Beacons.Clear();
foreach (var (nuid, beacon) in Beacons)
{
state.Beacons.Add(nuid, beacon);
}
}
public NavMapState CreateNewFullState(NavMapState state)
{
var chunks = new Dictionary<Vector2i, int[]>(state.Chunks.Count);
foreach (var (index, data) in state.Chunks)
{
if (!AllChunks!.Contains(index))
continue;
var newData = chunks[index] = new int[ArraySize];
if (ModifiedChunks.TryGetValue(index, out var updatedData))
Array.Copy(newData, updatedData, ArraySize);
else
Array.Copy(newData, data, ArraySize);
}
return new NavMapState(chunks, new(Beacons));
}
}
[Serializable, NetSerializable]
public record struct NavMapBeacon(NetEntity NetEnt, Color Color, string Text, Vector2 Position);
#endregion
}