WIP: all array elements share the same receptor (value)

This commit is contained in:
Pascal Serrarens 2026-02-05 12:52:13 +01:00
parent 16f0c3d3bf
commit b73b28146c
3 changed files with 10 additions and 101 deletions

View File

@ -76,65 +76,19 @@ public class Cluster : INucleus {
// Find the synapse for the weight
float weight = 1;
//NucleusArray clonedNucleusArray = null;
foreach (Synapse synapse in receiver.synapses) {
// Find the weight for this synapse
if (synapse.nucleus == receptor)
if (synapse.nucleus == receptor) {
weight = synapse.weight;
// if (synapse.nucleus is INucleus synapseNucleus) {
// if (synapseNucleus.array != null && synapseNucleus.array.nuclei.Length > 0) {
// Debug.Log("Clone: Nucleus array");
// if (clonedNucleusArray == null) {
// // copy the array
// clonedNucleusArray = new NucleusArray(synapseNucleus.array.nuclei.Length, "array");
// for (int arrayIx = 0; arrayIx < synapseNucleus.array.nuclei.Length; arrayIx++) {
// IReceptor arrayNucleus = synapseNucleus.array.nuclei[arrayIx];
// int ix2 = GetNucleusIndex(nuclei, arrayNucleus);
// clonedNucleusArray.nuclei[arrayIx] = clonedNuclei[ix2];
// }
// }
// synapseNucleus.array = clonedNucleusArray;
// }
// }
break;
}
}
clonedReceptor.AddReceiver(clonedReceiver, weight);
// Nucleus clonedNucleus = clonedReceptor as Nucleus;
// if (clonedNucleus is not null) {
// Synapse clonedSynapse = clonedNucleus.GetSynapse(clonedReceiver);
// if (clonedSynapse.nucleus is INucleus synapseNucleus) {
// if (synapseNucleus.array != null && synapseNucleus.array.nuclei.Length > 0) {
// Debug.Log("Clone: Nucleus array");
// if (clonedNucleusArray == null) {
// // copy the array
// clonedNucleusArray = new NucleusArray(synapseNucleus.array.nuclei.Length, "array");
// for (int arrayIx = 0; arrayIx < synapseNucleus.array.nuclei.Length; arrayIx++) {
// IReceptor arrayNucleus = synapseNucleus.array.nuclei[arrayIx];
// int ix2 = GetNucleusIndex(nuclei, arrayNucleus);
// clonedNucleusArray.nuclei[arrayIx] = clonedNuclei[ix2];
// }
// }
// synapseNucleus.array = clonedNucleusArray;
// }
// }
// }
}
// if (receptor is INucleus nucleus) {
// if (clonedSender is not INucleus clonedNucleus) {
// Debug.LogError("INucleus clone is not an INucleus!");
// continue;
// }
// clonedNucleus.array = new NucleusArray(nucleus.array._nuclei.Length, "array");
// for (int arrayIx = 0; arrayIx < nucleus.array._nuclei.Length; arrayIx++) {
// //foreach (INucleus arrayNucleus in nucleus.array.nuclei) {
// IReceptor arrayNucleus = nucleus.array._nuclei[arrayIx];
// int ix = GetNucleusIndex(nuclei, arrayNucleus);
// clonedNucleus.array._nuclei[arrayIx] = clonedNuclei[ix];
// }
// }
}
// Copy nucleus arrays
for (int nucleusIx = 0; nucleusIx < nuclei.Length; nucleusIx++) {
IReceptor prefabReceptor = nuclei[nucleusIx];
if (prefabReceptor is not INucleus prefabNucleus)

View File

@ -432,12 +432,12 @@ public class ClusterInspector : Editor {
tooltip = new(
$"{nucleus.name}" +
$"\nsynapse count {n.synapses.Count}" +
$"\nValue: {nucleus.outputValue}");
$"\nValue: {length(nucleus.outputValue)}");
}
else {
tooltip = new(
$"{nucleus.name}" +
$"\nValue: {nucleus.outputValue}");
$"\nValue: {length(nucleus.outputValue)}");
}
Vector2 mousePosition = Event.current.mousePosition;

View File

@ -25,12 +25,6 @@ public class Receptor : IReceptor {
cluster.nuclei.Add(this);
}
// public Receptor(ClusterPrefab cluster, INucleus nucleus) {
// this.cluster = cluster;
// if (cluster != null)
// cluster.nuclei.Add(this);
// this.AddReceiver(nucleus);
// }
public Receptor(Cluster parent, string name, string nucleusName) {
this.parent = parent ?? throw new ArgumentNullException(nameof(parent), "Parent cannot be null.");
@ -43,24 +37,6 @@ public class Receptor : IReceptor {
}
}
[Obsolete("This method is deprecated. Use Receptor() constructor instead.")]
public static Receptor CreateReceptor(Cluster cluster, string nucleusName) {
return new Receptor(cluster, "Receptor", nucleusName);
// if (cluster == null)
// return null;
// Receptor receptor = new(cluster);
// foreach (INucleus nucleus in cluster.inputs) {
// if (nucleus != null && nucleus.name == nucleusName) {
// receptor.AddReceiver(nucleus);
// }
// }
// if (receptor._receivers.Count == 0)
// return null;
// else
// return receptor;
}
private ClusterPrefab cluster;
private Cluster parent;
@ -68,20 +44,7 @@ public class Receptor : IReceptor {
Receptor clone = new(parent);
return clone;
}
// public virtual IReceptor ShallowCloneTo(ClusterPrefab parent) {
// Receptor clone = new(parent);
// return clone;
// }
// public virtual IReceptor CloneTo(ClusterPrefab parent) {
// Receptor clone = new(parent);
// foreach (INucleus receiver in this.receivers) {
// clone.AddReceiver(receiver);
// }
// return clone;
// }
public virtual IReceptor Clone() {
Receptor clone = new(this.cluster);
@ -127,16 +90,8 @@ public class Receptor : IReceptor {
private bool _isSleeping = false;
public bool isSleeping => _isSleeping;
public Vector3 localPosition {
set {
this.stale = 0;
this._isSleeping = false;
this._outputValue = value;
}
}
public float distanceResolution = 0.1f;
public float directionResolution = 5;
// public float distanceResolution = 0.1f;
// public float directionResolution = 5;
private float3 _outputValue;
public float3 outputValue {
@ -149,7 +104,7 @@ public class Receptor : IReceptor {
}
public virtual void ProcessStimulus(int thingId, Vector3 newLocalPositionVector, string thingName = null) {
this.localPosition = newLocalPositionVector;
this.outputValue = newLocalPositionVector;
if (this._receivers == null)
return;