diff --git a/src/xrAICore/Navigation/graph_engine.h b/src/xrAICore/Navigation/graph_engine.h index f1f70f2c3c6..cdf0625414c 100644 --- a/src/xrAICore/Navigation/graph_engine.h +++ b/src/xrAICore/Navigation/graph_engine.h @@ -1,9 +1,9 @@ //////////////////////////////////////////////////////////////////////////// -// Module : graph_engine.h -// Created : 21.03.2002 -// Modified : 26.11.2003 -// Author : Dmitriy Iassenev -// Description : Graph engine +// Module : graph_engine.h +// Created : 21.03.2002 +// Modified : 26.11.2003 +// Author : Dmitriy Iassenev +// Description : Graph engine //////////////////////////////////////////////////////////////////////////// #pragma once @@ -26,9 +26,7 @@ namespace hash_fixed_vertex_manager { inline u32 to_u32(const GraphEngineSpace::CWorldState &other) -{ - return other.hash_value(); -} +{ return other.hash_value(); } } using namespace GraphEngineSpace; @@ -56,7 +54,10 @@ class CGraphEngine #ifndef AI_COMPILER // solver algorithm - using CSolverPriorityQueue = CDataStorageBinaryHeap; + static const size_t SolverMaxVertexCount = 16*1024; + using CSolverPriorityQueue = CDataStorageBinaryHeap; + // XXX: originally CSolverAlgorithm is constructed with 16*1024 limit + // while the following definitions use 8*1024 limit -- check if that's a mistake using CSolverVertexManager = CVertexManagerHashFixed; using CSolverVertexAllocator = CVertexAllocatorFixed<8*1024>; using SolverAlgorithmStorage = CEdgePath<_solver_edge_type, true>; @@ -68,12 +69,13 @@ class CGraphEngine true, SolverAlgorithmStorage>; // string algorithm + static const size_t StringMaxVertexCount = 1024; using CStringPriorityQueue = CDataStorageBinaryHeap; - using CStringVertexManager = CVertexManagerHashFixed; - using CStringVertexAllocator = CVertexAllocatorFixed<1024>; + using CStringVertexManager = CVertexManagerHashFixed; + using CStringVertexAllocator = CVertexAllocatorFixed; using StringAlgorithmStorage = AlgorithmStorage; using StringAlgorithmDistance = float; - using CStringAlgorithm = CAStar< + using CStringAlgorithm = CAStar< StringAlgorithmDistance, CStringPriorityQueue, CStringVertexManager, @@ -82,63 +84,43 @@ class CGraphEngine StringAlgorithmStorage>; #endif // AI_COMPILER - CAlgorithm *m_algorithm; + CAlgorithm *m_algorithm; #ifndef AI_COMPILER - CSolverAlgorithm *m_solver_algorithm; - CStringAlgorithm *m_string_algorithm; + CSolverAlgorithm *m_solver_algorithm; + CStringAlgorithm *m_string_algorithm; #endif CStatTimer PathTimer; public: - inline CGraphEngine(u32 max_vertex_count); - virtual ~CGraphEngine(); + inline CGraphEngine(u32 max_vertex_count); + virtual ~CGraphEngine(); #ifndef AI_COMPILER - inline const CSolverAlgorithm &solver_algorithm() const; + inline const CSolverAlgorithm &solver_algorithm() const; #endif - template - inline bool search( - const _Graph &graph, - const shared_str &start_node, - const shared_str &dest_node, - xr_vector *node_path, - _Parameters ¶meters); + template + inline bool search(const _Graph &graph, const shared_str &start_node, const shared_str &dest_node, + xr_vector *node_path, _Parameters ¶meters); - template - inline bool search( - const _Graph &graph, - const _index_type &start_node, - const _index_type &dest_node, - xr_vector<_index_type> *node_path, - const _Parameters ¶meters); + template + inline bool search(const _Graph &graph, const _index_type &start_node, const _index_type &dest_node, + xr_vector<_index_type> *node_path, const _Parameters ¶meters); - template - inline bool search( - const _Graph &graph, - const _index_type &start_node, - const _index_type &dest_node, - xr_vector<_index_type> *node_path, - _Parameters ¶meters); + template + inline bool search(const _Graph &graph, const _index_type &start_node, const _index_type &dest_node, + xr_vector<_index_type> *node_path, _Parameters ¶meters); - template - inline bool search( - const _Graph &graph, - const _index_type &start_node, - const _index_type &dest_node, - xr_vector<_index_type> *node_path, - const _Parameters ¶meters, - _PathManager &path_manager); + template + inline bool search(const _Graph &graph, const _index_type &start_node, const _index_type &dest_node, + xr_vector<_index_type> *node_path, const _Parameters ¶meters, _PathManager &path_manager); #ifndef AI_COMPILER - template - inline bool search( - const CProblemSolver &graph, - const _solver_index_type &start_node, - const _solver_index_type &dest_node, - xr_vector<_solver_edge_type> *node_path, - const _Parameters ¶meters); + template + inline bool search(const CProblemSolver &graph, + const _solver_index_type &start_node, const _solver_index_type &dest_node, + xr_vector<_solver_edge_type> *node_path, const _Parameters ¶meters); #endif }; diff --git a/src/xrAICore/Navigation/graph_engine_inline.h b/src/xrAICore/Navigation/graph_engine_inline.h index a0618beba67..079790e0f62 100644 --- a/src/xrAICore/Navigation/graph_engine_inline.h +++ b/src/xrAICore/Navigation/graph_engine_inline.h @@ -1,212 +1,128 @@ //////////////////////////////////////////////////////////////////////////// -// Module : graph_engine_inline.h -// Created : 21.03.2002 -// Modified : 03.03.2004 -// Author : Dmitriy Iassenev -// Description : Graph engine inline functions +// Module : graph_engine_inline.h +// Created : 21.03.2002 +// Modified : 03.03.2004 +// Author : Dmitriy Iassenev +// Description : Graph engine inline functions //////////////////////////////////////////////////////////////////////////// #pragma once -IC CGraphEngine::CGraphEngine (u32 max_vertex_count) +inline CGraphEngine::CGraphEngine(u32 max_vertex_count) { - m_algorithm = xr_new (max_vertex_count); - m_algorithm->data_storage().set_min_bucket_value (_dist_type(0)); - m_algorithm->data_storage().set_max_bucket_value (_dist_type(2000)); - + m_algorithm = xr_new(max_vertex_count); + m_algorithm->data_storage().set_min_bucket_value(_dist_type(0)); + m_algorithm->data_storage().set_max_bucket_value(_dist_type(2000)); #ifndef AI_COMPILER - m_solver_algorithm = xr_new (16*1024); - m_string_algorithm = xr_new (1024); -#endif // AI_COMPILER + m_solver_algorithm = xr_new(SolverMaxVertexCount); + m_string_algorithm = xr_new(StringMaxVertexCount); +#endif } -IC CGraphEngine::~CGraphEngine () +inline CGraphEngine::~CGraphEngine() { - xr_delete (m_algorithm); + xr_delete(m_algorithm); #ifndef AI_COMPILER - xr_delete (m_solver_algorithm); - xr_delete (m_string_algorithm); -#endif // AI_COMPILER + xr_delete(m_solver_algorithm); + xr_delete(m_string_algorithm); +#endif } #ifndef AI_COMPILER -IC const CGraphEngine::CSolverAlgorithm &CGraphEngine::solver_algorithm() const -{ - return (*m_solver_algorithm); -} -#endif // AI_COMPILER +inline const CGraphEngine::CSolverAlgorithm &CGraphEngine::solver_algorithm() const +{ return *m_solver_algorithm; } +#endif -template < - typename _Graph, - typename _Parameters -> -IC bool CGraphEngine::search ( - const _Graph &graph, - const _index_type &start_node, - const _index_type &dest_node, - xr_vector<_index_type> *node_path, - const _Parameters ¶meters - ) +template +inline bool CGraphEngine::search(const _Graph &graph, const _index_type &start_node, const _index_type &dest_node, + xr_vector<_index_type> *node_path, const _Parameters ¶meters) { - START_PROFILE("graph_engine") - START_PROFILE("graph_engine/search") + START_PROFILE("graph_engine") + START_PROFILE("graph_engine/search") PathTimer.Begin(); - typedef CPathManager<_Graph, CAlgorithm::CDataStorage, _Parameters, _dist_type,_index_type,_iteration_type> CPathManagerGeneric; - - CPathManagerGeneric path_manager; - - path_manager.setup ( - &graph, - &m_algorithm->data_storage(), - node_path, - start_node, - dest_node, - parameters - ); - - bool successfull = m_algorithm->find(path_manager); + using CPathManagerGeneric = CPathManager< + _Graph, CAlgorithm::CDataStorage, _Parameters, _dist_type, _index_type, _iteration_type>; + CPathManagerGeneric path_manager; + path_manager.setup(&graph, &m_algorithm->data_storage(), node_path, start_node, dest_node, parameters); + bool successfull = m_algorithm->find(path_manager); PathTimer.End(); - return (successfull); - STOP_PROFILE - STOP_PROFILE + return successfull; + STOP_PROFILE + STOP_PROFILE } -template < - typename _Graph, - typename _Parameters -> -IC bool CGraphEngine::search ( - const _Graph &graph, - const _index_type &start_node, - const _index_type &dest_node, - xr_vector<_index_type> *node_path, - _Parameters ¶meters - ) +template +inline bool CGraphEngine::search(const _Graph &graph, const _index_type &start_node, const _index_type &dest_node, + xr_vector<_index_type> *node_path, _Parameters ¶meters) { - START_PROFILE("graph_engine") - START_PROFILE("graph_engine/search") + START_PROFILE("graph_engine") + START_PROFILE("graph_engine/search") PathTimer.Begin(); - typedef CPathManager<_Graph, CAlgorithm::CDataStorage, _Parameters, _dist_type,_index_type,_iteration_type> CPathManagerGeneric; - - CPathManagerGeneric path_manager; - - path_manager.setup ( - &graph, - &m_algorithm->data_storage(), - node_path, - start_node, - dest_node, - parameters - ); - - bool successfull = m_algorithm->find(path_manager); + using CPathManagerGeneric = CPathManager< + _Graph, CAlgorithm::CDataStorage, _Parameters, _dist_type, _index_type, _iteration_type>; + CPathManagerGeneric path_manager; + path_manager.setup(&graph, &m_algorithm->data_storage(), node_path, start_node, dest_node, parameters); + bool successfull = m_algorithm->find(path_manager); PathTimer.End(); - return (successfull); - STOP_PROFILE - STOP_PROFILE + return successfull; + STOP_PROFILE + STOP_PROFILE } -template < - typename _Graph, - typename _Parameters, - typename _PathManager -> -IC bool CGraphEngine::search ( - const _Graph &graph, - const _index_type &start_node, - const _index_type &dest_node, - xr_vector<_index_type> *node_path, - const _Parameters ¶meters, - _PathManager &path_manager - ) +template +inline bool CGraphEngine::search(const _Graph &graph, const _index_type &start_node, const _index_type &dest_node, + xr_vector<_index_type> *node_path, const _Parameters ¶meters, _PathManager &path_manager) { - START_PROFILE("graph_engine") - START_PROFILE("graph_engine/search") + START_PROFILE("graph_engine") + START_PROFILE("graph_engine/search") PathTimer.Begin(); - path_manager.setup ( - &graph, - &m_algorithm->data_storage(), - node_path, - start_node, - dest_node, - parameters - ); - - bool successfull = m_algorithm->find(path_manager); + path_manager.setup(&graph, &m_algorithm->data_storage(), node_path, start_node, dest_node, parameters); + bool successfull = m_algorithm->find(path_manager); PathTimer.End(); - return (successfull); - STOP_PROFILE - STOP_PROFILE + return successfull; + STOP_PROFILE + STOP_PROFILE } #ifndef AI_COMPILER template -inline bool CGraphEngine::search( - const CProblemSolver &graph, - const _solver_index_type &start_node, - const _solver_index_type &dest_node, - xr_vector<_solver_edge_type> *node_path, - const _Parameters ¶meters) + typename T5, bool T6, typename T7, typename T8, typename _Parameters> +inline bool CGraphEngine::search(const CProblemSolver &graph, + const _solver_index_type &start_node, const _solver_index_type &dest_node, + xr_vector<_solver_edge_type> *node_path, const _Parameters ¶meters) { - START_PROFILE("graph_engine") - START_PROFILE("graph_engine/proble_solver") + START_PROFILE("graph_engine") + START_PROFILE("graph_engine/proble_solver") PathTimer.Begin(); - typedef CProblemSolver CSProblemSolver; - typedef CPathManager CSolverPathManager; - - CSolverPathManager path_manager; - - path_manager.setup ( - &graph, - &m_solver_algorithm->data_storage(), - node_path, - start_node, - dest_node, - parameters - ); - - bool successfull = m_solver_algorithm->find(path_manager); + using CSProblemSolver = CProblemSolver; + using CSolverPathManager = CPathManager< + CSProblemSolver, CSolverAlgorithm::CDataStorage, _Parameters, + _solver_dist_type, _solver_index_type, GraphEngineSpace::_iteration_type>; + CSolverPathManager path_manager; + path_manager.setup(&graph, &m_solver_algorithm->data_storage(), node_path, start_node, dest_node, parameters); + bool successfull = m_solver_algorithm->find(path_manager); PathTimer.End(); - return (successfull); - STOP_PROFILE - STOP_PROFILE + return successfull; + STOP_PROFILE + STOP_PROFILE } -template < - typename _Graph, - typename _Parameters -> -IC bool CGraphEngine::search ( - const _Graph &graph, - const shared_str &start_node, - const shared_str &dest_node, - xr_vector *node_path, - _Parameters ¶meters - ) +template +inline bool CGraphEngine::search(const _Graph &graph, const shared_str &start_node, const shared_str &dest_node, + xr_vector *node_path, _Parameters ¶meters) { - START_PROFILE("graph_engine") - START_PROFILE("graph_engine/search") + START_PROFILE("graph_engine") + START_PROFILE("graph_engine/search") PathTimer.Begin(); - typedef CPathManager<_Graph, CStringAlgorithm::CDataStorage, _Parameters, float, shared_str,u32> CPathManagerGeneric; - - CPathManagerGeneric path_manager; - - path_manager.setup ( - &graph, - &m_string_algorithm->data_storage(), - node_path, - start_node, - dest_node, - parameters - ); - - bool successfull = m_string_algorithm->find(path_manager); - + using CPathManagerGeneric = CPathManager< + _Graph, CStringAlgorithm::CDataStorage, _Parameters, float, shared_str, u32>; + CPathManagerGeneric path_manager; + path_manager.setup(&graph, &m_string_algorithm->data_storage(), node_path, start_node, dest_node, parameters); + bool successfull = m_string_algorithm->find(path_manager); PathTimer.End(); - return (successfull); - STOP_PROFILE - STOP_PROFILE + return successfull; + STOP_PROFILE + STOP_PROFILE } #endif // AI_COMPILER diff --git a/src/xrAICore/Navigation/graph_engine_space.h b/src/xrAICore/Navigation/graph_engine_space.h index d3551e0f6e5..7c9dcddf490 100644 --- a/src/xrAICore/Navigation/graph_engine_space.h +++ b/src/xrAICore/Navigation/graph_engine_space.h @@ -1,150 +1,87 @@ //////////////////////////////////////////////////////////////////////////// -// Module : graph_engine_space.h -// Created : 21.03.2002 -// Modified : 26.11.2003 -// Author : Dmitriy Iassenev -// Description : Graph engine +// Module : graph_engine_space.h +// Created : 21.03.2002 +// Modified : 26.11.2003 +// Author : Dmitriy Iassenev +// Description : Graph engine //////////////////////////////////////////////////////////////////////////// #pragma once #include "xrCore/xrCore.h" -template < - typename _condition_type, - typename _value_type -> +template class COperatorConditionAbstract; -template < - typename _world_property -> +template class CConditionState; -template < - typename _world_property, - typename _edge_value_type -> +template class COperatorAbstract; -template < - typename _dist_type, - typename _index_type, - typename _iteration_type -> +template struct SBaseParameters; -template < - typename _dist_type, - typename _index_type, - typename _iteration_type -> -struct SFlooder ; - -template < - typename _dist_type, - typename _index_type, - typename _iteration_type -> +template +struct SFlooder; + +template struct SStraightLineParams; -template < - typename _dist_type, - typename _index_type, - typename _iteration_type -> +template struct SNearestVertex; -template < - typename _dist_type, - typename _index_type, - typename _iteration_type -> +template struct SGameLevel; -template < - typename _dist_type, - typename _index_type, - typename _iteration_type -> +template struct SGameVertex; -namespace GraphEngineSpace { - typedef float _dist_type; - typedef u32 _index_type; - typedef u32 _iteration_type; - typedef u16 _solver_dist_type; - typedef u32 _solver_condition_type; - typedef bool _solver_value_type; - - struct CSolverConditionValue { - _solver_condition_type m_condition; - _solver_value_type m_value; - - IC CSolverConditionValue (const _solver_condition_type &condition, const _solver_value_type &value) - { - m_condition = condition; - m_value = value; - } - - IC bool operator== (const _solver_condition_type &condition) const - { - return (condition == m_condition); - } - }; - - typedef xr_vector CSolverConditionStorage; - - typedef COperatorConditionAbstract< - _solver_condition_type, - _solver_value_type - > CWorldProperty; - - typedef CConditionState< - CWorldProperty - > CWorldState; - - typedef COperatorAbstract< - CWorldProperty, - _solver_dist_type - > CWorldOperator; - - typedef CWorldState _solver_index_type; - typedef u32 _solver_edge_type; - - typedef SBaseParameters< - _solver_dist_type, - _solver_index_type, - _iteration_type - > CSolverBaseParameters; - typedef SBaseParameters< - _dist_type, - _index_type, - _iteration_type - > CBaseParameters; - - typedef SFlooder< - _dist_type, - _index_type, - _iteration_type - > CFlooder; - typedef SStraightLineParams< - _dist_type, - _index_type, - _iteration_type - > CStraightLineParams; - typedef SNearestVertex< - _dist_type, - _index_type, - _iteration_type - > CNearestVertexParameters; - typedef SGameLevel< - _dist_type, - _index_type, - _iteration_type - > CGameLevelParams; - typedef SGameVertex< - _dist_type, - _index_type, - _iteration_type - > CGameVertexParams; +namespace GraphEngineSpace +{ + using _dist_type = float; + using _index_type = u32; + using _iteration_type = u32; + using _solver_dist_type = u16; + using _solver_condition_type = u32; + using _solver_value_type = bool; + + struct CSolverConditionValue + { + _solver_condition_type m_condition; + _solver_value_type m_value; + + CSolverConditionValue(const _solver_condition_type &condition, const _solver_value_type &value) + { + m_condition = condition; + m_value = value; + } + + bool operator==(const _solver_condition_type &condition) const + { return condition==m_condition; } + }; + + using CSolverConditionStorage = xr_vector; + + using CWorldProperty = COperatorConditionAbstract<_solver_condition_type, _solver_value_type>; + + using CWorldState = CConditionState; + + using CWorldOperator = COperatorAbstract; + + using _solver_index_type = CWorldState; + using _solver_edge_type = u32; + + using CSolverBaseParameters = SBaseParameters<_solver_dist_type, _solver_index_type, _iteration_type>; + + using CBaseParameters = SBaseParameters<_dist_type, _index_type, _iteration_type>; + + using CFlooder = SFlooder<_dist_type, _index_type, _iteration_type>; + + using CStraightLineParams = SStraightLineParams<_dist_type, _index_type, _iteration_type>; + + using CNearestVertexParameters = SNearestVertex<_dist_type, _index_type, _iteration_type>; + + using CGameLevelParams = SGameLevel<_dist_type, _index_type, _iteration_type>; + + using CGameVertexParams = SGameVertex<_dist_type, _index_type, _iteration_type>; };