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;
    }
}