Convert Tile.TypeId to an int (#4307)

Co-authored-by: ike709 <ike709@github.com>
Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
This commit is contained in:
ike709
2023-08-26 05:16:14 -07:00
committed by GitHub
parent f0c4d7c5eb
commit 8917b29255
10 changed files with 26 additions and 46 deletions

View File

@@ -27,7 +27,7 @@ namespace Robust.Client.Map
public Texture TileTextureAtlas => _tileTextureAtlas ?? Texture.Transparent;
private readonly Dictionary<ushort, Box2[]> _tileRegions = new();
private readonly Dictionary<int, Box2[]> _tileRegions = new();
public Box2 ErrorTileRegion { get; private set; }
@@ -38,7 +38,7 @@ namespace Robust.Client.Map
}
/// <inheritdoc />
public Box2[]? TileAtlasRegion(ushort tileType)
public Box2[]? TileAtlasRegion(int tileType)
{
if (_tileRegions.TryGetValue(tileType, out var region))
{

View File

@@ -27,6 +27,6 @@ namespace Robust.Client.Map
/// Gets the region inside the texture atlas to use to draw a tile type.
/// </summary>
/// <returns>If null, do not draw the tile at all.</returns>
Box2[]? TileAtlasRegion(ushort tileType);
Box2[]? TileAtlasRegion(int tileType);
}
}

View File

