Add generic EntityUid, remove some usages of .Owner (#4498)

This commit is contained in:
DrSmugleaf
2023-10-19 12:23:48 -07:00
committed by GitHub
parent ed5223b592
commit b737ecf9b3
83 changed files with 1539 additions and 622 deletions

View File

@@ -54,7 +54,7 @@ public class RecursiveMoveBenchmark
var mapSys = _entMan.System<SharedMapSystem>();
var mapId = mapMan.CreateMap();
var map = mapMan.GetMapEntityId(mapId);
var gridComp = mapMan.CreateGrid(mapId);
var gridComp = mapMan.CreateGridEntity(mapId);
var grid = gridComp.Owner;
_gridCoords = new EntityCoordinates(grid, .5f, .5f);
_mapCoords = new EntityCoordinates(map, 100, 100);

View File

@@ -27,9 +27,6 @@ namespace Robust.Client.Console.Commands
var componentName = args[1];
var component = _componentFactory.GetComponent(componentName);
component.Owner = entity;
_entityManager.AddComponent(entity, component);
}
}

View File

@@ -1,6 +1,7 @@
#if DEBUG
using System.Numerics;
using System.Text;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
@@ -8,7 +9,6 @@ using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
namespace Robust.Client.Debugging
@@ -19,6 +19,7 @@ namespace Robust.Client.Debugging
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IUserInterfaceManager _userInterface = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;
private Label? _label;
@@ -70,7 +71,7 @@ namespace Robust.Client.Debugging
return;
}
var tile = grid.GetTileRef(spot);
var tile = _mapSystem.GetTileRef(gridUid, grid, spot);
_label.Position = mouseSpot.Position + new Vector2(32, 0);
if (_hovered?.GridId == gridUid && _hovered?.Tile == tile) return;
@@ -79,7 +80,7 @@ namespace Robust.Client.Debugging
var text = new StringBuilder();
foreach (var ent in grid.GetAnchoredEntities(spot))
foreach (var ent in _mapSystem.GetAnchoredEntities(gridUid, grid, spot))
{
if (EntityManager.TryGetComponent<MetaDataComponent>(ent, out var meta))
{

View File

@@ -46,7 +46,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.Input;
@@ -207,6 +206,7 @@ namespace Robust.Client.Debugging
private readonly Font _font;
private HashSet<Joint> _drawnJoints = new();
private List<Entity<MapGridComponent>> _grids = new();
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IMapManager mapManager, IPlayerManager playerManager, IResourceCache cache, DebugPhysicsSystem system, EntityLookupSystem lookup, SharedPhysicsSystem physicsSystem)
{
@@ -231,32 +231,33 @@ namespace Robust.Client.Debugging
{
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, viewBounds))
{
if (_entityManager.HasComponent<MapGridComponent>(physBody.Owner)) continue;
if (_entityManager.HasComponent<MapGridComponent>(physBody)) continue;
var xform = _physicsSystem.GetPhysicsTransform(physBody.Owner);
var xform = _physicsSystem.GetPhysicsTransform(physBody);
var comp = physBody.Comp;
const float AlphaModifier = 0.2f;
foreach (var fixture in _entityManager.GetComponent<FixturesComponent>(physBody.Owner).Fixtures.Values)
foreach (var fixture in _entityManager.GetComponent<FixturesComponent>(physBody).Fixtures.Values)
{
// Invalid shape - Box2D doesn't check for IsSensor but we will for sanity.
if (physBody.BodyType == BodyType.Dynamic && fixture.Density == 0f && fixture.Hard)
if (comp.BodyType == BodyType.Dynamic && fixture.Density == 0f && fixture.Hard)
{
DrawShape(worldHandle, fixture, xform, Color.Red.WithAlpha(AlphaModifier));
}
else if (!physBody.CanCollide)
else if (!comp.CanCollide)
{
DrawShape(worldHandle, fixture, xform, new Color(0.5f, 0.5f, 0.3f).WithAlpha(AlphaModifier));
}
else if (physBody.BodyType == BodyType.Static)
else if (comp.BodyType == BodyType.Static)
{
DrawShape(worldHandle, fixture, xform, new Color(0.5f, 0.9f, 0.5f).WithAlpha(AlphaModifier));
}
else if ((physBody.BodyType & (BodyType.Kinematic | BodyType.KinematicController)) != 0x0)
else if ((comp.BodyType & (BodyType.Kinematic | BodyType.KinematicController)) != 0x0)
{
DrawShape(worldHandle, fixture, xform, new Color(0.5f, 0.5f, 0.9f).WithAlpha(AlphaModifier));
}
else if (!physBody.Awake)
else if (!comp.Awake)
{
DrawShape(worldHandle, fixture, xform, new Color(0.6f, 0.6f, 0.6f).WithAlpha(AlphaModifier));
}
@@ -275,15 +276,18 @@ namespace Robust.Client.Debugging
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, viewBounds))
{
var color = Color.Purple.WithAlpha(Alpha);
var transform = _physicsSystem.GetPhysicsTransform(physBody.Owner);
worldHandle.DrawCircle(Transform.Mul(transform, physBody.LocalCenter), 0.2f, color);
var transform = _physicsSystem.GetPhysicsTransform(physBody);
worldHandle.DrawCircle(Transform.Mul(transform, physBody.Comp.LocalCenter), 0.2f, color);
}
foreach (var grid in _mapManager.FindGridsIntersecting(mapId, viewBounds))
_grids.Clear();
_mapManager.FindGridsIntersecting(mapId, viewBounds, ref _grids);
foreach (var grid in _grids)
{
var physBody = _entityManager.GetComponent<PhysicsComponent>(grid.Owner);
var physBody = _entityManager.GetComponent<PhysicsComponent>(grid);
var color = Color.Orange.WithAlpha(Alpha);
var transform = _physicsSystem.GetPhysicsTransform(grid.Owner);
var transform = _physicsSystem.GetPhysicsTransform(grid);
worldHandle.DrawCircle(Transform.Mul(transform, physBody.LocalCenter), 1f, color);
}
}
@@ -292,14 +296,14 @@ namespace Robust.Client.Debugging
{
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, viewBounds))
{
if (_entityManager.HasComponent<MapGridComponent>(physBody.Owner)) continue;
if (_entityManager.HasComponent<MapGridComponent>(physBody)) continue;
var xform = _physicsSystem.GetPhysicsTransform(physBody.Owner);
var xform = _physicsSystem.GetPhysicsTransform(physBody);
const float AlphaModifier = 0.2f;
Box2? aabb = null;
foreach (var fixture in _entityManager.GetComponent<FixturesComponent>(physBody.Owner).Fixtures.Values)
foreach (var fixture in _entityManager.GetComponent<FixturesComponent>(physBody).Fixtures.Values)
{
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
@@ -318,10 +322,11 @@ namespace Robust.Client.Debugging
{
_drawnJoints.Clear();
foreach (var jointComponent in _entityManager.EntityQuery<JointComponent>(true))
var query = _entityManager.AllEntityQueryEnumerator<JointComponent>();
while (query.MoveNext(out var uid, out var jointComponent))
{
if (jointComponent.JointCount == 0 ||
!_entityManager.TryGetComponent(jointComponent.Owner, out TransformComponent? xf1) ||
!_entityManager.TryGetComponent(uid, out TransformComponent? xf1) ||
!viewAABB.Contains(xf1.WorldPosition)) continue;
foreach (var (_, joint) in jointComponent.Joints)
@@ -370,28 +375,31 @@ namespace Robust.Client.Debugging
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.ShapeInfo) != 0x0)
{
var hoverBodies = new List<PhysicsComponent>();
var hoverBodies = new List<Entity<PhysicsComponent>>();
var bounds = Box2.UnitCentered.Translated(_eyeManager.PixelToMap(mousePos.Position).Position);
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, bounds))
{
if (_entityManager.HasComponent<MapGridComponent>(physBody.Owner)) continue;
hoverBodies.Add(physBody);
var uid = physBody.Owner;
if (_entityManager.HasComponent<MapGridComponent>(uid)) continue;
hoverBodies.Add((uid, physBody));
}
var lineHeight = _font.GetLineHeight(1f);
var drawPos = mousePos.Position + new Vector2(20, 0) + new Vector2(0, -(hoverBodies.Count * 4 * lineHeight / 2f));
int row = 0;
foreach (var body in hoverBodies)
foreach (var bodyEnt in hoverBodies)
{
if (body != hoverBodies[0])
if (bodyEnt != hoverBodies[0])
{
screenHandle.DrawString(_font, drawPos + new Vector2(0, row * lineHeight), "------");
row++;
}
screenHandle.DrawString(_font, drawPos + new Vector2(0, row * lineHeight), $"Ent: {body.Owner}");
var body = bodyEnt.Comp;
screenHandle.DrawString(_font, drawPos + new Vector2(0, row * lineHeight), $"Ent: {bodyEnt.Owner}");
row++;
screenHandle.DrawString(_font, drawPos + new Vector2(0, row * lineHeight), $"Layer: {Convert.ToString(body.CollisionLayer, 2)}");
row++;

View File

@@ -86,10 +86,16 @@ namespace Robust.Client.GameObjects
/// <inheritdoc />
public override void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null)
{
Dirty(new Entity<IComponent>(uid, component), meta);
}
/// <inheritdoc />
public override void Dirty(Entity<IComponent> ent, MetaDataComponent? meta = null)
{
// Client only dirties during prediction
if (_gameTiming.InPrediction)
base.Dirty(uid, component, meta);
base.Dirty(ent, meta);
}
public override EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metaDataComponent = null)

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using Robust.Client.Animations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using static Robust.Client.Animations.AnimationPlaybackShared;
namespace Robust.Client.GameObjects
@@ -21,42 +19,5 @@ namespace Robust.Client.GameObjects
= new();
internal bool HasPlayingAnimation = false;
/// <summary>
/// Start playing an animation.
/// </summary>
/// <param name="animation">The animation to play.</param>
/// <param name="key">
/// The key for this animation play. This key can be used to stop playback short later.
/// </param>
[Obsolete("Use AnimationPlayerSystem.Play() instead")]
public void Play(Animation animation, string key)
{
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AnimationPlayerSystem>().AddComponent(this);
var playback = new AnimationPlayback(animation);
PlayingAnimations.Add(key, playback);
}
[Obsolete("Use AnimationPlayerSystem.HasRunningAnimation() instead")]
public bool HasRunningAnimation(string key)
{
return PlayingAnimations.ContainsKey(key);
}
[Obsolete("Use AnimationPlayerSystem.Stop() instead")]
public void Stop(string key)
{
PlayingAnimations.Remove(key);
}
[Obsolete("Temporary method until the event is replaced with eventbus")]
internal void AnimationComplete(string key)
{
AnimationCompleted?.Invoke(key);
}
[Obsolete("Use AnimationCompletedEvent instead")]
public event Action<string>? AnimationCompleted;
}
}

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Robust.Client.Animations;
using Robust.Shared.GameObjects;
@@ -9,7 +10,7 @@ namespace Robust.Client.GameObjects
{
public sealed class AnimationPlayerSystem : EntitySystem, IPostInjectInit
{
private readonly List<AnimationPlayerComponent> _activeAnimations = new();
private readonly List<Entity<AnimationPlayerComponent>> _activeAnimations = new();
private EntityQuery<MetaDataComponent> _metaQuery;
@@ -38,22 +39,22 @@ namespace Robust.Client.GameObjects
continue;
}
if (!Update(uid, anim, frameTime))
if (!Update(uid, anim.Comp, frameTime))
{
continue;
}
_activeAnimations.RemoveSwap(i);
i--;
anim.HasPlayingAnimation = false;
anim.Comp.HasPlayingAnimation = false;
}
}
internal void AddComponent(AnimationPlayerComponent component)
internal void AddComponent(Entity<AnimationPlayerComponent> ent)
{
if (component.HasPlayingAnimation) return;
_activeAnimations.Add(component);
component.HasPlayingAnimation = true;
if (ent.Comp.HasPlayingAnimation) return;
_activeAnimations.Add(ent);
ent.Comp.HasPlayingAnimation = true;
}
private bool Update(EntityUid uid, AnimationPlayerComponent component, float frameTime)
@@ -78,7 +79,6 @@ namespace Robust.Client.GameObjects
{
component.PlayingAnimations.Remove(key);
EntityManager.EventBus.RaiseLocalEvent(uid, new AnimationCompletedEvent {Uid = uid, Key = key}, true);
component.AnimationComplete(key);
}
return false;
@@ -89,22 +89,29 @@ namespace Robust.Client.GameObjects
/// </summary>
public void Play(EntityUid uid, Animation animation, string key)
{
var component = EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
Play(component, animation, key);
var component = EnsureComp<AnimationPlayerComponent>(uid);
Play(new Entity<AnimationPlayerComponent>(uid, component), animation, key);
}
[Obsolete("Use Play(EntityUid<AnimationPlayerComponent> ent, Animation animation, string key) instead")]
public void Play(EntityUid uid, AnimationPlayerComponent? component, Animation animation, string key)
{
component ??= EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
Play(component, animation, key);
Play(new Entity<AnimationPlayerComponent>(uid, component), animation, key);
}
/// <summary>
/// Start playing an animation.
/// </summary>
[Obsolete("Use Play(EntityUid<AnimationPlayerComponent> ent, Animation animation, string key) instead")]
public void Play(AnimationPlayerComponent component, Animation animation, string key)
{
AddComponent(component);
Play(new Entity<AnimationPlayerComponent>(component.Owner, component), animation, key);
}
public void Play(Entity<AnimationPlayerComponent> ent, Animation animation, string key)
{
AddComponent(ent);
var playback = new AnimationPlaybackShared.AnimationPlayback(animation);
#if DEBUG
@@ -120,14 +127,14 @@ namespace Robust.Client.GameObjects
return;
}
if (!EntityManager.TryGetComponent(component.Owner, compTrack.ComponentType, out var animatedComp))
if (!EntityManager.TryGetComponent(ent, compTrack.ComponentType, out var animatedComp))
{
_sawmill.Error(
$"Attempted to play a component animation, but the entity {ToPrettyString(component.Owner)} does not have the component to be animated: {compTrack.ComponentType}.");
$"Attempted to play a component animation, but the entity {ToPrettyString(ent)} does not have the component to be animated: {compTrack.ComponentType}.");
return;
}
if (IsClientSide(component.Owner) || !animatedComp.NetSyncEnabled)
if (IsClientSide(ent) || !animatedComp.NetSyncEnabled)
continue;
var reg = _compFact.GetRegistration(animatedComp);
@@ -140,13 +147,13 @@ namespace Robust.Client.GameObjects
if (animatedComp.GetType().GetProperty(compTrack.Property) is { } property &&
property.HasCustomAttribute<AutoNetworkedFieldAttribute>())
{
_sawmill.Warning($"Playing a component animation on a networked component {reg.Name} belonging to {ToPrettyString(component.Owner)}");
_sawmill.Warning($"Playing a component animation on a networked component {reg.Name} belonging to {ToPrettyString(ent)}");
}
}
}
#endif
component.PlayingAnimations.Add(key, playback);
ent.Comp.PlayingAnimations.Add(key, playback);
}
public bool HasRunningAnimation(EntityUid uid, string key)

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
@@ -58,6 +59,8 @@ namespace Robust.Client.GameObjects
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private List<Entity<MapGridComponent>> _grids = new();
public GridChunkBoundsOverlay(IEntityManager entManager, IEyeManager eyeManager, IMapManager mapManager)
{
_entityManager = entManager;
@@ -71,13 +74,15 @@ namespace Robust.Client.GameObjects
var viewport = args.WorldBounds;
var worldHandle = args.WorldHandle;
foreach (var grid in _mapManager.FindGridsIntersecting(currentMap, viewport))
_grids.Clear();
_mapManager.FindGridsIntersecting(currentMap, viewport, ref _grids);
foreach (var grid in _grids)
{
var worldMatrix = _entityManager.GetComponent<TransformComponent>(grid.Owner).WorldMatrix;
var worldMatrix = _entityManager.GetComponent<TransformComponent>(grid).WorldMatrix;
worldHandle.SetTransform(worldMatrix);
var transform = new Transform(Vector2.Zero, Angle.Zero);
var chunkEnumerator = grid.GetMapChunks(viewport);
var chunkEnumerator = grid.Comp.GetMapChunks(viewport);
while (chunkEnumerator.MoveNext(out var chunk))
{

View File

@@ -28,11 +28,11 @@ namespace Robust.Client.GameObjects
// Only keep track of transforms actively lerping.
// Much faster than iterating 3000+ transforms every frame.
[ViewVariables] private readonly List<TransformComponent> _lerpingTransforms = new();
[ViewVariables] private readonly List<Entity<TransformComponent>> _lerpingTransforms = new();
public void Reset()
{
foreach (var xform in _lerpingTransforms)
foreach (var (_, xform) in _lerpingTransforms)
{
xform.ActivelyLerping = false;
xform.NextPosition = null;
@@ -77,7 +77,7 @@ namespace Robust.Client.GameObjects
return;
}
_lerpingTransforms.Add(xform);
_lerpingTransforms.Add((uid, xform));
xform.ActivelyLerping = true;
xform.PredictedLerp = false;
xform.LerpParent = xform.ParentUid;
@@ -96,7 +96,7 @@ namespace Robust.Client.GameObjects
if (!xform.ActivelyLerping)
{
_lerpingTransforms.Add(xform);
_lerpingTransforms.Add((uid, xform));
xform.ActivelyLerping = true;
xform.PredictedLerp = true;
xform.PrevRotation = xform._localRotation;
@@ -123,8 +123,7 @@ namespace Robust.Client.GameObjects
for (var i = 0; i < _lerpingTransforms.Count; i++)
{
var transform = _lerpingTransforms[i];
var uid = transform.Owner;
var (uid, transform) = _lerpingTransforms[i];
var found = false;
// Only lerp if parent didn't change.

View File

@@ -604,7 +604,7 @@ namespace Robust.Client.GameStates
/// Whenever a new entity is created, the server doesn't send full state data, given that much of the data
/// can simply be obtained from the entity prototype information. This function basically creates a fake
/// initial server state for any newly created entity. It does this by simply using the standard <see
/// cref="IEntityManager.GetComponentState(IEventBus, IComponent)"/>.
/// cref="IEntityManager.GetComponentState"/>.
/// </remarks>
private void MergeImplicitData(IEnumerable<NetEntity> createdEntities)
{
@@ -1188,7 +1188,6 @@ namespace Robust.Client.GameStates
if (!meta.NetComponents.TryGetValue(id, out var comp))
{
comp = _compFactory.GetComponent(id);
comp.Owner = uid;
_entityManager.AddComponent(uid, comp, true, metadata: meta);
}
@@ -1202,7 +1201,6 @@ namespace Robust.Client.GameStates
if (!meta.NetComponents.TryGetValue(compChange.NetID, out var comp))
{
comp = _compFactory.GetComponent(compChange.NetID);
comp.Owner = uid;
_entityManager.AddComponent(uid, comp, true, metadata:meta);
}
else if (compChange.LastModifiedTick <= lastApplied && lastApplied != GameTick.Zero)
@@ -1272,7 +1270,9 @@ namespace Robust.Client.GameStates
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()}");
@@ -1429,7 +1429,6 @@ namespace Robust.Client.GameStates
if (!meta.NetComponents.TryGetValue(id, out var comp))
{
comp = _compFactory.GetComponent(id);
comp.Owner = uid;
_entityManager.AddComponent(uid, comp, true, meta);
}

View File

@@ -4,7 +4,6 @@ using OpenToolkit.Graphics.OpenGL4;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
@@ -41,21 +40,23 @@ namespace Robust.Client.Graphics.Clyde
gridProgram.SetUniformTextureMaybe(UniILightTexture, TextureUnit.Texture1);
gridProgram.SetUniform(UniIModUV, new Vector4(0, 0, 1, 1));
foreach (var mapGrid in _mapManager.FindGridsIntersecting(mapId, worldBounds))
var grids = new List<Entity<MapGridComponent>>();
_mapManager.FindGridsIntersecting(mapId, worldBounds, ref grids);
foreach (var mapGrid in grids)
{
if (!_mapChunkData.ContainsKey(mapGrid.Owner))
if (!_mapChunkData.ContainsKey(mapGrid))
continue;
var transform = _entityManager.GetComponent<TransformComponent>(mapGrid.Owner);
var transform = _entityManager.GetComponent<TransformComponent>(mapGrid);
gridProgram.SetUniform(UniIModelMatrix, transform.WorldMatrix);
var enumerator = mapGrid.GetMapChunks(worldBounds);
var enumerator = mapGrid.Comp.GetMapChunks(worldBounds);
while (enumerator.MoveNext(out var chunk))
{
if (_isChunkDirty(mapGrid, chunk))
_updateChunkMesh(mapGrid, chunk);
var datum = _mapChunkData[mapGrid.Owner][chunk.Indices];
var datum = _mapChunkData[mapGrid][chunk.Indices];
if (datum.TileCount == 0)
continue;
@@ -70,9 +71,9 @@ namespace Robust.Client.Graphics.Clyde
}
}
private void _updateChunkMesh(MapGridComponent grid, MapChunk chunk)
private void _updateChunkMesh(Entity<MapGridComponent> grid, MapChunk chunk)
{
var data = _mapChunkData[grid.Owner];
var data = _mapChunkData[grid];
if (!data.TryGetValue(chunk.Indices, out var datum))
{
@@ -83,7 +84,7 @@ namespace Robust.Client.Graphics.Clyde
Span<Vertex2D> vertexBuffer = stackalloc Vertex2D[_verticesPerChunk(chunk)];
var i = 0;
var cSz = grid.ChunkSize;
var cSz = grid.Comp.ChunkSize;
var cScaled = chunk.Indices * cSz;
for (ushort x = 0; x < cSz; x++)
{
@@ -130,7 +131,7 @@ namespace Robust.Client.Graphics.Clyde
datum.TileCount = i;
}
private unsafe MapChunkData _initChunkBuffers(MapGridComponent grid, MapChunk chunk)
private unsafe MapChunkData _initChunkBuffers(Entity<MapGridComponent> grid, MapChunk chunk)
{
var vao = GenVertexArray();
BindVertexArray(vao);
@@ -158,19 +159,19 @@ namespace Robust.Client.Graphics.Clyde
Dirty = true
};
_mapChunkData[grid.Owner].Add(chunk.Indices, datum);
_mapChunkData[grid].Add(chunk.Indices, datum);
return datum;
}
private bool _isChunkDirty(MapGridComponent grid, MapChunk chunk)
private bool _isChunkDirty(Entity<MapGridComponent> grid, MapChunk chunk)
{
var data = _mapChunkData[grid.Owner];
var data = _mapChunkData[grid];
return !data.TryGetValue(chunk.Indices, out var datum) || datum.Dirty;
}
public void _setChunkDirty(MapGridComponent grid, Vector2i chunk)
public void _setChunkDirty(Entity<MapGridComponent> grid, Vector2i chunk)
{
var data = _mapChunkData.GetOrNew(grid.Owner);
var data = _mapChunkData.GetOrNew(grid);
if (data.TryGetValue(chunk, out var datum))
{
datum.Dirty = true;
@@ -184,7 +185,7 @@ namespace Robust.Client.Graphics.Clyde
{
var grid = args.Grid;
var chunk = grid.GridTileToChunkIndices(pos);
_setChunkDirty(grid, chunk);
_setChunkDirty((args.GridEnt, grid), chunk);
}
}
@@ -192,7 +193,7 @@ namespace Robust.Client.Graphics.Clyde
{
var grid = _mapManager.GetGrid(args.NewTile.GridUid);
var chunk = grid.GridTileToChunkIndices(new Vector2i(args.NewTile.X, args.NewTile.Y));
_setChunkDirty(grid, chunk);
_setChunkDirty((args.NewTile.GridUid, grid), chunk);
}
private void _updateOnGridCreated(GridStartupEvent ev)

View File

@@ -350,7 +350,7 @@ namespace Robust.Client.Graphics.Clyde
_renderHandle.Viewport(Box2i.FromDimensions(-flippedPos, screenSize));
if (entry.Sprite.RaiseShaderEvent)
_entityManager.EventBus.RaiseLocalEvent(entry.Sprite.Owner,
_entityManager.EventBus.RaiseLocalEvent(entry.Uid,
new BeforePostShaderRenderEvent(entry.Sprite, viewport), false);
}
}

View File

@@ -1,11 +1,3 @@
using Robust.Client.ComponentTrees;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Threading;
using Robust.Shared.Utility;
using System;
using System.Buffers;
using System.Collections.Generic;
@@ -14,7 +6,15 @@ using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using System.Threading.Tasks;
using Robust.Client.ComponentTrees;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Threading;
using Robust.Shared.Utility;
namespace Robust.Client.Graphics.Clyde;
@@ -260,7 +260,7 @@ internal partial class Clyde
if (cmp != 0)
return cmp;
return a.Sprite.Owner.CompareTo(b.Sprite.Owner);
return a.Uid.CompareTo(b.Uid);
}
}
}

View File

@@ -17,11 +17,9 @@ using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Profiling;
using Robust.Shared.Timing;
using SixLabors.ImageSharp;
using Color = Robust.Shared.Maths.Color;
using DependencyAttribute = Robust.Shared.IoC.DependencyAttribute;
using TextureWrapMode = Robust.Shared.Graphics.TextureWrapMode;
namespace Robust.Client.Graphics.Clyde

View File

@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Direction = Robust.Shared.Maths.Direction;
namespace Robust.Client.Map;
@@ -22,6 +23,8 @@ public sealed class TileEdgeOverlay : Overlay
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowEntities;
private List<Entity<MapGridComponent>> _grids = new();
public TileEdgeOverlay(IEntityManager entManager, IMapManager mapManager, IResourceCache resource, ITileDefinitionManager tileDefManager)
{
_entManager = entManager;
@@ -36,16 +39,18 @@ public sealed class TileEdgeOverlay : Overlay
if (args.MapId == MapId.Nullspace)
return;
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
_grids.Clear();
_mapManager.FindGridsIntersecting(args.MapId, args.WorldBounds, ref _grids);
foreach (var grid in _mapManager.FindGridsIntersecting(args.MapId, args.WorldBounds))
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
foreach (var grid in _grids)
{
var tileSize = grid.TileSize;
var tileSize = grid.Comp.TileSize;
var tileDimensions = new Vector2(tileSize, tileSize);
var xform = xformQuery.GetComponent(grid.Owner);
var xform = xformQuery.GetComponent(grid);
args.WorldHandle.SetTransform(xform.WorldMatrix);
foreach (var tileRef in grid.GetTilesIntersecting(args.WorldBounds, false))
foreach (var tileRef in grid.Comp.GetTilesIntersecting(args.WorldBounds, false))
{
var tileDef = _tileDefManager[tileRef.Tile.TypeId];
@@ -61,7 +66,7 @@ public sealed class TileEdgeOverlay : Overlay
continue;
var neighborIndices = new Vector2i(tileRef.GridIndices.X + x, tileRef.GridIndices.Y + y);
var neighborTile = grid.GetTileRef(neighborIndices);
var neighborTile = grid.Comp.GetTileRef(neighborIndices);
var neighborDef = _tileDefManager[neighborTile.Tile.TypeId];
// If it's the same tile then no edge to be drawn.

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
@@ -26,7 +25,7 @@ namespace Robust.Client.Physics
protected override void Cleanup(PhysicsMapComponent component, float frameTime)
{
var toRemove = new List<PhysicsComponent>();
var toRemove = new List<Entity<PhysicsComponent>>();
// Because we're not predicting 99% of bodies its sleep timer never gets incremented so we'll just do it ourselves.
// (and serializing it over the network isn't necessary?)
@@ -38,13 +37,13 @@ namespace Robust.Client.Physics
body.SleepTime += frameTime;
if (body.SleepTime > TimeToSleep)
{
toRemove.Add(body);
toRemove.Add(new Entity<PhysicsComponent>(body.Owner, body));
}
}
foreach (var body in toRemove)
{
SetAwake(body.Owner, body, false);
SetAwake(body, false);
}
base.Cleanup(component, frameTime);

View File

@@ -7,7 +7,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using Direction = Robust.Shared.Maths.Direction;
namespace Robust.Client.UserInterface.Controls
{
@@ -18,18 +17,14 @@ namespace Robust.Client.UserInterface.Controls
IEntityManager _entMan;
[ViewVariables]
private SpriteComponent? _sprite;
public SpriteComponent? Sprite
{
get => _sprite;
[Obsolete("Use SetEntity()")]
set => SetEntity(value?.Owner);
}
public SpriteComponent? Sprite { get; private set; }
[ViewVariables]
public EntityUid? Entity { get; private set; }
public Entity<SpriteComponent>? Ent => Entity == null || Sprite == null ? null : (Entity.Value, Sprite);
/// <summary>
/// This field configures automatic scaling of the sprite. This automatic scaling is done before
/// applying the explicitly set scale <see cref="SpriteView.Scale"/>.
@@ -124,14 +119,22 @@ namespace Robust.Client.UserInterface.Controls
public SpriteView()
{
_entMan = IoCManager.Resolve<IEntityManager>();
_entMan.TryGetComponent(Entity, out _sprite);
if (_entMan.TryGetComponent(Entity, out SpriteComponent? sprite))
{
Sprite = sprite;
}
RectClipContent = true;
}
public void SetEntity(EntityUid? uid)
{
Entity = uid;
_entMan.TryGetComponent(Entity, out _sprite);
if (_entMan.TryGetComponent(Entity, out SpriteComponent? sprite))
{
Sprite = sprite;
}
}
protected override Vector2 MeasureOverride(Vector2 availableSize)
@@ -143,13 +146,13 @@ namespace Robust.Client.UserInterface.Controls
private void UpdateSize()
{
if (Entity == null || _sprite == null)
if (Entity == null || Sprite == null)
{
_spriteSize = default;
return;
}
var spriteBox = _sprite.CalculateRotatedBoundingBox(default, _worldRotation ?? Angle.Zero, _eyeRotation)
var spriteBox = Sprite.CalculateRotatedBoundingBox(default, _worldRotation ?? Angle.Zero, _eyeRotation)
.CalcBoundingBox();
if (!SpriteOffset)
@@ -191,10 +194,10 @@ namespace Robust.Client.UserInterface.Controls
internal override void DrawInternal(IRenderHandle renderHandle)
{
if (Entity is not {} uid || _sprite == null)
if (Entity is not {} uid || Sprite == null)
return;
if (_sprite.Deleted)
if (Sprite.Deleted)
{
SetEntity(null);
return;
@@ -214,11 +217,11 @@ namespace Robust.Client.UserInterface.Controls
var offset = SpriteOffset
? Vector2.Zero
: - (-_eyeRotation).RotateVec(_sprite.Offset) * new Vector2(1, -1) * EyeManager.PixelsPerMeter;
: - (-_eyeRotation).RotateVec(Sprite.Offset) * new Vector2(1, -1) * EyeManager.PixelsPerMeter;
var position = PixelSize / 2 + offset * stretch * UIScale;
var scale = Scale * UIScale * stretch;
renderHandle.DrawEntity(uid, position, scale, _worldRotation, _eyeRotation, OverrideDirection, _sprite);
renderHandle.DrawEntity(uid, position, scale, _worldRotation, _eyeRotation, OverrideDirection, Sprite);
}
}
}

View File

@@ -117,7 +117,7 @@ Mouse Pos:
{playerWorldOffset}
{playerCoordinates}
Rotation: {playerRotation.Degrees:F2}°
EntId: {entityTransform.Owner}
EntId: {controlledEntity}
GridUid: {entityTransform.GridUid}
Grid Rotation: {gridRotation.Degrees:F2}°");
}

View File

@@ -5,7 +5,7 @@ using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Map.Components;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Robust.Client.ViewVariables.Editors
@@ -67,13 +67,13 @@ namespace Robust.Client.ViewVariables.Editors
var xVal = float.Parse(x.Text, CultureInfo.InvariantCulture);
var yVal = float.Parse(y.Text, CultureInfo.InvariantCulture);
if (!mapManager.TryGetGrid(gridVal, out var grid))
if (!entityManager.HasComponent<MapGridComponent>(gridVal))
{
ValueChanged(new EntityCoordinates(EntityUid.Invalid, new(xVal, yVal)));
return;
}
ValueChanged(new EntityCoordinates(grid.Owner, new(xVal, yVal)));
ValueChanged(new EntityCoordinates(gridVal, new(xVal, yVal)));
}
if (!ReadOnly)

View File

@@ -120,7 +120,11 @@ namespace Robust.Client.ViewVariables.Instances
};
top.HorizontalExpand = true;
hBox.AddChild(top);
hBox.AddChild(new SpriteView {Sprite = sprite, OverrideDirection = Direction.South});
var view = new SpriteView { OverrideDirection = Direction.South };
view.SetEntity(_entity);
hBox.AddChild(view);
vBoxContainer.AddChild(hBox);
}
else
@@ -432,7 +436,6 @@ namespace Robust.Client.ViewVariables.Instances
try
{
var comp = componentFactory.GetComponent(registration.Type);
comp.Owner = _entity;
_entityManager.AddComponent(_entity, comp);
}
catch (Exception e)

View File

@@ -47,10 +47,6 @@ namespace Robust.Server.Console.Commands
}
var component = _componentFactory.GetComponent(registration.Type);
#pragma warning disable CS0618
component.Owner = uid.Value;
#pragma warning restore CS0618
_entityManager.AddComponent(uid.Value, component);
shell.WriteLine($"Added {componentName} component to entity {_entityManager.GetComponent<MetaDataComponent>(uid.Value).EntityName}.");

View File

@@ -1,5 +1,4 @@
using System;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -22,7 +21,7 @@ namespace Robust.Server.GameObjects
public int LayerVV
{
get => Layer;
set => EntitySystem.Get<VisibilitySystem>().SetLayer(this, value);
set => EntitySystem.Get<VisibilitySystem>().SetLayer(Owner, this, value);
}
}
}

View File

@@ -6,7 +6,6 @@ using System.IO;
using System.Linq;
using System.Numerics;
using Robust.Server.Maps;
using Robust.Shared.Collections;
using Robust.Shared.ContentPack;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -733,7 +732,7 @@ public sealed class MapLoaderSystem : EntitySystem
return;
// get ents that the grids will bind to
var gridComps = new MapGridComponent[yamlGrids.Count];
var gridComps = new Entity<MapGridComponent>[yamlGrids.Count];
var gridQuery = _serverEntityManager.GetEntityQuery<MapGridComponent>();
// linear search for new grid comps
@@ -745,7 +744,7 @@ public sealed class MapLoaderSystem : EntitySystem
// These should actually be new, pre-init
DebugTools.Assert(gridComp.LifeStage == ComponentLifeStage.Added);
gridComps[gridComp.GridIndex] = gridComp;
gridComps[gridComp.GridIndex] = new Entity<MapGridComponent>(uid, gridComp);
}
for (var index = 0; index < yamlGrids.Count; index++)
@@ -764,18 +763,18 @@ public sealed class MapLoaderSystem : EntitySystem
MappingDataNode yamlGridInfo = (MappingDataNode)yamlGrid["settings"];
SequenceDataNode yamlGridChunks = (SequenceDataNode)yamlGrid["chunks"];
var grid = AllocateMapGrid(gridComp, yamlGridInfo);
var gridUid = grid.Owner;
AllocateMapGrid(gridComp, yamlGridInfo);
var gridUid = gridComp.Owner;
foreach (var chunkNode in yamlGridChunks.Cast<MappingDataNode>())
{
var (chunkOffsetX, chunkOffsetY) = _serManager.Read<Vector2i>(chunkNode["ind"]);
_serManager.Read(chunkNode, _context, instanceProvider: () => _mapSystem.GetOrAddChunk(gridUid, grid, chunkOffsetX, chunkOffsetY), notNullableOverride: true);
_serManager.Read(chunkNode, _context, instanceProvider: () => _mapSystem.GetOrAddChunk(gridUid, gridComp, chunkOffsetX, chunkOffsetY), notNullableOverride: true);
}
}
}
private static MapGridComponent AllocateMapGrid(MapGridComponent gridComp, MappingDataNode yamlGridInfo)
private static void AllocateMapGrid(MapGridComponent gridComp, MappingDataNode yamlGridInfo)
{
// sane defaults
ushort csz = 16;
@@ -795,8 +794,6 @@ public sealed class MapLoaderSystem : EntitySystem
gridComp.ChunkSize = csz;
gridComp.TileSize = tsz;
return gridComp;
}
private void StartupEntities(MapData data)

