Remove explosion visuals component references (#15264)

This commit is contained in:
DrSmugleaf
2023-04-19 03:09:22 -07:00
committed by GitHub
parent 52fb725cf3
commit e95cd6e412
5 changed files with 44 additions and 39 deletions

View File

@@ -32,27 +32,35 @@ public sealed class ExplosionOverlay : Overlay
drawHandle.UseShader(_shader); drawHandle.UseShader(_shader);
var xforms = _entMan.GetEntityQuery<TransformComponent>(); var xforms = _entMan.GetEntityQuery<TransformComponent>();
var query = _entMan
.EntityQuery<ExplosionVisualsComponent, ExplosionVisualsTexturesComponent, AppearanceComponent>(true);
foreach (var (comp, appearance) in _entMan.EntityQuery<ExplosionVisualsComponent, AppearanceComponent>(true)) foreach (var (visuals, textures, appearance) in query)
{ {
if (comp.Epicenter.MapId != args.MapId) if (visuals.Epicenter.MapId != args.MapId)
continue; continue;
if (!appearance.TryGetData(ExplosionAppearanceData.Progress, out int index)) if (!appearance.TryGetData(ExplosionAppearanceData.Progress, out int index))
continue; continue;
index = Math.Min(index, comp.Intensity.Count - 1); index = Math.Min(index, visuals.Intensity.Count - 1);
DrawExplosion(drawHandle, args.WorldBounds, comp, index, xforms); DrawExplosion(drawHandle, args.WorldBounds, visuals, index, xforms, textures);
} }
drawHandle.SetTransform(Matrix3.Identity); drawHandle.SetTransform(Matrix3.Identity);
drawHandle.UseShader(null); drawHandle.UseShader(null);
} }
private void DrawExplosion(DrawingHandleWorld drawHandle, Box2Rotated worldBounds, ExplosionVisualsComponent exp, int index, EntityQuery<TransformComponent> xforms) private void DrawExplosion(
DrawingHandleWorld drawHandle,
Box2Rotated worldBounds,
ExplosionVisualsComponent visuals,
int index,
EntityQuery<TransformComponent> xforms,
ExplosionVisualsTexturesComponent textures)
{ {
Box2 gridBounds; Box2 gridBounds;
foreach (var (gridId, tiles) in exp.Tiles) foreach (var (gridId, tiles) in visuals.Tiles)
{ {
if (!_mapManager.TryGetGrid(gridId, out var grid)) if (!_mapManager.TryGetGrid(gridId, out var grid))
continue; continue;
@@ -63,16 +71,16 @@ public sealed class ExplosionOverlay : Overlay
gridBounds = invWorldMatrix.TransformBox(worldBounds).Enlarged(grid.TileSize * 2); gridBounds = invWorldMatrix.TransformBox(worldBounds).Enlarged(grid.TileSize * 2);
drawHandle.SetTransform(worldMatrix); drawHandle.SetTransform(worldMatrix);
DrawTiles(drawHandle, gridBounds, index, tiles, exp, grid.TileSize); DrawTiles(drawHandle, gridBounds, index, tiles, visuals, grid.TileSize, textures);
} }
if (exp.SpaceTiles == null) if (visuals.SpaceTiles == null)
return; return;
gridBounds = Matrix3.Invert(exp.SpaceMatrix).TransformBox(worldBounds).Enlarged(2); gridBounds = Matrix3.Invert(visuals.SpaceMatrix).TransformBox(worldBounds).Enlarged(2);
drawHandle.SetTransform(exp.SpaceMatrix); drawHandle.SetTransform(visuals.SpaceMatrix);
DrawTiles(drawHandle, gridBounds, index, exp.SpaceTiles, exp, exp.SpaceTileSize); DrawTiles(drawHandle, gridBounds, index, visuals.SpaceTiles, visuals, visuals.SpaceTileSize, textures);
} }
private void DrawTiles( private void DrawTiles(
@@ -80,26 +88,27 @@ public sealed class ExplosionOverlay : Overlay
Box2 gridBounds, Box2 gridBounds,
int index, int index,
Dictionary<int, List<Vector2i>> tileSets, Dictionary<int, List<Vector2i>> tileSets,
ExplosionVisualsComponent exp, ExplosionVisualsComponent visuals,
ushort tileSize) ushort tileSize,
ExplosionVisualsTexturesComponent textures)
{ {
for (var j = 0; j <= index; j++) for (var j = 0; j <= index; j++)
{ {
if (!tileSets.TryGetValue(j, out var tiles)) if (!tileSets.TryGetValue(j, out var tiles))
continue; continue;
var frameIndex = (int) Math.Min(exp.Intensity[j] / exp.IntensityPerState, exp.FireFrames.Count - 1); var frameIndex = (int) Math.Min(visuals.Intensity[j] / textures.IntensityPerState, textures.FireFrames.Count - 1);
var frames = exp.FireFrames[frameIndex]; var frames = textures.FireFrames[frameIndex];
foreach (var tile in tiles) foreach (var tile in tiles)
{ {
Vector2 centre = ((Vector2) tile + 0.5f) * tileSize; var centre = ((Vector2) tile + 0.5f) * tileSize;
if (!gridBounds.Contains(centre)) if (!gridBounds.Contains(centre))
continue; continue;
var texture = _robustRandom.Pick(frames); var texture = _robustRandom.Pick(frames);
drawHandle.DrawTextureRect(texture, Box2.CenteredAround(centre, (tileSize, tileSize)), exp.FireColor); drawHandle.DrawTextureRect(texture, Box2.CenteredAround(centre, (tileSize, tileSize)), textures.FireColor);
} }
} }
} }

