Skip to content

Commit

Permalink
change _active to BurningComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
deltanedas committed Sep 24, 2024
1 parent 06b83b1 commit bb82e09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
25 changes: 7 additions & 18 deletions Content.Server/Nutrition/EntitySystems/SmokingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public sealed partial class SmokingSystem : EntitySystem

private float _timer;

/// <summary>
/// We keep a list of active smokables, because iterating all existing smokables would be dumb.
/// </summary>
private readonly HashSet<EntityUid> _active = new();

public override void Initialize()
{
SubscribeLocalEvent<SmokableComponent, IsHotEvent>(OnSmokableIsHotEvent);
Expand All @@ -57,7 +52,7 @@ public override void Initialize()
public void SetSmokableState(EntityUid uid, SmokableState state, SmokableComponent? smokable = null,
AppearanceComponent? appearance = null, ClothingComponent? clothing = null)
{
if (!Resolve(uid, ref smokable, ref appearance, ref clothing))
if (!Resolve(uid, ref smokable, ref appearance, ref clothing) || smokable.State == state)
return;

smokable.State = state;
Expand All @@ -74,9 +69,9 @@ public void SetSmokableState(EntityUid uid, SmokableState state, SmokableCompone
_items.SetHeldPrefix(uid, newState);

if (state == SmokableState.Lit)
_active.Add(uid);
EnsureComp<BurningComponent>(uid);
else
_active.Remove(uid);
RemComp<BurningComponent>(uid);
}

private void OnSmokableIsHotEvent(Entity<SmokableComponent> entity, ref IsHotEvent args)
Expand All @@ -86,7 +81,7 @@ private void OnSmokableIsHotEvent(Entity<SmokableComponent> entity, ref IsHotEve

private void OnSmokableShutdownEvent(Entity<SmokableComponent> entity, ref ComponentShutdown args)
{
_active.Remove(entity);
RemComp<BurningComponent>(entity);
}

private void OnSmokeableEquipEvent(Entity<SmokableComponent> entity, ref GotEquippedEvent args)
Expand All @@ -104,18 +99,12 @@ public override void Update(float frameTime)
if (_timer < UpdateTimer)
return;

// TODO Use an "active smoke" component instead, EntityQuery over that.
foreach (var uid in _active.ToArray())
var query = EntityQueryEnumerator<BurningComponent, SmokableComponent>();
while (query.MoveNext(out var uid, out _, out var smokable))
{
if (!TryComp(uid, out SmokableComponent? smokable))
{
_active.Remove(uid);
continue;
}

if (!_solutionContainerSystem.TryGetSolution(uid, smokable.Solution, out var soln, out var solution))
{
_active.Remove(uid);
SetSmokableState(uid, SmokableState.Unlit, smokable);
continue;
}

Expand Down
10 changes: 10 additions & 0 deletions Content.Shared/Smoking/BurningComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Shared.Smoking;

/// <summary>
/// Marker component used to track active burning objects.
/// </summary>
/// <remarks>
/// Right now only smoking uses this, but flammable could use it as well in the future.
/// </remarks>
[RegisterComponent]
public sealed partial class BurningComponent : Component;

0 comments on commit bb82e09

Please sign in to comment.