diff --git a/Resources/Locale/en-US/commands.ftl b/Resources/Locale/en-US/commands.ftl index 4d4e3264618..fcafc42eedf 100644 --- a/Resources/Locale/en-US/commands.ftl +++ b/Resources/Locale/en-US/commands.ftl @@ -306,6 +306,15 @@ cmd-addmap-help = Usage: {$command} [pre-init] cmd-rmmap-desc = Removes a map from the world. You cannot remove nullspace. cmd-rmmap-help = Usage: {$command} +cmd-pausemap-desc = Pauses a map, pausing all simulation processing on it. +cmd-pausemap-help = Usage: pausemap + +cmd-unpausemap-desc = Unpauses a map, resuming all simulation processing on it. +cmd-unpausemap-help = Usage: unpausemap + +cmd-querymappaused-desc = Check whether a map is paused or not. +cmd-querymappaused-help = Usage: querymappaused + cmd-savegrid-desc = Serializes a grid to disk. cmd-savegrid-help = Usage: {$command} diff --git a/Robust.Benchmarks/Transform/RecursiveMoveBenchmark.cs b/Robust.Benchmarks/Transform/RecursiveMoveBenchmark.cs index 15acf565239..1f67c1a5483 100644 --- a/Robust.Benchmarks/Transform/RecursiveMoveBenchmark.cs +++ b/Robust.Benchmarks/Transform/RecursiveMoveBenchmark.cs @@ -47,7 +47,6 @@ public void GlobalSetup() Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()).Wait(); - var mapMan = server.ResolveDependency(); _entMan = server.ResolveDependency(); var confMan = server.ResolveDependency(); var sPlayerMan = server.ResolveDependency(); @@ -92,7 +91,7 @@ public void GlobalSetup() server.WaitPost(() => { var map = server.ResolveDependency().CreateMap(out var mapId); - var gridComp = mapMan.CreateGridEntity(mapId); + var gridComp = mapSys.CreateGridEntity(mapId); var grid = gridComp.Owner; mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1)); _gridCoords = new EntityCoordinates(grid, .5f, .5f); diff --git a/Robust.Client.IntegrationTests/GameObjects/Components/TransformComponentTests.cs b/Robust.Client.IntegrationTests/GameObjects/Components/TransformComponentTests.cs index 0f5a3e3c289..1b774095a6f 100644 --- a/Robust.Client.IntegrationTests/GameObjects/Components/TransformComponentTests.cs +++ b/Robust.Client.IntegrationTests/GameObjects/Components/TransformComponentTests.cs @@ -19,12 +19,13 @@ private static (ISimulation, EntityUid gridA, EntityUid gridB) SimulationFactor .NewSimulation() .InitializeInstance(); - var mapId = sim.Resolve().System().CreateMap(); - var mapManager = sim.Resolve(); + var entMan = sim.Resolve(); + var mapSys = entMan.System(); + var mapId = mapSys.CreateMap(); // Adds two grids to use in tests. - var gridA = mapManager.CreateGridEntity(mapId); - var gridB = mapManager.CreateGridEntity(mapId); + var gridA = mapSys.CreateGridEntity(mapId); + var gridB = mapSys.CreateGridEntity(mapId); return (sim, gridA, gridB); } diff --git a/Robust.Client/BaseClient.cs b/Robust.Client/BaseClient.cs index 428ab9859ce..4c8dbf89e2e 100644 --- a/Robust.Client/BaseClient.cs +++ b/Robust.Client/BaseClient.cs @@ -26,7 +26,6 @@ public sealed partial class BaseClient : IBaseClient, IPostInjectInit [Dependency] private IPlayerManager _playMan = default!; [Dependency] private IClientNetConfigurationManager _configManager = default!; [Dependency] private IClientEntityManager _entityManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IDiscordRichPresence _discord = default!; [Dependency] private IGameTiming _timing = default!; [Dependency] private IClientGameStateManager _gameStates = default!; @@ -247,7 +246,6 @@ private void OnNetDisconnect(object? sender, NetDisconnectedArgs args) private void GameStartedSetup() { _entityManager.Startup(); - _mapManager.Startup(); _timing.ResetSimTime(_timeBase); _timing.Paused = false; @@ -259,7 +257,6 @@ private void GameStoppedReset() _gameStates.Reset(); _playMan.Shutdown(); _entityManager.Shutdown(); - _mapManager.Shutdown(); _discord.ClearPresence(); Reset(); } diff --git a/Robust.Client/ClientIoC.cs b/Robust.Client/ClientIoC.cs index 3df84845048..7a2ca8e14fe 100644 --- a/Robust.Client/ClientIoC.cs +++ b/Robust.Client/ClientIoC.cs @@ -66,9 +66,6 @@ public static void RegisterIoC(GameController.DisplayMode mode, IDependencyColle deps.Register(); deps.Register(); deps.Register(); - deps.Register(); - deps.Register(); - deps.Register(); deps.Register(); deps.Register(); deps.Register(); diff --git a/Robust.Client/Console/Commands/Debug.cs b/Robust.Client/Console/Commands/Debug.cs index 3d8c0ed0a0a..1d21498e123 100644 --- a/Robust.Client/Console/Commands/Debug.cs +++ b/Robust.Client/Console/Commands/Debug.cs @@ -718,7 +718,6 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args) internal sealed partial class ChunkInfoCommand : LocalizedEntityCommands { - [Dependency] private IMapManager _map = default!; [Dependency] private IEyeManager _eye = default!; [Dependency] private IInputManager _input = default!; [Dependency] private SharedMapSystem _mapSystem = default!; @@ -729,7 +728,7 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args) { var mousePos = _eye.PixelToMap(_input.MouseScreenPosition); - if (!_map.TryFindGridAt(mousePos, out var gridUid, out var grid)) + if (!_mapSystem.TryFindGridAt(mousePos, out var gridUid, out var grid)) { shell.WriteLine("No grid under your mouse cursor."); return; diff --git a/Robust.Client/Debugging/DebugAnchoringSystem.cs b/Robust.Client/Debugging/DebugAnchoringSystem.cs index 0446aa7b676..75c6d07b7e7 100644 --- a/Robust.Client/Debugging/DebugAnchoringSystem.cs +++ b/Robust.Client/Debugging/DebugAnchoringSystem.cs @@ -17,7 +17,6 @@ public sealed partial class DebugAnchoringSystem : EntitySystem { [Dependency] private IEyeManager _eyeManager = default!; [Dependency] private IInputManager _inputManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IUserInterfaceManager _userInterface = default!; [Dependency] private MapSystem _mapSystem = default!; @@ -64,7 +63,7 @@ public override void FrameUpdate(float frameTime) var mouseSpot = _inputManager.MouseScreenPosition; var spot = _eyeManager.PixelToMap(mouseSpot); - if (!_mapManager.TryFindGridAt(spot, out var gridUid, out var grid)) + if (!_mapSystem.TryFindGridAt(spot, out var gridUid, out var grid)) { _label.Text = string.Empty; _hovered = null; diff --git a/Robust.Client/Debugging/DebugPhysicsSystem.cs b/Robust.Client/Debugging/DebugPhysicsSystem.cs index d34944a415d..df1e357be7c 100644 --- a/Robust.Client/Debugging/DebugPhysicsSystem.cs +++ b/Robust.Client/Debugging/DebugPhysicsSystem.cs @@ -84,7 +84,7 @@ public sealed partial class DebugPhysicsSystem : SharedDebugPhysicsSystem [Dependency] private IOverlayManager _overlay = default!; [Dependency] private IEyeManager _eye = default!; [Dependency] private IInputManager _input = default!; - [Dependency] private IMapManager _map = default!; + [Dependency] private SharedMapSystem _map = default!; [Dependency] private IPlayerManager _player = default!; [Dependency] private IResourceCache _resourceCache = default!; @@ -103,13 +103,13 @@ public PhysicsDebugFlags Flags EntityManager, _eye, _input, - _map, _player, _resourceCache, this, _entityLookup, _physics, - _transform)); + _transform, + _map)); if (value == PhysicsDebugFlags.None) _overlay.RemoveOverlay(typeof(PhysicsDebugOverlay)); @@ -203,12 +203,12 @@ internal sealed class PhysicsDebugOverlay : Overlay private readonly IEntityManager _entityManager; private readonly IEyeManager _eyeManager; private readonly IInputManager _inputManager; - private readonly IMapManager _mapManager; private readonly IPlayerManager _playerManager; private readonly DebugPhysicsSystem _debugPhysicsSystem; private readonly EntityLookupSystem _lookup; private readonly SharedPhysicsSystem _physicsSystem; private readonly SharedTransformSystem _transformSystem; + private readonly SharedMapSystem _mapSystem; public override OverlaySpace Space => OverlaySpace.WorldSpace | OverlaySpace.ScreenSpace; @@ -219,17 +219,17 @@ internal sealed class PhysicsDebugOverlay : Overlay private HashSet _drawnJoints = new(); private List> _grids = new(); - public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IMapManager mapManager, IPlayerManager playerManager, IResourceCache cache, DebugPhysicsSystem system, EntityLookupSystem lookup, SharedPhysicsSystem physicsSystem, SharedTransformSystem transformSystem) + public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IPlayerManager playerManager, IResourceCache cache, DebugPhysicsSystem system, EntityLookupSystem lookup, SharedPhysicsSystem physicsSystem, SharedTransformSystem transformSystem, SharedMapSystem mapSystem) { _entityManager = entityManager; _eyeManager = eyeManager; _inputManager = inputManager; - _mapManager = mapManager; _playerManager = playerManager; _debugPhysicsSystem = system; _lookup = lookup; _physicsSystem = physicsSystem; _transformSystem = transformSystem; + _mapSystem = mapSystem; _font = new VectorFont(cache.GetResource("/EngineFonts/NotoSans/NotoSans-Regular.ttf"), 10); } @@ -293,7 +293,7 @@ private void DrawWorld(DrawingHandleWorld worldHandle, OverlayDrawArgs args) } _grids.Clear(); - _mapManager.FindGridsIntersecting(mapId, viewBounds, ref _grids); + _mapSystem.FindGridsIntersecting(mapId, viewBounds, ref _grids); foreach (var grid in _grids) { diff --git a/Robust.Client/Debugging/Overlays/TileDebugOverlay.cs b/Robust.Client/Debugging/Overlays/TileDebugOverlay.cs index 74779c8eccc..d3f1df1639c 100644 --- a/Robust.Client/Debugging/Overlays/TileDebugOverlay.cs +++ b/Robust.Client/Debugging/Overlays/TileDebugOverlay.cs @@ -25,7 +25,6 @@ public abstract partial class TileDebugOverlay : Overlay, IPostInjectInit { [Dependency] protected IEntityManager Entity = default!; [Dependency] protected IEyeManager Eye = default!; - [Dependency] protected IMapManager MapMan = default!; [Dependency] protected IInputManager Input = default!; [Dependency] protected IUserInterfaceManager Ui = default!; [Dependency] protected IResourceCache Cache = default!; @@ -59,7 +58,7 @@ protected internal override void Draw(in OverlayDrawArgs args) if (args.Viewport.Eye?.Position.MapId is not {} map || map == MapId.Nullspace) return; - MapMan.FindGridsIntersecting(map, args.WorldBounds, ref Grids); + Map.FindGridsIntersecting(map, args.WorldBounds, ref Grids); foreach (var grid in Grids) { @@ -108,7 +107,7 @@ protected virtual void DrawTooltip(DrawingHandleScreen handle) var coords = viewport.PixelToMap(mousePos.Position); - if (!MapMan.TryFindGridAt(coords, out var grid, out var comp)) + if (!Map.TryFindGridAt(coords, out var grid, out var comp)) return; var local = Map.WorldToLocal(grid, comp, coords.Position); diff --git a/Robust.Client/GameController/GameController.cs b/Robust.Client/GameController/GameController.cs index 1071ea0df48..52f29e12bcd 100644 --- a/Robust.Client/GameController/GameController.cs +++ b/Robust.Client/GameController/GameController.cs @@ -61,7 +61,6 @@ internal sealed partial class GameController : IGameControllerInternal [Dependency] private IXamlHotReloadManager _xamlHotReloadManager = default!; [Dependency] private IPrototypeManager _prototypeManager = default!; [Dependency] private IClientNetManager _networkManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IStateManager _stateManager = default!; [Dependency] private IUserInterfaceManagerInternal _userInterfaceManager = default!; [Dependency] private IBaseClient _client = default!; @@ -148,7 +147,7 @@ internal bool StartupContinue(DisplayMode displayMode) { DebugTools.AssertNotNull(_resourceManifest); - _loadscr.Initialize(42); + _loadscr.Initialize(41); _loadscr.BeginLoadingSection("Init graphics", dontRender: true); _clyde.InitializePostWindowing(); @@ -236,7 +235,6 @@ internal bool StartupContinue(DisplayMode displayMode) _loadscr.LoadingStep(_userInterfaceManager.Initialize, "UI init"); _loadscr.LoadingStep(_eyeManager.Initialize, _eyeManager); _loadscr.LoadingStep(_entityManager.Initialize, _entityManager); - _loadscr.LoadingStep(_mapManager.Initialize, _mapManager); _loadscr.LoadingStep(_gameStateManager.Initialize, _gameStateManager); _loadscr.LoadingStep(_placementManager.Initialize, _placementManager); _loadscr.LoadingStep(_viewVariablesManager.Initialize, _viewVariablesManager); diff --git a/Robust.Client/GameObjects/EntitySystems/DebugLightTreeSystem.cs b/Robust.Client/GameObjects/EntitySystems/DebugLightTreeSystem.cs index cc41a5482ee..c50fa091e60 100644 --- a/Robust.Client/GameObjects/EntitySystems/DebugLightTreeSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/DebugLightTreeSystem.cs @@ -27,8 +27,6 @@ public bool Enabled { _lightOverlay = new DebugLightOverlay( EntityManager.System(), - IoCManager.Resolve(), - IoCManager.Resolve(), EntityManager.System()); overlayManager.AddOverlay(_lightOverlay); @@ -46,18 +44,14 @@ public bool Enabled private sealed class DebugLightOverlay : Overlay { private EntityLookupSystem _lookup; - private IEyeManager _eyeManager; - private IMapManager _mapManager; private LightTreeSystem _trees; public override OverlaySpace Space => OverlaySpace.WorldSpace; - public DebugLightOverlay(EntityLookupSystem lookup, IEyeManager eyeManager, IMapManager mapManager, LightTreeSystem trees) + public DebugLightOverlay(EntityLookupSystem lookup, LightTreeSystem trees) { _lookup = lookup; - _eyeManager = eyeManager; - _mapManager = mapManager; _trees = trees; } diff --git a/Robust.Client/GameObjects/EntitySystems/GridChunkBoundsDebugSystem.cs b/Robust.Client/GameObjects/EntitySystems/GridChunkBoundsDebugSystem.cs index 1a60f7bd9e7..761244b9b5b 100644 --- a/Robust.Client/GameObjects/EntitySystems/GridChunkBoundsDebugSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/GridChunkBoundsDebugSystem.cs @@ -4,7 +4,6 @@ using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Map; using Robust.Shared.Map.Components; using Robust.Shared.Maths; using Robust.Shared.Physics; @@ -15,8 +14,6 @@ namespace Robust.Client.GameObjects { public sealed partial class GridChunkBoundsDebugSystem : EntitySystem { - [Dependency] private IEyeManager _eyeManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IOverlayManager _overlayManager = default!; [Dependency] private TransformSystem _transform = default!; [Dependency] private SharedMapSystem _map = default!; @@ -37,8 +34,6 @@ public bool Enabled DebugTools.Assert(_overlay == null); _overlay = new GridChunkBoundsOverlay( EntityManager, - _eyeManager, - _mapManager, _transform, _map); @@ -58,8 +53,6 @@ public bool Enabled internal sealed class GridChunkBoundsOverlay : Overlay { private readonly IEntityManager _entityManager; - private readonly IEyeManager _eyeManager; - private readonly IMapManager _mapManager; private readonly SharedTransformSystem _transformSystem; private readonly SharedMapSystem _mapSystem; @@ -67,11 +60,9 @@ internal sealed class GridChunkBoundsOverlay : Overlay private List> _grids = new(); - public GridChunkBoundsOverlay(IEntityManager entManager, IEyeManager eyeManager, IMapManager mapManager, SharedTransformSystem transformSystem, SharedMapSystem mapSystem) + public GridChunkBoundsOverlay(IEntityManager entManager, SharedTransformSystem transformSystem, SharedMapSystem mapSystem) { _entityManager = entManager; - _eyeManager = eyeManager; - _mapManager = mapManager; _transformSystem = transformSystem; _mapSystem = mapSystem; } @@ -84,7 +75,7 @@ protected internal override void Draw(in OverlayDrawArgs args) var fixturesQuery = _entityManager.GetEntityQuery(); _grids.Clear(); - _mapManager.FindGridsIntersecting(currentMap, viewport, ref _grids); + _mapSystem.FindGridsIntersecting(currentMap, viewport, ref _grids); foreach (var grid in _grids) { var worldMatrix = _transformSystem.GetWorldMatrix(grid); diff --git a/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs b/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs index 933eb05b774..d47ba808ec6 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs @@ -52,19 +52,18 @@ private void RenderTileEdgesChanges(bool value) private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBounds, IEye eye) { var mapId = eye.Position.MapId; - if (!_mapManager.MapExists(mapId)) + if (!_mapSystem.MapExists(mapId)) { // fall back to nullspace map mapId = MapId.Nullspace; } _grids.Clear(); - _mapManager.FindGridsIntersecting(mapId, worldBounds, ref _grids); + _mapSystem.FindGridsIntersecting(mapId, worldBounds, ref _grids); var requiresFlush = true; GLShaderProgram gridProgram = default!; var gridOverlays = GetOverlaysForSpace(OverlaySpace.WorldSpaceGrids); - var mapSystem = _entityManager.System(); foreach (var mapGrid in _grids) { @@ -86,7 +85,7 @@ private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBoun } gridProgram.SetUniform(UniIModelMatrix, _transformSystem.GetWorldMatrix(mapGrid)); - var enumerator = mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds); + var enumerator = _mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds); // Handle base texture updates. while (enumerator.MoveNext(out var chunk)) @@ -123,7 +122,7 @@ private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBoun // Handle edge sprites. if (_drawTileEdges) { - enumerator = mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds); + enumerator = _mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds); while (enumerator.MoveNext(out var chunk)) { var datum = data[chunk.Indices]; @@ -132,7 +131,7 @@ private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBoun } } - enumerator = mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds); + enumerator = _mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds); // Draw chunks while (enumerator.MoveNext(out var chunk)) diff --git a/Robust.Client/Graphics/Clyde/Clyde.cs b/Robust.Client/Graphics/Clyde/Clyde.cs index 03f929c536d..4ac8937bd67 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.cs @@ -37,7 +37,6 @@ internal sealed partial class Clyde : IClydeInternal, IPostInjectInit, IEntityEv [Dependency] private IClydeTileDefinitionManager _tileDefinitionManager = default!; [Dependency] private ILightManager _lightManager = default!; [Dependency] private ILogManager _logManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IOverlayManager _overlayManager = default!; [Dependency] private IResourceCache _resourceCache = default!; [Dependency] private IResourceManager _resManager = default!; diff --git a/Robust.Client/Physics/GridFixtureSystem.cs b/Robust.Client/Physics/GridFixtureSystem.cs index 9907f81ef08..ac42b077369 100644 --- a/Robust.Client/Physics/GridFixtureSystem.cs +++ b/Robust.Client/Physics/GridFixtureSystem.cs @@ -13,7 +13,6 @@ namespace Robust.Client.Physics internal sealed partial class GridFixtureSystem : SharedGridFixtureSystem { [Dependency] private IOverlayManager _overlay = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private SharedTransformSystem _transform = default!; [Dependency] private SharedMapSystem _map = default!; @@ -29,7 +28,7 @@ public bool EnableDebug if (_enableDebug) { - var overlay = new GridSplitNodeOverlay(_mapManager, this, _transform, _map); + var overlay = new GridSplitNodeOverlay(this, _transform, _map); _overlay.AddOverlay(overlay); RaiseNetworkEvent(new RequestGridNodesMessage()); } @@ -72,14 +71,12 @@ private sealed class GridSplitNodeOverlay : Overlay { public override OverlaySpace Space => OverlaySpace.WorldSpace; - private readonly IMapManager _mapManager; private readonly GridFixtureSystem _system; private readonly SharedTransformSystem _transform; private readonly SharedMapSystem _map; - public GridSplitNodeOverlay(IMapManager mapManager, GridFixtureSystem system, SharedTransformSystem transform, SharedMapSystem map) + public GridSplitNodeOverlay(GridFixtureSystem system, SharedTransformSystem transform, SharedMapSystem map) { - _mapManager = mapManager; _system = system; _transform = transform; _map = map; @@ -91,7 +88,7 @@ protected internal override void Draw(in OverlayDrawArgs args) var state = (_system, _transform, args.WorldBounds, worldHandle); - _mapManager.FindGridsIntersecting(args.MapId, args.WorldBounds, ref state, + _map.FindGridsIntersecting(args.MapId, args.WorldBounds, ref state, (EntityUid uid, MapGridComponent grid, ref (GridFixtureSystem system, SharedTransformSystem transform, Box2Rotated worldBounds, DrawingHandleWorld worldHandle) tuple) => { diff --git a/Robust.Client/Placement/IPlacementManager.cs b/Robust.Client/Placement/IPlacementManager.cs index 15b8f09167d..756521b2e1c 100644 --- a/Robust.Client/Placement/IPlacementManager.cs +++ b/Robust.Client/Placement/IPlacementManager.cs @@ -24,7 +24,6 @@ public interface IPlacementManager IEntityManager EntityManager { get; } IEyeManager EyeManager { get; } - IMapManager MapManager { get; } /// /// The direction to spawn the entity in (presently exposed for EntitySpawnWindow UI) diff --git a/Robust.Client/Placement/Modes/AlignTileAny.cs b/Robust.Client/Placement/Modes/AlignTileAny.cs index ff51aa89eb0..9523b229514 100644 --- a/Robust.Client/Placement/Modes/AlignTileAny.cs +++ b/Robust.Client/Placement/Modes/AlignTileAny.cs @@ -17,7 +17,7 @@ public override void AlignPlacementMode(ScreenCoordinates mouseScreen) // Go over diagonal size so when placing in a line it doesn't stop snapping. const float searchBoxSize = 2f; // size of search box in meters - MouseCoords = ScreenToCursorGrid(mouseScreen).AlignWithClosestGridTile(searchBoxSize, pManager.EntityManager, pManager.MapManager); + MouseCoords = ScreenToCursorGrid(mouseScreen).AlignWithClosestGridTile(searchBoxSize, pManager.EntityManager); var gridId = pManager.EntityManager.System().GetGrid(MouseCoords); diff --git a/Robust.Client/Placement/PlacementManager.cs b/Robust.Client/Placement/PlacementManager.cs index eda141df12e..26d928fa51b 100644 --- a/Robust.Client/Placement/PlacementManager.cs +++ b/Robust.Client/Placement/PlacementManager.cs @@ -33,7 +33,6 @@ public sealed partial class PlacementManager : IPlacementManager, IDisposable, I [Dependency] internal IPlayerManager PlayerManager = default!; [Dependency] internal IResourceCache ResourceCache = default!; [Dependency] private IReflectionManager _reflectionManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IGameTiming _time = default!; [Dependency] private IEyeManager _eyeManager = default!; [Dependency] internal IInputManager InputManager = default!; @@ -48,7 +47,6 @@ public sealed partial class PlacementManager : IPlacementManager, IDisposable, I public IEntityManager EntityManager => _entityManager; public IEyeManager EyeManager => _eyeManager; - public IMapManager MapManager => _mapManager; private ISawmill _sawmill = default!; diff --git a/Robust.Client/Placement/PlacementMode.cs b/Robust.Client/Placement/PlacementMode.cs index 8ca0de2bd48..810ec1f0220 100644 --- a/Robust.Client/Placement/PlacementMode.cs +++ b/Robust.Client/Placement/PlacementMode.cs @@ -201,7 +201,7 @@ public TileRef GetTileRef(EntityCoordinates coordinates) return gridUidOpt is { } gridUid && gridUid.IsValid() ? pManager.EntityManager.System().GetTileRef(gridUid, pManager.EntityManager.GetComponent(gridUid), MouseCoords) : new TileRef(gridUidOpt ?? EntityUid.Invalid, - MouseCoords.ToVector2i(pManager.EntityManager, pManager.MapManager, pManager.EntityManager.System()), Tile.Empty); + MouseCoords.ToVector2i(pManager.EntityManager, pManager.EntityManager.System()), Tile.Empty); } public TextureResource GetSprite(string key) @@ -267,7 +267,8 @@ protected EntityCoordinates ScreenToCursorGrid(ScreenCoordinates coords) { var mapCoords = pManager.EyeManager.PixelToMap(coords.Position); var transformSys = pManager.EntityManager.System(); - if (!pManager.MapManager.TryFindGridAt(mapCoords, out var gridUid, out _)) + var mapSys = pManager.EntityManager.System(); + if (!mapSys.TryFindGridAt(mapCoords, out var gridUid, out _)) { return transformSys.ToCoordinates(mapCoords); } diff --git a/Robust.Client/UserInterface/CustomControls/DebugMonitorControls/DebugCoordsPanel.cs b/Robust.Client/UserInterface/CustomControls/DebugMonitorControls/DebugCoordsPanel.cs index 86ff546fb2f..f4d643d564d 100644 --- a/Robust.Client/UserInterface/CustomControls/DebugMonitorControls/DebugCoordsPanel.cs +++ b/Robust.Client/UserInterface/CustomControls/DebugMonitorControls/DebugCoordsPanel.cs @@ -19,7 +19,6 @@ internal sealed partial class DebugCoordsPanel : PanelContainer [Dependency] private IInputManager _inputManager = default!; [Dependency] private IEntityManager _entityManager = default!; [Dependency] private IClyde _displayManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IBaseClient _baseClient = default!; private readonly StringBuilder _textBuilder = new(); @@ -76,7 +75,7 @@ protected override void FrameUpdate(FrameEventArgs args) var mapSystem = _entityManager.System(); var xformSystem = _entityManager.System(); - if (_mapManager.TryFindGridAt(mouseWorldMap, out var mouseGridUid, out var mouseGrid)) + if (mapSystem.TryFindGridAt(mouseWorldMap, out var mouseGridUid, out var mouseGrid)) { mouseGridPos = mapSystem.MapToGrid(mouseGridUid, mouseWorldMap); tile = mapSystem.GetTileRef(mouseGridUid, mouseGrid, mouseGridPos); @@ -86,7 +85,7 @@ protected override void FrameUpdate(FrameEventArgs args) mouseGridPos = new EntityCoordinates(mapSystem.GetMapOrInvalid(mouseWorldMap.MapId), mouseWorldMap.Position); tile = new TileRef(EntityUid.Invalid, - mouseGridPos.ToVector2i(_entityManager, _mapManager, xformSystem), Tile.Empty); + mouseGridPos.ToVector2i(_entityManager, xformSystem), Tile.Empty); } } } diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorEntityCoordinates.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorEntityCoordinates.cs index 91620f5b544..840cd81de8a 100644 --- a/Robust.Client/ViewVariables/Editors/VVPropEditorEntityCoordinates.cs +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorEntityCoordinates.cs @@ -63,7 +63,6 @@ protected override Control MakeUI(object? value) void OnEntered(LineEdit.LineEditEventArgs e) { var gridVal = EntityUid.Parse(gridId.Text); - var mapManager = IoCManager.Resolve(); var xVal = float.Parse(x.Text, CultureInfo.InvariantCulture); var yVal = float.Parse(y.Text, CultureInfo.InvariantCulture); diff --git a/Robust.Server.IntegrationTests/GameObjects/Components/Container_Test.cs b/Robust.Server.IntegrationTests/GameObjects/Components/Container_Test.cs index 87f39f7a05c..175551d45d5 100644 --- a/Robust.Server.IntegrationTests/GameObjects/Components/Container_Test.cs +++ b/Robust.Server.IntegrationTests/GameObjects/Components/Container_Test.cs @@ -182,9 +182,11 @@ public void BaseContainer_InsertMap_False() public void BaseContainer_InsertGrid_False() { var sim = SimulationFactory(); - var containerSys = sim.Resolve().GetEntitySystem(); + var entMan = sim.Resolve(); + var mapSys = entMan.System(); + var containerSys = entMan.System(); - var grid = sim.Resolve().CreateGridEntity(new MapId(1)).Owner; + var grid = mapSys.CreateGridEntity(new MapId(1)).Owner; var entity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(entity, "dummy"); diff --git a/Robust.Server.IntegrationTests/GameObjects/Components/Transform_Test.cs b/Robust.Server.IntegrationTests/GameObjects/Components/Transform_Test.cs index 95b857bb95e..c61bb9a0ed9 100644 --- a/Robust.Server.IntegrationTests/GameObjects/Components/Transform_Test.cs +++ b/Robust.Server.IntegrationTests/GameObjects/Components/Transform_Test.cs @@ -19,7 +19,6 @@ internal sealed class Transform_Test : RobustUnitTest public override UnitTestProject Project => UnitTestProject.Server; private IEntityManager EntityManager = default!; - private IMapManager MapManager = default!; private SharedTransformSystem XformSystem => EntityManager.System(); const string Prototypes = @" @@ -47,7 +46,6 @@ public void Setup() IoCManager.Resolve().GenerateNetIds(); EntityManager = IoCManager.Resolve(); - MapManager = IoCManager.Resolve(); IoCManager.Resolve().Initialize(); var manager = IoCManager.Resolve(); @@ -60,8 +58,8 @@ public void Setup() mapSys.CreateMap(out MapA); mapSys.CreateMap(out MapB); - GridA = MapManager.CreateGridEntity(MapA); - GridB = MapManager.CreateGridEntity(MapB); + GridA = mapSys.CreateGridEntity(MapA); + GridB = mapSys.CreateGridEntity(MapB); //NOTE: The grids have not moved, so we can assert worldpos == localpos for the test } diff --git a/Robust.Server.IntegrationTests/GameStates/DetachedParentTest.cs b/Robust.Server.IntegrationTests/GameStates/DetachedParentTest.cs index 4ea2a2dd9e8..ea70798c356 100644 --- a/Robust.Server.IntegrationTests/GameStates/DetachedParentTest.cs +++ b/Robust.Server.IntegrationTests/GameStates/DetachedParentTest.cs @@ -29,7 +29,6 @@ public async Task TestDetachedParent() var mapSys = server.System(); var xformSys = server.System(); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var confMan = server.ResolveDependency(); var sPlayerMan = server.ResolveDependency(); @@ -83,7 +82,7 @@ await server.WaitPost(() => map = mapSys.CreateMap(out mapId); - var gridEnt = mapMan.CreateGridEntity(mapId); + var gridEnt = mapSys.CreateGridEntity(mapId); mapSys.SetTile(gridEnt.Owner, gridEnt.Comp, Vector2i.Zero, new Tile(1)); gridCoords = new EntityCoordinates(gridEnt, .5f, .5f); mapCoords = new EntityCoordinates(map, 200, 200); @@ -303,7 +302,7 @@ await server.WaitPost(() => await server.WaitPost(() => { map2 = mapSys.CreateMap(out mapId2); - var gridEnt = mapMan.CreateGridEntity(mapId2); + var gridEnt = mapSys.CreateGridEntity(mapId2); mapSys.SetTile(gridEnt.Owner, gridEnt.Comp, Vector2i.Zero, new Tile(1)); var grid2Coords = new EntityCoordinates(gridEnt, .5f, .5f); grid2 = gridEnt.Owner; @@ -384,7 +383,7 @@ await server.WaitPost(() => await server.WaitPost(() => { map3 = mapSys.CreateMap(out mapId3); - var gridEnt = mapMan.CreateGridEntity(mapId3); + var gridEnt = mapSys.CreateGridEntity(mapId3); mapSys.SetTile(gridEnt.Owner, gridEnt.Comp, Vector2i.Zero, new Tile(1)); var grid3Coords = new EntityCoordinates(gridEnt, .5f, .5f); grid3 = gridEnt.Owner; diff --git a/Robust.Server.IntegrationTests/GameStates/MissingParentTest.cs b/Robust.Server.IntegrationTests/GameStates/MissingParentTest.cs index 470ee32d37e..561e73c770e 100644 --- a/Robust.Server.IntegrationTests/GameStates/MissingParentTest.cs +++ b/Robust.Server.IntegrationTests/GameStates/MissingParentTest.cs @@ -23,7 +23,6 @@ public async Task TestMissingParent() await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var confMan = server.ResolveDependency(); var sPlayerMan = server.ResolveDependency(); diff --git a/Robust.Server.IntegrationTests/GameStates/PvsChunkTest.cs b/Robust.Server.IntegrationTests/GameStates/PvsChunkTest.cs index 6e7cb201f78..7f2c48439a9 100644 --- a/Robust.Server.IntegrationTests/GameStates/PvsChunkTest.cs +++ b/Robust.Server.IntegrationTests/GameStates/PvsChunkTest.cs @@ -22,7 +22,6 @@ public async Task TestGridMapChange() await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var confMan = server.ResolveDependency(); var sPlayerMan = server.ResolveDependency(); @@ -73,7 +72,7 @@ await server.WaitPost(() => mapCoords = new(map1, default); map2 = server.System().CreateMap(); - var gridComp = mapMan.CreateGridEntity(map2); + var gridComp = mapSys.CreateGridEntity(map2); grid = gridComp.Owner; mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1)); var gridCoords = new EntityCoordinates(grid, .5f, .5f); diff --git a/Robust.Server.IntegrationTests/GameStates/PvsReEntryTest.cs b/Robust.Server.IntegrationTests/GameStates/PvsReEntryTest.cs index 9ab6e1fa025..25116eba97a 100644 --- a/Robust.Server.IntegrationTests/GameStates/PvsReEntryTest.cs +++ b/Robust.Server.IntegrationTests/GameStates/PvsReEntryTest.cs @@ -28,7 +28,6 @@ public async Task TestLossyReEntry() await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var confMan = server.ResolveDependency(); var sPlayerMan = server.ResolveDependency(); diff --git a/Robust.Server.IntegrationTests/GameStates/PvsSystemTests.cs b/Robust.Server.IntegrationTests/GameStates/PvsSystemTests.cs index 6e4dc30273e..957a8e8384e 100644 --- a/Robust.Server.IntegrationTests/GameStates/PvsSystemTests.cs +++ b/Robust.Server.IntegrationTests/GameStates/PvsSystemTests.cs @@ -25,7 +25,6 @@ public async Task TestMultipleIndexChange() await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var confMan = server.ResolveDependency(); var sPlayerMan = server.ResolveDependency(); @@ -52,7 +51,7 @@ public async Task TestMultipleIndexChange() await server.WaitPost(() => { map = server.System().CreateMap(out var mapId); - var gridComp = mapMan.CreateGridEntity(mapId); + var gridComp = maps.CreateGridEntity(mapId); maps.SetTile(gridComp, Vector2i.Zero, new Tile(1)); grid = gridComp.Owner; }); diff --git a/Robust.Server.Testing/RobustServerSimulation.cs b/Robust.Server.Testing/RobustServerSimulation.cs index 66eb92d861d..5b6591eabd4 100644 --- a/Robust.Server.Testing/RobustServerSimulation.cs +++ b/Robust.Server.Testing/RobustServerSimulation.cs @@ -248,9 +248,6 @@ public ISimulation InitializeInstance() container.Register(); container.Register(); container.Register(); - container.Register(); - container.Register(); - container.Register(); container.Register(); container.Register(); container.Register(); @@ -341,11 +338,7 @@ public ISimulation InitializeInstance() _systemDelegate?.Invoke(entitySystemMan); - var mapManager = container.Resolve(); - mapManager.Initialize(); - entityMan.Startup(); - mapManager.Startup(); container.Resolve().Initialize(true); container.Resolve().Initialize(); diff --git a/Robust.Server/BaseServer.cs b/Robust.Server/BaseServer.cs index 7275de37265..65c1d2b221e 100644 --- a/Robust.Server/BaseServer.cs +++ b/Robust.Server/BaseServer.cs @@ -80,7 +80,6 @@ internal sealed partial class BaseServer : IBaseServerInternal, IPostInjectInit [Dependency] private IRobustSerializer _serializer = default!; [Dependency] private IGameTiming _time = default!; [Dependency] private IResourceManagerInternal _resources = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private ITimerManager _timerManager = default!; [Dependency] private IServerGameStateManager _stateManager = default!; [Dependency] private IServerNetManager _network = default!; @@ -379,7 +378,6 @@ public bool Start(ServerOptions options, Func? logHandlerFactory = _log.GetSawmill("res")); _entityManager.Initialize(); - _mapManager.Initialize(); _serialization.Initialize(); @@ -397,7 +395,6 @@ public bool Start(ServerOptions options, Func? logHandlerFactory = IoCManager.Resolve().Initialize(); _consoleHost.Initialize(); _entityManager.Startup(); - _mapManager.Startup(); _stateManager.Initialize(); _replay.Initialize(); diff --git a/Robust.Server/GameStates/PvsSystem.Chunks.cs b/Robust.Server/GameStates/PvsSystem.Chunks.cs index 99466b1f6b7..a270c7410b7 100644 --- a/Robust.Server/GameStates/PvsSystem.Chunks.cs +++ b/Robust.Server/GameStates/PvsSystem.Chunks.cs @@ -133,7 +133,7 @@ private void GetVisibleChunks(Entity eye, _grids.Clear(); var rangeVec = new Vector2(range, range); var box = new Box2(viewPos - rangeVec, viewPos + rangeVec); - _mapManager.FindGridsIntersecting(map, box, ref _grids, approx: true, includeMap: false); + _maps.FindGridsIntersecting(map, box, ref _grids, approx: true, includeMap: false); foreach (var (grid, _) in _grids) { diff --git a/Robust.Server/GameStates/PvsSystem.cs b/Robust.Server/GameStates/PvsSystem.cs index 2095023f220..02615e9ea73 100644 --- a/Robust.Server/GameStates/PvsSystem.cs +++ b/Robust.Server/GameStates/PvsSystem.cs @@ -28,7 +28,6 @@ namespace Robust.Server.GameStates; internal sealed partial class PvsSystem : EntitySystem { [Dependency] private IConfigurationManager _configManager = default!; - [Dependency] private INetworkedMapManager _mapManager = default!; [Dependency] private IServerEntityNetworkManager _netEntMan = default!; [Dependency] private IPlayerManager _playerManager = default!; [Dependency] private IParallelManager _parallelManager = default!; @@ -40,6 +39,7 @@ internal sealed partial class PvsSystem : EntitySystem [Dependency] private IParallelManagerInternal _parallelMgr = default!; [Dependency] private PvsOverrideSystem _pvsOverride = default!; [Dependency] private IServerReplayRecordingManager _replay = default!; + [Dependency] private SharedMapSystem _maps = default!; // TODO make this a cvar. Make it in terms of seconds and tie it to tick rate? // Main issue is that I CBF figuring out the logic for handling it changing mid-game. @@ -288,7 +288,7 @@ private void CullDeletionHistory(GameTick oldestAck) { using var _ = Histogram.WithLabels("Cull History").NewTimer(); CullDeletionHistoryUntil(oldestAck); - _mapManager.CullDeletionHistory(oldestAck); + _maps.CullDeletionHistory(oldestAck); } private void GetEntityStates(PvsSession session) diff --git a/Robust.Server/Physics/GridFixtureSystem.cs b/Robust.Server/Physics/GridFixtureSystem.cs index 873e2e7c31e..159a4ca15c1 100644 --- a/Robust.Server/Physics/GridFixtureSystem.cs +++ b/Robust.Server/Physics/GridFixtureSystem.cs @@ -25,7 +25,6 @@ namespace Robust.Server.Physics /// public sealed partial class GridFixtureSystem : SharedGridFixtureSystem { - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IConfigurationManager _cfg = default!; [Dependency] private IConGroupController _conGroup = default!; [Dependency] private EntityLookupSystem _lookup = default!; @@ -262,7 +261,7 @@ private void CheckSplits(EntityUid uid, HashSet dirtyNodes) for (var i = 0; i < grids.Count - 1; i++) { var group = grids[i]; - var newGrid = _mapManager.CreateGridEntity(mapId); + var newGrid = _maps.CreateGridEntity(mapId); var newGridUid = newGrid.Owner; var newGridXform = _xformQuery.GetComponent(newGridUid); newGrids[i] = newGridUid; diff --git a/Robust.Server/Placement/PlacementManager.cs b/Robust.Server/Placement/PlacementManager.cs index a7868c8730a..f4d426f669b 100644 --- a/Robust.Server/Placement/PlacementManager.cs +++ b/Robust.Server/Placement/PlacementManager.cs @@ -28,7 +28,6 @@ public sealed partial class PlacementManager : IPlacementManager [Dependency] private IPlayerManager _playerManager = default!; [Dependency] private IPrototypeManager _prototype = default!; [Dependency] private IServerEntityManager _entityManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private ILogManager _logManager = default!; private EntityLookupSystem _lookup => _entityManager.System(); @@ -190,27 +189,29 @@ private void PlaceNewTile(int tileType, EntityCoordinates coordinates, NetUserId { if (!coordinates.IsValid(_entityManager)) return; + var mapSystem = _maps; + MapGridComponent? grid; EntityUid gridId = coordinates.EntityId; if (_entityManager.TryGetComponent(coordinates.EntityId, out grid) - || _mapManager.TryFindGridAt(_xformSystem.ToMapCoordinates(coordinates), out gridId, out grid)) + || mapSystem.TryFindGridAt(_xformSystem.ToMapCoordinates(coordinates), out gridId, out grid)) { - _maps.SetTile(gridId, grid, coordinates, new Tile(tileType, rotationMirroring: (byte)(direction + (mirrored ? 4 : 0)))); + mapSystem.SetTile(gridId, grid, coordinates, new Tile(tileType, rotationMirroring: (byte)(direction + (mirrored ? 4 : 0)))); var placementEraseEvent = new PlacementTileEvent(tileType, coordinates, placingUserId); _entityManager.EventBus.RaiseEvent(EventSource.Local, placementEraseEvent); } else if (tileType != 0) // create a new grid { - var newGrid = _mapManager.CreateGridEntity(_xformSystem.GetMapId(coordinates)); + var newGrid = mapSystem.CreateGridEntity(_xformSystem.GetMapId(coordinates)); var newGridXform = new Entity( newGrid.Owner, _entityManager.GetComponent(newGrid)); _xformSystem.SetWorldPosition(newGridXform, coordinates.Position - newGrid.Comp.TileSizeHalfVector); // assume bottom left tile origin - var tilePos = _maps.WorldToTile(newGrid.Owner, newGrid.Comp, coordinates.Position); - _maps.SetTile(newGrid.Owner, newGrid.Comp, tilePos, new Tile(tileType, rotationMirroring: (byte)(direction + (mirrored ? 4 : 0)))); + var tilePos = mapSystem.WorldToTile(newGrid.Owner, newGrid.Comp, coordinates.Position); + mapSystem.SetTile(newGrid.Owner, newGrid.Comp, tilePos, new Tile(tileType, rotationMirroring: (byte)(direction + (mirrored ? 4 : 0)))); var placementEraseEvent = new PlacementTileEvent(tileType, coordinates, placingUserId); _entityManager.EventBus.RaiseEvent(EventSource.Local, placementEraseEvent); diff --git a/Robust.Server/ServerIoC.cs b/Robust.Server/ServerIoC.cs index 2c26ca5df06..9bda629e414 100644 --- a/Robust.Server/ServerIoC.cs +++ b/Robust.Server/ServerIoC.cs @@ -56,9 +56,6 @@ internal static void RegisterIoC(IDependencyCollection deps) deps.Register(); deps.Register(); deps.Register(); - deps.Register(); - deps.Register(); - deps.Register(); deps.Register(); deps.Register(); deps.Register(); diff --git a/Robust.Shared.IntegrationTests/EntityLookup_Test.cs b/Robust.Shared.IntegrationTests/EntityLookup_Test.cs index cd06309a60f..a6e4b60aa33 100644 --- a/Robust.Shared.IntegrationTests/EntityLookup_Test.cs +++ b/Robust.Shared.IntegrationTests/EntityLookup_Test.cs @@ -65,9 +65,9 @@ private EntityUid GetPhysicsEntity(IEntityManager entManager, MapCoordinates spa return ent; } - private Entity SetupGrid(MapId mapId, SharedMapSystem mapSystem, IEntityManager entManager, IMapManager mapManager) + private Entity SetupGrid(MapId mapId, SharedMapSystem mapSystem, IEntityManager entManager) { - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); entManager.System().SetLocalPosition(grid.Owner, new Vector2(10f, 10f)); mapSystem.SetTile(grid, Vector2i.Zero, new Tile(1)); return grid; @@ -88,11 +88,10 @@ public void TestEntityAnyIntersecting(bool physics, MapCoordinates spawnPos, Box var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); mapSystem.CreateMap(spawnPos.MapId); - var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager, mapManager); + var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager); if (physics) GetPhysicsEntity(entManager, spawnPos); @@ -113,11 +112,10 @@ public void TestEntityAnyLocalIntersecting(bool physics, MapCoordinates spawnPos var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); mapSystem.CreateMap(spawnPos.MapId); - var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager, mapManager); + var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager); if (physics) GetPhysicsEntity(entManager, spawnPos); @@ -141,11 +139,10 @@ public void TestEntityGridLocalIntersecting(bool physics, MapCoordinates spawnPo var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); mapSystem.CreateMap(spawnPos.MapId); - var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager, mapManager); + var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager); if (physics) GetPhysicsEntity(entManager, spawnPos); @@ -170,11 +167,10 @@ public void TestEntityGridTileIntersecting(bool physics, MapCoordinates spawnPos var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); mapSystem.CreateMap(spawnPos.MapId); - var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager, mapManager); + var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager); if (physics) GetPhysicsEntity(entManager, spawnPos); @@ -221,11 +217,10 @@ public void TestGridIntersecting(bool physics, MapCoordinates spawnPos, MapCoord var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); mapSystem.CreateMap(spawnPos.MapId); - var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager, mapManager); + var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager); if (physics) GetPhysicsEntity(entManager, spawnPos); @@ -247,11 +242,10 @@ public void TestGridInRange(bool physics, MapCoordinates spawnPos, MapCoordinate var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); mapSystem.CreateMap(spawnPos.MapId); - var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager, mapManager); + var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager); if (physics) GetPhysicsEntity(entManager, spawnPos); @@ -295,11 +289,10 @@ public void TestGridAnyIntersecting(bool physics, MapCoordinates spawnPos, Box2 var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); mapSystem.CreateMap(spawnPos.MapId); - var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager, mapManager); + var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager); if (physics) GetPhysicsEntity(entManager, spawnPos); @@ -323,11 +316,10 @@ public void TestGridLocalIntersecting(bool physics, MapCoordinates spawnPos, Box var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); mapSystem.CreateMap(spawnPos.MapId); - var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager, mapManager); + var grid = SetupGrid(spawnPos.MapId, mapSystem, entManager); if (physics) GetPhysicsEntity(entManager, spawnPos); @@ -354,12 +346,11 @@ public void TestAnchoring() var lookup = server.Resolve().GetEntitySystem(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); var transformSystem = entManager.System(); var mapId = server.CreateMap().MapId; - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var theMapSpotBeingUsed = new Box2(Vector2.Zero, Vector2.One); mapSystem.SetTile(grid, new Vector2i(), new Tile(1)); diff --git a/Robust.Shared.IntegrationTests/EntitySerialization/AutoIncludeSerializationTest.cs b/Robust.Shared.IntegrationTests/EntitySerialization/AutoIncludeSerializationTest.cs index 3e4b12c25d4..f049e1dfd37 100644 --- a/Robust.Shared.IntegrationTests/EntitySerialization/AutoIncludeSerializationTest.cs +++ b/Robust.Shared.IntegrationTests/EntitySerialization/AutoIncludeSerializationTest.cs @@ -34,7 +34,6 @@ public async Task TestAutoIncludeSerialization() var entMan = server.EntMan; var mapSys = server.System(); var loader = server.System(); - var mapMan = server.ResolveDependency(); var tileMan = server.ResolveDependency(); var mapPath = new ResPath($"{nameof(AutoIncludeSerializationTest)}_map.yml"); var gridPath = new ResPath($"{nameof(AutoIncludeSerializationTest)}_grid.yml"); @@ -55,7 +54,7 @@ public async Task TestAutoIncludeSerialization() await server.WaitPost(() => { var mapUid = mapSys.CreateMap(out mapId); - var gridUid = mapMan.CreateGridEntity(mapId); + var gridUid = mapSys.CreateGridEntity(mapId); mapSys.SetTile(gridUid, Vector2i.Zero, new Tile(tDef.TileId)); var onGridUid = entMan.SpawnEntity(null, new EntityCoordinates(gridUid, 0.5f, 0.5f)); diff --git a/Robust.Shared.IntegrationTests/EntitySerialization/CategorizationTest.cs b/Robust.Shared.IntegrationTests/EntitySerialization/CategorizationTest.cs index 5b48ec6c1e6..aee367cbd32 100644 --- a/Robust.Shared.IntegrationTests/EntitySerialization/CategorizationTest.cs +++ b/Robust.Shared.IntegrationTests/EntitySerialization/CategorizationTest.cs @@ -35,7 +35,6 @@ public async Task TestCategorization() var meta = server.System(); var mapSys = server.System(); var loader = server.System(); - var mapMan = server.ResolveDependency(); var tileMan = server.ResolveDependency(); var path = new ResPath($"{nameof(TestCategorization)}.yml"); @@ -56,8 +55,8 @@ await server.WaitPost(() => { mapA = mapSys.CreateMap(out var mapIdA); mapB = mapSys.CreateMap(out var mapIdB); - var gridEntA = mapMan.CreateGridEntity(mapIdA); - var gridEntB = mapMan.CreateGridEntity(mapIdB); + var gridEntA = mapSys.CreateGridEntity(mapIdA); + var gridEntB = mapSys.CreateGridEntity(mapIdB); mapSys.SetTile(gridEntA, Vector2i.Zero, new Tile(tDef.TileId)); mapSys.SetTile(gridEntB, Vector2i.Zero, new Tile(tDef.TileId)); gridA = gridEntA.Owner; diff --git a/Robust.Shared.IntegrationTests/EntitySerialization/MapMergeTest.cs b/Robust.Shared.IntegrationTests/EntitySerialization/MapMergeTest.cs index 97f2d94202f..aad38625cf4 100644 --- a/Robust.Shared.IntegrationTests/EntitySerialization/MapMergeTest.cs +++ b/Robust.Shared.IntegrationTests/EntitySerialization/MapMergeTest.cs @@ -35,7 +35,6 @@ public async Task TestMapMerge() var entMan = server.EntMan; var mapSys = server.System(); var loader = server.System(); - var mapMan = server.ResolveDependency(); var tileMan = server.ResolveDependency(); var mapPath = new ResPath($"{nameof(TestMapMerge)}_map.yml"); @@ -52,7 +51,7 @@ public async Task TestMapMerge() await server.WaitPost(() => { var mapUid = mapSys.CreateMap(out mapId, runMapInit: false); - var gridEnt = mapMan.CreateGridEntity(mapId); + var gridEnt = mapSys.CreateGridEntity(mapId); mapSys.SetTile(gridEnt, Vector2i.Zero, new Tile(tDef.TileId)); var entUid = entMan.SpawnEntity(null, new MapCoordinates(10, 10, mapId)); map = Get(mapUid, entMan); diff --git a/Robust.Shared.IntegrationTests/EntitySerialization/OrphanSerializationTest.cs b/Robust.Shared.IntegrationTests/EntitySerialization/OrphanSerializationTest.cs index 2cbb7f1db82..518abaf559f 100644 --- a/Robust.Shared.IntegrationTests/EntitySerialization/OrphanSerializationTest.cs +++ b/Robust.Shared.IntegrationTests/EntitySerialization/OrphanSerializationTest.cs @@ -129,7 +129,6 @@ public async Task TestOrphanedGridSerialization() var mapSys = server.System(); var loader = server.System(); var xform = server.System(); - var mapMan = server.ResolveDependency(); var tileMan = server.ResolveDependency(); var pathA = new ResPath($"{nameof(TestOrphanedGridSerialization)}_A.yml"); var pathB = new ResPath($"{nameof(TestOrphanedGridSerialization)}_B.yml"); @@ -150,12 +149,12 @@ await server.WaitPost(() => var mapUid = mapSys.CreateMap(out mapId); map = Get(mapUid, entMan); - var gridAUid = mapMan.CreateGridEntity(mapId); + var gridAUid = mapSys.CreateGridEntity(mapId); mapSys.SetTile(gridAUid, Vector2i.Zero, new Tile(tDef.TileId)); gridA = Get(gridAUid, entMan); xform.SetLocalPosition(gridA.Owner, new(100, 100)); - var gridBUid = mapMan.CreateGridEntity(mapId); + var gridBUid = mapSys.CreateGridEntity(mapId); mapSys.SetTile(gridBUid, Vector2i.Zero, new Tile(tDef.TileId)); gridB = Get(gridBUid, entMan); diff --git a/Robust.Shared.IntegrationTests/GameObjects/ContainerTests.cs b/Robust.Shared.IntegrationTests/GameObjects/ContainerTests.cs index 28b38f3f78b..8b52fba8d78 100644 --- a/Robust.Shared.IntegrationTests/GameObjects/ContainerTests.cs +++ b/Robust.Shared.IntegrationTests/GameObjects/ContainerTests.cs @@ -161,7 +161,6 @@ public async Task TestContainerExpectedEntityDeleted() var clientTime = client.ResolveDependency(); var clientNetManager = client.ResolveDependency(); - var sMapManager = server.ResolveDependency(); var sEntManager = server.ResolveDependency(); var sPlayerManager = server.ResolveDependency(); var serverTime = server.ResolveDependency(); diff --git a/Robust.Shared.IntegrationTests/GameObjects/DeferredEntityDeletionTest.cs b/Robust.Shared.IntegrationTests/GameObjects/DeferredEntityDeletionTest.cs index 5bb02e61d2c..1b354c9d81c 100644 --- a/Robust.Shared.IntegrationTests/GameObjects/DeferredEntityDeletionTest.cs +++ b/Robust.Shared.IntegrationTests/GameObjects/DeferredEntityDeletionTest.cs @@ -39,7 +39,6 @@ public async Task TestDeferredEntityDeletion() await server.WaitAssertion(() => { - var mapMan = IoCManager.Resolve(); entMan = IoCManager.Resolve(); var sys = entMan.EntitySysManager.GetEntitySystem(); diff --git a/Robust.Shared.IntegrationTests/GameObjects/Systems/AnchoredSystemTests.cs b/Robust.Shared.IntegrationTests/GameObjects/Systems/AnchoredSystemTests.cs index 9f04c1f2d55..d3abfc2e0e1 100644 --- a/Robust.Shared.IntegrationTests/GameObjects/Systems/AnchoredSystemTests.cs +++ b/Robust.Shared.IntegrationTests/GameObjects/Systems/AnchoredSystemTests.cs @@ -38,14 +38,14 @@ private static (ISimulation, Entity grid, MapCoordinates, Shar }) .InitializeInstance(); - var mapManager = sim.Resolve(); + var mapSystem = sim.System(); var testMapId = sim.CreateMap().MapId; var coords = new MapCoordinates(new Vector2(7, 7), testMapId); // Add grid 1, as the default grid to anchor things to. - var grid = mapManager.CreateGridEntity(testMapId); + var grid = mapSystem.CreateGridEntity(testMapId); - return (sim, grid, coords, sim.System(), sim.System()); + return (sim, grid, coords, sim.System(), mapSystem); } // An entity is anchored to the tile it is over on the target grid. @@ -160,9 +160,8 @@ public void OnInitAnchored_AddedToLookup() var mapSys = sim.System(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); var mapId = sim.CreateMap().MapId; - var grid = mapMan.CreateGridEntity(mapId); + var grid = mapSys.CreateGridEntity(mapId); var coordinates = new MapCoordinates(new Vector2(7, 7), mapId); var pos = mapSys.TileIndicesFor(grid, coordinates); mapSys.SetTile(grid, pos, new Tile(1)); diff --git a/Robust.Shared.IntegrationTests/GameObjects/TransformComponent_Tests.cs b/Robust.Shared.IntegrationTests/GameObjects/TransformComponent_Tests.cs index aeb951a1155..01f0559e625 100644 --- a/Robust.Shared.IntegrationTests/GameObjects/TransformComponent_Tests.cs +++ b/Robust.Shared.IntegrationTests/GameObjects/TransformComponent_Tests.cs @@ -54,12 +54,11 @@ public void AttachToGridOrMap() var server = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); var mapSystem = entManager.System(); var xformSystem = entManager.System(); mapSystem.CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); mapSystem.SetTile(grid, new Vector2i(0, 0), new Tile(1)); xformSystem.SetLocalPosition(grid, new Vector2(0f, 100f)); diff --git a/Robust.Shared.IntegrationTests/GameState/DeletionNetworkingTests.cs b/Robust.Shared.IntegrationTests/GameState/DeletionNetworkingTests.cs index 48b050625d0..86c4de18a61 100644 --- a/Robust.Shared.IntegrationTests/GameState/DeletionNetworkingTests.cs +++ b/Robust.Shared.IntegrationTests/GameState/DeletionNetworkingTests.cs @@ -28,7 +28,6 @@ public async Task DeletionNetworkingTest() await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var cEntMan = client.ResolveDependency(); var netMan = client.ResolveDependency(); @@ -61,13 +60,13 @@ async Task RunTicks() await server.WaitPost(() => { mapSys.CreateMap(out var mapId); - var gridComp = mapMan.CreateGridEntity(mapId); + var gridComp = mapSys.CreateGridEntity(mapId); mapSys.SetTile(gridComp, Vector2i.Zero, new Tile(1)); grid1 = gridComp.Owner; xformSys.SetLocalPosition(grid1, new Vector2(-2,0)); grid1Net = sEntMan.GetNetEntity(grid1); - gridComp = mapMan.CreateGridEntity(mapId); + gridComp = mapSys.CreateGridEntity(mapId); mapSys.SetTile(gridComp, Vector2i.Zero, new Tile(1)); grid2 = gridComp.Owner; xformSys.SetLocalPosition(grid2, new Vector2(2,0)); diff --git a/Robust.Shared.IntegrationTests/Map/EntityCoordinates_Tests.cs b/Robust.Shared.IntegrationTests/Map/EntityCoordinates_Tests.cs index f43ccb44fcd..c2c3035dab4 100644 --- a/Robust.Shared.IntegrationTests/Map/EntityCoordinates_Tests.cs +++ b/Robust.Shared.IntegrationTests/Map/EntityCoordinates_Tests.cs @@ -46,7 +46,6 @@ public void IsValid_InvalidEntId_False() public void IsValid_EntityDeleted_False() { var entityManager = IoCManager.Resolve(); - var mapManager = IoCManager.Resolve(); var mapEntity = entityManager.System().CreateMap(out var mapId); var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, mapId)); @@ -122,11 +121,11 @@ public void GetGridId_Map() public void GetGridId_Grid() { var entityManager = IoCManager.Resolve(); - var mapManager = IoCManager.Resolve(); + var mapSystem = entityManager.System(); var xformSys = entityManager.System(); entityManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(gridEnt, Vector2.Zero)); @@ -152,11 +151,11 @@ public void GetMapId_Map() public void GetMapId_Grid() { var entityManager = IoCManager.Resolve(); - var mapManager = IoCManager.Resolve(); + var mapSystem = entityManager.System(); var xformSys = entityManager.System(); entityManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(gridEnt, Vector2.Zero)); @@ -168,11 +167,11 @@ public void GetMapId_Grid() public void GetParent() { var entityManager = IoCManager.Resolve(); - var mapManager = IoCManager.Resolve(); + var mapSystem = entityManager.System(); var xformSys = entityManager.System(); var mapEnt = entityManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero)); @@ -190,11 +189,11 @@ public void GetParent() public void TryGetParent() { var entityManager = IoCManager.Resolve(); - var mapManager = IoCManager.Resolve(); + var mapSystem = entityManager.System(); var xformSys = entityManager.System(); var mapEnt = entityManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero)); @@ -241,11 +240,11 @@ public void ToMap_MoveGrid(float x1, float y1, float x2, float y2) var entPos = new Vector2(x2, y2); var entityManager = IoCManager.Resolve(); - var mapManager = IoCManager.Resolve(); + var mapSystem = entityManager.System(); var xformSys = entityManager.System(); entityManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, entPos)); var newXform = entityManager.GetComponent(newEnt); @@ -263,11 +262,11 @@ public void ToMap_MoveGrid(float x1, float y1, float x2, float y2) public void WithEntityId() { var entityManager = IoCManager.Resolve(); - var mapManager = IoCManager.Resolve(); + var mapSystem = entityManager.System(); var xformSys = entityManager.System(); var mapEnt = entityManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero)); var newEntXform = entityManager.GetComponent(newEnt); diff --git a/Robust.Shared.IntegrationTests/Map/GridCollision_Test.cs b/Robust.Shared.IntegrationTests/Map/GridCollision_Test.cs index b3726f19964..f2c6294ef17 100644 --- a/Robust.Shared.IntegrationTests/Map/GridCollision_Test.cs +++ b/Robust.Shared.IntegrationTests/Map/GridCollision_Test.cs @@ -19,7 +19,6 @@ public async Task TestGridsCollide() await server.WaitIdleAsync(); - var mapManager = server.ResolveDependency(); var entManager = server.ResolveDependency(); var physSystem = server.ResolveDependency().GetEntitySystem(); var mapSystem = server.ResolveDependency().GetEntitySystem(); @@ -35,8 +34,8 @@ public async Task TestGridsCollide() await server.WaitPost(() => { entManager.System().CreateMap(out mapId); - gridId1 = mapManager.CreateGridEntity(mapId); - gridId2 = mapManager.CreateGridEntity(mapId); + gridId1 = mapSystem.CreateGridEntity(mapId); + gridId2 = mapSystem.CreateGridEntity(mapId); gridEnt1 = gridId1.Value.Owner; gridEnt2 = gridId2.Value.Owner; physics1 = entManager.GetComponent(gridEnt1.Value); diff --git a/Robust.Shared.IntegrationTests/Map/GridContraction_Test.cs b/Robust.Shared.IntegrationTests/Map/GridContraction_Test.cs index a2eb87253f6..3256bd6abd6 100644 --- a/Robust.Shared.IntegrationTests/Map/GridContraction_Test.cs +++ b/Robust.Shared.IntegrationTests/Map/GridContraction_Test.cs @@ -17,13 +17,12 @@ public async Task TestGridDeletes() await server.WaitIdleAsync(); var entManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var mapSystem = entManager.EntitySysManager.GetEntitySystem(); await server.WaitAssertion(() => { entManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEntity = grid.Owner; for (var i = 0; i < 10; i++) @@ -56,13 +55,12 @@ public async Task TestGridNoDeletes() await server.WaitIdleAsync(); var entManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var mapSystem = entManager.System(); await server.WaitAssertion(() => { entManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); for (var i = 0; i < 10; i++) { diff --git a/Robust.Shared.IntegrationTests/Map/GridFixtures_Tests.cs b/Robust.Shared.IntegrationTests/Map/GridFixtures_Tests.cs index f7374c83b6e..34c12cd20b1 100644 --- a/Robust.Shared.IntegrationTests/Map/GridFixtures_Tests.cs +++ b/Robust.Shared.IntegrationTests/Map/GridFixtures_Tests.cs @@ -29,8 +29,8 @@ public void TestGridFixtureDeletion() var server = RobustServerSimulation.NewSimulation().InitializeInstance(); var map = server.CreateMap(); var entManager = server.Resolve(); - var grid = server.Resolve().CreateGridEntity(map.MapId); var mapSystem = entManager.System(); + var grid = mapSystem.CreateGridEntity(map.MapId); var fixtures = entManager.GetComponent(grid); mapSystem.SetTiles(grid, new List<(Vector2i GridIndices, Tile Tile)>() @@ -57,14 +57,13 @@ public async Task TestGridFixtures() await server.WaitIdleAsync(); var entManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var physSystem = server.ResolveDependency().GetEntitySystem(); var mapSystem = entManager.EntitySysManager.GetEntitySystem(); await server.WaitAssertion(() => { entManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); // Should be nothing if grid empty Assert.That(entManager.TryGetComponent(grid, out PhysicsComponent? gridBody)); diff --git a/Robust.Shared.IntegrationTests/Map/GridMerge_Tests.cs b/Robust.Shared.IntegrationTests/Map/GridMerge_Tests.cs index 0ff7aa9c4c9..fc70be68010 100644 --- a/Robust.Shared.IntegrationTests/Map/GridMerge_Tests.cs +++ b/Robust.Shared.IntegrationTests/Map/GridMerge_Tests.cs @@ -40,14 +40,13 @@ private ISimulation GetSim() public void Merge(Vector2i offset, Angle angle, Box2 bounds) { var sim = GetSim(); - var mapManager = sim.Resolve(); var entMan = sim.Resolve(); var mapSystem = entMan.System(); var gridFixtures = entMan.System(); var mapId = sim.CreateMap().MapId; - var grid1 = mapManager.CreateGridEntity(mapId); - var grid2 = mapManager.CreateGridEntity(mapId); + var grid1 = mapSystem.CreateGridEntity(mapId); + var grid2 = mapSystem.CreateGridEntity(mapId); var tiles = new List<(Vector2i, Tile)>(); for (var y = 0; y < 3; y++) @@ -58,11 +57,11 @@ public void Merge(Vector2i offset, Angle angle, Box2 bounds) mapSystem.SetTiles(grid1, tiles); mapSystem.SetTiles(grid2, tiles); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(2)); gridFixtures.Merge(grid1.Owner, grid2.Owner, offset, angle, grid1.Comp, grid2.Comp); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); Assert.That(grid1.Comp.LocalAABB, Is.EqualTo(bounds)); } diff --git a/Robust.Shared.IntegrationTests/Map/GridRotation_Tests.cs b/Robust.Shared.IntegrationTests/Map/GridRotation_Tests.cs index d73e86ff9b2..c3ca74f10e5 100644 --- a/Robust.Shared.IntegrationTests/Map/GridRotation_Tests.cs +++ b/Robust.Shared.IntegrationTests/Map/GridRotation_Tests.cs @@ -24,14 +24,13 @@ public async Task TestLocalWorldConversions() await server.WaitIdleAsync(); var entMan = server.ResolveDependency(); - var mapMan = server.ResolveDependency(); var mapSystem = entMan.System(); var transformSystem = entMan.System(); await server.WaitAssertion(() => { mapSystem.CreateMap(out var mapId); - var grid = mapMan.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEnt = grid.Owner; var coordinates = new EntityCoordinates(gridEnt, new Vector2(10, 0)); @@ -65,13 +64,12 @@ public async Task TestChunkRotations() await server.WaitIdleAsync(); var entMan = server.ResolveDependency(); - var mapMan = server.ResolveDependency(); var mapSystem = entMan.System(); await server.WaitAssertion(() => { mapSystem.CreateMap(out var mapId); - var grid = mapMan.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridEnt = grid.Owner; /* Test for map chunk rotations */ diff --git a/Robust.Shared.IntegrationTests/Map/GridSplit_Tests.cs b/Robust.Shared.IntegrationTests/Map/GridSplit_Tests.cs index 447c4ea9473..beca059b306 100644 --- a/Robust.Shared.IntegrationTests/Map/GridSplit_Tests.cs +++ b/Robust.Shared.IntegrationTests/Map/GridSplit_Tests.cs @@ -31,11 +31,10 @@ private ISimulation GetSim() public void NoSplit() { var sim = GetSim(); - var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; - var gridEnt = mapManager.CreateGridEntity(mapId); + var gridEnt = mapSystem.CreateGridEntity(mapId); var grid = gridEnt.Comp; grid.CanSplit = false; @@ -44,14 +43,14 @@ public void NoSplit() mapSystem.SetTile(gridEnt, new Vector2i(x, 0), new Tile(1)); } - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); mapSystem.SetTile(gridEnt, new Vector2i(1, 0), Tile.Empty); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); grid.CanSplit = true; mapSystem.SetTile(gridEnt, new Vector2i(2, 0), Tile.Empty); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(2)); mapSystem.DeleteMap(mapId); } @@ -60,20 +59,19 @@ public void NoSplit() public void SimpleSplit() { var sim = GetSim(); - var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; - var gridEnt = mapManager.CreateGridEntity(mapId); + var gridEnt = mapSystem.CreateGridEntity(mapId); for (var x = 0; x < 3; x++) { mapSystem.SetTile(gridEnt, new Vector2i(x, 0), new Tile(1)); } - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); mapSystem.SetTile(gridEnt, new Vector2i(1, 0), Tile.Empty); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(2)); mapSystem.DeleteMap(mapId); } @@ -82,10 +80,9 @@ public void SimpleSplit() public void DonutSplit() { var sim = GetSim(); - var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; - var gridEnt = mapManager.CreateGridEntity(mapId); + var gridEnt = mapSystem.CreateGridEntity(mapId); for (var x = 0; x < 3; x++) { @@ -95,16 +92,16 @@ public void DonutSplit() } } - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); mapSystem.SetTile(gridEnt, Vector2i.One, Tile.Empty); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); mapSystem.SetTile(gridEnt, new Vector2i(1, 2), Tile.Empty); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); mapSystem.SetTile(gridEnt, new Vector2i(1, 0), Tile.Empty); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(2)); mapSystem.DeleteMap(mapId); } @@ -113,10 +110,9 @@ public void DonutSplit() public void TriSplit() { var sim = GetSim(); - var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; - var gridEnt = mapManager.CreateGridEntity(mapId); + var gridEnt = mapSystem.CreateGridEntity(mapId); for (var x = 0; x < 3; x++) { @@ -125,10 +121,10 @@ public void TriSplit() mapSystem.SetTile(gridEnt, Vector2i.One, new Tile(1)); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); mapSystem.SetTile(gridEnt, new Vector2i(1, 0), Tile.Empty); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(3)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(3)); mapSystem.DeleteMap(mapId); } @@ -141,11 +137,10 @@ public void ReparentSplit() { var sim = GetSim(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); var transformSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; - var gridEnt = mapManager.CreateGridEntity(mapId); + var gridEnt = mapSystem.CreateGridEntity(mapId); var grid = gridEnt.Comp; for (var x = 0; x < 4; x++) @@ -153,7 +148,7 @@ public void ReparentSplit() mapSystem.SetTile(gridEnt, new Vector2i(x, 0), new Tile(1)); } - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(1)); var dummy = entManager.SpawnEntity(null, new EntityCoordinates(gridEnt, new Vector2(3.5f, 0.5f))); var dummyXform = entManager.GetComponent(dummy); @@ -164,9 +159,9 @@ public void ReparentSplit() Assert.That(anchoredXform.Anchored); mapSystem.SetTile(gridEnt, new Vector2i(2, 0), Tile.Empty); - Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2)); + Assert.That(mapSystem.GetAllGrids(mapId).Count(), Is.EqualTo(2)); - var newGrid = mapManager.GetAllGrids(mapId).First(x => x.Comp != grid); + var newGrid = mapSystem.GetAllGrids(mapId).First(x => x.Comp != grid); var newGridXform = entManager.GetComponent(newGrid.Owner); Assert.Multiple(() => diff --git a/Robust.Shared.IntegrationTests/Map/MapGridMap_Tests.cs b/Robust.Shared.IntegrationTests/Map/MapGridMap_Tests.cs index 7c6fef1c58f..782cb987de2 100644 --- a/Robust.Shared.IntegrationTests/Map/MapGridMap_Tests.cs +++ b/Robust.Shared.IntegrationTests/Map/MapGridMap_Tests.cs @@ -21,16 +21,15 @@ public void FindGrids() var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var mapSystem = entManager.System(); var mapId = sim.CreateMap().MapId; List> grids = []; - mapManager.FindGridsIntersecting(mapId, Box2.UnitCentered, ref grids); + mapSystem.FindGridsIntersecting(mapId, Box2.UnitCentered, ref grids); Assert.That(grids, Is.Empty); entManager.AddComponent(mapSystem.GetMapOrInvalid(mapId)); - mapManager.FindGridsIntersecting(mapId, Box2.UnitCentered, ref grids); + mapSystem.FindGridsIntersecting(mapId, Box2.UnitCentered, ref grids); Assert.That(grids, Has.Count.EqualTo(1)); } @@ -43,11 +42,10 @@ public void AddGridCompToMap() var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var mapSystem = entManager.System(); var mapId = sim.CreateMap().MapId; - mapManager.CreateGridEntity(mapId); + mapSystem.CreateGridEntity(mapId); Assert.DoesNotThrow(() => { diff --git a/Robust.Shared.IntegrationTests/Map/MapGrid_Tests.cs b/Robust.Shared.IntegrationTests/Map/MapGrid_Tests.cs index 1ba57f5825e..0aea19113e2 100644 --- a/Robust.Shared.IntegrationTests/Map/MapGrid_Tests.cs +++ b/Robust.Shared.IntegrationTests/Map/MapGrid_Tests.cs @@ -30,12 +30,11 @@ private static ISimulation SimulationFactory() public void GetTileRefCoords() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); mapSystem.SetTile(grid, new Vector2i(-9, -1), new Tile(typeId: 1, flags: 1, variant: 1)); var result = mapSystem.GetTileRef(grid.Owner, grid.Comp, new Vector2i(-9, -1)); @@ -52,13 +51,12 @@ public void GetTileRefCoords() public void BoundsExpansion() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var transformSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); transformSystem.SetWorldPosition(grid, new Vector2(3, 5)); mapSystem.SetTile(grid, new Vector2i(-1, -2), new Tile(1)); @@ -80,13 +78,12 @@ public void BoundsExpansion() public void BoundsContract() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var transformSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); transformSystem.SetWorldPosition(grid, new Vector2(3, 5)); @@ -108,12 +105,11 @@ public void BoundsContract() public void GridTileToChunkIndices() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); var result = mapSystem.GridTileToChunkIndices(grid.Comp, new Vector2i(-9, -1)); @@ -127,12 +123,11 @@ public void GridTileToChunkIndices() public void ToLocalCentered() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); var result = mapSystem.GridTileToLocal(grid.Owner, grid.Comp, new Vector2i(0, 0)).Position; @@ -144,12 +139,11 @@ public void ToLocalCentered() public void TryGetTileRefNoTile() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); var foundTile = mapSystem.TryGetTileRef(grid.Owner, grid.Comp, new Vector2i(-9, -1), out var tileRef) ; @@ -162,12 +156,11 @@ public void TryGetTileRefNoTile() public void TryGetTileRefTileExists() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); mapSystem.SetTile(grid, new Vector2i(-9, -1), new Tile(typeId: 1, flags: 1, variant: 1)); @@ -183,12 +176,11 @@ public void TryGetTileRefTileExists() public void PointCollidesWithGrid() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); mapSystem.SetTile(grid, new Vector2i(19, 23), new Tile(1)); @@ -201,12 +193,11 @@ public void PointCollidesWithGrid() public void PointNotCollideWithGrid() { var sim = SimulationFactory(); - var mapMan = sim.Resolve(); var mapSystem = sim.Resolve().System(); var mapId = sim.CreateMap().MapId; var gridOptions = new GridCreateOptions(); gridOptions.ChunkSize = 8; - var grid = mapMan.CreateGridEntity(mapId, gridOptions); + var grid = mapSystem.CreateGridEntity(mapId, gridOptions); mapSystem.SetTile(grid, new Vector2i(19, 23), new Tile(1)); diff --git a/Robust.Shared.IntegrationTests/Map/MapManager_Tests.cs b/Robust.Shared.IntegrationTests/Map/MapManager_Tests.cs deleted file mode 100644 index 12d4a4604e4..00000000000 --- a/Robust.Shared.IntegrationTests/Map/MapManager_Tests.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System.Numerics; -using NUnit.Framework; -using Robust.Shared.GameObjects; -using Robust.Shared.Map; -using Robust.Shared.Map.Components; -using Robust.UnitTesting.Server; - -namespace Robust.UnitTesting.Shared.Map -{ - [TestFixture, TestOf(typeof(MapManager))] - internal sealed class MapManagerTests - { - private static ISimulation SimulationFactory() - { - var sim = RobustServerSimulation - .NewSimulation() - .InitializeInstance(); - - return sim; - } - - /// - /// When the map manager is restarted, the maps are deleted. - /// - [Test] - public void Restart_ExistingMap_IsRemoved() - { - var sim = SimulationFactory(); - var mapMan = sim.Resolve(); - var entMan = sim.Resolve(); - var mapSys = entMan.System(); - - var mapID = sim.CreateMap().MapId; - - mapMan.Restart(); - - Assert.That(mapSys.MapExists(mapID), Is.False); - } - - /// - /// When the map manager is restarted, the grids are removed. - /// - [Test] - public void Restart_ExistingGrid_IsRemoved() - { - var sim = SimulationFactory(); - var mapMan = sim.Resolve(); - var entMan = sim.Resolve(); - - var mapID = sim.CreateMap().MapId; - var grid = mapMan.CreateGridEntity(mapID); - - mapMan.Restart(); - - Assert.That(entMan.HasComponent(grid), Is.False); - } - - /// - /// When entities are flushed check nullsapce is also culled. - /// - [Test] - public void Restart_NullspaceMap_IsEmptied() - { - var sim = SimulationFactory(); - var entMan = sim.Resolve(); - var oldEntity = entMan.CreateEntityUninitialized(null, MapCoordinates.Nullspace); - entMan.InitializeEntity(oldEntity); - entMan.FlushEntities(); - Assert.That(entMan.Deleted(oldEntity), Is.True); - } - - [Test] - public void Restart_MapEntity_IsRemoved() - { - var sim = SimulationFactory(); - var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); - var entity = entMan.System().CreateMap(); - mapMan.Restart(); - Assert.That((!entMan.EntityExists(entity) ? EntityLifeStage.Deleted : entMan.GetComponent(entity).EntityLifeStage) >= EntityLifeStage.Deleted, Is.True); - } - } -} diff --git a/Robust.Shared.IntegrationTests/Map/MapPauseTests.cs b/Robust.Shared.IntegrationTests/Map/MapPauseTests.cs index 3627df9311b..55effd21968 100644 --- a/Robust.Shared.IntegrationTests/Map/MapPauseTests.cs +++ b/Robust.Shared.IntegrationTests/Map/MapPauseTests.cs @@ -26,7 +26,6 @@ public void Paused_NotIncluded_NotInQuery() { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); // arrange var mapId = sim.CreateMap().Uid; @@ -47,7 +46,6 @@ public void UnPaused_NotIncluded_InQuery() { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); // arrange var mapId = sim.CreateMap().Uid; @@ -68,7 +66,6 @@ public void Paused_Included_InQuery() { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); // arrange var mapId = sim.CreateMap().Uid; @@ -89,7 +86,6 @@ public void Paused_AddEntity_IsPaused() { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); // arrange var mapId = sim.CreateMap().Uid; @@ -108,7 +104,6 @@ public void UnPaused_AddEntity_IsNotPaused() { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); // arrange var mapId = sim.CreateMap().Uid; @@ -127,14 +122,14 @@ public void Paused_AddGrid_GridPaused() { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); + var mapSys = entMan.System(); // arrange var mapId = sim.CreateMap().MapId; - entMan.System().SetPaused(mapId, true); + mapSys.SetPaused(mapId, true); // act - var newGrid = mapMan.CreateGridEntity(mapId); + var newGrid = mapSys.CreateGridEntity(mapId); // assert var metaData = entMan.GetComponent(newGrid); @@ -199,7 +194,6 @@ public void Paused_UnpauseMap_UnpausedEntities() { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); var mapId = sim.CreateMap().Uid; entMan.System().SetPaused(mapId, true); @@ -219,7 +213,6 @@ public void Unpaused_PauseMap_PausedEntities() { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); var mapId = sim.CreateMap().Uid; entMan.System().SetPaused(mapId, false); diff --git a/Robust.Shared.IntegrationTests/Map/Query_Tests.cs b/Robust.Shared.IntegrationTests/Map/Query_Tests.cs index ed6b1f369ea..1686c5ceb54 100644 --- a/Robust.Shared.IntegrationTests/Map/Query_Tests.cs +++ b/Robust.Shared.IntegrationTests/Map/Query_Tests.cs @@ -57,12 +57,11 @@ public void TestBox2GridIntersection(Vector2 position, float radians, Box2 world var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var mapSystem = entManager.System(); var xformSystem = entManager.System(); var map = mapSystem.CreateMap(); - var grid = mapManager.CreateGridEntity(map); + var grid = mapSystem.CreateGridEntity(map); for (var i = 0; i < 10; i++) { @@ -72,7 +71,7 @@ public void TestBox2GridIntersection(Vector2 position, float radians, Box2 world xformSystem.SetWorldRotation(grid.Owner, radians); var grids = new List>(); - mapManager.FindGridsIntersecting(map, worldAABB, ref grids); + mapSystem.FindGridsIntersecting(map, worldAABB, ref grids); Assert.That(grids.Count > 0, Is.EqualTo(result)); } diff --git a/Robust.Shared.IntegrationTests/Map/SingleTileRemoveTest.cs b/Robust.Shared.IntegrationTests/Map/SingleTileRemoveTest.cs index ada8ffa7d49..6ceda8406f9 100644 --- a/Robust.Shared.IntegrationTests/Map/SingleTileRemoveTest.cs +++ b/Robust.Shared.IntegrationTests/Map/SingleTileRemoveTest.cs @@ -28,7 +28,6 @@ public async Task TestRemoveSingleTile() await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var confMan = server.ResolveDependency(); var sPlayerMan = server.ResolveDependency(); @@ -74,7 +73,7 @@ public async Task TestRemoveSingleTile() await server.WaitPost(() => { sMap = sys.CreateMap(out var mapId); - var comp = mapMan.CreateGridEntity(mapId); + var comp = sys.CreateGridEntity(mapId); grid = (comp.Owner, comp); sys.SetTile(grid, grid, new Vector2i(0, 0), new Tile(typeId: 1, flags: 1, variant: 1)); var coords = new EntityCoordinates(grid, 0.5f, 0.5f); diff --git a/Robust.Shared.IntegrationTests/Physics/BroadphaseNetworkingTest.cs b/Robust.Shared.IntegrationTests/Physics/BroadphaseNetworkingTest.cs index db24213e235..026d64066a1 100644 --- a/Robust.Shared.IntegrationTests/Physics/BroadphaseNetworkingTest.cs +++ b/Robust.Shared.IntegrationTests/Physics/BroadphaseNetworkingTest.cs @@ -33,7 +33,6 @@ public async Task TestBroadphaseNetworking() await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var cEntMan = client.ResolveDependency(); var netMan = client.ResolveDependency(); @@ -60,7 +59,7 @@ public async Task TestBroadphaseNetworking() await server.WaitPost(() => { map1 = mapSystem.CreateMap(out var mapId); - var gridEnt = mapMan.CreateGridEntity(mapId); + var gridEnt = mapSystem.CreateGridEntity(mapId); mapSystem.SetTile(gridEnt, Vector2i.Zero, new Tile(1)); grid1 = gridEnt.Owner; }); @@ -130,7 +129,7 @@ await server.WaitPost(() => { // Create grid map2 = mapSystem.CreateMap(out var mapId); - var gridEnt = mapMan.CreateGridEntity(mapId); + var gridEnt = mapSystem.CreateGridEntity(mapId); mapSystem.SetTile(gridEnt, Vector2i.Zero, new Tile(1)); grid2 = gridEnt.Owner; diff --git a/Robust.Shared.IntegrationTests/Physics/Broadphase_Test.cs b/Robust.Shared.IntegrationTests/Physics/Broadphase_Test.cs index cb87f2dbaab..2f90b231d25 100644 --- a/Robust.Shared.IntegrationTests/Physics/Broadphase_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/Broadphase_Test.cs @@ -77,12 +77,11 @@ public void ReparentSundries() { var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var mapSys = entManager.System(); var xformSys = entManager.System(); var (mapEnt, mapId) = sim.CreateMap(); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSys.CreateGridEntity(mapId); mapSys.SetTile(grid, Vector2i.Zero, new Tile(1)); Assert.That(entManager.HasComponent(grid)); @@ -111,14 +110,13 @@ public void ReparentBroadphase() { var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var fixturesSystem = entManager.EntitySysManager.GetEntitySystem(); var physicsSystem = entManager.EntitySysManager.GetEntitySystem(); var mapSys = entManager.System(); var xformSys = entManager.System(); var (mapEnt, mapId) = sim.CreateMap(); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSys.CreateGridEntity(mapId); var gridUid = grid.Owner; mapSys.SetTile(grid, Vector2i.Zero, new Tile(1)); @@ -163,13 +161,12 @@ public void GridMapUpdate() { var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var mapSys = entManager.System(); var xformSys = entManager.System(); var (map1, mapId1) = sim.CreateMap(); var (map2, _) = sim.CreateMap(); - var grid = mapManager.CreateGridEntity(mapId1); + var grid = mapSys.CreateGridEntity(mapId1); mapSys.SetTile(grid, Vector2i.Zero, new Tile(1)); var mapBroadphase1 = entManager.GetComponent(map1); @@ -194,14 +191,13 @@ public void BroadphaseRecursiveUpdate() { var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var system = entManager.EntitySysManager; var physicsSystem = system.GetEntitySystem(); var lookup = system.GetEntitySystem(); var mapSys = entManager.System(); var (map, mapId) = sim.CreateMap(); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSys.CreateGridEntity(mapId); mapSys.SetTile(grid, Vector2i.Zero, new Tile(1)); var gridBroadphase = entManager.GetComponent(grid); @@ -244,7 +240,6 @@ public void EntMapChangeRecursiveUpdate() { var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var system = entManager.EntitySysManager; var lookup = system.GetEntitySystem(); var xforms = system.GetEntitySystem(); @@ -257,9 +252,9 @@ public void EntMapChangeRecursiveUpdate() var (mapB, mapBId) = sim.CreateMap(); // setup grids - var gridAComp = mapManager.CreateGridEntity(mapAId); - var gridBComp = mapManager.CreateGridEntity(mapBId); - var gridCComp = mapManager.CreateGridEntity(mapAId); + var gridAComp = mapSys.CreateGridEntity(mapAId); + var gridBComp = mapSys.CreateGridEntity(mapBId); + var gridCComp = mapSys.CreateGridEntity(mapAId); var gridA = gridAComp.Owner; var gridB = gridBComp.Owner; var gridC = gridCComp.Owner; diff --git a/Robust.Shared.IntegrationTests/Physics/CollisionWake_Test.cs b/Robust.Shared.IntegrationTests/Physics/CollisionWake_Test.cs index a4109827a8d..65b824afc7f 100644 --- a/Robust.Shared.IntegrationTests/Physics/CollisionWake_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/CollisionWake_Test.cs @@ -41,7 +41,6 @@ public async Task TestCollisionWakeGrid() await server.WaitIdleAsync(); var entManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var mapSystem = entManager.System(); var transformSystem = entManager.System(); @@ -56,7 +55,7 @@ public async Task TestCollisionWakeGrid() await server.WaitPost(() => { mapSystem.CreateMap(out mapId); - grid = mapManager.CreateGridEntity(mapId); + grid = mapSystem.CreateGridEntity(mapId); mapSystem.SetTile(grid, Vector2i.Zero, new Tile(1)); entityOne = entManager.SpawnEntity("CollisionWakeTestItem", new MapCoordinates(Vector2.One * 2f, mapId)); diff --git a/Robust.Shared.IntegrationTests/Physics/GridDeletion_Test.cs b/Robust.Shared.IntegrationTests/Physics/GridDeletion_Test.cs index 20b35cdf73c..54214964a33 100644 --- a/Robust.Shared.IntegrationTests/Physics/GridDeletion_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/GridDeletion_Test.cs @@ -27,8 +27,8 @@ public async Task GridDeletionTest() await server.WaitIdleAsync(); var entManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); - var physSystem = server.ResolveDependency().GetEntitySystem(); + var mapSystem = entManager.System(); + var physSystem = entManager.System(); PhysicsComponent physics = default!; @@ -38,7 +38,7 @@ public async Task GridDeletionTest() await server.WaitAssertion(() => { entManager.System().CreateMap(out mapId); - grid = mapManager.CreateGridEntity(mapId); + grid = mapSystem.CreateGridEntity(mapId); physics = entManager.GetComponent(grid); physSystem.SetBodyType(grid, BodyType.Dynamic, body: physics); @@ -55,7 +55,7 @@ await server.WaitAssertion(() => List> grids = []; // So if gridtree is fucky then this SHOULD throw. - mapManager.FindGridsIntersecting(mapId, + mapSystem.FindGridsIntersecting(mapId, new Box2(new Vector2(float.MinValue, float.MinValue), new Vector2(float.MaxValue, float.MaxValue)), ref grids); }); diff --git a/Robust.Shared.IntegrationTests/Physics/GridMovement_Test.cs b/Robust.Shared.IntegrationTests/Physics/GridMovement_Test.cs index 692fad565df..6f6601c8955 100644 --- a/Robust.Shared.IntegrationTests/Physics/GridMovement_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/GridMovement_Test.cs @@ -25,7 +25,6 @@ public async Task TestFindGridContacts() // Checks that FindGridContacts succesfully overlaps a grid + map broadphase physics body var systems = server.ResolveDependency(); var fixtureSystem = systems.GetEntitySystem(); - var mapManager = server.ResolveDependency(); var entManager = server.ResolveDependency(); var physSystem = systems.GetEntitySystem(); var transformSystem = entManager.EntitySysManager.GetEntitySystem(); @@ -34,7 +33,7 @@ public async Task TestFindGridContacts() await server.WaitAssertion(() => { entManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); // Setup 1 body on grid, 1 body off grid, and assert that it's all gucci. mapSystem.SetTile(grid, Vector2i.Zero, new Tile(1)); diff --git a/Robust.Shared.IntegrationTests/Physics/GridReparentVelocity_Test.cs b/Robust.Shared.IntegrationTests/Physics/GridReparentVelocity_Test.cs index a8c2d11f2c2..7c8bcf9cbde 100644 --- a/Robust.Shared.IntegrationTests/Physics/GridReparentVelocity_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/GridReparentVelocity_Test.cs @@ -19,7 +19,6 @@ internal sealed class GridReparentVelocity_Test private ISimulation _sim = default!; private IEntitySystemManager _systems = default!; private IEntityManager _entManager = default!; - private IMapManager _mapManager = default!; private FixtureSystem _fixtureSystem = default!; private SharedMapSystem _mapSystem = default!; private SharedPhysicsSystem _physSystem = default!; @@ -38,7 +37,6 @@ public void FixtureSetup() _systems = _sim.Resolve(); _entManager = _sim.Resolve(); - _mapManager = _sim.Resolve(); _fixtureSystem = _systems.GetEntitySystem(); _mapSystem = _systems.GetEntitySystem(); _physSystem = _systems.GetEntitySystem(); @@ -50,7 +48,7 @@ public void Setup() _mapUid = _mapSystem.CreateMap(out _mapId); // Spawn a 1x1 grid centered at (0.5, 0.5), ensure it's movable and its velocity has no damping. - var gridEnt = _mapManager.CreateGridEntity(_mapId); + var gridEnt = _mapSystem.CreateGridEntity(_mapId); var gridPhys = _entManager.GetComponent(gridEnt); _physSystem.SetSleepingAllowed(gridEnt, gridPhys, false); _physSystem.SetBodyType(gridEnt, BodyType.Dynamic, body: gridPhys); diff --git a/Robust.Shared.IntegrationTests/Physics/JointDeletion_Test.cs b/Robust.Shared.IntegrationTests/Physics/JointDeletion_Test.cs index e7ebeb642dd..97631aa532f 100644 --- a/Robust.Shared.IntegrationTests/Physics/JointDeletion_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/JointDeletion_Test.cs @@ -23,7 +23,6 @@ public async Task JointDeletionTest() await server.WaitIdleAsync(); var entManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var susManager = server.ResolveDependency(); var jointSystem = susManager.GetEntitySystem(); var broadphase = susManager.GetEntitySystem(); diff --git a/Robust.Shared.IntegrationTests/Physics/MapVelocity_Test.cs b/Robust.Shared.IntegrationTests/Physics/MapVelocity_Test.cs index 4067f53d130..23434da3b01 100644 --- a/Robust.Shared.IntegrationTests/Physics/MapVelocity_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/MapVelocity_Test.cs @@ -34,8 +34,8 @@ public async Task TestMapVelocities() await server.WaitIdleAsync(); var entityManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var system = entityManager.EntitySysManager; + var mapSystem = entityManager.System(); var physicsSys = system.GetEntitySystem(); var xformSystem = system.GetEntitySystem(); var traversal = entityManager.System(); @@ -44,8 +44,8 @@ public async Task TestMapVelocities() await server.WaitAssertion(() => { entityManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); - var grid2 = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); + var grid2 = mapSystem.CreateGridEntity(mapId); var gridUidA = grid.Owner; Assert.That(entityManager.TryGetComponent(gridUidA, out var gridPhysics)); @@ -106,8 +106,8 @@ public async Task TestNestedParentVelocities() await server.WaitIdleAsync(); var entityManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var system = entityManager.EntitySysManager; + var mapSystem = entityManager.System(); var physicsSys = system.GetEntitySystem(); var xformSystem = system.GetEntitySystem(); var traversal = entityManager.System(); @@ -116,7 +116,7 @@ public async Task TestNestedParentVelocities() await server.WaitAssertion(() => { entityManager.System().CreateMap(out var mapId); - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var gridUid = grid.Owner; Assert.That(entityManager.TryGetComponent(gridUid, out var gridPhysics)); diff --git a/Robust.Shared.IntegrationTests/Physics/RayCast_Test.cs b/Robust.Shared.IntegrationTests/Physics/RayCast_Test.cs index 1672d94c3ec..ee531eb2163 100644 --- a/Robust.Shared.IntegrationTests/Physics/RayCast_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/RayCast_Test.cs @@ -120,7 +120,7 @@ private void Setup(ISimulation sim, out MapId mapId) sim.System().CreateMap(out mapId); - var grid = sim.Resolve().CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); for (var i = 0; i < 3; i++) { diff --git a/Robust.Shared.IntegrationTests/Physics/RecursiveUpdateTest.cs b/Robust.Shared.IntegrationTests/Physics/RecursiveUpdateTest.cs index 4b061376888..10781409e90 100644 --- a/Robust.Shared.IntegrationTests/Physics/RecursiveUpdateTest.cs +++ b/Robust.Shared.IntegrationTests/Physics/RecursiveUpdateTest.cs @@ -21,13 +21,12 @@ public void ContainerRecursiveUpdateTest() { var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var xforms = entManager.System(); var mapSystem = entManager.System(); var containers = entManager.System(); var mapId = sim.CreateMap().MapId; - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var guid = grid.Owner; mapSystem.SetTile(grid, Vector2i.Zero, new Tile(1)); Assert.That(entManager.HasComponent(guid)); @@ -161,7 +160,6 @@ public void RecursiveMoveTest() { var sim = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var mapSystem = entManager.EntitySysManager.GetEntitySystem(); var transforms = entManager.EntitySysManager.GetEntitySystem(); var lookup = entManager.EntitySysManager.GetEntitySystem(); @@ -216,7 +214,7 @@ public void RecursiveMoveTest() Assert.That(ents, Does.Contain(child)); // Try again, but this time with a parent change. - var grid = mapManager.CreateGridEntity(mapId); + var grid = mapSystem.CreateGridEntity(mapId); var guid = grid.Owner; mapSystem.SetTile(grid, Vector2i.Zero, new Tile(1)); var gridBroadphase = entManager.GetComponent(guid); diff --git a/Robust.Shared.IntegrationTests/Physics/Stack_Test.cs b/Robust.Shared.IntegrationTests/Physics/Stack_Test.cs index eb90f663401..568aeb28251 100644 --- a/Robust.Shared.IntegrationTests/Physics/Stack_Test.cs +++ b/Robust.Shared.IntegrationTests/Physics/Stack_Test.cs @@ -155,7 +155,6 @@ public async Task TestCircleStack() await server.WaitIdleAsync(); var entityManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var entitySystemManager = server.ResolveDependency(); var fixtureSystem = entitySystemManager.GetEntitySystem(); var physSystem = entitySystemManager.GetEntitySystem(); diff --git a/Robust.Shared.IntegrationTests/Prototypes/HotReloadTest.cs b/Robust.Shared.IntegrationTests/Prototypes/HotReloadTest.cs index 22fa7147303..713ee695edf 100644 --- a/Robust.Shared.IntegrationTests/Prototypes/HotReloadTest.cs +++ b/Robust.Shared.IntegrationTests/Prototypes/HotReloadTest.cs @@ -34,7 +34,6 @@ internal sealed class HotReloadTest : OurRobustUnitTest - type: {HotReloadTestComponentTwoId}"; private PrototypeManager _prototypes = default!; - private IMapManager _maps = default!; private IEntityManager _entities = default!; protected override Type[]? ExtraComponents => new[] {typeof(HotReloadTestOneComponent), typeof(HotReloadTestTwoComponent)}; @@ -48,7 +47,6 @@ public void Setup() _prototypes.LoadString(InitialPrototypes); _prototypes.ResolveResults(); - _maps = IoCManager.Resolve(); _entities = IoCManager.Resolve(); } diff --git a/Robust.Shared.IntegrationTests/Spawning/EntitySpawnHelpersTest.cs b/Robust.Shared.IntegrationTests/Spawning/EntitySpawnHelpersTest.cs index 3453141b83c..91e96400c01 100644 --- a/Robust.Shared.IntegrationTests/Spawning/EntitySpawnHelpersTest.cs +++ b/Robust.Shared.IntegrationTests/Spawning/EntitySpawnHelpersTest.cs @@ -24,9 +24,6 @@ public abstract partial class EntitySpawnHelpersTest : RobustIntegrationTest protected SharedTransformSystem Xforms = default!; protected SharedContainerSystem Container = default!; - // Even if unused, content / downstream tests might use this class, so removal would be a breaking change? - protected IMapManager MapMan = default!; - protected EntityUid Map; protected MapId MapId; protected EntityUid Parent; // entity parented to the map. @@ -44,7 +41,6 @@ protected async Task Setup() { Server = StartServer(); await Server.WaitIdleAsync(); - MapMan = Server.ResolveDependency(); EntMan = Server.ResolveDependency(); MapSys = EntMan.System(); Xforms = EntMan.System(); diff --git a/Robust.Shared.IntegrationTests/TransformTests/GridTraversalTest.cs b/Robust.Shared.IntegrationTests/TransformTests/GridTraversalTest.cs index 92401b30d83..eac38f87795 100644 --- a/Robust.Shared.IntegrationTests/TransformTests/GridTraversalTest.cs +++ b/Robust.Shared.IntegrationTests/TransformTests/GridTraversalTest.cs @@ -16,7 +16,6 @@ public async Task TestSpawnTraversal() var server = StartServer(); await server.WaitIdleAsync(); - var mapMan = server.ResolveDependency(); var sEntMan = server.ResolveDependency(); var xforms = sEntMan.System(); var mapSys = sEntMan.System(); @@ -29,7 +28,7 @@ public async Task TestSpawnTraversal() await server.WaitPost(() => { map = sEntMan.System().CreateMap(out mapId); - var gridComp = mapMan.CreateGridEntity(mapId); + var gridComp = mapSys.CreateGridEntity(mapId); grid = gridComp.Owner; mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1)); var gridCentre = new EntityCoordinates(grid, .5f, .5f); diff --git a/Robust.Shared.Scripting/ScriptGlobalsShared.cs b/Robust.Shared.Scripting/ScriptGlobalsShared.cs index f384b772c0e..801df76606d 100644 --- a/Robust.Shared.Scripting/ScriptGlobalsShared.cs +++ b/Robust.Shared.Scripting/ScriptGlobalsShared.cs @@ -33,8 +33,6 @@ public abstract partial class ScriptGlobalsShared : IInvocationContext public IEntitySystemManager esm => _esm; [Dependency] private IPrototypeManager _prot = null!; public IPrototypeManager prot => _prot; - [Dependency] private IMapManager _map = null!; - public IMapManager map => _map; [Dependency] private IDependencyCollection _dependencies = null!; public IDependencyCollection dependencies => _dependencies; [Dependency] private ToolshedManager _shed = null!; diff --git a/Robust.Shared/ComponentTrees/ComponentTreeSystem.cs b/Robust.Shared/ComponentTrees/ComponentTreeSystem.cs index ded59959fe0..8bc7eda7148 100644 --- a/Robust.Shared/ComponentTrees/ComponentTreeSystem.cs +++ b/Robust.Shared/ComponentTrees/ComponentTreeSystem.cs @@ -25,7 +25,6 @@ public abstract partial class ComponentTreeSystem : EntitySyst { [Dependency] private RecursiveMoveSystem _recursiveMoveSys = default!; [Dependency] protected SharedTransformSystem XformSystem = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private SharedMapSystem _mapSystem = default!; private readonly Queue> _updateQueue = new(); @@ -312,7 +311,7 @@ protected virtual Box2 ExtractAabb(in ComponentTreeEntry entry) var state = (EntityManager, trees); - _mapManager.FindGridsIntersecting(mapId, worldAABB, ref state, + _mapSystem.FindGridsIntersecting(mapId, worldAABB, ref state, (EntityUid uid, MapGridComponent grid, ref (EntityManager EntityManager, ValueList<(EntityUid, TTreeComp)> trees) tuple) => { diff --git a/Robust.Shared/Console/Commands/MapCommands.cs b/Robust.Shared/Console/Commands/MapCommands.cs index 1c679f414f3..58eb49de4d4 100644 --- a/Robust.Shared/Console/Commands/MapCommands.cs +++ b/Robust.Shared/Console/Commands/MapCommands.cs @@ -157,7 +157,6 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args) internal sealed partial class ListMapsCommand : LocalizedEntityCommands { [Dependency] private IEntityManager _entManager = default!; - [Dependency] private IMapManager _map = default!; [Dependency] private SharedMapSystem _mapSystem = default!; public override string Command => "lsmap"; @@ -180,7 +179,7 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args) _mapSystem.IsInitialized(mapUid), _mapSystem.IsPaused(mapId), _entManager.GetNetEntity(mapUid), - string.Join(",", _map.GetAllGrids(mapId).Select(grid => grid.Owner))); + string.Join(",", _mapSystem.GetAllGrids(mapId).Select(grid => grid.Owner))); } // Trim the newline diff --git a/Robust.Shared/Console/Commands/TeleportCommands.cs b/Robust.Shared/Console/Commands/TeleportCommands.cs index c028ae2a897..e7e5fd8d447 100644 --- a/Robust.Shared/Console/Commands/TeleportCommands.cs +++ b/Robust.Shared/Console/Commands/TeleportCommands.cs @@ -17,7 +17,6 @@ namespace Robust.Shared.Console.Commands; internal sealed partial class TeleportCommand : LocalizedEntityCommands { - [Dependency] private IMapManager _map = default!; [Dependency] private IEntityManager _entityManager = default!; [Dependency] private SharedTransformSystem _transform = default!; [Dependency] private SharedMapSystem _mapSystem = default!; @@ -53,7 +52,7 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args) return; } - if (_map.TryFindGridAt(mapId, position, out var gridUid, out var grid)) + if (_mapSystem.TryFindGridAt(mapId, position, out var gridUid, out var grid)) { var gridPos = Vector2.Transform(position, _transform.GetInvWorldMatrix(gridUid)); diff --git a/Robust.Shared/EntitySerialization/MapChunkSerializer.cs b/Robust.Shared/EntitySerialization/MapChunkSerializer.cs index 0b3bb6c1c6a..c5df77dfadb 100644 --- a/Robust.Shared/EntitySerialization/MapChunkSerializer.cs +++ b/Robust.Shared/EntitySerialization/MapChunkSerializer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -41,8 +42,8 @@ public MapChunk Read(ISerializationManager serializationManager, MappingDataNode using var stream = new MemoryStream(tileBytes); using var reader = new BinaryReader(stream); - var mapManager = dependencies.Resolve(); - mapManager.SuppressOnTileChanged = true; + var mapSystem = dependencies.Resolve().System(); + mapSystem.SuppressOnTileChanged = true; ushort size = 16; @@ -112,7 +113,7 @@ public MapChunk Read(ISerializationManager serializationManager, MappingDataNode } chunk.SuppressCollisionRegeneration = false; - mapManager.SuppressOnTileChanged = false; + mapSystem.SuppressOnTileChanged = false; return chunk; } @@ -192,8 +193,8 @@ public MapChunk CreateCopy( SerializationHookContext hookCtx, ISerializationContext? context = null) { - var mapManager = dependencies.Resolve(); - mapManager.SuppressOnTileChanged = true; + var mapSystem = dependencies.Resolve().System(); + mapSystem.SuppressOnTileChanged = true; var chunk = new MapChunk(source.X, source.Y, source.ChunkSize) { SuppressCollisionRegeneration = true @@ -207,7 +208,7 @@ public MapChunk CreateCopy( } } - mapManager.SuppressOnTileChanged = false; + mapSystem.SuppressOnTileChanged = false; chunk.SuppressCollisionRegeneration = false; return chunk; diff --git a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs index f2e132d06cd..ec5ed25c69f 100644 --- a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs +++ b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs @@ -103,8 +103,6 @@ public Matrix3x2 InvLocalMatrix [ViewVariables] internal readonly HashSet _children = new(); - [Dependency] private IMapManager _mapManager = default!; - /// /// Returns the index of the map which this object is on /// @@ -375,7 +373,7 @@ public bool Anchored { _anchored = value; } - else if (value && !_anchored && _mapManager.TryFindGridAt(MapPosition, out _, out var grid)) + else if (value && !_anchored && _entMan.EntitySysManager.GetEntitySystem().TryFindGridAt(MapPosition, out _, out var grid)) { _anchored = _entMan.EntitySysManager.GetEntitySystem().AnchorEntity(Owner, this, grid); } diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index 2df50e9dbf9..dec2756581a 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -37,7 +37,6 @@ public abstract partial class EntityManager : IEntityManager [IoC.Dependency] protected IPrototypeManager PrototypeManager = default!; [IoC.Dependency] protected ILogManager LogManager = default!; [IoC.Dependency] private IEntitySystemManager _entitySystemManager = default!; - [IoC.Dependency] private IMapManager _mapManager = default!; [IoC.Dependency] private IGameTiming _gameTiming = default!; [IoC.Dependency] private ISerializationManager _serManager = default!; [IoC.Dependency] private ProfManager _prof = default!; @@ -360,7 +359,7 @@ public virtual EntityUid CreateEntityUninitialized(string? prototypeName, MapCoo throw new ArgumentException($"Attempted to spawn entity on an invalid map. Coordinates: {coordinates}"); EntityCoordinates coords; - if (_mapManager.TryFindGridAt(coordinates, out var gridUid, out var grid) + if (_mapSystem.TryFindGridAt(coordinates, out var gridUid, out var grid) && MetaQuery.TryGetComponentInternal(gridUid, out var meta) && meta.EntityLifeStage < EntityLifeStage.Terminating) { diff --git a/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs b/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs index 7d7d2ead228..dde211ed9b5 100644 --- a/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs +++ b/Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs @@ -93,7 +93,7 @@ private void AddEntitiesIntersecting(MapId mapId, flags); // Need to include maps - _mapManager.FindGridsIntersecting(mapId, worldAABB, ref state, + _map.FindGridsIntersecting(mapId, worldAABB, ref state, static (EntityUid uid, MapGridComponent _, ref EntityQueryState state) => { var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, uid); @@ -244,7 +244,7 @@ private bool AnyEntitiesIntersecting(MapId mapId, flags); // Need to include maps - _mapManager.FindGridsIntersecting(mapId, worldAABB, ref state, + _map.FindGridsIntersecting(mapId, worldAABB, ref state, static (EntityUid uid, MapGridComponent _, ref AnyEntityQueryState state) => { var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, uid); @@ -556,7 +556,7 @@ public void GetEntitiesIntersecting(EntityUid uid, HashSet intersecti var state = (uid, transform, intersecting, _fixturesQuery, this, _physics, flags); // Unfortuantely I can't think of a way to de-dupe this with the other ones as it's slightly different. - _mapManager.FindGridsIntersecting(mapId, worldAABB, ref state, + _map.FindGridsIntersecting(mapId, worldAABB, ref state, static (EntityUid gridUid, MapGridComponent grid, ref (EntityUid entity, Transform transform, HashSet intersecting, EntityQuery fixturesQuery, EntityLookupSystem lookup, SharedPhysicsSystem physics, LookupFlags flags) state) => @@ -786,7 +786,7 @@ public void FindLookupsIntersecting(MapId mapId, Box2Rotated worldBounds, Compon var state = (callback, _broadQuery); - _mapManager.FindGridsIntersecting(mapId, worldBounds, ref state, + _map.FindGridsIntersecting(mapId, worldBounds, ref state, static (EntityUid uid, MapGridComponent grid, ref (ComponentQueryCallback callback, EntityQuery _broadQuery) tuple) => diff --git a/Robust.Shared/GameObjects/Systems/EntityLookupSystem.ComponentQueries.cs b/Robust.Shared/GameObjects/Systems/EntityLookupSystem.ComponentQueries.cs index 16d33310d35..f579ecc7bc6 100644 --- a/Robust.Shared/GameObjects/Systems/EntityLookupSystem.ComponentQueries.cs +++ b/Robust.Shared/GameObjects/Systems/EntityLookupSystem.ComponentQueries.cs @@ -458,7 +458,7 @@ public bool AnyComponentsIntersecting(Type type, MapId mapId, T shape, Transf // Get grid entities var state = (this, worldAABB, flags, query, ignored, found: false); - _mapManager.FindGridsIntersecting(mapId, worldAABB, ref state, + _map.FindGridsIntersecting(mapId, worldAABB, ref state, static (EntityUid uid, MapGridComponent grid, ref (EntityLookupSystem system, Box2 worldAABB, @@ -550,7 +550,7 @@ public void GetEntitiesIntersecting(Type type, MapId mapId, T shape, Transfor // Get grid entities var state = new GridQueryState(intersecting, shape, shapeTransform, this, _physics, flags, query); - _mapManager.FindGridsIntersecting(mapId, worldAABB, ref state, + _map.FindGridsIntersecting(mapId, worldAABB, ref state, static (EntityUid uid, MapGridComponent grid, ref GridQueryState state) => { var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, uid); @@ -596,7 +596,7 @@ public void GetEntitiesIntersecting(MapId mapId, TShape shape, Transf // Get grid entities var state = new GridQueryState(entities, shape, shapeTransform, this, _physics, flags, query); - _mapManager.FindGridsIntersecting(mapId, worldAABB, ref state, + _map.FindGridsIntersecting(mapId, worldAABB, ref state, static (EntityUid uid, MapGridComponent grid, ref GridQueryState state) => { var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, uid); diff --git a/Robust.Shared/GameObjects/Systems/EntityLookupSystem.cs b/Robust.Shared/GameObjects/Systems/EntityLookupSystem.cs index 1d1e90c671d..25e124922f9 100644 --- a/Robust.Shared/GameObjects/Systems/EntityLookupSystem.cs +++ b/Robust.Shared/GameObjects/Systems/EntityLookupSystem.cs @@ -73,7 +73,6 @@ public record struct WorldAABBEvent public sealed partial class EntityLookupSystem : EntitySystem { [Dependency] private IManifoldManager _manifoldManager = default!; - [Dependency] private IMapManager _mapManager = default!; [Dependency] private IGameTiming _timing = default!; [Dependency] private INetManager _netMan = default!; [Dependency] private SharedContainerSystem _container = default!; diff --git a/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs b/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs index 5cbdd7f6f63..ef0f8f0108c 100644 --- a/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs @@ -13,7 +13,7 @@ namespace Robust.Shared.GameObjects; /// public sealed partial class SharedGridTraversalSystem : EntitySystem { - [Dependency] private IMapManagerInternal _mapManager = default!; + [Dependency] private SharedMapSystem _mapSystem = default!; [Dependency] private SharedTransformSystem _transform = default!; [Dependency] private IGameTiming _timing = default!; @@ -97,7 +97,7 @@ public void CheckTraversal(EntityUid entity, TransformComponent xform, EntityUid : Vector2.Transform(xform.LocalPosition, Transform(xform.ParentUid).LocalMatrix); // Change parent if necessary - if (_mapManager.TryFindGridAt(map, mapPos, out var gridUid, out _)) + if (_mapSystem.TryFindGridAt(map, mapPos, out var gridUid, out _)) { // Some minor duplication here with AttachParent but only happens when going on/off grid so not a big deal ATM. if (gridUid != xform.GridUid && !TerminatingOrDeleted(gridUid)) diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Coordinates.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Coordinates.cs index 7ff85746be3..de2ad55a9d2 100644 --- a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Coordinates.cs +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Coordinates.cs @@ -25,7 +25,7 @@ public EntityCoordinates AlignToGrid(EntityCoordinates coordinates) // Check if mappos intersects a grid. var mapPos = _transform.ToMapCoordinates(coordinates); - if (_mapInternal.TryFindGridAt(mapPos, out var gridUid, out gridComponent)) + if (TryFindGridAt(mapPos, out var gridUid, out gridComponent)) { var tile = CoordinatesToTile(gridUid, gridComponent, coordinates); return ToCenterCoordinates(gridUid, tile, gridComponent); diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.Queries.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.Queries.cs new file mode 100644 index 00000000000..4d754b59031 --- /dev/null +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.Queries.cs @@ -0,0 +1,612 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Numerics; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; +using Robust.Shared.Map.Enumerators; +using Robust.Shared.Maths; +using Robust.Shared.Physics; +using Robust.Shared.Physics.Collision.Shapes; +using Robust.Shared.Physics.Shapes; +using Transform = Robust.Shared.Physics.Transform; + +namespace Robust.Shared.GameObjects; + +public abstract partial class SharedMapSystem +{ + + /// + /// Whether and its extended family should only approximately check for intersection by default. + /// + public const bool Approximate = false; + + /// + /// Whether and its extended family should also check the map itself by default. + /// + public const bool IncludeMap = true; + + #region TryFindGridAt + + /// + /// Attempts to find a grid which overlaps with a given position on a given map. + /// If the map is itself a grid and there is no other grid overlapping with the given position this will return the map itself as such a grid. + /// + /// The uid of the map to search for a valid grid. + /// The exact position within and relative to the map to search for a valid grid. + /// Returns the uid of the grid found, if any. + /// Returns the component of the grid found, if any. + /// True if a grid overlapping with the given position within the given map was found, or false otherwise. + public bool TryFindGridAt(EntityUid mapEnt, Vector2 worldPos, out EntityUid uid, [NotNullWhen(true)] out MapGridComponent? grid) + { + var rangeVec = new Vector2(0.2f, 0.2f); + + // Need to enlarge the AABB by at least the grid shrinkage size. + var aabb = new Box2(worldPos - rangeVec, worldPos + rangeVec); + + uid = EntityUid.Invalid; + grid = null; + var state = (uid, grid, worldPos, this, _transform); + + FindGridsIntersecting(mapEnt, aabb, ref state, static (EntityUid iUid, MapGridComponent iGrid, ref ( + EntityUid uid, + MapGridComponent? grid, + Vector2 worldPos, + SharedMapSystem mapSystem, + SharedTransformSystem xformSystem) tuple) => + { + // Turn the worldPos into a localPos and work out the relevant chunk we need to check + // This is much faster than iterating over every chunk individually. + // (though now we need some extra calcs up front). + + // Doesn't use WorldBounds because it's just an AABB. + var matrix = tuple.xformSystem.GetInvWorldMatrix(iUid); + var localPos = Vector2.Transform(tuple.worldPos, matrix); + + // NOTE: + // If you change this to use fixtures instead (i.e. if you want half-tiles) then you need to make sure + // you account for the fact that fixtures are shrunk slightly! + var chunkIndices = GetChunkIndices(localPos, iGrid.ChunkSize); + + if (!iGrid.Chunks.TryGetValue(chunkIndices, out var chunk)) + return true; + + var chunkRelative = GetChunkRelative(localPos, iGrid.ChunkSize); + var chunkTile = chunk.GetTile(chunkRelative); + + if (chunkTile.IsEmpty) + return true; + + tuple.uid = iUid; + tuple.grid = iGrid; + return false; + }, approx: true, includeMap: false); + + if (state.grid == null && _gridQuery.TryGetComponent(mapEnt, out var mapGrid)) + { + uid = mapEnt; + grid = mapGrid; + return true; + } + + uid = state.uid; + grid = state.grid; + return grid != null; + } + + /// + /// The id of the map to search for a valid grid. + public bool TryFindGridAt(MapId mapId, Vector2 worldPos, out EntityUid uid, [NotNullWhen(true)] out MapGridComponent? grid) + { + if (TryGetMap(mapId, out var map)) + return TryFindGridAt(map.Value, worldPos, out uid, out grid); + + uid = default; + grid = null; + return false; + } + + /// + /// The map position to search for a valid grid. + public bool TryFindGridAt(MapCoordinates mapCoordinates, out EntityUid uid, [NotNullWhen(true)] out MapGridComponent? grid) + { + return TryFindGridAt(mapCoordinates.MapId, mapCoordinates.Position, out uid, out grid); + } + + #endregion + + #region MapId + + /// + /// Adds every grid on the specified map which intersects the given region to the provided collection. + /// + /// The shape of the region to check. + /// The transform, relative to the map, of the region to check. + public void FindGridsIntersecting( + MapId mapId, + TShape shape, + Transform transform, + ref List> grids, + bool approx = Approximate, + bool includeMap = IncludeMap) where TShape : IPhysShape + { + if (TryGetMap(mapId, out var mapEnt)) + FindGridsIntersecting(mapEnt.Value, shape, transform, ref grids, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// + /// The shape of the region to check. + /// The transform, relative to the map, of the region to check. + public void FindGridsIntersecting( + MapId mapId, + TShape shape, + Transform transform, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) where TShape : IPhysShape + { + if (TryGetMap(mapId, out var mapEnt)) + FindGridsIntersecting(mapEnt.Value, shape, transform, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// Allows providing some additional to pass to the callback when it is invoked. + /// + /// The shape of the region to check. + /// The transform, relative to the map, of the region to check. + public void FindGridsIntersecting( + MapId mapId, + TShape shape, + Transform transform, + ref TState state, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) where TShape : IPhysShape + { + if (TryGetMap(mapId, out var mapEnt)) + FindGridsIntersecting(mapEnt.Value, shape, transform, ref state, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// + public void FindGridsIntersecting( + MapId mapId, + Box2 worldAABB, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + if (TryGetMap(mapId, out var mapEnt)) + FindGridsIntersecting(mapEnt.Value, worldAABB, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// Allows providing some additional to pass to the callback when it is invoked. + /// + public void FindGridsIntersecting( + MapId mapId, + Box2 worldAABB, + ref TState state, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + if (TryGetMap(mapId, out var map)) + FindGridsIntersecting(map.Value, worldAABB, ref state, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Adds every grid on the specified map which intersects the given region to the provided collection. + /// + public void FindGridsIntersecting( + MapId mapId, + Box2 worldAABB, + ref List> grids, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + if (TryGetMap(mapId, out var map)) + FindGridsIntersecting(map.Value, worldAABB, ref grids, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// + public void FindGridsIntersecting( + MapId mapId, + Box2Rotated worldBounds, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + if (TryGetMap(mapId, out var mapEnt)) + FindGridsIntersecting(mapEnt.Value, worldBounds, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// Allows providing some additional to pass to the callback when it is invoked. + /// + public void FindGridsIntersecting( + MapId mapId, + Box2Rotated worldBounds, + ref TState state, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + if (TryGetMap(mapId, out var mapEnt)) + FindGridsIntersecting(mapEnt.Value, worldBounds, ref state, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Adds every grid on the specified map which intersects the given region to the provided collection. + /// + public void FindGridsIntersecting( + MapId mapId, + Box2Rotated worldBounds, + ref List> grids, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + if (TryGetMap(mapId, out var mapEnt)) + FindGridsIntersecting(mapEnt.Value, worldBounds, ref grids, approx: approx, includeMap: includeMap); + } + + #endregion + + #region EntityUid + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// + /// The shape of the region to check. + /// The transform, relative to the map, of the region to check. + public void FindGridsIntersecting( + EntityUid mapEnt, + TShape shape, + Transform transform, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) where TShape : IPhysShape + { + FindGridsIntersecting(mapEnt, shape, shape.ComputeAABB(transform, 0), transform, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// Allows providing some additional to pass to the callback when it is invoked. + /// + /// The shape of the region to check. + /// The transform, relative to the map, of the region to check. + public void FindGridsIntersecting( + EntityUid mapEnt, + TShape shape, + Transform transform, + ref TState state, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) where TShape : IPhysShape + { + FindGridsIntersecting(mapEnt, shape, shape.ComputeAABB(transform, 0), transform, ref state, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Adds every grid on the specified map which intersects the given region to the provided list. + /// + /// The shape of the region to check. + /// The transform, relative to the map, of the region to check. + public void FindGridsIntersecting( + EntityUid mapEnt, + TShape shape, + Transform transform, + ref List> grids, + bool approx = Approximate, + bool includeMap = IncludeMap) where TShape : IPhysShape + { + FindGridsIntersecting(mapEnt, shape, shape.ComputeAABB(transform, 0), transform, ref grids, approx: approx, includeMap: includeMap); + } + + /// + /// Adds every grid on the specified map which intersects the given regions to the provided collection. + /// + /// A set of regions to check. + /// The transform, relative to the map, of the regions to check. + public void FindGridsIntersecting( + EntityUid mapEnt, + List shapes, + Transform transform, + ref List> entities, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + foreach (var shape in shapes) + { + FindGridsIntersecting(mapEnt, shape, transform, ref entities, approx: approx, includeMap: includeMap); + } + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// + public void FindGridsIntersecting( + EntityUid mapEnt, + Box2 worldAABB, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + var shape = new SlimPolygon(worldAABB); + FindGridsIntersecting(mapEnt, shape, worldAABB, Robust.Shared.Physics.Transform.Empty, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// Allows providing some additional to pass to the callback when it is invoked. + /// + public void FindGridsIntersecting( + EntityUid mapEnt, + Box2 worldAABB, + ref TState state, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + var shape = new SlimPolygon(worldAABB); + FindGridsIntersecting(mapEnt, shape, worldAABB, Robust.Shared.Physics.Transform.Empty, ref state, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Adds every grid on the specified map which intersects the given regions to the provided list. + /// + public void FindGridsIntersecting( + EntityUid mapEnt, + Box2 worldAABB, + ref List> grids, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + var shape = new SlimPolygon(worldAABB); + FindGridsIntersecting(mapEnt, shape, worldAABB, Robust.Shared.Physics.Transform.Empty, ref grids, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// + public void FindGridsIntersecting( + EntityUid mapEnt, + Box2Rotated worldBounds, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + var shape = new SlimPolygon(worldBounds); + FindGridsIntersecting(mapEnt, shape, Robust.Shared.Physics.Transform.Empty, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// Allows providing some additional to pass to the callback when it is invoked. + /// + public void FindGridsIntersecting( + EntityUid mapEnt, + Box2Rotated worldBounds, + ref TState state, + GridCallback callback, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + var shape = new SlimPolygon(worldBounds); + FindGridsIntersecting(mapEnt, shape, Robust.Shared.Physics.Transform.Empty, ref state, callback, approx: approx, includeMap: includeMap); + } + + /// + /// Adds every grid on the specified map which intersects the given regions to the provided list. + /// + public void FindGridsIntersecting( + EntityUid mapEnt, + Box2Rotated worldBounds, + ref List> grids, + bool approx = Approximate, + bool includeMap = IncludeMap) + { + var shape = new SlimPolygon(worldBounds); + FindGridsIntersecting(mapEnt, shape, Robust.Shared.Physics.Transform.Empty, ref grids, approx: approx, includeMap: includeMap); + } + + #endregion + + /// + /// Enumerates all of the grids located on a given map. + /// + public IEnumerable> GetAllGrids(MapId mapId) + { + var query = AllEntityQuery(); + while (query.MoveNext(out var uid, out var grid, out var xform)) + { + if (xform.MapID != mapId) + continue; + + yield return (uid, grid); + } + } + + /// + /// This version only provides the component without the uid and should not be used. + /// + /// + [Obsolete("use GetAllGrids instead")] + public IEnumerable GetAllMapGrids(MapId mapId) + { + var query = AllEntityQuery(); + while (query.MoveNext(out var grid, out var xform)) + { + if (xform.MapID == mapId) + yield return grid; + } + } + + /// + /// Adds every grid on the specified map which intersects the given regions to the provided list. + /// + /// The shape of the region to check. + /// The world-local axis aligned bounding box of the region to check. + /// The transform, relative to the map, of the region to check. + private void FindGridsIntersecting( + EntityUid mapEnt, + TShape shape, + Box2 worldAABB, + Transform transform, + ref List> grids, + bool approx, + bool includeMap) where TShape : IPhysShape + { + var state = grids; + FindGridsIntersecting(mapEnt, shape, worldAABB, transform, ref state, + static (EntityUid uid, MapGridComponent grid, ref List> state) => + { + state.Add((uid, grid)); + return true; + }, + approx, includeMap + ); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// + /// The shape of the region to check. + /// The world-local axis aligned bounding box of the region to check. + /// The transform, relative to the map, of the region to check. + private void FindGridsIntersecting( + EntityUid mapEnt, + TShape shape, + Box2 worldAABB, + Transform transform, + GridCallback callback, + bool approx, + bool includeMap) where TShape : IPhysShape + { + var state = callback; + FindGridsIntersecting(mapEnt, shape, worldAABB, transform, ref state, + static (EntityUid uid, MapGridComponent grid, ref GridCallback state) => state.Invoke(uid, grid), + approx, includeMap + ); + } + + /// + /// Invokes the provided callback on every grid on the specified map which intersect the given region. + /// Allows providing some additional to pass to the callback when it is invoked. + /// + /// The shape of the region to check. + /// The world-local axis aligned bounding box of the region to check. + /// The transform, relative to the map, of the region to check. + private void FindGridsIntersecting( + EntityUid mapEnt, + TShape shape, + Box2 worldAABB, + Transform transform, + ref TState state, + GridCallback callback, + bool approx, + bool includeMap) where TShape : IPhysShape + { + if (!_gridTreeQuery.TryGetComponent(mapEnt, out var gridTree)) + return; + + if (includeMap && _gridQuery.TryGetComponent(mapEnt, out var mapGrid)) + { + callback(mapEnt, mapGrid, ref state); + } + + var gridState = new GridQueryState( + callback, + state, + worldAABB, + shape, + transform, + gridTree.Tree, + this, + _transform, + approx); + + gridTree.Tree.Query(ref gridState, static (ref GridQueryState state, DynamicTree.Proxy proxy) => + { + // Even for approximate we'll check if any chunks roughly overlap. + var data = state.Tree.GetUserData(proxy); + var gridInvMatrix = state.TransformSystem.GetInvWorldMatrix(data.Uid); + var localAABB = gridInvMatrix.TransformBox(state.WorldAABB); + + var overlappingChunks = state.MapSystem.GetLocalMapChunks(data.Uid, data.Grid, localAABB); + + if (state.Approximate) + { + if (!overlappingChunks.MoveNext(out _)) + return true; + } + else if (!state.MapSystem.IsIntersecting(overlappingChunks, state.Shape, state.Transform, (data.Uid, data.Fixtures))) + { + return true; + } + + var callbackState = state.State; + var result = state.Callback(data.Uid, data.Grid, ref callbackState); + state.State = callbackState; + + return result; + }, worldAABB); + + // By-ref things + state = gridState.State; + } + + /// + /// Tests whether any of a collection of grid chunks intersect with a given region. + /// + private bool IsIntersecting( + ChunkEnumerator enumerator, + TShape shape, + Transform shapeTransform, + Entity grid) where TShape : IPhysShape + { + var gridTransform = _physics.GetPhysicsTransform(grid); + + while (enumerator.MoveNext(out var chunk)) + { + foreach (var id in chunk.Fixtures) + { + var fixture = grid.Comp.Fixtures[id]; + + for (var j = 0; j < fixture.Shape.ChildCount; j++) + { + if (_manifolds.TestOverlap(shape, 0, fixture.Shape, j, shapeTransform, gridTransform)) + { + return true; + } + } + } + } + + return false; + } + + private record struct GridQueryState( + GridCallback Callback, + TState State, + Box2 WorldAABB, + TShape Shape, + Transform Transform, + B2DynamicTree<(EntityUid Uid, FixturesComponent Fixtures, MapGridComponent Grid)> Tree, + SharedMapSystem MapSystem, + SharedTransformSystem TransformSystem, + bool Approximate + ) where TShape : IPhysShape; +} + +public delegate bool GridCallback(EntityUid gridUid, MapGridComponent gridComp); +public delegate bool GridCallback(EntityUid gridUid, MapGridComponent gridComp, ref TState state); diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.cs index 6c21c94534d..2e4c328a8e7 100644 --- a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.cs +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.cs @@ -21,6 +21,52 @@ namespace Robust.Shared.GameObjects; public abstract partial class SharedMapSystem { + #region CreateGrid + + /// + /// Creates a new grid entity on a given map. + /// + public Entity CreateGridEntity(MapId mapId, GridCreateOptions? options = null) + { + return CreateGridEntity(GetMap(mapId), options); + } + + /// + /// Creates a new grid entity on a given map. + /// + public Entity CreateGridEntity(EntityUid mapEnt, GridCreateOptions? options = null) + { + options ??= GridCreateOptions.Default; + return CreateGridInternal(mapEnt, options.Value); + } + + protected Entity CreateGridInternal(EntityUid mapEnt, GridCreateOptions options) + { + var gridEnt = EntityManager.CreateEntityUninitialized(null); + + var grid = EnsureComp(gridEnt); + grid.ChunkSize = options.ChunkSize; + + Log.Debug("Binding new grid {gridEnt}"); + + //TODO: This is a hack to get TransformComponent.MapId working before entity states + //are applied. After they are applied the parent may be different, but the MapId will + //be the same. This causes TransformComponent.ParentUid of a grid to be unsafe to + //use in transform states anytime before the state parent is properly set. + _transform.SetParent(gridEnt, mapEnt); + + var meta = _metaQuery.GetComponent(gridEnt); + EntityManager.System().SetEntityName(gridEnt, $"grid", meta); + EntityManager.InitializeComponents(gridEnt, meta); + EntityManager.StartComponents(gridEnt); + // Note that this does not actually map-initialize the grid entity, even if the map its being spawn on has already been initialized. + // I don't know whether that is intentional or not. + + return (gridEnt, grid); + } + + #endregion + #region Chunk helpers [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -322,7 +368,7 @@ private void ApplyChunkData( var gridIndices = deletedChunk.ChunkTileToGridTile((x, y)); var newTileRef = new TileRef(uid, gridIndices, Tile.Empty); - _mapInternal.RaiseOnTileChanged(gridEnt, newTileRef, oldTile, index); + RaiseOnTileChanged(gridEnt, newTileRef, oldTile, index); } } @@ -484,6 +530,20 @@ private void GetFullState(EntityUid uid, MapGridComponent component, ref Compone #endif } + /// + /// Prunes tracked grid chunk deletions older than some given game tick. + /// + public void CullDeletionHistory(GameTick upToTick) + { + var query = AllEntityQuery(); + + while (query.MoveNext(out var grid)) + { + var chunks = grid.ChunkDeletionHistory; + chunks.RemoveAll(t => t.tick < upToTick); + } + } + private void OnGridAdd(EntityUid uid, MapGridComponent component, ComponentAdd args) { var msg = new GridAddEvent(uid); @@ -846,7 +906,7 @@ public void SetTiles(EntityUid uid, MapGridComponent grid, List<(Vector2i GridIn // Suppress sending out events for each tile changed // We're going to send them all out together at the end - MapManager.SuppressOnTileChanged = true; + SuppressOnTileChanged = true; foreach (var (gridIndices, tile) in tiles) { @@ -883,7 +943,7 @@ public void SetTiles(EntityUid uid, MapGridComponent grid, List<(Vector2i GridIn RegenerateCollision(uid, grid, modified); // Back to normal - MapManager.SuppressOnTileChanged = false; + SuppressOnTileChanged = false; } public TilesEnumerator GetLocalTilesEnumerator(EntityUid uid, MapGridComponent grid, Box2 aabb, @@ -1631,10 +1691,10 @@ private void OnTileModified(EntityUid uid, MapGridComponent grid, MapChunk mapCh // The map serializer currently sets tiles of unbound grids as part of the deserialization process // It properly sets SuppressOnTileChanged so that the event isn't spammed for every tile on the grid. // ParentMapId is not able to be accessed on unbound grids, so we can't even call this function for unbound grids. - if (!MapManager.SuppressOnTileChanged) + if (!SuppressOnTileChanged) { var newTileRef = new TileRef(uid, gridTile, newTile); - _mapInternal.RaiseOnTileChanged((uid, grid), newTileRef, oldTile, mapChunk.Indices); + RaiseOnTileChanged((uid, grid), newTileRef, oldTile, mapChunk.Indices); } if (shapeChanged && !mapChunk.SuppressCollisionRegeneration) @@ -1643,6 +1703,18 @@ private void OnTileModified(EntityUid uid, MapGridComponent grid, MapChunk mapCh } } + /// + /// Raises on the provided grid unless is set. + /// + internal void RaiseOnTileChanged(Entity entity, TileRef tileRef, Tile oldTile, Vector2i chunk) + { + if (SuppressOnTileChanged) + return; + + var ev = new TileChangedEvent(entity, tileRef, oldTile, chunk); + EntityManager.EventBus.RaiseLocalEvent(entity.Owner, ref ev, true); + } + /// /// Iterates the local tiles of the specified data. /// @@ -1738,3 +1810,12 @@ public bool MoveNext(out TileRef tile) } } } + +/// +/// Additional parameters used when creating a new grid entity. +/// +/// The number of tiles long/wide the grids chunks should be. +public record struct GridCreateOptions(ushort ChunkSize) +{ + public readonly static GridCreateOptions Default = new(ChunkSize: 16); +} diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs index 2f99eb9c7ae..9564f3b849a 100644 --- a/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs @@ -8,6 +8,7 @@ using Robust.Shared.Maths; using Robust.Shared.Network; using Robust.Shared.Physics; +using Robust.Shared.Physics.Collision; using Robust.Shared.Physics.Systems; using Robust.Shared.Timing; using Robust.Shared.Utility; @@ -21,8 +22,7 @@ public abstract partial class SharedMapSystem : EntitySystem { [Dependency] private ITileDefinitionManager _tileMan = default!; [Dependency] private IGameTiming _timing = default!; - [Dependency] protected IMapManager MapManager = default!; - [Dependency] private IMapManagerInternal _mapInternal = default!; + [Dependency] private IManifoldManager _manifolds = default!; [Dependency] private INetManager _netManager = default!; [Dependency] private FixtureSystem _fixtures = default!; [Dependency] private SharedPhysicsSystem _physics = default!; @@ -34,9 +34,18 @@ public abstract partial class SharedMapSystem : EntitySystem private EntityQuery _gridQuery; private EntityQuery _metaQuery; private EntityQuery _xformQuery; + [Dependency] EntityQuery _gridTreeQuery; internal Dictionary Maps { get; } = new(); + /// + /// If set, this prevents the from being raised when modifying grids. + /// + /// + /// Useful if you want to create a new grid, delete an existing grid, or bulk-modify tiles and don't want to spam ten billion individual tile-changed events. + /// + internal bool SuppressOnTileChanged { get; set; } + /// /// This hashset is used to try prevent MapId re-use. This is mainly for auto-assigned map ids. /// Loading a map with a specific id (e.g., the various mapping commands) may still result in an id being diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs index 2fa10c984a6..6f90d0fa3f1 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -283,7 +283,7 @@ private void OnCompInit(EntityUid uid, TransformComponent component, ComponentIn // Entity may not be directly parented to the grid (e.g., spawned using some relative entity coordinates) // in that case, we attempt to attach to a grid. var pos = new MapCoordinates(GetWorldPosition(component), component.MapID); - if (_mapManager.TryFindGridAt(pos, out var gridUid, out gridComp)) + if (_map.TryFindGridAt(pos, out var gridUid, out gridComp)) grid = (gridUid, gridComp); } @@ -990,7 +990,7 @@ public void SetMapCoordinates(Entity entity, MapCoordinates { var mapUid = _map.GetMap(coordinates.MapId); if (!_gridQuery.HasComponent(entity) && - _mapManager.TryFindGridAt(mapUid, coordinates.Position, out var targetGrid, out _)) + _map.TryFindGridAt(mapUid, coordinates.Position, out var targetGrid, out _)) { var invWorldMatrix = GetInvWorldMatrix(targetGrid); SetCoordinates((entity.Owner, entity.Comp, MetaData(entity.Owner)), new EntityCoordinates(targetGrid, Vector2.Transform(coordinates.Position, invWorldMatrix))); @@ -1233,7 +1233,7 @@ private void SetWorldPositionRotationInternal(EntityUid uid, Vector2 worldPos, A return; } - if (component.GridUid != uid && _mapManager.TryFindGridAt(component.MapUid.Value, worldPos, out var targetGrid, out _)) + if (component.GridUid != uid && _map.TryFindGridAt(component.MapUid.Value, worldPos, out var targetGrid, out _)) { var targetGridXform = XformQuery.GetComponent(targetGrid); var invLocalMatrix = targetGridXform.InvLocalMatrix; @@ -1487,7 +1487,7 @@ public bool TryGetMapOrGridCoordinates( return false; var oldPos = GetWorldPosition(xform); - if (_mapManager.TryFindGridAt(map, oldPos, out var gridUid, out _) && !TerminatingOrDeleted(gridUid)) + if (_map.TryFindGridAt(map, oldPos, out var gridUid, out _) && !TerminatingOrDeleted(gridUid)) { coordinates = gridUid == xform.ParentUid ? new EntityCoordinates(gridUid, xform.LocalPosition) @@ -1747,7 +1747,7 @@ public bool SwapPositions(Entity entity1, Entity entity1, Entity +/// Pauses a given map, halting all entity processing on it. +/// +public sealed partial class PauseMapCommand : LocalizedEntityCommands +{ + [Dependency] SharedMapSystem _mapSystem = default!; + public override string Command => "pausemap"; + + public override void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 1) + { + shell.WriteError("Need to supply a valid MapId"); + return; + } + + var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture)); + + if (!_mapSystem.MapExists(mapId)) + { + shell.WriteError("That map does not exist."); + return; + } + + _mapSystem.SetPaused(mapId, true); + } +} + +/// +/// Unpauses a given map, resuming all entity processing on it. +/// +public sealed partial class UnpauseMapCommand : LocalizedEntityCommands +{ + [Dependency] SharedMapSystem _mapSystem = default!; + public override string Command => "unpausemap"; + + public override void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 1) + { + shell.WriteError("Need to supply a valid MapId"); + return; + } + + var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture)); + + if (!_mapSystem.MapExists(mapId)) + { + shell.WriteError("That map does not exist."); + return; + } + + _mapSystem.SetPaused(mapId, false); + } +} + +/// +/// Checks whether a given map is currently paused. +/// +public sealed partial class QueryMapPausedCommand : LocalizedEntityCommands +{ + [Dependency] SharedMapSystem _mapSystem = default!; + public override string Command => "querymappaused"; + + public override void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 1) + { + shell.WriteError("Need to supply a valid MapId"); + return; + } + + var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture)); + + if (!_mapSystem.MapExists(mapId)) + { + shell.WriteError("That map does not exist."); + return; + } + + shell.WriteLine(_mapSystem.IsPaused(mapId).ToString()); + } +} diff --git a/Robust.Shared/Map/Components/MapComponent.cs b/Robust.Shared/Map/Components/MapComponent.cs index 3633ad41cbd..5fae7461a3a 100644 --- a/Robust.Shared/Map/Components/MapComponent.cs +++ b/Robust.Shared/Map/Components/MapComponent.cs @@ -18,10 +18,10 @@ public sealed partial class MapComponent : Component [ViewVariables(VVAccess.ReadOnly), Access(typeof(SharedMapSystem), Other = AccessPermissions.ReadExecute)] public MapId MapId { get; internal set; } = MapId.Nullspace; - [DataField, Access(typeof(SharedMapSystem), typeof(MapManager))] + [DataField, Access(typeof(SharedMapSystem))] public bool MapPaused; - [DataField, Access(typeof(SharedMapSystem), typeof(MapManager))] + [DataField, Access(typeof(SharedMapSystem))] public bool MapInitialized; } diff --git a/Robust.Shared/Map/CoordinatesExtensions.cs b/Robust.Shared/Map/CoordinatesExtensions.cs index 120afdf691b..38c8560efa7 100644 --- a/Robust.Shared/Map/CoordinatesExtensions.cs +++ b/Robust.Shared/Map/CoordinatesExtensions.cs @@ -8,9 +8,9 @@ namespace Robust.Shared.Map { public static class CoordinatesExtensions { - public static EntityCoordinates AlignWithClosestGridTile(this EntityCoordinates coords, float searchBoxSize = 1.5f, IEntityManager? entityManager = null, IMapManager? mapManager = null) + public static EntityCoordinates AlignWithClosestGridTile(this EntityCoordinates coords, float searchBoxSize = 1.5f, IEntityManager? entityManager = null) { - IoCManager.Resolve(ref entityManager, ref mapManager); + IoCManager.Resolve(ref entityManager); var xform = entityManager.System(); var gridId = xform.GetGrid(coords); @@ -23,7 +23,7 @@ public static EntityCoordinates AlignWithClosestGridTile(this EntityCoordinates var mapCoords = xform.ToMapCoordinates(coords); - if (mapManager.TryFindGridAt(mapCoords, out var gridUid, out mapGrid)) + if (mapSystem.TryFindGridAt(mapCoords, out var gridUid, out mapGrid)) { return mapSystem.GridTileToLocal(gridUid, mapGrid, mapSystem.CoordinatesToTile(gridUid, mapGrid, coords)); } @@ -34,7 +34,7 @@ public static EntityCoordinates AlignWithClosestGridTile(this EntityCoordinates // find grids in search box var gridsInArea = new List>(); - mapManager.FindGridsIntersecting(mapCoords.MapId, gridSearchBox, ref gridsInArea); + mapSystem.FindGridsIntersecting(mapCoords.MapId, gridSearchBox, ref gridsInArea); // find closest grid intersecting our search box. gridUid = EntityUid.Invalid; diff --git a/Robust.Shared/Map/EntityCoordinates.cs b/Robust.Shared/Map/EntityCoordinates.cs index 323fe187cbf..4eaae6b7cea 100644 --- a/Robust.Shared/Map/EntityCoordinates.cs +++ b/Robust.Shared/Map/EntityCoordinates.cs @@ -95,18 +95,11 @@ public static EntityCoordinates FromMap(EntityUid entity, MapCoordinates coordin return transformSystem.ToCoordinates(entity, coordinates); } - [Obsolete("Use SharedTransformSystem.ToCoordinates()")] - public static EntityCoordinates FromMap(IMapManager mapManager, MapCoordinates coordinates) - { - return IoCManager.Resolve().System().ToCoordinates(coordinates); - } - /// /// Converts this set of coordinates to Vector2i. /// public Vector2i ToVector2i( IEntityManager entityManager, - IMapManager mapManager, SharedTransformSystem transformSystem) { if(!IsValid(entityManager)) diff --git a/Robust.Shared/Map/IMapManager.cs b/Robust.Shared/Map/IMapManager.cs deleted file mode 100644 index d0aaea4a5a4..00000000000 --- a/Robust.Shared/Map/IMapManager.cs +++ /dev/null @@ -1,246 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Numerics; -using JetBrains.Annotations; -using Robust.Shared.GameObjects; -using Robust.Shared.Map.Components; -using Robust.Shared.Maths; -using Robust.Shared.Physics; -using Robust.Shared.Physics.Collision.Shapes; - -namespace Robust.Shared.Map -{ - public delegate bool GridCallback(EntityUid uid, MapGridComponent grid); - - public delegate bool GridCallback(EntityUid uid, MapGridComponent grid, ref TState state); - - /// - /// This manages all the grids and maps in the world. Largely superseded by . - /// - [NotContentImplementable] - public interface IMapManager - { - public const bool Approximate = false; - public const bool IncludeMap = true; - - /// - /// Should the OnTileChanged event be suppressed? This is useful for initially loading the map - /// so that you don't spam an event for each of the million station tiles. - /// - bool SuppressOnTileChanged { get; set; } - - /// - /// Starts up the map system. - /// - void Initialize(); - - void Shutdown(); - void Startup(); - - void Restart(); - - [Obsolete("Use MapSystem")] - MapId CreateMap(MapId? mapId = null); - - /// - /// Check whether a map with specified ID exists. - /// - /// The map ID to check existence of. - /// True if the map exists, false otherwise. - [Obsolete("Use MapSystem")] - bool MapExists([NotNullWhen(true)] MapId? mapId); - - /// - /// Returns the map entity ID for a given map, or an invalid entity Id if the map does not exist. - /// - [Obsolete("Use MapSystem")] - EntityUid GetMapEntityId(MapId mapId); - - /// - /// Replaces GetMapEntity()'s throw-on-failure semantics. - /// - [Obsolete("Use MapSystem")] - EntityUid GetMapEntityIdOrThrow(MapId mapId); - - [Obsolete("Use MapSystem")] - IEnumerable GetAllMapIds(); - - [Obsolete("Use MapSystem")] - void DeleteMap(MapId mapId); - - // ReSharper disable once MethodOverloadWithOptionalParameter - MapGridComponent CreateGrid(MapId currentMapId, ushort chunkSize = 16); - MapGridComponent CreateGrid(MapId currentMapId, in GridCreateOptions options); - MapGridComponent CreateGrid(MapId currentMapId); - Entity CreateGridEntity(MapId currentMapId, GridCreateOptions? options = null); - Entity CreateGridEntity(EntityUid map, GridCreateOptions? options = null); - - IEnumerable GetAllMapGrids(MapId mapId); - - IEnumerable> GetAllGrids(MapId mapId); - - #region MapId - - public void FindGridsIntersecting(MapId mapId, T shape, Transform transform, - ref List> grids, bool approx = Approximate, bool includeMap = IncludeMap) where T : IPhysShape; - - public void FindGridsIntersecting(MapId mapId, T shape, Transform transform, GridCallback callback, - bool approx = Approximate, bool includeMap = IncludeMap) where T : IPhysShape; - - public void FindGridsIntersecting(MapId mapId, Box2 worldAABB, GridCallback callback, bool approx = Approximate, - bool includeMap = IncludeMap); - - public void FindGridsIntersecting(MapId mapId, Box2 worldAABB, ref TState state, - GridCallback callback, bool approx = Approximate, bool includeMap = IncludeMap); - - public void FindGridsIntersecting(MapId mapId, Box2 worldAABB, ref List> grids, - bool approx = Approximate, bool includeMap = IncludeMap); - - public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, GridCallback callback, - bool approx = Approximate, - bool includeMap = IncludeMap); - - public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, ref TState state, - GridCallback callback, - bool approx = Approximate, bool includeMap = IncludeMap); - - public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, ref List> grids, - bool approx = Approximate, bool includeMap = IncludeMap); - - #endregion - - #region MapEnt - - public void FindGridsIntersecting(EntityUid mapEnt, T shape, Transform transform, GridCallback callback, - bool approx = Approximate, bool includeMap = IncludeMap) where T : IPhysShape; - - public void FindGridsIntersecting(EntityUid mapEnt, T shape, Transform transform, - ref TState state, GridCallback callback, bool approx = Approximate, bool includeMap = IncludeMap) where T : IPhysShape; - - /// - /// Returns true if any grids overlap the specified shapes. - /// - public void FindGridsIntersecting(EntityUid mapEnt, List shapes, Transform transform, - ref List> entities, bool approx = Approximate, bool includeMap = IncludeMap); - - public void FindGridsIntersecting(EntityUid mapEnt, T shape, Transform transform, - ref List> grids, bool approx = Approximate, bool includeMap = IncludeMap) where T : IPhysShape; - - public void FindGridsIntersecting(EntityUid mapEnt, Box2 worldAABB, GridCallback callback, - bool approx = Approximate, bool includeMap = IncludeMap); - - public void FindGridsIntersecting(EntityUid mapEnt, Box2 worldAABB, ref TState state, - GridCallback callback, bool approx = Approximate, bool includeMap = IncludeMap); - - public void FindGridsIntersecting(EntityUid mapEnt, Box2 worldAABB, ref List> grids, - bool approx = Approximate, bool includeMap = IncludeMap); - - public void FindGridsIntersecting(EntityUid mapEnt, Box2Rotated worldBounds, GridCallback callback, - bool approx = Approximate, - bool includeMap = IncludeMap); - - public void FindGridsIntersecting(EntityUid mapEnt, Box2Rotated worldBounds, ref TState state, - GridCallback callback, - bool approx = Approximate, bool includeMap = IncludeMap); - - public void FindGridsIntersecting(EntityUid mapEnt, Box2Rotated worldBounds, - ref List> grids, - bool approx = Approximate, bool includeMap = IncludeMap); - - #endregion - - #region TryFindGridAt - - public bool TryFindGridAt( - EntityUid mapEnt, - Vector2 worldPos, - out EntityUid uid, - [NotNullWhen(true)] out MapGridComponent? grid); - - /// - /// Attempts to find the map grid under the map location. - /// - public bool TryFindGridAt(MapId mapId, Vector2 worldPos, out EntityUid uid, - [NotNullWhen(true)] out MapGridComponent? grid); - - /// - /// Attempts to find the map grid under the map location. - /// - public bool TryFindGridAt(MapCoordinates mapCoordinates, out EntityUid uid, - [NotNullWhen(true)] out MapGridComponent? grid); - - #endregion - - #region Obsolete - - [Obsolete] - public bool TryFindGridAt(MapId mapId, Vector2 worldPos, EntityQuery query, out EntityUid uid, [NotNullWhen(true)] out MapGridComponent? grid) - { - return TryFindGridAt(mapId, worldPos, out uid, out grid); - } - - [Obsolete] - public IEnumerable FindGridsIntersecting(MapId mapId, Box2 worldAabb, bool approx = false, bool includeMap = true) - { - var grids = new List>(); - FindGridsIntersecting(mapId, worldAabb, ref grids, approx, includeMap); - - foreach (var grid in grids) - { - yield return grid.Comp; - } - } - - [Obsolete] - public IEnumerable FindGridsIntersecting(MapId mapId, Box2Rotated worldArea, bool approx = false, bool includeMap = true) - { - var grids = new List>(); - FindGridsIntersecting(mapId, worldArea, ref grids, approx, includeMap); - - foreach (var grid in grids) - { - yield return grid.Comp; - } - } - - #endregion - - - [Obsolete("Just delete the grid entity")] - void DeleteGrid(EntityUid euid); - - [Obsolete("Use HasComp")] - bool IsGrid(EntityUid uid); - - [Obsolete("Use HasComp")] - bool IsMap(EntityUid uid); - - // - // Pausing functions - // - - [Obsolete("Use MapSystem")] - void SetMapPaused(MapId mapId, bool paused); - - [Obsolete("Use MapSystem")] - void DoMapInitialize(MapId mapId); - - [Obsolete("Use MapSystem")] - bool IsMapPaused(MapId mapId); - - [Obsolete("Use MapSystem")] - bool IsMapInitialized(MapId mapId); - - } - - public struct GridCreateOptions - { - public static readonly GridCreateOptions Default = new() - { - ChunkSize = 16 - }; - - public ushort ChunkSize; - } -} diff --git a/Robust.Shared/Map/IMapManagerInternal.cs b/Robust.Shared/Map/IMapManagerInternal.cs deleted file mode 100644 index e6a5b5b3637..00000000000 --- a/Robust.Shared/Map/IMapManagerInternal.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Robust.Shared.GameObjects; -using Robust.Shared.Map.Components; -using Robust.Shared.Maths; - -namespace Robust.Shared.Map -{ - /// - internal interface IMapManagerInternal : IMapManager - { - /// - /// Raises the OnTileChanged event. - /// - /// A reference to the new tile. - /// The old tile that got replaced. - void RaiseOnTileChanged(Entity entity, TileRef tileRef, Tile oldTile, Vector2i chunk); - } -} diff --git a/Robust.Shared/Map/MapId.cs b/Robust.Shared/Map/MapId.cs index 4045791de7c..e8848ee8f36 100644 --- a/Robust.Shared/Map/MapId.cs +++ b/Robust.Shared/Map/MapId.cs @@ -11,7 +11,6 @@ namespace Robust.Shared.Map /// All maps, aside from , are also entities. When writing generic code it's usually /// preferable to use or instead. /// - /// /// [Serializable, NetSerializable] public readonly struct MapId : IEquatable diff --git a/Robust.Shared/Map/MapManager.GridCollection.cs b/Robust.Shared/Map/MapManager.GridCollection.cs deleted file mode 100644 index cf23be33c1c..00000000000 --- a/Robust.Shared/Map/MapManager.GridCollection.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using Robust.Shared.GameObjects; -using Robust.Shared.Map.Components; -using Robust.Shared.Maths; -using Robust.Shared.Utility; - -// All the obsolete warnings about GridId are probably useless here. -#pragma warning disable CS0618 - -namespace Robust.Shared.Map; -internal partial class MapManager -{ - // ReSharper disable once MethodOverloadWithOptionalParameter - public MapGridComponent CreateGrid(MapId currentMapId, ushort chunkSize = 16) - { - return CreateGrid(GetMapEntityIdOrThrow(currentMapId), chunkSize, default); - } - - public MapGridComponent CreateGrid(MapId currentMapId, in GridCreateOptions options) - { - return CreateGrid(GetMapEntityIdOrThrow(currentMapId), options.ChunkSize, default); - } - - public MapGridComponent CreateGrid(MapId currentMapId) - { - return CreateGrid(currentMapId, GridCreateOptions.Default); - } - - public Entity CreateGridEntity(MapId currentMapId, GridCreateOptions? options = null) - { - return CreateGridEntity(GetMapEntityIdOrThrow(currentMapId), options); - } - - public Entity CreateGridEntity(EntityUid map, GridCreateOptions? options = null) - { - options ??= GridCreateOptions.Default; - return CreateGrid(map, options.Value.ChunkSize, default); - } - - [Obsolete("Use HasComponent(uid)")] - public bool IsGrid(EntityUid uid) - { - return EntityManager.HasComponent(uid); - } - - public IEnumerable GetAllMapGrids(MapId mapId) - { - var query = EntityManager.AllEntityQueryEnumerator(); - while (query.MoveNext(out var grid, out var xform)) - { - if (xform.MapID == mapId) - yield return grid; - } - } - - public IEnumerable> GetAllGrids(MapId mapId) - { - var query = EntityManager.AllEntityQueryEnumerator(); - while (query.MoveNext(out var uid, out var grid, out var xform)) - { - if (xform.MapID != mapId) - continue; - - yield return (uid, grid); - } - } - - public virtual void DeleteGrid(EntityUid euid) - { - // Possible the grid was already deleted / is invalid - if (!EntityManager.TryGetComponent(euid, out var iGrid)) - { - DebugTools.Assert($"Calling {nameof(DeleteGrid)} with unknown uid {euid}."); - return; // Silently fail on release - } - - if (!EntityManager.TryGetComponent(euid, out MetaDataComponent? metaComp)) - { - DebugTools.Assert($"Calling {nameof(DeleteGrid)} with {euid}, but there was no allocated entity."); - return; // Silently fail on release - } - - // DeleteGrid may be triggered by the entity being deleted, - // so make sure that's not the case. - if (metaComp.EntityLifeStage < EntityLifeStage.Terminating) - EntityManager.DeleteEntity(euid); - } - - /// - public bool SuppressOnTileChanged { get; set; } - - /// - /// Raises the OnTileChanged event. - /// - /// A reference to the new tile. - /// The old tile that got replaced. - void IMapManagerInternal.RaiseOnTileChanged(Entity entity, TileRef tileRef, Tile oldTile, Vector2i chunk) - { - if (SuppressOnTileChanged) - return; - - var ev = new TileChangedEvent(entity, tileRef, oldTile, chunk); - EntityManager.EventBus.RaiseLocalEvent(entity.Owner, ref ev, true); - } - - protected Entity CreateGrid(EntityUid map, ushort chunkSize, EntityUid forcedGridEuid) - { - var gridEnt = EntityManager.CreateEntityUninitialized(null, forcedGridEuid); - - var grid = EntityManager.AddComponent(gridEnt); - grid.ChunkSize = chunkSize; - - _sawmill.Debug($"Binding new grid {gridEnt}"); - - //TODO: This is a hack to get TransformComponent.MapId working before entity states - //are applied. After they are applied the parent may be different, but the MapId will - //be the same. This causes TransformComponent.ParentUid of a grid to be unsafe to - //use in transform states anytime before the state parent is properly set. - EntityManager.GetComponent(gridEnt).AttachParent(map); - - var meta = EntityManager.GetComponent(gridEnt); - EntityManager.System().SetEntityName(gridEnt, $"grid", meta); - EntityManager.InitializeComponents(gridEnt, meta); - EntityManager.StartComponents(gridEnt); - // Note that this does not actually map-initialize the grid entity, even if the map its being spawn on has already been initialized. - // I don't know whether that is intentional or not. - - return (gridEnt, grid); - } -} diff --git a/Robust.Shared/Map/MapManager.MapCollection.cs b/Robust.Shared/Map/MapManager.MapCollection.cs deleted file mode 100644 index e8a5f44e181..00000000000 --- a/Robust.Shared/Map/MapManager.MapCollection.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using Robust.Shared.GameObjects; -using Robust.Shared.Map.Components; - -namespace Robust.Shared.Map; - -/// -/// Arguments for when a map is created or deleted locally ore remotely. -/// -public sealed class MapEventArgs : EventArgs -{ - /// - /// Creates a new instance of this class. - /// - public MapEventArgs(MapId map) - { - Map = map; - } - - /// - /// Map that is being modified. - /// - public MapId Map { get; } -} - -internal partial class MapManager -{ - /// - public virtual void DeleteMap(MapId mapId) - { - _mapSystem.DeleteMap(mapId); - } - - /// - public MapId CreateMap(MapId? mapId = null) - { - if (mapId != null) - { - _mapSystem.CreateMap(mapId.Value); - return mapId.Value; - } - - _mapSystem.CreateMap(out var map); - return map; - } - - /// - public bool MapExists([NotNullWhen(true)] MapId? mapId) - { - return _mapSystem.MapExists(mapId); - } - - /// - public EntityUid GetMapEntityId(MapId mapId) - { - return _mapSystem.GetMapOrInvalid(mapId); - } - - /// - /// Replaces GetMapEntity()'s throw-on-failure semantics. - /// - public EntityUid GetMapEntityIdOrThrow(MapId mapId) - { - return _mapSystem.GetMap(mapId); - } - - public bool TryGetMap([NotNullWhen(true)] MapId? mapId, [NotNullWhen(true)] out EntityUid? uid) - { - return _mapSystem.TryGetMap(mapId, out uid); - } - - /// - public IEnumerable GetAllMapIds() - { - return _mapSystem.GetAllMapIds(); - } - - /// - public bool IsMap(EntityUid uid) - { - return EntityManager.HasComponent(uid); - } -} diff --git a/Robust.Shared/Map/MapManager.Pause.cs b/Robust.Shared/Map/MapManager.Pause.cs deleted file mode 100644 index d4fb8f58976..00000000000 --- a/Robust.Shared/Map/MapManager.Pause.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System.Globalization; -using Robust.Shared.GameObjects; - -namespace Robust.Shared.Map -{ - internal partial class MapManager - { - public void SetMapPaused(MapId mapId, bool paused) - { - _mapSystem.SetPaused(mapId, paused); - } - - public void SetMapPaused(EntityUid uid, bool paused) - { - _mapSystem.SetPaused(uid, paused); - } - - public void DoMapInitialize(MapId mapId) - { - _mapSystem.InitializeMap(mapId); - } - - public bool IsMapInitialized(MapId mapId) - { - return _mapSystem.IsInitialized(mapId); - } - - /// - public bool IsMapPaused(MapId mapId) - { - return _mapSystem.IsPaused(mapId); - } - - /// - public bool IsMapPaused(EntityUid uid) - { - return _mapSystem.IsPaused(uid); - } - - /// - /// Initializes the map pausing system. - /// - private void InitializeMapPausing() - { - _conhost.RegisterCommand("pausemap", - "Pauses a map, pausing all simulation processing on it.", - "pausemap ", - (shell, _, args) => - { - if (args.Length != 1) - { - shell.WriteError("Need to supply a valid MapId"); - return; - } - - var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture)); - - if (!MapExists(mapId)) - { - shell.WriteError("That map does not exist."); - return; - } - - SetMapPaused(mapId, true); - }); - - _conhost.RegisterCommand("querymappaused", - "Check whether a map is paused or not.", - "querymappaused ", - (shell, _, args) => - { - var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture)); - - if (!MapExists(mapId)) - { - shell.WriteError("That map does not exist."); - return; - } - - shell.WriteLine(_mapSystem.IsPaused(mapId).ToString()); - }); - - _conhost.RegisterCommand("unpausemap", - "unpauses a map, resuming all simulation processing on it.", - "Usage: unpausemap ", - (shell, _, args) => - { - if (args.Length != 1) - { - shell.WriteLine("Need to supply a valid MapId"); - return; - } - - var mapId = new MapId(int.Parse(args[0], CultureInfo.InvariantCulture)); - - if (!MapExists(mapId)) - { - shell.WriteLine("That map does not exist."); - return; - } - - SetMapPaused(mapId, false); - }); - } - } -} diff --git a/Robust.Shared/Map/MapManager.Queries.cs b/Robust.Shared/Map/MapManager.Queries.cs deleted file mode 100644 index f37a545525f..00000000000 --- a/Robust.Shared/Map/MapManager.Queries.cs +++ /dev/null @@ -1,365 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Numerics; -using Robust.Shared.GameObjects; -using Robust.Shared.Map.Components; -using Robust.Shared.Map.Enumerators; -using Robust.Shared.Maths; -using Robust.Shared.Physics; -using Robust.Shared.Physics.Collision.Shapes; -using Robust.Shared.Physics.Shapes; - -namespace Robust.Shared.Map; - -internal partial class MapManager -{ - private bool IsIntersecting( - ChunkEnumerator enumerator, - T shape, - Transform shapeTransform, - Entity grid) where T : IPhysShape - { - var gridTransform = _physics.GetPhysicsTransform(grid); - - while (enumerator.MoveNext(out var chunk)) - { - foreach (var id in chunk.Fixtures) - { - var fixture = grid.Comp.Fixtures[id]; - - for (var j = 0; j < fixture.Shape.ChildCount; j++) - { - if (_manifolds.TestOverlap(shape, 0, fixture.Shape, j, shapeTransform, gridTransform)) - { - return true; - } - } - } - } - - return false; - } - - #region MapId - - public void FindGridsIntersecting(MapId mapId, T shape, Transform transform, - ref List> grids, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) where T : IPhysShape - { - if (_mapSystem.TryGetMap(mapId, out var mapEnt)) - FindGridsIntersecting(mapEnt.Value, shape, transform, ref grids, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(MapId mapId, T shape, Transform transform, GridCallback callback, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) where T : IPhysShape - { - if (_mapSystem.TryGetMap(mapId, out var mapEnt)) - FindGridsIntersecting(mapEnt.Value, shape, transform, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(MapId mapId, Box2 worldAABB, GridCallback callback, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - if (_mapSystem.TryGetMap(mapId, out var mapEnt)) - FindGridsIntersecting(mapEnt.Value, worldAABB, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(MapId mapId, Box2 worldAABB, ref TState state, GridCallback callback, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - if (_mapSystem.TryGetMap(mapId, out var map)) - FindGridsIntersecting(map.Value, worldAABB, ref state, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(MapId mapId, Box2 worldAABB, ref List> grids, - bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - if (_mapSystem.TryGetMap(mapId, out var map)) - FindGridsIntersecting(map.Value, worldAABB, ref grids, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, GridCallback callback, bool approx = IMapManager.Approximate, - bool includeMap = IMapManager.IncludeMap) - { - if (_mapSystem.TryGetMap(mapId, out var mapEnt)) - FindGridsIntersecting(mapEnt.Value, worldBounds, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, ref TState state, GridCallback callback, - bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - if (_mapSystem.TryGetMap(mapId, out var mapEnt)) - FindGridsIntersecting(mapEnt.Value, worldBounds, ref state, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, ref List> grids, - bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - if (_mapSystem.TryGetMap(mapId, out var mapEnt)) - FindGridsIntersecting(mapEnt.Value, worldBounds, ref grids, approx: approx, includeMap: includeMap); - } - - #endregion - - #region MapEnt - - public void FindGridsIntersecting( - EntityUid mapEnt, - T shape, - Transform transform, - GridCallback callback, - bool approx = IMapManager.Approximate, - bool includeMap = IMapManager.IncludeMap) where T : IPhysShape - { - FindGridsIntersecting(mapEnt, shape, shape.ComputeAABB(transform, 0), transform, callback, approx: approx, includeMap: includeMap); - } - - private void FindGridsIntersecting(EntityUid mapEnt, T shape, Box2 worldAABB, Transform transform, GridCallback callback, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) where T : IPhysShape - { - // This is here so we don't double up on code. - var state = callback; - - FindGridsIntersecting(mapEnt, shape, worldAABB, transform, ref state, - static (EntityUid uid, MapGridComponent grid, ref GridCallback state) => state.Invoke(uid, grid), - approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting( - EntityUid mapEnt, - T shape, - Transform transform, - ref TState state, - GridCallback callback, - bool approx = IMapManager.Approximate, - bool includeMap = IMapManager.IncludeMap) where T : IPhysShape - { - FindGridsIntersecting(mapEnt, shape, shape.ComputeAABB(transform, 0), transform, ref state, callback, approx: approx, includeMap: includeMap); - } - - private void FindGridsIntersecting( - EntityUid mapEnt, - T shape, - Box2 worldAABB, - Transform transform, - ref TState state, - GridCallback callback, - bool approx = IMapManager.Approximate, - bool includeMap = IMapManager.IncludeMap) where T : IPhysShape - { - if (!_gridTreeQuery.TryGetComponent(mapEnt, out var gridTree)) - return; - - if (includeMap && _gridQuery.TryGetComponent(mapEnt, out var mapGrid)) - { - callback(mapEnt, mapGrid, ref state); - } - - var gridState = new GridQueryState( - callback, - state, - worldAABB, - shape, - transform, - gridTree.Tree, - _mapSystem, - this, - _transformSystem, - approx); - - gridTree.Tree.Query(ref gridState, static (ref GridQueryState state, DynamicTree.Proxy proxy) => - { - // Even for approximate we'll check if any chunks roughly overlap. - var data = state.Tree.GetUserData(proxy); - var gridInvMatrix = state.TransformSystem.GetInvWorldMatrix(data.Uid); - var localAABB = gridInvMatrix.TransformBox(state.WorldAABB); - - var overlappingChunks = state.MapSystem.GetLocalMapChunks(data.Uid, data.Grid, localAABB); - - if (state.Approximate) - { - if (!overlappingChunks.MoveNext(out _)) - return true; - } - else if (!state.MapManager.IsIntersecting(overlappingChunks, state.Shape, state.Transform, (data.Uid, data.Fixtures))) - { - return true; - } - - var callbackState = state.State; - var result = state.Callback(data.Uid, data.Grid, ref callbackState); - state.State = callbackState; - - return result; - }, worldAABB); - - // By-ref things - state = gridState.State; - } - - /// - /// Returns true if any grids overlap the specified shapes. - /// - public void FindGridsIntersecting(EntityUid mapEnt, List shapes, Transform transform, ref List> entities, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - foreach (var shape in shapes) - { - FindGridsIntersecting(mapEnt, shape, shape.ComputeAABB(transform, 0), transform, ref entities, approx: approx, includeMap: includeMap); - } - } - - public void FindGridsIntersecting(EntityUid mapEnt, T shape, Transform transform, - ref List> grids, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) where T : IPhysShape - { - FindGridsIntersecting(mapEnt, shape, shape.ComputeAABB(transform, 0), transform, ref grids, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(EntityUid mapEnt, T shape, Box2 worldAABB, Transform transform, - ref List> grids, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) where T : IPhysShape - { - var state = grids; - - FindGridsIntersecting(mapEnt, shape, worldAABB, transform, ref state, - static (EntityUid uid, MapGridComponent grid, ref List> list) => - { - list.Add((uid, grid)); - return true; - }, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(EntityUid mapEnt, Box2 worldAABB, GridCallback callback, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - var polygon = new SlimPolygon(worldAABB); - FindGridsIntersecting(mapEnt, polygon, worldAABB, Transform.Empty, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(EntityUid mapEnt, Box2 worldAABB, ref TState state, GridCallback callback, bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - var polygon = new SlimPolygon(worldAABB); - FindGridsIntersecting(mapEnt, polygon, worldAABB, Transform.Empty, ref state, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(EntityUid mapEnt, Box2 worldAABB, ref List> grids, - bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - var polygon = new SlimPolygon(worldAABB); - FindGridsIntersecting(mapEnt, polygon, worldAABB, Transform.Empty, ref grids, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(EntityUid mapEnt, Box2Rotated worldBounds, GridCallback callback, bool approx = IMapManager.Approximate, - bool includeMap = IMapManager.IncludeMap) - { - var polygon = new SlimPolygon(worldBounds); - FindGridsIntersecting(mapEnt, polygon, worldBounds.CalcBoundingBox(), Transform.Empty, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(EntityUid mapEnt, Box2Rotated worldBounds, ref TState state, GridCallback callback, - bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - var polygon = new SlimPolygon(worldBounds); - FindGridsIntersecting(mapEnt, polygon, worldBounds.CalcBoundingBox(), Transform.Empty, ref state, callback, approx: approx, includeMap: includeMap); - } - - public void FindGridsIntersecting(EntityUid mapEnt, Box2Rotated worldBounds, ref List> grids, - bool approx = IMapManager.Approximate, bool includeMap = IMapManager.IncludeMap) - { - var polygon = new SlimPolygon(worldBounds); - FindGridsIntersecting(mapEnt, polygon, worldBounds.CalcBoundingBox(), Transform.Empty, ref grids, approx: approx, includeMap: includeMap); - } - - #endregion - - #region TryFindGridAt - - public bool TryFindGridAt( - EntityUid mapEnt, - Vector2 worldPos, - out EntityUid uid, - [NotNullWhen(true)] out MapGridComponent? grid) - { - var rangeVec = new Vector2(0.2f, 0.2f); - - // Need to enlarge the AABB by at least the grid shrinkage size. - var aabb = new Box2(worldPos - rangeVec, worldPos + rangeVec); - - uid = EntityUid.Invalid; - grid = null; - var state = (uid, grid, worldPos, _mapSystem, _transformSystem); - - FindGridsIntersecting(mapEnt, aabb, ref state, static (EntityUid iUid, MapGridComponent iGrid, ref ( - EntityUid uid, - MapGridComponent? grid, - Vector2 worldPos, - SharedMapSystem mapSystem, - SharedTransformSystem xformSystem) tuple) => - { - // Turn the worldPos into a localPos and work out the relevant chunk we need to check - // This is much faster than iterating over every chunk individually. - // (though now we need some extra calcs up front). - - // Doesn't use WorldBounds because it's just an AABB. - var matrix = tuple.xformSystem.GetInvWorldMatrix(iUid); - var localPos = Vector2.Transform(tuple.worldPos, matrix); - - // NOTE: - // If you change this to use fixtures instead (i.e. if you want half-tiles) then you need to make sure - // you account for the fact that fixtures are shrunk slightly! - var chunkIndices = SharedMapSystem.GetChunkIndices(localPos, iGrid.ChunkSize); - - if (!iGrid.Chunks.TryGetValue(chunkIndices, out var chunk)) - return true; - - var chunkRelative = SharedMapSystem.GetChunkRelative(localPos, iGrid.ChunkSize); - var chunkTile = chunk.GetTile(chunkRelative); - - if (chunkTile.IsEmpty) - return true; - - tuple.uid = iUid; - tuple.grid = iGrid; - return false; - }, approx: true, includeMap: false); - - if (state.grid == null && _gridQuery.TryGetComponent(mapEnt, out var mapGrid)) - { - uid = mapEnt; - grid = mapGrid; - return true; - } - - uid = state.uid; - grid = state.grid; - return grid != null; - } - - /// - /// Attempts to find the map grid under the map location. - /// - public bool TryFindGridAt(MapId mapId, Vector2 worldPos, out EntityUid uid, [NotNullWhen(true)] out MapGridComponent? grid) - { - if (_mapSystem.TryGetMap(mapId, out var map)) - return TryFindGridAt(map.Value, worldPos, out uid, out grid); - - uid = default; - grid = null; - return false; - } - - /// - /// Attempts to find the map grid under the map location. - /// - public bool TryFindGridAt(MapCoordinates mapCoordinates, out EntityUid uid, [NotNullWhen(true)] out MapGridComponent? grid) - { - return TryFindGridAt(mapCoordinates.MapId, mapCoordinates.Position, out uid, out grid); - } - - #endregion - - private record struct GridQueryState( - GridCallback Callback, - TState State, - Box2 WorldAABB, - T Shape, - Transform Transform, - B2DynamicTree<(EntityUid Uid, FixturesComponent Fixtures, MapGridComponent Grid)> Tree, - SharedMapSystem MapSystem, - MapManager MapManager, - SharedTransformSystem TransformSystem, - bool Approximate); -} diff --git a/Robust.Shared/Map/MapManager.cs b/Robust.Shared/Map/MapManager.cs deleted file mode 100644 index c5e853c8b63..00000000000 --- a/Robust.Shared/Map/MapManager.cs +++ /dev/null @@ -1,78 +0,0 @@ -using Robust.Shared.Console; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Log; -using Robust.Shared.Map.Components; -using Robust.Shared.Physics.Collision; -using Robust.Shared.Physics.Systems; -using Robust.Shared.Timing; - -namespace Robust.Shared.Map; - -/// -[Virtual] -internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber -{ - [Dependency] public IGameTiming GameTiming = default!; - [Dependency] public IEntityManager EntityManager = default!; - [Dependency] private IManifoldManager _manifolds = default!; - [Dependency] private ILogManager _logManager = default!; - [Dependency] private IConsoleHost _conhost = default!; - - private ISawmill _sawmill = default!; - - private SharedMapSystem _mapSystem = default!; - private SharedPhysicsSystem _physics = default!; - private SharedTransformSystem _transformSystem = default!; - - private EntityQuery _gridTreeQuery; - private EntityQuery _gridQuery; - - /// - public void Initialize() - { - _gridTreeQuery = EntityManager.GetEntityQuery(); - _gridQuery = EntityManager.GetEntityQuery(); - InitializeMapPausing(); - _sawmill = _logManager.GetSawmill("system.map"); - } - - /// - public void Startup() - { - _physics = EntityManager.System(); - _transformSystem = EntityManager.System(); - _mapSystem = EntityManager.System(); - - _sawmill.Debug("Starting..."); - } - - /// - public void Shutdown() - { - _sawmill.Debug("Stopping..."); - - // TODO: AllEntityQuery instead??? - var query = EntityManager.EntityQueryEnumerator(); - - while (query.MoveNext(out var uid, out _)) - { - EntityManager.DeleteEntity(uid); - } - } - - /// - public void Restart() - { - _sawmill.Debug("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. - var query = EntityManager.EntityQueryEnumerator(); - - while (query.MoveNext(out var uid, out _)) - { - EntityManager.DeleteEntity(uid); - } - } -} diff --git a/Robust.Shared/Map/NetworkedMapManager.cs b/Robust.Shared/Map/NetworkedMapManager.cs deleted file mode 100644 index 683916bc46d..00000000000 --- a/Robust.Shared/Map/NetworkedMapManager.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Robust.Shared.Map.Components; -using Robust.Shared.Timing; - -namespace Robust.Shared.Map; - -internal interface INetworkedMapManager : IMapManagerInternal -{ - void CullDeletionHistory(GameTick upToTick); -} - -internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager -{ - public void CullDeletionHistory(GameTick upToTick) - { - var query = EntityManager.AllEntityQueryEnumerator(); - - while (query.MoveNext(out var grid)) - { - var chunks = grid.ChunkDeletionHistory; - chunks.RemoveAll(t => t.tick < upToTick); - } - } -} diff --git a/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs b/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs index e6fbf61f9b2..17d2108adef 100644 --- a/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs +++ b/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs @@ -18,7 +18,6 @@ namespace Robust.Shared.Physics.Systems public abstract partial class SharedBroadphaseSystem : EntitySystem { [Dependency] private IConfigurationManager _cfg = default!; - [Dependency] private IMapManagerInternal _mapManager = default!; [Dependency] private IParallelManager _parallel = default!; [Dependency] private EntityLookupSystem _lookup = default!; [Dependency] private SharedGridTraversalSystem _traversal = default!; @@ -51,9 +50,9 @@ public override void Initialize() _contactJob = new() { - MapManager = _mapManager, System = this, TransformSys = EntityManager.System(), + MapSys = _map, // TODO: EntityManager one isn't ready yet? XformQuery = GetEntityQuery(), }; @@ -265,7 +264,7 @@ private void HandleGridCollisions(HashSet movedGrids) _physicsQuery, _xformQuery); - _mapManager.FindGridsIntersecting(xform.MapID, aabb, ref state, + _map.FindGridsIntersecting(xform.MapID, aabb, ref state, static (EntityUid gridBUid, MapGridComponent gridBMapComp, ref (Entity gridA, Transform gridAToWorldRigid, @@ -541,7 +540,7 @@ internal void GetBroadphases(MapId mapId, Box2 aabb, BroadphaseCallback callback if (_broadphaseQuery.TryGetComponent(map.Value, out var mapBroadphase)) callback((map.Value, mapBroadphase)); - _mapManager.FindGridsIntersecting(map.Value, + _map.FindGridsIntersecting(map.Value, aabb, ref internalState, static ( @@ -569,7 +568,7 @@ internal void GetBroadphases(MapId mapId, Box2 aabb, ref TState state, B if (_broadphaseQuery.TryGetComponent(map.Value, out var mapBroadphase)) callback((map.Value, mapBroadphase), ref state); - _mapManager.FindGridsIntersecting(map.Value, + _map.FindGridsIntersecting(map.Value, aabb, ref internalState, static ( @@ -596,7 +595,7 @@ private record struct BroadphaseContactJob() : IParallelRobustJob { public SharedBroadphaseSystem System = default!; public SharedTransformSystem TransformSys = default!; - public IMapManager MapManager = default!; + public SharedMapSystem MapSys = default!; public EntityQuery XformQuery; @@ -626,7 +625,7 @@ public void Execute(int index) var state = (System, proxy, worldAABB, Pairs); // Get every broadphase we may be intersecting. - MapManager.FindGridsIntersecting(mapUid, worldAABB.Enlarged(broadphaseExpand), ref state, + MapSys.FindGridsIntersecting(mapUid, worldAABB.Enlarged(broadphaseExpand), ref state, static (EntityUid uid, MapGridComponent _, ref ( SharedBroadphaseSystem system, FixtureProxy proxy, diff --git a/Robust.UnitTesting/IIntegrationInstance.cs b/Robust.UnitTesting/IIntegrationInstance.cs index f7c00c1f5c2..5585120fb83 100644 --- a/Robust.UnitTesting/IIntegrationInstance.cs +++ b/Robust.UnitTesting/IIntegrationInstance.cs @@ -31,7 +31,6 @@ public interface IIntegrationInstance : IDisposable IConfigurationManager CfgMan { get; } ISharedPlayerManager PlayerMan { get; } INetManager NetMan { get; } - IMapManager MapMan { get; } IGameTiming Timing { get; } ISawmill Log { get; } diff --git a/Robust.UnitTesting/Pool/TestPair.Helpers.cs b/Robust.UnitTesting/Pool/TestPair.Helpers.cs index 624b7241e35..f40c39f0a59 100644 --- a/Robust.UnitTesting/Pool/TestPair.Helpers.cs +++ b/Robust.UnitTesting/Pool/TestPair.Helpers.cs @@ -281,7 +281,7 @@ public async Task CreateTestMap(bool initialized, ushort tileTypeId await Server.WaitPost(() => { TestMap.MapUid = sys.CreateMap(out TestMap.MapId, runMapInit: initialized); - TestMap.Grid = Server.MapMan.CreateGridEntity(TestMap.MapId); + TestMap.Grid = sys.CreateGridEntity(TestMap.MapId); TestMap.GridCoords = new EntityCoordinates(TestMap.Grid, 0, 0); TestMap.MapCoords = new MapCoordinates(0, 0, TestMap.MapId); sys.SetTile(TestMap.Grid.Owner, TestMap.Grid.Comp, TestMap.GridCoords, new Tile(tileTypeId)); diff --git a/Robust.UnitTesting/RobustIntegrationTest.cs b/Robust.UnitTesting/RobustIntegrationTest.cs index 48be5149599..ab299c4ab56 100644 --- a/Robust.UnitTesting/RobustIntegrationTest.cs +++ b/Robust.UnitTesting/RobustIntegrationTest.cs @@ -323,7 +323,6 @@ public abstract class IntegrationInstance : IIntegrationInstance public ISharedPlayerManager PlayerMan { get; private set; } = default!; public INetManager NetMan { get; private set; } = default!; public IGameTiming Timing { get; private set; } = default!; - public IMapManager MapMan { get; private set; } = default!; public IConsoleHost ConsoleHost { get; private set; } = default!; public ISawmill Log { get; private set; } = default!; @@ -335,7 +334,6 @@ protected virtual void ResolveIoC(IDependencyCollection deps) PlayerMan = deps.Resolve(); Timing = deps.Resolve(); NetMan = deps.Resolve(); - MapMan = deps.Resolve(); ConsoleHost = deps.Resolve(); Log = deps.Resolve().GetSawmill("test"); } diff --git a/Robust.UnitTesting/RobustUnitTest.cs b/Robust.UnitTesting/RobustUnitTest.cs index 71e63806ac7..bdfc90ed64f 100644 --- a/Robust.UnitTesting/RobustUnitTest.cs +++ b/Robust.UnitTesting/RobustUnitTest.cs @@ -161,7 +161,6 @@ public void BaseSetup() } var entMan = deps.Resolve(); - var mapMan = deps.Resolve(); // Avoid discovering EntityCommands since they may depend on systems // that aren't available in a unit test context. @@ -193,7 +192,6 @@ public void BaseSetup() // RobustUnitTest is complete hot garbage. // This makes EventTables ignore *all* the screwed up component abuse it causes. entMan.EventBus.OnlyCallOnRobustUnitTestISwearToGodPleaseSomebodyKillThisNightmare(); // The nightmare never ends - mapMan.Initialize(); systems.Initialize(); deps.Resolve().LoadAssemblies(assemblies); @@ -203,7 +201,6 @@ public void BaseSetup() modLoader.TryLoadModulesFrom(ResPath.Root, ""); entMan.Startup(); - mapMan.Startup(); } [OneTimeTearDown]