Files
crystall-punk-14/Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs

150 lines
7.8 KiB
C#
Raw Normal View History

Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
using Content.Client.Atmos.EntitySystems;
using Content.Shared.Atmos;
Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
using Content.Shared.Atmos.EntitySystems;
using Robust.Client.Graphics;
Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
namespace Content.Client.Atmos.Overlays
{
public sealed class AtmosDebugOverlay : Overlay
{
private readonly AtmosDebugOverlaySystem _atmosDebugOverlaySystem;
[Dependency] private readonly IMapManager _mapManager = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public AtmosDebugOverlay()
{
IoCManager.InjectDependencies(this);
_atmosDebugOverlaySystem = EntitySystem.Get<AtmosDebugOverlaySystem>();
}
2021-04-19 09:52:40 +02:00
protected override void Draw(in OverlayDrawArgs args)
{
2021-04-19 09:52:40 +02:00
var drawHandle = args.WorldHandle;
var mapId = args.Viewport.Eye!.Position.MapId;
var worldBounds = args.WorldBounds;
// IF YOU ARE ABOUT TO INTRODUCE CHUNKING OR SOME OTHER OPTIMIZATION INTO THIS CODE:
// -- THINK! --
// 1. "Is this going to make a critical atmos debugging tool harder to debug itself?"
// 2. "Is this going to do anything that could cause the atmos debugging tool to use resources, server-side or client-side, when nobody's using it?"
// 3. "Is this going to make it harder for atmos programmers to add data that may not be chunk-friendly into the atmos debugger?"
// Nanotrasen needs YOU! to avoid premature optimization in critical debugging tools - 20kdc
foreach (var mapGrid in _mapManager.FindGridsIntersecting(mapId, worldBounds))
{
if (!_atmosDebugOverlaySystem.HasData(mapGrid.Index))
continue;
2021-11-01 00:40:57 +11:00
drawHandle.SetTransform(mapGrid.WorldMatrix);
for (var pass = 0; pass < 2; pass++)
{
2021-08-17 14:09:59 +10:00
foreach (var tile in mapGrid.GetTilesIntersecting(worldBounds))
{
var dataMaybeNull = _atmosDebugOverlaySystem.GetData(mapGrid.Index, tile.GridIndices);
if (dataMaybeNull != null)
{
var data = (SharedAtmosDebugOverlaySystem.AtmosDebugOverlayData) dataMaybeNull!;
if (pass == 0)
{
// -- Mole Count --
float total = 0;
switch (_atmosDebugOverlaySystem.CfgMode) {
case AtmosDebugOverlayMode.TotalMoles:
foreach (float f in data.Moles)
{
total += f;
}
break;
case AtmosDebugOverlayMode.GasMoles:
total = data.Moles[_atmosDebugOverlaySystem.CfgSpecificGas];
break;
case AtmosDebugOverlayMode.Temperature:
total = data.Temperature;
break;
}
var interp = ((total - _atmosDebugOverlaySystem.CfgBase) / _atmosDebugOverlaySystem.CfgScale);
Color res;
if (_atmosDebugOverlaySystem.CfgCBM)
{
// Greyscale interpolation
res = Color.InterpolateBetween(Color.Black, Color.White, interp);
}
else
{
// Red-Green-Blue interpolation
if (interp < 0.5f)
{
res = Color.InterpolateBetween(Color.Red, Color.LimeGreen, interp * 2);
}
else
{
res = Color.InterpolateBetween(Color.LimeGreen, Color.Blue, (interp - 0.5f) * 2);
}
}
res = res.WithAlpha(0.75f);
2021-11-01 00:40:57 +11:00
drawHandle.DrawRect(Box2.FromDimensions(new Vector2(tile.X, tile.Y), new Vector2(1, 1)), res);
}
else if (pass == 1)
{
// -- Blocked Directions --
void CheckAndShowBlockDir(AtmosDirection dir)
{
if (data.BlockDirection.HasFlag(dir))
{
// Account for South being 0.
var atmosAngle = dir.ToAngle() - Angle.FromDegrees(90);
var atmosAngleOfs = atmosAngle.ToVec() * 0.45f;
var atmosAngleOfsR90 = new Vector2(atmosAngleOfs.Y, -atmosAngleOfs.X);
var tileCentre = new Vector2(tile.X + 0.5f, tile.Y + 0.5f);
2021-11-01 00:40:57 +11:00
var basisA = tileCentre + atmosAngleOfs - atmosAngleOfsR90;
var basisB = tileCentre + atmosAngleOfs + atmosAngleOfsR90;
drawHandle.DrawLine(basisA, basisB, Color.Azure);
}
}
CheckAndShowBlockDir(AtmosDirection.North);
CheckAndShowBlockDir(AtmosDirection.South);
CheckAndShowBlockDir(AtmosDirection.East);
CheckAndShowBlockDir(AtmosDirection.West);
// -- Pressure Direction --
if (data.PressureDirection != AtmosDirection.Invalid)
{
// Account for South being 0.
var atmosAngle = data.PressureDirection.ToAngle() - Angle.FromDegrees(90);
var atmosAngleOfs = atmosAngle.ToVec() * 0.4f;
var tileCentre = new Vector2(tile.X + 0.5f, tile.Y + 0.5f);
2021-11-01 00:40:57 +11:00
var basisA = tileCentre;
var basisB = tileCentre + atmosAngleOfs;
drawHandle.DrawLine(basisA, basisB, Color.Blue);
}
// -- Excited Groups --
if (data.InExcitedGroup)
{
var tilePos = new Vector2(tile.X, tile.Y);
2021-11-01 00:40:57 +11:00
var basisA = tilePos;
var basisB = tilePos + new Vector2(1.0f, 1.0f);
var basisC = tilePos + new Vector2(0.0f, 1.0f);
var basisD = tilePos + new Vector2(1.0f, 0.0f);
drawHandle.DrawLine(basisA, basisB, Color.Cyan);
drawHandle.DrawLine(basisC, basisD, Color.Cyan);
}
}
}
}
}
}
2021-11-01 00:40:57 +11:00
drawHandle.SetTransform(Matrix3.Identity);
}
}
}