private void AssignSTL(int[,] matrix, int mapSize, Func <int, int> func) { matrix[this.startY, this.startX] = this.minValue + this.altitude; matrix[this.startY, this.startX + mapSize] = this.minValue + (int)rand.Next((uint)this.altitude); matrix[this.startY + mapSize, this.startX] = this.minValue + (int)rand.Next((uint)this.altitude); matrix[this.startY + mapSize, this.startX + mapSize] = this.minValue + (int)rand.Next((uint)this.altitude); DiamondSquareAverage.CreateDiamondSquareAverage(matrix, this.startX, this.startY, (uint)mapSize / 2, (uint)mapSize / 2, (uint)mapSize / 2, matrix[this.startY, this.startX], matrix[this.startY + mapSize, this.startX], matrix[this.startY, this.startX + mapSize], matrix[this.startY + mapSize, this.startX + mapSize], this.minValue + this.altitude, this.addAltitude, rand, func); }
private static int GetFramesForward(ulong s0, ulong s1, ulong n0, ulong n1, int loop) { var rand = new XorShift128(s0, s1); for (int i = 0; i < loop; i++) { _ = rand.Next(); if (rand.GetState64() == (n0, n1)) { return(i); } } return(-1); }
private void AssignSTL(int[,] matrix, int mapSize, Func <int, int> func) { // static_assert(this.startY == 0 && this.startX == 0) matrix[this.startY, this.startX] = matrix[this.startY + mapSize / 2, this.startX] = (int)rand.Next((uint)this.minValue, (uint)(this.minValue + this.altitude / 2)); matrix[this.startY, this.startX + mapSize] = matrix[this.startY, this.startX + mapSize / 2] = (int)rand.Next((uint)this.minValue, (uint)(this.minValue + this.altitude / 2)); matrix[this.startY + mapSize, this.startX] = matrix[this.startY + mapSize, this.startX + mapSize / 2] = (int)rand.Next((uint)this.minValue, (uint)(this.minValue + this.altitude / 2)); matrix[this.startY + mapSize, this.startX + mapSize] = matrix[this.startY + mapSize, this.startX + mapSize / 2] = (int)rand.Next((uint)this.minValue, (uint)(this.minValue + this.altitude / 2)); matrix[this.startY + mapSize / 2, this.startX + mapSize / 2] = this.minValue + this.altitude; DiamondSquareAverage.CreateDiamondSquareAverage(matrix, this.startX, this.startY, (uint)mapSize / 4, (uint)mapSize / 4, (uint)mapSize / 4, matrix[this.startY, this.startX], matrix[this.startY + mapSize / 2, this.startX], matrix[this.startY, this.startX + mapSize / 2], matrix[this.startY + mapSize / 2, this.startX + mapSize / 2], this.minValue + this.altitude, this.addAltitude, rand, func); DiamondSquareAverage.CreateDiamondSquareAverage(matrix, this.startX, this.startY, (uint)mapSize / 4, (uint)mapSize * 3 / 4, (uint)mapSize / 4, matrix[this.startY + mapSize / 2, this.startX], matrix[this.startY + mapSize, this.startX], matrix[this.startY + mapSize / 2, this.startX + mapSize / 2], matrix[this.startY + mapSize, this.startX + mapSize / 2], this.minValue + this.altitude, this.addAltitude, rand, func); DiamondSquareAverage.CreateDiamondSquareAverage(matrix, this.startX, this.startY, (uint)mapSize * 3 / 4, (uint)mapSize / 4, (uint)mapSize / 4, matrix[this.startY, this.startX + mapSize / 2], matrix[this.startY + mapSize / 2, this.startX + mapSize / 2], matrix[this.startY, this.startX + mapSize], matrix[this.startY + mapSize / 2, this.startX + mapSize], this.minValue + this.altitude, this.addAltitude, rand, func); DiamondSquareAverage.CreateDiamondSquareAverage(matrix, this.startX, this.startY, (uint)mapSize * 3 / 4, (uint)mapSize * 3 / 4, (uint)mapSize / 4, matrix[this.startY + mapSize / 2, this.startX + mapSize / 2], matrix[this.startY + mapSize, this.startX + mapSize / 2], matrix[this.startY + mapSize / 2, this.startX + mapSize], matrix[this.startY + mapSize, this.startX + mapSize], this.minValue + this.altitude, this.addAltitude, rand, func); }
private bool DrawNormal(int[,] matrix) { uint endX = CalcEndX(MatrixUtil.GetX(matrix)); uint endY = CalcEndY(MatrixUtil.GetY(matrix)); PerlinNoise perlin = new PerlinNoise((int)rand.Next()); double frequencyX = (endX - startX) / frequency; double frequencyY = (endY - startY) / frequency; // Debug.Log(frequencyX + " " + maxHeight); for (uint row = startY; row < endY; ++row) { for (uint col = startX; col < endX; ++col) { matrix[row, col] = minHeight + minHeight + (int)((double)(maxHeight - minHeight) * perlin.OctaveNoise(octaves, (col / frequencyX), (row / frequencyY))); } } return(true); }
private bool DrawNormal(int[,] matrix) { var chunkMatrix = new int[fiChunkSize + 1, fiChunkSize + 1]; var endX = CalcEndX(MatrixUtil.GetX(matrix)); var endY = CalcEndY(MatrixUtil.GetY(matrix)); if (this.altitude < 2) { return(false); } int chunkX = (int)(endX - this.startX) / fiChunkSize; int chunkY = (int)(endY - this.startY) / fiChunkSize; var randUp = new int[chunkX + 1]; var randDown = new int[chunkX + 1]; // バグ?(ではないっぽい) for (var col = 0; col <= chunkX; ++col) { randUp[col] = 0; } for (var row = 0; row < chunkY; ++row) { if (row + 1 == chunkY) { for (var col = 0; col <= chunkX; ++col) { randDown[col] = 0; } } else { for (var col = 1; col < chunkX; ++col) { randDown[col] = (int)rand.Next((uint)this.altitude); } randDown[0] = 0; randDown[chunkX] = randDown[0]; } for (var col = 0; col < chunkX; ++col) { chunkMatrix[0, 0] = randUp[col]; chunkMatrix[fiChunkSize, 0] = randDown[col]; chunkMatrix[0, fiChunkSize] = randUp[col + 1]; chunkMatrix[fiChunkSize, fiChunkSize] = randDown[col + 1]; // 地形の生成 this.CreateWorldMapSimple(chunkMatrix); for (var row2 = 0; row2 < fiChunkSize; ++row2) { for (var col2 = 0; col2 < fiChunkSize; ++col2) { matrix[this.startY + row * fiChunkSize + row2, startX + col * fiChunkSize + col2] = chunkMatrix[row2, col2]; } } } for (var col = 0; col <= chunkX; ++col) { randUp[col] = randDown[col]; } } return(true); }
/* Constructor */ public PerlinNoise() { this.rand = new XorShift128(); SetSeed(rand.Next()); } // = default();