Cluster instances deserialization

This commit is contained in:
Pascal Serrarens 2026-07-10 14:13:08 +02:00
parent 85017861b5
commit 90f8065a39
2 changed files with 30 additions and 4 deletions

View File

@ -186,7 +186,7 @@ namespace NanoBrain.Unity {
protected void ClusterInspector(Cluster cluster, ref bool anythingChanged) { protected void ClusterInspector(Cluster cluster, ref bool anythingChanged) {
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
int instanceCount = cluster.instanceCount; int instanceCount = (int)cluster.instanceCount;
if (instanceCount <= 1) { if (instanceCount <= 1) {
if (cluster.instances != null && cluster.instances.Length > 1) if (cluster.instances != null && cluster.instances.Length > 1)
instanceCount = cluster.instances.Count(); instanceCount = cluster.instances.Count();

View File

@ -63,7 +63,7 @@ namespace NanoBrain {
/// </summary> /// </summary>
/// A cluster is a multi-clsuter when there is more than one instance. /// A cluster is a multi-clsuter when there is more than one instance.
[SerializeField] [SerializeField]
public int instanceCount = 1; public uint instanceCount = 1;
/// <summary> /// <summary>
/// The mapping from things to cluster instances /// The mapping from things to cluster instances
/// </summary> /// </summary>
@ -89,7 +89,7 @@ namespace NanoBrain {
/// </summary> /// </summary>
/// <param name="prefab">The prefab to use</param> /// <param name="prefab">The prefab to use</param>
/// <param name="parent">The cluster in which this new cluster will be placed</param> /// <param name="parent">The cluster in which this new cluster will be placed</param>
public Cluster(ClusterPrefab prefab, Cluster parent) { public Cluster(ClusterPrefab prefab, Cluster parent, uint instanceCount = 1) {
this.prefab = prefab; this.prefab = prefab;
this.version = prefab.version; this.version = prefab.version;
this.name = prefab.name; this.name = prefab.name;
@ -97,6 +97,27 @@ namespace NanoBrain {
this.parent = parent; this.parent = parent;
this.parent?.nuclei.Add(this); this.parent?.nuclei.Add(this);
ClonePrefab(); ClonePrefab();
if (instanceCount > 1) {
Debug.Log($" InstanceCount = {instanceCount}");
List<Cluster> siblings = new() { this };
for (int instanceIx = 1; instanceIx < instanceCount; instanceIx++) {
// Create another sibling
Cluster sibling = new(prefab, this) {
name = $"{this.baseName}: {instanceIx}",
parent = this.parent,
instanceCount = this.instanceCount,
};
siblings.Add(sibling);
CopyAllExternalReceivers(this, sibling, this);
}
Cluster[] siblingClusters = siblings.ToArray();
foreach (Cluster sibling in siblings) {
sibling.instanceCount = instanceCount;
sibling.instances = siblingClusters;
}
}
} }
/// <summary> /// <summary>
@ -158,7 +179,12 @@ namespace NanoBrain {
if (extPrefab == null) if (extPrefab == null)
Debug.LogError($"Could not find cluster Resource {synapseData.clusterName}"); Debug.LogError($"Could not find cluster Resource {synapseData.clusterName}");
else { else {
Cluster extCluster = new Cluster(extPrefab, this); uint instanceCount = 1;
foreach (ExternalClusterData externalCluster in clusterData.clusters) {
if (externalCluster.name == synapseData.clusterName)
instanceCount = externalCluster.instanceCount;
}
Cluster extCluster = new Cluster(extPrefab, this, instanceCount);
Neuron extNeuron = extCluster.GetNeuron(synapseData.neuronName); Neuron extNeuron = extCluster.GetNeuron(synapseData.neuronName);
extNeuron.AddReceiver(receiver); extNeuron.AddReceiver(receiver);
} }