address all reviews

This commit is contained in:
Víctor Aguilera Puerto
2020-09-12 20:10:56 +02:00
parent efcd29bff8
commit fa74e9f19f
6 changed files with 22 additions and 17 deletions

View File

@@ -1101,7 +1101,7 @@ namespace Content.Server.Atmos
reconsiderAdjacent |= firelock.EmergencyPressureStop(); reconsiderAdjacent |= firelock.EmergencyPressureStop();
} }
foreach (var entity in other.GridIndices.GetEntitiesInTile(other.GridIndex)) foreach (var entity in other.GridIndices.GetEntitiesInTileFast(other.GridIndex))
{ {
if (!entity.TryGetComponent(out FirelockComponent firelock)) continue; if (!entity.TryGetComponent(out FirelockComponent firelock)) continue;
reconsiderAdjacent |= firelock.EmergencyPressureStop(); reconsiderAdjacent |= firelock.EmergencyPressureStop();

View File

@@ -24,6 +24,7 @@ namespace Content.Server.GameObjects.Components.Atmos
[Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!;
private (GridId, MapIndices) _lastPosition; private (GridId, MapIndices) _lastPosition;
private AtmosphereSystem _atmosphereSystem = default!;
public override string Name => "Airtight"; public override string Name => "Airtight";
@@ -79,6 +80,8 @@ namespace Content.Server.GameObjects.Components.Atmos
{ {
base.Initialize(); base.Initialize();
_atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
// Using the SnapGrid is critical for performance, and thus if it is absent the component // Using the SnapGrid is critical for performance, and thus if it is absent the component
// will not be airtight. A warning is much easier to track down than the object magically // will not be airtight. A warning is much easier to track down than the object magically
// not being airtight, so log one if the SnapGrid component is missing. // not being airtight, so log one if the SnapGrid component is missing.
@@ -140,7 +143,7 @@ namespace Content.Server.GameObjects.Components.Atmos
UpdatePosition(_lastPosition.Item1, _lastPosition.Item2); UpdatePosition(_lastPosition.Item1, _lastPosition.Item2);
if (_fixVacuum) if (_fixVacuum)
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(_lastPosition.Item1)?.FixVacuum(_lastPosition.Item2); _atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1)?.FixVacuum(_lastPosition.Item2);
} }
private void OnTransformMove() private void OnTransformMove()
@@ -162,7 +165,7 @@ namespace Content.Server.GameObjects.Components.Atmos
private void UpdatePosition(GridId gridId, MapIndices pos) private void UpdatePosition(GridId gridId, MapIndices pos)
{ {
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId); var gridAtmos = _atmosphereSystem.GetGridAtmosphere(gridId);
if (gridAtmos == null) return; if (gridAtmos == null) return;

View File

@@ -6,6 +6,7 @@ using Content.Server.GameObjects.Components.Interactable;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Shared.GameObjects.Components.Doors; using Content.Shared.GameObjects.Components.Doors;
using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components;
@@ -17,8 +18,6 @@ namespace Content.Server.GameObjects.Components.Atmos
[RegisterComponent] [RegisterComponent]
public class FirelockComponent : ServerDoorComponent, IInteractUsing, ICollideBehavior public class FirelockComponent : ServerDoorComponent, IInteractUsing, ICollideBehavior
{ {
[Dependency] private IServerNotifyManager _notifyManager = default!;
public override string Name => "Firelock"; public override string Name => "Firelock";
protected override TimeSpan CloseTimeOne => TimeSpan.FromSeconds(0.1f); protected override TimeSpan CloseTimeOne => TimeSpan.FromSeconds(0.1f);
@@ -87,7 +86,7 @@ namespace Content.Server.GameObjects.Components.Atmos
if (State == DoorState.Closed) if (State == DoorState.Closed)
{ {
if(holdingPressure) if(holdingPressure)
_notifyManager.PopupMessage(Owner, eventArgs.User, "A gush of air blows in your face... Maybe you should reconsider."); Owner.PopupMessage(eventArgs.User, "A gush of air blows in your face... Maybe you should reconsider.");
} }
if (!await tool.UseTool(eventArgs.User, Owner, holdingPressure || holdingFire ? 1.5f : 0.25f, ToolQuality.Prying)) return false; if (!await tool.UseTool(eventArgs.User, Owner, holdingPressure || holdingFire ? 1.5f : 0.25f, ToolQuality.Prying)) return false;

View File

@@ -16,6 +16,7 @@ using Robust.Shared.GameObjects.Components.Map;
using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -34,6 +35,7 @@ namespace Content.Server.GameObjects.Components.Atmos
[Robust.Shared.IoC.Dependency] private ITileDefinitionManager _tileDefinitionManager = default!; [Robust.Shared.IoC.Dependency] private ITileDefinitionManager _tileDefinitionManager = default!;
[Robust.Shared.IoC.Dependency] private IServerEntityManager _serverEntityManager = default!; [Robust.Shared.IoC.Dependency] private IServerEntityManager _serverEntityManager = default!;
/// <summary> /// <summary>
/// Check current execution time every n instances processed. /// Check current execution time every n instances processed.
/// </summary> /// </summary>

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; #nullable enable
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Content.Shared.Maps; using Content.Shared.Maps;
@@ -15,9 +16,9 @@ namespace Content.Server.Utility
/// Helper that returns all entities in a turf very fast. /// Helper that returns all entities in a turf very fast.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IEntity> GetEntitiesInTileFast(this TileRef turf) public static IEnumerable<IEntity> GetEntitiesInTileFast(this TileRef turf, GridTileLookupSystem? gridTileLookup = null)
{ {
var gridTileLookup = EntitySystem.Get<GridTileLookupSystem>(); gridTileLookup ??= EntitySystem.Get<GridTileLookupSystem>();
return gridTileLookup.GetEntitiesIntersecting(turf.GridIndex, turf.GridIndices); return gridTileLookup.GetEntitiesIntersecting(turf.GridIndex, turf.GridIndices);
} }
@@ -26,14 +27,14 @@ namespace Content.Server.Utility
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IEntity> GetEntitiesInTileFast(this MapIndices indices, GridId gridId) public static IEnumerable<IEntity> GetEntitiesInTileFast(this MapIndices indices, GridId gridId, GridTileLookupSystem? gridTileLookup = null)
{ {
var turf = indices.GetTileRef(gridId); var turf = indices.GetTileRef(gridId);
if (turf == null) if (turf == null)
return Enumerable.Empty<IEntity>(); return Enumerable.Empty<IEntity>();
return GetEntitiesInTileFast(turf.Value); return GetEntitiesInTileFast(turf.Value, gridTileLookup);
} }
} }
} }

View File

@@ -124,9 +124,9 @@ namespace Content.Shared.Maps
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IEntity> GetEntitiesInTile(this TileRef turf, bool approximate = false) public static IEnumerable<IEntity> GetEntitiesInTile(this TileRef turf, bool approximate = false, IEntityManager? entityManager = null)
{ {
var entityManager = IoCManager.Resolve<IEntityManager>(); entityManager ??= IoCManager.Resolve<IEntityManager>();
return entityManager.GetEntitiesIntersecting(turf.MapIndex, GetWorldTileBox(turf), approximate); return entityManager.GetEntitiesIntersecting(turf.MapIndex, GetWorldTileBox(turf), approximate);
} }
@@ -134,27 +134,27 @@ namespace Content.Shared.Maps
/// <summary> /// <summary>
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
public static IEnumerable<IEntity> GetEntitiesInTile(this EntityCoordinates coordinates, bool approximate = false) public static IEnumerable<IEntity> GetEntitiesInTile(this EntityCoordinates coordinates, bool approximate = false, IEntityManager? entityManager = null)
{ {
var turf = coordinates.GetTileRef(); var turf = coordinates.GetTileRef();
if (turf == null) if (turf == null)
return Enumerable.Empty<IEntity>(); return Enumerable.Empty<IEntity>();
return GetEntitiesInTile(turf.Value); return GetEntitiesInTile(turf.Value, approximate, entityManager);
} }
/// <summary> /// <summary>
/// Helper that returns all entities in a turf. /// Helper that returns all entities in a turf.
/// </summary> /// </summary>
public static IEnumerable<IEntity> GetEntitiesInTile(this MapIndices indices, GridId gridId, bool approximate = false) public static IEnumerable<IEntity> GetEntitiesInTile(this MapIndices indices, GridId gridId, bool approximate = false, IEntityManager? entityManager = null)
{ {
var turf = indices.GetTileRef(gridId); var turf = indices.GetTileRef(gridId);
if (turf == null) if (turf == null)
return Enumerable.Empty<IEntity>(); return Enumerable.Empty<IEntity>();
return GetEntitiesInTile(turf.Value); return GetEntitiesInTile(turf.Value, approximate, entityManager);
} }
/// <summary> /// <summary>