Don't load cargo shuttle by default (#9194)

* Don't load cargo shuttle by default

Realistically only I am going to care and it wastes a few seconds per test / debugging locally.

* Make it a general cvar instead

* a
This commit is contained in:
metalgearsloth
2022-06-27 14:58:40 +10:00
committed by GitHub
parent 2ae4e80732
commit e72e060972
3 changed files with 77 additions and 25 deletions

View File

@@ -10,12 +10,14 @@ using Content.Shared.Cargo.BUI;
using Content.Shared.Cargo.Components; using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Events; using Content.Shared.Cargo.Events;
using Content.Shared.Cargo.Prototypes; using Content.Shared.Cargo.Prototypes;
using Content.Shared.CCVar;
using Content.Shared.Dataset; using Content.Shared.Dataset;
using Content.Shared.GameTicking; using Content.Shared.GameTicking;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.Maps; using Robust.Server.Maps;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Configuration;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
@@ -30,6 +32,7 @@ public sealed partial class CargoSystem
* Handles cargo shuttle mechanics, including cargo shuttle consoles. * Handles cargo shuttle mechanics, including cargo shuttle consoles.
*/ */
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapLoader _loader = default!; [Dependency] private readonly IMapLoader _loader = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
@@ -50,8 +53,20 @@ public sealed partial class CargoSystem
private int _index; private int _index;
/// <summary>
/// Whether cargo shuttles are enabled at all. Mainly used to disable cargo shuttle loading for performance reasons locally.
/// </summary>
private bool _enabled;
private void InitializeShuttle() private void InitializeShuttle()
{ {
#if !FULL_RELEASE
_configManager.OverrideDefault(CCVars.CargoShuttles, false);
#endif
_enabled = _configManager.GetCVar(CCVars.CargoShuttles);
// Don't want to immediately call this as shuttles will get setup in the natural course of things.
_configManager.OnValueChanged(CCVars.CargoShuttles, SetCargoShuttleEnabled);
SubscribeLocalEvent<CargoShuttleComponent, MoveEvent>(OnCargoShuttleMove); SubscribeLocalEvent<CargoShuttleComponent, MoveEvent>(OnCargoShuttleMove);
SubscribeLocalEvent<CargoShuttleConsoleComponent, ComponentStartup>(OnCargoShuttleConsoleStartup); SubscribeLocalEvent<CargoShuttleConsoleComponent, ComponentStartup>(OnCargoShuttleConsoleStartup);
SubscribeLocalEvent<CargoShuttleConsoleComponent, CargoCallShuttleMessage>(OnCargoShuttleCall); SubscribeLocalEvent<CargoShuttleConsoleComponent, CargoCallShuttleMessage>(OnCargoShuttleCall);
@@ -66,6 +81,31 @@ public sealed partial class CargoSystem
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart); SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
} }
private void ShutdownShuttle()
{
_configManager.UnsubValueChanged(CCVars.CargoShuttles, SetCargoShuttleEnabled);
}
private void SetCargoShuttleEnabled(bool value)
{
if (_enabled == value) return;
_enabled = value;
if (value)
{
Setup();
foreach (var station in EntityQuery<StationCargoOrderDatabaseComponent>(true))
{
AddShuttle(station);
}
}
else
{
CleanupShuttle();
}
}
#region Cargo Pilot Console #region Cargo Pilot Console
private void OnCargoPilotConsoleOpen(EntityUid uid, CargoPilotConsoleComponent component, AfterActivatableUIOpenEvent args) private void OnCargoPilotConsoleOpen(EntityUid uid, CargoPilotConsoleComponent component, AfterActivatableUIOpenEvent args)
@@ -245,31 +285,30 @@ public sealed partial class CargoSystem
{ {
Setup(); Setup();
if (CargoMap == null || component.Shuttle != null) return; if (CargoMap == null ||
component.Shuttle != null ||
component.CargoShuttleProto == null) return;
if (component.CargoShuttleProto != null) var prototype = _protoMan.Index<CargoShuttlePrototype>(component.CargoShuttleProto);
{ var possibleNames = _protoMan.Index<DatasetPrototype>(prototype.NameDataset).Values;
var prototype = _protoMan.Index<CargoShuttlePrototype>(component.CargoShuttleProto); var name = _random.Pick(possibleNames);
var possibleNames = _protoMan.Index<DatasetPrototype>(prototype.NameDataset).Values;
var name = _random.Pick(possibleNames);
var (_, gridId) = _loader.LoadBlueprint(CargoMap.Value, prototype.Path.ToString()); var (_, gridId) = _loader.LoadBlueprint(CargoMap.Value, prototype.Path.ToString());
var shuttleUid = _mapManager.GetGridEuid(gridId!.Value); var shuttleUid = _mapManager.GetGridEuid(gridId!.Value);
var xform = Transform(shuttleUid); var xform = Transform(shuttleUid);
MetaData(shuttleUid).EntityName = name; MetaData(shuttleUid).EntityName = name;
// TODO: Something better like a bounds check. // TODO: Something better like a bounds check.
xform.LocalPosition += 100 * _index; xform.LocalPosition += 100 * _index;
var comp = EnsureComp<CargoShuttleComponent>(shuttleUid); var comp = EnsureComp<CargoShuttleComponent>(shuttleUid);
comp.Station = component.Owner; comp.Station = component.Owner;
comp.Coordinates = xform.Coordinates; comp.Coordinates = xform.Coordinates;
component.Shuttle = shuttleUid; component.Shuttle = shuttleUid;
comp.NextCall = _timing.CurTime + TimeSpan.FromSeconds(comp.Cooldown); comp.NextCall = _timing.CurTime + TimeSpan.FromSeconds(comp.Cooldown);
UpdateShuttleCargoConsoles(comp); UpdateShuttleCargoConsoles(comp);
_index++; _index++;
_sawmill.Info($"Added cargo shuttle to {ToPrettyString(shuttleUid)}"); _sawmill.Info($"Added cargo shuttle to {ToPrettyString(shuttleUid)}");
}
} }
private void SellPallets(CargoShuttleComponent component, StationBankAccountComponent bank) private void SellPallets(CargoShuttleComponent component, StationBankAccountComponent bank)
@@ -490,10 +529,10 @@ public sealed partial class CargoSystem
private void OnRoundRestart(RoundRestartCleanupEvent ev) private void OnRoundRestart(RoundRestartCleanupEvent ev)
{ {
Cleanup(); CleanupShuttle();
} }
private void Cleanup() private void CleanupShuttle()
{ {
if (CargoMap == null || !_mapManager.MapExists(CargoMap.Value)) if (CargoMap == null || !_mapManager.MapExists(CargoMap.Value))
{ {
@@ -508,13 +547,20 @@ public sealed partial class CargoSystem
// Shuttle may not have been in the cargo dimension (e.g. on the station map) so need to delete. // Shuttle may not have been in the cargo dimension (e.g. on the station map) so need to delete.
foreach (var comp in EntityQuery<CargoShuttleComponent>()) foreach (var comp in EntityQuery<CargoShuttleComponent>())
{ {
if (TryComp<StationCargoOrderDatabaseComponent>(comp.Station, out var station))
{
station.Shuttle = null;
}
QueueDel(comp.Owner); QueueDel(comp.Owner);
} }
} }
private void Setup() private void Setup()
{ {
if (CargoMap != null && _mapManager.MapExists(CargoMap.Value)) return; if (!_enabled || CargoMap != null && _mapManager.MapExists(CargoMap.Value))
{
return;
}
// It gets mapinit which is okay... buuutt we still want it paused to avoid power draining. // It gets mapinit which is okay... buuutt we still want it paused to avoid power draining.
CargoMap = _mapManager.CreateMap(); CargoMap = _mapManager.CreateMap();

View File

@@ -27,7 +27,8 @@ public sealed partial class CargoSystem : SharedCargoSystem
public override void Shutdown() public override void Shutdown()
{ {
base.Shutdown(); base.Shutdown();
Cleanup(); ShutdownShuttle();
CleanupShuttle();
} }
private void OnStationInit(StationInitializedEvent ev) private void OnStationInit(StationInitializedEvent ev)

View File

@@ -900,6 +900,11 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<float> ShuttleIdleAngularDamping = public static readonly CVarDef<float> ShuttleIdleAngularDamping =
CVarDef.Create("shuttle.idle_angular_damping", 100f, CVar.SERVERONLY); CVarDef.Create("shuttle.idle_angular_damping", 100f, CVar.SERVERONLY);
/// <summary>
/// Whether cargo shuttles are enabled.
/// </summary>
public static readonly CVarDef<bool> CargoShuttles =
CVarDef.Create("shuttle.cargo", true, CVar.SERVERONLY);
/* /*
* Emergency * Emergency