@@ -51,7 +51,7 @@ public sealed class MapLoaderSystem : EntitySystem
private ISawmill _logWriter = default!;
private static readonly MapLoadOptions DefaultLoadOptions = new();
private const int MapFormatVersion = 5;
private const int MapFormatVersion = 6;
private const int BackwardsVersion = 2;
private MapSerializationContext _context = default!;
@@ -384,11 +384,11 @@ public sealed class MapLoaderSystem : EntitySystem
// Load tile mapping so that we can map the stored tile IDs into the ones actually used at runtime.
var tileMap = data.RootMappingNode.Get<MappingDataNode>("tilemap");
_context.TileMap = new Dictionary<ushort, string>(tileMap.Count);
_context.TileMap = new Dictionary<int, string>(tileMap.Count);
foreach (var (key, value) in tileMap.Children)
{
var tileId = (ushort) ((ValueDataNode)key).AsInt();
var tileId = ((ValueDataNode)key).AsInt();
var tileDefName = ((ValueDataNode)value).Value;
_context.TileMap.Add(tileId, tileDefName);
}
@@ -960,7 +960,7 @@ public sealed class MapLoaderSystem : EntitySystem
{
// Although we could use tiledefmanager it might write tiledata we don't need so we'll compress it
var gridQuery = GetEntityQuery<MapGridComponent>();
var tileDefs = new HashSet<ushort>();
var tileDefs = new HashSet<int>();
foreach (var ent in entities)
{
@@ -977,7 +977,7 @@ public sealed class MapLoaderSystem : EntitySystem
var tileMap = new MappingDataNode();
rootNode.Add("tilemap", tileMap);
var ordered = new List<ushort>(tileDefs);
var ordered = new List<int>(tileDefs);
ordered.Sort();
foreach (var tyleId in ordered)

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using Robust.Server.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -48,7 +47,7 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
var chunk = instantiationDelegate != null ? instantiationDelegate() : new MapChunk(ind.X, ind.Y, size);
IReadOnlyDictionary<ushort, string>? tileMap = null;
IReadOnlyDictionary<int, string>? tileMap = null;
if (context is MapSerializationContext serContext)
{
@@ -65,11 +64,14 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
var tileDefinitionManager = dependencies.Resolve<ITileDefinitionManager>();
node.TryGetValue(new ValueDataNode("version"), out var versionNode);
var version = ((ValueDataNode?) versionNode)?.AsInt() ?? 1;
for (ushort y = 0; y < chunk.ChunkSize; y++)
{
for (ushort x = 0; x < chunk.ChunkSize; x++)
{
var id = reader.ReadUInt16();
var id = version < 6 ? reader.ReadUInt16() : reader.ReadInt32();
var flags = (TileRenderFlag)reader.ReadByte();
var variant = reader.ReadByte();
@@ -98,6 +100,8 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
var gridNode = new ValueDataNode();
root.Add("tiles", gridNode);
root.Add("version", new ValueDataNode("6"));
gridNode.Value = SerializeTiles(value);
return root;
@@ -106,7 +110,7 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
private static string SerializeTiles(MapChunk chunk)
{
// number of bytes written per tile, because sizeof(Tile) is useless.
const int structSize = 4;
const int structSize = 6;
var nTiles = chunk.ChunkSize * chunk.ChunkSize * structSize;
var barr = new byte[nTiles];

View File

@@ -82,7 +82,7 @@ namespace Robust.Server.Placement
var alignRcv = msg.Align;
var isTile = msg.IsTile;
ushort tileType = 0;
int tileType = 0;
var entityTemplateName = "";
if (isTile) tileType = msg.TileType;
@@ -177,7 +177,7 @@ namespace Robust.Server.Placement
}
}
private void PlaceNewTile(ushort tileType, EntityCoordinates coordinates, NetUserId placingUserId)
private void PlaceNewTile(int tileType, EntityCoordinates coordinates, NetUserId placingUserId)
{
if (!coordinates.IsValid(_entityManager)) return;

View File

@@ -9,7 +9,7 @@ namespace Robust.Shared.Enums
public EntityUid MobUid { get; set; }
public string? PlacementOption { get; set; }
public int Range { get; set; }
public ushort TileType { get; set; }
public int TileType { get; set; }
public int Uses { get; set; } = 1;
}
}

View File

@@ -22,7 +22,7 @@ internal sealed class MapSerializationContext : ISerializationContext, IEntityLo
public SerializationManager.SerializerProvider SerializerProvider { get; } = new();
// Run-specific data
public Dictionary<ushort, string>? TileMap;
public Dictionary<int, string>? TileMap;
public readonly Dictionary<string, IComponent> CurrentReadingEntityComponents = new();
public HashSet<string> CurrentlyIgnoredComponents = new();
public string? CurrentComponent;

View File

@@ -13,7 +13,7 @@ public readonly struct Tile : IEquatable<Tile>, ISpanFormattable
/// <summary>
/// Internal type ID of this tile.
/// </summary>
public readonly ushort TypeId;
public readonly int TypeId;
/// <summary>
/// Rendering flags.
@@ -41,37 +41,13 @@ public readonly struct Tile : IEquatable<Tile>, ISpanFormattable
/// <param name="typeId">Internal type ID.</param>
/// <param name="flags">Flags used by toolbox's rendering.</param>
/// <param name="variant">The visual variant this tile is using.</param>
public Tile(ushort typeId, TileRenderFlag flags = 0, byte variant = 0)
public Tile(int typeId, TileRenderFlag flags = 0, byte variant = 0)
{
TypeId = typeId;
Flags = flags;
Variant = variant;
}
/// <summary>
/// Explicit conversion of <c>Tile</c> to <c>uint</c> . This should only
/// be used in special cases like serialization. Do NOT use this in
/// content.
/// </summary>
public static explicit operator uint(Tile tile)
{
return ((uint)tile.TypeId << 16) | (uint)tile.Flags << 8 | tile.Variant;
}
/// <summary>
/// Explicit conversion of <c>uint</c> to <c>Tile</c> . This should only
/// be used in special cases like serialization. Do NOT use this in
/// content.
/// </summary>
public static explicit operator Tile(uint tile)
{
return new(
(ushort)(tile >> 16),
(TileRenderFlag)(tile >> 8),
(byte)tile
);
}
/// <summary>
/// Check for equality by value between two objects.
/// </summary>

View File

@@ -23,7 +23,7 @@ namespace Robust.Shared.Network.Messages
/// </summary>
public bool Replacement { get; set; }
public bool IsTile { get; set; }
public ushort TileType { get; set; }
public int TileType { get; set; }
public string EntityTemplateName { get; set; }
public EntityCoordinates EntityCoordinates { get; set; }
public Direction DirRcv { get; set; }
@@ -44,7 +44,7 @@ namespace Robust.Shared.Network.Messages
IsTile = buffer.ReadBoolean();
Replacement = buffer.ReadBoolean();
if (IsTile) TileType = buffer.ReadUInt16();
if (IsTile) TileType = buffer.ReadInt32();
else EntityTemplateName = buffer.ReadString();
EntityCoordinates = buffer.ReadEntityCoordinates();

View File

@@ -25,13 +25,13 @@ public readonly struct PlacementEntityEvent
public readonly struct PlacementTileEvent
{
public readonly ushort TileType;
public readonly int TileType;
public readonly EntityCoordinates Coordinates;
public readonly NetUserId? PlacerNetUserId;
public PlacementTileEvent(ushort tileType, EntityCoordinates coordinates, NetUserId? placerNetUserId)
public PlacementTileEvent(int tileType, EntityCoordinates coordinates, NetUserId? placerNetUserId)
{
TileType = tileType;
Coordinates = coordinates;