97 lines
3.2 KiB
C#
97 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Unity.Mathematics;
|
|
using static Unity.Mathematics.math;
|
|
|
|
[Serializable]
|
|
public class ClusterReceptor : Cluster, IReceptor {
|
|
public ClusterReceptor(ClusterPrefab prefab, Cluster parent, string name) : base(prefab, parent) {
|
|
this.name = name;
|
|
this.array ??= new NucleusArray(this);
|
|
}
|
|
public ClusterReceptor(ClusterPrefab prefabToInstantiate, ClusterPrefab parent, string name) : base(prefabToInstantiate, parent) {
|
|
this.name = name;
|
|
this.array = new NucleusArray(this);
|
|
}
|
|
|
|
public override Nucleus ShallowCloneTo(Cluster parent) {
|
|
ClusterReceptor clone = new(this.prefab, parent, this.name) {
|
|
clusterPrefab = this.clusterPrefab,
|
|
array = this.array
|
|
};
|
|
return clone;
|
|
}
|
|
|
|
public override Nucleus Clone(ClusterPrefab parent) {
|
|
ClusterReceptor clone = new(prefab, parent, this.name) {
|
|
array = this.array
|
|
};
|
|
|
|
foreach (Synapse synapse in this.synapses) {
|
|
Synapse clonedSynapse = clone.AddSynapse(synapse.nucleus);
|
|
clonedSynapse.weight = synapse.weight;
|
|
}
|
|
// foreach (Nucleus receiver in this.receivers) {
|
|
// clone.AddReceiver(receiver);
|
|
// }
|
|
return clone;
|
|
}
|
|
|
|
[SerializeReference]
|
|
private NucleusArray _array;
|
|
public NucleusArray array {
|
|
get { return _array; }
|
|
set { _array = value; }
|
|
}
|
|
|
|
#region Receivers
|
|
|
|
private List<Nucleus> _clusterReceivers = null;
|
|
// public override List<Nucleus> receivers {
|
|
// get {
|
|
// if (_clusterReceivers == null || _clusterReceivers.Count == 0) {
|
|
// _clusterReceivers = new();
|
|
// foreach (Nucleus output in this.clusterNuclei) {
|
|
// _clusterReceivers.AddRange(output.receivers);
|
|
// }
|
|
// }
|
|
// return _clusterReceivers;
|
|
// }
|
|
// }
|
|
// public override void AddReceiver(Nucleus receivingNucleus, float weight = 1) {
|
|
// string nucleusName = this.
|
|
// this.output.receivers.Add(receivingNucleus);
|
|
// receivingNucleus.AddSynapse(this.output, weight);
|
|
// }
|
|
|
|
#endregion Receivers
|
|
|
|
public override void UpdateStateIsolated() {
|
|
float3 sum = this.bias;
|
|
|
|
foreach (Nucleus nucleus in this.sortedNuclei)
|
|
nucleus.UpdateStateIsolated();
|
|
|
|
this.outputValue = this.defaultOutput.outputValue;
|
|
this.stale = 0;
|
|
|
|
UpdateNuclei();
|
|
}
|
|
|
|
public override void UpdateNuclei() {
|
|
this.stale++;
|
|
if (this.stale > staleValueForSleep && lengthsq(this.bias) > 0) {
|
|
this.bias = new float3(0, 0, 0);
|
|
this.parent.UpdateFromNucleus(this);
|
|
}
|
|
|
|
foreach (Nucleus nucleus in this.clusterNuclei)
|
|
nucleus.UpdateNuclei();
|
|
}
|
|
|
|
public virtual void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) {
|
|
this.array ??= new NucleusArray(this.parent);
|
|
this.array.ProcessStimulus(thingId, inputValue, thingName);
|
|
}
|
|
} |