View File

@@ -260,7 +260,7 @@ namespace Robust.Server.Physics
for (var i = 0; i < grids.Count - 1; i++)
{
var group = grids[i];
var newGrid = _mapManager.CreateGrid(mapId);
var newGrid = _mapManager.CreateGridEntity(mapId);
var newGridUid = newGrid.Owner;
var newGridXform = xformQuery.GetComponent(newGridUid);
newGrids[i] = newGridUid;
@@ -287,7 +287,7 @@ namespace Robust.Server.Physics
}
}
newGrid.SetTiles(tileData);
newGrid.Comp.SetTiles(tileData);
DebugTools.Assert(_mapManager.IsGrid(newGridUid), "A split grid had no tiles?");
// Set tiles on new grid + update anchored entities

View File

@@ -199,11 +199,11 @@ namespace Robust.Server.Placement
}
else if (tileType != 0) // create a new grid
{
var newGrid = _mapManager.CreateGrid(coordinates.GetMapId(_entityManager));
var newGridXform = _entityManager.GetComponent<TransformComponent>(newGrid.Owner);
newGridXform.WorldPosition = coordinates.Position - newGrid.TileSizeHalfVector; // assume bottom left tile origin
var tilePos = newGrid.WorldToTile(coordinates.Position);
newGrid.SetTile(tilePos, new Tile(tileType));
var newGrid = _mapManager.CreateGridEntity(coordinates.GetMapId(_entityManager));
var newGridXform = _entityManager.GetComponent<TransformComponent>(newGrid);
newGridXform.WorldPosition = coordinates.Position - newGrid.Comp.TileSizeHalfVector; // assume bottom left tile origin
var tilePos = newGrid.Comp.WorldToTile(coordinates.Position);
newGrid.Comp.SetTile(tilePos, new Tile(tileType));
var placementEraseEvent = new PlacementTileEvent(tileType, coordinates, placingUserId);
_entityManager.EventBus.RaiseEvent(EventSource.Local, placementEraseEvent);

View File

@@ -148,7 +148,7 @@ internal sealed class ListMapsCommand : LocalizedCommands
mapId, _map.IsMapInitialized(mapId),
_map.IsMapPaused(mapId),
_map.GetMapEntityId(mapId),
string.Join(",", _map.GetAllMapGrids(mapId).Select(grid => grid.Owner)));
string.Join(",", _map.GetAllGrids(mapId).Select(grid => grid.Owner)));
}
shell.WriteLine(msg.ToString());

View File

@@ -1,5 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Network;
@@ -9,12 +14,6 @@ using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
namespace Robust.Shared.Containers
{
@@ -62,7 +61,7 @@ namespace Robust.Shared.Containers
/// The entity that owns this container.
/// </summary>
[ViewVariables]
public EntityUid Owner => Manager.Owner;
public EntityUid Owner { get; internal set; }
/// <summary>
/// Should the contents of this container be shown? False for closed containers like lockers, true for
@@ -77,10 +76,7 @@ namespace Robust.Shared.Containers
DebugTools.AssertNull(ID);
ID = id;
Manager = component;
// TODO fix container init.
// Eventually, we want an owner field, but currently it needs to use component.Owner
// Owner = owner;
Owner = owner;
}
/// <summary>
@@ -107,10 +103,9 @@ namespace Robust.Shared.Containers
bool force = false)
{
IoCManager.Resolve(ref entMan);
DebugTools.Assert(transform == null || transform.Owner == toinsert);
DebugTools.Assert(ownerTransform == null || ownerTransform.Owner == Owner);
DebugTools.Assert(ownerTransform == null || ownerTransform.Owner == Owner);
DebugTools.Assert(physics == null || physics.Owner == toinsert);
DebugTools.AssertOwner(toinsert, transform);
DebugTools.AssertOwner(Owner, ownerTransform);
DebugTools.AssertOwner(toinsert, physics);
DebugTools.Assert(!ExpectedEntities.Contains(entMan.GetNetEntity(toinsert)));
DebugTools.Assert(Manager.Containers.ContainsKey(ID));
@@ -298,8 +293,8 @@ namespace Robust.Shared.Containers
IoCManager.Resolve(ref entMan);
DebugTools.AssertNotNull(Manager);
DebugTools.Assert(entMan.EntityExists(toRemove));
DebugTools.Assert(xform == null || xform.Owner == toRemove);
DebugTools.Assert(meta == null || meta.Owner == toRemove);
DebugTools.AssertOwner(toRemove, xform);
DebugTools.AssertOwner(toRemove, meta);
xform ??= entMan.GetComponent<TransformComponent>(toRemove);
meta ??= entMan.GetComponent<MetaDataComponent>(toRemove);
@@ -337,7 +332,7 @@ namespace Robust.Shared.Containers
else if (reparent)
{
// Container ECS when.
sys.AttachParentToContainerOrGrid(xform);
sys.AttachParentToContainerOrGrid((toRemove, xform));
if (localRotation != null)
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetLocalRotation(xform, localRotation.Value);
}

View File

@@ -7,7 +7,6 @@ using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -22,7 +21,6 @@ namespace Robust.Shared.Containers
{
[Dependency] private readonly IDynamicTypeFactoryInternal _dynFactory = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly INetManager _netMan = default!;
[DataField("containers")]
public Dictionary<string, BaseContainer> Containers = new();
@@ -30,41 +28,37 @@ namespace Robust.Shared.Containers
void ISerializationHooks.AfterDeserialization()
{
// TODO custom type serializer
// TODO set owner uid on init.
foreach (var (id, container) in Containers)
{
container.Manager = this;
container.Owner = Owner;
container.ID = id;
}
}
/// <inheritdoc />
public T MakeContainer<T>(string id)
public T MakeContainer<T>(EntityUid uid, string id)
where T : BaseContainer
{
if (HasContainer(id))
throw new ArgumentException($"Container with specified ID already exists: '{id}'");
var container = _dynFactory.CreateInstanceUnchecked<T>(typeof(T), inject: false);
container.Init(id, Owner, this);
container.Init(id, uid, this);
Containers[id] = container;
_entMan.Dirty(this);
return container;
}
/// <inheritdoc />
public BaseContainer GetContainer(string id)
{
return Containers[id];
}
/// <inheritdoc />
public bool HasContainer(string id)
{
return Containers.ContainsKey(id);
}
/// <inheritdoc />
public bool TryGetContainer(string id, [NotNullWhen(true)] out BaseContainer? container)
{
var ret = Containers.TryGetValue(id, out var cont);
@@ -72,7 +66,6 @@ namespace Robust.Shared.Containers
return ret;
}
/// <inheritdoc />
public bool TryGetContainer(EntityUid entity, [NotNullWhen(true)] out BaseContainer? container)
{
foreach (var contain in Containers.Values)
@@ -88,7 +81,6 @@ namespace Robust.Shared.Containers
return false;
}
/// <inheritdoc />
public bool ContainsEntity(EntityUid entity)
{
foreach (var container in Containers.Values)
@@ -99,7 +91,6 @@ namespace Robust.Shared.Containers
return false;
}
/// <inheritdoc />
public bool Remove(EntityUid toremove,
TransformComponent? xform = null,
MetaDataComponent? meta = null,
@@ -214,7 +205,9 @@ namespace Robust.Shared.Containers
object IEnumerator.Current => Current;
public void Dispose() { }
public void Dispose()
{
}
}
}
}

View File

