Viewport improvements (#3765)

This commit is contained in:
Pieter-Jan Briers
2021-04-19 09:52:40 +02:00
committed by GitHub
parent 8e2fc49357
commit 147a54c642
40 changed files with 1173 additions and 418 deletions

View File

@@ -1,3 +1,4 @@
using System;
using Content.Client.Interfaces.Parallax;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
@@ -18,7 +19,7 @@ namespace Content.Client.Parallax
private Texture? _parallaxTexture;
public override OverlaySpace Space => OverlaySpace.ScreenSpaceBelowWorld;
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowWorld;
private readonly ShaderInstance _shader;
public ParallaxOverlay()
@@ -36,26 +37,36 @@ namespace Content.Client.Parallax
}
}
protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace)
protected override void Draw(in OverlayDrawArgs args)
{
if (_parallaxTexture == null)
if (_parallaxTexture == null || args.Viewport.Eye == null)
{
return;
}
handle.UseShader(_shader);
var screenHandle = (DrawingHandleScreen) handle;
var screenHandle = args.WorldHandle;
screenHandle.UseShader(_shader);
var (sizeX, sizeY) = _parallaxTexture.Size;
var (posX, posY) = _eyeManager.ScreenToMap(Vector2.Zero).Position;
var (ox, oy) = (Vector2i) new Vector2(-posX / Slowness, posY / Slowness);
ox = MathHelper.Mod(ox, sizeX);
oy = MathHelper.Mod(oy, sizeY);
var (sizeX, sizeY) = _parallaxTexture.Size / (float) EyeManager.PixelsPerMeter;
var (posX, posY) = args.Viewport.Eye.Position;
var o = new Vector2(posX * Slowness, posY * Slowness);
var (screenSizeX, screenSizeY) = _displayManager.ScreenSize;
for (var x = -sizeX; x < screenSizeX; x += sizeX) {
for (var y = -sizeY; y < screenSizeY; y += sizeY) {
screenHandle.DrawTexture(_parallaxTexture, new Vector2(ox + x, oy + y));
// Remove offset so we can floor.
var (l, b) = args.WorldBounds.BottomLeft - o;
// Floor to background size.
l = sizeX * MathF.Floor(l / sizeX);
b = sizeY * MathF.Floor(b / sizeY);
// Re-offset.
l += o.X;
b += o.Y;
for (var x = l; x < args.WorldBounds.Right; x += sizeX)
{
for (var y = b; y < args.WorldBounds.Top; y += sizeY)
{
screenHandle.DrawTexture(_parallaxTexture, (x, y));
}
}
}