diff --git a/Content.Client/Audio/AmbientSoundSystem.cs b/Content.Client/Audio/AmbientSoundSystem.cs index d66ee434a29d..d39073fa330c 100644 --- a/Content.Client/Audio/AmbientSoundSystem.cs +++ b/Content.Client/Audio/AmbientSoundSystem.cs @@ -28,6 +28,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem { [Dependency] private readonly AmbientSoundTreeSystem _treeSys = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly SharedTransformSystem _xformSystem = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; @@ -172,7 +173,7 @@ public override void Update(float frameTime) _targetTime = _gameTiming.CurTime+TimeSpan.FromSeconds(_cooldown); - var player = _playerManager.LocalPlayer?.ControlledEntity; + var player = _playerManager.LocalEntity; if (!EntityManager.TryGetComponent(player, out TransformComponent? xform)) { ClearSounds(); @@ -198,13 +199,13 @@ private readonly struct QueryState public readonly Dictionary> SourceDict = new(); public readonly Vector2 MapPos; public readonly TransformComponent Player; - public readonly EntityQuery Query; + public readonly SharedTransformSystem TransformSystem; - public QueryState(Vector2 mapPos, TransformComponent player, EntityQuery query) + public QueryState(Vector2 mapPos, TransformComponent player, SharedTransformSystem transformSystem) { MapPos = mapPos; Player = player; - Query = query; + TransformSystem = transformSystem; } } @@ -218,7 +219,7 @@ private static bool Callback( var delta = xform.ParentUid == state.Player.ParentUid ? xform.LocalPosition - state.Player.LocalPosition - : xform.WorldPosition - state.MapPos; + : state.TransformSystem.GetWorldPosition(xform) - state.MapPos; var range = delta.Length(); if (range >= ambientComp.Range) @@ -244,7 +245,7 @@ private void ProcessNearbyAmbience(TransformComponent playerXform) { var query = GetEntityQuery(); var metaQuery = GetEntityQuery(); - var mapPos = playerXform.MapPosition; + var mapPos = _xformSystem.GetMapCoordinates(playerXform); // Remove out-of-range ambiences foreach (var (comp, sound) in _playingSounds) @@ -258,9 +259,10 @@ private void ProcessNearbyAmbience(TransformComponent playerXform) xform.MapID == playerXform.MapID && !metaQuery.GetComponent(entity).EntityPaused) { + // TODO: This is just trydistance for coordinates. var distance = (xform.ParentUid == playerXform.ParentUid) ? xform.LocalPosition - playerXform.LocalPosition - : xform.WorldPosition - mapPos.Position; + : _xformSystem.GetWorldPosition(xform) - mapPos.Position; if (distance.LengthSquared() < comp.Range * comp.Range) continue; @@ -277,7 +279,7 @@ private void ProcessNearbyAmbience(TransformComponent playerXform) return; var pos = mapPos.Position; - var state = new QueryState(pos, playerXform, query); + var state = new QueryState(pos, playerXform, _xformSystem); var worldAabb = new Box2(pos - MaxAmbientVector, pos + MaxAmbientVector); _treeSys.QueryAabb(ref state, Callback, mapPos.MapId, worldAabb); diff --git a/Content.IntegrationTests/Tests/CargoTest.cs b/Content.IntegrationTests/Tests/CargoTest.cs index e49f2e996ba8..09f179cf4f5a 100644 --- a/Content.IntegrationTests/Tests/CargoTest.cs +++ b/Content.IntegrationTests/Tests/CargoTest.cs @@ -108,7 +108,7 @@ public async Task NoStaticPriceAndStackPrice() await server.WaitAssertion(() => { var mapId = testMap.MapId; - var grid = mapManager.CreateGrid(mapId); + var grid = mapManager.CreateGridEntity(mapId); var coord = new EntityCoordinates(grid.Owner, 0, 0); var protoIds = protoManager.EnumeratePrototypes() diff --git a/Content.IntegrationTests/Tests/EntityTest.cs b/Content.IntegrationTests/Tests/EntityTest.cs index 9f8823fd5e88..152eb725221b 100644 --- a/Content.IntegrationTests/Tests/EntityTest.cs +++ b/Content.IntegrationTests/Tests/EntityTest.cs @@ -31,6 +31,7 @@ public async Task SpawnAndDeleteAllEntitiesOnDifferentMaps() var entityMan = server.ResolveDependency(); var mapManager = server.ResolveDependency(); var prototypeMan = server.ResolveDependency(); + var mapSystem = entityMan.System(); await server.WaitPost(() => { @@ -41,12 +42,13 @@ await server.WaitPost(() => .Where(p => !p.Components.ContainsKey("MapGrid")) // This will smash stuff otherwise. .Select(p => p.ID) .ToList(); + foreach (var protoId in protoIds) { var mapId = mapManager.CreateMap(); - var grid = mapManager.CreateGrid(mapId); + var grid = mapManager.CreateGridEntity(mapId); // TODO: Fix this better in engine. - grid.SetTile(Vector2i.Zero, new Tile(1)); + mapSystem.SetTile(grid.Owner, grid.Comp, Vector2i.Zero, new Tile(1)); var coord = new EntityCoordinates(grid.Owner, 0, 0); entityMan.SpawnEntity(protoId, coord); } @@ -61,7 +63,9 @@ await server.WaitPost(() => { var query = entityMan.AllEntityQueryEnumerator(); while (query.MoveNext(out var uid, out var meta)) + { yield return (uid, meta); + } } var entityMetas = Query(entityMan).ToList(); @@ -113,8 +117,10 @@ await server.WaitPost(() => { var query = entityMan.AllEntityQueryEnumerator(); while (query.MoveNext(out var uid, out var meta)) + { yield return (uid, meta); - }; + } + } var entityMetas = Query(entityMan).ToList(); foreach (var (uid, meta) in entityMetas) @@ -163,11 +169,11 @@ await server.WaitPost(() => foreach (var protoId in protoIds) { var mapId = mapManager.CreateMap(); - var grid = mapManager.CreateGrid(mapId); + var grid = mapManager.CreateGridEntity(mapId); var ent = sEntMan.SpawnEntity(protoId, new EntityCoordinates(grid.Owner, 0.5f, 0.5f)); foreach (var (_, component) in sEntMan.GetNetComponents(ent)) { - sEntMan.Dirty(component); + sEntMan.Dirty(ent, component); } } }); @@ -185,7 +191,9 @@ await server.WaitPost(() => { var query = entityMan.AllEntityQueryEnumerator(); while (query.MoveNext(out var uid, out var meta)) + { yield return (uid, meta); + } } var entityMetas = Query(sEntMan).ToList(); @@ -351,9 +359,10 @@ public async Task AllComponentsOneToOneDeleteTest() var entityManager = server.ResolveDependency(); var componentFactory = server.ResolveDependency(); var tileDefinitionManager = server.ResolveDependency(); + var mapSystem = entityManager.System(); var logmill = server.ResolveDependency().GetSawmill("EntityTest"); - MapGridComponent grid = default; + Entity grid = default!; await server.WaitPost(() => { @@ -362,13 +371,13 @@ await server.WaitPost(() => mapManager.AddUninitializedMap(mapId); - grid = mapManager.CreateGrid(mapId); + grid = mapManager.CreateGridEntity(mapId); var tileDefinition = tileDefinitionManager["Plating"]; var tile = new Tile(tileDefinition.TileId); - var coordinates = grid.ToCoordinates(); + var coordinates = new EntityCoordinates(grid.Owner, Vector2.Zero); - grid.SetTile(coordinates, tile); + mapSystem.SetTile(grid.Owner, grid.Comp!, coordinates, tile); mapManager.DoMapInitialize(mapId); }); @@ -379,7 +388,7 @@ await server.WaitAssertion(() => { Assert.Multiple(() => { - var testLocation = grid.ToCoordinates(); + var testLocation = new EntityCoordinates(grid.Owner, Vector2.Zero); foreach (var type in componentFactory.AllRegisteredTypes) { @@ -404,7 +413,6 @@ await server.WaitAssertion(() => continue; } - component.Owner = entity; logmill.Debug($"Adding component: {name}"); Assert.DoesNotThrow(() => diff --git a/Content.IntegrationTests/Tests/Shuttle/DockTest.cs b/Content.IntegrationTests/Tests/Shuttle/DockTest.cs index 3404c9fbbbe8..b6fc273570a1 100644 --- a/Content.IntegrationTests/Tests/Shuttle/DockTest.cs +++ b/Content.IntegrationTests/Tests/Shuttle/DockTest.cs @@ -32,6 +32,7 @@ public async Task TestDockingConfig(Vector2 dock1Pos, Vector2 dock2Pos, Angle do var entManager = server.ResolveDependency(); var mapManager = server.ResolveDependency(); var dockingSystem = entManager.System(); + var mapSystem = entManager.System(); var xformSystem = entManager.System(); var mapId = map.MapId; @@ -39,8 +40,8 @@ public async Task TestDockingConfig(Vector2 dock1Pos, Vector2 dock2Pos, Angle do await server.WaitAssertion(() => { entManager.DeleteEntity(map.GridUid); - var grid1 = mapManager.CreateGrid(mapId); - var grid2 = mapManager.CreateGrid(mapId); + var grid1 = mapManager.CreateGridEntity(mapId); + var grid2 = mapManager.CreateGridEntity(mapId); var grid1Ent = grid1.Owner; var grid2Ent = grid2.Owner; var grid2Offset = new Vector2(50f, 50f); @@ -57,7 +58,7 @@ await server.WaitAssertion(() => new(new Vector2i(0, 2), new Tile(1)), }; - grid1.SetTiles(tiles1); + mapSystem.SetTiles(grid1.Owner, grid1.Comp, tiles1); var dock1 = entManager.SpawnEntity("AirlockShuttle", new EntityCoordinates(grid1Ent, dock1Pos)); var dock1Xform = entManager.GetComponent(dock1); dock1Xform.LocalRotation = dock1Angle; @@ -71,7 +72,7 @@ await server.WaitAssertion(() => new(new Vector2i(1, 2), new Tile(1)), }; - grid2.SetTiles(tiles2); + mapSystem.SetTiles(grid2.Owner, grid2.Comp, tiles2); var dock2 = entManager.SpawnEntity("AirlockShuttle", new EntityCoordinates(grid2Ent, dock2Pos)); var dock2Xform = entManager.GetComponent(dock2); dock2Xform.LocalRotation = dock2Angle; @@ -94,9 +95,7 @@ public async Task TestPlanetDock() var otherMap = await pair.CreateTestMap(); var entManager = server.ResolveDependency(); - var mapManager = server.ResolveDependency(); var dockingSystem = entManager.System(); - var xformSystem = entManager.System(); var mapSystem = entManager.System(); var mapGrid = entManager.AddComponent(map.MapUid); diff --git a/Content.IntegrationTests/Tests/ShuttleTest.cs b/Content.IntegrationTests/Tests/ShuttleTest.cs index 304366adbf86..fb786373a5af 100644 --- a/Content.IntegrationTests/Tests/ShuttleTest.cs +++ b/Content.IntegrationTests/Tests/ShuttleTest.cs @@ -29,7 +29,7 @@ public async Task Test() await server.WaitAssertion(() => { var mapId = mapMan.CreateMap(); - var grid = mapMan.CreateGrid(mapId); + var grid = mapMan.CreateGridEntity(mapId); gridEnt = grid.Owner; Assert.Multiple(() =>