Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Content.Client/Parallax/ParallaxOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Numerics;
using Content.Client.Parallax.Managers;
using Content.Client.Viewport;
using Content.Shared._CE.ZLevels.Core.EntitySystems;
using Content.Shared.CCVar;
using Content.Shared.Parallax.Biomes;
using Robust.Client.Graphics;
Expand All @@ -20,6 +22,7 @@ public sealed class ParallaxOverlay : Overlay
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IParallaxManager _manager = default!;
private readonly ParallaxSystem _parallax;
private readonly CESharedZLevelsSystem _zLevel; //CrystallEdge
private Dictionary<ParallaxLayerPrepared, ShaderInstance?> _layerShaders;

public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowWorld;
Expand All @@ -29,6 +32,7 @@ public ParallaxOverlay()
ZIndex = ParallaxSystem.ParallaxZIndex;
IoCManager.InjectDependencies(this);
_parallax = _entManager.System<ParallaxSystem>();
_zLevel = _entManager.System<CESharedZLevelsSystem>(); //CrystallEdge
_layerShaders = new();
}

Expand All @@ -37,7 +41,12 @@ protected override bool BeforeDraw(in OverlayDrawArgs args)
if (args.MapId == MapId.Nullspace || _entManager.HasComponent<BiomeComponent>(_mapManager.GetMapEntityId(args.MapId)))
return false;

return true;
//CrystallEdge draw parallax only for lowest zlevel
if (args.Viewport.Eye is ScalingViewport.ZEye zEye)
return zEye.LowestDepth == zEye.Depth;
else
return !_zLevel.TryMapDown(args.MapUid, out _);
//CrystallEdge end
}

protected override void Draw(in OverlayDrawArgs args)
Expand Down
12 changes: 7 additions & 5 deletions Content.Client/Viewport/ScalingViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Content.Client.Viewport
/// <summary>
/// Viewport control that has a fixed viewport size and scales it appropriately.
/// </summary>
public sealed class ScalingViewport : Control, IViewportControl
public sealed partial class ScalingViewport : Control, IViewportControl //CrystallEdge partial for ZLevels rendering
{
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
Expand Down Expand Up @@ -150,13 +150,15 @@ protected override void Draw(IRenderHandle handle)

DebugTools.AssertNotNull(_viewport);

_viewport!.Render();
RenderZLevels(_viewport!); // CrystallEdge Process multi-Z rendering

// _viewport!.Render();

if (_queuedScreenshots.Count != 0)
{
var callbacks = _queuedScreenshots.ToArray();

_viewport.RenderTarget.CopyPixelsToMemory<Rgba32>(image =>
_viewport!.RenderTarget.CopyPixelsToMemory<Rgba32>(image =>
{
foreach (var callback in callbacks)
{
Expand All @@ -169,9 +171,9 @@ protected override void Draw(IRenderHandle handle)

var drawBox = GetDrawBox();
var drawBoxGlobal = drawBox.Translated(GlobalPixelPosition);
_viewport.RenderScreenOverlaysBelow(handle, this, drawBoxGlobal);
_viewport!.RenderScreenOverlaysBelow(handle, this, drawBoxGlobal);
handle.DrawingHandleScreen.DrawTextureRect(_viewport.RenderTarget.Texture, drawBox);
_viewport.RenderScreenOverlaysAbove(handle, this, drawBoxGlobal);
_viewport!.RenderScreenOverlaysAbove(handle, this, drawBoxGlobal);
}

public void Screenshot(CopyPixelsDelegate<Rgba32> callback)
Expand Down
96 changes: 96 additions & 0 deletions Content.Client/_CE/ZLevels/Core/CEClientZLevelsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* This file is sublicensed under MIT License
* https://github.com/space-wizards/space-station-14/blob/master/LICENSE.TXT
*/

using System.Numerics;
using Content.Shared._CE.ZLevels.Core.Components;
using Content.Shared._CE.ZLevels.Core.EntitySystems;
using Content.Shared.Camera;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;

namespace Content.Client._CE.ZLevels.Core;

/// <summary>
/// Only process Eye offset and drawdepth on clientside
/// </summary>
public sealed partial class CEClientZLevelsSystem : CESharedZLevelsSystem
{
[Dependency] private readonly IOverlayManager _overlay = default!;
[Dependency] private readonly SpriteSystem _sprite = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly AnimationPlayerSystem _animation = default!;

public static float ZLevelOffset = 0.7f;

public override void Initialize()
{
base.Initialize();
_overlay.AddOverlay(new CEZLevelBlurOverlay());

SubscribeLocalEvent<CEZPhysicsComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<CEZPhysicsComponent, GetEyeOffsetEvent>(OnEyeOffset);
}

private void OnEyeOffset(Entity<CEZPhysicsComponent> ent, ref GetEyeOffsetEvent args)
{
Angle rotation = _eye.CurrentEye.Rotation * -1;
var localPosition = GetVisualsLocalPosition((ent, ent), Transform(ent));
var offset = rotation.RotateVec(new Vector2(0, localPosition * ZLevelOffset));
args.Offset += offset;
}

private void OnStartup(Entity<CEZPhysicsComponent> ent, ref ComponentStartup args)
{
if (!TryComp<SpriteComponent>(ent, out var sprite))
return;

if (sprite.SnapCardinals)
return;

ent.Comp.NoRotDefault = sprite.NoRotation;
ent.Comp.DrawDepthDefault = sprite.DrawDepth;
ent.Comp.SpriteOffsetDefault = sprite.Offset;
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<CEZPhysicsComponent, SpriteComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var zPhys, out var sprite, out var xform))
{
var localPosition = GetVisualsLocalPosition((uid, zPhys), xform);

sprite.NoRotation = localPosition != 0 || zPhys.NoRotDefault;

_sprite.SetOffset((uid, sprite), zPhys.SpriteOffsetDefault + new Vector2(0, localPosition * ZLevelOffset));
_sprite.SetDrawDepth((uid, sprite), localPosition > 0 ? (int)Shared.DrawDepth.DrawDepth.OverMobs : zPhys.DrawDepthDefault);
}
}


public float GetVisualsLocalPosition(Entity<CEZPhysicsComponent?> ent, TransformComponent? xform = null)
{
if (!Resolve(ent, ref ent.Comp, false))
return 0;
if (!Resolve(ent, ref xform, false))
return 0;

var pos = ent.Comp.LocalPosition;

if (xform.ParentUid != xform.MapUid && ZPhyzQuery.TryComp(xform.ParentUid, out var parentZPhys))
pos = parentZPhys.LocalPosition;

return pos;
}

public override void Shutdown()
{
base.Shutdown();
_overlay.RemoveOverlay<CEZLevelBlurOverlay>();
}
}
70 changes: 70 additions & 0 deletions Content.Client/_CE/ZLevels/Core/CEZLevelBlurOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is sublicensed under MIT License
* https://github.com/space-wizards/space-station-14/blob/master/LICENSE.TXT
*/

using System.Numerics;
using Content.Client.Viewport;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;

namespace Content.Client._CE.ZLevels.Core;

public sealed class CEZLevelBlurOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IEntityManager _entity = default!;
private readonly ShaderInstance? _blurShader;

public override bool RequestScreenTexture => true;
public override OverlaySpace Space => OverlaySpace.WorldSpace;

private readonly ProtoId<ShaderPrototype> _zBlurShader = "CEZBlur";

public CEZLevelBlurOverlay()
{
IoCManager.InjectDependencies(this);
_blurShader = _proto.Index(_zBlurShader).InstanceUnique();
}

protected override bool BeforeDraw(in OverlayDrawArgs args)
{
if (args.Viewport.Eye is not ScalingViewport.ZEye zeye)
return false;

if (zeye.Depth >= 0)
return false;

if (args.MapId == MapId.Nullspace)
return false;

return true;
}

protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null || args.Viewport.Eye == null)
return;

var ambientColor = new Vector3(0, 0, 1); //Default blue

if (_entity.TryGetComponent<MapLightComponent>(args.MapUid, out var mapLight))
{
ambientColor = new Vector3(
mapLight.AmbientLightColor.R,
mapLight.AmbientLightColor.G,
mapLight.AmbientLightColor.B);
}

_blurShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);
_blurShader?.SetParameter("BLUR_COLOR", ambientColor);

var worldHandle = args.WorldHandle;
worldHandle.UseShader(_blurShader);
worldHandle.DrawRect(args.WorldBounds, Color.White);
worldHandle.UseShader(null);
}
}
71 changes: 71 additions & 0 deletions Content.Client/_CE/ZLevels/Core/CEZLevelDebugOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is sublicensed under MIT License
* https://github.com/space-wizards/space-station-14/blob/master/LICENSE.TXT
*/

