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

Resolve several compile warnings when comparing different int signedness #1755

Merged
merged 12 commits into from
Jan 4, 2025
10 changes: 5 additions & 5 deletions src/Layers/xrRender/AnimationKeyCalculate.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ IC void Dequantize(CKey& K, const CBlend& BD, const CMotion& M)
}
}

IC void MixInterlerp(CKey& Result, const CKey* R, const CBlend* const BA[MAX_BLENDED], int b_count)
IC void MixInterlerp(CKey& Result, const CKey* R, const CBlend* const BA[MAX_BLENDED], unsigned int b_count)
Xottab-DUTY marked this conversation as resolved.
Show resolved Hide resolved
{
VERIFY(MAX_BLENDED >= b_count);
switch (b_count)
Expand Down Expand Up @@ -237,14 +237,14 @@ IC void MixInterlerp(CKey& Result, const CKey* R, const CBlend* const BA[MAX_BLE
//int count = Blend.size();
float total = 0;
ConsistantKey S[MAX_BLENDED];
for (int i = 0; i < b_count; i++)
for (unsigned int i = 0; i < b_count; i++)
S[i].set(R + i, BA[i]->blendAmount);

std::sort(S, S + b_count);
CKey tmp;
total = S[0].w;
tmp = *S[0].K;
for (int cnt = 1; cnt < b_count; cnt++)
for (unsigned int cnt = 1; cnt < b_count; cnt++)
{
total += S[cnt].w;
float d;
Expand Down Expand Up @@ -400,14 +400,14 @@ IC void process_single_channel(
VERIFY(_valid(Result.T));
VERIFY(_valid(Result.Q));
}
IC void MixChannels(CKey& Result, const CKey* R, const animation::channel_def* BA, int b_count)
IC void MixChannels(CKey& Result, const CKey* R, const animation::channel_def* BA, unsigned int b_count)
{
VERIFY(b_count > 0);
Result = R[0];

// MixinAdd(Result,R,BA,b_count);
float lerp_factor_sum = 0.f;
for (int i = 1; i < b_count; i++)
for (unsigned int i = 1; i < b_count; i++)
switch (BA[i].rule.extern_)
{
case animation::add: key_mad(Result, CKey(Result), R[i], BA[i].factor); break;
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/DetailManager_CACHE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ void CDetailManager::cache_Initialize()
CDetailManager::Slot* CDetailManager::cache_Query(int r_x, int r_z)
{
int gx = w2cg_X(r_x + cache_cx);
VERIFY(gx >= 0 && gx < dm_cache_line);
VERIFY(gx >= 0 && gx < static_cast<int>(dm_cache_line));
int gz = w2cg_Z(r_z + cache_cz);
VERIFY(gz >= 0 && gz < dm_cache_line);
VERIFY(gz >= 0 && gz < static_cast<int>(dm_cache_line));
return cache[gz][gx];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/R_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class ECORE_API CBackend
void dbg_SetRS(D3DRENDERSTATETYPE p1, u32 p2);
void dbg_SetSS(u32 sampler, D3DSAMPLERSTATETYPE type, u32 value);
#ifdef DEBUG
void dbg_Draw(D3DPRIMITIVETYPE T, FVF::L* pVerts, int vcnt, u16* pIdx, int pcnt);
void dbg_Draw(D3DPRIMITIVETYPE T, FVF::L* pVerts, u32 vcnt, u16* pIdx, int pcnt);
void dbg_Draw(D3DPRIMITIVETYPE T, FVF::L* pVerts, int pcnt);

void dbg_DrawAABB(Fvector& T, float sx, float sy, float sz, u32 C)
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/R_Backend_DBG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void CBackend::dbg_DIP(D3DPRIMITIVETYPE pt, ref_geom geom, u32 baseV, u32 startV

#ifdef DEBUG

void CBackend::dbg_Draw(D3DPRIMITIVETYPE T, FVF::L* pVerts, int vcnt, u16* pIdx, int pcnt)
void CBackend::dbg_Draw(D3DPRIMITIVETYPE T, FVF::L* pVerts, u32 vcnt, u16* pIdx, int pcnt)
{
u32 vBase;
{
Expand Down Expand Up @@ -191,7 +191,7 @@ void CBackend::dbg_DrawEllipse(Fmatrix& T, u32 C)
102, 113, 104, 103, 113, 105, 104, 113, 106, 105, 113, 107, 106, 113, 108, 107, 113, 109, 108, 113, 110, 109,
113, 111, 110, 113, 112, 111, 113, 97, 112};

const int vcnt = sizeof(gVertices) / (sizeof(float) * 3);
const u32 vcnt = sizeof(gVertices) / (sizeof(float) * 3);
FVF::L verts[vcnt];
for (int i = 0; i < vcnt; i++)
Xottab-DUTY marked this conversation as resolved.
Show resolved Hide resolved
{
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ light::light() : SpatialBase(g_pGamePersistent->SpatialSpace)
vis.query_order = 0;
vis.visible = true;
vis.pending = false;
for (int id = 0; id < R__NUM_CONTEXTS; ++id)
for (unsigned int id = 0; id < R__NUM_CONTEXTS; ++id)
Xottab-DUTY marked this conversation as resolved.
Show resolved Hide resolved
svis[id].id = id;
#endif // (RENDER==R_R2) || (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
}
Expand Down Expand Up @@ -212,7 +212,7 @@ void light::spatial_move()
#if (RENDER == R_R2) || (RENDER == R_R3) || (RENDER == R_R4) || (RENDER == R_GL)
if (flags.bActive)
gi_generate();
for (int id = 0; id < R__NUM_CONTEXTS; ++id)
for (unsigned int id = 0; id < R__NUM_CONTEXTS; ++id)
svis[id].invalidate();
#endif // (RENDER==R_R2) || (RENDER==R_R3) || (RENDER==R_R4) || (RENDER == R_GL)
}
Expand Down
6 changes: 3 additions & 3 deletions src/Layers/xrRender/r__dsgraph_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,13 @@ void R_dsgraph_structure::load(const xr_vector<CSector::level_sector_data_t>& se
Sectors.resize(sectors_count);
Portals.resize(portals_count);

for (int idx = 0; idx < portals_count; ++idx)
for (unsigned int idx = 0; idx < portals_count; ++idx)
{
auto* portal = xr_new<CPortal>();
Portals[idx] = portal;
}

for (int idx = 0; idx < sectors_count; ++idx)
for (unsigned int idx = 0; idx < sectors_count; ++idx)
{
auto* sector = xr_new<CSector>();

Expand All @@ -690,7 +690,7 @@ void R_dsgraph_structure::load(const xr_vector<CSector::level_sector_data_t>& se
Sectors[idx] = sector;
}

for (int idx = 0; idx < portals_count; ++idx)
for (unsigned int idx = 0; idx < portals_count; ++idx)
{
auto* portal = static_cast<CPortal*>(Portals[idx]);

Expand Down
6 changes: 3 additions & 3 deletions src/Layers/xrRender/r__sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void CPortal::setup(const level_portal_data_t& data, const xr_vector<CSector*>&
// calc sphere
Fbox BB;
BB.invalidate();
for (int v = 0; v < vcnt; v++)
for (unsigned int v = 0; v < vcnt; v++)
BB.modify(V[v]);
BB.getsphere(S.P, S.R);

Expand All @@ -111,7 +111,7 @@ void CPortal::setup(const level_portal_data_t& data, const xr_vector<CSector*>&
N.set(0, 0, 0);

u32 _cnt = 0;
for (int i = 2; i < vcnt; i++)
for (unsigned int i = 2; i < vcnt; i++)
{
T.mknormal_non_normalized(poly[0], poly[i - 1], poly[i]);
float m = T.magnitude();
Expand All @@ -136,7 +136,7 @@ void CSector::setup(const level_sector_data_t& data, const xr_vector<CPortal*> &
// Assign portal polygons
const auto num_portals = data.portals_id.size();
m_portals.resize(num_portals);
for (int idx = 0; idx < num_portals; ++idx)
for (unsigned int idx = 0; idx < num_portals; ++idx)
{
const auto ID = data.portals_id[idx];
m_portals[idx] = portals[ID];
Expand Down
11 changes: 5 additions & 6 deletions src/Layers/xrRenderGL/glTextureUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ TextureFormatPairs TextureFormatList[] =

GLenum ConvertTextureFormat(D3DFORMAT dx9FMT)
{
constexpr size_t arrayLength = sizeof(TextureFormatList) / sizeof(TextureFormatList[0]);
for (int i = 0; i < arrayLength; ++i)
{
if (TextureFormatList[i].m_dx9FMT == dx9FMT)
return TextureFormatList[i].m_glFMT;
}
for (const auto& textureFormat : TextureFormatList)
{
if (textureFormat.m_dx9FMT == dx9FMT)
return textureFormat.m_glFMT;
}

VERIFY(!"ConvertTextureFormat didn't find appropriate gl texture format!");
return GL_NONE;
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender_R2/r2_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void CRender::LoadSectors(IReader* fs)
rmPortals = nullptr;
}

for (int id = 0; id < R__NUM_PARALLEL_CONTEXTS; ++id)
for (unsigned int id = 0; id < R__NUM_PARALLEL_CONTEXTS; ++id)
{
auto& dsgraph = contexts_pool[id];
dsgraph.reset();
Expand Down
8 changes: 4 additions & 4 deletions src/Layers/xrRender_R2/render_phase_sun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void render_sun::init()
return;

// pre-allocate contexts
for (int i = 0; i < R__NUM_SUN_CASCADES; ++i)
for (unsigned int i = 0; i < R__NUM_SUN_CASCADES; ++i)
{
contexts_ids[i] = RImplementation.alloc_context();
VERIFY(contexts_ids[i] != R_dsgraph_structure::INVALID_CONTEXT_ID);
Expand Down Expand Up @@ -114,7 +114,7 @@ void render_sun::calculate()
Fvector3 cull_COP[R__NUM_SUN_CASCADES];
Fmatrix cull_xform[R__NUM_SUN_CASCADES];

for (int cascade_ind = 0; cascade_ind < R__NUM_SUN_CASCADES; ++cascade_ind)
for (unsigned int cascade_ind = 0; cascade_ind < R__NUM_SUN_CASCADES; ++cascade_ind)
{
cull_planes.clear();

Expand Down Expand Up @@ -378,9 +378,9 @@ void render_sun::flush()

if (RImplementation.o.support_rt_arrays)
{
for (int cascade_ind = 0; cascade_ind < R__NUM_SUN_CASCADES; ++cascade_ind)
for (unsigned int i = 0; i < R__NUM_SUN_CASCADES; ++i)
{
accumulate_cascade(cascade_ind);
accumulate_cascade(i);
}
}

Expand Down
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
12 changes: 6 additions & 6 deletions src/xrCDB/Frustum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ u32 frustum_aabb_remap[8][6] =
EFC_Visible CFrustum::testSphere(Fvector& c, float r, u32& test_mask) const
{
u32 bit = 1;
for (int i = 0; i < p_count; i++, bit <<= 1)
for (unsigned int i = 0; i < p_count; i++, bit <<= 1)
{
if (test_mask & bit)
{
Expand Down Expand Up @@ -162,7 +162,7 @@ EFC_Visible CFrustum::testAABB(const float* mM, u32& test_mask) const
// go for trivial rejection or acceptance using "faster overlap test"
u32 bit = 1;

for (int i = 0; i < p_count; i++, bit <<= 1)
for (unsigned int i = 0; i < p_count; i++, bit <<= 1)
{
if (test_mask & bit)
{
Expand All @@ -182,7 +182,7 @@ EFC_Visible CFrustum::testAABB(const float* mM, u32& test_mask) const
EFC_Visible CFrustum::testSAABB(Fvector& c, float r, const float* mM, u32& test_mask) const
{
u32 bit = 1;
for (int i = 0; i < p_count; i++, bit <<= 1)
for (unsigned int i = 0; i < p_count; i++, bit <<= 1)
{
if (test_mask & bit)
{
Expand Down Expand Up @@ -213,7 +213,7 @@ EFC_Visible CFrustum::testSAABB(Fvector& c, float r, const float* mM, u32& test_
bool CFrustum::testPolyInside_dirty(Fvector* p, size_t count) const
{
Fvector* e = p + count;
for (int i = 0; i < p_count; i++)
for (unsigned int i = 0; i < p_count; i++)
{
const fplane& P = planes[i];
for (Fvector* I = p; I != e; I++)
Expand Down Expand Up @@ -384,7 +384,7 @@ sPoly* CFrustum::ClipPoly(sPoly& S, sPoly& D) const
{
sPoly* src = &D;
sPoly* dest = &S;
for (int i = 0; i < p_count; i++)
for (unsigned int i = 0; i < p_count; i++)
{
// cache plane and swap lists
const fplane& P = planes[i];
Expand Down Expand Up @@ -530,7 +530,7 @@ void CFrustum::CreateFromMatrix(Fmatrix& M, u32 mask)
p_count++;
}

for (int i = 0; i < p_count; i++)
for (unsigned int i = 0; i < p_count; i++)
{
float denom = 1.0f / planes[i].n.magnitude(); // Get magnitude of Vector
planes[i].n.x *= denom;
Expand Down
6 changes: 3 additions & 3 deletions src/xrCDB/xrCDB_Collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ CollectorPacked::CollectorPacked(const Fbox& bb, int apx_vertices, int apx_faces
flags.reserve(apx_faces);
int _size = (clpMX + 1) * (clpMY + 1) * (clpMZ + 1);
int _average = (apx_vertices / _size) / 2;
for (int ix = 0; ix < clpMX + 1; ix++)
for (int iy = 0; iy < clpMY + 1; iy++)
for (int iz = 0; iz < clpMZ + 1; iz++)
for (unsigned int ix = 0; ix < clpMX + 1; ix++)
for (unsigned int iy = 0; iy < clpMY + 1; iy++)
for (unsigned int iz = 0; iz < clpMZ + 1; iz++)
VM[ix][iy][iz].reserve(_average);
}

Expand Down
8 changes: 4 additions & 4 deletions src/xrCore/FixedVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class svector

public:
svector() : count(0) {}
svector(iterator p, int c) { assign(p, c); }
svector(iterator p, size_t c) { assign(p, c); }
IC iterator begin() { return array; }
IC iterator end() { return array + count; }
IC const_iterator begin() const { return array; }
Expand All @@ -30,13 +30,13 @@ class svector
IC u32 size() const { return count; }
IC void clear() { count = 0; }

IC void resize(int c)
IC void resize(size_t c)
{
VERIFY(c <= dim);
count = c;
}

IC void reserve(int c) {}
IC void reserve(size_t c) {}

IC void push_back(value_type e)
{
Expand Down Expand Up @@ -98,7 +98,7 @@ class svector
count++;
array[id] = V;
}
IC void assign(const_iterator p, int c)
IC void assign(const_iterator p, size_t c)
{
VERIFY(c > 0 && c <= dim);
CopyMemory(array, p, c * sizeof(value_type));
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/xrServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ void xrServer::Server_Client_Check(IClient* CL)
return;
};

if (CL->process_id == GetCurrentProcessId())
if (CL->process_id == static_cast<u32>(GetCurrentProcessId()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows process_id variable has DWORD type and GetCurrentProcessId() returns DWORD too.
On Linux this variable has type pid_t and GetCurrentProcessId() is a macro to getpid function that returns pid_t.

Why does it throw a warning here??

Copy link
Contributor Author

@alsed alsed Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with all the changes in this commit, the warning is for comparing a signed int with an unsigned.

Edit:
Is for pid_t :

warning: comparison of integer expressions of different signedness: ‘u32’ {aka ‘unsigned int’} and ‘__pid_t’ {aka ‘int’} [-Wsign-compare]
  869 |     if (CL->process_id == GetCurrentProcessId())
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~``

Copy link
Member

@Xottab-DUTY Xottab-DUTY Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try this. Will it fix the warning?

Suggested change
if (CL->process_id == static_cast<u32>(GetCurrentProcessId()))
if (CL->process_id == static_cast<xrpid_t>(GetCurrentProcessId()))

Copy link
Contributor Author

@alsed alsed Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning persist, xrpid_t is consider an int.
How about converting process_id to int for this comparison? unsigned to signed should be safer
if (static_cast<int>(CL->process_id) == GetCurrentProcessId())

{
CL->flags.bLocal = 1;
SV_Client = (xrClientData*)CL;
Expand Down
Loading
Loading