From e5d71ac4c63db02a6447a7270cc46c9c1a422fde Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 13:42:54 +0300 Subject: [PATCH 01/21] Fix process toggle buttons not matching their actual states --- src/gui_common/ChemicalEquation.cs | 19 +++++---- src/microbe_stage/IProcessDisplayInfo.cs | 2 + src/microbe_stage/MicrobeHUD.cs | 5 +-- src/microbe_stage/ProcessList.cs | 6 +-- src/microbe_stage/ProcessPanel.cs | 4 +- src/microbe_stage/ProcessSpeedInformation.cs | 5 +++ src/microbe_stage/ProcessStatistics.cs | 41 ++++++++++++++----- .../StrictProcessDisplayInfoEquality.cs | 6 +++ src/microbe_stage/TweakedProcess.cs | 19 +++++---- src/microbe_stage/systems/ProcessSystem.cs | 2 +- 10 files changed, 72 insertions(+), 37 deletions(-) diff --git a/src/gui_common/ChemicalEquation.cs b/src/gui_common/ChemicalEquation.cs index 18b6ee7d068..b1a4c68bae0 100644 --- a/src/gui_common/ChemicalEquation.cs +++ b/src/gui_common/ChemicalEquation.cs @@ -59,8 +59,6 @@ public partial class ChemicalEquation : VBoxContainer /// private bool hasNoInputs; - private bool lastToggle = true; - [Signal] public delegate void ToggleProcessPressedEventHandler(ChemicalEquation thisEquation); @@ -102,14 +100,19 @@ public bool ShowToggle public bool ProcessEnabled { - get => lastToggle; + get + { + if (EquationFromProcess == null) + return true; + + return EquationFromProcess.Enabled; + } set { - if (value == lastToggle) + if (EquationFromProcess == null) return; - lastToggle = value; - ApplyProcessToggleValue(); + EmitSignal(SignalName.ToggleProcessPressed, this, value); } } @@ -245,6 +248,8 @@ private void UpdateEquation() // Environment conditions UpdateEnvironmentPart(environmentalInputs); + + ApplyProcessToggleValue(); } private void UpdateHeader() @@ -376,8 +381,6 @@ private string GetEnvironmentLabelText() private void ToggleButtonPressed(bool toggled) { ProcessEnabled = toggled; - - EmitSignal(SignalName.ToggleProcessPressed, this); } private void ApplyProcessToggleValue() diff --git a/src/microbe_stage/IProcessDisplayInfo.cs b/src/microbe_stage/IProcessDisplayInfo.cs index ca6c1ee6217..c9e44889710 100644 --- a/src/microbe_stage/IProcessDisplayInfo.cs +++ b/src/microbe_stage/IProcessDisplayInfo.cs @@ -43,6 +43,8 @@ public interface IProcessDisplayInfo : IEquatable /// public float CurrentSpeed { get; } + public bool Enabled { get; } + /// /// The limiting compounds in speed. Or null if not set /// diff --git a/src/microbe_stage/MicrobeHUD.cs b/src/microbe_stage/MicrobeHUD.cs index 0462548a43d..a77245e04be 100644 --- a/src/microbe_stage/MicrobeHUD.cs +++ b/src/microbe_stage/MicrobeHUD.cs @@ -841,7 +841,7 @@ private void OnTranslationsChanged() UpdateColonySizeForMacroscopic(); } - private void ToggleProcessPressed(ChemicalEquation equation) + private void ToggleProcessPressed(ChemicalEquation equation, bool enabled) { if (!stage!.HasAlivePlayer || !stage.Player.Has()) return; @@ -867,8 +867,7 @@ private void ToggleProcessPressed(ChemicalEquation equation) if (equation.EquationFromProcess.MatchesUnderlyingProcess(activeProcesses[i].Process)) { var process = activeProcesses[i]; - process.SpeedMultiplier = equation.ProcessEnabled ? 1 : 0; - activeProcesses[i] = process; + process.SpeedMultiplier = enabled ? 0 : 1; } } } diff --git a/src/microbe_stage/ProcessList.cs b/src/microbe_stage/ProcessList.cs index 64c48ca1f0f..b73d4676343 100644 --- a/src/microbe_stage/ProcessList.cs +++ b/src/microbe_stage/ProcessList.cs @@ -88,8 +88,6 @@ private ChemicalEquation CreateEquation(StrictProcessDisplayInfoEquality process equation.Connect(SignalName.ToggleProcessPressed, new Callable(this, nameof(HandleToggleProcess))); - equation.ProcessEnabled = process.DisplayInfo.CurrentSpeed > 0; - if (ProcessesTitleColour != null) equation.DefaultTitleFont = ProcessesTitleColour; @@ -99,8 +97,8 @@ private ChemicalEquation CreateEquation(StrictProcessDisplayInfoEquality process return equation; } - private void HandleToggleProcess(ChemicalEquation equation) + private void HandleToggleProcess(ChemicalEquation equation, bool enabled) { - EmitSignal(SignalName.ToggleProcessPressed, equation); + EmitSignal(SignalName.ToggleProcessPressed, equation, enabled); } } diff --git a/src/microbe_stage/ProcessPanel.cs b/src/microbe_stage/ProcessPanel.cs index b9d3c441cd2..4441ca564e5 100644 --- a/src/microbe_stage/ProcessPanel.cs +++ b/src/microbe_stage/ProcessPanel.cs @@ -64,8 +64,8 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } - private void ToggleProcessToggled(ChemicalEquation equation) + private void ToggleProcessToggled(ChemicalEquation equation, bool enabled) { - EmitSignal(SignalName.ToggleProcessPressed, equation); + EmitSignal(SignalName.ToggleProcessPressed, equation, enabled); } } diff --git a/src/microbe_stage/ProcessSpeedInformation.cs b/src/microbe_stage/ProcessSpeedInformation.cs index 42b3df75493..c3501e60fd5 100644 --- a/src/microbe_stage/ProcessSpeedInformation.cs +++ b/src/microbe_stage/ProcessSpeedInformation.cs @@ -39,6 +39,11 @@ public ProcessSpeedInformation(BioProcess process) public float CurrentSpeed { get; set; } + public bool Enabled + { + get => true; + } + /// /// Efficiency is a measure of how well the environment is favorable to the process. /// diff --git a/src/microbe_stage/ProcessStatistics.cs b/src/microbe_stage/ProcessStatistics.cs index c43d5bac91b..51927b52a7a 100644 --- a/src/microbe_stage/ProcessStatistics.cs +++ b/src/microbe_stage/ProcessStatistics.cs @@ -15,7 +15,7 @@ public class ProcessStatistics /// a ThreadLocal in as that was causing the game process to lock up in /// Godot 4 (for unknown reasons). See: https://github.com/Revolutionary-Games/Thrive/issues/4989 for context. /// - private List? temporaryRemovedItems; + private List? temporaryRemovedItems; /// /// The processes and their associated speed statistics @@ -32,7 +32,7 @@ public class ProcessStatistics /// /// [JsonIgnore] - public Dictionary Processes { get; } = new(); + public Dictionary Processes { get; } = new(); public void MarkAllUnused() { @@ -49,7 +49,7 @@ public void RemoveUnused() { lock (Processes) { - temporaryRemovedItems ??= new List(); + temporaryRemovedItems ??= new List(); foreach (var entry in Processes) { @@ -71,7 +71,7 @@ public void RemoveUnused() } } - public SingleProcessStatistics GetAndMarkUsed(BioProcess forProcess) + public SingleProcessStatistics GetAndMarkUsed(TweakedProcess forProcess) { #if DEBUG if (forProcess == null!) @@ -109,7 +109,7 @@ public class SingleProcessStatistics : IProcessDisplayInfo private Dictionary? precomputedEnvironmentInputs; - public SingleProcessStatistics(BioProcess process, + public SingleProcessStatistics(TweakedProcess process, float keepSnapshotTime = Constants.DEFAULT_PROCESS_STATISTICS_AVERAGE_INTERVAL) { this.keepSnapshotTime = keepSnapshotTime; @@ -120,11 +120,11 @@ public SingleProcessStatistics(BioProcess process, /// /// The process these statistics are for /// - public BioProcess Process { get; } + public TweakedProcess Process { get; } public bool Used { get; internal set; } - public string Name => Process.Name; + public string Name => Process.Process.Name; public IEnumerable> Inputs => LatestSnapshot?.Inputs.Where(p => !IProcessDisplayInfo.IsEnvironmental(p.Key)) ?? @@ -135,7 +135,7 @@ public SingleProcessStatistics(BioProcess process, throw new InvalidOperationException("No snapshot set"); public IReadOnlyDictionary FullSpeedRequiredEnvironmentalInputs => - precomputedEnvironmentInputs ??= Process.Inputs + precomputedEnvironmentInputs ??= Process.Process.Inputs .Where(p => IProcessDisplayInfo.IsEnvironmental(p.Key.ID)) .ToDictionary(p => p.Key.ID, p => p.Value); @@ -154,6 +154,11 @@ public float CurrentSpeed } } + public bool Enabled + { + get => Process.SpeedMultiplier > 0.5f; + } + public IReadOnlyList? LimitingCompounds => LatestSnapshot?.LimitingCompounds; private SingleProcessStatisticsSnapshot? LatestSnapshot => @@ -296,7 +301,7 @@ public void Clear() public bool MatchesUnderlyingProcess(BioProcess process) { - return Process == process; + return Process.Process == process; } public bool Equals(IProcessDisplayInfo? other) @@ -312,6 +317,7 @@ public override bool Equals(object? obj) // This also checks for obj being null if (obj is SingleProcessStatistics statistics) { + GD.Print(Process.Equals(statistics.Process)); return Process.Equals(statistics.Process); } @@ -322,6 +328,10 @@ public bool Equals(SingleProcessStatistics? other) { if (ReferenceEquals(null, other)) return false; + + if (Process.SpeedMultiplier != other.Process.SpeedMultiplier) + GD.Print("Speed multiplier mismatch!"); + if (ReferenceEquals(this, other)) return true; @@ -394,9 +404,16 @@ public AverageProcessStatistics(SingleProcessStatistics owner) public float CurrentSpeed { get; set; } public IReadOnlyList LimitingCompounds => WritableLimitingCompounds; + public TweakedProcess Process => owner.Process; + + public bool Enabled + { + get => owner.Process.SpeedMultiplier > 0.5f; + } + public bool MatchesUnderlyingProcess(BioProcess process) { - return owner.Process == process; + return owner.Process.Process == process; } public bool Equals(IProcessDisplayInfo? other) @@ -412,6 +429,10 @@ public override bool Equals(object? obj) // This also checks for obj being null if (obj is AverageProcessStatistics statistics) { + GD.Print(owner.Equals(statistics.owner)); + if (owner.Process.SpeedMultiplier != statistics.owner.Process.SpeedMultiplier) + GD.Print("Speed multiplier mismatch!"); + return owner.Equals(statistics.owner); } diff --git a/src/microbe_stage/StrictProcessDisplayInfoEquality.cs b/src/microbe_stage/StrictProcessDisplayInfoEquality.cs index df1e7fbc9d5..b1be70fa72f 100644 --- a/src/microbe_stage/StrictProcessDisplayInfoEquality.cs +++ b/src/microbe_stage/StrictProcessDisplayInfoEquality.cs @@ -33,6 +33,9 @@ public bool Equals(StrictProcessDisplayInfoEquality? other) var our = DisplayInfo; var theirs = other.DisplayInfo; + if (our.Enabled != theirs.Enabled) + return false; + if (our.Name != theirs.Name) return false; @@ -71,6 +74,9 @@ public bool Equals(StrictProcessDisplayInfoEquality? other) if (our.LimitingCompounds != null && !our.LimitingCompounds.SequenceEqual(theirs.LimitingCompounds!)) return false; + if (!our.Equals(theirs)) + return false; + return true; } diff --git a/src/microbe_stage/TweakedProcess.cs b/src/microbe_stage/TweakedProcess.cs index 9f98d2ab368..36523bca5f6 100644 --- a/src/microbe_stage/TweakedProcess.cs +++ b/src/microbe_stage/TweakedProcess.cs @@ -1,16 +1,11 @@ using System; +using Godot; using Newtonsoft.Json; /// /// A concrete process that organelle does. Applies a modifier to the process /// -/// -/// -/// This is a struct as this just packs a few floats and a single object reference in here. This allows much tighter -/// data packing when this is used in lists. -/// -/// -public struct TweakedProcess : IEquatable +public class TweakedProcess : IEquatable { [JsonProperty] public readonly BioProcess Process; @@ -44,13 +39,19 @@ public override bool Equals(object? obj) return false; } - public bool Equals(TweakedProcess other) + public bool Equals(TweakedProcess? other) { + if (ReferenceEquals(null, other)) + return false; + if (ReferenceEquals(this, other)) + return true; + if (Process != other.Process) return false; // ReSharper disable once CompareOfFloatsByEqualityOperator - return Rate == other.Rate && ReferenceEquals(Process, other.Process); + return Rate == other.Rate && SpeedMultiplier == other.SpeedMultiplier + && ReferenceEquals(Process, other.Process); } public TweakedProcess Clone() diff --git a/src/microbe_stage/systems/ProcessSystem.cs b/src/microbe_stage/systems/ProcessSystem.cs index 2502bc4870f..b5f4540a2d2 100644 --- a/src/microbe_stage/systems/ProcessSystem.cs +++ b/src/microbe_stage/systems/ProcessSystem.cs @@ -745,7 +745,7 @@ private void ProcessNode(ref BioProcesses processor, ref CompoundStorage storage var processData = process.Process; - var currentProcessStatistics = processStatistics?.GetAndMarkUsed(process.Process); + var currentProcessStatistics = processStatistics?.GetAndMarkUsed(process); if (currentProcessStatistics != null) { From 675742b13182152074c761e98ed5d210823b1147 Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 13:52:04 +0300 Subject: [PATCH 02/21] Fix button flickering --- src/microbe_stage/MicrobeHUD.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/microbe_stage/MicrobeHUD.cs b/src/microbe_stage/MicrobeHUD.cs index a77245e04be..6b018d99aa4 100644 --- a/src/microbe_stage/MicrobeHUD.cs +++ b/src/microbe_stage/MicrobeHUD.cs @@ -867,7 +867,7 @@ private void ToggleProcessPressed(ChemicalEquation equation, bool enabled) if (equation.EquationFromProcess.MatchesUnderlyingProcess(activeProcesses[i].Process)) { var process = activeProcesses[i]; - process.SpeedMultiplier = enabled ? 0 : 1; + process.SpeedMultiplier = enabled ? 1 : 0; } } } From bf554c2e57a8d0e7cf238e0d37fcedfa1f253954 Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 13:55:11 +0300 Subject: [PATCH 03/21] Make processes save their enabled-state when updated --- src/microbe_stage/systems/ProcessSystem.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/microbe_stage/systems/ProcessSystem.cs b/src/microbe_stage/systems/ProcessSystem.cs index b5f4540a2d2..d0bbb32d12a 100644 --- a/src/microbe_stage/systems/ProcessSystem.cs +++ b/src/microbe_stage/systems/ProcessSystem.cs @@ -61,6 +61,13 @@ public static void ComputeActiveProcessList(IReadOnlyList { result ??= new List(); + var speedMultipliers = new Dictionary(); + + foreach (var process in result) + { + speedMultipliers.TryAdd(process.Process, process.SpeedMultiplier); + } + // Very important to clear any existing list to ensure old processes don't hang around result.Clear(); @@ -109,6 +116,12 @@ public static void ComputeActiveProcessList(IReadOnlyList result.Add(new TweakedProcess(process.Process, process.Rate)); } } + + foreach (var newProcess in result) + { + if (speedMultipliers.TryGetValue(newProcess.Process, out float speedMultiplier)) + newProcess.SpeedMultiplier = speedMultiplier; + } } /// From f302c888a31de38dd3b408e9488f777e96883fc0 Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 13:59:23 +0300 Subject: [PATCH 04/21] Remove obsolete comment --- src/microbe_stage/ProcessStatistics.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/microbe_stage/ProcessStatistics.cs b/src/microbe_stage/ProcessStatistics.cs index 51927b52a7a..e424bc32ce7 100644 --- a/src/microbe_stage/ProcessStatistics.cs +++ b/src/microbe_stage/ProcessStatistics.cs @@ -22,11 +22,6 @@ public class ProcessStatistics /// /// /// - /// This uses rather than as the key so that equality - /// comparison matches based on the process type not the process type and speed. All processables should - /// combine their processes to run correctly with speed tracking. - /// - /// /// This is JSON ignore to ensure that this object can exist in saves, but won't store non-savable information /// like the process statistics object. That's the situation now but maybe some other design would be better... /// From 7dd3d8985dfa8c43247390ffa65b0df70d5789be Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 14:11:57 +0300 Subject: [PATCH 05/21] Remove a redundant function call --- src/gui_common/ChemicalEquation.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui_common/ChemicalEquation.cs b/src/gui_common/ChemicalEquation.cs index b1a4c68bae0..a268b02b836 100644 --- a/src/gui_common/ChemicalEquation.cs +++ b/src/gui_common/ChemicalEquation.cs @@ -152,7 +152,6 @@ public bool ShowFullSecondText public override void _Ready() { UpdateEquation(); - ApplyProcessToggleValue(); } public override void _EnterTree() From 1a4f975993a1b5cf5e0e066e15f4fdbd19d84fbd Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 14:12:30 +0300 Subject: [PATCH 06/21] Remove a redundant 'using' --- src/microbe_stage/TweakedProcess.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/microbe_stage/TweakedProcess.cs b/src/microbe_stage/TweakedProcess.cs index 36523bca5f6..02670a90d47 100644 --- a/src/microbe_stage/TweakedProcess.cs +++ b/src/microbe_stage/TweakedProcess.cs @@ -1,5 +1,4 @@ using System; -using Godot; using Newtonsoft.Json; /// From 6cd8c99fd4067007e27f737dd0bb54ffb2f2eeff Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 14:20:56 +0300 Subject: [PATCH 07/21] Style fix --- src/microbe_stage/ProcessStatistics.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/microbe_stage/ProcessStatistics.cs b/src/microbe_stage/ProcessStatistics.cs index e424bc32ce7..5cad449e0da 100644 --- a/src/microbe_stage/ProcessStatistics.cs +++ b/src/microbe_stage/ProcessStatistics.cs @@ -149,10 +149,7 @@ public float CurrentSpeed } } - public bool Enabled - { - get => Process.SpeedMultiplier > 0.5f; - } + public bool Enabled => Process.SpeedMultiplier > 0.5f; public IReadOnlyList? LimitingCompounds => LatestSnapshot?.LimitingCompounds; @@ -401,10 +398,7 @@ public AverageProcessStatistics(SingleProcessStatistics owner) public TweakedProcess Process => owner.Process; - public bool Enabled - { - get => owner.Process.SpeedMultiplier > 0.5f; - } + public bool Enabled => owner.Process.SpeedMultiplier > 0.5f; public bool MatchesUnderlyingProcess(BioProcess process) { From ecfe1cbdf5a211f6ec1fde97f22af0b962a2ed8e Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 20:20:56 +0300 Subject: [PATCH 08/21] Fix processes not being togglable on early multicellular organisms --- src/microbe_stage/MicrobeHUD.cs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/microbe_stage/MicrobeHUD.cs b/src/microbe_stage/MicrobeHUD.cs index 6b018d99aa4..da77d36943f 100644 --- a/src/microbe_stage/MicrobeHUD.cs +++ b/src/microbe_stage/MicrobeHUD.cs @@ -852,9 +852,26 @@ private void ToggleProcessPressed(ChemicalEquation equation, bool enabled) return; } - ref var processes = ref stage.Player.Get(); + if (stage.Player.Has()) + { + ref var colony = ref stage.Player.Get(); + + foreach (var colonyMember in colony.ColonyMembers) + { + ref var bioProcesses = ref colonyMember.Get(); + ToggleProcessOnEntity(equation, enabled, ref bioProcesses); + } + } + else + { + ref var bioProcesses = ref stage.Player.Get(); + ToggleProcessOnEntity(equation, enabled, ref bioProcesses); + } + } - var activeProcesses = processes.ActiveProcesses; + private void ToggleProcessOnEntity(ChemicalEquation equation, bool enabled, ref BioProcesses bioProcesses) + { + var activeProcesses = bioProcesses.ActiveProcesses; if (activeProcesses == null) return; @@ -864,7 +881,7 @@ private void ToggleProcessPressed(ChemicalEquation equation, bool enabled) for (int i = 0; i < processesCount; ++i) { // Update speed of the process controlled by the GUI control that signaled this change - if (equation.EquationFromProcess.MatchesUnderlyingProcess(activeProcesses[i].Process)) + if (equation.EquationFromProcess!.MatchesUnderlyingProcess(activeProcesses[i].Process)) { var process = activeProcesses[i]; process.SpeedMultiplier = enabled ? 1 : 0; From c059396739281ec8eb3b0fe5f00e3aaea5b899ab Mon Sep 17 00:00:00 2001 From: dligr Date: Sun, 27 Oct 2024 20:21:27 +0300 Subject: [PATCH 09/21] Style fix --- src/microbe_stage/ProcessSpeedInformation.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/microbe_stage/ProcessSpeedInformation.cs b/src/microbe_stage/ProcessSpeedInformation.cs index c3501e60fd5..5706991ce3a 100644 --- a/src/microbe_stage/ProcessSpeedInformation.cs +++ b/src/microbe_stage/ProcessSpeedInformation.cs @@ -39,10 +39,7 @@ public ProcessSpeedInformation(BioProcess process) public float CurrentSpeed { get; set; } - public bool Enabled - { - get => true; - } + public bool Enabled => true; /// /// Efficiency is a measure of how well the environment is favorable to the process. From 49d2bb82d390260c0037ea1891c638b139ead9f8 Mon Sep 17 00:00:00 2001 From: dligr Date: Mon, 28 Oct 2024 13:01:25 +0300 Subject: [PATCH 10/21] Remove debug prints from ProcessStatistics --- src/microbe_stage/ProcessStatistics.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/microbe_stage/ProcessStatistics.cs b/src/microbe_stage/ProcessStatistics.cs index 5cad449e0da..dbe0eac6871 100644 --- a/src/microbe_stage/ProcessStatistics.cs +++ b/src/microbe_stage/ProcessStatistics.cs @@ -309,7 +309,6 @@ public override bool Equals(object? obj) // This also checks for obj being null if (obj is SingleProcessStatistics statistics) { - GD.Print(Process.Equals(statistics.Process)); return Process.Equals(statistics.Process); } @@ -321,9 +320,6 @@ public bool Equals(SingleProcessStatistics? other) if (ReferenceEquals(null, other)) return false; - if (Process.SpeedMultiplier != other.Process.SpeedMultiplier) - GD.Print("Speed multiplier mismatch!"); - if (ReferenceEquals(this, other)) return true; @@ -418,10 +414,6 @@ public override bool Equals(object? obj) // This also checks for obj being null if (obj is AverageProcessStatistics statistics) { - GD.Print(owner.Equals(statistics.owner)); - if (owner.Process.SpeedMultiplier != statistics.owner.Process.SpeedMultiplier) - GD.Print("Speed multiplier mismatch!"); - return owner.Equals(statistics.owner); } From b7344f8d8ee39b57516a9cf912ffe50a68964c76 Mon Sep 17 00:00:00 2001 From: dligr Date: Mon, 28 Oct 2024 13:11:11 +0300 Subject: [PATCH 11/21] Make TweakedProcess a struct (it was unnecessary for it to be a class) --- src/microbe_stage/MicrobeHUD.cs | 1 + src/microbe_stage/ProcessStatistics.cs | 5 ----- src/microbe_stage/TweakedProcess.cs | 15 ++++++++------- src/microbe_stage/systems/ProcessSystem.cs | 7 ++++++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/microbe_stage/MicrobeHUD.cs b/src/microbe_stage/MicrobeHUD.cs index da77d36943f..3d32085c566 100644 --- a/src/microbe_stage/MicrobeHUD.cs +++ b/src/microbe_stage/MicrobeHUD.cs @@ -885,6 +885,7 @@ private void ToggleProcessOnEntity(ChemicalEquation equation, bool enabled, ref { var process = activeProcesses[i]; process.SpeedMultiplier = enabled ? 1 : 0; + activeProcesses[i] = process; } } } diff --git a/src/microbe_stage/ProcessStatistics.cs b/src/microbe_stage/ProcessStatistics.cs index dbe0eac6871..543380dd534 100644 --- a/src/microbe_stage/ProcessStatistics.cs +++ b/src/microbe_stage/ProcessStatistics.cs @@ -68,11 +68,6 @@ public void RemoveUnused() public SingleProcessStatistics GetAndMarkUsed(TweakedProcess forProcess) { -#if DEBUG - if (forProcess == null!) - throw new ArgumentException("Invalid process marked used"); -#endif - lock (Processes) { if (Processes.TryGetValue(forProcess, out var entry)) diff --git a/src/microbe_stage/TweakedProcess.cs b/src/microbe_stage/TweakedProcess.cs index 02670a90d47..b93ad89d066 100644 --- a/src/microbe_stage/TweakedProcess.cs +++ b/src/microbe_stage/TweakedProcess.cs @@ -4,7 +4,13 @@ /// /// A concrete process that organelle does. Applies a modifier to the process /// -public class TweakedProcess : IEquatable +/// +/// +/// This is a struct as this just packs a few floats and a single object reference in here. This allows much tighter +/// data packing when this is used in lists. +/// +/// +public struct TweakedProcess : IEquatable { [JsonProperty] public readonly BioProcess Process; @@ -38,13 +44,8 @@ public override bool Equals(object? obj) return false; } - public bool Equals(TweakedProcess? other) + public bool Equals(TweakedProcess other) { - if (ReferenceEquals(null, other)) - return false; - if (ReferenceEquals(this, other)) - return true; - if (Process != other.Process) return false; diff --git a/src/microbe_stage/systems/ProcessSystem.cs b/src/microbe_stage/systems/ProcessSystem.cs index d0bbb32d12a..3c77aec45a9 100644 --- a/src/microbe_stage/systems/ProcessSystem.cs +++ b/src/microbe_stage/systems/ProcessSystem.cs @@ -117,10 +117,15 @@ public static void ComputeActiveProcessList(IReadOnlyList } } - foreach (var newProcess in result) + int newProcessCount = result.Count; + for (int i = 0; i < newProcessCount; i++) { + var newProcess = result[i]; if (speedMultipliers.TryGetValue(newProcess.Process, out float speedMultiplier)) + { newProcess.SpeedMultiplier = speedMultiplier; + result[i] = newProcess; + } } } From 2937ea3f607f90574f4da9de4b7c5ff50f86137e Mon Sep 17 00:00:00 2001 From: dligr Date: Mon, 28 Oct 2024 13:57:21 +0300 Subject: [PATCH 12/21] Revert a line break --- src/microbe_stage/ProcessStatistics.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/microbe_stage/ProcessStatistics.cs b/src/microbe_stage/ProcessStatistics.cs index 543380dd534..d5599784cbc 100644 --- a/src/microbe_stage/ProcessStatistics.cs +++ b/src/microbe_stage/ProcessStatistics.cs @@ -314,7 +314,6 @@ public bool Equals(SingleProcessStatistics? other) { if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; From 4a406e56adab8698345f63b610ea3211d38b5d01 Mon Sep 17 00:00:00 2001 From: dligr Date: Mon, 28 Oct 2024 14:02:39 +0300 Subject: [PATCH 13/21] Style fix --- src/microbe_stage/systems/ProcessSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/microbe_stage/systems/ProcessSystem.cs b/src/microbe_stage/systems/ProcessSystem.cs index 3c77aec45a9..3c9ecdb97a0 100644 --- a/src/microbe_stage/systems/ProcessSystem.cs +++ b/src/microbe_stage/systems/ProcessSystem.cs @@ -118,7 +118,7 @@ public static void ComputeActiveProcessList(IReadOnlyList } int newProcessCount = result.Count; - for (int i = 0; i < newProcessCount; i++) + for (int i = 0; i < newProcessCount; ++i) { var newProcess = result[i]; if (speedMultipliers.TryGetValue(newProcess.Process, out float speedMultiplier)) From cfd34b63c1f4884e8801246fc722eb2d0ab906ee Mon Sep 17 00:00:00 2001 From: dligr Date: Mon, 28 Oct 2024 14:08:52 +0300 Subject: [PATCH 14/21] Add an error print --- src/gui_common/ChemicalEquation.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gui_common/ChemicalEquation.cs b/src/gui_common/ChemicalEquation.cs index a268b02b836..ab046d947b5 100644 --- a/src/gui_common/ChemicalEquation.cs +++ b/src/gui_common/ChemicalEquation.cs @@ -110,7 +110,10 @@ public bool ProcessEnabled set { if (EquationFromProcess == null) + { + GD.PrintErr("Display info isn't assigned to a ChemicalEquation, can't toggle process"); return; + } EmitSignal(SignalName.ToggleProcessPressed, this, value); } From adb3fb71b2837db887ad2b9792c5ea5dd84f4e7c Mon Sep 17 00:00:00 2001 From: dligr Date: Mon, 28 Oct 2024 14:18:21 +0300 Subject: [PATCH 15/21] Add a debug exception throw --- src/microbe_stage/ProcessStatistics.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/microbe_stage/ProcessStatistics.cs b/src/microbe_stage/ProcessStatistics.cs index d5599784cbc..0d63a2118a2 100644 --- a/src/microbe_stage/ProcessStatistics.cs +++ b/src/microbe_stage/ProcessStatistics.cs @@ -72,6 +72,10 @@ public SingleProcessStatistics GetAndMarkUsed(TweakedProcess forProcess) { if (Processes.TryGetValue(forProcess, out var entry)) { +#if DEBUG + if (forProcess.Process == null!) + throw new ArgumentException("Invalid process marked used"); +#endif entry.Used = true; return entry; } From 16ac90df24bc44fa403d2a4df5969b704aa8e633 Mon Sep 17 00:00:00 2001 From: dligr Date: Mon, 28 Oct 2024 14:20:38 +0300 Subject: [PATCH 16/21] Fix wrong code revert --- src/microbe_stage/ProcessStatistics.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/microbe_stage/ProcessStatistics.cs b/src/microbe_stage/ProcessStatistics.cs index 0d63a2118a2..f71f4b3f010 100644 --- a/src/microbe_stage/ProcessStatistics.cs +++ b/src/microbe_stage/ProcessStatistics.cs @@ -68,14 +68,14 @@ public void RemoveUnused() public SingleProcessStatistics GetAndMarkUsed(TweakedProcess forProcess) { +#if DEBUG + if (forProcess.Process == null!) + throw new ArgumentException("Invalid process marked used"); +#endif lock (Processes) { if (Processes.TryGetValue(forProcess, out var entry)) { -#if DEBUG - if (forProcess.Process == null!) - throw new ArgumentException("Invalid process marked used"); -#endif entry.Used = true; return entry; } From 07063b479d06e0eb575dee3730771fd4bf8aed91 Mon Sep 17 00:00:00 2001 From: dligr Date: Mon, 28 Oct 2024 14:26:57 +0300 Subject: [PATCH 17/21] Remove some new comparisons --- src/microbe_stage/StrictProcessDisplayInfoEquality.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/microbe_stage/StrictProcessDisplayInfoEquality.cs b/src/microbe_stage/StrictProcessDisplayInfoEquality.cs index b1be70fa72f..df1e7fbc9d5 100644 --- a/src/microbe_stage/StrictProcessDisplayInfoEquality.cs +++ b/src/microbe_stage/StrictProcessDisplayInfoEquality.cs @@ -33,9 +33,6 @@ public bool Equals(StrictProcessDisplayInfoEquality? other) var our = DisplayInfo; var theirs = other.DisplayInfo; - if (our.Enabled != theirs.Enabled) - return false; - if (our.Name != theirs.Name) return false; @@ -74,9 +71,6 @@ public bool Equals(StrictProcessDisplayInfoEquality? other) if (our.LimitingCompounds != null && !our.LimitingCompounds.SequenceEqual(theirs.LimitingCompounds!)) return false; - if (!our.Equals(theirs)) - return false; - return true; } From e813cdbf870ebeb5c6210af5f47395813aff5cef Mon Sep 17 00:00:00 2001 From: dligr Date: Tue, 29 Oct 2024 22:45:38 +0300 Subject: [PATCH 18/21] Reduce temporary memory allocations --- src/microbe_stage/systems/ProcessSystem.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/microbe_stage/systems/ProcessSystem.cs b/src/microbe_stage/systems/ProcessSystem.cs index 3c9ecdb97a0..c91adbe07ed 100644 --- a/src/microbe_stage/systems/ProcessSystem.cs +++ b/src/microbe_stage/systems/ProcessSystem.cs @@ -32,6 +32,8 @@ namespace Systems; [RuntimeCost(55)] public sealed class ProcessSystem : AEntitySetSystem { + private static readonly Dictionary TempSpeedMultipliers = new(); + #if CHECK_USED_STATISTICS private readonly List usedStatistics = new(); #endif @@ -61,11 +63,9 @@ public static void ComputeActiveProcessList(IReadOnlyList { result ??= new List(); - var speedMultipliers = new Dictionary(); - foreach (var process in result) { - speedMultipliers.TryAdd(process.Process, process.SpeedMultiplier); + TempSpeedMultipliers.TryAdd(process.Process, process.SpeedMultiplier); } // Very important to clear any existing list to ensure old processes don't hang around @@ -121,12 +121,14 @@ public static void ComputeActiveProcessList(IReadOnlyList for (int i = 0; i < newProcessCount; ++i) { var newProcess = result[i]; - if (speedMultipliers.TryGetValue(newProcess.Process, out float speedMultiplier)) + if (TempSpeedMultipliers.TryGetValue(newProcess.Process, out float speedMultiplier)) { newProcess.SpeedMultiplier = speedMultiplier; result[i] = newProcess; } } + + TempSpeedMultipliers.Clear(); } /// From 98f8d40b5fa12c17f90da45f149159d244615012 Mon Sep 17 00:00:00 2001 From: dligr Date: Thu, 31 Oct 2024 22:06:29 +0300 Subject: [PATCH 19/21] Move memory allocations out of ProcessSystem --- .../world_effects/PhotosynthesisProductionEffect.cs | 4 +++- src/microbe_stage/components/OrganelleContainer.cs | 2 +- src/microbe_stage/editor/CellEditorComponent.cs | 4 +++- src/microbe_stage/systems/ProcessSystem.cs | 10 ++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index e885cf811f3..9f3ca9c78a0 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -50,6 +50,8 @@ private void ApplyCompoundsAddition() float oxygenBalance = 0; float co2Balance = 0; + Dictionary tempStorage = new(); + foreach (var species in patch.SpeciesInPatch) { // Only microbial photosynthesis and respiration are taken into account @@ -67,7 +69,7 @@ private void ApplyCompoundsAddition() if (balance.TotalConsumption < balance.TotalProduction) balanceModifier = balance.TotalConsumption / balance.TotalProduction; - ProcessSystem.ComputeActiveProcessList(microbeSpecies.Organelles, ref microbeProcesses); + ProcessSystem.ComputeActiveProcessList(microbeSpecies.Organelles, ref microbeProcesses, tempStorage); foreach (var process in microbeProcesses) { diff --git a/src/microbe_stage/components/OrganelleContainer.cs b/src/microbe_stage/components/OrganelleContainer.cs index 7743eb6ac6c..3e77a2d0768 100644 --- a/src/microbe_stage/components/OrganelleContainer.cs +++ b/src/microbe_stage/components/OrganelleContainer.cs @@ -348,7 +348,7 @@ public static void RecalculateOrganelleBioProcesses(this ref OrganelleContainer if (container.Organelles != null) { ProcessSystem.ComputeActiveProcessList(container.Organelles.Organelles, - ref bioProcesses.ActiveProcesses); + ref bioProcesses.ActiveProcesses, new Dictionary()); } } diff --git a/src/microbe_stage/editor/CellEditorComponent.cs b/src/microbe_stage/editor/CellEditorComponent.cs index e8769eea82a..a95e2ffbc72 100644 --- a/src/microbe_stage/editor/CellEditorComponent.cs +++ b/src/microbe_stage/editor/CellEditorComponent.cs @@ -164,6 +164,8 @@ public partial class CellEditorComponent : private readonly Dictionary processSpeedWorkMemory = new(); + private readonly Dictionary tempProcessListMemory = new(); + private readonly List temporaryDisplayerFetchList = new(); private readonly List ignoredEditorWarnings = new(); @@ -1994,7 +1996,7 @@ private void HandleProcessList(EnergyBalanceInfo energyBalance, IBiomeConditions // Empty list to later fill var processStatistics = new List(); - ProcessSystem.ComputeActiveProcessList(editedMicrobeOrganelles, ref processes); + ProcessSystem.ComputeActiveProcessList(editedMicrobeOrganelles, ref processes, tempProcessListMemory); float consumptionProductionRatio = energyBalance.TotalConsumption / energyBalance.TotalProduction; diff --git a/src/microbe_stage/systems/ProcessSystem.cs b/src/microbe_stage/systems/ProcessSystem.cs index c91adbe07ed..5f3ca38c2b1 100644 --- a/src/microbe_stage/systems/ProcessSystem.cs +++ b/src/microbe_stage/systems/ProcessSystem.cs @@ -32,8 +32,6 @@ namespace Systems; [RuntimeCost(55)] public sealed class ProcessSystem : AEntitySetSystem { - private static readonly Dictionary TempSpeedMultipliers = new(); - #if CHECK_USED_STATISTICS private readonly List usedStatistics = new(); #endif @@ -59,13 +57,13 @@ public ProcessSystem(World world, IParallelRunner runner) : base(world, runner, /// /// public static void ComputeActiveProcessList(IReadOnlyList organelles, - [NotNull] ref List? result) + [NotNull] ref List? result, Dictionary tempStorage) { result ??= new List(); foreach (var process in result) { - TempSpeedMultipliers.TryAdd(process.Process, process.SpeedMultiplier); + tempStorage.TryAdd(process.Process, process.SpeedMultiplier); } // Very important to clear any existing list to ensure old processes don't hang around @@ -121,14 +119,14 @@ public static void ComputeActiveProcessList(IReadOnlyList for (int i = 0; i < newProcessCount; ++i) { var newProcess = result[i]; - if (TempSpeedMultipliers.TryGetValue(newProcess.Process, out float speedMultiplier)) + if (tempStorage.TryGetValue(newProcess.Process, out float speedMultiplier)) { newProcess.SpeedMultiplier = speedMultiplier; result[i] = newProcess; } } - TempSpeedMultipliers.Clear(); + tempStorage.Clear(); } /// From 23acaae4f36d2fe1296a40fe666645cd6fd5ec6b Mon Sep 17 00:00:00 2001 From: dligr Date: Thu, 31 Oct 2024 22:36:01 +0300 Subject: [PATCH 20/21] Save some more memory allocations --- src/microbe_stage/MicrobeStage.cs | 5 +++-- src/microbe_stage/MicrobeVisualOnlySimulation.cs | 3 ++- src/microbe_stage/Spawners.cs | 3 ++- src/microbe_stage/components/CellProperties.cs | 4 ++-- src/microbe_stage/components/OrganelleContainer.cs | 10 +++++----- .../systems/EndosymbiontOrganelleSystem.cs | 3 ++- src/microbe_stage/systems/MicrobeReproductionSystem.cs | 5 +++-- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/microbe_stage/MicrobeStage.cs b/src/microbe_stage/MicrobeStage.cs index f4dad2e0aef..1f226dcc913 100644 --- a/src/microbe_stage/MicrobeStage.cs +++ b/src/microbe_stage/MicrobeStage.cs @@ -634,6 +634,7 @@ public override void OnReturnFromEditor() var workData1 = new List(); var workData2 = new List(); + var tempMemory = new Dictionary(); var playerSpecies = Player.Get().Species; @@ -650,13 +651,13 @@ public override void OnReturnFromEditor() earlySpeciesType.MulticellularCellType = earlySpeciesType.Species.Cells[0].CellType; cellProperties.ReApplyCellTypeProperties(Player, earlySpeciesType.MulticellularCellType, - earlySpeciesType.Species, WorldSimulation, workData1, workData2); + earlySpeciesType.Species, WorldSimulation, workData1, workData2, tempMemory); } else { ref var species = ref Player.Get(); cellProperties.ReApplyCellTypeProperties(Player, species.Species, species.Species, WorldSimulation, - workData1, workData2); + workData1, workData2, tempMemory); } var playerPosition = Player.Get().Position; diff --git a/src/microbe_stage/MicrobeVisualOnlySimulation.cs b/src/microbe_stage/MicrobeVisualOnlySimulation.cs index c8eaac0b892..808a9ce1e30 100644 --- a/src/microbe_stage/MicrobeVisualOnlySimulation.cs +++ b/src/microbe_stage/MicrobeVisualOnlySimulation.cs @@ -15,6 +15,7 @@ public sealed class MicrobeVisualOnlySimulation : WorldSimulation private readonly List hexWorkData1 = new(); private readonly List hexWorkData2 = new(); + private readonly Dictionary tempProcessListMemory = new(); // Base systems private AnimationControlSystem animationControlSystem = null!; @@ -143,7 +144,7 @@ public void ApplyNewVisualisationMicrobeSpecies(Entity microbe, MicrobeSpecies s // Do a full update apply with the general code method ref var cellProperties = ref microbe.Get(); - cellProperties.ReApplyCellTypeProperties(microbe, species, species, this, hexWorkData1, hexWorkData2); + cellProperties.ReApplyCellTypeProperties(microbe, species, species, this, hexWorkData1, hexWorkData2, tempProcessListMemory); // TODO: update species member component if species changed? } diff --git a/src/microbe_stage/Spawners.cs b/src/microbe_stage/Spawners.cs index 80ecb359d6e..52905d5d3bf 100644 --- a/src/microbe_stage/Spawners.cs +++ b/src/microbe_stage/Spawners.cs @@ -571,9 +571,10 @@ public static float SpawnMicrobeWithoutFinalizing(IWorldSimulation worldSimulati // just need to accept that spawning a microbe allocates a bit of temporary unnecessary memory var workData1 = new List(); var workData2 = new List(); + var tempMemory = new Dictionary(); container.CreateOrganelleLayout(usedCellDefinition, workData1, workData2); - container.RecalculateOrganelleBioProcesses(ref bioProcesses); + container.RecalculateOrganelleBioProcesses(ref bioProcesses, tempMemory); organelleCount = container.Organelles!.Count; diff --git a/src/microbe_stage/components/CellProperties.cs b/src/microbe_stage/components/CellProperties.cs index 442d813c96b..3924a3a3f7c 100644 --- a/src/microbe_stage/components/CellProperties.cs +++ b/src/microbe_stage/components/CellProperties.cs @@ -523,7 +523,7 @@ public static Vector3 CalculateExternalOrganellePosition(this ref CellProperties /// More temporary memory public static void ReApplyCellTypeProperties(this ref CellProperties cellProperties, in Entity entity, ICellDefinition newDefinition, Species baseReproductionCostFrom, IWorldSimulation worldSimulation, - List workMemory1, List workMemory2) + List workMemory1, List workMemory2, Dictionary tempStorage) { // Copy new cell type properties cellProperties.MembraneType = newDefinition.MembraneType; @@ -550,7 +550,7 @@ public static void ReApplyCellTypeProperties(this ref CellProperties cellPropert // Reset all the duplicates organelles / reproduction progress of the entity // This also resets multicellular creature's reproduction progress organelleContainer.ResetOrganelleLayout(ref entity.Get(), ref entity.Get(), - entity, newDefinition, baseReproductionCostFrom, worldSimulation, workMemory1, workMemory2); + entity, newDefinition, baseReproductionCostFrom, worldSimulation, workMemory1, workMemory2, tempStorage); // Reset runtime colour if (entity.Has()) diff --git a/src/microbe_stage/components/OrganelleContainer.cs b/src/microbe_stage/components/OrganelleContainer.cs index 3e77a2d0768..b3ed2f9faa7 100644 --- a/src/microbe_stage/components/OrganelleContainer.cs +++ b/src/microbe_stage/components/OrganelleContainer.cs @@ -272,7 +272,7 @@ public static void CreateOrganelleLayout(this ref OrganelleContainer container, public static void ResetOrganelleLayout(this ref OrganelleContainer container, ref CompoundStorage storageToUpdate, ref BioProcesses bioProcessesToUpdate, in Entity entity, ICellDefinition cellDefinition, Species baseReproductionCostFrom, IWorldSimulation worldSimulation, - List workMemory1, List workMemory2) + List workMemory1, List workMemory2, Dictionary tempStorage) { container.CreateOrganelleLayout(cellDefinition, workMemory1, workMemory2); container.UpdateEngulfingSizeData(ref entity.Get(), ref entity.Get(), @@ -314,7 +314,7 @@ public static void ResetOrganelleLayout(this ref OrganelleContainer container, container.UpdateCompoundBagStorageFromOrganelles(ref storageToUpdate); - container.RecalculateOrganelleBioProcesses(ref bioProcessesToUpdate); + container.RecalculateOrganelleBioProcesses(ref bioProcessesToUpdate, tempStorage); // Rescale health in case max health changed (for example the player picked a new membrane) ref var health = ref entity.Get(); @@ -330,7 +330,7 @@ public static void ResetOrganelleLayout(this ref OrganelleContainer container, /// public static void OnOrganellesChanged(this ref OrganelleContainer container, ref CompoundStorage storage, ref BioProcesses bioProcesses, ref Engulfer engulfer, ref Engulfable engulfable, - ref CellProperties cellProperties) + ref CellProperties cellProperties, Dictionary tempStorage) { container.OrganelleVisualsCreated = false; container.OrganelleComponentsCached = false; @@ -339,11 +339,11 @@ public static void OnOrganellesChanged(this ref OrganelleContainer container, re container.UpdateEngulfingSizeData(ref engulfer, ref engulfable, cellProperties.IsBacteria); container.UpdateCompoundBagStorageFromOrganelles(ref storage); - container.RecalculateOrganelleBioProcesses(ref bioProcesses); + container.RecalculateOrganelleBioProcesses(ref bioProcesses, tempStorage); } public static void RecalculateOrganelleBioProcesses(this ref OrganelleContainer container, - ref BioProcesses bioProcesses) + ref BioProcesses bioProcesses, Dictionary tempStorage) { if (container.Organelles != null) { diff --git a/src/microbe_stage/systems/EndosymbiontOrganelleSystem.cs b/src/microbe_stage/systems/EndosymbiontOrganelleSystem.cs index deb84ba750e..fcb62294f76 100644 --- a/src/microbe_stage/systems/EndosymbiontOrganelleSystem.cs +++ b/src/microbe_stage/systems/EndosymbiontOrganelleSystem.cs @@ -32,6 +32,7 @@ public class EndosymbiontOrganelleSystem : AEntitySetSystem private readonly List hexWorkData = new(); private readonly List hexWorkData2 = new(); + private readonly Dictionary tempProcessListMemory = new(); public EndosymbiontOrganelleSystem(World world, IParallelRunner parallelRunner) : base(world, parallelRunner, Constants.SYSTEM_NORMAL_ENTITIES_PER_THREAD) @@ -74,7 +75,7 @@ protected override void Update(float state, in Entity entity) // times and when not empty mostly just once organelleContainer.OnOrganellesChanged(ref entity.Get(), ref entity.Get(), ref entity.Get(), ref entity.Get(), - ref entity.Get()); + ref entity.Get(), tempProcessListMemory); endosymbiontInfo.CreatedOrganelleInstancesFor.Add(symbiontSpecies); } diff --git a/src/microbe_stage/systems/MicrobeReproductionSystem.cs b/src/microbe_stage/systems/MicrobeReproductionSystem.cs index 0c802e93568..2a0d36139a7 100644 --- a/src/microbe_stage/systems/MicrobeReproductionSystem.cs +++ b/src/microbe_stage/systems/MicrobeReproductionSystem.cs @@ -68,6 +68,7 @@ public sealed class MicrobeReproductionSystem : AEntitySetSystem private readonly List compoundWorkData = new(); private readonly List hexWorkData = new(); private readonly List hexWorkData2 = new(); + private readonly Dictionary tempProcessListMemory = new(); private GameWorld? gameWorld; @@ -532,7 +533,7 @@ private void SplitQueuedOrganelles(List organellesToAdd, // help to complicate things by trying to fetch these before the loop organelles.OnOrganellesChanged(ref storage, ref entity.Get(), ref entity.Get(), ref entity.Get(), - ref entity.Get()); + ref entity.Get(), tempProcessListMemory); if (entity.Has()) { @@ -623,7 +624,7 @@ private void ReadyToReproduce(in Entity entity, ref OrganelleContainer organelle // Return the first cell to its normal, non duplicated cell arrangement and spawn a daughter cell organelles.ResetOrganelleLayout(ref entity.Get(), ref entity.Get(), - entity, species, species, worldSimulation, workData1, workData2); + entity, species, species, worldSimulation, workData1, workData2, tempProcessListMemory); // This is purely inside this lock to suppress a warning on worldSimulation cellProperties.Divide(ref organelles, entity, species, worldSimulation, spawnEnvironment, From 2baf438338896a09a6e5c64208e09164b9725387 Mon Sep 17 00:00:00 2001 From: dligr Date: Thu, 31 Oct 2024 22:57:39 +0300 Subject: [PATCH 21/21] Fix style --- src/microbe_stage/MicrobeVisualOnlySimulation.cs | 3 ++- src/microbe_stage/components/CellProperties.cs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/microbe_stage/MicrobeVisualOnlySimulation.cs b/src/microbe_stage/MicrobeVisualOnlySimulation.cs index 808a9ce1e30..6e936165344 100644 --- a/src/microbe_stage/MicrobeVisualOnlySimulation.cs +++ b/src/microbe_stage/MicrobeVisualOnlySimulation.cs @@ -144,7 +144,8 @@ public void ApplyNewVisualisationMicrobeSpecies(Entity microbe, MicrobeSpecies s // Do a full update apply with the general code method ref var cellProperties = ref microbe.Get(); - cellProperties.ReApplyCellTypeProperties(microbe, species, species, this, hexWorkData1, hexWorkData2, tempProcessListMemory); + cellProperties.ReApplyCellTypeProperties(microbe, species, species, this, hexWorkData1, hexWorkData2, + tempProcessListMemory); // TODO: update species member component if species changed? } diff --git a/src/microbe_stage/components/CellProperties.cs b/src/microbe_stage/components/CellProperties.cs index 3924a3a3f7c..a0f929c66c6 100644 --- a/src/microbe_stage/components/CellProperties.cs +++ b/src/microbe_stage/components/CellProperties.cs @@ -521,6 +521,7 @@ public static Vector3 CalculateExternalOrganellePosition(this ref CellProperties /// /// Temporary memory used for organelle copying /// More temporary memory + /// Even more temporary memory public static void ReApplyCellTypeProperties(this ref CellProperties cellProperties, in Entity entity, ICellDefinition newDefinition, Species baseReproductionCostFrom, IWorldSimulation worldSimulation, List workMemory1, List workMemory2, Dictionary tempStorage)