Files
crystall-punk-14/Content.Client/Overlays/StencilOverlay.Weather.cs
Ed d6a8c169b2 Merge remote-tracking branch 'upstream/stable' into ed-29-09-2025-upstream
# Conflicts:
#	.github/CODEOWNERS
#	Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs
#	Content.Server/IdentityManagement/IdentitySystem.cs
#	Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs
2025-09-29 14:00:54 +03:00

84 lines
3.3 KiB
C#

using System.Numerics;
using Content.Shared.Light.Components;
using Content.Shared.Weather;
using Robust.Client.Graphics;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
namespace Content.Client.Overlays;
public sealed partial class StencilOverlay
{
private List<Entity<MapGridComponent>> _grids = new();
private void DrawWeather(
in OverlayDrawArgs args,
CachedResources res,
WeatherPrototype weatherProto,
float alpha,
Matrix3x2 invMatrix)
{
var worldHandle = args.WorldHandle;
var mapId = args.MapId;
var worldAABB = args.WorldAABB;
var worldBounds = args.WorldBounds;
var position = args.Viewport.Eye?.Position.Position ?? Vector2.Zero;
var eye = args.Viewport.Eye; //CP14
// Cut out the irrelevant bits via stencil
// This is why we don't just use parallax; we might want specific tiles to get drawn over
// particularly for planet maps or stations.
worldHandle.RenderInRenderTarget(res.Blep!, () =>
{
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
_grids.Clear();
// idk if this is safe to cache in a field and clear sloth help
_mapManager.FindGridsIntersecting(mapId, worldAABB, ref _grids);
foreach (var grid in _grids)
{
var matrix = _transform.GetWorldMatrix(grid, xformQuery);
var matty = Matrix3x2.Multiply(matrix, invMatrix);
worldHandle.SetTransform(matty);
_entManager.TryGetComponent(grid.Owner, out RoofComponent? roofComp);
foreach (var tile in _map.GetTilesIntersecting(grid.Owner, grid, worldAABB))
{
// Ignored tiles for stencil
if (_weather.CanWeatherAffect(grid.Owner, grid, tile, roofComp))
{
continue;
}
//CP14 offset - required for isometric walls
if (eye is not null)
{
Angle rotation = eye.Rotation * -1f;
var offset = rotation.ToWorldVec() * -0.5f;
var gridTile = new Box2(
tile.GridIndices * grid.Comp.TileSize + offset,
(tile.GridIndices + Vector2i.One) * grid.Comp.TileSize + offset);
worldHandle.DrawRect(gridTile, Color.White);
}
//CP14 offset end
}
}
}, Color.Transparent);
worldHandle.SetTransform(Matrix3x2.Identity);
worldHandle.UseShader(_protoManager.Index(StencilMask).Instance());
worldHandle.DrawTextureRect(res.Blep!.Texture, worldBounds);
var curTime = _timing.RealTime;
var sprite = _sprite.GetFrame(weatherProto.Sprite, curTime);
// Draw the rain
worldHandle.UseShader(_protoManager.Index(StencilDraw).Instance());
_parallax.DrawParallax(worldHandle, worldAABB, sprite, curTime, position, weatherProto.OffsetSpeed, modulate: (weatherProto.Color ?? Color.White).WithAlpha(alpha*weatherProto.Alpha)); //CP14 alpha and offset scrolling
worldHandle.SetTransform(Matrix3x2.Identity);
worldHandle.UseShader(null);
}
}