@@ -83,16 +83,16 @@ namespace Robust.Shared.Containers
where T : BaseContainer
{
if (!Resolve(uid, ref containerManager, false))
containerManager = EntityManager.AddComponent<ContainerManagerComponent>(uid); // Happy Vera.
containerManager = AddComp<ContainerManagerComponent>(uid); // Happy Vera.
return containerManager.MakeContainer<T>(id);
return containerManager.MakeContainer<T>(uid, id);
}
public T EnsureContainer<T>(EntityUid uid, string id, out bool alreadyExisted, ContainerManagerComponent? containerManager = null)
where T : BaseContainer
{
if (!Resolve(uid, ref containerManager, false))
containerManager = EntityManager.AddComponent<ContainerManagerComponent>(uid);
containerManager = AddComp<ContainerManagerComponent>(uid);
if (TryGetContainer(uid, id, out var container, containerManager))
{
@@ -141,7 +141,7 @@ namespace Robust.Shared.Containers
public bool TryGetContainingContainer(EntityUid uid, EntityUid containedUid, [NotNullWhen(true)] out BaseContainer? container, ContainerManagerComponent? containerManager = null, bool skipExistCheck = false)
{
if (Resolve(uid, ref containerManager, false) && (skipExistCheck || EntityManager.EntityExists(containedUid)))
if (Resolve(uid, ref containerManager, false) && (skipExistCheck || Exists(containedUid)))
return containerManager.TryGetContainer(containedUid, out container);
container = null;
@@ -150,7 +150,7 @@ namespace Robust.Shared.Containers
public bool ContainsEntity(EntityUid uid, EntityUid containedUid, ContainerManagerComponent? containerManager = null)
{
if (!Resolve(uid, ref containerManager, false) || !EntityManager.EntityExists(containedUid))
if (!Resolve(uid, ref containerManager, false) || !Exists(containedUid))
return false;
return containerManager.ContainsEntity(containedUid);
@@ -228,7 +228,7 @@ namespace Robust.Shared.Containers
{
if (meta == null)
{
metas ??= EntityManager.GetEntityQuery<MetaDataComponent>();
metas ??= GetEntityQuery<MetaDataComponent>();
meta = metas.Value.GetComponent(uid);
}
@@ -237,7 +237,7 @@ namespace Robust.Shared.Containers
if (xform == null)
{
xforms ??= EntityManager.GetEntityQuery<TransformComponent>();
xforms ??= GetEntityQuery<TransformComponent>();
xform = xforms.Value.GetComponent(uid);
}
@@ -297,7 +297,7 @@ namespace Robust.Shared.Containers
if (!xform.ParentUid.Valid)
return foundComponents.Any();
if (EntityManager.TryGetComponent(xform.ParentUid, out T? foundComponent))
if (TryComp(xform.ParentUid, out T? foundComponent))
foundComponents.Add(foundComponent);
return TryFindComponentsOnEntityContainerOrParent(xform.ParentUid, entityQuery, foundComponents);
@@ -394,7 +394,7 @@ namespace Robust.Shared.Containers
/// </summary>
public bool TryGetOuterContainer(EntityUid uid, TransformComponent xform, [NotNullWhen(true)] out BaseContainer? container)
{
var xformQuery = EntityManager.GetEntityQuery<TransformComponent>();
var xformQuery = GetEntityQuery<TransformComponent>();
return TryGetOuterContainer(uid, xform, out container, xformQuery);
}
@@ -406,8 +406,8 @@ namespace Robust.Shared.Containers
if (!uid.IsValid())
return false;
var conQuery = EntityManager.GetEntityQuery<ContainerManagerComponent>();
var metaQuery = EntityManager.GetEntityQuery<MetaDataComponent>();
var conQuery = GetEntityQuery<ContainerManagerComponent>();
var metaQuery = GetEntityQuery<MetaDataComponent>();
var child = uid;
var parent = xform.ParentUid;
@@ -501,20 +501,26 @@ namespace Robust.Shared.Containers
}
}
[Obsolete("Use AttachParentToContainerOrGrid(EntityUid<TransformComponent>) instead")]
public void AttachParentToContainerOrGrid(TransformComponent transform)
{
AttachParentToContainerOrGrid(new Entity<TransformComponent>(transform.Owner, transform));
}
public void AttachParentToContainerOrGrid(Entity<TransformComponent> transform)
{
// TODO make this check upwards for any container, and parent to that.
// Currently this just checks the direct parent, so entities will still teleport through containers.
if (!transform.ParentUid.IsValid()
|| !TryGetContainingContainer(transform.ParentUid, out var container)
if (!transform.Comp.ParentUid.IsValid()
|| !TryGetContainingContainer(transform.Comp.ParentUid, out var container)
|| !TryInsertIntoContainer(transform, container))
transform.AttachToGridOrMap();
transform.Comp.AttachToGridOrMap();
}
private bool TryInsertIntoContainer(TransformComponent transform, BaseContainer container)
private bool TryInsertIntoContainer(Entity<TransformComponent> transform, BaseContainer container)
{
if (container.Insert(transform.Owner)) return true;
if (container.Insert(transform)) return true;
if (Transform(container.Owner).ParentUid.IsValid()
&& TryGetContainingContainer(container.Owner, out var newContainer))

View File

@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
namespace Robust.Shared.GameObjects;
@@ -33,14 +32,6 @@ public sealed partial class AppearanceComponent : Component
[ViewVariables] internal Dictionary<Enum, object> AppearanceData = new();
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
[Obsolete("Use SharedAppearanceSystem instead")]
public void SetData(Enum key, object value)
{
_sysMan.GetEntitySystem<SharedAppearanceSystem>().SetData(Owner, key, value, this);
}
[Obsolete("Use SharedAppearanceSystem instead")]
public bool TryGetData<T>(Enum key, [NotNullWhen(true)] out T data)
{

View File

@@ -0,0 +1,584 @@
using Robust.Shared.Utility;
namespace Robust.Shared.GameObjects;
public record struct Entity<T>
where T : IComponent?
{
public EntityUid Owner;
public T Comp;
public Entity(EntityUid owner, T comp)
{
DebugTools.AssertOwner(owner, comp);
Owner = owner;
Comp = comp;
}
public static implicit operator Entity<T>((EntityUid Owner, T Comp) tuple)
{
return new Entity<T>(tuple.Owner, tuple.Comp);
}
public static implicit operator Entity<T?>(EntityUid owner)
{
return new Entity<T?>(owner, default);
}
public static implicit operator EntityUid(Entity<T> ent)
{
return ent.Owner;
}
public static implicit operator T(Entity<T> ent)
{
return ent.Comp;
}
public readonly void Deconstruct(out EntityUid owner, out T comp)
{
owner = Owner;
comp = Comp;
}
}
public record struct Entity<T1, T2>
where T1 : IComponent? where T2 : IComponent?
{
public EntityUid Owner;
public T1 Comp1;
public T2 Comp2;
public Entity(EntityUid owner, T1 comp1, T2 comp2)
{
DebugTools.AssertOwner(owner, comp1);
DebugTools.AssertOwner(owner, comp2);
Owner = owner;
Comp1 = comp1;
Comp2 = comp2;
}
public static implicit operator Entity<T1, T2>((EntityUid Owner, T1 Comp1, T2 Comp2) tuple)
{
return new Entity<T1, T2>(tuple.Owner, tuple.Comp1, tuple.Comp2);
}
public static implicit operator Entity<T1?, T2?>(EntityUid owner)
{
return new Entity<T1?, T2?>(owner, default, default);
}
public static implicit operator EntityUid(Entity<T1, T2> ent)
{
return ent.Owner;
}
public static implicit operator T1(Entity<T1, T2> ent)
{
return ent.Comp1;
}
public static implicit operator T2(Entity<T1, T2> ent)
{
return ent.Comp2;
}
public readonly void Deconstruct(out EntityUid owner, out T1 comp1, out T2 comp2)
{
owner = Owner;
comp1 = Comp1;
comp2 = Comp2;
}
}
public record struct Entity<T1, T2, T3>
where T1 : IComponent? where T2 : IComponent? where T3 : IComponent?
{
public EntityUid Owner;
public T1 Comp1;
public T2 Comp2;
public T3 Comp3;
public Entity(EntityUid owner, T1 comp1, T2 comp2, T3 comp3)
{
DebugTools.AssertOwner(owner, comp1);
DebugTools.AssertOwner(owner, comp2);
DebugTools.AssertOwner(owner, comp3);
Owner = owner;
Comp1 = comp1;
Comp2 = comp2;
Comp3 = comp3;
}
public static implicit operator Entity<T1, T2, T3>((EntityUid Owner, T1 Comp1, T2 Comp2, T3 Comp3) tuple)
{
return new Entity<T1, T2, T3>(tuple.Owner, tuple.Comp1, tuple.Comp2, tuple.Comp3);
}
public static implicit operator Entity<T1?, T2?, T3?>(EntityUid owner)
{
return new Entity<T1?, T2?, T3?>(owner, default, default, default);
}
public static implicit operator EntityUid(Entity<T1, T2, T3> ent)
{
return ent.Owner;
}
public static implicit operator T1(Entity<T1, T2, T3> ent)
{
return ent.Comp1;
}
public static implicit operator T2(Entity<T1, T2, T3> ent)
{
return ent.Comp2;
}
public static implicit operator T3(Entity<T1, T2, T3> ent)
{
return ent.Comp3;
}
public readonly void Deconstruct(out EntityUid owner, out T1 comp1, out T2 comp2, out T3 comp3)
{
owner = Owner;
comp1 = Comp1;
comp2 = Comp2;
comp3 = Comp3;
}
}
public record struct Entity<T1, T2, T3, T4>
where T1 : IComponent? where T2 : IComponent? where T3 : IComponent? where T4 : IComponent?
{
public EntityUid Owner;
public T1 Comp1;
public T2 Comp2;
public T3 Comp3;
public T4 Comp4;
public Entity(EntityUid owner, T1 comp1, T2 comp2, T3 comp3, T4 comp4)
{
DebugTools.AssertOwner(owner, comp1);
DebugTools.AssertOwner(owner, comp2);
DebugTools.AssertOwner(owner, comp3);
DebugTools.AssertOwner(owner, comp4);
Owner = owner;
Comp1 = comp1;
Comp2 = comp2;
Comp3 = comp3;
Comp4 = comp4;
}
public static implicit operator Entity<T1, T2, T3, T4>((EntityUid Owner, T1 Comp1, T2 Comp2, T3 Comp3, T4 Comp4) tuple)
{
return new Entity<T1, T2, T3, T4>(tuple.Owner, tuple.Comp1, tuple.Comp2, tuple.Comp3, tuple.Comp4);
}
public static implicit operator Entity<T1?, T2?, T3?, T4?>(EntityUid owner)
{
return new Entity<T1?, T2?, T3?, T4?>(owner, default, default, default, default);
}
public static implicit operator EntityUid(Entity<T1, T2, T3, T4> ent)
{
return ent.Owner;
}
public static implicit operator T1(Entity<T1, T2, T3, T4> ent)
{
return ent.Comp1;
}
public static implicit operator T2(Entity<T1, T2, T3, T4> ent)
{
return ent.Comp2;
}
public static implicit operator T3(Entity<T1, T2, T3, T4> ent)
{
return ent.Comp3;
}
public static implicit operator T4(Entity<T1, T2, T3, T4> ent)
{
return ent.Comp4;
}
public readonly void Deconstruct(out EntityUid owner, out T1 comp1, out T2 comp2, out T3 comp3, out T4 comp4)
{
owner = Owner;
comp1 = Comp1;
comp2 = Comp2;
comp3 = Comp3;
comp4 = Comp4;
}
}
public record struct Entity<T1, T2, T3, T4, T5>
where T1 : IComponent? where T2 : IComponent? where T3 : IComponent? where T4 : IComponent? where T5 : IComponent?
{
public EntityUid Owner;
public T1 Comp1;
public T2 Comp2;
public T3 Comp3;
public T4 Comp4;
public T5 Comp5;
public Entity(EntityUid owner, T1 comp1, T2 comp2, T3 comp3, T4 comp4, T5 comp5)
{
DebugTools.AssertOwner(owner, comp1);
DebugTools.AssertOwner(owner, comp2);
DebugTools.AssertOwner(owner, comp3);
DebugTools.AssertOwner(owner, comp4);
DebugTools.AssertOwner(owner, comp5);
Owner = owner;
Comp1 = comp1;
Comp2 = comp2;
Comp3 = comp3;
Comp4 = comp4;
Comp5 = comp5;
}
public static implicit operator Entity<T1, T2, T3, T4, T5>((EntityUid Owner, T1 Comp1, T2 Comp2, T3 Comp3, T4 Comp4, T5 Comp5) tuple)
{
return new Entity<T1, T2, T3, T4, T5>(tuple.Owner, tuple.Comp1, tuple.Comp2, tuple.Comp3, tuple.Comp4, tuple.Comp5);
}
public static implicit operator Entity<T1?, T2?, T3?, T4?, T5?>(EntityUid owner)
{
return new Entity<T1?, T2?, T3?, T4?, T5?>(owner, default, default, default, default, default);
}
public static implicit operator EntityUid(Entity<T1, T2, T3, T4, T5> ent)
{
return ent.Owner;
}
public static implicit operator T1(Entity<T1, T2, T3, T4, T5> ent)
{
return ent.Comp1;
}
public static implicit operator T2(Entity<T1, T2, T3, T4, T5> ent)
{
return ent.Comp2;
}
public static implicit operator T3(Entity<T1, T2, T3, T4, T5> ent)
{
return ent.Comp3;
}
public static implicit operator T4(Entity<T1, T2, T3, T4, T5> ent)
{
return ent.Comp4;
}
public static implicit operator T5(Entity<T1, T2, T3, T4, T5> ent)
{
return ent.Comp5;
}
public readonly void Deconstruct(out EntityUid owner, out T1 comp1, out T2 comp2, out T3 comp3, out T4 comp4, out T5 comp5)
{
owner = Owner;
comp1 = Comp1;
comp2 = Comp2;
comp3 = Comp3;
comp4 = Comp4;
comp5 = Comp5;
}
}
public record struct Entity<T1, T2, T3, T4, T5, T6>
where T1 : IComponent? where T2 : IComponent? where T3 : IComponent? where T4 : IComponent? where T5 : IComponent? where T6 : IComponent?
{
public EntityUid Owner;
public T1 Comp1;
public T2 Comp2;
public T3 Comp3;
public T4 Comp4;
public T5 Comp5;
public T6 Comp6;
public Entity(EntityUid owner, T1 comp1, T2 comp2, T3 comp3, T4 comp4, T5 comp5, T6 comp6)
{
DebugTools.AssertOwner(owner, comp1);
DebugTools.AssertOwner(owner, comp2);
DebugTools.AssertOwner(owner, comp3);
DebugTools.AssertOwner(owner, comp4);
DebugTools.AssertOwner(owner, comp5);
DebugTools.AssertOwner(owner, comp6);
Owner = owner;
Comp1 = comp1;
Comp2 = comp2;
Comp3 = comp3;
Comp4 = comp4;
Comp5 = comp5;
Comp6 = comp6;
}
public static implicit operator Entity<T1, T2, T3, T4, T5, T6>((EntityUid Owner, T1 Comp1, T2 Comp2, T3 Comp3, T4 Comp4, T5 Comp5, T6 Comp6) tuple)
{
return new Entity<T1, T2, T3, T4, T5, T6>(tuple.Owner, tuple.Comp1, tuple.Comp2, tuple.Comp3, tuple.Comp4, tuple.Comp5, tuple.Comp6);
}
public static implicit operator Entity<T1?, T2?, T3?, T4?, T5?, T6?>(EntityUid owner)
{
return new Entity<T1?, T2?, T3?, T4?, T5?, T6?>(owner, default, default, default, default, default, default);
}
public static implicit operator EntityUid(Entity<T1, T2, T3, T4, T5, T6> ent)
{
return ent.Owner;
}
public static implicit operator T1(Entity<T1, T2, T3, T4, T5, T6> ent)
{
return ent.Comp1;
}
public static implicit operator T2(Entity<T1, T2, T3, T4, T5, T6> ent)
{
return ent.Comp2;
}
public static implicit operator T3(Entity<T1, T2, T3, T4, T5, T6> ent)
{
return ent.Comp3;
}
public static implicit operator T4(Entity<T1, T2, T3, T4, T5, T6> ent)
{
return ent.Comp4;
}
public static implicit operator T5(Entity<T1, T2, T3, T4, T5, T6> ent)
{
return ent.Comp5;
}
public static implicit operator T6(Entity<T1, T2, T3, T4, T5, T6> ent)
{
return ent.Comp6;
}
public readonly void Deconstruct(out EntityUid owner, out T1 comp1, out T2 comp2, out T3 comp3, out T4 comp4, out T5 comp5, out T6 comp6)
{
owner = Owner;
comp1 = Comp1;
comp2 = Comp2;
comp3 = Comp3;
comp4 = Comp4;
comp5 = Comp5;
comp6 = Comp6;
}
}
public record struct Entity<T1, T2, T3, T4, T5, T6, T7>
where T1 : IComponent? where T2 : IComponent? where T3 : IComponent? where T4 : IComponent? where T5 : IComponent? where T6 : IComponent? where T7 : IComponent?
{
public EntityUid Owner;
public T1 Comp1;
public T2 Comp2;
public T3 Comp3;
public T4 Comp4;
public T5 Comp5;
public T6 Comp6;
public T7 Comp7;
public Entity(EntityUid owner, T1 comp1, T2 comp2, T3 comp3, T4 comp4, T5 comp5, T6 comp6, T7 comp7)
{
DebugTools.AssertOwner(owner, comp1);
DebugTools.AssertOwner(owner, comp2);
DebugTools.AssertOwner(owner, comp3);
DebugTools.AssertOwner(owner, comp4);
DebugTools.AssertOwner(owner, comp5);
DebugTools.AssertOwner(owner, comp6);
DebugTools.AssertOwner(owner, comp7);
Owner = owner;
Comp1 = comp1;
Comp2 = comp2;
Comp3 = comp3;
Comp4 = comp4;
Comp5 = comp5;
Comp6 = comp6;
Comp7 = comp7;
}
public static implicit operator Entity<T1, T2, T3, T4, T5, T6, T7>((EntityUid Owner, T1 Comp1, T2 Comp2, T3 Comp3, T4 Comp4, T5 Comp5, T6 Comp6, T7 Comp7) tuple)
{
return new Entity<T1, T2, T3, T4, T5, T6, T7>(tuple.Owner, tuple.Comp1, tuple.Comp2, tuple.Comp3, tuple.Comp4, tuple.Comp5, tuple.Comp6, tuple.Comp7);
}
public static implicit operator Entity<T1?, T2?, T3?, T4?, T5?, T6?, T7?>(EntityUid owner)
{
return new Entity<T1?, T2?, T3?, T4?, T5?, T6?, T7?>(owner, default, default, default, default, default, default, default);
}
public static implicit operator EntityUid(Entity<T1, T2, T3, T4, T5, T6, T7> ent)
{
return ent.Owner;
}
public static implicit operator T1(Entity<T1, T2, T3, T4, T5, T6, T7> ent)
{
return ent.Comp1;
}
public static implicit operator T2(Entity<T1, T2, T3, T4, T5, T6, T7> ent)
{
return ent.Comp2;
}
public static implicit operator T3(Entity<T1, T2, T3, T4, T5, T6, T7> ent)
{
return ent.Comp3;
}
public static implicit operator T4(Entity<T1, T2, T3, T4, T5, T6, T7> ent)
{
return ent.Comp4;
}
public static implicit operator T5(Entity<T1, T2, T3, T4, T5, T6, T7> ent)
{
return ent.Comp5;
}
public static implicit operator T6(Entity<T1, T2, T3, T4, T5, T6, T7> ent)
{
return ent.Comp6;
}
public static implicit operator T7(Entity<T1, T2, T3, T4, T5, T6, T7> ent)
{
return ent.Comp7;
}
public readonly void Deconstruct(out EntityUid owner, out T1 comp1, out T2 comp2, out T3 comp3, out T4 comp4, out T5 comp5, out T6 comp6, out T7 comp7)
{
owner = Owner;
comp1 = Comp1;
comp2 = Comp2;
comp3 = Comp3;
comp4 = Comp4;
comp5 = Comp5;
comp6 = Comp6;
comp7 = Comp7;
}
}
public record struct Entity<T1, T2, T3, T4, T5, T6, T7, T8>
where T1 : IComponent? where T2 : IComponent? where T3 : IComponent? where T4 : IComponent? where T5 : IComponent? where T6 : IComponent? where T7 : IComponent? where T8 : IComponent?
{
public EntityUid Owner;
public T1 Comp1;
public T2 Comp2;
public T3 Comp3;
public T4 Comp4;
public T5 Comp5;
public T6 Comp6;
public T7 Comp7;
public T8 Comp8;
public Entity(EntityUid owner, T1 comp1, T2 comp2, T3 comp3, T4 comp4, T5 comp5, T6 comp6, T7 comp7, T8 comp8)
{
DebugTools.AssertOwner(owner, comp1);
DebugTools.AssertOwner(owner, comp2);
DebugTools.AssertOwner(owner, comp3);
DebugTools.AssertOwner(owner, comp4);
DebugTools.AssertOwner(owner, comp5);
DebugTools.AssertOwner(owner, comp6);
DebugTools.AssertOwner(owner, comp7);
DebugTools.AssertOwner(owner, comp8);
Owner = owner;
Comp1 = comp1;
Comp2 = comp2;
Comp3 = comp3;
Comp4 = comp4;
Comp5 = comp5;
Comp6 = comp6;
Comp7 = comp7;
Comp8 = comp8;
}
public static implicit operator Entity<T1, T2, T3, T4, T5, T6, T7, T8>((EntityUid Owner, T1 Comp1, T2 Comp2, T3 Comp3, T4 Comp4, T5 Comp5, T6 Comp6, T7 Comp7, T8 Comp8) tuple)
{
return new Entity<T1, T2, T3, T4, T5, T6, T7, T8>(tuple.Owner, tuple.Comp1, tuple.Comp2, tuple.Comp3, tuple.Comp4, tuple.Comp5, tuple.Comp6, tuple.Comp7, tuple.Comp8);
}
public static implicit operator Entity<T1?, T2?, T3?, T4?, T5?, T6?, T7?, T8?>(EntityUid owner)
{
return new Entity<T1?, T2?, T3?, T4?, T5?, T6?, T7?, T8?>(owner, default, default, default, default, default, default, default, default);
}
public static implicit operator EntityUid(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Owner;
}
public static implicit operator T1(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Comp1;
}
public static implicit operator T2(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Comp2;
}
public static implicit operator T3(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Comp3;
}
public static implicit operator T4(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Comp4;
}
public static implicit operator T5(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Comp5;
}
public static implicit operator T6(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Comp6;
}
public static implicit operator T7(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Comp7;
}
public static implicit operator T8(Entity<T1, T2, T3, T4, T5, T6, T7, T8> ent)
{
return ent.Comp8;
}
public readonly void Deconstruct(out EntityUid owner, out T1 comp1, out T2 comp2, out T3 comp3, out T4 comp4, out T5 comp5, out T6 comp6, out T7 comp7, out T8 comp8)
{
owner = Owner;
comp1 = Comp1;
comp2 = Comp2;
comp3 = Comp3;
comp4 = Comp4;
comp5 = Comp5;
comp6 = Comp6;
comp7 = Comp7;
comp8 = Comp8;
}
}

View File

@@ -46,6 +46,12 @@ namespace Robust.Shared.GameObjects
where TComp : IComponent
where TEvent : notnull;
void SubscribeLocalEvent<TComp, TEvent>(
EntityEventRefHandler<TComp, TEvent> handler,
Type orderType, Type[]? before = null, Type[]? after = null)
where TComp : IComponent
where TEvent : notnull;
#endregion
void UnsubscribeLocalEvent<TComp, TEvent>()
@@ -294,6 +300,25 @@ namespace Robust.Shared.GameObjects
RegisterCommon(typeof(TEvent), orderData, out _);
}
public void SubscribeLocalEvent<TComp, TEvent>(EntityEventRefHandler<TComp, TEvent> handler, Type orderType,
Type[]? before = null,
Type[]? after = null) where TComp : IComponent where TEvent : notnull
{
void EventHandler(EntityUid uid, IComponent comp, ref TEvent args)
=> handler(new Entity<TComp>(uid, (TComp) comp), ref args);
var orderData = new OrderingData(orderType, before ?? Array.Empty<Type>(), after ?? Array.Empty<Type>());
EntSubscribe<TEvent>(
CompIdx.Index<TComp>(),
typeof(TComp),
typeof(TEvent),
EventHandler,
orderData);
RegisterCommon(typeof(TEvent), orderData, out _);
}
/// <inheritdoc />
public void UnsubscribeLocalEvent<TComp, TEvent>()
where TComp : IComponent
@@ -718,4 +743,8 @@ namespace Robust.Shared.GameObjects
public delegate void ComponentEventRefHandler<in TComp, TEvent>(EntityUid uid, TComp component, ref TEvent args)
where TComp : IComponent
where TEvent : notnull;
public delegate void EntityEventRefHandler<TComp, TEvent>(Entity<TComp> ent, ref TEvent args)
where TComp : IComponent
where TEvent : notnull;
}

View File

@@ -106,9 +106,7 @@ namespace Robust.Shared.GameObjects
public void InitializeComponents(EntityUid uid, MetaDataComponent? metadata = null)
{
#pragma warning disable CS0618 // Type or member is obsolete
DebugTools.Assert(metadata == null || metadata.Owner == uid);
#pragma warning restore CS0618 // Type or member is obsolete
DebugTools.AssertOwner(uid, metadata);
metadata ??= GetComponent<MetaDataComponent>(uid);
DebugTools.Assert(metadata.EntityLifeStage == EntityLifeStage.PreInit);
metadata.EntityLifeStage = EntityLifeStage.Initializing;
@@ -175,9 +173,6 @@ namespace Robust.Shared.GameObjects
public IComponent AddComponent(EntityUid uid, ushort netId, MetaDataComponent? meta = null)
{
var newComponent = _componentFactory.GetComponent(netId);
#pragma warning disable CS0618 // Type or member is obsolete
newComponent.Owner = uid;
#pragma warning restore CS0618 // Type or member is obsolete
AddComponent(uid, newComponent, metadata: meta);
return newComponent;
}
@@ -185,9 +180,6 @@ namespace Robust.Shared.GameObjects
public T AddComponent<T>(EntityUid uid) where T : IComponent, new()
{
var newComponent = _componentFactory.GetComponent<T>();
#pragma warning disable CS0618 // Type or member is obsolete
newComponent.Owner = uid;
#pragma warning restore CS0618 // Type or member is obsolete
AddComponent(uid, newComponent);
return newComponent;
}
@@ -486,7 +478,9 @@ namespace Robust.Shared.GameObjects
{
if (component == null) throw new ArgumentNullException(nameof(component));
#pragma warning disable CS0618 // Type or member is obsolete
if (component.Owner != uid)
#pragma warning restore CS0618 // Type or member is obsolete
throw new InvalidOperationException("Component is not owned by entity.");
if (component.Deleted) return;
@@ -1121,9 +1115,9 @@ namespace Robust.Shared.GameObjects
}
else
{
foreach (var t1Comp in comps.Values)
foreach (var (uid, t1Comp) in comps)
{
if (t1Comp.Deleted || !MetaQuery.TryGetComponentInternal(t1Comp.Owner, out var metaComp)) continue;
if (t1Comp.Deleted || !MetaQuery.TryGetComponentInternal(uid, out var metaComp)) continue;
if (metaComp.EntityPaused) continue;
@@ -1164,7 +1158,7 @@ namespace Robust.Shared.GameObjects
if (!trait2.TryGetValue(uid, out var t2Comp) || t2Comp.Deleted)
continue;
if (t1Comp.Deleted || !metaComps.TryGetValue(t1Comp.Owner, out var metaComp)) continue;
if (t1Comp.Deleted || !metaComps.TryGetValue(uid, out var metaComp)) continue;
var meta = (MetaDataComponent)metaComp;
@@ -1216,7 +1210,7 @@ namespace Robust.Shared.GameObjects
if (!trait3.TryGetValue(uid, out var t3Comp) || t3Comp.Deleted)
continue;
if (t1Comp.Deleted || !metaComps.TryGetValue(t1Comp.Owner, out var metaComp)) continue;
if (t1Comp.Deleted || !metaComps.TryGetValue(uid, out var metaComp)) continue;
var meta = (MetaDataComponent)metaComp;
@@ -1279,7 +1273,7 @@ namespace Robust.Shared.GameObjects
if (!trait4.TryGetValue(uid, out var t4Comp) || t4Comp.Deleted)
continue;
if (t1Comp.Deleted || !metaComps.TryGetValue(t1Comp.Owner, out var metaComp)) continue;
if (t1Comp.Deleted || !metaComps.TryGetValue(uid, out var metaComp)) continue;
var meta = (MetaDataComponent)metaComp;
@@ -1449,9 +1443,7 @@ namespace Robust.Shared.GameObjects
{
if (component != null)
{
#pragma warning disable CS0618 // Type or member is obsolete
DebugTools.Assert(uid == component.Owner, "Specified Entity is not the component's Owner!");
#pragma warning restore CS0618 // Type or member is obsolete
DebugTools.AssertOwner(uid, component);
return true;
}
@@ -1544,9 +1536,7 @@ namespace Robust.Shared.GameObjects
{
if (component != null)
{
#pragma warning disable CS0618 // Type or member is obsolete
DebugTools.Assert(uid == component.Owner, "Specified Entity is not the component's Owner!");
#pragma warning restore CS0618 // Type or member is obsolete
DebugTools.AssertOwner(uid, component);
return true;
}

View File

@@ -395,12 +395,19 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
public virtual void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null)
{
if (component.LifeStage >= ComponentLifeStage.Removing || !component.NetSyncEnabled)
Dirty(new Entity<IComponent>(uid, component), meta);
}
public virtual void Dirty(Entity<IComponent> ent, MetaDataComponent? meta = null)
{
if (ent.Comp.LifeStage >= ComponentLifeStage.Removing || !ent.Comp.NetSyncEnabled)
return;
DebugTools.AssertOwner(uid, component);
DirtyEntity(uid, meta);
component.LastModifiedTick = CurrentTick;
DebugTools.AssertOwner(ent, ent.Comp);
DirtyEntity(ent, meta);
#pragma warning disable CS0618 // Type or member is obsolete
ent.Comp.LastModifiedTick = CurrentTick;
#pragma warning restore CS0618 // Type or member is obsolete
}
/// <summary>
@@ -659,7 +666,9 @@ namespace Robust.Shared.GameObjects
// allocate the required TransformComponent
var xformComp = Unsafe.As<TransformComponent>(_componentFactory.GetComponent(_xformReg));
#pragma warning disable CS0618 // Type or member is obsolete
xformComp.Owner = uid;
#pragma warning restore CS0618 // Type or member is obsolete
AddComponentInternal(uid, xformComp, false, true, metadata);
return uid;

View File

@@ -220,6 +220,15 @@ public partial class EntitySystem
EntityManager.Dirty(uid, component, meta);
}
/// <summary>
/// Marks a component as dirty. This also implicitly dirties the entity this component belongs to.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void Dirty<T>(Entity<T> ent, MetaDataComponent? meta = null) where T : IComponent
{
EntityManager.Dirty(ent.Owner, ent.Comp, meta);
}
/// <summary>
/// Retrieves the name of an entity.
/// </summary>
@@ -396,7 +405,7 @@ public partial class EntitySystem
return true;
}
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
/// <inheritdoc cref="IEntityManager.ToPrettyString(EntityUid, MetaDataComponent?)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[return: NotNullIfNotNull("uid")]
protected EntityStringRepresentation? ToPrettyString(EntityUid? uid, MetaDataComponent? metadata = null)
@@ -404,7 +413,7 @@ public partial class EntitySystem
return EntityManager.ToPrettyString(uid, metadata);
}
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
/// <inheritdoc cref="IEntityManager.ToPrettyString(EntityUid, MetaDataComponent?)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[return: NotNullIfNotNull("netEntity")]
protected EntityStringRepresentation? ToPrettyString(NetEntity? netEntity)
@@ -412,17 +421,17 @@ public partial class EntitySystem
return EntityManager.ToPrettyString(netEntity);
}
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
/// <inheritdoc cref="IEntityManager.ToPrettyString(EntityUid, MetaDataComponent?)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metadata)
=> EntityManager.ToPrettyString(uid, metadata);
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
/// <inheritdoc cref="IEntityManager.ToPrettyString(EntityUid, MetaDataComponent?)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected EntityStringRepresentation ToPrettyString(EntityUid uid)
=> EntityManager.ToPrettyString(uid);
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
/// <inheritdoc cref="IEntityManager.ToPrettyString(EntityUid, MetaDataComponent?)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected EntityStringRepresentation ToPrettyString(NetEntity netEntity)
=> EntityManager.ToPrettyString(netEntity);
@@ -458,7 +467,7 @@ public partial class EntitySystem
/// <inheritdoc cref="IEntityManager.TryGetComponent&lt;T&gt;(EntityUid, out T)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected bool TryComp<T>(EntityUid uid, [NotNullWhen(true)] out T? comp)
protected bool TryComp<T>(EntityUid uid, [NotNullWhen(true)] out T? comp) where T : IComponent
{
return EntityManager.TryGetComponent(uid, out comp);
}
@@ -479,7 +488,7 @@ public partial class EntitySystem
/// <inheritdoc cref="IEntityManager.TryGetComponent&lt;T&gt;(EntityUid?, out T)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected bool TryComp<T>([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)] out T? comp)
protected bool TryComp<T>([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)] out T? comp) where T : IComponent
{
if (!uid.HasValue)
{

View File

@@ -19,7 +19,7 @@ namespace Robust.Shared.GameObjects
protected bool Resolve<TComp>(EntityUid uid, [NotNullWhen(true)] ref TComp? component, bool logMissing = true)
where TComp : IComponent
{
DebugTools.Assert(component == null || uid == component.Owner, "Specified Entity is not the component's Owner!");
DebugTools.AssertOwner(uid, component);
if (component != null && !component.Deleted)
return true;

View File

@@ -138,6 +138,18 @@ namespace Robust.Shared.GameObjects
_subscriptions.Add(new SubLocal<TComp, TEvent>());
}
protected void SubscribeLocalEvent<TComp, TEvent>(
EntityEventRefHandler<TComp, TEvent> handler,
Type[]? before = null, Type[]? after = null)
where TComp : IComponent
where TEvent : notnull
{
EntityManager.EventBus.SubscribeLocalEvent(handler, GetType(), before, after);
_subscriptions ??= new();
_subscriptions.Add(new SubLocal<TComp, TEvent>());
}
private void ShutdownSubscriptions()
{
if (_subscriptions == null)

View File

@@ -4,7 +4,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Robust.Shared.GameObjects
@@ -153,7 +152,7 @@ namespace Robust.Shared.GameObjects
set
{
if (MetaData is {} metaData)
metaData.EntityName = value;
IoCManager.Resolve<IEntityManager>().System<MetaDataSystem>().SetEntityName(this, value, metaData);
}
}
@@ -163,8 +162,11 @@ namespace Robust.Shared.GameObjects
get => MetaData?.EntityDescription ?? string.Empty;
set
{
if (MetaData is {} metaData)
metaData.EntityDescription = value;
if (MetaData is { } metaData)
{
var entManager = IoCManager.Resolve<IEntityManager>();
entManager.System<MetaDataSystem>().SetEntityDescription(this, value, metaData);
}
}
}

View File

@@ -87,6 +87,8 @@ namespace Robust.Shared.GameObjects
public void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null);
public void Dirty(Entity<IComponent> ent, MetaDataComponent? meta = null);
public void QueueDeleteEntity(EntityUid? uid);
public bool IsQueuedForDeletion(EntityUid uid);

View File

@@ -184,8 +184,11 @@ public readonly struct NetEntity : IEquatable<NetEntity>, IComparable<NetEntity>
get => MetaData?.EntityName ?? string.Empty;
set
{
if (MetaData is {} metaData)
metaData.EntityName = value;
if (MetaData is { } metaData)
{
var entManager = IoCManager.Resolve<IEntityManager>();
entManager.System<MetaDataSystem>().SetEntityName(entManager.GetEntity(this), value, metaData);
}
}
}
@@ -195,8 +198,11 @@ public readonly struct NetEntity : IEquatable<NetEntity>, IComparable<NetEntity>
get => MetaData?.EntityDescription ?? string.Empty;
set
{
if (MetaData is {} metaData)
metaData.EntityDescription = value;
if (MetaData is { } metaData)
{
var entManager = IoCManager.Resolve<IEntityManager>();
entManager.System<MetaDataSystem>().SetEntityDescription(entManager.GetEntity(this), value, metaData);
}
}
}

View File

@@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using Robust.Shared.Collections;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
@@ -273,9 +272,14 @@ public sealed partial class EntityLookupSystem
public HashSet<EntityUid> GetEntitiesIntersecting(MapId mapId, Box2 worldAABB, LookupFlags flags = DefaultFlags)
{
if (mapId == MapId.Nullspace) return new HashSet<EntityUid>();
var intersecting = new HashSet<EntityUid>();
GetEntitiesIntersecting(mapId, worldAABB, intersecting, flags);
return intersecting;
}
public void GetEntitiesIntersecting(MapId mapId, Box2 worldAABB, HashSet<EntityUid> intersecting, LookupFlags flags = DefaultFlags)
{
if (mapId == MapId.Nullspace) return;
// Get grid entities
var state = (this, _map, intersecting, worldAABB, _transform, flags);
@@ -309,8 +313,6 @@ public sealed partial class EntityLookupSystem
var localAABB = _transform.GetInvWorldMatrix(mapUid).TransformBox(worldAABB);
AddEntitiesIntersecting(mapUid, intersecting, localAABB, flags);
AddContained(intersecting, flags);
return intersecting;
}
#endregion
@@ -546,16 +548,23 @@ public sealed partial class EntityLookupSystem
public HashSet<EntityUid> GetEntitiesInRange(MapId mapId, Vector2 worldPos, float range,
LookupFlags flags = DefaultFlags)
{
var entities = new HashSet<EntityUid>();
GetEntitiesInRange(mapId, worldPos, range, entities, flags);
return entities;
}
public void GetEntitiesInRange(MapId mapId, Vector2 worldPos, float range, HashSet<EntityUid> entities, LookupFlags flags = DefaultFlags)
{
DebugTools.Assert(range > 0, "Range must be a positive float");
if (mapId == MapId.Nullspace)
return new HashSet<EntityUid>();
return;
// TODO: Actual circles
var rangeVec = new Vector2(range, range);
var worldAABB = new Box2(worldPos - rangeVec, worldPos + rangeVec);
return GetEntitiesIntersecting(mapId, worldAABB, flags);
GetEntitiesIntersecting(mapId, worldAABB, entities, flags);
}
#endregion

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Robust.Shared.Collections;
using Robust.Shared.Map;
@@ -20,6 +21,18 @@ public sealed partial class EntityLookupSystem
Box2 worldAABB,
LookupFlags flags,
EntityQuery<T> query) where T : IComponent
{
var intersectingEntities = new HashSet<Entity<T>>();
AddEntitiesIntersecting(lookupUid, intersectingEntities, worldAABB, flags, query);
intersecting.UnionWith(intersectingEntities.Select(e => e.Comp));
}
private void AddEntitiesIntersecting<T>(
EntityUid lookupUid,
HashSet<Entity<T>> intersecting,
Box2 worldAABB,
LookupFlags flags,
EntityQuery<T> query) where T : IComponent
{
var lookup = _broadQuery.GetComponent(lookupUid);
var invMatrix = _transform.GetInvWorldMatrix(lookupUid);
@@ -28,48 +41,48 @@ public sealed partial class EntityLookupSystem
if ((flags & LookupFlags.Dynamic) != 0x0)
{
lookup.DynamicTree.QueryAabb(ref state, static (ref (HashSet<T> intersecting, EntityQuery<T> query) tuple, in FixtureProxy value) =>
lookup.DynamicTree.QueryAabb(ref state, static (ref (HashSet<Entity<T>> intersecting, EntityQuery<T> query) tuple, in FixtureProxy value) =>
{
if (!tuple.query.TryGetComponent(value.Entity, out var comp))
return true;
tuple.intersecting.Add(comp);
tuple.intersecting.Add((value.Entity, comp));
return true;
}, localAABB, (flags & LookupFlags.Approximate) != 0x0);
}
if ((flags & (LookupFlags.Static)) != 0x0)
{
lookup.StaticTree.QueryAabb(ref state, static (ref (HashSet<T> intersecting, EntityQuery<T> query) tuple, in FixtureProxy value) =>
lookup.StaticTree.QueryAabb(ref state, static (ref (HashSet<Entity<T>> intersecting, EntityQuery<T> query) tuple, in FixtureProxy value) =>
{
if (!tuple.query.TryGetComponent(value.Entity, out var comp))
return true;
tuple.intersecting.Add(comp);
tuple.intersecting.Add((value.Entity, comp));
return true;
}, localAABB, (flags & LookupFlags.Approximate) != 0x0);
}
if ((flags & LookupFlags.StaticSundries) == LookupFlags.StaticSundries)
{
lookup.StaticSundriesTree.QueryAabb(ref state, static (ref (HashSet<T> intersecting, EntityQuery<T> query) tuple, in EntityUid value) =>
lookup.StaticSundriesTree.QueryAabb(ref state, static (ref (HashSet<Entity<T>> intersecting, EntityQuery<T> query) tuple, in EntityUid value) =>
{
if (!tuple.query.TryGetComponent(value, out var comp))
return true;
tuple.intersecting.Add(comp);
tuple.intersecting.Add((value, comp));
return true;
}, localAABB, (flags & LookupFlags.Approximate) != 0x0);
}
if ((flags & LookupFlags.Sundries) != 0x0)
{
lookup.SundriesTree.QueryAabb(ref state, static (ref (HashSet<T> intersecting, EntityQuery<T> query) tuple, in EntityUid value) =>
lookup.SundriesTree.QueryAabb(ref state, static (ref (HashSet<Entity<T>> intersecting, EntityQuery<T> query) tuple, in EntityUid value) =>
{
if (!tuple.query.TryGetComponent(value, out var comp))
return true;
tuple.intersecting.Add(comp);
tuple.intersecting.Add((value, comp));
return true;
}, localAABB, (flags & LookupFlags.Approximate) != 0x0);
}
@@ -166,15 +179,38 @@ public sealed partial class EntityLookupSystem
}
}
private void RecursiveAdd<T>(EntityUid uid, ref ValueList<Entity<T>> toAdd, EntityQuery<T> query) where T : IComponent
{
var childEnumerator = _xformQuery.GetComponent(uid).ChildEnumerator;
while (childEnumerator.MoveNext(out var child))
{
if (query.TryGetComponent(child.Value, out var compies))
{
toAdd.Add((child.Value, compies));
}
RecursiveAdd(child.Value, ref toAdd, query);
}
}
[Obsolete]
private void AddContained<T>(HashSet<T> intersecting, LookupFlags flags, EntityQuery<T> query) where T : IComponent
{
var intersectingEntities = new HashSet<Entity<T>>();
AddContained(intersectingEntities, flags, query);
intersecting.UnionWith(intersectingEntities.Select(e => e.Comp));
}
private void AddContained<T>(HashSet<Entity<T>> intersecting, LookupFlags flags, EntityQuery<T> query) where T : IComponent
{
if ((flags & LookupFlags.Contained) == 0x0) return;
var toAdd = new ValueList<T>();
var toAdd = new ValueList<Entity<T>>();
foreach (var comp in intersecting)
{
if (!_containerQuery.TryGetComponent(comp.Owner, out var conManager)) continue;
if (!_containerQuery.TryGetComponent(comp, out var conManager)) continue;
foreach (var con in conManager.GetAllContainers())
{
@@ -182,7 +218,7 @@ public sealed partial class EntityLookupSystem
{
if (query.TryGetComponent(contained, out var compies))
{
toAdd.Add(compies);
toAdd.Add((contained, compies));
}
RecursiveAdd(contained, ref toAdd, query);
@@ -272,13 +308,20 @@ public sealed partial class EntityLookupSystem
return false;
}
[Obsolete]
public HashSet<IComponent> GetComponentsIntersecting(Type type, MapId mapId, Box2 worldAABB, LookupFlags flags = DefaultFlags)
{
var intersectingEntities = new HashSet<Entity<IComponent>>();
GetEntitiesIntersecting(type, mapId, worldAABB, intersectingEntities, flags);
var intersecting = new HashSet<IComponent>(intersectingEntities.Select(e => e.Comp));
return intersecting;
}
public void GetEntitiesIntersecting(Type type, MapId mapId, Box2 worldAABB, HashSet<Entity<IComponent>> intersecting, LookupFlags flags = DefaultFlags)
{
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
if (mapId == MapId.Nullspace)
return new HashSet<IComponent>();
var intersecting = new HashSet<IComponent>();
return;
if (!UseBoundsQuery(type, worldAABB.Height * worldAABB.Width))
{
@@ -294,7 +337,7 @@ public sealed partial class EntityLookupSystem
continue;
}
intersecting.Add(comp);
intersecting.Add((uid, comp));
}
}
else
@@ -310,35 +353,39 @@ public sealed partial class EntityLookupSystem
Box2 worldAABB,
LookupFlags flags,
EntityQuery<IComponent> query,
HashSet<IComponent> intersecting) tuple) =>
HashSet<Entity<IComponent>> intersecting) tuple) =>
{
tuple.system.AddComponentsIntersecting(uid, tuple.intersecting, tuple.worldAABB, tuple.flags, tuple.query);
tuple.system.AddEntitiesIntersecting(uid, tuple.intersecting, tuple.worldAABB, tuple.flags, tuple.query);
return true;
}, (flags & LookupFlags.Approximate) != 0x0);
// Get map entities
var mapUid = _mapManager.GetMapEntityId(mapId);
AddComponentsIntersecting(mapUid, intersecting, worldAABB, flags, query);
AddEntitiesIntersecting(mapUid, intersecting, worldAABB, flags, query);
AddContained(intersecting, flags, query);
}
return intersecting;
}
[Obsolete]
public HashSet<T> GetComponentsIntersecting<T>(MapId mapId, Box2 worldAABB, LookupFlags flags = DefaultFlags) where T : IComponent
{
if (mapId == MapId.Nullspace) return new HashSet<T>();
var intersectingEntities = new HashSet<Entity<T>>();
GetEntitiesIntersecting(mapId, worldAABB, intersectingEntities, flags);
return new HashSet<T>(intersectingEntities.Select(e => e.Comp));
}
var intersecting = new HashSet<T>();
public void GetEntitiesIntersecting<T>(MapId mapId, Box2 worldAABB, HashSet<Entity<T>> entities, LookupFlags flags = DefaultFlags) where T : IComponent
{
if (mapId == MapId.Nullspace) return;
if (!UseBoundsQuery<T>(worldAABB.Height * worldAABB.Width))
{
var query = AllEntityQuery<T, TransformComponent>();
while (query.MoveNext(out var comp, out var xform))
while (query.MoveNext(out var uid, out var comp, out var xform))
{
if (xform.MapID != mapId || !worldAABB.Contains(_transform.GetWorldPosition(xform))) continue;
intersecting.Add(comp);
entities.Add((uid, comp));
}
}
else
@@ -346,27 +393,25 @@ public sealed partial class EntityLookupSystem
var query = GetEntityQuery<T>();
// Get grid entities
var state = (this, worldAABB, flags, query, intersecting);
var state = (this, worldAABB, flags, query, entities);
_mapManager.FindGridsIntersecting(mapId, worldAABB, ref state,
static (EntityUid uid, MapGridComponent grid,
ref (EntityLookupSystem system,
Box2 worldAABB,
LookupFlags flags,
EntityQuery<T> query,
HashSet<T> intersecting) tuple) =>
{
tuple.system.AddComponentsIntersecting(uid, tuple.intersecting, tuple.worldAABB, tuple.flags, tuple.query);
return true;
}, (flags & LookupFlags.Approximate) != 0x0);
ref (EntityLookupSystem system,
Box2 worldAABB,
LookupFlags flags,
EntityQuery<T> query,
HashSet<Entity<T>> intersecting) tuple) =>
{
tuple.system.AddEntitiesIntersecting(uid, tuple.intersecting, tuple.worldAABB, tuple.flags, tuple.query);
return true;
}, (flags & LookupFlags.Approximate) != 0x0);
// Get map entities
var mapUid = _mapManager.GetMapEntityId(mapId);
AddComponentsIntersecting(mapUid, intersecting, worldAABB, flags, query);
AddContained(intersecting, flags, query);
AddEntitiesIntersecting(mapUid, entities, worldAABB, flags, query);
AddContained(entities, flags, query);
}
return intersecting;
}
#endregion
@@ -378,21 +423,56 @@ public sealed partial class EntityLookupSystem
var mapPos = coordinates.ToMap(EntityManager, _transform);
return GetComponentsInRange<T>(mapPos, range);
}
public void GetEntitiesInRange<T>(EntityCoordinates coordinates, float range, HashSet<Entity<T>> entities) where T : IComponent
{
var mapPos = coordinates.ToMap(EntityManager, _transform);
GetEntitiesInRange(mapPos, range, entities);
}
public HashSet<Entity<T>> GetEntitiesInRange<T>(EntityCoordinates coordinates, float range) where T : IComponent
{
var entities = new HashSet<Entity<T>>();
GetEntitiesInRange(coordinates, range, entities);
return entities;
}
#endregion
#region MapCoordinates
[Obsolete]
public HashSet<IComponent> GetComponentsInRange(Type type, MapCoordinates coordinates, float range)
{
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
return GetComponentsInRange(type, coordinates.MapId, coordinates.Position, range);
}
public HashSet<Entity<IComponent>> GetEntitiesInRange(Type type, MapCoordinates coordinates, float range)
{
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
var entities = new HashSet<Entity<IComponent>>();
GetEntitiesInRange(type, coordinates.MapId, coordinates.Position, range, entities);
return entities;
}
public HashSet<T> GetComponentsInRange<T>(MapCoordinates coordinates, float range) where T : IComponent
{
return GetComponentsInRange<T>(coordinates.MapId, coordinates.Position, range);
}
public void GetEntitiesInRange<T>(MapCoordinates coordinates, float range, HashSet<Entity<T>> entities) where T : IComponent
{
GetEntitiesInRange(coordinates.MapId, coordinates.Position, range, entities);
}
public HashSet<Entity<T>> GetEntitiesInRange<T>(MapCoordinates coordinates, float range) where T : IComponent
{
var entities = new HashSet<Entity<T>>();
GetEntitiesInRange(coordinates.MapId, coordinates.Position, range, entities);
return entities;
}
#endregion
#region MapId
@@ -411,31 +491,47 @@ public sealed partial class EntityLookupSystem
return AnyComponentsIntersecting(type, mapId, worldAABB);
}
[Obsolete]
public HashSet<IComponent> GetComponentsInRange(Type type, MapId mapId, Vector2 worldPos, float range)
{
var entities = new HashSet<Entity<IComponent>>();
GetEntitiesInRange(type, mapId, worldPos, range, entities);
return new HashSet<IComponent>(entities.Select(e => e.Comp));
}
public void GetEntitiesInRange(Type type, MapId mapId, Vector2 worldPos, float range, HashSet<Entity<IComponent>> entities)
{
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
DebugTools.Assert(range > 0, "Range must be a positive float");
if (mapId == MapId.Nullspace) return new HashSet<IComponent>();
if (mapId == MapId.Nullspace) return;
// TODO: Actual circles
var rangeVec = new Vector2(range, range);
var worldAABB = new Box2(worldPos - rangeVec, worldPos + rangeVec);
return GetComponentsIntersecting(type, mapId, worldAABB);
GetEntitiesIntersecting(type, mapId, worldAABB, entities);
}
[Obsolete]
public HashSet<T> GetComponentsInRange<T>(MapId mapId, Vector2 worldPos, float range) where T : IComponent
{
var entities = new HashSet<Entity<T>>();
GetEntitiesInRange(mapId, worldPos, range, entities);
return new HashSet<T>(entities.Select(e => e.Comp));
}
public void GetEntitiesInRange<T>(MapId mapId, Vector2 worldPos, float range, HashSet<Entity<T>> entities) where T : IComponent
{
DebugTools.Assert(range > 0, "Range must be a positive float");
if (mapId == MapId.Nullspace) return new HashSet<T>();
if (mapId == MapId.Nullspace) return;
// TODO: Actual circles
var rangeVec = new Vector2(range, range);
var worldAABB = new Box2(worldPos - rangeVec, worldPos + rangeVec);
return GetComponentsIntersecting<T>(mapId, worldAABB);
GetEntitiesIntersecting(mapId, worldAABB, entities);
}
#endregion

