Skip to content

Commit

Permalink
Reformat: xrAICore
Browse files Browse the repository at this point in the history
  • Loading branch information
invokr committed Jan 15, 2017
1 parent 521f856 commit 3dbacd3
Show file tree
Hide file tree
Showing 97 changed files with 5,491 additions and 6,256 deletions.
88 changes: 41 additions & 47 deletions src/xrAICore/AISpaceBase.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "PCH.hpp"
#include "AISpaceBase.hpp"
#include "Include/xrAPI/xrAPI.h"
#include "Navigation/PatrolPath/patrol_path_storage.h"
#include "Navigation/game_graph.h"
#include "Navigation/level_graph.h"
#include "Navigation/graph_engine.h"
#include "Navigation/PatrolPath/patrol_path_storage.h"
#include "Include/xrAPI/xrAPI.h"
#include "Navigation/level_graph.h"
#include "PCH.hpp"

AISpaceBase::AISpaceBase()
{
Expand All @@ -19,38 +19,34 @@ AISpaceBase::~AISpaceBase()
GlobalEnv.AISpace = nullptr;
}

void AISpaceBase::Load(const char *levelName)
void AISpaceBase::Load(const char* levelName)
{
const CGameGraph::SLevel &currentLevel = game_graph().header().level(levelName);
const CGameGraph::SLevel& currentLevel = game_graph().header().level(levelName);
m_level_graph = new CLevelGraph();
game_graph().set_current_level(currentLevel.id());
auto &crossHeader = cross_table().header();
auto &levelHeader = level_graph().header();
auto &gameHeader = game_graph().header();
R_ASSERT2(crossHeader.level_guid()==levelHeader.guid(), "cross_table doesn't correspond to the AI-map");
R_ASSERT2(crossHeader.game_guid()==gameHeader.guid(), "graph doesn't correspond to the cross table");
auto& crossHeader = cross_table().header();
auto& levelHeader = level_graph().header();
auto& gameHeader = game_graph().header();
R_ASSERT2(crossHeader.level_guid() == levelHeader.guid(), "cross_table doesn't correspond to the AI-map");
R_ASSERT2(crossHeader.game_guid() == gameHeader.guid(), "graph doesn't correspond to the cross table");
u32 vertexCount = _max(gameHeader.vertex_count(), levelHeader.vertex_count());
m_graph_engine = new CGraphEngine(vertexCount);
R_ASSERT2(currentLevel.guid()==levelHeader.guid(), "graph doesn't correspond to the AI-map");
if (!xr_strcmp(currentLevel.name(), levelName))
Validate(currentLevel.id());
R_ASSERT2(currentLevel.guid() == levelHeader.guid(), "graph doesn't correspond to the AI-map");
if (!xr_strcmp(currentLevel.name(), levelName)) Validate(currentLevel.id());
level_graph().level_id(currentLevel.id());
}

void AISpaceBase::Unload(bool reload)
{
if (g_dedicated_server)
return;
if (g_dedicated_server) return;
xr_delete(m_graph_engine);
xr_delete(m_level_graph);
if (!reload && m_game_graph)
m_graph_engine = new CGraphEngine(game_graph().header().vertex_count());
if (!reload && m_game_graph) m_graph_engine = new CGraphEngine(game_graph().header().vertex_count());
}

