]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix crew monitoring direction & memory leak (#16459)
author20kdc <asdd2808@gmail.com>
Mon, 15 May 2023 20:38:41 +0000 (21:38 +0100)
committerGitHub <noreply@github.com>
Mon, 15 May 2023 20:38:41 +0000 (16:38 -0400)
Content.Client/Medical/CrewMonitoring/CrewMonitoringBoundUserInterface.cs
Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs

index 0943f89247d525e352db913bd7472e736389792d..c1093472b90798b4350564cf2ab0c8ff658d5c6e 100644 (file)
@@ -38,14 +38,8 @@ namespace Content.Client.Medical.CrewMonitoring
             {
                 case CrewMonitoringState st:
                     _entManager.TryGetComponent<TransformComponent>(Owner.Owner, out var xform);
-                    Vector2 localPosition = Vector2.Zero;
 
-                    if (_entManager.TryGetComponent<TransformComponent>(xform?.GridUid, out var gridXform))
-                    {
-                        localPosition = gridXform.InvWorldMatrix.Transform(xform.WorldPosition);
-                    }
-
-                    _menu?.ShowSensors(st.Sensors, localPosition, st.Snap, st.Precision);
+                    _menu?.ShowSensors(st.Sensors, xform?.Coordinates, st.Snap, st.Precision);
                     break;
             }
         }
index 6e781ed92f55b1dd18e256cc77a4e7733b7fca23..46ad6a56bca45666162fad6d6373e8c20e220bf1 100644 (file)
@@ -43,10 +43,12 @@ namespace Content.Client.Medical.CrewMonitoring
             }
         }
 
-        public void ShowSensors(List<SuitSensorStatus> stSensors, Vector2 localPosition, bool snap, float precision)
+        public void ShowSensors(List<SuitSensorStatus> stSensors, EntityCoordinates? monitorCoords, bool snap, float precision)
         {
             ClearAllSensors();
 
+            var monitorCoordsInStationSpace = _stationUid != null ? monitorCoords?.WithEntityId(_stationUid.Value, _entManager).Position : null;
+
             // TODO scroll container
             // TODO filter by name & occupation
             // TODO make each row a xaml-control. Get rid of some of this c# control creation.
@@ -103,7 +105,7 @@ namespace Content.Client.Medical.CrewMonitoring
 
                 // add users positions
                 // format: (x, y)
-                var box = GetPositionBox(sensor.Coordinates, localPosition, snap, precision);
+                var box = GetPositionBox(sensor.Coordinates, monitorCoordsInStationSpace ?? Vector2.Zero, snap, precision);
 
                 SensorsTable.AddChild(box);
                 _rowsContent.Add(box);
@@ -134,13 +136,16 @@ namespace Content.Client.Medical.CrewMonitoring
                     };
                 }
             }
+            // For debugging.
+            //if (monitorCoords != null)
+            //    NavMap.TrackedCoordinates.Add(monitorCoords.Value, (true, Color.FromHex("#FF00FF")));
         }
 
-        private BoxContainer GetPositionBox(EntityCoordinates? coordinates, Vector2 sensorPosition, bool snap, float precision)
+        private BoxContainer GetPositionBox(EntityCoordinates? coordinates, Vector2 monitorCoordsInStationSpace, bool snap, float precision)
         {
             var box = new BoxContainer() { Orientation = LayoutOrientation.Horizontal };
 
-            if (coordinates == null || !_entManager.TryGetComponent<TransformComponent>(_stationUid, out var xform))
+            if (coordinates == null || _stationUid == null)
             {
                 var dirIcon = new DirectionIcon()
                 {
@@ -152,8 +157,7 @@ namespace Content.Client.Medical.CrewMonitoring
             }
             else
             {
-                var position = coordinates.Value.ToMapPos(_entManager);
-                var local = xform.InvWorldMatrix.Transform(position);
+                var local = coordinates.Value.WithEntityId(_stationUid.Value, _entManager).Position;
 
                 var displayPos = local.Floored();
                 var dirIcon = new DirectionIcon(snap, precision)
@@ -163,7 +167,7 @@ namespace Content.Client.Medical.CrewMonitoring
                 };
                 box.AddChild(dirIcon);
                 box.AddChild(new Label() { Text = displayPos.ToString() });
-                _directionIcons.Add((dirIcon, local - sensorPosition));
+                _directionIcons.Add((dirIcon, local - monitorCoordsInStationSpace));
             }
 
             return box;
@@ -173,10 +177,23 @@ namespace Content.Client.Medical.CrewMonitoring
         {
             // the window is separate from any specific viewport, so there is no real way to get an eye-rotation without
             // using IEyeManager. Eventually this will have to be reworked for a station AI with multi-viewports.
+            // (From the future: Or alternatively, just disable the angular offset for station AIs?)
+
+            // An offsetAngle of zero here perfectly aligns directions to the station map.
+            // Note that the "relative angle" does this weird inverse-inverse thing.
+            // Could recalculate it all in world coordinates and then pass in eye directly... or do this.
+            var offsetAngle = Angle.Zero;
+            if (_entManager.TryGetComponent<TransformComponent>(_stationUid, out var xform))
+            {
+                // Apply the offset relative to the eye.
+                // For a station at 45 degrees rotation, the current eye rotation is -45 degrees.
+                // TODO: This feels sketchy. Is there something underlying wrong with eye rotation?
+                offsetAngle = -(_eye.CurrentEye.Rotation + xform.WorldRotation);
+            }
 
             foreach (var (icon, pos) in _directionIcons)
             {
-                icon.UpdateDirection(pos, -_eye.CurrentEye.Rotation);
+                icon.UpdateDirection(pos, offsetAngle);
             }
         }
 
@@ -188,6 +205,7 @@ namespace Content.Client.Medical.CrewMonitoring
             }
 
             _rowsContent.Clear();
+            _directionIcons.Clear();
             NavMap.TrackedCoordinates.Clear();
         }
     }