Skip to content

Commit 6eacc19

Browse files
authored
Merge pull request #198 from Vitek1425/xd_dev
Added parallelism to computing covers
2 parents e1e4c06 + 9a6a86b commit 6eacc19

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

src/xrGame/cover_manager.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
////////////////////////////////////////////////////////////////////////////
88

99
#include "stdafx.h"
10+
#include "tbb/parallel_for.h"
11+
#include "tbb/blocked_range.h"
1012
#include "xrAICore/Navigation/level_graph.h"
1113
#include "cover_manager.h"
1214
#include "ai_space.h"
@@ -33,7 +35,7 @@ CCoverManager::~CCoverManager()
3335
xr_delete(m_smart_covers_storage);
3436
}
3537

36-
IC bool CCoverManager::edge_vertex(u32 index)
38+
IC bool CCoverManager::edge_vertex(u32 index) const
3739
{
3840
CLevelGraph::CVertex* v = ai().level_graph().vertex(index);
3941
return ((!ai().level_graph().valid_vertex_id(v->link(0)) && (v->high_cover(0) < MIN_COVER_VALUE)) ||
@@ -46,21 +48,21 @@ IC bool CCoverManager::edge_vertex(u32 index)
4648
(!ai().level_graph().valid_vertex_id(v->link(3)) && (v->low_cover(3) < MIN_COVER_VALUE)));
4749
}
4850

49-
IC bool CCoverManager::cover(CLevelGraph::CVertex* v, u32 index0, u32 index1)
51+
IC bool CCoverManager::cover(CLevelGraph::CVertex* v, u32 index0, u32 index1) const
5052
{
5153
return (ai().level_graph().valid_vertex_id(v->link(index0)) &&
5254
ai().level_graph().valid_vertex_id(ai().level_graph().vertex(v->link(index0))->link(index1)) &&
5355
m_temp[ai().level_graph().vertex(v->link(index0))->link(index1)]);
5456
}
5557

56-
IC bool CCoverManager::critical_point(CLevelGraph::CVertex* v, u32 index, u32 index0, u32 index1)
58+
IC bool CCoverManager::critical_point(CLevelGraph::CVertex* v, u32 index, u32 index0, u32 index1) const
5759
{
5860
return (!ai().level_graph().valid_vertex_id(v->link(index)) &&
5961
(!ai().level_graph().valid_vertex_id(v->link(index0)) || !ai().level_graph().valid_vertex_id(v->link(index1)) ||
6062
cover(v, index0, index) || cover(v, index1, index)));
6163
}
6264

63-
IC bool CCoverManager::critical_cover(u32 index)
65+
IC bool CCoverManager::critical_cover(u32 index) const
6466
{
6567
CLevelGraph::CVertex* v = ai().level_graph().vertex(index);
6668
return (critical_point(v, 0, 1, 3) || critical_point(v, 2, 1, 3) || critical_point(v, 1, 0, 2) ||
@@ -75,25 +77,27 @@ void CCoverManager::compute_static_cover()
7577
ai().level_graph().header().box(), ai().level_graph().header().cell_size() * .5f, 8 * 65536, 4 * 65536);
7678
m_temp.resize(ai().level_graph().header().vertex_count());
7779

78-
CLevelGraph const& graph = ai().level_graph();
79-
u32 levelVertexCount = ai().level_graph().header().vertex_count();
80-
for (u32 i = 0; i < levelVertexCount; ++i)
81-
{
82-
CLevelGraph::CVertex const& vertex = *graph.vertex(i);
83-
if (vertex.high_cover(0) + vertex.high_cover(1) + vertex.high_cover(2) + vertex.high_cover(3))
80+
const CLevelGraph& graph = ai().level_graph();
81+
const u32 levelVertexCount = ai().level_graph().header().vertex_count();
82+
tbb::parallel_for(tbb::blocked_range<u32>(0, levelVertexCount), [&](const tbb::blocked_range<u32>& range) {
83+
for (u32 i = range.begin(); i != range.end(); ++i)
8484
{
85-
m_temp[i] = edge_vertex(i);
86-
continue;
85+
const CLevelGraph::CVertex& vertex = *graph.vertex(i);
86+
if (vertex.high_cover(0) + vertex.high_cover(1) + vertex.high_cover(2) + vertex.high_cover(3))
87+
{
88+
m_temp[i] = edge_vertex(i);
89+
continue;
90+
}
91+
92+
if (vertex.low_cover(0) + vertex.low_cover(1) + vertex.low_cover(2) + vertex.low_cover(3))
93+
{
94+
m_temp[i] = edge_vertex(i);
95+
continue;
96+
}
97+
98+
m_temp[i] = false;
8799
}
88-
89-
if (vertex.low_cover(0) + vertex.low_cover(1) + vertex.low_cover(2) + vertex.low_cover(3))
90-
{
91-
m_temp[i] = edge_vertex(i);
92-
continue;
93-
}
94-
95-
m_temp[i] = false;
96-
}
100+
});
97101

98102
for (u32 i = 0; i < levelVertexCount; ++i)
99103
if (m_temp[i] && critical_cover(i))

src/xrGame/cover_manager.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class CCoverManager
5353
mutable bool m_smart_covers_actual;
5454

5555
protected:
56-
IC bool edge_vertex(u32 index);
57-
IC bool cover(LevelGraph::CVertex* v, u32 index0, u32 index1);
58-
IC bool critical_point(LevelGraph::CVertex* v, u32 index, u32 index0, u32 index1);
59-
IC bool critical_cover(u32 index);
56+
IC bool edge_vertex(u32 index) const;
57+
IC bool cover(LevelGraph::CVertex* v, u32 index0, u32 index1) const;
58+
IC bool critical_point(LevelGraph::CVertex* v, u32 index, u32 index0, u32 index1) const;
59+
IC bool critical_cover(u32 index) const;
6060

6161
private:
6262
template <typename _evaluator_type, typename _restrictor_type>

0 commit comments

Comments
 (0)