Containment works again

This commit is contained in:
Pascal Serrarens 2026-02-18 17:26:45 +01:00
parent 76d8714778
commit f72a37b248
7 changed files with 36 additions and 39 deletions

View File

@ -39,10 +39,9 @@ public class Cluster : Nucleus {
Nucleus[] prefabNuclei = this.prefab.nuclei.ToArray(); Nucleus[] prefabNuclei = this.prefab.nuclei.ToArray();
// first clone the nuclei without their connections // first clone the nuclei without their connections
foreach (Nucleus nucleus in this.prefab.nuclei) { foreach (Nucleus nucleus in this.prefab.nuclei) {
Debug.Log($"prefab clone {nucleus.name}"); // Debug.Log($"prefab clone {nucleus.name}");
nucleus.ShallowCloneTo(this); nucleus.ShallowCloneTo(this);
} }
Debug.Log(" complete");
Nucleus[] clonedNuclei = this.clusterNuclei.ToArray(); Nucleus[] clonedNuclei = this.clusterNuclei.ToArray();
// Now clone the connections // Now clone the connections
@ -57,7 +56,7 @@ public class Cluster : Nucleus {
// Copy the receivers, which will also create the synapses // Copy the receivers, which will also create the synapses
// Clusters do not have receivers... // Clusters do not have receivers...
foreach (Nucleus receiver in prefabNeuron.receivers) { foreach (Nucleus receiver in prefabNeuron.receivers.ToArray()) {
int ix = GetNucleusIndex(prefabNuclei, receiver); int ix = GetNucleusIndex(prefabNuclei, receiver);
if (ix < 0) if (ix < 0)
continue; continue;
@ -420,10 +419,10 @@ public class Cluster : Nucleus {
return null; return null;
} }
public Receptor GetReceptor(string receptorName) { public IReceptor GetReceptor(string receptorName) {
foreach (Nucleus nucleus in this.clusterNuclei) { foreach (Nucleus nucleus in this.clusterNuclei) {
if (nucleus is Receptor receptor) if (nucleus is IReceptor receptor)
if (receptor.name == receptorName) if (receptor.GetName() == receptorName)
return receptor; return receptor;
} }
return null; return null;

View File

@ -15,6 +15,10 @@ public class ClusterReceptor : Cluster, IReceptor {
this.array = new NucleusArray(this); this.array = new NucleusArray(this);
} }
public string GetName() {
return this.name;
}
public override Nucleus ShallowCloneTo(Cluster parent) { public override Nucleus ShallowCloneTo(Cluster parent) {
ClusterReceptor clone = new(this.prefab, parent, this.name) { ClusterReceptor clone = new(this.prefab, parent, this.name) {
clusterPrefab = this.clusterPrefab, clusterPrefab = this.clusterPrefab,

View File

@ -452,10 +452,12 @@ public class ClusterInspector : Editor {
Handles.DrawLine(parentPos, pos); Handles.DrawLine(parentPos, pos);
Color color = Color.black; Color color = Color.black;
if (Application.isPlaying) { if (Application.isPlaying) {
float brightness = length(synapse.nucleus.outputValue) * synapse.weight / maxValue; if (maxValue == 0 || !float.IsFinite(maxValue))
maxValue = 1;
float brightness = length(synapse.nucleus.outputValue * synapse.weight) / maxValue;
color = new Color(brightness, brightness, brightness, 1f); color = new Color(brightness, brightness, brightness, 1f);
} }
if (synapse.nucleus.parent != null && synapse.nucleus.parent != this.currentNucleus) { if (synapse.nucleus.parent != null && synapse.nucleus.parent != this.currentNucleus.parent) {
// the synapse nucleus is part of a subcluster // the synapse nucleus is part of a subcluster
DrawNucleus(synapse.nucleus.parent, pos, maxValue, size, color); DrawNucleus(synapse.nucleus.parent, pos, maxValue, size, color);
} }

View File

@ -1,5 +1,11 @@
using UnityEngine;
public interface IReceptor { public interface IReceptor {
public string GetName();
public NucleusArray array { public NucleusArray array {
get; set; get; set;
} }
public void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName =null);
} }

View File

@ -4,19 +4,29 @@ using static Unity.Mathematics.math;
[System.Serializable] [System.Serializable]
public class Receptor : Neuron, IReceptor { public class Receptor : Neuron, IReceptor {
public Receptor(Cluster parent, string name) : base(parent, name) { } public Receptor(Cluster parent, string name) : base(parent, name) {
public Receptor(ClusterPrefab prefab, string name) : base(prefab, name) { } this.array ??= new NucleusArray(this);
}
public Receptor(ClusterPrefab prefab, string name) : base(prefab, name) {
this.array ??= new NucleusArray(this);
}
public string GetName() {
return this.name;
}
public override Nucleus ShallowCloneTo(Cluster parent) { public override Nucleus ShallowCloneTo(Cluster parent) {
Receptor clone = new(parent, name); Receptor clone = new(parent, name) {
//array = this.array
};
CloneFields(clone); CloneFields(clone);
clone.array = this.array;
return clone; return clone;
} }
public override Nucleus Clone(ClusterPrefab prefab) { public override Nucleus Clone(ClusterPrefab prefab) {
Receptor clone = new(prefab, name); Receptor clone = new(prefab, name) {
//array = this.array
};
CloneFields(clone); CloneFields(clone);
clone.array = this.array;
// Adding receivers will also add synapses to the receivers // Adding receivers will also add synapses to the receivers
foreach (Nucleus receiver in this.receivers) foreach (Nucleus receiver in this.receivers)
clone.AddReceiver(receiver); clone.AddReceiver(receiver);
@ -32,6 +42,7 @@ public class Receptor : Neuron, IReceptor {
public override void UpdateStateIsolated() { public override void UpdateStateIsolated() {
this.outputValue = this.bias; this.outputValue = this.bias;
//Debug.Log($"Receptor {this.name} outputvalue = {this.outputValue}");
} }
public override void UpdateNuclei() { public override void UpdateNuclei() {

View File

@ -1,23 +0,0 @@
using UnityEngine;
public class SelectorBrain : NanoBrain {
public Vector3 input1;
public Vector3 input2;
public Vector3 output;
public Receptor receptor;
//public Nucleus receptor2;
protected void Awake() {
receptor = this.brain.GetReceptor("Selector");
//receptor2 = this.brain.GetNucleus("Selector");
}
protected void Update() {
receptor.ProcessStimulus(input1, 0);
receptor.ProcessStimulus(input2, 1);
output = this.brain.outputValue;
this.brain.UpdateNuclei();
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 9051408e82b511584998506096af4bf0