Skip to content

Commit

Permalink
Fix some test warnings (space-wizards#24324)
Browse files Browse the repository at this point in the history
Extracted from smug's pr.
  • Loading branch information
metalgearsloth authored Jan 20, 2024
1 parent f10ecf4 commit 4a13dbe
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
18 changes: 10 additions & 8 deletions Content.Client/Audio/AmbientSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down Expand Up @@ -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();
Expand All @@ -198,13 +199,13 @@ private readonly struct QueryState
public readonly Dictionary<string, List<(float Importance, AmbientSoundComponent)>> SourceDict = new();
public readonly Vector2 MapPos;
public readonly TransformComponent Player;
public readonly EntityQuery<TransformComponent> Query;
public readonly SharedTransformSystem TransformSystem;

public QueryState(Vector2 mapPos, TransformComponent player, EntityQuery<TransformComponent> query)
public QueryState(Vector2 mapPos, TransformComponent player, SharedTransformSystem transformSystem)
{
MapPos = mapPos;
Player = player;
Query = query;
TransformSystem = transformSystem;
}
}

Expand All @@ -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)
Expand All @@ -244,7 +245,7 @@ private void ProcessNearbyAmbience(TransformComponent playerXform)
{
var query = GetEntityQuery<TransformComponent>();
var metaQuery = GetEntityQuery<MetaDataComponent>();
var mapPos = playerXform.MapPosition;
var mapPos = _xformSystem.GetMapCoordinates(playerXform);

// Remove out-of-range ambiences
foreach (var (comp, sound) in _playingSounds)
Expand All @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Content.IntegrationTests/Tests/CargoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityPrototype>()
Expand Down
30 changes: 19 additions & 11 deletions Content.IntegrationTests/Tests/EntityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public async Task SpawnAndDeleteAllEntitiesOnDifferentMaps()
var entityMan = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var prototypeMan = server.ResolveDependency<IPrototypeManager>();
var mapSystem = entityMan.System<SharedMapSystem>();

await server.WaitPost(() =>
{
Expand All @@ -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);
}
Expand All @@ -61,7 +63,9 @@ await server.WaitPost(() =>
{
var query = entityMan.AllEntityQueryEnumerator<TComp>();
while (query.MoveNext(out var uid, out var meta))
{
yield return (uid, meta);
}
}

var entityMetas = Query<MetaDataComponent>(entityMan).ToList();
Expand Down Expand Up @@ -113,8 +117,10 @@ await server.WaitPost(() =>
{
var query = entityMan.AllEntityQueryEnumerator<TComp>();
while (query.MoveNext(out var uid, out var meta))
{
yield return (uid, meta);
};
}
}

var entityMetas = Query<MetaDataComponent>(entityMan).ToList();
foreach (var (uid, meta) in entityMetas)
Expand Down Expand Up @@ -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);
}
}
});
Expand All @@ -185,7 +191,9 @@ await server.WaitPost(() =>
{
var query = entityMan.AllEntityQueryEnumerator<TComp>();
while (query.MoveNext(out var uid, out var meta))
{
yield return (uid, meta);
}
}

var entityMetas = Query<MetaDataComponent>(sEntMan).ToList();
Expand Down Expand Up @@ -351,9 +359,10 @@ public async Task AllComponentsOneToOneDeleteTest()
var entityManager = server.ResolveDependency<IEntityManager>();
var componentFactory = server.ResolveDependency<IComponentFactory>();
var tileDefinitionManager = server.ResolveDependency<ITileDefinitionManager>();
var mapSystem = entityManager.System<SharedMapSystem>();
var logmill = server.ResolveDependency<ILogManager>().GetSawmill("EntityTest");

MapGridComponent grid = default;
Entity<MapGridComponent> grid = default!;

await server.WaitPost(() =>
{
Expand All @@ -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);
});
Expand All @@ -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)
{
Expand All @@ -404,7 +413,6 @@ await server.WaitAssertion(() =>
continue;
}

component.Owner = entity;
logmill.Debug($"Adding component: {name}");

Assert.DoesNotThrow(() =>
Expand Down
11 changes: 5 additions & 6 deletions Content.IntegrationTests/Tests/Shuttle/DockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ public async Task TestDockingConfig(Vector2 dock1Pos, Vector2 dock2Pos, Angle do
var entManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var dockingSystem = entManager.System<DockingSystem>();
var mapSystem = entManager.System<SharedMapSystem>();
var xformSystem = entManager.System<SharedTransformSystem>();

var mapId = map.MapId;

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);
Expand All @@ -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<TransformComponent>(dock1);
dock1Xform.LocalRotation = dock1Angle;
Expand All @@ -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<TransformComponent>(dock2);
dock2Xform.LocalRotation = dock2Angle;
Expand All @@ -94,9 +95,7 @@ public async Task TestPlanetDock()
var otherMap = await pair.CreateTestMap();

var entManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var dockingSystem = entManager.System<DockingSystem>();
var xformSystem = entManager.System<SharedTransformSystem>();
var mapSystem = entManager.System<SharedMapSystem>();

var mapGrid = entManager.AddComponent<MapGridComponent>(map.MapUid);
Expand Down
2 changes: 1 addition & 1 deletion Content.IntegrationTests/Tests/ShuttleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
Expand Down

0 comments on commit 4a13dbe

Please sign in to comment.