additional refactor for #56; fixing AEPlanner spamming recalc of gear when coupling in waypoint mode and reporting stationary endlessly.

This commit is contained in:
2025-08-25 17:08:18 -05:00
parent ec9aadd6e2
commit 52e9fe1cab
3 changed files with 14 additions and 10 deletions

View File

@@ -2,6 +2,6 @@
<PropertyGroup> <PropertyGroup>
<MajorVersion>2</MajorVersion> <MajorVersion>2</MajorVersion>
<MinorVersion>1</MinorVersion> <MinorVersion>1</MinorVersion>
<PatchVersion>3</PatchVersion> <PatchVersion>4</PatchVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@@ -86,6 +86,8 @@ internal class AutoEngineerOrdersHelper_SendAutoEngineerCommand_Patch
noCaboose(); noCaboose();
logMessage += $"\nGovern AE? {output}"; logMessage += $"\nGovern AE? {output}";
if (_log.IsEnabled(Serilog.Events.LogEventLevel.Debug))
logMessage += $"\n{Environment.StackTrace}";
_log.Information(logMessage); _log.Information(logMessage);

View File

@@ -30,9 +30,7 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
private static readonly HashSet<IDisposable> _keyChangeObservers = new(); private static readonly HashSet<IDisposable> _keyChangeObservers = new();
private static readonly Dictionary<string, Dictionary<string, OpsCarPosition>> locoConsistDestinations = new(); private static readonly Dictionary<string, Dictionary<string, OpsCarPosition>> locoConsistDestinations = new();
private static readonly HashSet<Car> consist = new(); private static string _lastSelectedLoco = string.Empty;
private static string _lastLocoCarId = string.Empty;
private static bool recalcing = false;
static string getDictKey(Car car) => car.DisplayName; static string getDictKey(Car car) => car.DisplayName;
@@ -40,7 +38,9 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
{ {
PrepLocoUsage(out BaseLocomotive selectedLoco, out int numberOfCars); PrepLocoUsage(out BaseLocomotive selectedLoco, out int numberOfCars);
TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared; TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared;
if (!tweaksAndThings.IsEnabled()) return; if (!tweaksAndThings.IsEnabled() || (locoConsistDestinations.TryGetValue(getDictKey(selectedLoco), out Dictionary<string, OpsCarPosition> cars) && cars != null && _lastSelectedLoco == getDictKey(selectedLoco))) return;
_lastSelectedLoco = getDictKey(selectedLoco);
IterateCarsDetectDestinations( IterateCarsDetectDestinations(
__instance, __instance,
@@ -220,7 +220,6 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
_log.Debug($"{getDictKey(selectedLoco)} --> HI BOB[{numberOfCars}]"); _log.Debug($"{getDictKey(selectedLoco)} --> HI BOB[{numberOfCars}]");
foreach (var o in _keyChangeObservers) o.Dispose(); foreach (var o in _keyChangeObservers) o.Dispose();
_keyChangeObservers.Clear(); _keyChangeObservers.Clear();
recalcing = false;
} }
private static OpsCarPosition? GetCarDestinationIdentifier(Car c) private static OpsCarPosition? GetCarDestinationIdentifier(Car c)
@@ -276,7 +275,11 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
key, key,
delegate (Value value) delegate (Value value)
{ {
if (recalcing) return;
_log.Debug($"{getDictKey(car)} OBSV {key}: {value}");
if (locoConsistDestinations.TryGetValue(getDictKey(TrainController.Shared.SelectedLocomotive), out Dictionary<string, OpsCarPosition> cars) && cars == null) return;
bool waybillChng = (new[] { Car.KeyOpsWaybill, Car.KeyOpsRepairDestination }).Contains(key); bool waybillChng = (new[] { Car.KeyOpsWaybill, Car.KeyOpsRepairDestination }).Contains(key);
string? destId = string? destId =
waybillChng ? waybillChng ?
@@ -284,8 +287,7 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
null; null;
if (waybillChng) if (waybillChng)
{ {
if (locoConsistDestinations.TryGetValue(getDictKey(TrainController.Shared.SelectedLocomotive), out Dictionary<string, OpsCarPosition> cars) if (cars.TryGetValue(getDictKey(car), out OpsCarPosition pos)
&& cars.TryGetValue(getDictKey(car), out OpsCarPosition pos)
&& pos.Identifier == destId) && pos.Identifier == destId)
{ {
return; return;
@@ -307,7 +309,7 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
var loco = TrainController.Shared.SelectedLocomotive; var loco = TrainController.Shared.SelectedLocomotive;
if (!TrainController.Shared.SelectRecall()) TrainController.Shared.SelectedCar = null; if (!TrainController.Shared.SelectRecall()) TrainController.Shared.SelectedCar = null;
_keyChangeObservers.Clear(); _keyChangeObservers.Clear();
recalcing = true; if (locoConsistDestinations.TryGetValue(getDictKey(TrainController.Shared.SelectedLocomotive), out _)) locoConsistDestinations[getDictKey(TrainController.Shared.SelectedLocomotive)] = null;
TrainController.Shared.SelectedCar = loco; TrainController.Shared.SelectedCar = loco;
} }
catch (Exception ex) catch (Exception ex)