Make it work again

This commit is contained in:
Pascal Serrarens 2026-05-05 11:52:04 +02:00
parent 2ff550cba4
commit c78722abce
4 changed files with 60 additions and 59 deletions

View File

@ -88,7 +88,7 @@ namespace NanoBrain {
if (Application.isPlaying == false)
this.serializedBrain = new SerializedObject(this.prefab);
this.selectedOutput = this.currentCluster.outputs[0];
this.selectedOutput = this.currentCluster.defaultOutput;
this.currentNucleus = this.selectedOutput;
//this.currentCluster = this.currentNucleus.parent;
Rebuild(inspectorContainer);
@ -375,7 +375,7 @@ namespace NanoBrain {
bool disconnecting = GUILayout.Button("Disconnect", GUILayout.Width(80));
if (disconnecting) {
synapse.neuron.RemoveReceiver(this.currentNucleus);
this.prefab.GarbageCollection();
this.currentCluster.Refresh();
anythingChanged = true;
}
EditorGUILayout.EndHorizontal();
@ -517,35 +517,32 @@ namespace NanoBrain {
EditorGUILayout.EndHorizontal();
if (connecting) {
Nucleus nucleus = nuclei.ElementAt(selectedConnectNucleus);
// Nucleus prefabNucleus = this.prefab.cluster.nuclei.ElementAt(selectedConnectNucleus);
if (nucleus is Cluster subCluster) {
subCluster.AddArrayReceiver(this.currentNucleus);
// Cluster prefabSubCluster = prefabNucleus as Cluster;
}
else if (nucleus is Neuron neuron) {
neuron.AddReceiver(this.currentNucleus);
// if (prefabNucleus is Neuron prefabNeuron)
// prefabNeuron.AddReceiver(this.currentPrefabNucleus);
}
this.currentCluster.Refresh();
}
return connecting;
}
protected virtual void DisconnectNucleus(Neuron nucleus) {
if (this.currentNucleus.parent.prefab == null)
return;
Neuron currentNeuron = this.currentNucleus as Neuron;
string[] names = currentNeuron.synapses.Select(synapse => synapse.neuron.name).ToArray();
int selectedIndex = -1;
selectedIndex = EditorGUILayout.Popup("Disconnect from", selectedIndex, names);
if (selectedIndex >= 0 && selectedIndex < this.currentNucleus.parent.prefab.cluster.nuclei.Count) {
Synapse synapse = currentNeuron.synapses[selectedIndex];
synapse.neuron.RemoveReceiver(this.currentNucleus);
// protected virtual void DisconnectNucleus(Neuron nucleus) {
// if (this.currentNucleus.parent.prefab == null)
// return;
// Neuron currentNeuron = this.currentNucleus as Neuron;
// string[] names = currentNeuron.synapses.Select(synapse => synapse.neuron.name).ToArray();
// int selectedIndex = -1;
// selectedIndex = EditorGUILayout.Popup("Disconnect from", selectedIndex, names);
// if (selectedIndex >= 0 && selectedIndex < this.currentNucleus.parent.prefab.cluster.nuclei.Count) {
// Synapse synapse = currentNeuron.synapses[selectedIndex];
// synapse.neuron.RemoveReceiver(this.currentNucleus);
// synapse = currentNeuron.synapses[selectedIndex];
// synapse.neuron.RemoveReceiver(this.currentPrefabNucleus);
}
}
// // synapse = currentNeuron.synapses[selectedIndex];
// // synapse.neuron.RemoveReceiver(this.currentPrefabNucleus);
// }
// }
protected virtual void DeleteNucleus(Nucleus nucleus) {
if (nucleus == null)

View File

@ -72,10 +72,11 @@ namespace NanoBrain {
public Cluster(ClusterPrefab prefab, ClusterPrefab parent = null) {
this.prefab = prefab;
this.name = prefab.name;
this.parent.prefab = parent;
if (parent != null)
this.parent = parent.cluster;
if (this.parent.prefab != null)
this.parent.prefab.cluster.nuclei.Add(this);
// if (this.parent.prefab != null)
// this.parent.prefab.cluster.nuclei.Add(this);
ClonePrefab();
_ = this.inputs;
@ -773,9 +774,9 @@ namespace NanoBrain {
}
Neuron.Delete(nucleus);
int nucleusIx = this.nuclei.IndexOf(nucleus);
//int nucleusIx = this.nuclei.IndexOf(nucleus);
this.nuclei.Remove(nucleus);
this.prefab.cluster.nuclei.RemoveAt(nucleusIx);
//this.prefab.cluster.nuclei.RemoveAt(nucleusIx);
RefreshOutputs();
return true;
@ -908,6 +909,10 @@ namespace NanoBrain {
#endregion Update
public void Refresh() {
RefreshOutputs();
}
}
}

View File

@ -105,7 +105,7 @@ namespace NanoBrain {
/// <param name="inputValue"></param>
public virtual void SetBias(Vector3 inputValue) {
this.bias = inputValue;
this.parent.UpdateFromNucleus(this);
this.parent?.UpdateFromNucleus(this);
}
/// <summary>
@ -623,10 +623,9 @@ namespace NanoBrain {
#endregion Receivers
public override void ProcessStimulus(Vector3 inputValue) {
;
this.lastUpdate = Time.time;
this.bias = inputValue;
this.parent.UpdateFromNucleus(this);
this.parent?.UpdateFromNucleus(this);
}
}

View File

@ -101,38 +101,38 @@ namespace NanoBrain {
// this.nuclei.RemoveAll(nucleus => visitedNuclei.Contains(nucleus) == false);
}
public void MarkNuclei(HashSet<Nucleus> visitedNuclei, Nucleus nucleus) {
if (nucleus is null)
return;
// public void MarkNuclei(HashSet<Nucleus> visitedNuclei, Nucleus nucleus) {
// if (nucleus is null)
// return;
if (nucleus.parent != null && nucleus.parent.prefab != this)
visitedNuclei.Add(nucleus.parent);
else
visitedNuclei.Add(nucleus);
if (nucleus is Neuron neuron) {
if (neuron.synapses != null) {
HashSet<Synapse> visitedSynapses = new();
foreach (Synapse synapse in neuron.synapses) {
if (synapse != null && synapse.neuron != null) {
visitedSynapses.Add(synapse);
if (synapse.neuron is Nucleus synapse_nucleus)
MarkNuclei(visitedNuclei, synapse_nucleus);
}
}
neuron.synapses.RemoveAll(synapse => visitedSynapses.Contains(synapse) == false);
}
if (neuron.receivers != null) {
HashSet<Nucleus> visitedReceivers = new();
foreach (Nucleus receiver in neuron.receivers) {
if (receiver != null && receiver != null) {
visitedReceivers.Add(receiver);
visitedNuclei.Add(receiver);
}
}
neuron.receivers.RemoveAll(receiver => visitedReceivers.Contains(receiver) == false);
}
}
}
// if (nucleus.parent != null && nucleus.parent.prefab != this)
// visitedNuclei.Add(nucleus.parent);
// else
// visitedNuclei.Add(nucleus);
// if (nucleus is Neuron neuron) {
// if (neuron.synapses != null) {
// HashSet<Synapse> visitedSynapses = new();
// foreach (Synapse synapse in neuron.synapses) {
// if (synapse != null && synapse.neuron != null) {
// visitedSynapses.Add(synapse);
// if (synapse.neuron is Nucleus synapse_nucleus)
// MarkNuclei(visitedNuclei, synapse_nucleus);
// }
// }
// neuron.synapses.RemoveAll(synapse => visitedSynapses.Contains(synapse) == false);
// }
// if (neuron.receivers != null) {
// HashSet<Nucleus> visitedReceivers = new();
// foreach (Nucleus receiver in neuron.receivers) {
// if (receiver != null && receiver != null) {
// visitedReceivers.Add(receiver);
// visitedNuclei.Add(receiver);
// }
// }
// neuron.receivers.RemoveAll(receiver => visitedReceivers.Contains(receiver) == false);
// }
// }
// }
// public virtual void UpdateNuclei() {
// foreach (Nucleus nucleus in this.nuclei)