From 8a9700981b747a2a84d34ccb3125d16286a44ba4 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 4 Mar 2026 15:46:55 +0100 Subject: [PATCH] They are swarming! --- ClusterReceptor.cs | 18 ++++++++++++++---- Editor/ClusterInspector.cs | 5 +++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ClusterReceptor.cs b/ClusterReceptor.cs index b93e205..ba444c0 100644 --- a/ClusterReceptor.cs +++ b/ClusterReceptor.cs @@ -152,11 +152,11 @@ public class ClusterReceptor : Cluster, IReceptor { public virtual void ProcessStimulus(Neuron input, Vector3 inputValue, int thingId = 0, string thingName = null) { CleanupReceivers(); - Debug.Log($"{input.name} is {inputValue}, 1/{inputValue} = {1 / inputValue.x}, {1/inputValue.y}, {1/inputValue.z}"); + // Debug.Log($"{input.name} is {inputValue}, 1/{inputValue} = {1 / inputValue.x}, {1/inputValue.y}, {1/inputValue.z}"); //inputValue = input.Activator(inputValue); if (!thingReceivers.TryGetValue(thingId, out ClusterReceptor selectedReceiver)) - selectedReceiver = FindReceiver2(thingId, inputValue); + selectedReceiver = FindReceiver2(thingId, inputValue, input); if (selectedReceiver == null) return; @@ -174,7 +174,7 @@ public class ClusterReceptor : Cluster, IReceptor { if (selectedReceiver.clusterNuclei[inputIx] is Neuron selectedNeuron) selectedNeuron.ProcessStimulusDirect(inputValue); - Debug.Log($"cluster output = {selectedReceiver.defaultOutput.outputValue}"); + // Debug.Log($"cluster output = {selectedReceiver.defaultOutput.outputValue}"); } // private ClusterReceptor FindReceiver(int thingId, float3 inputValue) { @@ -220,7 +220,7 @@ public class ClusterReceptor : Cluster, IReceptor { // return selectedReceiver; // } - private ClusterReceptor FindReceiver2(int thingId, float3 inputValue) { + private ClusterReceptor FindReceiver2(int thingId, float3 inputValue, Neuron input) { // No existing nucleus for this thing ClusterReceptor selectedReceiver = null; float selectedMagnitude = 0; @@ -233,6 +233,7 @@ public class ClusterReceptor : Cluster, IReceptor { else if (receiver.defaultOutput.isSleeping) { // A sleeping receiver is not active and can therefore always be used thingReceivers.Add(thingId, receiver); + receiver.bias = float3(0, 0, 0); return receiver; } else if (selectedReceiver == null) { @@ -251,6 +252,15 @@ public class ClusterReceptor : Cluster, IReceptor { } } if (selectedReceiver != null) { + // To re-initialize the cluster (esp. memory cells) + // we update the cluster neuron twice. + // Bit of a hack..... + int inputIx = GetNucleusIndex(this.clusterNuclei, input); + if (inputIx >= 0) { + if (selectedReceiver.clusterNuclei[inputIx] is Neuron selectedNeuron) + selectedNeuron.ProcessStimulusDirect(inputValue); + } + // Replace the receiver // Find the thingId current associated with the receiver int keyToRemove = thingReceivers.FirstOrDefault(r => r.Value.Equals(selectedReceiver)).Key; diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index 56cb636..ef62a43 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -629,6 +629,7 @@ public class ClusterInspector : Editor { this.currentNucleus.name = newName; this.prefab.RefreshOutputs(); outputsField.choices = this.prefab.outputs.Select(output => output.name).ToList(); + anythingChanged = true; } if (Application.isPlaying) { @@ -767,8 +768,8 @@ public class ClusterInspector : Editor { } EditorGUILayout.Space(); - anythingChanged = ConnectNucleus(this.prefab, this.currentNucleus); - anythingChanged = AddSynapse(this.prefab, this.currentNucleus); + anythingChanged |= ConnectNucleus(this.prefab, this.currentNucleus); + anythingChanged |= AddSynapse(this.prefab, this.currentNucleus); } EditorGUILayout.EndFoldoutHeaderGroup(); }