Removed IReceptor

This commit is contained in:
Pascal Serrarens 2026-02-05 17:00:26 +01:00
parent 0d268edd6d
commit d48475b483
9 changed files with 37 additions and 37 deletions

View File

@ -80,7 +80,7 @@ public class Cluster : INucleus {
// Copy nucleus arrays // Copy nucleus arrays
for (int nucleusIx = 0; nucleusIx < prefabNuclei.Length; nucleusIx++) { for (int nucleusIx = 0; nucleusIx < prefabNuclei.Length; nucleusIx++) {
IReceptor prefabReceptor = prefabNuclei[nucleusIx]; INucleus prefabReceptor = prefabNuclei[nucleusIx];
if (prefabReceptor is not INucleus prefabNucleus) if (prefabReceptor is not INucleus prefabNucleus)
continue; continue;
@ -92,9 +92,9 @@ public class Cluster : INucleus {
// We clone the array only for the first entry // We clone the array only for the first entry
NucleusArray clonedArray = new(prefabNucleus.array.nuclei.Length, "array"); NucleusArray clonedArray = new(prefabNucleus.array.nuclei.Length, "array");
int arrayIx = 0; int arrayIx = 0;
foreach (IReceptor prefabArrayNucleus in prefabNucleus.array.nuclei) { foreach (INucleus prefabArrayNucleus in prefabNucleus.array.nuclei) {
int arrayNucleusIx = GetNucleusIndex(prefabNuclei, prefabArrayNucleus); int arrayNucleusIx = GetNucleusIndex(prefabNuclei, prefabArrayNucleus);
IReceptor clonedArrayNucleus = clonedNuclei[arrayNucleusIx]; INucleus clonedArrayNucleus = clonedNuclei[arrayNucleusIx];
clonedArray.nuclei[arrayIx] = clonedArrayNucleus; clonedArray.nuclei[arrayIx] = clonedArrayNucleus;
arrayIx++; arrayIx++;
} }
@ -110,9 +110,9 @@ public class Cluster : INucleus {
} }
// Sort the nuclei in a correct evaluation order // Sort the nuclei in a correct evaluation order
private List<IReceptor> TopologicalSort(List<INucleus> nodes) { private List<INucleus> TopologicalSort(List<INucleus> nodes) {
Dictionary<IReceptor, int> inDegree = new(); Dictionary<INucleus, int> inDegree = new();
foreach (IReceptor node in nodes) foreach (INucleus node in nodes)
inDegree[node] = 0; // Initialize in-degree to zero inDegree[node] = 0; // Initialize in-degree to zero
// Calculate in-degrees // Calculate in-degrees
@ -127,7 +127,7 @@ public class Cluster : INucleus {
queue.Enqueue(node); queue.Enqueue(node);
} }
List<IReceptor> sortedOrder = new(); List<INucleus> sortedOrder = new();
while (queue.Count > 0) { while (queue.Count > 0) {
INucleus current = queue.Dequeue(); INucleus current = queue.Dequeue();
sortedOrder.Add(current); // Process the node sortedOrder.Add(current); // Process the node
@ -146,7 +146,7 @@ public class Cluster : INucleus {
return sortedOrder; return sortedOrder;
} }
public virtual IReceptor Clone() { public virtual INucleus Clone() {
//Neuron clone = new(this.cluster, this.name) { //Neuron clone = new(this.cluster, this.name) {
Neuron clone = new(this.parent, this.name) { Neuron clone = new(this.parent, this.name) {
array = this.array, array = this.array,
@ -162,14 +162,14 @@ public class Cluster : INucleus {
return clone; return clone;
} }
public IReceptor ShallowCloneTo(Cluster parent) { public INucleus ShallowCloneTo(Cluster parent) {
Cluster clone = new(this.prefab, parent) { Cluster clone = new(this.prefab, parent) {
name = this.name, name = this.name,
}; };
return clone; return clone;
} }
private int GetNucleusIndex(IReceptor[] nucleiArray, IReceptor nucleus) { private int GetNucleusIndex(INucleus[] nucleiArray, INucleus nucleus) {
for (int i = 0; i < nucleiArray.Length; i++) { for (int i = 0; i < nucleiArray.Length; i++) {
if (nucleus == nucleiArray[i]) if (nucleus == nucleiArray[i])
return i; return i;
@ -188,14 +188,14 @@ public class Cluster : INucleus {
public List<INucleus> nuclei = new(); public List<INucleus> nuclei = new();
// the nuclei sorted using topological sorting // the nuclei sorted using topological sorting
// to ensure that the cluster is computer in the right order // to ensure that the cluster is computer in the right order
public List<IReceptor> sortedNuclei; public List<INucleus> sortedNuclei;
public List<INucleus> _inputs = null; public List<INucleus> _inputs = null;
public virtual List<INucleus> inputs { public virtual List<INucleus> inputs {
get { get {
if (this._inputs == null) { if (this._inputs == null) {
this._inputs = new(); this._inputs = new();
foreach (IReceptor receptor in this.nuclei) { foreach (INucleus receptor in this.nuclei) {
if (receptor is INucleus nucleus) { if (receptor is INucleus nucleus) {
// inputs have no incoming synapses yet. // inputs have no incoming synapses yet.
if (nucleus.synapses.Count == 0) if (nucleus.synapses.Count == 0)
@ -224,7 +224,7 @@ public class Cluster : INucleus {
} }
public bool TryGetNucleus(string nucleusName, out Nucleus foundNucleus) { public bool TryGetNucleus(string nucleusName, out Nucleus foundNucleus) {
foreach (IReceptor receptor in this.nuclei) { foreach (INucleus receptor in this.nuclei) {
if (receptor is Nucleus nucleus) if (receptor is Nucleus nucleus)
if (nucleus.name == nucleusName) { if (nucleus.name == nucleusName) {
foundNucleus = nucleus; foundNucleus = nucleus;
@ -236,7 +236,7 @@ public class Cluster : INucleus {
} }
public Nucleus GetNucleus(string nucleusName) { public Nucleus GetNucleus(string nucleusName) {
foreach (IReceptor receptor in this.nuclei) { foreach (INucleus receptor in this.nuclei) {
if (receptor is Nucleus nucleus) if (receptor is Nucleus nucleus)
if (nucleus.name == nucleusName) if (nucleus.name == nucleusName)
return nucleus; return nucleus;
@ -341,7 +341,7 @@ public class Cluster : INucleus {
//this.inputs[0].UpdateState(sum); //this.inputs[0].UpdateState(sum);
this.inputs[0].UpdateStateIsolated(sum); this.inputs[0].UpdateStateIsolated(sum);
foreach (IReceptor receptor in this.sortedNuclei) { foreach (INucleus receptor in this.sortedNuclei) {
if (receptor is INucleus nucleus && nucleus != this.inputs[0]) { if (receptor is INucleus nucleus && nucleus != this.inputs[0]) {
//if (nucleus.isSleeping == false) //if (nucleus.isSleeping == false)
nucleus.UpdateStateIsolated(); nucleus.UpdateStateIsolated();

View File

@ -17,7 +17,7 @@ public class ClusterPrefab : ScriptableObject {
get { get {
if (this._inputs == null) { if (this._inputs == null) {
this._inputs = new(); this._inputs = new();
foreach (IReceptor receptor in this.nuclei) { foreach (INucleus receptor in this.nuclei) {
if (receptor is INucleus nucleus) { if (receptor is INucleus nucleus) {
// inputs have no incoming synapses yet. // inputs have no incoming synapses yet.
if (nucleus.synapses.Count == 0) if (nucleus.synapses.Count == 0)

View File

@ -71,7 +71,7 @@ public class ClusterInspector : Editor {
INucleus currentNucleus; INucleus currentNucleus;
GameObject gameObject; GameObject gameObject;
private List<NeuroidLayer> layers = new(); private List<NeuroidLayer> layers = new();
private readonly Dictionary<IReceptor, Vector2Int> neuroidPositions = new(); private readonly Dictionary<INucleus, Vector2Int> neuroidPositions = new();
private bool expandArray = false; private bool expandArray = false;
ClusterWrapper currentWrapper; ClusterWrapper currentWrapper;
@ -165,7 +165,7 @@ public class ClusterInspector : Editor {
if (selectedNucleus.synapses != null) { if (selectedNucleus.synapses != null) {
foreach (Synapse synapse in selectedNucleus.synapses) { foreach (Synapse synapse in selectedNucleus.synapses) {
IReceptor input = synapse.nucleus; INucleus input = synapse.nucleus;
AddToLayer(currentLayer, input); AddToLayer(currentLayer, input);
// Debug.Log($"layer {layerIx} nucleus {input.name}"); // Debug.Log($"layer {layerIx} nucleus {input.name}");
} }
@ -175,7 +175,7 @@ public class ClusterInspector : Editor {
} }
} }
private void AddToLayer(NeuroidLayer layer, IReceptor nucleus) { private void AddToLayer(NeuroidLayer layer, INucleus nucleus) {
if (nucleus == null) if (nucleus == null)
return; return;
layer.neuroids.Add(nucleus); layer.neuroids.Add(nucleus);
@ -449,7 +449,7 @@ public class ClusterInspector : Editor {
GUI.Box(tooltipRect, tooltip); GUI.Box(tooltipRect, tooltip);
} }
private void HandleClicked(IReceptor nucleus) { private void HandleClicked(INucleus nucleus) {
if (nucleus == this.currentNucleus) { if (nucleus == this.currentNucleus) {
if (nucleus is INucleus n) { if (nucleus is INucleus n) {
expandArray = !expandArray; expandArray = !expandArray;
@ -734,7 +734,7 @@ public class ClusterInspector : Editor {
public class NeuroidLayer { public class NeuroidLayer {
public int ix = 0; public int ix = 0;
public List<IReceptor> neuroids = new(); public List<INucleus> neuroids = new();
} }
public class ClusterWrapper : ScriptableObject { public class ClusterWrapper : ScriptableObject {

View File

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Unity.Mathematics; using Unity.Mathematics;
public interface INucleus : IReceptor { public interface INucleus {
#region static struct #region static struct
@ -48,10 +48,10 @@ public interface INucleus : IReceptor {
#endregion dynamic #endregion dynamic
public IReceptor ShallowCloneTo(Cluster parent); public INucleus ShallowCloneTo(Cluster parent);
public IReceptor Clone(); public INucleus Clone();
} }
public interface IReceptor { // public interface IReceptor {
} // }

View File

@ -13,7 +13,7 @@ public class MemoryCell : Neuron, INucleus {
// this.parent?.nuclei.Add(this); // this.parent?.nuclei.Add(this);
// } // }
public override IReceptor ShallowCloneTo(Cluster newParent) { public override INucleus ShallowCloneTo(Cluster newParent) {
MemoryCell clone = new(newParent, this.name) { MemoryCell clone = new(newParent, this.name) {
array = this.array, array = this.array,
curve = this.curve, curve = this.curve,

View File

@ -181,7 +181,7 @@ public class Neuron : Nucleus, INucleus {
#endregion Runtime state #endregion Runtime state
// this clone the nucleus without the synapses and receivers // this clone the nucleus without the synapses and receivers
public override IReceptor ShallowCloneTo(Cluster newParent) { public override INucleus ShallowCloneTo(Cluster newParent) {
Neuron clone = new(newParent, this.name) { Neuron clone = new(newParent, this.name) {
array = null, array = null,
curve = this.curve, curve = this.curve,
@ -192,7 +192,7 @@ public class Neuron : Nucleus, INucleus {
return clone; return clone;
} }
public override IReceptor Clone() { public override INucleus Clone() {
//Neuron clone = new(this.cluster, this.name) { //Neuron clone = new(this.cluster, this.name) {
Neuron clone = new(this.parent, this.name) { Neuron clone = new(this.parent, this.name) {
array = this.array, array = this.array,

View File

@ -32,9 +32,9 @@ public abstract class Nucleus : INucleus {
public int stale = 1000; public int stale = 1000;
// Cannot clone an abstract nucleus... // Cannot clone an abstract nucleus...
public virtual IReceptor ShallowCloneTo(Cluster parent) { return null; } public virtual INucleus ShallowCloneTo(Cluster parent) { return null; }
// Cannot clone an abstract nucleus... // Cannot clone an abstract nucleus...
public virtual IReceptor Clone() { return null; } public virtual INucleus Clone() { return null; }
#region Synapses #region Synapses

View File

@ -5,8 +5,8 @@ using UnityEngine;
[System.Serializable] [System.Serializable]
public class NucleusArray { public class NucleusArray {
[SerializeReference] [SerializeReference]
private IReceptor[] _nuclei; private INucleus[] _nuclei;
public IReceptor[] nuclei { public INucleus[] nuclei {
get { get {
return _nuclei; return _nuclei;
} }
@ -34,7 +34,7 @@ public class NucleusArray {
return; return;
} }
int newLength = this._nuclei.Length + 1; int newLength = this._nuclei.Length + 1;
IReceptor[] newArray = new INucleus[newLength]; INucleus[] newArray = new INucleus[newLength];
for (int i = 0; i < this._nuclei.Length; i++) for (int i = 0; i < this._nuclei.Length; i++)
newArray[i] = this._nuclei[i]; newArray[i] = this._nuclei[i];
@ -50,7 +50,7 @@ public class NucleusArray {
Debug.LogWarning("Perceptoid array cannot be empty"); Debug.LogWarning("Perceptoid array cannot be empty");
return; return;
} }
IReceptor[] newPerceptei = new INucleus[newLength]; INucleus[] newPerceptei = new INucleus[newLength];
for (int i = 0; i < newLength; i++) for (int i = 0; i < newLength; i++)
newPerceptei[i] = this._nuclei[i]; newPerceptei[i] = this._nuclei[i];
// Delete the last perception // Delete the last perception
@ -67,7 +67,7 @@ public class NucleusArray {
CleanupReceivers(); CleanupReceivers();
if (!thingReceivers.TryGetValue(thingId, out INucleus selectedReceiver)) { if (!thingReceivers.TryGetValue(thingId, out INucleus selectedReceiver)) {
Debug.Log($"No receiver found for {thingId}"); Debug.Log($"No receiver found for {thingId}");
foreach (IReceptor receptor in this.nuclei) { foreach (INucleus receptor in this.nuclei) {
if (receptor is not INucleus receiver) if (receptor is not INucleus receiver)
continue; continue;

View File

@ -7,7 +7,7 @@ public class Selector : Neuron {
public Selector(Cluster parent, string name) : base(parent, name) { } public Selector(Cluster parent, string name) : base(parent, name) { }
public Selector(ClusterPrefab parent, string name) : base(parent, name) {} public Selector(ClusterPrefab parent, string name) : base(parent, name) {}
public override IReceptor ShallowCloneTo(Cluster newParent) { public override INucleus ShallowCloneTo(Cluster newParent) {
Selector clone = new(newParent, this.name) { Selector clone = new(newParent, this.name) {
array = this.array, array = this.array,
curve = this.curve, curve = this.curve,