Example #1
0
    private JobHandle GenerateNewChunk(chunkCenter c, int size, List <NativeArray <float> > noiseLists, NoiseParameters nosP)
    {
        NativeArray <float> NoiseValues = new NativeArray <float>(size * size, Allocator.TempJob);
        GenerateMapJob      job         = new GenerateMapJob
                                          (
            c.boundsCenterX,
            c.boundsCenterY,
            size,
            nosP,
            NoiseValues
                                          );

        noiseLists.Add(NoiseValues);
        Debug.Log("Generating new chunk noise values at " + c.boundsCenterX.ToString() + ", " + c.boundsCenterY.ToString());
        return(job.Schedule());
    }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (mapData.IsValid)
            {
                return(inputDeps);
            }

            var maps = query.ToComponentDataArray <Map>(Allocator.TempJob);

            if (maps.Length == 0)
            {
                maps.Dispose();
                return(inputDeps);
            }

            var map = maps[0];

            maps.Dispose();
            mapData = new MapData(map.width, map.height);

            var updateMap = new GenerateMapJob
            {
                mapTiles = mapData.tiles,
                width    = mapData.width
            };

            inputDeps = updateMap.Schedule(this, inputDeps);
            var directions = new GenerateDirectionsJob
            {
                map = mapData
            };

            inputDeps = directions.Schedule(this, inputDeps);

            _barier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }