Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rlbits-mapping/Assets/rlbits/mapping/ChannelMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class ChannelMap : MonoBehaviour
{
public string m_ChannelID;

protected float[] m_channel;
protected int[] m_channel;

public abstract void ProcessChannel(RuntimePCG pcg);
}
Expand Down
8 changes: 4 additions & 4 deletions rlbits-mapping/Assets/rlbits/mapping/NormalizedChannelMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class NormalizedChannelMap : ChannelMap
public override void ProcessChannel(RuntimePCG pcg)
{
m_channel = pcg.GetChannel(m_ChannelID);
BoundsInt bounds = new BoundsInt(0, 0, 0, pcg.m_Size.x, pcg.m_Size.y, 1);
BoundsInt bounds = new BoundsInt(0, 0, 0, pcg.GraphSize.x, pcg.GraphSize.y, 1);

TileBase[] tileArray = m_TargetMap.GetTilesBlock(bounds);
for (int y = 0; y < pcg.m_Size.y; y++)
for (int y = 0; y < pcg.GraphSize.y; y++)
{
for (int x = 0; x < pcg.m_Size.x; x++)
for (int x = 0; x < pcg.GraphSize.x; x++)
{
tileArray[x + (y * pcg.m_Size.x)] = GetTileForValue(m_channel[x + (y * pcg.m_Size.x)]);
tileArray[x + (y * pcg.GraphSize.x)] = GetTileForValue(m_channel[x + (y * pcg.GraphSize.x)]);
}
}
m_TargetMap.SetTilesBlock(bounds, tileArray);
Expand Down
28 changes: 14 additions & 14 deletions rlbits-mapping/Assets/rlbits/mapping/RuntimePCG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ namespace RLBits.Mapping
public class RuntimePCG : MonoBehaviour
{
[Header("Project References")]
public PCGNodeGraph m_Graph;
public PCGNodeGraph Graph;
[Header("Data")]
public Vector2Int m_Size = new Vector2Int(128, 128);
public int m_Seed = 100;
public ChannelMap[] m_ChannelMaps;
public bool m_Loop;
public Vector2Int GraphSize = new Vector2Int(128, 128);
public int Seed = 100;
public ChannelMap[] ChannelMaps;
public bool Loop;

private Dictionary<string, float[]> m_channels;
private Dictionary<string, int[]> channels;

void Start()
{
GenWorld();
if (m_Loop)
if (Loop)
StartCoroutine(LoopGenerations());
}

private void GenWorld()
{
m_channels = m_Graph.GetChannels(m_Seed, m_Size);
foreach (ChannelMap nc in m_ChannelMaps)
channels = Graph.GetChannels(Seed, GraphSize);
foreach (ChannelMap nc in ChannelMaps)
{
nc.ProcessChannel(this);
}
}

private IEnumerator LoopGenerations()
{
while (m_Loop)
while (Loop)
{
yield return new WaitForSeconds(0.0f);
m_Seed++;
Seed++;
GenWorld();
}
}
Expand All @@ -52,12 +52,12 @@ private IEnumerator LoopGenerations()
/// </summary>
/// <param name="name">name of the channel to retrieve (should match Ouput node)</param>
/// <returns>a channel as a single-dimension float array</returns>
public float[] GetChannel(string name)
public int[] GetChannel(string name)
{
//TODO KPD string lookups not great
if (m_channels.ContainsKey(name))
if (channels.ContainsKey(name))
{
return m_channels[name];
return channels[name];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace RLBits.Mapping.Graphs
[NodeTint(0.35f, 0.05f, 0.6f)]
public class CellularAutomata : PCGNode
{
[Input] public float[] m_input;
[Input] public int[] m_input;
[Input] public int IterationCount = 0;
[Tooltip("The value a value must be above to be considered `on`")]
[Input] public float ThresholdValue = 0.9f;
[Input] public int ThresholdValue = 200;
[Input] public bool UseWrap = false;
[Output] public float[] m_actualResult;
[Output] public int[] m_actualResult;

[Space]

Expand All @@ -40,23 +40,18 @@ public class CellularAutomata : PCGNode
//isntead of a list of rules w/ distances. There may be value in a simple/complex toggle.
//should see how easy custom node editor is.


[Output] public float[,] m_result;

[Output] public int[,] m_result;

protected int m_NoiseParentSizeX, m_NoiseParentSizeY;




// Return the correct value of an output port when requested
public override object GetValue(NodePort port)
{
if (port.fieldName == "m_actualResult")
{
if (m_actualResult != null)
{
if (m_actualResult.Length != noiseGraph.TotalCells)
if (m_actualResult.Length != NoiseGraph.TotalCells)
{
UpdateData();
}
Expand All @@ -68,10 +63,10 @@ public override object GetValue(NodePort port)

public override void UpdateData(bool withOutputs = true)
{
m_NoiseParentSizeX = noiseGraph.Size.x;
m_NoiseParentSizeY = noiseGraph.Size.y;
m_NoiseParentSizeX = NoiseGraph.Size.x;
m_NoiseParentSizeY = NoiseGraph.Size.y;

m_input = GetPort("m_input").GetInputValue<float[]>();
m_input = GetPort("m_input").GetInputValue<int[]>();

if (m_input == null)
{
Expand All @@ -82,7 +77,7 @@ public override void UpdateData(bool withOutputs = true)
return;
}

m_result = new float[m_NoiseParentSizeX, m_NoiseParentSizeY];
m_result = new int[m_NoiseParentSizeX, m_NoiseParentSizeY];

for (int y = 0; y < m_NoiseParentSizeY; y++)
{
Expand All @@ -95,10 +90,10 @@ public override void UpdateData(bool withOutputs = true)

//m_input.CopyTo(m_result, 0);

Random.InitState(noiseGraph.Seed);
Random.InitState(NoiseGraph.Seed);
BeginAutomata();

m_actualResult = new float[m_NoiseParentSizeX * m_NoiseParentSizeY];
m_actualResult = new int[m_NoiseParentSizeX * m_NoiseParentSizeY];
for (int y = 0; y < m_NoiseParentSizeY; y++)
{
for (int x = 0; x < m_NoiseParentSizeX; x++)
Expand Down Expand Up @@ -154,13 +149,13 @@ public bool PerformPass()
if (state && neighbourCount < NearLessThanCount)
{
changeHappened = true;
m_result[x, y] = 0.0f;
m_result[x, y] = 0;
continue;
}
if (!state && neighbourCount > NearGreaterThanCount)
{
changeHappened = true;
m_result[x, y] = 1.0f;
m_result[x, y] = 255;
continue;
}
}
Expand All @@ -171,13 +166,13 @@ public bool PerformPass()
if (state && neighbourCount < MidLessThanCount)
{
changeHappened = true;
m_result[x, y] = 0.0f;
m_result[x, y] = 0;
continue;
}
if (!state && neighbourCount > MidGreaterThanCount)
{
changeHappened = true;
m_result[x, y] = 1.0f;
m_result[x, y] = 255;
continue;
}
}
Expand All @@ -188,13 +183,13 @@ public bool PerformPass()
if (state && neighbourCount < FarLessThanCount)
{
changeHappened = true;
m_result[x, y] = 0.0f;
m_result[x, y] = 0;
continue;
}
if (!state && neighbourCount > FarGreaterThanCount)
{
changeHappened = true;
m_result[x, y] = 1.0f;
m_result[x, y] = 255;
continue;
}
}
Expand Down
14 changes: 7 additions & 7 deletions rlbits-mapping/Assets/rlbits/mapping/graphs/Nodes/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace RLBits.Mapping.Graphs
[CreateNodeMenu("Shapes/Circle")]
public class Circle : PCGNode
{
[Output] public float[] m_result;
[Output] public int[] m_result;

protected Vector2Int m_NoiseParentSize;

Expand All @@ -19,7 +19,7 @@ public override object GetValue(NodePort port)
{
if (port.fieldName == "m_result")
{
if (m_result.Length != noiseGraph.TotalCells)
if (m_result.Length != NoiseGraph.TotalCells)
{
UpdateData();
}
Expand All @@ -32,26 +32,26 @@ public override object GetValue(NodePort port)
public override void UpdateData(bool withOutputs = true)
{

m_NoiseParentSize = noiseGraph.Size;
m_NoiseParentSize = NoiseGraph.Size;

Vector2 centre = new Vector2(
m_NoiseParentSize.x * 0.5f,
m_NoiseParentSize.y * 0.5f);

if (m_result == null || m_result.Length != m_NoiseParentSize.x * m_NoiseParentSize.y)
{
m_result = new float[m_NoiseParentSize.x * m_NoiseParentSize.y];
m_result = new int[m_NoiseParentSize.x * m_NoiseParentSize.y];
}

for (int y = 0; y < m_NoiseParentSize.y; y++)
{
for (int x = 0; x < m_NoiseParentSize.x; x++)
{
m_result[x + (y * m_NoiseParentSize.x)] =
1.0f -
(Vector2.Distance(
255 -
Mathf.RoundToInt(Vector2.Distance(
new Vector2(x, y),
centre) / (centre.magnitude * 0.7f));
centre) / (centre.magnitude * 0.7f)*255);
}
}

Expand Down
12 changes: 6 additions & 6 deletions rlbits-mapping/Assets/rlbits/mapping/graphs/Nodes/ClampNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace RLBits.Mapping.Graphs

public class ClampNode : PCGNode
{
public float minValue;
public float maxValue;
public int minValue;
public int maxValue;

[Input(backingValue = ShowBackingValue.Never)] public Node m_Input;


[Output] public float[] m_Result;
[Output] public int[] m_Result;

private float[] m_A;
private int[] m_A;


public override void UpdateData(bool withOutputs = true)
Expand All @@ -36,15 +36,15 @@ public override void UpdateData(bool withOutputs = true)
inputValid = false;
}

if (m_A.Length != noiseGraph.TotalCells)
if (m_A.Length != NoiseGraph.TotalCells)
{
Debug.Log("MisMatch");
inputValid = false;
}

if (inputValid)
{
m_Result = new float[noiseGraph.TotalCells];
m_Result = new int[NoiseGraph.TotalCells];
for (int i = 0; i < m_Result.Length; i++)
{
m_Result[i] = Mathf.Clamp(m_A[i], minValue, maxValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class ConnectShapes : PCGNode
[Input] public List<GridShape> m_Input;

[Output] public List<GridShape> m_Shapes;
[Output] public float[] m_result;
[Output] public int[] m_result;

public int AdditionalConnectionsToMake;
public float MapValue;
public int MapValue;
public HallwayAttach RoomPositionSample;
public GridShape.Shape HallwayShape;
public int HallwayMinSize;
Expand Down Expand Up @@ -48,7 +48,7 @@ public override object GetValue(NodePort port)
{
if (m_result != null)
{
if (m_result.Length != noiseGraph.TotalCells)
if (m_result.Length != NoiseGraph.TotalCells)
{
UpdateData();
}
Expand All @@ -67,12 +67,12 @@ public override object GetValue(NodePort port)

public override void UpdateData(bool withOutputs = true)
{
m_NoiseParentSize = noiseGraph.Size;
m_NoiseParentSize = NoiseGraph.Size;
m_Input = GetPort("m_Input").GetInputValue<List<GridShape>>();

m_result = new float[m_NoiseParentSize.x * m_NoiseParentSize.y];
m_result = new int[m_NoiseParentSize.x * m_NoiseParentSize.y];

Random.InitState(noiseGraph.Seed);
Random.InitState(NoiseGraph.Seed);

if (m_Input == null)
{
Expand Down
Loading