Initial Commit

This commit is contained in:
Simeon Radivoev 2022-02-12 12:53:50 +02:00
commit ee5c2f922d
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
2255 changed files with 547750 additions and 0 deletions

View file

@ -0,0 +1,48 @@
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;
namespace DefaultNamespace.World
{
public struct CaveGenerator : IJobParallelFor
{
[ReadOnly] public NativeArray<int> readOnlyMap;
public NativeArray<int> map;
public Vector2Int size;
public void Execute(int i)
{
var wallTiles = GetSurroundingWallCount(i % size.x, Mathf.FloorToInt(i / (float)size.x));
if (wallTiles > 4)
{
map[i] = 1;
}
else if (wallTiles < 4)
{
map[i] = 0;
}
}
private int GetSurroundingWallCount(int gX, int gY)
{
var wallCount = 0;
for (var x = gX - 1; x <= gX + 1; x++)
for (var y = gY - 1; y <= gY + 1; y++)
{
if (x >= 0 && x < size.x && y >= 0 && y < size.y)
{
if (x != gX || y != gY)
{
wallCount += readOnlyMap[y * size.x + x];
}
}
else
{
wallCount++;
}
}
return wallCount;
}
}
}