diff --git a/source/graphics/Canvas2D.cpp b/source/graphics/Canvas2D.cpp index 954176e7e1..e912f7f713 100644 --- a/source/graphics/Canvas2D.cpp +++ b/source/graphics/Canvas2D.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 @@ -27,7 +27,6 @@ #include "graphics/TextRenderer.h" #include "graphics/TextureManager.h" #include "lib/debug.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "maths/Rect.h" #include "maths/Vector2D.h" @@ -280,7 +279,7 @@ void CCanvas2D::DrawLine(const std::vector& points, const float width std::vector> vertices; std::vector> uvs; - std::vector indices; + std::vector indices; const size_t reserveSize = 2 * pointsIndices.size() - 1; vertices.reserve(reserveSize); uvs.reserve(reserveSize); @@ -290,7 +289,7 @@ void CCanvas2D::DrawLine(const std::vector& points, const float width { if (!vertices.empty()) { - const u16 lastVertexIndex = static_cast(vertices.size() * 3 - 1); + const std::uint16_t lastVertexIndex = static_cast(vertices.size() * 3 - 1); ENSURE(lastVertexIndex >= 2); // First vertical half of the segment. indices.emplace_back(lastVertexIndex - 2); diff --git a/source/graphics/Entity.h b/source/graphics/Entity.h index ce3178b1a4..71984fab21 100644 --- a/source/graphics/Entity.h +++ b/source/graphics/Entity.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 @@ -19,7 +19,6 @@ #define INCLUDED_RMS_ENTITY #include "lib/code_annotation.h" -#include "lib/types.h" #include "maths/FixedVector3D.h" #include @@ -28,8 +27,8 @@ struct Entity { std::wstring templateName; - u16 entityID; - u16 playerID; + std::uint16_t entityID; + std::uint16_t playerID; CFixedVector3D position; CFixedVector3D rotation; }; diff --git a/source/graphics/Font.cpp b/source/graphics/Font.cpp index 5224d78e9b..f45d7feaca 100644 --- a/source/graphics/Font.cpp +++ b/source/graphics/Font.cpp @@ -72,7 +72,7 @@ using UniqueFTGlyph = std::unique_ptr, FTGlyphDe } // end namespace -const CFont::GlyphData* CFont::GlyphMap::get(u16 codepoint) const +const CFont::GlyphData* CFont::GlyphMap::get(std::uint16_t codepoint) const { if (!m_Data[codepoint >> 8]) return nullptr; @@ -81,7 +81,7 @@ const CFont::GlyphData* CFont::GlyphMap::get(u16 codepoint) const return &(*m_Data[codepoint >> 8])[codepoint & 0xff]; } -void CFont::GlyphMap::set(u16 codepoint, const GlyphData& glyph) +void CFont::GlyphMap::set(std::uint16_t codepoint, const GlyphData& glyph) { if (!m_Data[codepoint >> 8]) m_Data[codepoint >> 8] = std::make_unique>(); @@ -326,13 +326,13 @@ void CFont::InitalizeAtlasTextureIfNeeded( m_IsTextureInitialized = true; } -const CFont::GlyphData* CFont::GetGlyph(u16 codepoint) +const CFont::GlyphData* CFont::GetGlyph(std::uint16_t codepoint) { const CFont::GlyphData* g{m_Glyphs.get(codepoint)}; return (g && g->defined) ? g : ExtractAndGenerateGlyph(codepoint); } -const CFont::GlyphData* CFont::ExtractAndGenerateGlyph(u16 codepoint) +const CFont::GlyphData* CFont::ExtractAndGenerateGlyph(std::uint16_t codepoint) { ENSURE(!m_Faces.empty()); PROFILE2("Glyph font texture generate"); @@ -431,7 +431,8 @@ const CFont::GlyphData* CFont::ExtractAndGenerateGlyph(u16 codepoint) return m_Glyphs.get(codepoint); } -std::optional CFont::GenerateStrokeGlyphBitmap(const FT_Glyph& glyph, u16 codepoint, FT_Render_Mode renderMode, const float baselineInAtlas) +std::optional CFont::GenerateStrokeGlyphBitmap(const FT_Glyph& glyph, std::uint16_t codepoint, + FT_Render_Mode renderMode, const float baselineInAtlas) { FT_Glyph strokedGlyph; if (FT_Error error{FT_Glyph_Copy(glyph, &strokedGlyph)}) @@ -476,7 +477,8 @@ std::optional CFont::GenerateStrokeGlyphBitmap(const FT_Glyph& glyph, return offset; } -std::optional CFont::GenerateGlyphBitmap(FT_Glyph& glyph, u16 codepoint, FT_Render_Mode renderMode, CVector2D offset, const float baselineInAtlas) +std::optional CFont::GenerateGlyphBitmap(FT_Glyph& glyph, std::uint16_t codepoint, + FT_Render_Mode renderMode, CVector2D offset, const float baselineInAtlas) { if (FT_Error error{FT_Glyph_To_Bitmap(&glyph, renderMode, nullptr, 0)}) { diff --git a/source/graphics/Font.h b/source/graphics/Font.h index 085c55715a..bf4fa2976b 100644 --- a/source/graphics/Font.h +++ b/source/graphics/Font.h @@ -22,7 +22,6 @@ #include "lib/allocators/shared_ptr.h" #include "lib/code_annotation.h" #include "lib/os_path.h" -#include "lib/types.h" #include "maths/Rect.h" #include "renderer/backend/Format.h" @@ -86,9 +85,9 @@ public: * @param codepoint The unicode codepoint (0 ≤ cp ≤ 0x10FFFF) * @param glyph The glyphData data to store */ - void set(u16 codepoint, const GlyphData& glyph); + void set(std::uint16_t codepoint, const GlyphData& glyph); - const GlyphData* get(u16 codepoint) const; + const GlyphData* get(std::uint16_t codepoint) const; private: std::unique_ptr> m_Data[256]; }; @@ -120,7 +119,7 @@ public: Renderer::Backend::IDeviceCommandContext* deviceCommandContext); void UploadAtlasTextureToGPU( Renderer::Backend::IDeviceCommandContext* deviceCommandContext); - const GlyphData* GetGlyph(u16 i); + const GlyphData* GetGlyph(std::uint16_t i); private: static void ftFaceDeleter(FT_Face face) @@ -149,10 +148,12 @@ private: std::uint8_t g, std::uint8_t b); void BlendGlyphBitmapToTextureR8(const FT_Bitmap& bitmap, int targetX, int targetY); - std::optional GenerateStrokeGlyphBitmap(const FT_Glyph& glyph, u16 codepoint, FT_Render_Mode renderMode, const float baselineInAtlas); - std::optional GenerateGlyphBitmap(FT_Glyph& glyph, u16 codepoint, FT_Render_Mode renderMode, CVector2D offset, const float baselineInAtlas); + std::optional GenerateStrokeGlyphBitmap(const FT_Glyph& glyph, std::uint16_t codepoint, + FT_Render_Mode renderMode, const float baselineInAtlas); + std::optional GenerateGlyphBitmap(FT_Glyph& glyph, std::uint16_t codepoint, + FT_Render_Mode renderMode, CVector2D offset, const float baselineInAtlas); - const GlyphData* ExtractAndGenerateGlyph(u16 codepoint); + const GlyphData* ExtractAndGenerateGlyph(std::uint16_t codepoint); bool ConstructAtlasTexture(Renderer::Backend::IDevice* device); Renderer::Backend::Sampler::Desc ChooseTextureFormatAndSampler(); diff --git a/source/graphics/HFTracer.cpp b/source/graphics/HFTracer.cpp index 601f543c9a..7aa8ae2e83 100644 --- a/source/graphics/HFTracer.cpp +++ b/source/graphics/HFTracer.cpp @@ -235,12 +235,12 @@ bool CHFTracer::RayIntersect(const CVector3D& origin, const CVector3D& dir, int& return false; } -static bool TestTile(u16* heightmap, int stride, int i, int j, const CVector3D& pos, const CVector3D& dir, CVector3D& isct) +static bool TestTile(std::uint16_t* heightmap, int stride, int i, int j, const CVector3D& pos, const CVector3D& dir, CVector3D& isct) { - u16 y00 = heightmap[i + j*stride]; - u16 y10 = heightmap[i+1 + j*stride]; - u16 y01 = heightmap[i + (j+1)*stride]; - u16 y11 = heightmap[i+1 + (j+1)*stride]; + std::uint16_t y00 = heightmap[i + j*stride]; + std::uint16_t y10 = heightmap[i+1 + j*stride]; + std::uint16_t y01 = heightmap[i + (j+1)*stride]; + std::uint16_t y11 = heightmap[i+1 + (j+1)*stride]; CVector3D p00( i * TERRAIN_TILE_SIZE, y00 * HEIGHT_SCALE, j * TERRAIN_TILE_SIZE); CVector3D p10((i+1) * TERRAIN_TILE_SIZE, y10 * HEIGHT_SCALE, j * TERRAIN_TILE_SIZE); @@ -298,7 +298,7 @@ bool CHFTracer::PatchRayIntersect(CPatch* patch, const CVector3D& origin, const int heightmapStride = patch->m_Parent->GetVerticesPerSide(); // Get heightmap, offset to start at this patch - u16* heightmap = patch->m_Parent->GetHeightMap() + + std::uint16_t* heightmap = patch->m_Parent->GetHeightMap() + patch->m_X * PATCH_SIZE + patch->m_Z * PATCH_SIZE * heightmapStride; diff --git a/source/graphics/HFTracer.h b/source/graphics/HFTracer.h index 10ce73103c..28626c3ee3 100644 --- a/source/graphics/HFTracer.h +++ b/source/graphics/HFTracer.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 @@ -22,8 +22,6 @@ #ifndef INCLUDED_HFTRACER #define INCLUDED_HFTRACER -#include "lib/types.h" - #include class CPatch; @@ -66,7 +64,7 @@ private: // The terrain we're operating on CTerrain& m_Terrain; // the heightfield were tracing - const u16* m_Heightfield; + const std::uint16_t* m_Heightfield; // size of the heightfield size_t m_MapSize; // cell size - size of each cell in x and z diff --git a/source/graphics/HeightMipmap.cpp b/source/graphics/HeightMipmap.cpp index de70f992e8..899fc7f7b2 100644 --- a/source/graphics/HeightMipmap.cpp +++ b/source/graphics/HeightMipmap.cpp @@ -56,14 +56,14 @@ void CHeightMipmap::ReleaseData() m_Mipmap.clear(); } -void CHeightMipmap::Update(const u16* ptr) +void CHeightMipmap::Update(const std::uint16_t* ptr) { ENSURE(ptr != 0); Update(ptr, 0, 0, m_MapSize, m_MapSize); } -void CHeightMipmap::Update(const u16* ptr, size_t left, size_t bottom, size_t right, size_t top) +void CHeightMipmap::Update(const std::uint16_t* ptr, size_t left, size_t bottom, size_t right, size_t top) { ENSURE(ptr != 0); @@ -88,7 +88,7 @@ void CHeightMipmap::Update(const u16* ptr, size_t left, size_t bottom, size_t ri } } -void CHeightMipmap::Initialize(size_t mapSize, const u16* ptr) +void CHeightMipmap::Initialize(size_t mapSize, const std::uint16_t* ptr) { ENSURE(ptr != 0); ENSURE(mapSize > 0); @@ -100,7 +100,7 @@ void CHeightMipmap::Initialize(size_t mapSize, const u16* ptr) while (mipmapSize > 1) { - m_Mipmap.push_back(SMipmap(mipmapSize, new u16[mipmapSize*mipmapSize])); + m_Mipmap.push_back(SMipmap(mipmapSize, new std::uint16_t[mipmapSize*mipmapSize])); mipmapSize >>= 1; }; @@ -148,7 +148,8 @@ float CHeightMipmap::BilinearFilter(const SMipmap &mipmap, float x, float z) con xf * zf * h11; } -void CHeightMipmap::HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const u16* ptr, size_t left, size_t bottom, size_t right, size_t top) +void CHeightMipmap::HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const std::uint16_t* ptr, + size_t left, size_t bottom, size_t right, size_t top) { // specialized, faster version of BilinearUpdate for powers of 2 @@ -170,17 +171,18 @@ void CHeightMipmap::HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const size_t srcX = dstX << 1; size_t srcZ = dstZ << 1; - u16 h00 = ptr[srcX + 0 + srcZ * mapSize]; - u16 h10 = ptr[srcX + 1 + srcZ * mapSize]; - u16 h01 = ptr[srcX + 0 + (srcZ + 1) * mapSize]; - u16 h11 = ptr[srcX + 1 + (srcZ + 1) * mapSize]; + std::uint16_t h00 = ptr[srcX + 0 + srcZ * mapSize]; + std::uint16_t h10 = ptr[srcX + 1 + srcZ * mapSize]; + std::uint16_t h01 = ptr[srcX + 0 + (srcZ + 1) * mapSize]; + std::uint16_t h11 = ptr[srcX + 1 + (srcZ + 1) * mapSize]; out_mipmap.m_Heightmap[dstX + dstZ * out_mipmap.m_MapSize] = (h00 + h10 + h01 + h11) / 4; } } } -void CHeightMipmap::BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u16* ptr, size_t left, size_t bottom, size_t right, size_t top) +void CHeightMipmap::BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const std::uint16_t* ptr, + size_t left, size_t bottom, size_t right, size_t top) { ENSURE(out_mipmap.m_MapSize != 0); @@ -218,11 +220,9 @@ void CHeightMipmap::BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u1 const float h01 = ptr[srcX + 0 + (srcZ + 1) * mapSize]; const float h11 = ptr[srcX + 1 + (srcZ + 1) * mapSize]; - out_mipmap.m_Heightmap[dstX + dstZ * out_mipmap.m_MapSize] = (u16) - ((1.f - fx) * (1.f - fz) * h00 + - fx * (1.f - fz) * h10 + - (1.f - fx) * fz * h01 + - fx * fz * h11); + out_mipmap.m_Heightmap[dstX + dstZ * out_mipmap.m_MapSize] = + static_cast((1.f - fx) * (1.f - fz) * h00 + + fx * (1.f - fz) * h10 + (1.f - fx) * fz * h01 + fx * fz * h11); } } } @@ -248,13 +248,13 @@ void CHeightMipmap::DumpToDisk(const VfsPath& filename) const for (size_t i = 0; i < m_Mipmap.size(); ++i) { size_t size = m_Mipmap[i].m_MapSize; - u16* heightmap = m_Mipmap[i].m_Heightmap; + std::uint16_t* heightmap = m_Mipmap[i].m_Heightmap; ENSURE(size+yoff <= h); for (size_t y = 0; y < size; ++y) { for (size_t x = 0; x < size; ++x) { - u16 val = heightmap[x + y*size]; + std::uint16_t val = heightmap[x + y*size]; static_cast(img)[x + (y+yoff)*w] = val >> 8; } } diff --git a/source/graphics/HeightMipmap.h b/source/graphics/HeightMipmap.h index f57e058eba..b965af49ef 100644 --- a/source/graphics/HeightMipmap.h +++ b/source/graphics/HeightMipmap.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 @@ -25,7 +25,6 @@ #define INCLUDED_HEIGHTMIPMAP #include "lib/code_annotation.h" -#include "lib/types.h" #include #include @@ -36,10 +35,10 @@ using VfsPath = Path; struct SMipmap { SMipmap() : m_MapSize(0), m_Heightmap(0) { } - SMipmap(size_t MapSize, u16* Heightmap) : m_MapSize(MapSize), m_Heightmap(Heightmap) { } + SMipmap(size_t MapSize, std::uint16_t* Heightmap) : m_MapSize(MapSize), m_Heightmap(Heightmap) { } size_t m_MapSize; - u16* m_Heightmap; + std::uint16_t* m_Heightmap; }; class CHeightMipmap @@ -50,16 +49,16 @@ public: CHeightMipmap(); ~CHeightMipmap(); - void Initialize(size_t mapSize, const u16* ptr); + void Initialize(size_t mapSize, const std::uint16_t* ptr); void ReleaseData(); // update the heightmap mipmaps - void Update(const u16* ptr); + void Update(const std::uint16_t* ptr); // update a section of the heightmap mipmaps // (coordinates are heightmap cells, inclusive of lower bounds, // exclusive of upper bounds) - void Update(const u16* ptr, size_t left, size_t bottom, size_t right, size_t top); + void Update(const std::uint16_t* ptr, size_t left, size_t bottom, size_t right, size_t top); float GetTrilinearGroundLevel(float x, float z, float radius) const; @@ -71,10 +70,10 @@ private: float BilinearFilter(const SMipmap &mipmap, float x, float z) const; // update rectangle of the output mipmap by bilinear interpolating an input mipmap of exactly twice its size - void HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const u16* ptr, size_t left, size_t bottom, size_t right, size_t top); + void HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const std::uint16_t* ptr, size_t left, size_t bottom, size_t right, size_t top); // update rectangle of the output mipmap by bilinear interpolating the input mipmap - void BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u16* ptr, size_t left, size_t bottom, size_t right, size_t top); + void BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const std::uint16_t* ptr, size_t left, size_t bottom, size_t right, size_t top); // size of this map in each direction size_t m_MapSize; diff --git a/source/graphics/MapGenerator.cpp b/source/graphics/MapGenerator.cpp index b776df5e9d..718a832fe6 100644 --- a/source/graphics/MapGenerator.cpp +++ b/source/graphics/MapGenerator.cpp @@ -79,7 +79,7 @@ public: // Only the constructor and the destructor are called by C++. CMapGenerationCallbacks(const StopToken stopToken, Script::Interface& scriptInterface, - const u16 flags) : + const std::uint16_t flags) : m_StopToken{stopToken}, m_ScriptInterface{scriptInterface} { @@ -193,7 +193,7 @@ private: */ JS::Value LoadHeightmapImage(const VfsPath& filename) { - std::vector heightmap; + std::vector heightmap; if (LoadHeightmapImageVfs(filename, heightmap) != INFO::OK) { LOGERROR("Could not load heightmap file '%s'", filename.string8()); @@ -235,9 +235,9 @@ private: size_t verticesPerSide = patchesPerSide * PATCH_SIZE + 1; // unpack heightmap - std::vector heightmap; + std::vector heightmap; heightmap.resize(SQR(verticesPerSide)); - unpacker.UnpackRaw(&heightmap[0], SQR(verticesPerSide) * sizeof(u16)); + unpacker.UnpackRaw(&heightmap[0], SQR(verticesPerSide) * sizeof(std::uint16_t)); // unpack texture names size_t textureCount = unpacker.UnpackSize(); @@ -257,7 +257,7 @@ private: unpacker.UnpackRaw(&tiles[0], sizeof(CMapIO::STileDesc) * tiles.size()); // reorder by patches and store and save texture IDs per tile - std::vector textureIDs; + std::vector textureIDs; for (ssize_t x = 0; x < tilesPerSide; ++x) { size_t patchX = x / PATCH_SIZE; @@ -353,7 +353,8 @@ bool MapGenerationInterruptCallback(JSContext* cx) } // anonymous namespace Script::StructuredClone RunMapGenerationScript(const StopToken stopToken, std::atomic& progress, - Script::Interface& scriptInterface, const VfsPath& script, const std::string& settings, const u16 flags) + Script::Interface& scriptInterface, const VfsPath& script, const std::string& settings, + const std::uint16_t flags) { Script::Request rq(scriptInterface); diff --git a/source/graphics/MapGenerator.h b/source/graphics/MapGenerator.h index 5419b350c9..8e4397485f 100644 --- a/source/graphics/MapGenerator.h +++ b/source/graphics/MapGenerator.h @@ -19,7 +19,6 @@ #define INCLUDED_MAPGENERATOR #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "scriptinterface/StructuredClone.h" #include @@ -49,6 +48,6 @@ constexpr std::wstring_view RANDOM_MAP_PREFIX{L"maps/random/"}; */ Script::StructuredClone RunMapGenerationScript(const StopToken stopToken, std::atomic& progress, Script::Interface& scriptInterface, const VfsPath& script, const std::string& settings, - const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + const std::uint16_t flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); #endif //INCLUDED_MAPGENERATOR diff --git a/source/graphics/MapIO.cpp b/source/graphics/MapIO.cpp index 616bf5a5ed..1f55ec7262 100644 --- a/source/graphics/MapIO.cpp +++ b/source/graphics/MapIO.cpp @@ -41,9 +41,9 @@ #include Status ParseHeightmapImage(const std::shared_ptr& fileData, size_t fileSize, - std::vector& heightmap); + std::vector& heightmap); -Status LoadHeightmapImageVfs(const VfsPath& filepath, std::vector& heightmap) +Status LoadHeightmapImageVfs(const VfsPath& filepath, std::vector& heightmap) { std::shared_ptr fileData; size_t fileSize; @@ -53,7 +53,7 @@ Status LoadHeightmapImageVfs(const VfsPath& filepath, std::vector& heightma return ParseHeightmapImage(fileData, fileSize, heightmap); } -Status LoadHeightmapImageOs(const OsPath& filepath, std::vector& heightmap) +Status LoadHeightmapImageOs(const OsPath& filepath, std::vector& heightmap) { File file; RETURN_STATUS_IF_ERR(file.Open(OsString(filepath), O_RDONLY)); @@ -74,7 +74,8 @@ Status LoadHeightmapImageOs(const OsPath& filepath, std::vector& heightmap) return ParseHeightmapImage(fileData, fileSize, heightmap); } -Status ParseHeightmapImage(const std::shared_ptr& fileData, size_t fileSize, std::vector& heightmap) +Status ParseHeightmapImage(const std::shared_ptr& fileData, size_t fileSize, + std::vector& heightmap) { // Decode to a raw pixel format Tex tex; @@ -101,7 +102,8 @@ Status ParseHeightmapImage(const std::shared_ptr& fileData, size_t { // Repeat the last pixel of the image for the last vertex of the heightmap int offset = std::min(y, tileSize - 1) * mapLineSkip + std::min(x, tileSize - 1); - heightmap[(tileSize - y) * (tileSize + 1) + x] = static_cast(256) * mapdata[offset]; + heightmap[(tileSize - y) * (tileSize + 1) + x] = + static_cast(256) * mapdata[offset]; } else if (bytesPP == 4) for (ssize_t y = 0; y < tileSize + 1; ++y) @@ -109,7 +111,8 @@ Status ParseHeightmapImage(const std::shared_ptr& fileData, size_t { // Repeat the last pixel of the image for the last vertex of the heightmap int offset = std::min(y, tileSize - 1) * mapLineSkip + std::min(x, tileSize - 1) * bytesPP; - heightmap[(tileSize - y) * (tileSize + 1) + x] = static_cast(256) * std::max({ + heightmap[(tileSize - y) * (tileSize + 1) + x] = + static_cast(256) * std::max({ mapdata[offset], mapdata[offset + 1], mapdata[offset + 2]}); diff --git a/source/graphics/MapIO.h b/source/graphics/MapIO.h index 8e8c800113..bfe071586f 100644 --- a/source/graphics/MapIO.h +++ b/source/graphics/MapIO.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 @@ -25,9 +25,9 @@ #include -// Opens the given texture file and stores it in a one-dimensional u16 vector. -Status LoadHeightmapImageVfs(const VfsPath& filepath, std::vector& heightmap); -Status LoadHeightmapImageOs(const OsPath& filepath, std::vector& heightmap); +// Opens the given texture file and stores it in a one-dimensional std::uint16_t vector. +Status LoadHeightmapImageVfs(const VfsPath& filepath, std::vector& heightmap); +Status LoadHeightmapImageOs(const OsPath& filepath, std::vector& heightmap); class CMapIO { @@ -42,9 +42,9 @@ public: struct STileDesc { // Index into the texture array of first texture on tile. - u16 m_Tex1Index; + std::uint16_t m_Tex1Index; // Index into the texture array of second texture; (0xFFFF) if none. - u16 m_Tex2Index; + std::uint16_t m_Tex2Index; u32 m_Priority; }; #pragma pack(pop) diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index f5cb8cfe8a..7168ae2e0a 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -304,7 +304,7 @@ PS::Loader::Task CMapReader::UnpackTerrain() // unpack heightmap [600us] size_t verticesPerSide = m_PatchesPerSide*PATCH_SIZE+1; m_Heightmap.resize(SQR(verticesPerSide)); - unpacker.UnpackRaw(&m_Heightmap[0], SQR(verticesPerSide)*sizeof(u16)); + unpacker.UnpackRaw(&m_Heightmap[0], SQR(verticesPerSide) * sizeof(std::uint16_t)); } // unpack # textures @@ -597,7 +597,7 @@ void CXMLReader::ReadTerrain(XMBElement parent) ssize_t patches = 9; CStr texture = "grass1_spring"; int priority = 0; - u16 height = 16384; + std::uint16_t height = 16384; for (XMBAttribute attr : parent.GetAttributes()) { @@ -608,7 +608,7 @@ void CXMLReader::ReadTerrain(XMBElement parent) else if (attr.Name == at_priority) priority = attr.Value.ToInt(); else if (attr.Name == at_height) - height = (u16)attr.Value.ToInt(); + height = static_cast(attr.Value.ToInt()); } m_MapReader.m_PatchesPerSide = patches; @@ -621,7 +621,7 @@ void CXMLReader::ReadTerrain(XMBElement parent) m_MapReader.pTerrain->Initialize(patches, NULL); // Fill the heightmap - u16* heightmap = m_MapReader.pTerrain->GetHeightMap(); + std::uint16_t* heightmap = m_MapReader.pTerrain->GetHeightMap(); ssize_t verticesPerSide = m_MapReader.pTerrain->GetVerticesPerSide(); for (ssize_t i = 0; i < SQR(verticesPerSide); ++i) heightmap[i] = height; @@ -1387,7 +1387,7 @@ int CMapReader::ParseTerrain() m_PatchesPerSide = size / PATCH_SIZE; - // flat heightmap of u16 data + // flat heightmap of std::uint16_t data getTerrainProperty(m_MapData, "height", m_Heightmap); // load textures @@ -1410,8 +1410,8 @@ int CMapReader::ParseTerrain() getTerrainProperty(m_MapData, "tileData", &tileData); // parse tile data object into flat arrays - std::vector tileIndex; - std::vector tilePriority; + std::vector tileIndex; + std::vector tilePriority; getTerrainProperty(tileData, "index", tileIndex); getTerrainProperty(tileData, "priority", tilePriority); diff --git a/source/graphics/MapReader.h b/source/graphics/MapReader.h index ae8769c162..a261f160fb 100644 --- a/source/graphics/MapReader.h +++ b/source/graphics/MapReader.h @@ -119,7 +119,7 @@ private: // size of map ssize_t m_PatchesPerSide{0}; // heightmap for map - std::vector m_Heightmap; + std::vector m_Heightmap; // list of terrain textures used by map std::vector m_TerrainTextures; // tile descriptions for each tile diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index bbc4744bad..9c8ac12923 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -30,7 +30,6 @@ #include "lib/debug.h" #include "lib/path.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector3D.h" #include "maths/MathUtil.h" @@ -102,12 +101,13 @@ void CMapWriter::SaveMap(const VfsPath& pathname, CTerrain* pTerrain, WaterManag /////////////////////////////////////////////////////////////////////////////////////////////////// // GetHandleIndex: return the index of the given handle in the given list; or 0xFFFF if // handle isn't in list -static u16 GetEntryIndex(const CTerrainTextureEntry* entry, const std::vector& entries) +static std::uint16_t GetEntryIndex(const CTerrainTextureEntry* entry, + const std::vector& entries) { const size_t limit = std::min(entries.size(), size_t(0xFFFEu)); // paranoia for (size_t i=0;i(i); } } @@ -135,9 +135,9 @@ void CMapWriter::EnumTerrainTextures(CTerrain *pTerrain, for (ssize_t m=0;mGetPatch(i,j)->m_MiniPatches[m][k]; // can't fail - u16 index=u16(GetEntryIndex(mp.GetTextureEntry(),entries)); + std::uint16_t index = static_cast(GetEntryIndex(mp.GetTextureEntry(),entries)); if (index==0xFFFF) { - index=(u16)entries.size(); + index = static_cast(entries.size()); entries.push_back(mp.GetTextureEntry()); } @@ -182,7 +182,8 @@ void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain* pTerrain) packer.PackSize(mapsize); // pack heightmap - packer.PackRaw(pTerrain->GetHeightMap(),sizeof(u16)*SQR(pTerrain->GetVerticesPerSide())); + packer.PackRaw(pTerrain->GetHeightMap(), sizeof(std::uint16_t) * + SQR(pTerrain->GetVerticesPerSide())); // the list of textures used by map std::vector terrainTextures; diff --git a/source/graphics/MiniMapTexture.cpp b/source/graphics/MiniMapTexture.cpp index acc309d95f..43bd3448dc 100644 --- a/source/graphics/MiniMapTexture.cpp +++ b/source/graphics/MiniMapTexture.cpp @@ -232,7 +232,7 @@ CMiniMapTexture::CMiniMapTexture(Renderer::Backend::IDevice* device, CSimulation m_IndexArray.SetNumberOfVertices(MAX_ENTITIES_DRAWN * 6); m_IndexArray.Layout(); - VertexArrayIterator index = m_IndexArray.GetIterator(); + VertexArrayIterator index = m_IndexArray.GetIterator(); for (size_t i = 0; i < m_IndexArray.GetNumberOfVertices(); ++i) *index++ = 0; m_IndexArray.Upload(); @@ -709,9 +709,9 @@ void CMiniMapTexture::UpdateAndUploadEntities( const CellIconKey key{ cmpMinimap->GetIconPath(), v.r, v.g, v.b}; - const u16 gridX = Clamp( + const std::uint16_t gridX = Clamp( (v.position.X * invTileMapSize) * ICON_COMBINING_GRID_SIZE, 0, ICON_COMBINING_GRID_SIZE - 1); - const u16 gridY = Clamp( + const std::uint16_t gridY = Clamp( (v.position.Y * invTileMapSize) * ICON_COMBINING_GRID_SIZE, 0, ICON_COMBINING_GRID_SIZE - 1); CellIcon icon{ gridX, gridY, cmpMinimap->GetIconSize() * iconsSizeScale * 0.5f, v.position}; @@ -798,15 +798,15 @@ void CMiniMapTexture::UpdateAndUploadEntities( if (!m_UseInstancing) { - VertexArrayIterator index = m_IndexArray.GetIterator(); + VertexArrayIterator index = m_IndexArray.GetIterator(); for (size_t entityIndex = 0; entityIndex < m_EntitiesDrawn; ++entityIndex) { - index[entityIndex * 6 + 0] = static_cast(entityIndex * 4 + 0); - index[entityIndex * 6 + 1] = static_cast(entityIndex * 4 + 1); - index[entityIndex * 6 + 2] = static_cast(entityIndex * 4 + 2); - index[entityIndex * 6 + 3] = static_cast(entityIndex * 4 + 0); - index[entityIndex * 6 + 4] = static_cast(entityIndex * 4 + 2); - index[entityIndex * 6 + 5] = static_cast(entityIndex * 4 + 3); + index[entityIndex * 6 + 0] = static_cast(entityIndex * 4 + 0); + index[entityIndex * 6 + 1] = static_cast(entityIndex * 4 + 1); + index[entityIndex * 6 + 2] = static_cast(entityIndex * 4 + 2); + index[entityIndex * 6 + 3] = static_cast(entityIndex * 4 + 0); + index[entityIndex * 6 + 4] = static_cast(entityIndex * 4 + 2); + index[entityIndex * 6 + 5] = static_cast(entityIndex * 4 + 3); } m_IndexArray.Upload(); diff --git a/source/graphics/MiniMapTexture.h b/source/graphics/MiniMapTexture.h index 645c9bbd65..70c6518860 100644 --- a/source/graphics/MiniMapTexture.h +++ b/source/graphics/MiniMapTexture.h @@ -169,7 +169,7 @@ private: struct CellIcon { // TODO: use CVector2DI. - u16 gridX, gridY; + std::uint16_t gridX, gridY; float halfSize; CVector2D worldPosition; }; diff --git a/source/graphics/ModelDef.h b/source/graphics/ModelDef.h index 29ef8dc272..ef52e7b140 100644 --- a/source/graphics/ModelDef.h +++ b/source/graphics/ModelDef.h @@ -122,7 +122,7 @@ struct SModelVertex struct SModelFace { // indices of the 3 vertices on this face - u16 m_Verts[3]; + std::uint16_t m_Verts[3]; }; diff --git a/source/graphics/ParticleEmitter.cpp b/source/graphics/ParticleEmitter.cpp index f3c4ac5736..20d2513a7d 100644 --- a/source/graphics/ParticleEmitter.cpp +++ b/source/graphics/ParticleEmitter.cpp @@ -27,7 +27,6 @@ #include "graphics/TextureManager.h" #include "lib/allocators/STLAllocators.h" #include "lib/debug.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "ps/memory/LinearAllocator.h" #include "ps/CStrIntern.h" @@ -139,8 +138,8 @@ CParticleEmitter::CParticleEmitter(const CParticleEmitterType& type) : m_IndexArray.SetNumberOfVertices(m_UseInstancing ? 6 : m_Type.m_MaxParticles * 6); m_IndexArray.Layout(); - VertexArrayIterator index = m_IndexArray.GetIterator(); - for (u16 i = 0; i < (m_UseInstancing ? 1 : m_Type.m_MaxParticles); ++i) + VertexArrayIterator index = m_IndexArray.GetIterator(); + for (std::uint16_t i = 0; i < (m_UseInstancing ? 1 : m_Type.m_MaxParticles); ++i) { *index++ = i*4 + 0; *index++ = i*4 + 1; diff --git a/source/graphics/ParticleEmitterType.h b/source/graphics/ParticleEmitterType.h index 34987a22e6..39206e3c4c 100644 --- a/source/graphics/ParticleEmitterType.h +++ b/source/graphics/ParticleEmitterType.h @@ -21,7 +21,6 @@ #include "graphics/Texture.h" #include "lib/code_annotation.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "maths/BoundingBoxAligned.h" #include @@ -133,7 +132,7 @@ private: bool m_UseVelocityAsAxisX{false}; float m_MaxLifetime; - u16 m_MaxParticles; + std::uint16_t m_MaxParticles; CBoundingBoxAligned m_MaxBounds; std::vector> m_Variables; diff --git a/source/graphics/Terrain.cpp b/source/graphics/Terrain.cpp index 720ea05c61..00de77887d 100644 --- a/source/graphics/Terrain.cpp +++ b/source/graphics/Terrain.cpp @@ -61,7 +61,7 @@ void CTerrain::ReleaseData() /////////////////////////////////////////////////////////////////////////////// // Initialise: initialise this terrain to the given size // using given heightmap to setup elevation data -bool CTerrain::Initialize(ssize_t patchesPerSide, const u16* data) +bool CTerrain::Initialize(ssize_t patchesPerSide, const std::uint16_t* data) { // clean up any previous terrain ReleaseData(); @@ -70,19 +70,19 @@ bool CTerrain::Initialize(ssize_t patchesPerSide, const u16* data) m_MapSize = patchesPerSide * PATCH_SIZE + 1; m_MapSizePatches = patchesPerSide; // allocate data for new terrain - m_Heightmap = new u16[m_MapSize * m_MapSize]; + m_Heightmap = new std::uint16_t[m_MapSize * m_MapSize]; m_Patches = new CPatch[m_MapSizePatches * m_MapSizePatches]; // given a heightmap? if (data) { // yes; keep a copy of it - memcpy(m_Heightmap, data, m_MapSize*m_MapSize*sizeof(u16)); + memcpy(m_Heightmap, data, m_MapSize * m_MapSize * sizeof(std::uint16_t)); } else { // build a flat terrain - memset(m_Heightmap, 0, m_MapSize*m_MapSize*sizeof(u16)); + memset(m_Heightmap, 0, m_MapSize * m_MapSize * sizeof(std::uint16_t)); } // setup patch parents, indices etc @@ -102,7 +102,7 @@ void CTerrain::CalcPosition(ssize_t i, ssize_t j, CVector3D& pos) const { ssize_t hi = Clamp(i, 0, m_MapSize - 1); ssize_t hj = Clamp(j, 0, m_MapSize - 1); - u16 height = m_Heightmap[hj*m_MapSize + hi]; + std::uint16_t height = m_Heightmap[hj*m_MapSize + hi]; pos.X = float(i*TERRAIN_TILE_SIZE); pos.Y = float(height*HEIGHT_SCALE); pos.Z = float(j*TERRAIN_TILE_SIZE); @@ -114,9 +114,9 @@ void CTerrain::CalcPositionFixed(ssize_t i, ssize_t j, CFixedVector3D& pos) cons { ssize_t hi = Clamp(i, 0, m_MapSize - 1); ssize_t hj = Clamp(j, 0, m_MapSize - 1); - u16 height = m_Heightmap[hj*m_MapSize + hi]; + std::uint16_t height = m_Heightmap[hj*m_MapSize + hi]; pos.X = fixed::FromInt(i) * (int)TERRAIN_TILE_SIZE; - // fixed max value is 32767, but height is a u16, so divide by two to avoid overflow + // fixed max value is 32767, but height is a std::uint16_t, so divide by two to avoid overflow pos.Y = fixed::FromInt(height/ 2 ) / ((int)HEIGHT_UNITS_PER_METRE / 2); pos.Z = fixed::FromInt(j) * (int)TERRAIN_TILE_SIZE; } @@ -309,14 +309,14 @@ fixed CTerrain::GetSlopeFixed(ssize_t i, ssize_t j) const i = Clamp(i, 0, m_MapSize - 2); j = Clamp(j, 0, m_MapSize - 2); - u16 h00 = m_Heightmap[j*m_MapSize + i]; - u16 h01 = m_Heightmap[(j+1)*m_MapSize + i]; - u16 h10 = m_Heightmap[j*m_MapSize + (i+1)]; - u16 h11 = m_Heightmap[(j+1)*m_MapSize + (i+1)]; + std::uint16_t h00 = m_Heightmap[j*m_MapSize + i]; + std::uint16_t h01 = m_Heightmap[(j+1)*m_MapSize + i]; + std::uint16_t h10 = m_Heightmap[j*m_MapSize + (i+1)]; + std::uint16_t h11 = m_Heightmap[(j+1)*m_MapSize + (i+1)]; // Difference of highest point from lowest point - u16 delta = std::max(std::max(h00, h01), std::max(h10, h11)) - - std::min(std::min(h00, h01), std::min(h10, h11)); + std::uint16_t delta = std::max(std::max(h00, h01), std::max(h10, h11)) - + std::min(std::min(h00, h01), std::min(h10, h11)); // Compute fractional slope (being careful to avoid intermediate overflows) return fixed::FromInt(delta / TERRAIN_TILE_SIZE) / (int)HEIGHT_UNITS_PER_METRE; @@ -333,12 +333,12 @@ fixed CTerrain::GetExactSlopeFixed(fixed x, fixed z) const const fixed xf = Clamp((x / static_cast(TERRAIN_TILE_SIZE)) - fixed::FromInt(xi), fixed::Zero(), one); const fixed zf = Clamp((z / static_cast(TERRAIN_TILE_SIZE)) - fixed::FromInt(zi), fixed::Zero(), one); - u16 h00 = m_Heightmap[zi*m_MapSize + xi]; - u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; - u16 h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; - u16 h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; + std::uint16_t h00 = m_Heightmap[zi*m_MapSize + xi]; + std::uint16_t h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; + std::uint16_t h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; + std::uint16_t h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; - u16 delta; + std::uint16_t delta; if (GetTriangulationDir(xi, zi)) { if (xf + zf <= one) @@ -441,10 +441,10 @@ fixed CTerrain::GetExactGroundLevelFixed(fixed x, fixed z) const const fixed xf = Clamp((x / static_cast(TERRAIN_TILE_SIZE)) - fixed::FromInt(xi), fixed::Zero(), one); const fixed zf = Clamp((z / static_cast(TERRAIN_TILE_SIZE)) - fixed::FromInt(zi), fixed::Zero(), one); - u16 h00 = m_Heightmap[zi*m_MapSize + xi]; - u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; - u16 h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; - u16 h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; + std::uint16_t h00 = m_Heightmap[zi*m_MapSize + xi]; + std::uint16_t h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; + std::uint16_t h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; + std::uint16_t h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; // Intermediate scaling of xf, so we don't overflow in the multiplications below // (h00 <= 65535, xf <= 1, max fixed is < 32768; divide by 2 here so xf1*h00 <= 32767.5) @@ -498,8 +498,8 @@ void CTerrain::ResizeAndOffset(ssize_t size, ssize_t horizontalOffset, ssize_t v // Allocate data for new terrain. const ssize_t newMapSize = size * PATCH_SIZE + 1; - u16* newHeightmap = new u16[newMapSize * newMapSize]; - memset(newHeightmap, 0, newMapSize * newMapSize * sizeof(u16)); + std::uint16_t* newHeightmap = new std::uint16_t[newMapSize * newMapSize]; + memset(newHeightmap, 0, newMapSize * newMapSize * sizeof(std::uint16_t)); CPatch* newPatches = new CPatch[size * size]; // O--------------------+ @@ -567,8 +567,8 @@ void CTerrain::ResizeAndOffset(ssize_t size, ssize_t horizontalOffset, ssize_t v // | 5678 | // | | // +----------+ - u16* dst = newHeightmap + (j + destUpperLeftZ * PATCH_SIZE) * newMapSize + destUpperLeftX * PATCH_SIZE; - u16* src = m_Heightmap + (j + sourceUpperLeftZ * PATCH_SIZE) * m_MapSize + sourceUpperLeftX * PATCH_SIZE; + std::uint16_t* dst = newHeightmap + (j + destUpperLeftZ * PATCH_SIZE) * newMapSize + destUpperLeftX * PATCH_SIZE; + std::uint16_t* src = m_Heightmap + (j + sourceUpperLeftZ * PATCH_SIZE) * m_MapSize + sourceUpperLeftX * PATCH_SIZE; std::copy_n(src, width * PATCH_SIZE, dst); if (destUpperLeftX > 0) { @@ -580,7 +580,7 @@ void CTerrain::ResizeAndOffset(ssize_t size, ssize_t horizontalOffset, ssize_t v // | 5678 | // | | // +----------+ - u16* dst_prefix = newHeightmap + (j + destUpperLeftZ * PATCH_SIZE) * newMapSize; + std::uint16_t* dst_prefix = newHeightmap + (j + destUpperLeftZ * PATCH_SIZE) * newMapSize; std::fill_n(dst_prefix, destUpperLeftX * PATCH_SIZE, dst[0]); } if ((destUpperLeftX + width) * PATCH_SIZE < newMapSize) @@ -593,7 +593,7 @@ void CTerrain::ResizeAndOffset(ssize_t size, ssize_t horizontalOffset, ssize_t v // | 5678 | // | | // +----------+ - u16* dst_suffix = dst + width * PATCH_SIZE; + std::uint16_t* dst_suffix = dst + width * PATCH_SIZE; std::fill_n( dst_suffix, newMapSize - (width + destUpperLeftX) * PATCH_SIZE, @@ -610,8 +610,8 @@ void CTerrain::ResizeAndOffset(ssize_t size, ssize_t horizontalOffset, ssize_t v for (ssize_t j = 0; j < destUpperLeftZ * PATCH_SIZE; ++j) { - u16* dst = newHeightmap + j * newMapSize; - u16* src = newHeightmap + destUpperLeftZ * PATCH_SIZE * newMapSize; + std::uint16_t* dst = newHeightmap + j * newMapSize; + std::uint16_t* src = newHeightmap + destUpperLeftZ * PATCH_SIZE * newMapSize; std::copy_n(src, newMapSize, dst); } // Copy over heights from the succeeding row. Destination heightmap: @@ -623,8 +623,8 @@ void CTerrain::ResizeAndOffset(ssize_t size, ssize_t horizontalOffset, ssize_t v // +----------+ for (ssize_t j = (destUpperLeftZ + depth) * PATCH_SIZE; j < newMapSize; ++j) { - u16* dst = newHeightmap + j * newMapSize; - u16* src = newHeightmap + ((destUpperLeftZ + depth) * PATCH_SIZE - 1) * newMapSize; + std::uint16_t* dst = newHeightmap + j * newMapSize; + std::uint16_t* src = newHeightmap + ((destUpperLeftZ + depth) * PATCH_SIZE - 1) * newMapSize; std::copy_n(src, newMapSize, dst); } @@ -730,10 +730,10 @@ void CTerrain::InitialisePatches() /////////////////////////////////////////////////////////////////////////////// // SetHeightMap: set up a new heightmap from 16-bit source data; // assumes heightmap matches current terrain size -void CTerrain::SetHeightMap(u16* heightmap) +void CTerrain::SetHeightMap(std::uint16_t* heightmap) { // keep a copy of the given heightmap - memcpy(m_Heightmap, heightmap, m_MapSize*m_MapSize*sizeof(u16)); + memcpy(m_Heightmap, heightmap, m_MapSize * m_MapSize * sizeof(std::uint16_t)); // recalculate patch bounds, invalidate vertices for (ssize_t j = 0; j < m_MapSizePatches; j++) @@ -807,8 +807,8 @@ CBoundingBoxAligned CTerrain::GetVertexesBound(ssize_t i0, ssize_t j0, ssize_t i i1 = Clamp(i1, 0, m_MapSize - 1); j1 = Clamp(j1, 0, m_MapSize - 1); - u16 minH = 65535; - u16 maxH = 0; + std::uint16_t minH = 65535; + std::uint16_t maxH = 0; for (ssize_t j = j0; j <= j1; ++j) { diff --git a/source/graphics/Terrain.h b/source/graphics/Terrain.h index 866dbd097c..d06648e7d2 100644 --- a/source/graphics/Terrain.h +++ b/source/graphics/Terrain.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 @@ -25,7 +25,6 @@ #include "graphics/HeightMipmap.h" #include "graphics/SColor.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/Vector3D.h" @@ -40,10 +39,10 @@ class CPatch; /// metres [world space units] per tile in x and z const ssize_t TERRAIN_TILE_SIZE = 4; -/// number of u16 height units per metre +/// number of std::uint16_t height units per metre const ssize_t HEIGHT_UNITS_PER_METRE = 92; -/// metres per u16 height unit +/// metres per std::uint16_t height unit const float HEIGHT_SCALE = 1.f / HEIGHT_UNITS_PER_METRE; /////////////////////////////////////////////////////////////////////////////// @@ -60,7 +59,7 @@ public: // more efficiently be converted to/from floating point. use ssize_t // instead of int/long because these are sizes. - bool Initialize(ssize_t patchesPerSide, const u16* ptr); + bool Initialize(ssize_t patchesPerSide, const std::uint16_t* ptr); // return number of vertices along edge of the terrain ssize_t GetVerticesPerSide() const { return m_MapSize; } @@ -102,9 +101,9 @@ public: void ResizeAndOffset(ssize_t size, ssize_t horizontalOffset = 0, ssize_t verticalOffset = 0); // set up a new heightmap from 16 bit data; assumes heightmap matches current terrain size - void SetHeightMap(u16* heightmap); + void SetHeightMap(std::uint16_t* heightmap); // return a pointer to the heightmap - u16* GetHeightMap() const { return m_Heightmap; } + std::uint16_t* GetHeightMap() const { return m_Heightmap; } // get patch at given coordinates, expressed in patch-space; return 0 if // coordinates represent patch off the edge of the map @@ -172,7 +171,7 @@ private: // the patches comprising this terrain CPatch* m_Patches; // 16-bit heightmap data - u16* m_Heightmap; + std::uint16_t* m_Heightmap; // base color (usually white) SColor4ub m_BaseColor; // heightmap mipmap diff --git a/source/graphics/TerritoryBoundary.cpp b/source/graphics/TerritoryBoundary.cpp index 495715ef4c..822aeb400c 100644 --- a/source/graphics/TerritoryBoundary.cpp +++ b/source/graphics/TerritoryBoundary.cpp @@ -90,9 +90,9 @@ std::vector CTerritoryBoundaryCalculator::ComputeBoundaries( const int TERRITORY_DISCR_MASK = (ICmpTerritoryManager::TERRITORY_BLINKING_MASK | ICmpTerritoryManager::TERRITORY_PLAYER_MASK); // Try to find an assigned tile - for (u16 j = 0; j < grid.m_H; ++j) + for (std::uint16_t j = 0; j < grid.m_H; ++j) { - for (u16 i = 0; i < grid.m_W; ++i) + for (std::uint16_t i = 0; i < grid.m_W; ++i) { // saved tile state; from MSB to LSB: // processed bit, blinking bit, player ID @@ -123,10 +123,10 @@ std::vector CTerritoryBoundaryCalculator::ComputeBoundaries( std::uint8_t dir = TILE_BOTTOM; std::uint8_t cdir = dir; - u16 ci = i, cj = j; + std::uint16_t ci = i, cj = j; - u16 maxi = (u16)(grid.m_W-1); - u16 maxj = (u16)(grid.m_H-1); + std::uint16_t maxi = static_cast(grid.m_W - 1); + std::uint16_t maxj = static_cast(grid.m_H - 1); // Size of a territory tile in metres float territoryTileSize = (Pathfinding::NAVCELL_SIZE * ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE).ToFloat(); diff --git a/source/graphics/TextRenderer.cpp b/source/graphics/TextRenderer.cpp index 7ddbcecd71..49b4b14c9d 100644 --- a/source/graphics/TextRenderer.cpp +++ b/source/graphics/TextRenderer.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 "graphics/TextureManager.h" #include "lib/code_annotation.h" #include "lib/debug.h" -#include "lib/types.h" #include "lib/utf8.h" #include "ps/CStr.h" #include "ps/CStrIntern.h" @@ -211,7 +210,7 @@ void CTextRenderer::Render( const CVector2D& transformScale, const CVector2D& translation, const bool debugFontBox, const CColor& debugBoxColor) { - std::vector> indices{m_ScopedLinearAllocator}; + std::vector> indices{m_ScopedLinearAllocator}; std::vector> positions{m_ScopedLinearAllocator}; std::vector> uvs{m_ScopedLinearAllocator}; @@ -329,12 +328,12 @@ void CTextRenderer::Render( positions[idx*4+3].X = g->x1 + x; positions[idx*4+3].Y = g->y1 + y; - indices[idx*6+0] = static_cast(idx*4+0); - indices[idx*6+1] = static_cast(idx*4+1); - indices[idx*6+2] = static_cast(idx*4+2); - indices[idx*6+3] = static_cast(idx*4+2); - indices[idx*6+4] = static_cast(idx*4+3); - indices[idx*6+5] = static_cast(idx*4+0); + indices[idx*6+0] = static_cast(idx * 4 + 0); + indices[idx*6+1] = static_cast(idx * 4 + 1); + indices[idx*6+2] = static_cast(idx * 4 + 2); + indices[idx*6+3] = static_cast(idx * 4 + 2); + indices[idx*6+4] = static_cast(idx * 4 + 3); + indices[idx*6+5] = static_cast(idx * 4 + 0); x += g->xadvance; diff --git a/source/graphics/tests/test_Terrain.h b/source/graphics/tests/test_Terrain.h index 958ffc3d84..46b1690bd4 100644 --- a/source/graphics/tests/test_Terrain.h +++ b/source/graphics/tests/test_Terrain.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 @@ -22,7 +22,6 @@ #include "graphics/Patch.h" #include "graphics/RenderableObject.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector3D.h" #include "maths/Vector3D.h" @@ -35,13 +34,13 @@ class TestTerrain : public CxxTest::TestSuite { - void SetVertex(CTerrain& terrain, ssize_t i, ssize_t j, u16 height) + void SetVertex(CTerrain& terrain, ssize_t i, ssize_t j, std::uint16_t height) { terrain.GetHeightMap()[j*terrain.GetVerticesPerSide() + i] = height; terrain.MakeDirty(RENDERDATA_UPDATE_VERTICES); } - u16 GetVertex(CTerrain& terrain, ssize_t i, ssize_t j) + std::uint16_t GetVertex(CTerrain& terrain, ssize_t i, ssize_t j) { return terrain.GetHeightMap()[j*terrain.GetVerticesPerSide() + i]; } @@ -210,8 +209,8 @@ public: struct ResizeTestCase { ssize_t horizontalOffset, verticalOffset; - std::vector> sourcePatches; - std::vector> expectedPatches; + std::vector> sourcePatches; + std::vector> expectedPatches; }; const ResizeTestCase testCases[] = { // Without offset. @@ -388,7 +387,7 @@ public: CTerrain terrain; { - std::vector heightmap(sourceMapSize * sourceMapSize); + std::vector heightmap(sourceMapSize * sourceMapSize); for (ssize_t jTile = 0; jTile < sourceSize; ++jTile) { TS_ASSERT_EQUALS(sourceSize, testCase.sourcePatches[jTile].size()); diff --git a/source/gui/SettingTypes/CGUIString.cpp b/source/gui/SettingTypes/CGUIString.cpp index d3a0dd44fb..ff96fb58e5 100644 --- a/source/gui/SettingTypes/CGUIString.cpp +++ b/source/gui/SettingTypes/CGUIString.cpp @@ -41,7 +41,7 @@ struct CGUIColor; // The list contains ranges of word delimiters. The odd indexed chars are the start // of a range, the even are the end of a range. The list must be sorted in INCREASING ORDER static const int NUM_WORD_DELIMITERS = 4*2; -static const u16 WordDelimiters[NUM_WORD_DELIMITERS] = { +static const std::uint16_t WordDelimiters[NUM_WORD_DELIMITERS] = { ' ' , ' ', // spaces '-' , '-', // hyphens 0x3000, 0x31FF, // ideographic symbols diff --git a/source/gui/SettingTypes/MouseEventMask.cpp b/source/gui/SettingTypes/MouseEventMask.cpp index 7461286874..d2c5f44047 100644 --- a/source/gui/SettingTypes/MouseEventMask.cpp +++ b/source/gui/SettingTypes/MouseEventMask.cpp @@ -126,8 +126,8 @@ public: } auto mask = std::make_unique(); - mask->m_Width = static_cast(tex.m_Width); - mask->m_Height = static_cast(tex.m_Height); + mask->m_Width = static_cast(tex.m_Width); + mask->m_Height = static_cast(tex.m_Height); mask->m_Data.reserve(mask->m_Width * mask->m_Height); for (std::uint8_t* ptr = tex.get_data(); ptr < tex.get_data() + tex.m_DataSize; ptr += tex.m_Bpp/8) @@ -158,8 +158,8 @@ public: private: // This uses the bool specialization on purpose for the 'compression' effect. std::vector m_Data; - u16 m_Width; - u16 m_Height; + std::uint16_t m_Width; + std::uint16_t m_Height; }; bool CGUIMouseEventMask::DoFromString(const CStrW& Value) diff --git a/source/lib/byte_order.cpp b/source/lib/byte_order.cpp index e7d2cc9180..c004140ecd 100644 --- a/source/lib/byte_order.cpp +++ b/source/lib/byte_order.cpp @@ -34,9 +34,9 @@ #include #ifndef swap16 -u16 swap16(const u16 x) +std::uint16_t swap16(const std::uint16_t x) { - return (u16)(((x & 0xff) << 8) | (x >> 8)); + return static_cast(((x & 0xff) << 8) | (x >> 8)); } #endif @@ -67,9 +67,9 @@ u64 swap64(const u64 x) //----------------------------------------------------------------------------- -u16 read_le16(const void* p) +std::uint16_t read_le16(const void* p) { - u16 n; + std::uint16_t n; memcpy(&n, p, sizeof(n)); return to_le16(n); } @@ -89,9 +89,9 @@ u64 read_le64(const void* p) } -u16 read_be16(const void* p) +std::uint16_t read_be16(const void* p) { - u16 n; + std::uint16_t n; memcpy(&n, p, sizeof(n)); return to_be16(n); } @@ -111,9 +111,9 @@ u64 read_be64(const void* p) } -void write_le16(void* p, u16 x) +void write_le16(void* p, std::uint16_t x) { - u16 n = to_le16(x); + std::uint16_t n = to_le16(x); memcpy(p, &n, sizeof(n)); } @@ -130,9 +130,9 @@ void write_le64(void* p, u64 x) } -void write_be16(void* p, u16 x) +void write_be16(void* p, std::uint16_t x) { - u16 n = to_be16(x); + std::uint16_t n = to_be16(x); memcpy(p, &n, sizeof(n)); } diff --git a/source/lib/byte_order.h b/source/lib/byte_order.h index 881aab7c6d..6c2f97c7d6 100644 --- a/source/lib/byte_order.h +++ b/source/lib/byte_order.h @@ -98,22 +98,22 @@ #endif /// read a little-endian number from memory into native byte order. -u16 read_le16(const void* p); +std::uint16_t read_le16(const void* p); u32 read_le32(const void* p); /// see read_le16 u64 read_le64(const void* p); /// see read_le16 /// read a big-endian number from memory into native byte order. -u16 read_be16(const void* p); +std::uint16_t read_be16(const void* p); u32 read_be32(const void* p); /// see read_be16 u64 read_be64(const void* p); /// see read_be16 /// write a little-endian number to memory in native byte order. -void write_le16(void* p, u16 x); +void write_le16(void* p, std::uint16_t x); void write_le32(void* p, u32 x); /// see write_le16 void write_le64(void* p, u64 x); /// see write_le16 /// write a big-endian number to memory in native byte order. -void write_be16(void* p, u16 x); +void write_be16(void* p, std::uint16_t x); void write_be32(void* p, u32 x); /// see write_be16 void write_be64(void* p, u64 x); /// see write_be16 @@ -156,7 +156,7 @@ extern unsigned __int64 _byteswap_uint64(unsigned __int64); #endif #ifndef swap16 -u16 swap16(const u16 x); +std::uint16_t swap16(const std::uint16_t x); #endif #ifndef swap32 u32 swap32(const u32 x); diff --git a/source/lib/file/archive/archive_zip.cpp b/source/lib/file/archive/archive_zip.cpp index 9aa5fd9a3f..d666016b0a 100644 --- a/source/lib/file/archive/archive_zip.cpp +++ b/source/lib/file/archive/archive_zip.cpp @@ -90,16 +90,16 @@ static u32 FAT_from_time_t(time_t time) // (values are adjusted for DST) struct tm* t = localtime(&time); - const u16 fat_time = u16( + const std::uint16_t fat_time = static_cast( (t->tm_sec/2) | // 5 - (u16(t->tm_min) << 5) | // 6 - (u16(t->tm_hour) << 11) // 5 + (static_cast(t->tm_min) << 5) | // 6 + (static_cast(t->tm_hour) << 11) // 5 ); - const u16 fat_date = u16( + const std::uint16_t fat_date = static_cast( (t->tm_mday) | // 5 - (u16(t->tm_mon+1) << 5) | // 4 - (u16(t->tm_year-80) << 9) // 7 + (static_cast(t->tm_mon+1) << 5) | // 4 + (static_cast(t->tm_year-80) << 9) // 7 ); u32 fat_timedate = u32_from_u16(fat_date, fat_time); @@ -157,15 +157,15 @@ public: private: u32 m_magic; - u16 m_x1; // version needed - u16 m_flags; - u16 m_method; + std::uint16_t m_x1; // version needed + std::uint16_t m_flags; + std::uint16_t m_method; u32 m_fat_mtime; // last modified time (DOS FAT format) u32 m_crc; u32 m_csize; u32 m_usize; - u16 m_fn_len; - u16 m_e_len; + std::uint16_t m_fn_len; + std::uint16_t m_e_len; }; cassert(sizeof(LFH) == 30); @@ -247,15 +247,15 @@ public: private: u32 m_magic; u32 m_x1; // versions - u16 m_flags; - u16 m_method; + std::uint16_t m_flags; + std::uint16_t m_method; u32 m_fat_mtime; // last modified time (DOS FAT format) u32 m_crc; u32 m_csize; u32 m_usize; - u16 m_fn_len; - u16 m_e_len; - u16 m_c_len; + std::uint16_t m_fn_len; + std::uint16_t m_e_len; + std::uint16_t m_c_len; u32 m_x2; // spanning u32 m_x3; // attributes u32 m_lfh_ofs; @@ -293,13 +293,13 @@ public: private: u32 m_magic; - u16 m_diskNum; - u16 m_cd_diskNum; - u16 m_cd_numEntriesOnDisk; - u16 m_cd_numEntries; + std::uint16_t m_diskNum; + std::uint16_t m_cd_diskNum; + std::uint16_t m_cd_numEntriesOnDisk; + std::uint16_t m_cd_numEntries; u32 m_cd_size; u32 m_cd_ofs; - u16 m_comment_len; + std::uint16_t m_comment_len; }; cassert(sizeof(ECDR) == 22); @@ -316,7 +316,7 @@ class ArchiveFile_Zip final : public IArchiveFile public: ArchiveFile_Zip(const PFile& file, off_t ofs, off_t csize, u32 checksum, ZipMethod method) : m_file(file), m_ofs(ofs) - , m_csize(csize), m_checksum(checksum), m_method((u16)method) + , m_csize(csize), m_checksum(checksum), m_method(static_cast(method)) , m_flags(NeedsFixup) { } @@ -441,8 +441,8 @@ private: mutable off_t m_ofs; off_t m_csize; u32 m_checksum; - u16 m_method; - mutable u16 m_flags; + std::uint16_t m_method; + mutable std::uint16_t m_flags; }; diff --git a/source/lib/lib.cpp b/source/lib/lib.cpp index b5c762cded..d4271abdd1 100644 --- a/source/lib/lib.cpp +++ b/source/lib/lib.cpp @@ -46,14 +46,14 @@ u32 u64_lo(u64 x) return (u32)(x & 0xFFFFFFFF); } -u16 u32_hi(u32 x) +std::uint16_t u32_hi(u32 x) { - return (u16)(x >> 16); + return static_cast(x >> 16); } -u16 u32_lo(u32 x) +std::uint16_t u32_lo(u32 x) { - return (u16)(x & 0xFFFF); + return static_cast(x & 0xFFFF); } @@ -65,7 +65,7 @@ u64 u64_from_u32(u32 hi, u32 lo) return x; } -u32 u32_from_u16(u16 hi, u16 lo) +u32 u32_from_u16(std::uint16_t hi, std::uint16_t lo) { u32 x = (u32)hi; x <<= 16; @@ -88,8 +88,8 @@ std::uint8_t u8_from_double(double in) return static_cast(l); } -// input in [0, 1); convert to u16 range -u16 u16_from_double(double in) +// input in [0, 1); convert to std::uint16_t range +std::uint16_t u16_from_double(double in) { if(!(0.0 <= in && in < 1.0)) { @@ -99,5 +99,5 @@ u16 u16_from_double(double in) long l = (long)(in * 65535.0); ENSURE((unsigned long)l <= 65535u); - return (u16)l; + return static_cast(l); } diff --git a/source/lib/lib.h b/source/lib/lib.h index b3fa18453a..bfd21766c5 100644 --- a/source/lib/lib.h +++ b/source/lib/lib.h @@ -115,13 +115,13 @@ inline bool IsSimilarMagnitude(double d1, double d2, const double relativeErrorT extern u32 u64_hi(u64 x); /// return upper 32-bits extern u32 u64_lo(u64 x); /// return lower 32-bits -extern u16 u32_hi(u32 x); /// return upper 16-bits -extern u16 u32_lo(u32 x); /// return lower 16-bits +extern std::uint16_t u32_hi(u32 x); /// return upper 16-bits +extern std::uint16_t u32_lo(u32 x); /// return lower 16-bits extern u64 u64_from_u32(u32 hi, u32 lo); /// assemble u64 from u32 -extern u32 u32_from_u16(u16 hi, u16 lo); /// assemble u32 from u16 +extern u32 u32_from_u16(std::uint16_t hi, std::uint16_t lo); /// assemble u32 from std::uint16_t -// safe downcasters: cast from any integral type to u32 or u16; +// safe downcasters: cast from any integral type to u32 or std::uint16_t; // issues warning if larger than would fit in the target type. // // these are generally useful but included here (instead of e.g. lib.h) for @@ -139,12 +139,12 @@ template std::uint8_t u8_from_larger(T x) return static_cast(x & max); } -template u16 u16_from_larger(T x) +template std::uint16_t u16_from_larger(T x) { - const u16 max = std::numeric_limits::max(); + const std::uint16_t max = std::numeric_limits::max(); if((u64)x > (u64)max) throw std::out_of_range("u16_from_larger"); - return (u16)(x & max); + return static_cast(x & max); } template u32 u32_from_larger(T x) @@ -157,7 +157,7 @@ template u32 u32_from_larger(T x) /// convert double to std::uint8_t; verifies number is in range. extern std::uint8_t u8_from_double(double in); -/// convert double to u16; verifies number is in range. -extern u16 u16_from_double(double in); +/// convert double to std::uint16_t; verifies number is in range. +extern std::uint16_t u16_from_double(double in); #endif // #ifndef INCLUDED_LIB diff --git a/source/lib/sysdep/os/win/acpi.h b/source/lib/sysdep/os/win/acpi.h index c9b73b5777..33ffe5304f 100644 --- a/source/lib/sysdep/os/win/acpi.h +++ b/source/lib/sysdep/os/win/acpi.h @@ -68,8 +68,8 @@ struct FADT // signature is FACP! std::uint8_t unused1[40]; u32 pmTimerPortAddress; std::uint8_t unused2[16]; - u16 c2Latency; // [us] - u16 c3Latency; // [us] + std::uint16_t c2Latency; // [us] + std::uint16_t c3Latency; // [us] std::uint8_t unused3[5]; std::uint8_t dutyWidth; std::uint8_t unused4[6]; diff --git a/source/lib/sysdep/os/win/wnuma.cpp b/source/lib/sysdep/os/win/wnuma.cpp index 96951a9d5a..f090422fec 100644 --- a/source/lib/sysdep/os/win/wnuma.cpp +++ b/source/lib/sysdep/os/win/wnuma.cpp @@ -180,7 +180,7 @@ struct AffinityMemory AffinityHeader header; u32 proximityDomainNumber; - u16 reserved1; + std::uint16_t reserved1; u64 baseAddress; u64 length; u32 reserved2; diff --git a/source/lib/tests/test_bits.h b/source/lib/tests/test_bits.h index eb31454680..b155a8a0a2 100644 --- a/source/lib/tests/test_bits.h +++ b/source/lib/tests/test_bits.h @@ -56,9 +56,9 @@ public: void test_bit_mask() { - EQUALS(bit_mask(0), 0); - EQUALS(bit_mask(2), 0x3); - EQUALS(bit_mask(16), 0xFFFF); + EQUALS(bit_mask(0), 0); + EQUALS(bit_mask(2), 0x3); + EQUALS(bit_mask(16), 0xFFFF); EQUALS(bit_mask(0), 0u); EQUALS(bit_mask(2), 0x3u); EQUALS(bit_mask(32), 0xFFFFFFFFul); @@ -70,12 +70,12 @@ public: void test_bits() { - EQUALS(bits(0xFFFF, 0, 15), 0xFFFF); - EQUALS(bits(0xFFFF, 0, 7), 0xFF); - EQUALS(bits(0xFFFF, 8, 15), 0xFF); - EQUALS(bits(0xFFFF, 14, 15), 0x3); - EQUALS(bits(0xAA55, 4, 11), 0xA5); - EQUALS(bits(0xAA55, 14, 15), 0x2); + EQUALS(bits(0xFFFF, 0, 15), 0xFFFF); + EQUALS(bits(0xFFFF, 0, 7), 0xFF); + EQUALS(bits(0xFFFF, 8, 15), 0xFF); + EQUALS(bits(0xFFFF, 14, 15), 0x3); + EQUALS(bits(0xAA55, 4, 11), 0xA5); + EQUALS(bits(0xAA55, 14, 15), 0x2); EQUALS(bits(0ul, 0, 31), 0ul); EQUALS(bits(0xFFFFFFFFul, 0, 31), 0xFFFFFFFFul); EQUALS(bits(0ull, 0, 63), 0ull); diff --git a/source/lib/tex/tex_bmp.cpp b/source/lib/tex/tex_bmp.cpp index 7a1b416867..e5741c6263 100644 --- a/source/lib/tex/tex_bmp.cpp +++ b/source/lib/tex/tex_bmp.cpp @@ -43,18 +43,18 @@ struct BmpHeader { // BITMAPFILEHEADER - u16 bfType; // "BM" + std::uint16_t bfType; // "BM" u32 bfSize; // of file - u16 bfReserved1; - u16 bfReserved2; + std::uint16_t bfReserved1; + std::uint16_t bfReserved2; u32 bfOffBits; // offset to image data // BITMAPINFOHEADER u32 biSize; std::int32_t biWidth; std::int32_t biHeight; - u16 biPlanes; - u16 biBitCount; + std::uint16_t biPlanes; + std::uint16_t biBitCount; u32 biCompression; u32 biSizeImage; // the following are unused and zeroed when writing: @@ -109,7 +109,7 @@ Status TexCodecBmp::decode(std::uint8_t* RESTRICT data, size_t /*size*/, Tex* RE const BmpHeader* hdr = (const BmpHeader*)data; const long w = (long)read_le32(&hdr->biWidth); const long h_ = (long)read_le32(&hdr->biHeight); - const u16 bpp = read_le16(&hdr->biBitCount); + const std::uint16_t bpp = read_le16(&hdr->biBitCount); const u32 compress = read_le32(&hdr->biCompression); const long h = std::labs(h_); @@ -158,7 +158,7 @@ Status TexCodecBmp::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const static_cast(t->m_Width), h, 1, // biPlanes - (u16)t->m_Bpp, + static_cast(t->m_Bpp), BI_RGB, // biCompression (u32)img_size, // biSizeImage 0, 0, 0, 0 // unused (bi?PelsPerMeter, biClr*) diff --git a/source/lib/tex/tex_dds.cpp b/source/lib/tex/tex_dds.cpp index 86f33e5343..a2e7d76ac3 100644 --- a/source/lib/tex/tex_dds.cpp +++ b/source/lib/tex/tex_dds.cpp @@ -135,7 +135,7 @@ private: // MS bits - see http://www.mindcontrol.org/~hplus/graphics/expand-bits.html ; // this is also the algorithm used by graphics cards when decompressing S3TC). // used to convert 565 to 32bpp RGB. - static inline size_t unpack_to_8(u16 c, size_t bits_below, size_t num_bits) + static inline size_t unpack_to_8(std::uint16_t c, size_t bits_below, size_t num_bits) { const size_t num_filler_bits = 8-num_bits; const size_t field = (size_t)bits(c, bits_below, bits_below+num_bits-1); @@ -187,7 +187,7 @@ private: // read block contents // .. S3TC reference colors (565 format). the color table is generated // from some combination of these, depending on their ordering. - u16 rc[2]; + std::uint16_t rc[2]; for(int i = 0; i < 2; i++) rc[i] = read_le16(c_block + 2*i); // .. table of 2-bit color selectors diff --git a/source/lib/tex/tex_tga.cpp b/source/lib/tex/tex_tga.cpp index 7ef3899881..cd76f88589 100644 --- a/source/lib/tex/tex_tga.cpp +++ b/source/lib/tex/tex_tga.cpp @@ -34,7 +34,6 @@ #include "lib/os_path.h" #include "lib/status.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include @@ -59,11 +58,11 @@ typedef struct std::uint8_t img_type; // see TgaImgType std::uint8_t color_map[5]; // unused - u16 x_origin; // unused - u16 y_origin; // unused + std::uint16_t x_origin; // unused + std::uint16_t y_origin; // unused - u16 w; - u16 h; + std::uint16_t w; + std::uint16_t h; std::uint8_t bpp; // bits per pixel std::uint8_t img_desc; @@ -172,8 +171,8 @@ Status TexCodecTga::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const static_cast(img_type), {0,0,0,0,0}, // unused (color map) 0, 0, // unused (origin) - (u16)t->m_Width, - (u16)t->m_Height, + static_cast(t->m_Width), + static_cast(t->m_Height), static_cast(t->m_Bpp), img_desc }; diff --git a/source/lib/types.h b/source/lib/types.h index e40e48a6b8..5c152e5d2b 100644 --- a/source/lib/types.h +++ b/source/lib/types.h @@ -29,7 +29,6 @@ #include -typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index d49fb2f37f..f40ccda53b 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -23,7 +23,6 @@ #include "i18n/L10n.h" #include "lib/code_annotation.h" #include "lib/external_libraries/gloox.h" -#include "lib/types.h" #include "lib/utf8.h" #include "lobby/GlooxConversion.h" #include "network/NetClient.h" @@ -1440,7 +1439,8 @@ std::wstring XmppClient::GetRating(const std::string& nick) * Utilities * *****************************************************/ -void XmppClient::SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJIDStr) +void XmppClient::SendStunEndpointToHost(const std::string& ip, std::uint16_t port, + const std::string& hostJIDStr) { DbgXMPP("SendStunEndpointToHost " << hostJIDStr); diff --git a/source/lobby/XmppClient.h b/source/lobby/XmppClient.h index 62414cc167..42c1bc29be 100644 --- a/source/lobby/XmppClient.h +++ b/source/lobby/XmppClient.h @@ -18,8 +18,6 @@ #ifndef XMPPCLIENT_H #define XMPPCLIENT_H -#include "lib/types.h" - #include #include @@ -69,7 +67,7 @@ public: bool GuiPollHasPlayerListUpdate(); void SendMUCMessage(const std::string& message); - void SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJID); + void SendStunEndpointToHost(const std::string& ip, std::uint16_t port, const std::string& hostJID); private: class Impl; diff --git a/source/maths/Fixed.cpp b/source/maths/Fixed.cpp index a6babec23d..c0adbb98e3 100644 --- a/source/maths/Fixed.cpp +++ b/source/maths/Fixed.cpp @@ -105,7 +105,7 @@ CStr8 CFixed_15_16::ToString() const builder.Append(posvalue >> fract_bits); - u16 fraction = posvalue & ((1 << fract_bits) - 1); + std::uint16_t fraction = posvalue & ((1 << fract_bits) - 1); if (fraction) { builder.Append('.'); diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index e06198d0e9..636296fdf0 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -225,7 +225,7 @@ bool CNetClient::TryToConnectWithSTUN(std::string serverAddressOrHostname, std:: } CStr ip; - u16 port = 0; + std::uint16_t port = 0; if (!localNetwork) { if (!StunClient::FindPublicIP(*enetClient, ip, port)) diff --git a/source/network/NetClient.h b/source/network/NetClient.h index c4cfb087eb..c6e7cd20cd 100644 --- a/source/network/NetClient.h +++ b/source/network/NetClient.h @@ -314,7 +314,7 @@ private: CStr m_HostJID; CStr m_ServerAddressOrHostname; - u16 m_ServerPort{0}; + std::uint16_t m_ServerPort{0}; /** * Password to join the game. diff --git a/source/network/NetClientSession.cpp b/source/network/NetClientSession.cpp index 5cb995b4a0..6c242eaba6 100644 --- a/source/network/NetClientSession.cpp +++ b/source/network/NetClientSession.cpp @@ -44,7 +44,7 @@ CNetClientSession::~CNetClientSession() ENSURE(!m_LoopRunning); } -bool CNetClientSession::Connect(const CStr& server, const u16 port, ENetHost* enetClient) +bool CNetClientSession::Connect(const CStr& server, const std::uint16_t port, ENetHost* enetClient) { ENSURE(!m_LoopRunning); ENSURE(!m_Host); diff --git a/source/network/NetClientSession.h b/source/network/NetClientSession.h index 2446c85666..d89cfe9053 100644 --- a/source/network/NetClientSession.h +++ b/source/network/NetClientSession.h @@ -56,7 +56,7 @@ public: CNetClientSession(CNetClient& client); ~CNetClientSession(); - bool Connect(const CStr& server, const u16 port, ENetHost* enetClient); + bool Connect(const CStr& server, const std::uint16_t port, ENetHost* enetClient); /** * The client NetSession is threaded to avoid getting timeouts if the main thread hangs. diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index df5e6ace13..f2b7689d47 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -182,7 +182,7 @@ bool CNetServerWorker::CheckPassword(const std::string& password, const std::str } #if CONFIG2_MINIUPNPC -void CNetServerWorker::SetupUPnP(const u16 port) +void CNetServerWorker::SetupUPnP(const std::uint16_t port) { debug_SetThreadName("UPnP"); @@ -1650,7 +1650,7 @@ CStrW CNetServerWorker::DeduplicatePlayerName(const CStrW& original) } } -void CNetServerWorker::SendHolePunchingMessage(const CStr& ipStr, u16 port) +void CNetServerWorker::SendHolePunchingMessage(const CStr& ipStr, std::uint16_t port) { if (m_Host) StunClient::SendHolePunchingMessages(*m_Host, ipStr, port); @@ -1686,12 +1686,12 @@ CStr CNetServer::GetPublicIp() const return m_PublicIp; } -u16 CNetServer::GetPublicPort() const +std::uint16_t CNetServer::GetPublicPort() const { return m_PublicPort; } -u16 CNetServer::GetLocalPort() const +std::uint16_t CNetServer::GetLocalPort() const { std::lock_guard lock(m_Worker.m_WorkerMutex); if (!m_Worker.m_Host) @@ -1739,7 +1739,7 @@ void CNetServer::SetTurnLength(u32 msecs) m_Worker.m_TurnLengthQueue.push_back(msecs); } -void CNetServer::SendHolePunchingMessage(const CStr& ip, u16 port) +void CNetServer::SendHolePunchingMessage(const CStr& ip, std::uint16_t port) { m_Worker.SendHolePunchingMessage(ip, port); } diff --git a/source/network/NetServer.h b/source/network/NetServer.h index 3f8577870f..c22b7fe94f 100644 --- a/source/network/NetServer.h +++ b/source/network/NetServer.h @@ -234,7 +234,7 @@ private: */ void CheckClientConnections(); - void SendHolePunchingMessage(const CStr& ip, u16 port); + void SendHolePunchingMessage(const CStr& ip, std::uint16_t port); /** * Internal script context for (de)serializing script messages, @@ -326,7 +326,7 @@ private: /** * Try to find a UPnP root on the network and setup port forwarding. */ - static void SetupUPnP(const u16 port); + static void SetupUPnP(const std::uint16_t port); std::thread m_UPnPThread; #endif @@ -375,7 +375,7 @@ public: void OnLobbyAuth(const CStr& name, const CStr& token); - void SendHolePunchingMessage(const CStr& ip, u16 port); + void SendHolePunchingMessage(const CStr& ip, std::uint16_t port); /** * Return the externally accessible IP. @@ -385,12 +385,12 @@ public: /** * Return the externally accessible port. */ - u16 GetPublicPort() const; + std::uint16_t GetPublicPort() const; /** * Return the serving port on the local machine. */ - u16 GetLocalPort() const; + std::uint16_t GetLocalPort() const; /** * Check if password is valid. If is not, increase number of failed attempts of the lobby user. @@ -410,7 +410,7 @@ public: private: CNetServerWorker m_Worker; const bool m_LobbyAuth; - u16 m_PublicPort{20595}; + std::uint16_t m_PublicPort{20595}; CStr m_PublicIp; CStr m_Password; std::unordered_map m_FailedAttempts; diff --git a/source/network/StunClient.cpp b/source/network/StunClient.cpp index 6792ecb891..5a978b0d08 100644 --- a/source/network/StunClient.cpp +++ b/source/network/StunClient.cpp @@ -45,20 +45,20 @@ namespace StunClient * These constants are defined in Section 6 of RFC 5389. */ const u32 m_MagicCookie = 0x2112A442; -const u16 m_MethodTypeBinding = 0x01; +const std::uint16_t m_MethodTypeBinding = 0x01; const u32 m_BindingSuccessResponse = 0x0101; /** * Bit determining whether comprehension of an attribute is optional. * Described in Section 15 of RFC 5389. */ -const u16 m_ComprehensionOptional = 0x1 << 15; +const std::uint16_t m_ComprehensionOptional = 0x1 << 15; /** * Bit determining whether the bit was assigned by IETF Review. * Described in section 18.1. of RFC 5389. */ -const u16 m_IETFReview = 0x1 << 14; +const std::uint16_t m_IETFReview = 0x1 << 14; /** * These constants are defined in Section 15.1 of RFC 5389. @@ -68,8 +68,8 @@ const std::uint8_t m_IPAddressFamilyIPv4 = 0x01; /** * These constants are defined in Section 18.2 of RFC 5389. */ -const u16 m_AttrTypeMappedAddress = 0x001; -const u16 m_AttrTypeXORMappedAddress = 0x0020; +const std::uint16_t m_AttrTypeMappedAddress = 0x001; +const std::uint16_t m_AttrTypeXORMappedAddress = 0x0020; /** * Described in section 3 of RFC 5389. @@ -127,8 +127,8 @@ bool GetFromBuffer(const std::vector& buffer, u32& offset, T& resu void SendStunRequest(ENetHost& transactionHost, ENetAddress addr) { std::vector buffer; - AddToBuffer(buffer, m_MethodTypeBinding); - AddToBuffer(buffer, 0); // length + AddToBuffer(buffer, m_MethodTypeBinding); + AddToBuffer(buffer, 0); // length AddToBuffer(buffer, m_MagicCookie); for (std::size_t i = 0; i < sizeof(m_TransactionID); ++i) @@ -222,7 +222,7 @@ bool ParseStunResponse(const std::vector& buffer) { u32 offset = 0; - u16 responseType = 0; + std::uint16_t responseType = 0; if (!GetFromBuffer(buffer, offset, responseType) || responseType != m_BindingSuccessResponse) { LOGERROR("STUN response isn't a binding success response"); @@ -251,8 +251,8 @@ bool ParseStunResponse(const std::vector& buffer) while (offset < buffer.size()) { - u16 type = 0; - u16 size = 0; + std::uint16_t type = 0; + std::uint16_t size = 0; if (!GetFromBuffer(buffer, offset, type) || !GetFromBuffer(buffer, offset, size)) { @@ -284,7 +284,7 @@ bool ParseStunResponse(const std::vector& buffer) return false; } - u16 port = 0; + std::uint16_t port = 0; u32 ip = 0; if (!GetFromBuffer(buffer, offset, port) || !GetFromBuffer(buffer, offset, ip)) @@ -336,7 +336,7 @@ bool STUNRequestAndResponse(ENetHost& transactionHost) ParseStunResponse(buffer); } -bool FindPublicIP(ENetHost& transactionHost, CStr& ip, u16& port) +bool FindPublicIP(ENetHost& transactionHost, CStr& ip, std::uint16_t& port) { if (!STUNRequestAndResponse(transactionHost)) return false; @@ -353,7 +353,8 @@ bool FindPublicIP(ENetHost& transactionHost, CStr& ip, u16& port) return true; } -void SendHolePunchingMessages(ENetHost& enetClient, const std::string& serverAddress, u16 serverPort) +void SendHolePunchingMessages(ENetHost& enetClient, const std::string& serverAddress, + std::uint16_t serverPort) { // Convert ip string to int64 ENetAddress addr; diff --git a/source/network/StunClient.h b/source/network/StunClient.h index 5caef4bdbf..f4af7d272a 100644 --- a/source/network/StunClient.h +++ b/source/network/StunClient.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * Copyright (C) 2013-2016 SuperTuxKart-Team. * This file is part of 0 A.D. * @@ -20,7 +20,6 @@ #define STUNCLIENT_H #include "lib/external_libraries/enet.h" -#include "lib/types.h" #include @@ -35,7 +34,7 @@ namespace StunClient * This is done by contacting STUN server. * The return IP & port should only be considered valid for the give host/socket. */ -bool FindPublicIP(ENetHost& enetClient, CStr8& ip, u16& port); +bool FindPublicIP(ENetHost& enetClient, CStr8& ip, std::uint16_t& port); /** * Send a message to the target server with the given ENet host/socket. @@ -44,7 +43,7 @@ bool FindPublicIP(ENetHost& enetClient, CStr8& ip, u16& port); * NB: this assumes consistent NAT, i.e. the outgoing port is always the same for the given client, * thus allowing the IP discovered via STUN to be sent to the target server. */ -void SendHolePunchingMessages(ENetHost& enetClient, const std::string& serverAddress, u16 serverPort); +void SendHolePunchingMessages(ENetHost& enetClient, const std::string& serverAddress, std::uint16_t serverPort); /** * Return the local IP. diff --git a/source/network/scripting/JSInterface_Network.cpp b/source/network/scripting/JSInterface_Network.cpp index 279dd4a1ef..62d13b9fa7 100644 --- a/source/network/scripting/JSInterface_Network.cpp +++ b/source/network/scripting/JSInterface_Network.cpp @@ -21,7 +21,6 @@ #include "lib/code_generation.h" #include "lib/debug.h" -#include "lib/types.h" #include "lib/utf8.h" #include "lobby/XmppClient.h" #include "network/NetClient.h" @@ -55,7 +54,7 @@ namespace Script { class Interface; } namespace JSI_Network { -u16 GetDefaultPort() +std::uint16_t GetDefaultPort() { return PS_DEFAULT_PORT; } @@ -75,7 +74,7 @@ bool HasNetClient() return !!g_NetClient; } -void StartNetworkHost(const CStrW& playerName, const u16 serverPort, const CStr& password, +void StartNetworkHost(const CStrW& playerName, const std::uint16_t serverPort, const CStr& password, const bool continueSavedGame, bool storeReplay) { ENSURE(!g_NetClient); @@ -115,7 +114,8 @@ void StartNetworkHost(const CStrW& playerName, const u16 serverPort, const CStr& secret); } -void StartNetworkJoin(const CStrW& playerName, const CStr& serverAddress, u16 serverPort, bool storeReplay) +void StartNetworkJoin(const CStrW& playerName, const CStr& serverAddress, std::uint16_t serverPort, + bool storeReplay) { ENSURE(!g_NetClient); ENSURE(!g_NetServer); diff --git a/source/network/tests/test_StunClient.h b/source/network/tests/test_StunClient.h index b3c89e88a1..e56b7aa1d1 100644 --- a/source/network/tests/test_StunClient.h +++ b/source/network/tests/test_StunClient.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 @@ -18,7 +18,6 @@ #include "lib/self_test.h" #include "lib/external_libraries/enet.h" -#include "lib/types.h" #include "network/StunClient.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -70,7 +69,7 @@ public: // Disabled test -> should return your external IP by connecting to our STUN server. CConfigDB::Initialise(); CStr ip; - u16 port; + std::uint16_t port; g_ConfigDB.SetValueString(CFG_COMMAND, "lobby.stun.server", "lobby.wildfiregames.com"); g_ConfigDB.SetValueString(CFG_COMMAND, "lobby.stun.port", "3478"); ENetAddress addr { ENET_HOST_ANY, ENET_PORT_ANY }; diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index ca2adead68..782814e3bb 100644 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -95,10 +95,10 @@ namespace size_t i = 0; for (i = 0; i < len; i++) { - const u16 bigEndian = to_be16(str[i]); - *(u16 *)(buffer + i * 2) = bigEndian; + const std::uint16_t bigEndian = to_be16(str[i]); + *reinterpret_cast(buffer + i * 2) = bigEndian; } - *(u16 *)(buffer + i * 2) = 0; + *reinterpret_cast(buffer + i * 2) = 0; return buffer + len * 2 + 2; } else @@ -123,19 +123,19 @@ namespace } else if constexpr (std::is_same_v) { - const u16 *strend = (const u16 *)buffer; + const std::uint16_t* strend = reinterpret_cast(buffer); while (reinterpret_cast(strend) < bufferend && *strend) strend++; if (reinterpret_cast(strend) >= bufferend) return nullptr; - str.resize(strend - (const u16 *)buffer); - const u16 *ptr = (const u16 *)buffer; + str.resize(strend - reinterpret_cast(buffer)); + const std::uint16_t *ptr = reinterpret_cast(buffer); typename StrBase::iterator it = str.begin(); while (ptr < strend) { - const u16 native = to_be16(*(ptr++)); // we want from_be16, but that's the same + const std::uint16_t native = to_be16(*(ptr++)); // we want from_be16, but that's the same *(it++) = (Char)native; } diff --git a/source/ps/scripting/JSInterface_VFS.cpp b/source/ps/scripting/JSInterface_VFS.cpp index 16d5bbd1bf..e1df2bed81 100644 --- a/source/ps/scripting/JSInterface_VFS.cpp +++ b/source/ps/scripting/JSInterface_VFS.cpp @@ -302,7 +302,7 @@ bool DeleteCampaignSave(const CStrW& filePath) } void RegisterScriptFunctions_ReadWriteAnywhere(const Script::Request& rq, - const u16 flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */) + const std::uint16_t flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */) { Script::Function::Register<&BuildDirEntList>(rq, "ListDirectoryFiles", flags); Script::Function::Register<&FileExists>(rq, "FileExists", flags); @@ -315,7 +315,7 @@ void RegisterScriptFunctions_ReadWriteAnywhere(const Script::Request& rq, } void RegisterScriptFunctions_ReadOnlySimulation(const Script::Request& rq, - const u16 flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */) + const std::uint16_t flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */) { Script::Function::Register<&BuildDirEntList>(rq, "ListDirectoryFiles", flags); Script::Function::Register<&FileExists>(rq, "FileExists", flags); @@ -323,7 +323,7 @@ void RegisterScriptFunctions_ReadOnlySimulation(const Script::Request& rq, } void RegisterScriptFunctions_ReadOnlySimulationMaps(const Script::Request& rq, - const u16 flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */) + const std::uint16_t flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */) { Script::Function::Register<&BuildDirEntList>(rq, "ListDirectoryFiles", flags); Script::Function::Register<&FileExists>(rq, "FileExists", flags); diff --git a/source/ps/scripting/JSInterface_VFS.h b/source/ps/scripting/JSInterface_VFS.h index 9e13b1eb49..7133fb37d5 100644 --- a/source/ps/scripting/JSInterface_VFS.h +++ b/source/ps/scripting/JSInterface_VFS.h @@ -18,8 +18,6 @@ #ifndef INCLUDED_JSI_VFS #define INCLUDED_JSI_VFS -#include "lib/types.h" - #include namespace Script { class Request; } @@ -27,11 +25,11 @@ namespace Script { class Request; } namespace JSI_VFS { void RegisterScriptFunctions_ReadWriteAnywhere(const Script::Request& rq, - const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + const std::uint16_t flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); void RegisterScriptFunctions_ReadOnlySimulation(const Script::Request& rq, - const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + const std::uint16_t flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); void RegisterScriptFunctions_ReadOnlySimulationMaps(const Script::Request& rq, - const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + const std::uint16_t flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); } #endif // INCLUDED_JSI_VFS diff --git a/source/renderer/DecalRData.cpp b/source/renderer/DecalRData.cpp index 46711fcff3..9058b8f9f7 100644 --- a/source/renderer/DecalRData.cpp +++ b/source/renderer/DecalRData.cpp @@ -32,7 +32,6 @@ #include "lib/allocators/STLAllocators.h" #include "lib/debug.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "ps/CLogger.h" #include "ps/CStrIntern.h" @@ -357,7 +356,7 @@ void CDecalRData::BuildVertexData() } m_VBDecals->m_Owner->UpdateChunkVertices(m_VBDecals.Get(), vertices.data()); - std::vector indices((i1 - i0) * (j1 - j0) * 6); + std::vector indices((i1 - i0) * (j1 - j0) * 6); const ssize_t w = i1 - i0 + 1; auto itIdx = indices.begin(); @@ -369,23 +368,23 @@ void CDecalRData::BuildVertexData() const bool dir = m_Decal->m_Terrain->GetTriangulationDir(i0 + di, j0 + dj); if (dir) { - *itIdx++ = u16(((dj + 0) * w + (di + 0)) + base); - *itIdx++ = u16(((dj + 0) * w + (di + 1)) + base); - *itIdx++ = u16(((dj + 1) * w + (di + 0)) + base); + *itIdx++ = static_cast(((dj + 0) * w + (di + 0)) + base); + *itIdx++ = static_cast(((dj + 0) * w + (di + 1)) + base); + *itIdx++ = static_cast(((dj + 1) * w + (di + 0)) + base); - *itIdx++ = u16(((dj + 0) * w + (di + 1)) + base); - *itIdx++ = u16(((dj + 1) * w + (di + 1)) + base); - *itIdx++ = u16(((dj + 1) * w + (di + 0)) + base); + *itIdx++ = static_cast(((dj + 0) * w + (di + 1)) + base); + *itIdx++ = static_cast(((dj + 1) * w + (di + 1)) + base); + *itIdx++ = static_cast(((dj + 1) * w + (di + 0)) + base); } else { - *itIdx++ = u16(((dj + 0) * w + (di + 0)) + base); - *itIdx++ = u16(((dj + 0) * w + (di + 1)) + base); - *itIdx++ = u16(((dj + 1) * w + (di + 1)) + base); + *itIdx++ = static_cast(((dj + 0) * w + (di + 0)) + base); + *itIdx++ = static_cast(((dj + 0) * w + (di + 1)) + base); + *itIdx++ = static_cast(((dj + 1) * w + (di + 1)) + base); - *itIdx++ = u16(((dj + 1) * w + (di + 1)) + base); - *itIdx++ = u16(((dj + 1) * w + (di + 0)) + base); - *itIdx++ = u16(((dj + 0) * w + (di + 0)) + base); + *itIdx++ = static_cast(((dj + 1) * w + (di + 1)) + base); + *itIdx++ = static_cast(((dj + 1) * w + (di + 0)) + base); + *itIdx++ = static_cast(((dj + 0) * w + (di + 0)) + base); } } } @@ -394,7 +393,7 @@ void CDecalRData::BuildVertexData() if (!m_VBDecalsIndices || m_VBDecalsIndices->m_Count != indices.size()) { m_VBDecalsIndices = g_Renderer.GetVertexBufferManager().AllocateChunk( - sizeof(u16), indices.size(), + sizeof(std::uint16_t), indices.size(), Renderer::Backend::IBuffer::Type::INDEX, Renderer::Backend::IBuffer::Usage::TRANSFER_DST); } diff --git a/source/renderer/GPUSkinnedModelRenderer.cpp b/source/renderer/GPUSkinnedModelRenderer.cpp index 17ea829fe5..ea8656afa9 100644 --- a/source/renderer/GPUSkinnedModelRenderer.cpp +++ b/source/renderer/GPUSkinnedModelRenderer.cpp @@ -29,7 +29,6 @@ #include "graphics/ShaderTechniquePtr.h" #include "lib/debug.h" #include "lib/lib.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "maths/Vector3D.h" #include "maths/Vector4D.h" @@ -266,7 +265,7 @@ ModelDefRData::ModelDefRData(const CModelDefPtr& modelDef) m_IndexArray.Layout(); // Re-index geometry and upload index. - VertexArrayIterator indices{m_IndexArray.GetIterator()}; + VertexArrayIterator indices{m_IndexArray.GetIterator()}; for (uint32_t index{0}; index < modelDef->GetNumFaces() * 3; ++index) indices[index] = remapTable[index]; m_IndexArray.Upload(); diff --git a/source/renderer/InstancingModelRenderer.cpp b/source/renderer/InstancingModelRenderer.cpp index c955ef296c..1924e8f736 100644 --- a/source/renderer/InstancingModelRenderer.cpp +++ b/source/renderer/InstancingModelRenderer.cpp @@ -23,7 +23,6 @@ #include "graphics/Model.h" #include "graphics/ModelDef.h" #include "lib/debug.h" -#include "lib/types.h" #include "maths/Vector3D.h" #include "maths/Vector4D.h" #include "ps/containers/StaticVector.h" @@ -147,7 +146,7 @@ IModelDef::IModelDef(const CModelDefPtr& mdef) m_IndexArray.SetNumberOfVertices(mdef->GetNumFaces() * 3); m_IndexArray.Layout(); - VertexArrayIterator Indices = m_IndexArray.GetIterator(); + VertexArrayIterator Indices = m_IndexArray.GetIterator(); size_t idxidx = 0; diff --git a/source/renderer/ModelRenderer.cpp b/source/renderer/ModelRenderer.cpp index 42a381b446..7c21a9ec0d 100644 --- a/source/renderer/ModelRenderer.cpp +++ b/source/renderer/ModelRenderer.cpp @@ -180,7 +180,7 @@ void ModelRenderer::BuildUV( // static void ModelRenderer::BuildIndices( - const CModelDefPtr& mdef, const VertexArrayIterator& Indices) + const CModelDefPtr& mdef, const VertexArrayIterator& Indices) { size_t idxidx = 0; SModelFace* faces = mdef->GetFaces(); diff --git a/source/renderer/ModelRenderer.h b/source/renderer/ModelRenderer.h index 3eb7b3b629..56eb964cd4 100644 --- a/source/renderer/ModelRenderer.h +++ b/source/renderer/ModelRenderer.h @@ -27,7 +27,6 @@ #include "graphics/MeshManager.h" #include "graphics/RenderableObject.h" #include "renderer/SceneRenderer.h" -#include "lib/types.h" #include #include @@ -162,7 +161,7 @@ public: * mdef->GetNumFaces()*3 elements. */ static void BuildIndices( - const CModelDefPtr& mdef, const VertexArrayIterator& Indices); + const CModelDefPtr& mdef, const VertexArrayIterator& Indices); /** * GenTangents: Generate tangents for the given CModelDef. diff --git a/source/renderer/OverlayRenderer.cpp b/source/renderer/OverlayRenderer.cpp index dbff0efefd..d25a4068cf 100644 --- a/source/renderer/OverlayRenderer.cpp +++ b/source/renderer/OverlayRenderer.cpp @@ -33,7 +33,6 @@ #include "graphics/TextureManager.h" #include "lib/debug.h" #include "lib/hash.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "maths/Vector2D.h" #include "maths/Vector3D.h" @@ -220,7 +219,7 @@ struct OverlayRendererInternals // Geometry for a unit sphere std::vector sphereVertexes; - std::vector sphereIndexes; + std::vector sphereIndexes; void GenerateSphere(); // Performs one-time setup. Called from CRenderer::Open, after graphics capabilities have @@ -270,8 +269,8 @@ void OverlayRendererInternals::Initialize() // Since the quads in the vertex array are independent and always consist of exactly 4 vertices per quad, the // indices are always the same; we can therefore fill in all the indices once and pretty much forget about // them. We then also no longer need its backing store, since we never change any indices afterwards. - VertexArrayIterator index = quadIndices.GetIterator(); - for (u16 i = 0; i < static_cast(MAX_QUAD_OVERLAYS); ++i) + VertexArrayIterator index = quadIndices.GetIterator(); + for (std::uint16_t i = 0; i < static_cast(MAX_QUAD_OVERLAYS); ++i) { *index++ = i * 4 + 0; *index++ = i * 4 + 1; @@ -747,10 +746,9 @@ void OverlayRenderer::RenderForegroundOverlays( deviceCommandContext->EndPass(); } -static void TessellateSphereFace(const CVector3D& a, u16 ai, - const CVector3D& b, u16 bi, - const CVector3D& c, u16 ci, - std::vector& vertexes, std::vector& indexes, int level) +static void TessellateSphereFace(const CVector3D& a, std::uint16_t ai, const CVector3D& b, + std::uint16_t bi, const CVector3D& c, std::uint16_t ci, std::vector& vertexes, + std::vector& indexes, int level) { if (level == 0) { @@ -773,7 +771,7 @@ static void TessellateSphereFace(const CVector3D& a, u16 ai, } } -static void TessellateSphere(std::vector& vertexes, std::vector& indexes, int level) +static void TessellateSphere(std::vector& vertexes, std::vector& indexes, int level) { /* Start with a tetrahedron, then tessellate */ float s = sqrtf(0.5f); diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 6ccf2e504f..37b71a9581 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -243,7 +243,7 @@ struct STileBlend { CTerrainTextureEntry* m_Texture; int m_Priority; - u16 m_TileMask; // bit n set if this blend contains neighbour tile BlendOffsets[n] + std::uint16_t m_TileMask; // bit n set if this blend contains neighbour tile BlendOffsets[n] struct DecreasingPriority { @@ -299,7 +299,7 @@ void CPatchRData::BuildBlends() m_BlendSplats.clear(); std::vector blendVertices; - std::vector blendIndices; + std::vector blendIndices; CTerrain* terrain = m_Patch->m_Parent; @@ -454,10 +454,10 @@ void CPatchRData::BuildBlends() // Update the indices to include the base offset of the vertex data for (size_t k = 0; k < blendIndices.size(); ++k) - blendIndices[k] += static_cast(m_VBBlends->m_Index); + blendIndices[k] += static_cast(m_VBBlends->m_Index); m_VBBlendIndices = g_Renderer.GetVertexBufferManager().AllocateChunk( - sizeof(u16), blendIndices.size(), + sizeof(std::uint16_t), blendIndices.size(), Renderer::Backend::IBuffer::Type::INDEX, Renderer::Backend::IBuffer::Usage::TRANSFER_DST, nullptr, CVertexBufferManager::Group::TERRAIN); @@ -465,8 +465,9 @@ void CPatchRData::BuildBlends() } } -void CPatchRData::AddBlend(std::vector& blendVertices, std::vector& blendIndices, - u16 i, u16 j, std::uint8_t shape, CTerrainTextureEntry* texture) +void CPatchRData::AddBlend(std::vector& blendVertices, + std::vector& blendIndices, std::uint16_t i, std::uint16_t j, std::uint8_t shape, + CTerrainTextureEntry* texture) { CTerrain* terrain = m_Patch->m_Parent; @@ -519,7 +520,7 @@ void CPatchRData::AddBlend(std::vector& blendVertices, std::vector CVector3D normal; - u16 index = static_cast(blendVertices.size()); + std::uint16_t index = static_cast(blendVertices.size()); terrain->CalcPosition(gx, gz, dst.m_Position); terrain->CalcNormal(gx, gz, normal); @@ -587,7 +588,8 @@ void CPatchRData::BuildIndices() // number of vertices in each direction in each patch ssize_t vsize=PATCH_SIZE+1; - // PATCH_SIZE must be 2^8-2 or less to not overflow u16 indices buffer. Thankfully this is always true. + // PATCH_SIZE must be 2^8-2 or less to not overflow std::uint16_t indices buffer. Thankfully this is + // always true. ENSURE(vsize*vsize < 65536); std::vector indices; @@ -631,23 +633,23 @@ void CPatchRData::BuildIndices() bool dir = terrain->GetTriangulationDir(px+i, pz+j); if (dir) { - indices.push_back(u16(((j+0)*vsize+(i+0))+base)); - indices.push_back(u16(((j+0)*vsize+(i+1))+base)); - indices.push_back(u16(((j+1)*vsize+(i+0))+base)); + indices.push_back(static_cast(((j+0)*vsize+(i+0))+base)); + indices.push_back(static_cast(((j+0)*vsize+(i+1))+base)); + indices.push_back(static_cast(((j+1)*vsize+(i+0))+base)); - indices.push_back(u16(((j+0)*vsize+(i+1))+base)); - indices.push_back(u16(((j+1)*vsize+(i+1))+base)); - indices.push_back(u16(((j+1)*vsize+(i+0))+base)); + indices.push_back(static_cast(((j+0)*vsize+(i+1))+base)); + indices.push_back(static_cast(((j+1)*vsize+(i+1))+base)); + indices.push_back(static_cast(((j+1)*vsize+(i+0))+base)); } else { - indices.push_back(u16(((j+0)*vsize+(i+0))+base)); - indices.push_back(u16(((j+0)*vsize+(i+1))+base)); - indices.push_back(u16(((j+1)*vsize+(i+1))+base)); + indices.push_back(static_cast(((j+0)*vsize+(i+0))+base)); + indices.push_back(static_cast(((j+0)*vsize+(i+1))+base)); + indices.push_back(static_cast(((j+1)*vsize+(i+1))+base)); - indices.push_back(u16(((j+1)*vsize+(i+1))+base)); - indices.push_back(u16(((j+1)*vsize+(i+0))+base)); - indices.push_back(u16(((j+0)*vsize+(i+0))+base)); + indices.push_back(static_cast(((j+1)*vsize+(i+1))+base)); + indices.push_back(static_cast(((j+1)*vsize+(i+0))+base)); + indices.push_back(static_cast(((j+0)*vsize+(i+0))+base)); } } } @@ -662,7 +664,7 @@ void CPatchRData::BuildIndices() // Construct vertex buffer m_VBBaseIndices = g_Renderer.GetVertexBufferManager().AllocateChunk( - sizeof(u16), indices.size(), + sizeof(std::uint16_t), indices.size(), Renderer::Backend::IBuffer::Type::INDEX, Renderer::Backend::IBuffer::Usage::TRANSFER_DST, nullptr, CVertexBufferManager::Group::TERRAIN); m_VBBaseIndices->m_Owner->UpdateChunkVertices(m_VBBaseIndices.Get(), &indices[0]); @@ -1432,14 +1434,14 @@ void CPatchRData::BuildWater() // Build data for water std::vector water_vertex_data; - std::vector water_indices; - u16 water_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; + std::vector water_indices; + std::uint16_t water_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; memset(water_index_map, 0xFF, sizeof(water_index_map)); // Build data for shore std::vector water_vertex_data_shore; - std::vector water_indices_shore; - u16 water_shore_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; + std::vector water_indices_shore; + std::uint16_t water_shore_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; memset(water_shore_index_map, 0xFF, sizeof(water_shore_index_map)); const WaterManager& waterManager = g_Renderer.GetSceneRenderer().GetWaterManager(); @@ -1515,7 +1517,7 @@ void CPatchRData::BuildWater() vertex.m_WaterData = CVector2D(waterManager.m_WindStrength[xx + zz*mapSize], depth); - water_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast(water_vertex_data.size()); + water_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast(water_vertex_data.size()); water_vertex_data.push_back(vertex); } water_indices.push_back(water_index_map[z + moves[2][1]][x + moves[2][0]]); @@ -1548,7 +1550,7 @@ void CPatchRData::BuildWater() vertex.m_WaterData = CVector2D(0.0f, -5.0f); - water_shore_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast(water_vertex_data_shore.size()); + water_shore_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast(water_vertex_data_shore.size()); water_vertex_data_shore.push_back(vertex); } if (terrain->GetTriangulationDir(x + px, z + pz)) @@ -1583,7 +1585,7 @@ void CPatchRData::BuildWater() m_VBWater->m_Owner->UpdateChunkVertices(m_VBWater.Get(), &water_vertex_data[0]); m_VBWaterIndices = g_Renderer.GetVertexBufferManager().AllocateChunk( - sizeof(u16), water_indices.size(), + sizeof(std::uint16_t), water_indices.size(), Renderer::Backend::IBuffer::Type::INDEX, Renderer::Backend::IBuffer::Usage::TRANSFER_DST, nullptr, CVertexBufferManager::Group::WATER); @@ -1601,7 +1603,7 @@ void CPatchRData::BuildWater() // Construct indices buffer m_VBWaterIndicesShore = g_Renderer.GetVertexBufferManager().AllocateChunk( - sizeof(u16), water_indices_shore.size(), + sizeof(std::uint16_t), water_indices_shore.size(), Renderer::Backend::IBuffer::Type::INDEX, Renderer::Backend::IBuffer::Usage::TRANSFER_DST, nullptr, CVertexBufferManager::Group::WATER); diff --git a/source/renderer/PatchRData.h b/source/renderer/PatchRData.h index f2d088b3bd..2a816bd72f 100644 --- a/source/renderer/PatchRData.h +++ b/source/renderer/PatchRData.h @@ -23,7 +23,6 @@ #include "graphics/RenderableObject.h" #include "lib/code_annotation.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/BoundingBoxAligned.h" #include "maths/Vector2D.h" #include "maths/Vector3D.h" @@ -153,8 +152,8 @@ private: // build this renderdata object void Build(); - void AddBlend(std::vector& blendVertices, std::vector& blendIndices, - u16 i, u16 j, std::uint8_t shape, CTerrainTextureEntry* texture); + void AddBlend(std::vector& blendVertices, std::vector& blendIndices, + std::uint16_t i, std::uint16_t j, std::uint8_t shape, CTerrainTextureEntry* texture); void BuildBlends(); void BuildIndices(); diff --git a/source/renderer/SilhouetteRenderer.cpp b/source/renderer/SilhouetteRenderer.cpp index 93dacab547..c2b32e9b7e 100644 --- a/source/renderer/SilhouetteRenderer.cpp +++ b/source/renderer/SilhouetteRenderer.cpp @@ -30,7 +30,6 @@ #include "graphics/ShaderTechnique.h" #include "lib/debug.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/MathUtil.h" #include "maths/Matrix3D.h" #include "maths/Vector3D.h" @@ -121,14 +120,14 @@ void SilhouetteRenderer::AddCaster(CModel* model) * that lets us pack and sort the edge/point list efficiently. */ -static const u16 g_MaxCoord = 1 << 14; -static const u16 g_HalfMaxCoord = g_MaxCoord / 2; +static const std::uint16_t g_MaxCoord = 1 << 14; +static const std::uint16_t g_HalfMaxCoord = g_MaxCoord / 2; struct Occluder { CRenderableObject* renderable; bool isPatch; - u16 x0, y0, x1, y1; + std::uint16_t x0, y0, x1, y1; float z; bool rendered; }; @@ -136,7 +135,7 @@ struct Occluder struct Caster { CModel* model; - u16 x, y; + std::uint16_t x, y; float z; bool rendered; }; @@ -145,9 +144,9 @@ enum { EDGE_IN, EDGE_OUT, POINT }; // Entry is essentially: // struct Entry { -// u16 id; // index into occluders array -// u16 type : 2; -// u16 x : 14; +// std::uint16_t id; // index into occluders array +// std::uint16_t type : 2; +// std::uint16_t x : 14; // }; // where x is in the most significant bits, so that sorting as a uint32_t // is the same as sorting by x. To avoid worrying about endianness and the @@ -156,20 +155,23 @@ enum { EDGE_IN, EDGE_OUT, POINT }; typedef uint32_t Entry; -static Entry EntryCreate(int type, u16 id, u16 x) { return (x << 18) | (type << 16) | id; } +static Entry EntryCreate(int type, std::uint16_t id, std::uint16_t x) +{ + return (x << 18) | (type << 16) | id; +} static int EntryGetId(Entry e) { return e & 0xffff; } static int EntryGetType(Entry e) { return (e >> 16) & 3; } struct ActiveList { - std::vector m_Ids; + std::vector m_Ids; - void Add(u16 id) + void Add(std::uint16_t id) { m_Ids.push_back(id); } - void Remove(u16 id) + void Remove(std::uint16_t id) { ssize_t sz = m_Ids.size(); for (ssize_t i = sz-1; i >= 0; --i) @@ -187,10 +189,10 @@ struct ActiveList static void ComputeScreenBounds(Occluder& occluder, const CBoundingBoxAligned& bounds, CMatrix3D& proj) { - u16 x0 = std::numeric_limits::max(); - u16 y0 = std::numeric_limits::max(); - u16 x1 = std::numeric_limits::min(); - u16 y1 = std::numeric_limits::min(); + std::uint16_t x0 = std::numeric_limits::max(); + std::uint16_t y0 = std::numeric_limits::max(); + std::uint16_t x1 = std::numeric_limits::min(); + std::uint16_t y1 = std::numeric_limits::min(); float z0 = std::numeric_limits::max(); for (size_t ix = 0; ix <= 1; ++ix) { @@ -200,8 +202,12 @@ static void ComputeScreenBounds(Occluder& occluder, const CBoundingBoxAligned& b { CVector4D svec = proj.Transform(CVector4D(bounds[ix].X, bounds[iy].Y, bounds[iz].Z, 1.0f)); // Avoid overflows - u16 svx = static_cast(Clamp(g_HalfMaxCoord + g_HalfMaxCoord * (svec.X / svec.W), 0.f, static_cast(g_MaxCoord - 1))); - u16 svy = static_cast(Clamp(g_HalfMaxCoord + g_HalfMaxCoord * (svec.Y / svec.W), 0.f, static_cast(g_MaxCoord - 1))); + std::uint16_t svx = static_cast(Clamp(g_HalfMaxCoord + + g_HalfMaxCoord * (svec.X / svec.W), 0.f, + static_cast(g_MaxCoord - 1))); + std::uint16_t svy = static_cast(Clamp(g_HalfMaxCoord + + g_HalfMaxCoord * (svec.Y / svec.W), 0.f, + static_cast(g_MaxCoord - 1))); x0 = std::min(x0, svx); y0 = std::min(y0, svy); x1 = std::max(x1, svx); @@ -213,18 +219,24 @@ static void ComputeScreenBounds(Occluder& occluder, const CBoundingBoxAligned& b // TODO: there must be a quicker way to do this than to test every vertex, // given the symmetry of the bounding box - occluder.x0 = Clamp(x0, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); - occluder.y0 = Clamp(y0, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); - occluder.x1 = Clamp(x1, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); - occluder.y1 = Clamp(y1, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); + occluder.x0 = Clamp(x0, std::numeric_limits::min(), + static_cast(g_MaxCoord - 1)); + occluder.y0 = Clamp(y0, std::numeric_limits::min(), + static_cast(g_MaxCoord - 1)); + occluder.x1 = Clamp(x1, std::numeric_limits::min(), + static_cast(g_MaxCoord - 1)); + occluder.y1 = Clamp(y1, std::numeric_limits::min(), + static_cast(g_MaxCoord - 1)); occluder.z = z0; } static void ComputeScreenPos(Caster& caster, const CVector3D& pos, CMatrix3D& proj) { CVector4D svec = proj.Transform(CVector4D(pos.X, pos.Y, pos.Z, 1.0f)); - caster.x = static_cast(Clamp(g_HalfMaxCoord + g_HalfMaxCoord * (svec.X / svec.W), 0.f, static_cast(g_MaxCoord - 1))); - caster.y = static_cast(Clamp(g_HalfMaxCoord + g_HalfMaxCoord * (svec.Y / svec.W), 0.f, static_cast(g_MaxCoord - 1))); + caster.x = static_cast(Clamp(g_HalfMaxCoord + g_HalfMaxCoord * (svec.X / svec.W), 0.f, + static_cast(g_MaxCoord - 1))); + caster.y = static_cast(Clamp(g_HalfMaxCoord + g_HalfMaxCoord * (svec.Y / svec.W), 0.f, + static_cast(g_MaxCoord - 1))); caster.z = svec.Z / svec.W; } @@ -298,7 +310,7 @@ void SilhouetteRenderer::ComputeSubmissions(const CCamera& camera) if (d.x0 == d.x1 || d.y0 == d.y1) continue; - u16 id = static_cast(occluders.size()); + std::uint16_t id = static_cast(occluders.size()); occluders.push_back(d); entries.push_back(EntryCreate(EDGE_IN, id, d.x0)); @@ -319,7 +331,7 @@ void SilhouetteRenderer::ComputeSubmissions(const CCamera& camera) if (d.x0 == d.x1 || d.y0 == d.y1) continue; - u16 id = static_cast(occluders.size()); + std::uint16_t id = static_cast(occluders.size()); occluders.push_back(d); entries.push_back(EntryCreate(EDGE_IN, id, d.x0)); @@ -336,14 +348,14 @@ void SilhouetteRenderer::ComputeSubmissions(const CCamera& camera) d.rendered = false; ComputeScreenPos(d, pos, proj); - u16 id = static_cast(casters.size()); + std::uint16_t id = static_cast(casters.size()); casters.push_back(d); entries.push_back(EntryCreate(POINT, id, d.x)); } } - // Make sure the u16 id didn't overflow + // Make sure the std::uint16_t id didn't overflow ENSURE(occluders.size() < 65536 && casters.size() < 65536); { @@ -361,7 +373,7 @@ void SilhouetteRenderer::ComputeSubmissions(const CCamera& camera) { Entry e = entries[i]; int type = EntryGetType(e); - u16 id = EntryGetId(e); + std::uint16_t id = EntryGetId(e); if (type == EDGE_IN) active.Add(id); else if (type == EDGE_OUT) diff --git a/source/renderer/TexturedLineRData.cpp b/source/renderer/TexturedLineRData.cpp index 7e23608cd3..76dc320d9e 100644 --- a/source/renderer/TexturedLineRData.cpp +++ b/source/renderer/TexturedLineRData.cpp @@ -117,7 +117,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) float v = 0.f; std::vector vertices; - std::vector indices; + std::vector indices; const size_t n = line.m_Coords.size(); // number of line points bool closed = line.m_Closed; @@ -196,9 +196,9 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) vertices.push_back(vertex1); vertices.push_back(vertex2); - u16 vertexCount = static_cast(vertices.size()); - u16 index1 = vertexCount - 2; // index of vertex1 in this iteration (TR of this quad) - u16 index2 = vertexCount - 1; // index of the vertex2 in this iteration (TL of this quad) + std::uint16_t vertexCount = static_cast(vertices.size()); + std::uint16_t index1 = vertexCount - 2; // index of vertex1 in this iteration (TR of this quad) + std::uint16_t index2 = vertexCount - 1; // index of the vertex2 in this iteration (TL of this quad) if (i == 0) { @@ -208,8 +208,8 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) } else { - u16 index1Prev = vertexCount - 4; // index of the vertex1 in the previous iteration (BR of this quad) - u16 index2Prev = vertexCount - 3; // index of the vertex2 in the previous iteration (BL of this quad) + std::uint16_t index1Prev = vertexCount - 4; // index of the vertex1 in the previous iteration (BR of this quad) + std::uint16_t index2Prev = vertexCount - 3; // index of the vertex2 in the previous iteration (BL of this quad) ENSURE(index1Prev < vertexCount); ENSURE(index2Prev < vertexCount); // Add two corner points from last iteration and join with one of our own corners to create triangle 1 @@ -257,7 +257,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) // close the path if (n % 2 == 0) { - u16 vertexCount = static_cast(vertices.size()); + std::uint16_t vertexCount = static_cast(vertices.size()); indices.push_back(vertexCount - 2); indices.push_back(vertexCount - 1); indices.push_back(0); @@ -274,7 +274,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) vertices.push_back(vertex1); vertices.push_back(vertex2); - u16 vertexCount = static_cast(vertices.size()); + std::uint16_t vertexCount = static_cast(vertices.size()); indices.push_back(vertexCount - 4); indices.push_back(vertexCount - 3); indices.push_back(vertexCount - 2); @@ -289,7 +289,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) // Create start and end caps. On either end, this is done by taking the centroid between the last and second-to-last pair of // vertices that was generated along the path (i.e. the vertex1's and vertex2's from above), taking a directional vector // between them, and drawing the line cap in the plane given by the two butt-end corner points plus said vector. - std::vector capIndices; + std::vector capIndices; std::vector capVertices; // create end cap @@ -306,7 +306,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) ); for (unsigned i = 0; i < capIndices.size(); i++) - capIndices[i] += static_cast(vertices.size()); + capIndices[i] += static_cast(vertices.size()); vertices.insert(vertices.end(), capVertices.begin(), capVertices.end()); indices.insert(indices.end(), capIndices.begin(), capIndices.end()); @@ -328,7 +328,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) ); for (unsigned i = 0; i < capIndices.size(); i++) - capIndices[i] += static_cast(vertices.size()); + capIndices[i] += static_cast(vertices.size()); vertices.insert(vertices.end(), capVertices.begin(), capVertices.end()); indices.insert(indices.end(), capIndices.begin(), capIndices.end()); @@ -354,10 +354,10 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) m_VB->m_Owner->UpdateChunkVertices(m_VB.Get(), &vertices[0]); for (size_t k = 0; k < indices.size(); ++k) - indices[k] += static_cast(m_VB->m_Index); + indices[k] += static_cast(m_VB->m_Index); m_VBIndices = g_Renderer.GetVertexBufferManager().AllocateChunk( - sizeof(u16), indices.size(), Renderer::Backend::IBuffer::Type::INDEX, + sizeof(std::uint16_t), indices.size(), Renderer::Backend::IBuffer::Type::INDEX, Renderer::Backend::IBuffer::Usage::TRANSFER_DST); if (m_VBIndices) m_VBIndices->m_Owner->UpdateChunkVertices(m_VBIndices.Get(), &indices[0]); @@ -367,7 +367,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const CVector3D& corner1, const CVector3D& corner2, const CVector3D& lineDirectionNormal, SOverlayTexturedLine::LineCapType endCapType, std::vector& verticesOut, - std::vector& indicesOut) + std::vector& indicesOut) { if (endCapType == SOverlayTexturedLine::LINECAP_FLAT) return; // no action needed, this is the default @@ -389,7 +389,7 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C CVector3D centerPoint = (corner1 + corner2) * 0.5f; SVertex centerVertex(centerPoint, CVector2D(0.5f, 0.5f)); - u16 indexOffset = static_cast(verticesOut.size()); // index offset in verticesOut from where we start adding our vertices + std::uint16_t indexOffset = static_cast(verticesOut.size()); // index offset in verticesOut from where we start adding our vertices switch (endCapType) { diff --git a/source/renderer/TexturedLineRData.h b/source/renderer/TexturedLineRData.h index d7ddc09053..299e29dbe0 100644 --- a/source/renderer/TexturedLineRData.h +++ b/source/renderer/TexturedLineRData.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 @@ -21,7 +21,6 @@ #include "graphics/Overlay.h" #include "graphics/RenderableObject.h" #include "lib/code_annotation.h" -#include "lib/types.h" #include "maths/BoundingBoxAligned.h" #include "maths/Vector2D.h" #include "maths/Vector3D.h" @@ -87,8 +86,10 @@ protected: * @param verticesOut Output vector of vertices for passing to the renderer. * @param indicesOut Output vector of vertex indices for passing to the renderer. */ - void CreateLineCap(const SOverlayTexturedLine& line, const CVector3D& corner1, const CVector3D& corner2, const CVector3D& normal, - SOverlayTexturedLine::LineCapType endCapType, std::vector& verticesOut, std::vector& indicesOut); + void CreateLineCap(const SOverlayTexturedLine& line, const CVector3D& corner1, + const CVector3D& corner2, const CVector3D& normal, + SOverlayTexturedLine::LineCapType endCapType, std::vector& verticesOut, + std::vector& indicesOut); /// Small utility function; grabs the centroid of the positions of two vertices inline CVector3D Centroid(const SVertex& v1, const SVertex& v2) diff --git a/source/renderer/VertexArray.cpp b/source/renderer/VertexArray.cpp index fc8187fd24..2f2fbfda5d 100644 --- a/source/renderer/VertexArray.cpp +++ b/source/renderer/VertexArray.cpp @@ -47,16 +47,16 @@ uint32_t GetAttributeSize(const Renderer::Backend::Format format) case Renderer::Backend::Format::R16_UINT: case Renderer::Backend::Format::R16_SINT: case Renderer::Backend::Format::R16_SFLOAT: - return sizeof(u16); + return sizeof(std::uint16_t); case Renderer::Backend::Format::R16G16_UNORM: case Renderer::Backend::Format::R16G16_UINT: case Renderer::Backend::Format::R16G16_SINT: case Renderer::Backend::Format::R16G16_SFLOAT: - return sizeof(u16) * 2; + return sizeof(std::uint16_t) * 2; case Renderer::Backend::Format::R16G16B16_SFLOAT: - return sizeof(u16) * 3; + return sizeof(std::uint16_t) * 3; case Renderer::Backend::Format::R16G16B16A16_SFLOAT: - return sizeof(u16) * 4; + return sizeof(std::uint16_t) * 4; case Renderer::Backend::Format::R32_SFLOAT: return sizeof(float); case Renderer::Backend::Format::R32G32_SFLOAT: @@ -169,21 +169,21 @@ VertexArrayIterator VertexArray::Attribute::GetIterator() } template<> -VertexArrayIterator VertexArray::Attribute::GetIterator() const +VertexArrayIterator VertexArray::Attribute::GetIterator() const { ENSURE(vertexArray); ENSURE(format == Renderer::Backend::Format::R16_UINT); - return vertexArray->MakeIterator(this); + return vertexArray->MakeIterator(this); } template<> -VertexArrayIterator VertexArray::Attribute::GetIterator() const +VertexArrayIterator VertexArray::Attribute::GetIterator() const { ENSURE(vertexArray); ENSURE(format == Renderer::Backend::Format::R16G16_UINT); - return vertexArray->MakeIterator(this); + return vertexArray->MakeIterator(this); } template<> @@ -320,7 +320,7 @@ VertexIndexArray::VertexIndexArray(const uint32_t usage) : AddAttribute(&m_Attr); } -VertexArrayIterator VertexIndexArray::GetIterator() const +VertexArrayIterator VertexIndexArray::GetIterator() const { - return m_Attr.GetIterator(); + return m_Attr.GetIterator(); } diff --git a/source/renderer/VertexArray.h b/source/renderer/VertexArray.h index 283d047f30..2ee82f5faf 100644 --- a/source/renderer/VertexArray.h +++ b/source/renderer/VertexArray.h @@ -20,7 +20,6 @@ #include "lib/debug.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "renderer/VertexBuffer.h" #include "renderer/VertexBufferManager.h" #include "renderer/backend/Format.h" @@ -158,7 +157,7 @@ public: // Get an iterator over the backing store for the given attribute that // initially points at the first vertex. // Supported types T: CVector3D, CVector4D, float[2], SColor4ub, - // u16, u16[2], std::uint8_t[4], short, short[2]. + // std::uint16_t, std::uint16_t[2], std::uint8_t[4], short, short[2]. // This function verifies at runtime that the requested type T matches // the attribute definition passed to AddAttribute(). template @@ -233,8 +232,8 @@ class VertexIndexArray : public VertexArray public: VertexIndexArray(const uint32_t usage); - /// Gets the iterator over the (only) attribute in this array, i.e. a u16. - VertexArrayIterator GetIterator() const; + /// Gets the iterator over the (only) attribute in this array, i.e. a std::uint16_t. + VertexArrayIterator GetIterator() const; private: Attribute m_Attr; diff --git a/source/renderer/VertexBuffer.cpp b/source/renderer/VertexBuffer.cpp index 37ce3bb83c..60ac522eb3 100644 --- a/source/renderer/VertexBuffer.cpp +++ b/source/renderer/VertexBuffer.cpp @@ -20,7 +20,6 @@ #include "VertexBuffer.h" #include "lib/debug.h" -#include "lib/types.h" #include "renderer/Renderer.h" #include "renderer/backend/IDevice.h" #include "renderer/backend/IDeviceCommandContext.h" @@ -59,7 +58,7 @@ CVertexBuffer::CVertexBuffer( } else if (type == Renderer::Backend::IBuffer::Type::INDEX) { - ENSURE(vertexSize == sizeof(u16)); + ENSURE(vertexSize == sizeof(std::uint16_t)); } // store max/free vertex counts diff --git a/source/renderer/WaterManager.cpp b/source/renderer/WaterManager.cpp index f8c53a1fdb..34b3b3e286 100644 --- a/source/renderer/WaterManager.cpp +++ b/source/renderer/WaterManager.cpp @@ -479,7 +479,8 @@ void WaterManager::UnloadWaterTextures() } template -static inline void ComputeDirection(float* distanceMap, const u16* heightmap, float waterHeight, size_t SideSize, size_t maxLevel) +static inline void ComputeDirection(float* distanceMap, const std::uint16_t* heightmap, float waterHeight, + size_t SideSize, size_t maxLevel) { #define ABOVEWATER(x, z) (HEIGHT_SCALE * heightmap[z*SideSize + x] >= waterHeight) #define UPDATELOOKAHEAD \ @@ -545,7 +546,7 @@ void WaterManager::RecomputeDistanceHeightmap() // Create a manhattan-distance heightmap. // This could be refined to only be done near the coast itself, but it's probably not necessary. - const u16* const heightmap = terrain.GetHeightMap(); + const std::uint16_t* const heightmap = terrain.GetHeightMap(); ComputeDirection(m_DistanceHeightmap.get(), heightmap, m_WaterHeight, SideSize, maxLevel); ComputeDirection(m_DistanceHeightmap.get(), heightmap, m_WaterHeight, SideSize, maxLevel); @@ -688,13 +689,13 @@ void WaterManager::CreateWaveMeshes() } // Fourth step: create waves themselves, using those chains. We basically create subchains. - u16 waveSizes = 14; // maximal size in width. + std::uint16_t waveSizes = 14; // maximal size in width. // Construct indices buffer (we can afford one for all of them) - std::vector water_indices; - for (u16 a = 0; a < waveSizes - 1; ++a) + std::vector water_indices; + for (std::uint16_t a = 0; a < waveSizes - 1; ++a) { - for (u16 rect = 0; rect < 7; ++rect) + for (std::uint16_t rect = 0; rect < 7; ++rect) { water_indices.push_back(a * 9 + rect); water_indices.push_back(a * 9 + 9 + rect); @@ -706,7 +707,7 @@ void WaterManager::CreateWaveMeshes() } // Generic indexes, max-length m_ShoreWavesVBIndices = g_Renderer.GetVertexBufferManager().AllocateChunk( - sizeof(u16), water_indices.size(), + sizeof(std::uint16_t), water_indices.size(), Renderer::Backend::IBuffer::Type::INDEX, Renderer::Backend::IBuffer::Usage::TRANSFER_DST, nullptr, CVertexBufferManager::Group::WATER); @@ -722,14 +723,14 @@ void WaterManager::CreateWaveMeshes() if (CoastalPointsChains[i].size()- 1 - j < waveSizes) break; - u16 width = waveSizes; + std::uint16_t width = waveSizes; // First pass to get some parameters out. float outmost = 0.0f; // how far to move on the shore. float avgDepth = 0.0f; int sign = 1; CVector2D firstPerp(0,0), perp(0,0), lastPerp(0,0); - for (u16 a = 0; a < waveSizes;++a) + for (std::uint16_t a = 0; a < waveSizes; ++a) { lastPerp = perp; perp = CVector2D(0,0); @@ -814,7 +815,7 @@ void WaterManager::CreateWaveMeshes() shoreWave->m_TimeDiff = diff; diff += (rand() % 100) / 25.0f + 4.0f; - for (u16 a = 0; a < width;++a) + for (std::uint16_t a = 0; a < width; ++a) { perp = CVector2D(0,0); int nb = 0; diff --git a/source/scriptinterface/Conversions.cpp b/source/scriptinterface/Conversions.cpp index fdbb2c8b04..b93db26bf8 100644 --- a/source/scriptinterface/Conversions.cpp +++ b/source/scriptinterface/Conversions.cpp @@ -85,7 +85,7 @@ template<> bool FromJSVal(const Request& rq, JS::HandleValue v, u32& out) return true; } -template<> bool FromJSVal(const Request& rq, JS::HandleValue v, u16& out) +template<> bool FromJSVal(const Request& rq, JS::HandleValue v, std::uint16_t& out) { FAIL_IF_NOT(v.isNumber(), v); if (!JS::ToUint16(rq.cx, v, &out)) @@ -95,7 +95,7 @@ template<> bool FromJSVal(const Request& rq, JS::HandleValue v, u16& out) template<> bool FromJSVal(const Request& rq, JS::HandleValue v, std::uint8_t& out) { - u16 tmp; + std::uint16_t tmp; FAIL_IF_NOT(v.isNumber(), v); if (!JS::ToUint16(rq.cx, v, &tmp)) return false; @@ -211,7 +211,7 @@ template<> void ToJSVal(const Request&, JS::MutableHandleValue ret ret.set(JS::NumberValue(val)); } -template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, const u16& val) +template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, const std::uint16_t& val) { ret.set(JS::NumberValue(val)); } @@ -278,7 +278,7 @@ template<> void ToJSVal(const Request& rq, JS::MutableHandleValue ret, c JSVAL_VECTOR(int) JSVAL_VECTOR(u32) -JSVAL_VECTOR(u16) +JSVAL_VECTOR(std::uint16_t) JSVAL_VECTOR(std::string) JSVAL_VECTOR(std::wstring) JSVAL_VECTOR(std::vector) diff --git a/source/scriptinterface/FunctionWrapper.h b/source/scriptinterface/FunctionWrapper.h index 3d88de0220..da7d1ec783 100644 --- a/source/scriptinterface/FunctionWrapper.h +++ b/source/scriptinterface/FunctionWrapper.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_FUNCTIONWRAPPER #define INCLUDED_FUNCTIONWRAPPER -#include "lib/types.h" #include "scriptinterface/Conversions.h" #include "scriptinterface/Exceptions.h" #include "scriptinterface/Request.h" @@ -445,7 +444,7 @@ public: */ template thisGetter = nullptr> static JSFunctionSpec Wrap(const char* name, - const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) + const std::uint16_t flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) { return JS_FN(name, (&ToJSNative), args_info::nb_args, flags); } @@ -455,7 +454,7 @@ public: */ template thisGetter = nullptr> static JSFunction* Create(const Request& rq, const char* name, - const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) + const std::uint16_t flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) { return JS_NewFunction(rq.cx, &ToJSNative, args_info::nb_args, flags, name); } @@ -465,7 +464,7 @@ public: */ template thisGetter = nullptr> static void Register(const Request& rq, const char* name, - const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) + const std::uint16_t flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) { JS_DefineFunction(rq.cx, rq.nativeScope, name, &ToJSNative, args_info::nb_args, flags); } @@ -477,7 +476,7 @@ public: */ template thisGetter = nullptr> static void Register(JSContext* cx, JS::HandleObject scope, const char* name, - const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) + const std::uint16_t flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) { JS_DefineFunction(cx, scope, name, &ToJSNative, args_info::nb_args, flags); } diff --git a/source/simulation2/components/CCmpAIManager.cpp b/source/simulation2/components/CCmpAIManager.cpp index 83e86f397e..ffc929c2c7 100644 --- a/source/simulation2/components/CCmpAIManager.cpp +++ b/source/simulation2/components/CCmpAIManager.cpp @@ -761,7 +761,7 @@ public: // AI pathfinder Serializer(deserializer, "non pathfinding pass classes", m_NonPathfindingPassClasses); Serializer(deserializer, "pathfinding pass classes", m_PathfindingPassClasses); - u16 mapW, mapH; + std::uint16_t mapW, mapH; deserializer.NumberU16_Unbounded("pathfinder grid w", mapW); deserializer.NumberU16_Unbounded("pathfinder grid h", mapH); m_PassabilityMap = Grid(mapW, mapH); diff --git a/source/simulation2/components/CCmpObstructionManager.cpp b/source/simulation2/components/CCmpObstructionManager.cpp index 209f67d6c9..daf0aed703 100644 --- a/source/simulation2/components/CCmpObstructionManager.cpp +++ b/source/simulation2/components/CCmpObstructionManager.cpp @@ -578,7 +578,7 @@ private: if (m_UpdateInformations.dirtinessGrid.m_W == 0) return; - u16 j0, j1, i0, i1; + std::uint16_t j0, j1, i0, i1; Pathfinding::NearestNavcell(x - hbox.X, z - hbox.Y, i0, j0, m_UpdateInformations.dirtinessGrid.m_W, m_UpdateInformations.dirtinessGrid.m_H); Pathfinding::NearestNavcell(x + hbox.X, z + hbox.Y, i1, j1, m_UpdateInformations.dirtinessGrid.m_W, m_UpdateInformations.dirtinessGrid.m_H); @@ -1127,15 +1127,15 @@ void CCmpObstructionManager::Rasterize(Grid& grid, const std::vecto // Pass classes will get shapes rasterized on them depending on their Obstruction value. // Classes with another value than "pathfinding" should not use Clearance. - std::map pathfindingMasks; - u16 foundationMask = 0; + std::map pathfindingMasks; + std::uint16_t foundationMask = 0; for (const PathfinderPassability& passability : passClasses) { switch (passability.m_Obstructions) { case PathfinderPassability::PATHFINDING: { - std::map::iterator it = pathfindingMasks.find(passability.m_Clearance); + std::map::iterator it = pathfindingMasks.find(passability.m_Clearance); if (it == pathfindingMasks.end()) pathfindingMasks[passability.m_Clearance] = passability.m_Mask; else @@ -1200,11 +1200,11 @@ void CCmpObstructionManager::RasterizeHelper(Grid& grid, ICmpObstru CFixedVector2D center(pair.second.x, pair.second.z); entity_pos_t r = pair.second.clearance + clearance; - u16 i0, j0, i1, j1; + std::uint16_t i0, j0, i1, j1; Pathfinding::NearestNavcell(center.X - r, center.Y - r, i0, j0, grid.m_W, grid.m_H); Pathfinding::NearestNavcell(center.X + r, center.Y + r, i1, j1, grid.m_W, grid.m_H); - for (u16 j = j0+1; j < j1; ++j) - for (u16 i = i0+1; i < i1; ++i) + for (std::uint16_t j = j0+1; j < j1; ++j) + for (std::uint16_t i = i0+1; i < i1; ++i) grid.set(i, j, grid.get(i, j) | appliedMask); } } @@ -1318,8 +1318,8 @@ void CCmpObstructionManager::GetUnitsOnObstruction(const ObstructionSquare& squa // Check whether the unit's center is on a navcell that's in // any of the spans - u16 i = (shape.x / Pathfinding::NAVCELL_SIZE).ToInt_RoundToNegInfinity(); - u16 j = (shape.z / Pathfinding::NAVCELL_SIZE).ToInt_RoundToNegInfinity(); + std::uint16_t i = (shape.x / Pathfinding::NAVCELL_SIZE).ToInt_RoundToNegInfinity(); + std::uint16_t j = (shape.z / Pathfinding::NAVCELL_SIZE).ToInt_RoundToNegInfinity(); for (const SimRasterize::Span& span : spans) { diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index b58e487c38..7ea5812959 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -132,7 +132,8 @@ void CCmpPathfinder::Init(const CParamNode&) // to avoid spending too much time there (since the latter are threaded and thus much 'cheaper'). // This loads that maximum number (note that it's per computation call, not per turn for now). const CParamNode pathingSettings = externalParamNode.GetChild("Pathfinder"); - m_MaxSameTurnMoves = (u16)pathingSettings.GetChild("MaxSameTurnMoves").ToInt(); + m_MaxSameTurnMoves = static_cast( + pathingSettings.GetChild("MaxSameTurnMoves").ToInt()); const CParamNode::ChildrenMap& passClasses = externalParamNode.GetChild("Pathfinder").GetChild("PassabilityClasses").GetChildren(); for (CParamNode::ChildrenMap::const_iterator it = passClasses.begin(); it != passClasses.end(); ++it) @@ -349,26 +350,26 @@ const Grid& CCmpPathfinder::GetPassabilityGrid() * Euclidean distances; currently it effectively does dist=max(dx,dy) instead. * This would only really be a problem for big clearances. */ -static void ExpandImpassableCells(Grid& grid, u16 clearance, pass_class_t mask) +static void ExpandImpassableCells(Grid& grid, std::uint16_t clearance, pass_class_t mask) { PROFILE3("ExpandImpassableCells"); - u16 w = grid.m_W; - u16 h = grid.m_H; + std::uint16_t w = grid.m_W; + std::uint16_t h = grid.m_H; // First expand impassable cells horizontally into a temporary 1-bit grid Grid tempGrid(w, h); - for (u16 j = 0; j < h; ++j) + for (std::uint16_t j = 0; j < h; ++j) { // New cell (i,j) is blocked if (i',j) blocked for any i-clearance <= i' <= i+clearance // Count the number of blocked cells around i=0 - u16 numBlocked = 0; - for (u16 i = 0; i <= clearance && i < w; ++i) + std::uint16_t numBlocked = 0; + for (std::uint16_t i = 0; i <= clearance && i < w; ++i) if (!IS_PASSABLE(grid.get(i, j), mask)) ++numBlocked; - for (u16 i = 0; i < w; ++i) + for (std::uint16_t i = 0; i < w; ++i) { // Store a flag if blocked by at least one nearby cell if (numBlocked) @@ -384,16 +385,16 @@ static void ExpandImpassableCells(Grid& grid, u16 clearance, pass_c } } - for (u16 i = 0; i < w; ++i) + for (std::uint16_t i = 0; i < w; ++i) { // New cell (i,j) is blocked if (i,j') blocked for any j-clearance <= j' <= j+clearance // Count the number of blocked cells around j=0 - u16 numBlocked = 0; - for (u16 j = 0; j <= clearance && j < h; ++j) + std::uint16_t numBlocked = 0; + for (std::uint16_t j = 0; j <= clearance && j < h; ++j) if (tempGrid.get(i, j)) ++numBlocked; - for (u16 j = 0; j < h; ++j) + for (std::uint16_t j = 0; j < h; ++j) { // Add the mask if blocked by at least one nearby cell if (numBlocked) @@ -410,7 +411,7 @@ static void ExpandImpassableCells(Grid& grid, u16 clearance, pass_c } } -Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) +Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) { PROFILE3("ComputeShoreGrid"); @@ -420,15 +421,15 @@ Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) CTerrain& terrain = GetSimContext().GetTerrain(); // avoid integer overflow in intermediate calculation - const u16 shoreMax = 32767; + const std::uint16_t shoreMax = 32767; - u16 shoreGridSize = terrain.GetTilesPerSide(); + std::uint16_t shoreGridSize = terrain.GetTilesPerSide(); // First pass - find underwater tiles Grid waterGrid(shoreGridSize, shoreGridSize); - for (u16 j = 0; j < shoreGridSize; ++j) + for (std::uint16_t j = 0; j < shoreGridSize; ++j) { - for (u16 i = 0; i < shoreGridSize; ++i) + for (std::uint16_t i = 0; i < shoreGridSize; ++i) { fixed x, z; Pathfinding::TerrainTileCenter(i, j, x, z); @@ -439,10 +440,10 @@ Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) } // Second pass - find shore tiles - Grid shoreGrid(shoreGridSize, shoreGridSize); - for (u16 j = 0; j < shoreGridSize; ++j) + Grid shoreGrid(shoreGridSize, shoreGridSize); + for (std::uint16_t j = 0; j < shoreGridSize; ++j) { - for (u16 i = 0; i < shoreGridSize; ++i) + for (std::uint16_t i = 0; i < shoreGridSize; ++i) { // Find a land tile if (!waterGrid.get(i, j)) @@ -463,14 +464,14 @@ Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) } // Expand influences on land to find shore distance - for (u16 y = 0; y < shoreGridSize; ++y) + for (std::uint16_t y = 0; y < shoreGridSize; ++y) { - u16 min = shoreMax; - for (u16 x = 0; x < shoreGridSize; ++x) + std::uint16_t min = shoreMax; + for (std::uint16_t x = 0; x < shoreGridSize; ++x) { if (!waterGrid.get(x, y) || expandOnWater) { - u16 g = shoreGrid.get(x, y); + std::uint16_t g = shoreGrid.get(x, y); if (g > min) shoreGrid.set(x, y, min); else if (g < min) @@ -479,11 +480,11 @@ Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) ++min; } } - for (u16 x = shoreGridSize; x > 0; --x) + for (std::uint16_t x = shoreGridSize; x > 0; --x) { if (!waterGrid.get(x-1, y) || expandOnWater) { - u16 g = shoreGrid.get(x-1, y); + std::uint16_t g = shoreGrid.get(x-1, y); if (g > min) shoreGrid.set(x-1, y, min); else if (g < min) @@ -493,14 +494,14 @@ Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) } } } - for (u16 x = 0; x < shoreGridSize; ++x) + for (std::uint16_t x = 0; x < shoreGridSize; ++x) { - u16 min = shoreMax; - for (u16 y = 0; y < shoreGridSize; ++y) + std::uint16_t min = shoreMax; + for (std::uint16_t y = 0; y < shoreGridSize; ++y) { if (!waterGrid.get(x, y) || expandOnWater) { - u16 g = shoreGrid.get(x, y); + std::uint16_t g = shoreGrid.get(x, y); if (g > min) shoreGrid.set(x, y, min); else if (g < min) @@ -509,11 +510,11 @@ Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) ++min; } } - for (u16 y = shoreGridSize; y > 0; --y) + for (std::uint16_t y = shoreGridSize; y > 0; --y) { if (!waterGrid.get(x, y-1) || expandOnWater) { - u16 g = shoreGrid.get(x, y-1); + std::uint16_t g = shoreGrid.get(x, y-1); if (g > min) shoreGrid.set(x, y-1, min); else if (g < min) @@ -535,7 +536,7 @@ void CCmpPathfinder::UpdateGrid() if (!cmpTerrain) return; // error - u16 gridSize = cmpTerrain->GetMapSize() / Pathfinding::NAVCELL_SIZE_INT; + std::uint16_t gridSize = cmpTerrain->GetMapSize() / Pathfinding::NAVCELL_SIZE_INT; if (gridSize == 0) return; @@ -593,8 +594,8 @@ void CCmpPathfinder::UpdateGrid() { ENSURE(m_Grid->compare_sizes(m_TerrainOnlyGrid)); - for (u16 j = 0; j < m_DirtinessInformation.dirtinessGrid.m_H; ++j) - for (u16 i = 0; i < m_DirtinessInformation.dirtinessGrid.m_W; ++i) + for (std::uint16_t j = 0; j < m_DirtinessInformation.dirtinessGrid.m_H; ++j) + for (std::uint16_t i = 0; i < m_DirtinessInformation.dirtinessGrid.m_W; ++i) if (m_DirtinessInformation.dirtinessGrid.get(i, j) == 1) m_Grid->set(i, j, m_TerrainOnlyGrid->get(i, j)); } @@ -637,7 +638,7 @@ void CCmpPathfinder::TerrainUpdateHelper(bool expandPassability, int itile0, int if (!cmpTerrain || !cmpObstructionManager) return; - u16 gridSize = cmpTerrain->GetMapSize() / Pathfinding::NAVCELL_SIZE_INT; + std::uint16_t gridSize = cmpTerrain->GetMapSize() / Pathfinding::NAVCELL_SIZE_INT; if (gridSize == 0) return; @@ -660,7 +661,7 @@ void CCmpPathfinder::TerrainUpdateHelper(bool expandPassability, int itile0, int } } - Grid shoreGrid = ComputeShoreGrid(); + Grid shoreGrid = ComputeShoreGrid(); const bool partialTerrainGridUpdate = !expandPassability && !needsNewTerrainGrid && @@ -749,17 +750,17 @@ void CCmpPathfinder::TerrainUpdateHelper(bool expandPassability, int itile0, int } else { - for (u16 j = 0; j < h; ++j) - for (u16 i = 0; i < edgeSize; ++i) + for (std::uint16_t j = 0; j < h; ++j) + for (std::uint16_t i = 0; i < edgeSize; ++i) m_TerrainOnlyGrid->set(i, j, m_TerrainOnlyGrid->get(i, j) | edgeMask); - for (u16 j = 0; j < h; ++j) - for (u16 i = w-edgeSize+1; i < w; ++i) + for (std::uint16_t j = 0; j < h; ++j) + for (std::uint16_t i = w-edgeSize+1; i < w; ++i) m_TerrainOnlyGrid->set(i, j, m_TerrainOnlyGrid->get(i, j) | edgeMask); - for (u16 j = 0; j < edgeSize; ++j) - for (u16 i = edgeSize; i < w-edgeSize+1; ++i) + for (std::uint16_t j = 0; j < edgeSize; ++j) + for (std::uint16_t i = edgeSize; i < w-edgeSize+1; ++i) m_TerrainOnlyGrid->set(i, j, m_TerrainOnlyGrid->get(i, j) | edgeMask); - for (u16 j = h-edgeSize+1; j < h; ++j) - for (u16 i = edgeSize; i < w-edgeSize+1; ++i) + for (std::uint16_t j = h-edgeSize+1; j < h; ++j) + for (std::uint16_t i = edgeSize; i < w-edgeSize+1; ++i) m_TerrainOnlyGrid->set(i, j, m_TerrainOnlyGrid->get(i, j) | edgeMask); } @@ -898,7 +899,7 @@ bool CCmpPathfinder::IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const Pat { PROFILE2("IsGoalReachable"); - u16 i, j; + std::uint16_t i, j; Pathfinding::NearestNavcell(x0, z0, i, j, m_GridSize, m_GridSize); if (!IS_PASSABLE(m_Grid->get(i, j), passClass)) m_PathfinderHier->FindNearestPassableNavcell(i, j, passClass); @@ -1017,7 +1018,7 @@ ICmpObstruction::EFoundationCheck CCmpPathfinder::CheckUnitPlacement(const IObst // Test against terrain and static obstructions: - u16 i, j; + std::uint16_t i, j; Pathfinding::NearestNavcell(x, z, i, j, m_GridSize, m_GridSize); if (!IS_PASSABLE(m_Grid->get(i, j), passClass)) return ICmpObstruction::FOUNDATION_CHECK_FAIL_TERRAIN_CLASS; diff --git a/source/simulation2/components/CCmpPathfinder_Common.h b/source/simulation2/components/CCmpPathfinder_Common.h index 31dfe8dfdf..73f90ae007 100644 --- a/source/simulation2/components/CCmpPathfinder_Common.h +++ b/source/simulation2/components/CCmpPathfinder_Common.h @@ -82,13 +82,13 @@ public: std::map m_PassClassMasks; std::vector m_PassClasses; - u16 m_MaxSameTurnMoves; // Compute only this many paths when useMax is true in StartProcessingMoves. + std::uint16_t m_MaxSameTurnMoves; // Compute only this many paths when useMax is true in StartProcessingMoves. // Dynamic state: // Lazily-constructed dynamic state (not serialized): - u16 m_GridSize; // Navcells per side of the map. + std::uint16_t m_GridSize; // Navcells per side of the map. Grid* m_Grid; // terrain/passability information Grid* m_TerrainOnlyGrid; // same as m_Grid, but only with terrain, to avoid some recomputations @@ -128,7 +128,7 @@ public: /** * @param max - if non-zero, how many paths to process. */ - void PrepareForComputation(u16 max) + void PrepareForComputation(std::uint16_t max) { size_t n = m_Requests.size(); if (max && n > max) @@ -208,7 +208,7 @@ public: m_AIPathfinderDirtinessInformation.Clean(); } - Grid ComputeShoreGrid(bool expandOnWater = false) override; + Grid ComputeShoreGrid(bool expandOnWater = false) override; void ComputePathImmediate(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) const override; diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index b0725e96d3..41d9c35378 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -128,12 +128,12 @@ u32 CalcSharedLosMask(std::vector players) * Add/remove a player to/from mask, which is a 1-bit mask representing a list of players. * Returns true if the mask is modified. */ -bool SetPlayerSharedDirtyVisibilityBit(u16& mask, player_id_t player, bool enable) +bool SetPlayerSharedDirtyVisibilityBit(std::uint16_t& mask, player_id_t player, bool enable) { if (player <= 0 || player > 16) return false; - u16 oldMask = mask; + std::uint16_t oldMask = mask; if (enable) mask |= (0x1 << (player - 1)); @@ -156,7 +156,7 @@ LosVisibility GetPlayerVisibility(u32 visibilities, player_id_t player) /** * Test whether the visibility is dirty for a given LoS region and a given player */ -bool IsVisibilityDirty(u16 dirty, player_id_t player) +bool IsVisibilityDirty(std::uint16_t dirty, player_id_t player) { if (player > 0 && player <= 16) return (dirty >> (player - 1)) & 0x1; @@ -166,7 +166,7 @@ bool IsVisibilityDirty(u16 dirty, player_id_t player) /** * Test whether a player share this vision */ -bool HasVisionSharing(u16 visionSharing, player_id_t player) +bool HasVisionSharing(std::uint16_t visionSharing, player_id_t player) { return (visionSharing & (1 << (player - 1))) != 0; } @@ -174,7 +174,7 @@ bool HasVisionSharing(u16 visionSharing, player_id_t player) /** * Computes the shared vision mask for the player */ -u16 CalcVisionSharingMask(player_id_t player) +std::uint16_t CalcVisionSharingMask(player_id_t player) { return 1 << (player-1); } @@ -264,7 +264,7 @@ struct EntityData entity_pos_t visionRange; u32 visibilities; // 2-bit visibility, per player u32 size; - u16 visionSharing; // 1-bit per player + std::uint16_t visionSharing; // 1-bit per player std::int8_t owner; std::uint8_t flags; // See the FlagMasks enum @@ -462,7 +462,7 @@ public: // LOS state: static const player_id_t MAX_LOS_PLAYER_ID = 16; - using LosRegion = std::pair; + using LosRegion = std::pair; std::array m_LosRevealWholeMap; bool m_LosRevealWholeMapForAll; @@ -473,17 +473,17 @@ public: std::int32_t m_LosRegionsPerSide; bool m_GlobalVisibilityUpdate; std::array m_GlobalPlayerVisibilityUpdate; - Grid m_DirtyVisibility; + Grid m_DirtyVisibility; Grid> m_LosRegions; // List of entities that must be updated, regardless of the status of their tile std::vector m_ModifiedEntities; // Counts of units seeing vertex, per vertex, per player (starting with player 0). - // Use u16 to avoid overflows when we have very large (but not infeasibly large) numbers + // Use std::uint16_t to avoid overflows when we have very large (but not infeasibly large) numbers // of units in a very small area. // (Note we use vertexes, not tiles, to better match the renderer.) // Lazily constructed when it's needed, to save memory in smaller games. - std::array, MAX_LOS_PLAYER_ID> m_LosPlayerCounts; + std::array, MAX_LOS_PLAYER_ID> m_LosPlayerCounts; // 2-bit LosState per player, starting with player 1 (not 0!) up to player MAX_LOS_PLAYER_ID (inclusive) Grid m_LosState; @@ -495,7 +495,7 @@ public: // Shared LOS masks, one per player. std::array m_SharedLosMasks; // Shared dirty visibility masks, one per player. - std::array m_SharedDirtyVisibilityMasks; + std::array m_SharedDirtyVisibilityMasks; // Cache explored vertices per player (not serialized) u32 m_TotalInworldVertices; @@ -811,7 +811,7 @@ public: break; ENSURE(msgData.player > 0 && msgData.player < MAX_LOS_PLAYER_ID+1); - u16 visionChanged = CalcVisionSharingMask(msgData.player); + std::uint16_t visionChanged = CalcVisionSharingMask(msgData.player); if (!it->second.HasFlag()) { @@ -876,7 +876,7 @@ public: // Check that calling ResetDerivedData (i.e. recomputing all the state from scratch) // does not affect the incrementally-computed state - std::array, MAX_LOS_PLAYER_ID> oldPlayerCounts = m_LosPlayerCounts; + std::array, MAX_LOS_PLAYER_ID> oldPlayerCounts = m_LosPlayerCounts; Grid oldStateRevealed = m_LosStateRevealed; FastSpatialSubdivision oldSubdivision = m_Subdivision; Grid > oldLosRegions = m_LosRegions; @@ -2030,7 +2030,7 @@ public: return m_LosVerticesPerSide; } - LosRegion LosVertexToLosRegionsHelper(u16 x, u16 z) const + LosRegion LosVertexToLosRegionsHelper(std::uint16_t x, std::uint16_t z) const { return LosRegion { Clamp(x/LOS_REGION_RATIO, 0, m_LosRegionsPerSide - 1), @@ -2040,11 +2040,11 @@ public: LosRegion PosToLosRegionsHelper(entity_pos_t x, entity_pos_t z) const { - u16 i = Clamp( + std::uint16_t i = Clamp( (x/(LOS_TILE_SIZE*LOS_REGION_RATIO)).ToInt_RoundToZero(), 0, m_LosRegionsPerSide - 1); - u16 j = Clamp( + std::uint16_t j = Clamp( (z/(LOS_TILE_SIZE*LOS_REGION_RATIO)).ToInt_RoundToZero(), 0, m_LosRegionsPerSide - 1); @@ -2067,8 +2067,8 @@ public: { PROFILE("UpdateVisibilityData"); - for (u16 i = 0; i < m_LosRegionsPerSide; ++i) - for (u16 j = 0; j < m_LosRegionsPerSide; ++j) + for (std::uint16_t i = 0; i < m_LosRegionsPerSide; ++i) + for (std::uint16_t j = 0; j < m_LosRegionsPerSide; ++j) { LosRegion pos{i, j}; for (player_id_t player = 1; player < MAX_LOS_PLAYER_ID + 1; ++player) @@ -2347,19 +2347,19 @@ public: return; // Maximum distance to the shore - const u16 maxdist = 10; + const std::uint16_t maxdist = 10; CmpPtr cmpPathfinder(GetSystemEntity()); - const Grid& shoreGrid = cmpPathfinder->ComputeShoreGrid(true); + const Grid& shoreGrid = cmpPathfinder->ComputeShoreGrid(true); ENSURE(shoreGrid.m_W == m_LosVerticesPerSide-1 && shoreGrid.m_H == m_LosVerticesPerSide-1); - Grid& counts = m_LosPlayerCounts.at(p); + Grid& counts = m_LosPlayerCounts.at(p); ENSURE(!counts.blank()); - for (u16 j = 0; j < shoreGrid.m_H; ++j) - for (u16 i = 0; i < shoreGrid.m_W; ++i) + for (std::uint16_t j = 0; j < shoreGrid.m_H; ++j) + for (std::uint16_t i = 0; i < shoreGrid.m_W; ++i) { - u16 shoredist = shoreGrid.get(i, j); + std::uint16_t shoredist = shoreGrid.get(i, j); if (shoredist > maxdist) continue; @@ -2403,7 +2403,8 @@ public: /** * Update the LOS state of tiles within a given horizontal strip (i0,j) to (i1,j) (inclusive). */ - inline void LosAddStripHelper(std::uint8_t owner, std::int32_t i0, std::int32_t i1, std::int32_t j, Grid& counts) + inline void LosAddStripHelper(std::uint8_t owner, std::int32_t i0, std::int32_t i1, std::int32_t j, + Grid& counts) { if (i1 < i0) return; @@ -2423,8 +2424,8 @@ public: MarkVisibilityDirtyAroundTile(owner, i, j); } - ENSURE(counts.get(i, j) < std::numeric_limits::max()); - counts.get(i, j) = (u16)(counts.get(i, j) + 1); // ignore overflow; the player should never have 64K units + ENSURE(counts.get(i, j) < std::numeric_limits::max()); + counts.get(i, j) = static_cast(counts.get(i, j) + 1); // ignore overflow; the player should never have 64K units } } @@ -2432,7 +2433,7 @@ public: * Update the LOS state of tiles within a given horizontal strip (i0,j) to (i1,j) (inclusive). */ inline void LosRemoveStripHelper(std::uint8_t owner, std::int32_t i0, std::int32_t i1, std::int32_t j, - Grid& counts) + Grid& counts) { if (i1 < i0) return; @@ -2440,7 +2441,7 @@ public: 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); + counts.get(i, j) = static_cast(counts.get(i, j) - 1); // Decreasing from non-zero to zero - move from visible+explored to explored if (counts.get(i, j) == 0) @@ -2466,7 +2467,7 @@ public: LosRegion n3 = LosVertexToLosRegionsHelper(i, j-1); LosRegion n4 = LosVertexToLosRegionsHelper(i, j); - u16 sharedDirtyVisibilityMask = m_SharedDirtyVisibilityMasks[owner]; + std::uint16_t sharedDirtyVisibilityMask = m_SharedDirtyVisibilityMasks[owner]; if (j > 0 && i > 0) m_DirtyVisibility[n1] |= sharedDirtyVisibilityMask; @@ -2491,7 +2492,7 @@ public: PROFILE("LosUpdateHelper"); - Grid& counts = m_LosPlayerCounts.at(owner); + Grid& counts = m_LosPlayerCounts.at(owner); // Lazy initialisation of counts: if (counts.blank()) @@ -2578,7 +2579,7 @@ public: PROFILE("LosUpdateHelperIncremental"); - Grid& counts = m_LosPlayerCounts.at(owner); + Grid& counts = m_LosPlayerCounts.at(owner); // Lazy initialisation of counts: if (counts.blank()) @@ -2702,7 +2703,7 @@ public: LosUpdateHelper(static_cast(owner), visionRange, pos); } - void SharingLosAdd(u16 visionSharing, entity_pos_t visionRange, CFixedVector2D pos) + void SharingLosAdd(std::uint16_t visionSharing, entity_pos_t visionRange, CFixedVector2D pos) { if (visionRange.IsZero()) return; @@ -2720,7 +2721,7 @@ public: LosUpdateHelper(static_cast(owner), visionRange, pos); } - void SharingLosRemove(u16 visionSharing, entity_pos_t visionRange, CFixedVector2D pos) + void SharingLosRemove(std::uint16_t visionSharing, entity_pos_t visionRange, CFixedVector2D pos) { if (visionRange.IsZero()) return; @@ -2746,7 +2747,7 @@ public: LosUpdateHelperIncremental(static_cast(owner), visionRange, from, to); } - void SharingLosMove(u16 visionSharing, entity_pos_t visionRange, CFixedVector2D from, CFixedVector2D to) + void SharingLosMove(std::uint16_t visionSharing, entity_pos_t visionRange, CFixedVector2D from, CFixedVector2D to) { if (visionRange.IsZero()) return; diff --git a/source/simulation2/components/CCmpTerrain.cpp b/source/simulation2/components/CCmpTerrain.cpp index d5a9e08995..7d39735249 100644 --- a/source/simulation2/components/CCmpTerrain.cpp +++ b/source/simulation2/components/CCmpTerrain.cpp @@ -100,14 +100,14 @@ public: return m_Terrain->GetExactGroundLevel(x, z); } - u16 GetTilesPerSide() const override + std::uint16_t GetTilesPerSide() const override { ssize_t tiles = m_Terrain->GetTilesPerSide(); if (tiles == -1) return 0; ENSURE(1 <= tiles && tiles <= 65535); - return (u16)tiles; + return static_cast(tiles); } u32 GetMapSize() const override @@ -115,11 +115,11 @@ public: return GetTilesPerSide() * TERRAIN_TILE_SIZE; } - u16 GetVerticesPerSide() const override + std::uint16_t GetVerticesPerSide() const override { ssize_t vertices = m_Terrain->GetVerticesPerSide(); ENSURE(1 <= vertices && vertices <= 65535); - return (u16)vertices; + return static_cast(vertices); } CTerrain* GetCTerrain() override @@ -131,8 +131,8 @@ public: { // TODO: should refactor this code to be nicer - u16 tiles = GetTilesPerSide(); - u16 vertices = GetVerticesPerSide(); + std::uint16_t tiles = GetTilesPerSide(); + std::uint16_t vertices = GetVerticesPerSide(); CmpPtr cmpObstructionManager(GetSystemEntity()); if (cmpObstructionManager) diff --git a/source/simulation2/components/CCmpTerritoryInfluence.cpp b/source/simulation2/components/CCmpTerritoryInfluence.cpp index 9f40b17787..745fd01568 100644 --- a/source/simulation2/components/CCmpTerritoryInfluence.cpp +++ b/source/simulation2/components/CCmpTerritoryInfluence.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 @@ -35,7 +35,7 @@ public: DEFAULT_COMPONENT_ALLOCATOR(TerritoryInfluence) bool m_Root; - u16 m_Weight; + std::uint16_t m_Weight; u32 m_Radius; static std::string GetSchema() @@ -46,7 +46,7 @@ public: "" "" "" - "65535" // Max u16 value + "65535" // Max std::uint16_t value "" "" "" @@ -57,7 +57,7 @@ public: void Init(const CParamNode& paramNode) override { m_Root = paramNode.GetChild("Root").ToBool(); - m_Weight = (u16)paramNode.GetChild("Weight").ToInt(); + m_Weight = static_cast(paramNode.GetChild("Weight").ToInt()); m_Radius = paramNode.GetChild("Radius").ToInt(); } @@ -83,7 +83,7 @@ public: return cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Root", m_Root, GetEntityId()); } - u16 GetWeight() const override + std::uint16_t GetWeight() const override { CmpPtr cmpValueModificationManager(GetSystemEntity()); if (!cmpValueModificationManager) diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index 919b8fbb83..a157d2f088 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/source/simulation2/components/CCmpTerritoryManager.cpp @@ -122,8 +122,8 @@ public: // processed flag in bit 7 (TERRITORY_PROCESSED_MASK) Grid* m_Territories; - std::vector m_TerritoryCellCounts; - u16 m_TerritoryTotalPassableCellCount; + std::vector m_TerritoryCellCounts; + std::uint16_t m_TerritoryTotalPassableCellCount; // Saves the cost per tile (to stop territory on impassable tiles) Grid* m_CostGrid; @@ -367,8 +367,8 @@ REGISTER_COMPONENT_TYPE(TerritoryManager) // Tile data type, for easier accessing of coordinates struct Tile { - Tile(u16 i, u16 j) : x(i), z(j) { } - u16 x, z; + Tile(std::uint16_t i, std::uint16_t j) : x(i), z(j) { } + std::uint16_t x, z; }; /** @@ -409,8 +409,9 @@ void Floodfill(const Tile& origin, const Tile& gridSize, Decider decider) openTiles.pop(); for (const std::array& neighbour : neighbours) { - const Tile neighbourTile{static_cast(currentTile.x + std::get<0>(neighbour)), - static_cast(currentTile.z + std::get<1>(neighbour))}; + const Tile neighbourTile{ + static_cast(currentTile.x + std::get<0>(neighbour)), + static_cast(currentTile.z + std::get<1>(neighbour))}; // Check the bounds, underflow will cause the values to be big again. if (neighbourTile.x < gridSize.x && neighbourTile.z < gridSize.z) @@ -422,7 +423,8 @@ void Floodfill(const Tile& origin, const Tile& gridSize, Decider decider) /** * Compute the tile indexes on the grid nearest to a given point */ -static void NearestTerritoryTile(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u16 h) +static void NearestTerritoryTile(entity_pos_t x, entity_pos_t z, std::uint16_t& i, std::uint16_t& j, + std::uint16_t w, std::uint16_t h) { entity_pos_t scale = Pathfinding::NAVCELL_SIZE * ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE; i = Clamp((x / scale).ToInt_RoundToNegInfinity(), 0, w - 1); @@ -454,8 +456,8 @@ void CCmpTerritoryManager::CalculateCostGrid() for (int j = 0; j < tilesH; ++j) { NavcellData c = 0; - for (u16 di = 0; di < NAVCELLS_PER_TERRITORY_TILE; ++di) - for (u16 dj = 0; dj < NAVCELLS_PER_TERRITORY_TILE; ++dj) + for (std::uint16_t di = 0; di < NAVCELLS_PER_TERRITORY_TILE; ++di) + for (std::uint16_t dj = 0; dj < NAVCELLS_PER_TERRITORY_TILE; ++dj) c |= passGrid.get( i * NAVCELLS_PER_TERRITORY_TILE + di, j * NAVCELLS_PER_TERRITORY_TILE + dj); @@ -485,8 +487,8 @@ void CCmpTerritoryManager::CalculateTerritories() if (!m_CostGrid) return; - const u16 tilesW = m_CostGrid->m_W; - const u16 tilesH = m_CostGrid->m_H; + const std::uint16_t tilesW = m_CostGrid->m_W; + const std::uint16_t tilesH = m_CostGrid->m_H; m_Territories = new Grid(tilesW, tilesH); @@ -494,7 +496,7 @@ void CCmpTerritoryManager::CalculateTerritories() CmpPtr cmpPlayerManager(GetSystemEntity()); if (cmpPlayerManager && (size_t)cmpPlayerManager->GetNumPlayers() != m_TerritoryCellCounts.size()) m_TerritoryCellCounts.resize(cmpPlayerManager->GetNumPlayers()); - for (u16& count : m_TerritoryCellCounts) + for (std::uint16_t& count : m_TerritoryCellCounts) count = 0; // Find all territory influence entities @@ -551,7 +553,7 @@ void CCmpTerritoryManager::CalculateTerritories() .ToInt_RoundToNegInfinity() / radius; CFixedVector2D pos = cmpPosition->GetPosition2D(); - u16 i, j; + std::uint16_t i, j; NearestTerritoryTile(pos.X, pos.Y, i, j, tilesW, tilesH); if (cmpTerritoryInfluence->IsRoot()) @@ -608,7 +610,7 @@ void CCmpTerritoryManager::CalculateTerritories() CmpPtr cmpPosition(GetSimContext(), ent); CFixedVector2D pos = cmpPosition->GetPosition2D(); - u16 i, j; + std::uint16_t i, j; NearestTerritoryTile(pos.X, pos.Y, i, j, tilesW, tilesH); std::uint8_t owner = static_cast(cmpOwnership->GetOwner()); @@ -780,7 +782,7 @@ void CCmpTerritoryManager::RenderSubmit(SceneCollector& collector, const CFrustu player_id_t CCmpTerritoryManager::GetOwner(entity_pos_t x, entity_pos_t z) { - u16 i, j; + std::uint16_t i, j; if (!m_Territories) { CalculateTerritories(); @@ -803,14 +805,14 @@ std::vector CCmpTerritoryManager::GetNeighbours(entity_pos_t x, entity_pos_ if (!m_Territories) return ret; - u16 i, j; + std::uint16_t i, j; NearestTerritoryTile(x, z, i, j, m_Territories->m_W, m_Territories->m_H); // calculate the neighbours player_id_t thisOwner = m_Territories->get(i, j) & TERRITORY_PLAYER_MASK; - u16 tilesW = m_Territories->m_W; - u16 tilesH = m_Territories->m_H; + std::uint16_t tilesW = m_Territories->m_W; + std::uint16_t tilesH = m_Territories->m_H; // use a flood-fill algorithm that fills up to the borders and remembers the owners Grid markerGrid(tilesW, tilesH); @@ -836,7 +838,7 @@ std::vector CCmpTerritoryManager::GetNeighbours(entity_pos_t x, entity_pos_ bool CCmpTerritoryManager::IsConnected(entity_pos_t x, entity_pos_t z) { - u16 i, j; + std::uint16_t i, j; CalculateTerritories(); if (!m_Territories) return false; @@ -851,11 +853,11 @@ void CCmpTerritoryManager::SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, if (!m_Territories) return; - u16 i, j; + std::uint16_t i, j; NearestTerritoryTile(x, z, i, j, m_Territories->m_W, m_Territories->m_H); - u16 tilesW = m_Territories->m_W; - u16 tilesH = m_Territories->m_H; + std::uint16_t tilesW = m_Territories->m_W; + std::uint16_t tilesH = m_Territories->m_H; player_id_t thisOwner = m_Territories->get(i, j) & TERRITORY_PLAYER_MASK; @@ -883,7 +885,7 @@ bool CCmpTerritoryManager::IsTerritoryBlinking(entity_pos_t x, entity_pos_t z) if (!m_Territories) return false; - u16 i, j; + std::uint16_t i, j; NearestTerritoryTile(x, z, i, j, m_Territories->m_W, m_Territories->m_H); return (m_Territories->get(i, j) & TERRITORY_BLINKING_MASK) != 0; } diff --git a/source/simulation2/components/CCmpUnitMotion_System.cpp b/source/simulation2/components/CCmpUnitMotion_System.cpp index 6c6013a403..7c2c51a93e 100644 --- a/source/simulation2/components/CCmpUnitMotion_System.cpp +++ b/source/simulation2/components/CCmpUnitMotion_System.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 @@ -384,7 +384,7 @@ void CCmpUnitMotionManager::ResetSubdivisions() return; size_t size = cmpTerrain->GetMapSize(); - u16 gridSquareSize = static_cast(size / PUSHING_GRID_SIZE + 1); + std::uint16_t gridSquareSize = static_cast(size / PUSHING_GRID_SIZE + 1); m_MovingUnits.resize(gridSquareSize, gridSquareSize); } diff --git a/source/simulation2/components/ICmpObstructionManager.h b/source/simulation2/components/ICmpObstructionManager.h index 2d13f8803e..4381f49d4b 100644 --- a/source/simulation2/components/ICmpObstructionManager.h +++ b/source/simulation2/components/ICmpObstructionManager.h @@ -35,7 +35,7 @@ class PathfinderPassability; struct GridUpdateInformation; template class Grid; -using NavcellData = u16; +using NavcellData = std::uint16_t; /** * Obstruction manager: provides efficient spatial queries over objects in the world. diff --git a/source/simulation2/components/ICmpPathfinder.h b/source/simulation2/components/ICmpPathfinder.h index 24db77aff0..3899a476d1 100644 --- a/source/simulation2/components/ICmpPathfinder.h +++ b/source/simulation2/components/ICmpPathfinder.h @@ -100,7 +100,7 @@ public: /** * Get a grid representing the distance to the shore of the terrain tile. */ - virtual Grid ComputeShoreGrid(bool expandOnWater = false) = 0; + virtual Grid ComputeShoreGrid(bool expandOnWater = false) = 0; /** * Asynchronous version of ComputePath. diff --git a/source/simulation2/components/ICmpTerrain.h b/source/simulation2/components/ICmpTerrain.h index d24295543b..b50d39c03c 100644 --- a/source/simulation2/components/ICmpTerrain.h +++ b/source/simulation2/components/ICmpTerrain.h @@ -46,13 +46,13 @@ public: * Returns number of tiles per side on the terrain. * Return value is always non-zero. */ - virtual u16 GetTilesPerSide() const = 0; + virtual std::uint16_t GetTilesPerSide() const = 0; /** * Returns number of vertices per side on the terrain. * Return value is always non-zero. */ - virtual u16 GetVerticesPerSide() const = 0; + virtual std::uint16_t GetVerticesPerSide() const = 0; /** * Returns the map size in metres (world space units). diff --git a/source/simulation2/components/ICmpTerritoryInfluence.h b/source/simulation2/components/ICmpTerritoryInfluence.h index 68b58c3e1a..ec1aafb9c3 100644 --- a/source/simulation2/components/ICmpTerritoryInfluence.h +++ b/source/simulation2/components/ICmpTerritoryInfluence.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 @@ -29,7 +29,7 @@ class ICmpTerritoryInfluence : public IComponent public: virtual bool IsRoot() const = 0; - virtual u16 GetWeight() const = 0; + virtual std::uint16_t GetWeight() const = 0; virtual u32 GetRadius() const = 0; diff --git a/source/simulation2/components/ICmpValueModificationManager.cpp b/source/simulation2/components/ICmpValueModificationManager.cpp index 051aee3236..20f10aa43f 100644 --- a/source/simulation2/components/ICmpValueModificationManager.cpp +++ b/source/simulation2/components/ICmpValueModificationManager.cpp @@ -40,9 +40,9 @@ public: return m_Script.Call("ApplyModifications", valueName, currentValue, entity); } - u16 ApplyModifications(std::wstring valueName, u16 currentValue, entity_id_t entity) const override + std::uint16_t ApplyModifications(std::wstring valueName, std::uint16_t currentValue, entity_id_t entity) const override { - return m_Script.Call("ApplyModifications", valueName, currentValue, entity); + return m_Script.Call("ApplyModifications", valueName, currentValue, entity); } std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity) const override diff --git a/source/simulation2/components/ICmpValueModificationManager.h b/source/simulation2/components/ICmpValueModificationManager.h index e03af6d4c3..0d82ba7ab9 100644 --- a/source/simulation2/components/ICmpValueModificationManager.h +++ b/source/simulation2/components/ICmpValueModificationManager.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 @@ -37,7 +37,8 @@ class ICmpValueModificationManager : public IComponent public: virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) const = 0; virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) const = 0; - virtual u16 ApplyModifications(std::wstring valueName, u16 currentValue, entity_id_t entity) const = 0; + virtual std::uint16_t ApplyModifications(std::wstring valueName, std::uint16_t currentValue, + entity_id_t entity) const = 0; virtual std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity) const = 0; virtual bool ApplyModifications(std::wstring valueName, bool currentValue, entity_id_t entity) const = 0; diff --git a/source/simulation2/components/tests/test_HierPathfinder.h b/source/simulation2/components/tests/test_HierPathfinder.h index 8831d21718..852abac23e 100644 --- a/source/simulation2/components/tests/test_HierPathfinder.h +++ b/source/simulation2/components/tests/test_HierPathfinder.h @@ -17,7 +17,6 @@ #include "lib/self_test.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "simulation2/helpers/Grid.h" #include "simulation2/helpers/PathGoal.h" @@ -49,7 +48,7 @@ public: const pass_class_t PASS_2 = 2; const pass_class_t NON_PASS_1 = 4; - const u16 mapSize = 240; + const std::uint16_t mapSize = 240; std::map pathClassMask; std::map nonPathClassMask; @@ -64,7 +63,8 @@ public: } } - void debug_grid_points(Grid& grid, u16 i1, u16 j1, u16 i2, u16 j2) + void debug_grid_points(Grid& grid, std::uint16_t i1, std::uint16_t j1, std::uint16_t i2, + std::uint16_t j2) { for (size_t i = 0; i < grid.m_W; ++i) { @@ -85,15 +85,15 @@ public: { // test that the map has the same global region everywhere HierarchicalPathfinder::GlobalRegionID globalRegionID = hierPath.GetGlobalRegion(35, 23, PASS_1); - for (u16 i = 0; i < mapSize; ++i) - for (u16 j = 0; j < mapSize; ++j) + for (std::uint16_t i = 0; i < mapSize; ++i) + for (std::uint16_t j = 0; j < mapSize; ++j) { TS_ASSERT(globalRegionID == hierPath.GetGlobalRegion(i, j, PASS_1)); TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); } - u16 i = 89; - u16 j = 34; + std::uint16_t i = 89; + std::uint16_t j = 34; hierPath.FindNearestPassableNavcell(i, j, PASS_1); TS_ASSERT(i == 89 && j == 34); @@ -138,7 +138,7 @@ public: ////////////////////////////////////////////////////// // Split the map in two in the middle. - for (u16 j = 0; j < mapSize; ++j) + for (std::uint16_t j = 0; j < mapSize; ++j) { grid.set(125, j, 7); dirtyGrid.set(125, j, 1); @@ -148,19 +148,19 @@ public: // Global region: check we are now split in two. TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) != hierPath.GetGlobalRegion(150, 50, PASS_1)); - for (u16 j = 0; j < mapSize; ++j) + for (std::uint16_t j = 0; j < mapSize; ++j) { TS_ASSERT(hierPath.Get(125, j, PASS_1).r == 0); TS_ASSERT(hierPath.GetGlobalRegion(125, j, PASS_1) == 0); } - for (u16 i = 0; i < 125; ++i) - for (u16 j = 0; j < mapSize; ++j) + for (std::uint16_t i = 0; i < 125; ++i) + for (std::uint16_t j = 0; j < mapSize; ++j) { TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); } - for (u16 i = 126; i < mapSize; ++i) - for (u16 j = 0; j < mapSize; ++j) + for (std::uint16_t i = 126; i < mapSize; ++i) + for (std::uint16_t j = 0; j < mapSize; ++j) { TS_ASSERT(hierPath.GetGlobalRegion(150, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); @@ -181,7 +181,7 @@ public: ////////////////////////////////////////////////////// // Un-split the map in two in the middle. - for (u16 j = 0; j < mapSize; ++j) + for (std::uint16_t j = 0; j < mapSize; ++j) { grid.set(125, j, 6); dirtyGrid.set(125, j, 1); @@ -191,7 +191,7 @@ public: ////////////////////////////////////////////////////// // Partial split in the middle chunk - no actual connectivity change - for (u16 j = 120; j < 150; ++j) + for (std::uint16_t j = 120; j < 150; ++j) { grid.set(125, j, 7); dirtyGrid.set(125, j, 1); @@ -204,7 +204,7 @@ public: ////////////////////////////////////////////////////// // Block a strip along the edge, but regions are still connected. - for (u16 j = 70; j < 200; ++j) + for (std::uint16_t j = 70; j < 200; ++j) { grid.set(96, j, 7); dirtyGrid.set(96, j, 1); @@ -219,7 +219,7 @@ public: ////////////////////////////////////////////////////// // Block the other edge - for (u16 j = 70; j < 200; ++j) + for (std::uint16_t j = 70; j < 200; ++j) { grid.set(192, j, 7); dirtyGrid.set(192, j, 1); @@ -234,17 +234,17 @@ public: ////////////////////////////////////////////////////// // Create an isolated region in the middle chunk - for (u16 i = 96; i < 140; ++i) + for (std::uint16_t i = 96; i < 140; ++i) { grid.set(i, 110, 7); dirtyGrid.set(i, 110, 1); } - for (u16 i = 96; i < 140; ++i) + for (std::uint16_t i = 96; i < 140; ++i) { grid.set(i, 140, 7); dirtyGrid.set(i, 140, 1); } - for (u16 j = 110; j < 141; ++j) + for (std::uint16_t j = 110; j < 141; ++j) { grid.set(140, j, 7); dirtyGrid.set(140, j, 1); @@ -266,7 +266,7 @@ public: ////////////////////////////////////////////////////// // Open it - for (u16 j = 110; j < 141; ++j) + for (std::uint16_t j = 110; j < 141; ++j) { grid.set(140, j, 6); dirtyGrid.set(140, j, 1); @@ -283,12 +283,12 @@ public: TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(120, 120, PASS_1)].size() == 2); } - u16 manhattan(u16 i, u16 j, u16 gi, u16 gj) + std::uint16_t manhattan(std::uint16_t i, std::uint16_t j, std::uint16_t gi, std::uint16_t gj) { return abs(i - gi) + abs(j - gj); } - double euclidian(u16 i, u16 j, u16 gi, u16 gj) + double euclidian(std::uint16_t i, std::uint16_t j, std::uint16_t gi, std::uint16_t gj) { return sqrt((i - gi) * (i - gi) + (j - gj) * (j - gj)); } @@ -366,7 +366,7 @@ public: hierPath.Recompute(&grid, nonPathClassMask, pathClassMask); - u16 i = 5, j = 5; + std::uint16_t i = 5, j = 5; hierPath.FindNearestPassableNavcell(i, j, PASS_1); TS_ASSERT(i == 5 && j == 5); @@ -386,7 +386,7 @@ public: TS_ASSERT(IS_PASSABLE(grid.get(pi, pj), PASS_1)); \ TS_ASSERT_EQUALS(manhattan(pi, pj, oi, oj), expected_manhattan); \ } - u16 oi, oj, pi, pj; + std::uint16_t oi, oj, pi, pj; check_closest_passable(4 * scale, 4 * scale, 1); check_closest_passable(4 * scale + 1, 4 * scale + 1, 2); diff --git a/source/simulation2/components/tests/test_Pathfinder.h b/source/simulation2/components/tests/test_Pathfinder.h index c6eae50d4a..ece244aa34 100644 --- a/source/simulation2/components/tests/test_Pathfinder.h +++ b/source/simulation2/components/tests/test_Pathfinder.h @@ -250,9 +250,9 @@ public: template void DumpGrid(std::ostream& stream, const Grid& grid, int mask) { - for (u16 j = 0; j < grid.m_H; ++j) + for (std::uint16_t j = 0; j < grid.m_H; ++j) { - for (u16 i = 0; i < grid.m_W; ) + for (std::uint16_t i = 0; i < grid.m_W; ) { if (!(grid.get(i, j) & mask)) { @@ -260,7 +260,7 @@ public: continue; } - u16 i0 = i; + std::uint16_t i0 = i; for (i = i0+1; ; ++i) { if (i >= grid.m_W || !(grid.get(i, j) & mask)) diff --git a/source/simulation2/components/tests/test_TerritoryManager.h b/source/simulation2/components/tests/test_TerritoryManager.h index ff47efe159..ecec411acb 100644 --- a/source/simulation2/components/tests/test_TerritoryManager.h +++ b/source/simulation2/components/tests/test_TerritoryManager.h @@ -74,7 +74,7 @@ public: entity_pos_t GetMaximumClearance() const override { return entity_pos_t::FromInt(1); } const GridUpdateInformation& GetAIPathfinderDirtinessInformation() const override { static GridUpdateInformation gridInfo; return gridInfo; } void FlushAIPathfinderDirtinessInformation() override {} - Grid ComputeShoreGrid(bool = false) override { return Grid {}; } + Grid ComputeShoreGrid(bool = false) override { return Grid {}; } u32 ComputePathAsync(entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t, entity_id_t) override { return 1; } void ComputePathImmediate(entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t, WaypointPath&) const override {} u32 ComputeShortPathAsync(entity_pos_t, entity_pos_t, entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t, bool, entity_id_t, entity_id_t) override { return 1; } @@ -110,7 +110,7 @@ public: DEFAULT_MOCK_COMPONENT() bool IsRoot() const override { return true; }; - u16 GetWeight() const override { return 10; }; + std::uint16_t GetWeight() const override { return 10; }; u32 GetRadius() const override { return m_Radius; }; u32 m_Radius = 0; @@ -445,14 +445,14 @@ private: /// Parses a string representation of a grid into an actual Grid structure, such that the (i,j) axes are located in the bottom /// left hand side of the map. Note: leaves all custom bits in the grid values at zero (anything outside /// ICmpTerritoryManager::TERRITORY_PLAYER_MASK). - Grid GetGrid(const std::string& def, u16 w, u16 h) + Grid GetGrid(const std::string& def, std::uint16_t w, std::uint16_t h) { Grid grid(w, h); const char* chars = def.c_str(); - for (u16 y=0; y coords) { return get(coords.first, coords.second); } - T& get(std::pair coords) { return get(coords.first, coords.second); } + T& operator[](std::pair coords) { return get(coords.first, coords.second); } + T& get(std::pair coords) { return get(coords.first, coords.second); } - T& operator[](std::pair coords) const { return get(coords.first, coords.second); } - T& get(std::pair coords) const { return get(coords.first, coords.second); } + T& operator[](std::pair coords) const { return get(coords.first, coords.second); } + T& get(std::pair coords) const { return get(coords.first, coords.second); } T& get(int i, int j) { @@ -240,7 +240,7 @@ public: return g && m_W == g->m_W && m_H == g->m_H; } - u16 m_W, m_H; + std::uint16_t m_W, m_H; T* m_Data; }; @@ -278,7 +278,7 @@ struct SerializeHelper> void operator()(IDeserializer& deserialize, const char* name, Grid& value) { - u16 w, h; + std::uint16_t w, h; deserialize.NumberU16_Unbounded("width", w); deserialize.NumberU16_Unbounded("height", h); u32 len = h * w; @@ -318,12 +318,12 @@ class SparseGrid } public: - SparseGrid(u16 w, u16 h) : m_W(w), m_H(h), m_DirtyID(0) + SparseGrid(std::uint16_t w, std::uint16_t h) : m_W(w), m_H(h), m_DirtyID(0) { ENSURE(m_W && m_H); - m_BW = (u16)((m_W + BucketSize-1) >> BucketBits); - m_BH = (u16)((m_H + BucketSize-1) >> BucketBits); + m_BW = static_cast((m_W + BucketSize-1) >> BucketBits); + m_BH = static_cast((m_H + BucketSize-1) >> BucketBits); m_Data = new T*[m_BW*m_BH](); } @@ -359,8 +359,8 @@ public: return GetBucket(i, j)[(j % BucketSize)*BucketSize + (i % BucketSize)]; } - u16 m_W, m_H; - u16 m_BW, m_BH; + std::uint16_t m_W, m_H; + std::uint16_t m_BW, m_BH; T** m_Data; size_t m_DirtyID; // if this is < the id maintained by ICmpObstructionManager then it needs to be updated diff --git a/source/simulation2/helpers/HierarchicalPathfinder.cpp b/source/simulation2/helpers/HierarchicalPathfinder.cpp index 0194f3680c..00bca0efdc 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.cpp +++ b/source/simulation2/helpers/HierarchicalPathfinder.cpp @@ -41,7 +41,7 @@ class CSimContext; namespace { // Find the root ID of a region, used by InitRegions -u16 RootID(u16 x, const std::vector& v) +std::uint16_t RootID(std::uint16_t x, const std::vector& v) { while (v[x] < x) x = v[x]; @@ -52,7 +52,8 @@ u16 RootID(u16 x, const std::vector& v) void BuildTextureRGBA(HierarchicalPathfinder& pathfinderHier, std::uint8_t* data, std::size_t w, std::size_t h) { - ENSURE(h <= std::numeric_limits::max() && w <= std::numeric_limits::max()); + ENSURE(h <= std::numeric_limits::max() && + w <= std::numeric_limits::max()); pass_class_t passClass = pathfinderHier.GetPassabilityClass("default"); TerrainTextureOverlay::OverwriteEachTile(data, w, h, [&](const int i, const int j) @@ -84,11 +85,11 @@ void HierarchicalPathfinder::Chunk::InitRegions(int ci, int cj, Grid connect; + std::vector connect; - u16* pCurrentID = NULL; - u16 LeftID = 0; - u16 DownID = 0; + std::uint16_t* pCurrentID = NULL; + std::uint16_t LeftID = 0; + std::uint16_t DownID = 0; bool Checked = false; // prevent some unneccessary RootID calls connect.reserve(32); // TODO: What's a sensible number? @@ -120,8 +121,8 @@ void HierarchicalPathfinder::Chunk::InitRegions(int ci, int cj, Grid 0 && !Checked) { - u16 id0 = RootID(DownID, connect); - u16 id1 = RootID(LeftID, connect); + std::uint16_t id0 = RootID(DownID, connect); + std::uint16_t id1 = RootID(LeftID, connect); Checked = true; // this avoids repeatedly connecting the same IDs if (id0 < id1) @@ -149,7 +150,7 @@ void HierarchicalPathfinder::Chunk::InitRegions(int ci, int cj, Grid::max(); - for (u16 j = jmin; j < jmax; ++j) + for (std::uint16_t j = jmin; j < jmax; ++j) { - for (u16 i = imin; i < imax; ++i) + for (std::uint16_t i = imin; i < imax; ++i) { if (m_Regions[j][i] != r) continue; @@ -323,9 +326,9 @@ bool HierarchicalPathfinder::Chunk::RegionNearestNavcellInGoal(u16 r, u16 i0, u1 bool found = false; u32 dist2 = std::numeric_limits::max(); // loop over all navcells. - for (u16 j = 0; j < CHUNK_SIZE; ++j) + for (std::uint16_t j = 0; j < CHUNK_SIZE; ++j) { - for (u16 i = 0; i < CHUNK_SIZE; ++i) + for (std::uint16_t i = 0; i < CHUNK_SIZE; ++i) { if (m_Regions[j][i] != r) continue; @@ -445,7 +448,7 @@ void HierarchicalPathfinder::Recompute(Grid* grid, globalRegion.clear(); for (std::uint8_t cj = 0; cj < m_ChunksH; ++cj) for (std::uint8_t ci = 0; ci < m_ChunksW; ++ci) - for (u16 rid : GetChunk(ci, cj, passClass).m_RegionsID) + for (std::uint16_t rid : GetChunk(ci, cj, passClass).m_RegionsID) { RegionID reg{ci,cj,rid}; if (globalRegion.find(reg) == globalRegion.end()) @@ -511,7 +514,7 @@ void HierarchicalPathfinder::Update(Grid* grid, const Grid* grid, const Grid goalRegions(SortByBestToPoint(i0, j0)); @@ -745,11 +750,12 @@ bool HierarchicalPathfinder::MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, p } -bool HierarchicalPathfinder::IsGoalReachable(u16 i0, u16 j0, const PathGoal& goal, pass_class_t passClass) const +bool HierarchicalPathfinder::IsGoalReachable(std::uint16_t i0, std::uint16_t j0, const PathGoal& goal, + pass_class_t passClass) const { PROFILE2("IsGoalReachable"); - u16 iGoal, jGoal; + std::uint16_t iGoal, jGoal; Pathfinding::NearestNavcell(goal.x, goal.z, iGoal, jGoal, m_W, m_H); std::set goalRegions(SortByBestToPoint(i0, j0)); @@ -763,7 +769,8 @@ bool HierarchicalPathfinder::IsGoalReachable(u16 i0, u16 j0, const PathGoal& goa return false; } -void HierarchicalPathfinder::FindNearestPassableNavcell(u16& i, u16& j, pass_class_t passClass) const +void HierarchicalPathfinder::FindNearestPassableNavcell(std::uint16_t& i, std::uint16_t& j, + pass_class_t passClass) const { std::set regions(SortByCenterToPoint(i, j)); @@ -775,9 +782,11 @@ void HierarchicalPathfinder::FindNearestPassableNavcell(u16& i, u16& j, pass_cla FindNearestNavcellInRegions(regions, i, j, passClass); } -void HierarchicalPathfinder::FindNearestNavcellInRegions(const std::set& regions, u16& iGoal, u16& jGoal, pass_class_t passClass) const +void HierarchicalPathfinder::FindNearestNavcellInRegions( + const std::set& regions, std::uint16_t& iGoal, std::uint16_t& jGoal, + pass_class_t passClass) const { - u16 bestI = iGoal, bestJ = jGoal; // Somewhat sensible default-values should regions() be passed empty. + std::uint16_t bestI = iGoal, bestJ = jGoal; // Somewhat sensible default-values should regions() be passed empty. u32 bestDist = std::numeric_limits::max(); // Because regions are sorted by increasing distance, we can ignore regions that are obviously farther than the current best point. @@ -785,7 +794,7 @@ void HierarchicalPathfinder::FindNearestNavcellInRegions(const std::set::max()); + ENSURE(maxDistFromBest < std::numeric_limits::max()); maxDistFromBest *= maxDistFromBest; for (const RegionID& region : regions) @@ -810,7 +819,9 @@ void HierarchicalPathfinder::FindNearestNavcellInRegions(const std::set& regions, pass_class_t passClass) const +void HierarchicalPathfinder::FindGoalRegionsAndBestNavcells(std::uint16_t i0, std::uint16_t j0, + std::uint16_t gi, std::uint16_t gj, const PathGoal& goal, + std::set& regions, pass_class_t passClass) const { if (goal.type == PathGoal::POINT) { @@ -830,7 +841,7 @@ void HierarchicalPathfinder::FindGoalRegionsAndBestNavcells(u16 i0, u16 j0, u16 // (and even then not always) and that just doesn't happen for Inverse-XX goals int size = (std::max(goal.hh, goal.hw) * 3 / 2).ToInt_RoundToInfinity(); - u16 bestI, bestJ; + std::uint16_t bestI, bestJ; u32 c; // Unused. for (std::uint8_t sz = std::max(0,(gj - size) / CHUNK_SIZE); @@ -840,14 +851,15 @@ void HierarchicalPathfinder::FindGoalRegionsAndBestNavcells(u16 i0, u16 j0, u16 sx <= std::min(m_ChunksW-1, (gi + size + 1) / CHUNK_SIZE); ++sx) { const Chunk& chunk = GetChunk(sx, sz, passClass); - for (u16 i : chunk.m_RegionsID) + for (std::uint16_t i : chunk.m_RegionsID) if (chunk.RegionNearestNavcellInGoal(i, i0, j0, goal, bestI, bestJ, c)) regions.insert({RegionID{sx, sz, i}, bestI, bestJ}); } } } -void HierarchicalPathfinder::FillRegionOnGrid(const RegionID& region, pass_class_t passClass, u16 value, Grid& grid) const +void HierarchicalPathfinder::FillRegionOnGrid(const RegionID& region, pass_class_t passClass, + std::uint16_t value, Grid& grid) const { ENSURE(grid.m_W == m_W && grid.m_H == m_H); @@ -862,16 +874,16 @@ void HierarchicalPathfinder::FillRegionOnGrid(const RegionID& region, pass_class grid.set(i0 + i, j0 + j, value); } -Grid HierarchicalPathfinder::GetConnectivityGrid(pass_class_t passClass) const +Grid HierarchicalPathfinder::GetConnectivityGrid(pass_class_t passClass) const { - Grid connectivityGrid(m_W, m_H); + Grid connectivityGrid(m_W, m_H); connectivityGrid.reset(); - u16 idx = 1; + std::uint16_t idx = 1; - for (u16 i = 0; i < m_W; ++i) + for (std::uint16_t i = 0; i < m_W; ++i) { - for (u16 j = 0; j < m_H; ++j) + for (std::uint16_t j = 0; j < m_H; ++j) { if (connectivityGrid.get(i, j) != 0) continue; diff --git a/source/simulation2/helpers/HierarchicalPathfinder.h b/source/simulation2/helpers/HierarchicalPathfinder.h index 3a6cfe2f4d..3c14bf901b 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.h +++ b/source/simulation2/helpers/HierarchicalPathfinder.h @@ -80,9 +80,9 @@ public: struct RegionID { std::uint8_t ci, cj; // chunk ID - u16 r; // unique-per-chunk local region ID + std::uint16_t r; // unique-per-chunk local region ID - RegionID(std::uint8_t ci, std::uint8_t cj, u16 r) : ci(ci), cj(cj), r(r) { } + RegionID(std::uint8_t ci, std::uint8_t cj, std::uint16_t r) : ci(ci), cj(cj), r(r) { } bool operator<(const RegionID& b) const { @@ -104,7 +104,7 @@ public: } // Returns the distance from the center to the point (i, j) - inline u32 DistanceTo(u16 i, u16 j) const + inline u32 DistanceTo(std::uint16_t i, std::uint16_t j) const { return (ci * CHUNK_SIZE + CHUNK_SIZE/2 - i) * (ci * CHUNK_SIZE + CHUNK_SIZE/2 - i) + (cj * CHUNK_SIZE + CHUNK_SIZE/2 - j) * (cj * CHUNK_SIZE + CHUNK_SIZE/2 - j); @@ -124,9 +124,9 @@ public: void Update(Grid* grid, const Grid& dirtinessGrid); - RegionID Get(u16 i, u16 j, pass_class_t passClass) const; + RegionID Get(std::uint16_t i, std::uint16_t j, pass_class_t passClass) const; - GlobalRegionID GetGlobalRegion(u16 i, u16 j, pass_class_t passClass) const; + GlobalRegionID GetGlobalRegion(std::uint16_t i, std::uint16_t j, pass_class_t passClass) const; GlobalRegionID GetGlobalRegion(RegionID region, pass_class_t passClass) const; /** @@ -141,24 +141,26 @@ public: * * @returns true if the goal was reachable, false otherwise. */ - bool MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass) const; + bool MakeGoalReachable(std::uint16_t i0, std::uint16_t j0, PathGoal& goal, + pass_class_t passClass) const; /** * @return true if the goal is reachable from navcell i0, j0. * (similar to MakeGoalReachable but only checking for reachability). */ - bool IsGoalReachable(u16 i0, u16 j0, const PathGoal& goal, pass_class_t passClass) const; + bool IsGoalReachable(std::uint16_t i0, std::uint16_t j0, const PathGoal& goal, + pass_class_t passClass) const; /** * Updates @p i, @p j (which is assumed to be an impassable navcell) * to the nearest passable navcell. */ - void FindNearestPassableNavcell(u16& i, u16& j, pass_class_t passClass) const; + void FindNearestPassableNavcell(std::uint16_t& i, std::uint16_t& j, pass_class_t passClass) const; /** * Generates the connectivity grid associated with the given pass_class */ - Grid GetConnectivityGrid(pass_class_t passClass) const; + Grid GetConnectivityGrid(pass_class_t passClass) const; pass_class_t GetPassabilityClass(const std::string& name) const { @@ -179,8 +181,8 @@ private: struct Chunk { std::uint8_t m_ChunkI, m_ChunkJ; // chunk ID - std::vector m_RegionsID; // IDs of local regions, 0 (impassable) excluded - u16 m_Regions[CHUNK_SIZE][CHUNK_SIZE]; // local region ID per navcell + std::vector m_RegionsID; // IDs of local regions, 0 (impassable) excluded + std::uint16_t m_Regions[CHUNK_SIZE][CHUNK_SIZE]; // local region ID per navcell cassert(CHUNK_SIZE*CHUNK_SIZE/2 < 65536); // otherwise we could overflow m_RegionsID with a checkerboard pattern @@ -188,16 +190,21 @@ private: RegionID Get(int i, int j) const; - void RegionCenter(u16 r, int& i, int& j) const; + void RegionCenter(std::uint16_t r, int& i, int& j) const; - void RegionNavcellNearest(u16 r, int iGoal, int jGoal, int& iBest, int& jBest, u32& dist2Best) const; + void RegionNavcellNearest(std::uint16_t r, int iGoal, int jGoal, int& iBest, int& jBest, + u32& dist2Best) const; - bool RegionNearestNavcellInGoal(u16 r, u16 i0, u16 j0, const PathGoal& goal, u16& iOut, u16& jOut, u32& dist2Best) const; + bool RegionNearestNavcellInGoal(std::uint16_t r, std::uint16_t i0, std::uint16_t j0, + const PathGoal& goal, std::uint16_t& iOut, std::uint16_t& jOut, + u32& dist2Best) const; #ifdef TEST bool operator==(const Chunk& b) const { - return (m_ChunkI == b.m_ChunkI && m_ChunkJ == b.m_ChunkJ && m_RegionsID.size() == b.m_RegionsID.size() && memcmp(&m_Regions, &b.m_Regions, sizeof(u16) * CHUNK_SIZE * CHUNK_SIZE) == 0); + return (m_ChunkI == b.m_ChunkI && m_ChunkJ == b.m_ChunkJ && + m_RegionsID.size() == b.m_RegionsID.size() && memcmp(&m_Regions, &b.m_Regions, + sizeof(std::uint16_t) * CHUNK_SIZE * CHUNK_SIZE) == 0); } #endif }; @@ -248,7 +255,7 @@ private: struct SortByCenterToPoint { - SortByCenterToPoint(u16 i, u16 j): gi(i), gj(j) {}; + SortByCenterToPoint(std::uint16_t i, std::uint16_t j): gi(i), gj(j) {}; bool operator()(const HierarchicalPathfinder::RegionID& a, const HierarchicalPathfinder::RegionID& b) const { if (a.DistanceTo(gi, gj) < b.DistanceTo(gi, gj)) @@ -257,21 +264,21 @@ private: return false; return a.r < b.r; } - u16 gi, gj; + std::uint16_t gi, gj; }; void FindNearestNavcellInRegions(const std::set& regions, - u16& iGoal, u16& jGoal, pass_class_t passClass) const; + std::uint16_t& iGoal, std::uint16_t& jGoal, pass_class_t passClass) const; struct InterestingRegion { RegionID region; - u16 bestI; - u16 bestJ; + std::uint16_t bestI; + std::uint16_t bestJ; }; struct SortByBestToPoint { - SortByBestToPoint(u16 i, u16 j): gi(i), gj(j) {}; + SortByBestToPoint(std::uint16_t i, std::uint16_t j): gi(i), gj(j) {}; bool operator()(const InterestingRegion& a, const InterestingRegion& b) const { if ((a.bestI - gi) * (a.bestI - gi) + (a.bestJ - gj) * (a.bestJ - gj) < (b.bestI - gi) * (b.bestI - gi) + (b.bestJ - gj) * (b.bestJ - gj)) @@ -280,15 +287,18 @@ private: return false; return a.region.r < b.region.r; } - u16 gi, gj; + std::uint16_t gi, gj; }; // Returns the region along with the best cell for optimisation. - void FindGoalRegionsAndBestNavcells(u16 i0, u16 j0, u16 gi, u16 gj, const PathGoal& goal, std::set& regions, pass_class_t passClass) const; + void FindGoalRegionsAndBestNavcells(std::uint16_t i0, std::uint16_t j0, std::uint16_t gi, + std::uint16_t gj, const PathGoal& goal, std::set& regions, pass_class_t passClass) const; - void FillRegionOnGrid(const RegionID& region, pass_class_t passClass, u16 value, Grid& grid) const; + void FillRegionOnGrid(const RegionID& region, pass_class_t passClass, std::uint16_t value, + Grid& grid) const; - u16 m_W, m_H; + std::uint16_t m_W, m_H; std::uint8_t m_ChunksW, m_ChunksH; std::map > m_Chunks; diff --git a/source/simulation2/helpers/LongPathfinder.cpp b/source/simulation2/helpers/LongPathfinder.cpp index 46db99fc7b..5d79b389d8 100644 --- a/source/simulation2/helpers/LongPathfinder.cpp +++ b/source/simulation2/helpers/LongPathfinder.cpp @@ -70,10 +70,10 @@ void BuildTextureRGBA(LongPathfinder& pathfinder, std::uint8_t* data, std::size_ if (pathfinder.m_Debug.Path && !pathfinder.m_Debug.Path->m_Waypoints.empty()) { std::vector& waypoints = pathfinder.m_Debug.Path->m_Waypoints; - u16 ip = 0, jp = 0; + std::uint16_t ip = 0, jp = 0; for (size_t k = 0; k < waypoints.size(); ++k) { - u16 i, j; + std::uint16_t i, j; Pathfinding::NearestNavcell(waypoints[k].x, waypoints[k].z, i, j, pathfinder.m_GridSize, pathfinder.m_GridSize); if (k == 0) @@ -140,11 +140,11 @@ class JumpPointCache */ struct RowRaw { - std::vector data; + std::vector data; size_t GetMemoryUsage() const { - return data.capacity() * sizeof(u16); + return data.capacity() * sizeof(std::uint16_t); } RowRaw(int length) @@ -825,7 +825,7 @@ void LongPathfinder::ComputeJPSPath(const HierarchicalPathfinder& hierPath, enti } // Convert the start coordinates to tile indexes - u16 i0, j0; + std::uint16_t i0, j0; Pathfinding::NearestNavcell(x0, z0, i0, j0, m_GridSize, m_GridSize); if (!IS_PASSABLE(m_Grid->get(i0, j0), passClass)) @@ -883,8 +883,8 @@ void LongPathfinder::ComputeJPSPath(const HierarchicalPathfinder& hierPath, enti // Move best tile from open to closed PriorityQueue::Item curr = state.open.pop(); - u16 i = curr.id.i(); - u16 j = curr.id.j(); + std::uint16_t i = curr.id.i(); + std::uint16_t j = curr.id.j(); state.tiles->get(i, j).SetStatusClosed(); // If we've reached the destination, stop @@ -974,7 +974,7 @@ void LongPathfinder::ComputeJPSPath(const HierarchicalPathfinder& hierPath, enti } // Reconstruct the path (in reverse) - u16 ip = state.iBest, jp = state.jBest; + std::uint16_t ip = state.iBest, jp = state.jBest; while (ip != i0 || jp != j0) { PathfindTile& n = state.tiles->get(ip, jp); @@ -1070,13 +1070,13 @@ void LongPathfinder::GetDebugDataJPS(u32& steps, double& time, Grid lock(g_DebugMutex); - u16 iGoal, jGoal; + std::uint16_t iGoal, jGoal; Pathfinding::NearestNavcell(m_Debug.Goal.x, m_Debug.Goal.z, iGoal, jGoal, m_GridSize, m_GridSize); grid = Grid(m_Debug.Grid->m_W, m_Debug.Grid->m_H); - for (u16 j = 0; j < grid.m_H; ++j) + for (std::uint16_t j = 0; j < grid.m_H; ++j) { - for (u16 i = 0; i < grid.m_W; ++i) + for (std::uint16_t i = 0; i < grid.m_W; ++i) { if (i == iGoal && j == jGoal) continue; @@ -1104,7 +1104,7 @@ void LongPathfinder::ComputePath(const HierarchicalPathfinder& hierPath, entity_ ComputeJPSPath(hierPath, x0, z0, origGoal, SPECIAL_PASS_CLASS, path); } -inline bool InRegion(u16 i, u16 j, CircularRegion region) +inline bool InRegion(std::uint16_t i, std::uint16_t j, CircularRegion region) { fixed cellX = Pathfinding::NAVCELL_SIZE * i; fixed cellZ = Pathfinding::NAVCELL_SIZE * j; @@ -1114,9 +1114,9 @@ inline bool InRegion(u16 i, u16 j, CircularRegion region) void LongPathfinder::GenerateSpecialMap(pass_class_t passClass, std::vector excludedRegions) { - for (u16 j = 0; j < m_Grid->m_H; ++j) + for (std::uint16_t j = 0; j < m_Grid->m_H; ++j) { - for (u16 i = 0; i < m_Grid->m_W; ++i) + for (std::uint16_t i = 0; i < m_Grid->m_W; ++i) { NavcellData n = m_Grid->get(i, j); if (!IS_PASSABLE(n, passClass)) diff --git a/source/simulation2/helpers/LongPathfinder.h b/source/simulation2/helpers/LongPathfinder.h index 0a62171f72..e828e128b9 100644 --- a/source/simulation2/helpers/LongPathfinder.h +++ b/source/simulation2/helpers/LongPathfinder.h @@ -37,14 +37,14 @@ * Represents the 2D coordinates of a tile. * The i/j components are packed into a single u32, since we usually use these * objects for equality comparisons and the VC2010 optimizer doesn't seem to automatically - * compare two u16s in a single operation. + * compare two std::uint16_ts in a single operation. * TODO: maybe VC2012 will? */ struct TileID { TileID() { } - TileID(u16 i, u16 j) : data((i << 16) | j) { } + TileID(std::uint16_t i, std::uint16_t j) : data((i << 16) | j) { } bool operator==(const TileID& b) const { @@ -57,8 +57,8 @@ struct TileID return data < b.data; } - u16 i() const { return data >> 16; } - u16 j() const { return data & 0xFFFF; } + std::uint16_t i() const { return data >> 16; } + std::uint16_t j() const { return data & 0xFFFF; } private: u32 data; @@ -146,7 +146,7 @@ struct PathfinderState PathGoal goal; - u16 iGoal, jGoal; // goal tile + std::uint16_t iGoal, jGoal; // goal tile pass_class_t passClass; @@ -157,7 +157,7 @@ struct PathfinderState Grid* terrain; PathCost hBest; // heuristic of closest discovered tile to goal - u16 iBest, jBest; // closest tile + std::uint16_t iBest, jBest; // closest tile const JumpPointCache* jpc; }; @@ -227,7 +227,7 @@ public: } Grid* m_Grid; - u16 m_GridSize; + std::uint16_t m_GridSize; // Debugging - output from last pathfind operation. struct Debug diff --git a/source/simulation2/helpers/Pathfinding.cpp b/source/simulation2/helpers/Pathfinding.cpp index c1c0ff8abd..6b11d6ea5c 100644 --- a/source/simulation2/helpers/Pathfinding.cpp +++ b/source/simulation2/helpers/Pathfinding.cpp @@ -47,7 +47,7 @@ namespace Pathfinding // we allow them to move from an impassable to a passable cell (but not // vice versa). - u16 i0, j0, i1, j1; + std::uint16_t i0, j0, i1, j1; NearestNavcell(x0, z0, i0, j0, grid.m_W, grid.m_H); NearestNavcell(x1, z1, i1, j1, grid.m_W, grid.m_H); @@ -55,8 +55,8 @@ namespace Pathfinding int di = (i0 < i1 ? +1 : i1 < i0 ? -1 : 0); int dj = (j0 < j1 ? +1 : j1 < j0 ? -1 : 0); - u16 i = i0; - u16 j = j0; + std::uint16_t i = i0; + std::uint16_t j = j0; bool currentlyOnImpassable = !IS_PASSABLE(grid.get(i0, j0), passClass); diff --git a/source/simulation2/helpers/Pathfinding.h b/source/simulation2/helpers/Pathfinding.h index 7b7a30e1eb..688e000478 100644 --- a/source/simulation2/helpers/Pathfinding.h +++ b/source/simulation2/helpers/Pathfinding.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 @@ -31,7 +31,7 @@ class CParamNode; template class Grid; -typedef u16 pass_class_t; +typedef std::uint16_t pass_class_t; struct LongPathRequest { @@ -81,19 +81,19 @@ struct PathCost PathCost() : data(0) { } /// Construct from a number of horizontal/vertical and diagonal steps - PathCost(u16 hv, u16 d) + PathCost(std::uint16_t hv, std::uint16_t d) : data(hv * 65536 + d * 92682) // 2^16 * sqrt(2) == 92681.9 { } /// Construct for horizontal/vertical movement of given number of steps - static PathCost horizvert(u16 n) + static PathCost horizvert(std::uint16_t n) { return PathCost(n, 0); } /// Construct for diagonal movement of given number of steps - static PathCost diag(u16 n) + static PathCost diag(std::uint16_t n) { return PathCost(0, n); } @@ -126,7 +126,7 @@ private: }; inline constexpr int PASS_CLASS_BITS = 16; -typedef u16 NavcellData; // 1 bit per passability class (up to PASS_CLASS_BITS) +typedef std::uint16_t NavcellData; // 1 bit per passability class (up to PASS_CLASS_BITS) #define IS_PASSABLE(item, classmask) (((item) & (classmask)) == 0) #define PASS_CLASS_MASK_FROM_INDEX(id) ((pass_class_t)(1u << id)) #define SPECIAL_PASS_CLASS PASS_CLASS_MASK_FROM_INDEX((PASS_CLASS_BITS-1)) // 16th bit, used for special in-place computations @@ -163,24 +163,27 @@ namespace Pathfinding * Compute the navcell indexes on the grid nearest to a given point * w, h are the grid dimensions, i.e. the number of navcells per side */ - inline void NearestNavcell(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u16 h) + inline void NearestNavcell(entity_pos_t x, entity_pos_t z, std::uint16_t& i, std::uint16_t& j, + std::uint16_t w, std::uint16_t h) { // Use NAVCELL_SIZE_INT to save the cost of dividing by a fixed - i = static_cast(Clamp((x / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, w - 1)); - j = static_cast(Clamp((z / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, h - 1)); + i = static_cast(Clamp((x / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, + w - 1)); + j = static_cast(Clamp((z / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, + h - 1)); } /** * Returns the position of the center of the given terrain tile */ - inline void TerrainTileCenter(u16 i, u16 j, entity_pos_t& x, entity_pos_t& z) + inline void TerrainTileCenter(std::uint16_t i, std::uint16_t j, entity_pos_t& x, entity_pos_t& z) { static_assert(TERRAIN_TILE_SIZE % 2 == 0); x = entity_pos_t::FromInt(i*(int)TERRAIN_TILE_SIZE + (int)TERRAIN_TILE_SIZE / 2); z = entity_pos_t::FromInt(j*(int)TERRAIN_TILE_SIZE + (int)TERRAIN_TILE_SIZE / 2); } - inline void NavcellCenter(u16 i, u16 j, entity_pos_t& x, entity_pos_t& z) + inline void NavcellCenter(std::uint16_t i, std::uint16_t j, entity_pos_t& x, entity_pos_t& z) { x = entity_pos_t::FromInt(i * 2 + 1).Multiply(NAVCELL_SIZE / 2); z = entity_pos_t::FromInt(j * 2 + 1).Multiply(NAVCELL_SIZE / 2); diff --git a/source/simulation2/helpers/VertexPathfinder.cpp b/source/simulation2/helpers/VertexPathfinder.cpp index 6e0509a9d9..8454b485d1 100644 --- a/source/simulation2/helpers/VertexPathfinder.cpp +++ b/source/simulation2/helpers/VertexPathfinder.cpp @@ -267,7 +267,7 @@ inline static bool CheckVisibilityTop(const CFixedVector2D& a, const CFixedVecto return true; } -typedef PriorityQueueHeap VertexPriorityQueue; +typedef PriorityQueueHeap VertexPriorityQueue; /** * Add edges and vertexes to represent the boundaries between passable and impassable @@ -339,8 +339,8 @@ static void AddTerrainEdges(std::vector& edgesAligned, std::vector& } // XXX rewrite this stuff - std::vector segmentsR; - std::vector segmentsL; + std::vector segmentsR; + std::vector segmentsL; for (int j = j0; j < j1; ++j) { segmentsR.clear(); @@ -358,8 +358,8 @@ static void AddTerrainEdges(std::vector& edgesAligned, std::vector& if (!segmentsR.empty()) { segmentsR.push_back(0); // sentinel value to simplify the loop - u16 ia = segmentsR[0]; - u16 ib = ia + 1; + std::uint16_t ia = segmentsR[0]; + std::uint16_t ib = ia + 1; for (size_t n = 1; n < segmentsR.size(); ++n) { if (segmentsR[n] == ib) @@ -383,8 +383,8 @@ static void AddTerrainEdges(std::vector& edgesAligned, std::vector& if (!segmentsL.empty()) { segmentsL.push_back(0); // sentinel value to simplify the loop - u16 ia = segmentsL[0]; - u16 ib = ia + 1; + std::uint16_t ia = segmentsL[0]; + std::uint16_t ib = ia + 1; for (size_t n = 1; n < segmentsL.size(); ++n) { if (segmentsL[n] == ib) @@ -405,8 +405,8 @@ static void AddTerrainEdges(std::vector& edgesAligned, std::vector& } } } - std::vector segmentsU; - std::vector segmentsD; + std::vector segmentsU; + std::vector segmentsD; for (int i = i0; i < i1; ++i) { segmentsU.clear(); @@ -424,8 +424,8 @@ static void AddTerrainEdges(std::vector& edgesAligned, std::vector& if (!segmentsU.empty()) { segmentsU.push_back(0); // sentinel value to simplify the loop - u16 ja = segmentsU[0]; - u16 jb = ja + 1; + std::uint16_t ja = segmentsU[0]; + std::uint16_t jb = ja + 1; for (size_t n = 1; n < segmentsU.size(); ++n) { if (segmentsU[n] == jb) @@ -449,8 +449,8 @@ static void AddTerrainEdges(std::vector& edgesAligned, std::vector& if (!segmentsD.empty()) { segmentsD.push_back(0); // sentinel value to simplify the loop - u16 ja = segmentsD[0]; - u16 jb = ja + 1; + std::uint16_t ja = segmentsD[0]; + std::uint16_t jb = ja + 1; for (size_t n = 1; n < segmentsD.size(); ++n) { if (segmentsD[n] == jb) @@ -709,7 +709,7 @@ WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, // Add terrain obstructions { - u16 i0, j0, i1, j1; + std::uint16_t i0, j0, i1, j1; Pathfinding::NearestNavcell(rangeXMin, rangeZMin, i0, j0, m_GridSize, m_GridSize); Pathfinding::NearestNavcell(rangeXMax, rangeZMax, i1, j1, m_GridSize, m_GridSize); AddTerrainEdges(m_EdgesAligned, m_EdgesUnaligned, m_Vertexes, i0, j0, i1, j1, request.passClass, *m_TerrainOnlyGrid); @@ -735,7 +735,7 @@ WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, m_Vertexes[j].status = Vertex::CLOSED; } - ENSURE(m_Vertexes.size() < 65536); // We store array indexes as u16. + ENSURE(m_Vertexes.size() < 65536); // We store array indexes as std::uint16_t. g_VertexPathfinderDebugOverlay.DebugRenderGraph(cmpObstructionManager->GetSimContext(), m_Vertexes, m_EdgesAligned, m_EdgeSquares); @@ -765,7 +765,7 @@ WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, VertexPriorityQueue::Item qiStart = { START_VERTEX_ID, start.h, start.h }; open.push(qiStart); - u16 idBest = START_VERTEX_ID; + std::uint16_t idBest = START_VERTEX_ID; fixed hBest = start.h; while (!open.empty()) @@ -874,13 +874,14 @@ WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, if (n == GOAL_VERTEX_ID) m_Vertexes[n].p = npos; // remember the new best goal position - VertexPriorityQueue::Item t = { (u16)n, g + m_Vertexes[n].h, m_Vertexes[n].h }; + VertexPriorityQueue::Item t = { static_cast(n), + g + m_Vertexes[n].h, m_Vertexes[n].h }; open.push(t); // Remember the heuristically best vertex we've seen so far, in case we never actually reach the target if (m_Vertexes[n].h < hBest) { - idBest = (u16)n; + idBest = static_cast(n); hBest = m_Vertexes[n].h; } } @@ -894,7 +895,8 @@ WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, if (n == GOAL_VERTEX_ID) m_Vertexes[n].p = npos; // remember the new best goal position - open.promote((u16)n, gprev + m_Vertexes[n].h, g + m_Vertexes[n].h, m_Vertexes[n].h); + open.promote(static_cast(n), gprev + m_Vertexes[n].h, + g + m_Vertexes[n].h, m_Vertexes[n].h); } } } @@ -902,7 +904,7 @@ WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, // Reconstruct the path (in reverse) WaypointPath path; - for (u16 id = idBest; id != START_VERTEX_ID; id = m_Vertexes[id].pred) + for (std::uint16_t id = idBest; id != START_VERTEX_ID; id = m_Vertexes[id].pred) path.m_Waypoints.emplace_back(Waypoint{ m_Vertexes[id].p.X, m_Vertexes[id].p.Y }); m_EdgesAligned.clear(); diff --git a/source/simulation2/helpers/VertexPathfinder.h b/source/simulation2/helpers/VertexPathfinder.h index 0488b5b23c..6e342e67e7 100644 --- a/source/simulation2/helpers/VertexPathfinder.h +++ b/source/simulation2/helpers/VertexPathfinder.h @@ -19,7 +19,6 @@ #define INCLUDED_VERTEXPATHFINDER #include "graphics/Overlay.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "simulation2/helpers/Pathfinding.h" @@ -46,7 +45,7 @@ struct Vertex CFixedVector2D p; fixed g, h; - u16 pred = 0; + std::uint16_t pred = 0; std::uint8_t status; std::uint8_t quadInward : 4; // the quadrant which is inside the shape (or NONE) std::uint8_t quadOutward : 4; // the quadrants of the next point on the path which this vertex must be in, given 'pred' @@ -88,7 +87,10 @@ struct EdgeAA class VertexPathfinder { public: - VertexPathfinder(const u16& gridSize, Grid* const & terrainOnlyGrid) : m_GridSize(gridSize), m_TerrainOnlyGrid(terrainOnlyGrid) {}; + VertexPathfinder(const std::uint16_t& gridSize, Grid* const & terrainOnlyGrid) : + m_GridSize(gridSize), + m_TerrainOnlyGrid(terrainOnlyGrid) + {} VertexPathfinder(const VertexPathfinder&) = delete; VertexPathfinder(VertexPathfinder&& o) : m_GridSize(o.m_GridSize), m_TerrainOnlyGrid(o.m_TerrainOnlyGrid) {} @@ -104,7 +106,7 @@ public: private: // References to the Pathfinder for convenience. - const u16& m_GridSize; + const std::uint16_t& m_GridSize; Grid* const & m_TerrainOnlyGrid; // These vectors are expensive to recreate on every call, so we cache them here. diff --git a/source/simulation2/scripting/EngineScriptConversions.cpp b/source/simulation2/scripting/EngineScriptConversions.cpp index a53c0beec7..fcde02cf87 100644 --- a/source/simulation2/scripting/EngineScriptConversions.cpp +++ b/source/simulation2/scripting/EngineScriptConversions.cpp @@ -257,10 +257,11 @@ template<> void Script::ToJSVal>(const Script::Request& rq, J "data", data); } -template<> void Script::ToJSVal >(const Script::Request& rq, JS::MutableHandleValue ret, const Grid& val) +template<> void Script::ToJSVal>(const Script::Request& rq, JS::MutableHandleValue ret, + const Grid& val) { u32 length = (u32)(val.m_W * val.m_H); - u32 nbytes = (u32)(length * sizeof(u16)); + u32 nbytes = (u32)(length * sizeof(std::uint16_t)); JS::RootedObject objArr(rq.cx, JS_NewUint16Array(rq.cx, length)); // Copy the array data and then remove the no-GC check to allow further changes to the JS data { diff --git a/source/simulation2/serialization/BinarySerializer.h b/source/simulation2/serialization/BinarySerializer.h index a5b97312d5..52bdb714d2 100644 --- a/source/simulation2/serialization/BinarySerializer.h +++ b/source/simulation2/serialization/BinarySerializer.h @@ -175,7 +175,7 @@ protected: virtual void PutNumber(const char* name, int16_t value) { - int16_t v = static_cast(to_le16((u16)value)); + int16_t v = static_cast(to_le16(static_cast(value))); m_Impl.Put(name, reinterpret_cast(&v), sizeof(int16_t)); } diff --git a/source/simulation2/serialization/IDeserializer.cpp b/source/simulation2/serialization/IDeserializer.cpp index 44c5cca36e..8b661c22c6 100644 --- a/source/simulation2/serialization/IDeserializer.cpp +++ b/source/simulation2/serialization/IDeserializer.cpp @@ -67,7 +67,7 @@ void IDeserializer::NumberI16(const char* name, int16_t& out, int16_t lower, int { int16_t value; Get(name, reinterpret_cast(&value), sizeof(uint16_t)); - value = static_cast(to_le16((u16)value)); + value = static_cast(to_le16(static_cast(value))); if (!(lower <= value && value <= upper)) throw PSERROR_Deserialize_OutOfBounds(name); @@ -120,7 +120,7 @@ void IDeserializer::NumberI16_Unbounded(const char* name, int16_t& out) { int16_t value; Get(name, reinterpret_cast(&value), sizeof(int16_t)); - out = static_cast(to_le16((u16)value)); + out = static_cast(to_le16(static_cast(value))); } void IDeserializer::NumberU32_Unbounded(const char* name, uint32_t& out) diff --git a/source/simulation2/serialization/SerializedTypes.h b/source/simulation2/serialization/SerializedTypes.h index aeda48ff9d..a4fd9ad9df 100644 --- a/source/simulation2/serialization/SerializedTypes.h +++ b/source/simulation2/serialization/SerializedTypes.h @@ -182,14 +182,14 @@ struct SerializeHelper>> template<> -struct SerializeHelper +struct SerializeHelper { - void operator()(ISerializer& serialize, const char* name, u16 value) + void operator()(ISerializer& serialize, const char* name, std::uint16_t value) { serialize.NumberU16_Unbounded(name, value); } - void operator()(IDeserializer& deserialize, const char* name, u16& value) + void operator()(IDeserializer& deserialize, const char* name, std::uint16_t& value) { deserialize.NumberU16_Unbounded(name, value); } diff --git a/source/simulation2/system/ComponentTest.h b/source/simulation2/system/ComponentTest.h index 41ba6e0ce9..949d2cf691 100644 --- a/source/simulation2/system/ComponentTest.h +++ b/source/simulation2/system/ComponentTest.h @@ -230,7 +230,7 @@ public: return 50.f; } - u16 GetTilesPerSide() const override + std::uint16_t GetTilesPerSide() const override { return 16; } @@ -240,7 +240,7 @@ public: return GetTilesPerSide() * TERRAIN_TILE_SIZE; } - u16 GetVerticesPerSide() const override + std::uint16_t GetVerticesPerSide() const override { return 17; } diff --git a/source/simulation2/tests/test_SerializeTemplates.h b/source/simulation2/tests/test_SerializeTemplates.h index be2fe140ee..9beb7e3538 100644 --- a/source/simulation2/tests/test_SerializeTemplates.h +++ b/source/simulation2/tests/test_SerializeTemplates.h @@ -79,7 +79,7 @@ public: std::stringstream stream; CDebugSerializer serialize(script, stream); - Grid value; + Grid value; value.resize(3,2); // Checkerboard pattern. for (std::uint8_t j = 0; j < value.height(); ++j) diff --git a/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp index 371ad572f7..fb315e1e51 100644 --- a/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.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 @@ -21,7 +21,6 @@ #include "graphics/Terrain.h" #include "graphics/UnitManager.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/MathUtil.h" #include "maths/Vector3D.h" #include "ps/Game.h" @@ -44,7 +43,7 @@ namespace AtlasMessage { -class TerrainArray : public DeltaArray2D +class TerrainArray : public DeltaArray2D { public: void Init() @@ -59,7 +58,7 @@ public: if (size_t(x) >= size_t(m_VertsPerSide) || size_t(y) >= size_t(m_VertsPerSide)) return; - set(x, y, static_cast(Clamp(get(x,y) + amount, 0, 65535))); + set(x, y, static_cast(Clamp(get(x,y) + amount, 0, 65535))); } void MoveVertexTowards(ssize_t x, ssize_t y, int target, int amount) @@ -75,10 +74,10 @@ public: else return; - set(x, y, static_cast(Clamp(h, 0, 65535))); + set(x, y, static_cast(Clamp(h, 0, 65535))); } - void SetVertex(ssize_t x, ssize_t y, u16 value) + void SetVertex(ssize_t x, ssize_t y, std::uint16_t value) { if (size_t(x) >= size_t(m_VertsPerSide) || size_t(y) >= size_t(m_VertsPerSide)) return; @@ -86,22 +85,22 @@ public: set(x,y, value); } - u16 GetVertex(ssize_t x, ssize_t y) + std::uint16_t GetVertex(ssize_t x, ssize_t y) { return get(Clamp(x, 0, m_VertsPerSide - 1), Clamp(y, 0, m_VertsPerSide - 1)); } protected: - u16 getOld(ssize_t x, ssize_t y) + std::uint16_t getOld(ssize_t x, ssize_t y) { return m_Heightmap[y*m_VertsPerSide + x]; } - void setNew(ssize_t x, ssize_t y, const u16& val) + void setNew(ssize_t x, ssize_t y, const std::uint16_t& val) { m_Heightmap[y*m_VertsPerSide + x] = val; } - u16* m_Heightmap; + std::uint16_t* m_Heightmap; ssize_t m_VertsPerSide; }; @@ -332,7 +331,7 @@ BEGIN_COMMAND(FlattenElevation) ssize_t xc, yc; g_CurrentBrush.GetCentre(xc, yc); - u16 height = m_TerrainDelta.GetVertex(xc, yc); + std::uint16_t height = m_TerrainDelta.GetVertex(xc, yc); ssize_t x0, y0; g_CurrentBrush.GetBottomLeft(x0, y0); diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index 7f06e42264..49a23340ca 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -219,7 +219,7 @@ MESSAGEHANDLER(LoadMap) MESSAGEHANDLER(ImportHeightmap) { - std::vector heightmap_source; + std::vector heightmap_source; if (LoadHeightmapImageOs(*msg->filename, heightmap_source) != INFO::OK) { LOGERROR("Failed to decode heightmap."); @@ -235,7 +235,7 @@ MESSAGEHANDLER(ImportHeightmap) terrain.ResizeAndOffset(newSize, offset, offset); // copy heightmap data into map - u16* const heightmap = g_Game->GetWorld()->GetTerrain().GetHeightMap(); + std::uint16_t* const heightmap = g_Game->GetWorld()->GetTerrain().GetHeightMap(); ENSURE(heightmap_source.size() == (std::size_t) SQR(g_Game->GetWorld()->GetTerrain().GetVerticesPerSide())); std::copy(heightmap_source.begin(), heightmap_source.end(), heightmap); @@ -455,7 +455,7 @@ BEGIN_COMMAND(ResizeMap) ssize_t m_OldPatches, m_NewPatches; int m_OffsetX, m_OffsetY; - u16* m_Heightmap; + std::uint16_t* m_Heightmap; CPatch* m_Patches; std::vector m_DeletedObjects; @@ -562,7 +562,7 @@ BEGIN_COMMAND(ResizeMap) m_OffsetY = -(msg->offsetY / PATCH_SIZE); CTerrain* terrain = cmpTerrain->GetCTerrain(); - m_Heightmap = new u16[(m_OldPatches * PATCH_SIZE + 1) * (m_OldPatches * PATCH_SIZE + 1)]; + m_Heightmap = new std::uint16_t[(m_OldPatches * PATCH_SIZE + 1) * (m_OldPatches * PATCH_SIZE + 1)]; std::copy_n(terrain->GetHeightMap(), (m_OldPatches * PATCH_SIZE + 1) * (m_OldPatches * PATCH_SIZE + 1), m_Heightmap); m_Patches = new CPatch[m_OldPatches * m_OldPatches]; for (ssize_t j = 0; j < m_OldPatches; ++j) diff --git a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp index 1a28e2c32e..424635d333 100644 --- a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp @@ -22,7 +22,6 @@ #include "gui/GUIManager.h" #include "lib/external_libraries/libsdl.h" #include "lib/path.h" -#include "lib/types.h" #include "maths/MathUtil.h" #include "ps/Game.h" #include "ps/GameSetup/Config.h" @@ -128,8 +127,8 @@ MESSAGEHANDLER(GuiMouseButtonEvent) ev.button.clicks = msg->clicks; float x, y; msg->pos->GetScreenSpace(x, y); - ev.button.x = static_cast(Clamp(x, 0, g_VideoMode.GetWindowWidth())); - ev.button.y = static_cast(Clamp(y, 0, g_VideoMode.GetWindowHeight())); + ev.button.x = static_cast(Clamp(x, 0, g_VideoMode.GetWindowWidth())); + ev.button.y = static_cast(Clamp(y, 0, g_VideoMode.GetWindowHeight())); g_VideoMode.m_InputManager.DispatchEvent(ev); } @@ -142,8 +141,8 @@ MESSAGEHANDLER(GuiMouseMotionEvent) ev.type = SDL_MOUSEMOTION; float x, y; msg->pos->GetScreenSpace(x, y); - ev.motion.x = static_cast(Clamp(x, 0, g_VideoMode.GetWindowWidth())); - ev.motion.y = static_cast(Clamp(y, 0, g_VideoMode.GetWindowHeight())); + ev.motion.x = static_cast(Clamp(x, 0, g_VideoMode.GetWindowWidth())); + ev.motion.y = static_cast(Clamp(y, 0, g_VideoMode.GetWindowHeight())); g_VideoMode.m_InputManager.DispatchEvent(ev); } diff --git a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp index 6879c1edd6..35f58d1c61 100644 --- a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp @@ -542,19 +542,19 @@ BEGIN_COMMAND(FillTerrain) // Simple 4-way flood fill algorithm using queue and a grid to keep track of visited tiles, // almost as fast as loop for filling whole map, much faster for small patches SparseGrid visited(tiles, tiles); - std::queue > queue; + std::queue> queue; // Initial tile - queue.push(std::make_pair((u16)x0, (u16)y0)); + queue.push(std::make_pair(static_cast(x0), static_cast(y0))); visited.set(x0, y0, true); while(!queue.empty()) { // Check front of queue - std::pair t = queue.front(); + std::pair t = queue.front(); queue.pop(); - u16 i = t.first; - u16 j = t.second; + std::uint16_t i = t.first; + std::uint16_t j = t.second; if (m_TerrainDelta.GetTexEntry(i, j) == replacedTex) { diff --git a/source/tools/lint/cppcheck/suppressions-list.txt b/source/tools/lint/cppcheck/suppressions-list.txt index b057508fc9..a587ff371e 100644 --- a/source/tools/lint/cppcheck/suppressions-list.txt +++ b/source/tools/lint/cppcheck/suppressions-list.txt @@ -63,6 +63,7 @@ unknownMacro:source/lib/sysdep/os/win/wdbg_sym.cpp unknownMacro:source/lib/sysdep/os/win/wfirmware.cpp unknownMacro:source/lib/sysdep/os/win/wposix/wutsname.cpp unknownMacro:source/ps/CStr.cpp +unknownMacro:source/simulation2/components/tests/test_HierPathfinder.h uninitvar:source/ps/Game.cpp uninitvar:source/ps/scripting/JSInterface_SavedGame.cpp