miepzerino
2025-04-06 89ffa9ea09da478852ebe24f2ae2348c6b145edd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
    [ReadOnly] public NativeArray<float> perlinNoiseCache;
 
    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;
        }
        
        groundTiles[index] = perlinNoiseCache[x * groundDepth + Mathf.Abs(y)] <= 0.7f;
    }
}