From 48841a274d7beefaeb1e1a2eea122fd09095ed40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= <6766154+Zumorica@users.noreply.github.com> Date: Wed, 21 Oct 2020 17:13:41 +0200 Subject: [PATCH] Remove default grids (content) (#2241) * Default grids go poof * Address review * Update submodule * Fix DoAfterSystem for entities without grid. * Fix SubFloorHideSystem for entities without grid. * Fix ExplosionHelper for coordinates that aren't in a grid * Fix TurfHelpers' GetWorldTileBox crash in the case of invalid grid * Fix tile prying component crash when trying to pry space. * Spill fixes when passing coordinates without grids. * Are you static'in, son? * Change SaveLoadSaveTest grid Id hardcoded value It's still hardcoded, but at least now it's correct! * Only send debug AI thing if grid is not invalid * Update submodule. Co-authored-by: Pieter-Jan Briers --- .../EntitySystems/SubFloorHideSystem.cs | 3 +- Content.Client/State/GameScreenBase.cs | 6 +- .../UserInterface/ItemSlotManager.cs | 10 +-- .../Tests/SaveLoadSaveTest.cs | 3 +- Content.Server/Atmos/TileAtmosphere.cs | 8 +-- Content.Server/Explosions/ExplosionHelper.cs | 64 ++++++++++--------- .../Atmos/GridAtmosphereComponent.cs | 7 +- .../Components/Fluids/SpillExtensions.cs | 14 ++-- .../Interactable/TilePryingComponent.cs | 4 +- .../PowerProviderComponent.cs | 2 +- .../Accessible/AiReachableSystem.cs | 5 +- .../EntitySystems/DoAfter/DoAfterSystem.cs | 6 +- Content.Shared/Maps/TurfHelpers.cs | 20 +++--- RobustToolbox | 2 +- 14 files changed, 76 insertions(+), 78 deletions(-) diff --git a/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs b/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs index 5ac823dbce..d4f4352bd9 100644 --- a/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs @@ -37,8 +37,7 @@ namespace Content.Client.GameObjects.EntitySystems { foreach (var comp in EntityManager.ComponentManager.EntityQuery()) { - var gridId = comp.Owner.Transform.GridID; - var grid = _mapManager.GetGrid(gridId); + if (!_mapManager.TryGetGrid(comp.Owner.Transform.GridID, out var grid)) return; var snapPos = comp.Owner.GetComponent(); UpdateTile(grid, snapPos.Position); diff --git a/Content.Client/State/GameScreenBase.cs b/Content.Client/State/GameScreenBase.cs index 0e0c5bcb04..3e0fa48f65 100644 --- a/Content.Client/State/GameScreenBase.cs +++ b/Content.Client/State/GameScreenBase.cs @@ -209,11 +209,11 @@ namespace Content.Client.State var mousePosWorld = EyeManager.ScreenToMap(args.PointerLocation); var entityToClick = GetEntityUnderPosition(mousePosWorld); - if (!MapManager.TryFindGridAt(mousePosWorld, out var grid)) - grid = MapManager.GetDefaultGrid(mousePosWorld.MapId); + var coordinates = MapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) : + EntityCoordinates.FromMap(EntityManager, MapManager, mousePosWorld); var message = new FullInputCmdMessage(Timing.CurTick, Timing.TickFraction, funcId, args.State, - grid.MapToGrid(mousePosWorld), args.PointerLocation, + coordinates , args.PointerLocation, entityToClick?.Uid ?? EntityUid.Invalid); // client side command handlers will always be sent the local player session. diff --git a/Content.Client/UserInterface/ItemSlotManager.cs b/Content.Client/UserInterface/ItemSlotManager.cs index ee72f3c908..19ccaa4977 100644 --- a/Content.Client/UserInterface/ItemSlotManager.cs +++ b/Content.Client/UserInterface/ItemSlotManager.cs @@ -70,18 +70,20 @@ namespace Content.Client.UserInterface var func = args.Function; var funcId = _inputManager.NetworkBindMap.KeyFunctionID(args.Function); + var mousePosWorld = _eyeManager.ScreenToMap(args.PointerLocation); - if (!_mapManager.TryFindGridAt(mousePosWorld, out var grid)) - grid = _mapManager.GetDefaultGrid(mousePosWorld.MapId); + + var coordinates = _mapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) : + EntityCoordinates.FromMap(_entityManager, _mapManager, mousePosWorld); var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, funcId, BoundKeyState.Down, - grid.MapToGrid(mousePosWorld), args.PointerLocation, item.Uid); + coordinates, args.PointerLocation, item.Uid); // client side command handlers will always be sent the local player session. var session = _playerManager.LocalPlayer?.Session; if (session == null) return false; - + inputSys.HandleInputCommand(session, func, message); } else diff --git a/Content.IntegrationTests/Tests/SaveLoadSaveTest.cs b/Content.IntegrationTests/Tests/SaveLoadSaveTest.cs index cb4a8d3ea4..d130e3f821 100644 --- a/Content.IntegrationTests/Tests/SaveLoadSaveTest.cs +++ b/Content.IntegrationTests/Tests/SaveLoadSaveTest.cs @@ -26,7 +26,8 @@ namespace Content.IntegrationTests.Tests var mapManager = server.ResolveDependency(); server.Post(() => { - mapLoader.SaveBlueprint(new GridId(2), "save load save 1.yml"); + // TODO: Un-hardcode the grid Id for this test. + mapLoader.SaveBlueprint(new GridId(1), "save load save 1.yml"); var mapId = mapManager.CreateMap(); var grid = mapLoader.LoadBlueprint(mapId, "save load save 1.yml"); mapLoader.SaveBlueprint(grid.Index, "save load save 2.yml"); diff --git a/Content.Server/Atmos/TileAtmosphere.cs b/Content.Server/Atmos/TileAtmosphere.cs index 9653642e92..d885790d26 100644 --- a/Content.Server/Atmos/TileAtmosphere.cs +++ b/Content.Server/Atmos/TileAtmosphere.cs @@ -42,10 +42,7 @@ namespace Content.Server.Atmos [ViewVariables] private int _currentCycle; [ViewVariables] - private static GasTileOverlaySystem _gasTileOverlaySystem; - - [ViewVariables] - public float Temperature {get; private set; } = Atmospherics.T20C; + public float Temperature { get; private set; } = Atmospherics.T20C; [ViewVariables] private float _temperatureArchived = Atmospherics.T20C; @@ -1138,8 +1135,7 @@ namespace Content.Server.Atmos { if (Air == null) return; - _gasTileOverlaySystem ??= EntitySystem.Get(); - _gasTileOverlaySystem.Invalidate(GridIndex, GridIndices); + _gridAtmosphereComponent.GasTileOverlaySystem.Invalidate(GridIndex, GridIndices); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Content.Server/Explosions/ExplosionHelper.cs b/Content.Server/Explosions/ExplosionHelper.cs index b5e13936d6..7a0e47bc9a 100644 --- a/Content.Server/Explosions/ExplosionHelper.cs +++ b/Content.Server/Explosions/ExplosionHelper.cs @@ -75,42 +75,44 @@ namespace Content.Server.Explosions //Tile damage calculation mockup //TODO: make it into some sort of actual damage component or whatever the boys think is appropriate - var mapGrid = mapManager.GetGrid(coords.GetGridId(entityManager)); - var circle = new Circle(coords.Position, maxRange); - var tiles = mapGrid.GetTilesIntersecting(circle); - foreach (var tile in tiles) + if (mapManager.TryGetGrid(coords.GetGridId(entityManager), out var mapGrid)) { - var tileLoc = mapGrid.GridTileToLocal(tile.GridIndices); - var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId]; - var baseTurfs = tileDef.BaseTurfs; - if (baseTurfs.Count == 0) + var circle = new Circle(coords.Position, maxRange); + var tiles = mapGrid?.GetTilesIntersecting(circle); + foreach (var tile in tiles) { - continue; - } + var tileLoc = mapGrid.GridTileToLocal(tile.GridIndices); + var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId]; + var baseTurfs = tileDef.BaseTurfs; + if (baseTurfs.Count == 0) + { + continue; + } - if (!tileLoc.TryDistance(entityManager, coords, out var distance)) - { - continue; - } + if (!tileLoc.TryDistance(entityManager, coords, out var distance)) + { + continue; + } - var zeroTile = new Tile(tileDefinitionManager[baseTurfs[0]].TileId); - var previousTile = new Tile(tileDefinitionManager[baseTurfs[^1]].TileId); + var zeroTile = new Tile(tileDefinitionManager[baseTurfs[0]].TileId); + var previousTile = new Tile(tileDefinitionManager[baseTurfs[^1]].TileId); - switch (distance) - { - case var d when d < devastationRange: - mapGrid.SetTile(tileLoc, zeroTile); - break; - case var d when d < heavyImpactRange - && !previousTile.IsEmpty - && robustRandom.Prob(0.8f): - mapGrid.SetTile(tileLoc, previousTile); - break; - case var d when d < lightImpactRange - && !previousTile.IsEmpty - && robustRandom.Prob(0.5f): - mapGrid.SetTile(tileLoc, previousTile); - break; + switch (distance) + { + case var d when d < devastationRange: + mapGrid.SetTile(tileLoc, zeroTile); + break; + case var d when d < heavyImpactRange + && !previousTile.IsEmpty + && robustRandom.Prob(0.8f): + mapGrid.SetTile(tileLoc, previousTile); + break; + case var d when d < lightImpactRange + && !previousTile.IsEmpty + && robustRandom.Prob(0.5f): + mapGrid.SetTile(tileLoc, previousTile); + break; + } } } diff --git a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs index e8b1570ddc..df501e9bee 100644 --- a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs @@ -8,6 +8,7 @@ using Content.Server.Atmos; using Content.Server.GameObjects.Components.Atmos.Piping; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.EntitySystems; +using Content.Server.GameObjects.EntitySystems.Atmos; using Content.Shared.Atmos; using Content.Shared.Maps; using Robust.Server.GameObjects.EntitySystems.TileLookup; @@ -39,6 +40,7 @@ namespace Content.Server.GameObjects.Components.Atmos [Robust.Shared.IoC.Dependency] private IServerEntityManager _serverEntityManager = default!; public GridTileLookupSystem GridTileLookupSystem { get; private set; } = default!; + internal GasTileOverlaySystem GasTileOverlaySystem { get; private set; } = default!; public AtmosphereSystem AtmosphereSystem { get; private set; } = default!; /// @@ -173,10 +175,11 @@ namespace Content.Server.GameObjects.Components.Atmos public override void Initialize() { base.Initialize(); - RepopulateTiles(); - GridTileLookupSystem = EntitySystem.Get(); + GasTileOverlaySystem = EntitySystem.Get(); AtmosphereSystem = EntitySystem.Get(); + + RepopulateTiles(); } public override void OnAdd() diff --git a/Content.Server/GameObjects/Components/Fluids/SpillExtensions.cs b/Content.Server/GameObjects/Components/Fluids/SpillExtensions.cs index b3645d821a..6bbcb72f5f 100644 --- a/Content.Server/GameObjects/Components/Fluids/SpillExtensions.cs +++ b/Content.Server/GameObjects/Components/Fluids/SpillExtensions.cs @@ -66,8 +66,8 @@ namespace Content.Server.GameObjects.Components.Fluids var entityManager = IoCManager.Resolve(); var serverEntityManager = IoCManager.Resolve(); - var gridId = coordinates.GetGridId(entityManager); - var mapGrid = mapManager.GetGrid(gridId); + if (!mapManager.TryGetGrid(coordinates.GetGridId(entityManager), out var mapGrid)) + return null; // Let's not spill to space. // If space return early, let that spill go out into the void var tileRef = mapGrid.GetTileRef(coordinates); @@ -78,13 +78,11 @@ namespace Content.Server.GameObjects.Components.Fluids // Get normalized co-ordinate for spill location and spill it in the centre // TODO: Does SnapGrid or something else already do this? - var spillTileMapGrid = mapManager.GetGrid(gridId); - var spillTileRef = spillTileMapGrid.GetTileRef(coordinates).GridIndices; - var spillGridCoords = spillTileMapGrid.GridTileToLocal(spillTileRef); + var spillGridCoords = mapGrid.GridTileToLocal(tileRef.GridIndices); var spilt = false; - foreach (var spillEntity in entityManager.GetEntitiesAt(spillTileMapGrid.ParentMapId, spillGridCoords.Position)) + foreach (var spillEntity in entityManager.GetEntitiesAt(mapGrid.ParentMapId, spillGridCoords.Position)) { if (!spillEntity.TryGetComponent(out PuddleComponent? puddleComponent)) { @@ -167,7 +165,9 @@ namespace Content.Server.GameObjects.Components.Fluids // Get normalized co-ordinate for spill location and spill it in the centre // TODO: Does SnapGrid or something else already do this? - var spillTileMapGrid = mapManager.GetGrid(gridId); + if (!mapManager.TryGetGrid(gridId, out var spillTileMapGrid)) + return null; // Let's not spill to invalid grids. + var spillGridCoords = spillTileMapGrid.GridTileToLocal(tileRef.GridIndices); var spilt = false; diff --git a/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs b/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs index 848c8ceba6..5b0fdd854a 100644 --- a/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs @@ -36,7 +36,9 @@ namespace Content.Server.GameObjects.Components.Interactable if (!Owner.TryGetComponent(out var tool) && _toolComponentNeeded) return; - var mapGrid = _mapManager.GetGrid(clickLocation.GetGridId(Owner.EntityManager)); + if (!_mapManager.TryGetGrid(clickLocation.GetGridId(Owner.EntityManager), out var mapGrid)) + return; + var tile = mapGrid.GetTileRef(clickLocation); var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs index ed5819f3b5..4b53fcec71 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs @@ -113,7 +113,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents private void SetPowerTransferRange(int newPowerTransferRange) { - foreach (var receiver in _linkedReceivers) + foreach (var receiver in _linkedReceivers.ToArray()) { receiver.ClearProvider(); } diff --git a/Content.Server/GameObjects/EntitySystems/AI/Pathfinding/Accessible/AiReachableSystem.cs b/Content.Server/GameObjects/EntitySystems/AI/Pathfinding/Accessible/AiReachableSystem.cs index ac26f3a243..5bf8a1d419 100644 --- a/Content.Server/GameObjects/EntitySystems/AI/Pathfinding/Accessible/AiReachableSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AI/Pathfinding/Accessible/AiReachableSystem.cs @@ -621,7 +621,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible /// private void GenerateRegions(PathfindingChunk chunk) { - // Grid deleted while update queued. + // Grid deleted while update queued, or invalid grid. if (!_mapManager.TryGetGrid(chunk.GridId, out _)) { return; @@ -688,7 +688,8 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible private void SendDebugMessage(PlayerAttachSystemMessage message) { var playerGrid = message.Entity.Transform.GridID; - SendRegionsDebugMessage(playerGrid); + if(playerGrid.IsValid()) + SendRegionsDebugMessage(playerGrid); } private void SendRegionsDebugMessage(GridId gridId) diff --git a/Content.Server/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs b/Content.Server/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs index 9b758396a7..93dc9478bd 100644 --- a/Content.Server/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs @@ -6,24 +6,20 @@ using System.Threading.Tasks; using Content.Server.GameObjects.Components; using Content.Shared.GameObjects.Components.Damage; using JetBrains.Annotations; -using Robust.Server.Interfaces.Timing; using Robust.Shared.GameObjects.Systems; -using Robust.Shared.IoC; namespace Content.Server.GameObjects.EntitySystems.DoAfter { [UsedImplicitly] public sealed class DoAfterSystem : EntitySystem { - [Dependency] private readonly IPauseManager _pauseManager = default!; - public override void Update(float frameTime) { base.Update(frameTime); foreach (var comp in ComponentManager.EntityQuery()) { - if (_pauseManager.IsGridPaused(comp.Owner.Transform.GridID)) continue; + if (comp.Owner.Paused) continue; var cancelled = new List(0); var finished = new List(0); diff --git a/Content.Shared/Maps/TurfHelpers.cs b/Content.Shared/Maps/TurfHelpers.cs index 6df3c78180..3da39ad24a 100644 --- a/Content.Shared/Maps/TurfHelpers.cs +++ b/Content.Shared/Maps/TurfHelpers.cs @@ -187,21 +187,17 @@ namespace Content.Shared.Maps private static Box2 GetWorldTileBox(TileRef turf) { var map = IoCManager.Resolve(); - var tileGrid = map.GetGrid(turf.GridIndex); // This is scaled to 90 % so it doesn't encompass walls on other tiles. - var tileBox = Box2.UnitCentered.Scale(tileGrid.TileSize).Scale(0.9f); - return tileBox.Translated(tileGrid.GridTileToWorldPos(turf.GridIndices)); - } + var tileBox = Box2.UnitCentered.Scale(0.9f); - /// - /// Creates a box the size of a tile. - /// - private static Box2 GetTileBox(this TileRef turf) - { - var map = IoCManager.Resolve(); - var tileGrid = map.GetGrid(turf.GridIndex); - return Box2.UnitCentered.Scale(tileGrid.TileSize); + if (map.TryGetGrid(turf.GridIndex, out var tileGrid)) + { + tileBox = tileBox.Scale(tileGrid.TileSize); + return tileBox.Translated(tileGrid.GridTileToWorldPos(turf.GridIndices)); + } + + return tileBox; } } } diff --git a/RobustToolbox b/RobustToolbox index e3f2e36ad4..6a9cb790c0 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit e3f2e36ad4d47e47355de2672dc40b21ca482686 +Subproject commit 6a9cb790c0a4f23cfdd7ee5a45a9a32db1c52fef