From 00ee8253744e407bd9d78a5e4df2c503004e5764 Mon Sep 17 00:00:00 2001 From: phosit Date: Wed, 9 Sep 2026 09:59:47 +0200 Subject: [PATCH] Remove u8 It's better to use types from the standard library. --- source/collada/PMDConvert.cpp | 6 +- source/graphics/ColladaManager.cpp | 2 +- source/graphics/Color.h | 11 ++- source/graphics/Font.cpp | 33 +++++---- source/graphics/Font.h | 12 ++-- source/graphics/HeightMipmap.cpp | 4 +- source/graphics/LOSTexture.cpp | 13 ++-- source/graphics/LOSTexture.h | 5 +- source/graphics/MapIO.cpp | 11 +-- source/graphics/MiniMapTexture.cpp | 8 +-- source/graphics/MiniMapTexture.h | 2 +- source/graphics/ModelDef.h | 6 +- source/graphics/ObjectBase.cpp | 44 ++++++------ source/graphics/ObjectBase.h | 19 +++-- source/graphics/ObjectEntry.cpp | 3 +- source/graphics/ObjectEntry.h | 5 +- source/graphics/ObjectManager.cpp | 2 +- source/graphics/ObjectManager.h | 9 ++- source/graphics/SColor.h | 21 +++--- source/graphics/TerrainProperties.cpp | 10 +-- source/graphics/TerrainTextureManager.cpp | 10 +-- source/graphics/TerrainTextureManager.h | 5 +- source/graphics/TerritoryBoundary.cpp | 21 +++--- source/graphics/TerritoryBoundary.h | 5 +- source/graphics/TerritoryTexture.cpp | 12 ++-- source/graphics/TerritoryTexture.h | 6 +- source/graphics/TextureConverter.cpp | 31 ++++---- source/graphics/TextureManager.cpp | 8 +-- source/graphics/tests/test_LOSTexture.h | 8 +-- source/graphics/tests/test_MeshManager.h | 11 ++- source/graphics/tests/test_TextureConverter.h | 7 +- source/gui/SettingTypes/MouseEventMask.cpp | 6 +- source/lib/allocators/dynarray.cpp | 6 +- source/lib/allocators/dynarray.h | 5 +- source/lib/allocators/pool.cpp | 3 +- .../lib/allocators/tests/test_DynamicArena.h | 17 +++-- source/lib/app_hooks.cpp | 7 +- source/lib/byte_order.cpp | 8 +-- source/lib/byte_order.h | 26 +++---- source/lib/debug.cpp | 4 +- source/lib/debug.h | 3 +- source/lib/debug_stl.cpp | 40 ++++++----- source/lib/debug_stl.h | 7 +- source/lib/file/archive/archive.h | 6 +- source/lib/file/archive/archive_zip.cpp | 33 +++++---- source/lib/file/archive/codec.h | 7 +- source/lib/file/archive/codec_zlib.cpp | 16 +++-- .../archive/disabled_tests/test_codec_zlib.h | 14 ++-- .../archive/disabled_tests/test_compression.h | 10 +-- source/lib/file/archive/stream.cpp | 10 +-- source/lib/file/archive/stream.h | 18 ++--- source/lib/file/common/file_loader.h | 3 +- source/lib/file/common/real_directory.cpp | 4 +- source/lib/file/common/real_directory.h | 5 +- source/lib/file/io/io.h | 11 +-- source/lib/file/io/write_buffer.cpp | 16 +++-- source/lib/file/io/write_buffer.h | 11 ++- .../lib/file/vfs/tests/test_vfs_real_path.h | 3 +- source/lib/file/vfs/tests/test_vfs_tree.h | 3 +- source/lib/file/vfs/tests/test_vfs_util.h | 3 +- source/lib/file/vfs/vfs.cpp | 12 ++-- source/lib/file/vfs/vfs.h | 9 +-- source/lib/fnv_hash.cpp | 6 +- source/lib/lib.cpp | 6 +- source/lib/lib.h | 12 ++-- source/lib/sysdep/arch/x86_x64/apic.cpp | 2 +- source/lib/sysdep/arch/x86_x64/apic.h | 6 +- source/lib/sysdep/os/unix/unix.cpp | 5 +- source/lib/sysdep/os/win/acpi.cpp | 8 +-- source/lib/sysdep/os/win/acpi.h | 22 +++--- .../lib/sysdep/os/win/tests/test_wdbg_sym.h | 18 ++--- source/lib/sysdep/os/win/wdbg_sym.cpp | 71 ++++++++++--------- source/lib/sysdep/os/win/wdir_watch.cpp | 4 +- source/lib/sysdep/os/win/wfirmware.h | 2 +- source/lib/sysdep/os/win/wnuma.cpp | 22 +++--- source/lib/sysdep/os/win/wsysdep.cpp | 2 +- source/lib/sysdep/sysdep.h | 5 +- source/lib/sysdep/tests/test_sysdep.h | 4 +- source/lib/tests/test_byte_order.h | 12 ++-- source/lib/tex/tests/test_tex.h | 15 ++-- source/lib/tex/tex.cpp | 63 ++++++++-------- source/lib/tex/tex.h | 17 ++--- source/lib/tex/tex_bmp.cpp | 6 +- source/lib/tex/tex_codec.cpp | 5 +- source/lib/tex/tex_codec.h | 39 +++++----- source/lib/tex/tex_dds.cpp | 47 ++++++------ source/lib/tex/tex_png.cpp | 20 +++--- source/lib/tex/tex_tga.cpp | 30 ++++---- source/lib/types.h | 1 - source/lib/utf8.cpp | 2 +- source/maths/MD5.cpp | 10 +-- source/maths/MD5.h | 10 +-- source/maths/tests/test_MD5.h | 14 ++-- source/network/NMTCreator.h | 12 ++-- source/network/NetHost.cpp | 2 +- source/network/NetHost.h | 3 +- source/network/NetMessage.cpp | 14 ++-- source/network/NetMessage.h | 12 ++-- source/network/NetMessageSim.cpp | 28 ++++---- source/network/NetMessages.h | 10 +-- source/network/Serialization.h | 9 ++- source/network/StunClient.cpp | 28 ++++---- source/network/tests/test_NetMessage.h | 3 +- source/ps/CConsole.cpp | 3 +- source/ps/CStr.cpp | 15 ++-- source/ps/CStr.h | 5 +- source/ps/CacheLoader.cpp | 8 +-- source/ps/ConfigDB.cpp | 4 +- source/ps/FileIo.h | 2 +- source/ps/Filesystem.cpp | 4 +- source/ps/Filesystem.h | 5 +- source/ps/GUID.cpp | 4 +- source/ps/ModIo.cpp | 6 +- source/ps/Profiler2.cpp | 34 ++++----- source/ps/Profiler2.h | 6 +- source/ps/SavedGame.cpp | 13 ++-- source/ps/UserReport.cpp | 3 +- source/ps/Util.cpp | 4 +- source/ps/Util.h | 5 +- source/ps/VideoMode.cpp | 7 +- source/ps/VisualReplay.cpp | 2 +- source/ps/XMB/XMBStorage.h | 2 +- source/ps/XMB/tests/test_XMBData.h | 3 +- source/ps/XML/RelaxNG.cpp | 3 +- source/ps/XML/XMLWriter.cpp | 3 +- source/ps/scripting/JSInterface_Main.cpp | 5 +- source/ps/tests/test_CStr.h | 5 +- source/renderer/GPUSkinnedModelRenderer.cpp | 10 +-- source/renderer/MikktspaceWrap.cpp | 5 +- source/renderer/PatchRData.cpp | 11 +-- source/renderer/PatchRData.h | 8 +-- source/renderer/Renderer.cpp | 5 +- source/renderer/SkyManager.cpp | 7 +- source/renderer/TerrainOverlay.cpp | 4 +- source/renderer/TerrainOverlay.h | 1 - source/renderer/VertexArray.cpp | 12 ++-- source/renderer/VertexArray.h | 4 +- source/renderer/VertexBuffer.cpp | 4 +- .../renderer/backend/IDeviceCommandContext.h | 4 +- .../backend/dummy/DeviceCommandContext.h | 3 +- .../backend/gl/DeviceCommandContext.cpp | 5 +- .../backend/gl/DeviceCommandContext.h | 3 +- source/renderer/backend/gl/ShaderProgram.cpp | 4 +- .../backend/vulkan/RingCommandContext.h | 5 +- source/scriptinterface/Conversions.cpp | 6 +- .../simulation2/components/CCmpAIManager.cpp | 49 +++++++------ source/simulation2/components/CCmpMinimap.cpp | 19 +++-- .../components/CCmpObstructionManager.cpp | 5 +- .../simulation2/components/CCmpPathfinder.cpp | 12 ++-- .../components/CCmpPathfinder_Common.h | 3 +- .../components/CCmpRangeManager.cpp | 55 +++++++------- .../components/CCmpTerritoryManager.cpp | 30 ++++---- .../simulation2/components/CCmpUnitMotion.h | 21 +++--- source/simulation2/components/ICmpMinimap.h | 6 +- .../components/ICmpObstructionManager.h | 4 +- .../simulation2/components/ICmpPathfinder.h | 4 +- .../simulation2/components/ICmpRangeManager.h | 13 ++-- .../components/ICmpTerritoryManager.h | 6 +- .../components/tests/test_HierPathfinder.h | 8 +-- .../components/tests/test_Pathfinder.h | 2 +- .../components/tests/test_RangeManager.h | 2 +- .../components/tests/test_TerritoryManager.h | 14 ++-- source/simulation2/helpers/Grid.h | 4 +- .../helpers/HierarchicalPathfinder.cpp | 29 +++++--- .../helpers/HierarchicalPathfinder.h | 16 ++--- source/simulation2/helpers/LongPathfinder.cpp | 8 +-- source/simulation2/helpers/LongPathfinder.h | 8 +-- source/simulation2/helpers/Los.h | 2 +- .../simulation2/helpers/VertexPathfinder.cpp | 18 ++--- source/simulation2/helpers/VertexPathfinder.h | 6 +- .../scripting/EngineScriptConversions.cpp | 5 +- .../serialization/BinarySerializer.cpp | 11 +-- .../serialization/BinarySerializer.h | 26 +++---- .../serialization/DebugSerializer.cpp | 2 +- .../serialization/DebugSerializer.h | 3 +- .../serialization/HashSerializer.cpp | 4 +- .../serialization/HashSerializer.h | 9 ++- .../serialization/IDeserializer.cpp | 34 ++++----- .../simulation2/serialization/IDeserializer.h | 8 +-- .../simulation2/serialization/ISerializer.cpp | 2 +- .../simulation2/serialization/ISerializer.h | 7 +- .../serialization/SerializedTypes.h | 12 ++-- .../serialization/StdDeserializer.cpp | 10 +-- .../serialization/StdDeserializer.h | 3 +- .../simulation2/serialization/StdSerializer.h | 3 +- source/simulation2/system/IComponent.h | 2 +- .../tests/test_SerializeTemplates.h | 4 +- source/simulation2/tests/test_Serializer.h | 9 ++- source/simulation2/tests/test_Simulation2.h | 2 +- source/soundmanager/data/OggData.cpp | 7 +- source/soundmanager/data/ogg.cpp | 10 +-- source/soundmanager/data/ogg.h | 5 +- source/soundmanager/scripting/SoundGroup.h | 4 +- .../Handlers/EnvironmentHandlers.cpp | 2 +- .../GameInterface/Handlers/MapHandlers.cpp | 11 +-- .../Handlers/TerrainHandlers.cpp | 6 +- source/tools/atlas/GameInterface/Messages.h | 2 +- 197 files changed, 1050 insertions(+), 1032 deletions(-) diff --git a/source/collada/PMDConvert.cpp b/source/collada/PMDConvert.cpp index 1997a6fe16..46d6e07f08 100644 --- a/source/collada/PMDConvert.cpp +++ b/source/collada/PMDConvert.cpp @@ -296,9 +296,9 @@ public: } else { - // Check for less than 254 joints because we store them in a u8, - // 0xFF is a reserved value (no influence), and we reserve one slot - // for the above special case. + // Check for less than 254 joints because we store them in a + // std::uint8_t, 0xFF is a reserved value (no influence), and we + // reserve one slot for the above special case. uint32 jointIdx = vertexInfluences[i].GetPair(j)->jointIndex; REQUIRE(jointIdx < 0xFE, "sensible number of joints (<254)"); diff --git a/source/graphics/ColladaManager.cpp b/source/graphics/ColladaManager.cpp index 113355ac83..d7c8ad4a5b 100644 --- a/source/graphics/ColladaManager.cpp +++ b/source/graphics/ColladaManager.cpp @@ -314,7 +314,7 @@ public: } for (const u64& h : m_skeletonHashes) - hash.Update((const u8*)&h, sizeof(h)); + hash.Update(reinterpret_cast(&h), sizeof(h)); } private: diff --git a/source/graphics/Color.h b/source/graphics/Color.h index 430039d24c..985060e0f3 100644 --- a/source/graphics/Color.h +++ b/source/graphics/Color.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_COLOR #include "graphics/SColor.h" -#include "lib/types.h" #include "maths/Vector3D.h" #include "maths/Vector4D.h" @@ -89,10 +88,10 @@ struct CColor SColor4ub AsSColor4ub() const { return SColor4ub( - static_cast(r * 255.f), - static_cast(g * 255.f), - static_cast(b * 255.f), - static_cast(a * 255.f) + static_cast(r * 255.f), + static_cast(g * 255.f), + static_cast(b * 255.f), + static_cast(a * 255.f) ); } diff --git a/source/graphics/Font.cpp b/source/graphics/Font.cpp index 3c6edb2280..5224d78e9b 100644 --- a/source/graphics/Font.cpp +++ b/source/graphics/Font.cpp @@ -202,7 +202,7 @@ bool CFont::AddFontFromPath(const OsPath& fontPath) return false; } - std::unique_ptr fontData; + std::unique_ptr fontData; size_t fontDataSize; if (g_VFS->LoadFile(fontPath, fontData, fontDataSize) != 0) { @@ -305,7 +305,7 @@ bool CFont::ConstructAtlasTexture(Renderer::Backend::IDevice* device) // Initialise texture with transparency, for the areas we don't // overwrite with uploading later. - m_TexData = std::make_unique(m_AtlasSize); + m_TexData = std::make_unique(m_AtlasSize); std::fill_n(m_TexData.get(), m_AtlasSize, 0x00); m_IsTextureInitialized = false; @@ -521,7 +521,8 @@ void CFont::UploadAtlasTextureToGPU(Renderer::Backend::IDeviceCommandContext* de m_IsDirty = false; } -void CFont::BlendGlyphBitmapToTexture(const FT_Bitmap& bitmap, int targetX, int targetY, u8 r, u8 g, u8 b) +void CFont::BlendGlyphBitmapToTexture(const FT_Bitmap& bitmap, int targetX, int targetY, std::uint8_t r, + std::uint8_t g, std::uint8_t b) { PROFILE2("BlendGlyphBitmapToTexture font texture generate"); if (m_TextureFormat == Renderer::Backend::Format::R8G8B8A8_UNORM) @@ -530,17 +531,18 @@ void CFont::BlendGlyphBitmapToTexture(const FT_Bitmap& bitmap, int targetX, int BlendGlyphBitmapToTextureR8(bitmap, targetX, targetY); } -void CFont::BlendGlyphBitmapToTextureRGBA(const FT_Bitmap& bitmap, int targetX, int targetY, u8 r, u8 g, u8 b) +void CFont::BlendGlyphBitmapToTextureRGBA(const FT_Bitmap& bitmap, int targetX, int targetY, + std::uint8_t r, std::uint8_t g, std::uint8_t b) { for (uint y{0}; y != bitmap.rows; ++y) { - const u8* srcRow{bitmap.buffer + y * bitmap.pitch}; - u8* dstRow{m_TexData.get() + ((targetY + y) * m_AtlasWidth + targetX) * m_TextureFormatStride}; + const std::uint8_t* srcRow{bitmap.buffer + y * bitmap.pitch}; + std::uint8_t* dstRow{m_TexData.get() + ((targetY + y) * m_AtlasWidth + targetX) * m_TextureFormatStride}; for (uint x{0}; x != bitmap.width; ++x) { - u8* tempDstRow{dstRow + x * m_TextureFormatStride}; - u8 alpha{srcRow[x]}; + std::uint8_t* tempDstRow{dstRow + x * m_TextureFormatStride}; + std::uint8_t alpha{srcRow[x]}; const float srcAlpha{m_StrokeWidth > 0 ? m_GammaCorrectionLUT.get()[alpha] : alpha / 255.0f}; const float dstAlpha{tempDstRow[3] / 255.0f}; @@ -549,10 +551,13 @@ void CFont::BlendGlyphBitmapToTextureRGBA(const FT_Bitmap& bitmap, int targetX, if (outAlpha == 0.0f) continue; - tempDstRow[0] = static_cast(std::round(((r * srcAlpha + tempDstRow[0] * dstAlpha * (1.0f - srcAlpha)) / outAlpha))); - tempDstRow[1] = static_cast(std::round(((g * srcAlpha + tempDstRow[1] * dstAlpha * (1.0f - srcAlpha)) / outAlpha))); - tempDstRow[2] = static_cast(std::round(((b * srcAlpha + tempDstRow[2] * dstAlpha * (1.0f - srcAlpha)) / outAlpha))); - tempDstRow[3] = static_cast(std::round(outAlpha * 255.0f)); + tempDstRow[0] = static_cast(std::round(((r * srcAlpha + tempDstRow[0] * + dstAlpha * (1.0f - srcAlpha)) / outAlpha))); + tempDstRow[1] = static_cast(std::round(((g * srcAlpha + tempDstRow[1] * + dstAlpha * (1.0f - srcAlpha)) / outAlpha))); + tempDstRow[2] = static_cast(std::round(((b * srcAlpha + tempDstRow[2] * + dstAlpha * (1.0f - srcAlpha)) / outAlpha))); + tempDstRow[3] = static_cast(std::round(outAlpha * 255.0f)); } } } @@ -561,8 +566,8 @@ void CFont::BlendGlyphBitmapToTextureR8(const FT_Bitmap& bitmap, int targetX, i { for (uint y{0}; y != bitmap.rows; ++y) { - const u8* srcRow{bitmap.buffer + y * bitmap.pitch}; - u8* dstRow{m_TexData.get() + ((targetY + y) * m_AtlasWidth + targetX)}; + const std::uint8_t* srcRow{bitmap.buffer + y * bitmap.pitch}; + std::uint8_t* dstRow{m_TexData.get() + ((targetY + y) * m_AtlasWidth + targetX)}; std::memcpy(dstRow, srcRow, bitmap.width); } diff --git a/source/graphics/Font.h b/source/graphics/Font.h index 984ce49b75..085c55715a 100644 --- a/source/graphics/Font.h +++ b/source/graphics/Font.h @@ -61,7 +61,7 @@ public: float x0, y0, x1, y1; float xadvance; float yadvance; - u8 defined{0}; + std::uint8_t defined{0}; FT_Face face; }; @@ -143,8 +143,10 @@ private: Renderer::Backend::IDevice* device, const std::string& fontName, float size, float strokeWidth, float scale); - void BlendGlyphBitmapToTexture(const FT_Bitmap& bitmap, int targetX, int targetY, u8 r, u8 g, u8 b); - void BlendGlyphBitmapToTextureRGBA(const FT_Bitmap& bitmap, int targetX, int targetY, u8 r, u8 g, u8 b); + void BlendGlyphBitmapToTexture(const FT_Bitmap& bitmap, int targetX, int targetY, std::uint8_t r, + std::uint8_t g, std::uint8_t b); + void BlendGlyphBitmapToTextureRGBA(const FT_Bitmap& bitmap, int targetX, int targetY, std::uint8_t r, + 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); @@ -181,7 +183,7 @@ private: float m_StrokeWidth{0.0f}; float m_Scale{1.0f}; - std::unique_ptr m_TexData; + std::unique_ptr m_TexData; Renderer::Backend::Format m_TextureFormat{Renderer::Backend::Format::R8G8B8A8_UNORM}; int m_TextureFormatStride{4}; int m_AtlasSize{0}; @@ -191,7 +193,7 @@ private: std::reference_wrapper> m_GammaCorrectionLUT; FT_Library m_FreeType; - std::vector> m_FontsData; + std::vector> m_FontsData; std::vector m_Faces; UniqueFTStroker m_Stroker{nullptr, &ftStrokerDeleter}; diff --git a/source/graphics/HeightMipmap.cpp b/source/graphics/HeightMipmap.cpp index d387e9e766..de70f992e8 100644 --- a/source/graphics/HeightMipmap.cpp +++ b/source/graphics/HeightMipmap.cpp @@ -237,7 +237,7 @@ void CHeightMipmap::DumpToDisk(const VfsPath& filename) const const size_t img_size = w * h * bpp/8; const size_t hdr_size = tex_hdr_size(filename); - std::shared_ptr buf; + std::shared_ptr buf; AllocateAligned(buf, hdr_size+img_size, maxSectorSize); void* img = buf.get() + hdr_size; Tex t; @@ -255,7 +255,7 @@ void CHeightMipmap::DumpToDisk(const VfsPath& filename) const for (size_t x = 0; x < size; ++x) { u16 val = heightmap[x + y*size]; - ((u8*)img)[x + (y+yoff)*w] = val >> 8; + static_cast(img)[x + (y+yoff)*w] = val >> 8; } } yoff += size; diff --git a/source/graphics/LOSTexture.cpp b/source/graphics/LOSTexture.cpp index 3c1188c6e4..b8b0269613 100644 --- a/source/graphics/LOSTexture.cpp +++ b/source/graphics/LOSTexture.cpp @@ -284,7 +284,7 @@ void CLOSTexture::ConstructTexture(Renderer::Backend::IDeviceCommandContext* dev // Initialise texture with SoD color, for the areas we don't // overwrite with uploading later. const size_t textureDataSize = textureSize * textureSize * m_TextureFormatStride; - std::unique_ptr texData = std::make_unique(textureDataSize); + std::unique_ptr texData = std::make_unique(textureDataSize); memset(texData.get(), 0x00, textureDataSize); if (CRenderer::IsInitialised() && g_RenderingOptions.GetSmoothLOS()) @@ -379,7 +379,7 @@ void CLOSTexture::RecomputeTexture(Renderer::Backend::IDeviceCommandContext* dev size_t pitch; const size_t dataSize = GetBitmapSize(m_MapSize, m_MapSize, &pitch); ENSURE(pitch * m_MapSize <= dataSize); - std::unique_ptr losData = std::make_unique( + std::unique_ptr losData = std::make_unique( dataSize * m_TextureFormatStride); CLosQuerier los(cmpRangeManager->GetLosQuerier(m_Simulation.GetSimContext().GetCurrentDisplayedPlayer())); @@ -423,9 +423,10 @@ size_t CLOSTexture::GetBitmapSize(size_t w, size_t h, size_t* pitch) return *pitch * (h + g_BlurSize - 1); } -void CLOSTexture::GenerateBitmap(const CLosQuerier& los, u8* losData, size_t w, size_t h, size_t pitch) +void CLOSTexture::GenerateBitmap(const CLosQuerier& los, std::uint8_t* losData, size_t w, size_t h, + size_t pitch) { - u8 *dataPtr = losData; + std::uint8_t *dataPtr = losData; // Initialise the top padding for (size_t j = 0; j < g_BlurSize/2; ++j) @@ -465,7 +466,7 @@ void CLOSTexture::GenerateBitmap(const CLosQuerier& los, u8* losData, size_t w, { for (size_t i = 0; i < w; ++i) { - u8* d = &losData[i+j*pitch]; + std::uint8_t* d = &losData[i+j*pitch]; *d = ( 1*d[0] + 6*d[1] + @@ -484,7 +485,7 @@ void CLOSTexture::GenerateBitmap(const CLosQuerier& los, u8* losData, size_t w, { for (size_t i = 0; i < w; ++i) { - u8* d = &losData[i+j*pitch]; + std::uint8_t* d = &losData[i+j*pitch]; *d = ( 1*d[0*pitch] + 6*d[1*pitch] + diff --git a/source/graphics/LOSTexture.h b/source/graphics/LOSTexture.h index 4801f9c7c7..c293173360 100644 --- a/source/graphics/LOSTexture.h +++ b/source/graphics/LOSTexture.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 @@ -20,7 +20,6 @@ #include "graphics/ShaderTechniquePtr.h" #include "lib/code_annotation.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "renderer/backend/Format.h" #include @@ -84,7 +83,7 @@ private: void RecomputeTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); size_t GetBitmapSize(size_t w, size_t h, size_t* pitch); - void GenerateBitmap(const CLosQuerier& los, u8* losData, size_t w, size_t h, size_t pitch); + void GenerateBitmap(const CLosQuerier& los, std::uint8_t* losData, size_t w, size_t h, size_t pitch); CSimulation2& m_Simulation; diff --git a/source/graphics/MapIO.cpp b/source/graphics/MapIO.cpp index 40135ce2ac..616bf5a5ed 100644 --- a/source/graphics/MapIO.cpp +++ b/source/graphics/MapIO.cpp @@ -40,11 +40,12 @@ #include #include -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); Status LoadHeightmapImageVfs(const VfsPath& filepath, std::vector& heightmap) { - std::shared_ptr fileData; + std::shared_ptr fileData; size_t fileSize; RETURN_STATUS_IF_ERR(g_VFS->LoadFile(filepath, fileData, fileSize)); @@ -62,7 +63,7 @@ Status LoadHeightmapImageOs(const OsPath& filepath, std::vector& heightmap) if (ec) return StatusFromSystemError(ec); - std::shared_ptr fileData; + std::shared_ptr fileData; RETURN_STATUS_IF_ERR(AllocateAligned(fileData, fileSize, maxSectorSize)); Status readvalue = read(file.Descriptor(), fileData.get(), fileSize); @@ -73,7 +74,7 @@ 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; @@ -87,7 +88,7 @@ Status ParseHeightmapImage(const std::shared_ptr& fileData, size_t fileSize, ssize_t tileSize = std::min(tex.m_Width, tex.m_Height); tileSize -= tileSize % PATCH_SIZE; - u8* mapdata = tex.get_data(); + std::uint8_t* mapdata = tex.get_data(); ssize_t bytesPP = tex.m_Bpp / 8; ssize_t mapLineSkip = tex.m_Width * bytesPP; diff --git a/source/graphics/MiniMapTexture.cpp b/source/graphics/MiniMapTexture.cpp index d729fdfad8..acc309d95f 100644 --- a/source/graphics/MiniMapTexture.cpp +++ b/source/graphics/MiniMapTexture.cpp @@ -136,13 +136,13 @@ void DrawTexture( struct MinimapUnitVertex { // This struct is copyable for convenience and because to move is to copy for primitives. - u8 r, g, b, a; + std::uint8_t r, g, b, a; CVector2D position; }; // Adds a vertex to the passed VertexArray inline void AddEntity(const MinimapUnitVertex& v, - VertexArrayIterator& attrColor, + VertexArrayIterator& attrColor, VertexArrayIterator& attrPos, const float entityRadius, const bool useInstancing) @@ -238,7 +238,7 @@ CMiniMapTexture::CMiniMapTexture(Renderer::Backend::IDevice* device, CSimulation m_IndexArray.Upload(); VertexArrayIterator attrPos = m_AttributePos.GetIterator(); - VertexArrayIterator attrColor = m_AttributeColor.GetIterator(); + VertexArrayIterator attrColor = m_AttributeColor.GetIterator(); for (size_t i = 0; i < m_VertexArray.GetNumberOfVertices(); ++i) { (*attrColor)[0] = 0; @@ -655,7 +655,7 @@ void CMiniMapTexture::UpdateAndUploadEntities( CSimulation2::InterfaceList ents = m_Simulation.GetEntitiesWithInterface(IID_Minimap); VertexArrayIterator attrPos = m_AttributePos.GetIterator(); - VertexArrayIterator attrColor = m_AttributeColor.GetIterator(); + VertexArrayIterator attrColor = m_AttributeColor.GetIterator(); m_EntitiesDrawn = 0; MinimapUnitVertex v; diff --git a/source/graphics/MiniMapTexture.h b/source/graphics/MiniMapTexture.h index 183d12b25f..645c9bbd65 100644 --- a/source/graphics/MiniMapTexture.h +++ b/source/graphics/MiniMapTexture.h @@ -156,7 +156,7 @@ private: struct CellIconKey { std::string path; - u8 r, g, b; + std::uint8_t r, g, b; }; struct CellIconKeyHash { diff --git a/source/graphics/ModelDef.h b/source/graphics/ModelDef.h index 1a6a58a39d..29ef8dc272 100644 --- a/source/graphics/ModelDef.h +++ b/source/graphics/ModelDef.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 @@ -84,7 +84,7 @@ struct SPropPoint * Index of parent bone to which this prop point is relative, if any. The value 0xFF specifies that either the parent * model is unboned, or that this prop point is relative to the parent model's origin rather than one if its bones. */ - u8 m_BoneIndex; + std::uint8_t m_BoneIndex; }; /////////////////////////////////////////////////////////////////////////////// @@ -94,7 +94,7 @@ struct SVertexBlend { enum { SIZE = 4 }; // index of the influencing bone, or 0xff if none - u8 m_Bone[SIZE]; + std::uint8_t m_Bone[SIZE]; // weight of the influence; all weights sum to 1 float m_Weight[SIZE]; diff --git a/source/graphics/ObjectBase.cpp b/source/graphics/ObjectBase.cpp index 3577e28015..b753d0fd6c 100644 --- a/source/graphics/ObjectBase.cpp +++ b/source/graphics/ObjectBase.cpp @@ -60,7 +60,7 @@ int GetQuality(const CStr& value) } } // anonymous namespace -CObjectBase::CObjectBase(CObjectManager& objectManager, CActorDef& actorDef, u8 qualityLevel) +CObjectBase::CObjectBase(CObjectManager& objectManager, CActorDef& actorDef, std::uint8_t qualityLevel) : m_ObjectManager(objectManager), m_ActorDef(actorDef) { m_QualityLevel = qualityLevel; @@ -72,7 +72,7 @@ CObjectBase::CObjectBase(CObjectManager& objectManager, CActorDef& actorDef, u8 m_Identifier = fmt::format("{}{}", m_ActorDef.m_Pathname.string8().substr(11), m_QualityLevel); } -std::unique_ptr CObjectBase::CopyWithQuality(u8 newQualityLevel) const +std::unique_ptr CObjectBase::CopyWithQuality(std::uint8_t newQualityLevel) const { std::unique_ptr ret = std::make_unique(m_ObjectManager, m_ActorDef, newQualityLevel); // No need to actually change any quality-related stuff here, we assume that this is a copy for props. @@ -353,7 +353,8 @@ bool CObjectBase::LoadVariant(const CXeromyces& XeroFile, const XMBElement& vari return true; } -std::vector CObjectBase::CalculateVariationKey(const std::vector*>& selections) const +std::vector CObjectBase::CalculateVariationKey( + const std::vector*>& selections) const { // (TODO: see CObjectManager::FindObjectVariation for an opportunity to // call this function a bit less frequently) @@ -366,7 +367,7 @@ std::vector CObjectBase::CalculateVariationKey(const std::vector choices; + std::vector choices; std::multimap chosenProps; @@ -399,7 +400,7 @@ std::vector CObjectBase::CalculateVariationKey(const std::vectorcount((*grp)[i].m_VariantName)) { - match = (u8)i; + match = static_cast(i); break; } } @@ -433,7 +434,8 @@ std::vector CObjectBase::CalculateVariationKey(const std::vectorsecond); success) { - std::vector propChoices = prop.GetBase(m_QualityLevel)->CalculateVariationKey(selections); + std::vector propChoices = + prop.GetBase(m_QualityLevel)->CalculateVariationKey(selections); choices.insert(choices.end(), propChoices.begin(), propChoices.end()); } } @@ -441,7 +443,8 @@ std::vector CObjectBase::CalculateVariationKey(const std::vector& variationKey) const +const CObjectBase::Variation CObjectBase::BuildVariation( + const std::vector& variationKey) const { Variation variation; @@ -450,7 +453,7 @@ const CObjectBase::Variation CObjectBase::BuildVariation(const std::vector& // on the end for props, but we don't care about those in here.) std::vector >::const_iterator grp = m_VariantGroups.begin(); - std::vector::const_iterator match = variationKey.begin(); + std::vector::const_iterator match = variationKey.begin(); for ( ; grp != m_VariantGroups.end() && match != variationKey.end(); ++grp, ++match) @@ -730,9 +733,10 @@ std::vector > CObjectBase::GetVariantGroups() const return groups; } -void CObjectBase::GetQualitySplits(std::vector& splits) const +void CObjectBase::GetQualitySplits(std::vector& splits) const { - std::vector::iterator it = std::find_if(splits.begin(), splits.end(), [this](u8 qualityLevel) { return qualityLevel >= m_QualityLevel; }); + std::vector::iterator it = std::find_if(splits.begin(), splits.end(), + [this](std::uint8_t qualityLevel) { return qualityLevel >= m_QualityLevel; }); if (it == splits.end() || *it != m_QualityLevel) splits.emplace(it, m_QualityLevel); @@ -748,14 +752,14 @@ void CObjectBase::GetQualitySplits(std::vector& splits) const if (!success) continue; - std::vector newSplits = propActor.QualityLevels(); + std::vector newSplits = propActor.QualityLevels(); if (newSplits.size() <= 1) continue; // This is not entirely optimal since we might loop though redundant quality levels, but that shouldn't matter. // Custom implementation because this is inplace, std::set_union needs a 3rd vector. - std::vector::iterator v1 = splits.begin(); - std::vector::iterator v2 = newSplits.begin(); + std::vector::iterator v1 = splits.begin(); + std::vector::iterator v2 = newSplits.begin(); while (v2 != newSplits.end()) { if (v1 == splits.end() || *v1 > *v2) @@ -797,23 +801,23 @@ std::set CActorDef::PickSelectionsAtRandom(uint32_t seed) const return GetBase(255)->CalculateRandomRemainingSelections(seed, noSelections); } -std::vector CActorDef::QualityLevels() const +std::vector CActorDef::QualityLevels() const { - std::vector splits; + std::vector splits; splits.reserve(m_ObjectBases.size()); for (const std::shared_ptr& base : m_ObjectBases) splits.emplace_back(base->m_QualityLevel); return splits; } -const std::shared_ptr& CActorDef::GetBase(u8 QualityLevel) const +const std::shared_ptr& CActorDef::GetBase(std::uint8_t QualityLevel) const { for (const std::shared_ptr& base : m_ObjectBases) if (base->m_QualityLevel >= QualityLevel) return base; // This code path ought to be impossible to take, // because by construction we must have at least one valid CObjectBase of quality MAX_QUALITY - // (which necessarily fits the u8 comparison above). + // (which necessarily fits the std::uint8_t comparison above). // However compilers will warn that we return a reference to a local temporary if I return nullptr, // so just return something sane instead. ENSURE(false); @@ -876,7 +880,7 @@ bool CActorDef::Load(const VfsPath& pathname) return false; } } - u8 quality = 0; + std::uint8_t quality = 0; XMBElement inlineActor; for (XMBElement child : root.GetChildNodes()) { @@ -981,7 +985,7 @@ bool CActorDef::Load(const VfsPath& pathname) } // For each quality level, check if we need to further split (because of props). - std::vector splits = QualityLevels(); + std::vector splits = QualityLevels(); for (const std::shared_ptr& base : m_ObjectBases) base->GetQualitySplits(splits); ENSURE(splits.size() >= 1); @@ -992,7 +996,7 @@ bool CActorDef::Load(const VfsPath& pathname) } std::vector>::iterator it = m_ObjectBases.begin(); - std::vector::const_iterator qualityLevels = splits.begin(); + std::vector::const_iterator qualityLevels = splits.begin(); while (it != m_ObjectBases.end()) if ((*it)->m_QualityLevel > *qualityLevels) { diff --git a/source/graphics/ObjectBase.h b/source/graphics/ObjectBase.h index 15f5da7d2a..2ec1701e6d 100644 --- a/source/graphics/ObjectBase.h +++ b/source/graphics/ObjectBase.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 "lib/code_annotation.h" #include "lib/file/vfs/vfs_path.h" #include "lib/path.h" -#include "lib/types.h" #include "ps/CStr.h" #include "ps/CStrIntern.h" @@ -133,7 +132,7 @@ public: std::multimap samplers; }; - CObjectBase(CObjectManager& objectManager, CActorDef& actorDef, u8 QualityLevel); + CObjectBase(CObjectManager& objectManager, CActorDef& actorDef, std::uint8_t QualityLevel); // Returns a set of selection such that, added to initialSelections, CalculateVariationKey can proceed. std::set CalculateRandomRemainingSelections(uint32_t seed, const std::vector>& initialSelections) const; @@ -141,10 +140,10 @@ public: // Get the variation key (indices of chosen variants from each group) // based on the selection strings. // Should not have to make a random choice: the selections should be complete. - std::vector CalculateVariationKey(const std::vector*>& selections) const; + std::vector CalculateVariationKey(const std::vector*>& selections) const; // Get the final actor data, combining all selected variants - const Variation BuildVariation(const std::vector& variationKey) const; + const Variation BuildVariation(const std::vector& variationKey) const; // Get a list of variant groups for this object, plus for all possible // props. Duplicated groups are removed, if several props share the same @@ -174,7 +173,7 @@ public: VfsPath m_Material; // Quality level - part of the data resource path. - u8 m_QualityLevel; + std::uint8_t m_QualityLevel; private: // Private interface for CActorDef/ObjectEntry @@ -183,7 +182,7 @@ private: * Acts as an explicit copy constructor, for a new quality level. * Note that this does not reload the actor, so this setting will only change props. */ - std::unique_ptr CopyWithQuality(u8 newQualityLevel) const; + std::unique_ptr CopyWithQuality(std::uint8_t newQualityLevel) const; // A low-quality RNG like rand48 causes visible non-random patterns (particularly // in large grids of the same actor with consecutive seeds, e.g. forests), @@ -196,7 +195,7 @@ private: * Intended to be called by CActorFef. * @param splits - a sorted vector of unique quality splits. */ - void GetQualitySplits(std::vector& splits) const; + void GetQualitySplits(std::vector& splits) const; [[nodiscard]] bool Load(const CXeromyces& XeroFile, const XMBElement& base); [[nodiscard]] bool LoadVariant(const CXeromyces& XeroFile, const XMBElement& variant, Variant& currentVariant); @@ -228,7 +227,7 @@ public: CActorDef(CObjectManager& objectManager); - std::vector QualityLevels() const; + std::vector QualityLevels() const; VfsPath GetPathname() const { return m_Pathname; } @@ -242,7 +241,7 @@ protected: /** * Return the Object base matching the given quality level. */ - const std::shared_ptr& GetBase(u8 QualityLevel) const; + const std::shared_ptr& GetBase(std::uint8_t QualityLevel) const; /** * Initialise this object by loading from the given file. diff --git a/source/graphics/ObjectEntry.cpp b/source/graphics/ObjectEntry.cpp index dc347b6a15..aa80bb7950 100644 --- a/source/graphics/ObjectEntry.cpp +++ b/source/graphics/ObjectEntry.cpp @@ -75,8 +75,7 @@ CObjectEntry::CObjectEntry(const std::shared_ptr& base, const CSimu CObjectEntry::~CObjectEntry() = default; bool CObjectEntry::BuildVariation(const std::vector*>& completeSelections, - const std::vector& variationKey, - CObjectManager& objectManager) + const std::vector& variationKey, CObjectManager& objectManager) { CObjectBase::Variation variation = m_Base->BuildVariation(variationKey); diff --git a/source/graphics/ObjectEntry.h b/source/graphics/ObjectEntry.h index 0feed1d47c..055dab6433 100644 --- a/source/graphics/ObjectEntry.h +++ b/source/graphics/ObjectEntry.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/ObjectBase.h" #include "lib/code_annotation.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "ps/CStr.h" #include @@ -46,7 +45,7 @@ public: // Construct this actor, using the specified variation selections bool BuildVariation(const std::vector*>& completeSelections, - const std::vector& variationKey, CObjectManager& objectManager); + const std::vector& variationKey, CObjectManager& objectManager); // Base actor. Contains all the things that don't change between // different variations of the actor. diff --git a/source/graphics/ObjectManager.cpp b/source/graphics/ObjectManager.cpp index d0981360d8..879d88e88d 100644 --- a/source/graphics/ObjectManager.cpp +++ b/source/graphics/ObjectManager.cpp @@ -125,7 +125,7 @@ CObjectEntry* CObjectManager::FindObjectVariation(const std::shared_ptr choices = base->CalculateVariationKey(completeSelections); + std::vector choices = base->CalculateVariationKey(completeSelections); ObjectKey key (base->GetIdentifier(), choices); decltype(m_Objects)::iterator it = m_Objects.find(key); if (it != m_Objects.end() && !it->second.outdated) diff --git a/source/graphics/ObjectManager.h b/source/graphics/ObjectManager.h index ccf7bd78c9..c875224118 100644 --- a/source/graphics/ObjectManager.h +++ b/source/graphics/ObjectManager.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 "lib/code_annotation.h" #include "lib/file/vfs/vfs_path.h" #include "lib/status.h" -#include "lib/types.h" #include "ps/CStr.h" #include @@ -50,14 +49,14 @@ public: // Unique identifier of an actor variation struct ObjectKey { - ObjectKey(const CStr& identifier, const std::vector& var) + ObjectKey(const CStr& identifier, const std::vector& var) : ObjectBaseIdentifier(identifier), ActorVariation(var) {} bool operator< (const CObjectManager::ObjectKey& a) const; private: CStr ObjectBaseIdentifier; - std::vector ActorVariation; + std::vector ActorVariation; }; /** @@ -134,7 +133,7 @@ public: CSkeletonAnimManager& m_SkeletonAnimManager; CSimulation2& m_Simulation; - u8 m_QualityLevel = 100; + std::uint8_t m_QualityLevel = 100; std::unique_ptr m_QualityHook; VariantDiversity m_VariantDiversity = VariantDiversity::FULL; diff --git a/source/graphics/SColor.h b/source/graphics/SColor.h index 65c2a2b039..8d2dbd161e 100644 --- a/source/graphics/SColor.h +++ b/source/graphics/SColor.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,26 +18,25 @@ #ifndef INCLUDED_SCOLOR #define INCLUDED_SCOLOR -#include "lib/types.h" - // SColor3ub: structure for packed RGB colors struct SColor3ub { - u8 R; - u8 G; - u8 B; + std::uint8_t R; + std::uint8_t G; + std::uint8_t B; }; // SColor4ub: structure for packed RGBA colors struct SColor4ub { - u8 R; - u8 G; - u8 B; - u8 A; + std::uint8_t R; + std::uint8_t G; + std::uint8_t B; + std::uint8_t A; SColor4ub() { } - SColor4ub(u8 _r, u8 _g, u8 _b, u8 _a) : R(_r), G(_g), B(_b), A(_a) { } + SColor4ub(std::uint8_t _r, std::uint8_t _g, std::uint8_t _b, std::uint8_t _a) : + R(_r), G(_g), B(_b), A(_a) { } }; #endif diff --git a/source/graphics/TerrainProperties.cpp b/source/graphics/TerrainProperties.cpp index 3e41755956..5453871a74 100644 --- a/source/graphics/TerrainProperties.cpp +++ b/source/graphics/TerrainProperties.cpp @@ -128,11 +128,11 @@ void CTerrainProperties::LoadXml(XMBElement node, CXeromyces *pFile, const VfsPa continue; // m_BaseColor is BGRA - u8 *baseColor = (u8*)&m_BaseColor; - baseColor[0] = (u8)(col.b*255); - baseColor[1] = (u8)(col.g*255); - baseColor[2] = (u8)(col.r*255); - baseColor[3] = (u8)(col.a*255); + std::uint8_t* baseColor = reinterpret_cast(&m_BaseColor); + baseColor[0] = static_cast(col.b * 255); + baseColor[1] = static_cast(col.g * 255); + baseColor[2] = static_cast(col.r * 255); + baseColor[3] = static_cast(col.a * 255); m_HasBaseColor = true; } else if (attr.Name == attr_angle) diff --git a/source/graphics/TerrainTextureManager.cpp b/source/graphics/TerrainTextureManager.cpp index df5df91911..183a969537 100644 --- a/source/graphics/TerrainTextureManager.cpp +++ b/source/graphics/TerrainTextureManager.cpp @@ -198,7 +198,7 @@ CTerrainTextureManager::LoadAlphaMap(const VfsPath& alphaMapType) { // note: these individual textures can be discarded afterwards; // we cache the composite. - std::shared_ptr fileData; + std::shared_ptr fileData; size_t fileSize; if (g_VFS->LoadFile(path / fnames[i], fileData, fileSize) != INFO::OK || textures[i].decode(fileData, fileSize) != INFO::OK) @@ -233,19 +233,19 @@ CTerrainTextureManager::LoadAlphaMap(const VfsPath& alphaMapType) const size_t tileWidth = 2 + base + 2; // 2 pixel border (avoids bilinear filtering artifacts) const size_t totalWidth = std::bit_ceil(tileWidth * NUM_ALPHA_MAPS); const size_t totalHeight = base; ENSURE(std::has_single_bit(totalHeight)); - std::shared_ptr data; + std::shared_ptr data; AllocateAligned(data, totalWidth * totalHeight, maxSectorSize); // for each tile on row for (size_t i = 0; i < NUM_ALPHA_MAPS; ++i) { // get src of copy - u8* src = textures[i].get_data(); + std::uint8_t* src = textures[i].get_data(); ENSURE(src); const size_t srcStep = bpp / 8; // get destination of copy - u8* dst = data.get() + (i * tileWidth); + std::uint8_t* dst = data.get() + (i * tileWidth); // for each row of image for (size_t j = 0; j < base; ++j) @@ -292,7 +292,7 @@ CTerrainTextureManager::LoadAlphaMap(const VfsPath& alphaMapType) // write to disk //Status ret = INFO::OK; { - std::shared_ptr file = DummySharedPtr(da.base); + std::shared_ptr file = DummySharedPtr(da.base); const ssize_t bytes_written = g_VFS->CreateFile(filename, file, da.pos); if (bytes_written > 0) ENSURE(bytes_written == (ssize_t)da.pos); diff --git a/source/graphics/TerrainTextureManager.h b/source/graphics/TerrainTextureManager.h index 5521b53db7..4fa2538694 100644 --- a/source/graphics/TerrainTextureManager.h +++ b/source/graphics/TerrainTextureManager.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_TERRAINTEXTUREMANAGER #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "ps/CStr.h" #include "ps/Loader.h" #include "ps/Singleton.h" @@ -75,7 +74,7 @@ struct TerrainAlpha // Composite alpha map (all the alpha maps packed into one texture). std::unique_ptr m_CompositeAlphaMap; // Data is used to separate file loading and uploading to GPU. - std::shared_ptr m_CompositeDataToUpload; + std::shared_ptr m_CompositeDataToUpload; // Coordinates of each (untransformed) alpha map within the packed texture. struct { diff --git a/source/graphics/TerritoryBoundary.cpp b/source/graphics/TerritoryBoundary.cpp index dc370d72b9..495715ef4c 100644 --- a/source/graphics/TerritoryBoundary.cpp +++ b/source/graphics/TerritoryBoundary.cpp @@ -27,12 +27,13 @@ #include -std::vector CTerritoryBoundaryCalculator::ComputeBoundaries(const Grid* territory) +std::vector CTerritoryBoundaryCalculator::ComputeBoundaries( + const Grid* territory) { std::vector boundaries; // Copy the territories grid so we can mess with it - Grid grid(*territory); + Grid grid(*territory); // Some constants for the border walk CVector2D edgeOffsets[] = { @@ -43,10 +44,10 @@ std::vector CTerritoryBoundaryCalculator::ComputeBoundaries( }; // syntactic sugar - const u8 TILE_BOTTOM = 0; - const u8 TILE_RIGHT = 1; - const u8 TILE_TOP = 2; - const u8 TILE_LEFT = 3; + const std::uint8_t TILE_BOTTOM = 0; + const std::uint8_t TILE_RIGHT = 1; + const std::uint8_t TILE_TOP = 2; + const std::uint8_t TILE_LEFT = 3; const int CURVE_CW = -1; const int CURVE_CCW = 1; @@ -95,8 +96,8 @@ std::vector CTerritoryBoundaryCalculator::ComputeBoundaries( { // saved tile state; from MSB to LSB: // processed bit, blinking bit, player ID - u8 tileState = grid.get(i, j); - u8 tileDiscr = (tileState & TERRITORY_DISCR_MASK); + std::uint8_t tileState = grid.get(i, j); + std::uint8_t tileDiscr = (tileState & TERRITORY_DISCR_MASK); // ignore neutral tiles (note that tiles without an owner should never have the blinking bit set) if (!tileDiscr) @@ -119,9 +120,9 @@ std::vector CTerritoryBoundaryCalculator::ComputeBoundaries( boundaries.back().blinking = (tileState & ICmpTerritoryManager::TERRITORY_BLINKING_MASK) != 0; std::vector& points = boundaries.back().points; - u8 dir = TILE_BOTTOM; + std::uint8_t dir = TILE_BOTTOM; - u8 cdir = dir; + std::uint8_t cdir = dir; u16 ci = i, cj = j; u16 maxi = (u16)(grid.m_W-1); diff --git a/source/graphics/TerritoryBoundary.h b/source/graphics/TerritoryBoundary.h index 2280ad048d..284f368ddb 100644 --- a/source/graphics/TerritoryBoundary.h +++ b/source/graphics/TerritoryBoundary.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 @@ #ifndef INCLUDED_TERRITORYBOUNDARY #define INCLUDED_TERRITORYBOUNDARY -#include "lib/types.h" #include "maths/Vector2D.h" #include "simulation2/helpers/Player.h" @@ -62,7 +61,7 @@ public: * boundaries have them in CW order (because this matches the winding orders needed by the renderer to offset them * inwards/outwards appropriately). */ - static std::vector ComputeBoundaries(const Grid* territories); + static std::vector ComputeBoundaries(const Grid* territories); }; #endif // INCLUDED_TERRITORYBOUNDARY diff --git a/source/graphics/TerritoryTexture.cpp b/source/graphics/TerritoryTexture.cpp index a4485e76de..889211cf4c 100644 --- a/source/graphics/TerritoryTexture.cpp +++ b/source/graphics/TerritoryTexture.cpp @@ -105,7 +105,8 @@ void CTerritoryTexture::ConstructTexture(Renderer::Backend::IDeviceCommandContex // Initialise texture with transparency, for the areas we don't // overwrite with uploading later. - std::unique_ptr texData = std::make_unique(textureSize * textureSize * 4); + std::unique_ptr texData = std::make_unique(textureSize * + textureSize * 4); memset(texData.get(), 0x00, textureSize * textureSize * 4); deviceCommandContext->UploadTexture( m_Texture.get(), Renderer::Backend::Format::R8G8B8A8_UNORM, @@ -159,7 +160,7 @@ void CTerritoryTexture::RecomputeTexture(Renderer::Backend::IDeviceCommandContex if (!cmpTerritoryManager || !cmpTerritoryManager->IsVisible()) return; - std::unique_ptr bitmap = std::make_unique(m_MapSize * m_MapSize * 4); + std::unique_ptr bitmap = std::make_unique(m_MapSize * m_MapSize * 4); GenerateBitmap(cmpTerritoryManager->GetTerritoryGrid(), bitmap.get(), m_MapSize, m_MapSize); deviceCommandContext->UploadTextureRegion( @@ -167,7 +168,8 @@ void CTerritoryTexture::RecomputeTexture(Renderer::Backend::IDeviceCommandContex 0, 0, m_MapSize, m_MapSize); } -void CTerritoryTexture::GenerateBitmap(const Grid& territories, u8* bitmap, ssize_t w, ssize_t h) +void CTerritoryTexture::GenerateBitmap(const Grid& territories, std::uint8_t* bitmap, + ssize_t w, ssize_t h) { int alphaMax = 0xC0; int alphaFalloff = 0x20; @@ -185,11 +187,11 @@ void CTerritoryTexture::GenerateBitmap(const Grid& territories, u8* bitmap, colors.push_back(color); } - u8* p = bitmap; + std::uint8_t* p = bitmap; for (ssize_t j = 0; j < h; ++j) for (ssize_t i = 0; i < w; ++i) { - u8 val = territories.get(i, j) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK; + std::uint8_t val = territories.get(i, j) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK; CColor color(1, 0, 1, 1); if (val < colors.size()) diff --git a/source/graphics/TerritoryTexture.h b/source/graphics/TerritoryTexture.h index 2efa76fc61..943510794b 100644 --- a/source/graphics/TerritoryTexture.h +++ b/source/graphics/TerritoryTexture.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -17,7 +17,6 @@ #include "lib/code_annotation.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include @@ -77,7 +76,8 @@ private: void ConstructTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); void RecomputeTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); - void GenerateBitmap(const Grid& territories, u8* bitmap, ssize_t w, ssize_t h); + void GenerateBitmap(const Grid& territories, std::uint8_t* bitmap, ssize_t w, + ssize_t h); CSimulation2& m_Simulation; diff --git a/source/graphics/TextureConverter.cpp b/source/graphics/TextureConverter.cpp index 66e0633809..7b57ec0d24 100644 --- a/source/graphics/TextureConverter.cpp +++ b/source/graphics/TextureConverter.cpp @@ -26,7 +26,6 @@ #include "lib/regex.h" #include "lib/status.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include "maths/MD5.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -72,7 +71,7 @@ constexpr size_t MAX_QUEUE_SIZE_FOR_OPTIMAL_UTILIZATION{12}; */ struct BufferOutputHandler : public nvtt::OutputHandler { - std::vector buffer; + std::vector buffer; virtual void beginImage(int /*size*/, int /*width*/, int /*height*/, int /*depth*/, int /*face*/, int /*miplevel*/) @@ -121,14 +120,14 @@ struct CTextureConverter::ConversionResult void CTextureConverter::Settings::Hash(MD5& hash) { - hash.Update((const u8*)&format, sizeof(format)); - hash.Update((const u8*)&mipmap, sizeof(mipmap)); - hash.Update((const u8*)&normal, sizeof(normal)); - hash.Update((const u8*)&alpha, sizeof(alpha)); - hash.Update((const u8*)&filter, sizeof(filter)); - hash.Update((const u8*)&kaiserWidth, sizeof(kaiserWidth)); - hash.Update((const u8*)&kaiserAlpha, sizeof(kaiserAlpha)); - hash.Update((const u8*)&kaiserStretch, sizeof(kaiserStretch)); + hash.Update(reinterpret_cast(&format), sizeof(format)); + hash.Update(reinterpret_cast(&mipmap), sizeof(mipmap)); + hash.Update(reinterpret_cast(&normal), sizeof(normal)); + hash.Update(reinterpret_cast(&alpha), sizeof(alpha)); + hash.Update(reinterpret_cast(&filter), sizeof(filter)); + hash.Update(reinterpret_cast(&kaiserWidth), sizeof(kaiserWidth)); + hash.Update(reinterpret_cast(&kaiserAlpha), sizeof(kaiserAlpha)); + hash.Update(reinterpret_cast(&kaiserStretch), sizeof(kaiserStretch)); } CTextureConverter::SettingsFile* CTextureConverter::LoadSettings(const VfsPath& path) const @@ -327,7 +326,7 @@ CTextureConverter::~CTextureConverter() = default; bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath& src, const VfsPath& dest, const Settings& settings) { - std::shared_ptr file; + std::shared_ptr file; size_t fileSize; if (m_VFS->LoadFile(src, file, fileSize) < 0) { @@ -377,7 +376,7 @@ bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath if (hasAlpha) { hasAlpha = false; - u8* data = tex.get_data(); + std::uint8_t* data = tex.get_data(); for (size_t i = 0; i < tex.m_Width * tex.m_Height; ++i) { if (data[i*4+3] != 0xFF) @@ -459,9 +458,9 @@ bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath else // bpp == 8 { // NVTT requires 32-bit input data, so convert - const u8* input = tex.get_data(); - u8* rgba = new u8[tex.m_Width * tex.m_Height * 4]; - u8* p = rgba; + const std::uint8_t* input = tex.get_data(); + std::uint8_t* rgba = new std::uint8_t[tex.m_Width * tex.m_Height * 4]; + std::uint8_t* p = rgba; for (size_t i = 0; i < tex.m_Width * tex.m_Height; i++) { p[0] = p[1] = p[2] = p[3] = *input++; @@ -518,7 +517,7 @@ bool CTextureConverter::Poll(CTexturePtr& texture, VfsPath& dest, bool& ok) // Move output into a correctly-aligned buffer size_t size = result->output.buffer.size(); - std::shared_ptr file; + std::shared_ptr file; AllocateAligned(file, size, maxSectorSize); memcpy(file.get(), &result->output.buffer[0], size); if (m_VFS->CreateFile(result->dest, {file.get(), size}) < 0) diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index 208665b90d..a233fd24dc 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -184,7 +184,7 @@ public: const SColor4ub color32 = m_Color.AsSColor4ub(); // Construct 1x1 32-bit texture - const u8 data[4] = + const std::uint8_t data[4] = { color32.R, color32.G, @@ -232,7 +232,7 @@ public: const SColor4ub color32 = m_Color.AsSColor4ub(); // Construct 1x1 32-bit texture - const u8 data[4] = + const std::uint8_t data[4] = { color32.R, color32.G, @@ -293,7 +293,7 @@ public: if (!GetTexture() || !GetTexture()->GetBackendTexture()) return; - std::array, WIDTH> data; + std::array, WIDTH> data; for (uint32_t x = 0; x < WIDTH; ++x) { const float t = static_cast(x) / (WIDTH - 1); @@ -472,7 +472,7 @@ public: PROFILE2("load texture"); PROFILE2_ATTR("name: %ls", path.string().c_str()); - std::shared_ptr fileData; + std::shared_ptr fileData; size_t fileSize; const Status loadStatus = m_VFS->LoadFile(path, fileData, fileSize); if (loadStatus != INFO::OK) diff --git a/source/graphics/tests/test_LOSTexture.h b/source/graphics/tests/test_LOSTexture.h index 446e51a3f9..a882e757f2 100644 --- a/source/graphics/tests/test_LOSTexture.h +++ b/source/graphics/tests/test_LOSTexture.h @@ -52,8 +52,8 @@ public: }; Grid inputDataVec(size, size); - for (u8 i = 0; i < size; ++i) - for (u8 j = 0; j < size; ++j) + for (std::uint8_t i = 0; i < size; ++i) + for (std::uint8_t j = 0; j < size; ++j) inputDataVec.set(i, j, inputData[i + j * size]); // LosState::MASK should be cmpRanageManager->GetSharedLosMask(1), @@ -61,7 +61,7 @@ public: // should always be LosState::MASK for player 1 (as the other players are bit-shifted). CLosQuerier los((u32)LosState::MASK, inputDataVec, size); - std::vector losData; + std::vector losData; size_t pitch; losData.resize(tex.GetBitmapSize(size, size, &pitch)); @@ -90,7 +90,7 @@ public: double t = timer_Time(); for (size_t i = 0; i < reps; ++i) { - std::vector losData; + std::vector losData; size_t pitch; losData.resize(tex.GetBitmapSize(size, size, &pitch)); diff --git a/source/graphics/tests/test_MeshManager.h b/source/graphics/tests/test_MeshManager.h index eca06721df..de4c4df251 100644 --- a/source/graphics/tests/test_MeshManager.h +++ b/source/graphics/tests/test_MeshManager.h @@ -28,7 +28,6 @@ #include "lib/os_path.h" #include "lib/path.h" #include "lib/secure_crt.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "ps/XML/RelaxNG.h" @@ -82,7 +81,7 @@ class TestMeshManager : public CxxTest::TestSuite void copyFile(const VfsPath& src, const VfsPath& dst) { // Copy a file into the mod directory, so we can work on it: - std::unique_ptr data; size_t size = 0; + std::unique_ptr data; size_t size = 0; TS_ASSERT_OK(g_VFS->LoadFile(src, data, size)); TS_ASSERT_OK(g_VFS->CreateFile(dst, {data.get(), size})); } @@ -91,7 +90,7 @@ class TestMeshManager : public CxxTest::TestSuite { // Create a junk trace file first, because vfs_opt_auto_build requires one // std::string trace = "000.000000: L \"-\" 0 0000\n"; -// vfs_store("trace.txt", (const u8*)trace.c_str(), trace.size(), FILE_NO_AIO); +// vfs_store("trace.txt", static_cast(trace.c_str()), trace.size(), FILE_NO_AIO); // then make the archive // TS_ASSERT_OK(vfs_opt_rebuild_main_archive(MOD_PATH"/trace.txt", MOD_PATH"/test%02d.zip")); @@ -120,7 +119,7 @@ public: { copyFile(srcDAE, testDAE); //buildArchive(); - std::shared_ptr buf; + std::shared_ptr buf; AllocateAligned(buf, 100, maxSectorSize); strcpy_s((char*)buf.get(), 5, "Test"); g_VFS->CreateFile(testDAE, {buf.get(), 4}); @@ -186,7 +185,7 @@ public: TestLogger logger; copyFile(srcDAE, testDAE); - std::shared_ptr buf; + std::shared_ptr buf; AllocateAligned(buf, 100, maxSectorSize); strcpy_s((char*)buf.get(), 100, "Not valid XML"); g_VFS->CreateFile(testSkeletonDefs, {buf.get(), 13}); @@ -201,7 +200,7 @@ public: TestLogger logger; copyFile(srcSkeletonDefs, testSkeletonDefs); - std::shared_ptr buf; + std::shared_ptr buf; AllocateAligned(buf, 100, maxSectorSize); strcpy_s((char*)buf.get(), 100, "Not valid XML"); g_VFS->CreateFile(testDAE, {buf.get(), 13}); diff --git a/source/graphics/tests/test_TextureConverter.h b/source/graphics/tests/test_TextureConverter.h index e57c6d58a3..d82a8f6666 100644 --- a/source/graphics/tests/test_TextureConverter.h +++ b/source/graphics/tests/test_TextureConverter.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 @@ -23,7 +23,6 @@ #include "lib/file/vfs/vfs.h" #include "lib/path.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "ps/XMB/XMBStorage.h" @@ -77,7 +76,7 @@ public: SDL_Delay(10); } - std::shared_ptr file; + std::shared_ptr file; size_t fileSize = 0; TS_ASSERT_OK(m_VFS->LoadFile(dest, file, fileSize)); @@ -86,7 +85,7 @@ public: TS_ASSERT_OK(tex.transform_to((tex.m_Flags | TEX_BGR | TEX_ALPHA) & ~(TEX_DXT | TEX_MIPMAPS))); - u8* texdata = tex.get_data(); + std::uint8_t* texdata = tex.get_data(); // The source texture is repeated after 4 pixels, so the compressed texture // should be identical after 4 pixels diff --git a/source/gui/SettingTypes/MouseEventMask.cpp b/source/gui/SettingTypes/MouseEventMask.cpp index d7b3140e26..7461286874 100644 --- a/source/gui/SettingTypes/MouseEventMask.cpp +++ b/source/gui/SettingTypes/MouseEventMask.cpp @@ -25,7 +25,6 @@ #include "lib/path.h" #include "lib/status.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include "maths/Rect.h" #include "maths/Vector2D.h" #include "ps/CLogger.h" @@ -91,7 +90,7 @@ public: static std::unique_ptr Create(const std::string_view spec) { - std::shared_ptr shapeFile; + std::shared_ptr shapeFile; CCacheLoader loader(g_VFS, L".dds"); VfsPath sourcePath = VfsPath("art") / L"textures" / L"ui" / std::string{spec.substr(specOffset)}; @@ -130,7 +129,8 @@ public: 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 (u8* ptr = tex.get_data(); ptr < tex.get_data() + tex.m_DataSize; ptr += tex.m_Bpp/8) + for (std::uint8_t* ptr = tex.get_data(); ptr < tex.get_data() + tex.m_DataSize; + ptr += tex.m_Bpp/8) { if (tex.m_Bpp == 32) mask->m_Data.push_back(*(ptr + 3) > 0); diff --git a/source/lib/allocators/dynarray.cpp b/source/lib/allocators/dynarray.cpp index 72806972aa..62c7ddea31 100644 --- a/source/lib/allocators/dynarray.cpp +++ b/source/lib/allocators/dynarray.cpp @@ -41,7 +41,7 @@ static Status validate_da(DynArray* da) { if(!da) WARN_RETURN(ERR::INVALID_POINTER); -// u8* const base = da->base; +// std::uint8_t* const base = da->base; const size_t max_size_pa = da->max_size_pa; const size_t cur_size = da->cur_size; const size_t pos = da->pos; @@ -69,7 +69,7 @@ Status da_alloc(DynArray* da, size_t max_size) ENSURE(max_size != 0); const size_t max_size_pa = Align(max_size); - u8* p = (u8*)vm::ReserveAddressSpace(max_size_pa); + std::uint8_t* p = static_cast(vm::ReserveAddressSpace(max_size_pa)); if(!p) return ERR::NO_MEM; // NOWARN (already done in vm) @@ -111,7 +111,7 @@ Status da_set_size(DynArray* da, size_t new_size) if(new_size_pa > da->max_size_pa) return ERR::LIMIT; // NOWARN - u8* end = da->base + cur_size_pa; + std::uint8_t* end = da->base + cur_size_pa; bool ok = true; // expanding if(size_delta_pa > 0) diff --git a/source/lib/allocators/dynarray.h b/source/lib/allocators/dynarray.h index 0a21c3ecab..a46aabdcc2 100644 --- a/source/lib/allocators/dynarray.h +++ b/source/lib/allocators/dynarray.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -28,7 +28,6 @@ #define INCLUDED_ALLOCATORS_DYNARRAY #include "lib/status.h" -#include "lib/types.h" #include @@ -41,7 +40,7 @@ **/ struct DynArray { - u8* base; + std::uint8_t* base; size_t max_size_pa; /// reserved size_t cur_size; /// committed size_t cur_size_pa; diff --git a/source/lib/allocators/pool.cpp b/source/lib/allocators/pool.cpp index 8ef3a213b8..d154a2f6bc 100644 --- a/source/lib/allocators/pool.cpp +++ b/source/lib/allocators/pool.cpp @@ -30,7 +30,6 @@ #include "lib/alignment.h" #include "lib/allocators/freelist.h" -#include "lib/types.h" #include @@ -110,7 +109,7 @@ bool pool_contains(const Pool* p, void* el) return false; // sanity check: it should be aligned (if pool has fixed-size elements) if(p->el_size) - ENSURE((uintptr_t)((u8*)el - p->da.base) % p->el_size == 0); + ENSURE(static_cast(static_cast(el) - p->da.base) % p->el_size == 0); return true; } diff --git a/source/lib/allocators/tests/test_DynamicArena.h b/source/lib/allocators/tests/test_DynamicArena.h index 49c528fc4d..9760ae3b2b 100644 --- a/source/lib/allocators/tests/test_DynamicArena.h +++ b/source/lib/allocators/tests/test_DynamicArena.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -23,7 +23,6 @@ #include "lib/self_test.h" #include "lib/allocators/DynamicArena.h" -#include "lib/types.h" class TestDynamicArena : public CxxTest::TestSuite { @@ -31,7 +30,7 @@ public: void test_allocate() { Allocators::DynamicArena<100> testArena; - u8* p = static_cast(testArena.allocate(10, 1)); + std::uint8_t* p = static_cast(testArena.allocate(10, 1)); TS_ASSERT(p != nullptr); void* p2 = testArena.allocate(10, 1); TS_ASSERT(p + 10 == p2); @@ -55,22 +54,22 @@ public: void test_alignment() { Allocators::DynamicArena<100> testArena; - u8* p = static_cast(testArena.allocate(4, 1)); + std::uint8_t* p = static_cast(testArena.allocate(4, 1)); TS_ASSERT(p != nullptr); - u8* p2 = static_cast(testArena.allocate(1, 8)); + std::uint8_t* p2 = static_cast(testArena.allocate(1, 8)); TS_ASSERT_EQUALS(p + 8, p2); - p2 = static_cast(testArena.allocate(1, 8)); + p2 = static_cast(testArena.allocate(1, 8)); TS_ASSERT_EQUALS(p + 16, p2); - p2 = static_cast(testArena.allocate(1, 8)); + p2 = static_cast(testArena.allocate(1, 8)); TS_ASSERT_EQUALS(p + 24, p2); - p2 = static_cast(testArena.allocate(1, 2)); + p2 = static_cast(testArena.allocate(1, 2)); TS_ASSERT_EQUALS(p + 26, p2); - p2 = static_cast(testArena.allocate(1, 8)); + p2 = static_cast(testArena.allocate(1, 8)); TS_ASSERT_EQUALS(p + 32, p2); } }; diff --git a/source/lib/app_hooks.cpp b/source/lib/app_hooks.cpp index 8868999b40..2190ce994c 100644 --- a/source/lib/app_hooks.cpp +++ b/source/lib/app_hooks.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -25,7 +25,6 @@ #include "app_hooks.h" #include "lib/sysdep/sysdep.h" -#include "lib/types.h" #include @@ -87,8 +86,8 @@ void app_hooks_update(const AppHooks& new_ah) bool app_hook_was_redefined(size_t offset_in_struct) { - const u8* ah_bytes = (const u8*)&ah; - const u8* default_ah_bytes = (const u8*)&default_ah; + const std::uint8_t* ah_bytes = reinterpret_cast(&ah); + const std::uint8_t* default_ah_bytes = reinterpret_cast(&default_ah); typedef void(*FP)(); // a bit safer than comparing void* pointers if(*(FP)(ah_bytes+offset_in_struct) != *(FP)(default_ah_bytes+offset_in_struct)) return true; diff --git a/source/lib/byte_order.cpp b/source/lib/byte_order.cpp index 5660d84953..e7d2cc9180 100644 --- a/source/lib/byte_order.cpp +++ b/source/lib/byte_order.cpp @@ -149,7 +149,7 @@ void write_be64(void* p, u64 x) } -u64 movzx_le64(const u8* p, size_t size_bytes) +u64 movzx_le64(const std::uint8_t* p, size_t size_bytes) { u64 number = 0; for(size_t i = 0; i < std::min(size_bytes, (size_t)8u); i++) @@ -158,7 +158,7 @@ u64 movzx_le64(const u8* p, size_t size_bytes) return number; } -u64 movzx_be64(const u8* p, size_t size_bytes) +u64 movzx_be64(const std::uint8_t* p, size_t size_bytes) { u64 number = 0; for(size_t i = 0; i < std::min(size_bytes, (size_t)8u); i++) @@ -191,13 +191,13 @@ static inline std::int64_t SignExtend(u64 bits, size_t size_bytes) return number; } -std::int64_t movsx_le64(const u8* p, size_t size_bytes) +std::int64_t movsx_le64(const std::uint8_t* p, size_t size_bytes) { const u64 number = movzx_le64(p, size_bytes); return SignExtend(number, size_bytes); } -std::int64_t movsx_be64(const u8* p, size_t size_bytes) +std::int64_t movsx_be64(const std::uint8_t* p, size_t size_bytes) { const u64 number = movzx_be64(p, size_bytes); return SignExtend(number, size_bytes); diff --git a/source/lib/byte_order.h b/source/lib/byte_order.h index d2c3270375..881aab7c6d 100644 --- a/source/lib/byte_order.h +++ b/source/lib/byte_order.h @@ -55,18 +55,20 @@ // - can't pass code as string, and use s[0]..s[3], because // VC6/7 don't realize the macro is constant // (it should be usable as a switch{} expression) -// - the casts are ugly but necessary. u32 is required because u8 << 8 == 0; -// the additional u8 cast ensures each character is treated as unsigned -// (otherwise, they'd be promoted to signed int before the u32 cast, -// which would break things). +// - the casts are ugly but necessary. u32 is required because +// std::uint8_t << 8 == 0; the additional std::uint8_t cast ensures each +// character is treated as unsigned (otherwise, they'd be promoted to signed +// int before the u32 cast, which would break things). /// big-endian version of FOURCC -#define FOURCC_BE(a,b,c,d) ( ((u32)(u8)a) << 24 | ((u32)(u8)b) << 16 | \ - ((u32)(u8)c) << 8 | ((u32)(u8)d) << 0 ) +#define FOURCC_BE(a,b,c,d) ( ((u32)static_cast(a)) << 24 | \ + ((u32)static_cast(b)) << 16 | ((u32)static_cast(c)) << 8 | \ + ((u32)static_cast(d)) << 0 ) /// little-endian version of FOURCC -#define FOURCC_LE(a,b,c,d) ( ((u32)(u8)a) << 0 | ((u32)(u8)b) << 8 | \ - ((u32)(u8)c) << 16 | ((u32)(u8)d) << 24 ) +#define FOURCC_LE(a,b,c,d) ( ((u32)static_cast(a)) << 0 | \ + ((u32)static_cast(b)) << 8 | ((u32)static_cast(c)) << 16 | \ + ((u32)static_cast(d)) << 24 ) #if BYTE_ORDER == BIG_ENDIAN # define FOURCC FOURCC_BE @@ -119,15 +121,15 @@ void write_be64(void* p, u64 x); /// see write_be16 * zero-extend \ (truncated to 8) bytes of little-endian data to u64, * starting at address \ (need not be aligned). **/ -u64 movzx_le64(const u8* p, size_t size); -u64 movzx_be64(const u8* p, size_t size); +u64 movzx_le64(const std::uint8_t* p, size_t size); +u64 movzx_be64(const std::uint8_t* p, size_t size); /** * sign-extend \ (truncated to 8) bytes of little-endian data to * std::int64_t, starting at address \ (need not be aligned). **/ -std::int64_t movsx_le64(const u8* p, size_t size); -std::int64_t movsx_be64(const u8* p, size_t size); +std::int64_t movsx_le64(const std::uint8_t* p, size_t size); +std::int64_t movsx_be64(const std::uint8_t* p, size_t size); #if MSC_VERSION diff --git a/source/lib/debug.cpp b/source/lib/debug.cpp index 5dd1c05994..805e90fb74 100644 --- a/source/lib/debug.cpp +++ b/source/lib/debug.cpp @@ -432,7 +432,7 @@ static bool ShouldSkipError(Status err) ErrorReaction debug_OnError(Status err, std::atomic* suppress, const wchar_t* file, int line, const char* func) { - CACHE_ALIGNED(u8) context[DEBUG_CONTEXT_SIZE]; + CACHE_ALIGNED(std::uint8_t) context[DEBUG_CONTEXT_SIZE]; (void)debug_CaptureContext(context); if(ShouldSkipError(err)) @@ -447,7 +447,7 @@ ErrorReaction debug_OnError(Status err, std::atomic* suppress, const wchar ErrorReaction debug_OnAssertionFailure(const wchar_t* expr, std::atomic* suppress, const wchar_t* file, int line, const char* func) { - CACHE_ALIGNED(u8) context[DEBUG_CONTEXT_SIZE]; + CACHE_ALIGNED(std::uint8_t) context[DEBUG_CONTEXT_SIZE]; (void)debug_CaptureContext(context); const wchar_t* lastFuncToSkip = L"debug_OnAssertionFailure"; diff --git a/source/lib/debug.h b/source/lib/debug.h index 185369d79f..09ade0af4e 100644 --- a/source/lib/debug.h +++ b/source/lib/debug.h @@ -40,7 +40,6 @@ #include "lib/code_annotation.h" #include "lib/status.h" #include "lib/sysdep/compiler.h" -#include "lib/types.h" #include #include @@ -184,7 +183,7 @@ ErrorReaction debug_DisplayError(const wchar_t* description, size_t flags, void* #define DEBUG_DISPLAY_ERROR_IMPL(description, flags)\ do\ {\ - CACHE_ALIGNED(u8) context[DEBUG_CONTEXT_SIZE];\ + CACHE_ALIGNED(std::uint8_t) context[DEBUG_CONTEXT_SIZE];\ (void)debug_CaptureContext(context);\ (void)debug_DisplayError(description, flags, context, L"debug_DisplayError", WIDEN(__FILE__), __LINE__, __func__, 0);\ }\ diff --git a/source/lib/debug_stl.cpp b/source/lib/debug_stl.cpp index 74e0d7a35c..41b09b7fba 100644 --- a/source/lib/debug_stl.cpp +++ b/source/lib/debug_stl.cpp @@ -228,9 +228,10 @@ struct ContainerBase : public Container return this->size(); } - static const u8* DereferenceAndAdvance(typename Container::iterator& it, size_t /*el_size*/) + static const std::uint8_t* DereferenceAndAdvance(typename Container::iterator& it, + size_t /*el_size*/) { - const u8* p = (const u8*)&*it; + const std::uint8_t* p = reinterpret_cast(&*it); ++it; return p; } @@ -254,7 +255,7 @@ struct Any_deque : public ContainerBase > return true; } - static const u8* DereferenceAndAdvance(iterator& stl_it, size_t el_size) + static const std::uint8_t* DereferenceAndAdvance(iterator& stl_it, size_t el_size) { struct Iterator : public iterator { @@ -272,7 +273,7 @@ struct Any_deque : public ContainerBase > Iterator& it = *(Iterator*)&stl_it; Any_deque& container = it.Container(); const size_t currentIndex = it.CurrentIndex(); - const u8* p = container.GetNthElement(currentIndex, el_size); + const std::uint8_t* p = container.GetNthElement(currentIndex, el_size); ++it; return p; } @@ -283,16 +284,16 @@ private: return std::max(16u / el_size, (size_t)1u); // see _DEQUESIZ } - const u8* GetNthElement(size_t i, size_t el_size) const + const std::uint8_t* GetNthElement(size_t i, size_t el_size) const { const size_t el_per_bucket = ElementsPerBucket(el_size); const size_t bucket_idx = i / el_per_bucket; ENSURE(bucket_idx < _Mapsize); const size_t idx_in_bucket = i - bucket_idx * el_per_bucket; ENSURE(idx_in_bucket < el_per_bucket); - const u8** map = (const u8**)_Map; - const u8* bucket = map[bucket_idx]; - const u8* p = bucket + idx_in_bucket*el_size; + const std::uint8_t** map = static_cast(_Map); + const std::uint8_t* bucket = map[bucket_idx]; + const std::uint8_t* p = bucket + idx_in_bucket*el_size; return p; } @@ -324,7 +325,7 @@ struct Any_tree : public std::_Tree<_Traits> return size(); } - static const u8* DereferenceAndAdvance(iterator& stl_it, size_t el_size) + static const std::uint8_t* DereferenceAndAdvance(iterator& stl_it, size_t el_size) { struct Iterator : public const_iterator { @@ -341,7 +342,7 @@ struct Any_tree : public std::_Tree<_Traits> Iterator& it = *(Iterator*)&stl_it; _Nodeptr node = it.Node(); - const u8* p = (const u8*)&*it; + const std::uint8_t* p = static_cast(&*it); // end() shouldn't be incremented, don't move if(_Isnil(node, el_size)) @@ -370,7 +371,7 @@ private: // dependent on el_size. static _Charref _Isnil(_Nodeptr _Pnode, size_t el_size) { - const u8* p = (const u8*)&_Pnode->_Isnil; // correct for int specialization + const std::uint8_t* p = static_cast(&_Pnode->_Isnil); // correct for int specialization p += el_size - sizeof(value_type); // adjust for difference in el_size assert(*p <= 1); // bool value return (_Charref)*p; @@ -421,21 +422,21 @@ struct Any_vector: public ContainerBase > // element count as the difference between them. since we are // derived from a template specialization, the pointer arithmetic // is incorrect. we fix it by taking el_size into account. - return ((u8*)_Mylast - (u8*)_Myfirst) * el_size; + return (static_cast(_Mylast) - static_cast(_Myfirst)) * el_size; } - static const u8* DereferenceAndAdvance(iterator& stl_it, size_t el_size) + static const std::uint8_t* DereferenceAndAdvance(iterator& stl_it, size_t el_size) { struct Iterator : public const_iterator { void Advance(size_t numBytes) { - (u8*&)_Myptr += numBytes; + static_cast(_Myptr) += numBytes; } }; Iterator& it = *(Iterator*)&stl_it; - const u8* p = (const u8*)&*it; + const std::uint8_t* p = static_cast(&*it); it.Advance(el_size); return p; } @@ -485,7 +486,7 @@ struct Any_stack : public Any_deque // generic iterator - returns next element. dereferences and increments the // specific container iterator stored in it_mem. -template const u8* stl_iterator(void* it_mem, size_t el_size) +template const std::uint8_t* stl_iterator(void* it_mem, size_t el_size) { typedef typename T::iterator iterator; iterator& stl_it = *(iterator*)it_mem; @@ -507,7 +508,7 @@ static bool IsContainerValid(const T& t, size_t el_count) if(el_count != 0) { // valid pointer - const u8* front = (const u8*)&*t.begin(); // (note: map doesn't have front) + const std::uint8_t* front = reinterpret_cast(&*t.begin()); // (note: map doesn't have front) if(debug_IsPointerBogus(front)) return false; @@ -552,8 +553,9 @@ template bool get_container_info(const T& t, size_t size, size_t el_siz // return number of elements and an iterator (any data it needs is stored in // it_mem, which must hold DEBUG_STL_MAX_ITERATOR_SIZE bytes). // returns 0 on success or an StlContainerError. -Status debug_stl_get_container_info([[maybe_unused]] const wchar_t* type_name, [[maybe_unused]] const u8* p, - [[maybe_unused]] size_t size, [[maybe_unused]] size_t el_size, [[maybe_unused]] size_t* el_count, +Status debug_stl_get_container_info([[maybe_unused]] const wchar_t* type_name, + [[maybe_unused]] const std::uint8_t* p, [[maybe_unused]] size_t size, + [[maybe_unused]] size_t el_size, [[maybe_unused]] size_t* el_count, [[maybe_unused]] DebugStlIterator* el_iterator, [[maybe_unused]] void* it_mem) { #if MSC_VERSION diff --git a/source/lib/debug_stl.h b/source/lib/debug_stl.h index 9e448bc9df..2d72994cf6 100644 --- a/source/lib/debug_stl.h +++ b/source/lib/debug_stl.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -28,7 +28,6 @@ #define INCLUDED_DEBUG_STL #include "lib/status.h" -#include "lib/types.h" #include @@ -59,7 +58,7 @@ extern wchar_t* debug_stl_simplify_name(wchar_t* name); /** * abstraction of all STL iterators used by debug_stl. **/ -typedef const u8* (*DebugStlIterator)(void* internal, size_t el_size); +typedef const std::uint8_t* (*DebugStlIterator)(void* internal, size_t el_size); /** * no STL iterator is larger than this; see below. @@ -84,7 +83,7 @@ const size_t DEBUG_STL_MAX_ITERATOR_SIZE = 64; * at least DEBUG_STL_MAX_ITERATOR_SIZE bytes. * @return Status (ERR::STL_*) **/ -extern Status debug_stl_get_container_info(const wchar_t* type_name, const u8* p, size_t size, +extern Status debug_stl_get_container_info(const wchar_t* type_name, const std::uint8_t* p, size_t size, size_t el_size, size_t* el_count, DebugStlIterator* el_iterator, void* it_mem); #endif // #ifndef INCLUDED_DEBUG_STL diff --git a/source/lib/file/archive/archive.h b/source/lib/file/archive/archive.h index e94900fd80..7b087b1d6f 100644 --- a/source/lib/file/archive/archive.h +++ b/source/lib/file/archive/archive.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -32,7 +32,6 @@ #include "lib/file/vfs/vfs_path.h" #include "lib/os_path.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -110,7 +109,8 @@ struct IArchiveWriter * @param mtime the last-modified-time to be stored in the archive * @param pathnameInArchive the name to store in the archive **/ - virtual Status AddMemory(const u8* data, size_t size, time_t mtime, const OsPath& pathnameInArchive) = 0; + virtual Status AddMemory(const std::uint8_t* data, size_t size, time_t mtime, + const OsPath& pathnameInArchive) = 0; }; typedef std::shared_ptr PIArchiveWriter; diff --git a/source/lib/file/archive/archive_zip.cpp b/source/lib/file/archive/archive_zip.cpp index d68f4cc9bb..9aa5fd9a3f 100644 --- a/source/lib/file/archive/archive_zip.cpp +++ b/source/lib/file/archive/archive_zip.cpp @@ -336,7 +336,7 @@ public: return m_file->Pathname(); } - Status Load(const OsPath& /*name*/, const std::span buffer) const override + Status Load(const OsPath& /*name*/, const std::span buffer) const override { AdjustOffset(); @@ -384,7 +384,7 @@ private: struct LFH_Copier { - LFH_Copier(u8* lfh_dst, size_t lfh_bytes_remaining) + LFH_Copier(std::uint8_t* lfh_dst, size_t lfh_bytes_remaining) : lfh_dst(lfh_dst), lfh_bytes_remaining(lfh_bytes_remaining) { } @@ -396,7 +396,7 @@ private: // rationale: this allows using temp buffers for zip_fixup_lfh, // which avoids involving the file buffer manager and thus // avoids cluttering the trace and cache contents. - Status operator()(const u8* block, size_t size) const + Status operator()(const std::uint8_t* block, size_t size) const { ENSURE(size <= lfh_bytes_remaining); memcpy(lfh_dst, block, size); @@ -406,7 +406,7 @@ private: return INFO::OK; } - mutable u8* lfh_dst; + mutable std::uint8_t* lfh_dst; mutable size_t lfh_bytes_remaining; }; @@ -431,7 +431,7 @@ private: // previously read file (i.e. both are small). LFH lfh; io::Operation op(*m_file.get(), 0, sizeof(LFH), m_ofs); - if(io::Run(op, io::Parameters(), LFH_Copier((u8*)&lfh, sizeof(LFH))) == INFO::OK) + if(io::Run(op, io::Parameters(), LFH_Copier(reinterpret_cast(&lfh), sizeof(LFH))) == INFO::OK) m_ofs += (off_t)lfh.Size(); } @@ -476,7 +476,7 @@ public: RETURN_STATUS_IF_ERR(io::Run(op)); // iterate over Central Directory - const u8* pos = buf.get(); + const std::uint8_t* pos = buf.get(); for(size_t i = 0; i < cd_numEntries; i++) { // scan for next CDFH @@ -510,11 +510,12 @@ private: * @param recordSize size of record (including signature) * @return pointer to record within buffer or 0 if not found. **/ - static const u8* FindRecord(const u8* buf, size_t size, const u8* start, u32 magic, size_t recordSize) + static const std::uint8_t* FindRecord(const std::uint8_t* buf, size_t size, + const std::uint8_t* start, u32 magic, size_t recordSize) { // (don't use as the counter - otherwise we can't tell if // scanning within the buffer was necessary.) - for(const u8* p = start; p <= buf+size-recordSize; p++) + for(const std::uint8_t* p = start; p <= buf+size-recordSize; p++) { // found it if(*(u32*)p == magic) @@ -533,7 +534,8 @@ private: // search for ECDR in the last bytes of the file. // if found, fill with a copy of the (little-endian) ECDR and // return INFO::OK, otherwise IO error or ERR::CORRUPTED. - static Status ScanForEcdr(const PFile& file, off_t fileSize, u8* buf, size_t maxScanSize, size_t& cd_numEntries, off_t& cd_ofs, size_t& cd_size) + static Status ScanForEcdr(const PFile& file, off_t fileSize, std::uint8_t* buf, size_t maxScanSize, + size_t& cd_numEntries, off_t& cd_ofs, size_t& cd_size) { // don't scan more than the entire file const size_t scanSize = std::min(maxScanSize, size_t(fileSize)); @@ -551,7 +553,7 @@ private: for (off_t commentSize = 0; commentSize <= offsetInBlock && !ecdr; ++commentSize) { - const u8 *pECDRTest = buf + offsetInBlock - commentSize; + const std::uint8_t *pECDRTest = buf + offsetInBlock - commentSize; if (*reinterpret_cast(pECDRTest) == ecdr_magic) { // Signature matches, test whether comment @@ -588,7 +590,8 @@ private: { const size_t maxScanSize = 66000u; // see below io::BufferPtr buf(io::Allocate(maxScanSize)); - Status ret = ScanForEcdr(file, fileSize, static_cast(buf.get()), maxScanSize, cd_numEntries, cd_ofs, cd_size); + Status ret = ScanForEcdr(file, fileSize, static_cast(buf.get()), maxScanSize, + cd_numEntries, cd_ofs, cd_size); if(ret == INFO::OK) return INFO::OK; @@ -668,14 +671,16 @@ public: return AddFileOrMemory(fileInfo, pathnameInArchive, file, NULL); } - Status AddMemory(const u8* data, size_t size, time_t mtime, const OsPath& pathnameInArchive) + Status AddMemory(const std::uint8_t* data, size_t size, time_t mtime, + const OsPath& pathnameInArchive) { CFileInfo fileInfo(pathnameInArchive, size, mtime); return AddFileOrMemory(fileInfo, pathnameInArchive, PFile(), data); } - Status AddFileOrMemory(const CFileInfo& fileInfo, const OsPath& pathnameInArchive, const PFile& file, const u8* data) + Status AddFileOrMemory(const CFileInfo& fileInfo, const OsPath& pathnameInArchive, const PFile& file, + const std::uint8_t* data) { ENSURE((file && !data) || (data && !file)); @@ -714,7 +719,7 @@ public: // read and compress file contents size_t csize; u32 checksum; { - u8* cdata = buf.get() + sizeof(LFH) + pathnameLength; + std::uint8_t* cdata = buf.get() + sizeof(LFH) + pathnameLength; Stream stream(codec); stream.SetOutputBuffer(cdata, csizeMax); StreamFeeder streamFeeder(stream); diff --git a/source/lib/file/archive/codec.h b/source/lib/file/archive/codec.h index b187f89d2f..fc9dd836fb 100644 --- a/source/lib/file/archive/codec.h +++ b/source/lib/file/archive/codec.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -72,7 +72,8 @@ public: * output buffers were used. either or both of these can be zero if * the input size is small or there's not enough output space. **/ - virtual Status Process(const u8* in, size_t inSize, u8* out, size_t outSize, size_t& inConsumed, size_t& outProduced) = 0; + virtual Status Process(const std::uint8_t* in, size_t inSize, std::uint8_t* out, size_t outSize, + size_t& inConsumed, size_t& outProduced) = 0; /** * Flush buffers and make sure all output has been produced. @@ -92,7 +93,7 @@ public: * @return the new checksum. note: after all data has been seen, this is * identical to the what Finish would return. **/ - virtual u32 UpdateChecksum(u32 checksum, const u8* in, size_t inSize) const = 0; + virtual u32 UpdateChecksum(u32 checksum, const std::uint8_t* in, size_t inSize) const = 0; }; typedef std::shared_ptr PICodec; diff --git a/source/lib/file/archive/codec_zlib.cpp b/source/lib/file/archive/codec_zlib.cpp index 06499b520a..0ad4171ce6 100644 --- a/source/lib/file/archive/codec_zlib.cpp +++ b/source/lib/file/archive/codec_zlib.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -37,7 +37,7 @@ class Codec_ZLib : public ICodec { public: - u32 UpdateChecksum([[maybe_unused]] u32 checksum, [[maybe_unused]] const u8* in, + u32 UpdateChecksum([[maybe_unused]] u32 checksum, [[maybe_unused]] const std::uint8_t* in, [[maybe_unused]] size_t inSize) const { #if CODEC_COMPUTE_CHECKSUM @@ -84,7 +84,8 @@ public: return INFO::OK; } - virtual Status Process(const u8* in, size_t inSize, u8* out, size_t outSize, size_t& inConsumed, size_t& outProduced) + virtual Status Process(const std::uint8_t* in, size_t inSize, std::uint8_t* out, size_t outSize, + size_t& inConsumed, size_t& outProduced) { const size_t transferSize = std::min(inSize, outSize); memcpy(out, in, transferSize); @@ -142,7 +143,8 @@ protected: typedef int ZEXPORT (*ZLibFunc)(z_streamp strm, int flush); - Status CallStreamFunc(ZLibFunc func, int flush, const u8* in, const size_t inSize, u8* out, const size_t outSize, size_t& inConsumed, size_t& outProduced) + Status CallStreamFunc(ZLibFunc func, int flush, const std::uint8_t* in, const size_t inSize, + std::uint8_t* out, const size_t outSize, size_t& inConsumed, size_t& outProduced) { m_zs.next_in = (Byte*)in; m_zs.avail_in = (uInt)inSize; @@ -213,7 +215,8 @@ public: return LibError_from_zlib(ret); } - virtual Status Process(const u8* in, size_t inSize, u8* out, size_t outSize, size_t& inConsumed, size_t& outProduced) + virtual Status Process(const std::uint8_t* in, size_t inSize, std::uint8_t* out, size_t outSize, + size_t& inConsumed, size_t& outProduced) { m_checksum = UpdateChecksum(m_checksum, in, inSize); return CodecZLibStream::CallStreamFunc(deflate, 0, in, inSize, out, outSize, inConsumed, outProduced); @@ -272,7 +275,8 @@ public: return LibError_from_zlib(ret); } - virtual Status Process(const u8* in, size_t inSize, u8* out, size_t outSize, size_t& inConsumed, size_t& outProduced) + virtual Status Process(const std::uint8_t* in, size_t inSize, std::uint8_t* out, size_t outSize, + size_t& inConsumed, size_t& outProduced) { const Status ret = CodecZLibStream::CallStreamFunc(inflate, Z_SYNC_FLUSH, in, inSize, out, outSize, inConsumed, outProduced); m_checksum = UpdateChecksum(m_checksum, out, outProduced); diff --git a/source/lib/file/archive/disabled_tests/test_codec_zlib.h b/source/lib/file/archive/disabled_tests/test_codec_zlib.h index 3f4c3533e3..838ccf1e45 100644 --- a/source/lib/file/archive/disabled_tests/test_codec_zlib.h +++ b/source/lib/file/archive/disabled_tests/test_codec_zlib.h @@ -38,23 +38,23 @@ public: // generate random input udata // (limit values to 0..7 so that the udata will actually be compressible) std::mt19937 engine(42); - std::uniform_int_distribution distribution(0x00, 0x07); + std::uniform_int_distribution distribution(0x00, 0x07); const size_t usize = 10000; - u8 udata[usize]; + std::uint8_t udata[usize]; for(size_t i = 0; i < usize; i++) udata[i] = distribution(engine); // compress - u8* cdata; size_t csize; + std::uint8_t* cdata; size_t csize; { boost::shared_ptr compressor_zlib = CreateCompressor_ZLib(); ICodec* c = compressor_zlib.get(); const size_t csizeMax = c->MaxOutputSize(usize); - cdata = new u8[csizeMax]; + cdata = new std::uint8_t[csizeMax]; TS_ASSERT_OK(c->Process(udata, usize, cdata, csizeMax, inConsumed, outProduced)); TS_ASSERT_EQUALS(inConsumed, usize); TS_ASSERT_LESS_THAN_EQUALS(outProduced, csizeMax); - u8* cdata2; + std::uint8_t* cdata2; TS_ASSERT_OK(c->Finish(cdata2, csize, checksum)); TS_ASSERT_EQUALS(cdata, cdata2); TS_ASSERT_EQUALS(csize, outProduced); @@ -64,14 +64,14 @@ public: TS_ASSERT(csize != usize || memcmp(udata, cdata, std::min(usize, csize)) != 0); // decompress - u8 ddata[usize]; + std::uint8_t ddata[usize]; { boost::shared_ptr decompressor_zlib = CreateDecompressor_ZLib(); ICodec* d = decompressor_zlib.get(); TS_ASSERT_OK(decompressor_zlib->Process(cdata, csize, ddata, usize, inConsumed, outProduced)); TS_ASSERT_EQUALS(inConsumed, csize); // ZLib always outputs as much data as possible TS_ASSERT_EQUALS(outProduced, usize); // .. so these figures are correct before Finish() - u8* ddata2; size_t dsize; + std::uint8_t* ddata2; size_t dsize; TS_ASSERT_OK(d->Finish(&ddata2, &dsize, &checksum)); TS_ASSERT_EQUALS(ddata, ddata2); TS_ASSERT_EQUALS(dsize, outProduced); diff --git a/source/lib/file/archive/disabled_tests/test_compression.h b/source/lib/file/archive/disabled_tests/test_compression.h index 1158020e9d..322d6bfed1 100644 --- a/source/lib/file/archive/disabled_tests/test_compression.h +++ b/source/lib/file/archive/disabled_tests/test_compression.h @@ -35,14 +35,14 @@ public: // generate random input data // (limit values to 0..7 so that the data will actually be compressible) std::mt19937 engine(42); - std::uniform_int_distribution distribution(0x00, 0x07); + std::uniform_int_distribution distribution(0x00, 0x07); const size_t data_size = 10000; - u8 data[data_size]; + std::uint8_t data[data_size]; for(size_t i = 0; i < data_size; i++) data[i] = distribution(engine); - u8* cdata; size_t csize; - u8 udata[data_size]; + std::uint8_t* cdata; size_t csize; + std::uint8_t udata[data_size]; // compress uintptr_t c = comp_alloc(CT_COMPRESSION, CM_DEFLATE); @@ -64,7 +64,7 @@ public: comp_set_output(d, udata, data_size); const ssize_t udata_produced = comp_feed(d, cdata, csize); TS_ASSERT(udata_produced >= 0); - u8* udata_final; size_t usize_final; u32 checksum; + std::uint8_t* udata_final; size_t usize_final; u32 checksum; TS_ASSERT_OK(comp_finish(d, &udata_final, &usize_final, &checksum)); TS_ASSERT(udata_produced <= (ssize_t)usize_final); // can't have produced more than total TS_ASSERT_EQUALS(udata_final, udata); // output buffer address is same diff --git a/source/lib/file/archive/stream.cpp b/source/lib/file/archive/stream.cpp index d69157dce1..5949aa21c6 100644 --- a/source/lib/file/archive/stream.cpp +++ b/source/lib/file/archive/stream.cpp @@ -44,7 +44,7 @@ void OutputBufferManager::Reset() m_capacity = 0; } -void OutputBufferManager::SetBuffer(u8* buffer, size_t size) +void OutputBufferManager::SetBuffer(std::uint8_t* buffer, size_t size) { ENSURE(IsAllowableBuffer(buffer, size)); @@ -72,7 +72,7 @@ void OutputBufferManager::AllocateBuffer(size_t size) SetBuffer(m_mem.get(), size); } -bool OutputBufferManager::IsAllowableBuffer(u8* buffer, size_t size) +bool OutputBufferManager::IsAllowableBuffer(std::uint8_t* buffer, size_t size) { // none yet established if(m_buffer == 0 && m_size == 0) @@ -108,19 +108,19 @@ void Stream::AllocateOutputBuffer(size_t outSizeMax) } -void Stream::SetOutputBuffer(u8* out, size_t outSize) +void Stream::SetOutputBuffer(std::uint8_t* out, size_t outSize) { m_outputBufferManager.SetBuffer(out, outSize); } -Status Stream::Feed(const u8* in, size_t inSize) +Status Stream::Feed(const std::uint8_t* in, size_t inSize) { if(m_outProduced == m_outputBufferManager.Size()) // output buffer full; must not call Process return INFO::ALL_COMPLETE; size_t inConsumed, outProduced; - u8* const out = m_outputBufferManager.Buffer() + m_outProduced; + std::uint8_t* const out = m_outputBufferManager.Buffer() + m_outProduced; const size_t outSize = m_outputBufferManager.Size() - m_outProduced; RETURN_STATUS_IF_ERR(m_codec->Process(in, inSize, out, outSize, inConsumed, outProduced)); diff --git a/source/lib/file/archive/stream.h b/source/lib/file/archive/stream.h index 60ea9210ef..78c1b16a50 100644 --- a/source/lib/file/archive/stream.h +++ b/source/lib/file/archive/stream.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -43,7 +43,7 @@ public: OutputBufferManager(); void Reset(); - void SetBuffer(u8* buffer, size_t size); + void SetBuffer(std::uint8_t* buffer, size_t size); /** * allocate a new output buffer. @@ -57,7 +57,7 @@ public: **/ void AllocateBuffer(size_t size); - u8* Buffer() const + std::uint8_t* Buffer() const { return m_buffer; } @@ -68,12 +68,12 @@ public: } private: - bool IsAllowableBuffer(u8* buffer, size_t size); + bool IsAllowableBuffer(std::uint8_t* buffer, size_t size); - u8* m_buffer; + std::uint8_t* m_buffer; size_t m_size; - std::shared_ptr m_mem; + std::shared_ptr m_mem; // size of m_mem. allows reusing previously allocated buffers // (user-specified buffers can't be reused because we have no control // over their lifetime) @@ -86,14 +86,14 @@ class Stream public: Stream(const PICodec& codec); - void SetOutputBuffer(u8* out, size_t outSize); + void SetOutputBuffer(std::uint8_t* out, size_t outSize); void AllocateOutputBuffer(size_t outSizeMax); /** * 'feed' the codec with a data block. **/ - Status Feed(const u8* in, size_t inSize); + Status Feed(const std::uint8_t* in, size_t inSize); Status Finish(); @@ -127,7 +127,7 @@ public: { } - Status operator()(const u8* data, size_t size) const + Status operator()(const std::uint8_t* data, size_t size) const { return stream.Feed(data, size); } diff --git a/source/lib/file/common/file_loader.h b/source/lib/file/common/file_loader.h index 57983769f0..d99f395e6e 100644 --- a/source/lib/file/common/file_loader.h +++ b/source/lib/file/common/file_loader.h @@ -25,7 +25,6 @@ #include "lib/os_path.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -39,7 +38,7 @@ struct IFileLoader virtual wchar_t LocationCode() const = 0; virtual const OsPath& Path() const = 0; - virtual Status Load(const OsPath& name, const std::span buffer) const = 0; + virtual Status Load(const OsPath& name, const std::span buffer) const = 0; }; typedef std::shared_ptr PIFileLoader; diff --git a/source/lib/file/common/real_directory.cpp b/source/lib/file/common/real_directory.cpp index ecd362534f..b37be3b20e 100644 --- a/source/lib/file/common/real_directory.cpp +++ b/source/lib/file/common/real_directory.cpp @@ -48,13 +48,13 @@ RealDirectory::RealDirectory(const OsPath& path, size_t priority, size_t flags) } -/*virtual*/ Status RealDirectory::Load(const OsPath& name, const std::span buffer) const +/*virtual*/ Status RealDirectory::Load(const OsPath& name, const std::span buffer) const { return io::Load(m_path / name, buffer.data(), buffer.size()); } -Status RealDirectory::Store(const OsPath& name, std::span fileContents) +Status RealDirectory::Store(const OsPath& name, std::span fileContents) { return io::Store(m_path / name, fileContents.data(), fileContents.size()); } diff --git a/source/lib/file/common/real_directory.h b/source/lib/file/common/real_directory.h index 4be7b9b963..78f8813426 100644 --- a/source/lib/file/common/real_directory.h +++ b/source/lib/file/common/real_directory.h @@ -28,7 +28,6 @@ #include "lib/os_path.h" #include "lib/status.h" #include "lib/sysdep/dir_watch.h" -#include "lib/types.h" #include #include @@ -57,9 +56,9 @@ public: { return m_path; } - Status Load(const OsPath& name, const std::span buffer) const override; + Status Load(const OsPath& name, const std::span buffer) const override; - Status Store(const OsPath& name, std::span fileContents); + Status Store(const OsPath& name, std::span fileContents); void Watch(); diff --git a/source/lib/file/io/io.h b/source/lib/file/io/io.h index d0e71e5a29..70bc7a103a 100644 --- a/source/lib/file/io/io.h +++ b/source/lib/file/io/io.h @@ -41,7 +41,6 @@ #include "lib/sysdep/filesystem.h" #include "lib/sysdep/os.h" #include "lib/sysdep/rtl.h" -#include "lib/types.h" #include #include @@ -64,7 +63,7 @@ struct FreeAligned void operator()(void* pointer) { rtl_FreeAligned(pointer); } }; -using BufferPtr = std::unique_ptr; +using BufferPtr = std::unique_ptr; // @return memory suitable for use as an I/O buffer (address is a // multiple of alignment, size is rounded up to a multiple of alignment) @@ -77,7 +76,8 @@ static inline io::BufferPtr Allocate(size_t size, size_t alignment = maxSectorSi ENSURE(std::has_single_bit(alignment)); alignment = std::max(alignment, allocationAlignment); - u8* p = static_cast(rtl_AllocateAligned(round_up(size, alignment), alignment)); + std::uint8_t* p = static_cast(rtl_AllocateAligned(round_up(size, alignment), + alignment)); return {p, FreeAligned{}}; } @@ -180,7 +180,7 @@ struct DefaultCompletedHook * allows progress notification and processing data while waiting for * previous I/Os to complete. **/ - Status operator()(const u8* /*block*/, size_t /*blockSize*/) const + Status operator()(const std::uint8_t* /*block*/, size_t /*blockSize*/) const { return INFO::OK; } @@ -287,7 +287,8 @@ static inline Status Run(const Operation& op, const Parameters& p = Parameters() aiocb& cb = controlBlockRingBuffer[blocksCompleted]; RETURN_STATUS_IF_ERR(WaitUntilComplete(cb, p.queueDepth)); - RETURN_STATUS_FROM_CALLBACK(completedHook((u8*)cb.aio_buf, cb.aio_nbytes)); + RETURN_STATUS_FROM_CALLBACK(completedHook(const_cast( + reinterpret_cast(cb.aio_buf)), cb.aio_nbytes)); } #if ENABLE_IO_STATS diff --git a/source/lib/file/io/write_buffer.cpp b/source/lib/file/io/write_buffer.cpp index a2b4081013..5e096f02bf 100644 --- a/source/lib/file/io/write_buffer.cpp +++ b/source/lib/file/io/write_buffer.cpp @@ -38,8 +38,10 @@ static const size_t BLOCK_SIZE = 512*KiB; -WriteBuffer::WriteBuffer() - : m_capacity(g_PageSize), m_data((u8*)rtl_AllocateAligned(m_capacity, maxSectorSize), AlignedDeleter()), m_size(0) +WriteBuffer::WriteBuffer() : + m_capacity{g_PageSize}, + m_data{static_cast(rtl_AllocateAligned(m_capacity, maxSectorSize)), AlignedDeleter()}, + m_size{0} { } @@ -49,7 +51,7 @@ void WriteBuffer::EnsureSufficientCapacity(size_t size) if(m_size + size > m_capacity) { m_capacity = std::bit_ceil(m_size + size); - std::shared_ptr newData; + std::shared_ptr newData; AllocateAligned(newData, m_capacity, maxSectorSize); memcpy(newData.get(), m_data.get(), m_size); m_data = newData; @@ -84,8 +86,10 @@ void WriteBuffer::Overwrite(const void* data, size_t size, size_t offset) // UnalignedWriter //----------------------------------------------------------------------------- -UnalignedWriter::UnalignedWriter(const PFile& file, off_t ofs) - : m_file(file), m_alignedBuf((u8*)rtl_AllocateAligned(BLOCK_SIZE, maxSectorSize), AlignedDeleter()) +UnalignedWriter::UnalignedWriter(const PFile& file, off_t ofs) : + m_file{file}, + m_alignedBuf{static_cast(rtl_AllocateAligned(BLOCK_SIZE, maxSectorSize)), + AlignedDeleter()} { m_alignedOfs = round_down(ofs, (off_t)BLOCK_SIZE); const size_t misalignment = (size_t)(ofs - m_alignedOfs); @@ -104,7 +108,7 @@ UnalignedWriter::~UnalignedWriter() } -Status UnalignedWriter::Append(const u8* data, size_t size) const +Status UnalignedWriter::Append(const std::uint8_t* data, size_t size) const { while(size != 0) { diff --git a/source/lib/file/io/write_buffer.h b/source/lib/file/io/write_buffer.h index f1fcf33a2c..d4a2e02ad7 100644 --- a/source/lib/file/io/write_buffer.h +++ b/source/lib/file/io/write_buffer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -27,7 +27,6 @@ #include "lib/file/file.h" #include "lib/posix/posix_types.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -41,7 +40,7 @@ public: void Reserve(size_t size); void Overwrite(const void* data, size_t size, size_t offset); - std::shared_ptr Data() const + std::shared_ptr Data() const { return m_data; } @@ -56,7 +55,7 @@ private: size_t m_capacity; // must come first (init order) - std::shared_ptr m_data; + std::shared_ptr m_data; size_t m_size; }; @@ -71,7 +70,7 @@ public: /** * add data to the align buffer, writing it out to disk if full. **/ - Status Append(const u8* data, size_t size) const; + Status Append(const std::uint8_t* data, size_t size) const; /** * zero-initialize any remaining space in the align buffer and write @@ -83,7 +82,7 @@ private: Status WriteBlock() const; PFile m_file; - std::shared_ptr m_alignedBuf; + std::shared_ptr m_alignedBuf; mutable off_t m_alignedOfs; mutable size_t m_bytesUsed; }; diff --git a/source/lib/file/vfs/tests/test_vfs_real_path.h b/source/lib/file/vfs/tests/test_vfs_real_path.h index 1811d8b27d..01ae015edc 100644 --- a/source/lib/file/vfs/tests/test_vfs_real_path.h +++ b/source/lib/file/vfs/tests/test_vfs_real_path.h @@ -27,7 +27,6 @@ #include "lib/file/vfs/vfs.h" #include "lib/os_path.h" #include "lib/path.h" -#include "lib/types.h" #include #include @@ -81,7 +80,7 @@ public: createRealDir(TEST_FOLDER / "cache" / "some_folder"); createRealDir(TEST_FOLDER / "some_mod" / "cache" / "some_mod"); - std::shared_ptr buf; + std::shared_ptr buf; TS_ASSERT_OK(AllocateAligned(buf, 1, maxSectorSize)); g_VFS->Mount(L"", TEST_FOLDER / "some_mod" / "", 0, 0); diff --git a/source/lib/file/vfs/tests/test_vfs_tree.h b/source/lib/file/vfs/tests/test_vfs_tree.h index 0a2c6cea13..9082d12850 100644 --- a/source/lib/file/vfs/tests/test_vfs_tree.h +++ b/source/lib/file/vfs/tests/test_vfs_tree.h @@ -30,7 +30,6 @@ #include "lib/file/vfs/vfs_tree.h" #include "lib/os_path.h" #include "lib/status.h" -#include "lib/types.h" #include @@ -45,7 +44,7 @@ public: size_t Precedence() const override { return m_Precedence; } wchar_t LocationCode() const override { return L'\0'; } const OsPath& Path() const override { return m_Path; } - Status Load(const OsPath& /*name*/, const std::span) const override + Status Load(const OsPath& /*name*/, const std::span) const override { return INFO::OK; } diff --git a/source/lib/file/vfs/tests/test_vfs_util.h b/source/lib/file/vfs/tests/test_vfs_util.h index 3bc6cda926..412c747bfb 100644 --- a/source/lib/file/vfs/tests/test_vfs_util.h +++ b/source/lib/file/vfs/tests/test_vfs_util.h @@ -29,7 +29,6 @@ #include "lib/file/vfs/vfs_util.h" #include "lib/os_path.h" #include "lib/path.h" -#include "lib/types.h" #include @@ -77,7 +76,7 @@ public: void test_getPathnames() { - std::shared_ptr nodata; + std::shared_ptr nodata; TS_ASSERT_OK(AllocateAligned(nodata, 1, maxSectorSize)); g_VFS->CreateFile("test_file.txt", {nodata.get(), 0}); diff --git a/source/lib/file/vfs/vfs.cpp b/source/lib/file/vfs/vfs.cpp index c77e527204..22e267a616 100644 --- a/source/lib/file/vfs/vfs.cpp +++ b/source/lib/file/vfs/vfs.cpp @@ -134,7 +134,7 @@ public: return INFO::OK; } - Status CreateFile(const VfsPath& pathname, std::span fileContents) final + Status CreateFile(const VfsPath& pathname, std::span fileContents) final { std::lock_guard lock(vfs_mutex); VfsDirectory* directory; @@ -158,7 +158,8 @@ public: return INFO::OK; } - Status LoadFile(const VfsPath& pathname, std::shared_ptr& fileContents, size_t& size) final + Status LoadFile(const VfsPath& pathname, std::shared_ptr& fileContents, + size_t& size) final { std::lock_guard lock(vfs_mutex); @@ -168,7 +169,7 @@ public: // instead, callers should log the error, including pathname. RETURN_STATUS_IF_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, &file)); - fileContents = DummySharedPtr((u8*)0); + fileContents = DummySharedPtr(static_cast(0)); size = file->Size(); RETURN_STATUS_IF_ERR(AllocateAligned(fileContents, size, maxSectorSize)); @@ -180,7 +181,8 @@ public: return INFO::OK; } - Status LoadFile(const VfsPath& pathname, std::unique_ptr& fileContents, size_t& size) final + Status LoadFile(const VfsPath& pathname, + std::unique_ptr& fileContents, size_t& size) final { std::lock_guard lock(vfs_mutex); @@ -191,7 +193,7 @@ public: RETURN_STATUS_IF_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, &file)); size = file->Size(); - fileContents.reset(reinterpret_cast(rtl_AllocateAligned(size, maxSectorSize))); + fileContents.reset(reinterpret_cast(rtl_AllocateAligned(size, maxSectorSize))); if (!fileContents) WARN_RETURN(ERR::NO_MEM); diff --git a/source/lib/file/vfs/vfs.h b/source/lib/file/vfs/vfs.h index 923cbcbf48..93e4978a35 100644 --- a/source/lib/file/vfs/vfs.h +++ b/source/lib/file/vfs/vfs.h @@ -33,7 +33,6 @@ #include "lib/file/vfs/vfs_path.h" #include "lib/os_path.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -149,7 +148,7 @@ struct IVFS * @param fileContents the pointer must be aligned to maxSectorSize * @return Status. **/ - virtual Status CreateFile(const VfsPath& pathname, std::span fileContents) = 0; + virtual Status CreateFile(const VfsPath& pathname, std::span fileContents) = 0; /** * Read an entire file into memory. @@ -159,7 +158,8 @@ struct IVFS * @param size receives the size [bytes] of the file contents. * @return Status. **/ - virtual Status LoadFile(const VfsPath& pathname, std::shared_ptr& fileContents, size_t& size) = 0; + virtual Status LoadFile(const VfsPath& pathname, std::shared_ptr& fileContents, + size_t& size) = 0; /** * Read an entire file into memory. @@ -169,7 +169,8 @@ struct IVFS * @param size receives the size [bytes] of the file contents. * @return Status. **/ - virtual Status LoadFile(const VfsPath& pathname, std::unique_ptr& fileContents, size_t& size) = 0; + virtual Status LoadFile(const VfsPath& pathname, + std::unique_ptr& fileContents, size_t& size) = 0; /** * @return a string representation of all files and directories. diff --git a/source/lib/fnv_hash.cpp b/source/lib/fnv_hash.cpp index 4bdf722c25..ecaff0235a 100644 --- a/source/lib/fnv_hash.cpp +++ b/source/lib/fnv_hash.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -33,7 +33,7 @@ u32 fnv_hash(const void* buf, size_t len) // give distinct values for different length 0 buffers. // value taken from FNV; it has no special significance. - const u8* p = (const u8*)buf; + const std::uint8_t* p = static_cast(buf); // expected case: string if(!len) @@ -68,7 +68,7 @@ u64 fnv_hash64(const void* buf, size_t len) // give distinct values for different length 0 buffers. // value taken from FNV; it has no special significance. - const u8* p = (const u8*)buf; + const std::uint8_t* p = static_cast(buf); // expected case: string if(!len) diff --git a/source/lib/lib.cpp b/source/lib/lib.cpp index 91991003b5..b5c762cded 100644 --- a/source/lib/lib.cpp +++ b/source/lib/lib.cpp @@ -74,8 +74,8 @@ u32 u32_from_u16(u16 hi, u16 lo) } -// input in [0, 1); convert to u8 range -u8 u8_from_double(double in) +// input in [0, 1); convert to std::uint8_t range +std::uint8_t u8_from_double(double in) { if(!(0.0 <= in && in < 1.0)) { @@ -85,7 +85,7 @@ u8 u8_from_double(double in) int l = (int)(in * 255.0); ENSURE((unsigned)l <= 255u); - return (u8)l; + return static_cast(l); } // input in [0, 1); convert to u16 range diff --git a/source/lib/lib.h b/source/lib/lib.h index 466ce807ae..b3fa18453a 100644 --- a/source/lib/lib.h +++ b/source/lib/lib.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -131,12 +131,12 @@ extern u32 u32_from_u16(u16 hi, u16 lo); /// assemble u32 from u16 // - separate compilation of templates via export isn't supported by // most compilers. -template u8 u8_from_larger(T x) +template std::uint8_t u8_from_larger(T x) { - const u8 max = std::numeric_limits::max(); + const std::uint8_t max = std::numeric_limits::max(); if((u64)x > (u64)max) throw std::out_of_range("u8_from_larger"); - return (u8)(x & max); + return static_cast(x & max); } template u16 u16_from_larger(T x) @@ -155,8 +155,8 @@ template u32 u32_from_larger(T x) return (u32)(x & max); } -/// convert double to u8; verifies number is in range. -extern u8 u8_from_double(double in); +/// 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); diff --git a/source/lib/sysdep/arch/x86_x64/apic.cpp b/source/lib/sysdep/arch/x86_x64/apic.cpp index e258c09a01..8c38e30f81 100644 --- a/source/lib/sysdep/arch/x86_x64/apic.cpp +++ b/source/lib/sysdep/arch/x86_x64/apic.cpp @@ -43,7 +43,7 @@ ApicId GetApicId() // an xAPIC (e.g. P4/Athlon XP) will return a nonzero ID. [[maybe_unused]] bool ok = x86_x64::cpuid(®s); ASSERT(ok); - const u8 apicId = (u8)bits(regs.ebx, 24, 31); + const std::uint8_t apicId = static_cast(bits(regs.ebx, 24, 31)); return apicId; } diff --git a/source/lib/sysdep/arch/x86_x64/apic.h b/source/lib/sysdep/arch/x86_x64/apic.h index 4cc6ae7958..3c466696f6 100644 --- a/source/lib/sysdep/arch/x86_x64/apic.h +++ b/source/lib/sysdep/arch/x86_x64/apic.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -23,11 +23,9 @@ #ifndef INCLUDED_X86_X64_APIC #define INCLUDED_X86_X64_APIC -#include "lib/types.h" - #include -typedef u8 ApicId; // not necessarily contiguous values +typedef std::uint8_t ApicId; // not necessarily contiguous values /** * @return APIC ID of the currently executing processor or zero if the diff --git a/source/lib/sysdep/os/unix/unix.cpp b/source/lib/sysdep/os/unix/unix.cpp index 347aa666d4..b6e5356fa5 100644 --- a/source/lib/sysdep/os/unix/unix.cpp +++ b/source/lib/sysdep/os/unix/unix.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2025 Wildfire Games. +/* Copyright (c) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -31,7 +31,6 @@ #include "lib/sysdep/os.h" #include "lib/sysdep/os/unix/udbg.h" #include "lib/sysdep/sysdep.h" -#include "lib/types.h" #include "lib/utf8.h" #include @@ -323,7 +322,7 @@ std::wstring sys_get_user_name() return L""; } -Status sys_generate_random_bytes(u8* buf, size_t count) +Status sys_generate_random_bytes(std::uint8_t* buf, size_t count) { FILE* f = fopen("/dev/urandom", "rb"); if (!f) diff --git a/source/lib/sysdep/os/win/acpi.cpp b/source/lib/sysdep/os/win/acpi.cpp index 874200d547..b1366f950f 100644 --- a/source/lib/sysdep/os/win/acpi.cpp +++ b/source/lib/sysdep/os/win/acpi.cpp @@ -33,7 +33,7 @@ #pragma pack(1) -typedef const volatile u8* PCV_u8; +typedef const volatile std::uint8_t* PCV_u8; typedef const volatile AcpiTable* PCV_AcpiTable; @@ -55,12 +55,12 @@ static void DeallocateTable(const T* table) // return 8-bit checksum of a buffer (should be 0) -static u8 ComputeChecksum(PCV_u8 buf, size_t numBytes) +static std::uint8_t ComputeChecksum(PCV_u8 buf, size_t numBytes) { // (can't use std::accumulate - we need 8-bit wraparound) - u8 sum = 0; + std::uint8_t sum = 0; for(PCV_u8 p = buf; p < buf+numBytes; p++) - sum = u8((sum + *p) & 0xFF); + sum = static_cast((sum + *p) & 0xFF); return sum; } diff --git a/source/lib/sysdep/os/win/acpi.h b/source/lib/sysdep/os/win/acpi.h index 5125be506f..c9b73b5777 100644 --- a/source/lib/sysdep/os/win/acpi.h +++ b/source/lib/sysdep/os/win/acpi.h @@ -34,8 +34,8 @@ struct AcpiTable { char signature[4]; u32 size; // table size [bytes], including header - u8 revision; - u8 checksum; // to make sum of entire table == 0 + std::uint8_t revision; + std::uint8_t checksum; // to make sum of entire table == 0 char oemId[6]; char oemTableId[8]; u32 oemRevision; @@ -55,24 +55,24 @@ enum AcpiAddressSpace // address of a struct or register struct AcpiGenericAddress { - u8 addressSpaceId; - u8 registerBitWidth; - u8 registerBitOffset; - u8 accessSize; + std::uint8_t addressSpaceId; + std::uint8_t registerBitWidth; + std::uint8_t registerBitOffset; + std::uint8_t accessSize; u64 address; }; struct FADT // signature is FACP! { AcpiTable header; - u8 unused1[40]; + std::uint8_t unused1[40]; u32 pmTimerPortAddress; - u8 unused2[16]; + std::uint8_t unused2[16]; u16 c2Latency; // [us] u16 c3Latency; // [us] - u8 unused3[5]; - u8 dutyWidth; - u8 unused4[6]; + std::uint8_t unused3[5]; + std::uint8_t dutyWidth; + std::uint8_t unused4[6]; u32 flags; // (ACPI4 defines additional fields after this) diff --git a/source/lib/sysdep/os/win/tests/test_wdbg_sym.h b/source/lib/sysdep/os/win/tests/test_wdbg_sym.h index 79477dbb44..6132a21661 100644 --- a/source/lib/sysdep/os/win/tests/test_wdbg_sym.h +++ b/source/lib/sysdep/os/win/tests/test_wdbg_sym.h @@ -112,7 +112,7 @@ class TestWdbgSym : public CxxTest::TestSuite // this test now always runs. therefore, just make sure a decent // amount of text (not just "(failed)" error messages) was produced. - CACHE_ALIGNED(u8) context[DEBUG_CONTEXT_SIZE]; + CACHE_ALIGNED(std::uint8_t) context[DEBUG_CONTEXT_SIZE]; TS_ASSERT_EQUALS(debug_CaptureContext(context), INFO::OK); const wchar_t* text = debug_BuildErrorMessage(L"dummy", 0, 0, 0, context, L"m_test_array"); TS_ASSERT(wcslen(text) > 500); @@ -133,8 +133,8 @@ class TestWdbgSym : public CxxTest::TestSuite typedef struct { - u8 s1; - u8 s2; + std::uint8_t s1; + std::uint8_t s2; char s3; } Small; @@ -142,7 +142,7 @@ class TestWdbgSym : public CxxTest::TestSuite struct Large { - u8 large_member_u8; + std::uint8_t large_member_u8; std::string large_member_string; double large_member_double; }; @@ -204,10 +204,10 @@ class TestWdbgSym : public CxxTest::TestSuite s_uintptr.insert(0x123); s_uintptr.insert(0x456); // empty - std::deque d_u8_empty; + std::deque d_u8_empty; std::list l_nested_empty; std::map m_double_empty; - std::multimap mm_int_empty; + std::multimap mm_int_empty; std::set s_uint_empty; std::multiset ms_char_empty; std::vector v_double_empty; @@ -219,10 +219,10 @@ class TestWdbgSym : public CxxTest::TestSuite m_test_udt(); // uninitialized - std::deque d_u8_uninit; + std::deque d_u8_uninit; std::list l_nested_uninit; std::map m_double_uninit; - std::multimap mm_int_uninit; + std::multimap mm_int_uninit; std::set s_uint_uninit; std::multiset ms_char_uninit; std::vector v_double_uninit; @@ -242,7 +242,7 @@ class TestWdbgSym : public CxxTest::TestSuite [[maybe_unused]] bool l_bool = true; [[maybe_unused]] wchar_t l_wchars[] = L"wchar string"; [[maybe_unused]] enum TestEnum { VAL1=1, VAL2=2 } l_enum = VAL1; - [[maybe_unused]] u8 l_u8s[] = { 1,2,3,4 }; + [[maybe_unused]] std::uint8_t l_u8s[] = { 1,2,3,4 }; [[maybe_unused]] void (*l_funcptr)(void) = m_test_stl; static double s_double = -2.718; diff --git a/source/lib/sysdep/os/win/wdbg_sym.cpp b/source/lib/sysdep/os/win/wdbg_sym.cpp index 1dd446f207..a345721696 100644 --- a/source/lib/sysdep/os/win/wdbg_sym.cpp +++ b/source/lib/sysdep/os/win/wdbg_sym.cpp @@ -498,7 +498,7 @@ static Status out_check_limit() // called by dump_sequence for its string special-case. // // algorithm: scan the "string" and count # text chars vs. garbage. -static bool is_string(const u8* p, size_t stride) +static bool is_string(const std::uint8_t* p, size_t stride) { // note: access violations are caught by dump_sym; output is "?". int score = 0; @@ -530,7 +530,7 @@ static bool is_string(const u8* p, size_t stride) // forward decl; called by dump_sequence and some of dump_sym_*. -static Status dump_sym(DWORD id, const u8* p, DumpState& state); +static Status dump_sym(DWORD id, const std::uint8_t* p, DumpState& state); // from cvconst.h // @@ -578,7 +578,7 @@ static void dump_error(Status err) // moved out of dump_sequence. -static Status dump_string(const u8* p, size_t el_size) +static Status dump_string(const std::uint8_t* p, size_t el_size) { // not char or wchar_t string if(el_size != sizeof(char) && el_size != sizeof(wchar_t)) @@ -639,7 +639,7 @@ static void seq_determine_formatting(size_t el_size, size_t el_count, bool* fits static Status dump_sequence(DebugStlIterator el_iterator, void* internal, size_t el_count, DWORD el_type_id, size_t el_size, DumpState& state) { - const u8* el_p = 0; // avoid "uninitialized" warning + const std::uint8_t* el_p = 0; // avoid "uninitialized" warning // special case: display as a string if the sequence looks to be text. // do this only if container isn't empty because the otherwise the @@ -700,18 +700,18 @@ static Status dump_sequence(DebugStlIterator el_iterator, void* internal, size_t } -static const u8* array_iterator(void* internal, size_t el_size) +static const std::uint8_t* array_iterator(void* internal, size_t el_size) { - const u8*& pos = *(const u8**)internal; - const u8* cur_pos = pos; + const std::uint8_t*& pos = *static_cast(internal); + const std::uint8_t* cur_pos = pos; pos += el_size; return cur_pos; } -static Status dump_array(const u8* p, size_t el_count, DWORD el_type_id, size_t el_size, DumpState& state) +static Status dump_array(const std::uint8_t* p, size_t el_count, DWORD el_type_id, size_t el_size, DumpState& state) { - const u8* iterator_internal_pos = p; + const std::uint8_t* iterator_internal_pos = p; return dump_sequence(array_iterator, &iterator_internal_pos, el_count, el_type_id, el_size, state); } @@ -778,7 +778,8 @@ static bool IsUnretrievable(DWORD flags) return false; } -static Status DetermineSymbolAddress(DWORD id, const SYMBOL_INFOW* sym, const DumpState& state, const u8** pp) +static Status DetermineSymbolAddress(DWORD id, const SYMBOL_INFOW* sym, const DumpState& state, + const std::uint8_t** pp) { DWORD dataKind; if(!pSymGetTypeInfo(hProcess, state.moduleBase, id, TI_GET_DATAKIND, &dataKind)) @@ -798,7 +799,7 @@ static Status DetermineSymbolAddress(DWORD id, const SYMBOL_INFOW* sym, const Du else if(IsUnretrievable(sym->Flags)) return ERR::SYM_UNRETRIEVABLE; // NOWARN - *pp = (const u8*)(uintptr_t)addr; + *pp = reinterpret_cast((uintptr_t)addr); #if 0 debug_printf("Symbol: %s at %p flags=%X dk=%d sym->addr=%I64X fp=%I64x\n", @@ -818,7 +819,7 @@ static Status DetermineSymbolAddress(DWORD id, const SYMBOL_INFOW* sym, const Du // will display the appropriate error message via dump_error. // called by dump_sym; lock is held. -static Status dump_sym_array(DWORD type_id, const u8* p, DumpState& state) +static Status dump_sym_array(DWORD type_id, const std::uint8_t* p, DumpState& state) { ULONG64 size64 = 0; if(!pSymGetTypeInfo(hProcess, state.moduleBase, type_id, TI_GET_LENGTH, &size64)) @@ -859,7 +860,7 @@ static void AppendCharacterIfPrintable(u64 data) } -static Status dump_sym_base_type(DWORD type_id, const u8* p, DumpState& state) +static Status dump_sym_base_type(DWORD type_id, const std::uint8_t* p, DumpState& state) { DWORD base_type; if(!pSymGetTypeInfo(hProcess, state.moduleBase, type_id, TI_GET_BASETYPE, &base_type)) @@ -995,7 +996,7 @@ static Status dump_sym_base_type(DWORD type_id, const u8* p, DumpState& state) //----------------------------------------------------------------------------- -static Status dump_sym_base_class(DWORD type_id, const u8* p, DumpState& state) +static Status dump_sym_base_class(DWORD type_id, const std::uint8_t* p, DumpState& state) { DWORD base_class_type_id; if(!pSymGetTypeInfo(hProcess, state.moduleBase, type_id, TI_GET_TYPEID, &base_class_type_id)) @@ -1014,7 +1015,7 @@ static Status dump_sym_base_class(DWORD type_id, const u8* p, DumpState& state) //----------------------------------------------------------------------------- -static Status dump_sym_data(DWORD id, const u8* p, DumpState& state) +static Status dump_sym_data(DWORD id, const std::uint8_t* p, DumpState& state) { SYMBOL_INFO_PACKAGEW2 sp; SYMBOL_INFOW* sym = &sp.si; @@ -1038,7 +1039,7 @@ static Status dump_sym_data(DWORD id, const u8* p, DumpState& state) //----------------------------------------------------------------------------- -static Status dump_sym_enum(DWORD type_id, const u8* p, DumpState& state) +static Status dump_sym_enum(DWORD type_id, const std::uint8_t* p, DumpState& state) { ULONG64 size64 = 0; if(!pSymGetTypeInfo(hProcess, state.moduleBase, type_id, TI_GET_LENGTH, &size64)) @@ -1096,7 +1097,7 @@ static Status dump_sym_enum(DWORD type_id, const u8* p, DumpState& state) //----------------------------------------------------------------------------- -static Status dump_sym_function(DWORD /*type_id*/, const u8* /*p*/, DumpState&) +static Status dump_sym_function(DWORD /*type_id*/, const std::uint8_t* /*p*/, DumpState&) { return INFO::SYM_SUPPRESS_OUTPUT; } @@ -1104,7 +1105,7 @@ static Status dump_sym_function(DWORD /*type_id*/, const u8* /*p*/, DumpState&) //----------------------------------------------------------------------------- -static Status dump_sym_function_type(DWORD /*type_id*/, const u8* p, DumpState& state) +static Status dump_sym_function_type(DWORD /*type_id*/, const std::uint8_t* p, DumpState& state) { // this symbol gives class parent, return type, and parameter count. // unfortunately the one thing we care about, its name, @@ -1132,7 +1133,7 @@ static Status dump_sym_function_type(DWORD /*type_id*/, const u8* p, DumpState& // be reentered, which is not permissible). static const size_t maxVisited = 1000; -static const u8* visited[maxVisited]; +static const std::uint8_t* visited[maxVisited]; static size_t numVisited; static void ptr_reset_visited() @@ -1140,7 +1141,7 @@ static void ptr_reset_visited() numVisited = 0; } -static bool ptr_already_visited(const u8* p) +static bool ptr_already_visited(const std::uint8_t* p) { for(size_t i = 0; i < numVisited; i++) { @@ -1172,7 +1173,7 @@ static bool ptr_already_visited(const u8* p) } -static Status dump_sym_pointer(DWORD type_id, const u8* p, DumpState& state) +static Status dump_sym_pointer(DWORD type_id, const std::uint8_t* p, DumpState& state) { ULONG64 size64 = 0; if(!pSymGetTypeInfo(hProcess, state.moduleBase, type_id, TI_GET_LENGTH, &size64)) @@ -1180,7 +1181,7 @@ static Status dump_sym_pointer(DWORD type_id, const u8* p, DumpState& state) const size_t size = (size_t)size64; // read+output pointer's value. - p = (const u8*)(uintptr_t)movzx_le64(p, size); + p = reinterpret_cast(static_cast(movzx_le64(p, size))); out(L"0x%p", p); // bail if it's obvious the pointer is bogus @@ -1215,7 +1216,7 @@ static Status dump_sym_pointer(DWORD type_id, const u8* p, DumpState& state) //----------------------------------------------------------------------------- -static Status dump_sym_typedef(DWORD type_id, const u8* p, DumpState& state) +static Status dump_sym_typedef(DWORD type_id, const std::uint8_t* p, DumpState& state) { if(!pSymGetTypeInfo(hProcess, state.moduleBase, type_id, TI_GET_TYPEID, &type_id)) WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE); @@ -1263,7 +1264,8 @@ static Status udt_get_child_type(const wchar_t* child_name, ULONG numChildren, c } -static Status udt_dump_std(const wchar_t* type_name, const u8* p, size_t size, DumpState& state, ULONG numChildren, const DWORD* children) +static Status udt_dump_std(const wchar_t* type_name, const std::uint8_t* p, size_t size, DumpState& state, + ULONG numChildren, const DWORD* children) { Status err; @@ -1288,7 +1290,7 @@ static Status udt_dump_std(const wchar_t* type_name, const u8* p, size_t size, D // .. get iterator and # elements size_t el_count; DebugStlIterator el_iterator; - u8 it_mem[DEBUG_STL_MAX_ITERATOR_SIZE]; + std::uint8_t it_mem[DEBUG_STL_MAX_ITERATOR_SIZE]; err = debug_stl_get_container_info(type_name, p, size, el_size, &el_count, &el_iterator, it_mem); if(err != INFO::OK) goto not_valid_container; @@ -1380,7 +1382,7 @@ not_handle: } -static Status udt_dump_suppressed(const wchar_t* type_name, const u8* /*p*/, size_t /*size*/, +static Status udt_dump_suppressed(const wchar_t* type_name, const std::uint8_t* /*p*/, size_t /*size*/, DumpState state, ULONG /*numChildren*/, const DWORD* /*children*/) { if(!udt_should_suppress(type_name)) @@ -1433,7 +1435,8 @@ static bool udt_fits_on_one_line(const wchar_t* type_name, size_t child_count, s } -static Status udt_dump_normal(const wchar_t* type_name, const u8* p, size_t size, DumpState state, ULONG numChildren, const DWORD* children) +static Status udt_dump_normal(const wchar_t* type_name, const std::uint8_t* p, size_t size, + DumpState state, ULONG numChildren, const DWORD* children) { // special case: boost::unordered types are complex and may cause a stack overflow // see https://gitea.wildfiregames.com/0ad/0ad/issues/1813 @@ -1469,7 +1472,7 @@ static Status udt_dump_normal(const wchar_t* type_name, const u8* p, size_t size if(!fits_on_one_line) INDENT; - const u8* el_p = p+ofs; + const std::uint8_t* el_p = p+ofs; Status err = dump_sym(child_id, el_p, state); // there was no output for this child; undo its indentation (if any), @@ -1511,7 +1514,7 @@ static Status udt_dump_normal(const wchar_t* type_name, const u8* p, size_t size } -static Status dump_sym_udt(DWORD type_id, const u8* p, DumpState& state) +static Status dump_sym_udt(DWORD type_id, const std::uint8_t* p, DumpState& state) { ULONG64 size64 = 0; if(!pSymGetTypeInfo(hProcess, state.moduleBase, type_id, TI_GET_LENGTH, &size64)) @@ -1557,7 +1560,7 @@ done: //----------------------------------------------------------------------------- -static Status dump_sym_vtable(DWORD /*type_id*/, const u8* /*p*/, DumpState&) +static Status dump_sym_vtable(DWORD /*type_id*/, const std::uint8_t* /*p*/, DumpState&) { // unsupported (vtable internals are undocumented; too much work). return INFO::SYM_SUPPRESS_OUTPUT; @@ -1567,7 +1570,7 @@ static Status dump_sym_vtable(DWORD /*type_id*/, const u8* /*p*/, DumpState&) //----------------------------------------------------------------------------- -static Status dump_sym_unknown(DWORD type_id, const u8* /*p*/, DumpState& state) +static Status dump_sym_unknown(DWORD type_id, const std::uint8_t* /*p*/, DumpState& state) { // redundant (already done in dump_sym), but this is rare. DWORD type_tag; @@ -1582,7 +1585,7 @@ static Status dump_sym_unknown(DWORD type_id, const u8* /*p*/, DumpState& state) //----------------------------------------------------------------------------- -typedef Status (*DumpFunc)(DWORD typeId, const u8* p, DumpState& state); +typedef Status (*DumpFunc)(DWORD typeId, const std::uint8_t* p, DumpState& state); static DumpFunc DumpFuncFromTypeTag(DWORD typeTag) { @@ -1618,7 +1621,7 @@ static DumpFunc DumpFuncFromTypeTag(DWORD typeTag) // write name and value of the symbol to the output buffer. // delegates to dump_sym_* depending on the symbol's tag. -static Status dump_sym(DWORD type_id, const u8* p, DumpState& state) +static Status dump_sym(DWORD type_id, const std::uint8_t* p, DumpState& state) { RETURN_STATUS_IF_ERR(out_check_limit()); @@ -1651,7 +1654,7 @@ static BOOL CALLBACK dump_sym_cb(SYMBOL_INFOW* sym, ULONG /*size*/, PVOID userCo return TRUE; // continue out_latch_pos(); // see decl - const u8* p = (const u8*)(uintptr_t)sym->Address; + const std::uint8_t* p = reinterpret_cast((uintptr_t)sym->Address); DumpState state((uintptr_t)sym->ModBase, (LPSTACKFRAME64)userContext); INDENT; diff --git a/source/lib/sysdep/os/win/wdir_watch.cpp b/source/lib/sysdep/os/win/wdir_watch.cpp index 8f739c21fb..1428bf7a60 100644 --- a/source/lib/sysdep/os/win/wdir_watch.cpp +++ b/source/lib/sysdep/os/win/wdir_watch.cpp @@ -78,7 +78,7 @@ class DirWatchRequest NONCOPYABLE(DirWatchRequest); public: DirWatchRequest(const OsPath& path) - : m_path(path), m_dirHandle(path), m_data(new u8[dataSize]) + : m_path(path), m_dirHandle(path), m_data(new std::uint8_t[dataSize]) { m_ovl = (OVERLAPPED*)calloc(1, sizeof(OVERLAPPED)); // rationale for dynamic alloc: see decl ENSURE(m_ovl); @@ -208,7 +208,7 @@ private: // copy because the watches are independent and may be triggered // 'simultaneously' before the next poll.) // - lifetime must be managed manually (see dtor) - u8* m_data; + std::uint8_t* m_data; // rationale: // - ReadDirectoryChangesW's asynchronous mode is triggered by passing diff --git a/source/lib/sysdep/os/win/wfirmware.h b/source/lib/sysdep/os/win/wfirmware.h index 1f6437855d..e839fed3cd 100644 --- a/source/lib/sysdep/os/win/wfirmware.h +++ b/source/lib/sysdep/os/win/wfirmware.h @@ -34,7 +34,7 @@ typedef std::vector TableIds; extern TableIds GetTableIDs(Provider provider); -typedef std::vector Table; +typedef std::vector Table; extern Table GetTable(Provider provider, TableId tableId); diff --git a/source/lib/sysdep/os/win/wnuma.cpp b/source/lib/sysdep/os/win/wnuma.cpp index 91f768a18a..96951a9d5a 100644 --- a/source/lib/sysdep/os/win/wnuma.cpp +++ b/source/lib/sysdep/os/win/wnuma.cpp @@ -147,20 +147,20 @@ static void PopulateNodes() // fields common to Affinity* structures struct AffinityHeader { - u8 type; - u8 length; // size [bytes], including this header + std::uint8_t type; + std::uint8_t length; // size [bytes], including this header }; struct AffinityAPIC { - static const u8 type = 0; + static const std::uint8_t type = 0; AffinityHeader header; - u8 proximityDomainNumber0; - u8 apicId; + std::uint8_t proximityDomainNumber0; + std::uint8_t apicId; u32 flags; - u8 sapicId; - u8 proximityDomainNumber123[3]; + std::uint8_t sapicId; + std::uint8_t proximityDomainNumber123[3]; u32 clockDomain; u32 ProximityDomainNumber() const @@ -176,7 +176,7 @@ struct AffinityAPIC struct AffinityMemory { - static const u8 type = 1; + static const std::uint8_t type = 1; AffinityHeader header; u32 proximityDomainNumber; @@ -195,7 +195,7 @@ struct SRAT { AcpiTable header; u32 reserved1; - u8 reserved2[8]; + std::uint8_t reserved2[8]; AffinityHeader affinities[1]; }; @@ -364,7 +364,7 @@ struct SLIT { AcpiTable header; u64 numSystemLocalities; - u8 entries[1]; // numSystemLocalities*numSystemLocalities entries + std::uint8_t entries[1]; // numSystemLocalities*numSystemLocalities entries }; #pragma pack(pop) @@ -491,7 +491,7 @@ static bool VerifyPages([[maybe_unused]] void* mem, [[maybe_unused]] size_t size const size_t numPages = (size + pageSize-1) / pageSize; PSAPI_WORKING_SET_EX_INFORMATION* wsi = new PSAPI_WORKING_SET_EX_INFORMATION[numPages]; for(size_t i = 0; i < numPages; i++) - wsi[i].VirtualAddress = (u8*)mem + i*pageSize; + wsi[i].VirtualAddress = static_cast(mem) + i*pageSize; pQueryWorkingSetEx(GetCurrentProcess(), wsi, DWORD(sizeof(PSAPI_WORKING_SET_EX_INFORMATION)*numPages)); // ensure each is valid and allocated on the correct node diff --git a/source/lib/sysdep/os/win/wsysdep.cpp b/source/lib/sysdep/os/win/wsysdep.cpp index e6427a6759..b70a8f07fe 100644 --- a/source/lib/sysdep/os/win/wsysdep.cpp +++ b/source/lib/sysdep/os/win/wsysdep.cpp @@ -504,7 +504,7 @@ Status sys_open_url(const std::string& url) } -Status sys_generate_random_bytes(u8* buffer, size_t size) +Status sys_generate_random_bytes(std::uint8_t* buffer, size_t size) { HCRYPTPROV hCryptProv = 0; if(!CryptAcquireContext(&hCryptProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) diff --git a/source/lib/sysdep/sysdep.h b/source/lib/sysdep/sysdep.h index 1135ab78ff..798e776f6c 100644 --- a/source/lib/sysdep/sysdep.h +++ b/source/lib/sysdep/sysdep.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -35,7 +35,6 @@ #include "lib/os_path.h" #include "lib/status.h" #include "lib/sysdep/os.h" -#include "lib/types.h" #include #include @@ -169,7 +168,7 @@ extern size_t sys_max_sector_size(); * this should only be used with small numbers of bytes, to avoid * hogging the system's entropy. **/ -Status sys_generate_random_bytes(u8* buf, size_t count); +Status sys_generate_random_bytes(std::uint8_t* buf, size_t count); /** * get the proxy address for accessing the given HTTP URL. diff --git a/source/lib/sysdep/tests/test_sysdep.h b/source/lib/sysdep/tests/test_sysdep.h index c6916158d3..a58edad64f 100644 --- a/source/lib/sysdep/tests/test_sysdep.h +++ b/source/lib/sysdep/tests/test_sysdep.h @@ -46,8 +46,8 @@ public: void test_random() { u64 a = 0, b = 0; - TS_ASSERT_OK(sys_generate_random_bytes((u8*)&a, sizeof(a))); - TS_ASSERT_OK(sys_generate_random_bytes((u8*)&b, sizeof(b))); + TS_ASSERT_OK(sys_generate_random_bytes(reinterpret_cast(&a), sizeof(a))); + TS_ASSERT_OK(sys_generate_random_bytes(reinterpret_cast(&b), sizeof(b))); TS_ASSERT_DIFFERS(a, b); } diff --git a/source/lib/tests/test_byte_order.h b/source/lib/tests/test_byte_order.h index 61f90a01be..64ec0e831b 100644 --- a/source/lib/tests/test_byte_order.h +++ b/source/lib/tests/test_byte_order.h @@ -33,7 +33,7 @@ public: void test_conversion() { const u32 x = 0x01234567u; - u8 LS_byte; + std::uint8_t LS_byte; memcpy(&LS_byte, &x, 1); // little endian if(LS_byte == 0x67) @@ -66,8 +66,8 @@ public: void test_movzx() { - const u8 d1[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - const u8 d2[] = { 0x43, 0x12, 0x23, 0xA4 }; + const std::uint8_t d1[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + const std::uint8_t d2[] = { 0x43, 0x12, 0x23, 0xA4 }; TS_ASSERT_EQUALS(movzx_le64(d1, 1), 0x01ull); TS_ASSERT_EQUALS(movzx_le64(d1, 2), 0x0201ull); @@ -84,9 +84,9 @@ public: void test_movsx() { - const u8 d1[] = { 0x09, 0xFE }; - const u8 d2[] = { 0xD9, 0x2C, 0xDD, 0x8F }; - const u8 d3[] = { 0x92, 0x26, 0x88, 0xF1, 0x35, 0xAC, 0x01, 0x83 }; + const std::uint8_t d1[] = { 0x09, 0xFE }; + const std::uint8_t d2[] = { 0xD9, 0x2C, 0xDD, 0x8F }; + const std::uint8_t d3[] = { 0x92, 0x26, 0x88, 0xF1, 0x35, 0xAC, 0x01, 0x83 }; TS_ASSERT_EQUALS(movsx_le64(d1, 1), static_cast(0x09ull)); TS_ASSERT_EQUALS(movsx_le64(d1, 2), static_cast(0xFFFFFFFFFFFFFE09ull)); diff --git a/source/lib/tex/tests/test_tex.h b/source/lib/tex/tests/test_tex.h index 1b69ecaff4..f1511aaf43 100644 --- a/source/lib/tex/tests/test_tex.h +++ b/source/lib/tex/tests/test_tex.h @@ -24,7 +24,6 @@ #include "lib/allocators/shared_ptr.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include #include @@ -35,14 +34,14 @@ public: // have mipmaps be created for a test image; check resulting size and pixels void test_mipmap_create() { - static u8 imgData[] = { 0x10,0x20,0x30, 0x40,0x60,0x80, 0xA0,0xA4,0xA8, 0xC0,0xC1,0xC2 }; - std::shared_ptr img = DummySharedPtr(imgData); + static std::uint8_t imgData[] = { 0x10,0x20,0x30, 0x40,0x60,0x80, 0xA0,0xA4,0xA8, 0xC0,0xC1,0xC2 }; + std::shared_ptr img = DummySharedPtr(imgData); // assumes 2x2 box filter algorithm with rounding - static const u8 mipmap[] = { 0x6C,0x79,0x87 }; + static const std::uint8_t mipmap[] = { 0x6C,0x79,0x87 }; Tex t; TS_ASSERT_OK(t.wrap(2, 2, 24, 0, img, 0)); TS_ASSERT_OK(t.transform_to(TEX_MIPMAPS)); - const u8* const out_img = t.get_data(); + const std::uint8_t* const out_img = t.get_data(); TS_ASSERT_EQUALS((int)t.img_size(), 12+3); TS_ASSERT_SAME_DATA(out_img, imgData, 12); TS_ASSERT_SAME_DATA(out_img+12, mipmap, 3); @@ -50,7 +49,7 @@ public: void test_img_size() { - std::shared_ptr img; + std::shared_ptr img; TS_ASSERT_OK(AllocateAligned(img, 100 * 100 * 4)); Tex t; @@ -67,10 +66,10 @@ public: { const size_t w = 4, h = 4, bpp = 4; const size_t size = w*h/2; - std::shared_ptr img; + std::shared_ptr img; TS_ASSERT_OK(AllocateAligned(img, size)); memcpy(img.get(), "\xFF\xFF\x00\x00\x00\xAA\xFF\x55", 8); // gradient from white to black - const u8 expected[] = + const std::uint8_t expected[] = "\xFF\xFF\xFF" "\xFF\xFF\xFF" "\xFF\xFF\xFF" "\xFF\xFF\xFF" "\xAA\xAA\xAA" "\xAA\xAA\xAA" "\xAA\xAA\xAA" "\xAA\xAA\xAA" "\x55\x55\x55" "\x55\x55\x55" "\x55\x55\x55" "\x55\x55\x55" diff --git a/source/lib/tex/tex.cpp b/source/lib/tex/tex.cpp index 91cf0b3750..5f8e18aa76 100644 --- a/source/lib/tex/tex.cpp +++ b/source/lib/tex/tex.cpp @@ -128,12 +128,13 @@ Status tex_validate_plain_format(size_t bpp, size_t flags) // mipmaps //----------------------------------------------------------------------------- -void tex_util_foreach_mipmap(size_t w, size_t h, size_t bpp, const u8* pixels, int levels_to_skip, size_t data_padding, MipmapCB cb, void* RESTRICT cbData) +void tex_util_foreach_mipmap(size_t w, size_t h, size_t bpp, const std::uint8_t* pixels, + int levels_to_skip, size_t data_padding, MipmapCB cb, void* RESTRICT cbData) { ENSURE(levels_to_skip >= 0 || levels_to_skip == TEX_BASE_LEVEL_ONLY); size_t level_w = w, level_h = h; - const u8* level_data = pixels; + const std::uint8_t* level_data = pixels; // we iterate through the loop (necessary to skip over image data), // but do not actually call back until the requisite number of @@ -177,18 +178,19 @@ struct CreateLevelData size_t prev_level_w; size_t prev_level_h; - const u8* prev_level_data; + const std::uint8_t* prev_level_data; size_t prev_level_dataSize; }; // uses 2x2 box filter -static void create_level(size_t level, size_t level_w, size_t level_h, const u8* RESTRICT level_data, size_t level_dataSize, void* RESTRICT cbData) +static void create_level(size_t level, size_t level_w, size_t level_h, + const std::uint8_t* RESTRICT level_data, size_t level_dataSize, void* RESTRICT cbData) { CreateLevelData* cld = (CreateLevelData*)cbData; const size_t src_w = cld->prev_level_w; const size_t src_h = cld->prev_level_h; - const u8* src = cld->prev_level_data; - u8* dst = (u8*)level_data; + const std::uint8_t* src = cld->prev_level_data; + std::uint8_t* dst = const_cast(level_data); // base level - must be copied over from source buffer if(level == 0) @@ -258,9 +260,9 @@ static Status add_mipmaps(Tex* t, size_t w, size_t h, size_t bpp, void* newData, WARN_RETURN(ERR::TEX_INVALID_SIZE); t->m_Flags |= TEX_MIPMAPS; // must come before tex_img_size! const size_t mipmap_size = t->img_size(); - std::shared_ptr mipmapData; + std::shared_ptr mipmapData; AllocateAligned(mipmapData, mipmap_size); - CreateLevelData cld = { bpp/8, w, h, (const u8*)newData, dataSize }; + CreateLevelData cld = { bpp/8, w, h, static_cast(newData), dataSize }; tex_util_foreach_mipmap(w, h, bpp, mipmapData.get(), 0, 1, create_level, &cld); t->m_Data = mipmapData; t->m_DataSize = mipmap_size; @@ -288,7 +290,7 @@ static Status plain_transform(Tex* t, size_t transforms) // extract texture info const size_t w = t->m_Width, h = t->m_Height, bpp = t->m_Bpp; const size_t flags = t->m_Flags; - u8* const srcStorage = t->get_data(); + std::uint8_t* const srcStorage = t->get_data(); // sanity checks (not errors, we just can't handle these cases) // .. unknown transform @@ -330,12 +332,12 @@ static Status plain_transform(Tex* t, size_t transforms) // // this is necessary even when not flipping because the initial data // is read-only. - std::shared_ptr dstStorage; + std::shared_ptr dstStorage; AllocateAligned(dstStorage, dstSize); // setup row source/destination pointers (simplifies outer loop) - u8* dst = (u8*)dstStorage.get(); - const u8* src; + std::uint8_t* dst = static_cast(dstStorage.get()); + const std::uint8_t* src; const size_t pitch = w * bpp/8; // source bpp (not necessarily dest bpp) // .. avoid y*pitch multiply in row loop; instead, add row_ofs. ssize_t row_ofs = (ssize_t)pitch; @@ -343,18 +345,18 @@ static Status plain_transform(Tex* t, size_t transforms) // flipping rows (0,1,2 -> 2,1,0) if(transforms & TEX_ORIENTATION) { - src = (const u8*)srcStorage+srcSize-pitch; // last row + src = static_cast(srcStorage) + srcSize - pitch; // last row row_ofs = -(ssize_t)pitch; } // adding/removing alpha channel (can't convert in-place) else if(transforms & TEX_ALPHA) { - src = (const u8*)srcStorage; + src = static_cast(srcStorage); } // do other transforms in-place else { - src = (const u8*)dstStorage.get(); + src = static_cast(dstStorage.get()); memcpy(dstStorage.get(), srcStorage, srcSize); } @@ -379,7 +381,7 @@ static Status plain_transform(Tex* t, size_t transforms) for(size_t x = 0; x < w; x++) { // need temporaries in case src == dst (i.e. not flipping) - const u8 b = src[0], g = src[1], r = src[2]; + const std::uint8_t b = src[0], g = src[1], r = src[2]; dst[0] = r; dst[1] = g; dst[2] = b; dst[3] = 0xFF; dst += 4; src += 3; @@ -395,7 +397,7 @@ static Status plain_transform(Tex* t, size_t transforms) for(size_t x = 0; x < w; x++) { // need temporaries in case src == dst (i.e. not flipping) - const u8 r = src[0], g = src[1], b = src[2]; + const std::uint8_t r = src[0], g = src[1], b = src[2]; dst[0] = r; dst[1] = g; dst[2] = b; dst[3] = 0xFF; dst += 4; src += 3; @@ -411,7 +413,7 @@ static Status plain_transform(Tex* t, size_t transforms) for(size_t x = 0; x < w; x++) { // need temporaries in case src == dst (i.e. not flipping) - const u8 b = src[0], g = src[1], r = src[2]; + const std::uint8_t b = src[0], g = src[1], r = src[2]; dst[0] = r; dst[1] = g; dst[2] = b; dst += 3; src += 3; @@ -427,7 +429,7 @@ static Status plain_transform(Tex* t, size_t transforms) for(size_t x = 0; x < w; x++) { // need temporaries in case src == dst (i.e. not flipping) - const u8 b = src[0], g = src[1], r = src[2], a = src[3]; + const std::uint8_t b = src[0], g = src[1], r = src[2], a = src[3]; dst[0] = r; dst[1] = g; dst[2] = b; dst[3] = a; dst += 4; src += 4; @@ -581,7 +583,8 @@ bool tex_is_known_extension(const VfsPath& pathname) // // we need only add bookkeeping information and "wrap" it in // our Tex struct, hence the name. -Status Tex::wrap(size_t w, size_t h, size_t bpp, size_t flags, const std::shared_ptr& data, size_t ofs) +Status Tex::wrap(size_t w, size_t h, size_t bpp, size_t flags, const std::shared_ptr& data, + size_t ofs) { m_Width = w; m_Height = h; @@ -618,12 +621,12 @@ void Tex::free() // returns a pointer to the image data (pixels), taking into account any // header(s) that may come before it. -u8* Tex::get_data() +std::uint8_t* Tex::get_data() { - // (can't use normal CHECK_TEX due to u8* return value) + // (can't use normal CHECK_TEX due to std::uint8_t* return value) WARN_IF_ERR(validate()); - u8* p = m_Data.get(); + std::uint8_t* p = m_Data.get(); if(!p) return nullptr; return p + m_Ofs; @@ -657,16 +660,16 @@ u32 Tex::get_average_color() const // extract components into u32 ENSURE(basetex.m_DataSize >= basetex.m_Ofs+4); - u8 b = basetex.m_Data.get()[basetex.m_Ofs]; - u8 g = basetex.m_Data.get()[basetex.m_Ofs+1]; - u8 r = basetex.m_Data.get()[basetex.m_Ofs+2]; - u8 a = basetex.m_Data.get()[basetex.m_Ofs+3]; + std::uint8_t b = basetex.m_Data.get()[basetex.m_Ofs]; + std::uint8_t g = basetex.m_Data.get()[basetex.m_Ofs+1]; + std::uint8_t r = basetex.m_Data.get()[basetex.m_Ofs+2]; + std::uint8_t a = basetex.m_Data.get()[basetex.m_Ofs+3]; return b + (g << 8) + (r << 16) + (a << 24); } static void add_level_size(size_t /*level*/, size_t /*level_w*/, size_t /*level_h*/, - const u8* RESTRICT /*level_data*/, size_t level_dataSize, void* RESTRICT cbData) + const std::uint8_t* RESTRICT /*level_data*/, size_t level_dataSize, void* RESTRICT cbData) { size_t* ptotal_size = (size_t*)cbData; *ptotal_size += level_dataSize; @@ -709,7 +712,7 @@ size_t tex_hdr_size(const VfsPath& filename) // read/write from memory and disk //----------------------------------------------------------------------------- -Status Tex::decode(const std::shared_ptr& Data, size_t DataSize) +Status Tex::decode(const std::shared_ptr& Data, size_t DataSize) { const ITexCodec* c; RETURN_STATUS_IF_ERR(tex_codec_for_header(Data.get(), DataSize, &c)); @@ -782,7 +785,7 @@ void Tex::UpdateMIPLevels() m_MIPLevels.reserve(std::bit_width(maxSide) + !std::has_single_bit(maxSide)); } - u8* levelData = m_Data.get(); + std::uint8_t* levelData = m_Data.get(); levelData += m_Ofs; const u32 dataPadding = (m_Flags & TEX_DXT) != 0 ? 4 : 1; diff --git a/source/lib/tex/tex.h b/source/lib/tex/tex.h index 313aff5af2..7e16d7515d 100644 --- a/source/lib/tex/tex.h +++ b/source/lib/tex/tex.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -217,7 +217,7 @@ public: struct MIPLevel { // A pointer to the mip level image data (pixels). - u8* data; + std::uint8_t* data; u32 dataSize; u32 width; u32 height; @@ -228,7 +228,7 @@ public: * (which may occur when being loaded), this may be replaced with * a new buffer (e.g. if decompressing file contents). **/ - std::shared_ptr m_Data; + std::shared_ptr m_Data; size_t m_DataSize; @@ -277,7 +277,7 @@ public: * @param data_size Its size [bytes]. * @return Status. **/ - Status decode(const std::shared_ptr& data, size_t data_size); + Status decode(const std::shared_ptr& data, size_t data_size); /** * encode a texture into a memory buffer in the desired file format. @@ -312,7 +312,7 @@ public: * @param ofs * @return Status **/ - Status wrap(size_t w, size_t h, size_t bpp, size_t flags, const std::shared_ptr& data, size_t ofs); + Status wrap(size_t w, size_t h, size_t bpp, size_t flags, const std::shared_ptr& data, size_t ofs); // // modify image @@ -345,7 +345,7 @@ public: * * @return pointer to the data. **/ - u8* get_data(); + std::uint8_t* get_data(); const std::vector& GetMIPLevels() const { return m_MIPLevels; } @@ -397,7 +397,8 @@ const int TEX_BASE_LEVEL_ONLY = -1; * @param level_data_size [bytes] * @param cbData passed through from tex_util_foreach_mipmap. **/ -typedef void (*MipmapCB)(size_t level, size_t level_w, size_t level_h, const u8* RESTRICT level_data, size_t level_data_size, void* RESTRICT cbData); +typedef void (*MipmapCB)(size_t level, size_t level_w, size_t level_h, + const std::uint8_t* RESTRICT level_data, size_t level_data_size, void* RESTRICT cbData); /** * for a series of mipmaps stored from base to highest, call back for @@ -416,7 +417,7 @@ typedef void (*MipmapCB)(size_t level, size_t level_w, size_t level_h, const u8* * @param cb MipmapCB to call. * @param cbData Extra data to pass to cb. **/ -extern void tex_util_foreach_mipmap(size_t w, size_t h, size_t bpp, const u8* data, int levels_to_skip, size_t data_padding, MipmapCB cb, void* RESTRICT cbData); +extern void tex_util_foreach_mipmap(size_t w, size_t h, size_t bpp, const std::uint8_t* data, int levels_to_skip, size_t data_padding, MipmapCB cb, void* RESTRICT cbData); // diff --git a/source/lib/tex/tex_bmp.cpp b/source/lib/tex/tex_bmp.cpp index 471529162c..7a1b416867 100644 --- a/source/lib/tex/tex_bmp.cpp +++ b/source/lib/tex/tex_bmp.cpp @@ -75,7 +75,7 @@ Status TexCodecBmp::transform(Tex*, size_t /*transforms*/) const } -bool TexCodecBmp::is_hdr(const u8* file) const +bool TexCodecBmp::is_hdr(const std::uint8_t* file) const { // check header signature (bfType == "BM"?). // we compare single bytes to be endian-safe. @@ -89,7 +89,7 @@ bool TexCodecBmp::is_ext(const OsPath& extension) const } -size_t TexCodecBmp::hdr_size(const u8* file) const +size_t TexCodecBmp::hdr_size(const std::uint8_t* file) const { const size_t hdr_size = sizeof(BmpHeader); if(file) @@ -104,7 +104,7 @@ size_t TexCodecBmp::hdr_size(const u8* file) const // requirements: uncompressed, direct color, bottom up -Status TexCodecBmp::decode(u8* RESTRICT data, size_t /*size*/, Tex* RESTRICT t) const +Status TexCodecBmp::decode(std::uint8_t* RESTRICT data, size_t /*size*/, Tex* RESTRICT t) const { const BmpHeader* hdr = (const BmpHeader*)data; const long w = (long)read_le32(&hdr->biWidth); diff --git a/source/lib/tex/tex_codec.cpp b/source/lib/tex/tex_codec.cpp index c994f57007..33a3b6abd9 100644 --- a/source/lib/tex/tex_codec.cpp +++ b/source/lib/tex/tex_codec.cpp @@ -64,7 +64,7 @@ Status tex_codec_for_filename(const OsPath& extension, const ITexCodec** c) // find codec that recognizes the header's magic field -Status tex_codec_for_header(const u8* file, size_t file_size, const ITexCodec** c) +Status tex_codec_for_header(const std::uint8_t* file, size_t file_size, const ITexCodec** c) { // we guarantee at least 4 bytes for is_hdr to look at if(file_size < 4) @@ -118,7 +118,8 @@ Status tex_codec_transform(Tex* t, size_t transforms) // // note: we don't allocate the data param ourselves because this function is // needed for encoding, too (where data is already present). -std::vector tex_codec_alloc_rows(const u8* data, size_t h, size_t pitch, size_t src_flags, size_t dst_orientation) +std::vector tex_codec_alloc_rows(const std::uint8_t* data, size_t h, size_t pitch, + size_t src_flags, size_t dst_orientation) { const bool flip = !tex_orientations_match(src_flags, dst_orientation); diff --git a/source/lib/tex/tex_codec.h b/source/lib/tex/tex_codec.h index 6bd4e80f22..bd3bd70aea 100644 --- a/source/lib/tex/tex_codec.h +++ b/source/lib/tex/tex_codec.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -30,7 +30,6 @@ #include "lib/code_annotation.h" #include "lib/os_path.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -58,7 +57,7 @@ public: * @param t output texture object * @return Status **/ - virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const = 0; + virtual Status decode(std::uint8_t* data, size_t size, Tex* RESTRICT t) const = 0; /** * encode the texture data into the codec's file format (in memory). @@ -92,7 +91,7 @@ public: * (this should be enough to examine the header's 'magic' field) * @return bool **/ - virtual bool is_hdr(const u8* file) const = 0; + virtual bool is_hdr(const std::uint8_t* file) const = 0; /** * is the extension that of a file format supported by this codec? @@ -115,7 +114,7 @@ public: * variable-length fields. * @return size [bytes] **/ - virtual size_t hdr_size(const u8* file) const = 0; + virtual size_t hdr_size(const std::uint8_t* file) const = 0; /** * name of codec for debug purposes. typically set via TEX_CODEC_REGISTER. @@ -127,12 +126,12 @@ public: class TexCodecPng:ITexCodec { public: - virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; + virtual Status decode(std::uint8_t* data, size_t size, Tex* RESTRICT t) const; virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; virtual Status transform(Tex* t, size_t transforms) const; - virtual bool is_hdr(const u8* file) const; + virtual bool is_hdr(const std::uint8_t* file) const; virtual bool is_ext(const OsPath& extension) const; - virtual size_t hdr_size(const u8* file) const; + virtual size_t hdr_size(const std::uint8_t* file) const; virtual const wchar_t* get_name() const { static const wchar_t *name = L"png"; return name; @@ -141,12 +140,12 @@ public: class TexCodecDds:ITexCodec { public: - virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; + virtual Status decode(std::uint8_t* data, size_t size, Tex* RESTRICT t) const; virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; virtual Status transform(Tex* t, size_t transforms) const; - virtual bool is_hdr(const u8* file) const; + virtual bool is_hdr(const std::uint8_t* file) const; virtual bool is_ext(const OsPath& extension) const; - virtual size_t hdr_size(const u8* file) const; + virtual size_t hdr_size(const std::uint8_t* file) const; virtual const wchar_t* get_name() const { static const wchar_t *name = L"dds"; return name; @@ -155,12 +154,12 @@ public: class TexCodecTga:ITexCodec { public: - virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; + virtual Status decode(std::uint8_t* data, size_t size, Tex* RESTRICT t) const; virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; virtual Status transform(Tex* t, size_t transforms) const; - virtual bool is_hdr(const u8* file) const; + virtual bool is_hdr(const std::uint8_t* file) const; virtual bool is_ext(const OsPath& extension) const; - virtual size_t hdr_size(const u8* file) const; + virtual size_t hdr_size(const std::uint8_t* file) const; virtual const wchar_t* get_name() const { static const wchar_t *name = L"tga"; return name; @@ -169,12 +168,12 @@ public: class TexCodecBmp:ITexCodec { public: - virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; + virtual Status decode(std::uint8_t* data, size_t size, Tex* RESTRICT t) const; virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; virtual Status transform(Tex* t, size_t transforms) const; - virtual bool is_hdr(const u8* file) const; + virtual bool is_hdr(const std::uint8_t* file) const; virtual bool is_ext(const OsPath& extension) const; - virtual size_t hdr_size(const u8* file) const; + virtual size_t hdr_size(const std::uint8_t* file) const; virtual const wchar_t* get_name() const { static const wchar_t *name = L"bmp"; return name; @@ -202,7 +201,7 @@ extern Status tex_codec_for_filename(const OsPath& extension, const ITexCodec** * @return Status; ERR::RES_UNKNOWN_FORMAT if no codec indicates they can * handle the given format (header). **/ -extern Status tex_codec_for_header(const u8* data, size_t data_size, const ITexCodec** c); +extern Status tex_codec_for_header(const std::uint8_t* data, size_t data_size, const ITexCodec** c); /** * transform the texture's pixel format. @@ -234,8 +233,8 @@ extern Status tex_codec_transform(Tex* t, size_t transforms); * "global orientation". * depending on src and dst, the row array is flipped if necessary. **/ -typedef const u8* RowPtr; -extern std::vector tex_codec_alloc_rows(const u8* data, size_t h, size_t pitch, size_t src_flags, size_t dst_orientation); +typedef const std::uint8_t* RowPtr; +extern std::vector tex_codec_alloc_rows(const std::uint8_t* data, size_t h, size_t pitch, size_t src_flags, size_t dst_orientation); /** * apply transforms and then copy header and image into output buffer. diff --git a/source/lib/tex/tex_dds.cpp b/source/lib/tex/tex_dds.cpp index 4053150621..86f33e5343 100644 --- a/source/lib/tex/tex_dds.cpp +++ b/source/lib/tex/tex_dds.cpp @@ -64,25 +64,25 @@ class S3tcBlock { public: - S3tcBlock(size_t dxt, const u8* RESTRICT block) + S3tcBlock(size_t dxt, const std::uint8_t* RESTRICT block) : m_Dxt(dxt) { // (careful, 'dxt != 1' doesn't work - there's also DXT1a) - const u8* a_block = block; - const u8* c_block = (dxt == 3 || dxt == 5)? block+8 : block; + const std::uint8_t* a_block = block; + const std::uint8_t* c_block = (dxt == 3 || dxt == 5)? block+8 : block; PrecalculateAlpha(dxt, a_block); PrecalculateColor(dxt, c_block); } - void WritePixel(size_t pixel_idx, u8* RESTRICT out) const + void WritePixel(size_t pixel_idx, std::uint8_t* RESTRICT out) const { ENSURE(pixel_idx < 16); // pixel index -> color selector (2 bit) -> color const size_t c_selector = access_bit_tbl(c_selectors, pixel_idx, 2); for(int i = 0; i < 3; i++) - out[i] = (u8)c[c_selector][i]; + out[i] = static_cast(c[c_selector][i]); // if no alpha, done if(m_Dxt == 1) @@ -104,13 +104,14 @@ public: // (m_Dxt == DXT1A) else a = c[c_selector][A]; - out[A] = (u8)(a & 0xFF); + out[A] = static_cast(a & 0xFF); } private: - // pixel colors are stored as size_t[4]. size_t rather than u8 protects from - // overflow during calculations, and padding to an even size is a bit - // more efficient (even though we don't need the alpha component). + // pixel colors are stored as size_t[4]. size_t rather than std::uint8_t + // protects from overflow during calculations, and padding to an even + // size is a bit more efficient (even though we don't need the alpha + // component). enum RGBA { R, G, B, A }; static inline void mix_2_3(size_t dst[4], size_t c0[4], size_t c1[4]) @@ -142,10 +143,10 @@ private: return (field << num_filler_bits) | filler; } - void PrecalculateAlpha(size_t dxt, const u8* RESTRICT a_block) + void PrecalculateAlpha(size_t dxt, const std::uint8_t* RESTRICT a_block) { // read block contents - const u8 a0 = a_block[0], a1 = a_block[1]; + const std::uint8_t a0 = a_block[0], a1 = a_block[1]; a_bits = read_le64(a_block); // see below if(dxt == 5) @@ -154,7 +155,7 @@ private: a_bits >>= 16; const bool is_dxt5_special_combination = (a0 <= a1); - u8* a = dxt5_a_tbl; // shorthand + std::uint8_t* a = dxt5_a_tbl; // shorthand if(is_dxt5_special_combination) { a[0] = a0; @@ -181,7 +182,7 @@ private: } - void PrecalculateColor(size_t dxt, const u8* RESTRICT c_block) + void PrecalculateColor(size_t dxt, const std::uint8_t* RESTRICT c_block) { // read block contents // .. S3TC reference colors (565 format). the color table is generated @@ -220,7 +221,7 @@ private: size_t c[4][4]; // c[i][RGBA_component] // (DXT5 only) the 8 alpha choices - u8 dxt5_a_tbl[8]; + std::uint8_t dxt5_a_tbl[8]; // alpha block; interpretation depends on dxt. u64 a_bits; @@ -237,11 +238,11 @@ struct S3tcDecompressInfo size_t dxt; size_t s3tc_block_size; size_t out_Bpp; - u8* out; + std::uint8_t* out; }; static void s3tc_decompress_level(size_t /*level*/, size_t level_w, size_t level_h, - const u8* RESTRICT level_data, size_t level_data_size, void* RESTRICT cbData) + const std::uint8_t* RESTRICT level_data, size_t level_data_size, void* RESTRICT cbData) { S3tcDecompressInfo* di = (S3tcDecompressInfo*)cbData; const size_t dxt = di->dxt; @@ -252,7 +253,7 @@ static void s3tc_decompress_level(size_t /*level*/, size_t level_w, size_t level // 4x4 pixel block boundaries. const size_t blocks_w = DivideRoundUp(level_w, size_t(4)); const size_t blocks_h = DivideRoundUp(level_h, size_t(4)); - const u8* s3tc_data = level_data; + const std::uint8_t* s3tc_data = level_data; ENSURE(level_data_size % s3tc_block_size == 0); for(size_t block_y = 0; block_y < blocks_h; block_y++) @@ -267,7 +268,7 @@ static void s3tc_decompress_level(size_t /*level*/, size_t level_w, size_t level { // this is ugly, but advancing after x, y and block_y loops // is no better. - u8* out = (u8*)di->out + ((block_y*4+y)*blocks_w*4 + block_x*4) * di->out_Bpp; + std::uint8_t* out = static_cast(di->out) + ((block_y*4+y)*blocks_w*4 + block_x*4) * di->out_Bpp; for(int x = 0; x < 4; x++) { block.WritePixel(pixel_idx, out); @@ -296,12 +297,12 @@ static Status s3tc_decompress(Tex* t) const size_t dxt = t->m_Flags & TEX_DXT; const size_t out_bpp = (dxt != 1)? 32 : 24; const size_t out_size = t->img_size() * out_bpp / t->m_Bpp; - std::shared_ptr decompressedData; + std::shared_ptr decompressedData; AllocateAligned(decompressedData, out_size, g_PageSize); const size_t s3tc_block_size = (dxt == 3 || dxt == 5)? 16 : 8; S3tcDecompressInfo di = { dxt, s3tc_block_size, out_bpp/8, decompressedData.get() }; - const u8* s3tc_data = t->get_data(); + const std::uint8_t* s3tc_data = t->get_data(); const int levels_to_skip = (t->m_Flags & TEX_MIPMAPS)? 0 : TEX_BASE_LEVEL_ONLY; tex_util_foreach_mipmap(t->m_Width, t->m_Height, t->m_Bpp, s3tc_data, levels_to_skip, 4, s3tc_decompress_level, &di); t->m_Data = decompressedData; @@ -606,7 +607,7 @@ static Status decode_sd(const DDS_HEADER* sd, size_t& w, size_t& h, size_t& bpp, //----------------------------------------------------------------------------- -bool TexCodecDds::is_hdr(const u8* file) const +bool TexCodecDds::is_hdr(const std::uint8_t* file) const { return *(u32*)file == FOURCC('D','D','S',' '); } @@ -618,13 +619,13 @@ bool TexCodecDds::is_ext(const OsPath& extension) const } -size_t TexCodecDds::hdr_size(const u8* /*file*/) const +size_t TexCodecDds::hdr_size(const std::uint8_t* /*file*/) const { return 4+sizeof(DDS_HEADER); } -Status TexCodecDds::decode(u8* RESTRICT data, size_t /*size*/, Tex* RESTRICT t) const +Status TexCodecDds::decode(std::uint8_t* RESTRICT data, size_t /*size*/, Tex* RESTRICT t) const { const DDS_HEADER* sd = (const DDS_HEADER*)(data+4); RETURN_STATUS_IF_ERR(decode_sd(sd, t->m_Width, t->m_Height, t->m_Bpp, t->m_Flags)); diff --git a/source/lib/tex/tex_png.cpp b/source/lib/tex/tex_png.cpp index 4c741d8791..a09b81881f 100644 --- a/source/lib/tex/tex_png.cpp +++ b/source/lib/tex/tex_png.cpp @@ -65,7 +65,7 @@ class MemoryStream { public: - MemoryStream(u8* RESTRICT data, size_t size) + MemoryStream(std::uint8_t* RESTRICT data, size_t size) : data(data), size(size), pos(0) { } @@ -76,21 +76,21 @@ public: return size-pos; } - void CopyTo(u8* RESTRICT dst, size_t dstSize) + void CopyTo(std::uint8_t* RESTRICT dst, size_t dstSize) { memcpy(dst, data+pos, dstSize); pos += dstSize; } private: - u8* RESTRICT data; + std::uint8_t* RESTRICT data; size_t size; size_t pos; }; // pass data from PNG file in memory to libpng -static void io_read(png_struct* png_ptr, u8* RESTRICT data, png_size_t size) +static void io_read(png_struct* png_ptr, std::uint8_t* RESTRICT data, png_size_t size) { MemoryStream* stream = (MemoryStream*)png_get_io_ptr(png_ptr); if(stream->RemainingSize() < size) @@ -104,7 +104,7 @@ static void io_read(png_struct* png_ptr, u8* RESTRICT data, png_size_t size) // write libpng output to PNG file -static void io_write(png_struct* png_ptr, u8* data, png_size_t length) +static void io_write(png_struct* png_ptr, std::uint8_t* data, png_size_t length) { DynArray* da = (DynArray*)png_get_io_ptr(png_ptr); if(da_append(da, data, length) != 0) @@ -194,7 +194,7 @@ static Status png_decode_impl(MemoryStream* stream, png_structp png_ptr, png_inf flags |= TEX_GREY; const size_t img_size = pitch * h; - std::shared_ptr data; + std::shared_ptr data; AllocateAligned(data, img_size, g_PageSize); std::vector rows = tex_codec_alloc_rows(data.get(), h, pitch, TEX_TOP_DOWN, 0); @@ -237,7 +237,7 @@ static Status png_encode_impl(Tex* t, png_structp png_ptr, png_infop info_ptr, D png_set_IHDR(png_ptr, info_ptr, w, h, 8, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - u8* data = t->get_data(); + std::uint8_t* data = t->get_data(); std::vector rows = tex_codec_alloc_rows(data, h, pitch, t->m_Flags, TEX_TOP_DOWN); // PNG is native RGB. @@ -251,7 +251,7 @@ static Status png_encode_impl(Tex* t, png_structp png_ptr, png_infop info_ptr, D -bool TexCodecPng::is_hdr(const u8* file) const +bool TexCodecPng::is_hdr(const std::uint8_t* file) const { // don't use png_sig_cmp, so we don't pull in libpng for // this check alone (it might not actually be used). @@ -265,7 +265,7 @@ bool TexCodecPng::is_ext(const OsPath& extension) const } -size_t TexCodecPng::hdr_size(const u8* /*file*/) const +size_t TexCodecPng::hdr_size(const std::uint8_t* /*file*/) const { return 0; // libpng returns decoded image data; no header } @@ -280,7 +280,7 @@ static void user_warning_fn(png_structp, png_const_charp warning_msg) } // limitation: palette images aren't supported -Status TexCodecPng::decode(u8* RESTRICT data, size_t size, Tex* RESTRICT t) const +Status TexCodecPng::decode(std::uint8_t* RESTRICT data, size_t size, Tex* RESTRICT t) const { png_infop info_ptr = 0; diff --git a/source/lib/tex/tex_tga.cpp b/source/lib/tex/tex_tga.cpp index acc1418443..7ef3899881 100644 --- a/source/lib/tex/tex_tga.cpp +++ b/source/lib/tex/tex_tga.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -54,19 +54,19 @@ enum TgaImgDesc typedef struct { - u8 img_id_len; // 0 - no image identifier present - u8 color_map_type; // 0 - no color map present - u8 img_type; // see TgaImgType - u8 color_map[5]; // unused + std::uint8_t img_id_len; // 0 - no image identifier present + std::uint8_t color_map_type; // 0 - no color map present + std::uint8_t img_type; // see TgaImgType + std::uint8_t color_map[5]; // unused u16 x_origin; // unused u16 y_origin; // unused u16 w; u16 h; - u8 bpp; // bits per pixel + std::uint8_t bpp; // bits per pixel - u8 img_desc; + std::uint8_t img_desc; } TgaHeader; @@ -81,7 +81,7 @@ Status TexCodecTga::transform(Tex*, size_t /*transforms*/) const } -bool TexCodecTga::is_hdr(const u8* file) const +bool TexCodecTga::is_hdr(const std::uint8_t* file) const { TgaHeader* hdr = (TgaHeader*)file; @@ -107,7 +107,7 @@ bool TexCodecTga::is_ext(const OsPath& extension) const } -size_t TexCodecTga::hdr_size(const u8* file) const +size_t TexCodecTga::hdr_size(const std::uint8_t* file) const { size_t hdr_size = sizeof(TgaHeader); if(file) @@ -120,14 +120,14 @@ size_t TexCodecTga::hdr_size(const u8* file) const // requirements: uncompressed, direct color, bottom up -Status TexCodecTga::decode(u8* RESTRICT data, size_t /*size*/, Tex* RESTRICT t) const +Status TexCodecTga::decode(std::uint8_t* RESTRICT data, size_t /*size*/, Tex* RESTRICT t) const { const TgaHeader* hdr = (const TgaHeader*)data; - const u8 type = hdr->img_type; + const std::uint8_t type = hdr->img_type; const size_t w = read_le16(&hdr->w); const size_t h = read_le16(&hdr->h); const size_t bpp = hdr->bpp; - const u8 desc = hdr->img_desc; + const std::uint8_t desc = hdr->img_desc; size_t flags = 0; flags |= (desc & TGA_TOP_DOWN)? TEX_TOP_DOWN : TEX_BOTTOM_UP; @@ -154,7 +154,7 @@ Status TexCodecTga::decode(u8* RESTRICT data, size_t /*size*/, Tex* RESTRICT t) Status TexCodecTga::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const { - u8 img_desc = 0; + std::uint8_t img_desc = 0; if(t->m_Flags & TEX_TOP_DOWN) img_desc |= TGA_TOP_DOWN; if(t->m_Bpp == 32) @@ -169,12 +169,12 @@ Status TexCodecTga::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const { 0, // no image identifier present 0, // no color map present - (u8)img_type, + static_cast(img_type), {0,0,0,0,0}, // unused (color map) 0, 0, // unused (origin) (u16)t->m_Width, (u16)t->m_Height, - (u8)t->m_Bpp, + static_cast(t->m_Bpp), img_desc }; const size_t hdr_size = sizeof(hdr); diff --git a/source/lib/types.h b/source/lib/types.h index b3a4a90693..e40e48a6b8 100644 --- a/source/lib/types.h +++ b/source/lib/types.h @@ -29,7 +29,6 @@ #include -typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; diff --git a/source/lib/utf8.cpp b/source/lib/utf8.cpp index 784424bb44..2cef580d5c 100644 --- a/source/lib/utf8.cpp +++ b/source/lib/utf8.cpp @@ -75,7 +75,7 @@ STATUS_ADD_DEFINITIONS(utf8StatusDefinitions); // this implementation survives http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt // (must be unsigned to avoid sign extension) -typedef u8 UTF8; +typedef std::uint8_t UTF8; typedef u32 UTF32; diff --git a/source/maths/MD5.cpp b/source/maths/MD5.cpp index f5675e6e57..f0d7348be4 100644 --- a/source/maths/MD5.cpp +++ b/source/maths/MD5.cpp @@ -39,7 +39,7 @@ void MD5::InitState() memset(m_Buf, 0xcc, sizeof(m_Buf)); } -void MD5::UpdateRest(const u8* data, size_t len) +void MD5::UpdateRest(const std::uint8_t* data, size_t len) { const size_t CHUNK_SIZE = sizeof(m_Buf); @@ -72,24 +72,24 @@ void MD5::UpdateRest(const u8* data, size_t len) m_BufLen = len; } -void MD5::Final(u8* digest) +void MD5::Final(std::uint8_t* digest) { // Compute the message length in bits (before padding) u64 len = m_InputLen * 8; // Pad with 1-bit - const u8 pad = 0x80; + const std::uint8_t pad = 0x80; Update(&pad, 1); // Fill with zeros until length % 64 = 56 (bytes) while (m_BufLen % 64 != 56) { - const u8 zero = 0; + const std::uint8_t zero = 0; Update(&zero, 1); } // Append the length (assumes little-endian) - Update((const u8*)&len, 8); + Update(reinterpret_cast(&len), 8); // Return the digest (assumes little-endian) memcpy(digest, m_Digest, DIGESTSIZE); diff --git a/source/maths/MD5.h b/source/maths/MD5.h index fc84607e5e..e1a6c7704f 100644 --- a/source/maths/MD5.h +++ b/source/maths/MD5.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 @@ -34,7 +34,7 @@ public: MD5(); - void Update(const u8* data, size_t len) + void Update(const std::uint8_t* data, size_t len) { // (Defined inline for efficiency in the common fixed-length fits-in-buffer case) @@ -60,14 +60,14 @@ public: UpdateRest(data, len); } - void Final(u8* digest); + void Final(std::uint8_t* digest); private: void InitState(); - void UpdateRest(const u8* data, size_t len); + void UpdateRest(const std::uint8_t* data, size_t len); void Transform(const u32* in); u32 m_Digest[4]; // internal state - u8 m_Buf[64]; // buffered input bytes + std::uint8_t m_Buf[64]; // buffered input bytes size_t m_BufLen; // bytes in m_Buf that are valid u64 m_InputLen; // bytes }; diff --git a/source/maths/tests/test_MD5.h b/source/maths/tests/test_MD5.h index ae36c3f0ed..90492fa25f 100644 --- a/source/maths/tests/test_MD5.h +++ b/source/maths/tests/test_MD5.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -17,7 +17,6 @@ #include "lib/self_test.h" -#include "lib/types.h" #include "maths/MD5.h" #include "ps/Util.h" @@ -27,17 +26,17 @@ class TestMD5 : public CxxTest::TestSuite { public: - std::string decode(u8* digest) + std::string decode(std::uint8_t* digest) { return Hexify(digest, MD5::DIGESTSIZE); } void compare(const char* input, const char* expected) { - u8 digest[MD5::DIGESTSIZE]; + std::uint8_t digest[MD5::DIGESTSIZE]; MD5 m; - m.Update((const u8*)input, strlen(input)); + m.Update(reinterpret_cast(input), strlen(input)); m.Final(digest); TSM_ASSERT_STR_EQUALS(input, decode(digest), expected); @@ -96,9 +95,10 @@ public: void test_chunks() { - u8 digest[MD5::DIGESTSIZE]; + std::uint8_t digest[MD5::DIGESTSIZE]; - const u8* in = (const u8*)"12345678901234567890123456789012345678901234567890123456789012345678901234567890"; + const std::uint8_t* in = reinterpret_cast( + "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); size_t len = 80; const char* expected = "57edf4a22be3c955ac49da2e2107b67a"; diff --git a/source/network/NMTCreator.h b/source/network/NMTCreator.h index 8daf8daaba..3d139ce069 100644 --- a/source/network/NMTCreator.h +++ b/source/network/NMTCreator.h @@ -66,7 +66,7 @@ * have several classes with the same value of _tp in the same executable */ #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ -CNetMessage *Deserialize##_nm(const u8 *, size_t); \ +CNetMessage *Deserialize##_nm(const std::uint8_t *, size_t); \ class _nm: public _base \ { \ protected: \ @@ -78,8 +78,8 @@ protected: \ public: \ _nm(): _base(_tp) {} \ virtual size_t GetSerializedLength() const; \ - virtual u8 *Serialize(u8 *buffer) const; \ - virtual const u8 *Deserialize(const u8 *pos, const u8 *end); \ + virtual std::uint8_t *Serialize(std::uint8_t *buffer) const; \ + virtual const std::uint8_t *Deserialize(const std::uint8_t *pos, const std::uint8_t *end); \ virtual CStr ToString() const; \ inline operator CStr () const \ { return ToString(); } @@ -185,10 +185,10 @@ size_t _nm::GetSerializedLength() const \ #define START_NMT_CLASS(_nm, _tp) \ START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp) #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ -u8 *_nm::Serialize(u8 *buffer) const \ +std::uint8_t* _nm::Serialize(std::uint8_t *buffer) const \ { \ /*printf("In " #_nm "::Serialize()\n");*/ \ - u8 *pos=_base::Serialize(buffer); \ + std::uint8_t *pos=_base::Serialize(buffer); \ [[maybe_unused]] const _nm *thiz=this; #define NMT_START_ARRAY(_nm) \ @@ -231,7 +231,7 @@ u8 *_nm::Serialize(u8 *buffer) const \ #define START_NMT_CLASS(_nm, _tp) \ START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp) #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ -const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \ +const std::uint8_t* _nm::Deserialize(const std::uint8_t *pos, const std::uint8_t *end) \ { \ pos=_base::Deserialize(pos, end); \ if (pos == NULL) BAIL_DESERIALIZER;\ diff --git a/source/network/NetHost.cpp b/source/network/NetHost.cpp index 5f07dea104..e8267b75c8 100644 --- a/source/network/NetHost.cpp +++ b/source/network/NetHost.cpp @@ -57,7 +57,7 @@ ENetPacket* CNetHost::CreatePacket(const CNetMessage* message) ENSURE(size); // else we'll fail when accessing the 0th element // Adjust buffer for message - std::vector buffer; + std::vector buffer; buffer.resize(size); // Save message to internal buffer diff --git a/source/network/NetHost.h b/source/network/NetHost.h index d0b81dbddc..42e4b6d0c1 100644 --- a/source/network/NetHost.h +++ b/source/network/NetHost.h @@ -24,7 +24,6 @@ #define NETHOST_H #include "lib/external_libraries/enet.h" -#include "lib/types.h" #include "ps/CStr.h" #include @@ -51,7 +50,7 @@ struct PlayerAssignment std::int32_t m_PlayerID; /// Status - Ready or not: 0 for not ready, 1 for ready, 2 to stay ready - u8 m_Status; + std::uint8_t m_Status; }; typedef std::map PlayerAssignmentMap; // map from GUID -> assignment diff --git a/source/network/NetMessage.cpp b/source/network/NetMessage.cpp index f83047df64..d1137c450e 100644 --- a/source/network/NetMessage.cpp +++ b/source/network/NetMessage.cpp @@ -41,7 +41,7 @@ CNetMessage::~CNetMessage() { } -u8* CNetMessage::Serialize(u8* pBuffer) const +std::uint8_t* CNetMessage::Serialize(std::uint8_t* pBuffer) const { size_t size = GetSerializedLength(); Serialize_int_1(pBuffer, m_Type); @@ -50,7 +50,7 @@ u8* CNetMessage::Serialize(u8* pBuffer) const return pBuffer; } -const u8* CNetMessage::Deserialize(const u8* pStart, const u8* pEnd) +const std::uint8_t* CNetMessage::Deserialize(const std::uint8_t* pStart, const std::uint8_t* pEnd) { if (pStart + 3 > pEnd) { @@ -58,7 +58,7 @@ const u8* CNetMessage::Deserialize(const u8* pStart, const u8* pEnd) return NULL; } - const u8* pBuffer = pStart; + const std::uint8_t* pBuffer = pStart; int type; size_t size; @@ -99,7 +99,8 @@ CNetMessage* CNetMessageFactory::CreateMessage(const void* pData, CNetMessage header; // Figure out message type - header.Deserialize((const u8*)pData, (const u8*)pData + dataSize); + header.Deserialize(static_cast(pData), + static_cast(pData) + dataSize); switch (header.GetType()) { @@ -230,7 +231,10 @@ CNetMessage* CNetMessageFactory::CreateMessage(const void* pData, } if (pNewMessage) - pNewMessage->Deserialize((const u8*)pData, (const u8*)pData + dataSize); + { + pNewMessage->Deserialize(static_cast(pData), + static_cast(pData) + dataSize); + } return pNewMessage; } diff --git a/source/network/NetMessage.h b/source/network/NetMessage.h index f7d3aba340..492f70c5ef 100644 --- a/source/network/NetMessage.h +++ b/source/network/NetMessage.h @@ -66,7 +66,7 @@ public: * @return The position in the buffer right after the * serialized message */ - virtual u8* Serialize(u8* pBuffer) const; + virtual std::uint8_t* Serialize(std::uint8_t* pBuffer) const; /** * Deserializes the message from the specified buffer. @@ -76,7 +76,7 @@ public: * @return The position in the buffer right after the * message or NULL if an error occurred */ - virtual const u8* Deserialize(const u8* pStart, const u8* pEnd); + virtual const std::uint8_t* Deserialize(const std::uint8_t* pStart, const std::uint8_t* pEnd); /** * Retrieves the size in bytes of the serialized message. Before calling @@ -133,8 +133,8 @@ public: */ CSimulationMessage(const CSimulationMessage& orig); - virtual u8* Serialize(u8* pBuffer) const; - virtual const u8* Deserialize(const u8* pStart, const u8* pEnd); + virtual std::uint8_t* Serialize(std::uint8_t* pBuffer) const; + virtual const std::uint8_t* Deserialize(const std::uint8_t* pStart, const std::uint8_t* pEnd); virtual size_t GetSerializedLength() const; virtual CStr ToString() const; @@ -155,8 +155,8 @@ class CGameSetupMessage : public CNetMessage public: CGameSetupMessage(const Script::Interface& scriptInterface); CGameSetupMessage(const Script::Interface& scriptInterface, JS::HandleValue data); - virtual u8* Serialize(u8* pBuffer) const; - virtual const u8* Deserialize(const u8* pStart, const u8* pEnd); + virtual std::uint8_t* Serialize(std::uint8_t* pBuffer) const; + virtual const std::uint8_t* Deserialize(const std::uint8_t* pStart, const std::uint8_t* pEnd); virtual size_t GetSerializedLength() const; virtual CStr ToString() const; diff --git a/source/network/NetMessageSim.cpp b/source/network/NetMessageSim.cpp index 2cccb5def2..3f75ef7fc1 100644 --- a/source/network/NetMessageSim.cpp +++ b/source/network/NetMessageSim.cpp @@ -41,12 +41,12 @@ namespace Script { class Interface; } class CBufferBinarySerializerImpl { public: - CBufferBinarySerializerImpl(u8* buffer) : + CBufferBinarySerializerImpl(std::uint8_t* buffer) : m_Buffer(buffer) { } - void Put([[maybe_unused]] const char* name, const u8* data, size_t len) + void Put([[maybe_unused]] const char* name, const std::uint8_t* data, size_t len) { #if DEBUG_SERIALIZER_ANNOTATE std::string tag = "<"; @@ -59,7 +59,7 @@ public: m_Buffer += len; } - u8* m_Buffer; + std::uint8_t* m_Buffer; }; /** @@ -68,12 +68,12 @@ public: class CBufferBinarySerializer : public CBinarySerializer { public: - CBufferBinarySerializer(const Script::Interface& scriptInterface, u8* buffer) : + CBufferBinarySerializer(const Script::Interface& scriptInterface, std::uint8_t* buffer) : CBinarySerializer(scriptInterface, buffer) { } - u8* GetBuffer() + std::uint8_t* GetBuffer() { return m_Impl.m_Buffer; } @@ -87,7 +87,7 @@ public: { } - void Put([[maybe_unused]] const char* name, const u8* /*data*/, size_t len) + void Put([[maybe_unused]] const char* name, const std::uint8_t* /*data*/, size_t len) { #if DEBUG_SERIALIZER_ANNOTATE m_Length += 2; // '<' and '>' @@ -143,11 +143,11 @@ CSimulationMessage::CSimulationMessage(const CSimulationMessage& orig) : m_Data.init(rq.cx, orig.m_Data); } -u8* CSimulationMessage::Serialize(u8* pBuffer) const +std::uint8_t* CSimulationMessage::Serialize(std::uint8_t* pBuffer) const { // TODO: ought to handle serialization exceptions // TODO: ought to represent common commands more efficiently - u8* pos = CNetMessage::Serialize(pBuffer); + std::uint8_t* pos = CNetMessage::Serialize(pBuffer); CBufferBinarySerializer serializer(m_ScriptInterface, pos); serializer.NumberU32_Unbounded("client", m_Client); serializer.NumberI32_Unbounded("player", m_Player); @@ -157,11 +157,11 @@ u8* CSimulationMessage::Serialize(u8* pBuffer) const return serializer.GetBuffer(); } -const u8* CSimulationMessage::Deserialize(const u8* pStart, const u8* pEnd) +const std::uint8_t* CSimulationMessage::Deserialize(const std::uint8_t* pStart, const std::uint8_t* pEnd) { // TODO: ought to handle serialization exceptions // TODO: ought to represent common commands more efficiently - const u8* pos = CNetMessage::Deserialize(pStart, pEnd); + const std::uint8_t* pos = CNetMessage::Deserialize(pStart, pEnd); std::istringstream stream(std::string(pos, pEnd)); CStdDeserializer deserializer(m_ScriptInterface, stream); deserializer.NumberU32_Unbounded("client", m_Client); @@ -210,19 +210,19 @@ CGameSetupMessage::CGameSetupMessage(const Script::Interface& scriptInterface, J m_Data.init(rq.cx, data); } -u8* CGameSetupMessage::Serialize(u8* pBuffer) const +std::uint8_t* CGameSetupMessage::Serialize(std::uint8_t* pBuffer) const { // TODO: ought to handle serialization exceptions - u8* pos = CNetMessage::Serialize(pBuffer); + std::uint8_t* pos = CNetMessage::Serialize(pBuffer); CBufferBinarySerializer serializer(m_ScriptInterface, pos); serializer.ScriptVal("command", const_cast(&m_Data)); return serializer.GetBuffer(); } -const u8* CGameSetupMessage::Deserialize(const u8* pStart, const u8* pEnd) +const std::uint8_t* CGameSetupMessage::Deserialize(const std::uint8_t* pStart, const std::uint8_t* pEnd) { // TODO: ought to handle serialization exceptions - const u8* pos = CNetMessage::Deserialize(pStart, pEnd); + const std::uint8_t* pos = CNetMessage::Deserialize(pStart, pEnd); std::istringstream stream(std::string(pos, pEnd)); CStdDeserializer deserializer(m_ScriptInterface, stream); deserializer.ScriptVal("command", const_cast(&m_Data)); diff --git a/source/network/NetMessages.h b/source/network/NetMessages.h index c1a66e627f..f5e6861d03 100644 --- a/source/network/NetMessages.h +++ b/source/network/NetMessages.h @@ -138,7 +138,7 @@ END_NMT_CLASS() START_NMT_CLASS_(AuthenticateResult, NMT_AUTHENTICATE_RESULT) NMT_FIELD_INT(m_Code, u32, 4) NMT_FIELD_INT(m_HostID, u32, 2) - NMT_FIELD_INT(m_IsController, u8, 1) + NMT_FIELD_INT(m_IsController, std::uint8_t, 1) NMT_FIELD(CStrW, m_Message) END_NMT_CLASS() @@ -152,7 +152,7 @@ END_NMT_CLASS() START_NMT_CLASS_(Ready, NMT_READY) NMT_FIELD(CStr, m_GUID) - NMT_FIELD_INT(m_Status, u8, 1) + NMT_FIELD_INT(m_Status, std::uint8_t, 1) END_NMT_CLASS() START_NMT_CLASS_(ClearAllReady, NMT_CLEAR_ALL_READY) @@ -163,7 +163,7 @@ START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT) NMT_FIELD(CStr, m_GUID) NMT_FIELD(CStrW, m_Name) NMT_FIELD_INT(m_PlayerID, std::int8_t, 1) - NMT_FIELD_INT(m_Status, u8, 1) + NMT_FIELD_INT(m_Status, std::uint8_t, 1) NMT_END_ARRAY() END_NMT_CLASS() @@ -204,7 +204,7 @@ END_NMT_CLASS() START_NMT_CLASS_(Kicked, NMT_KICKED) NMT_FIELD(CStrW, m_Name) - NMT_FIELD_INT(m_Ban, u8, 1) + NMT_FIELD_INT(m_Ban, std::uint8_t, 1) END_NMT_CLASS() START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT) @@ -227,7 +227,7 @@ END_NMT_CLASS() START_NMT_CLASS_(ClientPaused, NMT_CLIENT_PAUSED) NMT_FIELD(CStr, m_GUID) - NMT_FIELD_INT(m_Pause, u8, 1) + NMT_FIELD_INT(m_Pause, std::uint8_t, 1) END_NMT_CLASS() START_NMT_CLASS_(LoadedGame, NMT_LOADED_GAME) diff --git a/source/network/Serialization.h b/source/network/Serialization.h index 57e408f43a..b5aa18f940 100644 --- a/source/network/Serialization.h +++ b/source/network/Serialization.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -17,7 +17,6 @@ #include "lib/code_annotation.h" #include "lib/code_generation.h" -#include "lib/types.h" #include @@ -25,7 +24,7 @@ #define INCLUDED_NETWORK_SERIALIZATION #define Serialize_int_1(_pos, _val) \ - STMT( *((_pos)++) = (u8)((_val)&0xff); ) + STMT( *((_pos)++) = static_cast((_val)&0xff); ) #define Serialize_int_2(_pos, _val) STMT(\ Serialize_int_1(_pos, (_val)>>8); \ @@ -93,7 +92,7 @@ public: * @return a pointer to the location in the buffer right after the * serialized object */ - virtual u8 *Serialize(u8 *buffer) const = 0; + virtual std::uint8_t *Serialize(std::uint8_t *buffer) const = 0; /** * Deserialize the object (i.e. read in data from the buffer and initialize * the object's fields). Note that it is up to the deserializer to detect @@ -105,7 +104,7 @@ public: * @returns a pointer to the location in the buffer right after the * serialized object, or NULL if there was a data format error */ - virtual const u8 *Deserialize(const u8 *buffer, const u8 *end) = 0; + virtual const std::uint8_t *Deserialize(const std::uint8_t *buffer, const std::uint8_t *end) = 0; }; #endif diff --git a/source/network/StunClient.cpp b/source/network/StunClient.cpp index c2cc98d8ca..6792ecb891 100644 --- a/source/network/StunClient.cpp +++ b/source/network/StunClient.cpp @@ -63,7 +63,7 @@ const u16 m_IETFReview = 0x1 << 14; /** * These constants are defined in Section 15.1 of RFC 5389. */ -const u8 m_IPAddressFamilyIPv4 = 0x01; +const std::uint8_t m_IPAddressFamilyIPv4 = 0x01; /** * These constants are defined in Section 18.2 of RFC 5389. @@ -74,7 +74,7 @@ const u16 m_AttrTypeXORMappedAddress = 0x0020; /** * Described in section 3 of RFC 5389. */ -u8 m_TransactionID[12]; +std::uint8_t m_TransactionID[12]; ENetAddress m_StunServer; @@ -87,7 +87,7 @@ ENetAddress m_PublicAddress; * Push integral type to a network-byte-order buffer. */ template -void AddToBuffer(std::vector& buffer, const T value) +void AddToBuffer(std::vector& buffer, const T value) { buffer.reserve(buffer.size() + n); // std::byte* can alias anything so this is legal. @@ -95,9 +95,9 @@ void AddToBuffer(std::vector& buffer, const T value) for (size_t a = 0; a < n; ++a) { if constexpr (std::endian::native == std::endian::little) - buffer.push_back(static_cast(*(ptr + n - 1 - a))); + buffer.push_back(static_cast(*(ptr + n - 1 - a))); else - buffer.push_back(static_cast(*(ptr + a))); + buffer.push_back(static_cast(*(ptr + a))); } } @@ -105,7 +105,7 @@ void AddToBuffer(std::vector& buffer, const T value) * Read integral type from a network-byte-order buffer. */ template -bool GetFromBuffer(const std::vector& buffer, u32& offset, T& result) +bool GetFromBuffer(const std::vector& buffer, u32& offset, T& result) { if (offset + n > buffer.size()) return false; @@ -126,14 +126,14 @@ bool GetFromBuffer(const std::vector& buffer, u32& offset, T& result) void SendStunRequest(ENetHost& transactionHost, ENetAddress addr) { - std::vector buffer; + std::vector buffer; AddToBuffer(buffer, m_MethodTypeBinding); AddToBuffer(buffer, 0); // length AddToBuffer(buffer, m_MagicCookie); for (std::size_t i = 0; i < sizeof(m_TransactionID); ++i) { - u8 random_byte = rand() % 256; + std::uint8_t random_byte = rand() % 256; buffer.push_back(random_byte); m_TransactionID[i] = random_byte; } @@ -171,7 +171,7 @@ bool CreateStunRequest(ENetHost& transactionHost) /** * Gets the response from the STUN server and checks it for its validity. */ -bool ReceiveStunResponse(ENetHost& transactionHost, std::vector& buffer) +bool ReceiveStunResponse(ENetHost& transactionHost, std::vector& buffer) { // TransportAddress sender; const int LEN = 2048; @@ -213,12 +213,12 @@ bool ReceiveStunResponse(ENetHost& transactionHost, std::vector& buffer) // Convert to network string. buffer.resize(len); - memcpy(buffer.data(), reinterpret_cast(input_buffer), len); + memcpy(buffer.data(), reinterpret_cast(input_buffer), len); return true; } -bool ParseStunResponse(const std::vector& buffer) +bool ParseStunResponse(const std::vector& buffer) { u32 offset = 0; @@ -241,7 +241,7 @@ bool ParseStunResponse(const std::vector& buffer) for (std::size_t i = 0; i < sizeof(m_TransactionID); ++i) { - u8 transactionChar = 0; + std::uint8_t transactionChar = 0; if (!GetFromBuffer(buffer, offset, transactionChar) || transactionChar != m_TransactionID[i]) { LOGERROR("STUN response doesn't contain the transaction ID"); @@ -277,7 +277,7 @@ bool ParseStunResponse(const std::vector& buffer) // Ignore the first byte as mentioned in Section 15.1 of RFC 5389. ++offset; - u8 ipFamily = 0; + std::uint8_t ipFamily = 0; if (!GetFromBuffer(buffer, offset, ipFamily) || ipFamily != m_IPAddressFamilyIPv4) { LOGERROR("Unsupported address family, IPv4 is expected"); @@ -331,7 +331,7 @@ bool STUNRequestAndResponse(ENetHost& transactionHost) if (!CreateStunRequest(transactionHost)) return false; - std::vector buffer; + std::vector buffer; return ReceiveStunResponse(transactionHost, buffer) && ParseStunResponse(buffer); } diff --git a/source/network/tests/test_NetMessage.h b/source/network/tests/test_NetMessage.h index b79c145632..f15f5b3a7f 100644 --- a/source/network/tests/test_NetMessage.h +++ b/source/network/tests/test_NetMessage.h @@ -17,7 +17,6 @@ #include "lib/self_test.h" -#include "lib/types.h" #include "network/NetMessage.h" #include "ps/CStr.h" #include "scriptinterface/Object.h" @@ -43,7 +42,7 @@ public: TS_ASSERT_STR_EQUALS(msg.ToString(), "CSimulationMessage { m_Client: 1, m_Player: 2, m_Turn: 3, m_Data: [4] }"); size_t len = msg.GetSerializedLength(); - u8* buf = new u8[len+1]; + std::uint8_t* buf = new std::uint8_t[len+1]; buf[len] = '!'; TS_ASSERT_EQUALS(msg.Serialize(buf) - (buf+len), 0); TS_ASSERT_EQUALS(buf[len], '!'); diff --git a/source/ps/CConsole.cpp b/source/ps/CConsole.cpp index a8ddc70c65..0ae492421c 100644 --- a/source/ps/CConsole.cpp +++ b/source/ps/CConsole.cpp @@ -32,7 +32,6 @@ #include "lib/file/vfs/vfs.h" #include "lib/status.h" #include "lib/timer.h" -#include "lib/types.h" #include "lib/utf8.h" #include "maths/MathUtil.h" #include "maths/Rect.h" @@ -629,7 +628,7 @@ void CConsole::LoadHistory() if (!VfsFileExists(m_HistoryFile)) return; - std::unique_ptr buf; size_t buflen; + std::unique_ptr buf; size_t buflen; if (g_VFS->LoadFile(m_HistoryFile, buf, buflen) < 0) return; diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index 8c5f02a915..ca2adead68 100644 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -73,7 +73,7 @@ namespace } template - u8* SerializeImpl(const StrBase& str, u8* buffer) + std::uint8_t* SerializeImpl(const StrBase& str, std::uint8_t* buffer) { using Char = typename StrBase::value_type; ENSURE(buffer); @@ -106,7 +106,8 @@ namespace } template - const u8* DeserializeImpl(const u8* buffer, const u8* bufferend, StrBase& str) + const std::uint8_t* DeserializeImpl(const std::uint8_t* buffer, const std::uint8_t* bufferend, + StrBase& str) { using Char = typename StrBase::value_type; ENSURE(buffer); @@ -123,9 +124,9 @@ namespace else if constexpr (std::is_same_v) { const u16 *strend = (const u16 *)buffer; - while ((const u8 *)strend < bufferend && *strend) + while (reinterpret_cast(strend) < bufferend && *strend) strend++; - if ((const u8 *)strend >= bufferend) + if (reinterpret_cast(strend) >= bufferend) return nullptr; str.resize(strend - (const u16 *)buffer); @@ -138,7 +139,7 @@ namespace *(it++) = (Char)native; } - return (const u8 *)(strend + 1); + return reinterpret_cast(strend + 1); } else static_assert(AlwaysFalse::value, "Not implemented."); @@ -431,12 +432,12 @@ size_t CStr::GetHashCode() const // the result was truncated down to 32 anyway. } -u8* CStr::Serialize(u8* buffer) const +std::uint8_t* CStr::Serialize(std::uint8_t* buffer) const { return SerializeImpl(*this, buffer); } -const u8* CStr::Deserialize(const u8* buffer, const u8* bufferend) +const std::uint8_t* CStr::Deserialize(const std::uint8_t* buffer, const std::uint8_t* bufferend) { return DeserializeImpl(buffer, bufferend, *this); } diff --git a/source/ps/CStr.h b/source/ps/CStr.h index 4dd7347a7b..8467f9906a 100644 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -50,7 +50,6 @@ enum PS_TRIM_MODE #define CSTR_H_A #endif -#include "lib/types.h" #include "ps/CStrForward.h" #include @@ -223,8 +222,8 @@ public: // (These are not virtual or inherited from ISerializable, to avoid // adding a vtable and making the strings larger than std::string) size_t GetSerializedLength() const; - u8* Serialize(u8* buffer) const; - const u8* Deserialize(const u8* buffer, const u8* bufferend); + std::uint8_t* Serialize(std::uint8_t* buffer) const; + const std::uint8_t* Deserialize(const std::uint8_t* buffer, const std::uint8_t* bufferend); }; namespace std diff --git a/source/ps/CacheLoader.cpp b/source/ps/CacheLoader.cpp index 26ed1f212e..17df18fa4c 100644 --- a/source/ps/CacheLoader.cpp +++ b/source/ps/CacheLoader.cpp @@ -134,12 +134,12 @@ VfsPath CCacheLoader::LooseCachePath(const VfsPath& sourcePath, const MD5& initi // Construct a hash of the file data and settings. MD5 hash = initialHash; - hash.Update((const u8*)&mtime, sizeof(mtime)); - hash.Update((const u8*)&size, sizeof(size)); - hash.Update((const u8*)&version, sizeof(version)); + hash.Update(reinterpret_cast(&mtime), sizeof(mtime)); + hash.Update(reinterpret_cast(&size), sizeof(size)); + hash.Update(reinterpret_cast(&version), sizeof(version)); // these are local cached files, so we don't care about endianness etc - u8 digest[MD5::DIGESTSIZE]; + std::uint8_t digest[MD5::DIGESTSIZE]; hash.Final(digest); // Get the mod path diff --git a/source/ps/ConfigDB.cpp b/source/ps/ConfigDB.cpp index 6849052e96..170bd7b33a 100644 --- a/source/ps/ConfigDB.cpp +++ b/source/ps/ConfigDB.cpp @@ -311,7 +311,7 @@ bool CConfigDB::Reload(EConfigNamespace ns) std::lock_guard s(m_Mutex); - std::unique_ptr buffer; + std::unique_ptr buffer; size_t buflen; { // Handle missing files quietly @@ -485,7 +485,7 @@ bool CConfigDB::WriteFile(EConfigNamespace ns, const VfsPath& path) const CHECK_NS(false); std::lock_guard s(m_Mutex); - std::shared_ptr buf; + std::shared_ptr buf; const size_t buffersize = 1*MiB; AllocateAligned(buf, buffersize, maxSectorSize); diff --git a/source/ps/FileIo.h b/source/ps/FileIo.h index ab4e038bc0..f4b32534ed 100644 --- a/source/ps/FileIo.h +++ b/source/ps/FileIo.h @@ -145,7 +145,7 @@ public: private: // the data read from file and used during unpack operations - std::unique_ptr m_buf; + std::unique_ptr m_buf; size_t m_bufSize; size_t m_unpackPos; /// current unpack position in stream diff --git a/source/ps/Filesystem.cpp b/source/ps/Filesystem.cpp index 67409062cb..955c35257e 100644 --- a/source/ps/Filesystem.cpp +++ b/source/ps/Filesystem.cpp @@ -139,7 +139,7 @@ PSRETURN CVFSFile::Load(const PIVFS& vfs, const VfsPath& filename, bool log /* = return PSRETURN_OK; } -const u8* CVFSFile::GetBuffer() const +const std::uint8_t* CVFSFile::GetBuffer() const { return m_Buffer.get(); } @@ -156,7 +156,7 @@ CStr CVFSFile::GetAsString() const CStr CVFSFile::DecodeUTF8() const { - const u8* buffer = GetBuffer(); + const std::uint8_t* buffer = GetBuffer(); // Detect if there's a UTF-8 BOM and strip it if (GetBufferSize() >= 3 && buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF) diff --git a/source/ps/Filesystem.h b/source/ps/Filesystem.h index 769422538a..508b5757ef 100644 --- a/source/ps/Filesystem.h +++ b/source/ps/Filesystem.h @@ -22,7 +22,6 @@ #include "lib/file/vfs/vfs.h" #include "lib/file/vfs/vfs_path.h" #include "lib/status.h" -#include "lib/types.h" #include "ps/Errors.h" #include @@ -84,7 +83,7 @@ public: * Returns buffer of this file as a stream of bytes * @note file must have been successfully loaded */ - const u8* GetBuffer() const; + const std::uint8_t* GetBuffer() const; size_t GetBufferSize() const; /** @@ -100,7 +99,7 @@ public: CStr8 DecodeUTF8() const; private: - std::unique_ptr m_Buffer; + std::unique_ptr m_Buffer; size_t m_BufferSize; }; diff --git a/source/ps/GUID.cpp b/source/ps/GUID.cpp index 9d216c9675..3d9a597639 100644 --- a/source/ps/GUID.cpp +++ b/source/ps/GUID.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 @@ -37,7 +37,7 @@ CStr ps_generate_guid(void) for (size_t i = 0; i < 2; ++i) { u32 r = 0; - sys_generate_random_bytes((u8*)&r, sizeof(r)); + sys_generate_random_bytes(reinterpret_cast(&r), sizeof(r)); char buf[32]; sprintf_s(buf, ARRAY_SIZE(buf), "%08X", r); guid += buf; diff --git a/source/ps/ModIo.cpp b/source/ps/ModIo.cpp index 996bd4c79b..3bea09d8b4 100644 --- a/source/ps/ModIo.cpp +++ b/source/ps/ModIo.cpp @@ -192,11 +192,11 @@ size_t ModIo::DownloadCallback(void* buffer, size_t size, size_t nmemb, void* us // but we do not want to have a possibly valid hash in that case. size_t written = len*size; - data->md5.Update(static_cast(buffer), written); + data->md5.Update(static_cast(buffer), written); ENSURE(data->hash_state); - crypto_generichash_update(data->hash_state, static_cast(buffer), written); + crypto_generichash_update(data->hash_state, static_cast(buffer), written); return written; } @@ -576,7 +576,7 @@ bool ModIo::VerifyDownloadedFile(std::string& err) // MD5 (because upstream provides it) // Just used to make sure there was no obvious corruption during transfer. { - u8 digest[MD5::DIGESTSIZE]; + std::uint8_t digest[MD5::DIGESTSIZE]; m_CallbackData->md5.Final(digest); std::string md5digest = Hexify(digest, MD5::DIGESTSIZE); diff --git a/source/ps/Profiler2.cpp b/source/ps/Profiler2.cpp index 8a8d39aeaf..647eacf66a 100644 --- a/source/ps/Profiler2.cpp +++ b/source/ps/Profiler2.cpp @@ -59,7 +59,7 @@ const size_t CProfiler2::MAX_ATTRIBUTE_LENGTH = 256; const size_t CProfiler2::BUFFER_SIZE = 4 * 1024 * 1024; // A human-recognisable pattern (for debugging) followed by random bytes (for uniqueness) -const u8 CProfiler2::RESYNC_MAGIC[8] = {0x11, 0x22, 0x33, 0x44, 0xf4, 0x93, 0xbe, 0x15}; +const std::uint8_t CProfiler2::RESYNC_MAGIC[8] = {0x11, 0x22, 0x33, 0x44, 0xf4, 0x93, 0xbe, 0x15}; thread_local CProfiler2::ThreadStorage* CProfiler2::m_CurrentStorage = nullptr; @@ -257,7 +257,7 @@ void CProfiler2::RemoveThreadStorage(ThreadStorage* storage) CProfiler2::ThreadStorage::ThreadStorage(CProfiler2& profiler, const std::string& name) : m_Profiler(profiler), m_Name(name), m_LastTime(timer_Time()) { - m_Buffer = new u8[BUFFER_SIZE]; + m_Buffer = new std::uint8_t[BUFFER_SIZE]; memset(m_Buffer, ITEM_NOP, BUFFER_SIZE); } @@ -288,7 +288,7 @@ void CProfiler2::ThreadStorage::Write(EItem type, const void* item, u32 itemSize m_ValidRange.begin.store(start + size); } - m_Buffer[start] = (u8)type; + m_Buffer[start] = static_cast(type); memcpy(&m_Buffer[start + 1], item, itemSize); m_ValidRange.end.store(start + size); @@ -300,7 +300,7 @@ std::string CProfiler2::ThreadStorage::GetBuffer() // // See comments on RingBufferSpan. - std::unique_ptr buffer{std::make_unique(BUFFER_SIZE)}; + std::unique_ptr buffer{std::make_unique(BUFFER_SIZE)}; const std::uint32_t pos1{m_ValidRange.end.load()}; @@ -336,7 +336,7 @@ void CProfiler2::ThreadStorage::RecordAttribute(const char* fmt, va_list argp) } // this flattens the stack, use it sensibly -void rewriteBuffer(u8* buffer, u32& bufferSize) +void rewriteBuffer(std::uint8_t* buffer, u32& bufferSize) { double startTime = timer_Time(); @@ -361,7 +361,7 @@ void rewriteBuffer(u8* buffer, u32& bufferSize) // Let's read the first event { - u8 type = buffer[readPos]; + std::uint8_t type = buffer[readPos]; ++readPos; if (type != CProfiler2::ITEM_ENTER) { @@ -381,7 +381,7 @@ void rewriteBuffer(u8* buffer, u32& bufferSize) // To make sure time doesn't bloat, subtract time from nested events while (readPos < size) { - u8 type = buffer[readPos]; + std::uint8_t type = buffer[readPos]; ++readPos; switch (type) @@ -495,7 +495,7 @@ void rewriteBuffer(u8* buffer, u32& bufferSize) // the region enter { CProfiler2::SItem_dt_id item = { (float)curTime, regionName }; - buffer[writePos] = (u8)CProfiler2::ITEM_ENTER; + buffer[writePos] = static_cast(CProfiler2::ITEM_ENTER); memcpy(buffer + writePos + 1, &item, sizeof(item)); writePos += sizeof(item) + 1; // add a nanosecond for sanity @@ -505,14 +505,14 @@ void rewriteBuffer(u8* buffer, u32& bufferSize) for (const std::pair& type : timeByType) { CProfiler2::SItem_dt_id item = { (float)curTime, std::get<0>(type.second) }; - buffer[writePos] = (u8)CProfiler2::ITEM_ENTER; + buffer[writePos] = static_cast(CProfiler2::ITEM_ENTER); memcpy(buffer + writePos + 1, &item, sizeof(item)); writePos += sizeof(item) + 1; // write relevant attributes if present for (const std::string& attrib : std::get<2>(type.second)) { - buffer[writePos] = (u8)CProfiler2::ITEM_ATTRIBUTE; + buffer[writePos] = static_cast(CProfiler2::ITEM_ATTRIBUTE); writePos++; std::string basic = attrib; std::map::iterator time_attrib = time_per_attribute.find(attrib); @@ -529,20 +529,20 @@ void rewriteBuffer(u8* buffer, u32& bufferSize) curTime += std::get<1>(type.second); float leave_time = (float)curTime; - buffer[writePos] = (u8)CProfiler2::ITEM_LEAVE; + buffer[writePos] = static_cast(CProfiler2::ITEM_LEAVE); memcpy(buffer + writePos + 1, &leave_time, sizeof(float)); writePos += sizeof(float) + 1; } // Time of computation { CProfiler2::SItem_dt_id item = { (float)curTime, "CondenseBuffer" }; - buffer[writePos] = (u8)CProfiler2::ITEM_ENTER; + buffer[writePos] = static_cast(CProfiler2::ITEM_ENTER); memcpy(buffer + writePos + 1, &item, sizeof(item)); writePos += sizeof(item) + 1; } { float time_out = (float)(curTime + timer_Time() - startTime); - buffer[writePos] = (u8)CProfiler2::ITEM_LEAVE; + buffer[writePos] = static_cast(CProfiler2::ITEM_LEAVE); memcpy(buffer + writePos + 1, &time_out, sizeof(float)); writePos += sizeof(float) + 1; // add a nanosecond for sanity @@ -555,7 +555,7 @@ void rewriteBuffer(u8* buffer, u32& bufferSize) { total_time = curTime + 0.000001; - buffer[writePos] = (u8)CProfiler2::ITEM_ATTRIBUTE; + buffer[writePos] = static_cast(CProfiler2::ITEM_ATTRIBUTE); writePos++; u32 length = sizeof("buffer overflow"); memcpy(buffer + writePos, &length, sizeof(length)); @@ -569,7 +569,7 @@ void rewriteBuffer(u8* buffer, u32& bufferSize) curTime = total_time; } float leave_time = (float)total_time; - buffer[writePos] = (u8)CProfiler2::ITEM_LEAVE; + buffer[writePos] = static_cast(CProfiler2::ITEM_LEAVE); memcpy(buffer + writePos + 1, &leave_time, sizeof(float)); writePos += sizeof(float) + 1; } @@ -630,7 +630,7 @@ void RunBufferVisitor(const std::string& buffer, V& visitor) while (pos < buffer.length()) { - u8 type = buffer[pos]; + std::uint8_t type = buffer[pos]; ++pos; switch (type) @@ -642,7 +642,7 @@ void RunBufferVisitor(const std::string& buffer, V& visitor) } case CProfiler2::ITEM_SYNC: { - u8 magic[sizeof(CProfiler2::RESYNC_MAGIC)]; + std::uint8_t magic[sizeof(CProfiler2::RESYNC_MAGIC)]; double t; memcpy(magic, buffer.c_str()+pos, ARRAY_SIZE(magic)); ENSURE(memcmp(magic, &CProfiler2::RESYNC_MAGIC, sizeof(CProfiler2::RESYNC_MAGIC)) == 0); diff --git a/source/ps/Profiler2.h b/source/ps/Profiler2.h index 3d96bca3bd..cc3939cfff 100644 --- a/source/ps/Profiler2.h +++ b/source/ps/Profiler2.h @@ -121,7 +121,7 @@ public: static const size_t MAX_ATTRIBUTE_LENGTH; // includes null terminator, which isn't stored /// An arbitrary number to help resyncing with the item stream when parsing. - static const u8 RESYNC_MAGIC[8]; + static const std::uint8_t RESYNC_MAGIC[8]; /** * An item with a relative time and an ID string pointer. @@ -152,7 +152,7 @@ private: // Store the magic string followed by the absolute time // (to correct for drift caused by the precision of relative // times stored in other items) - u8 buffer[sizeof(RESYNC_MAGIC) + sizeof(t)]; + std::uint8_t buffer[sizeof(RESYNC_MAGIC) + sizeof(t)]; memcpy(buffer, &RESYNC_MAGIC, sizeof(RESYNC_MAGIC)); memcpy(buffer + sizeof(RESYNC_MAGIC), &t, sizeof(t)); Write(ITEM_SYNC, buffer, ARRAY_SIZE(buffer)); @@ -219,7 +219,7 @@ private: double m_LastTime; // used for computing relative times - u8* m_Buffer; + std::uint8_t* m_Buffer; // To allow hopefully-safe reading of the buffer from a separate thread, // without any expensive synchronisation in the recording thread, diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp index ee8d3c6151..f864eb16d6 100644 --- a/source/ps/SavedGame.cpp +++ b/source/ps/SavedGame.cpp @@ -33,7 +33,6 @@ #include "lib/file/vfs/vfs_util.h" #include "lib/path.h" #include "lib/sysdep/filesystem.h" -#include "lib/types.h" #include "maths/Vector3D.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -152,8 +151,10 @@ Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation if (!archiveWriter) WARN_RETURN(ERR::FAIL); - WARN_RETURN_STATUS_IF_ERR(archiveWriter->AddMemory((const u8*)metadataString.c_str(), metadataString.length(), now, "metadata.json")); - WARN_RETURN_STATUS_IF_ERR(archiveWriter->AddMemory((const u8*)simStateStream.str().c_str(), simStateStream.str().length(), now, "simulation.dat")); + WARN_RETURN_STATUS_IF_ERR(archiveWriter->AddMemory(reinterpret_cast( + metadataString.c_str()), metadataString.length(), now, "metadata.json")); + WARN_RETURN_STATUS_IF_ERR(archiveWriter->AddMemory(reinterpret_cast( + simStateStream.str().c_str()), simStateStream.str().length(), now, "simulation.dat")); archiveWriter.reset(); // close the file WriteBuffer buffer; @@ -208,13 +209,15 @@ public: { std::string buffer; buffer.resize(fileInfo.Size()); - WARN_IF_ERR(archiveFile->Load("", {reinterpret_cast(buffer.data()), buffer.size()})); + WARN_IF_ERR(archiveFile->Load("", + {reinterpret_cast(buffer.data()), buffer.size()})); Script::ParseJSON(Script::Request(m_ScriptInterface), buffer, &m_Metadata); } else if (pathname == L"simulation.dat" && m_SavedState) { m_SavedState->resize(fileInfo.Size()); - WARN_IF_ERR(archiveFile->Load("", {reinterpret_cast(m_SavedState->data()), m_SavedState->size()})); + WARN_IF_ERR(archiveFile->Load("", + {reinterpret_cast(m_SavedState->data()), m_SavedState->size()})); } } diff --git a/source/ps/UserReport.cpp b/source/ps/UserReport.cpp index b13b64621e..c969fdba64 100644 --- a/source/ps/UserReport.cpp +++ b/source/ps/UserReport.cpp @@ -30,7 +30,6 @@ #include "lib/status.h" #include "lib/sysdep/sysdep.h" #include "lib/timer.h" -#include "lib/types.h" #include "lib/utf8.h" #include "ps/CStr.h" #include "ps/ConfigDB.h" @@ -505,7 +504,7 @@ std::string CUserReporter::LoadUserID() // If we don't have a validly-formatted user ID, generate a new one if (userID.length() != 16) { - u8 bytes[8] = {0}; + std::uint8_t bytes[8] = {0}; sys_generate_random_bytes(bytes, ARRAY_SIZE(bytes)); // ignore failures - there's not much we can do about it diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index 8d1e8616bf..30b0d3d64c 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -75,7 +75,7 @@ Status tex_write(Tex* t, const VfsPath& filename) // write to disk Status ret = INFO::OK; { - std::shared_ptr file = DummySharedPtr(da.base); + std::shared_ptr file = DummySharedPtr(da.base); const ssize_t bytes_written = g_VFS->CreateFile(filename, {file.get(), da.pos}); if(bytes_written > 0) ENSURE(bytes_written == (ssize_t)da.pos); @@ -128,7 +128,7 @@ std::string Hexify(const std::string& s) return str.str(); } -std::string Hexify(const u8* s, size_t length) +std::string Hexify(const std::uint8_t* s, size_t length) { std::stringstream str; str << std::hex; diff --git a/source/ps/Util.h b/source/ps/Util.h index 36cd505f4e..c86deb5013 100644 --- a/source/ps/Util.h +++ b/source/ps/Util.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 "lib/file/vfs/vfs_path.h" #include "lib/os_path.h" #include "lib/status.h" -#include "lib/types.h" #include "ps/CStr.h" #include @@ -38,6 +37,6 @@ OsPath createDateIndexSubdirectory(const OsPath& parentDir); Status tex_write(Tex* t, const VfsPath& filename); std::string Hexify(const std::string& s); -std::string Hexify(const u8* s, size_t length); +std::string Hexify(const std::uint8_t* s, size_t length); #endif // PS_UTIL_H diff --git a/source/ps/VideoMode.cpp b/source/ps/VideoMode.cpp index a2207d620d..c04affb0c2 100644 --- a/source/ps/VideoMode.cpp +++ b/source/ps/VideoMode.cpp @@ -31,7 +31,6 @@ #include "lib/status.h" #include "lib/sysdep/os.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include "ps/CConsole.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -198,7 +197,7 @@ void CVideoMode::CCursor::SetCursor(const CStrW& name) int hotspotX = 0, hotspotY = 0; { const VfsPath pathHotspotName = pathBaseName.ChangeExtension(L".txt"); - std::unique_ptr buffer; + std::unique_ptr buffer; size_t size; if (g_VFS->LoadFile(pathHotspotName, buffer, size) != INFO::OK) { @@ -211,7 +210,7 @@ void CVideoMode::CCursor::SetCursor(const CStrW& name) const VfsPath pathImageName = pathBaseName.ChangeExtension(L".png"); - std::shared_ptr file; + std::shared_ptr file; size_t fileSize; if (g_VFS->LoadFile(pathImageName, file, fileSize) != INFO::OK) { @@ -975,7 +974,7 @@ void CVideoMode::SetWindowIcon() // The window icon should be kept outside of art/textures/, or else it will be converted // to DDS by the archive builder and will become unusable here. Using DDS makes BGRA // conversion needlessly complicated. - std::shared_ptr iconFile; + std::shared_ptr iconFile; size_t iconFileSize; if (g_VFS->LoadFile("art/icons/window.png", iconFile, iconFileSize) != INFO::OK) { diff --git a/source/ps/VisualReplay.cpp b/source/ps/VisualReplay.cpp index f16297bb87..6f73e13f90 100644 --- a/source/ps/VisualReplay.cpp +++ b/source/ps/VisualReplay.cpp @@ -59,7 +59,7 @@ /** * Filter too short replays (value in seconds). */ -const u8 minimumReplayDuration = 3; +const std::uint8_t minimumReplayDuration = 3; OsPath VisualReplay::GetDirectoryPath() { diff --git a/source/ps/XMB/XMBStorage.h b/source/ps/XMB/XMBStorage.h index 29bdee0549..fa688393bd 100644 --- a/source/ps/XMB/XMBStorage.h +++ b/source/ps/XMB/XMBStorage.h @@ -108,7 +108,7 @@ public: */ bool LoadJSValue(const Script::Interface& scriptInterface, JS::HandleValue value, const std::string& rootName); - std::shared_ptr m_Buffer; + std::shared_ptr m_Buffer; size_t m_Size = 0; }; diff --git a/source/ps/XMB/tests/test_XMBData.h b/source/ps/XMB/tests/test_XMBData.h index bd61647ed7..adfc3e6268 100644 --- a/source/ps/XMB/tests/test_XMBData.h +++ b/source/ps/XMB/tests/test_XMBData.h @@ -17,7 +17,6 @@ #include "lib/self_test.h" -#include "lib/types.h" #include "ps/CStr.h" #include "ps/XMB/XMBData.h" #include "ps/XMB/XMBStorage.h" @@ -36,7 +35,7 @@ class TestXMBData : public CxxTest::TestSuite { private: - std::shared_ptr m_Buffer; + std::shared_ptr m_Buffer; std::unique_ptr m_ScriptInterface; diff --git a/source/ps/XML/RelaxNG.cpp b/source/ps/XML/RelaxNG.cpp index cf6a9dba51..efa9991ccb 100644 --- a/source/ps/XML/RelaxNG.cpp +++ b/source/ps/XML/RelaxNG.cpp @@ -19,7 +19,6 @@ #include "RelaxNG.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "ps/CStr.h" #include "ps/Errors.h" @@ -118,7 +117,7 @@ bool RelaxNGValidator::LoadGrammar(const std::string& grammar) return false; MD5 hash; - hash.Update((const u8*)grammar.c_str(), grammar.length()); + hash.Update(reinterpret_cast(grammar.c_str()), grammar.length()); m_Hash = hash; return true; diff --git a/source/ps/XML/XMLWriter.cpp b/source/ps/XML/XMLWriter.cpp index 0723c8124d..005335f7af 100644 --- a/source/ps/XML/XMLWriter.cpp +++ b/source/ps/XML/XMLWriter.cpp @@ -24,7 +24,6 @@ #include "lib/debug.h" #include "lib/path.h" #include "lib/status.h" -#include "lib/types.h" #include "lib/utf8.h" #include "maths/Fixed.h" #include "ps/CLogger.h" @@ -105,7 +104,7 @@ bool XMLWriter_File::StoreVFS(const PIVFS& vfs, const VfsPath& pathname) if (m_LastElement) debug_warn(L"ERROR: Saving XML while an element is still open"); const size_t size = m_Data.length(); - std::shared_ptr data; + std::shared_ptr data; AllocateAligned(data, size, maxSectorSize); memcpy(data.get(), m_Data.data(), size); Status ret = vfs->CreateFile(pathname, {data.get(), size}); diff --git a/source/ps/scripting/JSInterface_Main.cpp b/source/ps/scripting/JSInterface_Main.cpp index 4a1b85a946..6bffa2515b 100644 --- a/source/ps/scripting/JSInterface_Main.cpp +++ b/source/ps/scripting/JSInterface_Main.cpp @@ -25,7 +25,6 @@ #include "lib/file/vfs/vfs_path.h" #include "lib/frequency_filter.h" #include "lib/sysdep/sysdep.h" -#include "lib/types.h" #include "maths/MD5.h" #include "maths/Size2D.h" #include "ps/CLogger.h" @@ -125,10 +124,10 @@ int GetTextWidth(const std::string& fontName, const std::wstring& text) std::string CalculateMD5(const std::string& input) { - u8 digest[MD5::DIGESTSIZE]; + std::uint8_t digest[MD5::DIGESTSIZE]; MD5 m; - m.Update((const u8*)input.c_str(), input.length()); + m.Update(reinterpret_cast(input.c_str()), input.length()); m.Final(digest); return Hexify(digest, MD5::DIGESTSIZE); diff --git a/source/ps/tests/test_CStr.h b/source/ps/tests/test_CStr.h index 09d96789a3..db8a8ee82c 100644 --- a/source/ps/tests/test_CStr.h +++ b/source/ps/tests/test_CStr.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/code_annotation.h" -#include "lib/types.h" #include "ps/CStr.h" #include @@ -84,7 +83,7 @@ public: void roundtrip(const T& str) { size_t len = str.GetSerializedLength(); - u8* buf = new u8[len+1]; + std::uint8_t* buf = new std::uint8_t[len+1]; buf[len] = '!'; TS_ASSERT_EQUALS(str.Serialize(buf) - (buf+len), 0); TS_ASSERT_EQUALS(buf[len], '!'); diff --git a/source/renderer/GPUSkinnedModelRenderer.cpp b/source/renderer/GPUSkinnedModelRenderer.cpp index ef3e701a2d..17ea829fe5 100644 --- a/source/renderer/GPUSkinnedModelRenderer.cpp +++ b/source/renderer/GPUSkinnedModelRenderer.cpp @@ -196,8 +196,8 @@ ModelDefRData::ModelDefRData(const CModelDefPtr& modelDef) VertexArrayIterator normalIt{m_Normal.GetIterator()}; VertexArrayIterator tangentIt{m_Tangent.GetIterator()}; - VertexArrayIterator blendJointsIt{m_BlendJoints.GetIterator()}; - VertexArrayIterator blendWeightsIt{m_BlendWeights.GetIterator()}; + VertexArrayIterator blendJointsIt{m_BlendJoints.GetIterator()}; + VertexArrayIterator blendWeightsIt{m_BlendWeights.GetIterator()}; // Copy everything into the vertex array. for (int index{0}; index < finalNumberOfVertices; ++index) @@ -225,8 +225,10 @@ ModelDefRData::ModelDefRData(const CModelDefPtr& modelDef) for (uint32_t j{0}; j < 4; ++j) { - blendJointsIt[index][j] = static_cast(vertexDataOut[inputDataOffset + 0 + 2 * j]); - blendWeightsIt[index][j] = static_cast(vertexDataOut[inputDataOffset + 1 + 2 * j]); + blendJointsIt[index][j] = static_cast( + vertexDataOut[inputDataOffset + 0 + 2 * j]); + blendWeightsIt[index][j] = static_cast( + vertexDataOut[inputDataOffset + 1 + 2 * j]); } inputDataOffset += 8; diff --git a/source/renderer/MikktspaceWrap.cpp b/source/renderer/MikktspaceWrap.cpp index 2dc32d9d36..da3f91fabd 100644 --- a/source/renderer/MikktspaceWrap.cpp +++ b/source/renderer/MikktspaceWrap.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 @@ -20,7 +20,6 @@ #include "MikktspaceWrap.h" #include "graphics/ModelDef.h" -#include "lib/types.h" #include "maths/Vector2D.h" #include "maths/Vector3D.h" @@ -122,7 +121,7 @@ void MikkTSpace::SetTSpace(const SMikkTSpaceContext* pContext, const float* fvTa if (userData->m_GpuSkinning) { - for (u8 j = 0; j < 4; ++j) + for (std::uint8_t j = 0; j < 4; ++j) { userData->m_NewVertices.push_back(vertex.m_Blend.m_Bone[j]); userData->m_NewVertices.push_back(255.f * vertex.m_Blend.m_Weight[j]); diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index a2ef5a89b2..6ccf2e504f 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -273,7 +273,7 @@ struct STileBlend */ struct STileBlendStack { - u8 i, j; + std::uint8_t i, j; std::vector blends; // back of vector is lowest-priority texture }; @@ -284,8 +284,8 @@ struct SBlendLayer { struct Tile { - u8 i, j; - u8 shape; + std::uint8_t i, j; + std::uint8_t shape; }; CTerrainTextureEntry* m_Texture; @@ -383,7 +383,8 @@ void CPatchRData::BuildBlends() { if (!blendStacks[k].blends.empty() && blendStacks[k].blends.back().m_Texture == tex) { - SBlendLayer::Tile t = { blendStacks[k].i, blendStacks[k].j, (u8)blendStacks[k].blends.back().m_TileMask }; + SBlendLayer::Tile t = { blendStacks[k].i, blendStacks[k].j, + static_cast(blendStacks[k].blends.back().m_TileMask) }; blendLayers.back().m_Tiles.push_back(t); blendStacks[k].blends.pop_back(); } @@ -465,7 +466,7 @@ void CPatchRData::BuildBlends() } void CPatchRData::AddBlend(std::vector& blendVertices, std::vector& blendIndices, - u16 i, u16 j, u8 shape, CTerrainTextureEntry* texture) + u16 i, u16 j, std::uint8_t shape, CTerrainTextureEntry* texture) { CTerrain* terrain = m_Patch->m_Parent; diff --git a/source/renderer/PatchRData.h b/source/renderer/PatchRData.h index 4442c4d4f8..f2d088b3bd 100644 --- a/source/renderer/PatchRData.h +++ b/source/renderer/PatchRData.h @@ -116,7 +116,7 @@ private: CVector3D m_Position; CVector3D m_Normal; // pad to a power of two - u8 m_Padding[8]; + std::uint8_t m_Padding[8]; }; cassert(sizeof(SBaseVertex) == 32); @@ -125,7 +125,7 @@ private: // vertex position CVector3D m_Position; // pad to a power of two - u8 m_Padding[4]; + std::uint8_t m_Padding[4]; }; cassert(sizeof(SSideVertex) == 16); @@ -146,7 +146,7 @@ private: CVector3D m_Position; CVector2D m_WaterData; // pad to a power of two - u8 m_Padding[12]; + std::uint8_t m_Padding[12]; }; cassert(sizeof(SWaterVertex) == 32); @@ -154,7 +154,7 @@ private: void Build(); void AddBlend(std::vector& blendVertices, std::vector& blendIndices, - u16 i, u16 j, u8 shape, CTerrainTextureEntry* texture); + u16 i, u16 j, std::uint8_t shape, CTerrainTextureEntry* texture); void BuildBlends(); void BuildIndices(); diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index dc97931338..a3e75a4892 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -43,7 +43,6 @@ #include "lib/secure_crt.h" #include "lib/status.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "ps/CConsole.h" #include "ps/CLogger.h" @@ -807,7 +806,7 @@ void CRenderer::RenderScreenShot(const bool needsPresent) const size_t img_size = width * height * bpp / 8; const size_t hdr_size = tex_hdr_size(filename); - std::shared_ptr buf; + std::shared_ptr buf; AllocateAligned(buf, hdr_size + img_size, maxSectorSize); void* img = buf.get() + hdr_size; Tex t; @@ -888,7 +887,7 @@ void CRenderer::RenderBigScreenShot(const bool needsPresent) WARN_IF_ERR(ERR::NO_MEM); return; } - std::shared_ptr imageBuffer; + std::shared_ptr imageBuffer; AllocateAligned(imageBuffer, headerSize + imageSize, maxSectorSize); Tex t; diff --git a/source/renderer/SkyManager.cpp b/source/renderer/SkyManager.cpp index bd7ee4fba1..c6d941a0bc 100644 --- a/source/renderer/SkyManager.cpp +++ b/source/renderer/SkyManager.cpp @@ -32,7 +32,6 @@ #include "lib/path.h" #include "lib/status.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "maths/Vector3D.h" #include "ps/CLogger.h" @@ -111,7 +110,7 @@ void SkyManager::LoadAndUploadSkyTexturesIfNeeded( { VfsPath path = VfsPath("art/textures/skies") / m_SkySet / (Path::String(images[i]) + L".dds"); - std::shared_ptr file; + std::shared_ptr file; size_t fileSize; if (g_VFS->LoadFile(path, file, fileSize) != INFO::OK) { @@ -153,10 +152,10 @@ void SkyManager::LoadAndUploadSkyTexturesIfNeeded( Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE), 1, 1); - std::vector rotated; + std::vector rotated; for (size_t i = 0; i < NUMBER_OF_TEXTURES + 1; ++i) { - u8* data = textures[i].get_data(); + std::uint8_t* data = textures[i].get_data(); // We need to rotate the side if it's looking up or down. // TODO: maybe it should be done during texture conversion. diff --git a/source/renderer/TerrainOverlay.cpp b/source/renderer/TerrainOverlay.cpp index 3b84232e54..9cdafa943e 100644 --- a/source/renderer/TerrainOverlay.cpp +++ b/source/renderer/TerrainOverlay.cpp @@ -375,7 +375,7 @@ void TerrainTextureOverlay::RenderAfterWater( Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE)); } - u8* data = (u8*)calloc(w * h, 4); + std::uint8_t* data = static_cast(calloc(w * h, 4)); m_BuildTextureRGBA(data, w, h); deviceCommandContext->UploadTextureRegion( @@ -392,7 +392,7 @@ void TerrainTextureOverlay::RenderAfterWater( SColor4ub TerrainTextureOverlay::GetColor(std::size_t idx, std::uint8_t alpha) { - static u8 colors[][3] = + static std::uint8_t colors[][3] = { { 255, 0, 0 }, { 0, 255, 0 }, diff --git a/source/renderer/TerrainOverlay.h b/source/renderer/TerrainOverlay.h index 2dc2984c26..c0c68f779e 100644 --- a/source/renderer/TerrainOverlay.h +++ b/source/renderer/TerrainOverlay.h @@ -27,7 +27,6 @@ #include "graphics/ShaderTechniquePtr.h" #include "lib/code_annotation.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include #include diff --git a/source/renderer/VertexArray.cpp b/source/renderer/VertexArray.cpp index 2c1730d453..fc8187fd24 100644 --- a/source/renderer/VertexArray.cpp +++ b/source/renderer/VertexArray.cpp @@ -40,9 +40,9 @@ uint32_t GetAttributeSize(const Renderer::Backend::Format format) { case Renderer::Backend::Format::R8G8B8A8_UNORM: case Renderer::Backend::Format::R8G8B8A8_UINT: - return sizeof(u8) * 4; + return sizeof(std::uint8_t) * 4; case Renderer::Backend::Format::A8_UNORM: - return sizeof(u8); + return sizeof(std::uint8_t); case Renderer::Backend::Format::R16_UNORM: case Renderer::Backend::Format::R16_UINT: case Renderer::Backend::Format::R16_SINT: @@ -187,23 +187,23 @@ VertexArrayIterator VertexArray::Attribute::GetIterator() const } template<> -VertexArrayIterator VertexArray::Attribute::GetIterator() const +VertexArrayIterator VertexArray::Attribute::GetIterator() const { ENSURE(vertexArray); ENSURE(format == Renderer::Backend::Format::A8_UNORM); - 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::R8G8B8A8_UNORM || format == Renderer::Backend::Format::R8G8B8A8_UINT); - return vertexArray->MakeIterator(this); + return vertexArray->MakeIterator(this); } template<> diff --git a/source/renderer/VertexArray.h b/source/renderer/VertexArray.h index dc1d2c8faf..283d047f30 100644 --- a/source/renderer/VertexArray.h +++ b/source/renderer/VertexArray.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 @@ -158,7 +158,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], u8[4], short, short[2]. + // u16, u16[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 diff --git a/source/renderer/VertexBuffer.cpp b/source/renderer/VertexBuffer.cpp index 3a7d477a1b..37ce3bb83c 100644 --- a/source/renderer/VertexBuffer.cpp +++ b/source/renderer/VertexBuffer.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 @@ -246,7 +246,7 @@ void CVertexBuffer::UploadIfNeeded( if (needUpload) { - deviceCommandContext->UploadBuffer(m_Buffer.get(), [&](u8* mappedData) + deviceCommandContext->UploadBuffer(m_Buffer.get(), [&](std::uint8_t* mappedData) { #ifndef NDEBUG // To help detect bugs where PrepareForRendering() was not called, diff --git a/source/renderer/backend/IDeviceCommandContext.h b/source/renderer/backend/IDeviceCommandContext.h index 33ab31f1eb..1d4625339b 100644 --- a/source/renderer/backend/IDeviceCommandContext.h +++ b/source/renderer/backend/IDeviceCommandContext.h @@ -18,8 +18,6 @@ #ifndef INCLUDED_RENDERER_BACKEND_IDEVICECOMMANDCONTEXT #define INCLUDED_RENDERER_BACKEND_IDEVICECOMMANDCONTEXT -#include "lib/types.h" - #include "renderer/backend/IDeviceObject.h" #include @@ -126,7 +124,7 @@ public: const uint32_t width, const uint32_t height, const uint32_t level = 0, const uint32_t layer = 0) = 0; - using UploadBufferFunction = std::function; + using UploadBufferFunction = std::function; virtual void UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) = 0; virtual void UploadBuffer(IBuffer* buffer, const UploadBufferFunction& uploadFunction) = 0; virtual void UploadBufferRegion( diff --git a/source/renderer/backend/dummy/DeviceCommandContext.h b/source/renderer/backend/dummy/DeviceCommandContext.h index 7d60ade954..a3a4d8cf15 100644 --- a/source/renderer/backend/dummy/DeviceCommandContext.h +++ b/source/renderer/backend/dummy/DeviceCommandContext.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_RENDERER_BACKEND_DUMMY_DEVICECOMMANDCONTEXT #define INCLUDED_RENDERER_BACKEND_DUMMY_DEVICECOMMANDCONTEXT -#include "lib/types.h" #include "renderer/backend/IDeviceCommandContext.h" #include @@ -72,7 +71,7 @@ public: const uint32_t width, const uint32_t height, const uint32_t level = 0, const uint32_t layer = 0) override; - using UploadBufferFunction = std::function; + using UploadBufferFunction = std::function; void UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) override; void UploadBuffer(IBuffer* buffer, const UploadBufferFunction& uploadFunction) override; void UploadBufferRegion( diff --git a/source/renderer/backend/gl/DeviceCommandContext.cpp b/source/renderer/backend/gl/DeviceCommandContext.cpp index cb065505a7..7fb90d49d0 100644 --- a/source/renderer/backend/gl/DeviceCommandContext.cpp +++ b/source/renderer/backend/gl/DeviceCommandContext.cpp @@ -150,7 +150,7 @@ void UploadDynamicBufferRegionImpl( break; } - uploadFunction(static_cast(mappedData) + dataOffset); + uploadFunction(static_cast(mappedData) + dataOffset); if (glUnmapBuffer(target) == GL_TRUE) break; @@ -485,7 +485,8 @@ void CDeviceCommandContext::UploadBufferRegion( // dynamic upload. if (buffer->IsDynamic() && buffer->GetType() != IBuffer::Type::UNIFORM) { - UploadDynamicBufferRegionImpl(target, buffer->GetSize(), dataOffset, dataSize, [data, dataSize](u8* mappedData) + UploadDynamicBufferRegionImpl(target, buffer->GetSize(), dataOffset, dataSize, + [data, dataSize](std::uint8_t* mappedData) { std::memcpy(mappedData, data, dataSize); }); diff --git a/source/renderer/backend/gl/DeviceCommandContext.h b/source/renderer/backend/gl/DeviceCommandContext.h index 5a2ee7b13f..c6d620fc7a 100644 --- a/source/renderer/backend/gl/DeviceCommandContext.h +++ b/source/renderer/backend/gl/DeviceCommandContext.h @@ -20,7 +20,6 @@ #include "graphics/Color.h" #include "lib/config2.h" -#include "lib/types.h" #include "renderer/backend/IBuffer.h" #include "renderer/backend/IDeviceCommandContext.h" #include "renderer/backend/IShaderProgram.h" @@ -93,7 +92,7 @@ public: const uint32_t width, const uint32_t height, const uint32_t level = 0, const uint32_t layer = 0) override; - using UploadBufferFunction = std::function; + using UploadBufferFunction = std::function; void UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) override; void UploadBuffer(IBuffer* buffer, const UploadBufferFunction& uploadFunction) override; void UploadBufferRegion( diff --git a/source/renderer/backend/gl/ShaderProgram.cpp b/source/renderer/backend/gl/ShaderProgram.cpp index 0e1de634b8..3f50305e74 100644 --- a/source/renderer/backend/gl/ShaderProgram.cpp +++ b/source/renderer/backend/gl/ShaderProgram.cpp @@ -23,7 +23,6 @@ #include "graphics/ShaderDefines.h" #include "lib/config2.h" #include "lib/path.h" -#include "lib/types.h" #include "lib/utf8.h" #include "ps/CLogger.h" #include "ps/Errors.h" @@ -852,7 +851,8 @@ void CShaderProgram::VertexAttribPointer( const GLenum type = GLTypeFromFormat(format); const GLboolean normalized = NormalizedFromFormat(format); glVertexAttribPointer( - attributeLocation, size, type, normalized, stride, static_cast(data) + offset); + attributeLocation, size, type, normalized, stride, + static_cast(data) + offset); #if CONFIG2_GLES ENSURE(!m_Device->GetCapabilities().instancing); #else diff --git a/source/renderer/backend/vulkan/RingCommandContext.h b/source/renderer/backend/vulkan/RingCommandContext.h index 9911011e61..56a93865fc 100644 --- a/source/renderer/backend/vulkan/RingCommandContext.h +++ b/source/renderer/backend/vulkan/RingCommandContext.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 @@ #ifndef INCLUDED_RENDERER_BACKEND_VULKAN_RINGCOMMANDCONTEXT #define INCLUDED_RENDERER_BACKEND_VULKAN_RINGCOMMANDCONTEXT -#include "lib/types.h" #include "renderer/backend/vulkan/SubmitScheduler.h" #include @@ -95,7 +94,7 @@ public: void ScheduleUpload( CBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize); - using UploadBufferFunction = std::function; + using UploadBufferFunction = std::function; void ScheduleUpload( CBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize, diff --git a/source/scriptinterface/Conversions.cpp b/source/scriptinterface/Conversions.cpp index 8a1a620efd..fdbb2c8b04 100644 --- a/source/scriptinterface/Conversions.cpp +++ b/source/scriptinterface/Conversions.cpp @@ -93,13 +93,13 @@ template<> bool FromJSVal(const Request& rq, JS::HandleValue v, u16& out) return true; } -template<> bool FromJSVal(const Request& rq, JS::HandleValue v, u8& out) +template<> bool FromJSVal(const Request& rq, JS::HandleValue v, std::uint8_t& out) { u16 tmp; FAIL_IF_NOT(v.isNumber(), v); if (!JS::ToUint16(rq.cx, v, &tmp)) return false; - out = (u8)tmp; + out = static_cast(tmp); return true; } @@ -216,7 +216,7 @@ template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, const u ret.set(JS::NumberValue(val)); } -template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, const u8& val) +template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, const std::uint8_t& val) { ret.set(JS::NumberValue(val)); } diff --git a/source/simulation2/components/CCmpAIManager.cpp b/source/simulation2/components/CCmpAIManager.cpp index db97fc7228..83e86f397e 100644 --- a/source/simulation2/components/CCmpAIManager.cpp +++ b/source/simulation2/components/CCmpAIManager.cpp @@ -121,7 +121,8 @@ private: { NONCOPYABLE(CAIPlayer); public: - CAIPlayer(CAIWorker& worker, const std::wstring& aiName, player_id_t player, u8 difficulty, const std::wstring& behavior, + CAIPlayer(CAIWorker& worker, const std::wstring& aiName, player_id_t player, + std::uint8_t difficulty, const std::wstring& behavior, std::shared_ptr scriptInterface) : m_Worker(worker), m_AIName(aiName), m_Player(player), m_Difficulty(difficulty), m_Behavior(behavior), m_ScriptInterface(scriptInterface), m_Obj(scriptInterface->GetGeneralJSContext()) @@ -227,7 +228,7 @@ private: CAIWorker& m_Worker; std::wstring m_AIName; player_id_t m_Player; - u8 m_Difficulty; + std::uint8_t m_Difficulty; std::wstring m_Behavior; bool m_UseSharedComponent; @@ -389,15 +390,15 @@ public: const size_t img_size = w * h * bpp/8; const size_t hdr_size = tex_hdr_size(filename); - std::shared_ptr buf; + std::shared_ptr buf; AllocateAligned(buf, hdr_size+img_size, maxSectorSize); Tex t; if (t.wrap(w, h, bpp, flags, buf, hdr_size) < 0) return; - u8* img = buf.get() + hdr_size; + std::uint8_t* img = buf.get() + hdr_size; for (size_t i = 0; i < data.size(); ++i) - img[i] = (u8)((data[i] * 255) / max); + img[i] = static_cast((data[i] * 255) / max); tex_write(&t, filename); } @@ -468,7 +469,8 @@ public: return true; } - bool AddPlayer(const std::wstring& aiName, player_id_t player, u8 difficulty, const std::wstring& behavior) + bool AddPlayer(const std::wstring& aiName, player_id_t player, std::uint8_t difficulty, + const std::wstring& behavior) { std::shared_ptr ai = std::make_shared(*this, aiName, player, difficulty, behavior, m_ScriptInterface); if (!ai->Initialise()) @@ -483,8 +485,10 @@ public: return true; } - bool RunGamestateInit(const Script::StructuredClone& gameState, const Grid& passabilityMap, const Grid& territoryMap, - const std::map& nonPathfindingPassClassMasks, const std::map& pathfindingPassClassMasks) + bool RunGamestateInit(const Script::StructuredClone& gameState, + const Grid& passabilityMap, const Grid& territoryMap, + const std::map& nonPathfindingPassClassMasks, + const std::map& pathfindingPassClassMasks) { // this will be run last by InitGame.js, passing the full game representation. // For now it will run for the shared Component. @@ -526,8 +530,10 @@ public: m_GameState.init(Script::Request(m_ScriptInterface).cx, gameState); } - void UpdatePathfinder(const Grid& passabilityMap, bool globallyDirty, const Grid& dirtinessGrid, bool justDeserialized, - const std::map& nonPathfindingPassClassMasks, const std::map& pathfindingPassClassMasks) + void UpdatePathfinder(const Grid& passabilityMap, bool globallyDirty, + const Grid& dirtinessGrid, bool justDeserialized, + const std::map& nonPathfindingPassClassMasks, + const std::map& pathfindingPassClassMasks) { ENSURE(m_CommandsComputed); bool dimensionChange = m_PassabilityMap.m_W != passabilityMap.m_W || m_PassabilityMap.m_H != passabilityMap.m_H; @@ -565,7 +571,7 @@ public: } } - void UpdateTerritoryMap(const Grid& territoryMap) + void UpdateTerritoryMap(const Grid& territoryMap) { ENSURE(m_CommandsComputed); bool dimensionChange = m_TerritoryMap.m_W != territoryMap.m_W || m_TerritoryMap.m_H != territoryMap.m_H; @@ -585,7 +591,7 @@ public: u32 length = 0; ENSURE(JS::GetArrayLength(rq.cx, dataObj, &length)); - u32 nbytes = (u32)(length * sizeof(u8)); + u32 nbytes = (u32)(length * sizeof(std::uint8_t)); bool sharedMemory; JS::AutoCheckCannotGC nogc; @@ -692,7 +698,8 @@ public: Serializer(serializer, "pathfinding pass classes", m_PathfindingPassClasses); serializer.NumberU16_Unbounded("pathfinder grid w", m_PassabilityMap.m_W); serializer.NumberU16_Unbounded("pathfinder grid h", m_PassabilityMap.m_H); - serializer.RawBytes("pathfinder grid data", (const u8*)m_PassabilityMap.m_Data, + serializer.RawBytes("pathfinder grid data", + reinterpret_cast(m_PassabilityMap.m_Data), m_PassabilityMap.m_W*m_PassabilityMap.m_H*sizeof(NavcellData)); } @@ -729,7 +736,7 @@ public: { std::wstring name; player_id_t player; - u8 difficulty; + std::uint8_t difficulty; std::wstring behavior; deserializer.String("name", name, 1, 256); deserializer.NumberI32_Unbounded("player", player); @@ -758,7 +765,8 @@ public: deserializer.NumberU16_Unbounded("pathfinder grid w", mapW); deserializer.NumberU16_Unbounded("pathfinder grid h", mapH); m_PassabilityMap = Grid(mapW, mapH); - deserializer.RawBytes("pathfinder grid data", (u8*)m_PassabilityMap.m_Data, mapW*mapH*sizeof(NavcellData)); + deserializer.RawBytes("pathfinder grid data", + reinterpret_cast(m_PassabilityMap.m_Data), mapW * mapH * sizeof(NavcellData)); m_LongPathfinder.Reload(&m_PassabilityMap); m_HierarchicalPathfinder.Recompute(&m_PassabilityMap, m_NonPathfindingPassClasses, m_PathfindingPassClasses); } @@ -847,7 +855,7 @@ private: JS::PersistentRootedValue m_GameState; Grid m_PassabilityMap; JS::PersistentRootedValue m_PassabilityMapVal; - Grid m_TerritoryMap; + Grid m_TerritoryMap; JS::PersistentRootedValue m_TerritoryMapVal; std::map m_NonPathfindingPassClasses; @@ -917,7 +925,8 @@ public: m_JustDeserialized = true; } - void AddPlayer(const std::wstring& id, player_id_t player, u8 difficulty, const std::wstring& behavior) override + void AddPlayer(const std::wstring& id, player_id_t player, std::uint8_t difficulty, + const std::wstring& behavior) override { LoadUsedEntityTemplates(); @@ -963,8 +972,8 @@ public: // Get the territory data // Since getting the territory grid can trigger a recalculation, we check NeedUpdateAI first - Grid dummyGrid2; - const Grid* territoryMap = &dummyGrid2; + Grid dummyGrid2; + const Grid* territoryMap = &dummyGrid2; CmpPtr cmpTerritoryManager(GetSystemEntity()); if (cmpTerritoryManager && cmpTerritoryManager->NeedUpdateAI(&m_TerritoriesDirtyID, &m_TerritoriesDirtyBlinkingID)) territoryMap = &cmpTerritoryManager->GetTerritoryGrid(); @@ -1028,7 +1037,7 @@ public: CmpPtr cmpTerritoryManager(GetSystemEntity()); if (cmpTerritoryManager && (cmpTerritoryManager->NeedUpdateAI(&m_TerritoriesDirtyID, &m_TerritoriesDirtyBlinkingID) || m_JustDeserialized)) { - const Grid& territoryMap = cmpTerritoryManager->GetTerritoryGrid(); + const Grid& territoryMap = cmpTerritoryManager->GetTerritoryGrid(); m_Worker.UpdateTerritoryMap(territoryMap); } diff --git a/source/simulation2/components/CCmpMinimap.cpp b/source/simulation2/components/CCmpMinimap.cpp index b452f50eb3..82fac8b8c4 100644 --- a/source/simulation2/components/CCmpMinimap.cpp +++ b/source/simulation2/components/CCmpMinimap.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 @@ -20,7 +20,6 @@ #include "ICmpMinimap.h" #include "graphics/Color.h" -#include "lib/types.h" #include "simulation2/MessageTypes.h" #include "simulation2/components/ICmpOwnership.h" #include "simulation2/components/ICmpPlayer.h" @@ -50,7 +49,7 @@ public: bool m_UsePlayerColor; - u8 m_R, m_G, m_B; // static template state if m_UsePlayerColor false; dynamic state if true + std::uint8_t m_R, m_G, m_B; // static template state if m_UsePlayerColor false; dynamic state if true // Dynamic state: @@ -103,9 +102,9 @@ public: if (color.IsOk()) { m_UsePlayerColor = false; - m_R = (u8)color.GetChild("@r").ToInt(); - m_G = (u8)color.GetChild("@g").ToInt(); - m_B = (u8)color.GetChild("@b").ToInt(); + m_R = static_cast(color.GetChild("@r").ToInt()); + m_G = static_cast(color.GetChild("@g").ToInt()); + m_B = static_cast(color.GetChild("@b").ToInt()); } else { @@ -200,7 +199,7 @@ public: } } - bool GetRenderData(u8& r, u8& g, u8& b, entity_pos_t& x, entity_pos_t& z) const override + bool GetRenderData(std::uint8_t& r, std::uint8_t& g, std::uint8_t& b, entity_pos_t& x, entity_pos_t& z) const override { if (!m_Active) return false; @@ -252,9 +251,9 @@ public: return; CColor color = cmpPlayer->GetDisplayedColor(); - m_R = (u8) (color.r * 255); - m_G = (u8) (color.g * 255); - m_B = (u8) (color.b * 255); + m_R = static_cast(color.r * 255); + m_G = static_cast(color.g * 255); + m_B = static_cast(color.b * 255); } bool HasIcon() override diff --git a/source/simulation2/components/CCmpObstructionManager.cpp b/source/simulation2/components/CCmpObstructionManager.cpp index 7c8d616abe..209f67d6c9 100644 --- a/source/simulation2/components/CCmpObstructionManager.cpp +++ b/source/simulation2/components/CCmpObstructionManager.cpp @@ -22,7 +22,6 @@ #include "graphics/Color.h" #include "graphics/Overlay.h" #include "lib/debug.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/MathUtil.h" @@ -238,7 +237,7 @@ public: SerializeCommon(deserialize); std::int32_t size = ((m_WorldX1-m_WorldX0)/Pathfinding::NAVCELL_SIZE_INT).ToInt_RoundToInfinity(); - m_UpdateInformations.dirtinessGrid = Grid(size, size); + m_UpdateInformations.dirtinessGrid = Grid(size, size); } void HandleMessage(const CMessage& msg, bool /*global*/) override @@ -269,7 +268,7 @@ public: ResetSubdivisions(x1, z1); std::int32_t size = ((m_WorldX1-m_WorldX0)/Pathfinding::NAVCELL_SIZE_INT).ToInt_RoundToInfinity(); - m_UpdateInformations.dirtinessGrid = Grid(size, size); + m_UpdateInformations.dirtinessGrid = Grid(size, size); CmpPtr cmpPathfinder(GetSystemEntity()); if (cmpPathfinder) diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index 8a90892cf9..b58e487c38 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -270,7 +270,7 @@ void CCmpPathfinder::SetHierDebugOverlay(bool enabled) m_PathfinderHier->SetDebugOverlay(enabled, &GetSimContext()); } -void CCmpPathfinder::GetDebugData(u32& steps, double& time, Grid& grid) const +void CCmpPathfinder::GetDebugData(u32& steps, double& time, Grid& grid) const { m_LongPathfinder->GetDebugData(steps, time, grid); } @@ -357,7 +357,7 @@ static void ExpandImpassableCells(Grid& grid, u16 clearance, pass_c u16 h = grid.m_H; // First expand impassable cells horizontally into a temporary 1-bit grid - Grid tempGrid(w, h); + Grid tempGrid(w, h); for (u16 j = 0; j < h; ++j) { // New cell (i,j) is blocked if (i',j) blocked for any i-clearance <= i' <= i+clearance @@ -425,7 +425,7 @@ Grid CCmpPathfinder::ComputeShoreGrid(bool expandOnWater) u16 shoreGridSize = terrain.GetTilesPerSide(); // First pass - find underwater tiles - Grid waterGrid(shoreGridSize, shoreGridSize); + Grid waterGrid(shoreGridSize, shoreGridSize); for (u16 j = 0; j < shoreGridSize; ++j) { for (u16 i = 0; i < shoreGridSize; ++i) @@ -554,7 +554,7 @@ void CCmpPathfinder::UpdateGrid() SAFE_DELETE(m_TerrainOnlyGrid); m_TerrainOnlyGrid = new Grid(m_GridSize, m_GridSize); - m_DirtinessInformation = { true, true, Grid(m_GridSize, m_GridSize) }; + m_DirtinessInformation = { true, true, Grid(m_GridSize, m_GridSize) }; m_AIPathfinderDirtinessInformation = m_DirtinessInformation; m_TerrainDirty = true; @@ -564,7 +564,7 @@ void CCmpPathfinder::UpdateGrid() #ifdef NDEBUG ENSURE(m_DirtinessInformation.dirtinessGrid.compare_sizes(m_Grid)); #else - ENSURE(m_DirtinessInformation.dirtinessGrid == Grid(m_GridSize, m_GridSize)); + ENSURE(m_DirtinessInformation.dirtinessGrid == Grid(m_GridSize, m_GridSize)); #endif CmpPtr cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); @@ -655,7 +655,7 @@ void CCmpPathfinder::TerrainUpdateHelper(bool expandPassability, int itile0, int SAFE_DELETE(m_Grid); m_Grid = new Grid(m_GridSize, m_GridSize); - m_DirtinessInformation = { true, true, Grid(m_GridSize, m_GridSize) }; + m_DirtinessInformation = { true, true, Grid(m_GridSize, m_GridSize) }; m_AIPathfinderDirtinessInformation = m_DirtinessInformation; } } diff --git a/source/simulation2/components/CCmpPathfinder_Common.h b/source/simulation2/components/CCmpPathfinder_Common.h index bf04f8187e..31dfe8dfdf 100644 --- a/source/simulation2/components/CCmpPathfinder_Common.h +++ b/source/simulation2/components/CCmpPathfinder_Common.h @@ -226,7 +226,7 @@ public: void SetHierDebugOverlay(bool enabled) override; - void GetDebugData(u32& steps, double& time, Grid& grid) const override; + void GetDebugData(u32& steps, double& time, Grid& grid) const override; void SetAtlasOverlay(bool enable, pass_class_t passClass = 0) override; @@ -269,5 +269,4 @@ public: void RenderSubmit(SceneCollector& collector); }; - #endif // INCLUDED_CCMPPATHFINDER_COMMON diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 8de03c1a8c..b0725e96d3 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -192,7 +192,7 @@ struct Query entity_pos_t yOrigin; // Used for parabolas only. u32 ownersMask; std::int32_t interface; - u8 flagsMask; + std::uint8_t flagsMask; bool enabled; bool parabolic; bool accountForSize; // If true, the query accounts for unit sizes, otherwise it treats all entities as points. @@ -266,7 +266,7 @@ struct EntityData u32 size; u16 visionSharing; // 1-bit per player std::int8_t owner; - u8 flags; // See the FlagMasks enum + std::uint8_t flags; // See the FlagMasks enum template inline bool HasFlag() const { return (flags & mask) != 0; } @@ -274,7 +274,7 @@ struct EntityData template inline void SetFlag(bool val) { flags = val ? (flags | mask) : (flags & ~mask); } - inline void SetFlag(u8 mask, bool val) { flags = val ? (flags | mask) : (flags & ~mask); } + inline void SetFlag(std::uint8_t mask, bool val) { flags = val ? (flags | mask) : (flags & ~mask); } }; static_assert(sizeof(EntityData) == 24); @@ -942,7 +942,7 @@ public: for (std::int32_t j = 0; j < m_LosVerticesPerSide; j++) for (std::int32_t i = 0; i < m_LosVerticesPerSide; i++) if (!LosIsOffWorld(i, j)) - for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k) + for (std::uint8_t k = 1; k < MAX_LOS_PLAYER_ID+1; ++k) m_ExploredVertices.at(k) += ((m_LosState.get(i, j) & ((u32)LosState::EXPLORED << (2*(k-1)))) > 0); } else m_LosState.resize(m_LosVerticesPerSide, m_LosVerticesPerSide); @@ -996,7 +996,7 @@ public: tag_t CreateActiveQuery(entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, - const std::vector& owners, int requiredInterface, u8 flags, + const std::vector& owners, int requiredInterface, std::uint8_t flags, bool accountForSize, bool preferMirages) override { tag_t id = m_QueryNext++; @@ -1006,7 +1006,7 @@ public: tag_t CreateActiveParabolicQuery(entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, entity_pos_t baseRange, entity_pos_t yOrigin, - const std::vector& owners, int requiredInterface, u8 flags, bool preferMirages = false) override + const std::vector& owners, int requiredInterface, std::uint8_t flags, bool preferMirages = false) override { tag_t id = m_QueryNext++; m_Queries[id] = ConstructParabolicQuery(source, minRange, maxRange, baseRange, yOrigin, owners, requiredInterface, flags, true, preferMirages); @@ -1609,7 +1609,7 @@ public: Query ConstructQuery(entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, - const std::vector& owners, int requiredInterface, u8 flagsMask, + const std::vector& owners, int requiredInterface, std::uint8_t flagsMask, bool accountForSize, bool preferMirages = false) const { // Min range must be non-negative. @@ -1669,7 +1669,7 @@ public: Query ConstructParabolicQuery(entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, entity_pos_t baseRange, entity_pos_t yOrigin, - const std::vector& owners, int requiredInterface, u8 flagsMask, + const std::vector& owners, int requiredInterface, std::uint8_t flagsMask, bool accountForSize, bool preferMirages = false) const { Query q = ConstructQuery(source, minRange, maxRange, owners, requiredInterface, flagsMask, accountForSize, preferMirages); @@ -1815,7 +1815,7 @@ public: collector.Submit(&m_DebugOverlayLines[i]); } - u8 GetEntityFlagMask(const std::string& identifier) const override + std::uint8_t GetEntityFlagMask(const std::string& identifier) const override { if (identifier == "normal") return FlagMasks::Normal; @@ -1834,7 +1834,7 @@ public: if (it == m_EntityData.end()) return; - u8 flag = GetEntityFlagMask(identifier); + std::uint8_t flag = GetEntityFlagMask(identifier); if (flag == FlagMasks::None) LOGWARNING("CCmpRangeManager: Invalid flag identifier %s for entity %u", identifier.c_str(), ent); @@ -2084,7 +2084,7 @@ public: // Calling UpdateVisibility can modify m_ModifiedEntities, so be careful: // infinite loops could be triggered by feedback between entities and their mirages. - std::map attempts; + std::map attempts; while (!m_ModifiedEntities.empty()) { entity_id_t ent = m_ModifiedEntities.back(); @@ -2115,7 +2115,8 @@ public: if (oldVis == newVis) return; - itEnts->second.visibilities = (itEnts->second.visibilities & ~(0x3 << 2 * (player - 1))) | ((u8)newVis << 2 * (player - 1)); + itEnts->second.visibilities = (itEnts->second.visibilities & ~(0x3 << 2 * (player - 1))) | + (static_cast(newVis) << 2 * (player - 1)); CMessageVisibilityChanged msg(player, ent, static_cast(oldVis), static_cast(newVis)); GetSimContext().GetComponentManager().PostMessage(ent, msg); @@ -2218,7 +2219,7 @@ public: PROFILE3("ExploreTerritories"); CmpPtr cmpTerritoryManager(GetSystemEntity()); - const Grid& grid = cmpTerritoryManager->GetTerritoryGrid(); + const Grid& grid = cmpTerritoryManager->GetTerritoryGrid(); // Territory data is stored per territory-tile (typically a multiple of terrain-tiles). // LOS data is stored per los vertex (in reality tiles too, but it's the center that matters). @@ -2234,7 +2235,7 @@ public: { // TODO: This fetches data redundantly if the los grid is smaller than the territory grid // (but it's unlikely to matter much). - u8 p = grid.get(scale(i, grid.width() - 1), scale(j, grid.height() - 1)) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK; + std::uint8_t p = grid.get(scale(i, grid.width() - 1), scale(j, grid.height() - 1)) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK; if (p > 0 && p <= MAX_LOS_PLAYER_ID) { u32& explored = m_ExploredVertices.at(p); @@ -2402,7 +2403,7 @@ public: /** * Update the LOS state of tiles within a given horizontal strip (i0,j) to (i1,j) (inclusive). */ - inline void LosAddStripHelper(u8 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; @@ -2430,7 +2431,7 @@ public: /** * Update the LOS state of tiles within a given horizontal strip (i0,j) to (i1,j) (inclusive). */ - inline void LosRemoveStripHelper(u8 owner, std::int32_t i0, std::int32_t i1, std::int32_t j, + inline void LosRemoveStripHelper(std::uint8_t owner, std::int32_t i0, std::int32_t i1, std::int32_t j, Grid& counts) { if (i1 < i0) @@ -2452,7 +2453,7 @@ public: } } - inline void MarkVisibilityDirtyAroundTile(u8 owner, std::int32_t i, std::int32_t j) + inline void MarkVisibilityDirtyAroundTile(std::uint8_t owner, std::int32_t i, std::int32_t j) { // If we're still in the deserializing process, we must not modify m_DirtyVisibility if (m_Deserializing) @@ -2483,7 +2484,7 @@ public: * Assumes owner is in the valid range. */ template - void LosUpdateHelper(u8 owner, entity_pos_t visionRange, CFixedVector2D pos) + void LosUpdateHelper(std::uint8_t owner, entity_pos_t visionRange, CFixedVector2D pos) { if (m_LosVerticesPerSide == 0) // do nothing if not initialised yet return; @@ -2570,7 +2571,7 @@ public: * by removing visibility around the 'from' position * and then adding visibility around the 'to' position. */ - void LosUpdateHelperIncremental(u8 owner, entity_pos_t visionRange, CFixedVector2D from, CFixedVector2D to) + void LosUpdateHelperIncremental(std::uint8_t owner, entity_pos_t visionRange, CFixedVector2D from, CFixedVector2D to) { if (m_LosVerticesPerSide == 0) // do nothing if not initialised yet return; @@ -2698,7 +2699,7 @@ public: if (visionRange.IsZero() || owner <= 0 || owner > MAX_LOS_PLAYER_ID) return; - LosUpdateHelper((u8)owner, visionRange, pos); + LosUpdateHelper(static_cast(owner), visionRange, pos); } void SharingLosAdd(u16 visionSharing, entity_pos_t visionRange, CFixedVector2D pos) @@ -2716,7 +2717,7 @@ public: if (visionRange.IsZero() || owner <= 0 || owner > MAX_LOS_PLAYER_ID) return; - LosUpdateHelper((u8)owner, visionRange, pos); + LosUpdateHelper(static_cast(owner), visionRange, pos); } void SharingLosRemove(u16 visionSharing, entity_pos_t visionRange, CFixedVector2D pos) @@ -2737,12 +2738,12 @@ public: if ((from - to).CompareLength(visionRange) > 0) { // If it's a very large move, then simply remove and add to the new position - LosUpdateHelper((u8)owner, visionRange, from); - LosUpdateHelper((u8)owner, visionRange, to); + LosUpdateHelper(static_cast(owner), visionRange, from); + LosUpdateHelper(static_cast(owner), visionRange, to); } else // Otherwise use the version optimised for mostly-overlapping circles - LosUpdateHelperIncremental((u8)owner, visionRange, from, to); + LosUpdateHelperIncremental(static_cast(owner), visionRange, from, to); } void SharingLosMove(u16 visionSharing, entity_pos_t visionRange, CFixedVector2D from, CFixedVector2D to) @@ -2755,12 +2756,12 @@ public: LosMove(i, visionRange, from, to); } - u8 GetPercentMapExplored(player_id_t player) const override + std::uint8_t GetPercentMapExplored(player_id_t player) const override { - return m_ExploredVertices.at((u8)player) * 100 / m_TotalInworldVertices; + return m_ExploredVertices.at(static_cast(player)) * 100 / m_TotalInworldVertices; } - u8 GetUnionPercentMapExplored(const std::vector& players) const override + std::uint8_t GetUnionPercentMapExplored(const std::vector& players) const override { u32 exploredVertices = 0; std::vector::const_iterator playerIt; diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index 8f948cc415..919b8fbb83 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/source/simulation2/components/CCmpTerritoryManager.cpp @@ -77,11 +77,11 @@ namespace { constexpr bool DISABLE_TERRITORY_OVERLAY{true}; -void BuildTextureRGBA(Grid*& territories, std::uint8_t* data, const int w, const int h) +void BuildTextureRGBA(Grid*& territories, std::uint8_t* data, const int w, const int h) { TerrainTextureOverlay::OverwriteEachTile(data, w, h, [&](const int i, const int j) { - const u8 id{static_cast(territories->get(j, i) & + const std::uint8_t id{static_cast(territories->get(j, i) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK)}; return TerrainTextureOverlay::GetColor(id, 64); }); @@ -112,7 +112,7 @@ public: return ""; } - u8 m_ImpassableCost; + std::uint8_t m_ImpassableCost; float m_BorderThickness; float m_BorderSeparation; @@ -120,13 +120,13 @@ public: // connected flag in bit 5 (TERRITORY_CONNECTED_MASK) // blinking flag in bit 6 (TERRITORY_BLINKING_MASK) // processed flag in bit 7 (TERRITORY_PROCESSED_MASK) - Grid* m_Territories; + Grid* m_Territories; std::vector m_TerritoryCellCounts; u16 m_TerritoryTotalPassableCellCount; // Saves the cost per tile (to stop territory on impassable tiles) - Grid* m_CostGrid; + Grid* m_CostGrid; // Set to true when territories change; will send a TerritoriesChanged message // during the Update phase @@ -177,7 +177,7 @@ public: int impassableCost = externalParamNode.GetChild("TerritoryManager").GetChild("ImpassableCost").ToInt(); ENSURE(0 <= impassableCost && impassableCost <= 255); - m_ImpassableCost = (u8)impassableCost; + m_ImpassableCost = static_cast(impassableCost); const std::string& visibilityStatus = externalParamNode.GetChild("TerritoryManager").GetChild("VisibilityStatus").ToString(); m_Enabled = visibilityStatus != "off"; @@ -276,7 +276,7 @@ public: MakeDirty(); } - const Grid& GetTerritoryGrid() override + const Grid& GetTerritoryGrid() override { CalculateTerritories(); ENSURE(m_Territories); @@ -332,7 +332,7 @@ public: void CalculateTerritories(); - u8 GetTerritoryPercentage(player_id_t player) override; + std::uint8_t GetTerritoryPercentage(player_id_t player) override; std::vector ComputeBoundaries(); @@ -446,7 +446,7 @@ void CCmpTerritoryManager::CalculateCostGrid() int tilesW = passGrid.m_W / NAVCELLS_PER_TERRITORY_TILE; int tilesH = passGrid.m_H / NAVCELLS_PER_TERRITORY_TILE; - m_CostGrid = new Grid(tilesW, tilesH); + m_CostGrid = new Grid(tilesW, tilesH); m_TerritoryTotalPassableCellCount = 0; for (int i = 0; i < tilesW; ++i) @@ -488,7 +488,7 @@ void CCmpTerritoryManager::CalculateTerritories() const u16 tilesW = m_CostGrid->m_W; const u16 tilesH = m_CostGrid->m_H; - m_Territories = new Grid(tilesW, tilesH); + m_Territories = new Grid(tilesW, tilesH); // Reset territory counts for all players CmpPtr cmpPlayerManager(GetSystemEntity()); @@ -530,7 +530,7 @@ void CCmpTerritoryManager::CalculateTerritories() // playerGrid stores the combined weight of all entities for this player Grid playerGrid(tilesW, tilesH); - u8 owner = static_cast(pair.first); + std::uint8_t owner = static_cast(pair.first); const std::vector& ents = pair.second; // With 2^16 entities, we're safe against overflows as the weight is also limited to 2^16 ENSURE(ents.size() < 1 << 16); @@ -611,7 +611,7 @@ void CCmpTerritoryManager::CalculateTerritories() u16 i, j; NearestTerritoryTile(pos.X, pos.Y, i, j, tilesW, tilesH); - u8 owner = (u8)cmpOwnership->GetOwner(); + std::uint8_t owner = static_cast(cmpOwnership->GetOwner()); Floodfill({i, j}, {tilesW, tilesH}, [&](const Tile*, const Tile& neighbour) { @@ -645,7 +645,7 @@ std::vector CCmpTerritoryManager::ComputeBoundaries() return CTerritoryBoundaryCalculator::ComputeBoundaries(m_Territories); } -u8 CCmpTerritoryManager::GetTerritoryPercentage(player_id_t player) +std::uint8_t CCmpTerritoryManager::GetTerritoryPercentage(player_id_t player) { if (player <= 0 || (m_Territories && static_cast(player) >= m_TerritoryCellCounts.size())) return 0; @@ -656,7 +656,7 @@ u8 CCmpTerritoryManager::GetTerritoryPercentage(player_id_t player) if (m_TerritoryTotalPassableCellCount == 0 || static_cast(player) >= m_TerritoryCellCounts.size()) return 0; - u8 percentage = (m_TerritoryCellCounts[player] * 100) / m_TerritoryTotalPassableCellCount; + std::uint8_t percentage = (m_TerritoryCellCounts[player] * 100) / m_TerritoryTotalPassableCellCount; ENSURE(percentage <= 100); return percentage; } @@ -861,7 +861,7 @@ void CCmpTerritoryManager::SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, Floodfill({i, j}, {tilesW, tilesH}, [&](const Tile*, const Tile& neighbour) { - const u8 bitmask{m_Territories->get(neighbour.x, neighbour.z)}; + const std::uint8_t bitmask{m_Territories->get(neighbour.x, neighbour.z)}; if ((bitmask & TERRITORY_PLAYER_MASK) != thisOwner) return false; const bool blinking{(bitmask & TERRITORY_BLINKING_MASK) != 0}; diff --git a/source/simulation2/components/CCmpUnitMotion.h b/source/simulation2/components/CCmpUnitMotion.h index eb4767b7a8..1fe9e71458 100644 --- a/source/simulation2/components/CCmpUnitMotion.h +++ b/source/simulation2/components/CCmpUnitMotion.h @@ -74,7 +74,7 @@ namespace constexpr entity_pos_t SHORT_PATH_MIN_SEARCH_RANGE = entity_pos_t::FromInt(12 * Pathfinding::NAVCELL_SIZE_INT); constexpr entity_pos_t SHORT_PATH_MAX_SEARCH_RANGE = entity_pos_t::FromInt(56 * Pathfinding::NAVCELL_SIZE_INT); constexpr entity_pos_t SHORT_PATH_SEARCH_RANGE_INCREMENT = entity_pos_t::FromInt(4 * Pathfinding::NAVCELL_SIZE_INT); -constexpr u8 SHORT_PATH_SEARCH_RANGE_INCREASE_DELAY = 1; +constexpr std::uint8_t SHORT_PATH_SEARCH_RANGE_INCREASE_DELAY = 1; /** * When using the short-pathfinder to rejoin a long-path waypoint, aim for a circle of this radius around the waypoint. @@ -106,7 +106,7 @@ constexpr entity_pos_t TARGET_UNCERTAINTY_MULTIPLIER = entity_pos_t::FromInt(8 * * This is rather arbitrary and mostly for simplicity & optimisation (a better recomputing algorithm * would not need this). */ -constexpr u8 KNOWN_IMPERFECT_PATH_RESET_COUNTDOWN = 12; +constexpr std::uint8_t KNOWN_IMPERFECT_PATH_RESET_COUNTDOWN = 12; /** * When we fail to move this many turns in a row, inform other components that the move will fail. @@ -115,14 +115,14 @@ constexpr u8 KNOWN_IMPERFECT_PATH_RESET_COUNTDOWN = 12; * TODO: if UnitMotion could send differentiated "unreachable" and "currently stuck" failing messages, * this could probably be lowered. */ -constexpr u8 MAX_FAILED_MOVEMENTS = 35; +constexpr std::uint8_t MAX_FAILED_MOVEMENTS = 35; /** * When computing paths but failing to move, we want to occasionally alternate pathfinder systems * to avoid getting stuck (the short pathfinder can unstuck the long-range one and vice-versa, depending). */ -constexpr u8 ALTERNATE_PATH_TYPE_DELAY = 3; -constexpr u8 ALTERNATE_PATH_TYPE_EVERY = 6; +constexpr std::uint8_t ALTERNATE_PATH_TYPE_DELAY = 3; +constexpr std::uint8_t ALTERNATE_PATH_TYPE_EVERY = 6; /** * Units can occasionally get stuck near corners. The cause is a mismatch between CheckMovement and the short pathfinder. @@ -130,13 +130,13 @@ constexpr u8 ALTERNATE_PATH_TYPE_EVERY = 6; * Fixing this math mismatch is perhaps possible, but fixing it in UM is rather easy: just try backing up a bit * and that will probably un-stuck the unit. This is the 'failed movement' turn on which to try that. */ -constexpr u8 BACKUP_HACK_DELAY = 10; +constexpr std::uint8_t BACKUP_HACK_DELAY = 10; /** * After this many failed computations, start sending "VERY_OBSTRUCTED" messages instead. * Should probably be larger than ALTERNATE_PATH_TYPE_DELAY. */ -constexpr u8 VERY_OBSTRUCTED_THRESHOLD = 10; +constexpr std::uint8_t VERY_OBSTRUCTED_THRESHOLD = 10; struct PathColorPalette { @@ -196,7 +196,7 @@ public: // Internal counter used when recovering from obstructed movement. // Most notably, increases the search range of the vertex pathfinder. // See HandleObstructedMove() for more details. - u8 m_FailedMovements = 0; + std::uint8_t m_FailedMovements = 0; // If > 0, PathingUpdateNeeded returns false always. // This exists because the goal may be unreachable to the short/long pathfinder. @@ -205,7 +205,7 @@ public: // To avoid that, when we know the new path is imperfect, treat it as OK and follow it anyways. // When reaching the end, we'll go through HandleObstructedMove and reset regardless. // To still recompute now and then (the target may be moving), this is a countdown decremented on each frame. - u8 m_FollowKnownImperfectPathCountdown = 0; + std::uint8_t m_FollowKnownImperfectPathCountdown = 0; struct Ticket { u32 m_Ticket = 0; // asynchronous request ID we're waiting for, or 0 if none @@ -757,7 +757,8 @@ private: entity_pos_t ShortPathSearchRange() const { - u8 multiple = m_FailedMovements < SHORT_PATH_SEARCH_RANGE_INCREASE_DELAY ? 0 : m_FailedMovements - SHORT_PATH_SEARCH_RANGE_INCREASE_DELAY; + std::uint8_t multiple = m_FailedMovements < SHORT_PATH_SEARCH_RANGE_INCREASE_DELAY ? 0 : + m_FailedMovements - SHORT_PATH_SEARCH_RANGE_INCREASE_DELAY; fixed searchRange = SHORT_PATH_MIN_SEARCH_RANGE + SHORT_PATH_SEARCH_RANGE_INCREMENT * multiple; if (searchRange > SHORT_PATH_MAX_SEARCH_RANGE) searchRange = SHORT_PATH_MAX_SEARCH_RANGE; diff --git a/source/simulation2/components/ICmpMinimap.h b/source/simulation2/components/ICmpMinimap.h index f87458c442..4f0d6181eb 100644 --- a/source/simulation2/components/ICmpMinimap.h +++ b/source/simulation2/components/ICmpMinimap.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 @@ #ifndef INCLUDED_ICMPMINIMAP #define INCLUDED_ICMPMINIMAP -#include "lib/types.h" #include "simulation2/helpers/Position.h" #include "simulation2/system/Component.h" #include "simulation2/system/Interface.h" @@ -37,7 +36,8 @@ public: * If it should not be drawn, returns false; otherwise the arguments are set * to the color and world position. */ - virtual bool GetRenderData(u8& r, u8& g, u8& b, entity_pos_t& x, entity_pos_t& z) const = 0; + virtual bool GetRenderData(std::uint8_t& r, std::uint8_t& g, std::uint8_t& b, entity_pos_t& x, + entity_pos_t& z) const = 0; /** * Returns true if the entity is actively pinging based on the current time. diff --git a/source/simulation2/components/ICmpObstructionManager.h b/source/simulation2/components/ICmpObstructionManager.h index ebd27d3790..2d13f8803e 100644 --- a/source/simulation2/components/ICmpObstructionManager.h +++ b/source/simulation2/components/ICmpObstructionManager.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 @@ -103,7 +103,7 @@ public: /** * Bitmask of EFlag values. */ - typedef u8 flags_t; + typedef std::uint8_t flags_t; /** * Set the bounds of the world. diff --git a/source/simulation2/components/ICmpPathfinder.h b/source/simulation2/components/ICmpPathfinder.h index cddd54ebd6..24db77aff0 100644 --- a/source/simulation2/components/ICmpPathfinder.h +++ b/source/simulation2/components/ICmpPathfinder.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 @@ -207,7 +207,7 @@ public: /** * Returns some stats about the last ComputePath. */ - virtual void GetDebugData(u32& steps, double& time, Grid& grid) const = 0; + virtual void GetDebugData(u32& steps, double& time, Grid& grid) const = 0; /** * Sets up the pathfinder passability overlay in Atlas. diff --git a/source/simulation2/components/ICmpRangeManager.h b/source/simulation2/components/ICmpRangeManager.h index ad42f31b02..439dad244b 100644 --- a/source/simulation2/components/ICmpRangeManager.h +++ b/source/simulation2/components/ICmpRangeManager.h @@ -52,7 +52,7 @@ const entity_pos_t NEVER_IN_RANGE = entity_pos_t::FromInt(-2); * so define this enum here (Ideally, it'd be in its own header file, * but adding header file does incur its own compilation time increase). */ -enum class LosVisibility : u8 +enum class LosVisibility : std::uint8_t { HIDDEN = 0, FOGGED = 1, @@ -169,7 +169,7 @@ public: */ virtual tag_t CreateActiveQuery(entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, - const std::vector& owners, int requiredInterface, u8 flags, + const std::vector& owners, int requiredInterface, std::uint8_t flags, bool accountForSize, bool preferMirages = false) = 0; /** @@ -196,7 +196,8 @@ public: */ virtual tag_t CreateActiveParabolicQuery(entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, entity_pos_t baseRange, entity_pos_t yOrigin, - const std::vector& owners, int requiredInterface, u8 flags, bool preferMirages = false) = 0; + const std::vector& owners, int requiredInterface, std::uint8_t flags, + bool preferMirages = false) = 0; /** * Get the effective range in a parablic range query. @@ -288,7 +289,7 @@ public: /** * Returns the mask for the specified identifier. */ - virtual u8 GetEntityFlagMask(const std::string& identifier) const = 0; + virtual std::uint8_t GetEntityFlagMask(const std::string& identifier) const = 0; /** * Set the flag specified by the identifier to the supplied value for the entity @@ -415,13 +416,13 @@ public: /** * Get percent map explored statistics for specified player. */ - virtual u8 GetPercentMapExplored(player_id_t player) const = 0; + virtual std::uint8_t GetPercentMapExplored(player_id_t player) const = 0; /** * Get percent map explored statistics for specified set of players. * Note: this function computes statistics from scratch and should not be called too often. */ - virtual u8 GetUnionPercentMapExplored(const std::vector& players) const = 0; + virtual std::uint8_t GetUnionPercentMapExplored(const std::vector& players) const = 0; /** * @return The number of LOS vertices. diff --git a/source/simulation2/components/ICmpTerritoryManager.h b/source/simulation2/components/ICmpTerritoryManager.h index de395def80..f5f748e143 100644 --- a/source/simulation2/components/ICmpTerritoryManager.h +++ b/source/simulation2/components/ICmpTerritoryManager.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 @@ -61,7 +61,7 @@ public: * TERRITORY_CONNECTED_MASK is set if the tile is connected to a root object * (civ center etc). */ - virtual const Grid& GetTerritoryGrid() = 0; + virtual const Grid& GetTerritoryGrid() = 0; /** * Get owner of territory at given position. @@ -95,7 +95,7 @@ public: * Returns the percentage of the world controlled by a given player as defined by * the number of territory cells the given player owns */ - virtual u8 GetTerritoryPercentage(player_id_t player) = 0; + virtual std::uint8_t GetTerritoryPercentage(player_id_t player) = 0; /** * Enables or disables rendering of an territory borders. diff --git a/source/simulation2/components/tests/test_HierPathfinder.h b/source/simulation2/components/tests/test_HierPathfinder.h index cfccfddc7f..8831d21718 100644 --- a/source/simulation2/components/tests/test_HierPathfinder.h +++ b/source/simulation2/components/tests/test_HierPathfinder.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 @@ -125,7 +125,7 @@ public: HierarchicalPathfinder hierPath; Grid grid(mapSize, mapSize); - Grid dirtyGrid(mapSize, mapSize); + Grid dirtyGrid(mapSize, mapSize); // Entirely passable for PASS_1, not for others; for (size_t i = 0; i < mapSize; ++i) @@ -356,7 +356,7 @@ public: HierarchicalPathfinder hierPath; Grid grid(40*scale, 40*scale); - Grid dirtyGrid(40*scale, 40*scale); + Grid dirtyGrid(40*scale, 40*scale); for (size_t i = 0; i < 40; ++i) for (size_t j = 0; j < 40; ++j) @@ -522,7 +522,7 @@ public: #undef X HierarchicalPathfinder hierPath; Grid grid(5, 5); - Grid dirtyGrid(5, 5); + Grid dirtyGrid(5, 5); for (size_t i = 0; i < 5; ++i) for (size_t j = 0; j < 5; ++j) grid.set(i, j, gridDef[i][j]); diff --git a/source/simulation2/components/tests/test_Pathfinder.h b/source/simulation2/components/tests/test_Pathfinder.h index 586c8beaf9..c6eae50d4a 100644 --- a/source/simulation2/components/tests/test_Pathfinder.h +++ b/source/simulation2/components/tests/test_Pathfinder.h @@ -407,7 +407,7 @@ public: u32 debugSteps; double debugTime; - Grid debugGrid; + Grid debugGrid; cmpPathfinder->GetDebugData(debugSteps, debugTime, debugGrid); // stream << " \n"; diff --git a/source/simulation2/components/tests/test_RangeManager.h b/source/simulation2/components/tests/test_RangeManager.h index 4d319a39a1..ae4d8f0678 100644 --- a/source/simulation2/components/tests/test_RangeManager.h +++ b/source/simulation2/components/tests/test_RangeManager.h @@ -561,7 +561,7 @@ public: cmp->ExploreCircle(1, entity_pos_t::FromInt(128), entity_pos_t::FromInt(128), fixed::FromInt(50)); // Check that some tiles were explored (not 0%, not 100%) - u8 percentExplored = cmp->GetPercentMapExplored(1); + std::uint8_t percentExplored = cmp->GetPercentMapExplored(1); TS_ASSERT(percentExplored > 0 && percentExplored < 100); // Test invalid player (should do nothing) diff --git a/source/simulation2/components/tests/test_TerritoryManager.h b/source/simulation2/components/tests/test_TerritoryManager.h index 42e9c81ad8..ff47efe159 100644 --- a/source/simulation2/components/tests/test_TerritoryManager.h +++ b/source/simulation2/components/tests/test_TerritoryManager.h @@ -91,7 +91,7 @@ public: void SendRequestedPaths() override {} void StartProcessingMoves(bool) override {} void UpdateGrid() override {} - void GetDebugData(u32&, double&, Grid&) const override {} + void GetDebugData(u32&, double&, Grid&) const override {} void SetAtlasOverlay(bool, pass_class_t = 0) override {} }; @@ -232,7 +232,7 @@ public: void test_boundaries() { - Grid grid = GetGrid("--------" + Grid grid = GetGrid("--------" "777777--" "777777--" "777777--" @@ -256,7 +256,7 @@ public: void test_nested_boundaries1() { // test case from ticket #918; contains single-tile territories with double borders - Grid grid1 = GetGrid("--------" + Grid grid1 = GetGrid("--------" "-111111-" "-1-1213-" "-111111-" @@ -352,7 +352,7 @@ public: void test_nested_boundaries2() { - Grid grid1 = GetGrid("-22222-" + Grid grid1 = GetGrid("-22222-" "-2---2-" "-2-1123" "-2-1123" @@ -445,9 +445,9 @@ 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, u16 w, u16 h) { - Grid grid(w, h); + Grid grid(w, h); const char* chars = def.c_str(); for (u16 y=0; y dirtinessGrid; + Grid dirtinessGrid; /** * Update the information with additionnal needed updates, then erase the source of additions. diff --git a/source/simulation2/helpers/HierarchicalPathfinder.cpp b/source/simulation2/helpers/HierarchicalPathfinder.cpp index 84c7b400c2..0194f3680c 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.cpp +++ b/source/simulation2/helpers/HierarchicalPathfinder.cpp @@ -408,7 +408,9 @@ void HierarchicalPathfinder::Recompute(Grid* grid, m_W = grid->m_W; m_H = grid->m_H; - ENSURE((grid->m_W + CHUNK_SIZE - 1) / CHUNK_SIZE < 256 && (grid->m_H + CHUNK_SIZE - 1) / CHUNK_SIZE < 256); // else the u8 Chunk::m_ChunkI will overflow + // else the std::uint8_t Chunk::m_ChunkI will overflow + ENSURE((grid->m_W + CHUNK_SIZE - 1) / CHUNK_SIZE < 256 && + (grid->m_H + CHUNK_SIZE - 1) / CHUNK_SIZE < 256); // Divide grid into chunks with round-to-positive-infinity m_ChunksW = (grid->m_W + CHUNK_SIZE - 1) / CHUNK_SIZE; @@ -441,8 +443,8 @@ void HierarchicalPathfinder::Recompute(Grid* grid, // Spread global regions. std::map& globalRegion = m_GlobalRegions[passClass]; globalRegion.clear(); - for (u8 cj = 0; cj < m_ChunksH; ++cj) - for (u8 ci = 0; ci < m_ChunksW; ++ci) + 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) { RegionID reg{ci,cj,rid}; @@ -470,7 +472,7 @@ void HierarchicalPathfinder::Recompute(Grid* grid, } } -void HierarchicalPathfinder::Update(Grid* grid, const Grid& dirtinessGrid) +void HierarchicalPathfinder::Update(Grid* grid, const Grid& dirtinessGrid) { PROFILE3("Hierarchical Update"); @@ -490,11 +492,11 @@ void HierarchicalPathfinder::Update(Grid* grid, const Grid& dir // That's quite annoying, but I can't think of an easy way around it. // If we could be sure that a region's topology hasn't changed, we could skip removing its global region // but that's non trivial as we have no easy way to determine said topology (regions could "switch" IDs on update for now). - for (u8 cj = 0; cj < m_ChunksH; ++cj) + for (std::uint8_t cj = 0; cj < m_ChunksH; ++cj) { int j0 = cj * CHUNK_SIZE; int j1 = std::min(j0 + CHUNK_SIZE, (int)dirtinessGrid.m_H); - for (u8 ci = 0; ci < m_ChunksW; ++ci) + for (std::uint8_t ci = 0; ci < m_ChunksW; ++ci) { // Skip chunks where no navcells are dirty. int i0 = ci * CHUNK_SIZE; @@ -555,8 +557,8 @@ void HierarchicalPathfinder::ComputeNeighbors(EdgesMap& edges, Chunk& a, Chunk& RegionID rbPrev(0,0,0); for (int k = 0; k < CHUNK_SIZE; ++k) { - u8 aSide = opposite ? CHUNK_SIZE - 1 : 0; - u8 bSide = CHUNK_SIZE - 1 - aSide; + std::uint8_t aSide = opposite ? CHUNK_SIZE - 1 : 0; + std::uint8_t bSide = CHUNK_SIZE - 1 - aSide; RegionID ra = transpose ? a.Get(k, aSide) : a.Get(aSide, k); RegionID rb = transpose ? b.Get(k, bSide) : b.Get(bSide, k); if (ra.r && rb.r) @@ -574,7 +576,8 @@ void HierarchicalPathfinder::ComputeNeighbors(EdgesMap& edges, Chunk& a, Chunk& /** * Connect a chunk's regions to their neighbors. Not optimised for global recomputing. */ -void HierarchicalPathfinder::UpdateEdges(u8 ci, u8 cj, pass_class_t passClass, EdgesMap& edges) +void HierarchicalPathfinder::UpdateEdges(std::uint8_t ci, std::uint8_t cj, pass_class_t passClass, + EdgesMap& edges) { std::vector& chunks = m_Chunks[passClass]; @@ -830,14 +833,18 @@ void HierarchicalPathfinder::FindGoalRegionsAndBestNavcells(u16 i0, u16 j0, u16 u16 bestI, bestJ; u32 c; // Unused. - for (u8 sz = std::max(0,(gj - size) / CHUNK_SIZE); sz <= std::min(m_ChunksH-1, (gj + size + 1) / CHUNK_SIZE); ++sz) - for (u8 sx = std::max(0,(gi - size) / CHUNK_SIZE); sx <= std::min(m_ChunksW-1, (gi + size + 1) / CHUNK_SIZE); ++sx) + for (std::uint8_t sz = std::max(0,(gj - size) / CHUNK_SIZE); + sz <= std::min(m_ChunksH-1, (gj + size + 1) / CHUNK_SIZE); ++sz) + { + for (std::uint8_t sx = std::max(0,(gi - size) / CHUNK_SIZE); + 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) 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 diff --git a/source/simulation2/helpers/HierarchicalPathfinder.h b/source/simulation2/helpers/HierarchicalPathfinder.h index 98fdadb499..3a6cfe2f4d 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.h +++ b/source/simulation2/helpers/HierarchicalPathfinder.h @@ -79,10 +79,10 @@ public: struct RegionID { - u8 ci, cj; // chunk ID + std::uint8_t ci, cj; // chunk ID u16 r; // unique-per-chunk local region ID - RegionID(u8 ci, u8 cj, u16 r) : ci(ci), cj(cj), r(r) { } + RegionID(std::uint8_t ci, std::uint8_t cj, u16 r) : ci(ci), cj(cj), r(r) { } bool operator<(const RegionID& b) const { @@ -122,7 +122,7 @@ public: const std::map& nonPathfindingPassClassMasks, const std::map& pathfindingPassClassMasks); - void Update(Grid* grid, const Grid& dirtinessGrid); + void Update(Grid* grid, const Grid& dirtinessGrid); RegionID Get(u16 i, u16 j, pass_class_t passClass) const; @@ -173,12 +173,12 @@ public: void RenderSubmit(SceneCollector& collector); private: - static const u8 CHUNK_SIZE = 96; // number of navcells per side + static const std::uint8_t CHUNK_SIZE = 96; // number of navcells per side // TODO: figure out best number. Probably 64 < n < 128 struct Chunk { - u8 m_ChunkI, m_ChunkJ; // chunk ID + 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 @@ -202,7 +202,7 @@ private: #endif }; - const Chunk& GetChunk(u8 ci, u8 cj, pass_class_t passClass) const + const Chunk& GetChunk(std::uint8_t ci, std::uint8_t cj, pass_class_t passClass) const { return m_Chunks.at(passClass).at(cj * m_ChunksW + ci); } @@ -211,7 +211,7 @@ private: void ComputeNeighbors(EdgesMap& edges, Chunk& a, Chunk& b, bool transpose, bool opposite) const; void RecomputeAllEdges(pass_class_t passClass, EdgesMap& edges); - void UpdateEdges(u8 ci, u8 cj, pass_class_t passClass, EdgesMap& edges); + void UpdateEdges(std::uint8_t ci, std::uint8_t cj, pass_class_t passClass, EdgesMap& edges); void UpdateGlobalRegions(const std::map >& needNewGlobalRegionMap); @@ -289,7 +289,7 @@ private: void FillRegionOnGrid(const RegionID& region, pass_class_t passClass, u16 value, Grid& grid) const; u16 m_W, m_H; - u8 m_ChunksW, m_ChunksH; + std::uint8_t m_ChunksW, m_ChunksH; std::map > m_Chunks; std::map m_Edges; diff --git a/source/simulation2/helpers/LongPathfinder.cpp b/source/simulation2/helpers/LongPathfinder.cpp index 3f573bb1b9..46db99fc7b 100644 --- a/source/simulation2/helpers/LongPathfinder.cpp +++ b/source/simulation2/helpers/LongPathfinder.cpp @@ -44,7 +44,7 @@ void BuildTextureRGBA(LongPathfinder& pathfinder, std::uint8_t* data, std::size_ // Grab the debug data for the most recently generated path u32 steps; double time; - Grid debugGrid; + Grid debugGrid; pathfinder.GetDebugData(steps, time, debugGrid); // Render navcell passability @@ -55,7 +55,7 @@ void BuildTextureRGBA(LongPathfinder& pathfinder, std::uint8_t* data, std::size_ if (pathfinder.m_Debug.Goal.NavcellContainsGoal(i, j)) return SColor4ub(0, 0, 255, 127); - const u8 n{debugGrid.get(i, j)}; + const std::uint8_t n{debugGrid.get(i, j)}; if (n == 1) return SColor4ub(255, 255, 0, 127); if (n == 2) @@ -1060,7 +1060,7 @@ void LongPathfinder::ImprovePathWaypoints(WaypointPath& path, pass_class_t passC path.m_Waypoints.swap(newWaypoints); } -void LongPathfinder::GetDebugDataJPS(u32& steps, double& time, Grid& grid) const +void LongPathfinder::GetDebugDataJPS(u32& steps, double& time, Grid& grid) const { steps = m_Debug.Steps; time = m_Debug.Time; @@ -1073,7 +1073,7 @@ void LongPathfinder::GetDebugDataJPS(u32& steps, double& time, Grid& grid) c u16 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); + grid = Grid(m_Debug.Grid->m_W, m_Debug.Grid->m_H); for (u16 j = 0; j < grid.m_H; ++j) { for (u16 i = 0; i < grid.m_W; ++i) diff --git a/source/simulation2/helpers/LongPathfinder.h b/source/simulation2/helpers/LongPathfinder.h index 4654b48ce6..0a62171f72 100644 --- a/source/simulation2/helpers/LongPathfinder.h +++ b/source/simulation2/helpers/LongPathfinder.h @@ -95,12 +95,12 @@ private: u32 data; // 2-bit status; 15-bit PredI; 15-bit PredJ; packed for storage efficiency public: - inline u8 GetStatus() const + inline std::uint8_t GetStatus() const { return data & 3; } - inline void SetStatus(u8 s) + inline void SetStatus(std::uint8_t s) { ASSERT(s < 4); data &= ~3; @@ -221,7 +221,7 @@ public: void ComputePath(const HierarchicalPathfinder& hierPath, entity_pos_t x0, entity_pos_t z0, const PathGoal& origGoal, pass_class_t passClass, std::vector excludedRegions, WaypointPath& path); - void GetDebugData(u32& steps, double& time, Grid& grid) const + void GetDebugData(u32& steps, double& time, Grid& grid) const { GetDebugDataJPS(steps, time, grid); } @@ -269,7 +269,7 @@ private: * TODO: cleanup documentation */ void ComputeJPSPath(const HierarchicalPathfinder& hierPath, entity_pos_t x0, entity_pos_t z0, const PathGoal& origGoal, pass_class_t passClass, WaypointPath& path) const; - void GetDebugDataJPS(u32& steps, double& time, Grid& grid) const; + void GetDebugDataJPS(u32& steps, double& time, Grid& grid) const; // Helper functions for ComputePath diff --git a/source/simulation2/helpers/Los.h b/source/simulation2/helpers/Los.h index a9d49f105b..f94b9681a3 100644 --- a/source/simulation2/helpers/Los.h +++ b/source/simulation2/helpers/Los.h @@ -31,7 +31,7 @@ */ static constexpr std::int32_t LOS_TILE_SIZE = 4; -enum class LosState : u8 +enum class LosState : std::uint8_t { UNEXPLORED = 0, EXPLORED = 1, diff --git a/source/simulation2/helpers/VertexPathfinder.cpp b/source/simulation2/helpers/VertexPathfinder.cpp index 7163e2b292..6e0509a9d9 100644 --- a/source/simulation2/helpers/VertexPathfinder.cpp +++ b/source/simulation2/helpers/VertexPathfinder.cpp @@ -93,14 +93,14 @@ VertexPathfinderDebugOverlay g_VertexPathfinderDebugOverlay; * (For non-axis-aligned rectangles it's harder to do this computation, so we'll * not bother doing any discarding for those.) */ -static const u8 QUADRANT_NONE = 0; -static const u8 QUADRANT_BL = 1; -static const u8 QUADRANT_TR = 2; -static const u8 QUADRANT_TL = 4; -static const u8 QUADRANT_BR = 8; -static const u8 QUADRANT_BLTR = QUADRANT_BL|QUADRANT_TR; -static const u8 QUADRANT_TLBR = QUADRANT_TL|QUADRANT_BR; -static const u8 QUADRANT_ALL = QUADRANT_BLTR|QUADRANT_TLBR; +static const std::uint8_t QUADRANT_NONE = 0; +static const std::uint8_t QUADRANT_BL = 1; +static const std::uint8_t QUADRANT_TR = 2; +static const std::uint8_t QUADRANT_TL = 4; +static const std::uint8_t QUADRANT_BR = 8; +static const std::uint8_t QUADRANT_BLTR = QUADRANT_BL|QUADRANT_TR; +static const std::uint8_t QUADRANT_TLBR = QUADRANT_TL|QUADRANT_BR; +static const std::uint8_t QUADRANT_ALL = QUADRANT_BLTR|QUADRANT_TLBR; // When computing vertexes to insert into the search graph, // add a small delta so that the vertexes of an edge don't get interpreted @@ -822,7 +822,7 @@ WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, npos = m_Vertexes[n].p; // Work out which quadrant(s) we're approaching the new vertex from - u8 quad = 0; + std::uint8_t quad = 0; if (m_Vertexes[curr.id].p.X <= npos.X && m_Vertexes[curr.id].p.Y <= npos.Y) quad |= QUADRANT_BL; if (m_Vertexes[curr.id].p.X >= npos.X && m_Vertexes[curr.id].p.Y >= npos.Y) quad |= QUADRANT_TR; if (m_Vertexes[curr.id].p.X <= npos.X && m_Vertexes[curr.id].p.Y >= npos.Y) quad |= QUADRANT_TL; diff --git a/source/simulation2/helpers/VertexPathfinder.h b/source/simulation2/helpers/VertexPathfinder.h index 95800dc9c8..0488b5b23c 100644 --- a/source/simulation2/helpers/VertexPathfinder.h +++ b/source/simulation2/helpers/VertexPathfinder.h @@ -47,9 +47,9 @@ struct Vertex CFixedVector2D p; fixed g, h; u16 pred = 0; - u8 status; - u8 quadInward : 4; // the quadrant which is inside the shape (or NONE) - u8 quadOutward : 4; // the quadrants of the next point on the path which this vertex must be in, given 'pred' + 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' }; // Obstruction edges (paths will not cross any of these). diff --git a/source/simulation2/scripting/EngineScriptConversions.cpp b/source/simulation2/scripting/EngineScriptConversions.cpp index 177fea0ca6..a53c0beec7 100644 --- a/source/simulation2/scripting/EngineScriptConversions.cpp +++ b/source/simulation2/scripting/EngineScriptConversions.cpp @@ -235,10 +235,11 @@ template<> void Script::ToJSVal>(const Script::Req ToJSVal(rq, ret, val.value()); } -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(u8)); + u32 nbytes = (u32)(length * sizeof(std::uint8_t)); JS::RootedObject objArr(rq.cx, JS_NewUint8Array(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.cpp b/source/simulation2/serialization/BinarySerializer.cpp index 03059b3062..9f7880b7e5 100644 --- a/source/simulation2/serialization/BinarySerializer.cpp +++ b/source/simulation2/serialization/BinarySerializer.cpp @@ -49,7 +49,7 @@ class JSObject; -static u8 GetArrayType(js::Scalar::Type arrayType) +static std::uint8_t GetArrayType(js::Scalar::Type arrayType) { switch(arrayType) { @@ -169,7 +169,8 @@ void CBinarySerializerScriptImpl::HandleScriptVal(const Script::Request& rq, JS: m_Serializer.NumberU32_Unbounded("buffer length", length); JS::AutoCheckCannotGC nogc; bool sharedMemory; - m_Serializer.RawBytes("buffer data", (const u8*)JS::GetArrayBufferData(obj, &sharedMemory, nogc), length); + m_Serializer.RawBytes("buffer data", static_cast( + JS::GetArrayBufferData(obj, &sharedMemory, nogc)), length); break; } @@ -459,7 +460,7 @@ void CBinarySerializerScriptImpl::ScriptString(const Script::Request& rq, const size_t length; JS::AutoCheckCannotGC nogc; // Serialize strings directly as UTF-16 or Latin1, to avoid expensive encoding conversions - u8 isLatin1 = JS::StringHasLatin1Chars(string); + std::uint8_t isLatin1 = JS::StringHasLatin1Chars(string); m_Serializer.NumberU8_Unbounded("isLatin1", isLatin1); if (isLatin1) { @@ -467,7 +468,7 @@ void CBinarySerializerScriptImpl::ScriptString(const Script::Request& rq, const if (!chars) throw PSERROR_Serialize_ScriptError("JS_GetLatin1StringCharsAndLength failed"); m_Serializer.NumberU32_Unbounded("string length", (u32)length); - m_Serializer.RawBytes(name, (const u8*)chars, length); + m_Serializer.RawBytes(name, static_cast(chars), length); } else { @@ -476,7 +477,7 @@ void CBinarySerializerScriptImpl::ScriptString(const Script::Request& rq, const if (!chars) throw PSERROR_Serialize_ScriptError("JS_GetTwoByteStringCharsAndLength failed"); m_Serializer.NumberU32_Unbounded("string length", (u32)length); - m_Serializer.RawBytes(name, (const u8*)chars, length*2); + m_Serializer.RawBytes(name, reinterpret_cast(chars), length*2); } } diff --git a/source/simulation2/serialization/BinarySerializer.h b/source/simulation2/serialization/BinarySerializer.h index 15e8445a47..a5b97312d5 100644 --- a/source/simulation2/serialization/BinarySerializer.h +++ b/source/simulation2/serialization/BinarySerializer.h @@ -79,14 +79,14 @@ protected: if (n != 0) { pbump(-n); - m_SerializerImpl.Put("stream", reinterpret_cast (pbase()), n); + m_SerializerImpl.Put("stream", reinterpret_cast(pbase()), n); } return 0; } std::streamsize xsputn(const char* s, std::streamsize n) { - m_SerializerImpl.Put("stream", reinterpret_cast (s), n); + m_SerializerImpl.Put("stream", reinterpret_cast(s), n); return n; } }; @@ -159,52 +159,52 @@ protected: virtual void PutNumber(const char* name, uint8_t value) { - m_Impl.Put(name, (const u8*)&value, sizeof(uint8_t)); + m_Impl.Put(name, reinterpret_cast(&value), sizeof(uint8_t)); } virtual void PutNumber(const char* name, int8_t value) { - m_Impl.Put(name, (const u8*)&value, sizeof(int8_t)); + m_Impl.Put(name, reinterpret_cast(&value), sizeof(int8_t)); } virtual void PutNumber(const char* name, uint16_t value) { uint16_t v = to_le16(value); - m_Impl.Put(name, (const u8*)&v, sizeof(uint16_t)); + m_Impl.Put(name, reinterpret_cast(&v), sizeof(uint16_t)); } virtual void PutNumber(const char* name, int16_t value) { int16_t v = static_cast(to_le16((u16)value)); - m_Impl.Put(name, (const u8*)&v, sizeof(int16_t)); + m_Impl.Put(name, reinterpret_cast(&v), sizeof(int16_t)); } virtual void PutNumber(const char* name, uint32_t value) { uint32_t v = to_le32(value); - m_Impl.Put(name, (const u8*)&v, sizeof(uint32_t)); + m_Impl.Put(name, reinterpret_cast(&v), sizeof(uint32_t)); } virtual void PutNumber(const char* name, int32_t value) { int32_t v = static_cast(to_le32((u32)value)); - m_Impl.Put(name, (const u8*)&v, sizeof(int32_t)); + m_Impl.Put(name, reinterpret_cast(&v), sizeof(int32_t)); } virtual void PutNumber(const char* name, float value) { - m_Impl.Put(name, (const u8*)&value, sizeof(float)); + m_Impl.Put(name, reinterpret_cast(&value), sizeof(float)); } virtual void PutNumber(const char* name, double value) { - m_Impl.Put(name, (const u8*)&value, sizeof(double)); + m_Impl.Put(name, reinterpret_cast(&value), sizeof(double)); } virtual void PutNumber(const char* name, fixed value) { int32_t v = static_cast(to_le32((u32)value.GetInternalValue())); - m_Impl.Put(name, (const u8*)&v, sizeof(int32_t)); + m_Impl.Put(name, reinterpret_cast(&v), sizeof(int32_t)); } virtual void PutBool(const char* name, bool value) @@ -216,7 +216,7 @@ protected: { // TODO: maybe should intern strings, particularly to save space with script property names PutNumber("string length", (uint32_t)value.length()); - m_Impl.Put(name, (u8*)value.data(), value.length()); + m_Impl.Put(name, reinterpret_cast(value.data()), value.length()); } virtual void PutScriptVal(const char* /*name*/, JS::MutableHandleValue value) @@ -224,7 +224,7 @@ protected: m_ScriptImpl->PutScriptVal(value); } - virtual void PutRaw(const char* name, const u8* data, size_t len) + virtual void PutRaw(const char* name, const std::uint8_t* data, size_t len) { m_Impl.Put(name, data, len); } diff --git a/source/simulation2/serialization/DebugSerializer.cpp b/source/simulation2/serialization/DebugSerializer.cpp index 538d569f9c..f99084d453 100644 --- a/source/simulation2/serialization/DebugSerializer.cpp +++ b/source/simulation2/serialization/DebugSerializer.cpp @@ -172,7 +172,7 @@ void CDebugSerializer::PutScriptVal(const char* name, JS::MutableHandleValue val } } -void CDebugSerializer::PutRaw(const char* name, const u8* data, size_t len) +void CDebugSerializer::PutRaw(const char* name, const std::uint8_t* data, size_t len) { m_Stream << INDENT << name << ": (" << len << " bytes)"; diff --git a/source/simulation2/serialization/DebugSerializer.h b/source/simulation2/serialization/DebugSerializer.h index 9144d1e43a..a0b23a6121 100644 --- a/source/simulation2/serialization/DebugSerializer.h +++ b/source/simulation2/serialization/DebugSerializer.h @@ -22,7 +22,6 @@ #include "simulation2/system/Component.h" #include "lib/code_annotation.h" -#include "lib/types.h" #include "maths/Fixed.h" #include @@ -68,7 +67,7 @@ protected: virtual void PutBool(const char* name, bool value); virtual void PutString(const char* name, const std::string& value); virtual void PutScriptVal(const char* name, JS::MutableHandleValue value); - virtual void PutRaw(const char* name, const u8* data, size_t len); + virtual void PutRaw(const char* name, const std::uint8_t* data, size_t len); private: const Script::Interface& m_ScriptInterface; diff --git a/source/simulation2/serialization/HashSerializer.cpp b/source/simulation2/serialization/HashSerializer.cpp index 2ae8a3d1ed..5f722d3586 100644 --- a/source/simulation2/serialization/HashSerializer.cpp +++ b/source/simulation2/serialization/HashSerializer.cpp @@ -33,7 +33,7 @@ size_t CHashSerializer::GetHashLength() return m_Impl.GetHashLength(); } -const u8* CHashSerializer::ComputeHash() +const std::uint8_t* CHashSerializer::ComputeHash() { return m_Impl.ComputeHash(); } @@ -43,7 +43,7 @@ size_t CHashSerializerImpl::GetHashLength() return HashFunc::DIGESTSIZE; } -const u8* CHashSerializerImpl::ComputeHash() +const std::uint8_t* CHashSerializerImpl::ComputeHash() { m_Hash.Final(m_HashData); return m_HashData; diff --git a/source/simulation2/serialization/HashSerializer.h b/source/simulation2/serialization/HashSerializer.h index 7e4bef055c..f1dece6ea5 100644 --- a/source/simulation2/serialization/HashSerializer.h +++ b/source/simulation2/serialization/HashSerializer.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_HASHSERIALIZER #define INCLUDED_HASHSERIALIZER -#include "lib/types.h" #include "maths/MD5.h" #include "simulation2/serialization/BinarySerializer.h" @@ -34,16 +33,16 @@ class CHashSerializerImpl public: size_t GetHashLength(); - const u8* ComputeHash(); + const std::uint8_t* ComputeHash(); - void Put(const char* /*name*/, const u8* data, size_t len) + void Put(const char* /*name*/, const std::uint8_t* data, size_t len) { m_Hash.Update(data, len); } private: HashFunc m_Hash; - u8 m_HashData[HashFunc::DIGESTSIZE]; + std::uint8_t m_HashData[HashFunc::DIGESTSIZE]; }; class CHashSerializer : public CBinarySerializer @@ -52,7 +51,7 @@ public: CHashSerializer(const Script::Interface& scriptInterface); size_t GetHashLength(); - const u8* ComputeHash(); + const std::uint8_t* ComputeHash(); }; #endif // INCLUDED_HASHSERIALIZER diff --git a/source/simulation2/serialization/IDeserializer.cpp b/source/simulation2/serialization/IDeserializer.cpp index aace2d7104..44c5cca36e 100644 --- a/source/simulation2/serialization/IDeserializer.cpp +++ b/source/simulation2/serialization/IDeserializer.cpp @@ -32,7 +32,7 @@ IDeserializer::~IDeserializer() void IDeserializer::NumberU8(const char* name, uint8_t& out, uint8_t lower, uint8_t upper) { uint8_t value; - Get(name, (u8*)&value, sizeof(uint8_t)); + Get(name, static_cast(&value), sizeof(uint8_t)); if (!(lower <= value && value <= upper)) throw PSERROR_Deserialize_OutOfBounds(name); @@ -43,7 +43,7 @@ void IDeserializer::NumberU8(const char* name, uint8_t& out, uint8_t lower, uint void IDeserializer::NumberI8(const char* name, int8_t& out, int8_t lower, int8_t upper) { int8_t value; - Get(name, (u8*)&value, sizeof(uint8_t)); + Get(name, reinterpret_cast(&value), sizeof(uint8_t)); if (!(lower <= value && value <= upper)) throw PSERROR_Deserialize_OutOfBounds(name); @@ -54,7 +54,7 @@ void IDeserializer::NumberI8(const char* name, int8_t& out, int8_t lower, int8_t void IDeserializer::NumberU16(const char* name, uint16_t& out, uint16_t lower, uint16_t upper) { uint16_t value; - Get(name, (u8*)&value, sizeof(uint16_t)); + Get(name, reinterpret_cast(&value), sizeof(uint16_t)); value = to_le16(value); if (!(lower <= value && value <= upper)) @@ -66,7 +66,7 @@ void IDeserializer::NumberU16(const char* name, uint16_t& out, uint16_t lower, u void IDeserializer::NumberI16(const char* name, int16_t& out, int16_t lower, int16_t upper) { int16_t value; - Get(name, (u8*)&value, sizeof(uint16_t)); + Get(name, reinterpret_cast(&value), sizeof(uint16_t)); value = static_cast(to_le16((u16)value)); if (!(lower <= value && value <= upper)) @@ -78,7 +78,7 @@ void IDeserializer::NumberI16(const char* name, int16_t& out, int16_t lower, int void IDeserializer::NumberU32(const char* name, uint32_t& out, uint32_t lower, uint32_t upper) { uint32_t value; - Get(name, (u8*)&value, sizeof(uint32_t)); + Get(name, reinterpret_cast(&value), sizeof(uint32_t)); value = to_le32(value); if (!(lower <= value && value <= upper)) @@ -90,7 +90,7 @@ void IDeserializer::NumberU32(const char* name, uint32_t& out, uint32_t lower, u void IDeserializer::NumberI32(const char* name, int32_t& out, int32_t lower, int32_t upper) { int32_t value; - Get(name, (u8*)&value, sizeof(uint32_t)); + Get(name, reinterpret_cast(&value), sizeof(uint32_t)); value = static_cast(to_le32((u32)value)); if (!(lower <= value && value <= upper)) @@ -101,50 +101,50 @@ void IDeserializer::NumberI32(const char* name, int32_t& out, int32_t lower, int void IDeserializer::NumberU8_Unbounded(const char* name, uint8_t& out) { - Get(name, (u8*)&out, sizeof(uint8_t)); + Get(name, reinterpret_cast(&out), sizeof(uint8_t)); } void IDeserializer::NumberI8_Unbounded(const char* name, int8_t& out) { - Get(name, (u8*)&out, sizeof(int8_t)); + Get(name, reinterpret_cast(&out), sizeof(int8_t)); } void IDeserializer::NumberU16_Unbounded(const char* name, uint16_t& out) { uint16_t value; - Get(name, (u8*)&value, sizeof(uint16_t)); + Get(name, reinterpret_cast(&value), sizeof(uint16_t)); out = to_le16(value); } void IDeserializer::NumberI16_Unbounded(const char* name, int16_t& out) { int16_t value; - Get(name, (u8*)&value, sizeof(int16_t)); + Get(name, reinterpret_cast(&value), sizeof(int16_t)); out = static_cast(to_le16((u16)value)); } void IDeserializer::NumberU32_Unbounded(const char* name, uint32_t& out) { uint32_t value; - Get(name, (u8*)&value, sizeof(uint32_t)); + Get(name, reinterpret_cast(&value), sizeof(uint32_t)); out = to_le32(value); } void IDeserializer::NumberI32_Unbounded(const char* name, int32_t& out) { int32_t value; - Get(name, (u8*)&value, sizeof(int32_t)); + Get(name, reinterpret_cast(&value), sizeof(int32_t)); out = static_cast(to_le32((u32)value)); } void IDeserializer::NumberFloat_Unbounded(const char* name, float& out) { - Get(name, (u8*)&out, sizeof(float)); + Get(name, reinterpret_cast(&out), sizeof(float)); } void IDeserializer::NumberDouble_Unbounded(const char* name, double& out) { - Get(name, (u8*)&out, sizeof(double)); + Get(name, reinterpret_cast(&out), sizeof(double)); } void IDeserializer::NumberFixed_Unbounded(const char* name, fixed& out) @@ -168,7 +168,7 @@ void IDeserializer::StringASCII(const char* name, std::string& out, uint32_t min RequireBytesInStream(len); out.resize(len); - Get(name, (u8*)out.data(), len); + Get(name, reinterpret_cast(out.data()), len); for (size_t i = 0; i < out.length(); ++i) if (out[i] == 0 || (unsigned char)out[i] >= 128) @@ -183,7 +183,7 @@ void IDeserializer::String(const char* name, std::wstring& out, uint32_t minleng RequireBytesInStream(len); str.resize(len); - Get(name, (u8*)str.data(), len); + Get(name, reinterpret_cast(str.data()), len); Status err; out = wstring_from_utf8(str, &err); @@ -194,7 +194,7 @@ void IDeserializer::String(const char* name, std::wstring& out, uint32_t minleng throw PSERROR_Deserialize_OutOfBounds(name); } -void IDeserializer::RawBytes(const char* name, u8* data, size_t len) +void IDeserializer::RawBytes(const char* name, std::uint8_t* data, size_t len) { Get(name, data, len); } diff --git a/source/simulation2/serialization/IDeserializer.h b/source/simulation2/serialization/IDeserializer.h index ef6a7c47d8..475f4e6d40 100644 --- a/source/simulation2/serialization/IDeserializer.h +++ b/source/simulation2/serialization/IDeserializer.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 @@ #ifndef INCLUDED_IDESERIALIZER #define INCLUDED_IDESERIALIZER -#include "lib/types.h" #include "maths/Fixed.h" #include "ps/Errors.h" @@ -73,7 +72,7 @@ public: /// Deserialize a JSString virtual void ScriptString(const char* name, JS::MutableHandleString out) = 0; - virtual void RawBytes(const char* name, u8* data, size_t len); + virtual void RawBytes(const char* name, std::uint8_t* data, size_t len); // Features for simulation-state serialisation: virtual int GetVersion() const; @@ -97,7 +96,8 @@ public: virtual void RequireBytesInStream(size_t numBytes) = 0; protected: - virtual void Get(const char* name, u8* data, size_t len) = 0; + virtual void Get(const char* name, std::uint8_t* data, size_t len) = 0; }; #endif // INCLUDED_IDESERIALIZER + diff --git a/source/simulation2/serialization/ISerializer.cpp b/source/simulation2/serialization/ISerializer.cpp index 16d7c83a49..4aa1645635 100644 --- a/source/simulation2/serialization/ISerializer.cpp +++ b/source/simulation2/serialization/ISerializer.cpp @@ -101,7 +101,7 @@ void ISerializer::ScriptVal(const char* name, JS::MutableHandleValue value) PutScriptVal(name, value); } -void ISerializer::RawBytes(const char* name, const u8* data, size_t len) +void ISerializer::RawBytes(const char* name, const std::uint8_t* data, size_t len) { PutRaw(name, data, len); } diff --git a/source/simulation2/serialization/ISerializer.h b/source/simulation2/serialization/ISerializer.h index 234dc336f9..12c5d62b3e 100644 --- a/source/simulation2/serialization/ISerializer.h +++ b/source/simulation2/serialization/ISerializer.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 @@ #ifndef INCLUDED_ISERIALIZER #define INCLUDED_ISERIALIZER -#include "lib/types.h" #include "maths/Fixed.h" #include "ps/Errors.h" @@ -233,7 +232,7 @@ public: * It is the caller's responsibility to deal with portability (padding, endianness, etc); * the typed serialize methods should usually be used instead of this. */ - void RawBytes(const char* name, const u8* data, size_t len); + void RawBytes(const char* name, const std::uint8_t* data, size_t len); /** * Returns true if the serializer is being used in debug mode. @@ -264,7 +263,7 @@ protected: virtual void PutString(const char* name, const std::string& value) = 0; // We have to use a mutable handle because JS_Stringify requires that for unknown reasons. virtual void PutScriptVal(const char* name, JS::MutableHandleValue value) = 0; - virtual void PutRaw(const char* name, const u8* data, size_t len) = 0; + virtual void PutRaw(const char* name, const std::uint8_t* data, size_t len) = 0; }; #endif // INCLUDED_ISERIALIZER diff --git a/source/simulation2/serialization/SerializedTypes.h b/source/simulation2/serialization/SerializedTypes.h index 5634fb8fd0..aeda48ff9d 100644 --- a/source/simulation2/serialization/SerializedTypes.h +++ b/source/simulation2/serialization/SerializedTypes.h @@ -150,14 +150,14 @@ struct SerializeHelper> }; template<> -struct SerializeHelper +struct SerializeHelper { - void operator()(ISerializer& serialize, const char* name, u8 value) + void operator()(ISerializer& serialize, const char* name, std::uint8_t value) { serialize.NumberU8_Unbounded(name, value); } - void operator()(IDeserializer& deserialize, const char* name, u8& value) + void operator()(IDeserializer& deserialize, const char* name, std::uint8_t& value) { deserialize.NumberU8_Unbounded(name, value); } @@ -169,13 +169,13 @@ struct SerializeHelper>> { void operator()(ISerializer& serialize, const char* name, Enum value, Enum&& max) { - serialize.NumberU8(name, static_cast(value), 0, static_cast(max)); + serialize.NumberU8(name, static_cast(value), 0, static_cast(max)); } void operator()(IDeserializer& deserialize, const char* name, Enum& value, Enum&& max) { - u8 val; - deserialize.NumberU8(name, val, 0, static_cast(max)); + std::uint8_t val; + deserialize.NumberU8(name, val, 0, static_cast(max)); value = static_cast(val); } }; diff --git a/source/simulation2/serialization/StdDeserializer.cpp b/source/simulation2/serialization/StdDeserializer.cpp index b3d88b3d09..6b4620eb67 100644 --- a/source/simulation2/serialization/StdDeserializer.cpp +++ b/source/simulation2/serialization/StdDeserializer.cpp @@ -79,7 +79,7 @@ void CStdDeserializer::TraceMember(JSTracer *trc) JS::TraceEdge(trc, &backref, "StdDeserializer::m_ScriptBackrefs"); } -void CStdDeserializer::Get([[maybe_unused]] const char* name, u8* data, size_t len) +void CStdDeserializer::Get([[maybe_unused]] const char* name, std::uint8_t* data, size_t len) { #if DEBUG_SERIALIZER_ANNOTATE std::string strName; @@ -345,7 +345,7 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* /*name*/, JS::HandleObject } case SCRIPT_TYPE_TYPED_ARRAY: { - u8 arrayType; + std::uint8_t arrayType; u32 byteOffset, length; NumberU8_Unbounded("array type", arrayType); NumberU32_Unbounded("byte offset", byteOffset); @@ -412,7 +412,7 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* /*name*/, JS::HandleObject #endif void* bufferData = js_malloc(length); ENSURE(bufferData); - RawBytes("buffer data", (u8*)bufferData, length); + RawBytes("buffer data", reinterpret_cast(bufferData), length); mozilla::UniquePtr contents{ bufferData }; JS::RootedObject bufferObj(rq.cx, JS::NewArrayBufferWithContents(rq.cx, length, std::move(contents))); @@ -464,7 +464,7 @@ void CStdDeserializer::ReadStringLatin1(const char* name, std::vector(str.data()), len); } void CStdDeserializer::ReadStringUTF16(const char* name, std::u16string& str) @@ -473,7 +473,7 @@ void CStdDeserializer::ReadStringUTF16(const char* name, std::u16string& str) NumberU32_Unbounded("string length", len); RequireBytesInStream(len*2); str.resize(len); - Get(name, (u8*)str.data(), len*2); + Get(name, reinterpret_cast(str.data()), len*2); } void CStdDeserializer::ScriptString(const char* name, JS::MutableHandleString out) diff --git a/source/simulation2/serialization/StdDeserializer.h b/source/simulation2/serialization/StdDeserializer.h index 7e30492343..89cfcdbe25 100644 --- a/source/simulation2/serialization/StdDeserializer.h +++ b/source/simulation2/serialization/StdDeserializer.h @@ -19,7 +19,6 @@ #define INCLUDED_STDDESERIALIZER #include "lib/code_annotation.h" -#include "lib/types.h" #include "simulation2/system/Component.h" #include @@ -54,7 +53,7 @@ public: void TraceMember(JSTracer *trc); protected: - virtual void Get(const char* name, u8* data, size_t len); + virtual void Get(const char* name, std::uint8_t* data, size_t len); private: JS::Value ReadScriptVal(const char* name, JS::HandleObject preexistingObject); diff --git a/source/simulation2/serialization/StdSerializer.h b/source/simulation2/serialization/StdSerializer.h index 49780ae9a8..6150cd4276 100644 --- a/source/simulation2/serialization/StdSerializer.h +++ b/source/simulation2/serialization/StdSerializer.h @@ -19,7 +19,6 @@ #define INCLUDED_STDSERIALIZER #include "lib/code_annotation.h" -#include "lib/types.h" #include "simulation2/serialization/BinarySerializer.h" #include @@ -40,7 +39,7 @@ public: m_Stream.flush(); } - void Put([[maybe_unused]] const char* name, const u8* data, size_t len) + void Put([[maybe_unused]] const char* name, const std::uint8_t* data, size_t len) { #if DEBUG_SERIALIZER_ANNOTATE m_Stream.put('<'); diff --git a/source/simulation2/system/IComponent.h b/source/simulation2/system/IComponent.h index 71ead53651..3d7064945b 100644 --- a/source/simulation2/system/IComponent.h +++ b/source/simulation2/system/IComponent.h @@ -61,7 +61,7 @@ public: const CSimContext& GetSimContext() const { return *m_SimContext; } void SetSimContext(const CSimContext& context) { m_SimContext = &context; } - static u8 GetSerializationVersion() { return 0; } + static std::uint8_t GetSerializationVersion() { return 0; } virtual void Serialize(ISerializer& serialize) = 0; virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) = 0; diff --git a/source/simulation2/tests/test_SerializeTemplates.h b/source/simulation2/tests/test_SerializeTemplates.h index 88f2b274df..be2fe140ee 100644 --- a/source/simulation2/tests/test_SerializeTemplates.h +++ b/source/simulation2/tests/test_SerializeTemplates.h @@ -82,8 +82,8 @@ public: Grid value; value.resize(3,2); // Checkerboard pattern. - for (u8 j = 0; j < value.height(); ++j) - for (u8 i = 0; i < value.width(); ++i) + for (std::uint8_t j = 0; j < value.height(); ++j) + for (std::uint8_t i = 0; i < value.width(); ++i) value.set(i, j, ((i % 2) + (j % 2)) % 2); Serializer(serialize, "E", value); diff --git a/source/simulation2/tests/test_Serializer.h b/source/simulation2/tests/test_Serializer.h index 4f4a1eeb34..e9ebf6e54b 100644 --- a/source/simulation2/tests/test_Serializer.h +++ b/source/simulation2/tests/test_Serializer.h @@ -25,7 +25,6 @@ #include "lib/file/vfs/vfs.h" #include "lib/path.h" #include "lib/timer.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "ps/CLogger.h" #include "ps/Filesystem.h" @@ -89,7 +88,7 @@ public: wchar_t testw[] = { 't', 0xEA, 's', 't', 0 }; serialize.String("string 4", testw, 0, 255); - serialize.RawBytes("raw bytes", (const u8*)"\0\1\2\3\x0f\x10", 6); + serialize.RawBytes("raw bytes", reinterpret_cast("\0\1\2\3\x0f\x10"), 6); } void test_Debug_basic() @@ -213,7 +212,7 @@ public: bool bl; std::string str; std::wstring wstr; - u8 cbuf[256]; + std::uint8_t cbuf[256]; deserialize.NumberI8_Unbounded("i8", i8v); TS_ASSERT_EQUALS(i8v, -123); @@ -252,7 +251,7 @@ public: cbuf[6] = 0x42; // sentinel deserialize.RawBytes("raw bytes", cbuf, 6); - TS_ASSERT_SAME_DATA(cbuf, (const u8*)"\0\1\2\3\x0f\x10\x42", 7); + TS_ASSERT_SAME_DATA(cbuf, reinterpret_cast("\0\1\2\3\x0f\x10\x42"), 7); // NOTE: Don't use good() here - it fails due to a bug in older libc++ versions TS_ASSERT(!stream.bad() && !stream.fail()); @@ -933,7 +932,7 @@ public: debug_printf("# size = %d\n", (int)str.str().length()); debug_printf("# hash = "); for (const char byte : hash) - debug_printf("%02x", static_cast(static_cast(byte))); + debug_printf("%02x", static_cast(static_cast(byte))); debug_printf("\n"); } diff --git a/source/simulation2/tests/test_Simulation2.h b/source/simulation2/tests/test_Simulation2.h index d721e6425e..189ce3478c 100644 --- a/source/simulation2/tests/test_Simulation2.h +++ b/source/simulation2/tests/test_Simulation2.h @@ -39,7 +39,7 @@ class TestSimulation2 : public CxxTest::TestSuite { void copyFile(const VfsPath& src, const VfsPath& dst) { - std::unique_ptr data; + std::unique_ptr data; size_t size = 0; TS_ASSERT_OK(g_VFS->LoadFile(src, data, size)); TS_ASSERT_OK(g_VFS->CreateFile(dst, {data.get(), size})); diff --git a/source/soundmanager/data/OggData.cpp b/source/soundmanager/data/OggData.cpp index 4d960eaf39..590502a19b 100644 --- a/source/soundmanager/data/OggData.cpp +++ b/source/soundmanager/data/OggData.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 @@ -22,7 +22,6 @@ #if CONFIG2_AUDIO #include "lib/status.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "ps/Filesystem.h" #include "soundmanager/SoundManager.h" @@ -122,13 +121,13 @@ bool COggData::IsOneShot() int COggData::FetchDataIntoBuffer(int count, ALuint* buffers) { - std::vector PCMOut(OGG_DEFAULT_BUFFER_SIZE); + std::vector PCMOut(OGG_DEFAULT_BUFFER_SIZE); int buffersWritten{0}; for (int i{0}; i < count && !m_FileFinished; ++i) { std::fill(PCMOut.begin(), PCMOut.end(), 0); - const size_t totalRet{m_Stream->GetNextChunk(std::span(PCMOut))}; + const size_t totalRet{m_Stream->GetNextChunk(std::span(PCMOut))}; m_FileFinished = m_Stream->AtFileEOF(); if (totalRet == 0) continue; diff --git a/source/soundmanager/data/ogg.cpp b/source/soundmanager/data/ogg.cpp index 7f742ffd99..c57748f0ee 100644 --- a/source/soundmanager/data/ogg.cpp +++ b/source/soundmanager/data/ogg.cpp @@ -77,7 +77,7 @@ static Status LibErrorFromVorbis(int err) class VorbisBufferAdapter { public: - VorbisBufferAdapter(const std::shared_ptr& buffer, size_t size) + VorbisBufferAdapter(const std::shared_ptr& buffer, size_t size) : m_Buffer(buffer) , m_Size(size) { @@ -94,7 +94,7 @@ public: std::copy_n( adapter->m_Buffer.get() + adapter->m_Offset, sizeToRead, - static_cast(bufferToFill) + static_cast(bufferToFill) ); adapter->m_Offset += sizeToRead; @@ -138,7 +138,7 @@ public: } private: - std::shared_ptr m_Buffer; + std::shared_ptr m_Buffer; ogg_int64_t m_Size; ogg_int64_t m_Offset{0}; }; @@ -184,7 +184,7 @@ public: return INFO::OK; } - virtual size_t GetNextChunk(std::span buffer) + virtual size_t GetNextChunk(std::span buffer) { // We may have to call ov_read multiple times because it // treats the buffer size "as a limit and not a request". @@ -258,7 +258,7 @@ private: Status OpenOggNonstream(const PIVFS& vfs, const VfsPath& pathname, OggStreamPtr& stream) { - std::shared_ptr contents; + std::shared_ptr contents; size_t size; RETURN_STATUS_IF_ERR(vfs->LoadFile(pathname, contents, size)); diff --git a/source/soundmanager/data/ogg.h b/source/soundmanager/data/ogg.h index 83b41ac6cf..4ac9cf5e67 100644 --- a/source/soundmanager/data/ogg.h +++ b/source/soundmanager/data/ogg.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 @@ -24,7 +24,6 @@ #include "lib/file/vfs/vfs.h" #include "lib/file/vfs/vfs_path.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -40,7 +39,7 @@ public: virtual bool AtFileEOF() = 0; virtual Status ResetFile() = 0; - virtual size_t GetNextChunk(std::span buffer) = 0; + virtual size_t GetNextChunk(std::span buffer) = 0; }; using OggStreamPtr = std::shared_ptr; diff --git a/source/soundmanager/scripting/SoundGroup.h b/source/soundmanager/scripting/SoundGroup.h index ff8be23c26..332f86d374 100644 --- a/source/soundmanager/scripting/SoundGroup.h +++ b/source/soundmanager/scripting/SoundGroup.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 @@ -113,7 +113,7 @@ private: float m_PitchUpper; float m_Priority; // Up to eight individual parameters, use with eSndGrpFlags. - u8 m_Flags; + std::uint8_t m_Flags; }; #endif //#ifndef INCLUDED_SOUNDGROUP_H diff --git a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp index 2ca2b6241a..0130f3e75d 100644 --- a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp @@ -89,7 +89,7 @@ sEnvironmentSettings GetSettings() // RGBColor (CVector3D) colors #define COLOR(A, B) A = Color((int)(B.X*255), (int)(B.Y*255), (int)(B.Z*255)) s.sunoverbrightness = MaxComponent(g_LightEnv.m_SunColor); - // clamp color to [0..1] before packing into u8 triplet + // clamp color to [0..1] before packing into std::uint8_t triplet if(s.sunoverbrightness > 1.0f) g_LightEnv.m_SunColor *= 1.0/s.sunoverbrightness; // (there's no operator/=) // no component was above 1.0, so reset scale factor (don't want to darken) diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index f05e2b905d..7f06e42264 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -319,7 +319,7 @@ QUERYHANDLER(RasterizeMinimap) const ssize_t bpp = 24; const ssize_t imageDataSize = dimension * dimension * (bpp / 8); - std::vector imageBytes(imageDataSize); + std::vector imageBytes(imageDataSize); float shallowPassageHeight = CMiniMapTexture::GetShallowPassageHeight(); @@ -368,9 +368,12 @@ QUERYHANDLER(RasterizeMinimap) } // Convert - imageBytes[position++] = static_cast(static_cast(color & 0xff) * scale); - imageBytes[position++] = static_cast(static_cast((color >> 8) & 0xff) * scale); - imageBytes[position++] = static_cast(static_cast((color >> 16) & 0xff) * scale); + imageBytes[position++] = static_cast(static_cast( + color & 0xff) * scale); + imageBytes[position++] = static_cast(static_cast( + (color >> 8) & 0xff) * scale); + imageBytes[position++] = static_cast(static_cast( + (color >> 16) & 0xff) * scale); } } } diff --git a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp index 6d884db7b9..6879c1edd6 100644 --- a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp @@ -89,7 +89,7 @@ sTerrainTexturePreview GetPreview(CTerrainTextureEntry* tex, size_t width, size_ preview.name = tex->GetTag().FromUTF8(); const size_t previewBPP = 3; - std::vector buffer(width * height * previewBPP); + std::vector buffer(width * height * previewBPP); // It's not good to shrink the entire texture to fit the small preview // window, since it's the fine details in the texture that are @@ -107,7 +107,7 @@ sTerrainTexturePreview GetPreview(CTerrainTextureEntry* tex, size_t width, size_ texturePath = tex->GetDiffuseTexturePath(); } - std::shared_ptr fileData; + std::shared_ptr fileData; size_t fileSize; Tex texture; const bool canUsePreview = @@ -126,7 +126,7 @@ sTerrainTexturePreview GetPreview(CTerrainTextureEntry* tex, size_t width, size_ ++level; // Extract the middle section (as a representative preview), // and copy into buffer. - u8* data = texture.GetMIPLevels()[level].data; + std::uint8_t* data = texture.GetMIPLevels()[level].data; ENSURE(data); const size_t levelWidth = texture.m_Width >> level; const size_t levelHeight = texture.m_Height >> level; diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 624a817424..bb4c840cc3 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -500,7 +500,7 @@ struct sEnvironmentSettings // emulate 'HDR' by allowing overly bright suncolor. this is // multiplied on to suncolor after converting to float - // (struct Color stores as normal u8, 0..255) + // (struct Color stores as normal std::uint8_t, 0..255) Shareable sunoverbrightness; // range 1..3 // support different lighting models ("old" for the version compatible with old scenarios,