View File

@@ -31,14 +31,15 @@ internal sealed class PrototypeReloadSystem : EntitySystem
if (!eventArgs.ByType.TryGetValue(typeof(EntityPrototype), out var set))
return;
foreach (var metadata in EntityQuery<MetaDataComponent>())
var query = EntityQueryEnumerator<MetaDataComponent>();
while (query.MoveNext(out var uid, out var metadata))
{
var id = metadata.EntityPrototype?.ID;
if (id == null || !set.Modified.ContainsKey(id))
continue;
var proto = _prototypes.Index<EntityPrototype>(id);
UpdateEntity(metadata.Owner, metadata, proto);
UpdateEntity(uid, metadata, proto);
}
}
@@ -78,7 +79,6 @@ internal sealed class PrototypeReloadSystem : EntitySystem
{
var data = newPrototype.Components[name];
var component = _componentFactory.GetComponent(name);
component.Owner = entity;
EntityManager.AddComponent(entity, component);
}

View File

@@ -6,12 +6,12 @@ using System.Numerics;
using System.Runtime.CompilerServices;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
using Robust.Shared.Map.Components;
using Robust.Shared.Map.Enumerators;
using Robust.Shared.Map.Events;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -296,7 +296,7 @@ public abstract partial class SharedMapSystem
MapManager.SuppressOnTileChanged = false;
if (modified.Count != 0)
RaiseLocalEvent(uid, new GridModifiedEvent(component, modified), true);
RaiseLocalEvent(uid, new GridModifiedEvent(uid, component, modified), true);
}
private void OnGridGetState(EntityUid uid, MapGridComponent component, ref ComponentGetState args)

