Optimise pinpointer activation significantly (#7169)
This commit is contained in:
@@ -1,17 +1,13 @@
|
|||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Pinpointer;
|
using Content.Shared.Pinpointer;
|
||||||
using Content.Shared.Whitelist;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Pinpointer
|
namespace Content.Server.Pinpointer
|
||||||
{
|
{
|
||||||
public sealed class ServerPinpointerSystem : SharedPinpointerSystem
|
public sealed class ServerPinpointerSystem : SharedPinpointerSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -24,9 +20,16 @@ namespace Content.Server.Pinpointer
|
|||||||
TogglePinpointer(uid, component);
|
TogglePinpointer(uid, component);
|
||||||
|
|
||||||
// try to find target from whitelist
|
// try to find target from whitelist
|
||||||
if (component.IsActive && component.Whitelist != null)
|
if (component.IsActive && component.Component != null)
|
||||||
{
|
{
|
||||||
var target = FindTargetFromWhitelist(uid, component.Whitelist);
|
if (!EntityManager.ComponentFactory.TryGetRegistration(component.Component, out var reg))
|
||||||
|
{
|
||||||
|
Logger.Error($"Unable to find component registration for {component.Component} for pinpointer!");
|
||||||
|
DebugTools.Assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var target = FindTargetFromComponent(uid, reg.Type);
|
||||||
SetTarget(uid, target, component);
|
SetTarget(uid, target, component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,24 +50,28 @@ namespace Content.Server.Pinpointer
|
|||||||
/// Try to find the closest entity from whitelist on a current map
|
/// Try to find the closest entity from whitelist on a current map
|
||||||
/// Will return null if can't find anything
|
/// Will return null if can't find anything
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private EntityUid? FindTargetFromWhitelist(EntityUid uid, EntityWhitelist whitelist,
|
private EntityUid? FindTargetFromComponent(EntityUid uid, Type whitelist, TransformComponent? transform = null)
|
||||||
TransformComponent? transform = null)
|
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref transform))
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
|
if (transform == null)
|
||||||
|
xformQuery.TryGetComponent(uid, out transform);
|
||||||
|
|
||||||
|
if (transform == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var mapId = transform.MapID;
|
|
||||||
var ents = _entityLookup.GetEntitiesInMap(mapId);
|
|
||||||
|
|
||||||
// sort all entities in distance increasing order
|
// sort all entities in distance increasing order
|
||||||
|
var mapId = transform.MapID;
|
||||||
var l = new SortedList<float, EntityUid>();
|
var l = new SortedList<float, EntityUid>();
|
||||||
foreach (var e in ents)
|
var worldPos = _transform.GetWorldPosition(transform, xformQuery);
|
||||||
|
|
||||||
|
foreach (var comp in EntityManager.GetAllComponents(whitelist))
|
||||||
{
|
{
|
||||||
if (whitelist.IsValid(e))
|
if (!xformQuery.TryGetComponent(comp.Owner, out var compXform) ||
|
||||||
{
|
compXform.MapID != mapId) continue;
|
||||||
var dist = (EntityManager.GetComponent<TransformComponent>(e).WorldPosition - transform.WorldPosition).LengthSquared;
|
|
||||||
l.TryAdd(dist, e);
|
var dist = (_transform.GetWorldPosition(compXform, xformQuery) - worldPos).LengthSquared;
|
||||||
}
|
l.TryAdd(dist, comp.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return uid with a smallest distacne
|
// return uid with a smallest distacne
|
||||||
@@ -124,10 +131,12 @@ namespace Content.Server.Pinpointer
|
|||||||
/// <returns>Null if failed to caluclate distance between two entities</returns>
|
/// <returns>Null if failed to caluclate distance between two entities</returns>
|
||||||
private Vector2? CalculateDirection(EntityUid pinUid, EntityUid trgUid)
|
private Vector2? CalculateDirection(EntityUid pinUid, EntityUid trgUid)
|
||||||
{
|
{
|
||||||
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
// check if entities have transform component
|
// check if entities have transform component
|
||||||
if (!EntityManager.TryGetComponent(pinUid, out TransformComponent? pin))
|
if (!xformQuery.TryGetComponent(pinUid, out var pin))
|
||||||
return null;
|
return null;
|
||||||
if (!EntityManager.TryGetComponent(trgUid, out TransformComponent? trg))
|
if (!xformQuery.TryGetComponent(trgUid, out var trg))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// check if they are on same map
|
// check if they are on same map
|
||||||
@@ -135,7 +144,7 @@ namespace Content.Server.Pinpointer
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
// get world direction vector
|
// get world direction vector
|
||||||
var dir = (trg.WorldPosition - pin.WorldPosition);
|
var dir = (_transform.GetWorldPosition(trg, xformQuery) - _transform.GetWorldPosition(pin, xformQuery));
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
Content.Shared/Nuke/NukeDiskComponent.cs
Normal file
9
Content.Shared/Nuke/NukeDiskComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Nuke;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used for tracking the nuke disk - isn't a tag for pinpointer purposes.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent]
|
||||||
|
public sealed class NukeDiskComponent : Component {}
|
||||||
@@ -1,21 +1,19 @@
|
|||||||
using System;
|
|
||||||
using Content.Shared.Whitelist;
|
|
||||||
using Robust.Shared.Analyzers;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
|
||||||
|
|
||||||
namespace Content.Shared.Pinpointer
|
namespace Content.Shared.Pinpointer
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a sprite on the item that points towards the target component.
|
||||||
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[NetworkedComponent]
|
[NetworkedComponent]
|
||||||
[Friend(typeof(SharedPinpointerSystem))]
|
[Friend(typeof(SharedPinpointerSystem))]
|
||||||
public sealed class PinpointerComponent : Component
|
public sealed class PinpointerComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("whitelist")]
|
// TODO: Type serializer oh god
|
||||||
public EntityWhitelist? Whitelist;
|
[DataField("component")]
|
||||||
|
public string? Component;
|
||||||
|
|
||||||
[DataField("mediumDistance")]
|
[DataField("mediumDistance")]
|
||||||
public float MediumDistance = 16f;
|
public float MediumDistance = 16f;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Maths;
|
|
||||||
|
|
||||||
namespace Content.Shared.Pinpointer
|
namespace Content.Shared.Pinpointer
|
||||||
{
|
{
|
||||||
@@ -44,7 +41,7 @@ namespace Content.Shared.Pinpointer
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
pinpointer.DistanceToTarget = distance;
|
pinpointer.DistanceToTarget = distance;
|
||||||
pinpointer.Dirty();
|
Dirty(pinpointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -59,7 +56,7 @@ namespace Content.Shared.Pinpointer
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
pinpointer.DirectionToTarget = directionToTarget;
|
pinpointer.DirectionToTarget = directionToTarget;
|
||||||
pinpointer.Dirty();
|
Dirty(pinpointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -79,7 +76,7 @@ namespace Content.Shared.Pinpointer
|
|||||||
ActivePinpointers.Remove(uid);
|
ActivePinpointers.Remove(uid);
|
||||||
|
|
||||||
pinpointer.IsActive = isActive;
|
pinpointer.IsActive = isActive;
|
||||||
pinpointer.Dirty();
|
Dirty(pinpointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
ejectSound:
|
ejectSound:
|
||||||
path: /Audio/Machines/terminal_insert_disc.ogg
|
path: /Audio/Machines/terminal_insert_disc.ogg
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
components:
|
||||||
- NukeDisk
|
- NukeDisk
|
||||||
- type: InteractionOutline
|
- type: InteractionOutline
|
||||||
- type: ActivatableUI
|
- type: ActivatableUI
|
||||||
|
|||||||
@@ -28,6 +28,4 @@
|
|||||||
parent: PinpointerBase
|
parent: PinpointerBase
|
||||||
components:
|
components:
|
||||||
- type: Pinpointer
|
- type: Pinpointer
|
||||||
whitelist:
|
component: NukeDisk
|
||||||
tags:
|
|
||||||
- NukeDisk
|
|
||||||
|
|||||||
@@ -4,9 +4,7 @@
|
|||||||
id: NukeDisk
|
id: NukeDisk
|
||||||
description: A nuclear auth disk, capable of arming a nuke if used along with a code. Note from nanotrasen reads "THIS IS YOUR MOST IMPORTANT POSESSION, SECURE DAT FUKKEN DISK!"
|
description: A nuclear auth disk, capable of arming a nuke if used along with a code. Note from nanotrasen reads "THIS IS YOUR MOST IMPORTANT POSESSION, SECURE DAT FUKKEN DISK!"
|
||||||
components:
|
components:
|
||||||
- type: Tag
|
- type: NukeDisk
|
||||||
tags:
|
|
||||||
- NukeDisk
|
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
netsync: false
|
netsync: false
|
||||||
sprite: Objects/Misc/nukedisk.rsi
|
sprite: Objects/Misc/nukedisk.rsi
|
||||||
|
|||||||
@@ -167,7 +167,7 @@
|
|||||||
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
id: HidesHair # for headwear.
|
id: HidesHair # for headwear.
|
||||||
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
id: Hoe
|
id: Hoe
|
||||||
|
|
||||||
@@ -210,9 +210,6 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
id: NoSpinOnThrow
|
id: NoSpinOnThrow
|
||||||
|
|
||||||
- type: Tag
|
|
||||||
id: NukeDisk
|
|
||||||
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
id: Ointment
|
id: Ointment
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user