mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-26 08:15:53 +00:00
Remove i32
It's better to use types from the standard library.
This commit is contained in:
@@ -175,8 +175,8 @@ void CTerritoryTexture::GenerateBitmap(const Grid<u8>& territories, u8* bitmap,
|
||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(m_Simulation, SYSTEM_ENTITY);
|
||||
|
||||
std::vector<CColor> 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<ICmpPlayer> cmpPlayer(m_Simulation, cmpPlayerManager->GetPlayerByID(p));
|
||||
|
||||
@@ -119,7 +119,7 @@ void CGUISimpleSetting<T>::ToJSVal(const Script::Request& rq, JS::MutableHandleV
|
||||
template class CGUISimpleSetting<T>;
|
||||
|
||||
TYPE(bool)
|
||||
TYPE(i32)
|
||||
TYPE(std::int32_t)
|
||||
TYPE(u32)
|
||||
TYPE(float)
|
||||
TYPE(CVector2D)
|
||||
|
||||
@@ -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<bool>(const CGUI*, const CStrW& Value, bool& Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool CGUI::ParseString<i32>(const CGUI*, const CStrW& Value, int& Output)
|
||||
bool CGUI::ParseString<std::int32_t>(const CGUI*, const CStrW& Value, int& Output)
|
||||
{
|
||||
Output = Value.ToInt();
|
||||
return true;
|
||||
|
||||
@@ -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 <string>
|
||||
@@ -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<CTooltip*>(pGUI.FindObjectByName("__tooltip_" + style));
|
||||
|
||||
@@ -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<i32> m_BufferPosition;
|
||||
CGUISimpleSetting<std::int32_t> m_BufferPosition;
|
||||
CGUISimpleSetting<float> m_BufferZone;
|
||||
CGUISimpleSetting<CStrW> m_Caption;
|
||||
CGUISimpleSetting<CGUIString> m_PlaceholderText;
|
||||
CGUISimpleSetting<CStrW> m_Font;
|
||||
CGUISimpleSetting<CStrW> m_MaskChar;
|
||||
CGUISimpleSetting<bool> m_Mask;
|
||||
CGUISimpleSetting<i32> m_MaxLength;
|
||||
CGUISimpleSetting<std::int32_t> m_MaxLength;
|
||||
CGUISimpleSetting<bool> m_MultiLine;
|
||||
CGUISimpleSetting<bool> m_Readonly;
|
||||
CGUISimpleSetting<bool> m_ScrollBar;
|
||||
|
||||
@@ -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<CGUISpriteInstance> m_SpriteSelectAreaOverlay;
|
||||
CGUISimpleSetting<CGUIColor> m_TextColor;
|
||||
CGUISimpleSetting<CGUIColor> m_TextColorSelected;
|
||||
CGUISimpleSetting<i32> m_Selected;
|
||||
CGUISimpleSetting<std::int32_t> m_Selected;
|
||||
CGUISimpleSetting<bool> m_AutoScroll;
|
||||
CGUISimpleSetting<i32> m_Hovered;
|
||||
CGUISimpleSetting<std::int32_t> m_Hovered;
|
||||
CGUISimpleSetting<CGUIList> m_List;
|
||||
CGUISimpleSetting<CGUIList> m_ListData;
|
||||
|
||||
|
||||
@@ -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 <string>
|
||||
@@ -54,7 +53,7 @@ public:
|
||||
CGUISimpleSetting<CStrW> m_Heading; // CGUIString??
|
||||
CGUISimpleSetting<CGUIList> m_List;
|
||||
CGUISimpleSetting<bool> m_Hidden;
|
||||
CGUISimpleSetting<i32> m_SortOrder;
|
||||
CGUISimpleSetting<std::int32_t> m_SortOrder;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -96,7 +95,7 @@ protected:
|
||||
CGUISimpleSetting<CGUISpriteInstance> m_SpriteHeading;
|
||||
CGUISimpleSetting<bool> m_Sortable;
|
||||
CGUISimpleSetting<CStr> m_SelectedColumn;
|
||||
CGUISimpleSetting<i32> m_SelectedColumnOrder;
|
||||
CGUISimpleSetting<std::int32_t> m_SelectedColumnOrder;
|
||||
CGUISimpleSetting<CGUISpriteInstance> m_SpriteAsc;
|
||||
CGUISimpleSetting<CGUISpriteInstance> m_SpriteDesc;
|
||||
CGUISimpleSetting<CGUISpriteInstance> m_SpriteNotSorted;
|
||||
|
||||
@@ -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<CGUIString> m_Caption;
|
||||
CGUISimpleSetting<CStrW> m_Font;
|
||||
CGUISimpleSetting<CGUISpriteInstance> m_Sprite;
|
||||
CGUISimpleSetting<i32> m_Delay;
|
||||
CGUISimpleSetting<std::int32_t> m_Delay;
|
||||
CGUISimpleSetting<CGUIColor> m_TextColor;
|
||||
CGUISimpleSetting<float> m_MaxWidth;
|
||||
CGUISimpleSetting<CVector2D> m_Offset;
|
||||
|
||||
@@ -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<std::int32_t>(t->m_Height) :
|
||||
static_cast<std::int32_t>(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<std::int32_t>(t->m_Width),
|
||||
h,
|
||||
1, // biPlanes
|
||||
(u16)t->m_Bpp,
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
typedef int32_t i32;
|
||||
typedef int64_t i64;
|
||||
|
||||
typedef uint8_t u8;
|
||||
|
||||
@@ -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 <intrin.h>
|
||||
#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<T>::min(), std::min((i64)std::numeric_limits<T>::max(), t));
|
||||
return CFixed((i32)t);
|
||||
return CFixed(static_cast<std::int32_t>(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<i32, (i32)0x7fffffff, 32, 15, 16, 65536> CFixed_15_16;
|
||||
typedef CFixed<std::int32_t, static_cast<std::int32_t>(0x7fffffff), 32, 15, 16, 65536> CFixed_15_16;
|
||||
|
||||
/**
|
||||
* Default fixed-point type used by the engine.
|
||||
|
||||
@@ -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<i32>(d));
|
||||
r.SetInternalValue(static_cast<std::int32_t>(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<i32>(sum));
|
||||
ret.SetInternalValue(static_cast<std::int32_t>(sum));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::int32_t>(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<std::int32_t>(x));
|
||||
ret.Y.SetInternalValue(static_cast<std::int32_t>(y));
|
||||
ret.Z.SetInternalValue(static_cast<std::int32_t>(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<std::int32_t>(sum));
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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<float>::infinity());
|
||||
TS_ASSERT_EQUALS(c.GetInternalValue(), (i32)0);
|
||||
TS_ASSERT_EQUALS(c.GetInternalValue(), static_cast<std::int32_t>(0));
|
||||
|
||||
fixed d = fixed::FromFloat(-std::numeric_limits<float>::infinity());
|
||||
TS_ASSERT_EQUALS(d.GetInternalValue(), (i32)0);
|
||||
TS_ASSERT_EQUALS(d.GetInternalValue(), static_cast<std::int32_t>(0));
|
||||
|
||||
fixed e = fixed::FromFloat(std::numeric_limits<float>::quiet_NaN());
|
||||
TS_ASSERT_EQUALS(e.GetInternalValue(), (i32)0);
|
||||
TS_ASSERT_EQUALS(e.GetInternalValue(), static_cast<std::int32_t>(0));
|
||||
}
|
||||
|
||||
void test_FromDouble()
|
||||
@@ -93,13 +92,13 @@ public:
|
||||
TS_ASSERT_EQUALS(b.ToDouble(), -123.125);
|
||||
|
||||
fixed c = fixed::FromDouble(std::numeric_limits<double>::infinity());
|
||||
TS_ASSERT_EQUALS(c.GetInternalValue(), (i32)0);
|
||||
TS_ASSERT_EQUALS(c.GetInternalValue(), static_cast<std::int32_t>(0));
|
||||
|
||||
fixed d = fixed::FromDouble(-std::numeric_limits<double>::infinity());
|
||||
TS_ASSERT_EQUALS(d.GetInternalValue(), (i32)0);
|
||||
TS_ASSERT_EQUALS(d.GetInternalValue(), static_cast<std::int32_t>(0));
|
||||
|
||||
fixed e = fixed::FromDouble(std::numeric_limits<double>::quiet_NaN());
|
||||
TS_ASSERT_EQUALS(e.GetInternalValue(), (i32)0);
|
||||
TS_ASSERT_EQUALS(e.GetInternalValue(), static_cast<std::int32_t>(0));
|
||||
}
|
||||
|
||||
void test_FromFloat_Rounding()
|
||||
|
||||
@@ -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<std::int32_t>(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<std::int32_t>(static_cast<double>(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<std::int32_t>(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<std::int32_t>(static_cast<double>(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);
|
||||
|
||||
@@ -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<std::int32_t>(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<std::int32_t>(static_cast<double>(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<std::int32_t>(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<std::int32_t>(static_cast<double>(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);
|
||||
|
||||
@@ -208,7 +208,7 @@ bool CNetClient::TryToConnectWithSTUN(std::string serverAddressOrHostname, std::
|
||||
PushGuiMessage(
|
||||
"type", "netstatus",
|
||||
"status", "disconnected",
|
||||
"reason", static_cast<i32>(NDR_SERVER_REFUSED));
|
||||
"reason", static_cast<std::int32_t>(NDR_SERVER_REFUSED));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ bool CNetClient::TryToConnectWithSTUN(std::string serverAddressOrHostname, std::
|
||||
PushGuiMessage(
|
||||
"type", "netstatus",
|
||||
"status", "disconnected",
|
||||
"reason", static_cast<i32>(NDR_STUN_PORT_FAILED));
|
||||
"reason", static_cast<std::int32_t>(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<i32>(NDR_STUN_ENDPOINT_FAILED));
|
||||
"reason", static_cast<std::int32_t>(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<i32>(NDR_UNKNOWN));
|
||||
"reason", static_cast<std::int32_t>(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<int>(m_HostID), m_Game->GetReplayLogger()};
|
||||
@@ -722,7 +723,7 @@ bool CNetClient::OnHandshakeResponse(CNetClient* client, CFsmEvent<CNetMessage*>
|
||||
client->PushGuiMessage(
|
||||
"type", "netstatus",
|
||||
"status", "disconnected",
|
||||
"reason", static_cast<i32>(NDR_LOBBY_AUTH_FAILED));
|
||||
"reason", static_cast<std::int32_t>(NDR_LOBBY_AUTH_FAILED));
|
||||
|
||||
LOGMESSAGE("Net client: Couldn't send lobby auth xmpp message");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<JS::Value> m_Data;
|
||||
private:
|
||||
const Script::Interface& m_ScriptInterface;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<i32> usedIDs;
|
||||
std::set<std::int32_t> usedIDs;
|
||||
for (const std::pair<const CStr, PlayerAssignment>& 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)
|
||||
{
|
||||
|
||||
@@ -69,7 +69,7 @@ template<> bool FromJSVal<double>(const Request& rq, JS::HandleValue v, double&
|
||||
return true;
|
||||
}
|
||||
|
||||
template<> bool FromJSVal<i32>(const Request& rq, JS::HandleValue v, i32& out)
|
||||
template<> bool FromJSVal<std::int32_t>(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<double>(const Request&, JS::MutableHandleValue ret, cons
|
||||
ret.set(JS::NumberValue(val));
|
||||
}
|
||||
|
||||
template<> void ToJSVal<i32>(const Request&, JS::MutableHandleValue ret, const i32& val)
|
||||
template<> void ToJSVal<std::int32_t>(const Request&, JS::MutableHandleValue ret, const std::int32_t& val)
|
||||
{
|
||||
ret.set(JS::NumberValue(val));
|
||||
}
|
||||
@@ -299,4 +299,4 @@ template<> bool Script::FromJSVal<std::vector<Entity>>(const Script::Request& rq
|
||||
}
|
||||
|
||||
#undef FAIL
|
||||
#undef FAIL_IF_NOT
|
||||
#undef FAIL_IF_NOT
|
||||
|
||||
@@ -126,13 +126,13 @@ public:
|
||||
roundtrip<float>(1e9f, "1000000000");
|
||||
roundtrip<float>(1e30f, "1.0000000150474662e+30");
|
||||
|
||||
roundtrip<i32>(0, "0");
|
||||
roundtrip<i32>(123, "123");
|
||||
roundtrip<i32>(-123, "-123");
|
||||
roundtrip<i32>(JSVAL_INT_MAX - 1, "2147483646");
|
||||
roundtrip<i32>(JSVAL_INT_MAX, "2147483647");
|
||||
roundtrip<i32>(JSVAL_INT_MIN + 1, "-2147483647");
|
||||
roundtrip<i32>(JSVAL_INT_MIN, "-2147483648");
|
||||
roundtrip<std::int32_t>(0, "0");
|
||||
roundtrip<std::int32_t>(123, "123");
|
||||
roundtrip<std::int32_t>(-123, "-123");
|
||||
roundtrip<std::int32_t>(JSVAL_INT_MAX - 1, "2147483646");
|
||||
roundtrip<std::int32_t>(JSVAL_INT_MAX, "2147483647");
|
||||
roundtrip<std::int32_t>(JSVAL_INT_MIN + 1, "-2147483647");
|
||||
roundtrip<std::int32_t>(JSVAL_INT_MIN, "-2147483648");
|
||||
|
||||
roundtrip<u32>(0, "0");
|
||||
roundtrip<u32>(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<i32>(rq, &val0, 0);
|
||||
Script::ToJSVal<i32>(rq, &val1, JSVAL_INT_MAX - 1);
|
||||
Script::ToJSVal<i32>(rq, &val2, JSVAL_INT_MAX);
|
||||
Script::ToJSVal<i32>(rq, &val3, JSVAL_INT_MIN + 1);
|
||||
Script::ToJSVal<i32>(rq, &val4, -(i64)2147483648u); // JSVAL_INT_MIN
|
||||
Script::ToJSVal<std::int32_t>(rq, &val0, 0);
|
||||
Script::ToJSVal<std::int32_t>(rq, &val1, JSVAL_INT_MAX - 1);
|
||||
Script::ToJSVal<std::int32_t>(rq, &val2, JSVAL_INT_MAX);
|
||||
Script::ToJSVal<std::int32_t>(rq, &val3, JSVAL_INT_MIN + 1);
|
||||
Script::ToJSVal<std::int32_t>(rq, &val4, -(i64)2147483648u); // JSVAL_INT_MIN
|
||||
TS_ASSERT(val0.isInt32());
|
||||
TS_ASSERT(val1.isInt32());
|
||||
TS_ASSERT(val2.isInt32());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<u8>(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<u8>(size, size);
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity());
|
||||
|
||||
@@ -964,8 +964,8 @@ std::vector<CFixedVector2D> CCmpPathfinder::DistributeAround(std::vector<entity_
|
||||
{
|
||||
// Helper to compute squared distance between two points as integers
|
||||
auto distSq = [](const CFixedVector2D& p1, const CFixedVector2D& p2) -> 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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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<bool, MAX_LOS_PLAYER_ID+1> 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<bool, MAX_LOS_PLAYER_ID> m_GlobalPlayerVisibilityUpdate;
|
||||
Grid<u16> 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<i32>(isqrt64(
|
||||
effectiveRange.SetInternalValue(static_cast<std::int32_t>(isqrt64(
|
||||
SQUARE_U64_FIXED(range) +
|
||||
static_cast<i64>(heightDiff.GetInternalValue()) * static_cast<i64>(range.GetInternalValue()) * 2
|
||||
)));
|
||||
@@ -1501,7 +1501,8 @@ public:
|
||||
i64 numerator = rangeSq - distSq;
|
||||
|
||||
entity_pos_t result;
|
||||
result.SetInternalValue(static_cast<i32>(numerator / (static_cast<i64>(range.GetInternalValue()) * 2)));
|
||||
result.SetInternalValue(static_cast<std::int32_t>(numerator /
|
||||
(static_cast<i64>(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<u16>& counts)
|
||||
inline void LosAddStripHelper(u8 owner, std::int32_t i0, std::int32_t i1, std::int32_t j, Grid<u16>& 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<u16>& counts)
|
||||
inline void LosRemoveStripHelper(u8 owner, std::int32_t i0, std::int32_t i1, std::int32_t j,
|
||||
Grid<u16>& 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<player_id_t>::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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
|
||||
@@ -109,12 +109,12 @@ public:
|
||||
|
||||
int GetPredDI() const
|
||||
{
|
||||
return (i32)data >> 17;
|
||||
return static_cast<std::int32_t>(data) >> 17;
|
||||
}
|
||||
|
||||
int GetPredDJ() const
|
||||
{
|
||||
return ((i32)data << 15) >> 17;
|
||||
return (static_cast<std::int32_t>(data) << 15) >> 17;
|
||||
}
|
||||
|
||||
// Set the pi,pj coords of predecessor, given i,j coords of this tile
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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<std::int32_t>(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<std::int32_t>(to_le32((u32)value.GetInternalValue()));
|
||||
m_Impl.Put(name, (const u8*)&v, sizeof(int32_t));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::int32_t>(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<std::int32_t>(to_le32((u32)value));
|
||||
}
|
||||
|
||||
void IDeserializer::NumberFloat_Unbounded(const char* name, float& out)
|
||||
|
||||
@@ -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<u32>
|
||||
};
|
||||
|
||||
template<>
|
||||
struct SerializeHelper<i32>
|
||||
struct SerializeHelper<std::int32_t>
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user