Adding synapse to cluster

This commit is contained in:
Pascal Serrarens 2026-01-27 19:31:44 +01:00
parent 8d1a4c3b72
commit 296b80453f
3 changed files with 19 additions and 11 deletions

View File

@ -38,12 +38,15 @@ public class ClusterInstance : INucleus {
#region Synapses
private Synapse[] _synapses = new Synapse[0];
[SerializeReference]
private List<Synapse> _synapses = new();
public List<Synapse> synapses => new(_synapses);
public Synapse AddSynapse(IReceptor sendingNucleus, string nucleusName = null) {
if (nucleusName == null) {
this.asset.inputs[0].AddSynapse(sendingNucleus);
Synapse synapse = new(sendingNucleus);
this._synapses.Add(synapse);
// Nice, but this is not yet connected to the nucleusName
} else {
INucleus receptor = (INucleus)this.asset.nuclei.Find(nucleus => nucleus is INucleus n && nucleus.name == nucleusName);
receptor.AddSynapse(sendingNucleus);

View File

@ -142,7 +142,7 @@ public class Neuron : INucleus {
get { return _outputValue; }
set {
this.stale = 0;
this._isSleeping = false;
// this._isSleeping = false;
_outputValue = value;
}
}
@ -150,14 +150,16 @@ public class Neuron : INucleus {
[NonSerialized]
private int stale = 1000;
private bool _isSleeping = false;
public bool isSleeping => _isSleeping;
// private bool _isSleeping = false;
// public bool isSleeping => _isSleeping;
public bool isSleeping => lengthsq(this.outputValue) == 0;
public float lastTime { get; private set; }
public void UpdateNuclei() {
this.stale++;
this._isSleeping = this.stale > 2;
if (isSleeping)
// this._isSleeping = this.stale > 2;
// if (isSleeping)
if (this.stale > 2)
_outputValue = Vector3.zero;
}

View File

@ -371,6 +371,11 @@ public class ClusterInspector : Editor {
}
private void DrawNucleus(IReceptor nucleus, Vector3 position, float maxValue, float size, Color color) {
if (nucleus is MemoryCell memory) {
Handles.color = Color.white;
Handles.DrawWireDisc(position + Vector3.right * 10, Vector3.forward, size);
}
Handles.color = color;
Handles.DrawSolidDisc(position, Vector3.forward, size);
@ -489,8 +494,6 @@ public class ClusterInspector : Editor {
this.currentNucleus.name = EditorGUILayout.TextField(this.currentNucleus.name);
if (this.currentNucleus is Neuron neuroid) {
if (this.currentNucleus is MemoryCell memory) {
// should use serializedProperty
memory.deltaValue = EditorGUILayout.Toggle("DeltaValue", memory.deltaValue);
}
else {
EditorGUILayout.BeginHorizontal();
@ -652,8 +655,8 @@ public class ClusterInspector : Editor {
// Nucleus n = this.currentNucleus.brain.nuclei[selectedIndex - perceptei.Count()];
// n.AddReceiver(this.currentNucleus);
// }
IReceptor n = cluster.nuclei[selectedIndex];
n.AddReceiver(this.currentNucleus);
IReceptor receptor = cluster.nuclei[selectedIndex];
receptor.AddReceiver(this.currentNucleus);
}
}