void AISpaceBase::Initialize()
{
if (g_dedicated_server)
return;
if (g_dedicated_server) return;
VERIFY(!m_graph_engine);
m_graph_engine = new CGraphEngine(1024);
VERIFY(!m_patrol_path_storage);
Expand All @@ -60,58 +56,52 @@ void AISpaceBase::Initialize()
void AISpaceBase::Validate(u32 levelId) const
{
#ifdef DEBUG
VERIFY(level_graph().header().vertex_count()==cross_table().header().level_vertex_count());
for (GameGraph::_GRAPH_ID i = 0, n = game_graph().header().vertex_count(); i<n; i++)
VERIFY(level_graph().header().vertex_count() == cross_table().header().level_vertex_count());
for (GameGraph::_GRAPH_ID i = 0, n = game_graph().header().vertex_count(); i < n; i++)
{
const GameGraph::CVertex &vertex = *game_graph().vertex(i);
if (levelId!=vertex.level_id())
continue;
const GameGraph::CVertex& vertex = *game_graph().vertex(i);
if (levelId != vertex.level_id()) continue;
u32 vid = vertex.level_vertex_id();
if (!level_graph().valid_vertex_id(vid) ||
cross_table().vertex(vid).game_vertex_id()!=i ||
if (!level_graph().valid_vertex_id(vid) || cross_table().vertex(vid).game_vertex_id() != i ||
!level_graph().inside(vid, vertex.level_point()))
{
Msg("! Graph doesn't correspond to the cross table");
R_ASSERT2(false, "Graph doesn't correspond to the cross table");
}
}
//Msg("death graph point id : %d", cross_table().vertex(455236).game_vertex_id());
for (u32 i = 0, n = game_graph().header().vertex_count(); i<n; i++)
// Msg("death graph point id : %d", cross_table().vertex(455236).game_vertex_id());
for (u32 i = 0, n = game_graph().header().vertex_count(); i < n; i++)
{
if (levelId!=game_graph().vertex(i)->level_id())
continue;
if (levelId != game_graph().vertex(i)->level_id()) continue;
CGameGraph::const_spawn_iterator it, end;
game_graph().begin_spawn(i, it, end);
//Msg("vertex [%d] has %d death points", i, game_graph().vertex(i)->death_point_count());
for (; it!=end; it++)
// Msg("vertex [%d] has %d death points", i, game_graph().vertex(i)->death_point_count());
for (; it != end; it++)
VERIFY(cross_table().vertex(it->level_vertex_id()).game_vertex_id() == i);
}
//Msg("* Graph corresponds to the cross table");
// Msg("* Graph corresponds to the cross table");
#endif
}

void AISpaceBase::patrol_path_storage_raw(IReader &stream)
void AISpaceBase::patrol_path_storage_raw(IReader& stream)
{
if (g_dedicated_server)
return;
if (g_dedicated_server) return;
xr_delete(m_patrol_path_storage);
m_patrol_path_storage = new CPatrolPathStorage();
m_patrol_path_storage->load_raw(get_level_graph(), get_cross_table(), get_game_graph(), stream);
}

void AISpaceBase::patrol_path_storage(IReader &stream)
void AISpaceBase::patrol_path_storage(IReader& stream)
{
if (g_dedicated_server)
return;
if (g_dedicated_server) return;
xr_delete(m_patrol_path_storage);
m_patrol_path_storage = new CPatrolPathStorage();
m_patrol_path_storage->load(stream);
}

void AISpaceBase::SetGameGraph(CGameGraph *gameGraph)
void AISpaceBase::SetGameGraph(CGameGraph* gameGraph)
{
if (gameGraph)
{
if (gameGraph) {
VERIFY(!m_game_graph);
m_game_graph = gameGraph;
xr_delete(m_graph_engine);
Expand All @@ -125,8 +115,12 @@ void AISpaceBase::SetGameGraph(CGameGraph *gameGraph)
}
}

const CGameLevelCrossTable &AISpaceBase::cross_table() const
{ return game_graph().cross_table(); }
const CGameLevelCrossTable& AISpaceBase::cross_table() const
{
return game_graph().cross_table();
}

const CGameLevelCrossTable *AISpaceBase::get_cross_table() const
{ return &game_graph().cross_table(); }
const CGameLevelCrossTable* AISpaceBase::get_cross_table() const
{
return &game_graph().cross_table();
}
59 changes: 33 additions & 26 deletions src/xrAICore/AISpaceBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,67 @@ class CPatrolPathStorage;
class XRAICORE_API AISpaceBase
{
protected:
CGameGraph *m_game_graph = nullptr; // not owned by AISpaceBase
CLevelGraph *m_level_graph = nullptr;
CGraphEngine *m_graph_engine = nullptr;
CPatrolPathStorage *m_patrol_path_storage = nullptr;
CGameGraph* m_game_graph = nullptr; // not owned by AISpaceBase
CLevelGraph* m_level_graph = nullptr;
CGraphEngine* m_graph_engine = nullptr;
CPatrolPathStorage* m_patrol_path_storage = nullptr;

protected:
AISpaceBase();
void Load(const char *levelName);
void Load(const char* levelName);
void Unload(bool reload);
void Initialize();
void Validate(u32 levelId) const;
void patrol_path_storage_raw(IReader &stream);
void patrol_path_storage(IReader &stream);
void SetGameGraph(CGameGraph *gameGraph);
[[deprecated("This function is deprecated. Use AISpaceBase::SetGameGraph() instead.")]]
void game_graph(CGameGraph *g) { SetGameGraph(g); }
void patrol_path_storage_raw(IReader& stream);
void patrol_path_storage(IReader& stream);
void SetGameGraph(CGameGraph* gameGraph);
[[deprecated("This function is deprecated. Use AISpaceBase::SetGameGraph() instead.")]] void game_graph(
CGameGraph* g)
{
SetGameGraph(g);
}

public:
~AISpaceBase();
inline CGameGraph &game_graph() const;
inline CGameGraph *get_game_graph() const;
inline CLevelGraph &level_graph() const;
inline const CLevelGraph *get_level_graph() const;
const CGameLevelCrossTable &cross_table() const;
const CGameLevelCrossTable *get_cross_table() const;
inline const CPatrolPathStorage &patrol_paths() const;
inline CGraphEngine &graph_engine() const;
inline CGameGraph& game_graph() const;
inline CGameGraph* get_game_graph() const;
inline CLevelGraph& level_graph() const;
inline const CLevelGraph* get_level_graph() const;
const CGameLevelCrossTable& cross_table() const;
const CGameLevelCrossTable* get_cross_table() const;
inline const CPatrolPathStorage& patrol_paths() const;
inline CGraphEngine& graph_engine() const;
};

inline CGameGraph &AISpaceBase::game_graph() const
inline CGameGraph& AISpaceBase::game_graph() const
{
VERIFY(m_game_graph);
return *m_game_graph;
}

inline CGameGraph *AISpaceBase::get_game_graph() const
{ return m_game_graph; }
inline CGameGraph* AISpaceBase::get_game_graph() const
{
return m_game_graph;
}

inline CLevelGraph &AISpaceBase::level_graph() const
inline CLevelGraph& AISpaceBase::level_graph() const
{
VERIFY(m_level_graph);
return *m_level_graph;
}

inline const CLevelGraph *AISpaceBase::get_level_graph() const
{ return m_level_graph; }
inline const CLevelGraph* AISpaceBase::get_level_graph() const
{
return m_level_graph;
}

inline CGraphEngine &AISpaceBase::graph_engine() const
inline CGraphEngine& AISpaceBase::graph_engine() const
{
VERIFY(m_graph_engine);
return *m_graph_engine;
}

inline const CPatrolPathStorage &AISpaceBase::patrol_paths() const
inline const CPatrolPathStorage& AISpaceBase::patrol_paths() const
{
VERIFY(m_patrol_path_storage);
return *m_patrol_path_storage;
Expand Down
40 changes: 21 additions & 19 deletions src/xrAICore/Components/condition_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@
#include "xrAICore/Components/operator_condition.h"

template <typename _world_property>
class CConditionState {
class CConditionState
{
public:
typedef _world_property COperatorCondition;
typedef _world_property COperatorCondition;

protected:
xr_vector<COperatorCondition> m_conditions;
u32 m_hash;
xr_vector<COperatorCondition> m_conditions;
u32 m_hash;

public:
IC CConditionState ();
IC virtual ~CConditionState ();
IC const xr_vector<COperatorCondition> &conditions () const;
IC u8 weight (const CConditionState &condition) const;
IC void add_condition (const COperatorCondition &condition);
IC void remove_condition (const typename COperatorCondition::_condition_type &condition);
IC void add_condition (typename xr_vector<COperatorCondition>::const_iterator &J, const COperatorCondition &condition);
IC void add_condition_back (const COperatorCondition &condition);
IC bool includes (const CConditionState &condition) const;
IC void clear ();
IC bool operator< (const CConditionState &condition) const;
IC CConditionState<_world_property> &operator-= (const CConditionState &condition);
IC bool operator== (const CConditionState &condition) const;
IC u32 hash_value () const;
IC const COperatorCondition *property (const typename COperatorCondition::_condition_type &condition) const;
IC CConditionState();
IC virtual ~CConditionState();
IC const xr_vector<COperatorCondition>& conditions() const;
IC u8 weight(const CConditionState& condition) const;
IC void add_condition(const COperatorCondition& condition);
IC void remove_condition(const typename COperatorCondition::_condition_type& condition);
IC void add_condition(
typename xr_vector<COperatorCondition>::const_iterator& J, const COperatorCondition& condition);
IC void add_condition_back(const COperatorCondition& condition);
IC bool includes(const CConditionState& condition) const;
IC void clear();
IC bool operator<(const CConditionState& condition) const;
IC CConditionState<_world_property>& operator-=(const CConditionState& condition);
IC bool operator==(const CConditionState& condition) const;
IC u32 hash_value() const;
IC const COperatorCondition* property(const typename COperatorCondition::_condition_type& condition) const;
};

#include "xrAICore/Components/condition_state_inline.h"
Loading

0 comments on commit 3dbacd3

Please sign in to comment.