mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Fix some warnings. (#3803)
This commit is contained in:
committed by
GitHub
parent
48874b2773
commit
6bdb7c040f
@@ -1,54 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Shared.Console.Commands;
|
||||
|
||||
public sealed class TeleportToCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public override string Command => "tpto";
|
||||
public override bool RequireServerOrSingleplayer => true;
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
return;
|
||||
|
||||
var target = args[^1];
|
||||
if (!EntityUid.TryParse(target, out var uid))
|
||||
return;
|
||||
|
||||
if (!_entities.TryGetComponent(uid, out TransformComponent? targetTransform))
|
||||
return;
|
||||
|
||||
var targetCoords = targetTransform.Coordinates;
|
||||
|
||||
if (args.Length == 1)
|
||||
{
|
||||
var playerTransform = shell.Player?.AttachedEntityTransform;
|
||||
if (playerTransform == null)
|
||||
return;
|
||||
|
||||
playerTransform.Coordinates = targetCoords;
|
||||
playerTransform.AttachToGridOrMap();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var victim in args)
|
||||
{
|
||||
if (victim == target)
|
||||
continue;
|
||||
|
||||
if (!EntityUid.TryParse(victim, out var victimUid))
|
||||
continue;
|
||||
|
||||
if (!_entities.TryGetComponent(victimUid, out TransformComponent? victimTransform))
|
||||
continue;
|
||||
|
||||
victimTransform.Coordinates = targetCoords;
|
||||
victimTransform.AttachToGridOrMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,6 @@ public sealed class AudioSystem : SharedAudioSystem
|
||||
[Dependency] private readonly SharedPhysicsSystem _broadPhaseSystem = default!;
|
||||
[Dependency] private readonly IClydeAudio _clyde = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IParallelManager _parMan = default!;
|
||||
|
||||
@@ -23,7 +23,6 @@ namespace Robust.Client.GameStates
|
||||
[Dependency] private readonly IClientNetManager _netManager = default!;
|
||||
[Dependency] private readonly IClientGameStateManager _gameStateManager = default!;
|
||||
[Dependency] private readonly IComponentFactory _componentFactory = default!;
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
private const int HistorySize = 60 * 3; // number of ticks to keep in history.
|
||||
private const int TargetPayloadBps = 56000 / 8; // Target Payload size in Bytes per second. A mind-numbing fifty-six thousand bits per second, who would ever need more?
|
||||
|
||||
@@ -943,7 +943,7 @@ namespace Robust.Client.Input
|
||||
_inputManager.RegisterBinding(registration);
|
||||
}
|
||||
|
||||
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
|
||||
@@ -16,8 +16,17 @@ public sealed class ReplayRecordingManager : IReplayRecordingManager
|
||||
public bool Recording => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public event Action<(MappingDataNode, List<object>)>? OnRecordingStarted;
|
||||
public event Action<(MappingDataNode, List<object>)>? OnRecordingStarted
|
||||
{
|
||||
add { }
|
||||
remove { }
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public event Action<MappingDataNode>? OnRecordingStopped;
|
||||
public event Action<MappingDataNode>? OnRecordingStopped
|
||||
{
|
||||
add { }
|
||||
remove { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -165,8 +165,18 @@ namespace Robust.Server.Bql
|
||||
|
||||
public override IEnumerable<EntityUid> DoInitialSelection(IReadOnlyList<object> arguments, bool isInverted, IEntityManager entityManager)
|
||||
{
|
||||
return DoSelection(entityManager.EntityQuery<TransformComponent>(true).Select(x => x.Owner), arguments,
|
||||
return DoSelection(
|
||||
Query(entityManager.AllEntityQueryEnumerator<TransformComponent>()),
|
||||
arguments,
|
||||
isInverted, entityManager);
|
||||
|
||||
IEnumerable<EntityUid> Query(AllEntityQueryEnumerator<TransformComponent> enumerator)
|
||||
{
|
||||
while (enumerator.MoveNext(out var entityUid, out _))
|
||||
{
|
||||
yield return entityUid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,8 +321,8 @@ namespace Robust.Server.Bql
|
||||
public override IEnumerable<EntityUid> DoSelection(IEnumerable<EntityUid> input, IReadOnlyList<object> arguments, bool isInverted, IEntityManager entityManager)
|
||||
{
|
||||
var radius = (float)(double)arguments[0];
|
||||
var entityLookup = EntitySystem.Get<EntityLookupSystem>();
|
||||
var xformQuery = IoCManager.Resolve<IEntityManager>().GetEntityQuery<TransformComponent>();
|
||||
var entityLookup = entityManager.System<EntityLookupSystem>();
|
||||
var xformQuery = entityManager.GetEntityQuery<TransformComponent>();
|
||||
var distinct = new HashSet<EntityUid>();
|
||||
|
||||
foreach (var uid in input)
|
||||
|
||||
@@ -22,11 +22,13 @@ namespace Robust.Server.Bql
|
||||
return;
|
||||
}
|
||||
|
||||
var transformSystem = _entities.System<SharedTransformSystem>();
|
||||
|
||||
var (entities, rest) = _bql.SimpleParseAndExecute(argStr[6..]);
|
||||
|
||||
foreach (var ent in entities.ToList())
|
||||
{
|
||||
var cmds = SubstituteEntityDetails(_entities, shell, ent, rest).Split(";");
|
||||
var cmds = SubstituteEntityDetails(_entities, transformSystem, shell, ent, rest).Split(";");
|
||||
foreach (var cmd in cmds)
|
||||
{
|
||||
shell.ExecuteCommand(cmd);
|
||||
@@ -37,6 +39,7 @@ namespace Robust.Server.Bql
|
||||
// This will be refactored out soon.
|
||||
private static string SubstituteEntityDetails(
|
||||
IEntityManager entMan,
|
||||
SharedTransformSystem transformSystem,
|
||||
IConsoleShell shell,
|
||||
EntityUid ent,
|
||||
string ruleString)
|
||||
@@ -44,33 +47,29 @@ namespace Robust.Server.Bql
|
||||
var transform = entMan.GetComponent<TransformComponent>(ent);
|
||||
var metadata = entMan.GetComponent<MetaDataComponent>(ent);
|
||||
|
||||
var worldPos = transformSystem.GetWorldPosition(transform);
|
||||
var localPos = transform.LocalPosition;
|
||||
|
||||
// gross, is there a better way to do this?
|
||||
ruleString = ruleString.Replace("$ID", ent.ToString());
|
||||
ruleString = ruleString.Replace("$WX",
|
||||
transform.WorldPosition.X.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$WY",
|
||||
transform.WorldPosition.Y.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$LX",
|
||||
transform.LocalPosition.X.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$LY",
|
||||
transform.LocalPosition.Y.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$WX", worldPos.X.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$WY", worldPos.Y.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$LX", localPos.X.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$LY", localPos.Y.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$NAME", metadata.EntityName);
|
||||
|
||||
if (shell.Player is IPlayerSession player)
|
||||
if (shell.Player is { AttachedEntity: { } pEntity})
|
||||
{
|
||||
var ptransform = player.AttachedEntityTransform;
|
||||
if (ptransform != null)
|
||||
{
|
||||
ruleString = ruleString.Replace("$PID", ptransform.Owner.ToString());
|
||||
ruleString = ruleString.Replace("$PWX",
|
||||
ptransform.WorldPosition.X.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$PWY",
|
||||
ptransform.WorldPosition.Y.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$PLX",
|
||||
ptransform.LocalPosition.X.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$PLY",
|
||||
ptransform.LocalPosition.Y.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
var pTransform = entMan.GetComponent<TransformComponent>(pEntity);
|
||||
|
||||
var pWorldPos = transformSystem.GetWorldPosition(pTransform);
|
||||
var pLocalPos = pTransform.LocalPosition;
|
||||
|
||||
ruleString = ruleString.Replace("$PID", pEntity.ToString());
|
||||
ruleString = ruleString.Replace("$PWX", pWorldPos.X.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$PWY", pWorldPos.Y.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$PLX", pLocalPos.X.ToString(CultureInfo.InvariantCulture));
|
||||
ruleString = ruleString.Replace("$PLY", pLocalPos.Y.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
return ruleString;
|
||||
|
||||
@@ -49,7 +49,9 @@ namespace Robust.Server.Console.Commands
|
||||
|
||||
var component = (Component) _componentFactory.GetComponent(registration.Type);
|
||||
|
||||
#pragma warning disable CS0618
|
||||
component.Owner = uid;
|
||||
#pragma warning restore CS0618
|
||||
_entityManager.AddComponent(uid, component);
|
||||
|
||||
shell.WriteLine($"Added {componentName} component to entity {_entityManager.GetComponent<MetaDataComponent>(uid).EntityName}.");
|
||||
|
||||
@@ -7,8 +7,6 @@ using Robust.Shared.Console;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Robust.Server.Console.Commands
|
||||
@@ -27,9 +25,10 @@ namespace Robust.Server.Console.Commands
|
||||
|
||||
var target = args[^1];
|
||||
|
||||
if (!TryGetTransformFromUidOrUsername(target, shell, _entities, _players, out var targetTransform))
|
||||
if (!TryGetTransformFromUidOrUsername(target, shell, _entities, _players, out _, out var targetTransform))
|
||||
return;
|
||||
|
||||
var transformSystem = _entities.System<SharedTransformSystem>();
|
||||
var targetCoords = targetTransform.Coordinates;
|
||||
|
||||
if (args.Length == 1)
|
||||
@@ -47,7 +46,7 @@ namespace Robust.Server.Console.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
playerTransform.Coordinates = targetCoords;
|
||||
transformSystem.SetCoordinates(player.AttachedEntity!.Value, targetCoords);
|
||||
playerTransform.AttachToGridOrMap();
|
||||
}
|
||||
else
|
||||
@@ -57,31 +56,43 @@ namespace Robust.Server.Console.Commands
|
||||
if (victim == target)
|
||||
continue;
|
||||
|
||||
if (!TryGetTransformFromUidOrUsername(victim, shell, _entities, _players, out var victimTransform))
|
||||
if (!TryGetTransformFromUidOrUsername(victim, shell, _entities, _players, out var uid, out var victimTransform))
|
||||
return;
|
||||
|
||||
victimTransform.Coordinates = targetCoords;
|
||||
transformSystem.SetCoordinates(uid.Value, targetCoords);
|
||||
victimTransform.AttachToGridOrMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetTransformFromUidOrUsername(string str, IConsoleShell shell, IEntityManager entMan,
|
||||
IPlayerManager playerMan, [NotNullWhen(true)] out TransformComponent? transform)
|
||||
private static bool TryGetTransformFromUidOrUsername(
|
||||
string str,
|
||||
IConsoleShell shell,
|
||||
IEntityManager entMan,
|
||||
IPlayerManager playerMan,
|
||||
[NotNullWhen(true)] out EntityUid? victimUid,
|
||||
[NotNullWhen(true)] out TransformComponent? transform)
|
||||
{
|
||||
if (int.TryParse(str, out var uid)
|
||||
&& entMan.TryGetComponent(new EntityUid(uid), out transform))
|
||||
if (EntityUid.TryParse(str, out var uid) && entMan.TryGetComponent(uid, out transform))
|
||||
{
|
||||
victimUid = uid;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (playerMan.TryGetSessionByUsername(str, out var session)
|
||||
&& entMan.TryGetComponent(session.AttachedEntity, out transform))
|
||||
{
|
||||
victimUid = session.AttachedEntity;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (session == null)
|
||||
shell.WriteError("Can't find username/id: " + str);
|
||||
else
|
||||
shell.WriteError(str + " does not have an entity.");
|
||||
|
||||
transform = null;
|
||||
victimUid = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -135,7 +146,7 @@ namespace Robust.Server.Console.Commands
|
||||
shell.WriteLine("You need to provide a player to kick.");
|
||||
return;
|
||||
}
|
||||
shell.WriteLine($"You need to provide a player to kick. Try running 'kick {toKickPlayer?.Name}' as an example.");
|
||||
shell.WriteLine($"You need to provide a player to kick. Try running 'kick {toKickPlayer.Name}' as an example.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -17,6 +18,7 @@ namespace Robust.Server.GameObjects
|
||||
public int Layer = 1;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[Obsolete("Do not access directly, only exists for VV")]
|
||||
public int LayerVV
|
||||
{
|
||||
get => Layer;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
@@ -20,31 +21,55 @@ namespace Robust.Server.GameObjects
|
||||
EntityManager.EntityInitialized -= OnEntityInit;
|
||||
}
|
||||
|
||||
public void AddLayer(VisibilityComponent component, int layer, bool refresh = true)
|
||||
public void AddLayer(EntityUid uid, VisibilityComponent component, int layer, bool refresh = true)
|
||||
{
|
||||
if ((layer & component.Layer) == layer) return;
|
||||
if ((layer & component.Layer) == layer)
|
||||
return;
|
||||
|
||||
component.Layer |= layer;
|
||||
|
||||
if (refresh)
|
||||
RefreshVisibility(component.Owner, visibilityComponent: component);
|
||||
RefreshVisibility(uid, visibilityComponent: component);
|
||||
}
|
||||
|
||||
public void RemoveLayer(VisibilityComponent component, int layer, bool refresh = true)
|
||||
[Obsolete("Use overload that takes an EntityUid instead")]
|
||||
public void AddLayer(VisibilityComponent component, int layer, bool refresh = true)
|
||||
{
|
||||
if ((layer & component.Layer) != layer) return;
|
||||
AddLayer(component.Owner, component, layer, refresh);
|
||||
}
|
||||
|
||||
public void RemoveLayer(EntityUid uid, VisibilityComponent component, int layer, bool refresh = true)
|
||||
{
|
||||
if ((layer & component.Layer) != layer)
|
||||
return;
|
||||
|
||||
component.Layer &= ~layer;
|
||||
|
||||
if (refresh)
|
||||
RefreshVisibility(component.Owner, visibilityComponent: component);
|
||||
RefreshVisibility(uid, visibilityComponent: component);
|
||||
}
|
||||
|
||||
public void SetLayer(VisibilityComponent component, int layer, bool refresh = true)
|
||||
[Obsolete("Use overload that takes an EntityUid instead")]
|
||||
public void RemoveLayer(VisibilityComponent component, int layer, bool refresh = true)
|
||||
{
|
||||
if (component.Layer == layer) return;
|
||||
RemoveLayer(component.Owner, component, layer, refresh);
|
||||
}
|
||||
|
||||
public void SetLayer(EntityUid uid, VisibilityComponent component, int layer, bool refresh = true)
|
||||
{
|
||||
if (component.Layer == layer)
|
||||
return;
|
||||
|
||||
component.Layer = layer;
|
||||
|
||||
if (refresh)
|
||||
RefreshVisibility(component.Owner, visibilityComponent: component);
|
||||
RefreshVisibility(uid, visibilityComponent: component);
|
||||
}
|
||||
|
||||
[Obsolete("Use overload that takes an EntityUid instead")]
|
||||
public void SetLayer(VisibilityComponent component, int layer, bool refresh = true)
|
||||
{
|
||||
SetLayer(component.Owner, component, layer, refresh);
|
||||
}
|
||||
|
||||
private void OnParentChange(ref EntParentChangedMessage ev)
|
||||
@@ -63,6 +88,7 @@ namespace Robust.Server.GameObjects
|
||||
_metaSys.SetVisibilityMask(uid, GetVisibilityMask(uid, visibilityComponent), metaDataComponent);
|
||||
}
|
||||
|
||||
[Obsolete("Use overload that takes an EntityUid instead")]
|
||||
public void RefreshVisibility(VisibilityComponent visibilityComponent)
|
||||
{
|
||||
RefreshVisibility(visibilityComponent.Owner, null, visibilityComponent);
|
||||
@@ -73,7 +99,7 @@ namespace Robust.Server.GameObjects
|
||||
int visMask = 1; // apparently some content expects everything to have the first bit/flag set to true.
|
||||
if (Resolve(uid, ref visibilityComponent, false))
|
||||
visMask |= visibilityComponent.Layer;
|
||||
|
||||
|
||||
// Include parent vis masks
|
||||
if (Resolve(uid, ref xform) && xform.ParentUid.IsValid())
|
||||
visMask |= GetVisibilityMask(xform.ParentUid);
|
||||
|
||||
@@ -52,6 +52,7 @@ public interface IPVSCollection
|
||||
public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : IComparable<TIndex>, IEquatable<TIndex>
|
||||
{
|
||||
private readonly IEntityManager _entityManager;
|
||||
private readonly SharedTransformSystem _transformSystem;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2i GetChunkIndices(Vector2 coordinates)
|
||||
@@ -118,9 +119,10 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
|
||||
/// </summary>
|
||||
private HashSet<IChunkIndexLocation> _dirtyChunks = new();
|
||||
|
||||
public PVSCollection(IEntityManager entityManager)
|
||||
public PVSCollection(IEntityManager entityManager, SharedTransformSystem transformSystem)
|
||||
{
|
||||
_entityManager = entityManager;
|
||||
_transformSystem = transformSystem;
|
||||
}
|
||||
|
||||
public void Process()
|
||||
@@ -402,7 +404,7 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
|
||||
return;
|
||||
}
|
||||
|
||||
var mapCoordinates = coordinates.ToMap(_entityManager);
|
||||
var mapCoordinates = coordinates.ToMap(_entityManager, _transformSystem);
|
||||
var mapIndices = GetChunkIndices(coordinates.Position);
|
||||
UpdateIndex(index, mapCoordinates.MapId, mapIndices, true); //skip overridecheck bc we already did it (saves some dict lookups)
|
||||
}
|
||||
@@ -416,7 +418,7 @@ public sealed class PVSCollection<TIndex> : IPVSCollection where TIndex : ICompa
|
||||
return new GridChunkLocation(gridId, gridIndices);
|
||||
}
|
||||
|
||||
var mapCoordinates = coordinates.ToMap(_entityManager);
|
||||
var mapCoordinates = coordinates.ToMap(_entityManager, _transformSystem);
|
||||
var mapIndices = GetChunkIndices(coordinates.Position);
|
||||
return new MapChunkLocation(mapCoordinates.MapId, mapIndices);
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
|
||||
private PVSCollection<TIndex> RegisterPVSCollection<TIndex>() where TIndex : IComparable<TIndex>, IEquatable<TIndex>
|
||||
{
|
||||
var collection = new PVSCollection<TIndex>(EntityManager);
|
||||
var collection = new PVSCollection<TIndex>(EntityManager, _transform);
|
||||
_pvsCollections.Add(collection);
|
||||
return collection;
|
||||
}
|
||||
@@ -1068,11 +1068,13 @@ internal sealed partial class PVSSystem : EntitySystem
|
||||
if (tickData == null)
|
||||
{
|
||||
stateEntities = new List<EntityState>(EntityManager.EntityCount);
|
||||
foreach (var md in EntityManager.EntityQuery<MetaDataComponent>(true))
|
||||
var query = EntityManager.EntityQueryEnumerator<MetaDataComponent>();
|
||||
while (query.MoveNext(out var uid, out var md))
|
||||
{
|
||||
DebugTools.Assert(md.EntityLifeStage >= EntityLifeStage.Initialized);
|
||||
if (md.EntityLastModifiedTick > fromTick)
|
||||
stateEntities.Add(GetEntityState(player, md.Owner, fromTick, md));
|
||||
stateEntities.Add(GetEntityState(player, uid, fromTick, md));
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -272,7 +272,7 @@ namespace Robust.Server.ViewVariables
|
||||
switch (input)
|
||||
{
|
||||
case ViewVariablesBlobMembers.PrototypeReferenceToken token:
|
||||
if (!_prototypeManager.TryGetVariantType(token.Variant, out var variantType))
|
||||
if (!_prototypeManager.TryGetKindType(token.Variant, out var variantType))
|
||||
return false;
|
||||
|
||||
if (!_prototypeManager.TryIndex(variantType, token.ID, out var prototype))
|
||||
|
||||
@@ -274,7 +274,7 @@ public abstract class ComponentTreeSystem<TTreeComp, TComp> : EntitySystem
|
||||
var state = new HashSet<ComponentTreeEntry<TComp>>();
|
||||
foreach (var treeComp in GetIntersectingTrees(mapId, worldBounds))
|
||||
{
|
||||
var bounds = Transform(treeComp.Owner).InvWorldMatrix.TransformBox(worldBounds);
|
||||
var bounds = XformSystem.GetInvWorldMatrix(treeComp.Owner).TransformBox(worldBounds);
|
||||
|
||||
treeComp.Tree.QueryAabb(ref state, static (ref HashSet<ComponentTreeEntry<TComp>> state, in ComponentTreeEntry<TComp> value) =>
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Globalization;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Shared.Console.Commands;
|
||||
@@ -9,14 +10,15 @@ namespace Robust.Shared.Console.Commands;
|
||||
internal sealed class TeleportCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
public override string Command => "tp";
|
||||
public override bool RequireServerOrSingleplayer => true;
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var transform = shell.Player?.AttachedEntityTransform;
|
||||
if (transform == null)
|
||||
if (shell.Player is not { AttachedEntity: { } entity })
|
||||
return;
|
||||
|
||||
if (args.Length < 2 || !float.TryParse(args[0], out var posX) || !float.TryParse(args[1], out var posY))
|
||||
@@ -25,6 +27,8 @@ internal sealed class TeleportCommand : LocalizedCommands
|
||||
return;
|
||||
}
|
||||
|
||||
var xformSystem = _entitySystem.GetEntitySystem<SharedTransformSystem>();
|
||||
var transform = _entityManager.GetComponent<TransformComponent>(entity);
|
||||
var position = new Vector2(posX, posY);
|
||||
|
||||
transform.AttachToGridOrMap();
|
||||
@@ -45,13 +49,13 @@ internal sealed class TeleportCommand : LocalizedCommands
|
||||
{
|
||||
var gridPos = grid.WorldToLocal(position);
|
||||
|
||||
transform.Coordinates = new EntityCoordinates(grid.Owner, gridPos);
|
||||
xformSystem.SetCoordinates(entity, transform, new EntityCoordinates(grid.Owner, gridPos));
|
||||
}
|
||||
else
|
||||
{
|
||||
var mapEnt = _map.GetMapEntityIdOrThrow(mapId);
|
||||
transform.WorldPosition = position;
|
||||
transform.AttachParent(mapEnt);
|
||||
xformSystem.SetWorldPosition(transform, position);
|
||||
xformSystem.SetParent(entity, transform, mapEnt);
|
||||
}
|
||||
|
||||
shell.WriteLine($"Teleported {shell.Player} to {mapId}:{posX},{posY}.");
|
||||
@@ -66,14 +70,13 @@ sealed class LocationCommand : LocalizedCommands
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var pt = shell.Player?.AttachedEntityTransform;
|
||||
if (pt == null)
|
||||
if (shell.Player is not { AttachedEntity: { } entity })
|
||||
return;
|
||||
|
||||
var pt = _ent.GetComponent<TransformComponent>(entity);
|
||||
var pos = pt.Coordinates;
|
||||
|
||||
shell.WriteLine(
|
||||
$"MapID:{pos.GetMapId(_ent)} GridUid:{pos.GetGridUid(_ent)} X:{pos.X:N2} Y:{pos.Y:N2}");
|
||||
shell.WriteLine($"MapID:{pos.GetMapId(_ent)} GridUid:{pos.GetGridUid(_ent)} X:{pos.X:N2} Y:{pos.Y:N2}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,13 +100,19 @@ sealed class TpGridCommand : LocalizedCommands
|
||||
var xPos = float.Parse(args[1], CultureInfo.InvariantCulture);
|
||||
var yPos = float.Parse(args[2], CultureInfo.InvariantCulture);
|
||||
|
||||
if (!_map.TryGetGrid(gridId, out var grid))
|
||||
if (!_ent.EntityExists(gridId))
|
||||
{
|
||||
shell.WriteError($"Entity does not exist: {args[0]}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_ent.HasComponent<MapGridComponent>(gridId))
|
||||
{
|
||||
shell.WriteError($"No grid found with id {args[0]}");
|
||||
return;
|
||||
}
|
||||
|
||||
var gridXform = _ent.GetComponent<TransformComponent>(grid.Owner);
|
||||
var gridXform = _ent.GetComponent<TransformComponent>(gridId);
|
||||
var mapId = args.Length == 4 ? new MapId(int.Parse(args[3])) : gridXform.MapID;
|
||||
|
||||
gridXform.Coordinates = new EntityCoordinates(_map.GetMapEntityId(mapId), new Vector2(xPos, yPos));
|
||||
|
||||
@@ -177,9 +177,6 @@ namespace Robust.Shared.Containers
|
||||
EntityQuery<MetaDataComponent>? metas = null,
|
||||
EntityQuery<TransformComponent>? xforms = null)
|
||||
{
|
||||
DebugTools.Assert(meta == null || meta.Owner == uid);
|
||||
DebugTools.Assert(xform == null || xform.Owner == uid);
|
||||
|
||||
if (meta == null)
|
||||
{
|
||||
metas ??= EntityManager.GetEntityQuery<MetaDataComponent>();
|
||||
|
||||
@@ -6,9 +6,9 @@ using Timer = Robust.Shared.Timing.Timer;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
[Obsolete("Use a system update loop instead")]
|
||||
public static class TimerExtensions
|
||||
{
|
||||
[Obsolete("Use a system update loop instead")]
|
||||
private static TimerComponent EnsureTimerComponent(this EntityUid entity)
|
||||
{
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
@@ -266,7 +266,9 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
DebugTools.Assert(metadata.Owner == uid);
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
|
||||
if (metadata.EntityLastModifiedTick == _gameTiming.CurTick) return;
|
||||
@@ -281,7 +283,9 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
public virtual void Dirty(Component component, MetaDataComponent? meta = null)
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
var owner = component.Owner;
|
||||
#pragma warning restore CS0618
|
||||
|
||||
// Deserialization will cause this to be true.
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
@@ -312,13 +316,12 @@ namespace Robust.Shared.GameObjects
|
||||
// Networking blindly spams entities at this function, they can already be
|
||||
// deleted from being a child of a previously deleted entity
|
||||
// TODO: Why does networking need to send deletes for child entities?
|
||||
if (!metaQuery.TryGetComponent(e, out var comp)
|
||||
|| comp is not MetaDataComponent meta || meta.EntityDeleted)
|
||||
if (!metaQuery.TryGetComponent(e, out var meta) || meta.EntityDeleted)
|
||||
return;
|
||||
|
||||
if (meta.EntityLifeStage == EntityLifeStage.Terminating)
|
||||
{
|
||||
var msg = $"Called Delete on an entity already being deleted. Entity: {ToPrettyString(meta.Owner)}";
|
||||
var msg = $"Called Delete on an entity already being deleted. Entity: {ToPrettyString(e)}";
|
||||
#if !EXCEPTION_TOLERANCE
|
||||
throw new InvalidOperationException(msg);
|
||||
#else
|
||||
@@ -327,15 +330,18 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
// Notify all entities they are being terminated prior to detaching & deleting
|
||||
RecursiveFlagEntityTermination(meta, metaQuery, xformQuery, xformSys);
|
||||
RecursiveFlagEntityTermination(e, meta, metaQuery, xformQuery);
|
||||
|
||||
// Then actually delete them
|
||||
RecursiveDeleteEntity(meta, metaQuery, xformQuery, xformSys);
|
||||
RecursiveDeleteEntity(e, meta, metaQuery, xformQuery, xformSys);
|
||||
}
|
||||
|
||||
private void RecursiveFlagEntityTermination(MetaDataComponent metadata, EntityQuery<MetaDataComponent> metaQuery, EntityQuery<TransformComponent> xformQuery, SharedTransformSystem xformSys)
|
||||
private void RecursiveFlagEntityTermination(
|
||||
EntityUid uid,
|
||||
MetaDataComponent metadata,
|
||||
EntityQuery<MetaDataComponent> metaQuery,
|
||||
EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
var uid = metadata.Owner;
|
||||
var transform = xformQuery.GetComponent(uid);
|
||||
metadata.EntityLifeStage = EntityLifeStage.Terminating;
|
||||
|
||||
@@ -358,15 +364,19 @@ namespace Robust.Shared.GameObjects
|
||||
continue;
|
||||
}
|
||||
|
||||
RecursiveFlagEntityTermination(childMeta, metaQuery, xformQuery, xformSys);
|
||||
RecursiveFlagEntityTermination(child, childMeta, metaQuery, xformQuery);
|
||||
}
|
||||
}
|
||||
|
||||
private void RecursiveDeleteEntity(MetaDataComponent metadata, EntityQuery<MetaDataComponent> metaQuery, EntityQuery<TransformComponent> xformQuery, SharedTransformSystem xformSys)
|
||||
private void RecursiveDeleteEntity(
|
||||
EntityUid uid,
|
||||
MetaDataComponent metadata,
|
||||
EntityQuery<MetaDataComponent> metaQuery,
|
||||
EntityQuery<TransformComponent> xformQuery,
|
||||
SharedTransformSystem xformSys)
|
||||
{
|
||||
// Note about this method: #if EXCEPTION_TOLERANCE is not used here because we're gonna it in the future...
|
||||
|
||||
var uid = metadata.Owner;
|
||||
var transform = xformQuery.GetComponent(uid);
|
||||
|
||||
// Detach the base entity to null before iterating over children
|
||||
@@ -387,7 +397,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
try
|
||||
{
|
||||
RecursiveDeleteEntity(metaQuery.GetComponent(child), metaQuery, xformQuery, xformSys);
|
||||
RecursiveDeleteEntity(child, metaQuery.GetComponent(child), metaQuery, xformQuery, xformSys);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@@ -531,7 +541,9 @@ namespace Robust.Shared.GameObjects
|
||||
EntityAdded?.Invoke(uid);
|
||||
_eventBus.OnEntityAdded(uid);
|
||||
|
||||
#pragma warning disable CS0618
|
||||
metadata = new MetaDataComponent { Owner = uid };
|
||||
#pragma warning restore CS0618
|
||||
|
||||
Entities.Add(uid);
|
||||
// add the required MetaDataComponent directly.
|
||||
|
||||
@@ -66,7 +66,18 @@ public abstract partial class SharedTransformSystem
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
|
||||
[Obsolete("Use overload that takes an explicit EntityUid for the grid instead.")]
|
||||
public bool AnchorEntity(EntityUid uid, TransformComponent xform, MapGridComponent grid, Vector2i tileIndices)
|
||||
{
|
||||
return AnchorEntity(uid, xform, grid.Owner, grid, tileIndices);
|
||||
}
|
||||
|
||||
public bool AnchorEntity(
|
||||
EntityUid uid,
|
||||
TransformComponent xform,
|
||||
EntityUid gridUid,
|
||||
MapGridComponent grid,
|
||||
Vector2i tileIndices)
|
||||
{
|
||||
if (!grid.AddToSnapGridCell(tileIndices, uid))
|
||||
return false;
|
||||
@@ -84,7 +95,7 @@ public abstract partial class SharedTransformSystem
|
||||
}
|
||||
|
||||
// Anchor snapping. Note that set coordiantes will dirty the component for us.
|
||||
var pos = new EntityCoordinates(grid.Owner, grid.GridTileToLocal(tileIndices).Position);
|
||||
var pos = new EntityCoordinates(gridUid, grid.GridTileToLocal(tileIndices).Position);
|
||||
SetCoordinates(uid, xform, pos, unanchor: false);
|
||||
|
||||
return true;
|
||||
@@ -345,7 +356,9 @@ public abstract partial class SharedTransformSystem
|
||||
|
||||
public virtual void SetLocalPosition(TransformComponent xform, Vector2 value)
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
xform.LocalPosition = value;
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
|
||||
public void SetLocalPositionNoLerp(EntityUid uid, Vector2 value, TransformComponent? xform = null)
|
||||
@@ -356,7 +369,9 @@ public abstract partial class SharedTransformSystem
|
||||
|
||||
public virtual void SetLocalPositionNoLerp(TransformComponent xform, Vector2 value)
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
xform.LocalPosition = value;
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaSys = default!;
|
||||
|
||||
// Needed on release no remove.
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
|
||||
@@ -1,27 +1,37 @@
|
||||
using System.Linq;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
public sealed class TimerSystem : EntitySystem
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
// Avoid a collection was modified while enumerating.
|
||||
var timers = EntityManager.EntityQuery<TimerComponent>().ToList();
|
||||
|
||||
foreach (var timer in timers)
|
||||
// Avoid a collection was modified while enumerating.
|
||||
var timers = EntityManager.EntityQueryEnumerator<TimerComponent>();
|
||||
var timersList = new ValueList<(EntityUid, TimerComponent)>();
|
||||
while (timers.MoveNext(out var uid, out var timer))
|
||||
{
|
||||
timersList.Add((uid, timer));
|
||||
}
|
||||
|
||||
foreach (var (_, timer) in timersList)
|
||||
{
|
||||
timer.Update(frameTime);
|
||||
}
|
||||
|
||||
foreach (var timer in timers)
|
||||
foreach (var (uid, timer) in timersList)
|
||||
{
|
||||
if (!timer.Deleted && !EntityManager.Deleted(timer.Owner) && timer.RemoveOnEmpty && timer.TimerCount == 0) {
|
||||
EntityManager.RemoveComponent<TimerComponent>(timer.Owner);
|
||||
if (!timer.Deleted && !EntityManager.Deleted(uid) && timer.RemoveOnEmpty && timer.TimerCount == 0)
|
||||
{
|
||||
EntityManager.RemoveComponent<TimerComponent>(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Robust.Shared.Map
|
||||
var grid = mapManager.GetGrid(gridId);
|
||||
var tile = grid.TileSize;
|
||||
|
||||
return new EntityCoordinates(grid.Owner, (vector.X * tile, vector.Y * tile));
|
||||
return new EntityCoordinates(gridId, (vector.X * tile, vector.Y * tile));
|
||||
}
|
||||
|
||||
public static EntityCoordinates AlignWithClosestGridTile(this EntityCoordinates coords, float searchBoxSize = 1.5f, IEntityManager? entityManager = null, IMapManager? mapManager = null)
|
||||
|
||||
@@ -75,13 +75,24 @@ namespace Robust.Shared.Map
|
||||
/// </summary>
|
||||
/// <param name="entityManager">Entity Manager containing the entity Id.</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("Use ToMap() with TransformSystem overload")]
|
||||
public MapCoordinates ToMap(IEntityManager entityManager)
|
||||
{
|
||||
return ToMap(entityManager, entityManager.System<SharedTransformSystem>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms this set of coordinates from the entity's local space to the map space.
|
||||
/// </summary>
|
||||
/// <param name="entityManager">Entity Manager containing the entity Id.</param>
|
||||
/// <param name="transformSystem">Shared transform system for doing calculations.</param>
|
||||
public MapCoordinates ToMap(IEntityManager entityManager, SharedTransformSystem transformSystem)
|
||||
{
|
||||
if(!IsValid(entityManager))
|
||||
return MapCoordinates.Nullspace;
|
||||
|
||||
var transform = entityManager.GetComponent<TransformComponent>(EntityId);
|
||||
var worldPos = transform.WorldMatrix.Transform(Position);
|
||||
var worldPos = transformSystem.GetWorldMatrix(transform).Transform(Position);
|
||||
return new MapCoordinates(worldPos, transform.MapID);
|
||||
}
|
||||
|
||||
@@ -90,26 +101,45 @@ namespace Robust.Shared.Map
|
||||
/// </summary>
|
||||
/// <param name="entityManager">Entity Manager containing the entity Id.</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("Use ToMapPos() with TransformSystem overload")]
|
||||
public Vector2 ToMapPos(IEntityManager entityManager)
|
||||
{
|
||||
return ToMap(entityManager).Position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transform this set of coordinates from the entity's local space to the map space.
|
||||
/// </summary>
|
||||
/// <param name="entityManager">Entity Manager containing the entity Id.</param>
|
||||
/// <param name="transformSystem">Shared transform system for doing calculations.</param>
|
||||
public Vector2 ToMapPos(IEntityManager entityManager, SharedTransformSystem transformSystem)
|
||||
{
|
||||
return ToMap(entityManager, transformSystem).Position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates EntityCoordinates given an entity and some MapCoordinates.
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="coordinates"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException">If <see cref="entity"/> is not on the same map as the <see cref="coordinates"/>.</exception>
|
||||
[Obsolete("Use FromMap() with TransformSystem overload")]
|
||||
public static EntityCoordinates FromMap(EntityUid entity, MapCoordinates coordinates, IEntityManager? entMan = null)
|
||||
{
|
||||
IoCManager.Resolve(ref entMan);
|
||||
return FromMap(entity, coordinates, entMan.System<SharedTransformSystem>(), entMan);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates EntityCoordinates given an entity and some MapCoordinates.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">If <see cref="entity"/> is not on the same map as the <see cref="coordinates"/>.</exception>
|
||||
public static EntityCoordinates FromMap(EntityUid entity, MapCoordinates coordinates, SharedTransformSystem transformSystem, IEntityManager? entMan = null)
|
||||
{
|
||||
IoCManager.Resolve(ref entMan);
|
||||
var transform = entMan.GetComponent<TransformComponent>(entity);
|
||||
if(transform.MapID != coordinates.MapId)
|
||||
throw new InvalidOperationException("Entity is not on the same map!");
|
||||
|
||||
var localPos = transform.InvWorldMatrix.Transform(coordinates.Position);
|
||||
var localPos = transformSystem.GetInvWorldMatrix(transform).Transform(coordinates.Position);
|
||||
return new EntityCoordinates(entity, localPos);
|
||||
}
|
||||
|
||||
@@ -121,9 +151,10 @@ namespace Robust.Shared.Map
|
||||
/// <param name="coordinates"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException">If <see cref="entityUid"/> is not on the same map as the <see cref="coordinates"/>.</exception>
|
||||
[Obsolete("Use overload with other parameter order.")]
|
||||
public static EntityCoordinates FromMap(IEntityManager entityManager, EntityUid entityUid, MapCoordinates coordinates)
|
||||
{
|
||||
return FromMap(entityUid, coordinates);
|
||||
return FromMap(entityUid, coordinates, entityManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -142,21 +173,30 @@ namespace Robust.Shared.Map
|
||||
/// <summary>
|
||||
/// Converts this set of coordinates to Vector2i.
|
||||
/// </summary>
|
||||
/// <param name="entityManager"></param>
|
||||
/// <param name="mapManager"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("Use overload with TransformSystem")]
|
||||
public Vector2i ToVector2i(IEntityManager entityManager, IMapManager mapManager)
|
||||
{
|
||||
return ToVector2i(entityManager, mapManager, entityManager.System<SharedTransformSystem>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts this set of coordinates to Vector2i.
|
||||
/// </summary>
|
||||
public Vector2i ToVector2i(
|
||||
IEntityManager entityManager,
|
||||
IMapManager mapManager,
|
||||
SharedTransformSystem transformSystem)
|
||||
{
|
||||
if(!IsValid(entityManager))
|
||||
return new Vector2i();
|
||||
|
||||
var gridIdOpt = GetGridUid(entityManager);
|
||||
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
|
||||
if (gridIdOpt is { } gridId && gridId.IsValid())
|
||||
{
|
||||
return mapManager.GetGrid(gridId).GetTileRef(this).GridIndices;
|
||||
}
|
||||
|
||||
var (x, y) = ToMapPos(entityManager);
|
||||
var (x, y) = ToMapPos(entityManager, transformSystem);
|
||||
|
||||
return new Vector2i((int)Math.Floor(x), (int)Math.Floor(y));
|
||||
}
|
||||
@@ -194,12 +234,26 @@ namespace Robust.Shared.Map
|
||||
public EntityCoordinates WithEntityId(EntityUid entity, IEntityManager? entMan = null)
|
||||
{
|
||||
IoCManager.Resolve(ref entMan);
|
||||
var mapPos = ToMap(entMan);
|
||||
return WithEntityId(entity, entMan.System<SharedTransformSystem>(), entMan);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new set of EntityCoordinates local to a new entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity that the new coordinates will be local to</param>
|
||||
/// <returns>A new set of EntityCoordinates local to a new entity.</returns>
|
||||
public EntityCoordinates WithEntityId(
|
||||
EntityUid entity,
|
||||
SharedTransformSystem transformSystem,
|
||||
IEntityManager? entMan = null)
|
||||
{
|
||||
IoCManager.Resolve(ref entMan);
|
||||
var mapPos = ToMap(entMan, transformSystem);
|
||||
|
||||
if(!IsValid(entMan) || entMan.GetComponent<TransformComponent>(entity).MapID != mapPos.MapId)
|
||||
return new EntityCoordinates(entity, Vector2.Zero);
|
||||
|
||||
var localPos = entMan.GetComponent<TransformComponent>(entity).InvWorldMatrix.Transform(mapPos.Position);
|
||||
var localPos = transformSystem.GetInvWorldMatrix(entity).Transform(mapPos.Position);
|
||||
return new EntityCoordinates(entity, localPos);
|
||||
}
|
||||
|
||||
@@ -253,7 +307,24 @@ namespace Robust.Shared.Map
|
||||
/// <param name="otherCoordinates">Other set of coordinates to use.</param>
|
||||
/// <param name="range">maximum distance between the two sets of coordinates.</param>
|
||||
/// <returns>True if the two points are within a given range.</returns>
|
||||
[Obsolete("Use overload with TransformSystem")]
|
||||
public bool InRange(IEntityManager entityManager, EntityCoordinates otherCoordinates, float range)
|
||||
{
|
||||
return InRange(entityManager, entityManager.System<SharedTransformSystem>(), otherCoordinates, range);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two sets of coordinates to see if they are in range of each other.
|
||||
/// </summary>
|
||||
/// <param name="entityManager">Entity Manager containing the two entity Ids.</param>
|
||||
/// <param name="otherCoordinates">Other set of coordinates to use.</param>
|
||||
/// <param name="range">maximum distance between the two sets of coordinates.</param>
|
||||
/// <returns>True if the two points are within a given range.</returns>
|
||||
public bool InRange(
|
||||
IEntityManager entityManager,
|
||||
SharedTransformSystem transformSystem,
|
||||
EntityCoordinates otherCoordinates,
|
||||
float range)
|
||||
{
|
||||
if (!IsValid(entityManager) || !otherCoordinates.IsValid(entityManager))
|
||||
return false;
|
||||
@@ -261,8 +332,8 @@ namespace Robust.Shared.Map
|
||||
if (EntityId == otherCoordinates.EntityId)
|
||||
return (otherCoordinates.Position - Position).LengthSquared < range * range;
|
||||
|
||||
var mapCoordinates = ToMap(entityManager);
|
||||
var otherMapCoordinates = otherCoordinates.ToMap(entityManager);
|
||||
var mapCoordinates = ToMap(entityManager, transformSystem);
|
||||
var otherMapCoordinates = otherCoordinates.ToMap(entityManager, transformSystem);
|
||||
|
||||
return mapCoordinates.InRange(otherMapCoordinates, range);
|
||||
}
|
||||
@@ -275,6 +346,23 @@ namespace Robust.Shared.Map
|
||||
/// <param name="distance"></param>
|
||||
/// <returns>True if it was possible to calculate the distance</returns>
|
||||
public bool TryDistance(IEntityManager entityManager, EntityCoordinates otherCoordinates, out float distance)
|
||||
{
|
||||
return TryDistance(
|
||||
entityManager,
|
||||
entityManager.System<SharedTransformSystem>(),
|
||||
otherCoordinates,
|
||||
out distance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to calculate the distance between two sets of coordinates.
|
||||
/// </summary>
|
||||
/// <returns>True if it was possible to calculate the distance</returns>
|
||||
public bool TryDistance(
|
||||
IEntityManager entityManager,
|
||||
SharedTransformSystem transformSystem,
|
||||
EntityCoordinates otherCoordinates,
|
||||
out float distance)
|
||||
{
|
||||
distance = 0f;
|
||||
|
||||
@@ -287,8 +375,8 @@ namespace Robust.Shared.Map
|
||||
return true;
|
||||
}
|
||||
|
||||
var mapCoordinates = ToMap(entityManager);
|
||||
var otherMapCoordinates = otherCoordinates.ToMap(entityManager);
|
||||
var mapCoordinates = ToMap(entityManager, transformSystem);
|
||||
var otherMapCoordinates = otherCoordinates.ToMap(entityManager, transformSystem);
|
||||
|
||||
if (mapCoordinates.MapId != otherMapCoordinates.MapId)
|
||||
return false;
|
||||
|
||||
@@ -4,6 +4,7 @@ using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Shared.Noise
|
||||
{
|
||||
[Obsolete("Use FastNoiseLite")]
|
||||
[PublicAPI]
|
||||
public sealed class NoiseGenerator
|
||||
{
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace Robust.Shared.Physics.Systems
|
||||
public sealed partial class FixtureSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
|
||||
public override void Initialize()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -47,6 +48,7 @@ namespace Robust.Shared.Players
|
||||
/// <summary>
|
||||
/// Porting convenience for admin commands which use such logic as "at the player's feet", etc: the transform component of the attached entity.
|
||||
/// </summary>
|
||||
[Obsolete("Query manually from the EntityUid")]
|
||||
TransformComponent? AttachedEntityTransform => IoCManager.Resolve<IEntityManager>().GetComponentOrNull<TransformComponent>(AttachedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user