using System.Numerics;
using Content.Shared._CE.ZLevels.Core.Components;
using Content.Shared._CE.ZLevels.Core.EntitySystems;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Console;
using Robust.Shared.Enums;

namespace Content.Client._CE.ZLevels.Core;

public sealed class CEZLevelDebugOverlay : Overlay
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IResourceCache _cache = default!;
private readonly CESharedZLevelsSystem _zLevels = default!;
private readonly SharedTransformSystem _transform = default!;
public override OverlaySpace Space => OverlaySpace.ScreenSpace;

private readonly Font _font;

public CEZLevelDebugOverlay()
{
IoCManager.InjectDependencies(this);

_zLevels = _entityManager.System<CESharedZLevelsSystem>();
_transform = _entityManager.System<SharedTransformSystem>();

_font = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 8);
}

protected override void Draw(in OverlayDrawArgs args)
{
var query = _entityManager.EntityQueryEnumerator<CEZPhysicsComponent, CEActiveZPhysicsComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var zPhys, out _, out var xform))
{
if (xform.MapUid != xform.ParentUid)
continue;

var worldPos = _transform.GetWorldPosition(uid);
var screenPos = args.ViewportControl?.WorldToScreen(worldPos) ?? Vector2.Zero;

var localPos = MathF.Round(zPhys.LocalPosition, 2);
var groundDis = MathF.Round(zPhys.LocalPosition - zPhys.CurrentGroundHeight, 2);
var velocity = MathF.Round(zPhys.Velocity, 2);
var sticky = zPhys.CurrentStickyGround;

var depthText = $"ZLocalHeight: {localPos}\nDistance to ground: {groundDis}\nVelocity: {velocity}\nSticky: {sticky}";

args.ScreenHandle.DrawString(_font, screenPos, depthText, Color.White);
}
}
}

public sealed class CEShowZLevelDebugCommand : LocalizedCommands
{
[Dependency] private readonly IOverlayManager _overlayManager = default!;
public override string Command => "showzleveldebug";

public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (_overlayManager.HasOverlay<CEZLevelDebugOverlay>())
_overlayManager.RemoveOverlay<CEZLevelDebugOverlay>();
else
_overlayManager.AddOverlay(new CEZLevelDebugOverlay());
}
}
Loading
Loading