From d5c49816484ec7af295eb1719b42eb86366bee8c Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:05:02 +1200 Subject: [PATCH] Partial MapManager refactor (#5042) * MapManager rejig * Update Tests * A --- .../AddRemoveComponentBenchmark.cs | 5 +- .../ComponentIteratorBenchmark.cs | 4 +- .../EntityManager/GetComponentBenchmark.cs | 4 +- .../SpawnDeleteEntityBenchmark.cs | 7 +- .../Transform/RecursiveMoveBenchmark.cs | 3 +- .../GameObjects/EntitySystems/MapSystem.cs | 19 +- .../GameStates/ClientGameStateManager.cs | 19 +- .../Graphics/Clyde/Clyde.GridRendering.cs | 2 +- Robust.Client/Graphics/Clyde/Clyde.HLR.cs | 4 +- .../Console/Commands/TestbedCommand.cs | 12 +- .../EntitySystems/MapLoaderSystem.cs | 46 ++--- .../GameObjects/EntitySystems/MapSystem.cs | 17 +- Robust.Shared/Console/Commands/MapCommands.cs | 10 +- .../Transform/TransformComponent.cs | 1 - .../GameObjects/EntityManager.Components.cs | 5 + .../GameObjects/EntityManager.Spawn.cs | 23 ++- Robust.Shared/GameObjects/EntityManager.cs | 22 +- .../GameObjects/EntitySystem.Proxy.cs | 4 +- .../GameObjects/IEntityManager.Spawn.cs | 2 +- Robust.Shared/GameObjects/IEntityManager.cs | 2 + .../Systems/SharedMapSystem.Map.cs | 156 +++++++++++++-- .../Systems/SharedMapSystem.MapInit.cs | 89 +++++++++ .../Systems/SharedMapSystem.Pause.cs | 60 ++++++ .../GameObjects/Systems/SharedMapSystem.cs | 6 + .../SharedTransformSystem.Component.cs | 67 +++---- .../Systems/SharedTransformSystem.cs | 2 + Robust.Shared/Map/Components/MapComponent.cs | 28 +-- Robust.Shared/Map/IMapManager.cs | 48 +---- Robust.Shared/Map/IMapManagerInternal.cs | 8 - Robust.Shared/Map/MapId.cs | 2 + .../Map/MapManager.GridCollection.cs | 47 +---- Robust.Shared/Map/MapManager.GridTrees.cs | 12 -- Robust.Shared/Map/MapManager.MapCollection.cs | 188 ++---------------- Robust.Shared/Map/MapManager.Pause.cs | 128 ++---------- Robust.Shared/Map/MapManager.cs | 30 --- .../Components/TransformComponentTests.cs | 10 +- .../GameObjects/ComponentMapInitTest.cs | 2 +- .../GameObjects/Components/Container_Test.cs | 58 +++--- .../Components/TransformIntegration_Test.cs | 5 +- .../GameObjects/Components/Transform_Test.cs | 8 +- .../ThrowingEntityDeletion_Test.cs | 5 +- .../Server/GameStates/DefaultEntityTest.cs | 3 +- .../Server/GameStates/MissingParentTest.cs | 4 +- .../Server/GameStates/PvsChunkTest.cs | 9 +- .../Server/GameStates/PvsReEntryTest.cs | 3 +- .../Server/GameStates/PvsSystemTests.cs | 3 +- .../Server/Maps/MapLoaderTest.cs | 10 +- .../Server/RobustServerSimulation.cs | 17 +- .../Shared/EntityLookup_Test.cs | 4 +- .../Shared/GameObjects/ContainerTests.cs | 8 +- .../EntityEventBusTests.OrderedEvents.cs | 3 +- .../EntityEventBusTests.RefDirectedEvents.cs | 8 +- .../EntityManager_Components_Tests.cs | 83 ++++---- .../Shared/GameObjects/IEntityManagerTests.cs | 13 +- .../Systems/AnchoredSystemTests.cs | 86 ++++---- .../Systems/TransformSystemTests.cs | 10 +- .../GameObjects/TransformComponent_Tests.cs | 6 +- .../Shared/GameState/ComponentStateTests.cs | 14 +- .../GameState/DeletionNetworkingTests.cs | 3 +- .../GameState/NoSharedReferencesTest.cs | 7 +- .../Shared/Map/EntityCoordinates_Tests.cs | 37 +--- .../Shared/Map/GridCollision_Test.cs | 2 +- .../Shared/Map/GridContraction_Test.cs | 4 +- .../Shared/Map/GridFixtures_Tests.cs | 2 +- .../Shared/Map/GridMerge_Tests.cs | 2 +- .../Shared/Map/GridRotation_Tests.cs | 4 +- .../Shared/Map/GridSplit_Tests.cs | 10 +- .../Shared/Map/MapGridMap_Tests.cs | 4 +- .../Shared/Map/MapGrid_Tests.cs | 18 +- .../Shared/Map/MapManager_Tests.cs | 55 +---- .../Shared/Map/MapPauseTests.cs | 143 ++++--------- .../Shared/Map/SingleTileRemoveTest.cs | 4 +- .../Physics/BroadphaseNetworkingTest.cs | 6 +- .../Shared/Physics/Broadphase_Test.cs | 22 +- .../Shared/Physics/CollisionWake_Test.cs | 2 +- .../Shared/Physics/Collision_Test.cs | 4 +- .../Shared/Physics/Fixtures_Test.cs | 2 +- .../Shared/Physics/GridDeletion_Test.cs | 2 +- .../Shared/Physics/GridMovement_Test.cs | 2 +- .../Shared/Physics/JointDeletion_Test.cs | 2 +- .../Shared/Physics/Joints_Test.cs | 4 +- .../Shared/Physics/MapVelocity_Test.cs | 4 +- .../Shared/Physics/PhysicsComponent_Test.cs | 2 +- .../Shared/Physics/PhysicsMap_Test.cs | 4 +- .../Shared/Physics/RecursiveUpdateTest.cs | 4 +- .../Shared/Physics/Stack_Test.cs | 7 +- .../Shared/Prototypes/HotReloadTest.cs | 2 +- .../InheritanceSerializationTest.cs | 7 +- .../Shared/Spawning/EntitySpawnHelpersTest.cs | 3 +- .../Shared/Spawning/SpawnNextToOrDropTest.cs | 14 ++ .../TransformTests/GridTraversalTest.cs | 4 +- 91 files changed, 760 insertions(+), 1086 deletions(-) create mode 100644 Robust.Shared/GameObjects/Systems/SharedMapSystem.MapInit.cs create mode 100644 Robust.Shared/GameObjects/Systems/SharedMapSystem.Pause.cs delete mode 100644 Robust.Shared/Map/MapManager.GridTrees.cs diff --git a/Robust.Benchmarks/EntityManager/AddRemoveComponentBenchmark.cs b/Robust.Benchmarks/EntityManager/AddRemoveComponentBenchmark.cs index 767ba7db3..adb9020c2 100644 --- a/Robust.Benchmarks/EntityManager/AddRemoveComponentBenchmark.cs +++ b/Robust.Benchmarks/EntityManager/AddRemoveComponentBenchmark.cs @@ -26,9 +26,8 @@ public partial class AddRemoveComponentBenchmark .InitializeInstance(); _entityManager = _simulation.Resolve(); - - var coords = new MapCoordinates(0, 0, new MapId(1)); - _simulation.AddMap(coords.MapId); + var map = _simulation.CreateMap().Uid; + var coords = new EntityCoordinates(map, default); for (var i = 0; i < N; i++) { diff --git a/Robust.Benchmarks/EntityManager/ComponentIteratorBenchmark.cs b/Robust.Benchmarks/EntityManager/ComponentIteratorBenchmark.cs index f8bbba7bd..bd551658b 100644 --- a/Robust.Benchmarks/EntityManager/ComponentIteratorBenchmark.cs +++ b/Robust.Benchmarks/EntityManager/ComponentIteratorBenchmark.cs @@ -29,8 +29,8 @@ public partial class ComponentIteratorBenchmark Comps = new A[N+2]; - var coords = new MapCoordinates(0, 0, new MapId(1)); - _simulation.AddMap(coords.MapId); + var map = _simulation.CreateMap().MapId; + var coords = new MapCoordinates(default, map); for (var i = 0; i < N; i++) { diff --git a/Robust.Benchmarks/EntityManager/GetComponentBenchmark.cs b/Robust.Benchmarks/EntityManager/GetComponentBenchmark.cs index d3f16b6d3..72568de68 100644 --- a/Robust.Benchmarks/EntityManager/GetComponentBenchmark.cs +++ b/Robust.Benchmarks/EntityManager/GetComponentBenchmark.cs @@ -31,8 +31,8 @@ public partial class GetComponentBenchmark Comps = new A[N+2]; - var coords = new MapCoordinates(0, 0, new MapId(1)); - _simulation.AddMap(coords.MapId); + var map = _simulation.CreateMap().Uid; + var coords = new EntityCoordinates(map, default); for (var i = 0; i < N; i++) { diff --git a/Robust.Benchmarks/EntityManager/SpawnDeleteEntityBenchmark.cs b/Robust.Benchmarks/EntityManager/SpawnDeleteEntityBenchmark.cs index 4acb57101..d7a47a10a 100644 --- a/Robust.Benchmarks/EntityManager/SpawnDeleteEntityBenchmark.cs +++ b/Robust.Benchmarks/EntityManager/SpawnDeleteEntityBenchmark.cs @@ -29,10 +29,9 @@ public partial class SpawnDeleteEntityBenchmark .InitializeInstance(); _entityManager = _simulation.Resolve(); - - _mapCoords = new MapCoordinates(0, 0, new MapId(1)); - var uid = _simulation.AddMap(_mapCoords.MapId); - _entCoords = new EntityCoordinates(uid, 0, 0); + var (map, mapId) = _simulation.CreateMap(); + _mapCoords = new MapCoordinates(default, mapId); + _entCoords = new EntityCoordinates(map, 0, 0); } [Benchmark(Baseline = true)] diff --git a/Robust.Benchmarks/Transform/RecursiveMoveBenchmark.cs b/Robust.Benchmarks/Transform/RecursiveMoveBenchmark.cs index fba81cd10..6deaa7e12 100644 --- a/Robust.Benchmarks/Transform/RecursiveMoveBenchmark.cs +++ b/Robust.Benchmarks/Transform/RecursiveMoveBenchmark.cs @@ -91,8 +91,7 @@ public class RecursiveMoveBenchmark : RobustIntegrationTest // Set up map and spawn player server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - var map = mapMan.GetMapEntityId(mapId); + var map = server.ResolveDependency().CreateMap(out var mapId); var gridComp = mapMan.CreateGridEntity(mapId); var grid = gridComp.Owner; mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1)); diff --git a/Robust.Client/GameObjects/EntitySystems/MapSystem.cs b/Robust.Client/GameObjects/EntitySystems/MapSystem.cs index 44ef28275..9077957e0 100644 --- a/Robust.Client/GameObjects/EntitySystems/MapSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/MapSystem.cs @@ -1,12 +1,9 @@ using Robust.Client.Graphics; using Robust.Client.Map; -using Robust.Client.Physics; using Robust.Client.ResourceManagement; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Map.Components; -using Robust.Shared.Physics.Dynamics; namespace Robust.Client.GameObjects; @@ -16,6 +13,17 @@ public sealed class MapSystem : SharedMapSystem [Dependency] private readonly IResourceCache _resource = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; + protected override MapId GetNextMapId() + { + // Client-side map entities use negative map Ids to avoid conflict with server-side maps. + var id = new MapId(--LastMapId); + while (MapManager.MapExists(id)) + { + id = new MapId(--LastMapId); + } + return id; + } + public override void Initialize() { base.Initialize(); @@ -27,9 +35,4 @@ public sealed class MapSystem : SharedMapSystem base.Shutdown(); _overlayManager.RemoveOverlay(); } - - protected override void OnMapAdd(EntityUid uid, MapComponent component, ComponentAdd args) - { - EnsureComp(uid); - } } diff --git a/Robust.Client/GameStates/ClientGameStateManager.cs b/Robust.Client/GameStates/ClientGameStateManager.cs index 3b764031d..8e66deafd 100644 --- a/Robust.Client/GameStates/ClientGameStateManager.cs +++ b/Robust.Client/GameStates/ClientGameStateManager.cs @@ -1329,23 +1329,8 @@ namespace Robust.Client.GameStates foreach (var (comp, cur, next) in _compStateWork.Values) { - try - { - var handleState = new ComponentHandleState(cur, next); - bus.RaiseComponentEvent(comp, ref handleState); - } -#pragma warning disable CS0168 // Variable is declared but never used - catch (Exception e) -#pragma warning restore CS0168 // Variable is declared but never used - { -#if EXCEPTION_TOLERANCE - _sawmill.Error($"Failed to apply comp state: entity={_entities.ToPrettyString(uid)}, comp={comp.GetType()}"); - _runtimeLog.LogException(e, $"{nameof(ClientGameStateManager)}.{nameof(HandleEntityState)}"); -#else - _sawmill.Error($"Failed to apply comp state: entity={_entities.ToPrettyString(uid)}, comp={comp.GetType()}"); - throw; -#endif - } + var handleState = new ComponentHandleState(cur, next); + bus.RaiseComponentEvent(comp, ref handleState); } } diff --git a/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs b/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs index 724bde9b0..d71847977 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs @@ -124,7 +124,7 @@ namespace Robust.Client.Graphics.Clyde { foreach (var (grid, chunks) in _mapChunkData) { - var gridComp = _mapManager.GetGridComp(grid); + var gridComp = _entityManager.GetComponent(grid); foreach (var (index, chunk) in chunks) { if (!chunk.Dirty || gridComp.Chunks.ContainsKey(index)) diff --git a/Robust.Client/Graphics/Clyde/Clyde.HLR.cs b/Robust.Client/Graphics/Clyde/Clyde.HLR.cs index 66abf120b..a4cc29756 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.HLR.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.HLR.cs @@ -251,10 +251,8 @@ namespace Robust.Client.Graphics.Clyde private void DrawEntities(Viewport viewport, Box2Rotated worldBounds, Box2 worldAABB, IEye eye) { var mapId = eye.Position.MapId; - if (mapId == MapId.Nullspace || !_mapManager.HasMapEntity(mapId)) - { + if (mapId == MapId.Nullspace) return; - } RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowEntities, worldAABB, worldBounds); var worldOverlays = GetOverlaysForSpace(OverlaySpace.WorldSpaceEntities); diff --git a/Robust.Server/Console/Commands/TestbedCommand.cs b/Robust.Server/Console/Commands/TestbedCommand.cs index e18a22ad8..37a3f8c44 100644 --- a/Robust.Server/Console/Commands/TestbedCommand.cs +++ b/Robust.Server/Console/Commands/TestbedCommand.cs @@ -70,6 +70,11 @@ namespace Robust.Server.Console.Commands } var mapId = new MapId(mapInt); + if (!_map.MapExists(mapId)) + { + shell.WriteError($"map {args[0]} does not exist"); + return; + } if (shell.Player == null) { @@ -110,13 +115,6 @@ namespace Robust.Server.Console.Commands private void SetupPlayer(MapId mapId, IConsoleShell shell) { - if (mapId == MapId.Nullspace) return; - - if (!_map.MapExists(mapId)) - { - _map.CreateMap(mapId); - } - _map.SetMapPaused(mapId, false); var mapUid = _map.GetMapEntityIdOrThrow(mapId); _ent.System().SetGravity(mapUid, new Vector2(0, -9.8f)); diff --git a/Robust.Server/GameObjects/EntitySystems/MapLoaderSystem.cs b/Robust.Server/GameObjects/EntitySystems/MapLoaderSystem.cs index 6a0d2282f..f8d112199 100644 --- a/Robust.Server/GameObjects/EntitySystems/MapLoaderSystem.cs +++ b/Robust.Server/GameObjects/EntitySystems/MapLoaderSystem.cs @@ -658,11 +658,12 @@ public sealed class MapLoaderSystem : EntitySystem var xformQuery = GetEntityQuery(); // We just need to cache the old mapuid and point to the new mapuid. - if (HasComp(rootNode)) + if (TryComp(rootNode, out MapComponent? mapComp)) { // If map exists swap out - if (_mapManager.MapExists(data.TargetMap)) + if (_mapSystem.TryGetMap(data.TargetMap, out var existing)) { + data.MapIsPaused = _mapSystem.IsPaused(existing.Value); // Map exists but we also have a map file with stuff on it soooo swap out the old map. if (data.Options.LoadMap) { @@ -675,26 +676,28 @@ public sealed class MapLoaderSystem : EntitySystem data.Options.Rotation = Angle.Zero; } - _mapManager.SetMapEntity(data.TargetMap, rootNode); + Del(existing); EnsureComp(rootNode); + + mapComp.MapId = data.TargetMap; + DebugTools.Assert(mapComp.LifeStage < ComponentLifeStage.Initializing); } // Otherwise just ignore the map in the file. else { var oldRootUid = data.Entities[0]; - var newRootUid = _mapManager.GetMapEntityId(data.TargetMap); - data.Entities[0] = newRootUid; + data.Entities[0] = existing.Value; foreach (var ent in data.Entities) { - if (ent == newRootUid) + if (ent == existing) continue; var xform = xformQuery.GetComponent(ent); if (!xform.ParentUid.IsValid() || xform.ParentUid.Equals(oldRootUid)) { - _transform.SetParent(ent, xform, newRootUid); + _transform.SetParent(ent, xform, existing.Value); } } @@ -703,16 +706,8 @@ public sealed class MapLoaderSystem : EntitySystem } else { - // If we're loading a file with a map then swap out the entityuid - // TODO: Mapmanager nonsense - var AAAAA = _mapManager.CreateMap(data.TargetMap); - - if (!data.MapIsPostInit) - { - _mapManager.AddUninitializedMap(data.TargetMap); - } - - _mapManager.SetMapEntity(data.TargetMap, rootNode); + mapComp.MapId = data.TargetMap; + DebugTools.Assert(mapComp.LifeStage < ComponentLifeStage.Initializing); EnsureComp(rootNode); // Nothing should have invalid uid except for the root node. @@ -721,17 +716,14 @@ public sealed class MapLoaderSystem : EntitySystem else { // No map file root, in that case create a new map / get the one we're loading onto. - var mapNode = _mapManager.GetMapEntityId(data.TargetMap); - - if (!mapNode.IsValid()) + if (!_mapSystem.TryGetMap(data.TargetMap, out var mapNode)) { // Map doesn't exist so we'll start it up now so we can re-attach the preinit entities to it for later. - _mapManager.CreateMap(data.TargetMap); - _mapManager.AddUninitializedMap(data.TargetMap); - mapNode = _mapManager.GetMapEntityId(data.TargetMap); - DebugTools.Assert(mapNode.IsValid()); + mapNode = _mapSystem.CreateMap(data.TargetMap, false); } + data.MapIsPaused = _mapSystem.IsPaused(mapNode.Value); + // If anything has an invalid parent (e.g. it's some form of root node) then parent it to the map. foreach (var ent in data.Entities) { @@ -743,12 +735,11 @@ public sealed class MapLoaderSystem : EntitySystem if (!xform.ParentUid.IsValid()) { - _transform.SetParent(ent, xform, mapNode); + _transform.SetParent(ent, xform, mapNode.Value); } } } - data.MapIsPaused = _mapManager.IsMapPaused(data.TargetMap); _logLoader.Debug($"Swapped out root node in {_stopwatch.Elapsed}"); } @@ -896,6 +887,7 @@ public sealed class MapLoaderSystem : EntitySystem { EntityManager.SetLifeStage(metadata, EntityLifeStage.MapInitialized); } + // TODO MAP LOAD cache this else if (_mapManager.IsMapInitialized(data.TargetMap)) { _serverEntityManager.RunMapInit(uid, metadata); @@ -964,7 +956,7 @@ public sealed class MapLoaderSystem : EntitySystem // Yes, post-init maps do not have EntityLifeStage >= EntityLifeStage.MapInitialized bool postInit; if (TryComp(uid, out MapComponent? mapComp)) - postInit = !mapComp.MapPreInit; + postInit = mapComp.MapInitialized; else postInit = metadata.EntityLifeStage >= EntityLifeStage.MapInitialized; diff --git a/Robust.Server/GameObjects/EntitySystems/MapSystem.cs b/Robust.Server/GameObjects/EntitySystems/MapSystem.cs index 2d5fce29e..c7ce2e635 100644 --- a/Robust.Server/GameObjects/EntitySystems/MapSystem.cs +++ b/Robust.Server/GameObjects/EntitySystems/MapSystem.cs @@ -5,9 +5,9 @@ using Robust.Shared.Collections; using Robust.Shared.Configuration; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Map; using Robust.Shared.Map.Components; using Robust.Shared.Map.Events; -using Robust.Shared.Physics.Dynamics; namespace Robust.Server.GameObjects { @@ -18,6 +18,16 @@ namespace Robust.Server.GameObjects private bool _deleteEmptyGrids; + protected override MapId GetNextMapId() + { + var id = new MapId(++LastMapId); + while (MapManager.MapExists(id)) + { + id = new MapId(++LastMapId); + } + return id; + } + protected override void UpdatePvsChunks(Entity grid) { _pvs.GridParentChanged(grid); @@ -31,11 +41,6 @@ namespace Robust.Server.GameObjects Subs.CVar(_cfg, CVars.GameDeleteEmptyGrids, SetGridDeletion, true); } - protected override void OnMapAdd(EntityUid uid, MapComponent component, ComponentAdd args) - { - EnsureComp(uid); - } - private void SetGridDeletion(bool value) { _deleteEmptyGrids = value; diff --git a/Robust.Shared/Console/Commands/MapCommands.cs b/Robust.Shared/Console/Commands/MapCommands.cs index 17a2f3143..517dcf938 100644 --- a/Robust.Shared/Console/Commands/MapCommands.cs +++ b/Robust.Shared/Console/Commands/MapCommands.cs @@ -10,7 +10,8 @@ namespace Robust.Shared.Console.Commands; sealed class AddMapCommand : LocalizedCommands { - [Dependency] private readonly IMapManager _map = default!; + [Dependency] private readonly IMapManagerInternal _map = default!; + [Dependency] private readonly IEntityManager _entMan = default!; public override string Command => "addmap"; public override bool RequireServerOrSingleplayer => true; @@ -24,11 +25,8 @@ sealed class AddMapCommand : LocalizedCommands if (!_map.MapExists(mapId)) { - _map.CreateMap(mapId); - if (args.Length >= 2 && args[1] == "false") - { - _map.AddUninitializedMap(mapId); - } + var init = args.Length < 2 || !bool.Parse(args[1]); + _entMan.System().CreateMap(mapId, runMapInit: init); shell.WriteLine($"Map with ID {mapId} created."); return; diff --git a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs index 1ff62c832..97db53904 100644 --- a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs +++ b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs @@ -101,7 +101,6 @@ namespace Robust.Shared.GameObjects internal bool _mapIdInitialized; internal bool _gridInitialized; - // TODO: Cache this. /// /// The EntityUid of the map which this object is on, if any. /// diff --git a/Robust.Shared/GameObjects/EntityManager.Components.cs b/Robust.Shared/GameObjects/EntityManager.Components.cs index 6c6ba2d36..9dc9a57ab 100644 --- a/Robust.Shared/GameObjects/EntityManager.Components.cs +++ b/Robust.Shared/GameObjects/EntityManager.Components.cs @@ -1013,6 +1013,11 @@ namespace Robust.Shared.GameObjects } } + /// + /// Internal variant of that directly returns the actual component set. + /// + internal IReadOnlyCollection GetComponentsInternal(EntityUid uid) => _entCompIndex[uid]; + /// public int ComponentCount(EntityUid uid) { diff --git a/Robust.Shared/GameObjects/EntityManager.Spawn.cs b/Robust.Shared/GameObjects/EntityManager.Spawn.cs index 32e3e96d4..a5ba665f6 100644 --- a/Robust.Shared/GameObjects/EntityManager.Spawn.cs +++ b/Robust.Shared/GameObjects/EntityManager.Spawn.cs @@ -83,8 +83,12 @@ public partial class EntityManager } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public EntityUid Spawn(string? protoName = null, ComponentRegistry? overrides = null) - => Spawn(protoName, MapCoordinates.Nullspace, overrides); + public EntityUid Spawn(string? protoName = null, ComponentRegistry? overrides = null, bool doMapInit = true) + { + var entity = CreateEntityUninitialized(protoName, MapCoordinates.Nullspace, overrides); + InitializeAndStartEntity(entity, doMapInit); + return entity; + } public virtual EntityUid Spawn(string? protoName, MapCoordinates coordinates, ComponentRegistry? overrides = null) { @@ -117,7 +121,8 @@ public partial class EntityManager return true; } - uid = Spawn(protoName, overrides); + var doMapInit = _mapSystem.IsInitialized(xform.MapUid); + uid = Spawn(protoName, overrides, doMapInit); if (_containers.Insert(uid.Value, container)) return true; @@ -141,7 +146,8 @@ public partial class EntityManager if (!containerComp.Containers.TryGetValue(containerId, out var container)) return false; - uid = Spawn(protoName, overrides); + var doMapInit = _mapSystem.IsInitialized(TransformQuery.GetComponent(containerUid).MapUid); + uid = Spawn(protoName, overrides, doMapInit); if (_containers.Insert(uid.Value, container)) return true; @@ -157,7 +163,8 @@ public partial class EntityManager if (!xform.ParentUid.IsValid()) return Spawn(protoName); - var uid = Spawn(protoName, overrides); + var doMapInit = _mapSystem.IsInitialized(xform.MapUid); + var uid = Spawn(protoName, overrides, doMapInit); _xforms.DropNextTo(uid, target); return uid; } @@ -182,16 +189,16 @@ public partial class EntityManager ContainerManagerComponent? containerComp = null, ComponentRegistry? overrides = null) { - var uid = Spawn(protoName, overrides); inserted = true; + xform ??= TransformQuery.GetComponent(containerUid); + var doMapInit = _mapSystem.IsInitialized(xform.MapUid); + var uid = Spawn(protoName, overrides, doMapInit); if ((containerComp == null && !TryGetComponent(containerUid, out containerComp)) || !containerComp.Containers.TryGetValue(containerId, out var container) || !_containers.Insert(uid, container)) { - inserted = false; - xform ??= TransformQuery.GetComponent(containerUid); if (xform.ParentUid.IsValid()) _xforms.DropNextTo(uid, (containerUid, xform)); } diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index 621b88d74..dbd0f8704 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -304,7 +304,6 @@ namespace Robust.Shared.GameObjects if (coordinates.MapId == MapId.Nullspace) { - DebugTools.Assert(_mapManager.GetMapEntityId(coordinates.MapId) == EntityUid.Invalid); transform._parent = EntityUid.Invalid; transform.Anchored = false; return newEntity; @@ -821,15 +820,22 @@ namespace Robust.Shared.GameObjects public void InitializeAndStartEntity(EntityUid entity, MapId? mapId = null) { + var doMapInit = _mapManager.IsMapInitialized(mapId ?? TransformQuery.GetComponent(entity).MapID); + InitializeAndStartEntity(entity, doMapInit); + } + + public void InitializeAndStartEntity(Entity entity, bool doMapInit) + { + if (!MetaQuery.Resolve(entity.Owner, ref entity.Comp)) + return; + try { - var meta = MetaQuery.GetComponent(entity); - InitializeEntity(entity, meta); - StartEntity(entity); + InitializeEntity(entity.Owner, entity.Comp); + StartEntity(entity.Owner); - // If the map we're initializing the entity on is initialized, run map init on it. - if (_mapManager.IsMapInitialized(mapId ?? TransformQuery.GetComponent(entity).MapID)) - RunMapInit(entity, meta); + if (doMapInit) + RunMapInit(entity.Owner, entity.Comp); } catch (Exception e) { @@ -859,7 +865,7 @@ namespace Robust.Shared.GameObjects DebugTools.Assert(meta.EntityLifeStage == EntityLifeStage.Initialized, $"Expected entity {ToPrettyString(entity)} to be initialized, was {meta.EntityLifeStage}"); SetLifeStage(meta, EntityLifeStage.MapInitialized); - EventBus.RaiseLocalEvent(entity, MapInitEventInstance, false); + EventBus.RaiseLocalEvent(entity, MapInitEventInstance); } /// diff --git a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs b/Robust.Shared/GameObjects/EntitySystem.Proxy.cs index 392d0f8cc..662b2a8f5 100644 --- a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs +++ b/Robust.Shared/GameObjects/EntitySystem.Proxy.cs @@ -713,8 +713,8 @@ public partial class EntitySystem /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected EntityUid Spawn(string? prototype = null) - => EntityManager.Spawn(prototype); + protected EntityUid Spawn(string? prototype = null, ComponentRegistry? overrides = null, bool doMapInit = true) + => EntityManager.Spawn(prototype, overrides, doMapInit); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Robust.Shared/GameObjects/IEntityManager.Spawn.cs b/Robust.Shared/GameObjects/IEntityManager.Spawn.cs index 1fddff230..2bcd44ce4 100644 --- a/Robust.Shared/GameObjects/IEntityManager.Spawn.cs +++ b/Robust.Shared/GameObjects/IEntityManager.Spawn.cs @@ -27,7 +27,7 @@ public partial interface IEntityManager /// /// Spawns an entity in nullspace. /// - EntityUid Spawn(string? protoName = null, ComponentRegistry? overrides = null); + EntityUid Spawn(string? protoName = null, ComponentRegistry? overrides = null, bool doMapInit = true); /// /// Spawns an entity at a specific world position. The entity will either be parented to the map or a grid. diff --git a/Robust.Shared/GameObjects/IEntityManager.cs b/Robust.Shared/GameObjects/IEntityManager.cs index fc052dc8b..ea9acf234 100644 --- a/Robust.Shared/GameObjects/IEntityManager.cs +++ b/Robust.Shared/GameObjects/IEntityManager.cs @@ -80,6 +80,8 @@ namespace Robust.Shared.GameObjects void InitializeAndStartEntity(EntityUid entity, MapId? mapId = null); + void InitializeAndStartEntity(Entity entity, bool doMapInit); + void InitializeEntity(EntityUid entity, MetaDataComponent? meta = null); void StartEntity(EntityUid entity); diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Map.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Map.cs index b8f1d4ea1..6b848b501 100644 --- a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Map.cs +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Map.cs @@ -1,68 +1,188 @@ +using System; +using System.Diagnostics.CodeAnalysis; using Robust.Shared.GameStates; -using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Map.Components; +using Robust.Shared.Physics.Dynamics; using Robust.Shared.Utility; namespace Robust.Shared.GameObjects; public abstract partial class SharedMapSystem { + protected int LastMapId; + private void InitializeMap() { - SubscribeLocalEvent(OnMapAdd); - SubscribeLocalEvent(OnMapInit); + SubscribeLocalEvent(OnComponentAdd); + SubscribeLocalEvent(OnCompInit); + SubscribeLocalEvent(OnCompStartup); + SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnMapRemoved); SubscribeLocalEvent(OnMapHandleState); SubscribeLocalEvent(OnMapGetState); } + public bool MapExists([NotNullWhen(true)] MapId? mapId) + { + return mapId != null && Maps.ContainsKey(mapId.Value); + } + + public EntityUid GetMap(MapId mapId) + { + return Maps[mapId]; + } + + public bool TryGetMap([NotNullWhen(true)] MapId? mapId, [NotNullWhen(true)] out EntityUid? uid) + { + if (mapId == null || !Maps.TryGetValue(mapId.Value, out var map)) + { + uid = null; + return false; + } + + uid = map; + return true; + } + private void OnMapHandleState(EntityUid uid, MapComponent component, ref ComponentHandleState args) { if (args.Current is not MapComponentState state) return; - component.MapId = state.MapId; - - if (!MapManager.MapExists(state.MapId)) + if (component.MapId == MapId.Nullspace) { - var mapInternal = (IMapManagerInternal)MapManager; - mapInternal.CreateMap(state.MapId, uid); + if (state.MapId == MapId.Nullspace) + throw new Exception($"Received invalid map state? {ToPrettyString(uid)}"); + + component.MapId = state.MapId; + Maps.Add(component.MapId, uid); + RecursiveMapIdUpdate(uid, uid, component.MapId); } + DebugTools.AssertEqual(component.MapId, state.MapId); component.LightingEnabled = state.LightingEnabled; - var xformQuery = GetEntityQuery(); + component.MapInitialized = state.Initialized; - xformQuery.GetComponent(uid).ChangeMapId(state.MapId, xformQuery); + if (LifeStage(uid) >= EntityLifeStage.Initialized) + SetPaused(uid, state.MapPaused); + else + component.MapPaused = state.MapPaused; + } - MapManager.SetMapPaused(state.MapId, state.MapPaused); + private void RecursiveMapIdUpdate(EntityUid uid, EntityUid mapUid, MapId mapId) + { + // This is required only in the event where an entity becomes a map AFTER children have already been attached to it. + // AFAIK, this currently only happens when the client applies entity states out of order (i.e., ignoring transform hierarchy), + // which itself only happens if PVS is disabled. + // TODO MAPS remove this + + var xform = Transform(uid); + xform.MapUid = mapUid; + xform.MapID = mapId; + xform._mapIdInitialized = true; + foreach (var child in xform._children) + { + RecursiveMapIdUpdate(child, mapUid, mapId); + } } private void OnMapGetState(EntityUid uid, MapComponent component, ref ComponentGetState args) { - args.State = new MapComponentState(component.MapId, component.LightingEnabled, component.MapPaused); + args.State = new MapComponentState(component.MapId, component.LightingEnabled, component.MapPaused, component.MapInitialized); } - protected abstract void OnMapAdd(EntityUid uid, MapComponent component, ComponentAdd args); + protected abstract MapId GetNextMapId(); - private void OnMapInit(EntityUid uid, MapComponent component, ComponentInit args) + private void OnComponentAdd(EntityUid uid, MapComponent component, ComponentAdd args) { + // ordered startups when + EnsureComp(uid); EnsureComp(uid); EnsureComp(uid); + } + + private void OnCompInit(EntityUid uid, MapComponent component, ComponentInit args) + { + if (component.MapId == MapId.Nullspace) + component.MapId = GetNextMapId(); + + DebugTools.AssertEqual(component.MapId.IsClientSide, IsClientSide(uid)); + if (!Maps.TryAdd(component.MapId, uid)) + { + if (Maps[component.MapId] != uid) + throw new Exception($"Attempted to initialize a map {ToPrettyString(uid)} with a duplicate map id {component.MapId}"); + } var msg = new MapChangedEvent(uid, component.MapId, true); RaiseLocalEvent(uid, msg, true); } + private void OnCompStartup(EntityUid uid, MapComponent component, ComponentStartup args) + { + if (component.MapPaused) + RecursiveSetPaused(uid, true); + } + private void OnMapRemoved(EntityUid uid, MapComponent component, ComponentShutdown args) { DebugTools.Assert(component.MapId != MapId.Nullspace); - Log.Info($"Deleting map {component.MapId}"); - - var iMap = (IMapManagerInternal)MapManager; - iMap.RemoveMapId(component.MapId); + Maps.Remove(component.MapId); var msg = new MapChangedEvent(uid, component.MapId, false); RaiseLocalEvent(uid, msg, true); } + + /// + /// Creates a new map, automatically assigning a map id. + /// + public EntityUid CreateMap(out MapId mapId, bool runMapInit = true) + { + mapId = GetNextMapId(); + var uid = CreateMap(mapId, runMapInit); + return uid; + } + + /// + public EntityUid CreateMap(bool runMapInit = true) => CreateMap(out _, runMapInit); + + /// + /// Creates a new map with the specified map id. + /// + /// Throws if an invalid or already existing map id is provided. + public EntityUid CreateMap(MapId mapId, bool runMapInit = true) + { + if (Maps.ContainsKey(mapId)) + throw new ArgumentException($"Map with id {mapId} already exists"); + + if (mapId == MapId.Nullspace) + throw new ArgumentException($"Cannot create a null-space map"); + + if (_netManager.IsServer && mapId.IsClientSide) + throw new ArgumentException($"Attempted to create a client-side map on the server?"); + + if (_netManager.IsClient && _netManager.IsConnected && !mapId.IsClientSide) + throw new ArgumentException($"Attempted to create a client-side map entity with a non client-side map ID?"); + + var uid = EntityManager.CreateEntityUninitialized(null); + var map = _factory.GetComponent(); + map.MapId = mapId; + AddComp(uid, map); + + // Give the entity a name, mainly for debugging. Content can always override this with a localized name. + var meta = MetaData(uid); + _meta.SetEntityName(uid, $"Map Entity", meta); + + // Initialize components. this should add the map id to the collections. + EntityManager.InitializeComponents(uid, meta); + EntityManager.StartComponents(uid); + DebugTools.Assert(Maps[mapId] == uid); + + if (runMapInit) + InitializeMap((uid, map)); + else + SetPaused((uid, map), true); + + return uid; + } } diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.MapInit.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.MapInit.cs new file mode 100644 index 000000000..f6122e0c1 --- /dev/null +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.MapInit.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; +using Robust.Shared.Utility; + +namespace Robust.Shared.GameObjects; + +public abstract partial class SharedMapSystem +{ + private List _toInitialize = new(); + + public bool IsInitialized(MapId mapId) + { + if (mapId == MapId.Nullspace) + return true; // Nullspace is always initialized + + if(!Maps.TryGetValue(mapId, out var uid)) + throw new ArgumentException($"Map {mapId} does not exist."); + + return IsInitialized(uid); + } + public bool IsInitialized(EntityUid? map) + { + if (map == null) + return true; // Nullspace is always initialized + + return IsInitialized(map.Value); + } + + public bool IsInitialized(Entity map) + { + if (!_mapQuery.Resolve(map, ref map.Comp)) + return false; + + return map.Comp.MapInitialized; + } + + private void OnMapInit(EntityUid uid, MapComponent component, MapInitEvent args) + { + DebugTools.Assert(!component.MapInitialized); + component.MapInitialized = true; + EntityManager.Dirty(uid, component); + } + + public void InitializeMap(MapId mapId, bool unpause = true) + { + if(!Maps.TryGetValue(mapId, out var uid)) + throw new ArgumentException($"Map {mapId} does not exist."); + + InitializeMap(uid, unpause); + } + + public void InitializeMap(Entity map, bool unpause = true) + { + if (!_mapQuery.Resolve(map, ref map.Comp)) + return; + + if (map.Comp.MapInitialized) + throw new ArgumentException($"Map {ToPrettyString(map)} is already initialized."); + + RecursiveMapInit(map.Owner); + + if (unpause) + SetPaused(map, false); + } + + private void RecursiveMapInit(EntityUid entity) + { + _toInitialize.Clear(); + _toInitialize.Add(entity); + + for (var i = 0; i < _toInitialize.Count; i++) + { + var uid = _toInitialize[i]; + // _toInitialize might contain deleted entities. + if(!_metaQuery.TryComp(uid, out var meta)) + continue; + + if (meta.EntityLifeStage == EntityLifeStage.MapInitialized) + continue; + + _toInitialize.AddRange(Transform(uid)._children); + EntityManager.RunMapInit(uid, meta); + } + + _toInitialize.Clear(); + } +} diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Pause.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Pause.cs new file mode 100644 index 000000000..cd62f2c2d --- /dev/null +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Pause.cs @@ -0,0 +1,60 @@ +using System; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; + +namespace Robust.Shared.GameObjects; + +public abstract partial class SharedMapSystem +{ + public bool IsPaused(MapId mapId) + { + if (mapId == MapId.Nullspace) + return false; + + if(!Maps.TryGetValue(mapId, out var uid)) + throw new ArgumentException($"Map {mapId} does not exist."); + + return IsPaused(uid); + } + + public bool IsPaused(Entity map) + { + if (!_mapQuery.Resolve(map, ref map.Comp)) + return false; + + return map.Comp.MapPaused; + } + + public void SetPaused(MapId mapId, bool paused) + { + if(!Maps.TryGetValue(mapId, out var uid)) + throw new ArgumentException($"Map {mapId} does not exist."); + + SetPaused(uid, paused); + } + + public void SetPaused(Entity map, bool paused) + { + if (!_mapQuery.Resolve(map, ref map.Comp)) + return; + + if (map.Comp.MapPaused == paused) + return; + + map.Comp.MapPaused = paused; + if (map.Comp.LifeStage < ComponentLifeStage.Initializing) + return; + + Dirty(map); + RecursiveSetPaused(map, paused); + } + + private void RecursiveSetPaused(EntityUid entity, bool paused) + { + _meta.SetEntityPaused(entity, paused); + foreach (var child in Transform(entity)._children) + { + RecursiveSetPaused(child, paused); + } + } +} diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs index 8045aee7e..6267c1eca 100644 --- a/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs @@ -20,17 +20,23 @@ namespace Robust.Shared.GameObjects [Dependency] private readonly FixtureSystem _fixtures = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly IComponentFactory _factory = default!; + [Dependency] private readonly MetaDataSystem _meta = default!; private EntityQuery _mapQuery; private EntityQuery _gridQuery; + private EntityQuery _metaQuery; private EntityQuery _xformQuery; + internal Dictionary Maps { get; } = new(); + public override void Initialize() { base.Initialize(); _mapQuery = GetEntityQuery(); _gridQuery = GetEntityQuery(); + _metaQuery = GetEntityQuery(); _xformQuery = GetEntityQuery(); InitializeMap(); diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs index a60cef3a8..29a693918 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -199,47 +199,34 @@ public abstract partial class SharedTransformSystem #region Component Lifetime + private (EntityUid?, MapId) InitializeMapUid(EntityUid uid, TransformComponent xform) + { + if (xform._mapIdInitialized) + return (xform.MapUid, xform.MapID); + + if (xform.ParentUid.IsValid()) + { + (xform.MapUid, xform.MapID) = InitializeMapUid(xform.ParentUid, Transform(xform.ParentUid)); + } + else if (_mapQuery.TryComp(uid, out var mapComp)) + { + DebugTools.AssertNotEqual(mapComp.MapId, MapId.Nullspace); + xform.MapUid = uid; + xform.MapID = mapComp.MapId; + } + else + { + xform.MapUid = null; + xform.MapID = MapId.Nullspace; + } + + xform._mapIdInitialized = true; + return (xform.MapUid, xform.MapID); + } + private void OnCompInit(EntityUid uid, TransformComponent component, ComponentInit args) { - // Children MAY be initialized here before their parents are. - // We do this whole dance to handle this recursively, - // setting _mapIdInitialized along the way to avoid going to the MapComponent every iteration. - static MapId FindMapIdAndSet(EntityUid uid, TransformComponent xform, IEntityManager entMan, EntityQuery xformQuery, IMapManager mapManager) - { - if (xform._mapIdInitialized) - return xform.MapID; - - MapId value; - - if (xform.ParentUid.IsValid()) - { - value = FindMapIdAndSet(xform.ParentUid, xformQuery.GetComponent(xform.ParentUid), entMan, xformQuery, mapManager); - } - else - { - // second level node, terminates recursion up the branch of the tree - if (entMan.TryGetComponent(uid, out MapComponent? mapComp)) - { - value = mapComp.MapId; - } - else - { - // We allow entities to be spawned directly into null-space. - value = MapId.Nullspace; - } - } - - xform.MapUid = value == MapId.Nullspace ? null : mapManager.GetMapEntityId(value); - xform.MapID = value; - xform._mapIdInitialized = true; - return value; - } - - if (!component._mapIdInitialized) - { - FindMapIdAndSet(uid, component, EntityManager, XformQuery, _mapManager); - component._mapIdInitialized = true; - } + InitializeMapUid(uid, component); // Has to be done if _parent is set from ExposeData. if (component.ParentUid.IsValid()) @@ -522,6 +509,8 @@ public abstract partial class SharedTransformSystem throw new InvalidOperationException($"Attempted to re-parent to a terminating object. Entity: {ToPrettyString(uid)}, new parent: {ToPrettyString(value.EntityId)}"); } + InitializeMapUid(value.EntityId, newParent); + // Check for recursive/circular transform hierarchies. if (xform.MapUid == newParent.MapUid) { diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs index aedb98f74..3433c4ef6 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs @@ -26,6 +26,7 @@ namespace Robust.Shared.GameObjects [Dependency] private readonly INetManager _netMan = default!; [Dependency] private readonly SharedContainerSystem _container = default!; + private EntityQuery _mapQuery; private EntityQuery _gridQuery; private EntityQuery _metaQuery; protected EntityQuery XformQuery; @@ -50,6 +51,7 @@ namespace Robust.Shared.GameObjects UpdatesOutsidePrediction = true; + _mapQuery = GetEntityQuery(); _gridQuery = GetEntityQuery(); _metaQuery = GetEntityQuery(); XformQuery = GetEntityQuery(); diff --git a/Robust.Shared/Map/Components/MapComponent.cs b/Robust.Shared/Map/Components/MapComponent.cs index fb07046bc..d771a8c47 100644 --- a/Robust.Shared/Map/Components/MapComponent.cs +++ b/Robust.Shared/Map/Components/MapComponent.cs @@ -12,35 +12,29 @@ namespace Robust.Shared.Map.Components public sealed partial class MapComponent : Component { [ViewVariables(VVAccess.ReadWrite)] - [DataField("lightingEnabled")] + [DataField] public bool LightingEnabled { get; set; } = true; [ViewVariables(VVAccess.ReadOnly)] public MapId MapId { get; internal set; } = MapId.Nullspace; - [ViewVariables(VVAccess.ReadOnly)] - public bool MapPaused { get; set; } = false; + [DataField, Access(typeof(SharedMapSystem), typeof(MapManager))] + public bool MapPaused; - //TODO replace MapPreInit with the map's entity life stage - [ViewVariables(VVAccess.ReadOnly)] - public bool MapPreInit { get; set; } = false; + [DataField, Access(typeof(SharedMapSystem), typeof(MapManager))] + public bool MapInitialized; } /// /// Serialized state of a . /// [Serializable, NetSerializable] - public sealed class MapComponentState : ComponentState + public sealed class MapComponentState(MapId mapId, bool lightingEnabled, bool paused, bool init) + : ComponentState { - public MapId MapId; - public bool LightingEnabled; - public bool MapPaused; - - public MapComponentState(MapId mapId, bool lightingEnabled, bool paused) - { - MapId = mapId; - LightingEnabled = lightingEnabled; - MapPaused = paused; - } + public MapId MapId = mapId; + public bool LightingEnabled = lightingEnabled; + public bool MapPaused = paused; + public bool Initialized = init; } } diff --git a/Robust.Shared/Map/IMapManager.cs b/Robust.Shared/Map/IMapManager.cs index 4a7913c8c..5b18ed748 100644 --- a/Robust.Shared/Map/IMapManager.cs +++ b/Robust.Shared/Map/IMapManager.cs @@ -23,9 +23,6 @@ namespace Robust.Shared.Map public const bool Approximate = false; public const bool IncludeMap = true; - [Obsolete("Use EntityQuery")] - IEnumerable GetAllGrids(); - /// /// 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. @@ -42,16 +39,7 @@ namespace Robust.Shared.Map void Restart(); - /// - /// Creates a new map. - /// - /// - /// If provided, the new map will use this ID. If not provided, a new ID will be selected automatically. - /// - /// The new map. - /// - /// Throw if an explicit ID for the map or default grid is passed and a map or grid with the specified ID already exists, respectively. - /// + [Obsolete("Use MapSystem")] MapId CreateMap(MapId? mapId = null); /// @@ -59,24 +47,12 @@ namespace Robust.Shared.Map /// /// The map ID to check existence of. /// True if the map exists, false otherwise. - bool MapExists(MapId mapId); + bool MapExists([NotNullWhen(true)] MapId? mapId); /// - /// Creates a new entity, then sets it as the map entity. - /// - /// Newly created entity. - EntityUid CreateNewMapEntity(MapId mapId); - - /// - /// Sets the MapEntity(root node) for a given map. If an entity is already set, it will be deleted - /// before the new one is set. - /// - /// Should we re-parent children from the old map to the new one, or delete them. - void SetMapEntity(MapId mapId, EntityUid newMapEntityId, bool updateChildren = true); - - /// - /// Returns the map entity ID for a given map. + /// Returns the map entity ID for a given map, or an invalid entity Id if the map does not exist. /// + [Obsolete("Use TryGetMap")] EntityUid GetMapEntityId(MapId mapId); /// @@ -93,6 +69,7 @@ namespace Robust.Shared.Map 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); [Obsolete("Use GetComponent(uid)")] MapGridComponent GetGrid(EntityUid gridId); @@ -233,17 +210,13 @@ namespace Robust.Shared.Map #endregion - void DeleteGrid(EntityUid euid); - bool HasMapEntity(MapId mapId); + [Obsolete("Just delete the grid entity")] + void DeleteGrid(EntityUid euid); bool IsGrid(EntityUid uid); bool IsMap(EntityUid uid); - [Obsolete("Whatever this is used for, it is a terrible idea. Create a new map and get it's MapId.")] - MapId NextMapId(); - MapGridComponent GetGridComp(EntityUid euid); - // // Pausing functions // @@ -252,14 +225,15 @@ namespace Robust.Shared.Map void DoMapInitialize(MapId mapId); - // TODO rename this to actually be descriptive or just remove it. + [Obsolete("Use CreateMap's runMapInit argument")] void AddUninitializedMap(MapId mapId); - [Pure] + [Obsolete("Use MapSystem")] bool IsMapPaused(MapId mapId); - [Pure] + [Obsolete("Use MapSystem")] bool IsMapInitialized(MapId mapId); + } public struct GridCreateOptions diff --git a/Robust.Shared/Map/IMapManagerInternal.cs b/Robust.Shared/Map/IMapManagerInternal.cs index 0e42ea41b..f3234ab31 100644 --- a/Robust.Shared/Map/IMapManagerInternal.cs +++ b/Robust.Shared/Map/IMapManagerInternal.cs @@ -1,23 +1,15 @@ -using Robust.Shared.GameObjects; using Robust.Shared.Maths; -using Robust.Shared.Timing; namespace Robust.Shared.Map { /// internal interface IMapManagerInternal : IMapManager { - IGameTiming GameTiming { get; } - /// /// Raises the OnTileChanged event. /// /// A reference to the new tile. /// The old tile that got replaced. void RaiseOnTileChanged(TileRef tileRef, Tile oldTile, Vector2i chunk); - - MapId CreateMap(MapId? mapId, EntityUid euid); - - void RemoveMapId(MapId mapId); } } diff --git a/Robust.Shared/Map/MapId.cs b/Robust.Shared/Map/MapId.cs index 6899d181a..1a696e501 100644 --- a/Robust.Shared/Map/MapId.cs +++ b/Robust.Shared/Map/MapId.cs @@ -53,5 +53,7 @@ namespace Robust.Shared.Map { return Value.ToString(); } + + public bool IsClientSide => Value < 0; } } diff --git a/Robust.Shared/Map/MapManager.GridCollection.cs b/Robust.Shared/Map/MapManager.GridCollection.cs index ac49ec691..67d639316 100644 --- a/Robust.Shared/Map/MapManager.GridCollection.cs +++ b/Robust.Shared/Map/MapManager.GridCollection.cs @@ -12,32 +12,15 @@ using Robust.Shared.Utility; namespace Robust.Shared.Map; internal partial class MapManager { - [Obsolete("Use GetComponent(uid)")] - public MapGridComponent GetGridComp(EntityUid euid) - { - return EntityManager.GetComponent(euid); - } - - [Obsolete("Use EntityQuery instead.")] - public IEnumerable GetAllGrids() - { - var compQuery = EntityManager.AllEntityQueryEnumerator(); - - while (compQuery.MoveNext(out var comp)) - { - yield return comp; - } - } - // ReSharper disable once MethodOverloadWithOptionalParameter public MapGridComponent CreateGrid(MapId currentMapId, ushort chunkSize = 16) { - return CreateGrid(currentMapId, chunkSize, default); + return CreateGrid(GetMapEntityIdOrThrow(currentMapId), chunkSize, default); } public MapGridComponent CreateGrid(MapId currentMapId, in GridCreateOptions options) { - return CreateGrid(currentMapId, options.ChunkSize, default); + return CreateGrid(GetMapEntityIdOrThrow(currentMapId), options.ChunkSize, default); } public MapGridComponent CreateGrid(MapId currentMapId) @@ -46,18 +29,19 @@ internal partial class MapManager } 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(currentMapId, options.Value.ChunkSize, default); + return CreateGrid(map, options.Value.ChunkSize, default); } [Obsolete("Use GetComponent(uid)")] public MapGridComponent GetGrid(EntityUid gridId) - { - DebugTools.Assert(gridId.IsValid()); - - return GetGridComp(gridId); - } + => EntityManager.GetComponent(gridId); [Obsolete("Use HasComponent(uid)")] public bool IsGrid(EntityUid uid) @@ -108,10 +92,6 @@ internal partial class MapManager public virtual void DeleteGrid(EntityUid euid) { -#if DEBUG - DebugTools.Assert(_dbgGuardRunning); -#endif - // Possible the grid was already deleted / is invalid if (!EntityManager.TryGetComponent(euid, out var iGrid)) { @@ -141,10 +121,6 @@ internal partial class MapManager /// The old tile that got replaced. public void RaiseOnTileChanged(TileRef tileRef, Tile oldTile, Vector2i chunk) { -#if DEBUG - DebugTools.Assert(_dbgGuardRunning); -#endif - if (SuppressOnTileChanged) return; @@ -153,7 +129,7 @@ internal partial class MapManager EntityManager.EventBus.RaiseLocalEvent(euid, ref ev, true); } - protected Entity CreateGrid(MapId currentMapId, ushort chunkSize, EntityUid forcedGridEuid) + protected Entity CreateGrid(EntityUid map, ushort chunkSize, EntityUid forcedGridEuid) { var gridEnt = EntityManager.CreateEntityUninitialized(null, forcedGridEuid); @@ -166,8 +142,7 @@ internal partial class MapManager //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. - var fallbackParentEuid = GetMapEntityIdOrThrow(currentMapId); - EntityManager.GetComponent(gridEnt).AttachParent(fallbackParentEuid); + EntityManager.GetComponent(gridEnt).AttachParent(map); var meta = EntityManager.GetComponent(gridEnt); EntityManager.System().SetEntityName(gridEnt, $"grid", meta); diff --git a/Robust.Shared/Map/MapManager.GridTrees.cs b/Robust.Shared/Map/MapManager.GridTrees.cs deleted file mode 100644 index 249e46798..000000000 --- a/Robust.Shared/Map/MapManager.GridTrees.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Robust.Shared.Map; - -internal partial class MapManager -{ - public void RemoveMapId(MapId mapId) - { - if (mapId == MapId.Nullspace) - return; - - _mapEntities.Remove(mapId); - } -} diff --git a/Robust.Shared/Map/MapManager.MapCollection.cs b/Robust.Shared/Map/MapManager.MapCollection.cs index df59546bb..7eda32cca 100644 --- a/Robust.Shared/Map/MapManager.MapCollection.cs +++ b/Robust.Shared/Map/MapManager.MapCollection.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Robust.Shared.GameObjects; using Robust.Shared.Map.Components; using Robust.Shared.Utility; @@ -27,131 +28,42 @@ public sealed class MapEventArgs : EventArgs internal partial class MapManager { - private readonly Dictionary _mapEntities = new(); - private MapId _highestMapId = MapId.Nullspace; + private Dictionary _mapEntities => _mapSystem.Maps; /// public virtual void DeleteMap(MapId mapId) { -#if DEBUG - DebugTools.Assert(_dbgGuardRunning); -#endif - if (!_mapEntities.TryGetValue(mapId, out var ent) || !ent.IsValid()) throw new InvalidOperationException($"Attempted to delete nonexistent map '{mapId}'"); EntityManager.DeleteEntity(ent); + DebugTools.Assert(!_mapEntities.ContainsKey(mapId)); } /// public MapId CreateMap(MapId? mapId = null) { - return ((IMapManagerInternal) this).CreateMap(mapId, default); + if (mapId != null) + { + _mapSystem.CreateMap(mapId.Value); + return mapId.Value; + } + + _mapSystem.CreateMap(out var map); + return map; } /// - public bool MapExists(MapId mapId) + public bool MapExists([NotNullWhen(true)] MapId? mapId) { - return _mapEntities.ContainsKey(mapId); - } - - /// - public EntityUid CreateNewMapEntity(MapId mapId) - { - DebugTools.Assert(mapId != MapId.Nullspace); -#if DEBUG - DebugTools.Assert(_dbgGuardRunning); -#endif - - var newEntity = EntityManager.CreateEntityUninitialized(null); - SetMapEntity(mapId, newEntity); - - EntityManager.InitializeComponents(newEntity); - EntityManager.StartComponents(newEntity); - - return newEntity; - } - - /// - public void SetMapEntity(MapId mapId, EntityUid newMapEntity, bool updateChildren = true) - { -#if DEBUG - DebugTools.Assert(_dbgGuardRunning); -#endif - - if (!_mapEntities.ContainsKey(mapId)) - throw new InvalidOperationException($"Map {mapId} does not exist."); - - foreach (var kvEntity in _mapEntities) - { - if (kvEntity.Value == newMapEntity) - { - if (mapId == kvEntity.Key) - return; - - throw new InvalidOperationException( - $"Entity {newMapEntity} is already the root node of another map {kvEntity.Key}."); - } - } - - MapComponent? mapComp; - // If this is being done as part of maploader then we want to copy the preinit state across mainly. - bool preInit = false; - bool paused = false; - - // remove existing graph - if (_mapEntities.TryGetValue(mapId, out var oldEntId)) - { - if (EntityManager.TryGetComponent(oldEntId, out mapComp)) - { - preInit = mapComp.MapPreInit; - paused = mapComp.MapPaused; - } - - EntityManager.System().ReparentChildren(oldEntId, newMapEntity); - - //Note: EntityUid.Invalid gets passed in here - //Note: This prevents setting a subgraph as the root, since the subgraph will be deleted - EntityManager.DeleteEntity(oldEntId); - } - - var raiseEvent = false; - - // re-use or add map component - if (!EntityManager.TryGetComponent(newMapEntity, out mapComp)) - mapComp = EntityManager.AddComponent(newMapEntity); - else - { - raiseEvent = true; - - if (mapComp.MapId != mapId) - { - _sawmill.Warning($"Setting map {mapId} root to entity {newMapEntity}, but entity thinks it is root node of map {mapComp.MapId}."); - } - } - - _sawmill.Debug($"Setting map {mapId} entity to {newMapEntity}"); - - // set as new map entity - mapComp.MapPreInit = preInit; - mapComp.MapPaused = paused; - - mapComp.MapId = mapId; - _mapEntities[mapId] = newMapEntity; - - // Yeah this sucks but I just want to save maps for now, deal. - if (raiseEvent) - { - var ev = new MapChangedEvent(newMapEntity, mapId, true); - EntityManager.EventBus.RaiseLocalEvent(newMapEntity, ev, true); - } + return _mapSystem.MapExists(mapId); } /// public EntityUid GetMapEntityId(MapId mapId) { - if (_mapEntities.TryGetValue(mapId, out var entId)) - return entId; + if (_mapSystem.TryGetMap(mapId, out var entId)) + return entId.Value; return EntityUid.Invalid; } @@ -161,13 +73,12 @@ internal partial class MapManager /// public EntityUid GetMapEntityIdOrThrow(MapId mapId) { - return _mapEntities[mapId]; + return _mapSystem.GetMap(mapId); } - /// - public bool HasMapEntity(MapId mapId) + public bool TryGetMap([NotNullWhen(true)] MapId? mapId, [NotNullWhen(true)] out EntityUid? uid) { - return _mapEntities.ContainsKey(mapId); + return _mapSystem.TryGetMap(mapId, out uid); } /// @@ -181,67 +92,4 @@ internal partial class MapManager { return EntityManager.HasComponent(uid); } - - /// - public MapId NextMapId() - { - return _highestMapId = new MapId(_highestMapId.Value + 1); - } - - MapId IMapManagerInternal.CreateMap(MapId? mapId, EntityUid entityUid) - { - if (mapId == MapId.Nullspace) - throw new InvalidOperationException("Attempted to create a null-space map."); - -#if DEBUG - DebugTools.Assert(_dbgGuardRunning); -#endif - - var actualId = mapId ?? new MapId(_highestMapId.Value + 1); - - if (MapExists(actualId)) - throw new InvalidOperationException($"A map with ID {actualId} already exists"); - - if (_highestMapId.Value < actualId.Value) - _highestMapId = actualId; - - _sawmill.Info($"Creating new map {actualId}"); - - if (actualId != MapId.Nullspace) // nullspace isn't bound to an entity - { - Entity result = default; - var query = EntityManager.AllEntityQueryEnumerator(); - while (query.MoveNext(out var uid, out var map)) - { - if (map.MapId != actualId) - continue; - - result = (uid, map); - break; - } - - if (result != default) - { - DebugTools.Assert(mapId != null); - _mapEntities.Add(actualId, result); - _sawmill.Debug($"Rebinding map {actualId} to entity {result.Owner}"); - } - else - { - var newEnt = EntityManager.CreateEntityUninitialized(null, entityUid); - _mapEntities.Add(actualId, newEnt); - - var mapComp = EntityManager.AddComponent(newEnt); - mapComp.MapId = actualId; - var meta = EntityManager.GetComponent(newEnt); - EntityManager.System().SetEntityName(newEnt, $"map {actualId}", meta); - EntityManager.Dirty(newEnt, mapComp, meta); - EntityManager.InitializeComponents(newEnt, meta); - EntityManager.StartComponents(newEnt); - _sawmill.Debug($"Binding map {actualId} to entity {newEnt}"); - } - } - - return actualId; - } } diff --git a/Robust.Shared/Map/MapManager.Pause.cs b/Robust.Shared/Map/MapManager.Pause.cs index 221c92f1f..9cd232f4c 100644 --- a/Robust.Shared/Map/MapManager.Pause.cs +++ b/Robust.Shared/Map/MapManager.Pause.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using System.Linq; using Robust.Shared.GameObjects; using Robust.Shared.Map.Components; @@ -8,145 +7,44 @@ namespace Robust.Shared.Map { internal partial class MapManager { - /// public void SetMapPaused(MapId mapId, bool paused) { - if(mapId == MapId.Nullspace) - return; - - if(!MapExists(mapId)) - throw new ArgumentException("That map does not exist."); - - var mapUid = GetMapEntityId(mapId); - var mapComp = EntityManager.GetComponent(mapUid); - - if (mapComp.MapPaused == paused) - return; - - mapComp.MapPaused = paused; - EntityManager.Dirty(mapUid, mapComp); - - var xformQuery = EntityManager.GetEntityQuery(); - var metaQuery = EntityManager.GetEntityQuery(); - var metaSystem = EntityManager.EntitySysManager.GetEntitySystem(); - - RecursiveSetPaused(mapUid, paused, in xformQuery, in metaQuery, in metaSystem); + _mapSystem.SetPaused(mapId, paused); } - private static void RecursiveSetPaused(EntityUid entity, bool paused, - in EntityQuery xformQuery, - in EntityQuery metaQuery, - in MetaDataSystem system) + public void SetMapPaused(EntityUid uid, bool paused) { - system.SetEntityPaused(entity, paused, metaQuery.GetComponent(entity)); - var xform = xformQuery.GetComponent(entity); - foreach (var child in xform._children) - { - RecursiveSetPaused(child, paused, in xformQuery, in metaQuery, in system); - } + _mapSystem.SetPaused(uid, paused); } - /// public void DoMapInitialize(MapId mapId) { - if(!MapExists(mapId)) - throw new ArgumentException("That map does not exist."); - - if (IsMapInitialized(mapId)) - throw new ArgumentException("That map is already initialized."); - - var mapEnt = GetMapEntityId(mapId); - var mapComp = EntityManager.GetComponent(mapEnt); - var xformQuery = EntityManager.GetEntityQuery(); - var metaQuery = EntityManager.GetEntityQuery(); - var metaSystem = EntityManager.EntitySysManager.GetEntitySystem(); - - mapComp.MapPreInit = false; - mapComp.MapPaused = false; - EntityManager.Dirty(mapEnt, mapComp); - - RecursiveDoMapInit(mapEnt, in xformQuery, in metaQuery, in metaSystem); + _mapSystem.InitializeMap(mapId); } - private void RecursiveDoMapInit(EntityUid entity, - in EntityQuery xformQuery, - in EntityQuery metaQuery, - in MetaDataSystem system) + public bool IsMapInitialized(MapId mapId) { - // RunMapInit can modify the TransformTree - // ToArray caches deleted euids, we check here if they still exist. - if(!metaQuery.TryGetComponent(entity, out var meta)) - return; - - EntityManager.RunMapInit(entity, meta); - system.SetEntityPaused(entity, false, meta); - - foreach (var child in xformQuery.GetComponent(entity)._children.ToArray()) - { - RecursiveDoMapInit(child, in xformQuery, in metaQuery, in system); - } + return _mapSystem.IsInitialized(mapId); } - /// public void AddUninitializedMap(MapId mapId) { - SetMapPreInit(mapId); - } - - private bool CheckMapPause(MapId mapId) - { - if(mapId == MapId.Nullspace) - return false; - - var mapEuid = GetMapEntityId(mapId); - - if (!EntityManager.TryGetComponent(mapEuid, out var map)) - return false; - - return map.MapPaused; - } - - private void SetMapPreInit(MapId mapId) - { - if(mapId == MapId.Nullspace) - return; - - var mapEuid = GetMapEntityId(mapId); - var mapComp = EntityManager.GetComponent(mapEuid); - mapComp.MapPreInit = true; - } - - private bool CheckMapPreInit(MapId mapId) - { - if(mapId == MapId.Nullspace) - return false; - - var mapEuid = GetMapEntityId(mapId); - - if (!EntityManager.TryGetComponent(mapEuid, out var map)) - return false; - - return map.MapPreInit; + var ent = GetMapEntityId(mapId); + EntityManager.GetComponent(ent).MapInitialized = false; + var meta = EntityManager.GetComponent(ent); + ((EntityManager)EntityManager).SetLifeStage(meta, EntityLifeStage.Initialized); } /// public bool IsMapPaused(MapId mapId) { - if(mapId == MapId.Nullspace) - return false; - - var mapEuid = GetMapEntityId(mapId); - - if (!EntityManager.TryGetComponent(mapEuid, out var map)) - return false; - - return map.MapPaused || map.MapPreInit; + return _mapSystem.IsPaused(mapId); } /// - public bool IsMapInitialized(MapId mapId) + public bool IsMapPaused(EntityUid uid) { - return !CheckMapPreInit(mapId); + return _mapSystem.IsPaused(uid); } /// diff --git a/Robust.Shared/Map/MapManager.cs b/Robust.Shared/Map/MapManager.cs index 8d3bd6a5e..c8d01b26a 100644 --- a/Robust.Shared/Map/MapManager.cs +++ b/Robust.Shared/Map/MapManager.cs @@ -3,13 +3,9 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map.Components; -using Robust.Shared.Maths; -using Robust.Shared.Physics; using Robust.Shared.Physics.Collision; -using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Systems; using Robust.Shared.Timing; -using Robust.Shared.Utility; namespace Robust.Shared.Map; @@ -25,58 +21,37 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber private ISawmill _sawmill = default!; - private FixtureSystem _fixtureSystem = default!; private SharedMapSystem _mapSystem = default!; private SharedPhysicsSystem _physics = default!; private SharedTransformSystem _transformSystem = default!; - private EntityQuery _fixturesQuery; private EntityQuery _gridTreeQuery; private EntityQuery _gridQuery; - private EntityQuery _physicsQuery; - private EntityQuery _xformQuery; /// public void Initialize() { - _fixturesQuery = EntityManager.GetEntityQuery(); _gridTreeQuery = EntityManager.GetEntityQuery(); _gridQuery = EntityManager.GetEntityQuery(); - _physicsQuery = EntityManager.GetEntityQuery(); - _xformQuery = EntityManager.GetEntityQuery(); _sawmill = Logger.GetSawmill("map"); -#if DEBUG - DebugTools.Assert(!_dbgGuardInit); - DebugTools.Assert(!_dbgGuardRunning); - _dbgGuardInit = true; -#endif InitializeMapPausing(); } /// public void Startup() { - _fixtureSystem = EntityManager.System(); _physics = EntityManager.System(); _transformSystem = EntityManager.System(); _mapSystem = EntityManager.System(); -#if DEBUG - DebugTools.Assert(_dbgGuardInit); - _dbgGuardRunning = true; -#endif - _sawmill.Debug("Starting..."); } /// public void Shutdown() { -#if DEBUG - DebugTools.Assert(_dbgGuardInit); -#endif _sawmill.Debug("Stopping..."); // TODO: AllEntityQuery instead??? @@ -102,9 +77,4 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber EntityManager.DeleteEntity(uid); } } - -#if DEBUG - private bool _dbgGuardInit; - private bool _dbgGuardRunning; -#endif } diff --git a/Robust.UnitTesting/Client/GameObjects/Components/TransformComponentTests.cs b/Robust.UnitTesting/Client/GameObjects/Components/TransformComponentTests.cs index 02990b61c..0f5a3e3c2 100644 --- a/Robust.UnitTesting/Client/GameObjects/Components/TransformComponentTests.cs +++ b/Robust.UnitTesting/Client/GameObjects/Components/TransformComponentTests.cs @@ -13,22 +13,18 @@ namespace Robust.UnitTesting.Client.GameObjects.Components [TestOf(typeof(TransformComponent))] public sealed class TransformComponentTests { - private static readonly MapId TestMapId = new(1); - private static (ISimulation, EntityUid gridA, EntityUid gridB) SimulationFactory() { var sim = RobustServerSimulation .NewSimulation() .InitializeInstance(); + var mapId = sim.Resolve().System().CreateMap(); var mapManager = sim.Resolve(); - // Adds the map with id 1, and spawns entity 1 as the map entity. - mapManager.CreateMap(TestMapId); - // Adds two grids to use in tests. - var gridA = mapManager.CreateGridEntity(TestMapId); - var gridB = mapManager.CreateGridEntity(TestMapId); + var gridA = mapManager.CreateGridEntity(mapId); + var gridB = mapManager.CreateGridEntity(mapId); return (sim, gridA, gridB); } diff --git a/Robust.UnitTesting/Server/GameObjects/ComponentMapInitTest.cs b/Robust.UnitTesting/Server/GameObjects/ComponentMapInitTest.cs index 1d1e07af0..25ed08d68 100644 --- a/Robust.UnitTesting/Server/GameObjects/ComponentMapInitTest.cs +++ b/Robust.UnitTesting/Server/GameObjects/ComponentMapInitTest.cs @@ -27,7 +27,7 @@ public sealed partial class ComponentMapInitTest var sim = simFactory.InitializeInstance(); var entManager = sim.Resolve(); var mapManager = sim.Resolve(); - var mapId = mapManager.CreateMap(); + sim.Resolve().System().CreateMap(out var mapId); var ent = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); Assert.That(entManager.GetComponent(ent).EntityLifeStage, Is.EqualTo(EntityLifeStage.MapInitialized)); diff --git a/Robust.UnitTesting/Server/GameObjects/Components/Container_Test.cs b/Robust.UnitTesting/Server/GameObjects/Components/Container_Test.cs index 1286d091c..434ec44fd 100644 --- a/Robust.UnitTesting/Server/GameObjects/Components/Container_Test.cs +++ b/Robust.UnitTesting/Server/GameObjects/Components/Container_Test.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Numerics; using NUnit.Framework; using Robust.Server.Containers; using Robust.Shared.Containers; @@ -19,14 +18,15 @@ namespace Robust.UnitTesting.Server.GameObjects.Components [TestFixture, Parallelizable] public sealed partial class ContainerTest { + private static EntityCoordinates _coords; + private static ISimulation SimulationFactory() { var sim = RobustServerSimulation .NewSimulation() .InitializeInstance(); - - // Adds the map with id 1, and spawns entity 1 as the map entity. - sim.AddMap(1); + var map = sim.CreateMap(); + _coords = new EntityCoordinates(map.Item1, default); return sim; } @@ -37,8 +37,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var sim = SimulationFactory(); var entManager = sim.Resolve(); var containerSys = sim.Resolve().GetEntitySystem(); - - var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var entity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(entity, "dummy"); @@ -74,9 +73,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var sim = SimulationFactory(); var entManager = sim.Resolve(); var containerSys = sim.Resolve().GetEntitySystem(); - - var owner = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); - var inserted = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var owner = sim.SpawnEntity(null,_coords); + var inserted = sim.SpawnEntity(null,_coords); var transform = entManager.GetComponent(inserted); var container = containerSys.MakeContainer(owner, "dummy"); @@ -104,11 +102,10 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var sim = SimulationFactory(); var entManager = sim.Resolve(); var containerSys = sim.Resolve().GetEntitySystem(); - - var owner = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); - var inserted = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var owner = sim.SpawnEntity(null,_coords); + var inserted = sim.SpawnEntity(null,_coords); var transform = entManager.GetComponent(inserted); - var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var entity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(owner, "dummy"); Assert.That(containerSys.Insert(inserted, container), Is.True); @@ -132,8 +129,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var sim = SimulationFactory(); var entMan = sim.Resolve(); var containerSys = sim.Resolve().GetEntitySystem(); - - var coordinates = new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0)); + var coordinates =_coords; var entityOne = sim.SpawnEntity(null, coordinates); var entityTwo = sim.SpawnEntity(null, coordinates); var entityThree = sim.SpawnEntity(null, coordinates); @@ -165,8 +161,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components { var sim = SimulationFactory(); var containerSys = sim.Resolve().GetEntitySystem(); - - var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var entity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(entity, "dummy"); Assert.That(containerSys.Insert(entity, container), Is.False); @@ -178,9 +173,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components { var sim = SimulationFactory(); var containerSys = sim.Resolve().GetEntitySystem(); - - var mapEnt = EntityUid.FirstUid; - var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var mapEnt = new EntityUid(1); + var entity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(entity, "dummy"); Assert.That(containerSys.Insert(mapEnt, container), Is.False); @@ -194,7 +188,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var containerSys = sim.Resolve().GetEntitySystem(); var grid = sim.Resolve().CreateGridEntity(new MapId(1)).Owner; - var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var entity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(entity, "dummy"); Assert.That(containerSys.Insert(grid, container), Is.False); @@ -207,10 +201,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var sim = SimulationFactory(); var entManager = sim.Resolve(); var containerSys = sim.Resolve().GetEntitySystem(); - - var containerEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var containerEntity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(containerEntity, "dummy"); - var insertEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var insertEntity = sim.SpawnEntity(null,_coords); var result = containerSys.Insert(insertEntity, container); @@ -230,10 +223,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components { var sim = SimulationFactory(); var containerSys = sim.Resolve().GetEntitySystem(); - - var containerEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var containerEntity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(containerEntity, "dummy"); - var insertEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var insertEntity = sim.SpawnEntity(null,_coords); var result = containerSys.Remove(insertEntity, container); @@ -245,12 +237,11 @@ namespace Robust.UnitTesting.Server.GameObjects.Components { var sim = SimulationFactory(); var containerSys = sim.Resolve().GetEntitySystem(); - - var entity1 = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var entity1 = sim.SpawnEntity(null,_coords); var container1 = containerSys.MakeContainer(entity1, "dummy"); - var entity2 = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var entity2 = sim.SpawnEntity(null,_coords); var container2 = containerSys.MakeContainer(entity2, "dummy"); - var transferEntity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var transferEntity = sim.SpawnEntity(null,_coords); containerSys.Insert(transferEntity, container1); var result = containerSys.Insert(transferEntity, container2); @@ -266,10 +257,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components var sim = SimulationFactory(); var entManager = sim.Resolve(); var containerSys = entManager.System(); - - var entity = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var entity = sim.SpawnEntity(null,_coords); var container = containerSys.MakeContainer(entity, "dummy"); - var childEnt = sim.SpawnEntity(null, new EntityCoordinates(EntityUid.FirstUid, new Vector2(0, 0))); + var childEnt = sim.SpawnEntity(null,_coords); container.OccludesLight = true; container.ShowContents = true; diff --git a/Robust.UnitTesting/Server/GameObjects/Components/TransformIntegration_Test.cs b/Robust.UnitTesting/Server/GameObjects/Components/TransformIntegration_Test.cs index 9da5438ef..2977025d0 100644 --- a/Robust.UnitTesting/Server/GameObjects/Components/TransformIntegration_Test.cs +++ b/Robust.UnitTesting/Server/GameObjects/Components/TransformIntegration_Test.cs @@ -20,12 +20,9 @@ public sealed class TransformIntegration_Test var sim = factory.InitializeInstance(); var entManager = sim.Resolve(); - var mapManager = sim.Resolve(); var containerSystem = entManager.System(); var xformSystem = entManager.System(); - - var map1Id = mapManager.CreateMap(); - var map1 = mapManager.GetMapEntityId(map1Id); + var map1 = sim.CreateMap().Uid; var ent1 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero)); var ent2 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero)); diff --git a/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs b/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs index bb91e6128..97e312d4b 100644 --- a/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs +++ b/Robust.UnitTesting/Server/GameObjects/Components/Transform_Test.cs @@ -49,7 +49,6 @@ namespace Robust.UnitTesting.Server.GameObjects.Components EntityManager = IoCManager.Resolve(); MapManager = IoCManager.Resolve(); - MapManager.CreateMap(); IoCManager.Resolve().Initialize(); var manager = IoCManager.Resolve(); @@ -57,11 +56,12 @@ namespace Robust.UnitTesting.Server.GameObjects.Components manager.LoadFromStream(new StringReader(Prototypes)); manager.ResolveResults(); + var mapSys = EntityManager.System(); // build the net dream - MapA = MapManager.CreateMap(); - GridA = MapManager.CreateGridEntity(MapA); + mapSys.CreateMap(out MapA); + mapSys.CreateMap(out MapB); - MapB = MapManager.CreateMap(); + GridA = MapManager.CreateGridEntity(MapA); GridB = MapManager.CreateGridEntity(MapB); //NOTE: The grids have not moved, so we can assert worldpos == localpos for the test diff --git a/Robust.UnitTesting/Server/GameObjects/ThrowingEntityDeletion_Test.cs b/Robust.UnitTesting/Server/GameObjects/ThrowingEntityDeletion_Test.cs index c1ce9fc43..2bff79e80 100644 --- a/Robust.UnitTesting/Server/GameObjects/ThrowingEntityDeletion_Test.cs +++ b/Robust.UnitTesting/Server/GameObjects/ThrowingEntityDeletion_Test.cs @@ -37,8 +37,6 @@ namespace Robust.UnitTesting.Server.GameObjects .RegisterEntitySystems(f => f.LoadExtraSystemType()) .RegisterPrototypes(protoMan => protoMan.LoadString(PROTOTYPES)) .InitializeInstance(); - - _sim.AddMap(1); } [TestCase("throwInAdd")] @@ -47,8 +45,9 @@ namespace Robust.UnitTesting.Server.GameObjects public void Test(string prototypeName) { var entMan = _sim.Resolve(); + _sim.Resolve().System().CreateMap(out var map); - Assert.That(() => entMan.SpawnEntity(prototypeName, new MapCoordinates(0, 0, new MapId(1))), + Assert.That(() => entMan.SpawnEntity(prototypeName, new MapCoordinates(0, 0, map)), Throws.TypeOf()); Assert.That(entMan.GetEntities().Where(p => entMan.GetComponent(p).EntityPrototype?.ID == prototypeName), Is.Empty); diff --git a/Robust.UnitTesting/Server/GameStates/DefaultEntityTest.cs b/Robust.UnitTesting/Server/GameStates/DefaultEntityTest.cs index 5c4186abd..235c5b1fa 100644 --- a/Robust.UnitTesting/Server/GameStates/DefaultEntityTest.cs +++ b/Robust.UnitTesting/Server/GameStates/DefaultEntityTest.cs @@ -75,8 +75,7 @@ public sealed class DefaultEntityTest : RobustIntegrationTest EntityCoordinates coords = default!; await server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - var map = mapMan.GetMapEntityId(mapId); + var map = server.System().CreateMap(); coords = new(map, default); var playerUid = sEntMan.SpawnEntity(null, coords); player = sEntMan.GetNetEntity(playerUid); diff --git a/Robust.UnitTesting/Server/GameStates/MissingParentTest.cs b/Robust.UnitTesting/Server/GameStates/MissingParentTest.cs index 233e25cb2..c3fc09efa 100644 --- a/Robust.UnitTesting/Server/GameStates/MissingParentTest.cs +++ b/Robust.UnitTesting/Server/GameStates/MissingParentTest.cs @@ -71,15 +71,13 @@ public sealed class MissingParentTest : RobustIntegrationTest } // Set up map and spawn player - EntityUid map = default; NetEntity player = default; NetEntity entity = default; EntityCoordinates coords = default; NetCoordinates nCoords = default; await server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - map = mapMan.GetMapEntityId(mapId); + var map = server.System().CreateMap(); coords = new(map, default); var playerUid = sEntMan.SpawnEntity(null, coords); diff --git a/Robust.UnitTesting/Server/GameStates/PvsChunkTest.cs b/Robust.UnitTesting/Server/GameStates/PvsChunkTest.cs index f3a009d79..8aa0ecaa2 100644 --- a/Robust.UnitTesting/Server/GameStates/PvsChunkTest.cs +++ b/Robust.UnitTesting/Server/GameStates/PvsChunkTest.cs @@ -69,14 +69,11 @@ public sealed class PvsChunkTest : RobustIntegrationTest EntityCoordinates mapCoords = default; await server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - map1 = mapMan.GetMapEntityId(mapId); + map1 = server.System().CreateMap(); mapCoords = new(map1, default); - var map2Id = mapMan.CreateMap(); - map2 = mapMan.GetMapEntityId(map2Id); - - var gridComp = mapMan.CreateGridEntity(map2Id); + map2 = server.System().CreateMap(); + var gridComp = mapMan.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.UnitTesting/Server/GameStates/PvsReEntryTest.cs b/Robust.UnitTesting/Server/GameStates/PvsReEntryTest.cs index c5c3534f4..7fea6330c 100644 --- a/Robust.UnitTesting/Server/GameStates/PvsReEntryTest.cs +++ b/Robust.UnitTesting/Server/GameStates/PvsReEntryTest.cs @@ -74,8 +74,7 @@ public sealed class PvsReEntryTest : RobustIntegrationTest EntityCoordinates coords = default; await server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - map = mapMan.GetMapEntityId(mapId); + map = server.System().CreateMap(); coords = new(map, default); var playerUid = sEntMan.SpawnEntity(null, coords); diff --git a/Robust.UnitTesting/Server/GameStates/PvsSystemTests.cs b/Robust.UnitTesting/Server/GameStates/PvsSystemTests.cs index 84fa99d82..f08e7c563 100644 --- a/Robust.UnitTesting/Server/GameStates/PvsSystemTests.cs +++ b/Robust.UnitTesting/Server/GameStates/PvsSystemTests.cs @@ -50,8 +50,7 @@ public sealed class PvsSystemTests : RobustIntegrationTest EntityUid map = default; await server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - map = mapMan.GetMapEntityId(mapId); + map = server.System().CreateMap(out var mapId); var gridComp = mapMan.CreateGridEntity(mapId); gridComp.Comp.SetTile(Vector2i.Zero, new Tile(1)); grid = gridComp.Owner; diff --git a/Robust.UnitTesting/Server/Maps/MapLoaderTest.cs b/Robust.UnitTesting/Server/Maps/MapLoaderTest.cs index 515e47092..68ad2b220 100644 --- a/Robust.UnitTesting/Server/Maps/MapLoaderTest.cs +++ b/Robust.UnitTesting/Server/Maps/MapLoaderTest.cs @@ -11,6 +11,7 @@ using Robust.Shared.Physics.Dynamics; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager; using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Utility; namespace Robust.UnitTesting.Server.Maps { @@ -78,15 +79,10 @@ entities: public void TestDataLoadPriority() { // TODO: Fix after serv3 - var map = IoCManager.Resolve(); + // fix what? var entMan = IoCManager.Resolve(); - - var mapId = map.CreateMap(); - // Yay test bullshit - var mapUid = map.GetMapEntityId(mapId); - entMan.EnsureComponent(mapUid); - entMan.EnsureComponent(mapUid); + entMan.System().CreateMap(out var mapId); var traversal = entMan.System(); traversal.Enabled = false; diff --git a/Robust.UnitTesting/Server/RobustServerSimulation.cs b/Robust.UnitTesting/Server/RobustServerSimulation.cs index 8022debcd..78b073403 100644 --- a/Robust.UnitTesting/Server/RobustServerSimulation.cs +++ b/Robust.UnitTesting/Server/RobustServerSimulation.cs @@ -71,8 +71,7 @@ namespace Robust.UnitTesting.Server /// /// Adds a new map directly to the map manager. /// - EntityUid AddMap(int mapId); - EntityUid AddMap(MapId mapId); + (EntityUid Uid, MapId MapId) CreateMap(); EntityUid SpawnEntity(string? protoId, EntityCoordinates coordinates); EntityUid SpawnEntity(string? protoId, MapCoordinates coordinates); } @@ -99,18 +98,10 @@ namespace Robust.UnitTesting.Server return Collection.Resolve(); } - public EntityUid AddMap(int mapId) + public (EntityUid Uid, MapId MapId) CreateMap() { - var mapMan = Collection.Resolve(); - mapMan.CreateMap(new MapId(mapId)); - return mapMan.GetMapEntityId(new MapId(mapId)); - } - - public EntityUid AddMap(MapId mapId) - { - var mapMan = Collection.Resolve(); - mapMan.CreateMap(mapId); - return mapMan.GetMapEntityId(mapId); + var uid = Collection.Resolve().System().CreateMap(out var mapId); + return (uid, mapId); } public EntityUid SpawnEntity(string? protoId, EntityCoordinates coordinates) diff --git a/Robust.UnitTesting/Shared/EntityLookup_Test.cs b/Robust.UnitTesting/Shared/EntityLookup_Test.cs index 8994cd86c..e4deb6d12 100644 --- a/Robust.UnitTesting/Shared/EntityLookup_Test.cs +++ b/Robust.UnitTesting/Shared/EntityLookup_Test.cs @@ -21,7 +21,7 @@ namespace Robust.UnitTesting.Shared var entManager = server.Resolve(); var mapManager = server.Resolve(); - var mapId = mapManager.CreateMap(); + var mapId = server.CreateMap().MapId; var theMapSpotBeingUsed = new Box2(Vector2.Zero, Vector2.One); @@ -43,7 +43,7 @@ namespace Robust.UnitTesting.Shared var entManager = server.Resolve(); var mapManager = server.Resolve(); - var mapId = mapManager.CreateMap(); + var mapId = server.CreateMap().MapId; var grid = mapManager.CreateGridEntity(mapId); var theMapSpotBeingUsed = new Box2(Vector2.Zero, Vector2.One); diff --git a/Robust.UnitTesting/Shared/GameObjects/ContainerTests.cs b/Robust.UnitTesting/Shared/GameObjects/ContainerTests.cs index 907950f78..51c353d16 100644 --- a/Robust.UnitTesting/Shared/GameObjects/ContainerTests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/ContainerTests.cs @@ -62,7 +62,7 @@ namespace Robust.UnitTesting.Shared.GameObjects await server.WaitAssertion(() => { - mapId = sMapManager.CreateMap(); + sEntManager.System().CreateMap(out mapId); mapPos = new MapCoordinates(new Vector2(0, 0), mapId); entityUid = sEntManager.SpawnEntity(null, mapPos); @@ -190,7 +190,7 @@ namespace Robust.UnitTesting.Shared.GameObjects await server.WaitAssertion(() => { - mapId = sMapManager.CreateMap(); + sEntManager.System().CreateMap(out mapId); mapPos = new MapCoordinates(new Vector2(0, 0), mapId); sEntityUid = sEntManager.SpawnEntity(null, mapPos); @@ -300,7 +300,7 @@ namespace Robust.UnitTesting.Shared.GameObjects await server.WaitAssertion(() => { // build the map - var mapIdOne = mapManager.CreateMap(); + sEntManager.System().CreateMap(out var mapIdOne); Assert.That(mapManager.IsMapInitialized(mapIdOne), Is.True); var containerEnt = sEntManager.SpawnEntity(null, new MapCoordinates(1, 1, mapIdOne)); @@ -327,7 +327,7 @@ namespace Robust.UnitTesting.Shared.GameObjects await server.WaitAssertion(() => { var mapLoader = sEntManager.System(); - var mapIdTwo = mapManager.CreateMap(); + sEntManager.System().CreateMap(out var mapIdTwo); // load the map mapLoader.Load(mapIdTwo, "container_test.yml"); diff --git a/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.OrderedEvents.cs b/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.OrderedEvents.cs index 17a6d8354..5b655d240 100644 --- a/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.OrderedEvents.cs +++ b/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.OrderedEvents.cs @@ -30,8 +30,7 @@ public sealed partial class EntityEventBusTests .RegisterComponents(factory => factory.RegisterClass()) .InitializeInstance(); - var map = new MapId(1); - simulation.AddMap(map); + var map = simulation.CreateMap().MapId; var entity = simulation.SpawnEntity(null, new MapCoordinates(0, 0, map)); simulation.Resolve().AddComponent(entity); diff --git a/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.RefDirectedEvents.cs b/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.RefDirectedEvents.cs index 2878d59e8..c2f1ef3dd 100644 --- a/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.RefDirectedEvents.cs +++ b/Robust.UnitTesting/Shared/GameObjects/EntityEventBusTests.RefDirectedEvents.cs @@ -20,9 +20,7 @@ namespace Robust.UnitTesting.Shared.GameObjects .RegisterEntitySystems(factory => factory.LoadExtraSystemType()) .InitializeInstance(); - var map = new MapId(1); - simulation.AddMap(map); - + var map = simulation.CreateMap().MapId; var entity = simulation.SpawnEntity(null, new MapCoordinates(0, 0, map)); IoCManager.Resolve().AddComponent(entity); @@ -86,9 +84,7 @@ namespace Robust.UnitTesting.Shared.GameObjects }) .InitializeInstance(); - var map = new MapId(1); - simulation.AddMap(map); - + var map = simulation.CreateMap().MapId; var entity = simulation.SpawnEntity(null, new MapCoordinates(0, 0, map)); IoCManager.Resolve().AddComponent(entity); IoCManager.Resolve().AddComponent(entity); diff --git a/Robust.UnitTesting/Shared/GameObjects/EntityManager_Components_Tests.cs b/Robust.UnitTesting/Shared/GameObjects/EntityManager_Components_Tests.cs index 46064fdeb..2fa43f4c7 100644 --- a/Robust.UnitTesting/Shared/GameObjects/EntityManager_Components_Tests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/EntityManager_Components_Tests.cs @@ -16,8 +16,6 @@ namespace Robust.UnitTesting.Shared.GameObjects [TestFixture, Parallelizable ,TestOf(typeof(EntityManager))] public sealed partial class EntityManager_Components_Tests { - private static readonly EntityCoordinates DefaultCoords = new(EntityUid.FirstUid, Vector2.Zero); - private const string DummyLoad = @" - type: entity id: DummyLoad @@ -35,12 +33,12 @@ namespace Robust.UnitTesting.Shared.GameObjects .RegisterPrototypes(fac => fac.LoadString(DummyLoad)) .InitializeInstance(); - sim.AddMap(1); - var entMan = sim.Resolve(); var protoManager = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var map = sim.CreateMap().Uid; + var coords = new EntityCoordinates(map, default); + var entity = entMan.SpawnEntity(null, coords); Assert.That(!entMan.HasComponent(entity)); var proto = protoManager.Index("DummyLoad"); @@ -60,12 +58,12 @@ namespace Robust.UnitTesting.Shared.GameObjects .RegisterPrototypes(fac => fac.LoadString(DummyLoad)) .InitializeInstance(); - sim.AddMap(1); - var entMan = sim.Resolve(); var protoManager = sim.Resolve(); - var entity = entMan.SpawnEntity("DummyLoad", DefaultCoords); + var map = sim.CreateMap().Uid; + var coords = new EntityCoordinates(map, default); + var entity = entMan.SpawnEntity("DummyLoad", coords); var proto = protoManager.Index("DummyLoad"); entMan.RemoveComponents(entity, proto); @@ -80,9 +78,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void AddComponentTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = new DummyComponent() { Owner = entity @@ -100,9 +98,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void AddComponentOverwriteTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = new DummyComponent() { Owner = entity @@ -120,9 +118,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void AddComponent_ExistingDeleted() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var firstComp = new DummyComponent {Owner = entity}; entMan.AddComponent(entity, firstComp); entMan.RemoveComponent(entity); @@ -140,9 +138,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void HasComponentTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); entMan.AddComponent(entity); // Act @@ -156,9 +154,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void HasComponentNoGenericTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); entMan.AddComponent(entity); // Act @@ -172,13 +170,13 @@ namespace Robust.UnitTesting.Shared.GameObjects public void HasNetComponentTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var factory = sim.Resolve(); var netId = factory.GetRegistration().NetID!; var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); entMan.AddComponent(entity); // Act @@ -192,13 +190,13 @@ namespace Robust.UnitTesting.Shared.GameObjects public void GetNetComponentTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var factory = sim.Resolve(); var netId = factory.GetRegistration().NetID!; var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); // Act @@ -212,9 +210,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void TryGetComponentTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); // Act @@ -229,13 +227,13 @@ namespace Robust.UnitTesting.Shared.GameObjects public void TryGetNetComponentTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var factory = sim.Resolve(); var netId = factory.GetRegistration().NetID!; var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); // Act @@ -250,9 +248,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void RemoveComponentTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); // Act @@ -266,9 +264,9 @@ namespace Robust.UnitTesting.Shared.GameObjects [Test] public void EnsureQueuedComponentDeletion() { - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); Assert.That(component.LifeStage, Is.LessThanOrEqualTo(ComponentLifeStage.Running)); @@ -284,13 +282,13 @@ namespace Robust.UnitTesting.Shared.GameObjects public void RemoveNetComponentTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var factory = sim.Resolve(); var netId = factory.GetRegistration().NetID!; var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); // Act @@ -305,9 +303,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void GetComponentsTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); // Act @@ -323,9 +321,9 @@ namespace Robust.UnitTesting.Shared.GameObjects public void GetAllComponentsTest() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); // Act @@ -341,10 +339,10 @@ namespace Robust.UnitTesting.Shared.GameObjects public void GetAllComponentInstances() { // Arrange - var sim = SimulationFactory(); + var (sim, coords) = SimulationFactory(); var entMan = sim.Resolve(); var fac = sim.Resolve(); - var entity = entMan.SpawnEntity(null, DefaultCoords); + var entity = entMan.SpawnEntity(null, coords); var component = entMan.AddComponent(entity); // Act @@ -356,17 +354,16 @@ namespace Robust.UnitTesting.Shared.GameObjects Assert.That(list[0], Is.EqualTo(component)); } - private static ISimulation SimulationFactory() + private static (ISimulation, EntityCoordinates) SimulationFactory() { var sim = RobustServerSimulation .NewSimulation() .RegisterComponents(factory => factory.RegisterClass()) .InitializeInstance(); - // Adds the map with id 1, and spawns entity 1 as the map entity. - sim.AddMap(1); - - return sim; + var map = sim.CreateMap().Uid; + var coords = new EntityCoordinates(map, default); + return (sim, coords); } [NetworkedComponent()] diff --git a/Robust.UnitTesting/Shared/GameObjects/IEntityManagerTests.cs b/Robust.UnitTesting/Shared/GameObjects/IEntityManagerTests.cs index e8975b322..28dc8c5c2 100644 --- a/Robust.UnitTesting/Shared/GameObjects/IEntityManagerTests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/IEntityManagerTests.cs @@ -1,7 +1,6 @@ using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.Map; -using Robust.Shared.Maths; using Robust.UnitTesting.Server; namespace Robust.UnitTesting.Shared.GameObjects @@ -9,19 +8,12 @@ namespace Robust.UnitTesting.Shared.GameObjects [TestFixture, Parallelizable] sealed class EntityManagerTests { - private static readonly MapId TestMapId = new(1); - private static ISimulation SimulationFactory() { var sim = RobustServerSimulation .NewSimulation() .InitializeInstance(); - var mapManager = sim.Resolve(); - - // Adds the map with id 1, and spawns entity 1 as the map entity. - mapManager.CreateMap(TestMapId); - return sim; } @@ -32,9 +24,10 @@ namespace Robust.UnitTesting.Shared.GameObjects public void SpawnEntity_PrototypeTransform_Works() { var sim = SimulationFactory(); + var map = sim.CreateMap().MapId; var entMan = sim.Resolve(); - var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, TestMapId)); + var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, map)); Assert.That(newEnt, Is.Not.EqualTo(EntityUid.Invalid)); } @@ -48,7 +41,7 @@ namespace Robust.UnitTesting.Shared.GameObjects Assert.That(entManager.Count(), Is.EqualTo(0)); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; Assert.That(entManager.Count(), Is.EqualTo(1)); mapManager.DeleteMap(mapId); Assert.That(entManager.Count(), Is.EqualTo(0)); diff --git a/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs b/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs index c34c679b2..e260e50da 100644 --- a/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs @@ -20,8 +20,6 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [TestFixture, Parallelizable] public sealed partial class AnchoredSystemTests { - private static readonly MapId TestMapId = new(1); - private sealed class Subscriber : IEntityEventSubscriber { } private const string Prototypes = @" @@ -32,7 +30,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems - type: Transform anchored: true"; - private static (ISimulation, EntityUid gridId) SimulationFactory() + private static (ISimulation, EntityUid gridId, MapCoordinates) SimulationFactory() { var sim = RobustServerSimulation .NewSimulation() @@ -46,12 +44,12 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems var mapManager = sim.Resolve(); // Adds the map with id 1, and spawns entity 1 as the map entity. - mapManager.CreateMap(TestMapId); - + 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 = mapManager.CreateGridEntity(testMapId); - return (sim, grid); + return (sim, grid, coords); } // An entity is anchored to the tile it is over on the target grid. @@ -70,11 +68,9 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void OnAnchored_WorldPosition_TileCenter() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coordinates) = SimulationFactory(); var entMan = sim.Resolve(); - var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId); - // can only be anchored to a tile var grid = entMan.GetComponent(gridId); grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1)); @@ -169,9 +165,9 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems var entMan = sim.Resolve(); var mapMan = sim.Resolve(); - mapMan.CreateMap(TestMapId); - var grid = mapMan.CreateGrid(TestMapId); - var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId); + var mapId = sim.CreateMap().MapId; + var grid = mapMan.CreateGrid(mapId); + var coordinates = new MapCoordinates(new Vector2(7, 7), mapId); var pos = grid.TileIndicesFor(coordinates); grid.SetTile(pos, new Tile(1)); @@ -194,11 +190,9 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void OnAnchored_Parent_SetToGrid() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coordinates) = SimulationFactory(); var entMan = sim.Resolve(); - var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId); - // can only be anchored to a tile var grid = entMan.GetComponent(gridId); grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1)); @@ -221,11 +215,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void OnAnchored_EmptyTile_Nop() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); grid.SetTile(tileIndices, Tile.Empty); @@ -243,11 +237,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void OnAnchored_NonEmptyTile_Anchors() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); grid.SetTile(tileIndices, new Tile(1)); @@ -269,11 +263,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void Anchored_SetPosition_Nop() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coordinates) = SimulationFactory(); var entMan = sim.Resolve(); // coordinates are already tile centered to prevent snapping and MoveEvent - var coordinates = new MapCoordinates(new Vector2(7.5f, 7.5f), TestMapId); + coordinates = coordinates.Offset(new Vector2(0.5f, 0.5f)); // can only be anchored to a tile var grid = entMan.GetComponent(gridId); @@ -297,12 +291,10 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void Anchored_ChangeParent_Unanchors() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coordinates) = SimulationFactory(); var entMan = sim.Resolve(); var mapMan = sim.Resolve(); - var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId); - var grid = entMan.GetComponent(gridId); var ent1 = entMan.SpawnEntity(null, coordinates); @@ -311,7 +303,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems entMan.GetComponent(ent1).Anchored = true; // Act - entMan.EntitySysManager.GetEntitySystem().SetParent(ent1, mapMan.GetMapEntityId(TestMapId)); + entMan.EntitySysManager.GetEntitySystem().SetParent(ent1, mapMan.GetMapEntityId(coordinates.MapId)); Assert.That(entMan.GetComponent(ent1).Anchored, Is.False); Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0)); @@ -326,11 +318,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void Anchored_SetParentSame_Nop() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); grid.SetTile(tileIndices, new Tile(1)); entMan.GetComponent(ent1).Anchored = true; @@ -348,11 +340,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void Anchored_TileToSpace_Unanchors() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); grid.SetTile(tileIndices, new Tile(1)); grid.SetTile(new Vector2i(100, 100), new Tile(1)); // Prevents the grid from being deleted when the Act happens @@ -376,11 +368,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void Anchored_AddToContainer_Unanchors() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); grid.SetTile(tileIndices, new Tile(1)); entMan.GetComponent(ent1).Anchored = true; @@ -404,11 +396,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void Anchored_AddPhysComp_IsStaticBody() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); grid.SetTile(tileIndices, new Tile(1)); entMan.GetComponent(ent1).Anchored = true; @@ -426,12 +418,10 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void OnAnchored_HasPhysicsComp_IsStaticBody() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coordinates) = SimulationFactory(); var entMan = sim.Resolve(); var physSystem = sim.Resolve().GetEntitySystem(); - var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId); - // can only be anchored to a tile var grid = entMan.GetComponent(gridId); grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1)); @@ -452,11 +442,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void OnUnanchored_HasPhysicsComp_IsDynamicBody() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); grid.SetTile(tileIndices, new Tile(1)); var physComp = entMan.AddComponent(ent1); @@ -474,13 +464,13 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void SpawnAnchored_EmptyTile_Unanchors() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); // Act - var ent1 = entMan.SpawnEntity("anchoredEnt", new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity("anchoredEnt", coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); Assert.That(grid.GetAnchoredEntities(tileIndices).Count(), Is.EqualTo(0)); @@ -494,11 +484,11 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void OnAnchored_InContainer_Nop() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coords) = SimulationFactory(); var entMan = sim.Resolve(); var grid = entMan.GetComponent(gridId); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(new Vector2(7, 7), TestMapId)); + var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = grid.TileIndicesFor(entMan.GetComponent(ent1).Coordinates); grid.SetTile(tileIndices, new Tile(1)); @@ -522,12 +512,10 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void Unanchored_Unanchor_Nop() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coordinates) = SimulationFactory(); var entMan = sim.Resolve(); var mapMan = sim.Resolve(); - var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId); - // can only be anchored to a tile var grid = entMan.GetComponent(gridId); grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1)); @@ -539,7 +527,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems // Act entMan.System().FailOnMove = true; entMan.GetComponent(ent1).Anchored = false; - Assert.That(entMan.GetComponent(ent1).ParentUid, Is.EqualTo(mapMan.GetMapEntityId(TestMapId))); + Assert.That(entMan.GetComponent(ent1).ParentUid, Is.EqualTo(mapMan.GetMapEntityId(coordinates.MapId))); entMan.System().FailOnMove = false; traversal.Enabled = true; } @@ -550,11 +538,9 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems [Test] public void Anchored_Unanchored_ParentUnchanged() { - var (sim, gridId) = SimulationFactory(); + var (sim, gridId, coordinates) = SimulationFactory(); var entMan = sim.Resolve(); - var coordinates = new MapCoordinates(new Vector2(7, 7), TestMapId); - // can only be anchored to a tile var grid = entMan.GetComponent(gridId); grid.SetTile(grid.TileIndicesFor(coordinates), new Tile(1)); diff --git a/Robust.UnitTesting/Shared/GameObjects/Systems/TransformSystemTests.cs b/Robust.UnitTesting/Shared/GameObjects/Systems/TransformSystemTests.cs index 8af756eff..e4431ec88 100644 --- a/Robust.UnitTesting/Shared/GameObjects/Systems/TransformSystemTests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/Systems/TransformSystemTests.cs @@ -17,9 +17,6 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems .RegisterEntitySystems(f => f.LoadExtraSystemType()) .InitializeInstance(); - // Adds the map with id 1, and spawns entity 1 as the map entity. - sim.AddMap(1); - return sim; } @@ -31,7 +28,8 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems { var sim = SimulationFactory(); var entMan = sim.Resolve(); - var ent1 = entMan.SpawnEntity(null, new MapCoordinates(Vector2.Zero, new MapId(1))); + var map = sim.CreateMap().MapId; + var ent1 = entMan.SpawnEntity(null, new MapCoordinates(Vector2.Zero, map)); entMan.System().ResetCounters(); IoCManager.Resolve().GetComponent(ent1).LocalPosition = Vector2.One; @@ -47,7 +45,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems var sim = SimulationFactory(); var entManager = sim.Resolve(); var xformSystem = sim.Resolve().GetEntitySystem(); - var mapId = new MapId(1); + var mapId = sim.CreateMap().MapId; var parent = entManager.SpawnEntity(null, new MapCoordinates(Vector2.One, mapId)); var parentXform = entManager.GetComponent(parent); @@ -83,7 +81,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems var sim = SimulationFactory(); var entManager = sim.Resolve(); var xformSystem = sim.Resolve().GetEntitySystem(); - var mapId = new MapId(1); + var mapId = sim.CreateMap().MapId; var parent = entManager.SpawnEntity(null, new MapCoordinates(Vector2.One, mapId)); var parentXform = entManager.GetComponent(parent); diff --git a/Robust.UnitTesting/Shared/GameObjects/TransformComponent_Tests.cs b/Robust.UnitTesting/Shared/GameObjects/TransformComponent_Tests.cs index 7039f8ff7..336c9e02e 100644 --- a/Robust.UnitTesting/Shared/GameObjects/TransformComponent_Tests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/TransformComponent_Tests.cs @@ -20,9 +20,7 @@ namespace Robust.UnitTesting.Shared.GameObjects var server = RobustServerSimulation.NewSimulation().InitializeInstance(); var entManager = server.Resolve(); - var mapManager = server.Resolve(); - - var mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out var mapId); var ent1 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); var ent2 = entManager.SpawnEntity(null, new MapCoordinates(new Vector2(100f, 0f), mapId)); @@ -56,7 +54,7 @@ namespace Robust.UnitTesting.Shared.GameObjects var entManager = server.Resolve(); var mapManager = server.Resolve(); - var mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); grid.Comp.SetTile(new Vector2i(0, 0), new Tile(1)); var gridXform = entManager.GetComponent(grid); diff --git a/Robust.UnitTesting/Shared/GameState/ComponentStateTests.cs b/Robust.UnitTesting/Shared/GameState/ComponentStateTests.cs index 0aa713f7c..2d0d303b2 100644 --- a/Robust.UnitTesting/Shared/GameState/ComponentStateTests.cs +++ b/Robust.UnitTesting/Shared/GameState/ComponentStateTests.cs @@ -38,12 +38,7 @@ public sealed partial class ComponentStateTests : RobustIntegrationTest server.Post(() => server.CfgMan.SetCVar(CVars.NetPVS, true)); // Set up map. - EntityUid map = default; - await server.WaitPost(() => - { - var mapId = server.MapMan.CreateMap(); - map = server.MapMan.GetMapEntityId(mapId); - }); + var map = server.System().CreateMap(); await RunTicks(); @@ -162,12 +157,7 @@ public sealed partial class ComponentStateTests : RobustIntegrationTest server.Post(() => server.CfgMan.SetCVar(CVars.NetPVS, true)); // Set up map. - EntityUid map = default; - await server.WaitPost(() => - { - var mapId = server.MapMan.CreateMap(); - map = server.MapMan.GetMapEntityId(mapId); - }); + var map = server.System().CreateMap(); await RunTicks(); diff --git a/Robust.UnitTesting/Shared/GameState/DeletionNetworkingTests.cs b/Robust.UnitTesting/Shared/GameState/DeletionNetworkingTests.cs index d73656ea0..4185e9524 100644 --- a/Robust.UnitTesting/Shared/GameState/DeletionNetworkingTests.cs +++ b/Robust.UnitTesting/Shared/GameState/DeletionNetworkingTests.cs @@ -58,11 +58,10 @@ public sealed class DeletionNetworkingTests : RobustIntegrationTest EntityUid grid2 = default; NetEntity grid1Net = default; NetEntity grid2Net = default; + server.System().CreateMap(out var mapId); await server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - mapMan.GetMapEntityId(mapId); var gridComp = mapMan.CreateGridEntity(mapId); gridComp.Comp.SetTile(Vector2i.Zero, new Tile(1)); grid1 = gridComp.Owner; diff --git a/Robust.UnitTesting/Shared/GameState/NoSharedReferencesTest.cs b/Robust.UnitTesting/Shared/GameState/NoSharedReferencesTest.cs index eecee8159..e0829283f 100644 --- a/Robust.UnitTesting/Shared/GameState/NoSharedReferencesTest.cs +++ b/Robust.UnitTesting/Shared/GameState/NoSharedReferencesTest.cs @@ -37,12 +37,7 @@ public sealed partial class NoSharedReferencesTest : RobustIntegrationTest client.Post(() => netMan.ClientConnect(null!, 0, null!)); // Set up map. - EntityUid map = default; - await server.WaitPost(() => - { - var mapId = server.MapMan.CreateMap(); - map = server.MapMan.GetMapEntityId(mapId); - }); + var map = server.System().CreateMap(); await RunTicks(); diff --git a/Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs b/Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs index d1613b1e4..79f8efdb9 100644 --- a/Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/EntityCoordinates_Tests.cs @@ -48,8 +48,7 @@ namespace Robust.UnitTesting.Shared.Map var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); - var mapId = mapManager.CreateMap(); - var mapEntity = mapManager.CreateNewMapEntity(mapId); + var mapEntity = entityManager.System().CreateMap(out var mapId); var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, mapId)); var coords = IoCManager.Resolve().GetComponent(newEnt).Coordinates; @@ -74,10 +73,7 @@ namespace Robust.UnitTesting.Shared.Map public void IsValid_NonFiniteVector_False(float x, float y) { var entityManager = IoCManager.Resolve(); - var mapManager = IoCManager.Resolve(); - - var mapId = mapManager.CreateMap(); - var mapEntity = mapManager.CreateNewMapEntity(mapId); + entityManager.System().CreateMap(out var mapId); var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(new Vector2(x, y), mapId)); var coords = IoCManager.Resolve().GetComponent(newEnt).Coordinates; @@ -88,11 +84,7 @@ namespace Robust.UnitTesting.Shared.Map [Test] public void EntityCoordinates_Map() { - var mapManager = IoCManager.Resolve(); - - var mapId = mapManager.CreateMap(); - var mapEntity = mapManager.CreateNewMapEntity(mapId); - + var mapEntity = IoCManager.Resolve().System().CreateMap(); Assert.That(IoCManager.Resolve().GetComponent(mapEntity).ParentUid.IsValid(), Is.False); Assert.That(IoCManager.Resolve().GetComponent(mapEntity).Coordinates.EntityId, Is.EqualTo(mapEntity)); } @@ -104,12 +96,10 @@ namespace Robust.UnitTesting.Shared.Map [Test] public void NoParent_OffsetZero() { - var mapManager = IoCManager.Resolve(); var entMan = IoCManager.Resolve(); var uid = entMan.SpawnEntity(null, MapCoordinates.Nullspace); var xform = entMan.GetComponent(uid); Assert.That(xform.Coordinates.Position, Is.EqualTo(Vector2.Zero)); - xform.LocalPosition = Vector2.One; Assert.That(xform.Coordinates.Position, Is.EqualTo(Vector2.Zero)); } @@ -120,8 +110,7 @@ namespace Robust.UnitTesting.Shared.Map var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); - var mapId = mapManager.CreateMap(); - var mapEnt = mapManager.CreateNewMapEntity(mapId); + var mapEnt = entityManager.System().CreateMap(out var mapId); var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, mapId)); Assert.That(IoCManager.Resolve().GetComponent(mapEnt).Coordinates.GetGridUid(entityManager), Is.Null); @@ -135,7 +124,7 @@ namespace Robust.UnitTesting.Shared.Map var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); - var mapId = mapManager.CreateMap(); + entityManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(gridEnt, Vector2.Zero)); @@ -152,8 +141,7 @@ namespace Robust.UnitTesting.Shared.Map var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); - var mapId = mapManager.CreateMap(); - var mapEnt = mapManager.CreateNewMapEntity(mapId); + var mapEnt = entityManager.System().CreateMap(out var mapId); var newEnt = entityManager.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, mapId)); Assert.That(IoCManager.Resolve().GetComponent(mapEnt).Coordinates.GetMapId(entityManager), Is.EqualTo(mapId)); @@ -166,7 +154,7 @@ namespace Robust.UnitTesting.Shared.Map var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); - var mapId = mapManager.CreateMap(); + entityManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(gridEnt, Vector2.Zero)); @@ -181,9 +169,8 @@ namespace Robust.UnitTesting.Shared.Map var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); - var mapId = mapManager.CreateMap(); + var mapEnt = entityManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); - var mapEnt = mapManager.GetMapEntityId(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero)); @@ -203,9 +190,8 @@ namespace Robust.UnitTesting.Shared.Map var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); - var mapId = mapManager.CreateMap(); + var mapEnt = entityManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); - var mapEnt = mapManager.GetMapEntityId(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero)); @@ -256,7 +242,7 @@ namespace Robust.UnitTesting.Shared.Map var transformSystem = entityManager.System(); - var mapId = mapManager.CreateMap(); + entityManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, entPos)); @@ -274,8 +260,7 @@ namespace Robust.UnitTesting.Shared.Map var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); - var mapId = mapManager.CreateMap(); - var mapEnt = mapManager.GetMapEntityId(mapId); + var mapEnt = entityManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); var gridEnt = grid.Owner; var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero)); diff --git a/Robust.UnitTesting/Shared/Map/GridCollision_Test.cs b/Robust.UnitTesting/Shared/Map/GridCollision_Test.cs index da5ff311b..59b7318fe 100644 --- a/Robust.UnitTesting/Shared/Map/GridCollision_Test.cs +++ b/Robust.UnitTesting/Shared/Map/GridCollision_Test.cs @@ -33,7 +33,7 @@ namespace Robust.UnitTesting.Shared.Map await server.WaitPost(() => { - mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out mapId); gridId1 = mapManager.CreateGridEntity(mapId); gridId2 = mapManager.CreateGridEntity(mapId); gridEnt1 = gridId1.Value.Owner; diff --git a/Robust.UnitTesting/Shared/Map/GridContraction_Test.cs b/Robust.UnitTesting/Shared/Map/GridContraction_Test.cs index 0fcb868db..3d1d348d4 100644 --- a/Robust.UnitTesting/Shared/Map/GridContraction_Test.cs +++ b/Robust.UnitTesting/Shared/Map/GridContraction_Test.cs @@ -21,7 +21,7 @@ namespace Robust.UnitTesting.Shared.Map await server.WaitAssertion(() => { - var mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); var gridEntity = grid.Owner; @@ -59,7 +59,7 @@ namespace Robust.UnitTesting.Shared.Map await server.WaitAssertion(() => { - var mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); for (var i = 0; i < 10; i++) diff --git a/Robust.UnitTesting/Shared/Map/GridFixtures_Tests.cs b/Robust.UnitTesting/Shared/Map/GridFixtures_Tests.cs index fa66557e5..cb27151cb 100644 --- a/Robust.UnitTesting/Shared/Map/GridFixtures_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/GridFixtures_Tests.cs @@ -30,7 +30,7 @@ namespace Robust.UnitTesting.Shared.Map await server.WaitAssertion(() => { - var mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); // Should be nothing if grid empty diff --git a/Robust.UnitTesting/Shared/Map/GridMerge_Tests.cs b/Robust.UnitTesting/Shared/Map/GridMerge_Tests.cs index 0e46950fd..903452834 100644 --- a/Robust.UnitTesting/Shared/Map/GridMerge_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/GridMerge_Tests.cs @@ -45,7 +45,7 @@ public sealed class GridMerge_Tests var mapSystem = entMan.System(); var gridFixtures = entMan.System(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid1 = mapManager.CreateGridEntity(mapId); var grid2 = mapManager.CreateGridEntity(mapId); var tiles = new List<(Vector2i, Tile)>(); diff --git a/Robust.UnitTesting/Shared/Map/GridRotation_Tests.cs b/Robust.UnitTesting/Shared/Map/GridRotation_Tests.cs index 958329d96..ed8fb7dc7 100644 --- a/Robust.UnitTesting/Shared/Map/GridRotation_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/GridRotation_Tests.cs @@ -28,7 +28,7 @@ namespace Robust.UnitTesting.Shared.Map await server.WaitAssertion(() => { - var mapId = mapMan.CreateMap(); + entMan.System().CreateMap(out var mapId); var grid = mapMan.CreateGridEntity(mapId); var gridEnt = grid.Owner; var coordinates = new EntityCoordinates(gridEnt, new Vector2(10, 0)); @@ -67,7 +67,7 @@ namespace Robust.UnitTesting.Shared.Map await server.WaitAssertion(() => { - var mapId = mapMan.CreateMap(); + entMan.System().CreateMap(out var mapId); var grid = mapMan.CreateGridEntity(mapId); var gridEnt = grid.Owner; diff --git a/Robust.UnitTesting/Shared/Map/GridSplit_Tests.cs b/Robust.UnitTesting/Shared/Map/GridSplit_Tests.cs index e5768eb1b..3439f45fd 100644 --- a/Robust.UnitTesting/Shared/Map/GridSplit_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/GridSplit_Tests.cs @@ -34,7 +34,7 @@ public sealed class GridSplit_Tests var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var gridEnt = mapManager.CreateGridEntity(mapId); var grid = gridEnt.Comp; grid.CanSplit = false; @@ -62,7 +62,7 @@ public sealed class GridSplit_Tests var sim = GetSim(); var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var gridEnt = mapManager.CreateGridEntity(mapId); for (var x = 0; x < 3; x++) @@ -84,7 +84,7 @@ public sealed class GridSplit_Tests var sim = GetSim(); var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var gridEnt = mapManager.CreateGridEntity(mapId); for (var x = 0; x < 3; x++) @@ -115,7 +115,7 @@ public sealed class GridSplit_Tests var sim = GetSim(); var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var gridEnt = mapManager.CreateGridEntity(mapId); for (var x = 0; x < 3; x++) @@ -143,7 +143,7 @@ public sealed class GridSplit_Tests var entManager = sim.Resolve(); var mapManager = sim.Resolve(); var mapSystem = sim.Resolve().System(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var gridEnt = mapManager.CreateGridEntity(mapId); var grid = gridEnt.Comp; diff --git a/Robust.UnitTesting/Shared/Map/MapGridMap_Tests.cs b/Robust.UnitTesting/Shared/Map/MapGridMap_Tests.cs index 5ebd9cc62..9c7743d51 100644 --- a/Robust.UnitTesting/Shared/Map/MapGridMap_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/MapGridMap_Tests.cs @@ -22,7 +22,7 @@ public sealed class MapGridMap_Tests var entManager = sim.Resolve(); var mapManager = sim.Resolve(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; Assert.That(!mapManager.FindGridsIntersecting(mapId, Box2.UnitCentered).Any()); entManager.AddComponent(mapManager.GetMapEntityId(mapId)); @@ -40,7 +40,7 @@ public sealed class MapGridMap_Tests var entManager = sim.Resolve(); var mapManager = sim.Resolve(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; mapManager.CreateGridEntity(mapId); Assert.DoesNotThrow(() => diff --git a/Robust.UnitTesting/Shared/Map/MapGrid_Tests.cs b/Robust.UnitTesting/Shared/Map/MapGrid_Tests.cs index 3f2e20ba0..e5233cb7c 100644 --- a/Robust.UnitTesting/Shared/Map/MapGrid_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/MapGrid_Tests.cs @@ -31,7 +31,7 @@ namespace Robust.UnitTesting.Shared.Map { var sim = SimulationFactory(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); grid.SetTile(new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1)); @@ -52,7 +52,7 @@ namespace Robust.UnitTesting.Shared.Map var sim = SimulationFactory(); var entMan = sim.Resolve(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); var gridXform = entMan.GetComponent(grid.Owner); gridXform.WorldPosition = new Vector2(3, 5); @@ -78,7 +78,7 @@ namespace Robust.UnitTesting.Shared.Map var sim = SimulationFactory(); var entMan = sim.Resolve(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); var gridXform = entMan.GetComponent(grid.Owner); @@ -103,7 +103,7 @@ namespace Robust.UnitTesting.Shared.Map { var sim = SimulationFactory(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); var result = grid.GridTileToChunkIndices(new Vector2i(-9, -1)); @@ -119,7 +119,7 @@ namespace Robust.UnitTesting.Shared.Map { var sim = SimulationFactory(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); var result = grid.GridTileToLocal(new Vector2i(0, 0)).Position; @@ -133,7 +133,7 @@ namespace Robust.UnitTesting.Shared.Map { var sim = SimulationFactory(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); var foundTile = grid.TryGetTileRef(new Vector2i(-9, -1), out var tileRef); @@ -148,7 +148,7 @@ namespace Robust.UnitTesting.Shared.Map { var sim = SimulationFactory(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); grid.SetTile(new Vector2i(-9, -1), new Tile(1, (TileRenderFlag)1, 1)); @@ -166,7 +166,7 @@ namespace Robust.UnitTesting.Shared.Map { var sim = SimulationFactory(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); grid.SetTile(new Vector2i(19, 23), new Tile(1)); @@ -181,7 +181,7 @@ namespace Robust.UnitTesting.Shared.Map { var sim = SimulationFactory(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapMan.CreateGrid(mapId, 8); grid.SetTile(new Vector2i(19, 23), new Tile(1)); diff --git a/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs b/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs index 16ba20606..218df5584 100644 --- a/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs @@ -28,8 +28,7 @@ namespace Robust.UnitTesting.Shared.Map var sim = SimulationFactory(); var mapMan = sim.Resolve(); - var mapID = new MapId(11); - mapMan.CreateMap(mapID); + var mapID = sim.CreateMap().MapId; mapMan.Restart(); @@ -46,8 +45,7 @@ namespace Robust.UnitTesting.Shared.Map var mapMan = sim.Resolve(); var entMan = sim.Resolve(); - var mapID = new MapId(11); - mapMan.CreateMap(mapID); + var mapID = sim.CreateMap().MapId; var grid = mapMan.CreateGridEntity(mapID); mapMan.Restart(); @@ -69,60 +67,13 @@ namespace Robust.UnitTesting.Shared.Map Assert.That(entMan.Deleted(oldEntity), Is.True); } - /// - /// When using SetMapEntity, the existing entities on the map are removed, and the new map entity gets a MapComponent. - /// - [Test] - public void SetMapEntity_WithExistingEntity_ExistingEntityDeleted() - { - // Arrange - var sim = SimulationFactory(); - var entMan = sim.Resolve(); - var mapMan = sim.Resolve(); - - var mapID = new MapId(11); - - mapMan.CreateMap(new MapId(7)); - mapMan.CreateMap(mapID); - var oldMapEntity = mapMan.GetMapEntityId(mapID); - var newMapEntity = entMan.CreateEntityUninitialized(null, new MapCoordinates(Vector2.Zero, new MapId(7))); - - // Act - mapMan.SetMapEntity(mapID, newMapEntity); - - // Assert - Assert.That(entMan.Deleted(oldMapEntity)); - Assert.That(entMan.HasComponent(newMapEntity)); - - var mapComp = entMan.GetComponent(newMapEntity); - Assert.That(mapComp.MapId == mapID); - } - - /// - /// After creating a new map entity for nullspace, you can spawn entities into nullspace like any other map. - /// - [Test] - public void SpawnEntityAt_IntoNullspace_Success() - { - // Arrange - var sim = SimulationFactory(); - var entMan = sim.Resolve(); - - // Act - var newEntity = entMan.SpawnEntity(null, MapCoordinates.Nullspace); - - // Assert - Assert.That(entMan.GetComponent(newEntity).MapID, Is.EqualTo(MapId.Nullspace)); - } - [Test] public void Restart_MapEntity_IsRemoved() { var sim = SimulationFactory(); var entMan = sim.Resolve(); var mapMan = sim.Resolve(); - var map = mapMan.CreateMap(); - var entity = mapMan.GetMapEntityId(map); + 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.UnitTesting/Shared/Map/MapPauseTests.cs b/Robust.UnitTesting/Shared/Map/MapPauseTests.cs index 7ece14055..0f4fdbc14 100644 --- a/Robust.UnitTesting/Shared/Map/MapPauseTests.cs +++ b/Robust.UnitTesting/Shared/Map/MapPauseTests.cs @@ -31,10 +31,9 @@ internal sealed class MapPauseTests var mapMan = sim.Resolve(); // arrange - var mapId = mapMan.CreateMap(); - mapMan.SetMapPaused(mapId, true); - - entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); + var mapId = sim.CreateMap().Uid; + entMan.System().SetPaused(mapId, true); + entMan.SpawnEntity(null, new EntityCoordinates(mapId, default)); var query = entMan.EntityQuery(false).ToList(); @@ -53,10 +52,9 @@ internal sealed class MapPauseTests var mapMan = sim.Resolve(); // arrange - var mapId = mapMan.CreateMap(); - mapMan.SetMapPaused(mapId, false); - - var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); + var mapId = sim.CreateMap().Uid; + entMan.System().SetPaused(mapId, false); + entMan.SpawnEntity(null, new EntityCoordinates(mapId, default)); var query = entMan.EntityQuery(false).ToList(); @@ -75,10 +73,9 @@ internal sealed class MapPauseTests var mapMan = sim.Resolve(); // arrange - var mapId = mapMan.CreateMap(); - mapMan.SetMapPaused(mapId, true); - - entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); + var mapId = sim.CreateMap().Uid; + entMan.System().SetPaused(mapId, true); + entMan.SpawnEntity(null, new EntityCoordinates(mapId, default)); var query = entMan.EntityQuery(true).ToList(); @@ -97,10 +94,9 @@ internal sealed class MapPauseTests var mapMan = sim.Resolve(); // arrange - var mapId = mapMan.CreateMap(); - mapMan.SetMapPaused(mapId, true); - - var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); + var mapId = sim.CreateMap().Uid; + entMan.System().SetPaused(mapId, true); + var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(mapId, default)); var metaData = entMan.GetComponent(newEnt); Assert.That(metaData.EntityPaused, Is.True); @@ -117,10 +113,9 @@ internal sealed class MapPauseTests var mapMan = sim.Resolve(); // arrange - var mapId = mapMan.CreateMap(); - mapMan.SetMapPaused(mapId, false); - - var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); + var mapId = sim.CreateMap().Uid; + entMan.System().SetPaused(mapId, false); + var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(mapId, default)); var metaData = entMan.GetComponent(newEnt); Assert.That(metaData.EntityPaused, Is.False); @@ -137,8 +132,8 @@ internal sealed class MapPauseTests var mapMan = sim.Resolve(); // arrange - var mapId = mapMan.CreateMap(); - mapMan.SetMapPaused(mapId, true); + var mapId = sim.CreateMap().MapId; + entMan.System().SetPaused(mapId, true); // act var newGrid = mapMan.CreateGridEntity(mapId); @@ -160,17 +155,16 @@ internal sealed class MapPauseTests var mapMan = sim.Resolve(); // arrange - var map1 = mapMan.CreateMap(); - mapMan.SetMapPaused(map1, true); - - var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, map1)); + var map1 = sim.CreateMap().Uid; + entMan.System().SetPaused(map1, true); + var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(map1, default)); var xform = entMan.GetComponent(newEnt); - var map2 = mapMan.CreateMap(); - mapMan.SetMapPaused(map2, false); + var map2 = sim.CreateMap().Uid; + entMan.System().SetPaused(map2, false); // Act - entMan.EntitySysManager.GetEntitySystem().SetParent(xform.Owner, mapMan.GetMapEntityId(map2)); + entMan.EntitySysManager.GetEntitySystem().SetParent(xform.Owner, map2); var metaData = entMan.GetComponent(newEnt); Assert.That(metaData.EntityPaused, Is.False); @@ -188,17 +182,16 @@ internal sealed class MapPauseTests var mapMan = sim.Resolve(); // arrange - var map1 = mapMan.CreateMap(); - mapMan.SetMapPaused(map1, false); - - var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, map1)); + var map1 = sim.CreateMap().Uid; + entMan.System().SetPaused(map1, false); + var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(map1, default)); var xform = entMan.GetComponent(newEnt); - var map2 = mapMan.CreateMap(); - mapMan.SetMapPaused(map2, true); + var map2 = sim.CreateMap().Uid; + entMan.System().SetPaused(map2, true); // Act - entMan.EntitySysManager.GetEntitySystem().SetParent(xform.Owner, mapMan.GetMapEntityId(map2)); + entMan.EntitySysManager.GetEntitySystem().SetParent(xform.Owner, map2); var metaData = entMan.GetComponent(newEnt); Assert.That(metaData.EntityPaused, Is.True); @@ -214,11 +207,11 @@ internal sealed class MapPauseTests var entMan = sim.Resolve(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); - mapMan.SetMapPaused(mapId, true); - var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); + var mapId = sim.CreateMap().Uid; + entMan.System().SetPaused(mapId, true); + var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(mapId, default)); - mapMan.SetMapPaused(mapId, false); + entMan.System().SetPaused(mapId, false); var metaData = entMan.GetComponent(newEnt); Assert.That(metaData.EntityPaused, Is.False); @@ -234,75 +227,13 @@ internal sealed class MapPauseTests var entMan = sim.Resolve(); var mapMan = sim.Resolve(); - var mapId = mapMan.CreateMap(); - mapMan.SetMapPaused(mapId, false); - var newEnt = entMan.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); + var mapId = sim.CreateMap().Uid; + entMan.System().SetPaused(mapId, false); + var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(mapId, default)); - mapMan.SetMapPaused(mapId, true); + entMan.System().SetPaused(mapId, true); var metaData = entMan.GetComponent(newEnt); Assert.That(metaData.EntityPaused, Is.True); } - - /// - /// An unallocated MapId is always unpaused. - /// - [Test] - public void UnallocatedMap_IsUnPaused() - { - var sim = SimulationFactory(); - var entMan = sim.Resolve(); - var mapMan = (IMapManagerInternal)sim.Resolve(); - - // some random unallocated MapId - var paused = mapMan.IsMapPaused(new MapId(12)); - - Assert.That(paused, Is.False); - } - - /// - /// Nullspace is always unpaused, and setting it is a no-op. - /// - [Test] - public void Nullspace_Pause_IsUnPaused() - { - var sim = SimulationFactory(); - var entMan = sim.Resolve(); - var mapMan = (IMapManagerInternal)sim.Resolve(); - - mapMan.SetMapPaused(MapId.Nullspace, true); - - var paused = mapMan.IsMapPaused(MapId.Nullspace); - Assert.That(paused, Is.False); - } - - /// - /// An allocated MapId without an allocated entity (Nullspace) is always unpaused. - /// - [Test] - public void Nullspace_IsUnPaused() - { - var sim = SimulationFactory(); - var entMan = sim.Resolve(); - var mapMan = (IMapManagerInternal)sim.Resolve(); - - var paused = mapMan.IsMapPaused(MapId.Nullspace); - - Assert.That(paused, Is.False); - } - - /// - /// A freed MapId is always unpaused. - /// - [Test] - public void Unpaused_Freed_IsUnPaused() - { - var sim = SimulationFactory(); - var entMan = sim.Resolve(); - var mapMan = (IMapManagerInternal)sim.Resolve(); - - var paused = mapMan.IsMapPaused(MapId.Nullspace); - - Assert.That(paused, Is.False); - } } diff --git a/Robust.UnitTesting/Shared/Map/SingleTileRemoveTest.cs b/Robust.UnitTesting/Shared/Map/SingleTileRemoveTest.cs index 5ca7704eb..0e0db47d1 100644 --- a/Robust.UnitTesting/Shared/Map/SingleTileRemoveTest.cs +++ b/Robust.UnitTesting/Shared/Map/SingleTileRemoveTest.cs @@ -75,9 +75,7 @@ public sealed class GridDeleteSingleTileRemoveTestTest : RobustIntegrationTest var sys = sEntMan.System(); await server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - sMap = mapMan.GetMapEntityId(mapId); - + sMap = sys.CreateMap(out var mapId); var comp = mapMan.CreateGridEntity(mapId); grid = (comp.Owner, comp); sys.SetTile(grid, grid, new Vector2i(0, 0), new Tile(1, (TileRenderFlag)1, 1)); diff --git a/Robust.UnitTesting/Shared/Physics/BroadphaseNetworkingTest.cs b/Robust.UnitTesting/Shared/Physics/BroadphaseNetworkingTest.cs index e3a33cc63..b8d831810 100644 --- a/Robust.UnitTesting/Shared/Physics/BroadphaseNetworkingTest.cs +++ b/Robust.UnitTesting/Shared/Physics/BroadphaseNetworkingTest.cs @@ -60,8 +60,7 @@ public sealed class BroadphaseNetworkingTest : RobustIntegrationTest EntityUid map1 = default; await server.WaitPost(() => { - var mapId = mapMan.CreateMap(); - map1 = mapMan.GetMapEntityId(mapId); + map1 = sEntMan.System().CreateMap(out var mapId); var gridEnt = mapMan.CreateGridEntity(mapId); gridEnt.Comp.SetTile(Vector2i.Zero, new Tile(1)); grid1 = gridEnt.Owner; @@ -132,8 +131,7 @@ public sealed class BroadphaseNetworkingTest : RobustIntegrationTest await server.WaitPost(() => { // Create grid - var mapId = mapMan.CreateMap(); - map2 = mapMan.GetMapEntityId(mapId); + map2 = sEntMan.System().CreateMap(out var mapId); var gridEnt = mapMan.CreateGridEntity(mapId); gridEnt.Comp.SetTile(Vector2i.Zero, new Tile(1)); grid2 = gridEnt.Owner; diff --git a/Robust.UnitTesting/Shared/Physics/Broadphase_Test.cs b/Robust.UnitTesting/Shared/Physics/Broadphase_Test.cs index 5143efb8f..0f0118b08 100644 --- a/Robust.UnitTesting/Shared/Physics/Broadphase_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/Broadphase_Test.cs @@ -26,8 +26,7 @@ public sealed class Broadphase_Test var entManager = sim.Resolve(); var mapManager = sim.Resolve(); - var mapId = mapManager.CreateMap(); - var mapEnt = mapManager.GetMapEntityId(mapId); + var (mapEnt, mapId) = sim.CreateMap(); var grid = mapManager.CreateGridEntity(mapId); grid.Comp.SetTile(Vector2i.Zero, new Tile(1)); @@ -61,8 +60,7 @@ public sealed class Broadphase_Test var fixturesSystem = entManager.EntitySysManager.GetEntitySystem(); var physicsSystem = entManager.EntitySysManager.GetEntitySystem(); - var mapId = mapManager.CreateMap(); - var mapEnt = mapManager.GetMapEntityId(mapId); + var (mapEnt, mapId) = sim.CreateMap(); var grid = mapManager.CreateGridEntity(mapId); var gridUid = grid.Owner; @@ -110,8 +108,8 @@ public sealed class Broadphase_Test var entManager = sim.Resolve(); var mapManager = sim.Resolve(); - var mapId1 = mapManager.CreateMap(); - var mapId2 = mapManager.CreateMap(); + var mapId1 = sim.CreateMap().MapId; + var mapId2 = sim.CreateMap().MapId; var grid = mapManager.CreateGridEntity(mapId1); var xform = entManager.GetComponent(grid); @@ -143,7 +141,7 @@ public sealed class Broadphase_Test var physicsSystem = system.GetEntitySystem(); var lookup = system.GetEntitySystem(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapManager.CreateGridEntity(mapId); grid.Comp.SetTile(Vector2i.Zero, new Tile(1)); @@ -195,10 +193,8 @@ public sealed class Broadphase_Test var fixtures = system.GetEntitySystem(); // setup maps - var mapAId = mapManager.CreateMap(); - var mapA = mapManager.GetMapEntityId(mapAId); - var mapBId = mapManager.CreateMap(); - var mapB = mapManager.GetMapEntityId(mapBId); + var (mapA, mapAId) = sim.CreateMap(); + var (mapB, mapBId) = sim.CreateMap(); // setup grids var gridAComp = mapManager.CreateGridEntity(mapAId); @@ -323,10 +319,8 @@ public sealed class Broadphase_Test var physSystem = system.GetEntitySystem(); var lookup = system.GetEntitySystem(); var fixtures = system.GetEntitySystem(); - var mapManager = sim.Resolve(); + var (mapUid, mapId) = sim.CreateMap(); - var mapId = mapManager.CreateMap(); - var mapUid = mapManager.GetMapEntityId(mapId); var mapBroadphase = entManager.GetComponent(mapUid); Assert.That(entManager.EntityQuery(true).Count(), Is.EqualTo(1)); diff --git a/Robust.UnitTesting/Shared/Physics/CollisionWake_Test.cs b/Robust.UnitTesting/Shared/Physics/CollisionWake_Test.cs index d2d7aa246..ed15497a3 100644 --- a/Robust.UnitTesting/Shared/Physics/CollisionWake_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/CollisionWake_Test.cs @@ -51,7 +51,7 @@ namespace Robust.UnitTesting.Shared.Physics await server.WaitPost(() => { - mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out mapId); grid = mapManager.CreateGridEntity(mapId); grid.Comp.SetTile(Vector2i.Zero, new Tile(1)); diff --git a/Robust.UnitTesting/Shared/Physics/Collision_Test.cs b/Robust.UnitTesting/Shared/Physics/Collision_Test.cs index 08bc6b807..7a5dc3c08 100644 --- a/Robust.UnitTesting/Shared/Physics/Collision_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/Collision_Test.cs @@ -102,8 +102,8 @@ public sealed class Collision_Test var fixtures = entManager.System(); var physics = entManager.System(); var xformSystem = entManager.System(); - var mapId = mapManager.CreateMap(); - var mapId2 = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; + var mapId2 = sim.CreateMap().MapId; var ent1 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); var ent2 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); diff --git a/Robust.UnitTesting/Shared/Physics/Fixtures_Test.cs b/Robust.UnitTesting/Shared/Physics/Fixtures_Test.cs index 443830fcd..9c25a17c5 100644 --- a/Robust.UnitTesting/Shared/Physics/Fixtures_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/Fixtures_Test.cs @@ -24,7 +24,7 @@ public sealed class Fixtures_Test var sysManager = sim.Resolve(); var fixturesSystem = sysManager.GetEntitySystem(); var physicsSystem = sysManager.GetEntitySystem(); - var map = mapManager.CreateMap(); + var map = sim.CreateMap().MapId; var ent = sim.SpawnEntity(null, new MapCoordinates(Vector2.Zero, map)); var body = entManager.AddComponent(ent); diff --git a/Robust.UnitTesting/Shared/Physics/GridDeletion_Test.cs b/Robust.UnitTesting/Shared/Physics/GridDeletion_Test.cs index 27d3121c6..5bc66d892 100644 --- a/Robust.UnitTesting/Shared/Physics/GridDeletion_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/GridDeletion_Test.cs @@ -36,7 +36,7 @@ public sealed class GridDeletion_Test : RobustIntegrationTest await server.WaitAssertion(() => { - mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out mapId); grid = mapManager.CreateGridEntity(mapId); physics = entManager.GetComponent(grid); diff --git a/Robust.UnitTesting/Shared/Physics/GridMovement_Test.cs b/Robust.UnitTesting/Shared/Physics/GridMovement_Test.cs index d8ccf5896..62d23b004 100644 --- a/Robust.UnitTesting/Shared/Physics/GridMovement_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/GridMovement_Test.cs @@ -31,7 +31,7 @@ public sealed class GridMovement_Test : RobustIntegrationTest await server.WaitAssertion(() => { - var mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); // Setup 1 body on grid, 1 body off grid, and assert that it's all gucci. diff --git a/Robust.UnitTesting/Shared/Physics/JointDeletion_Test.cs b/Robust.UnitTesting/Shared/Physics/JointDeletion_Test.cs index 5a3833a4e..099ad2569 100644 --- a/Robust.UnitTesting/Shared/Physics/JointDeletion_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/JointDeletion_Test.cs @@ -39,7 +39,7 @@ public sealed class JointDeletion_Test : RobustIntegrationTest await server.WaitPost(() => { - mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out mapId); ent1 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); ent2 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.One, mapId)); diff --git a/Robust.UnitTesting/Shared/Physics/Joints_Test.cs b/Robust.UnitTesting/Shared/Physics/Joints_Test.cs index 7c106b851..cd68b31bf 100644 --- a/Robust.UnitTesting/Shared/Physics/Joints_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/Joints_Test.cs @@ -27,7 +27,7 @@ public sealed class Joints_Test var mapManager = sim.Resolve(); var jointSystem = entManager.System(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var uidA = entManager.SpawnEntity(null, new MapCoordinates(0f, 0f, mapId)); var uidB = entManager.SpawnEntity(null, new MapCoordinates(0f, 0f, mapId)); @@ -71,7 +71,7 @@ public sealed class Joints_Test var broadphaseSystem = entManager.EntitySysManager.GetEntitySystem(); var physicsSystem = server.Resolve().GetEntitySystem(); - var mapId = mapManager.CreateMap(); + var mapId = server.CreateMap().MapId; var ent1 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); var ent2 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); diff --git a/Robust.UnitTesting/Shared/Physics/MapVelocity_Test.cs b/Robust.UnitTesting/Shared/Physics/MapVelocity_Test.cs index 84633036c..a843a7ac0 100644 --- a/Robust.UnitTesting/Shared/Physics/MapVelocity_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/MapVelocity_Test.cs @@ -43,7 +43,7 @@ namespace Robust.UnitTesting.Shared.Physics await server.WaitAssertion(() => { - var mapId = mapManager.CreateMap(); + entityManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); var grid2 = mapManager.CreateGridEntity(mapId); var gridUidA = grid.Owner; @@ -115,7 +115,7 @@ namespace Robust.UnitTesting.Shared.Physics await server.WaitAssertion(() => { - var mapId = mapManager.CreateMap(); + entityManager.System().CreateMap(out var mapId); var grid = mapManager.CreateGridEntity(mapId); var gridUid = grid.Owner; diff --git a/Robust.UnitTesting/Shared/Physics/PhysicsComponent_Test.cs b/Robust.UnitTesting/Shared/Physics/PhysicsComponent_Test.cs index afe7b769c..291329efe 100644 --- a/Robust.UnitTesting/Shared/Physics/PhysicsComponent_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/PhysicsComponent_Test.cs @@ -32,7 +32,7 @@ namespace Robust.UnitTesting.Shared.Physics await server.WaitAssertion(() => { - var mapId = mapManager.CreateMap(); + entManager.System().CreateMap(out var mapId); var boxEnt = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId)); var box = entManager.AddComponent(boxEnt); var poly = new PolygonShape(); diff --git a/Robust.UnitTesting/Shared/Physics/PhysicsMap_Test.cs b/Robust.UnitTesting/Shared/Physics/PhysicsMap_Test.cs index def98fbb7..5f3bbbb35 100644 --- a/Robust.UnitTesting/Shared/Physics/PhysicsMap_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/PhysicsMap_Test.cs @@ -29,8 +29,8 @@ public sealed class PhysicsMap_Test var fixtureSystem = system.GetEntitySystem(); var xformSystem = system.GetEntitySystem(); - var mapId = mapManager.CreateMap(); - var mapId2 = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; + var mapId2 = sim.CreateMap().MapId; var mapUid = mapManager.GetMapEntityId(mapId); var mapUid2 = mapManager.GetMapEntityId(mapId2); diff --git a/Robust.UnitTesting/Shared/Physics/RecursiveUpdateTest.cs b/Robust.UnitTesting/Shared/Physics/RecursiveUpdateTest.cs index 484ad2210..8dcccbe38 100644 --- a/Robust.UnitTesting/Shared/Physics/RecursiveUpdateTest.cs +++ b/Robust.UnitTesting/Shared/Physics/RecursiveUpdateTest.cs @@ -27,7 +27,7 @@ public sealed class RecursiveUpdateTest var xforms = entManager.System(); var containers = entManager.System(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var grid = mapManager.CreateGridEntity(mapId); var guid = grid.Owner; grid.Comp.SetTile(Vector2i.Zero, new Tile(1)); @@ -166,7 +166,7 @@ public sealed class RecursiveUpdateTest var transforms = entManager.EntitySysManager.GetEntitySystem(); var lookup = entManager.EntitySysManager.GetEntitySystem(); - var mapId = mapManager.CreateMap(); + var mapId = sim.CreateMap().MapId; var map = mapManager.GetMapEntityId(mapId); var mapBroadphase = entManager.GetComponent(map); diff --git a/Robust.UnitTesting/Shared/Physics/Stack_Test.cs b/Robust.UnitTesting/Shared/Physics/Stack_Test.cs index fb843d500..9412df334 100644 --- a/Robust.UnitTesting/Shared/Physics/Stack_Test.cs +++ b/Robust.UnitTesting/Shared/Physics/Stack_Test.cs @@ -66,9 +66,7 @@ public sealed class PhysicsTestBedTest : RobustIntegrationTest await server.WaitPost(() => { - mapId = mapManager.CreateMap(); - - var mapUid = mapManager.GetMapEntityId(mapId); + var mapUid = entityManager.System().CreateMap(out mapId); gravSystem.SetGravity(mapUid, new Vector2(0f, -9.8f)); var groundUid = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); @@ -173,8 +171,7 @@ public sealed class PhysicsTestBedTest : RobustIntegrationTest await server.WaitPost(() => { - mapId = mapManager.CreateMap(); - var mapUid = mapManager.GetMapEntityId(mapId); + var mapUid = entityManager.System().CreateMap(out mapId); gravSystem.SetGravity(mapUid, new Vector2(0f, -9.8f)); var groundUid = entityManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId)); diff --git a/Robust.UnitTesting/Shared/Prototypes/HotReloadTest.cs b/Robust.UnitTesting/Shared/Prototypes/HotReloadTest.cs index 62bbc6926..387f891a2 100644 --- a/Robust.UnitTesting/Shared/Prototypes/HotReloadTest.cs +++ b/Robust.UnitTesting/Shared/Prototypes/HotReloadTest.cs @@ -55,7 +55,7 @@ namespace Robust.UnitTesting.Shared.Prototypes [Test] public void TestHotReload() { - var id = IoCManager.Resolve().CreateMap(); + IoCManager.Resolve().System().CreateMap(out var id); var entity = _entities.SpawnEntity(DummyId, new MapCoordinates(default, id)); var entityComponent = IoCManager.Resolve().GetComponent(entity); diff --git a/Robust.UnitTesting/Shared/Serialization/InheritanceSerializationTest.cs b/Robust.UnitTesting/Shared/Serialization/InheritanceSerializationTest.cs index 3fc8251ac..d64b083a1 100644 --- a/Robust.UnitTesting/Shared/Serialization/InheritanceSerializationTest.cs +++ b/Robust.UnitTesting/Shared/Serialization/InheritanceSerializationTest.cs @@ -59,12 +59,7 @@ namespace Robust.UnitTesting.Shared.Serialization prototypeManager.ResolveResults(); var entityManager = IoCManager.Resolve(); - - var mapManager = IoCManager.Resolve(); - - var mapId = new MapId(1); - - mapManager.CreateMap(mapId); + entityManager.System().CreateMap(out var mapId); var coordinates = new MapCoordinates(0, 0, mapId); diff --git a/Robust.UnitTesting/Shared/Spawning/EntitySpawnHelpersTest.cs b/Robust.UnitTesting/Shared/Spawning/EntitySpawnHelpersTest.cs index c1cd947d7..f2f3d952d 100644 --- a/Robust.UnitTesting/Shared/Spawning/EntitySpawnHelpersTest.cs +++ b/Robust.UnitTesting/Shared/Spawning/EntitySpawnHelpersTest.cs @@ -49,8 +49,7 @@ public abstract partial class EntitySpawnHelpersTest : RobustIntegrationTest // Set up map and spawn several nested containers await Server.WaitPost(() => { - MapId = MapMan.CreateMap(); - Map = MapMan.GetMapEntityId(MapId); + Map = Server.System().CreateMap(out MapId); Parent = EntMan.SpawnEntity(null, new EntityCoordinates(Map, new(1,2))); ChildA = EntMan.SpawnEntity(null, new EntityCoordinates(Map, default)); ChildB = EntMan.SpawnEntity(null, new EntityCoordinates(Map, default)); diff --git a/Robust.UnitTesting/Shared/Spawning/SpawnNextToOrDropTest.cs b/Robust.UnitTesting/Shared/Spawning/SpawnNextToOrDropTest.cs index fa1cd9f4b..67c3d3fe7 100644 --- a/Robust.UnitTesting/Shared/Spawning/SpawnNextToOrDropTest.cs +++ b/Robust.UnitTesting/Shared/Spawning/SpawnNextToOrDropTest.cs @@ -107,6 +107,20 @@ public sealed class SpawnNextToOrDropTest : EntitySpawnHelpersTest Assert.That(xform.GridUid, Is.Null); }); + // Spawning next to an entity on a pre-init map does not initialize the entity. + // Previously the intermediate step of spawning the entity into nullspace would cause it to get initialized. + await Server.WaitPost(() => + { + var preInitMap = EntMan.System().CreateMap(out var mapId, runMapInit: false); + var ent = EntMan.Spawn(null, new MapCoordinates(default, mapId)); + + Assert.That(EntMan.GetComponent(preInitMap).EntityLifeStage, Is.LessThan(EntityLifeStage.MapInitialized)); + Assert.That(EntMan.GetComponent(ent).EntityLifeStage, Is.LessThan(EntityLifeStage.MapInitialized)); + + var uid = EntMan.SpawnNextToOrDrop(null, ent); + Assert.That(EntMan.GetComponent(uid).EntityLifeStage, Is.LessThan(EntityLifeStage.MapInitialized)); + }); + await Server.WaitPost(() =>MapMan.DeleteMap(MapId)); Server.Dispose(); } diff --git a/Robust.UnitTesting/Shared/TransformTests/GridTraversalTest.cs b/Robust.UnitTesting/Shared/TransformTests/GridTraversalTest.cs index c14761e49..e9edf633c 100644 --- a/Robust.UnitTesting/Shared/TransformTests/GridTraversalTest.cs +++ b/Robust.UnitTesting/Shared/TransformTests/GridTraversalTest.cs @@ -28,9 +28,7 @@ public sealed class GridTraversalTest : RobustIntegrationTest Vector2 gridMapPos = default; await server.WaitPost(() => { - mapId = mapMan.CreateMap(); - map = mapMan.GetMapEntityId(mapId); - + map = sEntMan.System().CreateMap(out mapId); var gridComp = mapMan.CreateGridEntity(mapId); grid = gridComp.Owner; mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1));