View File

@@ -1,11 +1,9 @@
using JetBrains.Annotations;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using System.Collections.Generic;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using System.Linq;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Timing;
@@ -156,6 +154,11 @@ namespace Robust.Shared.GameObjects
/// </summary>
public sealed class GridModifiedEvent : EntityEventArgs
{
/// <summary>
/// The id of the grid being changed.
/// </summary>
public EntityUid GridEnt { get; }
/// <summary>
/// Grid being changed.
/// </summary>
@@ -169,8 +172,9 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// Creates a new instance of this class.
/// </summary>
public GridModifiedEvent(MapGridComponent grid, IReadOnlyCollection<(Vector2i position, Tile tile)> modified)
public GridModifiedEvent(EntityUid gridEnt, MapGridComponent grid, IReadOnlyCollection<(Vector2i position, Tile tile)> modified)
{
GridEnt = gridEnt;
Grid = grid;
Modified = modified;
}

View File

@@ -25,7 +25,7 @@ namespace Robust.Shared.Map.Components
// This field is used for deserialization internally in the map loader.
// If you want to remove this, you would have to restructure the map save file.
[DataField("index")] internal int GridIndex = 0;
[DataField("index")] internal int GridIndex;
// the grid section now writes the grid's EntityUID. as long as existing maps get updated (just a load+save),
// this can be removed
@@ -75,70 +75,83 @@ namespace Robust.Shared.Map.Components
#region TileAccess
[Obsolete("Use the MapSystem method")]
public TileRef GetTileRef(MapCoordinates coords)
{
return MapSystem.GetTileRef(Owner, this, coords);
}
[Obsolete("Use the MapSystem method")]
public TileRef GetTileRef(EntityCoordinates coords)
{
return MapSystem.GetTileRef(Owner, this, coords);
}
[Obsolete("Use the MapSystem method")]
public TileRef GetTileRef(Vector2i tileCoordinates)
{
return MapSystem.GetTileRef(Owner, this, tileCoordinates);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<TileRef> GetAllTiles(bool ignoreEmpty = true)
{
return MapSystem.GetAllTiles(Owner, this, ignoreEmpty);
}
[Obsolete("Use the MapSystem method")]
public GridTileEnumerator GetAllTilesEnumerator(bool ignoreEmpty = true)
{
return MapSystem.GetAllTilesEnumerator(Owner, this, ignoreEmpty);
}
[Obsolete("Use the MapSystem method")]
public void SetTile(EntityCoordinates coords, Tile tile)
{
MapSystem.SetTile(Owner, this, coords, tile);
}
[Obsolete("Use the MapSystem method")]
public void SetTile(Vector2i gridIndices, Tile tile)
{
MapSystem.SetTile(Owner, this, gridIndices, tile);
}
[Obsolete("Use the MapSystem method")]
public void SetTiles(List<(Vector2i GridIndices, Tile Tile)> tiles)
{
MapSystem.SetTiles(Owner, this, tiles);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<TileRef> GetLocalTilesIntersecting(Box2Rotated localArea, bool ignoreEmpty = true,
Predicate<TileRef>? predicate = null)
{
return MapSystem.GetLocalTilesIntersecting(Owner, this, localArea, ignoreEmpty, predicate);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<TileRef> GetTilesIntersecting(Box2Rotated worldArea, bool ignoreEmpty = true,
Predicate<TileRef>? predicate = null)
{
return MapSystem.GetTilesIntersecting(Owner, this, worldArea, ignoreEmpty, predicate);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<TileRef> GetTilesIntersecting(Box2 worldArea, bool ignoreEmpty = true,
Predicate<TileRef>? predicate = null)
{
return MapSystem.GetTilesIntersecting(Owner, this, worldArea, ignoreEmpty, predicate);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<TileRef> GetLocalTilesIntersecting(Box2 localArea, bool ignoreEmpty = true,
Predicate<TileRef>? predicate = null)
{
return MapSystem.GetLocalTilesIntersecting(Owner, this, localArea, ignoreEmpty, predicate);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<TileRef> GetTilesIntersecting(Circle worldArea, bool ignoreEmpty = true,
Predicate<TileRef>? predicate = null)
{
@@ -149,16 +162,19 @@ namespace Robust.Shared.Map.Components
#region ChunkAccess
[Obsolete("Use the MapSystem method")]
internal bool TryGetChunk(Vector2i chunkIndices, [NotNullWhen(true)] out MapChunk? chunk)
{
return MapSystem.TryGetChunk(Owner, this, chunkIndices, out chunk);
}
[Obsolete("Use the MapSystem method")]
internal IReadOnlyDictionary<Vector2i, MapChunk> GetMapChunks()
{
return MapSystem.GetMapChunks(Owner, this);
}
[Obsolete("Use the MapSystem method")]
internal ChunkEnumerator GetMapChunks(Box2Rotated worldArea)
{
return MapSystem.GetMapChunks(Owner, this, worldArea);
@@ -168,56 +184,67 @@ namespace Robust.Shared.Map.Components
#region SnapGridAccess
[Obsolete("Use the MapSystem method")]
public IEnumerable<EntityUid> GetAnchoredEntities(MapCoordinates coords)
{
return MapSystem.GetAnchoredEntities(Owner, this, coords);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<EntityUid> GetAnchoredEntities(Vector2i pos)
{
return MapSystem.GetAnchoredEntities(Owner, this, pos);
}
[Obsolete("Use the MapSystem method")]
public AnchoredEntitiesEnumerator GetAnchoredEntitiesEnumerator(Vector2i pos)
{
return MapSystem.GetAnchoredEntitiesEnumerator(Owner, this, pos);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<EntityUid> GetLocalAnchoredEntities(Box2 localAABB)
{
return MapSystem.GetLocalAnchoredEntities(Owner, this, localAABB);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<EntityUid> GetAnchoredEntities(Box2 worldAABB)
{
return MapSystem.GetAnchoredEntities(Owner, this, worldAABB);
}
[Obsolete("Use the MapSystem method")]
public Vector2i TileIndicesFor(EntityCoordinates coords)
{
return MapSystem.TileIndicesFor(Owner, this, coords);
}
[Obsolete("Use the MapSystem method")]
public Vector2i TileIndicesFor(MapCoordinates worldPos)
{
return MapSystem.TileIndicesFor(Owner, this, worldPos);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<EntityUid> GetInDir(EntityCoordinates position, Direction dir)
{
return MapSystem.GetInDir(Owner, this, position, dir);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<EntityUid> GetLocal(EntityCoordinates coords)
{
return MapSystem.GetLocal(Owner, this, coords);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<EntityUid> GetCardinalNeighborCells(EntityCoordinates coords)
{
return MapSystem.GetCardinalNeighborCells(Owner, this, coords);
}
[Obsolete("Use the MapSystem method")]
public IEnumerable<EntityUid> GetCellsInSquareArea(EntityCoordinates coords, int n)
{
return MapSystem.GetCellsInSquareArea(Owner, this, coords, n);
@@ -225,66 +252,79 @@ namespace Robust.Shared.Map.Components
#endregion
[Obsolete("Use the MapSystem method")]
public Vector2 WorldToLocal(Vector2 posWorld)
{
return MapSystem.WorldToLocal(Owner, this, posWorld);
}
[Obsolete("Use the MapSystem method")]
public EntityCoordinates MapToGrid(MapCoordinates posWorld)
{
return MapSystem.MapToGrid(Owner, posWorld);
}
[Obsolete("Use the MapSystem method")]
public Vector2 LocalToWorld(Vector2 posLocal)
{
return MapSystem.LocalToWorld(Owner, this, posLocal);
}
[Obsolete("Use the MapSystem method")]
public Vector2i WorldToTile(Vector2 posWorld)
{
return MapSystem.WorldToTile(Owner, this, posWorld);
}
[Obsolete("Use the MapSystem method")]
public Vector2i LocalToTile(EntityCoordinates coordinates)
{
return MapSystem.LocalToTile(Owner, this, coordinates);
}
[Obsolete("Use the MapSystem method")]
public Vector2i CoordinatesToTile(EntityCoordinates coords)
{
return MapSystem.CoordinatesToTile(Owner, this, coords);
}
[Obsolete("Use the MapSystem method")]
public bool CollidesWithGrid(Vector2i indices)
{
return MapSystem.CollidesWithGrid(Owner, this, indices);
}
[Obsolete("Use the MapSystem method")]
public Vector2i GridTileToChunkIndices(Vector2i gridTile)
{
return MapSystem.GridTileToChunkIndices(Owner, this, gridTile);
}
[Obsolete("Use the MapSystem method")]
public EntityCoordinates GridTileToLocal(Vector2i gridTile)
{
return MapSystem.GridTileToLocal(Owner, this, gridTile);
}
[Obsolete("Use the MapSystem method")]
public Vector2 GridTileToWorldPos(Vector2i gridTile)
{
return MapSystem.GridTileToWorldPos(Owner, this, gridTile);
}
[Obsolete("Use the MapSystem method")]
public MapCoordinates GridTileToWorld(Vector2i gridTile)
{
return MapSystem.GridTileToWorld(Owner, this, gridTile);
}
[Obsolete("Use the MapSystem method")]
public bool TryGetTileRef(Vector2i indices, out TileRef tile)
{
return MapSystem.TryGetTileRef(Owner, this, indices, out tile);
}
[Obsolete("Use the MapSystem method")]
public bool TryGetTileRef(EntityCoordinates coords, out TileRef tile)
{
return MapSystem.TryGetTileRef(Owner, this, coords, out tile);

View File

@@ -87,11 +87,21 @@ namespace Robust.Shared.Map
MapGridComponent CreateGrid(MapId currentMapId, ushort chunkSize = 16);
MapGridComponent CreateGrid(MapId currentMapId, in GridCreateOptions options);
MapGridComponent CreateGrid(MapId currentMapId);
Entity<MapGridComponent> CreateGridEntity(MapId currentMapId, GridCreateOptions? options = null);
[Obsolete("Use GetComponent<MapGridComponent>(uid)")]
MapGridComponent GetGrid(EntityUid gridId);
[Obsolete("Use TryGetComponent(uid, out MapGridComponent? grid)")]
bool TryGetGrid([NotNullWhen(true)] EntityUid? euid, [NotNullWhen(true)] out MapGridComponent? grid);
[Obsolete("Use HasComponent<MapGridComponent>(uid)")]
bool GridExists([NotNullWhen(true)] EntityUid? euid);
IEnumerable<MapGridComponent> GetAllMapGrids(MapId mapId);
IEnumerable<Entity<MapGridComponent>> GetAllGrids(MapId mapId);
/// <summary>
/// Attempts to find the map grid under the map location.
/// </summary>
@@ -131,10 +141,13 @@ namespace Robust.Shared.Map
void FindGridsIntersecting<TState>(MapId mapId, Box2 worldAABB, ref TState state, GridCallback<TState> callback, bool approx = false, bool includeMap = true);
void FindGridsIntersecting(MapId mapId, Box2 worldAABB, ref List<Entity<MapGridComponent>> state, bool approx = false, bool includeMap = true);
void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, GridCallback callback, bool approx = false, bool includeMap = true);
void FindGridsIntersecting<TState>(MapId mapId, Box2Rotated worldBounds, ref TState state, GridCallback<TState> callback, bool approx = false, bool includeMap = true);
void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, ref List<Entity<MapGridComponent>> state, bool approx = false, bool includeMap = true);
/// <summary>
/// Returns the grids intersecting this AABB.

View File

@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
// All the obsolete warnings about GridId are probably useless here.
@@ -47,6 +44,12 @@ internal partial class MapManager
return CreateGrid(currentMapId, GridCreateOptions.Default);
}
public Entity<MapGridComponent> CreateGridEntity(MapId currentMapId, GridCreateOptions? options = null)
{
options ??= GridCreateOptions.Default;
return CreateGrid(currentMapId, options.Value.ChunkSize, default);
}
[Obsolete("Use GetComponent<MapGridComponent>(uid)")]
public MapGridComponent GetGrid(EntityUid gridId)
{
@@ -61,6 +64,7 @@ internal partial class MapManager
return EntityManager.HasComponent<MapGridComponent>(uid);
}
[Obsolete("Use TryGetComponent(uid, out MapGridComponent? grid)")]
public bool TryGetGrid([NotNullWhen(true)] EntityUid? euid, [MaybeNullWhen(false)] out MapGridComponent grid)
{
if (EntityManager.TryGetComponent(euid, out MapGridComponent? comp))
@@ -81,11 +85,24 @@ internal partial class MapManager
public IEnumerable<MapGridComponent> GetAllMapGrids(MapId mapId)
{
var xformQuery = EntityManager.GetEntityQuery<TransformComponent>();
var query = EntityManager.AllEntityQueryEnumerator<MapGridComponent, TransformComponent>();
while (query.MoveNext(out var grid, out var xform))
{
if (xform.MapID != mapId)
yield return grid;
}
}
return EntityManager.EntityQuery<MapGridComponent>(true)
.Where(c => xformQuery.GetComponent(c.Owner).MapID == mapId)
.Select(c => c);
public IEnumerable<Entity<MapGridComponent>> GetAllGrids(MapId mapId)
{
var query = EntityManager.AllEntityQueryEnumerator<MapGridComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var grid, out var xform))
{
if (xform.MapID != mapId)
continue;
yield return (uid, grid);
}
}
public virtual void DeleteGrid(EntityUid euid)
@@ -135,7 +152,7 @@ internal partial class MapManager
EntityManager.EventBus.RaiseLocalEvent(euid, ref ev, true);
}
protected MapGridComponent CreateGrid(MapId currentMapId, ushort chunkSize, EntityUid forcedGridEuid)
protected Entity<MapGridComponent> CreateGrid(MapId currentMapId, ushort chunkSize, EntityUid forcedGridEuid)
{
var gridEnt = EntityManager.CreateEntityUninitialized(null, forcedGridEuid);
@@ -155,6 +172,6 @@ internal partial class MapManager
EntityManager.System<MetaDataSystem>().SetEntityName(gridEnt, $"grid", meta);
EntityManager.InitializeComponents(gridEnt, meta);
EntityManager.StartComponents(gridEnt);
return grid;
return (gridEnt, grid);
}
}

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Map.Components;
using Robust.Shared.Utility;
@@ -211,22 +209,21 @@ internal partial class MapManager
if (actualId != MapId.Nullspace) // nullspace isn't bound to an entity
{
var mapComps = EntityManager.EntityQuery<MapComponent>(true);
MapComponent? result = null;
foreach (var mapComp in mapComps)
Entity<MapComponent> result = default;
var query = EntityManager.AllEntityQueryEnumerator<MapComponent>();
while (query.MoveNext(out var uid, out var map))
{
if (mapComp.MapId != actualId)
if (map.MapId != actualId)
continue;
result = mapComp;
result = (uid, map);
break;
}
if (result != null)
if (result != default)
{
DebugTools.Assert(mapId != null);
_mapEntities.Add(actualId, result.Owner);
_mapEntities.Add(actualId, result);
_sawmill.Debug($"Rebinding map {actualId} to entity {result.Owner}");
}
else

View File

@@ -96,6 +96,17 @@ internal partial class MapManager
state = state2.state;
}
public void FindGridsIntersecting(MapId mapId, Box2 worldAABB, ref List<Entity<MapGridComponent>> state,
bool approx = false, bool includeMap = true)
{
FindGridsIntersecting(mapId, worldAABB, ref state, static (EntityUid uid, MapGridComponent grid,
ref List<Entity<MapGridComponent>> list) =>
{
list.Add((uid, grid));
return true;
}, approx, includeMap);
}
public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, GridCallback callback, bool approx = false,
bool includeMap = true)
{
@@ -108,6 +119,17 @@ internal partial class MapManager
FindGridsIntersecting(mapId, worldBounds.CalcBoundingBox(), ref state, callback, approx, includeMap);
}
public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, ref List<Entity<MapGridComponent>> state,
bool approx = false, bool includeMap = true)
{
FindGridsIntersecting(mapId, worldBounds, ref state, static (EntityUid uid, MapGridComponent grid,
ref List<Entity<MapGridComponent>> list) =>
{
list.Add((uid, grid));
return true;
}, approx, includeMap);
}
private bool IsIntersecting(
Box2 aabb,
EntityUid gridUid,

View File

@@ -9,9 +9,9 @@ namespace Robust.Shared.Physics.Events
[ByRefEvent]
public readonly struct CollisionLayerChangeEvent
{
public readonly PhysicsComponent Body;
public readonly Entity<PhysicsComponent> Body;
public CollisionLayerChangeEvent(PhysicsComponent body)
public CollisionLayerChangeEvent(Entity<PhysicsComponent> body)
{
Body = body;
}

View File

@@ -5,7 +5,6 @@ using Robust.Shared.Collections;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
@@ -354,7 +353,7 @@ namespace Robust.Shared.Physics.Systems
if (oldLayer != layer)
{
var ev = new CollisionLayerChangeEvent(body);
var ev = new CollisionLayerChangeEvent((uid, body));
RaiseLocalEvent(ref ev);
}

View File

@@ -26,7 +26,7 @@ public abstract partial class SharedJointSystem : EntitySystem
// To avoid issues with component states we'll queue up all dirty joints and check it every tick to see if
// we can delete the component.
private readonly HashSet<JointComponent> _dirtyJoints = new();
private readonly HashSet<Entity<JointComponent>> _dirtyJoints = new();
protected readonly HashSet<Joint> AddedJoints = new();
protected readonly List<Joint> ToRemove = new();
@@ -115,8 +115,8 @@ public abstract partial class SharedJointSystem : EntitySystem
foreach (var joint in _dirtyJoints)
{
if (joint.Deleted || joint.JointCount != 0) continue;
EntityManager.RemoveComponent<JointComponent>(joint.Owner);
if (joint.Comp.Deleted || joint.Comp.JointCount != 0) continue;
EntityManager.RemoveComponent<JointComponent>(joint);
}
_dirtyJoints.Clear();
@@ -139,7 +139,8 @@ public abstract partial class SharedJointSystem : EntitySystem
jointComponentA ??= EnsureComp<JointComponent>(aUid);
jointComponentB ??= EnsureComp<JointComponent>(bUid);
DebugTools.Assert(jointComponentA.Owner == aUid && jointComponentB.Owner == bUid);
DebugTools.AssertOwner(aUid, jointComponentA);
DebugTools.AssertOwner(bUid, jointComponentB);
DebugTools.AssertNotEqual(jointComponentA.Relay, bUid);
DebugTools.AssertNotEqual(jointComponentB.Relay, aUid);
@@ -198,8 +199,8 @@ public abstract partial class SharedJointSystem : EntitySystem
Dirty(bUid, jointComponentB);
// Also flag these for checking juusssttt in case.
_dirtyJoints.Add(jointComponentA);
_dirtyJoints.Add(jointComponentB);
_dirtyJoints.Add((aUid, jointComponentA));
_dirtyJoints.Add((bUid, jointComponentB));
// Note: creating a joint doesn't wake the bodies.
// Raise broadcast last so we can do both sides of directed first.
@@ -522,12 +523,12 @@ public abstract partial class SharedJointSystem : EntitySystem
// Originally I logged these but because of prediction the client can just nuke them multiple times in a row
// because each body has its own JointComponent, bleh.
if (!EntityManager.TryGetComponent<JointComponent>(bodyAUid, out var jointComponentA))
if (!TryComp<JointComponent>(bodyAUid, out var jointComponentA))
{
return;
}
if (!EntityManager.TryGetComponent<JointComponent>(bodyBUid, out var jointComponentB))
if (!TryComp<JointComponent>(bodyBUid, out var jointComponentB))
{
return;
}
@@ -559,12 +560,12 @@ public abstract partial class SharedJointSystem : EntitySystem
if (!jointComponentA.Deleted)
{
Dirty(jointComponentA);
Dirty(bodyAUid, jointComponentA);
}
if (!jointComponentB.Deleted)
{
Dirty(jointComponentB);
Dirty(bodyBUid, jointComponentB);
}
if (jointComponentA.Deleted && jointComponentB.Deleted)
@@ -599,8 +600,8 @@ public abstract partial class SharedJointSystem : EntitySystem
}
// We can't just check up front due to how prediction works.
_dirtyJoints.Add(jointComponentA);
_dirtyJoints.Add(jointComponentB);
_dirtyJoints.Add((bodyAUid, jointComponentA));
_dirtyJoints.Add((bodyBUid, jointComponentB));
}
#endregion

View File

@@ -22,6 +22,7 @@
* PhysicsComponent is heavily modified from Box2D.
*/
using System;
using System.Numerics;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
@@ -371,8 +372,16 @@ public partial class SharedPhysicsSystem
Dirty(body);
}
[Obsolete("Use SetAwake with EntityUid<PhysicsComponent>")]
public void SetAwake(EntityUid uid, PhysicsComponent body, bool value, bool updateSleepTime = true)
{
SetAwake(new Entity<PhysicsComponent>(uid, body), value, updateSleepTime);
}
public void SetAwake(Entity<PhysicsComponent> ent, bool value, bool updateSleepTime = true)
{
var uid = ent.Owner;
var body = ent.Comp;
if (body.Awake == value)
return;
@@ -396,7 +405,7 @@ public partial class SharedPhysicsSystem
if (updateSleepTime)
SetSleepTime(body, 0);
Dirty(body);
Dirty(ent);
}
public void TrySetBodyType(EntityUid uid, BodyType value, FixturesComponent? manager = null, PhysicsComponent? body = null, TransformComponent? xform = null)

View File

@@ -150,11 +150,12 @@ namespace Robust.Shared.Physics.Systems
/// <summary>
/// Get all entities colliding with a certain body.
/// </summary>
public IEnumerable<PhysicsComponent> GetCollidingEntities(MapId mapId, in Box2Rotated worldBounds)
public IEnumerable<Entity<PhysicsComponent>> GetCollidingEntities(MapId mapId, in Box2Rotated worldBounds)
{
if (mapId == MapId.Nullspace) return Array.Empty<PhysicsComponent>();
if (mapId == MapId.Nullspace)
return Array.Empty<Entity<PhysicsComponent>>();
var bodies = new HashSet<PhysicsComponent>();
var bodies = new HashSet<Entity<PhysicsComponent>>();
foreach (var (uid, broadphase) in _broadphase.GetBroadphases(mapId, worldBounds.CalcBoundingBox()))
{
@@ -162,12 +163,12 @@ namespace Robust.Shared.Physics.Systems
foreach (var proxy in broadphase.StaticTree.QueryAabb(gridAABB, false))
{
bodies.Add(proxy.Body);
bodies.Add(new Entity<PhysicsComponent>(proxy.Entity, proxy.Body));
}
foreach (var proxy in broadphase.DynamicTree.QueryAabb(gridAABB, false))
{
bodies.Add(proxy.Body);
bodies.Add(new Entity<PhysicsComponent>(proxy.Entity, proxy.Body));
}
}

View File

@@ -250,7 +250,6 @@ namespace Robust.Shared.Prototypes
if (!entityManager.TryGetComponent(entity, compReg.Idx, out var component))
{
var newComponent = factory.GetComponent(compName);
newComponent.Owner = entity;
entityManager.AddComponent(entity, newComponent);
component = newComponent;
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
@@ -98,7 +97,9 @@ namespace Robust.Shared.Utility
// Whenever .owner is removed this will need to be replaced by something.
// As long as components are just reference types, we could just get the component and check if the references are equal?
#pragma warning disable CS0618 // Type or member is obsolete
if (component.Owner != uid)
#pragma warning restore CS0618 // Type or member is obsolete
throw new DebugAssertException($"Entity {uid} is not the owner of the component. Component: {component.GetType().Name}");
}

View File

@@ -26,10 +26,10 @@ namespace Robust.UnitTesting.Client.GameObjects.Components
mapManager.CreateMap(TestMapId);
// Adds two grids to use in tests.
var gridA = mapManager.CreateGrid(TestMapId);
var gridB = mapManager.CreateGrid(TestMapId);
var gridA = mapManager.CreateGridEntity(TestMapId);
var gridB = mapManager.CreateGridEntity(TestMapId);
return (sim, gridA.Owner, gridB.Owner);
return (sim, gridA, gridB);
}
/// <summary>
@@ -47,18 +47,18 @@ namespace Robust.UnitTesting.Client.GameObjects.Components
var gridB = mapMan.GetGrid(gridIdB);
// Arrange
var initialPos = new EntityCoordinates(gridA.Owner, new Vector2(0, 0));
var initialPos = new EntityCoordinates(gridIdA, new Vector2(0, 0));
var parent = entMan.SpawnEntity(null, initialPos);
var child = entMan.SpawnEntity(null, initialPos);
var parentTrans = entMan.GetComponent<TransformComponent>(parent);
var childTrans = entMan.GetComponent<TransformComponent>(child);
ComponentHandleState handleState;
var compState = new TransformComponentState(new Vector2(5, 5), new Angle(0), entMan.GetNetEntity(gridB.Owner), false, false);
var compState = new TransformComponentState(new Vector2(5, 5), new Angle(0), entMan.GetNetEntity(gridIdB), false, false);
handleState = new ComponentHandleState(compState, null);
xformSystem.OnHandleState(parent, parentTrans, ref handleState);
compState = new TransformComponentState(new Vector2(6, 6), new Angle(0), entMan.GetNetEntity(gridB.Owner), false, false);
compState = new TransformComponentState(new Vector2(6, 6), new Angle(0), entMan.GetNetEntity(gridIdB), false, false);
handleState = new ComponentHandleState(compState, null);
xformSystem.OnHandleState(child, childTrans, ref handleState);
// World pos should be 6, 6 now.
@@ -90,7 +90,7 @@ namespace Robust.UnitTesting.Client.GameObjects.Components
var gridB = mapMan.GetGrid(gridIdB);
// Arrange
var initalPos = new EntityCoordinates(gridA.Owner, new Vector2(0, 0));
var initalPos = new EntityCoordinates(gridIdA, new Vector2(0, 0));
var node1 = entMan.SpawnEntity(null, initalPos);
var node2 = entMan.SpawnEntity(null, initalPos);
var node3 = entMan.SpawnEntity(null, initalPos);
@@ -103,7 +103,7 @@ namespace Robust.UnitTesting.Client.GameObjects.Components
var node2Trans = entMan.GetComponent<TransformComponent>(node2);
var node3Trans = entMan.GetComponent<TransformComponent>(node3);
var compState = new TransformComponentState(new Vector2(6, 6), Angle.FromDegrees(135), entMan.GetNetEntity(gridB.Owner), false, false);
var compState = new TransformComponentState(new Vector2(6, 6), Angle.FromDegrees(135), entMan.GetNetEntity(gridIdB), false, false);
var handleState = new ComponentHandleState(compState, null);
xformSystem.OnHandleState(node1, node1Trans, ref handleState);

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using JetBrains.Annotations;
using NUnit.Framework;
using Robust.Server.Containers;
using Robust.Shared.Containers;
@@ -195,7 +193,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
var sim = SimulationFactory();
var containerSys = sim.Resolve<IEntitySystemManager>().GetEntitySystem<ContainerSystem>();
var grid = sim.Resolve<IMapManager>().CreateGrid(new MapId(1)).Owner;
var grid = sim.Resolve<IMapManager>().CreateGridEntity(new MapId(1)).Owner;
var entity = sim.SpawnEntity(null, new EntityCoordinates(new EntityUid(1), new Vector2(0, 0)));
var container = containerSys.MakeContainer<Container>(entity, "dummy");

View File

@@ -1,17 +1,12 @@
using System.IO;
using System.Numerics;
using System.Reflection;
using Moq;
using NUnit.Framework;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Server.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Timing;
@@ -40,9 +35,9 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
";
private MapId MapA;
private MapGridComponent GridA = default!;
private Entity<MapGridComponent> GridA = default!;
private MapId MapB;
private MapGridComponent GridB = default!;
private Entity<MapGridComponent> GridB = default!;
private static readonly EntityCoordinates InitialPos = new(new EntityUid(1), new Vector2(0, 0));
@@ -63,10 +58,10 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
// build the net dream
MapA = MapManager.CreateMap();
GridA = MapManager.CreateGrid(MapA);
GridA = MapManager.CreateGridEntity(MapA);
MapB = MapManager.CreateMap();
GridB = MapManager.CreateGrid(MapB);
GridB = MapManager.CreateGridEntity(MapB);
//NOTE: The grids have not moved, so we can assert worldpos == localpos for the test
}
@@ -89,8 +84,8 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
var childTrans = EntityManager.GetComponent<TransformComponent>(child);
// that are not on the same map
parentTrans.Coordinates = new EntityCoordinates(GridA.Owner, new Vector2(5, 5));
childTrans.Coordinates = new EntityCoordinates(GridB.Owner, new Vector2(4, 4));
parentTrans.Coordinates = new EntityCoordinates(GridA, new Vector2(5, 5));
childTrans.Coordinates = new EntityCoordinates(GridB, new Vector2(4, 4));
// if they are parented, the child keeps its world position, but moves to the parents map
childTrans.AttachParent(parentTrans);
@@ -100,7 +95,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
{
Assert.That(childTrans.MapID, Is.EqualTo(parentTrans.MapID));
Assert.That(childTrans.GridUid, Is.EqualTo(parentTrans.GridUid));
Assert.That(childTrans.Coordinates, Is.EqualTo(new EntityCoordinates(parentTrans.Owner, new Vector2(-1, -1))));
Assert.That(childTrans.Coordinates, Is.EqualTo(new EntityCoordinates(parent, new Vector2(-1, -1))));
Assert.That(childTrans.WorldPosition, Is.EqualTo(new Vector2(4, 4)));
});

View File

@@ -54,8 +54,8 @@ public sealed class PvsSystemTests : RobustIntegrationTest
{
var mapId = mapMan.CreateMap();
map = mapMan.GetMapEntityId(mapId);
var gridComp = mapMan.CreateGrid(mapId);
gridComp.SetTile(Vector2i.Zero, new Tile(1));
var gridComp = mapMan.CreateGridEntity(mapId);
gridComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
grid = gridComp.Owner;
});

View File

@@ -44,10 +44,10 @@ namespace Robust.UnitTesting.Shared
var mapManager = server.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var theMapSpotBeingUsed = new Box2(Vector2.Zero, Vector2.One);
grid.SetTile(new Vector2i(), new Tile(1));
grid.Comp.SetTile(new Vector2i(), new Tile(1));
Assert.That(lookup.GetEntitiesIntersecting(mapId, theMapSpotBeingUsed).ToList().Count, Is.EqualTo(0));
@@ -66,7 +66,7 @@ namespace Robust.UnitTesting.Shared
Assert.That(lookup.GetEntitiesIntersecting(mapId, theMapSpotBeingUsed).ToList().Count, Is.EqualTo(1));
entManager.DeleteEntity(dummy);
mapManager.DeleteGrid(grid.Owner);
mapManager.DeleteGrid(grid);
mapManager.DeleteMap(mapId);
}
}

View File

@@ -8,7 +8,6 @@ using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Timing;
@@ -42,7 +41,6 @@ namespace Robust.UnitTesting.Shared.GameObjects
Assert.DoesNotThrow(() => client.SetConnectTarget(server));
client.Post(() =>
{
clientNetManager.ClientConnect(null!, 0, null!);
});
@@ -58,16 +56,18 @@ namespace Robust.UnitTesting.Shared.GameObjects
EntityUid entityUid = default!;
var cContainerSys = cEntManager.System<ContainerSystem>();
var sContainerSys = sEntManager.System<SharedContainerSystem>();
var sMetadataSys = sEntManager.System<MetaDataSystem>();
await server.WaitAssertion(() =>
{
var containerSys = sEntManager.System<SharedContainerSystem>();
mapId = sMapManager.CreateMap();
mapPos = new MapCoordinates(new Vector2(0, 0), mapId);
entityUid = sEntManager.SpawnEntity(null, mapPos);
sEntManager.GetComponent<MetaDataComponent>(entityUid).EntityName = "Container";
containerSys.EnsureContainer<Container>(entityUid, "dummy");
sMetadataSys.SetEntityName(entityUid, "Container");
sContainerSys.EnsureContainer<Container>(entityUid, "dummy");
// Setup PVS
sEntManager.AddComponent<EyeComponent>(entityUid);
@@ -85,11 +85,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
EntityUid itemUid = default!;
await server.WaitAssertion(() =>
{
var containerSys = sEntManager.System<SharedContainerSystem>();
itemUid = sEntManager.SpawnEntity(null, mapPos);
sEntManager.GetComponent<MetaDataComponent>(itemUid).EntityName = "Item";
var container = containerSys.EnsureContainer<Container>(entityUid, "dummy");
sMetadataSys.SetEntityName(itemUid, "Item");
var container = sContainerSys.EnsureContainer<Container>(entityUid, "dummy");
Assert.That(container.Insert(itemUid));
// Move item out of PVS so that it doesn't get sent to the client
@@ -114,9 +112,8 @@ namespace Robust.UnitTesting.Shared.GameObjects
Assert.That(container.ContainedEntities.Count, Is.EqualTo(0));
Assert.That(container.ExpectedEntities.Count, Is.EqualTo(1));
var containerSystem = cEntManager.System<ContainerSystem>();
Assert.That(containerSystem.ExpectedEntities.ContainsKey(sEntManager.GetNetEntity(itemUid)));
Assert.That(containerSystem.ExpectedEntities.Count, Is.EqualTo(1));
Assert.That(cContainerSys.ExpectedEntities.ContainsKey(sEntManager.GetNetEntity(itemUid)));
Assert.That(cContainerSys.ExpectedEntities.Count, Is.EqualTo(1));
});
await server.WaitAssertion(() =>
@@ -140,9 +137,8 @@ namespace Robust.UnitTesting.Shared.GameObjects
Assert.That(container.ContainedEntities.Count, Is.EqualTo(1));
Assert.That(container.ExpectedEntities.Count, Is.EqualTo(0));
var containerSystem = cEntManager.System<ContainerSystem>();
Assert.That(!containerSystem.ExpectedEntities.ContainsKey(sEntManager.GetNetEntity(itemUid)));
Assert.That(containerSystem.ExpectedEntities, Is.Empty);
Assert.That(!cContainerSys.ExpectedEntities.ContainsKey(sEntManager.GetNetEntity(itemUid)));
Assert.That(cContainerSys.ExpectedEntities, Is.Empty);
});
}
@@ -188,16 +184,18 @@ namespace Robust.UnitTesting.Shared.GameObjects
EntityUid sItemUid = default!;
NetEntity netEnt = default;
var cContainerSys = cEntManager.System<ContainerSystem>();
var sContainerSys = sEntManager.System<SharedContainerSystem>();
var sMetadataSys = sEntManager.System<MetaDataSystem>();
await server.WaitAssertion(() =>
{
var containerSys = sEntManager.System<SharedContainerSystem>();
mapId = sMapManager.CreateMap();
mapPos = new MapCoordinates(new Vector2(0, 0), mapId);
sEntityUid = sEntManager.SpawnEntity(null, mapPos);
sEntManager.GetComponent<MetaDataComponent>(sEntityUid).EntityName = "Container";
containerSys.EnsureContainer<Container>(sEntityUid, "dummy");
sMetadataSys.SetEntityName(sEntityUid, "Container");
sContainerSys.EnsureContainer<Container>(sEntityUid, "dummy");
// Setup PVS
sEntManager.AddComponent<EyeComponent>(sEntityUid);
@@ -214,12 +212,10 @@ namespace Robust.UnitTesting.Shared.GameObjects
await server.WaitAssertion(() =>
{
var containerSys = sEntManager.System<SharedContainerSystem>();
sItemUid = sEntManager.SpawnEntity(null, mapPos);
netEnt = sEntManager.GetNetEntity(sItemUid);
sEntManager.GetComponent<MetaDataComponent>(sItemUid).EntityName = "Item";
var container = containerSys.GetContainer(sEntityUid, "dummy");
sMetadataSys.SetEntityName(sItemUid, "Item");
var container = sContainerSys.GetContainer(sEntityUid, "dummy");
container.Insert(sItemUid);
// Move item out of PVS so that it doesn't get sent to the client
@@ -247,20 +243,17 @@ namespace Robust.UnitTesting.Shared.GameObjects
Assert.That(container.ContainedEntities.Count, Is.EqualTo(0));
Assert.That(container.ExpectedEntities.Count, Is.EqualTo(1));
var containerSystem = cEntManager.System<ContainerSystem>();
Assert.That(containerSystem.ExpectedEntities.ContainsKey(netEnt));
Assert.That(containerSystem.ExpectedEntities.Count, Is.EqualTo(1));
Assert.That(cContainerSys.ExpectedEntities.ContainsKey(netEnt));
Assert.That(cContainerSys.ExpectedEntities.Count, Is.EqualTo(1));
});
await server.WaitAssertion(() =>
{
var containerSystem = sEntManager.System<SharedContainerSystem>();
// If possible it'd be best to only have the DeleteEntity, but right now
// the entity deleted event is not played on the client if the entity does not exist on the client.
if (sEntManager.EntityExists(sItemUid)
// && itemUid.TryGetContainer(out var container))
&& containerSystem.TryGetContainingContainer(sItemUid, out var container))
&& sContainerSys.TryGetContainingContainer(sItemUid, out var container))
{
container.ForceRemove(sItemUid);
}
@@ -283,9 +276,8 @@ namespace Robust.UnitTesting.Shared.GameObjects
Assert.That(container.ContainedEntities.Count, Is.EqualTo(0));
Assert.That(container.ExpectedEntities.Count, Is.EqualTo(0));
var containerSystem = cEntManager.System<ContainerSystem>();
Assert.That(!containerSystem.ExpectedEntities.ContainsKey(netEnt));
Assert.That(containerSystem.ExpectedEntities.Count, Is.EqualTo(0));
Assert.That(!cContainerSys.ExpectedEntities.ContainsKey(netEnt));
Assert.That(cContainerSys.ExpectedEntities.Count, Is.EqualTo(0));
});
}
@@ -302,22 +294,22 @@ namespace Robust.UnitTesting.Shared.GameObjects
var sEntManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var sContainerSys = sEntManager.System<SharedContainerSystem>();
var sMetadataSys = sEntManager.System<MetaDataSystem>();
await server.WaitAssertion(() =>
{
var containerSys = sEntManager.EntitySysManager.GetEntitySystem<Robust.Server.Containers.ContainerSystem>();
// build the map
var mapIdOne = mapManager.CreateMap();
Assert.That(mapManager.IsMapInitialized(mapIdOne), Is.True);
var containerEnt = sEntManager.SpawnEntity(null, new MapCoordinates(1, 1, mapIdOne));
sEntManager.GetComponent<MetaDataComponent>(containerEnt).EntityName = "ContainerEnt";
sMetadataSys.SetEntityName(containerEnt, "ContainerEnt");
var containeeEnt = sEntManager.SpawnEntity(null, new MapCoordinates(2, 2, mapIdOne));
sEntManager.GetComponent<MetaDataComponent>(containeeEnt).EntityName = "ContaineeEnt";
sMetadataSys.SetEntityName(containeeEnt, "ContaineeEnt");
var container = containerSys.MakeContainer<Container>(containerEnt, "testContainer");
var container = sContainerSys.MakeContainer<Container>(containerEnt, "testContainer");
container.OccludesLight = true;
container.ShowContents = true;
container.Insert(containeeEnt);
@@ -347,15 +339,21 @@ namespace Robust.UnitTesting.Shared.GameObjects
await server.WaitAssertion(() =>
{
// verify container
var containerQuery = sEntManager.EntityQuery<ContainerManagerComponent>();
var containerComp = containerQuery.First();
var containerEnt = containerComp.Owner;
Entity<ContainerManagerComponent> container = default;
var query = sEntManager.EntityQueryEnumerator<ContainerManagerComponent>();
while (query.MoveNext(out var uid, out var containerComp))
{
container = (uid, containerComp);
}
var containerEnt = container.Owner;
Assert.NotNull(container.Comp);
Assert.That(sEntManager.GetComponent<MetaDataComponent>(containerEnt).EntityName, Is.EqualTo("ContainerEnt"));
Assert.That(containerComp.Containers.ContainsKey("testContainer"));
Assert.That(container.Comp!.Containers.ContainsKey("testContainer"));
var baseContainer = containerComp.GetContainer("testContainer");
var baseContainer = container.Comp.GetContainer("testContainer");
Assert.That(baseContainer.ContainedEntities, Has.Count.EqualTo(1));
var containeeEnt = baseContainer.ContainedEntities[0];

View File

@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Robust.UnitTesting.Shared.GameObjects;
public sealed class GenericEntityPrint
{
// [Test]
public void Print()
{
// Using the test framework for things it was not meant for is my passion
var i = 8;
IEnumerable<string> Generics(int n, bool nullable)
{
for (var j = 1; j <= n; j++)
{
var jStr = n == 1 ? string.Empty : j.ToString();
yield return $"T{jStr}{(nullable ? "?" : string.Empty)}";
}
}
var structs = new StringBuilder();
var constraints = new StringBuilder();
var fields = new StringBuilder();
var parameters = new StringBuilder();
var asserts = new StringBuilder();
var assignments = new StringBuilder();
var tupleParameters = new StringBuilder();
var tupleAccess = new StringBuilder();
var defaults = new StringBuilder();
var compOperators = new StringBuilder();
var deConstructorParameters = new StringBuilder();
var deConstructorAccess = new StringBuilder();
for (var j = 1; j <= i; j++)
{
constraints.Clear();
fields.Clear();
parameters.Clear();
asserts.Clear();
assignments.Clear();
tupleParameters.Clear();
tupleAccess.Clear();
defaults.Clear();
compOperators.Clear();
deConstructorParameters.Clear();
deConstructorAccess.Clear();
var generics = string.Join(", ", Generics(j, false));
var nullableGenerics = string.Join(", ", Generics(j, true));
for (var k = 1; k <= j; k++)
{
var kStr = j == 1 ? string.Empty : k.ToString();
fields.AppendLine($" public T{kStr} Comp{kStr};");
constraints.Append($"where T{kStr} : IComponent? ");
parameters.Append($", T{kStr} comp{kStr}");
asserts.AppendLine($" DebugTools.AssertOwner(owner, comp{kStr});");
assignments.AppendLine($" Comp{kStr} = comp{kStr};");
tupleParameters.Append($", T{kStr} Comp{kStr}");
tupleAccess.Append($", tuple.Comp{kStr}");
defaults.Append(", default");
compOperators.AppendLine($$"""
public static implicit operator T{{kStr}}(Entity<{{generics}}> ent)
{
return ent.Comp{{kStr}};
}
""");
deConstructorParameters.Append($", out T{kStr} comp{kStr}");
deConstructorAccess.AppendLine($" comp{kStr} = Comp{kStr};");
}
structs.Append($$"""
public record struct Entity<{{generics}}>
{{constraints.ToString().TrimEnd()}}
{
public EntityUid Owner;
{{fields.ToString().TrimEnd()}}
public Entity(EntityUid owner{{parameters}})
{
{{asserts}}
Owner = owner;
{{assignments.ToString().TrimEnd()}}
}
public static implicit operator Entity<{{generics}}>((EntityUid Owner{{tupleParameters}}) tuple)
{
return new Entity<{{generics}}>(tuple.Owner{{tupleAccess}});
}
public static implicit operator Entity<{{nullableGenerics}}>(EntityUid owner)
{
return new Entity<{{nullableGenerics}}>(owner{{defaults}});
}
public static implicit operator EntityUid(Entity<{{generics}}> ent)
{
return ent.Owner;
}
{{compOperators.ToString().TrimEnd()}}
public readonly void Deconstruct(out EntityUid owner{{deConstructorParameters}})
{
owner = Owner;
{{deConstructorAccess.ToString().TrimEnd()}}
}
}
""");
}
Console.WriteLine(structs);
}
}

View File

@@ -1,15 +1,14 @@
using System.Linq;
using System.Numerics;
using NUnit.Framework;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.UnitTesting.Server;
using System.Linq;
using System.Numerics;
// ReSharper disable AccessToStaticMemberViaDerivedType
@@ -46,9 +45,9 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
mapManager.CreateMap(TestMapId);
// Add grid 1, as the default grid to anchor things to.
var grid = mapManager.CreateGrid(TestMapId);
var grid = mapManager.CreateGridEntity(TestMapId);
return (sim, grid.Owner);
return (sim, grid);
}
// An entity is anchored to the tile it is over on the target grid.
@@ -130,7 +129,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
var ent1 = entMan.SpawnEntity(null, coordinates);
Assert.False(entMan.GetComponent<TransformComponent>(ent1).Anchored);
Assert.That(grid.GetAnchoredEntities(pos).Count() == 0);
Assert.That(!grid.GetAnchoredEntities(pos).Any());
entMan.DeleteEntity(ent1);
var ent2 = entMan.CreateEntityUninitialized(null, coordinates);
@@ -359,8 +358,8 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
// Act
// We purposefully use the grid as container so parent stays the same, reparent will unanchor
var containerMan = entMan.AddComponent<ContainerManagerComponent>(grid.Owner);
var container = containerMan.MakeContainer<Container>("TestContainer");
var containerMan = entMan.AddComponent<ContainerManagerComponent>(gridId);
var container = containerMan.MakeContainer<Container>(gridId, "TestContainer");
container.Insert(ent1);
Assert.That(entMan.GetComponent<TransformComponent>(ent1).Anchored, Is.False);
@@ -478,8 +477,8 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
var tileIndices = grid.TileIndicesFor(entMan.GetComponent<TransformComponent>(ent1).Coordinates);
grid.SetTile(tileIndices, new Tile(1));
var containerMan = entMan.AddComponent<ContainerManagerComponent>(grid.Owner);
var container = containerMan.MakeContainer<Container>("TestContainer");
var containerMan = entMan.AddComponent<ContainerManagerComponent>(gridId);
var container = containerMan.MakeContainer<Container>(gridId, "TestContainer");
container.Insert(ent1);
// Act

View File

@@ -57,19 +57,19 @@ namespace Robust.UnitTesting.Shared.GameObjects
var mapManager = server.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
grid.SetTile(new Vector2i(0, 0), new Tile(1));
var gridXform = entManager.GetComponent<TransformComponent>(grid.Owner);
var grid = mapManager.CreateGridEntity(mapId);
grid.Comp.SetTile(new Vector2i(0, 0), new Tile(1));
var gridXform = entManager.GetComponent<TransformComponent>(grid);
gridXform.LocalPosition = new Vector2(0f, 100f);
var ent1 = entManager.SpawnEntity(null, new EntityCoordinates(grid.Owner, Vector2.One * grid.TileSize / 2));
var ent1 = entManager.SpawnEntity(null, new EntityCoordinates(grid, Vector2.One * grid.Comp.TileSize / 2));
var ent2 = entManager.SpawnEntity(null, new EntityCoordinates(ent1, Vector2.Zero));
var xform2 = entManager.GetComponent<TransformComponent>(ent2);
Assert.That(xform2.WorldPosition, Is.EqualTo(new Vector2(0.5f, 100.5f)));
xform2.AttachToGridOrMap();
Assert.That(xform2.LocalPosition, Is.EqualTo(Vector2.One * grid.TileSize / 2));
Assert.That(xform2.LocalPosition, Is.EqualTo(Vector2.One * grid.Comp.TileSize / 2));
}
}
}

View File

@@ -9,11 +9,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
using cIPlayerManager = Robust.Client.Player.IPlayerManager;
using sIPlayerManager = Robust.Server.Player.IPlayerManager;
@@ -70,14 +65,14 @@ public sealed class DeletionNetworkingTests : RobustIntegrationTest
{
var mapId = mapMan.CreateMap();
mapMan.GetMapEntityId(mapId);
var gridComp = mapMan.CreateGrid(mapId);
gridComp.SetTile(Vector2i.Zero, new Tile(1));
var gridComp = mapMan.CreateGridEntity(mapId);
gridComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
grid1 = gridComp.Owner;
xformSys.SetLocalPosition(grid1, new Vector2(-2,0));
grid1Net = sEntMan.GetNetEntity(grid1);
gridComp = mapMan.CreateGrid(mapId);
gridComp.SetTile(Vector2i.Zero, new Tile(1));
gridComp = mapMan.CreateGridEntity(mapId);
gridComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
grid2 = gridComp.Owner;
xformSys.SetLocalPosition(grid2, new Vector2(2,0));
grid2Net = sEntMan.GetNetEntity(grid2);

View File

@@ -1,14 +1,8 @@
using System.IO;
using System.Numerics;
using Moq;
using NUnit.Framework;
using Robust.Server.GameObjects;
using Robust.Server.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
@@ -142,7 +136,7 @@ namespace Robust.UnitTesting.Shared.Map
var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var gridEnt = grid.Owner;
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(gridEnt, Vector2.Zero));
@@ -173,7 +167,7 @@ namespace Robust.UnitTesting.Shared.Map
var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var gridEnt = grid.Owner;
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(gridEnt, Vector2.Zero));
@@ -188,10 +182,10 @@ namespace Robust.UnitTesting.Shared.Map
var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var mapEnt = mapManager.GetMapEntityId(mapId);
var gridEnt = grid.Owner;
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid.Owner, Vector2.Zero));
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero));
Assert.That(entityManager.GetComponent<TransformComponent>(mapEnt).Coordinates.EntityId, Is.EqualTo(mapEnt));
Assert.That(entityManager.GetComponent<TransformComponent>(gridEnt).Coordinates.EntityId, Is.EqualTo(mapEnt));
@@ -210,10 +204,10 @@ namespace Robust.UnitTesting.Shared.Map
var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var mapEnt = mapManager.GetMapEntityId(mapId);
var gridEnt = grid.Owner;
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid.Owner, Vector2.Zero));
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero));
var mapCoords = entityManager.GetComponent<TransformComponent>(mapEnt).Coordinates;
Assert.That(mapCoords.IsValid(entityManager), Is.EqualTo(true));
@@ -261,9 +255,9 @@ namespace Robust.UnitTesting.Shared.Map
var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var gridEnt = grid.Owner;
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid.Owner, entPos));
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, entPos));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.ToMap(entityManager), Is.EqualTo(new MapCoordinates(entPos, mapId)));
@@ -280,9 +274,9 @@ namespace Robust.UnitTesting.Shared.Map
var mapId = mapManager.CreateMap();
var mapEnt = mapManager.GetMapEntityId(mapId);
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var gridEnt = grid.Owner;
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid.Owner, Vector2.Zero));
var newEnt = entityManager.CreateEntityUninitialized(null, new EntityCoordinates(grid, Vector2.Zero));
Assert.That(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(newEnt).Coordinates.WithEntityId(mapEnt).Position, Is.EqualTo(Vector2.Zero));

