Skip to content

Commit b8b81c0

Browse files
ElectroJrstellar-novas
authored andcommitted
Resolve conflicts with #26102
1 parent aa28ce4 commit b8b81c0

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

Content.Server/Spreader/SpreaderSystem.cs

+29-30
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public sealed class SpreaderSystem : EntitySystem
3333
// TODO PERFORMANCE Assign each prototype to an index and convert dictionary to array
3434
private readonly Dictionary<EntityUid, Dictionary<string, int>> _gridUpdates = [];
3535

36+
private EntityQuery<EdgeSpreaderComponent> _query;
37+
3638
public const float SpreadCooldownSeconds = 1;
3739

3840
[ValidatePrototypeId<TagPrototype>]
@@ -47,6 +49,8 @@ public override void Initialize()
4749

4850
SubscribeLocalEvent<EdgeSpreaderComponent, EntityTerminatingEvent>(OnTerminating);
4951
SetupPrototypes();
52+
53+
_query = GetEntityQuery<EdgeSpreaderComponent>();
5054
}
5155

5256
private void OnPrototypeReload(PrototypesReloadedEventArgs obj)
@@ -66,7 +70,7 @@ private void SetupPrototypes()
6670

6771
private void OnAirtightChanged(ref AirtightChanged ev)
6872
{
69-
ActivateGetSpreadableNeighbors(ev.Entity, ev.Airtight, ev.Position);
73+
ActivateSpreadableNeighbors(ev.Entity, ev.Position);
7074
}
7175

7276
private void OnGridInit(GridInitializeEvent ev)
@@ -76,13 +80,7 @@ private void OnGridInit(GridInitializeEvent ev)
7680

7781
private void OnTerminating(Entity<EdgeSpreaderComponent> entity, ref EntityTerminatingEvent args)
7882
{
79-
var neighbors = GetSpreadableNeighbors(entity);
80-
81-
foreach (var neighbor in neighbors)
82-
{
83-
if (!TerminatingOrDeleted(neighbor))
84-
EnsureComp<ActiveEdgeSpreaderComponent>(neighbor);
85-
}
83+
ActivateSpreadableNeighbors(entity);
8684
}
8785

8886
/// <inheritdoc/>
@@ -248,8 +246,7 @@ public void GetNeighbors(EntityUid uid, TransformComponent comp, ProtoId<EdgeSpr
248246
if (!_map.TryGetTileRef(neighborEnt, neighborGrid, neighborPos, out var tileRef) || tileRef.Tile.IsEmpty)
249247
continue;
250248

251-
var directionEnumerator =
252-
_map.GetAnchoredEntitiesEnumerator(neighborEnt, neighborGrid, neighborPos);
249+
var directionEnumerator = _map.GetAnchoredEntitiesEnumerator(neighborEnt, neighborGrid, neighborPos);
253250
var occupied = false;
254251

255252
while (directionEnumerator.MoveNext(out var ent))
@@ -271,8 +268,7 @@ public void GetNeighbors(EntityUid uid, TransformComponent comp, ProtoId<EdgeSpr
271268
continue;
272269

273270
var oldCount = occupiedTiles.Count;
274-
directionEnumerator =
275-
_map.GetAnchoredEntitiesEnumerator(neighborEnt, neighborGrid, neighborPos);
271+
directionEnumerator = _map.GetAnchoredEntitiesEnumerator(neighborEnt, neighborGrid, neighborPos);
276272

277273
while (directionEnumerator.MoveNext(out var ent))
278274
{
@@ -293,13 +289,11 @@ public void GetNeighbors(EntityUid uid, TransformComponent comp, ProtoId<EdgeSpr
293289
}
294290

295291
/// <summary>
296-
/// Given an entity, this returns a list of all adjacent entities with a <see cref="EdgeSpreaderComponent"/>.
292+
/// This function activates all spreaders that are adjacent to a given entity. This also activates other spreaders
293+
/// on the same tile as the current entity (for thin airtight entities like windoors).
297294
/// </summary>
298-
public void ActivateGetSpreadableNeighbors(EntityUid uid, AirtightComponent? comp = null,
299-
(EntityUid Grid, Vector2i Tile)? position = null)
295+
public void ActivateSpreadableNeighbors(EntityUid uid, (EntityUid Grid, Vector2i Tile)? position = null)
300296
{
301-
Resolve(uid, ref comp, false);
302-
303297
Vector2i tile;
304298
EntityUid ent;
305299
MapGridComponent? grid;
@@ -308,34 +302,39 @@ public void ActivateGetSpreadableNeighbors(EntityUid uid, AirtightComponent? com
308302
{
309303
var transform = Transform(uid);
310304
if (!TryComp(transform.GridUid, out grid) || TerminatingOrDeleted(transform.GridUid.Value))
311-
return neighbors;
305+
return;
306+
312307
tile = _map.TileIndicesFor(transform.GridUid.Value, grid, transform.Coordinates);
313308
ent = transform.GridUid.Value;
314309
}
315310
else
316311
{
317312
if (!TryComp(position.Value.Grid, out grid))
318-
return neighbors;
319-
tile = position.Value.Tile;
320-
ent = position.Value.Grid;
313+
return;
314+
(ent, tile) = position.Value;
321315
}
322316

323-
var spreaderQuery = GetEntityQuery<EdgeSpreaderComponent>();
317+
var anchored = _map.GetAnchoredEntitiesEnumerator(ent, grid, tile);
318+
while (anchored.MoveNext(out var entity))
319+
{
320+
if (entity == ent)
321+
continue;
322+
DebugTools.Assert(Transform(entity.Value).Anchored);
323+
if (_query.HasComponent(ent) && !TerminatingOrDeleted(entity.Value))
324+
EnsureComp<ActiveEdgeSpreaderComponent>(entity.Value);
325+
}
324326

325327
for (var i = 0; i < Atmospherics.Directions; i++)
326328
{
327329
var direction = (AtmosDirection) (1 << i);
328-
if (comp != null && !comp.AirBlockedDirection.IsFlagSet(direction))
329-
continue;
330-
331-
var directionEnumerator =
332-
_map.GetAnchoredEntitiesEnumerator(ent, grid, SharedMapSystem.GetDirection(tile, direction.ToDirection()));
330+
var adjacentTile = SharedMapSystem.GetDirection(tile, direction.ToDirection());
331+
anchored = _map.GetAnchoredEntitiesEnumerator(ent, grid, adjacentTile);
333332

334-
while (directionEnumerator.MoveNext(out var entity))
333+
while (anchored.MoveNext(out var entity))
335334
{
336335
DebugTools.Assert(Transform(entity.Value).Anchored);
337-
if (spreaderQuery.HasComponent(entity) && !TerminatingOrDeleted(entity.Value))
338-
neighbors.Add(entity.Value);
336+
if (_query.HasComponent(ent) && !TerminatingOrDeleted(entity.Value))
337+
EnsureComp<ActiveEdgeSpreaderComponent>(entity.Value);
339338
}
340339
}
341340
}

0 commit comments

Comments
 (0)