mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 10:07:15 +02:00
RobustToolbox projects should be named Robust.* This PR changes the RobustToolbox projects from SS14.* to Robust.* Updates SS14.* prefixes/namespaces to Robust.* Updates SpaceStation14.sln to RobustToolbox.sln Updates MSBUILD/SS14.* to MSBUILD/Robust.* Updates CSProject and MSBuild references for the above Updates git_helper.py Removes Runserver and Runclient as they are unusable
75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using Robust.Server.GameObjects.Components.UserInterface;
|
|
using Robust.Server.Interfaces.Player;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.GameObjects.Components;
|
|
|
|
namespace Robust.Server.GameObjects.EntitySystems
|
|
{
|
|
internal class UserInterfaceSystem : EntitySystem
|
|
{
|
|
private const float MaxWindowRange = 2;
|
|
private const float MaxWindowRangeSquared = MaxWindowRange * MaxWindowRange;
|
|
|
|
private readonly List<IPlayerSession> _sessionCache = new List<IPlayerSession>();
|
|
|
|
/// <inheritdoc />
|
|
public override void Initialize()
|
|
{
|
|
EntityQuery = new TypeEntityQuery(typeof(ServerUserInterfaceComponent));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void Update(float frameTime)
|
|
{
|
|
foreach (var entity in RelevantEntities)
|
|
{
|
|
var uiComp = entity.GetComponent<ServerUserInterfaceComponent>();
|
|
|
|
CheckRange(entity.Transform, uiComp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that the subscribed clients are still in range of the entity.
|
|
/// </summary>
|
|
/// <param name="transformComp">Transform Component of the entity being checked.</param>
|
|
/// <param name="uiComp">UserInterface Component of entity being checked.</param>
|
|
private void CheckRange(ITransformComponent transformComp, ServerUserInterfaceComponent uiComp)
|
|
{
|
|
foreach (var ui in uiComp.Interfaces)
|
|
{
|
|
// We have to cache the set of sessions because Unsubscribe modifies the original.
|
|
_sessionCache.Clear();
|
|
_sessionCache.AddRange(ui.SubscribedSessions);
|
|
|
|
if (_sessionCache.Count == 0)
|
|
continue;
|
|
|
|
var uiPos = transformComp.WorldPosition;
|
|
var uiMap = transformComp.MapID;
|
|
|
|
foreach (var session in _sessionCache)
|
|
{
|
|
var attachedEntity = session.AttachedEntity;
|
|
|
|
// The component manages the set of sessions, so this invalid session should be removed soon.
|
|
if (attachedEntity == null || !attachedEntity.IsValid())
|
|
continue;
|
|
|
|
if (uiMap != attachedEntity.Transform.MapID)
|
|
{
|
|
ui.Close(session);
|
|
continue;
|
|
}
|
|
|
|
var distanceSquared = (uiPos - attachedEntity.Transform.WorldPosition).LengthSquared;
|
|
if (distanceSquared > MaxWindowRangeSquared)
|
|
ui.Close(session);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|