Skip to content

Commit

Permalink
Tweak VertexData composition.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Dec 10, 2015
1 parent b54aca7 commit 98cc544
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 57 deletions.
26 changes: 11 additions & 15 deletions src/xrAICore/Navigation/a_star.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
#include "xrAICore/Navigation/data_storage_constructor.h"
#include "xrAICore/Navigation/dijkstra.h"

namespace AStar
{
template<typename _dist_type>
struct ByDistType
template<typename _dist_type, typename TVertexData>
struct AStarVertexData
{
template<typename TCompoundVertex>
struct VertexData :
Dijkstra::template ByDistType<_dist_type>::template VertexData<TCompoundVertex>
struct VertexData : TVertexData::template VertexData<TCompoundVertex>
{
typedef _dist_type _dist_type;
typedef _dist_type _dist_type;

_dist_type _g;
_dist_type _h;
Expand All @@ -30,26 +27,25 @@ struct ByDistType
_dist_type &h() { return _h; }
};
};
}

template <
typename _dist_type,
typename _priority_queue,
typename _vertex_manager,
typename _vertex_allocator,
typename TCompoundVertex = EmptyVertexData,
bool euclidian_heuristics = true,
typename _data_storage_base = CVertexPath<euclidian_heuristics>,
typename _iteration_type = u32
typename _iteration_type = u32,
typename TVertexData = EmptyVertexData
> class CAStar : public CDijkstra<
_dist_type,
_priority_queue,
_vertex_manager,
_vertex_allocator,
TCompoundVertex,
euclidian_heuristics,
_data_storage_base,
_iteration_type
_iteration_type,
AStarVertexData<_dist_type, TVertexData>
>
{
protected:
Expand All @@ -58,12 +54,12 @@ template <
_priority_queue,
_vertex_manager,
_vertex_allocator,
TCompoundVertex,
euclidian_heuristics,
_data_storage_base,
_iteration_type
_iteration_type,
AStarVertexData<_dist_type, TVertexData>
> inherited;
typedef TCompoundVertex CGraphVertex;
typedef typename inherited::CGraphVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;

Expand Down
8 changes: 4 additions & 4 deletions src/xrAICore/Navigation/a_star_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
typename _priority_queue,\
typename _vertex_manager,\
typename _vertex_allocator,\
typename TCompoundVertex,\
bool euclidian_heuristics,\
typename _data_storage_base,\
typename _iteration_type\
typename _iteration_type,\
typename TVertexData\
>

#define CSAStar CAStar<\
_dist_type,\
_priority_queue,\
_vertex_manager,\
_vertex_allocator,\
TCompoundVertex,\
euclidian_heuristics,\
_data_storage_base,\
_iteration_type\
_iteration_type,\
TVertexData\
>

TEMPLATE_SPECIALIZATION
Expand Down
6 changes: 5 additions & 1 deletion src/xrAICore/Navigation/data_storage_constructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
#pragma once

struct EmptyVertexData
{};
{
template<typename TCompoundVertex> // result mixin type
struct VertexData
{};
};

template<typename... Components>
struct CompoundVertex : Components::template VertexData<CompoundVertex<Components...>>...
Expand Down
37 changes: 18 additions & 19 deletions src/xrAICore/Navigation/dijkstra.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,47 @@
#include "xrAICore/Navigation/vertex_path.h"
#include "xrAICore/Navigation/data_storage_constructor.h"

namespace Dijkstra
template<typename _dist_type, typename TVertexData>
struct DijkstraVertexData
{
template<typename _dist_type>
struct ByDistType
template<typename TCompoundVertex>
struct VertexData : TVertexData::template VertexData<TCompoundVertex>
{
template<typename TCompoundVertex>
struct VertexData
{
typedef _dist_type _dist_type;
typedef _dist_type _dist_type;

_dist_type _f;
TCompoundVertex *_back;
_dist_type _f;
TCompoundVertex *_back;

_dist_type &f() { return _f; }
const _dist_type &f() const { return _f; }
TCompoundVertex *&back() { return _back; }
};
};
}
_dist_type &f() { return _f; }
const _dist_type &f() const { return _f; }
TCompoundVertex *&back() { return _back; }
};
};

