public void ExecuteActionDist(World world, ActionDist distro) { if (!distro.IsDegenerated()) { this.splitLock.SignalStart(); StartCoroutine(this.SplitWorld(world, distro)); } else { // TODO this should probably look for the action which has weight 1! world.EnqueueAction(distro.GetAction(0)); world.ExecuteNextAction(); } }
public IEnumerator SplitWorld(World world, ActionDist distro) { QuadTree.Node worldNode = (QuadTree.Node) this.worldTree.nodesByWorldId[world.id]; Vector3[] newOrigins = this.OriginsAfterSplit(world); float newScale = WorldManager.ScaleAfterSplit(world); List <int> hues = new List <int>(); while (hues.Count < 4) { int hue = UnityEngine.Random.Range(0, 360); if (hues.All(x => Math.Abs(x - hue) > 10)) { hues.Add(hue); } } World[] newWorlds = new World[4]; for (int i = 0; i < 4; i++) { newWorlds[i] = this.CopyWorld(world, newOrigins[i], newScale, world.integrity * distro.GetWeight(i), hues[i]); newWorlds[i].EnqueueAction(distro.GetAction(i)); } // Add new worlds to the tree this.worldTree.SplitNode(worldNode, newWorlds); this.DestroyWorld(world); while (this.AnyWorldLocked()) { yield return(new WaitForEndOfFrame()); } for (int i = 0; i < 4; i++) { newWorlds[i].ExecuteNextAction(); while (newWorlds[i].Locked()) { yield return(null); } } this.splitLock.SignalStop(); yield break; }