* 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
170 lines
6.1 KiB
C#
170 lines
6.1 KiB
C#
#nullable enable
|
|
using System.Collections.Generic;
|
|
using Content.Server.Atmos.Components;
|
|
using Content.Shared.Atmos;
|
|
using Content.Shared.Atmos.EntitySystems;
|
|
using Content.Shared.CCVar;
|
|
using JetBrains.Annotations;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Atmos.EntitySystems
|
|
{
|
|
[UsedImplicitly]
|
|
public sealed class AtmosDebugOverlaySystem : SharedAtmosDebugOverlaySystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
|
|
|
/// <summary>
|
|
/// Players allowed to see the atmos debug overlay.
|
|
/// To modify it see <see cref="AddObserver"/> and
|
|
/// <see cref="RemoveObserver"/>.
|
|
/// </summary>
|
|
private readonly HashSet<IPlayerSession> _playerObservers = new();
|
|
|
|
/// <summary>
|
|
/// Overlay update ticks per second.
|
|
/// </summary>
|
|
private float _updateCooldown;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
_playerManager.PlayerStatusChanged -= OnPlayerStatusChanged;
|
|
}
|
|
|
|
public bool AddObserver(IPlayerSession observer)
|
|
{
|
|
return _playerObservers.Add(observer);
|
|
}
|
|
|
|
public bool HasObserver(IPlayerSession observer)
|
|
{
|
|
return _playerObservers.Contains(observer);
|
|
}
|
|
|
|
public bool RemoveObserver(IPlayerSession observer)
|
|
{
|
|
if (!_playerObservers.Remove(observer))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var message = new AtmosDebugOverlayDisableMessage();
|
|
RaiseNetworkEvent(message, observer.ConnectedClient);
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds the given observer if it doesn't exist, removes it otherwise.
|
|
/// </summary>
|
|
/// <param name="observer">The observer to toggle.</param>
|
|
/// <returns>true if added, false if removed.</returns>
|
|
public bool ToggleObserver(IPlayerSession observer)
|
|
{
|
|
if (HasObserver(observer))
|
|
{
|
|
RemoveObserver(observer);
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
AddObserver(observer);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
|
{
|
|
if (e.NewStatus != SessionStatus.InGame)
|
|
{
|
|
RemoveObserver(e.Session);
|
|
}
|
|
}
|
|
|
|
private AtmosDebugOverlayData ConvertTileToData(TileAtmosphere? tile)
|
|
{
|
|
var gases = new float[Atmospherics.TotalNumberOfGases];
|
|
if (tile?.Air == null)
|
|
{
|
|
return new AtmosDebugOverlayData(0, gases, AtmosDirection.Invalid, false, tile?.BlockedAirflow ?? AtmosDirection.Invalid);
|
|
}
|
|
else
|
|
{
|
|
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
|
{
|
|
gases[i] = tile.Air.GetMoles(i);
|
|
}
|
|
return new AtmosDebugOverlayData(tile.Air.Temperature, gases, tile.PressureDirectionForDebugOverlay, tile.ExcitedGroup != null, tile.BlockedAirflow);
|
|
}
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
AccumulatedFrameTime += frameTime;
|
|
_updateCooldown = 1 / _configManager.GetCVar(CCVars.NetAtmosDebugOverlayTickRate);
|
|
|
|
if (AccumulatedFrameTime < _updateCooldown)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// This is the timer from GasTileOverlaySystem
|
|
AccumulatedFrameTime -= _updateCooldown;
|
|
|
|
var currentTick = _gameTiming.CurTick;
|
|
|
|
// Now we'll go through each player, then through each chunk in range of that player checking if the player is still in range
|
|
// If they are, check if they need the new data to send (i.e. if there's an overlay for the gas).
|
|
// Afterwards we reset all the chunk data for the next time we tick.
|
|
foreach (var session in _playerObservers)
|
|
{
|
|
if (session.AttachedEntity == null) continue;
|
|
|
|
var entity = session.AttachedEntity;
|
|
|
|
var worldBounds = Box2.CenteredAround(entity.Transform.WorldPosition,
|
|
new Vector2(LocalViewRange, LocalViewRange));
|
|
|
|
foreach (var grid in _mapManager.FindGridsIntersecting(entity.Transform.MapID, worldBounds))
|
|
{
|
|
if (!EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) continue;
|
|
|
|
if (!gridEnt.TryGetComponent<GridAtmosphereComponent>(out var gam)) continue;
|
|
|
|
var entityTile = grid.GetTileRef(entity.Transform.Coordinates).GridIndices;
|
|
var baseTile = new Vector2i(entityTile.X - (LocalViewRange / 2), entityTile.Y - (LocalViewRange / 2));
|
|
var debugOverlayContent = new AtmosDebugOverlayData[LocalViewRange * LocalViewRange];
|
|
|
|
var index = 0;
|
|
for (var y = 0; y < LocalViewRange; y++)
|
|
{
|
|
for (var x = 0; x < LocalViewRange; x++)
|
|
{
|
|
var Vector2i = new Vector2i(baseTile.X + x, baseTile.Y + y);
|
|
debugOverlayContent[index++] = ConvertTileToData(gam.GetTile(Vector2i));
|
|
}
|
|
}
|
|
|
|
RaiseNetworkEvent(new AtmosDebugOverlayMessage(grid.Index, baseTile, debugOverlayContent), session.ConnectedClient);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|