mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 14:52:35 +02:00
* Move MapManager queries to SharedMapSystem Moves all variants of FindGridsIntersecting/TryFindGridAt to SharedMapSystem Hollows out the MapManager methods and converts them into relays to SharedMapSystem * Move CreateGrid to SharedMapSystem Moves the functionality for CreateGrid and its variants to SharedMapSystem Hollows out the MapManager methods and converts them into relays for the SharedMapSystem methods Obsoletes them too Also moves over the GetAllMapGrids and GetAllGrids methods * Move RaiseOnTileChanged to SharedMapSystem Also moves the SuppressOnTileChanged flag member to SharedMapSystem Hollows out and obsoletes the MapManager versions * Move default value constants to SharedMapSystem * Converts map pausing events into LocalizedEntityCommands * Move MapManager related delegates/structs to SharedMapSystem Moves the GridCreationOptions struct to the same namespace as SharedMapSystem and converts it into a record struct Move the GridCallback delegates to the same namespace as SharedMapSystem * Move CullDeletionHistory to SharedMapSystem Well, that was less painful than I thought it would be * Actually obsolete the NetworkedMapManager method * Rename file * Doc comments for new SharedMapSystem methods * Doc comment * Doc comments * Fix access * Purge all references to IMapManagerInternal * Cull easy IMapManager references * The rest * Purge IMapManager * Private internal FindGridsIntersecting method * please die * 41 * notes --------- Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
125 lines
4.4 KiB
C#
125 lines
4.4 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Robust.UnitTesting.Server.GameStates;
|
|
|
|
public sealed class PvsChunkTest : RobustIntegrationTest
|
|
{
|
|
[Test]
|
|
public async Task TestGridMapChange()
|
|
{
|
|
await using var pair = await StartConnectedPair();
|
|
var (client, server) = pair;
|
|
|
|
var sEntMan = server.ResolveDependency<IEntityManager>();
|
|
var confMan = server.ResolveDependency<IConfigurationManager>();
|
|
var sPlayerMan = server.ResolveDependency<ISharedPlayerManager>();
|
|
var xforms = sEntMan.System<SharedTransformSystem>();
|
|
var mapSys = sEntMan.System<MapSystem>();
|
|
|
|
var cEntMan = client.ResolveDependency<IEntityManager>();
|
|
|
|
server.Post(() => confMan.SetCVar(CVars.NetPVS, true));
|
|
|
|
await RunTicksSync(server, client, 10);
|
|
|
|
// Ensure client & server ticks are synced.
|
|
// Client runs 1 tick ahead
|
|
{
|
|
var sTick = (int)server.Timing.CurTick.Value;
|
|
var cTick = (int)client.Timing.CurTick.Value;
|
|
var delta = cTick - sTick;
|
|
|
|
if (delta > 1)
|
|
await server.WaitRunTicks(delta - 1);
|
|
else if (delta < 1)
|
|
await client.WaitRunTicks(1 - delta);
|
|
|
|
sTick = (int)server.Timing.CurTick.Value;
|
|
cTick = (int)client.Timing.CurTick.Value;
|
|
delta = cTick - sTick;
|
|
Assert.That(delta, Is.EqualTo(1));
|
|
}
|
|
|
|
// Set up entities
|
|
EntityUid map1 = default;
|
|
EntityUid map2 = default;
|
|
EntityUid grid = default;
|
|
EntityUid player = default;
|
|
EntityUid entity = default;
|
|
EntityCoordinates mapCoords = default;
|
|
await server.WaitPost(() =>
|
|
{
|
|
map1 = server.System<SharedMapSystem>().CreateMap();
|
|
mapCoords = new(map1, default);
|
|
|
|
map2 = server.System<SharedMapSystem>().CreateMap();
|
|
var gridComp = mapSys.CreateGridEntity(map2);
|
|
grid = gridComp.Owner;
|
|
mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1));
|
|
var gridCoords = new EntityCoordinates(grid, .5f, .5f);
|
|
|
|
player = sEntMan.SpawnEntity(null, mapCoords);
|
|
entity = sEntMan.SpawnEntity(null, gridCoords);
|
|
|
|
// Attach player.
|
|
var session = sPlayerMan.Sessions.First();
|
|
server.PlayerMan.SetAttachedEntity(session, player);
|
|
sPlayerMan.JoinGame(session);
|
|
});
|
|
|
|
await RunTicksSync(server, client, 10);
|
|
|
|
var nEntity = sEntMan.GetNetEntity(entity);
|
|
var nGrid = sEntMan.GetNetEntity(grid);
|
|
var nMap1 = sEntMan.GetNetEntity(map1);
|
|
var nMap2 = sEntMan.GetNetEntity(map2);
|
|
|
|
var xform = sEntMan.GetComponent<TransformComponent>(entity);
|
|
Assert.That(xform.ParentUid, Is.EqualTo(grid));
|
|
Assert.That(xform.GridUid, Is.EqualTo(grid));
|
|
Assert.That(xform.MapUid, Is.EqualTo(map2));
|
|
|
|
Assert.That(!cEntMan.TryGetEntity(nEntity, out _));
|
|
Assert.That(cEntMan.TryGetEntity(nMap1, out _));
|
|
Assert.That(cEntMan.TryGetEntity(nMap2, out _));
|
|
Assert.That(cEntMan.TryGetEntity(nGrid, out _));
|
|
|
|
// Teleport grid to new map
|
|
await server.WaitPost(() => xforms.SetCoordinates(grid, mapCoords));
|
|
await RunTicksSync(server, client, 10);
|
|
|
|
Assert.That(xform.ParentUid, Is.EqualTo(grid));
|
|
Assert.That(xform.GridUid, Is.EqualTo(grid));
|
|
Assert.That(xform.MapUid, Is.EqualTo(map1));
|
|
|
|
Assert.That(cEntMan.TryGetEntity(nEntity, out _));
|
|
Assert.That(cEntMan.TryGetEntity(nMap1, out _));
|
|
Assert.That(cEntMan.TryGetEntity(nMap2, out _));
|
|
Assert.That(cEntMan.TryGetEntity(nGrid, out _));
|
|
|
|
// Delete the original map.
|
|
await server.WaitPost(() => sEntMan.DeleteEntity(map2));
|
|
await RunTicksSync(server, client, 10);
|
|
|
|
Assert.That(xform.ParentUid, Is.EqualTo(grid));
|
|
Assert.That(xform.GridUid, Is.EqualTo(grid));
|
|
Assert.That(xform.MapUid, Is.EqualTo(map1));
|
|
|
|
Assert.That(cEntMan.TryGetEntity(nEntity, out _));
|
|
Assert.That(cEntMan.TryGetEntity(nMap1, out _));
|
|
Assert.That(!cEntMan.TryGetEntity(nMap2, out _));
|
|
Assert.That(cEntMan.TryGetEntity(nGrid, out _));
|
|
|
|
}
|
|
}
|
|
|