From 8b8e5fc33c1256d1ddf131342fa4ed90e4c4b6cb Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 21 Jan 2026 17:21:06 +0100 Subject: [PATCH] Starting with clusterinstance --- Assembly-CSharp.csproj | 1 + Assets/NanoBrain/ClusterInstance.cs | 74 ++++++++++++++++++++++++ Assets/NanoBrain/ClusterInstance.cs.meta | 2 + 3 files changed, 77 insertions(+) create mode 100644 Assets/NanoBrain/ClusterInstance.cs create mode 100644 Assets/NanoBrain/ClusterInstance.cs.meta diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index 4ac4a55..1f5f66b 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -73,6 +73,7 @@ + diff --git a/Assets/NanoBrain/ClusterInstance.cs b/Assets/NanoBrain/ClusterInstance.cs new file mode 100644 index 0000000..dd9c4c4 --- /dev/null +++ b/Assets/NanoBrain/ClusterInstance.cs @@ -0,0 +1,74 @@ +public class ClusterInstance { + // The ScriptableObject asset from which the runtime object has been created + public readonly Cluster asset; + + public ClusterInstance parent; + + public ClusterInstance(Cluster asset) { + this.asset = asset; + } + + public NucleusArray array; + + #region Synapses + + private Synapse[] _synapses = new Synapse[0]; + public Synapse[] synapses => _synapses; + + public void AddSynapse(IReceptor sendingNucleus) { + + } + + // Does this even exist already? + public void RemoveSynapse() { + + } + + #endregion Synapses + + #region Receivers + + private INucleus[] _nucleiReceivers = new INucleus[0]; + public INucleus[] nucleiReceivers => _nucleiReceivers; + + public void AddReceiver(INucleus receivingNucleus) { + int newLength = this._nucleiReceivers.Length + 1; + INucleus[] newReceivers = new INucleus[newLength]; + + // Copy the existing receivers + for (int ix = 0; ix < this._nucleiReceivers.Length; ix++) + newReceivers[ix] = this._nucleiReceivers[ix]; + // Add the new receivers + newReceivers[this._nucleiReceivers.Length] = receivingNucleus; + // Replace the receivers with the new receivers + this._nucleiReceivers = newReceivers; + } + + public void RemoveReceiver(INucleus receivingNucleus) { + int newLength = this._nucleiReceivers.Length - 1; + if (newLength < 0) + // Array was empty, so we cannot remove anything + return; + + INucleus[] newReceivers = new INucleus[newLength]; + + int newIx = 0; + // Copy all receivers except receivingNucleus + for (int ix = 0; ix < this._nucleiReceivers.Length; ix++) { + if (this._nucleiReceivers[ix] == receivingNucleus) + // skip the receiver we want to remote + continue; + + if (newIx >= newLength) + // We want to copy more elements than expected + // the receivingNucleus is not found + // and the original array is returned + return; + newReceivers[newIx] = this._nucleiReceivers[ix]; + newIx++; + } + this._nucleiReceivers = newReceivers; + } + + #endregion Receivers +} diff --git a/Assets/NanoBrain/ClusterInstance.cs.meta b/Assets/NanoBrain/ClusterInstance.cs.meta new file mode 100644 index 0000000..a10caff --- /dev/null +++ b/Assets/NanoBrain/ClusterInstance.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f13cdc4a175a9f379a00317ae68d8bea \ No newline at end of file