Files
RobustToolbox/Robust.Shared/Map/MapManager.cs
T
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

87 lines
2.2 KiB
C#

using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Robust.Shared.Map;
/// <inheritdoc cref="IMapManager" />
[Virtual]
internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber
{
[field: Dependency] public IGameTiming GameTiming { get; } = default!;
[field: Dependency] public IEntityManager EntityManager { get; } = default!;
[Dependency] private readonly IConsoleHost _conhost = default!;
/// <inheritdoc />
public void Initialize()
{
#if DEBUG
DebugTools.Assert(!_dbgGuardInit);
DebugTools.Assert(!_dbgGuardRunning);
_dbgGuardInit = true;
#endif
InitializeMapPausing();
}
/// <inheritdoc />
public void Startup()
{
#if DEBUG
DebugTools.Assert(_dbgGuardInit);
_dbgGuardRunning = true;
#endif
Logger.DebugS("map", "Starting...");
StartupGridTrees();
EnsureNullspaceExistsAndClear();
DebugTools.Assert(_grids.Count == 0);
DebugTools.Assert(!GridExists(GridId.Invalid));
}
/// <inheritdoc />
public void Shutdown()
{
#if DEBUG
DebugTools.Assert(_dbgGuardInit);
#endif
Logger.DebugS("map", "Stopping...");
foreach (var mapComp in EntityManager.EntityQuery<IMapComponent>())
{
EntityManager.DeleteEntity(mapComp.Owner);
}
ShutdownGridTrees();
#if DEBUG
DebugTools.Assert(_grids.Count == 0);
DebugTools.Assert(!GridExists(GridId.Invalid));
_dbgGuardRunning = false;
#endif
}
/// <inheritdoc />
public void Restart()
{
Logger.DebugS("map", "Restarting...");
// Don't just call Shutdown / Startup because we don't want to touch the subscriptions on gridtrees
// Restart can be called any time during a game, whereas shutdown / startup are typically called upon connection.
foreach (var mapComp in EntityManager.EntityQuery<IMapComponent>())
{
EntityManager.DeleteEntity(mapComp.Owner);
}
EnsureNullspaceExistsAndClear();
}
#if DEBUG
private bool _dbgGuardInit;
private bool _dbgGuardRunning;
#endif
}