/// The Generation Funtion IEnumerator GenStep() { var queue = new SortedSet <GenElement>(); int hcount = 0; // ==================================================================== // Highway generation phase. // ==================================================================== // Initialization. // Simply create a highway segment. queue.Add(new GenHighway(cfg.beginSegment, cfg.beginPopulation, 0, 0)); // Add a reversed begin segment. queue.Add(new GenHighway( new Segment(cfg.beginSegment.from, cfg.beginSegment.from - cfg.beginSegment.dir) , cfg.beginPopulation, 0, 0)); for (int t = 0; hcount < cfg.count && queue.Count != 0; t++) { info.currentHighwayCount = hcount + 1; var cur = queue.First(); queue.Remove(cur); var x = cur.segment; var prevX = x; x = GenUtil.IntersectionCut(segs, x); x = GenUtil.CloseEndpointCut(segs, x, cfg.endpointCutDist); x = GenUtil.CloseEndpointMerge(segs, x, cfg.endpointMergeDist); if (GenUtil.HasSimilarSegment(segs, x, cfg.segmentCloseDist)) { continue; } if (x.dir.magnitude <= cfg.removeLength) { continue; } if (x != prevX) { cur.intercepted = true; } segs.Add(x); colors.Add(cur.color, cur.color); // Two points per segment, so there're two colors. hcount += 1; cur.segment = x; cur.Gen(queue); GenUtil.SubmitToMesh(mesh, segs, colors); yield return(null); // Next frame. } yield break; // Terminate. }