Un-revert IPlayerManager refactor (#21244)

This commit is contained in:
Leon Friedrich
2023-10-28 09:59:53 +11:00
committed by GitHub
parent c55e1dcafd
commit e685cb626b
245 changed files with 781 additions and 943 deletions

View File

@@ -10,6 +10,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Player;
namespace Content.Server.Atmos.EntitySystems
{
@@ -27,7 +28,7 @@ namespace Content.Server.Atmos.EntitySystems
/// To modify it see <see cref="AddObserver"/> and
/// <see cref="RemoveObserver"/>.
/// </summary>
private readonly HashSet<IPlayerSession> _playerObservers = new();
private readonly HashSet<ICommonSession> _playerObservers = new();
/// <summary>
/// Overlay update ticks per second.
@@ -48,17 +49,17 @@ namespace Content.Server.Atmos.EntitySystems
_playerManager.PlayerStatusChanged -= OnPlayerStatusChanged;
}
public bool AddObserver(IPlayerSession observer)
public bool AddObserver(ICommonSession observer)
{
return _playerObservers.Add(observer);
}
public bool HasObserver(IPlayerSession observer)
public bool HasObserver(ICommonSession observer)
{
return _playerObservers.Contains(observer);
}
public bool RemoveObserver(IPlayerSession observer)
public bool RemoveObserver(ICommonSession observer)
{
if (!_playerObservers.Remove(observer))
{
@@ -76,7 +77,7 @@ namespace Content.Server.Atmos.EntitySystems
/// </summary>
/// <param name="observer">The observer to toggle.</param>
/// <returns>true if added, false if removed.</returns>
public bool ToggleObserver(IPlayerSession observer)
public bool ToggleObserver(ICommonSession observer)
{
if (HasObserver(observer))
{

View File

@@ -12,7 +12,6 @@ using Content.Shared.Toggleable;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.Physics.Systems;
@@ -60,12 +59,6 @@ namespace Content.Server.Atmos.EntitySystems
private void OnGasTankToggleInternals(Entity<GasTankComponent> ent, ref GasTankToggleInternalsMessage args)
{
if (args.Session is not IPlayerSession playerSession ||
playerSession.AttachedEntity == null)
{
return;
}
ToggleInternals(ent);
}

View File

@@ -16,6 +16,7 @@ using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Threading;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -35,7 +36,7 @@ namespace Content.Server.Atmos.EntitySystems
[Robust.Shared.IoC.Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Robust.Shared.IoC.Dependency] private readonly ChunkingSystem _chunkingSys = default!;
private readonly Dictionary<IPlayerSession, Dictionary<NetEntity, HashSet<Vector2i>>> _lastSentChunks = new();
private readonly Dictionary<ICommonSession, Dictionary<NetEntity, HashSet<Vector2i>>> _lastSentChunks = new();
// Oh look its more duplicated decal system code!
private ObjectPool<HashSet<Vector2i>> _chunkIndexPool =
@@ -286,12 +287,12 @@ namespace Content.Server.Atmos.EntitySystems
// 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.
var players = _playerManager.ServerSessions.Where(x => x.Status == SessionStatus.InGame).ToArray();
var players = _playerManager.Sessions.Where(x => x.Status == SessionStatus.InGame).ToArray();
var opts = new ParallelOptions { MaxDegreeOfParallelism = _parMan.ParallelProcessCount };
Parallel.ForEach(players, opts, p => UpdatePlayer(p, curTick));
}
private void UpdatePlayer(IPlayerSession playerSession, GameTick curTick)
private void UpdatePlayer(ICommonSession playerSession, GameTick curTick)
{
var chunksInRange = _chunkingSys.GetChunksForSession(playerSession, ChunkSize, _chunkIndexPool, _chunkViewerPool);
var previouslySent = _lastSentChunks[playerSession];