Fires burn bright (#6516)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
hubismal
2022-02-08 04:43:33 -06:00
committed by GitHub
parent 11f650a459
commit 1c6df07086
4 changed files with 100 additions and 20 deletions

View File

@@ -1,7 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Client.Atmos.Overlays;
using Content.Shared.Atmos;
using Content.Shared.Atmos.EntitySystems;
@@ -9,9 +5,7 @@ using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.Utility;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
namespace Content.Client.Atmos.EntitySystems
@@ -41,6 +35,8 @@ namespace Content.Client.Atmos.EntitySystems
private readonly Dictionary<GridId, Dictionary<Vector2i, GasOverlayChunk>> _tileData =
new();
public const int GasOverlayZIndex = 1;
public override void Initialize()
{
base.Initialize();
@@ -86,8 +82,8 @@ namespace Content.Client.Atmos.EntitySystems
}
var overlayManager = IoCManager.Resolve<IOverlayManager>();
if(!overlayManager.HasOverlay<GasTileOverlay>())
overlayManager.AddOverlay(new GasTileOverlay());
overlayManager.AddOverlay(new GasTileOverlay());
overlayManager.AddOverlay(new FireTileOverlay());
}
private void HandleGasOverlayMessage(GasOverlayMessage message)
@@ -124,8 +120,8 @@ namespace Content.Client.Atmos.EntitySystems
base.Shutdown();
_mapManager.OnGridRemoved -= OnGridRemoved;
var overlayManager = IoCManager.Resolve<IOverlayManager>();
if(!overlayManager.HasOverlay<GasTileOverlay>())
overlayManager.RemoveOverlay<GasTileOverlay>();
overlayManager.RemoveOverlay<GasTileOverlay>();
overlayManager.RemoveOverlay<FireTileOverlay>();
}
private void OnGridRemoved(MapId mapId, GridId gridId)
@@ -155,6 +151,20 @@ namespace Content.Client.Atmos.EntitySystems
return new GasOverlayEnumerator(overlays, this);
}
public FireOverlayEnumerator GetFireOverlays(GridId gridIndex, Vector2i indices)
{
if (!_tileData.TryGetValue(gridIndex, out var chunks))
return default;
var chunkIndex = GetGasChunkIndices(indices);
if (!chunks.TryGetValue(chunkIndex, out var chunk))
return default;
var overlays = chunk.GetData(indices);
return new FireOverlayEnumerator(overlays, this);
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
@@ -184,11 +194,10 @@ namespace Content.Client.Atmos.EntitySystems
}
}
public struct GasOverlayEnumerator : IDisposable
public struct GasOverlayEnumerator
{
private readonly GasTileOverlaySystem _system;
private readonly GasData[]? _data;
private byte _fireState;
// TODO: Take Fire Temperature into account, when we code fire color
private readonly int _length; // We cache the length so we can avoid a pointer dereference, for speed. Brrr.
@@ -198,7 +207,6 @@ namespace Content.Client.Atmos.EntitySystems
{
// Gas can't be null, as the caller to this constructor already ensured it wasn't.
_data = data.Gas;
_fireState = data.FireState;
_system = system;
@@ -217,6 +225,25 @@ namespace Content.Client.Atmos.EntitySystems
return true;
}
overlay = default;
return false;
}
}
public struct FireOverlayEnumerator
{
private readonly GasTileOverlaySystem _system;
private byte _fireState;
// TODO: Take Fire Temperature into account, when we code fire color
public FireOverlayEnumerator(in GasOverlayData data, GasTileOverlaySystem system)
{
_fireState = data.FireState;
_system = system;
}
public bool MoveNext(out (Texture Texture, Color Color) overlay)
{
if (_fireState != 0)
{
var state = _fireState - 1;
@@ -232,10 +259,6 @@ namespace Content.Client.Atmos.EntitySystems
overlay = default;
return false;
}
public void Dispose()
{
}
}
}
}