View File

@@ -1,7 +1,6 @@
using System.Threading.Tasks;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
@@ -25,8 +24,8 @@ namespace Robust.UnitTesting.Shared.Map
var physSystem = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<SharedPhysicsSystem>();
MapId mapId;
MapGridComponent? gridId1 = null;
MapGridComponent? gridId2 = null;
Entity<MapGridComponent>? gridId1 = null;
Entity<MapGridComponent>? gridId2 = null;
PhysicsComponent? physics1 = null;
PhysicsComponent? physics2 = null;
EntityUid? gridEnt1;
@@ -35,10 +34,10 @@ namespace Robust.UnitTesting.Shared.Map
await server.WaitPost(() =>
{
mapId = mapManager.CreateMap();
gridId1 = mapManager.CreateGrid(mapId);
gridId2 = mapManager.CreateGrid(mapId);
gridEnt1 = gridId1.Owner;
gridEnt2 = gridId2.Owner;
gridId1 = mapManager.CreateGridEntity(mapId);
gridId2 = mapManager.CreateGridEntity(mapId);
gridEnt1 = gridId1.Value.Owner;
gridEnt2 = gridId2.Value.Owner;
physics1 = entManager.GetComponent<PhysicsComponent>(gridEnt1.Value);
physics2 = entManager.GetComponent<PhysicsComponent>(gridEnt2.Value);
// Can't collide static bodies and grids (at time of this writing) start as static
@@ -70,8 +69,8 @@ namespace Robust.UnitTesting.Shared.Map
await server.WaitAssertion(() =>
{
gridId1?.SetTile(new Vector2i(0, 0), new Tile(1));
gridId2?.SetTile(new Vector2i(0, 0), new Tile(1));
gridId1?.Comp.SetTile(new Vector2i(0, 0), new Tile(1));
gridId2?.Comp.SetTile(new Vector2i(0, 0), new Tile(1));
});
await server.WaitRunTicks(1);

View File

@@ -22,17 +22,17 @@ namespace Robust.UnitTesting.Shared.Map
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var gridEntity = grid.Owner;
for (var i = 0; i < 10; i++)
{
grid.SetTile(new Vector2i(i, 0), new Tile(1));
grid.Comp.SetTile(new Vector2i(i, 0), new Tile(1));
}
for (var i = 10; i >= 0; i--)
{
grid.SetTile(new Vector2i(i, 0), Tile.Empty);
grid.Comp.SetTile(new Vector2i(i, 0), Tile.Empty);
}
Assert.That(entManager.Deleted(gridEntity));
@@ -60,19 +60,19 @@ namespace Robust.UnitTesting.Shared.Map
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
for (var i = 0; i < 10; i++)
{
grid.SetTile(new Vector2i(i, 0), new Tile(1));
grid.Comp.SetTile(new Vector2i(i, 0), new Tile(1));
}
for (var i = 10; i >= 0; i--)
{
grid.SetTile(new Vector2i(i, 0), Tile.Empty);
grid.Comp.SetTile(new Vector2i(i, 0), Tile.Empty);
}
Assert.That(!((!entManager.EntityExists(grid.Owner) ? EntityLifeStage.Deleted : entManager.GetComponent<MetaDataComponent>(grid.Owner).EntityLifeStage) >= EntityLifeStage.Deleted));
Assert.That(!((!entManager.EntityExists(grid) ? EntityLifeStage.Deleted : entManager.GetComponent<MetaDataComponent>(grid).EntityLifeStage) >= EntityLifeStage.Deleted));
});
}
}

