Change HighPressureMovements to use GridTileLookup (#2025)
* Change spacewinds to use GridTileLookup * Add tile lookup tests Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
69
Content.IntegrationTests/Tests/GridTileLookupTest.cs
Normal file
69
Content.IntegrationTests/Tests/GridTileLookupTest.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Robust.Server.GameObjects.EntitySystems.TileLookup;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Map;
|
||||||
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
|
|
||||||
|
namespace Content.IntegrationTests.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class GridTileLookupTest : ContentIntegrationTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public async Task Test()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
|
||||||
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
||||||
|
var tileLookup = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<GridTileLookupSystem>();
|
||||||
|
var mapManager = server.ResolveDependency<IMapManager>();
|
||||||
|
var tileDefinitionManager = server.ResolveDependency<ITileDefinitionManager>();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
List<IEntity> entities;
|
||||||
|
var mapOne = mapManager.CreateMap();
|
||||||
|
var gridOne = mapManager.CreateGrid(mapOne);
|
||||||
|
|
||||||
|
var tileDefinition = tileDefinitionManager["underplating"];
|
||||||
|
var underplating = new Tile(tileDefinition.TileId);
|
||||||
|
gridOne.SetTile(new MapIndices(0, 0), underplating);
|
||||||
|
gridOne.SetTile(new MapIndices(-1, -1), underplating);
|
||||||
|
|
||||||
|
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(0, 0)).ToList();
|
||||||
|
Assert.That(entities.Count, Is.EqualTo(0));
|
||||||
|
|
||||||
|
// Space entity, check that nothing intersects it and that also it doesn't throw.
|
||||||
|
entityManager.SpawnEntity("HumanMob_Content", new MapCoordinates(Vector2.One * 1000, mapOne));
|
||||||
|
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(1000, 1000)).ToList();
|
||||||
|
Assert.That(entities.Count, Is.EqualTo(0));
|
||||||
|
|
||||||
|
var entityOne = entityManager.SpawnEntity("HumanMob_Content", new GridCoordinates(Vector2.Zero, gridOne));
|
||||||
|
entityManager.SpawnEntity("HumanMob_Content", new GridCoordinates(Vector2.One, gridOne));
|
||||||
|
|
||||||
|
var entityTiles = tileLookup.GetIndices(entityOne);
|
||||||
|
Assert.That(entityTiles.Count, Is.EqualTo(2));
|
||||||
|
|
||||||
|
entities = tileLookup.GetEntitiesIntersecting(entityOne).ToList();
|
||||||
|
// Includes station entity
|
||||||
|
Assert.That(entities.Count, Is.EqualTo(3));
|
||||||
|
|
||||||
|
// Both dummies should be in each corner of the 0,0 tile but only one dummy intersects -1,-1
|
||||||
|
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(-1, -1)).ToList();
|
||||||
|
Assert.That(entities.Count, Is.EqualTo(1));
|
||||||
|
|
||||||
|
entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new MapIndices(0, 0)).ToList();
|
||||||
|
Assert.That(entities.Count, Is.EqualTo(2));
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ using Content.Shared.Audio;
|
|||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
using Robust.Server.GameObjects.EntitySystems;
|
||||||
|
using Robust.Server.GameObjects.EntitySystems.TileLookup;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
@@ -31,6 +32,7 @@ namespace Content.Server.Atmos
|
|||||||
[Robust.Shared.IoC.Dependency] private readonly IRobustRandom _robustRandom = default!;
|
[Robust.Shared.IoC.Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||||
[Robust.Shared.IoC.Dependency] private readonly IEntityManager _entityManager = default!;
|
[Robust.Shared.IoC.Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
[Robust.Shared.IoC.Dependency] private readonly IMapManager _mapManager = default!;
|
[Robust.Shared.IoC.Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
private readonly GridTileLookupSystem _gridTileLookupSystem = default!;
|
||||||
|
|
||||||
|
|
||||||
private static readonly TileAtmosphereComparer Comparer = new TileAtmosphereComparer();
|
private static readonly TileAtmosphereComparer Comparer = new TileAtmosphereComparer();
|
||||||
@@ -115,6 +117,7 @@ namespace Content.Server.Atmos
|
|||||||
{
|
{
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
_gridAtmosphereComponent = atmosphereComponent;
|
_gridAtmosphereComponent = atmosphereComponent;
|
||||||
|
_gridTileLookupSystem = _entityManager.EntitySysManager.GetEntitySystem<GridTileLookupSystem>();
|
||||||
GridIndex = gridIndex;
|
GridIndex = gridIndex;
|
||||||
GridIndices = gridIndices;
|
GridIndices = gridIndices;
|
||||||
Air = mixture;
|
Air = mixture;
|
||||||
@@ -188,7 +191,7 @@ namespace Content.Server.Atmos
|
|||||||
GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(PressureDifference / 10, 10, 100)));
|
GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(PressureDifference / 10, 10, 100)));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var entity in _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(GridIndex).ParentMapId, Box2.UnitCentered.Translated(GridIndices)))
|
foreach (var entity in _gridTileLookupSystem.GetEntitiesIntersecting(GridIndex, GridIndices))
|
||||||
{
|
{
|
||||||
if (!entity.TryGetComponent(out ICollidableComponent physics)
|
if (!entity.TryGetComponent(out ICollidableComponent physics)
|
||||||
|| !entity.TryGetComponent(out MovedByPressureComponent pressure)
|
|| !entity.TryGetComponent(out MovedByPressureComponent pressure)
|
||||||
|
|||||||
Reference in New Issue
Block a user