public void CalculateBlockTypesParallel() { var multiThreadTaskQueue = new MultiThreadTaskQueue(); for (int x = 0; x < _totalBlockNumberX; x++) { for (int z = 0; z < _totalBlockNumberZ; z++) { multiThreadTaskQueue.ScheduleTask(CalculateBlockTypesForColumnParallel, x, z); } } multiThreadTaskQueue.RunAllInParallel(); }
/// <summary> /// Adds trees to the world. /// If treeProb parameter is set to TreeProbability.None then no trees will be added. /// In order to avoid potential collisions boundary cubes on x and z axis are ignored /// and therefore will never grow a tree resulting in slightly different although unnoticeable /// for player results. /// </summary> public void AddTreesParallel(TreeProbability treeProb) { if (treeProb == TreeProbability.None) { return; } float woodbaseProbability = treeProb == TreeProbability.Some ? WoodbaseSomeProbability : WoodbaseHighProbability; var queue = new MultiThreadTaskQueue(); // schedule one task per chunk for (int i = 0; i < World.Settings.WorldSizeX; i++) { for (int j = 0; j < World.Settings.WorldSizeZ; j++) { queue.ScheduleTask(AddTreesInChunkParallel, woodbaseProbability, i, j); } } queue.RunAllInParallel(); // this is synchronous }