private void AddDiffMapToPowder(float[] diffmap) { ParallelHelper.For2D(this.Width, this.Height, (x, y, i) => { this.Map[i].Powder += diffmap[i]; }); }
public void Test_ParallelHelper_ParameterName_ThrowArgumentOutOfRangeExceptionForTopGreaterThanBottom() { try { ParallelHelper.For2D <DummyAction2D>(1, 0, 0, 1); } catch (ArgumentOutOfRangeException e) when(e.GetType() == typeof(ArgumentOutOfRangeException)) { var name = ( from method in typeof(ParallelHelper).GetMethods() where method.Name == nameof(ParallelHelper.For2D) && method.IsGenericMethodDefinition let typeParams = method.GetGenericArguments() let normalParams = method.GetParameters() where typeParams.Length == 1 && normalParams.Length == 4 && normalParams.All(p => p.ParameterType == typeof(int)) select normalParams[0].Name).Single(); Assert.AreEqual(e.ParamName, name); return; } Assert.Fail("Failed to raise correct exception"); }
private void UpdateTileDataPass2() { ParallelHelper.For2D(this.tile.Width, this.tile.Height, (x, y, i) => { this.tile.Data[i] = (this.TerrainPass2.Map[i].Height) / 4096.0f; }); ParallelHelper.For2D(this.tile.Width, this.tile.Height, (x, y, i) => { this.shadeTexData[i].R = (byte)((this.TerrainPass2.Map[i].Ice * 64f).ClampInclusive(0.0f, 255.0f)); // ice this.shadeTexData[i].G = (byte)((this.TerrainPass2.Map[i].Snow * 64f).ClampInclusive(0.0f, 255.0f)); // snow this.shadeTexData[i].B = (byte)((this.TerrainPass2.Map[i].Powder * 1024f).ClampInclusive(0.0f, 255.0f)); // powder this.shadeTexData[i].A = 0; }); //Parallel.For(0, this.tile.Height, y => //{ // int i = y * this.TerrainPass2.Width; // for (int x = 0; x < this.tile.Width; x++) // { // var c = this.TerrainPass2.Map[i]; // this.tile.Data[i] = (c.Height) / 4096.0f; // this.shadeTexData[i].R = (byte)((c.Ice * 64f).ClampInclusive(0.0f, 255.0f)); // ice // this.shadeTexData[i].G = (byte)((c.Snow * 64f).ClampInclusive(0.0f, 255.0f)); // snow // this.shadeTexData[i].B = (byte)((c.Powder * 64f).ClampInclusive(0.0f, 255.0f)); // powder // this.shadeTexData[i].A = 0; // i++; // } //}); this.tile.UpdateHeights(device); this.tile.UpdateShadeTexture(this.shadeTexData); }
private void CombineDiffMapsForDirection(int xofs, int yofs) { ParallelHelper.For2D(this.Width, this.Height, (x, y, pTo) => { this.TempDiffMap2[C(x + xofs, y + yofs)] -= this.TempDiffMap[pTo]; this.TempDiffMap2[pTo] += this.TempDiffMap[pTo]; }); }
public void CompactPowder(float minDepth, float amount, float invDensityRatio) { ParallelHelper.For2D(this.Width, this.Height, (i) => { float powder = this.Map[i].Powder; if (powder > minDepth) { powder = (powder - minDepth) * amount; this.Map[i].Powder -= powder; this.Map[i].Snow += powder * invDensityRatio; } }); }
public void AddPowder(float amount, Vector3 direction) { float a1 = this.parameters.SnowFallWindDirectionComponent; float a0 = (1f - a1); a0 *= amount; a1 *= amount; direction = -direction; ParallelHelper.For2D(this.Width, this.Height, (i) => { this.Map[i].Powder += a0 + a1 * Vector3.Dot(direction, this.MapNormals[i]).ClampInclusive(0f, 1f); }); }
public void Test_ParallelHelper_For2DWithIndices() { foreach (var size in TestFor2DSizes) { int[,] data = new int[size.Height, size.Width]; ParallelHelper.For2D(0, size.Height, 0, size.Width, new Assigner2D(data)); for (int i = 0; i < size.Height; i++) { for (int j = 0; j < size.Width; j++) { if (data[i, j] != unchecked (i * 397 ^ j)) { Assert.Fail($"Invalid item at position [{i},{j}], value was {data[i, j]} instead of {unchecked(i * 397 ^ j)}"); } } } } }
public unsafe void Test_ParallelHelper_For2DWithIndices() { foreach (var size in TestFor2DSizes) { using UnmanagedSpanOwner <int> data = new UnmanagedSpanOwner <int>(size.Height * size.Width); data.GetSpan().Clear(); ParallelHelper.For2D(0, size.Height, 0, size.Width, new Assigner2D(size.Height, size.Width, data.Ptr)); for (int i = 0; i < size.Height; i++) { for (int j = 0; j < size.Width; j++) { if (data.Ptr[(i * size.Width) + j] != unchecked (i * 397 ^ j)) { Assert.Fail($"Invalid item at position [{i},{j}], value was {data.Ptr[(i * size.Width) + j]} instead of {unchecked(i * 397 ^ j)}"); } } } } }
private void UpdateTileData() { ParallelHelper.For2D(this.tile.Width, this.tile.Height, (x, y, i) => { this.tile.Data[i] = (this.Terrain.Map[i].Height) / 4096.0f; }); ParallelHelper.For2D(this.tile.Width, this.tile.Height, (x, y, i) => { this.shadeTexData[i].G = (byte)((this.Terrain.Map[i].Loose * 4.0f).ClampInclusive(0.0f, 255.0f)); this.shadeTexData[i].B = (byte)((this.Terrain.Map[i].MovingWater * 2048.0f).ClampInclusive(0.0f, 255.0f)); this.shadeTexData[i].A = (byte)((this.Terrain.Map[i].Erosion * 32f).ClampInclusive(0.0f, 255.0f)); // erosion rate this.shadeTexData[i].R = (byte)((this.Terrain.Map[i].Carrying * 32f).ClampInclusive(0.0f, 255.0f)); // carrying capacity }); /* * Parallel.For(0, this.tile.Height, y => * { * int i = y * this.Terrain.Width; * for (int x = 0; x < this.tile.Width; x++) * { * var c = this.Terrain.Map[i]; * this.tile.Data[i] = (c.Height) / 4096.0f; * //this.shadeTexData[i].R = (byte)((c.Hard / 4.0f).ClampInclusive(0.0f, 255.0f)); * * this.shadeTexData[i].G = (byte)((c.Loose * 4.0f).ClampInclusive(0.0f, 255.0f)); * //this.shadeTexData[i].G = (byte)((c.Slumping * 256.0f).ClampInclusive(0.0f, 255.0f)); * * this.shadeTexData[i].B = (byte)((c.MovingWater * 2048.0f).ClampInclusive(0.0f, 255.0f)); * this.shadeTexData[i].A = (byte)((c.Erosion * 32f).ClampInclusive(0.0f, 255.0f)); // erosion rate * this.shadeTexData[i].R = (byte)((c.Carrying * 32f).ClampInclusive(0.0f, 255.0f)); // carrying capacity * i++; * } * });*/ this.tile.UpdateHeights(device); this.tile.UpdateShadeTexture(this.shadeTexData); }