Starting with clusterinstance

This commit is contained in:
Pascal Serrarens 2026-01-21 17:21:06 +01:00
parent b556aa62fc
commit 8b8e5fc33c
3 changed files with 77 additions and 0 deletions

View File

@ -73,6 +73,7 @@
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Vector2Int.cs" />
<Compile Include="Assets/Scenes/Boids/Scripts/SwarmControl.cs" />
<Compile Include="Assets/NanoBrain/INucleus.cs" />
<Compile Include="Assets/NanoBrain/ClusterInstance.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Spherical.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/test/Vector3FloatTest.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/test/QuaternionTest.cs" />

View File

@ -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
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f13cdc4a175a9f379a00317ae68d8bea