Skip to content

Commit 98cc544

Browse files
author
nitrocaster
committed
Tweak VertexData composition.
1 parent b54aca7 commit 98cc544

File tree

6 files changed

+44
-57
lines changed

6 files changed

+44
-57
lines changed

src/xrAICore/Navigation/a_star.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
#include "xrAICore/Navigation/data_storage_constructor.h"
1313
#include "xrAICore/Navigation/dijkstra.h"
1414

15-
namespace AStar
16-
{
17-
template<typename _dist_type>
18-
struct ByDistType
15+
template<typename _dist_type, typename TVertexData>
16+
struct AStarVertexData
1917
{
2018
template<typename TCompoundVertex>
21-
struct VertexData :
22-
Dijkstra::template ByDistType<_dist_type>::template VertexData<TCompoundVertex>
19+
struct VertexData : TVertexData::template VertexData<TCompoundVertex>
2320
{
24-
typedef _dist_type _dist_type;
21+
typedef _dist_type _dist_type;
2522

2623
_dist_type _g;
2724
_dist_type _h;
@@ -30,26 +27,25 @@ struct ByDistType
3027
_dist_type &h() { return _h; }
3128
};
3229
};
33-
}
3430

3531
template <
3632
typename _dist_type,
3733
typename _priority_queue,
3834
typename _vertex_manager,
3935
typename _vertex_allocator,
40-
typename TCompoundVertex = EmptyVertexData,
4136
bool euclidian_heuristics = true,
4237
typename _data_storage_base = CVertexPath<euclidian_heuristics>,
43-
typename _iteration_type = u32
38+
typename _iteration_type = u32,
39+
typename TVertexData = EmptyVertexData
4440
> class CAStar : public CDijkstra<
4541
_dist_type,
4642
_priority_queue,
4743
_vertex_manager,
4844
_vertex_allocator,
49-
TCompoundVertex,
5045
euclidian_heuristics,
5146
_data_storage_base,
52-
_iteration_type
47+
_iteration_type,
48+
AStarVertexData<_dist_type, TVertexData>
5349
>
5450
{
5551
protected:
@@ -58,12 +54,12 @@ template <
5854
_priority_queue,
5955
_vertex_manager,
6056
_vertex_allocator,
61-
TCompoundVertex,
6257
euclidian_heuristics,
6358
_data_storage_base,
64-
_iteration_type
59+
_iteration_type,
60+
AStarVertexData<_dist_type, TVertexData>
6561
> inherited;
66-
typedef TCompoundVertex CGraphVertex;
62+
typedef typename inherited::CGraphVertex CGraphVertex;
6763
typedef typename CGraphVertex::_dist_type _dist_type;
6864
typedef typename CGraphVertex::_index_type _index_type;
6965

src/xrAICore/Navigation/a_star_inline.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
typename _priority_queue,\
1515
typename _vertex_manager,\
1616
typename _vertex_allocator,\
17-
typename TCompoundVertex,\
1817
bool euclidian_heuristics,\
1918
typename _data_storage_base,\
20-
typename _iteration_type\
19+
typename _iteration_type,\
20+
typename TVertexData\
2121
>
2222

2323
#define CSAStar CAStar<\
2424
_dist_type,\
2525
_priority_queue,\
2626
_vertex_manager,\
2727
_vertex_allocator,\
28-
TCompoundVertex,\
2928
euclidian_heuristics,\
3029
_data_storage_base,\
31-
_iteration_type\
30+
_iteration_type,\
31+
TVertexData\
3232
>
3333

3434
TEMPLATE_SPECIALIZATION

src/xrAICore/Navigation/data_storage_constructor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
#pragma once
1010

1111
struct EmptyVertexData
12-
{};
12+
{
13+
template<typename TCompoundVertex> // result mixin type
14+
struct VertexData
15+
{};
16+
};
1317

1418
template<typename... Components>
1519
struct CompoundVertex : Components::template VertexData<CompoundVertex<Components...>>...

src/xrAICore/Navigation/dijkstra.h

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,47 @@
1111
#include "xrAICore/Navigation/vertex_path.h"
1212
#include "xrAICore/Navigation/data_storage_constructor.h"
1313

14-
namespace Dijkstra
14+
template<typename _dist_type, typename TVertexData>
15+
struct DijkstraVertexData
1516
{
16-
template<typename _dist_type>
17-
struct ByDistType
17+
template<typename TCompoundVertex>
18+
struct VertexData : TVertexData::template VertexData<TCompoundVertex>
1819
{
19-
template<typename TCompoundVertex>
20-
struct VertexData
21-
{
22-
typedef _dist_type _dist_type;
20+
typedef _dist_type _dist_type;
2321

24-
_dist_type _f;
25-
TCompoundVertex *_back;
22+
_dist_type _f;
23+
TCompoundVertex *_back;
2624

27-
_dist_type &f() { return _f; }
28-
const _dist_type &f() const { return _f; }
29-
TCompoundVertex *&back() { return _back; }
30-
};
31-
};
32-
}
25+
_dist_type &f() { return _f; }
26+
const _dist_type &f() const { return _f; }
27+
TCompoundVertex *&back() { return _back; }
28+
};
29+
};
3330