View File

@@ -48,28 +48,35 @@ public sealed class ExplosionOverlaySystem : EntitySystem
private void OnCompRemove(EntityUid uid, ExplosionVisualsComponent component, ComponentRemove args) private void OnCompRemove(EntityUid uid, ExplosionVisualsComponent component, ComponentRemove args)
{ {
QueueDel(component.LightEntity); if (TryComp(uid, out ExplosionVisualsTexturesComponent? textures))
QueueDel(textures.LightEntity);
} }
private void OnExplosionInit(EntityUid uid, ExplosionVisualsComponent component, ComponentInit args) private void OnExplosionInit(EntityUid uid, ExplosionVisualsComponent component, ComponentInit args)
{ {
if (!_protoMan.TryIndex(component.ExplosionType, out ExplosionPrototype? type)) EnsureComp<ExplosionVisualsTexturesComponent>(uid);
if (!_protoMan.TryIndex(component.ExplosionType, out ExplosionPrototype? type) ||
!TryComp(uid, out ExplosionVisualsTexturesComponent? textures))
{
return; return;
}
// spawn in a client-side light source at the epicenter // spawn in a client-side light source at the epicenter
var lightEntity = Spawn("ExplosionLight", component.Epicenter); var lightEntity = Spawn("ExplosionLight", component.Epicenter);
var light = EnsureComp<PointLightComponent>(lightEntity); var light = EnsureComp<PointLightComponent>(lightEntity);
light.Energy = light.Radius = component.Intensity.Count; light.Energy = light.Radius = component.Intensity.Count;
light.Color = type.LightColor; light.Color = type.LightColor;
component.LightEntity = lightEntity;
component.FireColor = type.FireColor; textures.LightEntity = lightEntity;
component.IntensityPerState = type.IntensityPerState; textures.FireColor = type.FireColor;
textures.IntensityPerState = type.IntensityPerState;
var fireRsi = _resCache.GetResource<RSIResource>(type.TexturePath).RSI; var fireRsi = _resCache.GetResource<RSIResource>(type.TexturePath).RSI;
foreach (var state in fireRsi) foreach (var state in fireRsi)
{ {
component.FireFrames.Add(state.GetFrames(RSI.State.Direction.South)); textures.FireFrames.Add(state.GetFrames(RSI.State.Direction.South));
if (component.FireFrames.Count == type.FireStates) if (textures.FireFrames.Count == type.FireStates)
break; break;
} }
} }

View File

@@ -1,11 +1,9 @@
using Content.Shared.Explosion;
using Robust.Client.Graphics; using Robust.Client.Graphics;
namespace Content.Client.Explosion; namespace Content.Client.Explosion;
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(SharedExplosionVisualsComponent))] public sealed class ExplosionVisualsTexturesComponent : Component
public sealed class ExplosionVisualsComponent : SharedExplosionVisualsComponent
{ {
/// <summary> /// <summary>
/// Uid of the client-side point light entity for this explosion. /// Uid of the client-side point light entity for this explosion.

View File

@@ -1,9 +0,0 @@
using Content.Shared.Explosion;
namespace Content.Server.Explosion;
[RegisterComponent]
[ComponentReference(typeof(SharedExplosionVisualsComponent))]
public sealed class ExplosionVisualsComponent : SharedExplosionVisualsComponent
{
}

View File

@@ -7,8 +7,8 @@ namespace Content.Shared.Explosion;
/// <summary> /// <summary>
/// Component that is used to send explosion overlay/visual data to an abstract explosion entity. /// Component that is used to send explosion overlay/visual data to an abstract explosion entity.
/// </summary> /// </summary>
[NetworkedComponent] [RegisterComponent, NetworkedComponent]
public abstract class SharedExplosionVisualsComponent : Component public sealed class ExplosionVisualsComponent : Component
{ {
public MapCoordinates Epicenter; public MapCoordinates Epicenter;
public Dictionary<int, List<Vector2i>>? SpaceTiles; public Dictionary<int, List<Vector2i>>? SpaceTiles;
@@ -52,5 +52,5 @@ public sealed class ExplosionVisualsState : ComponentState
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum ExplosionAppearanceData public enum ExplosionAppearanceData
{ {
Progress, // iteration index tracker for explosions that are still expanding outwards, Progress, // iteration index tracker for explosions that are still expanding outwards,
} }