public unsafe override NativeInt2DArray GetInts(int areaX, int areaY, int areaWidth, int areaHeight, Allocator allocator) { int parentAreaX = areaX > 0 ? areaX / 2 : (areaX - 1) / 2; int parentAreaY = areaY > 0 ? areaY / 2 : (areaY - 1) / 2; int parentWidth = areaWidth / 2 + 2; int parentHeight = areaHeight / 2 + 2; NativeInt2DArray parentRes = m_Parent.GetInts(parentAreaX, parentAreaY, parentWidth, parentHeight, allocator); int tempWidth = (parentWidth - 1) * 2; int tempHeight = (parentHeight - 1) * 2; NativeInt2DArray temp = new NativeInt2DArray(tempHeight, tempWidth, allocator); for (int parentY = 0; parentY < parentHeight - 1; ++parentY) { int parentValue = parentRes[parentY, 0]; int parentValueY1 = parentRes[parentY + 1, 0]; for (int parentX = 0; parentX < parentWidth - 1; ++parentX) { int randomSeed = GetChunkSeed((parentX + parentAreaX) * 2, (parentY + parentAreaY) * 2); int parentValueX1 = parentRes[parentY, parentX + 1]; int parentValueX1Y1 = parentRes[parentY + 1, parentX + 1]; temp[parentY * 2, parentX * 2] = parentValue; int *array = stackalloc int[2] { parentValue, parentValueY1 }; temp[parentY * 2 + 1, parentX * 2] = SelectRandom(randomSeed, array, 2); array[1] = parentValueX1; temp[parentY * 2, parentX * 2 + 1] = SelectRandom(randomSeed, array, 2); temp[parentY * 2 + 1, parentX * 2 + 1] = SelectModeOrRandom(randomSeed, parentValue, parentValueX1, parentValueY1, parentValueX1Y1); parentValue = parentValueX1; parentValueY1 = parentValueX1Y1; } } NativeInt2DArray result = new NativeInt2DArray(areaHeight, areaWidth, allocator); int areaOffsetX = Mathf.Abs(areaX % 2); int areaOffsetY = Mathf.Abs(areaY % 2); for (int resultY = 0; resultY < areaHeight; ++resultY) { for (int resultX = 0; resultX < areaWidth; ++resultX) { result[resultY, resultX] = temp[resultY + areaOffsetY, resultX + areaOffsetX]; } } parentRes.Dispose(); temp.Dispose(); return(result); }
public override NativeInt2DArray GetInts(int areaX, int areaY, int areaWidth, int areaHeight, Allocator allocator) { NativeInt2DArray parentResult = m_Parent.GetInts(areaX, areaY, areaWidth, areaHeight, allocator); for (int i = 0; i < areaHeight; ++i) { for (int j = 0; j < areaWidth; ++j) { Random random = new Random(GetChunkSeed(areaX + j, areaY + i)); if (parentResult[i, j] == (int)BiomeId.Plains) { int r = random.Next(10); if (r >= 0 && r < 1) { parentResult[i, j] = (int)BiomeId.Forest; } else if (r >= 1 && r < 2) { parentResult[i, j] = (int)BiomeId.Mountains; } else if (r >= 2 && r < 3) { parentResult[i, j] = (int)BiomeId.Swamp; } else if (r >= 3 && r < 5) { parentResult[i, j] = (int)BiomeId.Desert; } else if (r >= 5 && r < 7) { parentResult[i, j] = (int)BiomeId.Taiga; } else if (r >= 7 && r < 8) { parentResult[i, j] = (int)BiomeId.Savanna; } } } } return(parentResult); }
public override NativeInt2DArray GetInts(int areaX, int areaY, int areaWidth, int areaHeight, Allocator allocator) { NativeInt2DArray result = new NativeInt2DArray(areaHeight, areaWidth, allocator); for (int i = 0; i < areaHeight; ++i) { for (int j = 0; j < areaWidth; ++j) { Random random = new Random(GetChunkSeed(areaX + j, areaY + i)); result[i, j] = random.Next(5) == 0 ? 1 : 0; } } if (-areaWidth < areaX && areaX <= 0 && -areaHeight < areaY && areaY <= 0) { result[-areaY, -areaX] = (int)BiomeId.Plains; } return(result); }
public override NativeInt2DArray GetInts(int areaX, int areaY, int areaWidth, int areaHeight, Allocator allocator) { int parentAreaX = areaX - 1; int parentAreaY = areaY - 1; int parentWidth = areaWidth + 2; int parentHeight = areaHeight + 2; NativeInt2DArray parentRes = m_Parent.GetInts(parentAreaX, parentAreaY, parentWidth, parentHeight, allocator); NativeInt2DArray result = new NativeInt2DArray(areaHeight, areaWidth, allocator); for (int y = 0; y < areaHeight; ++y) { for (int x = 0; x < areaWidth; ++x) { int parentValue = parentRes[y, x]; int parentValueX2 = parentRes[y, x + 2]; int parentValueY2 = parentRes[y + 2, x]; int parentValueX2Y2 = parentRes[y + 2, x + 2]; int parentValueX1Y1 = parentRes[y + 1, x + 1]; if (parentValueX1Y1 != 0 && (parentValue == 0 || parentValueX2 == 0 || parentValueY2 == 0 || parentValueX2Y2 == 0)) { if (parentValueX1Y1 != (int)BiomeId.Mountains) { result[y, x] = (int)BiomeId.Beach; } } else { result[y, x] = parentValueX1Y1; } } } parentRes.Dispose(); return(result); }
public override NativeInt2DArray GetInts(int areaX, int areaY, int areaWidth, int areaHeight, Allocator allocator) { int parentAreaX = areaX - 1; int parentAreaY = areaY - 1; int parentWidth = areaWidth + 2; int parentHeight = areaHeight + 2; NativeInt2DArray parentRes = m_Parent.GetInts(parentAreaX, parentAreaY, parentWidth, parentHeight, allocator); NativeInt2DArray result = new NativeInt2DArray(areaHeight, areaWidth, allocator); for (int y = 0; y < areaHeight; ++y) { for (int x = 0; x < areaWidth; ++x) { int parentValue = parentRes[y, x]; int parentValueX2 = parentRes[y, x + 2]; int parentValueY2 = parentRes[y + 2, x]; int parentValueX2Y2 = parentRes[y + 2, x + 2]; int parentValueX1Y1 = parentRes[y + 1, x + 1]; int randomSeed = GetChunkSeed(x + areaX, y + areaY); Random random = new Random(randomSeed); if (parentValueX1Y1 != 0 || (parentValue == 0 && parentValueX2 == 0 && parentValueY2 == 0 && parentValueX2Y2 == 0)) { if (parentValueX1Y1 > 0 && (parentValue == 0 || parentValueX2 == 0 || parentValueY2 == 0 || parentValueX2Y2 == 0)) { if (random.Next(5) == 0) { if (parentValueX1Y1 == 4) { result[y, x] = 4; } else { result[y, x] = 0; } } else { result[y, x] = parentValueX1Y1; } } else { result[y, x] = parentValueX1Y1; } } else { int deno = 1; int value = 1; if (parentValue != 0 && random.Next(deno++) == 0) { value = parentValue; } if (parentValueX2 != 0 && random.Next(deno++) == 0) { value = parentValueX2; } if (parentValueY2 != 0 && random.Next(deno++) == 0) { value = parentValueY2; } if (parentValueX2Y2 != 0 && random.Next(deno++) == 0) { value = parentValueX2Y2; } if (random.Next(3) == 0) { result[y, x] = value; } else if (value == 4) { result[y, x] = 4; } else { result[y, x] = 0; } } } } parentRes.Dispose(); return(result); }
public override NativeInt2DArray GetInts(int areaX, int areaY, int areaWidth, int areaHeight, Allocator allocator) { int parentAreaX = areaX - 1; int parentAreaY = areaY - 1; int parentWidth = areaWidth + 2; int parentHeight = areaHeight + 2; NativeInt2DArray parentRes = m_Parent.GetInts(parentAreaX, parentAreaY, parentWidth, parentHeight, allocator); NativeInt2DArray result = new NativeInt2DArray(areaHeight, areaWidth, allocator); for (int y = 0; y < areaHeight; ++y) { for (int x = 0; x < areaWidth; ++x) { int randomValueY1 = parentRes[y + 1, x]; int randomValueX2Y1 = parentRes[y + 1, x + 2]; int randomValueX1 = parentRes[y, x + 1]; int randomValueX1Y2 = parentRes[y + 2, x + 1]; int randomValueX1Y1 = parentRes[y + 1, x + 1]; int tempX, tempY; if (x + areaX >= 0) { tempX = (x + areaX) / 64; } else { tempX = (x + areaX) / 64 - 1; } if (y + areaY >= 0) { tempY = (y + areaY) / 64; } else { tempY = (y + areaY) / 64 - 1; } int seed = GetChunkSeed(tempX, tempY); Random rand = new Random(seed); if (randomValueX1Y1 == randomValueY1 && randomValueX1Y1 == randomValueX1 && randomValueX1Y1 == randomValueX2Y1 && randomValueX1Y1 == randomValueX1Y2) { result[y, x] = randomValueX1Y1; } else if (rand.Next(5) == 0) { if (randomValueX1Y1 != (int)BiomeId.Ocean && randomValueX1Y1 != (int)BiomeId.Beach) { result[y, x] = (int)BiomeId.River; } } else { result[y, x] = randomValueX1Y1; } } } parentRes.Dispose(); return(result); }