Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves several compile warnings when comparing different int signedness #1755

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/xrAICore/Navigation/level_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class XRAICORE_API CLevelGraph
ICF u32 vertex(const CLevelVertex& vertex_r) const;
IC const Fvector vertex_position(const CLevelGraph::CPosition& source_position) const;
IC const Fvector& vertex_position(Fvector& dest_position, const CLevelGraph::CPosition& source_position) const;
IC int calculate_packed_xz(const float x, const float z) const;
IC const CLevelGraph::CPosition& vertex_position(
CLevelGraph::CPosition& dest_position, const Fvector& source_position) const;
IC const CLevelGraph::CPosition vertex_position(const Fvector& position) const;
Expand Down Expand Up @@ -196,7 +197,7 @@ class XRAICORE_API CLevelGraph
template <class _predicate>
IC float vertex_low_cover_angle(u32 vertex_id, float inc_angle, _predicate compare_predicate) const;
IC void set_invalid_vertex(u32& vertex_id, CLevelVertex** vertex = NULL) const;
IC const u32 vertex_id(const CLevelGraph::CLevelVertex* vertex) const;
IC u32 vertex_id(const CLevelGraph::CLevelVertex* vertex) const;
u32 vertex_id(const Fvector& position) const;

private:
Expand Down
31 changes: 14 additions & 17 deletions src/xrAICore/Navigation/level_graph_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,23 @@ ICF const Fvector& CLevelGraph::vertex_position(
return (dest_position = vertex_position(source_position));
}

// XXX: This method is WAY to large to inline.
IC const CLevelGraph::CPosition& CLevelGraph::vertex_position(CPosition& dest_position, const Fvector& source_position) const
IC int CLevelGraph::calculate_packed_xz(const float x, const float z) const
{
const auto [box_x, box_y, box_z] = header().box().vMin;
const auto cell_size = header().cell_size();
const int packed_xz = iFloor((x - box_x) / cell_size + .5f) * m_row_length +
iFloor((z - box_z) / cell_size + .5f);

VERIFY(iFloor((source_position.z - box_z) / cell_size + .5f) < (int)m_row_length);
alsed marked this conversation as resolved.
Show resolved Hide resolved
VERIFY(packed_xz < static_cast<int>(NodePosition::MAX_XZ));
return packed_xz;
}

const int packed_xz = iFloor((source_position.x - box_x) / cell_size + .5f)
* m_row_length + iFloor((source_position.z - box_z) / cell_size + .5f);
VERIFY(packed_xz < NodePosition::MAX_XZ);
// XXX: This method is WAY too large to inline.
IC const CLevelGraph::CPosition& CLevelGraph::vertex_position(CPosition& dest_position, const Fvector& source_position) const
{
const int packed_xz = calculate_packed_xz(source_position.x, source_position.z);

int packed_y = iFloor(65535.f * (source_position.y - box_y) / header().factor_y() + EPS_S);
int packed_y = iFloor(65535.f * (source_position.y - header().box().vMin.y) / header().factor_y() + EPS_S);
clamp(packed_y, 0, 65535);

dest_position.xz(u32(packed_xz));
Expand Down Expand Up @@ -195,15 +199,8 @@ IC bool CLevelGraph::inside(const u32 vertex_id, const Fvector& position, const

IC bool CLevelGraph::inside(const u32 vertex_id, const Fvector2& position) const
{
[[maybe_unused]]
const auto [box_x, box_y, box_z] = header().box().vMin;
const auto cell_size = header().cell_size();

const int packed_xz = iFloor((position.x - box_x) / cell_size + .5f) * m_row_length +
iFloor((position.y - box_z) / cell_size + .5f);
VERIFY(packed_xz < NodePosition::MAX_XZ);
const bool b = vertex(vertex_id)->position().xz() == u32(packed_xz);
return b;
const int packed_xz = calculate_packed_xz(position.x, position.y);
return vertex(vertex_id)->position().xz() == u32(packed_xz);
}

IC float CLevelGraph::vertex_plane_y(const CLevelGraph::CLevelVertex& vertex, const float X, const float Z) const
Expand Down Expand Up @@ -299,7 +296,7 @@ IC void CLevelGraph::set_invalid_vertex(u32& vertex_id, CLevelVertex** vertex) c
*vertex = NULL;
}

IC const u32 CLevelGraph::vertex_id(const CLevelGraph::CLevelVertex* vertex) const
IC u32 CLevelGraph::vertex_id(const CLevelGraph::CLevelVertex* vertex) const
{
VERIFY(valid_vertex_id(u32(vertex - m_nodes->begin())));
return (u32(vertex - m_nodes->begin()));
Expand Down