Exemple #1
0
            [NonSerialized] public CoroutineManager.Task switchLodCoroutine;             //should be cancelled somehow, but shouldn't be added to coroutines list (otherwise IsGenerating return true)

            public DetailLevel(TerrainTile tile, bool isDraft)
            {
                data = new TileData(); terrain = tile.CreateTerrain(isDraft);
            }
        private void Generate(Graph graph, TerrainTile tile, DetailLevel det, StopToken stop)
        /// Note that referencing det.task is illegal since task could be changed
        {
            OnBeforeTileGenerate?.Invoke(tile, det.data, stop);

            //do not return (for draft) until the end (apply)
//				if (!stop.stop) graph.CheckClear(det.data, stop);
            if (!stop.stop)
            {
                graph.Generate(det.data, stop);
            }
            if (!stop.stop)
            {
                graph.Finalize(det.data, stop);
            }

            //finalize event
            OnTileFinalized?.Invoke(tile, det.data, stop);

            //flushing products for playmode (all except apply)
            if (MapMagicObject.isPlaying)
            {
                det.data.Clear(clearApply: false);
            }

            //welding (before apply since apply will flush 2d array)
            if (!stop.stop)
            {
                Weld.ReadEdges(det.data, det.edges);
            }
            if (!stop.stop)
            {
                Weld.WeldEdgesInThread(det.edges, tile.mapMagic.tiles, tile.coord, det.data.isDraft);
            }
            if (!stop.stop)
            {
                Weld.WriteEdges(det.data, det.edges);
            }

            //enqueue apply
            if (!MapMagicObject.isPlaying || det.data.isDraft)                     //editor is applied right after the generating is done (drafts apply now in any case)
            //tile.StartApply(tile, det, stop); //could be called in thread
            {
                if (det.data.isDraft)
                {
                    det.coroutine = CoroutineManager.Enqueue(() => ApplyNow(det, stop), Priority + 1000, "ApplyNow " + coord);
                }

                else
                {
                    IEnumerator coroutine = ApplyRoutine(det, stop);
                    det.coroutine = CoroutineManager.Enqueue(coroutine, Priority, "ApplyRoutine " + coord);
                }
            }

            else                     //while the playmode is applied on SwitchLod to avoid unnecessary lags
            {
                det.switchLodCoroutine = CoroutineManager.Enqueue(SwitchLod, Priority - 1, "LodSwitch " + coord);
            }

            det.generateReady = true;
        }