From 5dcd4665ba3c5c12d67cb8df3463e0782772a4db Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Thu, 03 Apr 2025 22:37:09 +0000 Subject: [PATCH] #42 fixed ore generation height --- Assets/Scripts/Jobs/GenerateGroundJob.cs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) diff --git a/Assets/Scripts/Jobs/GenerateGroundJob.cs b/Assets/Scripts/Jobs/GenerateGroundJob.cs new file mode 100644 index 0000000..ce435a5 --- /dev/null +++ b/Assets/Scripts/Jobs/GenerateGroundJob.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.Burst; +using Unity.Collections; +using Unity.Jobs; +using Unity.Mathematics; +using UnityEngine; + + +// Add these struct definitions at the top of the file, outside the class +[BurstCompile] +public struct GenerateGroundJob : IJobParallelFor +{ + public int chunkStartX; + public int chunkStartY; + public int chunkSize; + public int maxWidth; + public int groundDepth; + public float scale; + public float offsetX; + public float offsetY; + + [WriteOnly] + public NativeArray<bool> groundTiles; + + public void Execute(int index) + { + int x = chunkStartX + (index % chunkSize); + int y = chunkStartY - (index / chunkSize); + + if (x < 1 || x >= maxWidth || y < -groundDepth || y >= 0) + { + groundTiles[index] = false; + return; + } + + float xPerlin = ((float)x / maxWidth) * scale + offsetX; + float yPerlin = ((float)math.abs(y) / groundDepth) * scale + offsetY; + float perlinNoise = noise.cnoise(new float2(xPerlin, yPerlin)); + + groundTiles[index] = perlinNoise <= 0.7f; + } +} -- Gitblit v1.9.3