pforeach.h 627 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include "AIGateway.h"
  3. #include "Engine/Nullkiller.h"
  4. namespace NK2AI
  5. {
  6. template<typename TFunc>
  7. void pforeachTilePaths(const int3 & mapSize, const Nullkiller * aiNk, TFunc fn)
  8. {
  9. for(int z = 0; z < mapSize.z; ++z)
  10. {
  11. tbb::parallel_for(
  12. tbb::blocked_range<size_t>(0, mapSize.x),
  13. [&](const tbb::blocked_range<size_t> & r)
  14. {
  15. int3 pos(0, 0, z);
  16. std::vector<AIPath> paths;
  17. for(pos.x = r.begin(); pos.x != r.end(); ++pos.x)
  18. {
  19. for(pos.y = 0; pos.y < mapSize.y; ++pos.y)
  20. {
  21. aiNk->pathfinder->calculatePathInfo(paths, pos);
  22. fn(pos, paths);
  23. }
  24. }
  25. }
  26. );
  27. }
  28. }
  29. }