Skip to content

Commit

Permalink
WIP of xrAI and xrSE_Factory. Replace magical constants. Small code c…
Browse files Browse the repository at this point in the history
…leanup. Perhaps I fixed a strange bug (or not bug?) replacing level_graph().clear_mask(m_border) --> level_graph().clear_mask(m_internal).
  • Loading branch information
intorr committed Jan 1, 2018
1 parent b62d302 commit 893cd3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions src/utils/xrAI/space_restrictor_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ bool CSpaceRestrictorWrapper::inside(const Fvector& position, float radius) cons
{
switch (i.type)
{
case 0:
case CShapeData::cfSphere:
{
Fsphere temp;
m_xform.transform_tiny(temp.P, i.data.sphere.P);
temp.R = i.data.sphere.R;
if (sphere.intersect(temp))
return (true);
return true;

continue;
}
case 1:
case CShapeData::cfBox:
{
Fmatrix temp;
temp.mul_43(m_xform, i.data.box);
Expand Down Expand Up @@ -97,7 +97,7 @@ bool CSpaceRestrictorWrapper::inside(const Fvector& position, float radius) cons
plane.build(points[1], points[0], points[6]);
if (plane.classify(sphere.P) > sphere.R)
break;
return (true);
return true;
}
default: NODEFAULT;
}
Expand Down Expand Up @@ -135,15 +135,15 @@ void CSpaceRestrictorWrapper::fill_shape(const CShapeData::shape_def& shape)
Fvector start, dest;
switch (shape.type)
{
case 0:
case CShapeData::cfSphere:
{
start.sub(Fvector().set(shape.data.sphere.P), Fvector().set(shape.data.sphere.R, 0.f, shape.data.sphere.R));
dest.add(Fvector().set(shape.data.sphere.P), Fvector().set(shape.data.sphere.R, 0.f, shape.data.sphere.R));
start.add(object().o_Position);
dest.add(object().o_Position);
break;
}
case 1:
case CShapeData::cfBox:
{
Fvector points[8] = {Fvector().set(-.5f, -.5f, -.5f), Fvector().set(-.5f, -.5f, +.5f),
Fvector().set(-.5f, +.5f, -.5f), Fvector().set(-.5f, +.5f, +.5f), Fvector().set(+.5f, -.5f, -.5f),
Expand Down Expand Up @@ -207,7 +207,6 @@ struct sort_by_xz_predicate

void CSpaceRestrictorWrapper::build_border()
{
typedef CShapeData::ShapeVec ShapeVec;
for (auto &i : object().shapes)
fill_shape(i);

Expand Down Expand Up @@ -246,27 +245,30 @@ void CSpaceRestrictorWrapper::verify_connectivity()

if (!level_graph().valid_vertex_id(start_vertex_id))
{
Msg("Warning : restrictor %s covers the whole AI map");
Msg("Warning : restrictor %s covers the whole AI map", object().name_replace());
return;
}

level_graph().set_mask(m_border);
//level_graph().set_mask(m_border);
level_graph().set_mask(m_internal);

xr_vector<u32> nodes;

graph_engine().search(level_graph(), start_vertex_id, start_vertex_id, &nodes,
GraphEngineSpace::CFlooder(GraphEngineSpace::_dist_type(6000), GraphEngineSpace::_iteration_type(-1), u32(-1)));

level_graph().clear_mask(m_border);
//level_graph().clear_mask(m_border);
level_graph().clear_mask(m_internal);

VERIFY(nodes.size() + m_internal.size() <= level_graph().header().vertex_count());
if (nodes.size() + m_internal.size() == level_graph().header().vertex_count())
return;

Msg("! %d nodes are disconnected!", level_graph().header().vertex_count() - (nodes.size() + m_internal.size()));
Msg("! %7d nodes are disconnected! Restrictor '%s' separates AI map into several disconnected components",
level_graph().header().vertex_count() - (nodes.size() + m_internal.size()), object().name_replace());

R_ASSERT3(nodes.size() + m_internal.size() == level_graph().header().vertex_count(),
"Restrictor separates AI map into several disconnected components", object().name_replace());
//R_ASSERT3(nodes.size() + m_internal.size() == level_graph().header().vertex_count(),
// "Restrictor separates AI map into several disconnected components", object().name_replace());
}

void CSpaceRestrictorWrapper::verify(CLevelGraph& level_graph, CGraphEngine& graph_engine, bool no_separator_check)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrAI/xrAI_Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The following keys are supported / required:
-s <NAME,...> == build game spawn data
-out <FILE> == name of output file (default: 'NAME.spawn')
-start <NAME> == name of game start level
-no_separator_check == do not verify connectivity between levels
-no_separator_check == do not verify that restrictors separates AI map into several disconnected components
-verify <NAME> == verify compiled 'level.ai'
-noverbose == do not print all single linked vertices (print only count)

Expand Down

0 comments on commit 893cd3f

Please sign in to comment.