Remove 700 usages of Component.Owner (#21100)

This commit is contained in:
DrSmugleaf
2023-10-19 12:34:31 -07:00
committed by GitHub
parent 5825ffb95c
commit f560f88eb5
261 changed files with 2291 additions and 2036 deletions

View File

@@ -15,6 +15,7 @@ using Content.Shared.Roles.Jobs;
using JetBrains.Annotations;
using Robust.Server.Player;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
@@ -34,11 +35,23 @@ namespace Content.Server.GameTicking
/// How many players have joined the round through normal methods.
/// Useful for game rules to look at. Doesn't count observers, people in lobby, etc.
/// </summary>
public int PlayersJoinedRoundNormally = 0;
public int PlayersJoinedRoundNormally;
// Mainly to avoid allocations.
private readonly List<EntityCoordinates> _possiblePositions = new();
private List<EntityUid> GetSpawnableStations()
{
var spawnableStations = new List<EntityUid>();
var query = EntityQueryEnumerator<StationJobsComponent, StationSpawningComponent>();
while (query.MoveNext(out var uid, out _, out _))
{
spawnableStations.Add(uid);
}
return spawnableStations;
}
private void SpawnPlayers(List<IPlayerSession> readyPlayers, Dictionary<NetUserId, HumanoidCharacterProfile> profiles, bool force)
{
// Allow game rules to spawn players by themselves if needed. (For example, nuke ops or wizard)
@@ -66,8 +79,7 @@ namespace Content.Server.GameTicking
}
}
var spawnableStations = EntityQuery<StationJobsComponent, StationSpawningComponent>().Select(x => x.Item1.Owner).ToList();
var spawnableStations = GetSpawnableStations();
var assignedJobs = _stationJobs.AssignJobs(profiles, spawnableStations);
_stationJobs.AssignOverflowJobs(ref assignedJobs, playerNetIds, profiles, spawnableStations);
@@ -125,7 +137,7 @@ namespace Content.Server.GameTicking
if (station == EntityUid.Invalid)
{
var stations = EntityQuery<StationJobsComponent, StationSpawningComponent>().Select(x => x.Item1.Owner).ToList();
var stations = GetSpawnableStations();
_robustRandom.Shuffle(stations);
if (stations.Count == 0)
station = EntityUid.Invalid;
@@ -161,7 +173,8 @@ namespace Content.Server.GameTicking
restrictedRoles.UnionWith(getDisallowed);
var jobBans = _banManager.GetJobBans(player.UserId);
if(jobBans != null) restrictedRoles.UnionWith(jobBans);
if (jobBans != null)
restrictedRoles.UnionWith(jobBans);
// Pick best job best on prefs.
jobId ??= _stationJobs.PickBestAvailableJobWithPriority(station, character.JobPriorities, true,
@@ -350,15 +363,16 @@ namespace Content.Server.GameTicking
// Fallback to a random grid.
if (_possiblePositions.Count == 0)
{
foreach (var grid in _mapManager.GetAllGrids())
var query = AllEntityQuery<MapGridComponent>();
while (query.MoveNext(out var uid, out var grid))
{
if (!metaQuery.TryGetComponent(grid.Owner, out var meta) ||
if (!metaQuery.TryGetComponent(uid, out var meta) ||
meta.EntityPaused)
{
continue;
}
_possiblePositions.Add(new EntityCoordinates(grid.Owner, Vector2.Zero));
_possiblePositions.Add(new EntityCoordinates(uid, Vector2.Zero));
}
}