diff --git a/source/graphics/TerritoryTexture.cpp b/source/graphics/TerritoryTexture.cpp index 4b979c4a42..a4485e76de 100644 --- a/source/graphics/TerritoryTexture.cpp +++ b/source/graphics/TerritoryTexture.cpp @@ -175,8 +175,8 @@ void CTerritoryTexture::GenerateBitmap(const Grid& territories, u8* bitmap, CmpPtr cmpPlayerManager(m_Simulation, SYSTEM_ENTITY); std::vector colors; - i32 numPlayers = cmpPlayerManager->GetNumPlayers(); - for (i32 p = 0; p < numPlayers; ++p) + std::int32_t numPlayers = cmpPlayerManager->GetNumPlayers(); + for (std::int32_t p = 0; p < numPlayers; ++p) { CColor color(1, 0, 1, 1); CmpPtr cmpPlayer(m_Simulation, cmpPlayerManager->GetPlayerByID(p)); diff --git a/source/gui/CGUISetting.cpp b/source/gui/CGUISetting.cpp index ca59112644..7a7c5659bc 100644 --- a/source/gui/CGUISetting.cpp +++ b/source/gui/CGUISetting.cpp @@ -119,7 +119,7 @@ void CGUISimpleSetting::ToJSVal(const Script::Request& rq, JS::MutableHandleV template class CGUISimpleSetting; TYPE(bool) -TYPE(i32) +TYPE(std::int32_t) TYPE(u32) TYPE(float) TYPE(CVector2D) diff --git a/source/gui/GUIStringConversions.cpp b/source/gui/GUIStringConversions.cpp index 351b2f06c0..47ad96c3cf 100644 --- a/source/gui/GUIStringConversions.cpp +++ b/source/gui/GUIStringConversions.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -51,7 +51,7 @@ bool CGUI::ParseString(const CGUI*, const CStrW& Value, bool& Output) } template <> -bool CGUI::ParseString(const CGUI*, const CStrW& Value, int& Output) +bool CGUI::ParseString(const CGUI*, const CStrW& Value, int& Output) { Output = Value.ToInt(); return true; diff --git a/source/gui/GUITooltip.cpp b/source/gui/GUITooltip.cpp index f4ecff23f3..34bf4dd188 100644 --- a/source/gui/GUITooltip.cpp +++ b/source/gui/GUITooltip.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -24,7 +24,6 @@ #include "gui/ObjectTypes/CTooltip.h" #include "lib/debug.h" #include "lib/timer.h" -#include "lib/types.h" #include "ps/CLogger.h" #include @@ -180,7 +179,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) tooltipobj->SetHidden(true); } -static i32 GetTooltipDelay(const CStr& style, CGUI& pGUI) +static std::int32_t GetTooltipDelay(const CStr& style, CGUI& pGUI) { // Objects in __tooltip_ are guaranteed to be CTooltip* by the engine. CTooltip* tooltipobj = static_cast(pGUI.FindObjectByName("__tooltip_" + style)); diff --git a/source/gui/ObjectTypes/CInput.h b/source/gui/ObjectTypes/CInput.h index 67312882a4..18b2b20809 100644 --- a/source/gui/ObjectTypes/CInput.h +++ b/source/gui/ObjectTypes/CInput.h @@ -25,7 +25,6 @@ #include "gui/ObjectBases/IGUIScrollBarOwner.h" #include "gui/SettingTypes/CGUIColor.h" #include "gui/SettingTypes/CGUIString.h" -#include "lib/types.h" #include "maths/Rect.h" #include "ps/CStr.h" #include "ps/Input.h" @@ -227,14 +226,14 @@ protected: static const CStr EventNamePress; static const CStr EventNameTab; - CGUISimpleSetting m_BufferPosition; + CGUISimpleSetting m_BufferPosition; CGUISimpleSetting m_BufferZone; CGUISimpleSetting m_Caption; CGUISimpleSetting m_PlaceholderText; CGUISimpleSetting m_Font; CGUISimpleSetting m_MaskChar; CGUISimpleSetting m_Mask; - CGUISimpleSetting m_MaxLength; + CGUISimpleSetting m_MaxLength; CGUISimpleSetting m_MultiLine; CGUISimpleSetting m_Readonly; CGUISimpleSetting m_ScrollBar; diff --git a/source/gui/ObjectTypes/CList.h b/source/gui/ObjectTypes/CList.h index d94fffb2eb..5be5b825cf 100644 --- a/source/gui/ObjectTypes/CList.h +++ b/source/gui/ObjectTypes/CList.h @@ -25,7 +25,6 @@ #include "gui/ObjectBases/IGUITextOwner.h" #include "gui/SettingTypes/CGUIColor.h" #include "gui/SettingTypes/CGUIList.h" -#include "lib/types.h" #include "maths/Rect.h" #include "ps/CStr.h" @@ -149,9 +148,9 @@ protected: CGUISimpleSetting m_SpriteSelectAreaOverlay; CGUISimpleSetting m_TextColor; CGUISimpleSetting m_TextColorSelected; - CGUISimpleSetting m_Selected; + CGUISimpleSetting m_Selected; CGUISimpleSetting m_AutoScroll; - CGUISimpleSetting m_Hovered; + CGUISimpleSetting m_Hovered; CGUISimpleSetting m_List; CGUISimpleSetting m_ListData; diff --git a/source/gui/ObjectTypes/COList.h b/source/gui/ObjectTypes/COList.h index 4810be9e35..c0e5132f21 100644 --- a/source/gui/ObjectTypes/COList.h +++ b/source/gui/ObjectTypes/COList.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -24,7 +24,6 @@ #include "gui/SettingTypes/CGUIColor.h" #include "gui/SettingTypes/CGUIList.h" #include "lib/code_annotation.h" -#include "lib/types.h" #include "ps/CStr.h" #include @@ -54,7 +53,7 @@ public: CGUISimpleSetting m_Heading; // CGUIString?? CGUISimpleSetting m_List; CGUISimpleSetting m_Hidden; - CGUISimpleSetting m_SortOrder; + CGUISimpleSetting m_SortOrder; }; /** @@ -96,7 +95,7 @@ protected: CGUISimpleSetting m_SpriteHeading; CGUISimpleSetting m_Sortable; CGUISimpleSetting m_SelectedColumn; - CGUISimpleSetting m_SelectedColumnOrder; + CGUISimpleSetting m_SelectedColumnOrder; CGUISimpleSetting m_SpriteAsc; CGUISimpleSetting m_SpriteDesc; CGUISimpleSetting m_SpriteNotSorted; diff --git a/source/gui/ObjectTypes/CTooltip.h b/source/gui/ObjectTypes/CTooltip.h index 277dffdafa..55e7261ddd 100644 --- a/source/gui/ObjectTypes/CTooltip.h +++ b/source/gui/ObjectTypes/CTooltip.h @@ -24,7 +24,6 @@ #include "gui/ObjectBases/IGUITextOwner.h" #include "gui/SettingTypes/CGUIColor.h" #include "gui/SettingTypes/CGUIString.h" -#include "lib/types.h" #include "maths/Vector2D.h" #include "ps/CStr.h" @@ -42,7 +41,7 @@ public: CTooltip(CGUI& pGUI); const CStr& GetUsedObject() const { return m_UseObject; } - i32 GetTooltipDelay() const { return m_Delay; } + std::int32_t GetTooltipDelay() const { return m_Delay; } bool ShouldHideObject() const { return m_HideObject; } void SetMousePos(const CVector2D& vec) { m_MousePos.Set(vec, true); } @@ -67,7 +66,7 @@ protected: CGUISimpleSetting m_Caption; CGUISimpleSetting m_Font; CGUISimpleSetting m_Sprite; - CGUISimpleSetting m_Delay; + CGUISimpleSetting m_Delay; CGUISimpleSetting m_TextColor; CGUISimpleSetting m_MaxWidth; CGUISimpleSetting m_Offset; diff --git a/source/lib/tex/tex_bmp.cpp b/source/lib/tex/tex_bmp.cpp index d2fe26dc61..471529162c 100644 --- a/source/lib/tex/tex_bmp.cpp +++ b/source/lib/tex/tex_bmp.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -51,15 +51,15 @@ struct BmpHeader // BITMAPINFOHEADER u32 biSize; - i32 biWidth; - i32 biHeight; + std::int32_t biWidth; + std::int32_t biHeight; u16 biPlanes; u16 biBitCount; u32 biCompression; u32 biSizeImage; // the following are unused and zeroed when writing: - i32 biXPelsPerMeter; - i32 biYPelsPerMeter; + std::int32_t biXPelsPerMeter; + std::int32_t biYPelsPerMeter; u32 biClrUsed; u32 biClrImportant; }; @@ -138,7 +138,8 @@ Status TexCodecBmp::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const const size_t hdr_size = sizeof(BmpHeader); // needed for BITMAPFILEHEADER const size_t img_size = t->img_size(); const size_t file_size = hdr_size + img_size; - const i32 h = (t->m_Flags & TEX_TOP_DOWN)? -(i32)t->m_Height : (i32)t->m_Height; + const std::int32_t h = (t->m_Flags & TEX_TOP_DOWN)? -static_cast(t->m_Height) : + static_cast(t->m_Height); size_t transforms = t->m_Flags; transforms &= ~TEX_ORIENTATION; // no flip needed - we can set top-down bit. @@ -154,7 +155,7 @@ Status TexCodecBmp::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const // BITMAPINFOHEADER 40, // biSize = sizeof(BITMAPINFOHEADER) - (i32)t->m_Width, + static_cast(t->m_Width), h, 1, // biPlanes (u16)t->m_Bpp, diff --git a/source/lib/types.h b/source/lib/types.h index ecb8f409db..7c284e07df 100644 --- a/source/lib/types.h +++ b/source/lib/types.h @@ -29,7 +29,6 @@ #include -typedef int32_t i32; typedef int64_t i64; typedef uint8_t u8; diff --git a/source/maths/Fixed.h b/source/maths/Fixed.h index 81de7f6c24..c7d7837ae4 100644 --- a/source/maths/Fixed.h +++ b/source/maths/Fixed.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -35,7 +35,8 @@ class CStrW; #endif #if MSC_VERSION -// i32*i32 -> i64 multiply: MSVC x86 doesn't optimise i64 multiplies automatically, so use the intrinsic +// std::int32_t * std::int32_t -> i64 multiply: MSVC x86 doesn't optimise i64 multiplies automatically, so +// use the intrinsic #include #define MUL_I64_I32_I32(a, b)\ (__emul((a), (b))) @@ -298,7 +299,7 @@ public: { i64 t = (i64)value * n; t = std::max((i64)std::numeric_limits::min(), std::min((i64)std::numeric_limits::max(), t)); - return CFixed((i32)t); + return CFixed(static_cast(t)); } /// Divide by an integer. Must not have n == 0. Cannot overflow unless n == -1. @@ -370,7 +371,7 @@ private: /** * A fixed-point number class with 1-bit sign, 15-bit integral part, 16-bit fractional part. */ -typedef CFixed CFixed_15_16; +typedef CFixed(0x7fffffff), 32, 15, 16, 65536> CFixed_15_16; /** * Default fixed-point type used by the engine. diff --git a/source/maths/FixedVector2D.h b/source/maths/FixedVector2D.h index 5906c8a61f..ba0d4de7c0 100644 --- a/source/maths/FixedVector2D.h +++ b/source/maths/FixedVector2D.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -109,9 +109,9 @@ public: u32 d = isqrt64(d2); - CheckU32CastOverflow(d, i32, L"Overflow in CFixedVector2D::Length() part 2") + CheckU32CastOverflow(d, std::int32_t, L"Overflow in CFixedVector2D::Length() part 2") fixed r; - r.SetInternalValue(static_cast(d)); + r.SetInternalValue(static_cast(d)); return r; } @@ -215,9 +215,9 @@ public: i64 sum = x + y; sum >>= fixed::fract_bits; - CheckCastOverflow(sum, i32, L"Overflow in CFixedVector2D::Dot() part 2", L"Underflow in CFixedVector2D::Dot() part 2") + CheckCastOverflow(sum, std::int32_t, L"Overflow in CFixedVector2D::Dot() part 2", L"Underflow in CFixedVector2D::Dot() part 2") fixed ret; - ret.SetInternalValue(static_cast(sum)); + ret.SetInternalValue(static_cast(sum)); return ret; } diff --git a/source/maths/FixedVector3D.h b/source/maths/FixedVector3D.h index e4fbc9ed6a..ab06f65be2 100644 --- a/source/maths/FixedVector3D.h +++ b/source/maths/FixedVector3D.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -94,9 +94,9 @@ public: u32 d = isqrt64(d2); - CheckU32CastOverflow(d, i32, L"Overflow in CFixedVector3D::Length() part 3") + CheckU32CastOverflow(d, std::int32_t, L"Overflow in CFixedVector3D::Length() part 3") fixed r; - r.SetInternalValue((i32)d); + r.SetInternalValue(static_cast(d)); return r; } @@ -153,13 +153,13 @@ public: i64 z = x_vy - y_vx; z >>= fixed::fract_bits; - CheckCastOverflow(x, i32, L"Overflow in CFixedVector3D::Cross() part 4", L"Underflow in CFixedVector3D::Cross() part 4") - CheckCastOverflow(y, i32, L"Overflow in CFixedVector3D::Cross() part 5", L"Underflow in CFixedVector3D::Cross() part 5") - CheckCastOverflow(z, i32, L"Overflow in CFixedVector3D::Cross() part 6", L"Underflow in CFixedVector3D::Cross() part 6") + CheckCastOverflow(x, std::int32_t, L"Overflow in CFixedVector3D::Cross() part 4", L"Underflow in CFixedVector3D::Cross() part 4") + CheckCastOverflow(y, std::int32_t, L"Overflow in CFixedVector3D::Cross() part 5", L"Underflow in CFixedVector3D::Cross() part 5") + CheckCastOverflow(z, std::int32_t, L"Overflow in CFixedVector3D::Cross() part 6", L"Underflow in CFixedVector3D::Cross() part 6") CFixedVector3D ret; - ret.X.SetInternalValue((i32)x); - ret.Y.SetInternalValue((i32)y); - ret.Z.SetInternalValue((i32)z); + ret.X.SetInternalValue(static_cast(x)); + ret.Y.SetInternalValue(static_cast(y)); + ret.Z.SetInternalValue(static_cast(z)); return ret; } @@ -177,10 +177,10 @@ public: CheckSignedAdditionOverflow(i64, t, z, L"Overflow in CFixedVector3D::Dot() part 2", L"Underflow in CFixedVector3D::Dot() part 2") i64 sum = t + z; sum >>= fixed::fract_bits; - CheckCastOverflow(sum, i32, L"Overflow in CFixedVector3D::Dot() part 3", L"Underflow in CFixedVector3D::Dot() part 3") + CheckCastOverflow(sum, std::int32_t, L"Overflow in CFixedVector3D::Dot() part 3", L"Underflow in CFixedVector3D::Dot() part 3") fixed ret; - ret.SetInternalValue((i32)sum); + ret.SetInternalValue(static_cast(sum)); return ret; } }; diff --git a/source/maths/tests/test_Fixed.h b/source/maths/tests/test_Fixed.h index 183b1438fa..1d0ff10211 100644 --- a/source/maths/tests/test_Fixed.h +++ b/source/maths/tests/test_Fixed.h @@ -23,7 +23,6 @@ # pragma warning(disable: 4724) #endif -#include "lib/types.h" #include "maths/Fixed.h" #include "ps/CStr.h" @@ -73,13 +72,13 @@ public: TS_ASSERT_EQUALS(b.ToDouble(), -123.125); fixed c = fixed::FromFloat(std::numeric_limits::infinity()); - TS_ASSERT_EQUALS(c.GetInternalValue(), (i32)0); + TS_ASSERT_EQUALS(c.GetInternalValue(), static_cast(0)); fixed d = fixed::FromFloat(-std::numeric_limits::infinity()); - TS_ASSERT_EQUALS(d.GetInternalValue(), (i32)0); + TS_ASSERT_EQUALS(d.GetInternalValue(), static_cast(0)); fixed e = fixed::FromFloat(std::numeric_limits::quiet_NaN()); - TS_ASSERT_EQUALS(e.GetInternalValue(), (i32)0); + TS_ASSERT_EQUALS(e.GetInternalValue(), static_cast(0)); } void test_FromDouble() @@ -93,13 +92,13 @@ public: TS_ASSERT_EQUALS(b.ToDouble(), -123.125); fixed c = fixed::FromDouble(std::numeric_limits::infinity()); - TS_ASSERT_EQUALS(c.GetInternalValue(), (i32)0); + TS_ASSERT_EQUALS(c.GetInternalValue(), static_cast(0)); fixed d = fixed::FromDouble(-std::numeric_limits::infinity()); - TS_ASSERT_EQUALS(d.GetInternalValue(), (i32)0); + TS_ASSERT_EQUALS(d.GetInternalValue(), static_cast(0)); fixed e = fixed::FromDouble(std::numeric_limits::quiet_NaN()); - TS_ASSERT_EQUALS(e.GetInternalValue(), (i32)0); + TS_ASSERT_EQUALS(e.GetInternalValue(), static_cast(0)); } void test_FromFloat_Rounding() diff --git a/source/maths/tests/test_FixedVector2D.h b/source/maths/tests/test_FixedVector2D.h index f90b38f992..76a3dc47b8 100644 --- a/source/maths/tests/test_FixedVector2D.h +++ b/source/maths/tests/test_FixedVector2D.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -17,7 +17,6 @@ #include "lib/self_test.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" @@ -60,12 +59,13 @@ public: TS_ASSERT_EQUALS(v1.Length().ToDouble(), 5.0); fixed max; - max.SetInternalValue((i32)0x7fffffff); + max.SetInternalValue(static_cast(0x7fffffff)); CFixedVector2D v2 (max, fixed::FromInt(0)); TS_ASSERT_EQUALS(v2.Length().ToDouble(), max.ToDouble()); + // largest value that shouldn't cause overflow fixed large; - large.SetInternalValue((i32)((double)0x7fffffff/sqrt(2.0))); // largest value that shouldn't cause overflow + large.SetInternalValue(static_cast(static_cast(0x7fffffff)/sqrt(2.0))); CFixedVector2D v3 (large, large); TS_ASSERT_DELTA(v3.Length().ToDouble(), sqrt(2.0)*large.ToDouble(), 0.01); } @@ -101,13 +101,14 @@ public: TS_ASSERT_VEC_DELTA(v1, 3.0/5.0, 4.0/5.0, 0.01); fixed max; - max.SetInternalValue((i32)0x7fffffff); + max.SetInternalValue(static_cast(0x7fffffff)); CFixedVector2D v2 (max, fixed::FromInt(0)); v2.Normalize(); TS_ASSERT_VEC_EQUALS(v2, 1.0, 0.0); + // largest value that shouldn't cause overflow fixed large; - large.SetInternalValue((i32)((double)0x7fffffff/sqrt(2.0))); // largest value that shouldn't cause overflow + large.SetInternalValue(static_cast(static_cast(0x7fffffff)/sqrt(2.0))); CFixedVector2D v3 (large, large); v3.Normalize(); TS_ASSERT_VEC_DELTA(v3, 1.0/sqrt(2.0), 1.0/sqrt(2.0), 0.01); diff --git a/source/maths/tests/test_FixedVector3D.h b/source/maths/tests/test_FixedVector3D.h index d2515f0d09..80849833dd 100644 --- a/source/maths/tests/test_FixedVector3D.h +++ b/source/maths/tests/test_FixedVector3D.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -17,7 +17,6 @@ #include "lib/self_test.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector3D.h" @@ -62,12 +61,13 @@ public: TS_ASSERT_EQUALS(v1.Length().ToDouble(), 13.0); fixed max; - max.SetInternalValue((i32)0x7fffffff); + max.SetInternalValue(static_cast(0x7fffffff)); CFixedVector3D v2 (max, fixed::FromInt(0), fixed::FromInt(0)); TS_ASSERT_EQUALS(v2.Length().ToDouble(), max.ToDouble()); + // largest value that shouldn't cause overflow fixed large; - large.SetInternalValue((i32)((double)0x7fffffff/sqrt(3.0))+1); // largest value that shouldn't cause overflow + large.SetInternalValue(static_cast(static_cast(0x7fffffff)/sqrt(3.0))+1); CFixedVector3D v3 (large, large, large); TS_ASSERT_DELTA(v3.Length().ToDouble(), sqrt(3.0)*large.ToDouble(), 0.01); } @@ -83,13 +83,14 @@ public: TS_ASSERT_VEC_DELTA(v1, 3.0/13.0, 4.0/13.0, 12.0/13.0, 0.01); fixed max; - max.SetInternalValue((i32)0x7fffffff); + max.SetInternalValue(static_cast(0x7fffffff)); CFixedVector3D v2 (max, fixed::FromInt(0), fixed::FromInt(0)); v2.Normalize(); TS_ASSERT_VEC_EQUALS(v2, 1.0, 0.0, 0.0); + // largest value that shouldn't cause overflow fixed large; - large.SetInternalValue((i32)((double)0x7fffffff/sqrt(3.0))+1); // largest value that shouldn't cause overflow + large.SetInternalValue(static_cast(static_cast(0x7fffffff)/sqrt(3.0))+1); CFixedVector3D v3 (large, large, large); v3.Normalize(); TS_ASSERT_VEC_DELTA(v3, 1.0/sqrt(3.0), 1.0/sqrt(3.0), 1.0/sqrt(3.0), 0.01); diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index 0bb39d39d8..e06198d0e9 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -208,7 +208,7 @@ bool CNetClient::TryToConnectWithSTUN(std::string serverAddressOrHostname, std:: PushGuiMessage( "type", "netstatus", "status", "disconnected", - "reason", static_cast(NDR_SERVER_REFUSED)); + "reason", static_cast(NDR_SERVER_REFUSED)); return false; } @@ -220,7 +220,7 @@ bool CNetClient::TryToConnectWithSTUN(std::string serverAddressOrHostname, std:: PushGuiMessage( "type", "netstatus", "status", "disconnected", - "reason", static_cast(NDR_STUN_PORT_FAILED)); + "reason", static_cast(NDR_STUN_PORT_FAILED)); return false; } @@ -233,7 +233,7 @@ bool CNetClient::TryToConnectWithSTUN(std::string serverAddressOrHostname, std:: PushGuiMessage( "type", "netstatus", "status", "disconnected", - "reason", static_cast(NDR_STUN_ENDPOINT_FAILED)); + "reason", static_cast(NDR_STUN_ENDPOINT_FAILED)); return false; } @@ -291,7 +291,7 @@ bool CNetClient::TryToConnectWithSTUN(std::string serverAddressOrHostname, std:: PushGuiMessage( "type", "netstatus", "status", "disconnected", - "reason", static_cast(NDR_UNKNOWN)); + "reason", static_cast(NDR_UNKNOWN)); return false; } @@ -674,7 +674,8 @@ void CNetClient::SendAuthenticateMessage() void CNetClient::StartGame(const JS::MutableHandleValue initAttributes, const std::string& savedState) { const auto foundPlayer = m_PlayerAssignments.find(m_GUID); - const i32 player{foundPlayer != m_PlayerAssignments.end() ? foundPlayer->second.m_PlayerID : -1}; + const std::int32_t player{foundPlayer != m_PlayerAssignments.end() ? foundPlayer->second.m_PlayerID : + -1}; m_ClientTurnManager = new CNetClientTurnManager{*m_Game->GetSimulation2(), *this, static_cast(m_HostID), m_Game->GetReplayLogger()}; @@ -722,7 +723,7 @@ bool CNetClient::OnHandshakeResponse(CNetClient* client, CFsmEvent client->PushGuiMessage( "type", "netstatus", "status", "disconnected", - "reason", static_cast(NDR_LOBBY_AUTH_FAILED)); + "reason", static_cast(NDR_LOBBY_AUTH_FAILED)); LOGMESSAGE("Net client: Couldn't send lobby auth xmpp message"); } diff --git a/source/network/NetHost.h b/source/network/NetHost.h index 7912cc9ee5..d0b81dbddc 100644 --- a/source/network/NetHost.h +++ b/source/network/NetHost.h @@ -48,7 +48,7 @@ struct PlayerAssignment CStrW m_Name; /// The player that the given host controls, or -1 if none (observer) - i32 m_PlayerID; + std::int32_t m_PlayerID; /// Status - Ready or not: 0 for not ready, 1 for ready, 2 to stay ready u8 m_Status; diff --git a/source/network/NetMessage.h b/source/network/NetMessage.h index 34bd81243e..f7d3aba340 100644 --- a/source/network/NetMessage.h +++ b/source/network/NetMessage.h @@ -124,7 +124,8 @@ class CSimulationMessage : public CNetMessage { public: CSimulationMessage(const Script::Interface& scriptInterface); - CSimulationMessage(const Script::Interface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data); + CSimulationMessage(const Script::Interface& scriptInterface, u32 client, std::int32_t player, + u32 turn, JS::HandleValue data); /** The compiler can't create a copy constructor because of the PersistentRooted member, * so we have to write it manually. @@ -138,8 +139,8 @@ public: virtual CStr ToString() const; u32 m_Client; - i32 m_Player; - i32 m_Turn; + std::int32_t m_Player; + std::int32_t m_Turn; JS::PersistentRooted m_Data; private: const Script::Interface& m_ScriptInterface; diff --git a/source/network/NetMessageSim.cpp b/source/network/NetMessageSim.cpp index a57f24ee5e..2cccb5def2 100644 --- a/source/network/NetMessageSim.cpp +++ b/source/network/NetMessageSim.cpp @@ -123,7 +123,8 @@ CSimulationMessage::CSimulationMessage(const Script::Interface& scriptInterface) m_Data.init(rq.cx); } -CSimulationMessage::CSimulationMessage(const Script::Interface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) : +CSimulationMessage::CSimulationMessage(const Script::Interface& scriptInterface, u32 client, + std::int32_t player, u32 turn, JS::HandleValue data) : CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), m_Client(client), m_Player(player), m_Turn(turn) { diff --git a/source/network/NetMessages.h b/source/network/NetMessages.h index b3d6ac9ba1..c1a66e627f 100644 --- a/source/network/NetMessages.h +++ b/source/network/NetMessages.h @@ -231,7 +231,7 @@ START_NMT_CLASS_(ClientPaused, NMT_CLIENT_PAUSED) END_NMT_CLASS() START_NMT_CLASS_(LoadedGame, NMT_LOADED_GAME) - NMT_FIELD_INT(m_CurrentTurn, i32, 4) + NMT_FIELD_INT(m_CurrentTurn, std::int32_t, 4) END_NMT_CLASS() START_NMT_CLASS_(GameStart, NMT_GAME_START) @@ -243,17 +243,17 @@ START_NMT_CLASS_(GameSavedStart, NMT_SAVED_GAME_START) END_NMT_CLASS() START_NMT_CLASS_(EndCommandBatch, NMT_END_COMMAND_BATCH) - NMT_FIELD_INT(m_Turn, i32, 4) + NMT_FIELD_INT(m_Turn, std::int32_t, 4) NMT_FIELD_INT(m_TurnLength, u32, 2) END_NMT_CLASS() START_NMT_CLASS_(SyncCheck, NMT_SYNC_CHECK) - NMT_FIELD_INT(m_Turn, i32, 4) + NMT_FIELD_INT(m_Turn, std::int32_t, 4) NMT_FIELD(CStr, m_Hash) END_NMT_CLASS() START_NMT_CLASS_(SyncError, NMT_SYNC_ERROR) - NMT_FIELD_INT(m_Turn, i32, 4) + NMT_FIELD_INT(m_Turn, std::int32_t, 4) NMT_FIELD(CStr, m_HashExpected) NMT_START_ARRAY(m_PlayerNames) NMT_FIELD(CStrW, m_Name) diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index 447a074c98..df5e6ace13 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -715,7 +715,7 @@ void CNetServerWorker::OnUserLeave(CNetServerSession* session) void CNetServerWorker::AddPlayer(const CStr& guid, const CStrW& name) { // Find all player IDs in active use; we mustn't give them to a second player (excluding the unassigned ID: -1) - std::set usedIDs; + std::set usedIDs; for (const std::pair& p : m_PlayerAssignments) if (p.second.m_Enabled && p.second.m_PlayerID != -1) usedIDs.insert(p.second.m_PlayerID); @@ -724,7 +724,7 @@ void CNetServerWorker::AddPlayer(const CStr& guid, const CStrW& name) // back their old player ID. Don't do this in pregame however, // as that ID might be invalid for various reasons. - i32 playerID = -1; + std::int32_t playerID = -1; if (m_State != SERVER_STATE_PREGAME) { diff --git a/source/scriptinterface/Conversions.cpp b/source/scriptinterface/Conversions.cpp index 8a65fbd377..8a1a620efd 100644 --- a/source/scriptinterface/Conversions.cpp +++ b/source/scriptinterface/Conversions.cpp @@ -69,7 +69,7 @@ template<> bool FromJSVal(const Request& rq, JS::HandleValue v, double& return true; } -template<> bool FromJSVal(const Request& rq, JS::HandleValue v, i32& out) +template<> bool FromJSVal(const Request& rq, JS::HandleValue v, std::int32_t& out) { FAIL_IF_NOT(v.isNumber(), v); if (!JS::ToInt32(rq.cx, v, &out)) @@ -206,7 +206,7 @@ template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, cons ret.set(JS::NumberValue(val)); } -template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, const i32& val) +template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, const std::int32_t& val) { ret.set(JS::NumberValue(val)); } @@ -299,4 +299,4 @@ template<> bool Script::FromJSVal>(const Script::Request& rq } #undef FAIL -#undef FAIL_IF_NOT \ No newline at end of file +#undef FAIL_IF_NOT diff --git a/source/scriptinterface/tests/test_ScriptConversions.h b/source/scriptinterface/tests/test_ScriptConversions.h index 5c9139d5e3..8b364bf66b 100644 --- a/source/scriptinterface/tests/test_ScriptConversions.h +++ b/source/scriptinterface/tests/test_ScriptConversions.h @@ -126,13 +126,13 @@ public: roundtrip(1e9f, "1000000000"); roundtrip(1e30f, "1.0000000150474662e+30"); - roundtrip(0, "0"); - roundtrip(123, "123"); - roundtrip(-123, "-123"); - roundtrip(JSVAL_INT_MAX - 1, "2147483646"); - roundtrip(JSVAL_INT_MAX, "2147483647"); - roundtrip(JSVAL_INT_MIN + 1, "-2147483647"); - roundtrip(JSVAL_INT_MIN, "-2147483648"); + roundtrip(0, "0"); + roundtrip(123, "123"); + roundtrip(-123, "-123"); + roundtrip(JSVAL_INT_MAX - 1, "2147483646"); + roundtrip(JSVAL_INT_MAX, "2147483647"); + roundtrip(JSVAL_INT_MIN + 1, "-2147483647"); + roundtrip(JSVAL_INT_MIN, "-2147483648"); roundtrip(0, "0"); roundtrip(123, "123"); @@ -181,11 +181,11 @@ public: // using new uninitialized variables each time to be sure the test doesn't succeeed if ToJSVal doesn't touch the value at all. JS::RootedValue val0(rq.cx), val1(rq.cx), val2(rq.cx), val3(rq.cx), val4(rq.cx), val5(rq.cx), val6(rq.cx), val7(rq.cx), val8(rq.cx); - Script::ToJSVal(rq, &val0, 0); - Script::ToJSVal(rq, &val1, JSVAL_INT_MAX - 1); - Script::ToJSVal(rq, &val2, JSVAL_INT_MAX); - Script::ToJSVal(rq, &val3, JSVAL_INT_MIN + 1); - Script::ToJSVal(rq, &val4, -(i64)2147483648u); // JSVAL_INT_MIN + Script::ToJSVal(rq, &val0, 0); + Script::ToJSVal(rq, &val1, JSVAL_INT_MAX - 1); + Script::ToJSVal(rq, &val2, JSVAL_INT_MAX); + Script::ToJSVal(rq, &val3, JSVAL_INT_MIN + 1); + Script::ToJSVal(rq, &val4, -(i64)2147483648u); // JSVAL_INT_MIN TS_ASSERT(val0.isInt32()); TS_ASSERT(val1.isInt32()); TS_ASSERT(val2.isInt32()); diff --git a/source/simulation2/components/CCmpCommandQueue.cpp b/source/simulation2/components/CCmpCommandQueue.cpp index 3d59e151ef..b40799aa3b 100644 --- a/source/simulation2/components/CCmpCommandQueue.cpp +++ b/source/simulation2/components/CCmpCommandQueue.cpp @@ -84,7 +84,7 @@ public: deserialize.NumberU32_Unbounded("num commands", numCmds); for (size_t i = 0; i < numCmds; ++i) { - i32 player; + std::int32_t player; JS::RootedValue data(rq.cx); deserialize.NumberI32_Unbounded("player", player); deserialize.ScriptVal("data", &data); diff --git a/source/simulation2/components/CCmpFootprint.cpp b/source/simulation2/components/CCmpFootprint.cpp index 2eb4ba73a4..ca30cd49c5 100644 --- a/source/simulation2/components/CCmpFootprint.cpp +++ b/source/simulation2/components/CCmpFootprint.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,7 +19,6 @@ #include "ICmpFootprint.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/FixedVector3D.h" @@ -330,20 +329,20 @@ public: entity_angle_t initialAngle = cmpPosition->GetRotation().Y; // Max spawning distance + 1 (in meters) - const i32 maxSpawningDistance = 13; + const std::int32_t maxSpawningDistance = 13; if (m_Shape == CIRCLE) { // Expand outwards from foundation with a fixed step of 1 meter - for (i32 dist = 0; dist <= maxSpawningDistance; ++dist) + for (std::int32_t dist = 0; dist <= maxSpawningDistance; ++dist) { // The spawn point should be far enough from this footprint to fit the unit, plus a little gap entity_pos_t clearance = spawnedRadius + entity_pos_t::FromInt(1+dist); entity_pos_t radius = m_Size0 + clearance; // Try equally-spaced points around the circle in alternating directions, starting from the front - const i32 numPoints = 31 + 2*dist; - for (i32 i = 0; i < (numPoints+1)/2; i = (i > 0 ? -i : 1-i)) // [0, +1, -1, +2, -2, ... (np-1)/2, -(np-1)/2] + const std::int32_t numPoints = 31 + 2*dist; + for (std::int32_t i = 0; i < (numPoints+1)/2; i = (i > 0 ? -i : 1-i)) // [0, +1, -1, +2, -2, ... (np-1)/2, -(np-1)/2] { entity_angle_t angle = initialAngle + (entity_angle_t::Pi()*2).Multiply(entity_angle_t::FromInt(i)/(int)numPoints); @@ -365,12 +364,12 @@ public: sincos_approx(initialAngle, s, c); // Expand outwards from foundation with a fixed step of 1 meter - for (i32 dist = 0; dist <= maxSpawningDistance; ++dist) + for (std::int32_t dist = 0; dist <= maxSpawningDistance; ++dist) { // The spawn point should be far enough from this footprint to fit the unit, plus a little gap entity_pos_t clearance = spawnedRadius + entity_pos_t::FromInt(1+dist); - for (i32 edge = 0; edge < 4; ++edge) + for (std::int32_t edge = 0; edge < 4; ++edge) { // Compute the direction and length of the current edge CFixedVector2D dir; @@ -401,9 +400,9 @@ public: sx = sx/2 + clearance; sy = sy/2 + clearance; // Try equally-spaced (1 meter) points along the edge in alternating directions, starting from the middle - i32 numPoints = 1 + 2*sx.ToInt_RoundToNearest(); + std::int32_t numPoints = 1 + 2*sx.ToInt_RoundToNearest(); CFixedVector2D center = initialPos - dir.Perpendicular().Multiply(sy); - for (i32 i = 0; i < (numPoints+1)/2; i = (i > 0 ? -i : 1-i)) // [0, +1, -1, +2, -2, ... (np-1)/2, -(np-1)/2] + for (std::int32_t i = 0; i < (numPoints+1)/2; i = (i > 0 ? -i : 1-i)) // [0, +1, -1, +2, -2, ... (np-1)/2, -(np-1)/2] { CFixedVector2D pos (center + dir*i); diff --git a/source/simulation2/components/CCmpObstructionManager.cpp b/source/simulation2/components/CCmpObstructionManager.cpp index 238ffee763..7c8d616abe 100644 --- a/source/simulation2/components/CCmpObstructionManager.cpp +++ b/source/simulation2/components/CCmpObstructionManager.cpp @@ -237,7 +237,7 @@ public: SerializeCommon(deserialize); - i32 size = ((m_WorldX1-m_WorldX0)/Pathfinding::NAVCELL_SIZE_INT).ToInt_RoundToInfinity(); + std::int32_t size = ((m_WorldX1-m_WorldX0)/Pathfinding::NAVCELL_SIZE_INT).ToInt_RoundToInfinity(); m_UpdateInformations.dirtinessGrid = Grid(size, size); } @@ -268,7 +268,7 @@ public: ENSURE(x0.IsZero() && z0.IsZero()); // don't bother implementing non-zero offsets yet ResetSubdivisions(x1, z1); - i32 size = ((m_WorldX1-m_WorldX0)/Pathfinding::NAVCELL_SIZE_INT).ToInt_RoundToInfinity(); + std::int32_t size = ((m_WorldX1-m_WorldX0)/Pathfinding::NAVCELL_SIZE_INT).ToInt_RoundToInfinity(); m_UpdateInformations.dirtinessGrid = Grid(size, size); CmpPtr cmpPathfinder(GetSystemEntity()); diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index 3da5cb7cd9..8a90892cf9 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -964,8 +964,8 @@ std::vector CCmpPathfinder::DistributeAround(std::vector u32 { - i32 dx = (p1.X - p2.X).ToInt_RoundToInfinity(); - i32 dy = (p1.Y - p2.Y).ToInt_RoundToInfinity(); + std::int32_t dx = (p1.X - p2.X).ToInt_RoundToInfinity(); + std::int32_t dy = (p1.Y - p2.Y).ToInt_RoundToInfinity(); return dx*dx + dy*dy; }; diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 8841ffbfe6..d9737a458c 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -191,7 +191,7 @@ struct Query entity_pos_t baseRange; // Non-parabolic detection range entity_pos_t yOrigin; // Used for parabolas only. u32 ownersMask; - i32 interface; + std::int32_t interface; u8 flagsMask; bool enabled; bool parabolic; @@ -214,9 +214,9 @@ static bool InParabolicRange(CFixedVector3D v, fixed range) u64 zz = SQUARE_U64_FIXED(v.Z); i64 d2 = (xx + zz) >> 1; // d2 <= 2^62 (no overflow) - i32 y = v.Y.GetInternalValue(); - i32 c = range.GetInternalValue(); - i32 c_2 = c >> 1; + std::int32_t y = v.Y.GetInternalValue(); + std::int32_t c = range.GetInternalValue(); + std::int32_t c_2 = c >> 1; i64 c2 = MUL_I64_I32_I32(c_2 - y, c); @@ -467,10 +467,10 @@ public: std::array m_LosRevealWholeMap; bool m_LosRevealWholeMapForAll; bool m_LosCircular; - i32 m_LosVerticesPerSide; + std::int32_t m_LosVerticesPerSide; // Cache for visibility tracking - i32 m_LosRegionsPerSide; + std::int32_t m_LosRegionsPerSide; bool m_GlobalVisibilityUpdate; std::array m_GlobalPlayerVisibilityUpdate; Grid m_DirtyVisibility; @@ -939,8 +939,8 @@ public: if (m_Deserializing) { // recalc current exploration stats. - for (i32 j = 0; j < m_LosVerticesPerSide; j++) - for (i32 i = 0; i < m_LosVerticesPerSide; i++) + for (std::int32_t j = 0; j < m_LosVerticesPerSide; j++) + for (std::int32_t i = 0; i < m_LosVerticesPerSide; i++) if (!LosIsOffWorld(i, j)) for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k) m_ExploredVertices.at(k) += ((m_LosState.get(i, j) & ((u32)LosState::EXPLORED << (2*(k-1)))) > 0); @@ -972,8 +972,8 @@ public: } m_TotalInworldVertices = 0; - for (i32 j = 0; j < m_LosVerticesPerSide; ++j) - for (i32 i = 0; i < m_LosVerticesPerSide; ++i) + for (std::int32_t j = 0; j < m_LosVerticesPerSide; ++j) + for (std::int32_t i = 0; i < m_LosVerticesPerSide; ++i) { if (LosIsOffWorld(i,j)) m_LosStateRevealed.get(i, j) = 0; @@ -1452,7 +1452,7 @@ public: return NEVER_IN_RANGE; entity_pos_t effectiveRange; - effectiveRange.SetInternalValue(static_cast(isqrt64( + effectiveRange.SetInternalValue(static_cast(isqrt64( SQUARE_U64_FIXED(range) + static_cast(heightDiff.GetInternalValue()) * static_cast(range.GetInternalValue()) * 2 ))); @@ -1501,7 +1501,8 @@ public: i64 numerator = rangeSq - distSq; entity_pos_t result; - result.SetInternalValue(static_cast(numerator / (static_cast(range.GetInternalValue()) * 2))); + result.SetInternalValue(static_cast(numerator / + (static_cast(range.GetInternalValue()) * 2))); return yOrigin + result; } @@ -2198,8 +2199,8 @@ public: void ExploreMap(player_id_t p) override { - for (i32 j = 0; j < m_LosVerticesPerSide; ++j) - for (i32 i = 0; i < m_LosVerticesPerSide; ++i) + for (std::int32_t j = 0; j < m_LosVerticesPerSide; ++j) + for (std::int32_t i = 0; i < m_LosVerticesPerSide; ++i) { if (LosIsOffWorld(i,j)) continue; @@ -2221,14 +2222,14 @@ public: // Territory data is stored per territory-tile (typically a multiple of terrain-tiles). // LOS data is stored per los vertex (in reality tiles too, but it's the center that matters). // This scales from LOS coordinates to Territory coordinates. - auto scale = [](i32 coord, i32 max) -> i32 { + auto scale = [](std::int32_t coord, std::int32_t max) -> std::int32_t { return std::min(max, (coord * LOS_TILE_SIZE + LOS_TILE_SIZE / 2) / (ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE * Pathfinding::NAVCELL_SIZE_INT)); }; // For each territory-tile, if it is owned by a valid player then update the LOS // for every vertex inside/around that tile, to mark them as explored. - for (i32 j = 0; j < m_LosVerticesPerSide; ++j) - for (i32 i = 0; i < m_LosVerticesPerSide; ++i) + for (std::int32_t j = 0; j < m_LosVerticesPerSide; ++j) + for (std::int32_t i = 0; i < m_LosVerticesPerSide; ++i) { // TODO: This fetches data redundantly if the los grid is smaller than the territory grid // (but it's unlikely to matter much). @@ -2400,13 +2401,13 @@ public: /** * Update the LOS state of tiles within a given horizontal strip (i0,j) to (i1,j) (inclusive). */ - inline void LosAddStripHelper(u8 owner, i32 i0, i32 i1, i32 j, Grid& counts) + inline void LosAddStripHelper(u8 owner, std::int32_t i0, std::int32_t i1, std::int32_t j, Grid& counts) { if (i1 < i0) return; u32 &explored = m_ExploredVertices.at(owner); - for (i32 i = i0; i <= i1; ++i) + for (std::int32_t i = i0; i <= i1; ++i) { // Increasing from zero to non-zero - move from unexplored/explored to visible+explored if (counts.get(i, j) == 0) @@ -2428,12 +2429,13 @@ public: /** * Update the LOS state of tiles within a given horizontal strip (i0,j) to (i1,j) (inclusive). */ - inline void LosRemoveStripHelper(u8 owner, i32 i0, i32 i1, i32 j, Grid& counts) + inline void LosRemoveStripHelper(u8 owner, std::int32_t i0, std::int32_t i1, std::int32_t j, + Grid& counts) { if (i1 < i0) return; - for (i32 i = i0; i <= i1; ++i) + for (std::int32_t i = i0; i <= i1; ++i) { ASSERT(counts.get(i, j) > 0); counts.get(i, j) = (u16)(counts.get(i, j) - 1); @@ -2449,7 +2451,7 @@ public: } } - inline void MarkVisibilityDirtyAroundTile(u8 owner, i32 i, i32 j) + inline void MarkVisibilityDirtyAroundTile(u8 owner, std::int32_t i, std::int32_t j) { // If we're still in the deserializing process, we must not modify m_DirtyVisibility if (m_Deserializing) @@ -2504,10 +2506,10 @@ public: // Compute top/bottom coordinates, and clamp to exclude the 1-tile border around the map // (so that we never render the sharp edge of the map) - i32 j0 = ((pos.Y - visionRange)/LOS_TILE_SIZE).ToInt_RoundToInfinity(); - i32 j1 = ((pos.Y + visionRange)/LOS_TILE_SIZE).ToInt_RoundToNegInfinity(); - i32 j0clamp = std::max(j0, 1); - i32 j1clamp = std::min(j1, m_LosVerticesPerSide-2); + std::int32_t j0 = ((pos.Y - visionRange)/LOS_TILE_SIZE).ToInt_RoundToInfinity(); + std::int32_t j1 = ((pos.Y + visionRange)/LOS_TILE_SIZE).ToInt_RoundToNegInfinity(); + std::int32_t j0clamp = std::max(j0, 1); + std::int32_t j1clamp = std::min(j1, m_LosVerticesPerSide-2); // Translate world coordinates into fractional tile-space coordinates entity_pos_t x = pos.X / LOS_TILE_SIZE; @@ -2516,14 +2518,14 @@ public: entity_pos_t r2 = r.Square(); // Compute the integers on either side of x - i32 xfloor = (x - entity_pos_t::Epsilon()).ToInt_RoundToNegInfinity(); - i32 xceil = (x + entity_pos_t::Epsilon()).ToInt_RoundToInfinity(); + std::int32_t xfloor = (x - entity_pos_t::Epsilon()).ToInt_RoundToNegInfinity(); + std::int32_t xceil = (x + entity_pos_t::Epsilon()).ToInt_RoundToInfinity(); // Initialise the strip (i0, i1) to a rough guess - i32 i0 = xfloor; - i32 i1 = xceil; + std::int32_t i0 = xfloor; + std::int32_t i1 = xceil; - for (i32 j = j0clamp; j <= j1clamp; ++j) + for (std::int32_t j = j0clamp; j <= j1clamp; ++j) { // Adjust i0 and i1 to be the outermost values that don't exceed // the circle's radius (i.e. require dy^2 + dx^2 <= r^2). @@ -2553,8 +2555,8 @@ public: // Clamp the strip to exclude the 1-tile border, // then add or remove the strip as requested - i32 i0clamp = std::max(i0, 1); - i32 i1clamp = std::min(i1, m_LosVerticesPerSide-2); + std::int32_t i0clamp = std::max(i0, 1); + std::int32_t i1clamp = std::min(i1, m_LosVerticesPerSide-2); if (adding) LosAddStripHelper(owner, i0clamp, i1clamp, j, counts); else @@ -2587,12 +2589,12 @@ public: // so we can compute the difference between the removed/added strips // and only have to touch tiles that have a net change.) - i32 j0_from = ((from.Y - visionRange)/LOS_TILE_SIZE).ToInt_RoundToInfinity(); - i32 j1_from = ((from.Y + visionRange)/LOS_TILE_SIZE).ToInt_RoundToNegInfinity(); - i32 j0_to = ((to.Y - visionRange)/LOS_TILE_SIZE).ToInt_RoundToInfinity(); - i32 j1_to = ((to.Y + visionRange)/LOS_TILE_SIZE).ToInt_RoundToNegInfinity(); - i32 j0clamp = std::max(std::min(j0_from, j0_to), 1); - i32 j1clamp = std::min(std::max(j1_from, j1_to), m_LosVerticesPerSide-2); + std::int32_t j0_from = ((from.Y - visionRange)/LOS_TILE_SIZE).ToInt_RoundToInfinity(); + std::int32_t j1_from = ((from.Y + visionRange)/LOS_TILE_SIZE).ToInt_RoundToNegInfinity(); + std::int32_t j0_to = ((to.Y - visionRange)/LOS_TILE_SIZE).ToInt_RoundToInfinity(); + std::int32_t j1_to = ((to.Y + visionRange)/LOS_TILE_SIZE).ToInt_RoundToNegInfinity(); + std::int32_t j0clamp = std::max(std::min(j0_from, j0_to), 1); + std::int32_t j1clamp = std::min(std::max(j1_from, j1_to), m_LosVerticesPerSide-2); entity_pos_t x_from = from.X / LOS_TILE_SIZE; entity_pos_t y_from = from.Y / LOS_TILE_SIZE; @@ -2601,17 +2603,17 @@ public: entity_pos_t r = visionRange / LOS_TILE_SIZE; entity_pos_t r2 = r.Square(); - i32 xfloor_from = (x_from - entity_pos_t::Epsilon()).ToInt_RoundToNegInfinity(); - i32 xceil_from = (x_from + entity_pos_t::Epsilon()).ToInt_RoundToInfinity(); - i32 xfloor_to = (x_to - entity_pos_t::Epsilon()).ToInt_RoundToNegInfinity(); - i32 xceil_to = (x_to + entity_pos_t::Epsilon()).ToInt_RoundToInfinity(); + std::int32_t xfloor_from = (x_from - entity_pos_t::Epsilon()).ToInt_RoundToNegInfinity(); + std::int32_t xceil_from = (x_from + entity_pos_t::Epsilon()).ToInt_RoundToInfinity(); + std::int32_t xfloor_to = (x_to - entity_pos_t::Epsilon()).ToInt_RoundToNegInfinity(); + std::int32_t xceil_to = (x_to + entity_pos_t::Epsilon()).ToInt_RoundToInfinity(); - i32 i0_from = xfloor_from; - i32 i1_from = xceil_from; - i32 i0_to = xfloor_to; - i32 i1_to = xceil_to; + std::int32_t i0_from = xfloor_from; + std::int32_t i1_from = xceil_from; + std::int32_t i0_to = xfloor_to; + std::int32_t i1_to = xceil_to; - for (i32 j = j0clamp; j <= j1clamp; ++j) + for (std::int32_t j = j0clamp; j <= j1clamp; ++j) { entity_pos_t dy_from = entity_pos_t::FromInt(j) - y_from; entity_pos_t dy2_from = dy_from.Square(); @@ -2655,10 +2657,10 @@ public: // Check whether this strip moved at all if (!(i0_to == i0_from && i1_to == i1_from)) { - i32 i0clamp_from = std::max(i0_from, 1); - i32 i1clamp_from = std::min(i1_from, m_LosVerticesPerSide-2); - i32 i0clamp_to = std::max(i0_to, 1); - i32 i1clamp_to = std::min(i1_to, m_LosVerticesPerSide-2); + std::int32_t i0clamp_from = std::max(i0_from, 1); + std::int32_t i1clamp_from = std::min(i1_from, m_LosVerticesPerSide-2); + std::int32_t i0clamp_to = std::max(i0_to, 1); + std::int32_t i1clamp_to = std::min(i1_to, m_LosVerticesPerSide-2); // Check whether one strip is negative width, // and we can just add/remove the entire other strip @@ -2762,8 +2764,8 @@ public: u32 exploredVertices = 0; std::vector::const_iterator playerIt; - for (i32 j = 0; j < m_LosVerticesPerSide; j++) - for (i32 i = 0; i < m_LosVerticesPerSide; i++) + for (std::int32_t j = 0; j < m_LosVerticesPerSide; j++) + for (std::int32_t i = 0; i < m_LosVerticesPerSide; i++) { if (LosIsOffWorld(i, j)) continue; diff --git a/source/simulation2/components/CCmpTerrain.cpp b/source/simulation2/components/CCmpTerrain.cpp index 60cfa2a34e..d5a9e08995 100644 --- a/source/simulation2/components/CCmpTerrain.cpp +++ b/source/simulation2/components/CCmpTerrain.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -158,7 +158,7 @@ public: MakeDirty(0, 0, tiles+1, tiles+1); } - void MakeDirty(i32 i0, i32 j0, i32 i1, i32 j1) override + void MakeDirty(std::int32_t i0, std::int32_t j0, std::int32_t i1, std::int32_t j1) override { CMessageTerrainChanged msg(i0, j0, i1, j1); GetSimContext().GetComponentManager().BroadcastMessage(msg); diff --git a/source/simulation2/components/ICmpTerrain.h b/source/simulation2/components/ICmpTerrain.h index d97ec6705c..d24295543b 100644 --- a/source/simulation2/components/ICmpTerrain.h +++ b/source/simulation2/components/ICmpTerrain.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -73,7 +73,7 @@ public: * exclusive upper bound) have been changed. CMessageTerrainChanged will be * sent to any components that care about terrain changes. */ - virtual void MakeDirty(i32 i0, i32 j0, i32 i1, i32 j1) = 0; + virtual void MakeDirty(std::int32_t i0, std::int32_t j0, std::int32_t i1, std::int32_t j1) = 0; DECLARE_INTERFACE_TYPE(Terrain) }; diff --git a/source/simulation2/helpers/LongPathfinder.h b/source/simulation2/helpers/LongPathfinder.h index d033532a21..4654b48ce6 100644 --- a/source/simulation2/helpers/LongPathfinder.h +++ b/source/simulation2/helpers/LongPathfinder.h @@ -109,12 +109,12 @@ public: int GetPredDI() const { - return (i32)data >> 17; + return static_cast(data) >> 17; } int GetPredDJ() const { - return ((i32)data << 15) >> 17; + return (static_cast(data) << 15) >> 17; } // Set the pi,pj coords of predecessor, given i,j coords of this tile diff --git a/source/simulation2/helpers/Los.h b/source/simulation2/helpers/Los.h index ca6e73dcf7..a9d49f105b 100644 --- a/source/simulation2/helpers/Los.h +++ b/source/simulation2/helpers/Los.h @@ -29,7 +29,7 @@ * This is the size, in meters, separating each LOS vertex. * (Note that this also means it is the minimal meaningful resolution of any vision range change). */ -static constexpr i32 LOS_TILE_SIZE = 4; +static constexpr std::int32_t LOS_TILE_SIZE = 4; enum class LosState : u8 { diff --git a/source/simulation2/serialization/BinarySerializer.cpp b/source/simulation2/serialization/BinarySerializer.cpp index a16b058c2d..03059b3062 100644 --- a/source/simulation2/serialization/BinarySerializer.cpp +++ b/source/simulation2/serialization/BinarySerializer.cpp @@ -421,7 +421,7 @@ void CBinarySerializerScriptImpl::HandleScriptVal(const Script::Request& rq, JS: // their binary representation and thus the hash would be different. double d; d = val.toNumber(); - i32 integer; + std::int32_t integer; if (JS_DoubleIsInt32(d, &integer)) { diff --git a/source/simulation2/serialization/BinarySerializer.h b/source/simulation2/serialization/BinarySerializer.h index 0b41cbd693..15e8445a47 100644 --- a/source/simulation2/serialization/BinarySerializer.h +++ b/source/simulation2/serialization/BinarySerializer.h @@ -187,7 +187,7 @@ protected: virtual void PutNumber(const char* name, int32_t value) { - int32_t v = (i32)to_le32((u32)value); + int32_t v = static_cast(to_le32((u32)value)); m_Impl.Put(name, (const u8*)&v, sizeof(int32_t)); } @@ -203,7 +203,7 @@ protected: virtual void PutNumber(const char* name, fixed value) { - int32_t v = (i32)to_le32((u32)value.GetInternalValue()); + int32_t v = static_cast(to_le32((u32)value.GetInternalValue())); m_Impl.Put(name, (const u8*)&v, sizeof(int32_t)); } diff --git a/source/simulation2/serialization/IDeserializer.cpp b/source/simulation2/serialization/IDeserializer.cpp index f449bb6029..aace2d7104 100644 --- a/source/simulation2/serialization/IDeserializer.cpp +++ b/source/simulation2/serialization/IDeserializer.cpp @@ -91,7 +91,7 @@ void IDeserializer::NumberI32(const char* name, int32_t& out, int32_t lower, int { int32_t value; Get(name, (u8*)&value, sizeof(uint32_t)); - value = (i32)to_le32((u32)value); + value = static_cast(to_le32((u32)value)); if (!(lower <= value && value <= upper)) throw PSERROR_Deserialize_OutOfBounds(name); @@ -134,7 +134,7 @@ void IDeserializer::NumberI32_Unbounded(const char* name, int32_t& out) { int32_t value; Get(name, (u8*)&value, sizeof(int32_t)); - out = (i32)to_le32((u32)value); + out = static_cast(to_le32((u32)value)); } void IDeserializer::NumberFloat_Unbounded(const char* name, float& out) diff --git a/source/simulation2/serialization/SerializedTypes.h b/source/simulation2/serialization/SerializedTypes.h index e107d790dc..5634fb8fd0 100644 --- a/source/simulation2/serialization/SerializedTypes.h +++ b/source/simulation2/serialization/SerializedTypes.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -212,14 +212,14 @@ struct SerializeHelper }; template<> -struct SerializeHelper +struct SerializeHelper { - void operator()(ISerializer& serialize, const char* name, i32 value) + void operator()(ISerializer& serialize, const char* name, std::int32_t value) { serialize.NumberI32_Unbounded(name, value); } - void operator()(IDeserializer& deserialize, const char* name, i32& value) + void operator()(IDeserializer& deserialize, const char* name, std::int32_t& value) { deserialize.NumberI32_Unbounded(name, value); } diff --git a/source/simulation2/serialization/StdDeserializer.cpp b/source/simulation2/serialization/StdDeserializer.cpp index f2253d5b8f..b3d88b3d09 100644 --- a/source/simulation2/serialization/StdDeserializer.cpp +++ b/source/simulation2/serialization/StdDeserializer.cpp @@ -282,7 +282,7 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* /*name*/, JS::HandleObject } case SCRIPT_TYPE_BACKREF: { - i32 tag; + std::int32_t tag; NumberI32("tag", tag, 0, JSVAL_INT_MAX); JS::RootedObject obj(rq.cx); GetScriptBackref(tag, &obj); diff --git a/source/simulation2/system/ComponentTest.h b/source/simulation2/system/ComponentTest.h index 832f959a2d..41ba6e0ce9 100644 --- a/source/simulation2/system/ComponentTest.h +++ b/source/simulation2/system/ComponentTest.h @@ -250,7 +250,7 @@ public: return nullptr; } - void MakeDirty(i32 /*i0*/, i32 /*j0*/, i32 /*i1*/, i32 /*j1*/) override + void MakeDirty(std::int32_t /*i0*/, std::int32_t /*j0*/, std::int32_t /*i1*/, std::int32_t /*j1*/) override { }