From fba2cc864fada464533afdd9e40f607cfe24ce2d Mon Sep 17 00:00:00 2001 From: nookii Date: Sat, 17 Aug 2024 13:00:47 -0400 Subject: [PATCH 1/4] implement --- Robust.Shared/GameObjects/EntityManager.Spawn.cs | 4 ++-- Robust.Shared/GameObjects/EntityManager.cs | 3 ++- Robust.Shared/GameObjects/EntitySystem.Proxy.cs | 4 ++-- Robust.Shared/GameObjects/IEntityManager.Spawn.cs | 2 +- Robust.Shared/GameObjects/IEntityManager.cs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Robust.Shared/GameObjects/EntityManager.Spawn.cs b/Robust.Shared/GameObjects/EntityManager.Spawn.cs index 2739308fa9a..03e6529d042 100644 --- a/Robust.Shared/GameObjects/EntityManager.Spawn.cs +++ b/Robust.Shared/GameObjects/EntityManager.Spawn.cs @@ -73,12 +73,12 @@ public EntityUid[] SpawnEntities(MapCoordinates coordinates, List proto return ents; } - public virtual EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default) + public virtual EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default, bool traversal = true) { if (!coordinates.IsValid(this)) throw new InvalidOperationException($"Tried to spawn entity {protoName} on invalid coordinates {coordinates}."); - var entity = CreateEntityUninitialized(protoName, coordinates, overrides, rotation); + var entity = CreateEntityUninitialized(protoName, coordinates, overrides, rotation, traversal); InitializeAndStartEntity(entity, coordinates.GetMapId(this)); return entity; } diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index c854bf9e869..31360117359 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -300,11 +300,12 @@ public virtual EntityUid CreateEntityUninitialized(string? prototypeName, Compon } /// - public virtual EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default) + public virtual EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default, bool traversal = true) { var newEntity = CreateEntity(prototypeName, out _, overrides); var xformComp = TransformQuery.GetComponent(newEntity); + xformComp.GridTraversal = traversal; _xforms.SetCoordinates(newEntity, xformComp, coordinates, rotation: rotation, unanchor: false); return newEntity; } diff --git a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs b/Robust.Shared/GameObjects/EntitySystem.Proxy.cs index fa9b6bc8730..ecf24f0e5eb 100644 --- a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs +++ b/Robust.Shared/GameObjects/EntitySystem.Proxy.cs @@ -736,8 +736,8 @@ protected EntityUid Spawn(string? prototype = null, ComponentRegistry? overrides /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected EntityUid SpawnAttachedTo(string? prototype, EntityCoordinates coordinates, ComponentRegistry? overrides = null) - => EntityManager.SpawnAttachedTo(prototype, coordinates, overrides); + protected EntityUid SpawnAttachedTo(string? prototype, EntityCoordinates coordinates, ComponentRegistry? overrides = null, bool traversal = true) + => EntityManager.SpawnAttachedTo(prototype, coordinates, overrides, traversal: traversal); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Robust.Shared/GameObjects/IEntityManager.Spawn.cs b/Robust.Shared/GameObjects/IEntityManager.Spawn.cs index 809a24962b0..f97f40a492f 100644 --- a/Robust.Shared/GameObjects/IEntityManager.Spawn.cs +++ b/Robust.Shared/GameObjects/IEntityManager.Spawn.cs @@ -38,7 +38,7 @@ EntityUid[] SpawnEntities(EntityCoordinates coordinates, List protoName /// /// Spawns an entity and then parents it to the entity that the given entity coordinates are relative to. /// - EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default); + EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default, bool traversal = true); /// /// Resolves the given entity coordinates into world coordinates and spawns an entity at that location. The diff --git a/Robust.Shared/GameObjects/IEntityManager.cs b/Robust.Shared/GameObjects/IEntityManager.cs index 528d91f8008..49f9a1fc419 100644 --- a/Robust.Shared/GameObjects/IEntityManager.cs +++ b/Robust.Shared/GameObjects/IEntityManager.cs @@ -96,7 +96,7 @@ public partial interface IEntityManager /// Coordinates to set position and parent of the newly spawned entity to. /// /// - EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default); + EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default, bool traversal = true); /// /// Creates an uninitialized entity and puts it on the grid or map at the MapCoordinates provided. From c34994fbf420e1d7afc4f7a65fab075dcc660737 Mon Sep 17 00:00:00 2001 From: nookii Date: Sun, 25 Aug 2024 16:07:56 -0400 Subject: [PATCH 2/4] remove startup traversal --- .../GameObjects/Systems/SharedGridTraversalSystem.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs b/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs index 4ed8bdd7e97..c3a81b4885f 100644 --- a/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedGridTraversalSystem.cs @@ -27,12 +27,6 @@ internal sealed class SharedGridTraversalSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnStartup); - } - - private void OnStartup(ref TransformStartupEvent ev) - { - CheckTraverse(ev.Entity); } internal void CheckTraverse(Entity entity) From a55b4da7cc75d19ba3141cc72120140bc7a6138c Mon Sep 17 00:00:00 2001 From: nookii Date: Sun, 25 Aug 2024 16:27:57 -0400 Subject: [PATCH 3/4] remove overrides --- Robust.Shared/GameObjects/EntityManager.Spawn.cs | 4 ++-- Robust.Shared/GameObjects/EntityManager.cs | 3 +-- Robust.Shared/GameObjects/EntitySystem.Proxy.cs | 4 ++-- Robust.Shared/GameObjects/IEntityManager.Spawn.cs | 2 +- Robust.Shared/GameObjects/IEntityManager.cs | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Robust.Shared/GameObjects/EntityManager.Spawn.cs b/Robust.Shared/GameObjects/EntityManager.Spawn.cs index 03e6529d042..2739308fa9a 100644 --- a/Robust.Shared/GameObjects/EntityManager.Spawn.cs +++ b/Robust.Shared/GameObjects/EntityManager.Spawn.cs @@ -73,12 +73,12 @@ public EntityUid[] SpawnEntities(MapCoordinates coordinates, List proto return ents; } - public virtual EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default, bool traversal = true) + public virtual EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default) { if (!coordinates.IsValid(this)) throw new InvalidOperationException($"Tried to spawn entity {protoName} on invalid coordinates {coordinates}."); - var entity = CreateEntityUninitialized(protoName, coordinates, overrides, rotation, traversal); + var entity = CreateEntityUninitialized(protoName, coordinates, overrides, rotation); InitializeAndStartEntity(entity, coordinates.GetMapId(this)); return entity; } diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index 31360117359..c854bf9e869 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -300,12 +300,11 @@ public virtual EntityUid CreateEntityUninitialized(string? prototypeName, Compon } /// - public virtual EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default, bool traversal = true) + public virtual EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default) { var newEntity = CreateEntity(prototypeName, out _, overrides); var xformComp = TransformQuery.GetComponent(newEntity); - xformComp.GridTraversal = traversal; _xforms.SetCoordinates(newEntity, xformComp, coordinates, rotation: rotation, unanchor: false); return newEntity; } diff --git a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs b/Robust.Shared/GameObjects/EntitySystem.Proxy.cs index ecf24f0e5eb..fa9b6bc8730 100644 --- a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs +++ b/Robust.Shared/GameObjects/EntitySystem.Proxy.cs @@ -736,8 +736,8 @@ protected EntityUid Spawn(string? prototype = null, ComponentRegistry? overrides /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected EntityUid SpawnAttachedTo(string? prototype, EntityCoordinates coordinates, ComponentRegistry? overrides = null, bool traversal = true) - => EntityManager.SpawnAttachedTo(prototype, coordinates, overrides, traversal: traversal); + protected EntityUid SpawnAttachedTo(string? prototype, EntityCoordinates coordinates, ComponentRegistry? overrides = null) + => EntityManager.SpawnAttachedTo(prototype, coordinates, overrides); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Robust.Shared/GameObjects/IEntityManager.Spawn.cs b/Robust.Shared/GameObjects/IEntityManager.Spawn.cs index f97f40a492f..809a24962b0 100644 --- a/Robust.Shared/GameObjects/IEntityManager.Spawn.cs +++ b/Robust.Shared/GameObjects/IEntityManager.Spawn.cs @@ -38,7 +38,7 @@ EntityUid[] SpawnEntities(EntityCoordinates coordinates, List protoName /// /// Spawns an entity and then parents it to the entity that the given entity coordinates are relative to. /// - EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default, bool traversal = true); + EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default); /// /// Resolves the given entity coordinates into world coordinates and spawns an entity at that location. The diff --git a/Robust.Shared/GameObjects/IEntityManager.cs b/Robust.Shared/GameObjects/IEntityManager.cs index 49f9a1fc419..528d91f8008 100644 --- a/Robust.Shared/GameObjects/IEntityManager.cs +++ b/Robust.Shared/GameObjects/IEntityManager.cs @@ -96,7 +96,7 @@ public partial interface IEntityManager /// Coordinates to set position and parent of the newly spawned entity to. /// /// - EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default, bool traversal = true); + EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default); /// /// Creates an uninitialized entity and puts it on the grid or map at the MapCoordinates provided. From 68cb5d23aaacacb4b2ee03d5ec6ed0563ea9c5e8 Mon Sep 17 00:00:00 2001 From: nookii Date: Sun, 29 Sep 2024 22:02:02 -0400 Subject: [PATCH 4/4] change mapcoordinate-based spawning to check/reparent to grids --- Robust.Shared/GameObjects/EntityManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index c854bf9e869..cc1ce80fbb4 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -327,10 +327,10 @@ public virtual EntityUid CreateEntityUninitialized(string? prototypeName, MapCoo throw new ArgumentException($"Attempted to spawn entity on an invalid map. Coordinates: {coordinates}"); EntityCoordinates coords; - if (transform.Anchored && _mapManager.TryFindGridAt(coordinates, out var gridUid, out var grid)) + if (_mapManager.TryFindGridAt(coordinates, out var gridUid, out var grid)) { coords = new EntityCoordinates(gridUid, _mapSystem.WorldToLocal(gridUid, grid, coordinates.Position)); - _xforms.SetCoordinates(newEntity, transform, coords, rotation, unanchor: false); + _xforms.SetCoordinates(newEntity, transform, coords, rotation, unanchor: !transform.Anchored); } else {