forked from Syomus/ProceduralToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CellularAutomaton: Separated cells into a structure
- Loading branch information
1 parent
da27b2e
commit 9e2af0c
Showing
4 changed files
with
74 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using Unity.Collections; | ||
using Random = UnityEngine.Random; | ||
|
||
namespace ProceduralToolkit.CellularAutomata | ||
{ | ||
public struct Cells : IDisposable | ||
{ | ||
public NativeArray2D<bool> cells; | ||
public NativeArray2D<bool> copy; | ||
|
||
public Cells(CellularAutomaton.Config config) | ||
{ | ||
cells = new NativeArray2D<bool>(config.width, config.height, Allocator.Persistent); | ||
copy = new NativeArray2D<bool>(config.width, config.height, Allocator.Persistent); | ||
|
||
FillWithNoise(config.startNoise); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (cells.IsCreated) | ||
{ | ||
cells.Dispose(); | ||
} | ||
if (copy.IsCreated) | ||
{ | ||
copy.Dispose(); | ||
} | ||
} | ||
|
||
public void FillWithNoise(float noise) | ||
{ | ||
for (int y = 0; y < cells.LengthY; y++) | ||
{ | ||
for (int x = 0; x < cells.LengthX; x++) | ||
{ | ||
cells[x, y] = copy[x, y] = Random.value < noise; | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters