Storage system opts (#7427)
This commit is contained in:
@@ -366,6 +366,7 @@ namespace Content.Server.Storage.Components
|
|||||||
SubscribedSessions.Add(session);
|
SubscribedSessions.Add(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_entityManager.EnsureComponent<ActiveStorageComponent>(Owner);
|
||||||
if (SubscribedSessions.Count == 1)
|
if (SubscribedSessions.Count == 1)
|
||||||
UpdateStorageVisualization();
|
UpdateStorageVisualization();
|
||||||
}
|
}
|
||||||
@@ -388,7 +389,14 @@ namespace Content.Server.Storage.Components
|
|||||||
CloseNestedInterfaces(session);
|
CloseNestedInterfaces(session);
|
||||||
|
|
||||||
if (SubscribedSessions.Count == 0)
|
if (SubscribedSessions.Count == 0)
|
||||||
|
{
|
||||||
UpdateStorageVisualization();
|
UpdateStorageVisualization();
|
||||||
|
|
||||||
|
if (_entityManager.HasComponent<ActiveStorageComponent>(Owner))
|
||||||
|
{
|
||||||
|
_entityManager.RemoveComponent<ActiveStorageComponent>(Owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -635,4 +643,7 @@ namespace Content.Server.Storage.Components
|
|||||||
SoundSystem.Play(Filter.Pvs(Owner), StorageSoundCollection.GetSound(), Owner, AudioParams.Default);
|
SoundSystem.Play(Filter.Pvs(Owner), StorageSoundCollection.GetSound(), Owner, AudioParams.Default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class ActiveStorageComponent : Component {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using Robust.Server.Player;
|
|||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Storage.EntitySystems
|
namespace Content.Server.Storage.EntitySystems
|
||||||
{
|
{
|
||||||
@@ -23,8 +24,6 @@ namespace Content.Server.Storage.EntitySystems
|
|||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly DisposalUnitSystem _disposalSystem = default!;
|
[Dependency] private readonly DisposalUnitSystem _disposalSystem = default!;
|
||||||
|
|
||||||
private readonly List<IPlayerSession> _sessionCache = new();
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -88,7 +87,7 @@ namespace Content.Server.Storage.EntitySystems
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
foreach (var component in EntityManager.EntityQuery<ServerStorageComponent>())
|
foreach (var (_, component) in EntityManager.EntityQuery<ActiveStorageComponent, ServerStorageComponent>())
|
||||||
{
|
{
|
||||||
CheckSubscribedEntities(component);
|
CheckSubscribedEntities(component);
|
||||||
}
|
}
|
||||||
@@ -261,32 +260,33 @@ namespace Content.Server.Storage.EntitySystems
|
|||||||
|
|
||||||
private void CheckSubscribedEntities(ServerStorageComponent storageComp)
|
private void CheckSubscribedEntities(ServerStorageComponent storageComp)
|
||||||
{
|
{
|
||||||
|
var xform = Transform(storageComp.Owner);
|
||||||
|
var storagePos = xform.WorldPosition;
|
||||||
|
var storageMap = xform.MapID;
|
||||||
|
|
||||||
// We have to cache the set of sessions because Unsubscribe modifies the original.
|
var remove = new RemQueue<IPlayerSession>();
|
||||||
_sessionCache.Clear();
|
|
||||||
_sessionCache.AddRange(storageComp.SubscribedSessions);
|
|
||||||
|
|
||||||
if (_sessionCache.Count == 0)
|
foreach (var session in storageComp.SubscribedSessions)
|
||||||
return;
|
|
||||||
|
|
||||||
var storagePos = EntityManager.GetComponent<TransformComponent>(storageComp.Owner).WorldPosition;
|
|
||||||
var storageMap = EntityManager.GetComponent<TransformComponent>(storageComp.Owner).MapID;
|
|
||||||
|
|
||||||
foreach (var session in _sessionCache)
|
|
||||||
{
|
{
|
||||||
// The component manages the set of sessions, so this invalid session should be removed soon.
|
// The component manages the set of sessions, so this invalid session should be removed soon.
|
||||||
if (session.AttachedEntity is not {} attachedEntity || !EntityManager.EntityExists(attachedEntity))
|
if (session.AttachedEntity is not {} attachedEntity || !EntityManager.EntityExists(attachedEntity))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (storageMap != EntityManager.GetComponent<TransformComponent>(attachedEntity).MapID)
|
var attachedXform = Transform(attachedEntity);
|
||||||
|
if (storageMap != attachedXform.MapID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var distanceSquared = (storagePos - EntityManager.GetComponent<TransformComponent>(attachedEntity).WorldPosition).LengthSquared;
|
var distanceSquared = (storagePos - attachedXform.WorldPosition).LengthSquared;
|
||||||
if (distanceSquared > SharedInteractionSystem.InteractionRangeSquared)
|
if (distanceSquared > SharedInteractionSystem.InteractionRangeSquared)
|
||||||
|
{
|
||||||
|
remove.Add(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var session in remove)
|
||||||
{
|
{
|
||||||
storageComp.UnsubscribeSession(session);
|
storageComp.UnsubscribeSession(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user