miepzerino
2025-04-03 d9d5b7b5c58a7b044b78ee7993f0a15e5b79f689
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
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
 
public struct OreGnerationJob : IJobParallelFor
{
    [ReadOnly] public int ChunkStartX;
    [ReadOnly] public int ChunkStartY;
    [ReadOnly] public int ChunkSize;
    [ReadOnly] public int Weight;
    [ReadOnly] public int ClusterWeight;
    [ReadOnly] public float OffsetX;
    [ReadOnly] public float OffsetY;
    [ReadOnly] public int MaxWidth;
    [ReadOnly] public int MaxDepth;
 
    public NativeArray<bool> OreMap;
 
    public void Execute(int index)
    {
        int x = ChunkStartX + (index % ChunkSize);
        int y = ChunkStartY - (index / ChunkSize);
 
        float xPerlin = ((float)x / MaxWidth) * ClusterWeight + OffsetX;
        float yPerlin = ((float)Mathf.Abs(y) / MaxDepth) * ClusterWeight + OffsetY;
        float perlinNoise = noise.snoise(new float2(xPerlin, yPerlin));
 
        OreMap[index] = perlinNoise <= (1f / (float)Weight);
    }
}