mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
87 lines
2.6 KiB
C#
87 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using JetBrains.Annotations;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Robust.Client.GameObjects
|
|
{
|
|
/// <summary>
|
|
/// Updates the layer animation for every visible sprite.
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
public sealed class SpriteSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
|
[Dependency] private readonly RenderingTreeSystem _treeSystem = default!;
|
|
|
|
private readonly Queue<SpriteComponent> _inertUpdateQueue = new();
|
|
private HashSet<ISpriteComponent> _manualUpdate = new();
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<SpriteUpdateInertEvent>(QueueUpdateInert);
|
|
}
|
|
|
|
private void QueueUpdateInert(SpriteUpdateInertEvent ev)
|
|
{
|
|
_inertUpdateQueue.Enqueue(ev.Sprite);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void FrameUpdate(float frameTime)
|
|
{
|
|
while (_inertUpdateQueue.TryDequeue(out var sprite))
|
|
{
|
|
sprite.DoUpdateIsInert();
|
|
}
|
|
|
|
foreach (var sprite in _manualUpdate)
|
|
{
|
|
if (!sprite.Deleted && !sprite.IsInert)
|
|
sprite.FrameUpdate(frameTime);
|
|
}
|
|
|
|
var pvsBounds = _eyeManager.GetWorldViewbounds();
|
|
|
|
var currentMap = _eyeManager.CurrentMap;
|
|
if (currentMap == MapId.Nullspace)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var xforms = EntityManager.GetEntityQuery<TransformComponent>();
|
|
|
|
foreach (var comp in _treeSystem.GetRenderTrees(currentMap, pvsBounds))
|
|
{
|
|
var bounds = xforms.GetComponent(comp.Owner).InvWorldMatrix.TransformBox(pvsBounds);
|
|
|
|
comp.SpriteTree.QueryAabb(ref frameTime, (ref float state, in SpriteComponent value) =>
|
|
{
|
|
if (value.IsInert)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (!_manualUpdate.Contains(value))
|
|
value.FrameUpdate(state);
|
|
return true;
|
|
}, bounds, true);
|
|
}
|
|
|
|
_manualUpdate.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Force update of the sprite component next frame
|
|
/// </summary>
|
|
public void ForceUpdate(ISpriteComponent sprite)
|
|
{
|
|
_manualUpdate.Add(sprite);
|
|
}
|
|
}
|
|
}
|