Пример #1
0
        public void Execute(int i)
        {
            Utils.IndexDeflattenizer2D(i, TotalBlockNumberX, out int x, out int z);

            ReadonlyVector3Int heights = TerrainGenerator.CalculateHeights(Seed, x, z);

            int max = heights.X; // max could be passed to the loop below but it requires air to be default type

            if (heights.Y > max)
            {
                max = heights.Y;
            }
            if (heights.Z > max)
            {
                max = heights.Z;
            }

            var blockTypes = new BlockTypeColumn(max);

            unsafe
            {
                // heights are inclusive
                for (int y = 0; y <= max; y++)
                {
                    blockTypes.Types[y] = (byte)TerrainGenerator.DetermineType(Seed, x, y, z, in heights);
                }
            }

            Result[i] = blockTypes;
        }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <CoordinatesComponent> coordinatesArray = chunk.GetNativeArray(Coordinates);
            NativeArray <BlockTypesComponent>  blockTypesArray  = chunk.GetNativeArray(BlockTypes);
            SeedComponent seed = chunk.GetChunkComponentData(Seed);

            for (int i = 0; i < chunk.Count; i++)
            {
                int3 coordinates           = coordinatesArray[i].Coordinates;
                ReadonlyVector3Int heights = TerrainGenerator.CalculateHeights_NoiseSampler(seed.Seed, coordinates.x, coordinates.z);

                blockTypesArray[i] = new BlockTypesComponent()
                {
                    BlockType = TerrainGenerator.DetermineType_NoiseSampler(seed.Seed, coordinates.x, coordinates.y, coordinates.z, in heights)
                };
            }
        }
    }
Пример #3
0
        /// <summary>
        /// Calculates global heights. This method uses Unity Job System.
        /// Each column described by its x and z values has three heights.
        /// One for Bedrock, Stone and Dirt. Heights determines up to where certain types appear.
        /// x is Bedrock, y is Stone and z is Dirt.
        /// </summary>
        internal static ReadonlyVector3Int[] CalculateHeightsJobSystem()
        {
            // output data
            var heights = new ReadonlyVector3Int[TotalBlockNumberX * TotalBlockNumberZ];

            var heightJob = new HeightJob()
            {
                // input
                TotalBlockNumberX = TotalBlockNumberX,

                // output
                Result = new NativeArray <ReadonlyVector3Int>(heights, Allocator.TempJob)
            };

            var heightJobHandle = heightJob.Schedule(TotalBlockNumberX * TotalBlockNumberZ, 8);

            heightJobHandle.Complete();
            heightJob.Result.CopyTo(heights);

            // cleanup
            heightJob.Result.Dispose();

            return(heights);
        }
 public ChunkData(ReadonlyVector3Int coord, ReadonlyVector3Int position)
 {
     Coord    = coord;
     Position = position;
     Status   = ChunkStatus.NotReady;
 }
 public ChunkData(ReadonlyVector3Int coord, ReadonlyVector3Int position, ChunkStatus status)
 {
     Coord    = coord;
     Position = position;
     Status   = status;
 }
Пример #6
0
 static void Write(ReadonlyVector3Int value)
 {
     _writer.Write(value.X);
     _writer.Write(value.Y);
     _writer.Write(value.Z);
 }