pforeach.h 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include "Engine/Nullkiller.h"
  3. namespace NKAI
  4. {
  5. template<typename TFunc>
  6. void pforeachTilePos(const int3 & mapSize, TFunc fn)
  7. {
  8. for(int z = 0; z < mapSize.z; ++z)
  9. {
  10. tbb::parallel_for(tbb::blocked_range<size_t>(0, mapSize.x), [&](const tbb::blocked_range<size_t> & r)
  11. {
  12. int3 pos(0, 0, z);
  13. for(pos.x = r.begin(); pos.x != r.end(); ++pos.x)
  14. {
  15. for(pos.y = 0; pos.y < mapSize.y; ++pos.y)
  16. {
  17. fn(pos);
  18. }
  19. }
  20. });
  21. }
  22. }
  23. template<typename TFunc>
  24. void pforeachTilePaths(const int3 & mapSize, const Nullkiller * ai, TFunc fn)
  25. {
  26. for(int z = 0; z < mapSize.z; ++z)
  27. {
  28. tbb::parallel_for(tbb::blocked_range<size_t>(0, mapSize.x), [&](const tbb::blocked_range<size_t> & r)
  29. {
  30. int3 pos(0, 0, z);
  31. std::vector<AIPath> paths;
  32. for(pos.x = r.begin(); pos.x != r.end(); ++pos.x)
  33. {
  34. for(pos.y = 0; pos.y < mapSize.y; ++pos.y)
  35. {
  36. ai->pathfinder->calculatePathInfo(paths, pos);
  37. fn(pos, paths);
  38. }
  39. }
  40. });
  41. }
  42. }
  43. }