3431
template <
3532
typename _dist_type,
3633
typename _priority_queue,
3734
typename _vertex_manager,
3835
typename _vertex_allocator,
39-
typename TCompoundVertex = EmptyVertexData,
4036
bool euclidian_heuristics = true,
4137
typename _data_storage_base = CVertexPath<euclidian_heuristics>,
42-
typename _iteration_type = u32
38+
typename _iteration_type = u32,
39+
typename TVertexData = EmptyVertexData
4340
> class CDijkstra
4441
{
4542
public:
43+
using CompoundVertex = CompoundVertex<DijkstraVertexData<_dist_type, TVertexData>,
44+
_priority_queue, _vertex_manager, _vertex_allocator, _data_storage_base>;
4645
typedef CDataStorageConstructor<
4746
_priority_queue, // algorithm
4847
_vertex_manager, // manager
4948
_data_storage_base, // builder
5049
_vertex_allocator, // allocator
51-
TCompoundVertex
50+
CompoundVertex
5251
> CDataStorage;
5352

5453
protected:
55-
typedef TCompoundVertex CGraphVertex;
54+
typedef CompoundVertex CGraphVertex;
5655
typedef typename CGraphVertex::_dist_type _dist_type;
5756
typedef typename CGraphVertex::_index_type _index_type;
5857

src/xrAICore/Navigation/dijkstra_inline.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
typename _priority_queue,\
1515
typename _vertex_manager,\
1616
typename _vertex_allocator,\
17-
typename TCompoundVertex,\
1817
bool euclidian_heuristics,\
1918
typename _data_storage_base,\
20-
typename _iteration_type\
19+
typename _iteration_type,\
20+
typename TVertexData\
2121
>
2222

2323
#define CSDijkstra CDijkstra<\
2424
_dist_type,\
2525
_priority_queue,\
2626
_vertex_manager,\
2727
_vertex_allocator,\
28-
TCompoundVertex,\
2928
euclidian_heuristics,\
3029
_data_storage_base,\
31-
_iteration_type\
30+
_iteration_type,\
31+
TVertexData\
3232
>
3333

3434
TEMPLATE_SPECIALIZATION

src/xrAICore/Navigation/graph_engine.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,45 +55,33 @@ class CGraphEngine
5555
using CStringVertexAllocator = CVertexAllocatorFixed<1024>;
5656
#endif
5757
using AlgorithmStorage = CVertexPath<true>;
58-
using AlgorithmVertexData = AStar::template ByDistType<_dist_type>;
59-
using AlgorithmVertex = CompoundVertex<AlgorithmVertexData,
60-
CPriorityQueue, CVertexManager, CVertexAllocator, AlgorithmStorage>;
61-
using CAlgorithm = CAStar<
58+
using CAlgorithm = CAStar<
6259
_dist_type,
6360
CPriorityQueue,
6461
CVertexManager,
6562
CVertexAllocator,
66-
AlgorithmVertex,
6763
true,
6864
AlgorithmStorage>;
6965

7066
#ifndef AI_COMPILER
7167
using SolverAlgorithmStorage = CEdgePath<_solver_edge_type, true>;
72-
using SolverAlgorithmVertexData = AStar::template ByDistType<_solver_dist_type>;
73-
using SolverAlgorithmVertex = CompoundVertex<SolverAlgorithmVertexData,
74-
CSolverPriorityQueue, CSolverVertexManager, CSolverVertexAllocator, SolverAlgorithmStorage>;
7568
using CSolverAlgorithm = CAStar<
7669
_solver_dist_type,
7770
CSolverPriorityQueue,
7871
CSolverVertexManager,
7972
CSolverVertexAllocator,
80-
SolverAlgorithmVertex,
8173
true,
8274
SolverAlgorithmStorage>;
8375

8476
using _string_dist_type = float;
8577
using StringAlgorithmStorage = AlgorithmStorage;
86-
using StringAlgorithmVertexData = AStar::template ByDistType<_string_dist_type>;
87-
using StringAlgorithmVertex = CompoundVertex<StringAlgorithmVertexData,
88-
CStringPriorityQueue, CStringVertexManager, CStringVertexAllocator, StringAlgorithmStorage>;
8978
using CStringAlgorithm = CAStar<
9079
_string_dist_type,
9180
CStringPriorityQueue,
9281
CStringVertexManager,
9382
CStringVertexAllocator,
94-
StringAlgorithmVertex,
9583
true,
96-
AlgorithmStorage>;
84+
StringAlgorithmStorage>;
9785
#endif // AI_COMPILER
9886

9987
CAlgorithm *m_algorithm;

0 commit comments

Comments
 (0)