miepzerino
2025-04-03 ee1703b69b7977a8cd6d37dd097f425c8c905882
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
41
42
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;
    }
}