Files
RobustToolbox/Robust.Shared/GameStates/GameStateMapData.cs
AcruidandGitHub 6b9b56ca83 Grid Components Allocate Grids (#2597)
* Deleting a map is now routed through MapComponent deletion.

* Remove map and grid deletions from map networking, just delete the entity if you want to remove the map.

* Moved the chunkSize property of created grids from the networked MapData to the MapGridComponent state.

* Remove unused IMapManager.DefaultMap property.

* Removed MapCreationTick field from MapManager.MapCollection.

* Removed _maps hashset field from MapManager.

* Removed CreatedMaps array from network MapData.

* MapGrid.ParentMapId is now derived from the bound TransformComponent, and isn't required in the MapGrid ctor.
Removed MapGrid.CreatedTick, it can be found on MapGridComponent.CreationTick.

* Remove a bunch of ApplyGameStatePre code duplication.

* Completely refactored CreateGrid.

* Adds AddComponentUninitialized to the ECS system. This allows you to access a component before it is initialized in a using block.

* Use AddComponentUninitialized to allocate a grid after the component is allocated.

* MapLoader now creates the grids after creating the map entities.

* Chunksize and TileSize properties are now actually read out of the map yaml.
TileSize has a public Setter.

* Minor cleanup.

* Moved grid allocation onto the MapGridComponent.

* Final Cleanup.

* Merge Fail.

* Fixed test, grid was getting deleted because it was empty.

* Remove DeletedChunkDatum from grid networking.

* ApplyMapGridState moved from map manager to the MapGridComponent.
2022-03-13 18:28:59 -07:00

70 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
namespace Robust.Shared.GameStates
{
[Serializable, NetSerializable]
public sealed class GameStateMapData
{
public readonly KeyValuePair<GridId, GridDatum>[]? GridData;
public GameStateMapData(KeyValuePair<GridId, GridDatum>[]? gridData)
{
GridData = gridData;
}
[Serializable, NetSerializable]
public struct GridDatum
{
// TransformComponent State
public readonly MapCoordinates Coordinates;
public readonly Angle Angle;
// MapGridComponent State
public readonly ChunkDatum[] ChunkData;
public GridDatum(ChunkDatum[] chunkData, MapCoordinates coordinates, Angle angle)
{
ChunkData = chunkData;
Coordinates = coordinates;
Angle = angle;
}
}
[Serializable, NetSerializable]
public readonly struct ChunkDatum
{
public readonly Vector2i Index;
// Definitely wasteful to send EVERY tile.
// Optimize away future coder.
// Also it's stored row-major.
public readonly Tile[] TileData;
public bool IsDeleted()
{
return TileData == default;
}
private ChunkDatum(Vector2i index, Tile[] tileData)
{
Index = index;
TileData = tileData;
}
public static ChunkDatum CreateModified(Vector2i index, Tile[] tileData)
{
return new ChunkDatum(index, tileData);
}
public static ChunkDatum CreateDeleted(Vector2i index)
{
return new ChunkDatum(index, default!);
}
}
}
}