template <
typename _dist_type,
typename _priority_queue,
typename _vertex_manager,
typename _vertex_allocator,
typename TCompoundVertex = EmptyVertexData,
bool euclidian_heuristics = true,
typename _data_storage_base = CVertexPath<euclidian_heuristics>,
typename _iteration_type = u32
typename _iteration_type = u32,
typename TVertexData = EmptyVertexData
> class CDijkstra
{
public:
using CompoundVertex = CompoundVertex<DijkstraVertexData<_dist_type, TVertexData>,
_priority_queue, _vertex_manager, _vertex_allocator, _data_storage_base>;
typedef CDataStorageConstructor<
_priority_queue, // algorithm
_vertex_manager, // manager
_data_storage_base, // builder
_vertex_allocator, // allocator
TCompoundVertex
CompoundVertex
> CDataStorage;

protected:
typedef TCompoundVertex CGraphVertex;
typedef CompoundVertex CGraphVertex;
typedef typename CGraphVertex::_dist_type _dist_type;
typedef typename CGraphVertex::_index_type _index_type;

Expand Down
8 changes: 4 additions & 4 deletions src/xrAICore/Navigation/dijkstra_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
typename _priority_queue,\
typename _vertex_manager,\
typename _vertex_allocator,\
typename TCompoundVertex,\
bool euclidian_heuristics,\
typename _data_storage_base,\
typename _iteration_type\
typename _iteration_type,\
typename TVertexData\
>

#define CSDijkstra CDijkstra<\
_dist_type,\
_priority_queue,\
_vertex_manager,\
_vertex_allocator,\
TCompoundVertex,\
euclidian_heuristics,\
_data_storage_base,\
_iteration_type\
_iteration_type,\
TVertexData\
>

TEMPLATE_SPECIALIZATION
Expand Down
16 changes: 2 additions & 14 deletions src/xrAICore/Navigation/graph_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,33 @@ class CGraphEngine
using CStringVertexAllocator = CVertexAllocatorFixed<1024>;
#endif
using AlgorithmStorage = CVertexPath<true>;
using AlgorithmVertexData = AStar::template ByDistType<_dist_type>;
using AlgorithmVertex = CompoundVertex<AlgorithmVertexData,
CPriorityQueue, CVertexManager, CVertexAllocator, AlgorithmStorage>;
using CAlgorithm = CAStar<
using CAlgorithm = CAStar<
_dist_type,
CPriorityQueue,
CVertexManager,
CVertexAllocator,
AlgorithmVertex,
true,
AlgorithmStorage>;

#ifndef AI_COMPILER
using SolverAlgorithmStorage = CEdgePath<_solver_edge_type, true>;
using SolverAlgorithmVertexData = AStar::template ByDistType<_solver_dist_type>;
using SolverAlgorithmVertex = CompoundVertex<SolverAlgorithmVertexData,
CSolverPriorityQueue, CSolverVertexManager, CSolverVertexAllocator, SolverAlgorithmStorage>;
using CSolverAlgorithm = CAStar<
_solver_dist_type,
CSolverPriorityQueue,
CSolverVertexManager,
CSolverVertexAllocator,
SolverAlgorithmVertex,
true,
SolverAlgorithmStorage>;

using _string_dist_type = float;
using StringAlgorithmStorage = AlgorithmStorage;
using StringAlgorithmVertexData = AStar::template ByDistType<_string_dist_type>;
using StringAlgorithmVertex = CompoundVertex<StringAlgorithmVertexData,
CStringPriorityQueue, CStringVertexManager, CStringVertexAllocator, StringAlgorithmStorage>;
using CStringAlgorithm = CAStar<
_string_dist_type,
CStringPriorityQueue,
CStringVertexManager,
CStringVertexAllocator,
StringAlgorithmVertex,
true,
AlgorithmStorage>;
StringAlgorithmStorage>;
#endif // AI_COMPILER

CAlgorithm *m_algorithm;
Expand Down

0 comments on commit 98cc544

Please sign in to comment.