Files
crystall-punk-14/Content.Shared/Light/EntitySystems/SharedRoofSystem.cs

131 lines
3.8 KiB
C#
Raw Normal View History

Add sun shadows (planet lighting stage 2) (#35145) * Implements a Dynamic Lighting System on maps. * Edit: the night should be a little bit brighter and blue now. * Major edit: everything must be done on the client side now, with certain datafield replicated. Changes were outlined in the salvage to accommodate the new lighting system. * Edit: The offset is now serverside, this makes the time accurate in all situations. * Removing ununsed import * Minor tweaks * Tweak in time precision * Minor tweak + Unused import removed * Edit: apparently RealTime is better for what I'm looking for * Fix: Now the time is calculated correctly. * Minor tweaks * Adds condition for when the light should be updated * Add planet lighting * she * close-ish * c * bittersweat * Fixes * Revert "Merge branch '22719' into 2024-09-29-planet-lighting" This reverts commit 9f2785bb16aee47d794aa3eed8ae15004f97fc35, reversing changes made to 19649c07a5fb625423e08fc18d91c9cb101daa86. * Europa and day-night * weh * rooves working * Clean * Remove Europa * Fixes * fix * Update * Fix caves * Update for engine * Add sun shadows (planet lighting v2) For now mostly targeting walls and having the shadows change over time. Got the basic proof-of-concept working just needs a hell of a lot of polish. * Documentation * a * Fixes * Move blur to an overlay * Slughands * Fixes * Apply RoofOverlay per-grid not per-map * Fix light render scales * sangas * Juice it a bit * Better angle * Fixes * Add color support * Rounding bandaid * Wehs * Better * Remember I forgot to do this when writing docs --------- Co-authored-by: DoutorWhite <thedoctorwhite@gmail.com>
2025-03-08 16:07:42 +11:00
using System.Diagnostics.Contracts;
using Content.Shared.Light.Components;
using Content.Shared.Maps;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
namespace Content.Shared.Light.EntitySystems;
/// <summary>
/// Handles the roof flag for tiles that gets used for the RoofOverlay.
/// </summary>
public abstract class SharedRoofSystem : EntitySystem
{
2025-02-23 18:23:00 +11:00
[Dependency] private readonly EntityLookupSystem _lookup = default!;
private HashSet<Entity<IsRoofComponent>> _roofSet = new();
/// <summary>
/// Returns whether the specified tile is roof-occupied.
/// </summary>
/// <returns>Returns false if no data or not rooved.</returns>
Add sun shadows (planet lighting stage 2) (#35145) * Implements a Dynamic Lighting System on maps. * Edit: the night should be a little bit brighter and blue now. * Major edit: everything must be done on the client side now, with certain datafield replicated. Changes were outlined in the salvage to accommodate the new lighting system. * Edit: The offset is now serverside, this makes the time accurate in all situations. * Removing ununsed import * Minor tweaks * Tweak in time precision * Minor tweak + Unused import removed * Edit: apparently RealTime is better for what I'm looking for * Fix: Now the time is calculated correctly. * Minor tweaks * Adds condition for when the light should be updated * Add planet lighting * she * close-ish * c * bittersweat * Fixes * Revert "Merge branch '22719' into 2024-09-29-planet-lighting" This reverts commit 9f2785bb16aee47d794aa3eed8ae15004f97fc35, reversing changes made to 19649c07a5fb625423e08fc18d91c9cb101daa86. * Europa and day-night * weh * rooves working * Clean * Remove Europa * Fixes * fix * Update * Fix caves * Update for engine * Add sun shadows (planet lighting v2) For now mostly targeting walls and having the shadows change over time. Got the basic proof-of-concept working just needs a hell of a lot of polish. * Documentation * a * Fixes * Move blur to an overlay * Slughands * Fixes * Apply RoofOverlay per-grid not per-map * Fix light render scales * sangas * Juice it a bit * Better angle * Fixes * Add color support * Rounding bandaid * Wehs * Better * Remember I forgot to do this when writing docs --------- Co-authored-by: DoutorWhite <thedoctorwhite@gmail.com>
2025-03-08 16:07:42 +11:00
[Pure]
2025-02-23 18:23:00 +11:00
public bool IsRooved(Entity<MapGridComponent, RoofComponent> grid, Vector2i index)
{
var roof = grid.Comp2;
var chunkOrigin = SharedMapSystem.GetChunkIndices(index, RoofComponent.ChunkSize);
if (roof.Data.TryGetValue(chunkOrigin, out var bitMask))
{
var chunkRelative = SharedMapSystem.GetChunkRelative(index, RoofComponent.ChunkSize);
var bitFlag = (ulong) 1 << (chunkRelative.X + chunkRelative.Y * RoofComponent.ChunkSize);
var isRoof = (bitMask & bitFlag) == bitFlag;
// Early out, otherwise check for components on tile.
if (isRoof)
return true;
}
_roofSet.Clear();
_lookup.GetLocalEntitiesIntersecting(grid.Owner, index, _roofSet);
foreach (var isRoofEnt in _roofSet)
{
if (!isRoofEnt.Comp.Enabled)
continue;
return true;
}
return false;
}
Add sun shadows (planet lighting stage 2) (#35145) * Implements a Dynamic Lighting System on maps. * Edit: the night should be a little bit brighter and blue now. * Major edit: everything must be done on the client side now, with certain datafield replicated. Changes were outlined in the salvage to accommodate the new lighting system. * Edit: The offset is now serverside, this makes the time accurate in all situations. * Removing ununsed import * Minor tweaks * Tweak in time precision * Minor tweak + Unused import removed * Edit: apparently RealTime is better for what I'm looking for * Fix: Now the time is calculated correctly. * Minor tweaks * Adds condition for when the light should be updated * Add planet lighting * she * close-ish * c * bittersweat * Fixes * Revert "Merge branch '22719' into 2024-09-29-planet-lighting" This reverts commit 9f2785bb16aee47d794aa3eed8ae15004f97fc35, reversing changes made to 19649c07a5fb625423e08fc18d91c9cb101daa86. * Europa and day-night * weh * rooves working * Clean * Remove Europa * Fixes * fix * Update * Fix caves * Update for engine * Add sun shadows (planet lighting v2) For now mostly targeting walls and having the shadows change over time. Got the basic proof-of-concept working just needs a hell of a lot of polish. * Documentation * a * Fixes * Move blur to an overlay * Slughands * Fixes * Apply RoofOverlay per-grid not per-map * Fix light render scales * sangas * Juice it a bit * Better angle * Fixes * Add color support * Rounding bandaid * Wehs * Better * Remember I forgot to do this when writing docs --------- Co-authored-by: DoutorWhite <thedoctorwhite@gmail.com>
2025-03-08 16:07:42 +11:00
[Pure]
public Color? GetColor(Entity<MapGridComponent, RoofComponent> grid, Vector2i index)
{
var roof = grid.Comp2;
var chunkOrigin = SharedMapSystem.GetChunkIndices(index, RoofComponent.ChunkSize);
if (roof.Data.TryGetValue(chunkOrigin, out var bitMask))
{
var chunkRelative = SharedMapSystem.GetChunkRelative(index, RoofComponent.ChunkSize);
var bitFlag = (ulong) 1 << (chunkRelative.X + chunkRelative.Y * RoofComponent.ChunkSize);
var isRoof = (bitMask & bitFlag) == bitFlag;
// Early out, otherwise check for components on tile.
if (isRoof)
{
return roof.Color;
}
}
_roofSet.Clear();
_lookup.GetLocalEntitiesIntersecting(grid.Owner, index, _roofSet);
foreach (var isRoofEnt in _roofSet)
{
if (!isRoofEnt.Comp.Enabled)
continue;
return isRoofEnt.Comp.Color ?? roof.Color;
}
return null;
}
public void SetRoof(Entity<MapGridComponent?, RoofComponent?> grid, Vector2i index, bool value)
{
if (!Resolve(grid, ref grid.Comp1, ref grid.Comp2, false))
return;
2025-02-23 18:23:00 +11:00
var chunkOrigin = SharedMapSystem.GetChunkIndices(index, RoofComponent.ChunkSize);
var roof = grid.Comp2;
2025-02-23 18:23:00 +11:00
if (!roof.Data.TryGetValue(chunkOrigin, out var chunkData))
{
// No value to remove so leave it.
if (!value)
{
return;
}
2025-02-23 18:23:00 +11:00
chunkData = 0;
}
2025-02-23 18:23:00 +11:00
var chunkRelative = SharedMapSystem.GetChunkRelative(index, RoofComponent.ChunkSize);
var bitFlag = (ulong) 1 << (chunkRelative.X + chunkRelative.Y * RoofComponent.ChunkSize);
if (value)
{
2025-02-23 18:23:00 +11:00
// Already set
if ((chunkData & bitFlag) == bitFlag)
return;
chunkData |= bitFlag;
}
else
{
2025-02-23 18:23:00 +11:00
// Not already set
if ((chunkData & bitFlag) == 0x0)
return;
chunkData &= ~bitFlag;
}
2025-02-23 18:23:00 +11:00
roof.Data[chunkOrigin] = chunkData;
Dirty(grid.Owner, roof);
}
}