mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 14:52:35 +02:00
* Work on shadow casting. * Shadowcasting depth works, code cleanup * Adds #include support to SWSL parser. * Move lighting shader to swsl. Also more shader parser fixes. * Move PI constant to correct file. * Got functional FOV, working on wall bleed. * Hey, it kinda works. * Occluder component now lives in shared. * Optimizations. * Fix light map color format. I set it to something else while testing perf. * Front face cull final FOV pass. * Fix holes in occlusion geometry due to disabled occluders. * Starting work on better wall handling. * Some comments. * Improve font-face-culled FOV pass. * Improve various light biasing things. * VSM, smooth shadows. Also unused VSM blurring because it didn't work but committing it like this will forever keep it in Git somewhere. * FOV smoothing, looks kinda awful. * Base wall bleed blur strength on camera size. * The part where I give up. * Comments. Many comments. * Allow eyes to disable FOV. * Improve OccluderComponent on the client. * Update for occluder component changes. * Maybe do this properly...
118 lines
3.9 KiB
C#
118 lines
3.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Components.Transform;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.Interfaces.Map;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.Client.GameObjects.EntitySystems
|
|
{
|
|
internal sealed class OccluderSystem : EntitySystem
|
|
{
|
|
#pragma warning disable 649
|
|
[Dependency] private readonly IMapManager _mapManager;
|
|
#pragma warning restore 649
|
|
|
|
private readonly Queue<IEntity> _dirtyEntities = new Queue<IEntity>();
|
|
|
|
private uint _updateGeneration;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<OccluderDirtyEvent>(HandleDirtyEvent);
|
|
}
|
|
|
|
public override void FrameUpdate(float frameTime)
|
|
{
|
|
base.FrameUpdate(frameTime);
|
|
|
|
if (_dirtyEntities.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_updateGeneration += 1;
|
|
|
|
while (_dirtyEntities.TryDequeue(out var entity))
|
|
{
|
|
if (!entity.Deleted
|
|
&& entity.TryGetComponent(out ClientOccluderComponent occluder)
|
|
&& occluder.UpdateGeneration != _updateGeneration)
|
|
{
|
|
occluder.Update();
|
|
|
|
occluder.UpdateGeneration = _updateGeneration;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void HandleDirtyEvent(OccluderDirtyEvent ev)
|
|
{
|
|
var sender = ev.Sender;
|
|
if (sender.IsValid() &&
|
|
sender.TryGetComponent(out ClientOccluderComponent iconSmooth)
|
|
&& iconSmooth.Running)
|
|
{
|
|
var snapGrid = sender.GetComponent<SnapGridComponent>();
|
|
|
|
_dirtyEntities.Enqueue(sender);
|
|
AddValidEntities(snapGrid.GetInDir(Direction.North));
|
|
AddValidEntities(snapGrid.GetInDir(Direction.South));
|
|
AddValidEntities(snapGrid.GetInDir(Direction.East));
|
|
AddValidEntities(snapGrid.GetInDir(Direction.West));
|
|
}
|
|
|
|
if (ev.LastPosition.HasValue)
|
|
{
|
|
// Entity is no longer valid, update around the last position it was at.
|
|
var grid = _mapManager.GetGrid(ev.LastPosition.Value.grid);
|
|
var pos = ev.LastPosition.Value.pos;
|
|
|
|
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, 0), ev.Offset));
|
|
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, 0), ev.Offset));
|
|
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(0, 1), ev.Offset));
|
|
AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(0, -1), ev.Offset));
|
|
}
|
|
}
|
|
|
|
private void AddValidEntities(IEnumerable<IEntity> candidates)
|
|
{
|
|
foreach (var entity in candidates)
|
|
{
|
|
if (entity.HasComponent<ClientOccluderComponent>())
|
|
{
|
|
_dirtyEntities.Enqueue(entity);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AddValidEntities(IEnumerable<IComponent> candidates)
|
|
{
|
|
AddValidEntities(candidates.Select(c => c.Owner));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event raised by a <see cref="ClientOccluderComponent"/> when it needs to be recalculated.
|
|
/// </summary>
|
|
internal sealed class OccluderDirtyEvent : EntitySystemMessage
|
|
{
|
|
public OccluderDirtyEvent(IEntity sender, (GridId grid, MapIndices pos)? lastPosition, SnapGridOffset offset)
|
|
{
|
|
LastPosition = lastPosition;
|
|
Offset = offset;
|
|
Sender = sender;
|
|
}
|
|
|
|
public (GridId grid, MapIndices pos)? LastPosition { get; }
|
|
public SnapGridOffset Offset { get; }
|
|
public IEntity Sender { get; }
|
|
}
|
|
}
|