Replace NavMap dictionaries with int[] (#27602)
* Replace NavMap dictionaries with int[] * Remove badly named const * Remove unnecessary offset * Prioritize airlocks
This commit is contained in:
@@ -12,8 +12,6 @@ namespace Content.Shared.Pinpointer;
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class NavMapComponent : Component
|
||||
{
|
||||
public const int Categories = 4;
|
||||
|
||||
/*
|
||||
* Don't need DataFields as this can be reconstructed
|
||||
*/
|
||||
@@ -28,62 +26,37 @@ public sealed partial class NavMapComponent : Component
|
||||
/// List of station beacons.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public HashSet<SharedNavMapSystem.NavMapBeacon> Beacons = new();
|
||||
public Dictionary<NetEntity, SharedNavMapSystem.NavMapBeacon> Beacons = new();
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class NavMapChunk
|
||||
public sealed class NavMapChunk(Vector2i origin)
|
||||
{
|
||||
/// <summary>
|
||||
/// The chunk origin
|
||||
/// </summary>
|
||||
public readonly Vector2i Origin;
|
||||
[ViewVariables]
|
||||
public readonly Vector2i Origin = origin;
|
||||
|
||||
/// <summary>
|
||||
/// Array with each entry corresponding to a <see cref="NavMapChunkType"/>.
|
||||
/// Uses a bitmask for tiles, 1 for occupied and 0 for empty. There is a bitmask for each cardinal direction,
|
||||
/// representing each edge of the tile, in case the entities inside it do not entirely fill it
|
||||
/// Array containing the chunk's data. The
|
||||
/// </summary>
|
||||
public Dictionary<AtmosDirection, ushort>?[] TileData;
|
||||
[ViewVariables]
|
||||
public int[] TileData = new int[SharedNavMapSystem.ArraySize];
|
||||
|
||||
/// <summary>
|
||||
/// The last game tick that the chunk was updated
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public GameTick LastUpdate;
|
||||
|
||||
public NavMapChunk(Vector2i origin)
|
||||
{
|
||||
Origin = origin;
|
||||
TileData = new Dictionary<AtmosDirection, ushort>?[NavMapComponent.Categories];
|
||||
}
|
||||
|
||||
public Dictionary<AtmosDirection, ushort> EnsureType(NavMapChunkType chunkType)
|
||||
{
|
||||
var data = TileData[(int) chunkType];
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
data = new Dictionary<AtmosDirection, ushort>()
|
||||
{
|
||||
[AtmosDirection.North] = 0,
|
||||
[AtmosDirection.East] = 0,
|
||||
[AtmosDirection.South] = 0,
|
||||
[AtmosDirection.West] = 0,
|
||||
};
|
||||
|
||||
TileData[(int) chunkType] = data;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public enum NavMapChunkType : byte
|
||||
{
|
||||
Invalid,
|
||||
Floor,
|
||||
Wall,
|
||||
Airlock,
|
||||
// Update the categories const if you update this.
|
||||
// Values represent bit shift offsets when retrieving data in the tile array.
|
||||
Invalid = byte.MaxValue,
|
||||
Floor = 0, // I believe floors have directional information for diagonal tiles?
|
||||
Wall = SharedNavMapSystem.Directions,
|
||||
Airlock = 2 * SharedNavMapSystem.Directions,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user