View File

@@ -30,16 +30,16 @@ namespace Robust.UnitTesting.Shared.Map
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
// Should be nothing if grid empty
Assert.That(entManager.TryGetComponent(grid.Owner, out PhysicsComponent? gridBody));
Assert.That(entManager.TryGetComponent(grid.Owner, out FixturesComponent? manager));
Assert.That(entManager.TryGetComponent(grid, out PhysicsComponent? gridBody));
Assert.That(entManager.TryGetComponent(grid, out FixturesComponent? manager));
Assert.That(manager!.FixtureCount, Is.EqualTo(0));
Assert.That(gridBody!.BodyType, Is.EqualTo(BodyType.Static));
// 1 fixture if we only ever update the 1 chunk
grid.SetTile(Vector2i.Zero, new Tile(1));
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
Assert.That(manager.FixtureCount, Is.EqualTo(1));
// Also should only be a single tile.
@@ -48,7 +48,7 @@ namespace Robust.UnitTesting.Shared.Map
Assert.That(MathHelper.CloseToPercent(Box2.Area(bounds), 1.0f, 0.1f));
// Now do 2 tiles (same chunk)
grid.SetTile(new Vector2i(0, 1), new Tile(1));
grid.Comp.SetTile(new Vector2i(0, 1), new Tile(1));
Assert.That(manager.FixtureCount, Is.EqualTo(1));
bounds = manager.Fixtures.First().Value.Shape.ComputeAABB(new Transform(Vector2.Zero, (float) Angle.Zero.Theta), 0);
@@ -57,10 +57,10 @@ namespace Robust.UnitTesting.Shared.Map
Assert.That(MathHelper.CloseToPercent(Box2.Area(bounds), 2.0f, 0.1f));
// If we add a new chunk should be 2 now
grid.SetTile(new Vector2i(0, -1), new Tile(1));
grid.Comp.SetTile(new Vector2i(0, -1), new Tile(1));
Assert.That(manager.FixtureCount, Is.EqualTo(2));
physSystem.SetLinearVelocity(grid.Owner, Vector2.One, manager: manager, body: gridBody);
physSystem.SetLinearVelocity(grid, Vector2.One, manager: manager, body: gridBody);
Assert.That(gridBody.LinearVelocity.Length, Is.EqualTo(0f));
});
}

View File

