From e72e0609729bd22710bbe83b6187c3158ed45fc0 Mon Sep 17 00:00:00 2001
From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Date: Mon, 27 Jun 2022 14:58:40 +1000
Subject: [PATCH] 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
---
.../Cargo/Systems/CargoSystem.Shuttle.cs | 94 ++++++++++++++-----
Content.Server/Cargo/Systems/CargoSystem.cs | 3 +-
Content.Shared/CCVar/CCVars.cs | 5 +
3 files changed, 77 insertions(+), 25 deletions(-)
diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs
index 3f1bc47d1e..78fcbd0484 100644
--- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs
+++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs
@@ -10,12 +10,14 @@ using Content.Shared.Cargo.BUI;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Events;
using Content.Shared.Cargo.Prototypes;
+using Content.Shared.CCVar;
using Content.Shared.Dataset;
using Content.Shared.GameTicking;
using Content.Shared.MobState.Components;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Audio;
+using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Random;
@@ -30,6 +32,7 @@ public sealed partial class CargoSystem
* Handles cargo shuttle mechanics, including cargo shuttle consoles.
*/
+ [Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapLoader _loader = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
@@ -50,8 +53,20 @@ public sealed partial class CargoSystem
private int _index;
+ ///
+ /// Whether cargo shuttles are enabled at all. Mainly used to disable cargo shuttle loading for performance reasons locally.
+ ///
+ private bool _enabled;
+
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(OnCargoShuttleMove);
SubscribeLocalEvent(OnCargoShuttleConsoleStartup);
SubscribeLocalEvent(OnCargoShuttleCall);
@@ -66,6 +81,31 @@ public sealed partial class CargoSystem
SubscribeLocalEvent(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(true))
+ {
+ AddShuttle(station);
+ }
+ }
+ else
+ {
+ CleanupShuttle();
+ }
+ }
+
#region Cargo Pilot Console
private void OnCargoPilotConsoleOpen(EntityUid uid, CargoPilotConsoleComponent component, AfterActivatableUIOpenEvent args)
@@ -245,31 +285,30 @@ public sealed partial class CargoSystem
{
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(component.CargoShuttleProto);
- var possibleNames = _protoMan.Index(prototype.NameDataset).Values;
- var name = _random.Pick(possibleNames);
+ var prototype = _protoMan.Index(component.CargoShuttleProto);
+ var possibleNames = _protoMan.Index(prototype.NameDataset).Values;
+ var name = _random.Pick(possibleNames);
- var (_, gridId) = _loader.LoadBlueprint(CargoMap.Value, prototype.Path.ToString());
- var shuttleUid = _mapManager.GetGridEuid(gridId!.Value);
- var xform = Transform(shuttleUid);
- MetaData(shuttleUid).EntityName = name;
+ var (_, gridId) = _loader.LoadBlueprint(CargoMap.Value, prototype.Path.ToString());
+ var shuttleUid = _mapManager.GetGridEuid(gridId!.Value);
+ var xform = Transform(shuttleUid);
+ MetaData(shuttleUid).EntityName = name;
- // TODO: Something better like a bounds check.
- xform.LocalPosition += 100 * _index;
- var comp = EnsureComp(shuttleUid);
- comp.Station = component.Owner;
- comp.Coordinates = xform.Coordinates;
+ // TODO: Something better like a bounds check.
+ xform.LocalPosition += 100 * _index;
+ var comp = EnsureComp(shuttleUid);
+ comp.Station = component.Owner;
+ comp.Coordinates = xform.Coordinates;
- component.Shuttle = shuttleUid;
- comp.NextCall = _timing.CurTime + TimeSpan.FromSeconds(comp.Cooldown);
- UpdateShuttleCargoConsoles(comp);
- _index++;
- _sawmill.Info($"Added cargo shuttle to {ToPrettyString(shuttleUid)}");
- }
+ component.Shuttle = shuttleUid;
+ comp.NextCall = _timing.CurTime + TimeSpan.FromSeconds(comp.Cooldown);
+ UpdateShuttleCargoConsoles(comp);
+ _index++;
+ _sawmill.Info($"Added cargo shuttle to {ToPrettyString(shuttleUid)}");
}
private void SellPallets(CargoShuttleComponent component, StationBankAccountComponent bank)
@@ -490,10 +529,10 @@ public sealed partial class CargoSystem
private void OnRoundRestart(RoundRestartCleanupEvent ev)
{
- Cleanup();
+ CleanupShuttle();
}
- private void Cleanup()
+ private void CleanupShuttle()
{
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.
foreach (var comp in EntityQuery())
{
+ if (TryComp(comp.Station, out var station))
+ {
+ station.Shuttle = null;
+ }
QueueDel(comp.Owner);
}
}
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.
CargoMap = _mapManager.CreateMap();
diff --git a/Content.Server/Cargo/Systems/CargoSystem.cs b/Content.Server/Cargo/Systems/CargoSystem.cs
index f675d05f25..695d0a55f1 100644
--- a/Content.Server/Cargo/Systems/CargoSystem.cs
+++ b/Content.Server/Cargo/Systems/CargoSystem.cs
@@ -27,7 +27,8 @@ public sealed partial class CargoSystem : SharedCargoSystem
public override void Shutdown()
{
base.Shutdown();
- Cleanup();
+ ShutdownShuttle();
+ CleanupShuttle();
}
private void OnStationInit(StationInitializedEvent ev)
diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs
index 4d5db09c5a..872c020548 100644
--- a/Content.Shared/CCVar/CCVars.cs
+++ b/Content.Shared/CCVar/CCVars.cs
@@ -900,6 +900,11 @@ namespace Content.Shared.CCVar
public static readonly CVarDef ShuttleIdleAngularDamping =
CVarDef.Create("shuttle.idle_angular_damping", 100f, CVar.SERVERONLY);
+ ///
+ /// Whether cargo shuttles are enabled.
+ ///
+ public static readonly CVarDef CargoShuttles =
+ CVarDef.Create("shuttle.cargo", true, CVar.SERVERONLY);
/*
* Emergency