示例#1
0
        public void CalculateNormals()
        {
            ParallelHelper.For2DParallel(this.Width, this.Height, (cx, cy, i) =>
            {
                float h1 = this.Map[C(cx, cy - 1)].Height;
                float h2 = this.Map[C(cx, cy + 1)].Height;
                float h3 = this.Map[C(cx - 1, cy)].Height;
                float h4 = this.Map[C(cx + 1, cy)].Height;

                this.MapNormals[i].X = h3 - h4;
                this.MapNormals[i].Y = h1 - h2;
                this.MapNormals[i].Z = 2f;
                this.MapNormals[i].Normalize();
            });
        }
示例#2
0
 public void Compare(string name, int runs, Action <int, int, int> a)
 {
     Console.WriteLine(name);
     Console.WriteLine(string.Format("Single thread: {0}ms", U.Utils.AverageTime(() => { InitData(); return(U.Utils.TimeFor(() => ParallelHelper.For2DSingle(Width, Height, a))); }, runs)));
     Console.WriteLine(string.Format("Parallel thread: {0}ms", U.Utils.AverageTime(() => { InitData(); return(U.Utils.TimeFor(() => ParallelHelper.For2DParallel(Width, Height, a))); }, runs)));
     Console.WriteLine(string.Format("Parallel thread, unrolled: {0}ms", U.Utils.AverageTime(() => { InitData(); return(U.Utils.TimeFor(() => ParallelHelper.For2DParallelUnrolled(Width, Height, a))); }, runs)));
     Console.WriteLine(string.Format("Batched thread: {0}ms", U.Utils.AverageTime(() => { InitData(); return(U.Utils.TimeFor(() => ParallelHelper.For2DParallelBatched(Width, Height, a))); }, runs)));
 }