Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make crew monitor update blips at consistent rates #32555

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public sealed partial class CrewMonitoringWindow : FancyWindow
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly SharedTransformSystem _transformSystem;
private readonly SpriteSystem _spriteSystem;

private NetEntity? _trackedEntity;
Expand All @@ -36,10 +37,10 @@ public CrewMonitoringWindow()
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

_transformSystem = _entManager.System<SharedTransformSystem>();
_spriteSystem = _entManager.System<SpriteSystem>();

NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;

}

public void Set(string stationName, EntityUid? mapUid)
Expand Down Expand Up @@ -290,7 +291,7 @@ private void PopulateDepartmentList(IEnumerable<SuitSensorStatus> departmentSens
{
NavMap.TrackedEntities.TryAdd(sensor.SuitSensorUid,
new NavMapBlip
(coordinates.Value,
(CoordinatesToLocal(coordinates!.Value),
_blipTexture,
(_trackedEntity == null || sensor.SuitSensorUid == _trackedEntity) ? Color.LimeGreen : Color.LimeGreen * Color.DimGray,
sensor.SuitSensorUid == _trackedEntity));
Expand Down Expand Up @@ -356,7 +357,7 @@ private void UpdateSensorsTable(NetEntity? currTrackedEntity, NetEntity? prevTra
if (NavMap.TrackedEntities.TryGetValue(castSensor.SuitSensorUid, out var data))
{
data = new NavMapBlip
(data.Coordinates,
(CoordinatesToLocal(data.Coordinates),
data.Texture,
(currTrackedEntity == null || castSensor.SuitSensorUid == currTrackedEntity) ? Color.LimeGreen : Color.LimeGreen * Color.DimGray,
castSensor.SuitSensorUid == currTrackedEntity);
Expand Down Expand Up @@ -421,6 +422,31 @@ private bool TryGetNextScrollPosition([NotNullWhen(true)] out float? nextScrollP
return false;
}

/// <summary>
/// Converts the input coordinates to an EntityCoordinates which are in
/// reference to the grid that the map is displaying. This is a stylistic
/// choice; this window deliberately limits the rate that blips update,
/// but if the blip is attached to another grid which is moving, that
/// blip will move smoothly, unlike the others. By converting the
/// coordinates, we are back in control of the blip movement.
/// </summary>
private EntityCoordinates CoordinatesToLocal(EntityCoordinates refCoords)
{
if (NavMap.MapUid == null || NavMap.MapUid == refCoords.EntityId)
{
return refCoords;
}
else
{
var refEntToWorld = _transformSystem.GetWorldMatrix(refCoords.EntityId);
var refPosition = Vector2.Transform(refCoords.Position, refEntToWorld);

var worldToMonitor = _transformSystem.GetInvWorldMatrix((EntityUid)NavMap.MapUid);
var refInMonitor = Vector2.Transform(refPosition, worldToMonitor);
return new EntityCoordinates((EntityUid)NavMap.MapUid, refInMonitor);
}
}

private void ClearOutDatedData()
{
SensorsTable.RemoveAllChildren();
Expand Down
Loading