Add tile entity occlusion (#14626)
This commit is contained in:
55
Content.Client/Movement/Systems/FloorOcclusionSystem.cs
Normal file
55
Content.Client/Movement/Systems/FloorOcclusionSystem.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Movement.Systems;
|
||||
|
||||
public sealed class FloorOcclusionSystem : SharedFloorOcclusionSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<FloorOcclusionComponent, ComponentStartup>(OnOcclusionStartup);
|
||||
SubscribeLocalEvent<FloorOcclusionComponent, AfterAutoHandleStateEvent>(OnOcclusionAuto);
|
||||
}
|
||||
|
||||
private void OnOcclusionAuto(EntityUid uid, FloorOcclusionComponent component, ref AfterAutoHandleStateEvent args)
|
||||
{
|
||||
SetEnabled(uid, component, component.Enabled);
|
||||
}
|
||||
|
||||
private void OnOcclusionStartup(EntityUid uid, FloorOcclusionComponent component, ComponentStartup args)
|
||||
{
|
||||
if (component.Enabled && TryComp<SpriteComponent>(uid, out var sprite))
|
||||
SetShader(sprite, true);
|
||||
}
|
||||
|
||||
protected override void SetEnabled(EntityUid uid, FloorOcclusionComponent component, bool enabled)
|
||||
{
|
||||
if (component.Enabled == enabled)
|
||||
return;
|
||||
|
||||
base.SetEnabled(uid, component, enabled);
|
||||
|
||||
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
||||
return;
|
||||
|
||||
SetShader(sprite, enabled);
|
||||
}
|
||||
|
||||
private void SetShader(SpriteComponent sprite, bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
sprite.PostShader = _proto.Index<ShaderPrototype>("HorizontalCut").Instance();
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.PostShader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Content.Server/Movement/Systems/FloorOcclusionSystem.cs
Normal file
8
Content.Server/Movement/Systems/FloorOcclusionSystem.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Movement.Systems;
|
||||
|
||||
namespace Content.Server.Movement.Systems;
|
||||
|
||||
public sealed class FloorOcclusionSystem : SharedFloorOcclusionSystem
|
||||
{
|
||||
|
||||
}
|
||||
12
Content.Shared/Movement/Components/FloorOccluderComponent.cs
Normal file
12
Content.Shared/Movement/Components/FloorOccluderComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Applies floor occlusion to any <see cref="FloorOcclusionComponent"/> that intersect us.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class FloorOccluderComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Applies an occlusion shader to this entity if it's colliding with a <see cref="FloorOccluderComponent"/>
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
public sealed partial class FloorOcclusionComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Is the shader currently enabled.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("enabled"), AutoNetworkedField]
|
||||
public bool Enabled;
|
||||
|
||||
[DataField("colliding")]
|
||||
public List<EntityUid> Colliding = new();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Applies an occlusion shader for any relevant entities.
|
||||
/// </summary>
|
||||
public abstract class SharedFloorOcclusionSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<FloorOccluderComponent, StartCollideEvent>(OnStartCollide);
|
||||
SubscribeLocalEvent<FloorOccluderComponent, EndCollideEvent>(OnEndCollide);
|
||||
}
|
||||
|
||||
private void OnStartCollide(EntityUid uid, FloorOccluderComponent component, ref StartCollideEvent args)
|
||||
{
|
||||
var other = args.OtherEntity;
|
||||
|
||||
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion) ||
|
||||
occlusion.Colliding.Contains(uid))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetEnabled(other, occlusion, true);
|
||||
occlusion.Colliding.Add(uid);
|
||||
}
|
||||
|
||||
private void OnEndCollide(EntityUid uid, FloorOccluderComponent component, ref EndCollideEvent args)
|
||||
{
|
||||
var other = args.OtherEntity;
|
||||
|
||||
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion))
|
||||
return;
|
||||
|
||||
occlusion.Colliding.Remove(uid);
|
||||
|
||||
if (occlusion.Colliding.Count == 0)
|
||||
SetEnabled(other, occlusion, false);
|
||||
}
|
||||
|
||||
protected virtual void SetEnabled(EntityUid uid, FloorOcclusionComponent component, bool enabled)
|
||||
{
|
||||
if (component.Enabled == enabled)
|
||||
return;
|
||||
|
||||
component.Enabled = enabled;
|
||||
Dirty(uid, component);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
id: BaseMobOrganic
|
||||
noSpawn: true
|
||||
components:
|
||||
- type: FloorOcclusion
|
||||
- type: LagCompensation
|
||||
- type: RangedDamageSound
|
||||
soundGroups:
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
snap:
|
||||
- Wall
|
||||
components:
|
||||
- type: StepTrigger
|
||||
requiredTriggeredSpeed: 0
|
||||
intersectRatio: 0.1
|
||||
- type: FloorOccluder
|
||||
- type: Transform
|
||||
anchored: true
|
||||
- type: SyncSprite
|
||||
|
||||
@@ -76,3 +76,9 @@
|
||||
id: PaperStamp
|
||||
kind: source
|
||||
path: "/Textures/Shaders/paperstamp.swsl"
|
||||
|
||||
# Simple horizontal cut
|
||||
- type: shader
|
||||
id: HorizontalCut
|
||||
kind: source
|
||||
path: "/Textures/Shaders/hcut.swsl"
|
||||
|
||||
13
Resources/Textures/Shaders/hcut.swsl
Normal file
13
Resources/Textures/Shaders/hcut.swsl
Normal file
@@ -0,0 +1,13 @@
|
||||
light_mode unshaded;
|
||||
|
||||
const highp float c = 0.3;
|
||||
const highp float alphaModifier = 0.2;
|
||||
uniform bool below = true;
|
||||
|
||||
void fragment()
|
||||
{
|
||||
highp vec4 tex = zTexture(UV);
|
||||
highp float modifier = (UV.y > c ^^ !below) ? 1 : alphaModifier;
|
||||
|
||||
COLOR = vec4(tex.x, tex.y, tex.z, tex.w * modifier);
|
||||
}
|
||||
Reference in New Issue
Block a user