2023-11-15 13:23:40 +11:00
using System.Numerics ;
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
{
2023-11-28 23:35:38 +11:00
private List < Entity < MapGridComponent > > _grids = new ( ) ;
2024-06-02 05:07:41 +01:00
private void DrawWeather ( in OverlayDrawArgs args , WeatherPrototype weatherProto , float alpha , Matrix3x2 invMatrix )
2023-11-15 13:23:40 +11:00
{
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 ;
// 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 ( _blep ! , ( ) = >
{
var xformQuery = _entManager . GetEntityQuery < TransformComponent > ( ) ;
2023-11-28 23:35:38 +11:00
_grids . Clear ( ) ;
2023-11-15 13:23:40 +11:00
// idk if this is safe to cache in a field and clear sloth help
2023-11-28 23:35:38 +11:00
_mapManager . FindGridsIntersecting ( mapId , worldAABB , ref _grids ) ;
2023-11-15 13:23:40 +11:00
2023-11-28 23:35:38 +11:00
foreach ( var grid in _grids )
2023-11-15 13:23:40 +11:00
{
var matrix = _transform . GetWorldMatrix ( grid , xformQuery ) ;
2024-06-02 05:07:41 +01:00
var matty = Matrix3x2 . Multiply ( matrix , invMatrix ) ;
2023-11-15 13:23:40 +11:00
worldHandle . SetTransform ( matty ) ;
2024-12-01 04:56:47 +03:00
foreach ( var tile in _map . GetTilesIntersecting ( grid . Owner , grid , worldAABB ) )
2023-11-15 13:23:40 +11:00
{
// Ignored tiles for stencil
2024-06-18 13:27:34 +03:00
if ( _weather . CanWeatherAffect ( grid . Owner , grid , tile ) )
2023-11-15 13:23:40 +11:00
{
continue ;
}
var gridTile = new Box2 ( tile . GridIndices * grid . Comp . TileSize ,
( tile . GridIndices + Vector2i . One ) * grid . Comp . TileSize ) ;
worldHandle . DrawRect ( gridTile , Color . White ) ;
}
}
} , Color . Transparent ) ;
2024-06-02 05:07:41 +01:00
worldHandle . SetTransform ( Matrix3x2 . Identity ) ;
2023-11-15 13:23:40 +11:00
worldHandle . UseShader ( _protoManager . Index < ShaderPrototype > ( "StencilMask" ) . Instance ( ) ) ;
worldHandle . DrawTextureRect ( _blep ! . Texture , worldBounds ) ;
var curTime = _timing . RealTime ;
var sprite = _sprite . GetFrame ( weatherProto . Sprite , curTime ) ;
// Draw the rain
worldHandle . UseShader ( _protoManager . Index < ShaderPrototype > ( "StencilDraw" ) . Instance ( ) ) ;
2024-09-29 13:07:30 +03:00
_parallax . DrawParallax ( worldHandle , worldAABB , sprite , curTime , position , weatherProto . OffsetSpeed , modulate : ( weatherProto . Color ? ? Color . White ) . WithAlpha ( alpha * weatherProto . Alpha ) ) ; //CP14 alpha and offset scrolling
2023-11-15 13:23:40 +11:00
2024-06-02 05:07:41 +01:00
worldHandle . SetTransform ( Matrix3x2 . Identity ) ;
2023-11-15 13:23:40 +11:00
worldHandle . UseShader ( null ) ;
}
}