private void BuildVoxel(List<GeometryPartModule> geoModules, bool multiThreaded, bool solidify) { threadsQueued = Environment.ProcessorCount - 1; //for (int i = 0; i < geoModules.Count; i++) // threadsQueued += geoModules[i].meshDataList.Count; //Doing this out here allows us to get rid of the lock, which should reduce sync costs for many meshes if (!multiThreaded) for (int i = 0; i < geoModules.Count; i++) //Go through it backwards; this ensures that children (and so interior to cargo bay parts) are handled first { GeometryPartModule m = geoModules[i]; for (int j = 0; j < m.meshDataList.Count; j++) UpdateFromMesh(m.meshDataList[j], m.part); } else { int count = threadsQueued; for (int i = 0; i < count; i++) { VoxelShellMeshParams meshParams = new VoxelShellMeshParams((geoModules.Count * i) / count, ((i + 1) * geoModules.Count) / count, geoModules); ThreadPool.QueueUserWorkItem(UpdateFromMesh, meshParams); } lock (_locker) while (threadsQueued > 0) Monitor.Wait(_locker); } if (solidify) { threadsQueued = 2; if (multiThreaded) { VoxelSolidParams data = new VoxelSolidParams(0, (yLength / 2) * 8, true); ThreadPool.QueueUserWorkItem(SolidifyVoxel, data); data = new VoxelSolidParams((yLength / 2) * 8, yCellLength, false); ThreadPool.QueueUserWorkItem(SolidifyVoxel, data); } else { SolidifyVoxel(0, yCellLength, false); } if (multiThreaded) lock (_locker) while (threadsQueued > 0) Monitor.Wait(_locker); } }
private void BuildVoxel(List<GeometryPartModule> geoModules, bool multiThreaded, bool solidify) { threadsQueued = 0; for (int i = 0; i < geoModules.Count; i++) threadsQueued += geoModules[i].meshDataList.Count; //Doing this out here allows us to get rid of the lock, which should reduce sync costs for many meshes for (int i = 0; i < geoModules.Count; i++) //Go through it backwards; this ensures that children (and so interior to cargo bay parts) are handled first { GeometryPartModule m = geoModules[i]; for (int j = 0; j < m.meshDataList.Count; j++) { if (multiThreaded) { //lock (_locker) //{ //while (threadsQueued > 4) // Monitor.Wait(_locker); //threadsQueued++; VoxelShellParams data = new VoxelShellParams(m.part, m.meshDataList[j]); ThreadPool.QueueUserWorkItem(UpdateFromMesh, data); //} } else UpdateFromMesh(m.meshDataList[j], m.part); } } if (multiThreaded) lock (_locker) while (threadsQueued > 0) Monitor.Wait(_locker); if (solidify) { threadsQueued = 2; if (multiThreaded) { VoxelSolidParams data = new VoxelSolidParams(0, (yLength / 2) * 8, true); ThreadPool.QueueUserWorkItem(SolidifyVoxel, data); data = new VoxelSolidParams((yLength / 2) * 8, yCellLength, false); ThreadPool.QueueUserWorkItem(SolidifyVoxel, data); } else { SolidifyVoxel(0, yCellLength, false); } if (multiThreaded) lock (_locker) while (threadsQueued > 0) Monitor.Wait(_locker); } }