|
12 | 12 | #include "xrAICore/Navigation/level_graph.h"
|
13 | 13 | #include "space_restrictor.h"
|
14 | 14 | #include "xrAICore/Navigation/graph_engine.h"
|
| 15 | +#include "xrCore/Threading/ParallelFor.hpp" |
15 | 16 |
|
16 | 17 | struct CBorderMergePredicate
|
17 | 18 | {
|
@@ -79,10 +80,43 @@ void CSpaceRestrictionShape::fill_shape(const CCF_Shape::shape_def& shape)
|
79 | 80 | }
|
80 | 81 | default: NODEFAULT;
|
81 | 82 | }
|
82 |
| - ai().level_graph().iterate_vertices(start, dest, CBorderMergePredicate(this)); |
| 83 | + |
| 84 | + CLevelGraph& graph = ai().level_graph(); |
| 85 | + |
| 86 | + std::mutex mergeMutex; |
| 87 | + |
| 88 | + auto [begin, end] = graph.get_range(start, dest); |
| 89 | + xr_parallel_for(TaskRange{begin, end}, [this, &mergeMutex, &graph] (auto &range) { |
| 90 | + xr_vector<u32> m_border_chunk; |
| 91 | + m_border_chunk.reserve(range.size()); |
| 92 | + for (auto &vertex : range) |
| 93 | + { |
| 94 | + if (inside(graph.vertex_id(&vertex), true) && |
| 95 | + !inside(graph.vertex_id(&vertex), false)) |
| 96 | + m_border_chunk.push_back(graph.vertex_id(&vertex)); |
| 97 | + } |
| 98 | + std::lock_guard lock(mergeMutex); |
| 99 | + if (m_border.capacity() < m_border.size() + m_border_chunk.size()) |
| 100 | + m_border.reserve(m_border.size() + m_border_chunk.size()); |
| 101 | + for (auto x : m_border_chunk) |
| 102 | + m_border.push_back(x); |
| 103 | + }); |
83 | 104 |
|
84 | 105 | #ifdef DEBUG
|
85 |
| - ai().level_graph().iterate_vertices(start, dest, CShapeTestPredicate(this)); |
| 106 | + xr_parallel_for(TaskRange{begin, end}, [this, &mergeMutex, &graph] (const auto &range) { |
| 107 | + xr_vector<u32> m_test_storage_chunk; |
| 108 | + m_test_storage_chunk.reserve(range.size()); |
| 109 | + for (auto &vertex : range) |
| 110 | + { |
| 111 | + if (inside(graph.vertex_id(&vertex), false)) |
| 112 | + m_test_storage_chunk.push_back(graph.vertex_id(&vertex)); |
| 113 | + } |
| 114 | + std::lock_guard lock(mergeMutex); |
| 115 | + if (m_test_storage.capacity() < m_test_storage.size() + m_test_storage_chunk.size()) |
| 116 | + m_test_storage.reserve(m_test_storage.size() + m_test_storage_chunk.size()); |
| 117 | + for (auto x : m_test_storage_chunk) |
| 118 | + m_test_storage.push_back(x); |
| 119 | + }); |
86 | 120 | #endif
|
87 | 121 | }
|
88 | 122 |
|
|
0 commit comments