Base for reworked sulph sea worldgen
This commit is contained in:
1 parent
c8f17eba61
commit
ce75de9a84
3 files changed
+497
-822
No files matched your search
@@ -27,7 +27,6 @@ namespace CalamityMod
|
||||
/// <param name="y">The Y position on the map.</param>
|
||||
/// <param name="octaves">A metric of "instability" of the noise. The higher this is, the more unstable. Lower of bounds of 2-3 are preferable.</param>
|
||||
/// <param name="seed">The seed for the noise.</param>
|
||||
/// <returns></returns>
|
||||
public static float PerlinNoise2D(float x, float y, int octaves, int seed)
|
||||
{
|
||||
float SmoothFunction(float n) => 3f * n * n - 2f * n * n * n;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
|
||||
@@ -31,5 +32,58 @@ namespace CalamityMod
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates caves via celluar automata in terms of active/inactive states. May also be used to smoothen out areas.
|
||||
/// </summary>
|
||||
/// <param name="area">The area to perform the algorithm on.</param>
|
||||
/// <param name="gameIterations">The number of times to iterate. The higher this value is, the more smooth the result is.</param>
|
||||
public static void GenerateCellularAutomataCave(Rectangle area, int gameIterations)
|
||||
{
|
||||
bool[,] cellStates = new bool[area.Width, area.Height];
|
||||
int width = cellStates.GetLength(0);
|
||||
int height = cellStates.GetLength(1);
|
||||
|
||||
// Initialize the cell states.
|
||||
for (int i = area.Left; i < area.Right; i++)
|
||||
{
|
||||
for (int j = area.Top; j < area.Bottom; j++)
|
||||
cellStates[i - area.Left, j - area.Top] = ParanoidTileRetrieval(i, j).HasTile;
|
||||
}
|
||||
|
||||
for (int i = 0; i < gameIterations; i++)
|
||||
{
|
||||
bool[,] newState = cellStates.Clone() as bool[,];
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
int nearbyActiveCells = 0;
|
||||
for (int dx = -1; dx <= 1; dx++)
|
||||
{
|
||||
for (int dy = -1; dy <= 1; dy++)
|
||||
{
|
||||
if (x + dx < 0 || x + dx >= width || y + dy < 0 || y + dy >= height)
|
||||
{
|
||||
nearbyActiveCells++;
|
||||
continue;
|
||||
}
|
||||
|
||||
nearbyActiveCells += cellStates[x + dx, y + dy].ToInt();
|
||||
}
|
||||
}
|
||||
|
||||
newState[x, y] = nearbyActiveCells >= 5;
|
||||
}
|
||||
}
|
||||
cellStates = newState;
|
||||
}
|
||||
|
||||
for (int i = area.Left; i < area.Right; i++)
|
||||
{
|
||||
for (int j = area.Top; j < area.Bottom; j++)
|
||||
Main.tile[i, j].Get<TileWallWireStateData>().HasTile = cellStates[i - area.Left, j - area.Top];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+443
-821
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user