@@ -4,9 +4,7 @@ using System.Numerics;
using System.Threading.Tasks;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
namespace Robust.UnitTesting.Shared.Map
@@ -31,27 +29,27 @@ namespace Robust.UnitTesting.Shared.Map
await server.WaitAssertion(() =>
{
var mapId = mapMan.CreateMap();
var grid = mapMan.CreateGrid(mapId);
var grid = mapMan.CreateGridEntity(mapId);
var gridEnt = grid.Owner;
var coordinates = new EntityCoordinates(gridEnt, new Vector2(10, 0));
// if no rotation and 0,0 position should just be the same coordinate.
Assert.That(entMan.GetComponent<TransformComponent>(gridEnt).WorldRotation, Is.EqualTo(Angle.Zero));
Assert.That(grid.WorldToLocal(coordinates.Position), Is.EqualTo(coordinates.Position));
Assert.That(grid.Comp.WorldToLocal(coordinates.Position), Is.EqualTo(coordinates.Position));
// Rotate 180 degrees should show -10, 0 for the position in map-terms and 10, 0 for the position in entity terms (i.e. no change).
entMan.GetComponent<TransformComponent>(gridEnt).WorldRotation += new Angle(MathF.PI);
Assert.That(entMan.GetComponent<TransformComponent>(gridEnt).WorldRotation, Is.EqualTo(new Angle(MathF.PI)));
// Check the map coordinate rotates correctly
Assert.That(grid.WorldToLocal(new Vector2(10, 0)).EqualsApprox(new Vector2(-10, 0), 0.01f));
Assert.That(grid.LocalToWorld(coordinates.Position).EqualsApprox(new Vector2(-10, 0), 0.01f));
Assert.That(grid.Comp.WorldToLocal(new Vector2(10, 0)).EqualsApprox(new Vector2(-10, 0), 0.01f));
Assert.That(grid.Comp.LocalToWorld(coordinates.Position).EqualsApprox(new Vector2(-10, 0), 0.01f));
// Now we'll do the same for 180 degrees.
entMan.GetComponent<TransformComponent>(gridEnt).WorldRotation += MathF.PI / 2f;
// If grid facing down then worldpos of 10, 0 gets rotated 90 degrees CCW and hence should be 0, 10
Assert.That(grid.WorldToLocal(new Vector2(10, 0)).EqualsApprox(new Vector2(0, 10), 0.01f));
Assert.That(grid.Comp.WorldToLocal(new Vector2(10, 0)).EqualsApprox(new Vector2(0, 10), 0.01f));
// If grid facing down then local 10,0 pos should just return 0, -10 given it's aligned with the rotation.
Assert.That(grid.LocalToWorld(coordinates.Position).EqualsApprox(new Vector2(0, -10), 0.01f));
Assert.That(grid.Comp.LocalToWorld(coordinates.Position).EqualsApprox(new Vector2(0, -10), 0.01f));
});
}
@@ -70,7 +68,7 @@ namespace Robust.UnitTesting.Shared.Map
await server.WaitAssertion(() =>
{
var mapId = mapMan.CreateMap();
var grid = mapMan.CreateGrid(mapId);
var grid = mapMan.CreateGridEntity(mapId);
var gridEnt = grid.Owner;
/* Test for map chunk rotations */
@@ -80,11 +78,11 @@ namespace Robust.UnitTesting.Shared.Map
{
for (var y = 0; y < 10; y++)
{
grid.SetTile(new Vector2i(x, y), tile);
grid.Comp.SetTile(new Vector2i(x, y), tile);
}
}
var chunks = grid.GetMapChunks().Select(c => c.Value).ToList();
var chunks = grid.Comp.GetMapChunks().Select(c => c.Value).ToList();
Assert.That(chunks.Count, Is.EqualTo(1));
var chunk = chunks[0];

View File

@@ -32,7 +32,8 @@ public sealed class GridSplit_Tests
var sim = GetSim();
var mapManager = sim.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var gridEnt = mapManager.CreateGridEntity(mapId);
var grid = gridEnt.Comp;
grid.CanSplit = false;
for (var x = 0; x < 5; x++)
@@ -40,14 +41,14 @@ public sealed class GridSplit_Tests
grid.SetTile(new Vector2i(x, 0), new Tile(1));
}
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(1));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1));
grid.SetTile(new Vector2i(1, 0), Tile.Empty);
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(1));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1));
grid.CanSplit = true;
grid.SetTile(new Vector2i(2, 0), Tile.Empty);
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(2));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2));
mapManager.DeleteMap(mapId);
}
@@ -58,17 +59,18 @@ public sealed class GridSplit_Tests
var sim = GetSim();
var mapManager = sim.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var gridEnt = mapManager.CreateGridEntity(mapId);
var grid = gridEnt.Comp;
for (var x = 0; x < 3; x++)
{
grid.SetTile(new Vector2i(x, 0), new Tile(1));
}
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(1));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1));
grid.SetTile(new Vector2i(1, 0), Tile.Empty);
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(2));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2));
mapManager.DeleteMap(mapId);
}
@@ -79,7 +81,8 @@ public sealed class GridSplit_Tests
var sim = GetSim();
var mapManager = sim.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var gridEnt = mapManager.CreateGridEntity(mapId);
var grid = gridEnt.Comp;
for (var x = 0; x < 3; x++)
{
@@ -89,16 +92,16 @@ public sealed class GridSplit_Tests
}
}
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(1));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1));
grid.SetTile(Vector2i.One, Tile.Empty);
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(1));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1));
grid.SetTile(new Vector2i(1, 2), Tile.Empty);
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(1));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1));
grid.SetTile(new Vector2i(1, 0), Tile.Empty);
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(2));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2));
mapManager.DeleteMap(mapId);
}
@@ -109,7 +112,8 @@ public sealed class GridSplit_Tests
var sim = GetSim();
var mapManager = sim.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var gridEnt = mapManager.CreateGridEntity(mapId);
var grid = gridEnt.Comp;
for (var x = 0; x < 3; x++)
{
@@ -118,10 +122,10 @@ public sealed class GridSplit_Tests
grid.SetTile(Vector2i.One, new Tile(1));
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(1));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1));
grid.SetTile(new Vector2i(1, 0), Tile.Empty);
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(3));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(3));
mapManager.DeleteMap(mapId);
}
@@ -136,27 +140,28 @@ public sealed class GridSplit_Tests
var entManager = sim.Resolve<IEntityManager>();
var mapManager = sim.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var gridEnt = mapManager.CreateGridEntity(mapId);
var grid = gridEnt.Comp;
for (var x = 0; x < 4; x++)
{
grid.SetTile(new Vector2i(x, 0), new Tile(1));
}
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(1));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(1));
var dummy = entManager.SpawnEntity(null, new EntityCoordinates(grid.Owner, new Vector2(3.5f, 0.5f)));
var dummy = entManager.SpawnEntity(null, new EntityCoordinates(gridEnt, new Vector2(3.5f, 0.5f)));
var dummyXform = entManager.GetComponent<TransformComponent>(dummy);
var anchored = entManager.SpawnEntity(null, new EntityCoordinates(grid.Owner, new Vector2(3.5f, 0.5f)));
var anchored = entManager.SpawnEntity(null, new EntityCoordinates(gridEnt, new Vector2(3.5f, 0.5f)));
var anchoredXform = entManager.GetComponent<TransformComponent>(anchored);
anchoredXform.Anchored = true;
Assert.That(anchoredXform.Anchored);
grid.SetTile(new Vector2i(2, 0), Tile.Empty);
Assert.That(mapManager.GetAllMapGrids(mapId).Count(), Is.EqualTo(2));
Assert.That(mapManager.GetAllGrids(mapId).Count(), Is.EqualTo(2));
var newGrid = mapManager.GetAllMapGrids(mapId).Last();
var newGridXform = entManager.GetComponent<TransformComponent>(newGrid.Owner);
var newGrid = mapManager.GetAllGrids(mapId).Last();
var newGridXform = entManager.GetComponent<TransformComponent>(newGrid);
Assert.Multiple(() =>
{

View File

@@ -41,7 +41,7 @@ public sealed class MapGridMap_Tests
var mapManager = sim.Resolve<IMapManager>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
mapManager.CreateGridEntity(mapId);
Assert.DoesNotThrow(() =>
{

View File

@@ -1,11 +1,9 @@
using System.Numerics;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.UnitTesting.Server;
using System.Management;
using System.Numerics;
using Robust.Shared.Map.Components;
using Robust.UnitTesting.Server;
namespace Robust.UnitTesting.Shared.Map
{
@@ -49,11 +47,11 @@ namespace Robust.UnitTesting.Shared.Map
var mapID = new MapId(11);
mapMan.CreateMap(mapID);
var grid = mapMan.CreateGrid(mapID);
var grid = mapMan.CreateGridEntity(mapID);
mapMan.Restart();
Assert.That(mapMan.GridExists(grid.Owner), Is.False);
Assert.That(mapMan.GridExists(grid), Is.False);
}
/// <summary>

View File

@@ -141,10 +141,10 @@ internal sealed class MapPauseTests
mapMan.SetMapPaused(mapId, true);
// act
var newGrid = mapMan.CreateGrid(mapId);
var newGrid = mapMan.CreateGridEntity(mapId);
// assert
var metaData = entMan.GetComponent<MetaDataComponent>(newGrid.Owner);
var metaData = entMan.GetComponent<MetaDataComponent>(newGrid);
Assert.That(metaData.EntityPaused, Is.True);
}

View File

@@ -64,9 +64,9 @@ public sealed class BroadphaseNetworkingTest : RobustIntegrationTest
{
var mapId = mapMan.CreateMap();
map1 = mapMan.GetMapEntityId(mapId);
var gridComp = mapMan.CreateGrid(mapId);
gridComp.SetTile(Vector2i.Zero, new Tile(1));
grid1 = gridComp.Owner;
var gridEnt = mapMan.CreateGridEntity(mapId);
gridEnt.Comp.SetTile(Vector2i.Zero, new Tile(1));
grid1 = gridEnt.Owner;
});
var map1Net = sEntMan.GetNetEntity(map1);
@@ -136,9 +136,9 @@ public sealed class BroadphaseNetworkingTest : RobustIntegrationTest
// Create grid
var mapId = mapMan.CreateMap();
map2 = mapMan.GetMapEntityId(mapId);
var gridComp = mapMan.CreateGrid(mapId);
gridComp.SetTile(Vector2i.Zero, new Tile(1));
grid2 = gridComp.Owner;
var gridEnt = mapMan.CreateGridEntity(mapId);
gridEnt.Comp.SetTile(Vector2i.Zero, new Tile(1));
grid2 = gridEnt.Owner;
// Move player
var coords = new EntityCoordinates(grid2, Vector2.Zero);

View File

@@ -1,8 +1,6 @@
using System.Linq;
using System.Numerics;
using NUnit.Framework;
using Robust.Client.UserInterface.CustomControls;
using Robust.Server.GameStates;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -30,13 +28,13 @@ public sealed class Broadphase_Test
var mapId = mapManager.CreateMap();
var mapEnt = mapManager.GetMapEntityId(mapId);
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
grid.SetTile(Vector2i.Zero, new Tile(1));
Assert.That(entManager.HasComponent<BroadphaseComponent>(grid.Owner));
var broadphase = entManager.GetComponent<BroadphaseComponent>(grid.Owner);
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
Assert.That(entManager.HasComponent<BroadphaseComponent>(grid));
var broadphase = entManager.GetComponent<BroadphaseComponent>(grid);
var ent = entManager.SpawnEntity(null, new EntityCoordinates(grid.Owner, new Vector2(0.5f, 0.5f)));
var ent = entManager.SpawnEntity(null, new EntityCoordinates(grid, new Vector2(0.5f, 0.5f)));
var xform = entManager.GetComponent<TransformComponent>(ent);
Assert.That(broadphase.SundriesTree, Does.Contain(ent));
@@ -65,10 +63,10 @@ public sealed class Broadphase_Test
var mapId = mapManager.CreateMap();
var mapEnt = mapManager.GetMapEntityId(mapId);
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var gridUid = grid.Owner;
grid.SetTile(Vector2i.Zero, new Tile(1));
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
Assert.That(entManager.HasComponent<BroadphaseComponent>(gridUid));
var broadphase = entManager.GetComponent<BroadphaseComponent>(gridUid);
@@ -114,10 +112,10 @@ public sealed class Broadphase_Test
var mapId1 = mapManager.CreateMap();
var mapId2 = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId1);
var xform = entManager.GetComponent<TransformComponent>(grid.Owner);
var grid = mapManager.CreateGridEntity(mapId1);
var xform = entManager.GetComponent<TransformComponent>(grid);
grid.SetTile(Vector2i.Zero, new Tile(1));
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
var mapBroadphase1 = entManager.GetComponent<BroadphaseComponent>(mapManager.GetMapEntityId(mapId1));
var mapBroadphase2 = entManager.GetComponent<BroadphaseComponent>(mapManager.GetMapEntityId(mapId2));
entManager.TickUpdate(0.016f, false);
@@ -146,15 +144,15 @@ public sealed class Broadphase_Test
var lookup = system.GetEntitySystem<EntityLookupSystem>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
grid.SetTile(Vector2i.Zero, new Tile(1));
var gridBroadphase = entManager.GetComponent<BroadphaseComponent>(grid.Owner);
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
var gridBroadphase = entManager.GetComponent<BroadphaseComponent>(grid);
var mapBroadphase = entManager.GetComponent<BroadphaseComponent>(mapManager.GetMapEntityId(mapId));
Assert.That(entManager.EntityQuery<BroadphaseComponent>(true).Count(), Is.EqualTo(2));
var parent = entManager.SpawnEntity(null, new EntityCoordinates(grid.Owner, new Vector2(0.5f, 0.5f)));
var parent = entManager.SpawnEntity(null, new EntityCoordinates(grid, new Vector2(0.5f, 0.5f)));
var child1 = entManager.SpawnEntity(null, new EntityCoordinates(parent, Vector2.Zero));
var child1Xform = entManager.GetComponent<TransformComponent>(child1);
@@ -173,7 +171,7 @@ public sealed class Broadphase_Test
Assert.That(lookup.FindBroadphase(child1), Is.EqualTo(gridBroadphase));
// They should get deparented to the map and updated to the map's broadphase instead.
grid.SetTile(Vector2i.Zero, Tile.Empty);
grid.Comp.SetTile(Vector2i.Zero, Tile.Empty);
Assert.That(lookup.FindBroadphase(parent), Is.EqualTo(mapBroadphase));
Assert.That(lookup.FindBroadphase(child1), Is.EqualTo(mapBroadphase));
Assert.That(lookup.FindBroadphase(child2), Is.EqualTo(mapBroadphase));
@@ -203,16 +201,16 @@ public sealed class Broadphase_Test
var mapB = mapManager.GetMapEntityId(mapBId);
// setup grids
var gridAComp = mapManager.CreateGrid(mapAId);
var gridBComp = mapManager.CreateGrid(mapBId);
var gridCComp = mapManager.CreateGrid(mapAId);
var gridAComp = mapManager.CreateGridEntity(mapAId);
var gridBComp = mapManager.CreateGridEntity(mapBId);
var gridCComp = mapManager.CreateGridEntity(mapAId);
var gridA = gridAComp.Owner;
var gridB = gridBComp.Owner;
var gridC = gridCComp.Owner;
xforms.SetLocalPosition(gridC, new Vector2(10, 10));
gridAComp.SetTile(Vector2i.Zero, new Tile(1));
gridBComp.SetTile(Vector2i.Zero, new Tile(1));
gridCComp.SetTile(Vector2i.Zero, new Tile(1));
gridAComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
gridBComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
gridCComp.Comp.SetTile(Vector2i.Zero, new Tile(1));
// set up test entities
var parent = entManager.SpawnEntity(null, new EntityCoordinates(mapA, new Vector2(200,200)));

View File

@@ -1,12 +1,11 @@
using System.Numerics;
using System.Threading.Tasks;
using NUnit.Framework;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using System.Threading.Tasks;
using Robust.Shared.Map.Components;
namespace Robust.UnitTesting.Shared.Physics
{
@@ -44,7 +43,7 @@ namespace Robust.UnitTesting.Shared.Physics
var entManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
MapGridComponent grid = default!;
Entity<MapGridComponent> grid = default!;
MapId mapId = default!;
PhysicsComponent entityOnePhysics = default!;
TransformComponent xform = default!;
@@ -53,15 +52,15 @@ namespace Robust.UnitTesting.Shared.Physics
await server.WaitPost(() =>
{
mapId = mapManager.CreateMap();
grid = mapManager.CreateGrid(mapId);
grid.SetTile(Vector2i.Zero, new Tile(1));
grid = mapManager.CreateGridEntity(mapId);
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
var entityOne = entManager.SpawnEntity("CollisionWakeTestItem", new MapCoordinates(Vector2.One * 2f, mapId));
entityOnePhysics = entManager.GetComponent<PhysicsComponent>(entityOne);
xform = entManager.GetComponent<TransformComponent>(entityOne);
Assert.That(xform.ParentUid == mapManager.GetMapEntityId(mapId));
var entityTwo = entManager.SpawnEntity("CollisionWakeTestItem", new EntityCoordinates(grid.Owner, new Vector2(0.5f, 0.5f)));
var entityTwo = entManager.SpawnEntity("CollisionWakeTestItem", new EntityCoordinates(grid, new Vector2(0.5f, 0.5f)));
entityTwoPhysics = entManager.GetComponent<PhysicsComponent>(entityTwo);
Assert.That(entManager.GetComponent<TransformComponent>(entityTwo).ParentUid == grid.Owner);
@@ -76,7 +75,7 @@ namespace Robust.UnitTesting.Shared.Physics
Assert.That(entityOnePhysics.CanCollide, Is.EqualTo(true));
xform.LocalPosition = new Vector2(0.5f, 0.5f);
xform.AttachParent(grid.Owner);
xform.AttachParent(grid);
// Entity 2 should immediately not be collidable on spawn
Assert.That(entityTwoPhysics.Awake, Is.EqualTo(false));

View File

@@ -31,17 +31,17 @@ public sealed class GridDeletion_Test : RobustIntegrationTest
PhysicsComponent physics = default!;
MapGridComponent grid = default!;
Entity<MapGridComponent> grid = default!;
MapId mapId = default!;
await server.WaitAssertion(() =>
{
mapId = mapManager.CreateMap();
grid = mapManager.CreateGrid(mapId);
grid = mapManager.CreateGridEntity(mapId);
physics = entManager.GetComponent<PhysicsComponent>(grid.Owner);
physSystem.SetBodyType(grid.Owner, BodyType.Dynamic, body: physics);
physSystem.SetLinearVelocity(grid.Owner, new Vector2(50f, 0f), body: physics);
physics = entManager.GetComponent<PhysicsComponent>(grid);
physSystem.SetBodyType(grid, BodyType.Dynamic, body: physics);
physSystem.SetLinearVelocity(grid, new Vector2(50f, 0f), body: physics);
Assert.That(physics.LinearVelocity.Length, NUnit.Framework.Is.GreaterThan(0f));
});
@@ -50,7 +50,7 @@ public sealed class GridDeletion_Test : RobustIntegrationTest
await server.WaitAssertion(() =>
{
Assert.That(physics.LinearVelocity.Length, NUnit.Framework.Is.GreaterThan(0f));
entManager.DeleteEntity(grid.Owner);
entManager.DeleteEntity(grid);
// So if gridtree is fucky then this SHOULD throw.
foreach (var _ in mapManager.FindGridsIntersecting(mapId,

View File

@@ -32,14 +32,14 @@ public sealed class GridMovement_Test : RobustIntegrationTest
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
// Setup 1 body on grid, 1 body off grid, and assert that it's all gucci.
grid.SetTile(Vector2i.Zero, new Tile(1));
var fixtures = entManager.GetComponent<FixturesComponent>(grid.Owner);
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
var fixtures = entManager.GetComponent<FixturesComponent>(grid);
Assert.That(fixtures.FixtureCount, Is.EqualTo(1));
var onGrid = entManager.SpawnEntity(null, new EntityCoordinates(grid.Owner, 0.5f, 0.5f ));
var onGrid = entManager.SpawnEntity(null, new EntityCoordinates(grid, 0.5f, 0.5f ));
var onGridBody = entManager.AddComponent<PhysicsComponent>(onGrid);
physSystem.SetBodyType(onGrid, BodyType.Dynamic, body: onGridBody);
var shapeA = new PolygonShape();

View File

@@ -1,12 +1,11 @@
using System.Numerics;
using System.Threading.Tasks;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using System.Threading.Tasks;
namespace Robust.UnitTesting.Shared.Physics
{
@@ -43,8 +42,8 @@ namespace Robust.UnitTesting.Shared.Physics
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid2 = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var grid2 = mapManager.CreateGridEntity(mapId);
var gridUidA = grid.Owner;
Assert.That(entityManager.TryGetComponent<PhysicsComponent>(gridUidA, out var gridPhysics));
@@ -53,7 +52,7 @@ namespace Robust.UnitTesting.Shared.Physics
Vector2 offset = new(3, 4);
Vector2 expectedFinalVelocity = new Vector2(-4, 3) * 2 + Vector2.One;
var dummy = entityManager.SpawnEntity(DummyEntity, new EntityCoordinates(grid.Owner, offset));
var dummy = entityManager.SpawnEntity(DummyEntity, new EntityCoordinates(grid, offset));
Assert.That(entityManager.TryGetComponent(dummy, out PhysicsComponent? body));
Assert.That(entityManager.TryGetComponent(dummy, out TransformComponent? xform));
xformSystem.SetParent(dummy, xform!, gridUidA);
@@ -85,7 +84,7 @@ namespace Robust.UnitTesting.Shared.Physics
Assert.That(velocities.Item2, Is.Approximately(angularVelocity, 1e-6));
// Check that velocity does not change when changing parent
xformSystem.SetParent(dummy, xform!, grid2.Owner);
xformSystem.SetParent(dummy, xform!, grid2);
linearVelocity = physicsSys.GetMapLinearVelocity(dummy, body);
angularVelocity = physicsSys.GetMapAngularVelocity(dummy, body);
velocities = physicsSys.GetMapVelocities(dummy, body);
@@ -112,7 +111,7 @@ namespace Robust.UnitTesting.Shared.Physics
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var gridUid = grid.Owner;
Assert.That(entityManager.TryGetComponent<PhysicsComponent>(gridUid, out var gridPhysics));

View File

@@ -8,6 +8,8 @@ using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.UnitTesting.Server;
// ReSharper disable AccessToStaticMemberViaDerivedType
namespace Robust.UnitTesting.Shared.Physics;
[TestFixture]
@@ -26,9 +28,9 @@ public sealed class RecursiveUpdateTest
var containers = entManager.System<ContainerSystem>();
var mapId = mapManager.CreateMap();
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var guid = grid.Owner;
grid.SetTile(Vector2i.Zero, new Tile(1));
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
Assert.That(entManager.HasComponent<BroadphaseComponent>(guid));
var broadphase = entManager.GetComponent<BroadphaseComponent>(guid);
@@ -214,9 +216,9 @@ public sealed class RecursiveUpdateTest
Assert.That(ents, Does.Contain(child));
// Try again, but this time with a parent change.
var grid = mapManager.CreateGrid(mapId);
var grid = mapManager.CreateGridEntity(mapId);
var guid = grid.Owner;
grid.SetTile(Vector2i.Zero, new Tile(1));
grid.Comp.SetTile(Vector2i.Zero, new Tile(1));
var gridBroadphase = entManager.GetComponent<BroadphaseComponent>(guid);
var gridBroadData = new BroadphaseData(guid, EntityUid.Invalid, false, false);