diff --git a/source/graphics/ColladaManager.cpp b/source/graphics/ColladaManager.cpp index d7c8ad4a5b..98a6503e9a 100644 --- a/source/graphics/ColladaManager.cpp +++ b/source/graphics/ColladaManager.cpp @@ -265,7 +265,7 @@ public: * @param[out] version version passed to CCacheLoader, used if code change should force * cache invalidation */ - void PrepareCacheKey(MD5& hash, u32& version) + void PrepareCacheKey(MD5& hash, std::uint32_t& version) { // Add converter version to the hash version = COLLADA_CONVERTER_VERSION; @@ -380,7 +380,7 @@ VfsPath CColladaManager::GetLoadablePath(const VfsPath& pathnameNoExtension, Fil // Now we're looking for cached files CCacheLoader cacheLoader(m_VFS, extn); MD5 hash; - u32 version; + std::uint32_t version; m->PrepareCacheKey(hash, version); VfsPath cachePath; diff --git a/source/graphics/MapGenerator.cpp b/source/graphics/MapGenerator.cpp index 718a832fe6..eb5ad41f54 100644 --- a/source/graphics/MapGenerator.cpp +++ b/source/graphics/MapGenerator.cpp @@ -374,7 +374,7 @@ Script::StructuredClone RunMapGenerationScript(const StopToken stopToken, std::a } // Init RNG seed - u32 seed = 0; + std::uint32_t seed = 0; if (!Script::HasProperty(rq, settingsVal, "Seed") || !Script::GetProperty(rq, settingsVal, "Seed", seed)) LOGWARNING("RunMapGenerationScript: No seed value specified - using 0"); diff --git a/source/graphics/MapIO.h b/source/graphics/MapIO.h index bfe071586f..4e125c36df 100644 --- a/source/graphics/MapIO.h +++ b/source/graphics/MapIO.h @@ -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 @@ -45,7 +44,7 @@ public: std::uint16_t m_Tex1Index; // Index into the texture array of second texture; (0xFFFF) if none. std::uint16_t m_Tex2Index; - u32 m_Priority; + std::uint32_t m_Priority; }; #pragma pack(pop) }; diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 7168ae2e0a..0defc459e9 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -1154,7 +1154,7 @@ void CXMLReader::ReadEntities(XMBElement entity, CSimulation2& sim) if (cmpVisual) { if (Seed != -1) - cmpVisual->SetActorSeed((u32)Seed); + cmpVisual->SetActorSeed(static_cast(Seed)); // TODO: variation/selection strings } @@ -1382,7 +1382,7 @@ int CMapReader::ParseTerrain() "Error parsing terrain data.\nCheck application log for details"); }; - u32 size; + std::uint32_t size; getTerrainProperty(m_MapData, "size", size); m_PatchesPerSide = size / PATCH_SIZE; diff --git a/source/graphics/MapReader.h b/source/graphics/MapReader.h index a261f160fb..3518470a5d 100644 --- a/source/graphics/MapReader.h +++ b/source/graphics/MapReader.h @@ -23,7 +23,6 @@ #include "graphics/LightEnv.h" #include "lib/file/vfs/vfs_path.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Vector3D.h" #include "ps/CStr.h" #include "ps/Errors.h" @@ -148,7 +147,7 @@ private: bool m_SkipEntities; VfsPath m_FilenameXml; bool only_xml; - u32 file_format_version; + std::uint32_t file_format_version; entity_id_t m_StartingCameraTarget; CVector3D m_StartingCamera; diff --git a/source/graphics/MiniMapTexture.cpp b/source/graphics/MiniMapTexture.cpp index 43bd3448dc..29b6bc0d87 100644 --- a/source/graphics/MiniMapTexture.cpp +++ b/source/graphics/MiniMapTexture.cpp @@ -409,7 +409,7 @@ void CMiniMapTexture::CreateTextures( // Initialise texture with solid black, for the areas we don't // overwrite with uploading later. - std::unique_ptr texData = std::make_unique(textureSize * textureSize); + std::unique_ptr texData = std::make_unique(textureSize * textureSize); for (size_t i = 0; i < textureSize * textureSize; ++i) texData[i] = 0xFF000000; deviceCommandContext->UploadTexture( @@ -417,7 +417,7 @@ void CMiniMapTexture::CreateTextures( texData.get(), textureSize * textureSize * 4); texData.reset(); - m_TerrainData = std::make_unique((m_MapSize - 1) * (m_MapSize - 1)); + m_TerrainData = std::make_unique((m_MapSize - 1) * (m_MapSize - 1)); m_FinalTexture = g_Renderer.GetTextureManager().WrapBackendTexture( backendDevice->CreateTexture2D("MiniMapFinalTexture", @@ -447,18 +447,18 @@ void CMiniMapTexture::RebuildTerrainTexture( Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain& terrain) { - const u32 x = 0; - const u32 y = 0; - const u32 width = m_MapSize - 1; - const u32 height = m_MapSize - 1; + const std::uint32_t x = 0; + const std::uint32_t y = 0; + const std::uint32_t width = m_MapSize - 1; + const std::uint32_t height = m_MapSize - 1; m_WaterHeight = g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight; m_TerrainTextureDirty = false; - for (u32 j = 0; j < height; ++j) + for (std::uint32_t j = 0; j < height; ++j) { - u32* dataPtr = m_TerrainData.get() + ((y + j) * width) + x; - for (u32 i = 0; i < width; ++i) + std::uint32_t* dataPtr = m_TerrainData.get() + ((y + j) * width) + x; + for (std::uint32_t i = 0; i < width; ++i) { const float avgHeight = ( terrain.GetVertexGroundLevel(static_cast(i), static_cast(j)) @@ -483,7 +483,7 @@ void CMiniMapTexture::RebuildTerrainTexture( static_cast(terrain.GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8; int val = (hmap / 3) + 170; - u32 color = 0xFFFFFFFF; + std::uint32_t color = 0xFFFFFFFF; CMiniPatch* const mp = terrain.GetTile(x + i, y + j); if (mp) @@ -732,7 +732,7 @@ void CMiniMapTexture::UpdateAndUploadEntities( // row. struct Cell { - u32 count; + std::uint32_t count; float maxHalfSize; CVector2D averagePosition; }; diff --git a/source/graphics/MiniMapTexture.h b/source/graphics/MiniMapTexture.h index 70c6518860..c808a1051d 100644 --- a/source/graphics/MiniMapTexture.h +++ b/source/graphics/MiniMapTexture.h @@ -23,7 +23,6 @@ #include "graphics/Texture.h" #include "lib/code_annotation.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Vector2D.h" #include "renderer/VertexArray.h" @@ -119,7 +118,7 @@ private: m_FinalTextureFramebuffer; // texture data - std::unique_ptr m_TerrainData; + std::unique_ptr m_TerrainData; // map size ssize_t m_MapSize = 0; diff --git a/source/graphics/ModelDef.cpp b/source/graphics/ModelDef.cpp index e767047f33..074453ed42 100644 --- a/source/graphics/ModelDef.cpp +++ b/source/graphics/ModelDef.cpp @@ -38,9 +38,9 @@ void CModelDef::GetMaxBounds(CSkeletonAnimDef* anim, bool loop, CBoundingBoxAligned& result) { - const u32 animIndex = anim ? anim->m_UID : 0; + const std::uint32_t animIndex = anim ? anim->m_UID : 0; - std::unordered_map::const_iterator it = m_MaxBoundsPerAnimDef.find(animIndex); + std::unordered_map::const_iterator it = m_MaxBoundsPerAnimDef.find(animIndex); if (it != m_MaxBoundsPerAnimDef.end()) { result = it->second; diff --git a/source/graphics/ModelDef.h b/source/graphics/ModelDef.h index ef52e7b140..36dc83576b 100644 --- a/source/graphics/ModelDef.h +++ b/source/graphics/ModelDef.h @@ -24,7 +24,6 @@ #include "lib/code_annotation.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "maths/BoundingBoxAligned.h" #include "maths/Matrix3D.h" #include "maths/Quaternion.h" @@ -280,7 +279,7 @@ private: VfsPath m_Name; // filename // Maximal bounding box of this mesh for a given animation. - std::unordered_map m_MaxBoundsPerAnimDef; + std::unordered_map m_MaxBoundsPerAnimDef; // renderdata shared by models of the same modeldef, // by render path diff --git a/source/graphics/RenderableObject.h b/source/graphics/RenderableObject.h index 064cf8c63a..33852f8e37 100644 --- a/source/graphics/RenderableObject.h +++ b/source/graphics/RenderableObject.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 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 @@ #define INCLUDED_RENDERABLEOBJECT #include "lib/code_annotation.h" -#include "lib/types.h" #include "maths/BoundingBoxAligned.h" #include "maths/Matrix3D.h" @@ -84,7 +83,7 @@ public: // mark some part of the renderdata as dirty, and requiring // an update on next render - void SetDirty(u32 dirtyflags) + void SetDirty(std::uint32_t dirtyflags) { if (m_RenderData) m_RenderData->m_UpdateFlags |= dirtyflags; diff --git a/source/graphics/SkeletonAnimDef.cpp b/source/graphics/SkeletonAnimDef.cpp index fdc195b8a8..5e544127f8 100644 --- a/source/graphics/SkeletonAnimDef.cpp +++ b/source/graphics/SkeletonAnimDef.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ namespace { // Start IDs at 1 to leave 0 as a special value. -u32 g_NextSkeletonDefUID = 1; +std::uint32_t g_NextSkeletonDefUID = 1; } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/graphics/SkeletonAnimDef.h b/source/graphics/SkeletonAnimDef.h index 7178321970..ef48b239db 100644 --- a/source/graphics/SkeletonAnimDef.h +++ b/source/graphics/SkeletonAnimDef.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 @@ #define INCLUDED_SKELETONANIMDEF #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "maths/Quaternion.h" #include "maths/Vector3D.h" @@ -98,8 +97,8 @@ public: // animation data - m_NumKeys*m_NumFrames total keys std::vector m_Keys; // Unique identifier - used by CModelDef to cache bounds per-animDef. - // (hopefully we won't run into the u32 limit too soon). - u32 m_UID; + // (hopefully we won't run into the std::uint32_t limit too soon). + std::uint32_t m_UID; }; #endif diff --git a/source/graphics/TerrainProperties.cpp b/source/graphics/TerrainProperties.cpp index 5453871a74..7ee58ca2ba 100644 --- a/source/graphics/TerrainProperties.cpp +++ b/source/graphics/TerrainProperties.cpp @@ -151,7 +151,7 @@ bool CTerrainProperties::HasBaseColor() return m_HasBaseColor || (m_pParent && m_pParent->HasBaseColor()); } -u32 CTerrainProperties::GetBaseColor() +std::uint32_t CTerrainProperties::GetBaseColor() { if (m_HasBaseColor || !m_pParent) return m_BaseColor; diff --git a/source/graphics/TerrainProperties.h b/source/graphics/TerrainProperties.h index 7f7d5f9ed6..f9ece1b83e 100644 --- a/source/graphics/TerrainProperties.h +++ b/source/graphics/TerrainProperties.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 @@ -28,7 +28,6 @@ #define INCLUDED_TERRAINPROPERTIES #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include #include @@ -53,7 +52,7 @@ private: // ..Valid is true if the base color is specified in this terrain XML // No caching here, since ideally, a saved XML file of an object should // produce be equivalent to the source file - u32 m_BaseColor; + std::uint32_t m_BaseColor; bool m_HasBaseColor; // Orientation of texture (in radians) (default pi/4 = 45 degrees) @@ -90,7 +89,7 @@ public: // its parents. If no minimap color is specified, return garbage. // Use HasBaseColor() to see if the value is valid. // The color value is in BGRA format - u32 GetBaseColor(); + std::uint32_t GetBaseColor(); float GetTextureAngle() { diff --git a/source/graphics/TerrainTextureEntry.h b/source/graphics/TerrainTextureEntry.h index 1086c36cf2..370bfdaf15 100644 --- a/source/graphics/TerrainTextureEntry.h +++ b/source/graphics/TerrainTextureEntry.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/TerrainTextureManager.h" #include "graphics/Texture.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "ps/CStr.h" @@ -74,7 +73,7 @@ public: const VfsPath& GetDiffuseTexturePath() const { return m_DiffuseTexturePath; } // Get mipmap color in BGRA format - u32 GetBaseColor() + std::uint32_t GetBaseColor() { if (!m_BaseColorValid) BuildBaseColor(); return m_BaseColor; @@ -98,7 +97,7 @@ private: // BGRA color of topmost mipmap level, for coloring minimap, or a color // specified by the terrain properties - u32 m_BaseColor; + std::uint32_t m_BaseColor; // ..Valid is true if the base color has been cached bool m_BaseColorValid; diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index a233fd24dc..d54462c2c0 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -601,7 +601,7 @@ public: /** * Set up some parameters for the loose cache filename code. */ - void PrepareCacheKey(const CTexturePtr& texture, MD5& hash, u32& version) + void PrepareCacheKey(const CTexturePtr& texture, MD5& hash, std::uint32_t& version) { // Hash the settings, so we won't use an old loose cache file if the // settings have changed @@ -621,7 +621,7 @@ public: bool TryLoadingCached(const CTexturePtr& texture) { MD5 hash; - u32 version; + std::uint32_t version; PrepareCacheKey(texture, hash, version); VfsPath loadPath; @@ -663,7 +663,7 @@ public: PROFILE2_ATTR("name: %ls", sourcePath.string().c_str()); MD5 hash; - u32 version; + std::uint32_t version; PrepareCacheKey(texture, hash, version); const VfsPath looseCachePath = m_CacheLoader.LooseCachePath(sourcePath, hash, version); @@ -1036,7 +1036,7 @@ bool CTexture::HasAlpha() const format == Renderer::Backend::Format::BC3_UNORM; } -u32 CTexture::GetBaseColor() const +std::uint32_t CTexture::GetBaseColor() const { return m_BaseColor; } diff --git a/source/graphics/TextureManager.h b/source/graphics/TextureManager.h index 4320a00030..3361febdd8 100644 --- a/source/graphics/TextureManager.h +++ b/source/graphics/TextureManager.h @@ -22,7 +22,6 @@ #include "lib/code_annotation.h" #include "lib/file/vfs/vfs.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "renderer/backend/Format.h" #include "renderer/backend/Sampler.h" @@ -294,7 +293,7 @@ public: * average of the whole texture). * Returns 0 if the texture has no mipmaps. */ - u32 GetBaseColor() const; + std::uint32_t GetBaseColor() const; /** * Returns total number of bytes uploaded for this texture. @@ -364,7 +363,7 @@ private: std::unique_ptr m_BackendTexture; // It's possible to m_FallbackBackendTexture references m_BackendTexture. Renderer::Backend::ITexture* m_FallbackBackendTexture = nullptr; - u32 m_BaseColor; + std::uint32_t m_BaseColor; std::unique_ptr m_TextureData; size_t m_UploadedSize = 0; uint32_t m_BaseLevelOffset = 0; diff --git a/source/graphics/tests/test_Color.h b/source/graphics/tests/test_Color.h index e37ecd5427..7a335c9137 100644 --- a/source/graphics/tests/test_Color.h +++ b/source/graphics/tests/test_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 @@ #include "graphics/Color.h" #include "graphics/SColor.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -98,11 +97,11 @@ public: } private: - void CheckColor(int r, int g, int b, u32 expected) + void CheckColor(int r, int g, int b, std::uint32_t expected) { SColor4ub colorStruct = ConvertRGBColorTo4ub(RGBColor(r,g,b)); - u32 actual; - memcpy(&actual, &colorStruct, sizeof(u32)); + std::uint32_t actual; + memcpy(&actual, &colorStruct, sizeof(std::uint32_t)); expected |= 0xff000000; // ConvertRGBColorTo4ub sets alpha to opaque TS_ASSERT_EQUALS(expected, actual); } diff --git a/source/graphics/tests/test_LOSTexture.h b/source/graphics/tests/test_LOSTexture.h index a882e757f2..6902f6ec62 100644 --- a/source/graphics/tests/test_LOSTexture.h +++ b/source/graphics/tests/test_LOSTexture.h @@ -21,7 +21,6 @@ #include "lib/posix/posix_types.h" #include "lib/timer.h" -#include "lib/types.h" #include "scriptinterface/Interface.h" #include "simulation2/Simulation2.h" #include "simulation2/helpers/Grid.h" @@ -40,7 +39,7 @@ public: CLOSTexture tex(sim); const ssize_t size = 8; - u32 inputData[size*size] = { + std::uint32_t inputData[size*size] = { 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, @@ -50,7 +49,7 @@ public: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }; - Grid inputDataVec(size, size); + Grid inputDataVec(size, size); for (std::uint8_t i = 0; i < size; ++i) for (std::uint8_t j = 0; j < size; ++j) @@ -59,7 +58,7 @@ public: // LosState::MASK should be cmpRanageManager->GetSharedLosMask(1), // but that would mean adding a huge mock component for this and it // should always be LosState::MASK for player 1 (as the other players are bit-shifted). - CLosQuerier los((u32)LosState::MASK, inputDataVec, size); + CLosQuerier los(static_cast(LosState::MASK), inputDataVec, size); std::vector losData; size_t pitch; @@ -79,12 +78,12 @@ public: CLOSTexture tex(sim); const ssize_t size = 257; - Grid inputDataVec(size, size); + Grid inputDataVec(size, size); // LosState::MASK should be cmpRanageManager->GetSharedLosMask(1), // but that would mean adding a huge mock component for this and it // should always be LosState::MASK for player 1 (as the other players are bit-shifted). - CLosQuerier los((u32)LosState::MASK, inputDataVec, size); + CLosQuerier los(static_cast(LosState::MASK), inputDataVec, size); size_t reps = 128; double t = timer_Time(); diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index deb345edfb..29d998dd19 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -70,7 +70,7 @@ #include const double SELECT_DBLCLICK_RATE = 0.5; -const u32 MAX_OBJECT_DEPTH = 100; // Max number of nesting for GUI includes. Used to detect recursive inclusion +const std::uint32_t MAX_OBJECT_DEPTH = 100; // Max number of nesting for GUI includes. Used to detect recursive inclusion const CStr CGUI::EventNameLoad = "Load"; const CStr CGUI::EventNameTick = "Tick"; @@ -661,7 +661,7 @@ void CGUI::Xeromyces_ReadRootSetup(const XMBData& xmb, XMBElement element) void CGUI::Xeromyces_ReadObject(const XMBData& xmb, XMBElement element, IGUIObject& parent, std::vector >& NameSubst, std::unordered_set& Paths, - u32 nesting_depth) + std::uint32_t nesting_depth) { XMBAttributeList attributes = element.GetAttributes(); @@ -960,7 +960,8 @@ void CGUI::Xeromyces_ReadObject(const XMBData& xmb, XMBElement element, IGUIObje } void CGUI::Xeromyces_ReadRepeat(const XMBData& xmb, XMBElement element, IGUIObject& parent, - std::vector>& NameSubst, std::unordered_set& Paths, u32 nesting_depth) + std::vector>& NameSubst, std::unordered_set& Paths, + std::uint32_t nesting_depth) { #define ELMT(x) int elmt_##x = xmb.GetElementID(#x) #define ATTR(x) int attr_##x = xmb.GetAttributeID(#x) diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index 3de215602b..1930dca1d2 100644 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -31,7 +31,6 @@ #include "gui/SettingTypes/CGUIColor.h" #include "lib/code_annotation.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "maths/Rect.h" #include "maths/Vector2D.h" #include "ps/CStr.h" @@ -471,7 +470,7 @@ private: */ void Xeromyces_ReadObject(const XMBData& xmb, XMBElement element, IGUIObject& parent, std::vector >& NameSubst, std::unordered_set& Paths, - u32 nesting_depth); + std::uint32_t nesting_depth); /** * Reads in the element \, which repeats its child \s @@ -481,7 +480,7 @@ private: */ void Xeromyces_ReadRepeat(const XMBData& xmb, XMBElement element, IGUIObject& parent, std::vector >& NameSubst, std::unordered_set& Paths, - u32 nesting_depth); + std::uint32_t nesting_depth); /** * Reads in the element \ (the XMBElement) and executes diff --git a/source/gui/CGUISetting.cpp b/source/gui/CGUISetting.cpp index 7a7c5659bc..c9ddbbc40d 100644 --- a/source/gui/CGUISetting.cpp +++ b/source/gui/CGUISetting.cpp @@ -26,7 +26,6 @@ #include "gui/SettingTypes/CGUIList.h" #include "gui/SettingTypes/CGUISeries.h" #include "gui/SettingTypes/CGUIString.h" -#include "lib/types.h" #include "maths/Vector2D.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -120,7 +119,7 @@ void CGUISimpleSetting::ToJSVal(const Script::Request& rq, JS::MutableHandleV TYPE(bool) TYPE(std::int32_t) -TYPE(u32) +TYPE(std::uint32_t) TYPE(float) TYPE(CVector2D) TYPE(CStr) diff --git a/source/gui/GUIObjectEventBroadcaster.h b/source/gui/GUIObjectEventBroadcaster.h index 34151c58e6..0b66e8e14b 100644 --- a/source/gui/GUIObjectEventBroadcaster.h +++ b/source/gui/GUIObjectEventBroadcaster.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/alignment.h" #include "lib/allocators/DynamicArena.h" #include "lib/allocators/STLAllocators.h" -#include "lib/types.h" #include #include @@ -36,7 +35,7 @@ namespace { IGUIObject* object; // Index of the object in a depth-first search inside GUI tree. - u32 index; + std::uint32_t index; // Cached value of GetBufferedZ to avoid recursive calls in a deep hierarchy. float bufferedZ; }; @@ -47,7 +46,8 @@ namespace for (IGUIObject* const& object : objects) if (!object->IsHidden()) { - visibleObjects->emplace_back(VisibleObject{ object, static_cast(visibleObjects->size()), 0.0f }); + visibleObjects->emplace_back(VisibleObject{ object, + static_cast(visibleObjects->size()), 0.0f }); CollectVisibleObjectsRecursively(object->GetVisibleChildren(), visibleObjects); } } diff --git a/source/gui/GUIStringConversions.cpp b/source/gui/GUIStringConversions.cpp index 47ad96c3cf..cfdd4440da 100644 --- a/source/gui/GUIStringConversions.cpp +++ b/source/gui/GUIStringConversions.cpp @@ -24,7 +24,6 @@ #include "gui/SettingTypes/CGUIString.h" #include "gui/SettingTypes/EAlign.h" #include "gui/SettingTypes/EScrollOrientation.h" -#include "lib/types.h" #include "maths/Rect.h" #include "maths/Size2D.h" #include "maths/Vector2D.h" @@ -58,7 +57,7 @@ bool CGUI::ParseString(const CGUI*, const CStrW& Value, int& Outpu } template <> -bool CGUI::ParseString(const CGUI*, const CStrW& Value, u32& Output) +bool CGUI::ParseString(const CGUI*, const CStrW& Value, std::uint32_t& Output) { Output = Value.ToUInt(); return true; diff --git a/source/gui/ObjectTypes/CDropDown.h b/source/gui/ObjectTypes/CDropDown.h index 0583463865..cbdc90e809 100644 --- a/source/gui/ObjectTypes/CDropDown.h +++ b/source/gui/ObjectTypes/CDropDown.h @@ -33,7 +33,6 @@ GUI Object - Drop Down (list) #include "gui/ObjectBases/IGUIObject.h" #include "gui/ObjectTypes/CList.h" #include "gui/SettingTypes/CGUIColor.h" -#include "lib/types.h" #include "maths/Rect.h" #include "maths/Vector2D.h" #include "ps/CStr.h" @@ -141,7 +140,7 @@ protected: CGUISimpleSetting m_ButtonWidth; CGUISimpleSetting m_DropDownSize; CGUISimpleSetting m_DropDownBuffer; - CGUISimpleSetting m_MinimumVisibleItems; + CGUISimpleSetting m_MinimumVisibleItems; CGUISimpleSetting m_SoundClosed; CGUISimpleSetting m_SoundEnter; CGUISimpleSetting m_SoundLeave; diff --git a/source/gui/ObjectTypes/CMiniMap.cpp b/source/gui/ObjectTypes/CMiniMap.cpp index 48373e6139..90546fbdcf 100644 --- a/source/gui/ObjectTypes/CMiniMap.cpp +++ b/source/gui/ObjectTypes/CMiniMap.cpp @@ -197,7 +197,7 @@ void CMiniMap::RecreateFlareTextures() const CStr textureNumberingFormat = "art/textures/animated/minimap-flare/frame%02u.png"; m_FlareTextures.clear(); m_FlareTextures.reserve(m_FlareTextureCount); - for (u32 i = 0; i < m_FlareTextureCount; ++i) + for (std::uint32_t i = 0; i < m_FlareTextureCount; ++i) { CTextureProperties textureProps(fmt::sprintf(textureNumberingFormat, i).c_str()); textureProps.SetIgnoreQuality(true); @@ -327,7 +327,7 @@ void CMiniMap::DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double curren const double deltaTime = currentTime - flare.time; const double remainingTime = m_FlareLifetimeSeconds - deltaTime; - const u32 flooredStep = floor(deltaTime * m_FlareAnimationSpeed); + const std::uint32_t flooredStep = floor(deltaTime * m_FlareAnimationSpeed); const float startFadeAlpha = m_FlareStartFadeSeconds > 0.0f ? deltaTime / m_FlareStartFadeSeconds : 1.0f; const float stopFadeAlpha = m_FlareStopFadeSeconds > 0.0f ? remainingTime / m_FlareStopFadeSeconds : 1.0f; @@ -345,7 +345,7 @@ void CMiniMap::DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double curren } } -void CMiniMap::DrawFlareFrame(CCanvas2D& canvas, const u32 frameIndex, +void CMiniMap::DrawFlareFrame(CCanvas2D& canvas, const std::uint32_t frameIndex, const CRect& destination, const CColor& color, float alpha) const { // TODO: Only draw inside the minimap circle. diff --git a/source/gui/ObjectTypes/CMiniMap.h b/source/gui/ObjectTypes/CMiniMap.h index 2805cbe0c6..67c1cb23e7 100644 --- a/source/gui/ObjectTypes/CMiniMap.h +++ b/source/gui/ObjectTypes/CMiniMap.h @@ -23,7 +23,6 @@ #include "gui/CGUISetting.h" #include "gui/ObjectBases/IGUIObject.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Vector2D.h" #include "ps/CStr.h" @@ -82,8 +81,8 @@ private: std::vector m_FlareTextures; - CGUISimpleSetting m_FlareTextureCount; - CGUISimpleSetting m_FlareRenderSize; + CGUISimpleSetting m_FlareTextureCount; + CGUISimpleSetting m_FlareRenderSize; CGUISimpleSetting m_FlareInterleave; CGUISimpleSetting m_FlareAnimationSpeed; CGUISimpleSetting m_FlareLifetimeSeconds; @@ -104,7 +103,8 @@ private: void DrawViewRect(CCanvas2D& canvas) const; void DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double currentTime) const; - void DrawFlareFrame(CCanvas2D& canvas, const u32 frameIndex, const CRect& destination, const CColor& color, float alpha) const; + void DrawFlareFrame(CCanvas2D& canvas, const std::uint32_t frameIndex, const CRect& destination, + const CColor& color, float alpha) const; void GetMouseWorldCoordinates(float& x, float& z) const; diff --git a/source/gui/SettingTypes/CGUIString.cpp b/source/gui/SettingTypes/CGUIString.cpp index ff96fb58e5..a0080e2237 100644 --- a/source/gui/SettingTypes/CGUIString.cpp +++ b/source/gui/SettingTypes/CGUIString.cpp @@ -25,7 +25,6 @@ #include "gui/ObjectBases/IGUIObject.h" #include "gui/SGUIIcon.h" #include "lib/debug.h" -#include "lib/types.h" #include "lib/utf8.h" #include "maths/Rect.h" #include "ps/CLogger.h" @@ -473,7 +472,7 @@ void CGUIString::SetValue(const CStrW& str) m_Words.push_back(0); // Add word boundaries in increasing order - for (u32 i = 0; i < m_RawString.length(); ++i) + for (std::uint32_t i = 0; i < m_RawString.length(); ++i) { wchar_t c = m_RawString[i]; if (c == '\n') diff --git a/source/lib/byte_order.cpp b/source/lib/byte_order.cpp index c004140ecd..93c6e3754f 100644 --- a/source/lib/byte_order.cpp +++ b/source/lib/byte_order.cpp @@ -41,7 +41,7 @@ std::uint16_t swap16(const std::uint16_t x) #endif #ifndef swap32 -u32 swap32(const u32 x) +std::uint32_t swap32(const std::uint32_t x) { return (x << 24) | (x >> 24) | @@ -53,11 +53,11 @@ u32 swap32(const u32 x) #ifndef swap64 u64 swap64(const u64 x) { - const u32 lo = (u32)(x & 0xFFFFFFFF); - const u32 hi = (u32)(x >> 32); + const std::uint32_t lo = static_cast(x & 0xFFFFFFFF); + const std::uint32_t hi = static_cast(x >> 32); u64 ret = swap32(lo); ret <<= 32; - // careful: must shift var of type u64, not u32 + // careful: must shift var of type u64, not std::uint32_t ret |= swap32(hi); return ret; } @@ -74,9 +74,9 @@ std::uint16_t read_le16(const void* p) return to_le16(n); } -u32 read_le32(const void* p) +std::uint32_t read_le32(const void* p) { - u32 n; + std::uint32_t n; memcpy(&n, p, sizeof(n)); return to_le32(n); } @@ -96,9 +96,9 @@ std::uint16_t read_be16(const void* p) return to_be16(n); } -u32 read_be32(const void* p) +std::uint32_t read_be32(const void* p) { - u32 n; + std::uint32_t n; memcpy(&n, p, sizeof(n)); return to_be32(n); } @@ -117,9 +117,9 @@ void write_le16(void* p, std::uint16_t x) memcpy(p, &n, sizeof(n)); } -void write_le32(void* p, u32 x) +void write_le32(void* p, std::uint32_t x) { - u32 n = to_le32(x); + std::uint32_t n = to_le32(x); memcpy(p, &n, sizeof(n)); } @@ -136,9 +136,9 @@ void write_be16(void* p, std::uint16_t x) memcpy(p, &n, sizeof(n)); } -void write_be32(void* p, u32 x) +void write_be32(void* p, std::uint32_t x) { - u32 n = to_be32(x); + std::uint32_t n = to_be32(x); memcpy(p, &n, sizeof(n)); } diff --git a/source/lib/byte_order.h b/source/lib/byte_order.h index 6c2f97c7d6..5f52ef86a5 100644 --- a/source/lib/byte_order.h +++ b/source/lib/byte_order.h @@ -45,7 +45,7 @@ /** - * convert 4 characters to u32 (at compile time) for easy comparison. + * convert 4 characters to std::uint32_t (at compile time) for easy comparison. * output is in native byte order; e.g. FOURCC_LE can be used instead. **/ #define FOURCC(a,b,c,d) // real definition is below @@ -55,20 +55,22 @@ // - 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 +// - the casts are ugly but necessary. std::uint32_t 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). +// int before the std::uint32_t cast, which would break things). /// big-endian version of FOURCC -#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 ) +#define FOURCC_BE(a,b,c,d) ( static_cast(static_cast(a)) << 24 | \ + static_cast(static_cast(b)) << 16 | \ + static_cast(static_cast(c)) << 8 | \ + static_cast(static_cast(d)) << 0 ) /// little-endian version of FOURCC -#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 ) +#define FOURCC_LE(a,b,c,d) ( static_cast(static_cast(a)) << 0 | \ + static_cast(static_cast(b)) << 8 | \ + static_cast(static_cast(c)) << 16 | \ + static_cast(static_cast(d)) << 24 ) #if BYTE_ORDER == BIG_ENDIAN # define FOURCC FOURCC_BE @@ -99,22 +101,22 @@ /// read a little-endian number from memory into native byte order. std::uint16_t read_le16(const void* p); -u32 read_le32(const void* p); /// see read_le16 +std::uint32_t read_le32(const void* p); /// see read_le16 u64 read_le64(const void* p); /// see read_le16 /// read a big-endian number from memory into native byte order. std::uint16_t read_be16(const void* p); -u32 read_be32(const void* p); /// see read_be16 +std::uint32_t read_be32(const void* p); /// see read_be16 u64 read_be64(const void* p); /// see read_be16 /// write a little-endian number to memory in native byte order. void write_le16(void* p, std::uint16_t x); -void write_le32(void* p, u32 x); /// see write_le16 +void write_le32(void* p, std::uint32_t x); /// see write_le16 void write_le64(void* p, u64 x); /// see write_le16 /// write a big-endian number to memory in native byte order. void write_be16(void* p, std::uint16_t x); -void write_be32(void* p, u32 x); /// see write_be16 +void write_be32(void* p, std::uint32_t x); /// see write_be16 void write_be64(void* p, u64 x); /// see write_be16 /** @@ -159,7 +161,7 @@ extern unsigned __int64 _byteswap_uint64(unsigned __int64); std::uint16_t swap16(const std::uint16_t x); #endif #ifndef swap32 -u32 swap32(const u32 x); +std::uint32_t swap32(const std::uint32_t x); #endif #ifndef swap64 u64 swap64(const u64 x); diff --git a/source/lib/file/archive/archive_zip.cpp b/source/lib/file/archive/archive_zip.cpp index d666016b0a..09d5521638 100644 --- a/source/lib/file/archive/archive_zip.cpp +++ b/source/lib/file/archive/archive_zip.cpp @@ -46,7 +46,6 @@ #include "lib/path.h" #include "lib/posix/posix_types.h" #include "lib/status.h" -#include "lib/types.h" #include "lib/utf8.h" #include @@ -62,10 +61,10 @@ // timestamp conversion: DOS FAT <-> Unix time_t //----------------------------------------------------------------------------- -static time_t time_t_from_FAT(u32 fat_timedate) +static time_t time_t_from_FAT(std::uint32_t fat_timedate) { - const u32 fat_time = bits(fat_timedate, 0, 15); - const u32 fat_date = bits(fat_timedate, 16, 31); + const std::uint32_t fat_time = bits(fat_timedate, 0, 15); + const std::uint32_t fat_date = bits(fat_timedate, 16, 31); struct tm t; // struct tm format: t.tm_sec = bits(fat_time, 0,4) * 2; // [0,59] @@ -85,7 +84,7 @@ static time_t time_t_from_FAT(u32 fat_timedate) } -static u32 FAT_from_time_t(time_t time) +static std::uint32_t FAT_from_time_t(time_t time) { // (values are adjusted for DST) struct tm* t = localtime(&time); @@ -102,7 +101,7 @@ static u32 FAT_from_time_t(time_t time) (static_cast(t->tm_year-80) << 9) // 7 ); - u32 fat_timedate = u32_from_u16(fat_date, fat_time); + std::uint32_t fat_timedate = u32_from_u16(fat_date, fat_time); return fat_timedate; } @@ -111,9 +110,9 @@ static u32 FAT_from_time_t(time_t time) // Zip archive definitions //----------------------------------------------------------------------------- -static const u32 cdfh_magic = FOURCC_LE('P','K','\1','\2'); -static const u32 lfh_magic = FOURCC_LE('P','K','\3','\4'); -static const u32 ecdr_magic = FOURCC_LE('P','K','\5','\6'); +static const std::uint32_t cdfh_magic = FOURCC_LE('P','K','\1','\2'); +static const std::uint32_t lfh_magic = FOURCC_LE('P','K','\3','\4'); +static const std::uint32_t ecdr_magic = FOURCC_LE('P','K','\5','\6'); enum ZipMethod { @@ -126,7 +125,8 @@ enum ZipMethod class LFH { public: - void Init(const CFileInfo& fileInfo, off_t csize, ZipMethod method, u32 checksum, const Path& pathname) + void Init(const CFileInfo& fileInfo, off_t csize, ZipMethod method, std::uint32_t checksum, + const Path& pathname) { const std::string pathnameUTF8 = utf8_from_wstring(pathname.string()); const size_t pathnameSize = pathnameUTF8.length(); @@ -156,14 +156,14 @@ public: } private: - u32 m_magic; + std::uint32_t m_magic; std::uint16_t m_x1; // version needed std::uint16_t m_flags; std::uint16_t m_method; - u32 m_fat_mtime; // last modified time (DOS FAT format) - u32 m_crc; - u32 m_csize; - u32 m_usize; + std::uint32_t m_fat_mtime; // last modified time (DOS FAT format) + std::uint32_t m_crc; + std::uint32_t m_csize; + std::uint32_t m_usize; std::uint16_t m_fn_len; std::uint16_t m_e_len; }; @@ -174,7 +174,8 @@ cassert(sizeof(LFH) == 30); class CDFH { public: - void Init(const CFileInfo& fileInfo, off_t ofs, off_t csize, ZipMethod method, u32 checksum, const Path& pathname, size_t slack) + void Init(const CFileInfo& fileInfo, off_t ofs, off_t csize, ZipMethod method, + std::uint32_t checksum, const Path& pathname, size_t slack) { const std::string pathnameUTF8 = utf8_from_wstring(pathname.string()); const size_t pathnameLength = pathnameUTF8.length(); @@ -224,14 +225,14 @@ public: return (ZipMethod)read_le16(&m_method); } - u32 Checksum() const + std::uint32_t Checksum() const { return read_le32(&m_crc); } time_t MTime() const { - const u32 fat_mtime = read_le32(&m_fat_mtime); + const std::uint32_t fat_mtime = read_le32(&m_fat_mtime); return time_t_from_FAT(fat_mtime); } @@ -245,20 +246,20 @@ public: } private: - u32 m_magic; - u32 m_x1; // versions + std::uint32_t m_magic; + std::uint32_t m_x1; // versions std::uint16_t m_flags; std::uint16_t m_method; - u32 m_fat_mtime; // last modified time (DOS FAT format) - u32 m_crc; - u32 m_csize; - u32 m_usize; + std::uint32_t m_fat_mtime; // last modified time (DOS FAT format) + std::uint32_t m_crc; + std::uint32_t m_csize; + std::uint32_t m_usize; std::uint16_t m_fn_len; std::uint16_t m_e_len; std::uint16_t m_c_len; - u32 m_x2; // spanning - u32 m_x3; // attributes - u32 m_lfh_ofs; + std::uint32_t m_x2; // spanning + std::uint32_t m_x3; // attributes + std::uint32_t m_lfh_ofs; }; cassert(sizeof(CDFH) == 46); @@ -292,13 +293,13 @@ public: } private: - u32 m_magic; + std::uint32_t m_magic; std::uint16_t m_diskNum; std::uint16_t m_cd_diskNum; std::uint16_t m_cd_numEntriesOnDisk; std::uint16_t m_cd_numEntries; - u32 m_cd_size; - u32 m_cd_ofs; + std::uint32_t m_cd_size; + std::uint32_t m_cd_ofs; std::uint16_t m_comment_len; }; @@ -314,7 +315,7 @@ cassert(sizeof(ECDR) == 22); class ArchiveFile_Zip final : public IArchiveFile { public: - ArchiveFile_Zip(const PFile& file, off_t ofs, off_t csize, u32 checksum, ZipMethod method) + ArchiveFile_Zip(const PFile& file, off_t ofs, off_t csize, std::uint32_t checksum, ZipMethod method) : m_file(file), m_ofs(ofs) , m_csize(csize), m_checksum(checksum), m_method(static_cast(method)) , m_flags(NeedsFixup) @@ -440,7 +441,7 @@ private: // all relevant LFH/CDFH fields not covered by CFileInfo mutable off_t m_ofs; off_t m_csize; - u32 m_checksum; + std::uint32_t m_checksum; std::uint16_t m_method; mutable std::uint16_t m_flags; }; @@ -511,14 +512,14 @@ private: * @return pointer to record within buffer or 0 if not found. **/ static const std::uint8_t* FindRecord(const std::uint8_t* buf, size_t size, - const std::uint8_t* start, u32 magic, size_t recordSize) + const std::uint8_t* start, std::uint32_t magic, size_t recordSize) { // (don't use as the counter - otherwise we can't tell if // scanning within the buffer was necessary.) for(const std::uint8_t* p = start; p <= buf+size-recordSize; p++) { // found it - if(*(u32*)p == magic) + if(*reinterpret_cast(p) == magic) { ENSURE(p == start); // otherwise, the archive is a bit broken return p; @@ -554,7 +555,7 @@ private: for (off_t commentSize = 0; commentSize <= offsetInBlock && !ecdr; ++commentSize) { const std::uint8_t *pECDRTest = buf + offsetInBlock - commentSize; - if (*reinterpret_cast(pECDRTest) == ecdr_magic) + if (*reinterpret_cast(pECDRTest) == ecdr_magic) { // Signature matches, test whether comment // fills up the whole space following the @@ -717,7 +718,7 @@ public: io::BufferPtr buf(io::Allocate(sizeof(LFH) + pathnameLength + csizeMax)); // read and compress file contents - size_t csize; u32 checksum; + size_t csize; std::uint32_t checksum; { std::uint8_t* cdata = buf.get() + sizeof(LFH) + pathnameLength; Stream stream(codec); diff --git a/source/lib/file/archive/codec.h b/source/lib/file/archive/codec.h index fc9dd836fb..303227687a 100644 --- a/source/lib/file/archive/codec.h +++ b/source/lib/file/archive/codec.h @@ -30,7 +30,6 @@ #define INCLUDED_CODEC #include "lib/status.h" -#include "lib/types.h" #include #include @@ -82,7 +81,7 @@ public: * @param outProduced * @return error status for the entire operation. **/ - virtual Status Finish(u32& checksum, size_t& outProduced) = 0; + virtual Status Finish(std::uint32_t& checksum, size_t& outProduced) = 0; /** * update a checksum to reflect the contents of a buffer. @@ -93,7 +92,8 @@ 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 std::uint8_t* in, size_t inSize) const = 0; + virtual std::uint32_t UpdateChecksum(std::uint32_t 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 0ad4171ce6..625244463a 100644 --- a/source/lib/file/archive/codec_zlib.cpp +++ b/source/lib/file/archive/codec_zlib.cpp @@ -29,7 +29,6 @@ #include "lib/external_libraries/zlib.h" #include "lib/file/archive/codec.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -37,18 +36,18 @@ class Codec_ZLib : public ICodec { public: - u32 UpdateChecksum([[maybe_unused]] u32 checksum, [[maybe_unused]] const std::uint8_t* in, + std::uint32_t UpdateChecksum([[maybe_unused]] std::uint32_t checksum, [[maybe_unused]] const std::uint8_t* in, [[maybe_unused]] size_t inSize) const { #if CODEC_COMPUTE_CHECKSUM - return (u32)crc32(checksum, in, (uInt)inSize); + return static_cast(crc32(checksum, in, (uInt)inSize)); #else return 0; #endif } protected: - u32 InitializeChecksum() + std::uint32_t InitializeChecksum() { #if CODEC_COMPUTE_CHECKSUM return crc32(0, 0, 0); @@ -94,7 +93,7 @@ public: return INFO::OK; } - virtual Status Finish(u32& checksum, size_t& outProduced) + virtual Status Finish(std::uint32_t& checksum, size_t& outProduced) { outProduced = 0; checksum = m_checksum; @@ -102,7 +101,7 @@ public: } private: - u32 m_checksum; + std::uint32_t m_checksum; }; @@ -174,7 +173,7 @@ protected: // calculate a checksum ourselves. // adler32 is somewhat weaker than CRC32, but a more important argument // is that we should use the latter for compatibility with Zip archives. - mutable u32 m_checksum; + mutable std::uint32_t m_checksum; }; @@ -222,7 +221,7 @@ public: return CodecZLibStream::CallStreamFunc(deflate, 0, in, inSize, out, outSize, inConsumed, outProduced); } - virtual Status Finish(u32& checksum, size_t& outProduced) + virtual Status Finish(std::uint32_t& checksum, size_t& outProduced) { const uInt availOut = m_zs.avail_out; @@ -283,7 +282,7 @@ public: return ret; } - virtual Status Finish(u32& checksum, size_t& outProduced) + virtual Status Finish(std::uint32_t& checksum, size_t& outProduced) { // no action needed - decompression always flushes immediately. outProduced = 0; 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 838ccf1e45..ed2a408b33 100644 --- a/source/lib/file/archive/disabled_tests/test_codec_zlib.h +++ b/source/lib/file/archive/disabled_tests/test_codec_zlib.h @@ -33,7 +33,7 @@ public: void test_compress_decompress_compare() { size_t inConsumed, outProduced; - u32 checksum; + std::uint32_t checksum; // generate random input udata // (limit values to 0..7 so that the udata will actually be compressible) diff --git a/source/lib/file/archive/disabled_tests/test_compression.h b/source/lib/file/archive/disabled_tests/test_compression.h index 322d6bfed1..c065774237 100644 --- a/source/lib/file/archive/disabled_tests/test_compression.h +++ b/source/lib/file/archive/disabled_tests/test_compression.h @@ -52,7 +52,7 @@ public: TS_ASSERT_OK(comp_alloc_output(c, csizeBound)); const ssize_t cdata_produced = comp_feed(c, data, data_size); TS_ASSERT(cdata_produced >= 0); - u32 checksum; + std::uint32_t checksum; TS_ASSERT_OK(comp_finish(c, &cdata, &csize, &checksum)); TS_ASSERT(cdata_produced <= (ssize_t)csize); // can't have produced more than total } @@ -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); - std::uint8_t* udata_final; size_t usize_final; u32 checksum; + std::uint8_t* udata_final; size_t usize_final; std::uint32_t 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.h b/source/lib/file/archive/stream.h index 78c1b16a50..726c4f8d7c 100644 --- a/source/lib/file/archive/stream.h +++ b/source/lib/file/archive/stream.h @@ -30,7 +30,6 @@ #include "lib/code_annotation.h" #include "lib/file/archive/codec.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -102,7 +101,7 @@ public: return m_outProduced; } - u32 Checksum() const + std::uint32_t Checksum() const { return m_checksum; } @@ -113,7 +112,7 @@ private: size_t m_inConsumed; size_t m_outProduced; - u32 m_checksum; + std::uint32_t m_checksum; }; // avoids the need for std::bind (not supported on all compilers) and boost::bind (can't be diff --git a/source/lib/fnv_hash.cpp b/source/lib/fnv_hash.cpp index ecaff0235a..b55d7e8450 100644 --- a/source/lib/fnv_hash.cpp +++ b/source/lib/fnv_hash.cpp @@ -27,9 +27,9 @@ // FNV1-A hash - good for strings. // if len = 0 (default), treat buf as a C-string; // otherwise, hash bytes of buf. -u32 fnv_hash(const void* buf, size_t len) +std::uint32_t fnv_hash(const void* buf, size_t len) { - u32 h = 0x811c9dc5u; + std::uint32_t h = 0x811c9dc5u; // give distinct values for different length 0 buffers. // value taken from FNV; it has no special significance. diff --git a/source/lib/fnv_hash.h b/source/lib/fnv_hash.h index fe0f921ce2..357f411057 100644 --- a/source/lib/fnv_hash.h +++ b/source/lib/fnv_hash.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 @@ -46,7 +46,7 @@ * @return hash result. note: results are distinct for buffers containing * differing amounts of zero bytes because the hash value is seeded. **/ -extern u32 fnv_hash(const void* buf, size_t len = 0); +extern std::uint32_t fnv_hash(const void* buf, size_t len = 0); /// 64-bit version of fnv_hash. extern u64 fnv_hash64(const void* buf, size_t len = 0); diff --git a/source/lib/lib.cpp b/source/lib/lib.cpp index d4271abdd1..eea505a882 100644 --- a/source/lib/lib.cpp +++ b/source/lib/lib.cpp @@ -36,28 +36,28 @@ // these avoid a common mistake in using >> (ANSI requires shift count be // less than the bit width of the type). -u32 u64_hi(u64 x) +std::uint32_t u64_hi(u64 x) { - return (u32)(x >> 32); + return static_cast(x >> 32); } -u32 u64_lo(u64 x) +std::uint32_t u64_lo(u64 x) { - return (u32)(x & 0xFFFFFFFF); + return static_cast(x & 0xFFFFFFFF); } -std::uint16_t u32_hi(u32 x) +std::uint16_t u32_hi(std::uint32_t x) { return static_cast(x >> 16); } -std::uint16_t u32_lo(u32 x) +std::uint16_t u32_lo(std::uint32_t x) { return static_cast(x & 0xFFFF); } -u64 u64_from_u32(u32 hi, u32 lo) +u64 u64_from_u32(std::uint32_t hi, std::uint32_t lo) { u64 x = (u64)hi; x <<= 32; @@ -65,9 +65,9 @@ u64 u64_from_u32(u32 hi, u32 lo) return x; } -u32 u32_from_u16(std::uint16_t hi, std::uint16_t lo) +std::uint32_t u32_from_u16(std::uint16_t hi, std::uint16_t lo) { - u32 x = (u32)hi; + std::uint32_t x = static_cast(hi); x <<= 16; x |= lo; return x; diff --git a/source/lib/lib.h b/source/lib/lib.h index bfd21766c5..f532bb0c19 100644 --- a/source/lib/lib.h +++ b/source/lib/lib.h @@ -113,16 +113,16 @@ inline bool IsSimilarMagnitude(double d1, double d2, const double relativeErrorT // note: these avoid a common mistake in using >> (ANSI requires // shift count be less than the bit width of the type). -extern u32 u64_hi(u64 x); /// return upper 32-bits -extern u32 u64_lo(u64 x); /// return lower 32-bits -extern std::uint16_t u32_hi(u32 x); /// return upper 16-bits -extern std::uint16_t u32_lo(u32 x); /// return lower 16-bits +extern std::uint32_t u64_hi(u64 x); /// return upper 32-bits +extern std::uint32_t u64_lo(u64 x); /// return lower 32-bits +extern std::uint16_t u32_hi(std::uint32_t x); /// return upper 16-bits +extern std::uint16_t u32_lo(std::uint32_t x); /// return lower 16-bits -extern u64 u64_from_u32(u32 hi, u32 lo); /// assemble u64 from u32 -extern u32 u32_from_u16(std::uint16_t hi, std::uint16_t lo); /// assemble u32 from std::uint16_t +extern u64 u64_from_u32(std::uint32_t hi, std::uint32_t lo); /// assemble u64 from std::uint32_t +extern std::uint32_t u32_from_u16(std::uint16_t hi, std::uint16_t lo); /// assemble std::uint32_t from std::uint16_t -// safe downcasters: cast from any integral type to u32 or std::uint16_t; -// issues warning if larger than would fit in the target type. +// safe downcasters: cast from any integral type to std::uint32_t or +// std::uint16_t; issues warning if larger than would fit in the target type. // // these are generally useful but included here (instead of e.g. lib.h) for // several reasons: @@ -147,12 +147,12 @@ template std::uint16_t u16_from_larger(T x) return static_cast(x & max); } -template u32 u32_from_larger(T x) +template std::uint32_t u32_from_larger(T x) { - const u32 max = std::numeric_limits::max(); + const std::uint32_t max = std::numeric_limits::max(); if((u64)x > (u64)max) throw std::out_of_range("u32_from_larger"); - return (u32)(x & max); + return static_cast(x & max); } /// convert double to std::uint8_t; verifies number is in range. diff --git a/source/lib/sysdep/arch/x86_x64/x86_x64.cpp b/source/lib/sysdep/arch/x86_x64/x86_x64.cpp index 65094aa975..0aa32fe0b8 100644 --- a/source/lib/sysdep/arch/x86_x64/x86_x64.cpp +++ b/source/lib/sysdep/arch/x86_x64/x86_x64.cpp @@ -80,8 +80,8 @@ static void Invoke_cpuid(CpuidRegs* regs) __cpuidex((int*)regs, regs->eax, regs->ecx); } -static u32 cpuid_maxFunction; -static u32 cpuid_maxExtendedFunction; +static std::uint32_t cpuid_maxFunction; +static std::uint32_t cpuid_maxExtendedFunction; static Status InitCpuid() { @@ -103,7 +103,7 @@ bool cpuid(CpuidRegs* regs) static ModuleInitState initState{ 0 }; ModuleInit(&initState, InitCpuid); - const u32 function = regs->eax; + const std::uint32_t function = regs->eax; if(function > cpuid_maxExtendedFunction) return false; if(function < 0x80000000 && function > cpuid_maxFunction) @@ -119,7 +119,7 @@ bool cpuid(CpuidRegs* regs) // treated as 128 bit field; order: std ecx, std edx, ext ecx, ext edx // keep in sync with enum Cap! -static u32 caps[4]; +static std::uint32_t caps[4]; static ModuleInitState capsInitState{ 0 }; @@ -156,7 +156,7 @@ bool Cap(Caps cap) return IsBitSet(caps[index], bit); } -void GetCapBits(u32* d0, u32* d1, u32* d2, u32* d3) +void GetCapBits(std::uint32_t* d0, std::uint32_t* d1, std::uint32_t* d2, std::uint32_t* d3) { ModuleInit(&capsInitState, InitCaps); @@ -287,7 +287,7 @@ static Status InitIdentifierString() // get brand string (if available) char* pos = identifierString; bool gotBrandString = true; - for(u32 function = 0x80000002; function <= 0x80000004; function++) + for(std::uint32_t function = 0x80000002; function <= 0x80000004; function++) { CpuidRegs regs = { 0 }; regs.eax = function; @@ -377,7 +377,7 @@ u64 rdtsc() { #if GCC_VERSION // GCC supports "portable" assembly for both x86 and x64 - volatile u32 lo, hi; + volatile std::uint32_t lo, hi; __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); return u64_from_u32(hi, lo); #endif diff --git a/source/lib/sysdep/arch/x86_x64/x86_x64.h b/source/lib/sysdep/arch/x86_x64/x86_x64.h index 6e0659e464..8193a87610 100644 --- a/source/lib/sysdep/arch/x86_x64/x86_x64.h +++ b/source/lib/sysdep/arch/x86_x64/x86_x64.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 @@ -49,10 +49,10 @@ namespace x86_x64 { #pragma pack(push, 1) // (allows casting to int*) struct CpuidRegs { - u32 eax; - u32 ebx; - u32 ecx; - u32 edx; + std::uint32_t eax; + std::uint32_t ebx; + std::uint32_t ecx; + std::uint32_t edx; }; #pragma pack(pop) @@ -147,7 +147,7 @@ enum Caps **/ bool Cap(Caps cap); -void GetCapBits(u32* d0, u32* d1, u32* d2, u32* d3); +void GetCapBits(std::uint32_t* d0, std::uint32_t* d1, std::uint32_t* d2, std::uint32_t* d3); //----------------------------------------------------------------------------- diff --git a/source/lib/sysdep/os/osx/osx.cpp b/source/lib/sysdep/os/osx/osx.cpp index 97359dd997..446d099f72 100644 --- a/source/lib/sysdep/os/osx/osx.cpp +++ b/source/lib/sysdep/os/osx/osx.cpp @@ -50,7 +50,7 @@ OsPath sys_ExecutablePathname() else { char temp[PATH_MAX]; - u32 size = PATH_MAX; + std::uint32_t size = PATH_MAX; if (_NSGetExecutablePath(temp, &size) == 0) { char name[PATH_MAX]; diff --git a/source/lib/sysdep/os/win/acpi.h b/source/lib/sysdep/os/win/acpi.h index 33ffe5304f..67d1b160db 100644 --- a/source/lib/sysdep/os/win/acpi.h +++ b/source/lib/sysdep/os/win/acpi.h @@ -33,14 +33,14 @@ struct AcpiTable { char signature[4]; - u32 size; // table size [bytes], including header + std::uint32_t size; // table size [bytes], including header std::uint8_t revision; std::uint8_t checksum; // to make sum of entire table == 0 char oemId[6]; char oemTableId[8]; - u32 oemRevision; + std::uint32_t oemRevision; char creatorId[4]; - u32 creatorRevision; + std::uint32_t creatorRevision; }; enum AcpiAddressSpace @@ -66,14 +66,14 @@ struct FADT // signature is FACP! { AcpiTable header; std::uint8_t unused1[40]; - u32 pmTimerPortAddress; + std::uint32_t pmTimerPortAddress; std::uint8_t unused2[16]; std::uint16_t c2Latency; // [us] std::uint16_t c3Latency; // [us] std::uint8_t unused3[5]; std::uint8_t dutyWidth; std::uint8_t unused4[6]; - u32 flags; + std::uint32_t flags; // (ACPI4 defines additional fields after this) bool IsDutyCycleSupported() const diff --git a/source/lib/sysdep/os/win/wcpu.cpp b/source/lib/sysdep/os/win/wcpu.cpp index b9064be995..22bae047d2 100644 --- a/source/lib/sysdep/os/win/wcpu.cpp +++ b/source/lib/sysdep/os/win/wcpu.cpp @@ -76,7 +76,7 @@ size_t os_cpu_NumProcessors() //----------------------------------------------------------------------------- -Status wcpu_ReadFrequencyFromRegistry(u32& freqMhz) +Status wcpu_ReadFrequencyFromRegistry(std::uint32_t& freqMhz) { HKEY hKey; if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) diff --git a/source/lib/sysdep/os/win/wcpu.h b/source/lib/sysdep/os/win/wcpu.h index f566e22847..8660772a93 100644 --- a/source/lib/sysdep/os/win/wcpu.h +++ b/source/lib/sysdep/os/win/wcpu.h @@ -29,7 +29,7 @@ #include "lib/sysdep/os/win/win.h" -extern Status wcpu_ReadFrequencyFromRegistry(u32& freqMhz); +extern Status wcpu_ReadFrequencyFromRegistry(std::uint32_t& freqMhz); // "affinity" and "processorNumber" are what Windows sees. // "processorMask" and "processor" are the idealized representation we expose diff --git a/source/lib/sysdep/os/win/wfirmware.h b/source/lib/sysdep/os/win/wfirmware.h index e839fed3cd..b323d5daf4 100644 --- a/source/lib/sysdep/os/win/wfirmware.h +++ b/source/lib/sysdep/os/win/wfirmware.h @@ -27,9 +27,9 @@ namespace wfirmware { -typedef u32 Provider; +typedef std::uint32_t Provider; -typedef u32 TableId; +typedef std::uint32_t TableId; typedef std::vector TableIds; extern TableIds GetTableIDs(Provider provider); diff --git a/source/lib/sysdep/os/win/wnuma.cpp b/source/lib/sysdep/os/win/wnuma.cpp index f090422fec..c635de61b0 100644 --- a/source/lib/sysdep/os/win/wnuma.cpp +++ b/source/lib/sysdep/os/win/wnuma.cpp @@ -54,7 +54,7 @@ struct Node // POD // we associate them with contiguous indices in nodes[]) UCHAR nodeNumber; - u32 proximityDomainNumber; + std::uint32_t proximityDomainNumber; uintptr_t processorMask; }; @@ -158,15 +158,15 @@ struct AffinityAPIC AffinityHeader header; std::uint8_t proximityDomainNumber0; std::uint8_t apicId; - u32 flags; + std::uint32_t flags; std::uint8_t sapicId; std::uint8_t proximityDomainNumber123[3]; - u32 clockDomain; + std::uint32_t clockDomain; - u32 ProximityDomainNumber() const + std::uint32_t ProximityDomainNumber() const { // (this is the apparent result of backwards compatibility, ugh.) - u32 proximityDomainNumber; + std::uint32_t proximityDomainNumber; memcpy(&proximityDomainNumber, &proximityDomainNumber123[0]-1, sizeof(proximityDomainNumber)); proximityDomainNumber &= ~0xFF; proximityDomainNumber |= proximityDomainNumber0; @@ -179,12 +179,12 @@ struct AffinityMemory static const std::uint8_t type = 1; AffinityHeader header; - u32 proximityDomainNumber; + std::uint32_t proximityDomainNumber; std::uint16_t reserved1; u64 baseAddress; u64 length; - u32 reserved2; - u32 flags; + std::uint32_t reserved2; + std::uint32_t flags; u64 reserved3; }; @@ -194,7 +194,7 @@ struct AffinityMemory struct SRAT { AcpiTable header; - u32 reserved1; + std::uint32_t reserved1; std::uint8_t reserved2[8]; AffinityHeader affinities[1]; }; @@ -223,7 +223,7 @@ struct ProximityDomain // (AffinityMemory's fields are not currently needed) }; -typedef std::map ProximityDomains; +typedef std::map ProximityDomains; static ProximityDomains ExtractProximityDomainsFromSRAT(const SRAT* srat) { @@ -244,7 +244,7 @@ static ProximityDomains ExtractProximityDomainsFromSRAT(const SRAT* srat) } const size_t processor = ProcessorFromApicId(affinityAPIC->apicId); - const u32 proximityDomainNumber = affinityAPIC->ProximityDomainNumber(); + const std::uint32_t proximityDomainNumber = affinityAPIC->ProximityDomainNumber(); ProximityDomain& proximityDomain = proximityDomains[proximityDomainNumber]; proximityDomain.processorMask |= Bit(processor); } @@ -256,7 +256,7 @@ static void PopulateNodesFromProximityDomains(const ProximityDomains& proximityD { for(ProximityDomains::const_iterator it = proximityDomains.begin(); it != proximityDomains.end(); ++it) { - const u32 proximityDomainNumber = it->first; + const std::uint32_t proximityDomainNumber = it->first; const ProximityDomain& proximityDomain = it->second; Node* node = FindNodeWithProcessorMask(proximityDomain.processorMask); diff --git a/source/lib/sysdep/os_cpu.cpp b/source/lib/sysdep/os_cpu.cpp index 5e813c6ae3..e1eb7215bb 100644 --- a/source/lib/sysdep/os_cpu.cpp +++ b/source/lib/sysdep/os_cpu.cpp @@ -50,7 +50,7 @@ double os_cpu_ClockFrequency() return clockFrequency; #if OS_WIN - u32 freqMhz; + std::uint32_t freqMhz; if(wcpu_ReadFrequencyFromRegistry(freqMhz) == INFO::OK) return clockFrequency = freqMhz * 1e6; #endif diff --git a/source/lib/tests/test_bits.h b/source/lib/tests/test_bits.h index b155a8a0a2..28d2febc5b 100644 --- a/source/lib/tests/test_bits.h +++ b/source/lib/tests/test_bits.h @@ -35,7 +35,7 @@ public: { EQUALS(Bit(0), 1u); EQUALS(Bit(8), 0x100u); - EQUALS(Bit(31), u32(0x80000000ul)); + EQUALS(Bit(31), static_cast(0x80000000ul)); EQUALS(Bit(1), u64(2)); EQUALS(Bit(32), u64(0x100000000ull)); EQUALS(Bit(63), u64(0x8000000000000000ull)); @@ -46,8 +46,8 @@ public: EQUALS(IsBitSet(0u, 1), false); EQUALS(IsBitSet(1u, 1), false); EQUALS(IsBitSet(2u, 1), true); - EQUALS(IsBitSet(0xFFFFFFFFul, 0), true); - EQUALS(IsBitSet(0xFFFFFFFFul, 31), true); + EQUALS(IsBitSet(0xFFFFFFFFul, 0), true); + EQUALS(IsBitSet(0xFFFFFFFFul, 31), true); EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 0), true); EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 31), true); EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 32), true); @@ -59,9 +59,9 @@ public: EQUALS(bit_mask(0), 0); EQUALS(bit_mask(2), 0x3); EQUALS(bit_mask(16), 0xFFFF); - EQUALS(bit_mask(0), 0u); - EQUALS(bit_mask(2), 0x3u); - EQUALS(bit_mask(32), 0xFFFFFFFFul); + EQUALS(bit_mask(0), 0u); + EQUALS(bit_mask(2), 0x3u); + EQUALS(bit_mask(32), 0xFFFFFFFFul); EQUALS(bit_mask(0), 0u); EQUALS(bit_mask(2), 0x3u); EQUALS(bit_mask(32), 0xFFFFFFFFull); @@ -76,8 +76,8 @@ public: EQUALS(bits(0xFFFF, 14, 15), 0x3); EQUALS(bits(0xAA55, 4, 11), 0xA5); EQUALS(bits(0xAA55, 14, 15), 0x2); - EQUALS(bits(0ul, 0, 31), 0ul); - EQUALS(bits(0xFFFFFFFFul, 0, 31), 0xFFFFFFFFul); + EQUALS(bits(0ul, 0, 31), 0ul); + EQUALS(bits(0xFFFFFFFFul, 0, 31), 0xFFFFFFFFul); EQUALS(bits(0ull, 0, 63), 0ull); EQUALS(bits(0xFFFFFFFFull, 0, 31), 0xFFFFFFFFull); EQUALS(bits(0x0000FFFFFFFF0000ull, 16, 47), 0xFFFFFFFFull); diff --git a/source/lib/tests/test_byte_order.h b/source/lib/tests/test_byte_order.h index 64ec0e831b..1afc101477 100644 --- a/source/lib/tests/test_byte_order.h +++ b/source/lib/tests/test_byte_order.h @@ -23,7 +23,6 @@ #include "lib/self_test.h" #include "lib/byte_order.h" -#include "lib/types.h" #include @@ -32,7 +31,7 @@ class TestByteOrder : public CxxTest::TestSuite public: void test_conversion() { - const u32 x = 0x01234567u; + const std::uint32_t x = 0x01234567u; std::uint8_t LS_byte; memcpy(&LS_byte, &x, 1); // little endian diff --git a/source/lib/tests/test_fnv_hash.h b/source/lib/tests/test_fnv_hash.h index 9ba77dcee0..4dfbfc1388 100644 --- a/source/lib/tests/test_fnv_hash.h +++ b/source/lib/tests/test_fnv_hash.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 @@ -31,7 +31,7 @@ public: void test_fnv_hash() { TS_ASSERT_EQUALS(fnv_hash(""), 0x811C9DC5u); // verify initial value - const u32 h1 = fnv_hash("abcdef"); + const std::uint32_t h1 = fnv_hash("abcdef"); TS_ASSERT_EQUALS(h1, 0xFF478A2A); // verify value for simple string TS_ASSERT_EQUALS(fnv_hash("abcdef", 6), h1); // same result if hashing buffer diff --git a/source/lib/tex/tex.cpp b/source/lib/tex/tex.cpp index 5f8e18aa76..5483a17c37 100644 --- a/source/lib/tex/tex.cpp +++ b/source/lib/tex/tex.cpp @@ -633,7 +633,7 @@ std::uint8_t* Tex::get_data() } // returns color of 1x1 mipmap level -u32 Tex::get_average_color() const +std::uint32_t Tex::get_average_color() const { // require mipmaps if(!(m_Flags & TEX_MIPMAPS)) @@ -658,7 +658,7 @@ u32 Tex::get_average_color() const // convert to BGRA WARN_IF_ERR(basetex.transform_to(TEX_BGR | TEX_ALPHA)); - // extract components into u32 + // extract components into std::uint32_t ENSURE(basetex.m_DataSize >= basetex.m_Ofs+4); std::uint8_t b = basetex.m_Data.get()[basetex.m_Ofs]; std::uint8_t g = basetex.m_Data.get()[basetex.m_Ofs+1]; @@ -788,11 +788,11 @@ void Tex::UpdateMIPLevels() std::uint8_t* levelData = m_Data.get(); levelData += m_Ofs; - const u32 dataPadding = (m_Flags & TEX_DXT) != 0 ? 4 : 1; - u32 levelWidth = m_Width, levelHeight = m_Height; + const std::uint32_t dataPadding = (m_Flags & TEX_DXT) != 0 ? 4 : 1; + std::uint32_t levelWidth = m_Width, levelHeight = m_Height; for (;;) { - const u32 levelDataSize = round_up(levelWidth, dataPadding) * round_up(levelHeight, dataPadding) * m_Bpp / 8; + const std::uint32_t levelDataSize = round_up(levelWidth, dataPadding) * round_up(levelHeight, dataPadding) * m_Bpp / 8; m_MIPLevels.emplace_back(); m_MIPLevels.back().data = levelData; m_MIPLevels.back().dataSize = levelDataSize; @@ -806,7 +806,7 @@ void Tex::UpdateMIPLevels() break; levelData += levelDataSize; - levelWidth = std::max(levelWidth / 2, 1); - levelHeight = std::max(levelHeight / 2, 1); + levelWidth = std::max(levelWidth / 2, 1); + levelHeight = std::max(levelHeight / 2, 1); } } diff --git a/source/lib/tex/tex.h b/source/lib/tex/tex.h index 7e16d7515d..791bf1f520 100644 --- a/source/lib/tex/tex.h +++ b/source/lib/tex/tex.h @@ -108,7 +108,6 @@ library and IO layer. Read and write are zero-copy. #include "lib/file/vfs/vfs_path.h" #include "lib/os_path.h" #include "lib/status.h" -#include "lib/types.h" #include #include @@ -218,9 +217,9 @@ public: { // A pointer to the mip level image data (pixels). std::uint8_t* data; - u32 dataSize; - u32 width; - u32 height; + std::uint32_t dataSize; + std::uint32_t width; + std::uint32_t height; }; /** @@ -354,7 +353,7 @@ public: * * @return ARGB value (or 0 if texture does not have mipmaps) **/ - u32 get_average_color() const; + std::uint32_t get_average_color() const; /** * return total byte size of the image pixels. (including mipmaps!) diff --git a/source/lib/tex/tex_bmp.cpp b/source/lib/tex/tex_bmp.cpp index e5741c6263..4feec9e388 100644 --- a/source/lib/tex/tex_bmp.cpp +++ b/source/lib/tex/tex_bmp.cpp @@ -34,7 +34,6 @@ #include "lib/os_path.h" #include "lib/status.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include @@ -44,24 +43,24 @@ struct BmpHeader { // BITMAPFILEHEADER std::uint16_t bfType; // "BM" - u32 bfSize; // of file + std::uint32_t bfSize; // of file std::uint16_t bfReserved1; std::uint16_t bfReserved2; - u32 bfOffBits; // offset to image data + std::uint32_t bfOffBits; // offset to image data // BITMAPINFOHEADER - u32 biSize; + std::uint32_t biSize; std::int32_t biWidth; std::int32_t biHeight; std::uint16_t biPlanes; std::uint16_t biBitCount; - u32 biCompression; - u32 biSizeImage; + std::uint32_t biCompression; + std::uint32_t biSizeImage; // the following are unused and zeroed when writing: std::int32_t biXPelsPerMeter; std::int32_t biYPelsPerMeter; - u32 biClrUsed; - u32 biClrImportant; + std::uint32_t biClrUsed; + std::uint32_t biClrImportant; }; #pragma pack(pop) @@ -95,7 +94,7 @@ size_t TexCodecBmp::hdr_size(const std::uint8_t* file) const if(file) { BmpHeader* hdr = (BmpHeader*)file; - const u32 ofs = read_le32(&hdr->bfOffBits); + const std::uint32_t ofs = read_le32(&hdr->bfOffBits); ENSURE(ofs >= hdr_size && "bmp_hdr_size invalid"); return ofs; } @@ -110,7 +109,7 @@ Status TexCodecBmp::decode(std::uint8_t* RESTRICT data, size_t /*size*/, Tex* RE const long w = (long)read_le32(&hdr->biWidth); const long h_ = (long)read_le32(&hdr->biHeight); const std::uint16_t bpp = read_le16(&hdr->biBitCount); - const u32 compress = read_le32(&hdr->biCompression); + const std::uint32_t compress = read_le32(&hdr->biCompression); const long h = std::labs(h_); @@ -149,7 +148,7 @@ Status TexCodecBmp::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const { // BITMAPFILEHEADER 0x4D42, // bfType = 'B','M' - (u32)file_size, // bfSize + static_cast(file_size), // bfSize 0, 0, // bfReserved1,2 hdr_size, // bfOffBits @@ -160,7 +159,7 @@ Status TexCodecBmp::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const 1, // biPlanes static_cast(t->m_Bpp), BI_RGB, // biCompression - (u32)img_size, // biSizeImage + static_cast(img_size), // biSizeImage 0, 0, 0, 0 // unused (bi?PelsPerMeter, biClr*) }; return tex_codec_write(t, transforms, &hdr, hdr_size, da); diff --git a/source/lib/tex/tex_dds.cpp b/source/lib/tex/tex_dds.cpp index a2e7d76ac3..9bc47cd3cd 100644 --- a/source/lib/tex/tex_dds.cpp +++ b/source/lib/tex/tex_dds.cpp @@ -227,7 +227,7 @@ private: u64 a_bits; // table of 2-bit color selectors - u32 c_selectors; + std::uint32_t c_selectors; size_t m_Dxt; }; @@ -337,14 +337,14 @@ static Status s3tc_decompress(Tex* t) struct DDS_PIXELFORMAT { - u32 dwSize; // size of structure (32) - u32 dwFlags; // indicates which fields are valid - u32 dwFourCC; // (DDPF_FOURCC) FOURCC code, "DXTn" - u32 dwRGBBitCount; // (DDPF_RGB) bits per pixel - u32 dwRBitMask; - u32 dwGBitMask; - u32 dwBBitMask; - u32 dwABitMask; // (DDPF_ALPHA or DDPF_ALPHAPIXELS) + std::uint32_t dwSize; // size of structure (32) + std::uint32_t dwFlags; // indicates which fields are valid + std::uint32_t dwFourCC; // (DDPF_FOURCC) FOURCC code, "DXTn" + std::uint32_t dwRGBBitCount; // (DDPF_RGB) bits per pixel + std::uint32_t dwRBitMask; + std::uint32_t dwGBitMask; + std::uint32_t dwBBitMask; + std::uint32_t dwABitMask; // (DDPF_ALPHA or DDPF_ALPHAPIXELS) }; @@ -365,21 +365,21 @@ struct DDS_PIXELFORMAT struct DDS_HEADER { // (preceded by the FOURCC "DDS ") - u32 dwSize; // size of structure (124) - u32 dwFlags; // indicates which fields are valid - u32 dwHeight; // (DDSD_HEIGHT) height of main image (pixels) - u32 dwWidth; // (DDSD_WIDTH ) width of main image (pixels) - u32 dwPitchOrLinearSize; // (DDSD_LINEARSIZE) size [bytes] of top level + std::uint32_t dwSize; // size of structure (124) + std::uint32_t dwFlags; // indicates which fields are valid + std::uint32_t dwHeight; // (DDSD_HEIGHT) height of main image (pixels) + std::uint32_t dwWidth; // (DDSD_WIDTH ) width of main image (pixels) + std::uint32_t dwPitchOrLinearSize; // (DDSD_LINEARSIZE) size [bytes] of top level // (DDSD_PITCH) bytes per row (%4 = 0) - u32 dwDepth; // (DDSD_DEPTH) vol. textures: vol. depth - u32 dwMipMapCount; // (DDSD_MIPMAPCOUNT) total # levels - u32 dwReserved1[11]; // reserved + std::uint32_t dwDepth; // (DDSD_DEPTH) vol. textures: vol. depth + std::uint32_t dwMipMapCount; // (DDSD_MIPMAPCOUNT) total # levels + std::uint32_t dwReserved1[11]; // reserved DDS_PIXELFORMAT ddpf; // (DDSD_PIXELFORMAT) surface description - u32 dwCaps; // (DDSD_CAPS) misc. surface flags - u32 dwCaps2; - u32 dwCaps3; - u32 dwCaps4; - u32 dwReserved2; // reserved + std::uint32_t dwCaps; // (DDSD_CAPS) misc. surface flags + std::uint32_t dwCaps2; + std::uint32_t dwCaps3; + std::uint32_t dwCaps4; + std::uint32_t dwReserved2; // reserved }; #pragma pack(pop) @@ -609,7 +609,7 @@ static Status decode_sd(const DDS_HEADER* sd, size_t& w, size_t& h, size_t& bpp, bool TexCodecDds::is_hdr(const std::uint8_t* file) const { - return *(u32*)file == FOURCC('D','D','S',' '); + return *reinterpret_cast(file) == FOURCC('D','D','S',' '); } diff --git a/source/lib/tex/tex_png.cpp b/source/lib/tex/tex_png.cpp index a09b81881f..09c7f8d4d5 100644 --- a/source/lib/tex/tex_png.cpp +++ b/source/lib/tex/tex_png.cpp @@ -39,7 +39,6 @@ #include "lib/status.h" #include "lib/sysdep/compiler.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include #include @@ -185,7 +184,7 @@ static Status png_decode_impl(MemoryStream* stream, png_structp png_ptr, png_inf WARN_RETURN(ERR::TEX_FMT_INVALID); const size_t pitch = png_get_rowbytes(png_ptr, info_ptr); - const u32 bpp = (u32)(pitch / w * 8); + const std::uint32_t bpp = static_cast(pitch / w * 8); size_t flags = 0; if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) @@ -255,7 +254,7 @@ 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). - return *(u32*)file == FOURCC('\x89','P','N','G'); + return *reinterpret_cast(file) == FOURCC('\x89','P','N','G'); } diff --git a/source/lib/types.h b/source/lib/types.h index 5c152e5d2b..cabfd8cb15 100644 --- a/source/lib/types.h +++ b/source/lib/types.h @@ -29,7 +29,6 @@ #include -typedef uint32_t u32; typedef uint64_t u64; typedef unsigned int uint; diff --git a/source/lib/utf8.cpp b/source/lib/utf8.cpp index 2cef580d5c..18cb9ae4cc 100644 --- a/source/lib/utf8.cpp +++ b/source/lib/utf8.cpp @@ -26,7 +26,6 @@ #include "lib/code_annotation.h" #include "lib/debug.h" -#include "lib/types.h" #include @@ -76,7 +75,7 @@ STATUS_ADD_DEFINITIONS(utf8StatusDefinitions); // (must be unsigned to avoid sign extension) typedef std::uint8_t UTF8; -typedef u32 UTF32; +typedef std::uint32_t UTF32; // called from ReplaceIfInvalid and UTF8Codec::Decode diff --git a/source/main.cpp b/source/main.cpp index 7f1ef3da25..31d668b099 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -48,7 +48,6 @@ that of Atlas depending on commandline parameters. #include "lib/sysdep/compiler.h" #include "lib/sysdep/os.h" #include "lib/timer.h" -#include "lib/types.h" #include "lobby/XmppClient.h" #include "network/NetClient.h" #include "ps/ArchiveBuilder.h" @@ -467,7 +466,7 @@ static void NonVisualFrame() if (g_NetClient) g_NetClient->Poll(); - static u32 turn = 0; + static std::uint32_t turn = 0; if (g_Game && g_Game->IsGameStarted() && g_Game->GetTurnManager()) { if (g_Game->GetTurnManager()->Update(DEFAULT_TURN_LENGTH, 1, diff --git a/source/maths/Fixed.cpp b/source/maths/Fixed.cpp index c0adbb98e3..8f19729c48 100644 --- a/source/maths/Fixed.cpp +++ b/source/maths/Fixed.cpp @@ -58,8 +58,8 @@ CFixed_15_16 CFixed_15_16::FromString(const CStr8& s) else if (*c == '.') { ++c; - u32 frac = 0; - u32 div = 1; + std::uint32_t frac = 0; + std::uint32_t div = 1; // Fractional part while (*c >= '0' && *c <= '9') { @@ -99,7 +99,7 @@ CStr8 CFixed_15_16::ToString() const char buffer[16]; PS::StringBuilder builder({std::begin(buffer), std::end(buffer)}); - u32 posvalue = abs(value); + std::uint32_t posvalue = abs(value); if (value < 0) builder.Append('-'); @@ -110,8 +110,8 @@ CStr8 CFixed_15_16::ToString() const { builder.Append('.'); - u32 frac = 0; - u32 div = 1; + std::uint32_t frac = 0; + std::uint32_t div = 1; // Do the inverse of FromString: Keep adding digits until (frac<<16)/div == expected fraction while (true) @@ -120,7 +120,7 @@ CStr8 CFixed_15_16::ToString() const div *= 10; // Low estimate of d such that ((frac+d)<<16)/div == fraction - u32 digit = (((u64)fraction*div) >> 16) - frac; + std::uint32_t digit = (((u64)fraction*div) >> 16) - frac; frac += digit; // If this gives the exact target, then add the digit and stop diff --git a/source/maths/Fixed.h b/source/maths/Fixed.h index aeb42e0f84..de031cdd59 100644 --- a/source/maths/Fixed.h +++ b/source/maths/Fixed.h @@ -83,7 +83,7 @@ class CStrW; debug_warn(underflowWarning); #define CheckU32CastOverflow(var, targetType, overflowWarning) \ - if(var > (u32)std::numeric_limits::max()) \ + if(var > static_cast(std::numeric_limits::max())) \ debug_warn(overflowWarning); #define CheckUnsignedAdditionOverflow(result, operand, overflowWarning) \ @@ -359,7 +359,7 @@ public: { if (value <= 0) return CFixed(0); - u32 s = isqrt64((u64)value << fract_bits); + std::uint32_t s = isqrt64((u64)value << fract_bits); return CFixed(s); } diff --git a/source/maths/FixedVector2D.h b/source/maths/FixedVector2D.h index 556ffab0ae..2c5bda9fba 100644 --- a/source/maths/FixedVector2D.h +++ b/source/maths/FixedVector2D.h @@ -107,7 +107,7 @@ public: u64 d2 = xx + yy; CheckUnsignedAdditionOverflow(d2, xx, L"Overflow in CFixedVector2D::Length() part 1") - u32 d = isqrt64(d2); + std::uint32_t d = isqrt64(d2); CheckU32CastOverflow(d, std::int32_t, L"Overflow in CFixedVector2D::Length() part 2") fixed r; diff --git a/source/maths/FixedVector3D.h b/source/maths/FixedVector3D.h index c87a18441c..9a86b2b7f0 100644 --- a/source/maths/FixedVector3D.h +++ b/source/maths/FixedVector3D.h @@ -92,7 +92,7 @@ public: u64 d2 = t + zz; CheckUnsignedAdditionOverflow(d2, t, L"Overflow in CFixedVector3D::Length() part 2") - u32 d = isqrt64(d2); + std::uint32_t d = isqrt64(d2); CheckU32CastOverflow(d, std::int32_t, L"Overflow in CFixedVector3D::Length() part 3") fixed r; diff --git a/source/maths/MD5.cpp b/source/maths/MD5.cpp index f0d7348be4..5e8537313b 100644 --- a/source/maths/MD5.cpp +++ b/source/maths/MD5.cpp @@ -51,7 +51,7 @@ void MD5::UpdateRest(const std::uint8_t* data, size_t len) len -= n; // Flush the (now full) buffer - Transform((const u32*)m_Buf); // assumes little-endian + Transform(reinterpret_cast(m_Buf)); // assumes little-endian // Process whole chunks of the input while (len >= CHUNK_SIZE) @@ -59,9 +59,9 @@ void MD5::UpdateRest(const std::uint8_t* data, size_t len) #if defined(__ARM_ARCH_7A__) // Avoid SIGBUS on alignment-sensitive architecture memcpy(m_Buf, data, CHUNK_SIZE); - Transform((const u32*)m_Buf); + Transform(reinterpret_cast(m_Buf)); #else - Transform((const u32*)data); // assumes little-endian; ignores alignment + Transform(reinterpret_cast(data)); // assumes little-endian; ignores alignment #endif data += CHUNK_SIZE; len -= CHUNK_SIZE; @@ -102,7 +102,7 @@ void MD5::Final(std::uint8_t* digest) #define rotlFixed(x, y) (((x) << (y)) | ((x) >> (32 - (y)))) // TODO: Crypto++ has an overload using _lrotl on MSVC - is that worthwhile? -void MD5::Transform(const u32* in) +void MD5::Transform(const std::uint32_t* in) { #define F1(x, y, z) (z ^ (x & (y ^ z))) #define F2(x, y, z) F1(z, x, y) @@ -112,10 +112,10 @@ void MD5::Transform(const u32* in) #define MD5STEP(f, w, x, y, z, data, s) \ t = w + f(x, y, z) + data; w = rotlFixed(t, s) + x - u32* digest = m_Digest; + std::uint32_t* digest = m_Digest; - u32 a, b, c, d; - u32 t; + std::uint32_t a, b, c, d; + std::uint32_t t; a = digest[0]; b = digest[1]; diff --git a/source/maths/MD5.h b/source/maths/MD5.h index e1a6c7704f..8da13d9eb1 100644 --- a/source/maths/MD5.h +++ b/source/maths/MD5.h @@ -65,8 +65,8 @@ public: private: void InitState(); void UpdateRest(const std::uint8_t* data, size_t len); - void Transform(const u32* in); - u32 m_Digest[4]; // internal state + void Transform(const std::uint32_t* in); + std::uint32_t m_Digest[4]; // internal state 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/Sqrt.cpp b/source/maths/Sqrt.cpp index b63a2df1f0..2493fd8cca 100644 --- a/source/maths/Sqrt.cpp +++ b/source/maths/Sqrt.cpp @@ -20,7 +20,7 @@ #include "Sqrt.h" // Based on http://freaknet.org/martin/tape/gos/misc/personal/msc/sqrt/sqrt.html -u32 isqrt64(u64 n) +std::uint32_t isqrt64(u64 n) { u64 op = n; u64 res = 0; @@ -39,10 +39,10 @@ u32 isqrt64(u64 n) res >>= 1; one >>= 2; } - return (u32)res; + return static_cast(res); } -// TODO: This should be equivalent to (u32)sqrt((double)n), and in practice +// TODO: This should be equivalent to static_cast(sqrt((double)n)), and in practice // that seems to be true for all input, so do we actually need this integer-only // implementation? i.e. are there any platforms / compiler settings where // sqrt(double) won't give the correct answer? and is sqrt(double) faster? diff --git a/source/maths/Sqrt.h b/source/maths/Sqrt.h index 6685e08626..14efc4a59c 100644 --- a/source/maths/Sqrt.h +++ b/source/maths/Sqrt.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,6 +24,6 @@ * 64-bit integer square root. * Returns r such that r^2 <= n < (r+1)^2, for the complete u64 range. */ -u32 isqrt64(u64 n); +std::uint32_t isqrt64(u64 n); #endif // INCLUDED_MATH_SQRT diff --git a/source/maths/tests/test_Sqrt.h b/source/maths/tests/test_Sqrt.h index d396b85114..f3d7ea670c 100644 --- a/source/maths/tests/test_Sqrt.h +++ b/source/maths/tests/test_Sqrt.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 @@ -27,7 +27,7 @@ class TestSqrt : public CxxTest::TestSuite { public: - void t(u32 n) + void t(std::uint32_t n) { TS_ASSERT_EQUALS(isqrt64((u64)n*(u64)n), n); } diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index 636296fdf0..dffad3afba 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -62,7 +62,7 @@ * Since commands are sent client -> server -> client, divide by 2. * (duplicated in NetServer.cpp to avoid having to fetch the constants in a header file) */ -constexpr u32 NETWORK_BAD_PING = DEFAULT_TURN_LENGTH * COMMAND_DELAY_MP / 2; +constexpr std::uint32_t NETWORK_BAD_PING = DEFAULT_TURN_LENGTH * COMMAND_DELAY_MP / 2; CNetClient *g_NetClient = NULL; @@ -343,7 +343,7 @@ void CNetClient::CheckServerConnection() m_LastConnectionCheck = now; // Report if we are losing the connection to the server - u32 lastReceived = m_Session->GetLastReceivedTime(); + std::uint32_t lastReceived = m_Session->GetLastReceivedTime(); if (lastReceived > NETWORK_WARNING_TIMEOUT) { PushGuiMessage( @@ -354,7 +354,7 @@ void CNetClient::CheckServerConnection() } // Report if we have a bad ping to the server. - u32 meanRTT = m_Session->GetMeanRTT(); + std::uint32_t meanRTT = m_Session->GetMeanRTT(); if (meanRTT > NETWORK_BAD_PING) { PushGuiMessage( @@ -466,7 +466,7 @@ void CNetClient::HandleConnect() Update((uint)NMT_CONNECT_COMPLETE, NULL); } -void CNetClient::HandleDisconnect(u32 reason) +void CNetClient::HandleDisconnect(std::uint32_t reason) { if (reason == NDR_INCORRECT_SOFTWARE_VERSION) { const auto& mismatch = CheckHandshake(m_ServerHandshake, CreateHandshake()); @@ -604,7 +604,7 @@ bool CNetClient::HandleMessage(CNetMessage* message) std::stringstream stream; LOGMESSAGERENDER("Serializing game at turn %u for rejoining player", m_ClientTurnManager->GetCurrentTurn()); - u32 turn = to_le32(m_ClientTurnManager->GetCurrentTurn()); + std::uint32_t turn = to_le32(m_ClientTurnManager->GetCurrentTurn()); stream.write((char*)&turn, sizeof(turn)); bool ok = m_Game->GetSimulation2()->SerializeState(stream); @@ -634,7 +634,7 @@ void CNetClient::LoadFinished() std::stringstream stream(m_JoinSyncBuffer); - u32 turn; + std::uint32_t turn; stream.read((char*)&turn, sizeof(turn)); turn = to_le32(turn); diff --git a/source/network/NetClient.h b/source/network/NetClient.h index c6e7cd20cd..521e86b8b5 100644 --- a/source/network/NetClient.h +++ b/source/network/NetClient.h @@ -20,7 +20,6 @@ #include "lib/code_annotation.h" #include "lib/external_libraries/enet.h" -#include "lib/types.h" #include "network/FSM.h" #include "network/NetHost.h" #include "network/NetMessage.h" @@ -191,7 +190,7 @@ public: /** * Call when the network connection has been lost. */ - void HandleDisconnect(u32 reason); + void HandleDisconnect(std::uint32_t reason); /** * Call when a message has been received from the network. @@ -336,7 +335,7 @@ private: CNetClientTurnManager* m_ClientTurnManager{nullptr}; /// Unique-per-game identifier of this client, used to identify the sender of simulation commands - u32 m_HostID{static_cast(-1)}; + std::uint32_t m_HostID{static_cast(-1)}; /// True if the player is currently rejoining or has already rejoined the game. bool m_Rejoin{false}; diff --git a/source/network/NetClientSession.cpp b/source/network/NetClientSession.cpp index 6c242eaba6..a5af893e29 100644 --- a/source/network/NetClientSession.cpp +++ b/source/network/NetClientSession.cpp @@ -205,7 +205,7 @@ bool CNetClientSession::SendMessage(const CNetMessage* message) return true; } -u32 CNetClientSession::GetLastReceivedTime() const +std::uint32_t CNetClientSession::GetLastReceivedTime() const { if (!m_Server) return 0; @@ -213,7 +213,7 @@ u32 CNetClientSession::GetLastReceivedTime() const return m_LastReceivedTime; } -u32 CNetClientSession::GetMeanRTT() const +std::uint32_t CNetClientSession::GetMeanRTT() const { if (!m_Server) return 0; diff --git a/source/network/NetClientSession.h b/source/network/NetClientSession.h index d89cfe9053..a814978205 100644 --- a/source/network/NetClientSession.h +++ b/source/network/NetClientSession.h @@ -20,7 +20,6 @@ #include "lib/code_annotation.h" #include "lib/external_libraries/enet.h" -#include "lib/types.h" #include "network/NetFileTransfer.h" #include "network/NetHost.h" @@ -82,12 +81,12 @@ public: /** * Number of milliseconds since the most recent packet of the server was received. */ - u32 GetLastReceivedTime() const; + std::uint32_t GetLastReceivedTime() const; /** * Average round trip time to the server. */ - u32 GetMeanRTT() const; + std::uint32_t GetMeanRTT() const; CNetFileTransferer& GetFileTransferer() { return m_FileTransferer; } private: @@ -117,8 +116,8 @@ private: bool m_WasConnected{false}; // Wrapper around enet stats - those are atomic as the code is lock-free. - std::atomic m_LastReceivedTime{0}; - std::atomic m_MeanRTT{0}; + std::atomic m_LastReceivedTime{0}; + std::atomic m_MeanRTT{0}; // If this is true, calling Connect() or deleting the session is an error. std::atomic m_LoopRunning{false}; diff --git a/source/network/NetFileTransfer.cpp b/source/network/NetFileTransfer.cpp index e984b1f078..dbd58c9c87 100644 --- a/source/network/NetFileTransfer.cpp +++ b/source/network/NetFileTransfer.cpp @@ -151,7 +151,7 @@ Status CNetFileTransferer::OnFileTransferAck(const CFileTransferAckMessage& mess void CNetFileTransferer::StartTask(RequestType requestType, std::function task) { - u32 requestID = m_NextRequestID++; + std::uint32_t requestID = m_NextRequestID++; m_FileReceiveTasks.emplace(requestID, AsyncFileReceiveTask{std::move(task)}); @@ -161,7 +161,7 @@ void CNetFileTransferer::StartTask(RequestType requestType, std::function& p : m_FileSendTasks) + for (std::pair& p : m_FileSendTasks) { CNetFileSendTask& task = p.second; diff --git a/source/network/NetFileTransfer.h b/source/network/NetFileTransfer.h index 6b57b3dd3c..ba39ed7e39 100644 --- a/source/network/NetFileTransfer.h +++ b/source/network/NetFileTransfer.h @@ -20,7 +20,6 @@ #include "lib/alignment.h" #include "lib/status.h" -#include "lib/types.h" #include "ps/Future.h" #include @@ -83,7 +82,7 @@ public: * (Callers are expected to have their own mechanism for receiving * requests and deciding what to respond with.) */ - void StartResponse(u32 requestID, const std::string& data); + void StartResponse(std::uint32_t requestID, const std::string& data); /** * Call frequently (e.g. once per frame) to trigger any necessary @@ -101,7 +100,7 @@ private: */ struct CNetFileSendTask { - u32 requestID; + std::uint32_t requestID; std::string buffer; size_t offset; size_t maxWindowSize; @@ -111,7 +110,7 @@ private: std::function m_SendMessage; - u32 m_NextRequestID{1}; + std::uint32_t m_NextRequestID{1}; struct AsyncFileReceiveTask @@ -128,10 +127,10 @@ private: std::string buffer; }; - using FileReceiveTasksMap = std::unordered_map; + using FileReceiveTasksMap = std::unordered_map; FileReceiveTasksMap m_FileReceiveTasks; - using FileSendTasksMap = std::map; + using FileSendTasksMap = std::map; FileSendTasksMap m_FileSendTasks; double m_LastProgressReportTime{0}; diff --git a/source/network/NetMessage.h b/source/network/NetMessage.h index 492f70c5ef..24434675df 100644 --- a/source/network/NetMessage.h +++ b/source/network/NetMessage.h @@ -19,7 +19,6 @@ #define NETMESSAGE_H #include "lib/code_annotation.h" -#include "lib/types.h" #include "network/Serialization.h" #include "ps/CStr.h" @@ -124,8 +123,8 @@ class CSimulationMessage : public CNetMessage { public: CSimulationMessage(const Script::Interface& scriptInterface); - CSimulationMessage(const Script::Interface& scriptInterface, u32 client, std::int32_t player, - u32 turn, JS::HandleValue data); + CSimulationMessage(const Script::Interface& scriptInterface, std::uint32_t client, + std::int32_t player, std::uint32_t turn, JS::HandleValue data); /** The compiler can't create a copy constructor because of the PersistentRooted member, * so we have to write it manually. @@ -138,7 +137,7 @@ public: virtual size_t GetSerializedLength() const; virtual CStr ToString() const; - u32 m_Client; + std::uint32_t m_Client; std::int32_t m_Player; std::int32_t m_Turn; JS::PersistentRooted m_Data; diff --git a/source/network/NetMessageSim.cpp b/source/network/NetMessageSim.cpp index 3f75ef7fc1..86c774feff 100644 --- a/source/network/NetMessageSim.cpp +++ b/source/network/NetMessageSim.cpp @@ -20,7 +20,6 @@ #include "NetMessage.h" #include "lib/code_annotation.h" -#include "lib/types.h" #include "network/NetMessage.h" #include "ps/CStr.h" #include "scriptinterface/JSON.h" @@ -123,8 +122,8 @@ CSimulationMessage::CSimulationMessage(const Script::Interface& scriptInterface) m_Data.init(rq.cx); } -CSimulationMessage::CSimulationMessage(const Script::Interface& scriptInterface, u32 client, - std::int32_t player, u32 turn, JS::HandleValue data) : +CSimulationMessage::CSimulationMessage(const Script::Interface& scriptInterface, std::uint32_t client, + std::int32_t player, std::uint32_t turn, JS::HandleValue data) : CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), m_Client(client), m_Player(player), m_Turn(turn) { diff --git a/source/network/NetMessages.h b/source/network/NetMessages.h index f5e6861d03..1d2538e6b3 100644 --- a/source/network/NetMessages.h +++ b/source/network/NetMessages.h @@ -104,8 +104,8 @@ enum AuthenticateResultCode START_NMTS() START_NMT_CLASS_(SrvHandshake, NMT_SERVER_HANDSHAKE) - NMT_FIELD_INT(m_Magic, u32, 4) - NMT_FIELD_INT(m_ProtocolVersion, u32, 4) + NMT_FIELD_INT(m_Magic, std::uint32_t, 4) + NMT_FIELD_INT(m_ProtocolVersion, std::uint32_t, 4) NMT_FIELD(CStr, m_EngineVersion) NMT_START_ARRAY(m_EnabledMods) NMT_FIELD(CStr, m_Name) @@ -114,8 +114,8 @@ START_NMT_CLASS_(SrvHandshake, NMT_SERVER_HANDSHAKE) END_NMT_CLASS() START_NMT_CLASS_(CliHandshake, NMT_CLIENT_HANDSHAKE) - NMT_FIELD_INT(m_MagicResponse, u32, 4) - NMT_FIELD_INT(m_ProtocolVersion, u32, 4) + NMT_FIELD_INT(m_MagicResponse, std::uint32_t, 4) + NMT_FIELD_INT(m_ProtocolVersion, std::uint32_t, 4) NMT_FIELD(CStr, m_EngineVersion) NMT_START_ARRAY(m_EnabledMods) NMT_FIELD(CStr, m_Name) @@ -124,8 +124,8 @@ START_NMT_CLASS_(CliHandshake, NMT_CLIENT_HANDSHAKE) END_NMT_CLASS() START_NMT_CLASS_(SrvHandshakeResponse, NMT_SERVER_HANDSHAKE_RESPONSE) - NMT_FIELD_INT(m_UseProtocolVersion, u32, 4) - NMT_FIELD_INT(m_Flags, u32, 4) + NMT_FIELD_INT(m_UseProtocolVersion, std::uint32_t, 4) + NMT_FIELD_INT(m_Flags, std::uint32_t, 4) NMT_FIELD(CStr, m_GUID) END_NMT_CLASS() @@ -136,8 +136,8 @@ START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE) 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_Code, std::uint32_t, 4) + NMT_FIELD_INT(m_HostID, std::uint32_t, 2) NMT_FIELD_INT(m_IsController, std::uint8_t, 1) NMT_FIELD(CStrW, m_Message) END_NMT_CLASS() @@ -169,22 +169,22 @@ END_NMT_CLASS() START_NMT_CLASS_(FileTransferRequest, NMT_FILE_TRANSFER_REQUEST) NMT_FIELD_INT(m_RequestType, std::int8_t, 1) - NMT_FIELD_INT(m_RequestID, u32, 4) + NMT_FIELD_INT(m_RequestID, std::uint32_t, 4) END_NMT_CLASS() START_NMT_CLASS_(FileTransferResponse, NMT_FILE_TRANSFER_RESPONSE) - NMT_FIELD_INT(m_RequestID, u32, 4) - NMT_FIELD_INT(m_Length, u32, 4) + NMT_FIELD_INT(m_RequestID, std::uint32_t, 4) + NMT_FIELD_INT(m_Length, std::uint32_t, 4) END_NMT_CLASS() START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA) - NMT_FIELD_INT(m_RequestID, u32, 4) + NMT_FIELD_INT(m_RequestID, std::uint32_t, 4) NMT_FIELD(CStr, m_Data) END_NMT_CLASS() START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK) - NMT_FIELD_INT(m_RequestID, u32, 4) - NMT_FIELD_INT(m_NumPackets, u32, 4) + NMT_FIELD_INT(m_RequestID, std::uint32_t, 4) + NMT_FIELD_INT(m_NumPackets, std::uint32_t, 4) END_NMT_CLASS() START_NMT_CLASS_(JoinSyncStart, NMT_JOIN_SYNC_START) @@ -209,13 +209,13 @@ END_NMT_CLASS() START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT) NMT_FIELD(CStr, m_GUID) - NMT_FIELD_INT(m_LastReceivedTime, u32, 4) + NMT_FIELD_INT(m_LastReceivedTime, std::uint32_t, 4) END_NMT_CLASS() START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE) NMT_START_ARRAY(m_Clients) NMT_FIELD(CStr, m_GUID) - NMT_FIELD_INT(m_MeanRTT, u32, 4) + NMT_FIELD_INT(m_MeanRTT, std::uint32_t, 4) NMT_END_ARRAY() END_NMT_CLASS() @@ -244,7 +244,7 @@ END_NMT_CLASS() START_NMT_CLASS_(EndCommandBatch, NMT_END_COMMAND_BATCH) NMT_FIELD_INT(m_Turn, std::int32_t, 4) - NMT_FIELD_INT(m_TurnLength, u32, 2) + NMT_FIELD_INT(m_TurnLength, std::uint32_t, 2) END_NMT_CLASS() START_NMT_CLASS_(SyncCheck, NMT_SYNC_CHECK) diff --git a/source/network/NetProtocol.h b/source/network/NetProtocol.h index 7faa82b721..dea84e03d2 100644 --- a/source/network/NetProtocol.h +++ b/source/network/NetProtocol.h @@ -30,7 +30,7 @@ /** * Report the peer if we didn't receive a packet after this time (milliseconds). */ -inline constexpr u32 NETWORK_WARNING_TIMEOUT{2000}; +inline constexpr std::uint32_t NETWORK_WARNING_TIMEOUT{2000}; struct HandshakeError { diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index f2b7689d47..c429d2c5c9 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -99,7 +99,7 @@ static const int HOST_SERVICE_TIMEOUT = 50; * Since commands are sent client -> server -> client, divide by 2. * (duplicated in NetServer.cpp to avoid having to fetch the constants in a header file) */ -constexpr u32 NETWORK_BAD_PING = DEFAULT_TURN_LENGTH * COMMAND_DELAY_MP / 2; +constexpr std::uint32_t NETWORK_BAD_PING = DEFAULT_TURN_LENGTH * COMMAND_DELAY_MP / 2; CNetServer* g_NetServer = NULL; @@ -419,7 +419,7 @@ bool CNetServerWorker::RunStep() std::vector newStartGame; std::vector> newLobbyAuths; - std::vector newTurnLength; + std::vector newTurnLength; { std::lock_guard lock(m_WorkerMutex); @@ -561,8 +561,8 @@ void CNetServerWorker::CheckClientConnections() for (size_t i = 0; i < m_Sessions.size(); ++i) { - u32 lastReceived = m_Sessions[i]->GetLastReceivedTime(); - u32 meanRTT = m_Sessions[i]->GetMeanRTT(); + std::uint32_t lastReceived = m_Sessions[i]->GetLastReceivedTime(); + std::uint32_t meanRTT = m_Sessions[i]->GetMeanRTT(); CNetMessage* message = nullptr; @@ -797,7 +797,7 @@ void CNetServerWorker::KickPlayer(const CStrW& playerName, const bool ban) m_BannedPlayers.push_back(m_LobbyAuth ? CStrW(playerName.substr(0, playerName.find(L" ("))) : playerName); // Remember IP address - u32 ipAddress = (*it)->GetIPAddress(); + std::uint32_t ipAddress = (*it)->GetIPAddress(); if (std::find(m_BannedIPs.begin(), m_BannedIPs.end(), ipAddress) == m_BannedIPs.end()) m_BannedIPs.push_back(ipAddress); } @@ -856,7 +856,7 @@ const Script::Interface& CNetServerWorker::GetScriptInterface() return *m_ScriptInterface; } -void CNetServerWorker::SetTurnLength(u32 msecs) +void CNetServerWorker::SetTurnLength(std::uint32_t msecs) { if (m_ServerTurnManager) m_ServerTurnManager->SetTurnLength(msecs); @@ -1077,7 +1077,7 @@ bool CNetServerWorker::OnAuthenticate(CNetServerSession* session, CFsmEventSetUserName(username); session->SetHostID(newHostID); @@ -1733,7 +1733,7 @@ void CNetServer::OnLobbyAuth(const CStr& name, const CStr& token) m_Worker.m_LobbyAuthQueue.push_back(std::make_pair(name, token)); } -void CNetServer::SetTurnLength(u32 msecs) +void CNetServer::SetTurnLength(std::uint32_t msecs) { std::lock_guard lock(m_Worker.m_WorkerMutex); m_Worker.m_TurnLengthQueue.push_back(msecs); diff --git a/source/network/NetServer.h b/source/network/NetServer.h index c22b7fe94f..776d071916 100644 --- a/source/network/NetServer.h +++ b/source/network/NetServer.h @@ -20,7 +20,6 @@ #include "lib/code_annotation.h" #include "lib/config2.h" -#include "lib/types.h" #include "network/NetHost.h" #include "ps/CStr.h" @@ -182,7 +181,7 @@ private: * Set the turn length to a fixed value. * TODO: we should replace this with some adaptive lag-dependent computation. */ - void SetTurnLength(u32 msecs); + void SetTurnLength(std::uint32_t msecs); void ProcessLobbyAuth(const CStr& name, const CStr& token); @@ -272,7 +271,7 @@ private: CStrW m_ServerName{L"Unnamed Server"}; - std::vector m_BannedIPs; + std::vector m_BannedIPs; std::vector m_BannedPlayers; CStr m_Password; @@ -282,7 +281,7 @@ private: */ std::vector m_PausingPlayers; - u32 m_NextHostID{1}; + std::uint32_t m_NextHostID{1}; std::unique_ptr m_ServerTurnManager; @@ -343,7 +342,7 @@ private: // Queues for messages sent by the game thread (protected by m_WorkerMutex): std::vector m_StartGameQueue; std::vector> m_LobbyAuthQueue; - std::vector m_TurnLengthQueue; + std::vector m_TurnLengthQueue; }; /** @@ -369,7 +368,7 @@ public: * Set the turn length to a fixed value. * TODO: we should replace this with some adapative lag-dependent computation. */ - void SetTurnLength(u32 msecs); + void SetTurnLength(std::uint32_t msecs); bool UseLobbyAuth() const; diff --git a/source/network/NetServerSession.cpp b/source/network/NetServerSession.cpp index 4bd1793420..e9eb0466d5 100644 --- a/source/network/NetServerSession.cpp +++ b/source/network/NetServerSession.cpp @@ -30,12 +30,12 @@ CNetServerSession::CNetServerSession(CNetServerWorker& server, ENetPeer* peer) : { } -u32 CNetServerSession::GetIPAddress() const +std::uint32_t CNetServerSession::GetIPAddress() const { return m_Peer->address.host; } -u32 CNetServerSession::GetLastReceivedTime() const +std::uint32_t CNetServerSession::GetLastReceivedTime() const { if (!m_Peer) return 0; @@ -43,7 +43,7 @@ u32 CNetServerSession::GetLastReceivedTime() const return enet_time_get() - m_Peer->lastReceiveTime; } -u32 CNetServerSession::GetMeanRTT() const +std::uint32_t CNetServerSession::GetMeanRTT() const { if (!m_Peer) return 0; diff --git a/source/network/NetServerSession.h b/source/network/NetServerSession.h index 635e33b252..59ee1603b8 100644 --- a/source/network/NetServerSession.h +++ b/source/network/NetServerSession.h @@ -50,20 +50,20 @@ public: const CStrW& GetUserName() const { return m_UserName; } void SetUserName(const CStrW& name) { m_UserName = name; } - u32 GetHostID() const { return m_HostID; } - void SetHostID(u32 id) { m_HostID = id; } + std::uint32_t GetHostID() const { return m_HostID; } + void SetHostID(std::uint32_t id) { m_HostID = id; } - u32 GetIPAddress() const; + std::uint32_t GetIPAddress() const; /** * Number of milliseconds since the latest packet of that client was received. */ - u32 GetLastReceivedTime() const; + std::uint32_t GetLastReceivedTime() const; /** * Average round trip time to the client. */ - u32 GetMeanRTT() const; + std::uint32_t GetMeanRTT() const; /** * Sends a disconnection notification to the client, @@ -96,7 +96,7 @@ private: CStr m_GUID; CStrW m_UserName; - u32 m_HostID{0}; + std::uint32_t m_HostID{0}; CStr m_Password; }; diff --git a/source/network/NetServerTurnManager.cpp b/source/network/NetServerTurnManager.cpp index 2a90ec1d1f..0d21495c01 100644 --- a/source/network/NetServerTurnManager.cpp +++ b/source/network/NetServerTurnManager.cpp @@ -47,7 +47,7 @@ CNetServerTurnManager::CNetServerTurnManager(CNetServerWorker& server) m_SavedTurnLengths.push_back(0); // Turns [1..COMMAND_DELAY - 1] are special: all clients run them without waiting on a server command batch. // Because of this, they are always run with the default MP turn length. - for (u32 i = 1; i < COMMAND_DELAY_MP; ++i) + for (std::uint32_t i = 1; i < COMMAND_DELAY_MP; ++i) m_SavedTurnLengths.push_back(m_TurnLength); } @@ -224,12 +224,12 @@ void CNetServerTurnManager::UninitialiseClient(int client) } } -void CNetServerTurnManager::SetTurnLength(u32 msecs) +void CNetServerTurnManager::SetTurnLength(std::uint32_t msecs) { m_TurnLength = msecs; } -u32 CNetServerTurnManager::GetSavedTurnLength(turn_id_t turn) +std::uint32_t CNetServerTurnManager::GetSavedTurnLength(turn_id_t turn) { ENSURE(turn <= m_ReadyTurn); return m_SavedTurnLengths.at(static_cast(turn)); diff --git a/source/network/NetServerTurnManager.h b/source/network/NetServerTurnManager.h index a686781dbe..26643c2b8f 100644 --- a/source/network/NetServerTurnManager.h +++ b/source/network/NetServerTurnManager.h @@ -19,7 +19,6 @@ #define INCLUDED_NETSERVERTURNMANAGER #include "lib/code_annotation.h" -#include "lib/types.h" #include "ps/CStr.h" #include "simulation2/helpers/SimulationCommand.h" @@ -60,7 +59,7 @@ public: */ void UninitialiseClient(int client); - void SetTurnLength(u32 msecs); + void SetTurnLength(std::uint32_t msecs); /** * Returns the latest turn for which all clients are ready; @@ -72,7 +71,7 @@ public: * Returns the turn length that was used for the given turn. * Requires turn <= GetReadyTurn(). */ - u32 GetSavedTurnLength(turn_id_t turn); + std::uint32_t GetSavedTurnLength(turn_id_t turn); private: void CheckClientsReady(); @@ -100,10 +99,10 @@ private: turn_id_t m_ReadyTurn; // Current turn length - u32 m_TurnLength; + std::uint32_t m_TurnLength; // Turn lengths for all previously executed turns - std::vector m_SavedTurnLengths; + std::vector m_SavedTurnLengths; CNetServerWorker& m_NetServer; }; diff --git a/source/network/StringConverters.h b/source/network/StringConverters.h index 14709ad54f..b61e86773b 100644 --- a/source/network/StringConverters.h +++ b/source/network/StringConverters.h @@ -18,12 +18,11 @@ #ifndef INCLUDED_NETWORK_STRINGCONVERTERS #define INCLUDED_NETWORK_STRINGCONVERTERS -#include "lib/types.h" #include "ps/CStr.h" #include -static inline CStr NetMessageStringConvert(u32 arg) +static inline CStr NetMessageStringConvert(std::uint32_t arg) { return std::to_string(arg); } diff --git a/source/network/StunClient.cpp b/source/network/StunClient.cpp index 5a978b0d08..8731599869 100644 --- a/source/network/StunClient.cpp +++ b/source/network/StunClient.cpp @@ -44,9 +44,9 @@ namespace StunClient /** * These constants are defined in Section 6 of RFC 5389. */ -const u32 m_MagicCookie = 0x2112A442; +const std::uint32_t m_MagicCookie = 0x2112A442; const std::uint16_t m_MethodTypeBinding = 0x01; -const u32 m_BindingSuccessResponse = 0x0101; +const std::uint32_t m_BindingSuccessResponse = 0x0101; /** * Bit determining whether comprehension of an attribute is optional. @@ -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, std::uint32_t& offset, T& result) { if (offset + n > buffer.size()) return false; @@ -129,7 +129,7 @@ void SendStunRequest(ENetHost& transactionHost, ENetAddress addr) std::vector buffer; AddToBuffer(buffer, m_MethodTypeBinding); AddToBuffer(buffer, 0); // length - AddToBuffer(buffer, m_MagicCookie); + AddToBuffer(buffer, m_MagicCookie); for (std::size_t i = 0; i < sizeof(m_TransactionID); ++i) { @@ -220,7 +220,7 @@ bool ReceiveStunResponse(ENetHost& transactionHost, std::vector& b bool ParseStunResponse(const std::vector& buffer) { - u32 offset = 0; + std::uint32_t offset = 0; std::uint16_t responseType = 0; if (!GetFromBuffer(buffer, offset, responseType) || responseType != m_BindingSuccessResponse) @@ -232,7 +232,7 @@ bool ParseStunResponse(const std::vector& buffer) // Ignore message size offset += 2; - u32 cookie = 0; + std::uint32_t cookie = 0; if (!GetFromBuffer(buffer, offset, cookie) || cookie != m_MagicCookie) { LOGERROR("STUN response doesn't contain the magic cookie"); @@ -285,7 +285,7 @@ bool ParseStunResponse(const std::vector& buffer) } std::uint16_t port = 0; - u32 ip = 0; + std::uint32_t ip = 0; if (!GetFromBuffer(buffer, offset, port) || !GetFromBuffer(buffer, offset, ip)) { diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index 782814e3bb..f72f7a9841 100644 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -82,7 +82,7 @@ namespace // CStr8 is always serialized to / from ASCII(or whatever 8 - bit codepage stored // in the CStr). size_t len = str.length(); - Serialize_int_4(buffer, (u32)len); + Serialize_int_4(buffer, static_cast(len)); size_t i = 0; for (i = 0; i < len; i++) buffer[i] = str[i]; @@ -114,7 +114,7 @@ namespace ENSURE(bufferend); if constexpr (std::is_same_v) { - u32 len; + std::uint32_t len; Deserialize_int_4(buffer, len); if (buffer + len > bufferend) return NULL; diff --git a/source/ps/CStrIntern.cpp b/source/ps/CStrIntern.cpp index 9b20e64bb2..39d8f25384 100644 --- a/source/ps/CStrIntern.cpp +++ b/source/ps/CStrIntern.cpp @@ -45,7 +45,7 @@ public: } const std::string data; - const u32 hash; // fnv_hash of data + const std::uint32_t hash; // fnv_hash of data private: CStrInternInternals& operator=(const CStrInternInternals&); @@ -135,7 +135,7 @@ CStrIntern::CStrIntern(const std::string_view str) m = GetString(str.data(), str.length()); } -u32 CStrIntern::GetHash() const +std::uint32_t CStrIntern::GetHash() const { return m->hash; } diff --git a/source/ps/CStrIntern.h b/source/ps/CStrIntern.h index ef345ec41b..becb8924f0 100644 --- a/source/ps/CStrIntern.h +++ b/source/ps/CStrIntern.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,8 +18,6 @@ #ifndef INCLUDED_CSTRINTERN #define INCLUDED_CSTRINTERN -#include "lib/types.h" - #include #include #include @@ -51,7 +49,7 @@ public: /** * Returns cached FNV1-A hash of the string. */ - u32 GetHash() const; + std::uint32_t GetHash() const; /** * Returns null-terminated string. diff --git a/source/ps/CacheLoader.cpp b/source/ps/CacheLoader.cpp index 17df18fa4c..c27fd80f61 100644 --- a/source/ps/CacheLoader.cpp +++ b/source/ps/CacheLoader.cpp @@ -34,7 +34,8 @@ CCacheLoader::CCacheLoader(PIVFS vfs, const std::wstring& fileExtension) : { } -Status CCacheLoader::TryLoadingCached(const VfsPath& sourcePath, const MD5& initialHash, u32 version, VfsPath& loadPath) +Status CCacheLoader::TryLoadingCached(const VfsPath& sourcePath, const MD5& initialHash, + std::uint32_t version, VfsPath& loadPath) { VfsPath archiveCachePath = ArchiveCachePath(sourcePath); @@ -119,7 +120,7 @@ VfsPath CCacheLoader::ArchiveCachePath(const VfsPath& sourcePath) const return sourcePath.ChangeExtension(std::wstring{sourcePath.Extension()} + L".cached" + m_FileExtension); } -VfsPath CCacheLoader::LooseCachePath(const VfsPath& sourcePath, const MD5& initialHash, u32 version) +VfsPath CCacheLoader::LooseCachePath(const VfsPath& sourcePath, const MD5& initialHash, std::uint32_t version) { CFileInfo fileInfo; if (m_VFS->GetFileInfo(sourcePath, &fileInfo) < 0) diff --git a/source/ps/CacheLoader.h b/source/ps/CacheLoader.h index c77d3a24ea..b10c90fc33 100644 --- a/source/ps/CacheLoader.h +++ b/source/ps/CacheLoader.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.h" #include "lib/file/vfs/vfs_path.h" #include "lib/status.h" -#include "lib/types.h" #include @@ -53,7 +52,8 @@ public: * Returns INFO::SKIPPED and sets loadPath to the desire loose cache name if there isn't one. * Returns a value < 0 on error (e.g. the source file doesn't exist). No error is logged or thrown. */ - Status TryLoadingCached(const VfsPath& sourcePath, const MD5& initialHash, u32 version, VfsPath& loadPath); + Status TryLoadingCached(const VfsPath& sourcePath, const MD5& initialHash, + std::uint32_t version, VfsPath& loadPath); /** * Determines whether we can safely use the archived cache file, or need to @@ -69,7 +69,7 @@ public: /** * Return the path of the loose cache for the given source file. */ - VfsPath LooseCachePath(const VfsPath& sourcePath, const MD5& initialHash, u32 version); + VfsPath LooseCachePath(const VfsPath& sourcePath, const MD5& initialHash, std::uint32_t version); private: PIVFS m_VFS; diff --git a/source/ps/ConfigDB.cpp b/source/ps/ConfigDB.cpp index 170bd7b33a..e51f51ee0e 100644 --- a/source/ps/ConfigDB.cpp +++ b/source/ps/ConfigDB.cpp @@ -131,7 +131,7 @@ std::string EscapeString(const CStr& str) } GETVAL(bool) GETVAL(int) -GETVAL(u32) +GETVAL(std::uint32_t) GETVAL(float) GETVAL(double) GETVAL(std::string) diff --git a/source/ps/ConfigDB.h b/source/ps/ConfigDB.h index 62dcf2d6a0..d644768f83 100644 --- a/source/ps/ConfigDB.h +++ b/source/ps/ConfigDB.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 @@ -28,7 +28,6 @@ #define INCLUDED_CONFIGDB #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "ps/CStr.h" #include @@ -89,7 +88,7 @@ public: ///@copydoc CConfigDB::GetValue void GetValue(EConfigNamespace ns, const std::string_view name, int& value); ///@copydoc CConfigDB::GetValue - void GetValue(EConfigNamespace ns, const std::string_view name, u32& value); + void GetValue(EConfigNamespace ns, const std::string_view name, std::uint32_t& value); ///@copydoc CConfigDB::GetValue void GetValue(EConfigNamespace ns, const std::string_view name, float& value); ///@copydoc CConfigDB::GetValue diff --git a/source/ps/Errors.h b/source/ps/Errors.h index 3b3084c7f7..9bd466e36a 100644 --- a/source/ps/Errors.h +++ b/source/ps/Errors.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 @@ -70,11 +70,9 @@ plus a few extra things for converting between error codes and exceptions. */ -#include "lib/types.h" - #include -typedef u32 PSRETURN; +typedef std::uint32_t PSRETURN; class PSERROR : public std::exception { diff --git a/source/ps/FileIo.cpp b/source/ps/FileIo.cpp index dccc579fcf..92c19f65f3 100644 --- a/source/ps/FileIo.cpp +++ b/source/ps/FileIo.cpp @@ -41,8 +41,8 @@ struct FileHeader { char magic[4]; - u32 version_le; - u32 payloadSize_le; // = file size - sizeof(FileHeader) + std::uint32_t version_le; + std::uint32_t payloadSize_le; // = file size - sizeof(FileHeader) }; cassert(sizeof(FileHeader) == 12); @@ -52,7 +52,7 @@ cassert(sizeof(FileHeader) == 12); //----------------------------------------------------------------------------- // CFilePacker -CFilePacker::CFilePacker(u32 version, const char magic[4]) +CFilePacker::CFilePacker(std::uint32_t version, const char magic[4]) { // put header in our data array. // (its payloadSize_le will be updated on every Pack*() call) @@ -72,7 +72,7 @@ CFilePacker::~CFilePacker() void CFilePacker::Write(const VfsPath& filename) { const size_t payloadSize = m_writeBuffer.Size() - sizeof(FileHeader); - const u32 payloadSize_le = to_le32(u32_from_larger(payloadSize)); + const std::uint32_t payloadSize_le = to_le32(u32_from_larger(payloadSize)); m_writeBuffer.Overwrite(&payloadSize_le, sizeof(payloadSize_le), 0+offsetof(FileHeader, payloadSize_le)); // write out all data (including header) @@ -92,7 +92,7 @@ void CFilePacker::PackRaw(const void* rawData, size_t rawSize) void CFilePacker::PackSize(size_t value) { - const u32 value_le32 = to_le32(u32_from_larger(value)); + const std::uint32_t value_le32 = to_le32(u32_from_larger(value)); PackRaw(&value_le32, sizeof(value_le32)); } @@ -171,7 +171,7 @@ void CFileUnpacker::UnpackRaw(void* rawData, size_t rawDataSize) size_t CFileUnpacker::UnpackSize() { - u32 value_le32; + std::uint32_t value_le32; UnpackRaw(&value_le32, sizeof(value_le32)); return (size_t)to_le32(value_le32); } diff --git a/source/ps/FileIo.h b/source/ps/FileIo.h index f4b32534ed..d3e88f0c4c 100644 --- a/source/ps/FileIo.h +++ b/source/ps/FileIo.h @@ -33,7 +33,6 @@ #include "lib/allocators/shared_ptr.h" #include "lib/file/io/write_buffer.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "ps/Errors.h" #include @@ -63,7 +62,7 @@ public: * this means Write() can write the entire buffer to file in one go, * which is simpler and more efficient than writing in pieces. **/ - CFilePacker(u32 version, const char magic[4]); + CFilePacker(std::uint32_t version, const char magic[4]); ~CFilePacker(); @@ -81,7 +80,7 @@ public: /** * convenience: convert a number (almost always a size type) to - * little-endian u32 and pack that. + * little-endian std::uint32_t and pack that. **/ void PackSize(size_t value); @@ -118,7 +117,7 @@ public: /** * @return version number that was stored in the file's header. **/ - u32 GetVersion() const + std::uint32_t GetVersion() const { return m_version; } @@ -149,7 +148,7 @@ private: size_t m_bufSize; size_t m_unpackPos; /// current unpack position in stream - u32 m_version; /// version that was stored in the file header + std::uint32_t m_version; /// version that was stored in the file header }; #endif diff --git a/source/ps/GUID.cpp b/source/ps/GUID.cpp index 3d9a597639..1981359ae8 100644 --- a/source/ps/GUID.cpp +++ b/source/ps/GUID.cpp @@ -19,7 +19,6 @@ #include "lib/code_annotation.h" #include "lib/secure_crt.h" #include "lib/sysdep/sysdep.h" -#include "lib/types.h" #include "ps/CStr.h" #include @@ -36,7 +35,7 @@ CStr ps_generate_guid(void) CStr guid; for (size_t i = 0; i < 2; ++i) { - u32 r = 0; + std::uint32_t r = 0; sys_generate_random_bytes(reinterpret_cast(&r), sizeof(r)); char buf[32]; sprintf_s(buf, ARRAY_SIZE(buf), "%08X", r); diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index eb30de3a16..b296db34a9 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -147,14 +147,14 @@ int CGame::LoadVisualReplayData() CReplayTurnManager* replayTurnMgr = static_cast(GetTurnManager()); - u32 currentTurn = 0; + std::uint32_t currentTurn = 0; std::string type; while ((*m_ReplayStream >> type).good()) { if (type == "turn") { - u32 turn = 0; - u32 turnLength = 0; + std::uint32_t turn = 0; + std::uint32_t turnLength = 0; *m_ReplayStream >> turn >> turnLength; ENSURE(turn == currentTurn && "You tried to replay a commands.txt file of a rejoined client. Please use the host's file."); replayTurnMgr->StoreReplayTurnLength(currentTurn, turnLength); diff --git a/source/ps/Game.h b/source/ps/Game.h index d10e3b3dd1..6ba54be50c 100644 --- a/source/ps/Game.h +++ b/source/ps/Game.h @@ -20,7 +20,6 @@ #include "lib/code_annotation.h" #include "lib/os_path.h" -#include "lib/types.h" #include "ps/CStr.h" #include "ps/Errors.h" #include "simulation2/helpers/Player.h" @@ -233,7 +232,7 @@ private: OsPath m_ReplayPath; bool m_IsVisualReplay; std::istream* m_ReplayStream; - u32 m_FinalReplayTurn; + std::uint32_t m_FinalReplayTurn; }; extern CGame *g_Game; diff --git a/source/ps/GameSetup/HWDetect.cpp b/source/ps/GameSetup/HWDetect.cpp index bfa7f9f09e..dac2783f34 100644 --- a/source/ps/GameSetup/HWDetect.cpp +++ b/source/ps/GameSetup/HWDetect.cpp @@ -35,7 +35,6 @@ #include "lib/sysdep/os_cpu.h" #include "lib/sysdep/sysdep.h" // sys_OpenFile #include "lib/timer.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "ps/CStr.h" #include "ps/Errors.h" @@ -431,23 +430,23 @@ void RunHardwareDetection(bool writeSystemInfoBeforeDetection, Renderer::Backend Script::SetProperty(rq, settings, "cpu_identifier", std::string(cpu_IdentifierString())); Script::SetProperty(rq, settings, "cpu_frequency", os_cpu_ClockFrequency()); - Script::SetProperty(rq, settings, "cpu_pagesize", (u32)os_cpu_PageSize()); - Script::SetProperty(rq, settings, "cpu_largepagesize", (u32)os_cpu_LargePageSize()); - Script::SetProperty(rq, settings, "cpu_numprocs", (u32)os_cpu_NumProcessors()); + Script::SetProperty(rq, settings, "cpu_pagesize", static_cast(os_cpu_PageSize())); + Script::SetProperty(rq, settings, "cpu_largepagesize", static_cast(os_cpu_LargePageSize())); + Script::SetProperty(rq, settings, "cpu_numprocs", static_cast(os_cpu_NumProcessors())); - Script::SetProperty(rq, settings, "numa_numnodes", (u32)numa_NumNodes()); + Script::SetProperty(rq, settings, "numa_numnodes", static_cast(numa_NumNodes())); Script::SetProperty(rq, settings, "numa_factor", numa_Factor()); Script::SetProperty(rq, settings, "numa_interleaved", numa_IsMemoryInterleaved()); - Script::SetProperty(rq, settings, "ram_total", (u32)os_cpu_MemorySize()); - Script::SetProperty(rq, settings, "ram_total_os", (u32)os_cpu_QueryMemorySize()); + Script::SetProperty(rq, settings, "ram_total", static_cast(os_cpu_MemorySize())); + Script::SetProperty(rq, settings, "ram_total_os", static_cast(os_cpu_QueryMemorySize())); #if ARCH_X86_X64 - Script::SetProperty(rq, settings, "x86_vendor", (u32)x86_x64::Vendor()); - Script::SetProperty(rq, settings, "x86_model", (u32)x86_x64::Model()); - Script::SetProperty(rq, settings, "x86_family", (u32)x86_x64::Family()); + Script::SetProperty(rq, settings, "x86_vendor", static_cast(x86_x64::Vendor())); + Script::SetProperty(rq, settings, "x86_model", static_cast(x86_x64::Model())); + Script::SetProperty(rq, settings, "x86_family", static_cast(x86_x64::Family())); - u32 caps0, caps1, caps2, caps3; + std::uint32_t caps0, caps1, caps2, caps3; x86_x64::GetCapBits(&caps0, &caps1, &caps2, &caps3); Script::SetProperty(rq, settings, "x86_caps[0]", caps0); Script::SetProperty(rq, settings, "x86_caps[1]", caps1); diff --git a/source/ps/ModIo.cpp b/source/ps/ModIo.cpp index 3bea09d8b4..49f1ccfb3a 100644 --- a/source/ps/ModIo.cpp +++ b/source/ps/ModIo.cpp @@ -327,7 +327,7 @@ void ModIo::StartListMods() m_DownloadProgressData.status = DownloadProgressStatus::LISTING; } -void ModIo::StartDownloadMod(u32 idx) +void ModIo::StartDownloadMod(std::uint32_t idx) { // Don't start such a request during active downloads. if (m_DownloadProgressData.status == DownloadProgressStatus::GAMEID || @@ -646,7 +646,7 @@ bool ModIo::ParseGameIdResponse(const Script::Interface& scriptInterface, const FAIL("data property not an object."); JS::RootedObject data(rq.cx, dataVal.toObjectOrNull()); - u32 length; + std::uint32_t length; bool isArray; if (!JS::IsArrayObject(rq.cx, data, &isArray) || !isArray || !JS::GetArrayLength(rq.cx, data, &length) || !length) FAIL("data property not an array with at least one element."); @@ -714,7 +714,7 @@ bool ModIo::ParseModsResponse(const Script::Interface& scriptInterface, const st FAIL("data property not an object."); JS::RootedObject rData(rq.cx, dataVal.toObjectOrNull()); - u32 length; + std::uint32_t length; bool isArray; if (!JS::IsArrayObject(rq.cx, rData, &isArray) || !isArray || !JS::GetArrayLength(rq.cx, rData, &length) || !length) FAIL("data property not an array with at least one element."); @@ -729,7 +729,7 @@ bool ModIo::ParseModsResponse(const Script::Interface& scriptInterface, const st continue;\ } - for (u32 i = 0; i < length; ++i) + for (std::uint32_t i = 0; i < length; ++i) { modData.emplace_back(); ModIoModData& data = modData.back(); diff --git a/source/ps/ModIo.h b/source/ps/ModIo.h index 4cc7403ce7..f3511062a7 100644 --- a/source/ps/ModIo.h +++ b/source/ps/ModIo.h @@ -26,7 +26,6 @@ #include "lib/code_annotation.h" #include "lib/external_libraries/curl.h" #include "lib/os_path.h" -#include "lib/types.h" #include #include @@ -139,7 +138,7 @@ public: // Async requests void StartGetGameId(); void StartListMods(); - void StartDownloadMod(u32 idx); + void StartDownloadMod(std::uint32_t idx); /** * Advance the current async request and perform final steps if the download is complete. diff --git a/source/ps/Profiler2.cpp b/source/ps/Profiler2.cpp index 647eacf66a..e98ce25fa3 100644 --- a/source/ps/Profiler2.cpp +++ b/source/ps/Profiler2.cpp @@ -266,11 +266,11 @@ CProfiler2::ThreadStorage::~ThreadStorage() delete[] m_Buffer; } -void CProfiler2::ThreadStorage::Write(EItem type, const void* item, u32 itemSize) +void CProfiler2::ThreadStorage::Write(EItem type, const void* item, std::uint32_t itemSize) { // See RingBufferSpan for comments on synchronisation - u32 size = 1 + itemSize; + std::uint32_t size = 1 + itemSize; std::uint32_t start{m_ValidRange.begin.load()}; if (start + size > BUFFER_SIZE) { @@ -336,12 +336,12 @@ void CProfiler2::ThreadStorage::RecordAttribute(const char* fmt, va_list argp) } // this flattens the stack, use it sensibly -void rewriteBuffer(std::uint8_t* buffer, u32& bufferSize) +void rewriteBuffer(std::uint8_t* buffer, std::uint32_t& bufferSize) { double startTime = timer_Time(); - u32 size = bufferSize; - u32 readPos = 0; + std::uint32_t size = bufferSize; + std::uint32_t readPos = 0; double initialTime = -1; double total_time = -1; @@ -462,7 +462,7 @@ void rewriteBuffer(std::uint8_t* buffer, u32& bufferSize) case CProfiler2::ITEM_ATTRIBUTE: { // skip for now - u32 len; + std::uint32_t len; memcpy(&len, buffer + readPos, sizeof(len)); ENSURE(len <= CProfiler2::MAX_ATTRIBUTE_LENGTH); readPos += sizeof(len); @@ -490,7 +490,7 @@ void rewriteBuffer(std::uint8_t* buffer, u32& bufferSize) // rewrite the buffer // what we rewrite will always be smaller than the current buffer's size - u32 writePos = 0; + std::uint32_t writePos = 0; double curTime = initialTime; // the region enter { @@ -519,7 +519,7 @@ void rewriteBuffer(std::uint8_t* buffer, u32& bufferSize) if (time_attrib != time_per_attribute.end()) basic = fmt::format("{} {}us", basic, 1000000 * time_attrib->second); - u32 length = static_cast(basic.size()); + std::uint32_t length = static_cast(basic.size()); memcpy(buffer + writePos, &length, sizeof(length)); writePos += sizeof(length); memcpy(buffer + writePos, basic.c_str(), length); @@ -557,7 +557,7 @@ void rewriteBuffer(std::uint8_t* buffer, u32& bufferSize) buffer[writePos] = static_cast(CProfiler2::ITEM_ATTRIBUTE); writePos++; - u32 length = sizeof("buffer overflow"); + std::uint32_t length = sizeof("buffer overflow"); memcpy(buffer + writePos, &length, sizeof(length)); writePos += sizeof(length); memcpy(buffer + writePos, "buffer overflow", length); @@ -608,9 +608,10 @@ void RunBufferVisitor(const std::string& buffer, V& visitor) // so scan forwards until we find a sync marker. // (This is probably pretty inefficient.) - u32 realStart = (u32)-1; // the start point decided by the scan algorithm + std::uint32_t realStart = static_cast(-1); // the start point decided by the scan algorithm - for (u32 start = 0; start + 1 + sizeof(CProfiler2::RESYNC_MAGIC) <= buffer.length(); ++start) + for (std::uint32_t start = 0; start + 1 + sizeof(CProfiler2::RESYNC_MAGIC) <= buffer.length(); + ++start) { if (buffer[start] == CProfiler2::ITEM_SYNC && memcmp(buffer.c_str() + start + 1, &CProfiler2::RESYNC_MAGIC, sizeof(CProfiler2::RESYNC_MAGIC)) == 0) @@ -620,9 +621,9 @@ void RunBufferVisitor(const std::string& buffer, V& visitor) } } - ENSURE(realStart != (u32)-1); // we should have found a sync point somewhere in the buffer + ENSURE(realStart != static_cast(-1)); // we should have found a sync point somewhere in the buffer - u32 pos = realStart; // the position as we step through the buffer + std::uint32_t pos = realStart; // the position as we step through the buffer double lastTime = -1; // set to non-negative by EVENT_SYNC; we ignore all items before that @@ -688,7 +689,7 @@ void RunBufferVisitor(const std::string& buffer, V& visitor) } case CProfiler2::ITEM_ATTRIBUTE: { - u32 len; + std::uint32_t len; memcpy(&len, buffer.c_str()+pos, sizeof(len)); ENSURE(len <= CProfiler2::MAX_ATTRIBUTE_LENGTH); pos += sizeof(len); diff --git a/source/ps/Profiler2.h b/source/ps/Profiler2.h index cc3939cfff..d4b353103f 100644 --- a/source/ps/Profiler2.h +++ b/source/ps/Profiler2.h @@ -81,7 +81,6 @@ #include "lib/code_annotation.h" #include "lib/debug.h" #include "lib/timer.h" -#include "lib/types.h" #include "ps/ThreadUtil.h" #include @@ -210,9 +209,9 @@ private: /** * Store an item into the buffer. */ - void Write(EItem type, const void* item, u32 itemSize); + void Write(EItem type, const void* item, std::uint32_t itemSize); - void WriteHold(EItem type, const void* item, u32 itemSize); + void WriteHold(EItem type, const void* item, std::uint32_t itemSize); CProfiler2& m_Profiler; std::string m_Name; diff --git a/source/ps/Profiler2GPU.cpp b/source/ps/Profiler2GPU.cpp index 8149c09df7..5ae717be6f 100644 --- a/source/ps/Profiler2GPU.cpp +++ b/source/ps/Profiler2GPU.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 "Profiler2GPU.h" #include "lib/debug.h" -#include "lib/types.h" #include "ps/ConfigDB.h" #include "ps/Profiler2.h" #include "ps/VideoMode.h" @@ -57,7 +56,7 @@ class CProfiler2GPUImpl struct SFrame { - u32 num; + std::uint32_t num; double syncTimeStart; // CPU time at start of this frame. diff --git a/source/ps/Replay.cpp b/source/ps/Replay.cpp index c5ff813797..9247662190 100644 --- a/source/ps/Replay.cpp +++ b/source/ps/Replay.cpp @@ -92,7 +92,7 @@ void CReplayLogger::StartGame(JS::MutableHandleValue attribs) *m_Stream << "start " << Script::StringifyJSON(rq, attribs, false) << "\n"; } -void CReplayLogger::Turn(u32 n, u32 turnLength, std::vector& commands) +void CReplayLogger::Turn(std::uint32_t n, std::uint32_t turnLength, std::vector& commands) { Script::Request rq(m_ScriptInterface); @@ -206,8 +206,8 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest g_ScriptContext = std::make_shared(contextSize, heapGrowthBytesGCTrigger); std::vector commands; - u32 turn = 0; - u32 turnLength = 0; + std::uint32_t turn = 0; + std::uint32_t turnLength = 0; { std::string type; diff --git a/source/ps/Replay.h b/source/ps/Replay.h index b6e1152a71..520d1f899a 100644 --- a/source/ps/Replay.h +++ b/source/ps/Replay.h @@ -20,7 +20,6 @@ #include "lib/code_annotation.h" #include "lib/os_path.h" -#include "lib/types.h" #include #include @@ -51,7 +50,7 @@ public: /** * Run the given turn with the given collection of player commands. */ - virtual void Turn(u32 n, u32 turnLength, std::vector& commands) = 0; + virtual void Turn(std::uint32_t n, std::uint32_t turnLength, std::vector& commands) = 0; /** * Optional hash of simulation state (for sync checking). @@ -76,7 +75,8 @@ class CDummyReplayLogger : public IReplayLogger { public: virtual void StartGame(JS::MutableHandleValue /*attribs*/) { } - virtual void Turn(u32 /*n*/, u32 /*turnLength*/, std::vector&) { } + virtual void Turn(std::uint32_t /*n*/, std::uint32_t /*turnLength*/, std::vector&) + {} virtual void Hash(const std::string& /*hash*/, bool /*quick*/) { } virtual void SaveMetadata(const CSimulation2&) { }; virtual OsPath GetDirectory() const { return OsPath(); } @@ -93,7 +93,7 @@ public: ~CReplayLogger(); virtual void StartGame(JS::MutableHandleValue attribs); - virtual void Turn(u32 n, u32 turnLength, std::vector& commands); + virtual void Turn(std::uint32_t n, std::uint32_t turnLength, std::vector& commands); virtual void Hash(const std::string& hash, bool quick); virtual void SaveMetadata(const CSimulation2& simulation); virtual OsPath GetDirectory() const; diff --git a/source/ps/VisualReplay.cpp b/source/ps/VisualReplay.cpp index 6f73e13f90..d6a2cdbbfb 100644 --- a/source/ps/VisualReplay.cpp +++ b/source/ps/VisualReplay.cpp @@ -138,7 +138,7 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const Script::Interface& script Script::Request rq(scriptInterface); // Maps the filename onto the index, mtime and size - using replayCacheMap = std::map>; + using replayCacheMap = std::map>; replayCacheMap fileList; @@ -146,9 +146,9 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const Script::Interface& script if (ReadCacheFile(scriptInterface, &cachedReplaysObject)) { // Create list of files included in the cache - u32 cacheLength = 0; + std::uint32_t cacheLength = 0; JS::GetArrayLength(rq.cx, cachedReplaysObject, &cacheLength); - for (u32 j = 0; j < cacheLength; ++j) + for (std::uint32_t j = 0; j < cacheLength; ++j) { JS::RootedValue replay(rq.cx); JS_GetElement(rq.cx, cachedReplaysObject, j, &replay); @@ -172,9 +172,9 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const Script::Interface& script return replays; bool newReplays = false; - std::vector copyFromOldCache; + std::vector copyFromOldCache; // Specifies where the next replay should be kept - u32 i = 0; + std::uint32_t i = 0; for (const OsPath& directory : directories) { @@ -241,7 +241,7 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const Script::Interface& script { // Copy the replays from the old cache that are not deleted if (!copyFromOldCache.empty()) - for (u32 j : copyFromOldCache) + for (std::uint32_t j : copyFromOldCache) { JS::RootedValue replay(rq.cx); JS_GetElement(rq.cx, cachedReplaysObject, j, &replay); @@ -261,9 +261,9 @@ JS::Value VisualReplay::GetReplays(const Script::Interface& scriptInterface, boo // Only take entries with data JS::RootedValueVector replaysWithoutNullEntries{rq.cx}; - u32 replaysLength = 0; + std::uint32_t replaysLength = 0; JS::GetArrayLength(rq.cx, replays, &replaysLength); - for (u32 j = 0; j < replaysLength; ++j) + for (std::uint32_t j = 0; j < replaysLength; ++j) { JS::RootedValue replay(rq.cx); JS_GetElement(rq.cx, replays, j, &replay); @@ -345,7 +345,7 @@ inline int getReplayDuration(std::istream* replayStream, const OsPath& fileName, // Found last turn, compute duration. if (currentPosition + 4 < fileSize && (*replayStream >> type).good() && type == "turn") { - u32 turn = 0, turnLength = 0; + std::uint32_t turn = 0, turnLength = 0; *replayStream >> turn >> turnLength; return (turn+1) * turnLength / 1000; // add +1 as turn numbers starts with 0 } @@ -411,7 +411,7 @@ JS::Value VisualReplay::LoadReplayData(const Script::Interface& scriptInterface, } // Don't process files of rejoined clients - u32 turn = 1; + std::uint32_t turn = 1; *replayStream >> turn; if (turn != 0) { @@ -489,7 +489,7 @@ void VisualReplay::AddReplayToCache(const Script::Interface& scriptInterface, co if (!ReadCacheFile(scriptInterface, &cachedReplaysObject)) cachedReplaysObject = JS::NewArrayObject(rq.cx, 0); - u32 cacheLength = 0; + std::uint32_t cacheLength = 0; JS::GetArrayLength(rq.cx, cachedReplaysObject, &cacheLength); JS_SetElement(rq.cx, cachedReplaysObject, cacheLength, replayData); diff --git a/source/ps/XMB/XMBData.cpp b/source/ps/XMB/XMBData.cpp index 26b28045f9..f9b1ac8fd3 100644 --- a/source/ps/XMB/XMBData.cpp +++ b/source/ps/XMB/XMBData.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 @@ #include "lib/debug.h" #include "lib/posix/posix.h" #include "lib/secure_crt.h" -#include "lib/types.h" #include "ps/XMB/XMBStorage.h" #include @@ -48,7 +47,7 @@ bool XMBData::Initialise(const XMBStorage& doc) return false; ENSURE(strcmp(Header, XMBStorage::HeaderMagicStr) == 0 && "Invalid XMB header!"); - u32 Version = read(m_Pointer); + std::uint32_t Version = read(m_Pointer); m_Pointer += 4; if (Version != XMBStorage::XMBVersion) return false; @@ -58,9 +57,9 @@ bool XMBData::Initialise(const XMBStorage& doc) // access, but it might crash on an invalid file, reading a couple of // billion random element names from RAM) - m_ElementPointer = start + read(m_Pointer); m_Pointer += 4; + m_ElementPointer = start + read(m_Pointer); m_Pointer += 4; m_ElementNameCount = read(m_Pointer); m_Pointer += 4; - m_AttributePointer = start + read(m_Pointer); m_Pointer += 4; + m_AttributePointer = start + read(m_Pointer); m_Pointer += 4; m_AttributeNameCount = read(m_Pointer); m_Pointer += 4; // At this point m_Pointer points to the element start, as expected. return true; // success diff --git a/source/ps/XMB/XMBData.h b/source/ps/XMB/XMBData.h index b3467cd18e..29b4acf871 100644 --- a/source/ps/XMB/XMBData.h +++ b/source/ps/XMB/XMBData.h @@ -28,7 +28,7 @@ Theoretical file structure: XMB_File { char Header[4]; // because everyone has one; currently "XMB0" - u32 Version; + std::uint32_t Version; int OffsetFromStartToElementNames; int ElementNameCount; diff --git a/source/ps/XMB/XMBStorage.cpp b/source/ps/XMB/XMBStorage.cpp index f4b0cb5095..1af51be5bd 100644 --- a/source/ps/XMB/XMBStorage.cpp +++ b/source/ps/XMB/XMBStorage.cpp @@ -46,7 +46,7 @@ const char* XMBStorage::HeaderMagicStr = "XMB0"; const char* XMBStorage::UnfinishedHeaderMagicStr = "XMBu"; // Arbitrary version number - change this if we update the code and // need to invalidate old users' caches -const u32 XMBStorage::XMBVersion = 4; +const std::uint32_t XMBStorage::XMBVersion = 4; namespace { @@ -95,7 +95,7 @@ void WriteStringAndLineNumber(WriteBuffer& writeBuffer, const std::string& text, else { // Write length and line number and null-terminated text - u32 nodeLen = u32(4 + text.length() + 1); + std::uint32_t nodeLen = static_cast(4 + text.length() + 1); writeBuffer.Append(&nodeLen, 4); writeBuffer.Append(&lineNumber, 4); writeBuffer.Append((void*)text.c_str(), nodeLen-4); @@ -120,7 +120,7 @@ bool XMBStorageWriter::Load(WriteBuffer& writeBuffer, Args&&... args) if (!OutputElements(writeBuffer, std::forward(args)...)) return false; - u32 data = writeBuffer.Size(); + std::uint32_t data = writeBuffer.Size(); writeBuffer.Overwrite(&data, 4, elementPtr); data = m_ElementIDs.size(); writeBuffer.Overwrite(&data, 4, elementPtr + 4); @@ -146,7 +146,7 @@ void XMBStorageWriter::OutputNames(WriteBuffer& writeBuffer, const std::unordere std::sort(orderedElements.begin(), orderedElements.end(), [](const auto& a, const auto&b) { return a.second < b.second; }); for (const std::pair& n : orderedElements) { - u32 textLen = (u32)n.first.length() + 1; + std::uint32_t textLen = static_cast(n.first.length()) + 1; writeBuffer.Append(&textLen, 4); writeBuffer.Append((void*)n.first.c_str(), textLen); } @@ -160,15 +160,16 @@ public: bool Setup(XMBStorageWriter& xmb, JS::HandleValue value); bool Output(WriteBuffer& writeBuffer, JS::HandleValue value) const; - std::vector> m_Attributes; - std::vector>> m_Children; + std::vector> m_Attributes; + std::vector>> m_Children; const Script::Interface& scriptInterface; const Script::Request rq; }; template<> -bool XMBStorageWriter::OutputElements(WriteBuffer& writeBuffer, JSNodeData& data, const u32& nodeName, JS::HandleValue&& value) +bool XMBStorageWriter::OutputElements( + WriteBuffer& writeBuffer, JSNodeData& data, const std::uint32_t& nodeName, JS::HandleValue&& value) { // Set up variables. if (!data.Setup(*this, value)) @@ -180,10 +181,10 @@ bool XMBStorageWriter::OutputElements(data.m_Attributes.size()); + std::uint32_t attrCount = static_cast(data.m_Attributes.size()); writeBuffer.Append(&attrCount, 4); - u32 childCount = data.m_Children.size(); + std::uint32_t childCount = data.m_Children.size(); writeBuffer.Append(&childCount, 4); // Filled in later with the offset to the list of child elements @@ -193,29 +194,29 @@ bool XMBStorageWriter::OutputElements attr : data.m_Attributes) + for (const std::pair attr : data.m_Attributes) { writeBuffer.Append(&attr.first, 4); - u32 attrLen = u32(attr.second.size())+1; + std::uint32_t attrLen = static_cast(attr.second.size()) + 1; writeBuffer.Append(&attrLen, 4); writeBuffer.Append((void*)attr.second.c_str(), attrLen); } // Go back and fill in the child-element offset - u32 childrenOffset = (u32)(writeBuffer.Size() - (posChildrenOffset+4)); + std::uint32_t childrenOffset = static_cast(writeBuffer.Size() - (posChildrenOffset+4)); writeBuffer.Overwrite(&childrenOffset, 4, posChildrenOffset); // Output all child elements, making a copy since data will be overwritten. - std::vector>> children = data.m_Children; - for (const std::pair>& child : children) + std::vector>> children = data.m_Children; + for (const std::pair>& child : children) { JS::RootedValue val(data.rq.cx, child.second); - if (!OutputElements(writeBuffer, data, child.first, val)) + if (!OutputElements(writeBuffer, data, child.first, val)) return false; } // Go back and fill in the length - u32 length = (u32)(writeBuffer.Size() - posLength); + std::uint32_t length = static_cast(writeBuffer.Size() - posLength); writeBuffer.Overwrite(&length, 4, posLength); return true; @@ -287,7 +288,7 @@ bool JSNodeData::Setup(XMBStorageWriter& xmb, JS::HandleValue value) // Parse each array object as a child. JS::RootedObject obj(rq.cx); JS_ValueToObject(rq.cx, child, &obj); - u32 length; + std::uint32_t length; JS::GetArrayLength(rq.cx, obj, &length); for (size_t i = 0; i < length; ++i) { @@ -353,15 +354,15 @@ bool XMBStorageWriter::OutputElements(WriteBuffer& writeBuffer, xm size_t posLength = writeBuffer.Size(); writeBuffer.Append("????", 4); - u32 name = GetElementName((const char*)node->name); + std::uint32_t name = GetElementName((const char*)node->name); writeBuffer.Append(&name, 4); - u32 attrCount = 0; + std::uint32_t attrCount = 0; for (xmlAttrPtr attr = node->properties; attr; attr = attr->next) ++attrCount; writeBuffer.Append(&attrCount, 4); - u32 childCount = 0; + std::uint32_t childCount = 0; for (xmlNodePtr child = node->children; child; child = child->next) if (child->type == XML_ELEMENT_NODE) ++childCount; @@ -388,7 +389,7 @@ bool XMBStorageWriter::OutputElements(WriteBuffer& writeBuffer, xm } } - u32 linenum = xmlGetLineNo(node); + std::uint32_t linenum = xmlGetLineNo(node); // Find the start of the non-whitespace section size_t first = text.find_first_not_of(whitespace); @@ -417,18 +418,19 @@ bool XMBStorageWriter::OutputElements(WriteBuffer& writeBuffer, xm // Output attributes for (xmlAttrPtr attr = node->properties; attr; attr = attr->next) { - u32 attrName = GetAttributeName((const char*)attr->name); + std::uint32_t attrName = GetAttributeName((const char*)attr->name); writeBuffer.Append(&attrName, 4); xmlChar* value = xmlNodeGetContent(attr->children); - u32 attrLen = u32(xmlStrlen(value)+1); + std::uint32_t attrLen = static_cast(xmlStrlen(value) + 1); writeBuffer.Append(&attrLen, 4); writeBuffer.Append((void*)value, attrLen); xmlFree(value); } // Go back and fill in the child-element offset - u32 childrenOffset = (u32)(writeBuffer.Size() - (posChildrenOffset+4)); + std::uint32_t childrenOffset = + static_cast(writeBuffer.Size() - (posChildrenOffset + 4)); writeBuffer.Overwrite(&childrenOffset, 4, posChildrenOffset); // Output all child elements @@ -437,7 +439,7 @@ bool XMBStorageWriter::OutputElements(WriteBuffer& writeBuffer, xm OutputElements(writeBuffer, std::move(child)); // Go back and fill in the length - u32 length = (u32)(writeBuffer.Size() - posLength); + std::uint32_t length = static_cast(writeBuffer.Size() - posLength); writeBuffer.Overwrite(&length, 4, posLength); return true; @@ -475,7 +477,7 @@ bool XMBStorage::LoadJSValue(const Script::Interface& scriptInterface, JS::Handl WriteBuffer writeBuffer; XMBStorageWriter writer; - const u32 name = writer.GetElementName(rootName); + const std::uint32_t name = writer.GetElementName(rootName); JSNodeData data(scriptInterface); if (!writer.Load(writeBuffer, data, name, std::move(value))) return false; diff --git a/source/ps/XMB/XMBStorage.h b/source/ps/XMB/XMBStorage.h index fa688393bd..865880b5d9 100644 --- a/source/ps/XMB/XMBStorage.h +++ b/source/ps/XMB/XMBStorage.h @@ -18,8 +18,6 @@ #ifndef INCLUDED_XMBSTORAGE #define INCLUDED_XMBSTORAGE -#include "lib/types.h" - #include #include #include @@ -46,7 +44,7 @@ public: // File headers, to make sure it doesn't try loading anything other than an XMB static const char* HeaderMagicStr; static const char* UnfinishedHeaderMagicStr; - static const u32 XMBVersion; + static const std::uint32_t XMBVersion; XMBStorage() = default; diff --git a/source/ps/tests/test_TaskManager.h b/source/ps/tests/test_TaskManager.h index 4b6c7c0a52..8495e8f0cb 100644 --- a/source/ps/tests/test_TaskManager.h +++ b/source/ps/tests/test_TaskManager.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 "ps/Future.h" #include "ps/TaskManager.h" @@ -89,20 +88,20 @@ public: #define ITERATIONS 100000 std::vector> futures; futures.resize(ITERATIONS); - std::vector values(ITERATIONS); + std::vector values(ITERATIONS); Future f1{g_TaskManager, [&futures]{ - for (u32 i = 0; i < ITERATIONS; i+=3) + for (std::uint32_t i = 0; i < ITERATIONS; i+=3) futures[i] = {g_TaskManager, []{ return 5; }}; }}; Future f2{g_TaskManager, [&futures]{ - for (u32 i = 1; i < ITERATIONS; i+=3) + for (std::uint32_t i = 1; i < ITERATIONS; i+=3) futures[i] = {g_TaskManager, []{ return 5; }, Threading::TaskPriority::LOW}; }}; Future f3{g_TaskManager, [&futures]{ - for (u32 i = 2; i < ITERATIONS; i+=3) + for (std::uint32_t i = 2; i < ITERATIONS; i+=3) futures[i] = {g_TaskManager, []{ return 5; }}; }}; diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 37b71a9581..c90bb2c90d 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -869,7 +869,9 @@ typename M::mapped_type& PooledPairGet(M& m, const typename M::key_type& k, PS:: } // Each multidraw batch has a list of index counts, and a list of pointers-to-first-indexes -using BatchElements = std::pair>, std::vector>>; +using BatchElements = std::pair< + std::vector>, + std::vector>>; // Group batches by index buffer using IndexBufferBatches = PooledBatchMap; @@ -1265,7 +1267,7 @@ void CPatchRData::RenderStreams( PROFILE3("render terrain streams"); // Each batch has a list of index counts, and a list of pointers-to-first-indexes - using StreamBatchElements = std::pair, std::vector>; + using StreamBatchElements = std::pair, std::vector>; // Group batches by index buffer using StreamIndexBufferBatches = std::map; diff --git a/source/renderer/VertexBufferManager.h b/source/renderer/VertexBufferManager.h index 7687670b00..1f9beea736 100644 --- a/source/renderer/VertexBufferManager.h +++ b/source/renderer/VertexBufferManager.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 @@ #ifndef INCLUDED_VERTEXBUFFERMANAGER #define INCLUDED_VERTEXBUFFERMANAGER -#include "lib/types.h" #include "renderer/VertexBuffer.h" #include "renderer/backend/IBuffer.h" @@ -41,7 +40,7 @@ class CVertexBufferManager public: CVertexBufferManager(Renderer::Backend::IDevice* device) : m_Device(device) {} - enum class Group : u32 + enum class Group : std::uint32_t { DEFAULT, TERRAIN, diff --git a/source/renderer/WaterManager.h b/source/renderer/WaterManager.h index 76b7f0ffbb..cbaa6fbb40 100644 --- a/source/renderer/WaterManager.h +++ b/source/renderer/WaterManager.h @@ -25,7 +25,6 @@ #include "graphics/Color.h" #include "graphics/Texture.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Matrix3D.h" #include "renderer/VertexBufferManager.h" @@ -78,10 +77,10 @@ public: std::unique_ptr m_RefrFboDepthTexture; // used to know what to update when updating parts of the terrain only. - u32 m_updatei0; - u32 m_updatej0; - u32 m_updatei1; - u32 m_updatej1; + std::uint32_t m_updatei0; + std::uint32_t m_updatej0; + std::uint32_t m_updatei1; + std::uint32_t m_updatej1; bool m_RenderWater; diff --git a/source/rlinterface/RLInterface.cpp b/source/rlinterface/RLInterface.cpp index a60d0e1ead..fa6f46126b 100644 --- a/source/rlinterface/RLInterface.cpp +++ b/source/rlinterface/RLInterface.cpp @@ -23,7 +23,6 @@ #include "gui/GUIManager.h" #include "lib/debug.h" -#include "lib/types.h" #include "network/HttpServer.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -339,7 +338,7 @@ void Interface::ApplyMessage(const GameMessage& msg) turnMgr->PostCommand(command.playerID, commandJSON); } - const u32 deltaRealTime = DEFAULT_TURN_LENGTH; + const std::uint32_t deltaRealTime = DEFAULT_TURN_LENGTH; if (nonVisual) { const double deltaSimTime = deltaRealTime * g_Game->GetSimRate(); diff --git a/source/scriptinterface/Conversions.cpp b/source/scriptinterface/Conversions.cpp index b93db26bf8..2bf903b680 100644 --- a/source/scriptinterface/Conversions.cpp +++ b/source/scriptinterface/Conversions.cpp @@ -77,7 +77,7 @@ template<> bool FromJSVal(const Request& rq, JS::HandleValue v, s return true; } -template<> bool FromJSVal(const Request& rq, JS::HandleValue v, u32& out) +template<> bool FromJSVal(const Request& rq, JS::HandleValue v, std::uint32_t& out) { FAIL_IF_NOT(v.isNumber(), v); if (!JS::ToUint32(rq.cx, v, &out)) @@ -221,7 +221,8 @@ template<> void ToJSVal(const Request&, JS::MutableHandleValue ret ret.set(JS::NumberValue(val)); } -template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, const u32& val) +template<> void ToJSVal(const Request&, JS::MutableHandleValue ret, + const std::uint32_t& val) { ret.set(JS::NumberValue(val)); } @@ -277,7 +278,7 @@ template<> void ToJSVal(const Request& rq, JS::MutableHandleValue ret, c // Instantiate various vector types: JSVAL_VECTOR(int) -JSVAL_VECTOR(u32) +JSVAL_VECTOR(std::uint32_t) JSVAL_VECTOR(std::uint16_t) JSVAL_VECTOR(std::string) JSVAL_VECTOR(std::wstring) diff --git a/source/scriptinterface/Conversions.h b/source/scriptinterface/Conversions.h index 12c9e83674..b07241d1e2 100644 --- a/source/scriptinterface/Conversions.h +++ b/source/scriptinterface/Conversions.h @@ -20,7 +20,6 @@ #include "lib/code_generation.h" #include "lib/debug.h" -#include "lib/types.h" #include "ps/CStr.h" #include "scriptinterface/Exceptions.h" #include "scriptinterface/Request.h" @@ -140,8 +139,8 @@ template inline void ToJSVal_vector(const Request& rq, JS::MutableHa return; } - ENSURE(val.size() <= std::numeric_limits::max()); - for (u32 i = 0; i < val.size(); ++i) + ENSURE(val.size() <= std::numeric_limits::max()); + for (std::uint32_t i = 0; i < val.size(); ++i) { JS::RootedValue el(rq.cx); ToJSVal(rq, &el, val[i]); @@ -163,13 +162,13 @@ template inline bool FromJSVal_vector(const Request& rq, JS::HandleV if ((!JS::IsArrayObject(rq.cx, obj, &isArray) || !isArray) && !JS_IsTypedArrayObject(obj)) FAIL("Argument must be an array"); - u32 length; + std::uint32_t length; if (!JS::GetArrayLength(rq.cx, obj, &length)) FAIL("Failed to get array length"); out.clear(); out.reserve(length); - for (u32 i = 0; i < length; ++i) + for (std::uint32_t i = 0; i < length; ++i) { JS::RootedValue el(rq.cx); if (!JS_GetElement(rq.cx, obj, i, &el)) diff --git a/source/scriptinterface/JSON.cpp b/source/scriptinterface/JSON.cpp index baef69c6ab..80bcd83599 100644 --- a/source/scriptinterface/JSON.cpp +++ b/source/scriptinterface/JSON.cpp @@ -21,7 +21,6 @@ #include "lib/file/vfs/vfs_path.h" #include "lib/status.h" -#include "lib/types.h" #include "lib/utf8.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -42,7 +41,7 @@ bool Script::ParseJSON(const Script::Request& rq, const std::string& string_utf8 { std::wstring attrsW = wstring_from_utf8(string_utf8); std::u16string string(attrsW.begin(), attrsW.end()); - if (JS_ParseJSON(rq.cx, string.c_str(), (u32)string.size(), out)) + if (JS_ParseJSON(rq.cx, string.c_str(), static_cast(string.size()), out)) return true; Script::Exception::CatchPending(rq); @@ -77,7 +76,7 @@ namespace { struct Stringifier { - static bool callback(const char16_t* buf, u32 len, void* data) + static bool callback(const char16_t* buf, std::uint32_t len, void* data) { std::u16string str(buf, buf+len); std::wstring strw(str.begin(), str.end()); diff --git a/source/scriptinterface/tests/test_ScriptConversions.h b/source/scriptinterface/tests/test_ScriptConversions.h index da28160351..d003297288 100644 --- a/source/scriptinterface/tests/test_ScriptConversions.h +++ b/source/scriptinterface/tests/test_ScriptConversions.h @@ -19,7 +19,6 @@ #include "lib/file/vfs/vfs.h" #include "lib/path.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/FixedVector3D.h" @@ -134,12 +133,12 @@ public: roundtrip(JSVAL_INT_MIN + 1, "-2147483647"); roundtrip(JSVAL_INT_MIN, "-2147483648"); - roundtrip(0, "0"); - roundtrip(123, "123"); - roundtrip(JSVAL_INT_MAX - 1, "2147483646"); - roundtrip(JSVAL_INT_MAX, "2147483647"); + roundtrip(0, "0"); + roundtrip(123, "123"); + roundtrip(JSVAL_INT_MAX - 1, "2147483646"); + roundtrip(JSVAL_INT_MAX, "2147483647"); - roundtrip(static_cast(JSVAL_INT_MAX) + 1, "2147483648"); + roundtrip(static_cast(JSVAL_INT_MAX) + 1, "2147483648"); std::string s1 = "test"; s1[1] = '\0'; @@ -192,10 +191,10 @@ public: TS_ASSERT(val3.isInt32()); TS_ASSERT(val4.isInt32()); - Script::ToJSVal(rq, &val5, 0); - Script::ToJSVal(rq, &val6, 2147483646u); // JSVAL_INT_MAX-1 - Script::ToJSVal(rq, &val7, 2147483647u); // JSVAL_INT_MAX - Script::ToJSVal(rq, &val8, 2147483648u); // JSVAL_INT_MAX+1 + Script::ToJSVal(rq, &val5, 0); + Script::ToJSVal(rq, &val6, 2147483646u); // JSVAL_INT_MAX-1 + Script::ToJSVal(rq, &val7, 2147483647u); // JSVAL_INT_MAX + Script::ToJSVal(rq, &val8, 2147483648u); // JSVAL_INT_MAX+1 TS_ASSERT(val5.isInt32()); TS_ASSERT(val6.isInt32()); TS_ASSERT(val7.isInt32()); diff --git a/source/simulation2/MessageTypes.h b/source/simulation2/MessageTypes.h index 8e24551338..4d6daa2ccf 100644 --- a/source/simulation2/MessageTypes.h +++ b/source/simulation2/MessageTypes.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_MESSAGETYPES #define INCLUDED_MESSAGETYPES -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/Vector3D.h" #include "ps/CStr.h" @@ -432,7 +431,7 @@ public: - u32 tag; + std::uint32_t tag; std::vector added; std::vector removed; @@ -444,10 +443,10 @@ public: CMessageRangeUpdate() { } - CMessageRangeUpdate(u32 tag) : tag(tag) + CMessageRangeUpdate(std::uint32_t tag) : tag(tag) { } - CMessageRangeUpdate(u32 tag, const std::vector& added, const std::vector& removed) + CMessageRangeUpdate(std::uint32_t tag, const std::vector& added, const std::vector& removed) : tag(tag), added(added), removed(removed) { } @@ -472,12 +471,12 @@ class CMessagePathResult final : public CMessage public: DEFAULT_MESSAGE_IMPL(PathResult) - CMessagePathResult(u32 ticket, const WaypointPath& path) : + CMessagePathResult(std::uint32_t ticket, const WaypointPath& path) : ticket(ticket), path(path) { } - u32 ticket; + std::uint32_t ticket; WaypointPath path; }; diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index ea36a5ab8f..92fce73ce5 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -28,7 +28,6 @@ #include "lib/path.h" #include "lib/sysdep/filesystem.h" #include "lib/timer.h" -#include "lib/types.h" #include "lib/utf8.h" #include "maths/Fixed.h" #include "maths/MathUtil.h" @@ -358,7 +357,7 @@ void CSimulation2Impl::ReportSerializationFailure( void CSimulation2Impl::InitRNGSeedSimulation() { - u32 seed = 0; + std::uint32_t seed = 0; Script::Request rq(m_ComponentManager.GetScriptInterface()); if (!Script::HasProperty(rq, m_MapSettings, "Seed") || !Script::GetProperty(rq, m_MapSettings, "Seed", seed)) @@ -369,7 +368,7 @@ void CSimulation2Impl::InitRNGSeedSimulation() void CSimulation2Impl::InitRNGSeedAI() { - u32 seed = 0; + std::uint32_t seed = 0; Script::Request rq(m_ComponentManager.GetScriptInterface()); if (!Script::HasProperty(rq, m_MapSettings, "AISeed") || !Script::GetProperty(rq, m_MapSettings, "AISeed", seed)) diff --git a/source/simulation2/components/CCmpAIManager.cpp b/source/simulation2/components/CCmpAIManager.cpp index ffc929c2c7..eb874ec179 100644 --- a/source/simulation2/components/CCmpAIManager.cpp +++ b/source/simulation2/components/CCmpAIManager.cpp @@ -29,7 +29,6 @@ #include "lib/os_path.h" #include "lib/path.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include "lib/utf8.h" #include "maths/FixedVector2D.h" #include "ps/CLogger.h" @@ -368,7 +367,8 @@ public: /** * Debug function for AI scripts to dump 2D array data (e.g. terrain tile weights). */ - void DumpImage(const std::wstring& name, const std::vector& data, u32 w, u32 h, u32 max) + void DumpImage(const std::wstring& name, const std::vector& data, std::uint32_t w, + std::uint32_t h, std::uint32_t max) { // TODO: this is totally not threadsafe. VfsPath filename = L"screenshots/aidump/" + name; @@ -403,7 +403,7 @@ public: tex_write(&t, filename); } - void SetRNGSeed(u32 seed) + void SetRNGSeed(std::uint32_t seed) { m_RNG.seed(seed); } @@ -561,9 +561,9 @@ public: ENSURE(JS_GetProperty(rq.cx, mapObj, "data", &mapData)); JS::RootedObject dataObj(rq.cx, &mapData.toObject()); - u32 length = 0; + std::uint32_t length = 0; ENSURE(JS::GetArrayLength(rq.cx, dataObj, &length)); - u32 nbytes = (u32)(length * sizeof(NavcellData)); + std::uint32_t nbytes = static_cast(length * sizeof(NavcellData)); bool sharedMemory; JS::AutoCheckCannotGC nogc; @@ -589,9 +589,9 @@ public: ENSURE(JS_GetProperty(rq.cx, mapObj, "data", &mapData)); JS::RootedObject dataObj(rq.cx, &mapData.toObject()); - u32 length = 0; + std::uint32_t length = 0; ENSURE(JS::GetArrayLength(rq.cx, dataObj, &length)); - u32 nbytes = (u32)(length * sizeof(std::uint8_t)); + std::uint32_t nbytes = static_cast(length * sizeof(std::uint8_t)); bool sharedMemory; JS::AutoCheckCannotGC nogc; @@ -682,7 +682,7 @@ public: serializer.NumberU8_Unbounded("difficulty", m_Players[i]->m_Difficulty); serializer.String("behavior", m_Players[i]->m_Behavior, 1, 256); - serializer.NumberU32_Unbounded("num commands", (u32)m_Players[i]->m_Commands.size()); + serializer.NumberU32_Unbounded("num commands", static_cast(m_Players[i]->m_Commands.size())); for (size_t j = 0; j < m_Players[i]->m_Commands.size(); ++j) { JS::RootedValue val(rq.cx); @@ -703,7 +703,7 @@ public: m_PassabilityMap.m_W*m_PassabilityMap.m_H*sizeof(NavcellData)); } - void Deserialize(std::istream& stream, u32 numAis) + void Deserialize(std::istream& stream, std::uint32_t numAis) { m_PlayerMetadata.clear(); m_Players.clear(); @@ -745,7 +745,7 @@ public: if (!AddPlayer(name, player, difficulty, behavior)) throw PSERROR_Deserialize_ScriptError(); - u32 numCommands; + std::uint32_t numCommands; deserializer.NumberU32_Unbounded("num commands", numCommands); m_Players.back()->m_Commands.reserve(numCommands); for (size_t j = 0; j < numCommands; ++j) @@ -838,7 +838,7 @@ private: std::shared_ptr m_ScriptInterface; boost::rand48 m_RNG; - u32 m_TurnNum; + std::uint32_t m_TurnNum; JS::PersistentRootedValue m_EntityTemplates; bool m_HasLoadedEntityTemplates; @@ -915,7 +915,7 @@ public: { Init(paramNode); - u32 numAis; + std::uint32_t numAis; deserialize.NumberU32_Unbounded("num ais", numAis); if (numAis > 0) LoadUsedEntityTemplates(); @@ -940,7 +940,7 @@ public: cmpRangeManager->SetLosRevealWholeMap(player, true); } - void SetRNGSeed(u32 seed) override + void SetRNGSeed(std::uint32_t seed) override { m_Worker.SetRNGSeed(seed); } diff --git a/source/simulation2/components/CCmpCommandQueue.cpp b/source/simulation2/components/CCmpCommandQueue.cpp index b40799aa3b..447c035997 100644 --- a/source/simulation2/components/CCmpCommandQueue.cpp +++ b/source/simulation2/components/CCmpCommandQueue.cpp @@ -19,7 +19,6 @@ #include "ICmpCommandQueue.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "ps/Game.h" #include "ps/Profiler2.h" @@ -68,7 +67,7 @@ public: { Script::Request rq(GetSimContext().GetScriptInterface()); - serialize.NumberU32_Unbounded("num commands", (u32)m_LocalQueue.size()); + serialize.NumberU32_Unbounded("num commands", static_cast(m_LocalQueue.size())); for (size_t i = 0; i < m_LocalQueue.size(); ++i) { serialize.NumberI32_Unbounded("player", m_LocalQueue[i].player); @@ -80,7 +79,7 @@ public: { Script::Request rq(GetSimContext().GetScriptInterface()); - u32 numCmds; + std::uint32_t numCmds; deserialize.NumberU32_Unbounded("num commands", numCmds); for (size_t i = 0; i < numCmds; ++i) { diff --git a/source/simulation2/components/CCmpObstructionManager.cpp b/source/simulation2/components/CCmpObstructionManager.cpp index daf0aed703..5335b78956 100644 --- a/source/simulation2/components/CCmpObstructionManager.cpp +++ b/source/simulation2/components/CCmpObstructionManager.cpp @@ -158,10 +158,10 @@ public: SpatialSubdivision m_StaticSubdivision; // TODO: using std::map is a bit inefficient; is there a better way to store these? - std::map m_UnitShapes; - std::map m_StaticShapes; - u32 m_UnitShapeNext; // next allocated id - u32 m_StaticShapeNext; + std::map m_UnitShapes; + std::map m_StaticShapes; + std::uint32_t m_UnitShapeNext; // next allocated id + std::uint32_t m_StaticShapeNext; entity_pos_t m_MaxClearance; @@ -280,14 +280,14 @@ public: m_UnitSubdivision.Reset(x1, z1, OBSTRUCTION_SUBDIVISION_SIZE); m_StaticSubdivision.Reset(x1, z1, OBSTRUCTION_SUBDIVISION_SIZE); - for (std::map::iterator it = m_UnitShapes.begin(); it != m_UnitShapes.end(); ++it) + for (auto it = m_UnitShapes.begin(); it != m_UnitShapes.end(); ++it) { CFixedVector2D center(it->second.x, it->second.z); CFixedVector2D halfSize(it->second.clearance, it->second.clearance); m_UnitSubdivision.Add(it->first, center - halfSize, center + halfSize); } - for (std::map::iterator it = m_StaticShapes.begin(); it != m_StaticShapes.end(); ++it) + for (auto it = m_StaticShapes.begin(); it != m_StaticShapes.end(); ++it) { CFixedVector2D center(it->second.x, it->second.z); CFixedVector2D bbHalfSize = Geometry::GetHalfBoundingBox(it->second.u, it->second.v, CFixedVector2D(it->second.hw, it->second.hh)); @@ -298,7 +298,7 @@ public: tag_t AddUnitShape(entity_id_t ent, entity_pos_t x, entity_pos_t z, entity_pos_t clearance, flags_t flags, entity_id_t group) override { UnitShape shape = { ent, x, z, clearance, flags, group }; - u32 id = m_UnitShapeNext++; + std::uint32_t id = m_UnitShapeNext++; m_UnitShapes[id] = shape; m_UnitSubdivision.Add(id, CFixedVector2D(x - clearance, z - clearance), CFixedVector2D(x + clearance, z + clearance)); @@ -316,7 +316,7 @@ public: CFixedVector2D v(s, c); StaticShape shape = { ent, x, z, u, v, w/2, h/2, flags, group, group2 }; - u32 id = m_StaticShapeNext++; + std::uint32_t id = m_StaticShapeNext++; m_StaticShapes[id] = shape; CFixedVector2D center(x, z); @@ -543,8 +543,8 @@ private: // Dynamic updates for the long-range pathfinder GridUpdateInformation m_UpdateInformations; // These vectors might contain shapes that were deleted - std::vector m_DirtyStaticShapes; - std::vector m_DirtyUnitShapes; + std::vector m_DirtyStaticShapes; + std::vector m_DirtyUnitShapes; /** * Mark all previous Rasterize()d grids as dirty, and the debug display. @@ -591,7 +591,7 @@ private: * Mark all previous Rasterize()d grids as dirty, if they depend on this shape. * Call this when a static shape has changed. */ - void MakeDirtyStatic(flags_t flags, u32 index, const StaticShape& shape) + void MakeDirtyStatic(flags_t flags, std::uint32_t index, const StaticShape& shape) { m_DebugOverlayDirty = true; @@ -615,15 +615,15 @@ private: CFixedVector2D hbox = Geometry::GetHalfBoundingBox(shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh)); CFixedVector2D expand(m_MaxClearance, m_MaxClearance); - std::vector staticsNear; + std::vector staticsNear; m_StaticSubdivision.GetInRange(staticsNear, center - hbox - expand*2, center + hbox + expand*2); - for (u32& staticId : staticsNear) + for (std::uint32_t& staticId : staticsNear) if (std::find(m_DirtyStaticShapes.begin(), m_DirtyStaticShapes.end(), staticId) == m_DirtyStaticShapes.end()) m_DirtyStaticShapes.push_back(staticId); - std::vector unitsNear; + std::vector unitsNear; m_UnitSubdivision.GetInRange(unitsNear, center - hbox - expand*2, center + hbox + expand*2); - for (u32& unitId : unitsNear) + for (std::uint32_t& unitId : unitsNear) if (std::find(m_DirtyUnitShapes.begin(), m_DirtyUnitShapes.end(), unitId) == m_DirtyUnitShapes.end()) m_DirtyUnitShapes.push_back(unitId); @@ -635,7 +635,7 @@ private: * Mark all previous Rasterize()d grids as dirty, if they depend on this shape. * Call this when a unit shape has changed. */ - void MakeDirtyUnit(flags_t flags, u32 index, const UnitShape& shape) + void MakeDirtyUnit(flags_t flags, std::uint32_t index, const UnitShape& shape) { m_DebugOverlayDirty = true; @@ -657,15 +657,15 @@ private: CFixedVector2D center(shape.x, shape.z); - std::vector staticsNear; + std::vector staticsNear; m_StaticSubdivision.GetNear(staticsNear, center, shape.clearance + m_MaxClearance*2); - for (u32& staticId : staticsNear) + for (std::uint32_t& staticId : staticsNear) if (std::find(m_DirtyStaticShapes.begin(), m_DirtyStaticShapes.end(), staticId) == m_DirtyStaticShapes.end()) m_DirtyStaticShapes.push_back(staticId); - std::vector unitsNear; + std::vector unitsNear; m_UnitSubdivision.GetNear(unitsNear, center, shape.clearance + m_MaxClearance*2); - for (u32& unitId : unitsNear) + for (std::uint32_t& unitId : unitsNear) if (std::find(m_DirtyUnitShapes.begin(), m_DirtyUnitShapes.end(), unitId) == m_DirtyUnitShapes.end()) m_DirtyUnitShapes.push_back(unitId); @@ -902,7 +902,7 @@ bool CCmpObstructionManager::TestLine(const IObstructionTestFilter& filter, enti m_UnitSubdivision.GetInRange(unitShapes, posMin, posMax); for (const entity_id_t& shape : unitShapes) { - std::map::const_iterator it = m_UnitShapes.find(shape); + std::map::const_iterator it = m_UnitShapes.find(shape); ENSURE(it != m_UnitShapes.end()); if (!filter.TestShape(UNIT_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, INVALID_ENTITY)) @@ -918,7 +918,7 @@ bool CCmpObstructionManager::TestLine(const IObstructionTestFilter& filter, enti m_StaticSubdivision.GetInRange(staticShapes, posMin, posMax); for (const entity_id_t& shape : staticShapes) { - std::map::const_iterator it = m_StaticShapes.find(shape); + std::map::const_iterator it = m_StaticShapes.find(shape); ENSURE(it != m_StaticShapes.end()); if (!filter.TestShape(STATIC_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, it->second.group2)) @@ -951,7 +951,7 @@ bool CCmpObstructionManager::TestUnitLine(const IObstructionTestFilter& filter, m_UnitSubdivision.GetInRange(unitShapes, posMin, posMax); for (const entity_id_t& shape : unitShapes) { - std::map::const_iterator it = m_UnitShapes.find(shape); + std::map::const_iterator it = m_UnitShapes.find(shape); ENSURE(it != m_UnitShapes.end()); if (!filter.TestShape(UNIT_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, INVALID_ENTITY)) @@ -1003,7 +1003,7 @@ bool CCmpObstructionManager::TestStaticShape(const IObstructionTestFilter& filte m_UnitSubdivision.GetInRange(unitShapes, posMin, posMax); for (entity_id_t& shape : unitShapes) { - std::map::const_iterator it = m_UnitShapes.find(shape); + std::map::const_iterator it = m_UnitShapes.find(shape); ENSURE(it != m_UnitShapes.end()); if (!filter.TestShape(UNIT_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, INVALID_ENTITY)) @@ -1024,7 +1024,7 @@ bool CCmpObstructionManager::TestStaticShape(const IObstructionTestFilter& filte m_StaticSubdivision.GetInRange(staticShapes, posMin, posMax); for (entity_id_t& shape : staticShapes) { - std::map::const_iterator it = m_StaticShapes.find(shape); + std::map::const_iterator it = m_StaticShapes.find(shape); ENSURE(it != m_StaticShapes.end()); if (!filter.TestShape(STATIC_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, it->second.group2)) @@ -1070,7 +1070,7 @@ bool CCmpObstructionManager::TestUnitShape(const IObstructionTestFilter& filter, m_UnitSubdivision.GetInRange(unitShapes, posMin, posMax); for (const entity_id_t& shape : unitShapes) { - std::map::const_iterator it = m_UnitShapes.find(shape); + std::map::const_iterator it = m_UnitShapes.find(shape); ENSURE(it != m_UnitShapes.end()); if (!filter.TestShape(UNIT_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, INVALID_ENTITY)) @@ -1095,7 +1095,7 @@ bool CCmpObstructionManager::TestUnitShape(const IObstructionTestFilter& filter, m_StaticSubdivision.GetInRange(staticShapes, posMin, posMax); for (const entity_id_t& shape : staticShapes) { - std::map::const_iterator it = m_StaticShapes.find(shape); + std::map::const_iterator it = m_StaticShapes.find(shape); ENSURE(it != m_StaticShapes.end()); if (!filter.TestShape(STATIC_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, it->second.group2)) @@ -1225,7 +1225,7 @@ void CCmpObstructionManager::GetUnitObstructionsInRange(const IObstructionTestFi m_UnitSubdivision.GetInRange(unitShapes, CFixedVector2D(x0, z0), CFixedVector2D(x1, z1)); for (entity_id_t& unitShape : unitShapes) { - std::map::const_iterator it = m_UnitShapes.find(unitShape); + std::map::const_iterator it = m_UnitShapes.find(unitShape); ENSURE(it != m_UnitShapes.end()); if (!filter.TestShape(UNIT_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, INVALID_ENTITY)) @@ -1253,7 +1253,7 @@ void CCmpObstructionManager::GetStaticObstructionsInRange(const IObstructionTest m_StaticSubdivision.GetInRange(staticShapes, CFixedVector2D(x0, z0), CFixedVector2D(x1, z1)); for (entity_id_t& staticShape : staticShapes) { - std::map::const_iterator it = m_StaticShapes.find(staticShape); + std::map::const_iterator it = m_StaticShapes.find(staticShape); ENSURE(it != m_StaticShapes.end()); if (!filter.TestShape(STATIC_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, it->second.group2)) @@ -1288,9 +1288,9 @@ void CCmpObstructionManager::GetUnitsOnObstruction(const ObstructionSquare& squa std::map rasterizedRects; - for (const u32& unitShape : unitShapes) + for (const std::uint32_t& unitShape : unitShapes) { - std::map::const_iterator it = m_UnitShapes.find(unitShape); + std::map::const_iterator it = m_UnitShapes.find(unitShape); ENSURE(it != m_UnitShapes.end()); const UnitShape& shape = it->second; @@ -1341,9 +1341,9 @@ void CCmpObstructionManager::GetStaticObstructionsOnObstruction(const Obstructio CFixedVector2D expandedBox = Geometry::GetHalfBoundingBox(square.u, square.v, CFixedVector2D(square.hw, square.hh)); m_StaticSubdivision.GetInRange(staticShapes, center - expandedBox, center + expandedBox); - for (const u32& staticShape : staticShapes) + for (const std::uint32_t& staticShape : staticShapes) { - std::map::const_iterator it = m_StaticShapes.find(staticShape); + std::map::const_iterator it = m_StaticShapes.find(staticShape); ENSURE(it != m_StaticShapes.end()); const StaticShape& shape = it->second; @@ -1387,14 +1387,14 @@ void CCmpObstructionManager::RenderSubmit(SceneCollector& collector) (m_WorldX1-m_WorldX0).ToFloat(), (m_WorldZ1-m_WorldZ0).ToFloat(), 0, m_DebugOverlayLines.back(), true); - for (std::map::iterator it = m_UnitShapes.begin(); it != m_UnitShapes.end(); ++it) + for (std::map::iterator it = m_UnitShapes.begin(); it != m_UnitShapes.end(); ++it) { m_DebugOverlayLines.push_back(SOverlayLine()); m_DebugOverlayLines.back().m_Color = ((it->second.flags & FLAG_MOVING) ? movingColor : defaultColor); SimRender::ConstructSquareOnGround(GetSimContext(), it->second.x.ToFloat(), it->second.z.ToFloat(), it->second.clearance.ToFloat(), it->second.clearance.ToFloat(), 0, m_DebugOverlayLines.back(), true); } - for (std::map::iterator it = m_StaticShapes.begin(); it != m_StaticShapes.end(); ++it) + for (std::map::iterator it = m_StaticShapes.begin(); it != m_StaticShapes.end(); ++it) { m_DebugOverlayLines.push_back(SOverlayLine()); m_DebugOverlayLines.back().m_Color = defaultColor; diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index 7ea5812959..a50277c99b 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -28,7 +28,6 @@ #include "lib/code_generation.h" #include "lib/debug.h" #include "lib/path.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/MathUtil.h" @@ -271,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(std::uint32_t& steps, double& time, Grid& grid) const { m_LongPathfinder->GetDebugData(steps, time, grid); } @@ -784,14 +783,15 @@ void CCmpPathfinder::TerrainUpdateHelper(bool expandPassability, int itile0, int ////////////////////////////////////////////////////////// -u32 CCmpPathfinder::ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) +std::uint32_t CCmpPathfinder::ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, + pass_class_t passClass, entity_id_t notify) { LongPathRequest req = { m_NextAsyncTicket++, x0, z0, goal, passClass, notify }; m_LongPathRequests.m_Requests.push_back(req); return req.ticket; } -u32 CCmpPathfinder::ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, +std::uint32_t CCmpPathfinder::ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t group, entity_id_t notify) { @@ -964,7 +964,7 @@ std::vector CCmpPathfinder::DistributeAround(std::vector u32 { + auto distSq = [](const CFixedVector2D& p1, const CFixedVector2D& p2) -> std::uint32_t { std::int32_t dx = (p1.X - p2.X).ToInt_RoundToInfinity(); std::int32_t dy = (p1.Y - p2.Y).ToInt_RoundToInfinity(); return dx*dx + dy*dy; @@ -972,8 +972,10 @@ std::vector CCmpPathfinder::DistributeAround(std::vector m_LongPathRequests; PathRequests m_ShortPathRequests; - u32 m_NextAsyncTicket; // Unique IDs for asynchronous path requests. + std::uint32_t m_NextAsyncTicket; // Unique IDs for asynchronous path requests. pass_class_t m_OverlayPassClass; TerrainTextureOverlay* m_AtlasOverlay; @@ -212,11 +211,11 @@ public: void ComputePathImmediate(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) const override; - u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) override; + std::uint32_t ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) override; WaypointPath ComputeShortPathImmediate(const ShortPathRequest& request) const override; - u32 ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t controller, entity_id_t notify) override; + std::uint32_t ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t controller, entity_id_t notify) override; bool IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) override; @@ -226,7 +225,7 @@ public: void SetHierDebugOverlay(bool enabled) override; - void GetDebugData(u32& steps, double& time, Grid& grid) const override; + void GetDebugData(std::uint32_t& steps, double& time, Grid& grid) const override; void SetAtlasOverlay(bool enable, pass_class_t passClass = 0) override; diff --git a/source/simulation2/components/CCmpRallyPointRenderer.cpp b/source/simulation2/components/CCmpRallyPointRenderer.cpp index 39b902df5b..dc788ebf85 100644 --- a/source/simulation2/components/CCmpRallyPointRenderer.cpp +++ b/source/simulation2/components/CCmpRallyPointRenderer.cpp @@ -993,7 +993,7 @@ void CCmpRallyPointRenderer::SetPosition(const CFixedVector2D& pos) } } -void CCmpRallyPointRenderer::UpdatePosition(u32 rallyPointId, const CFixedVector2D& pos) +void CCmpRallyPointRenderer::UpdatePosition(std::uint32_t rallyPointId, const CFixedVector2D& pos) { if (rallyPointId >= m_RallyPoints.size()) return; diff --git a/source/simulation2/components/CCmpRallyPointRenderer.h b/source/simulation2/components/CCmpRallyPointRenderer.h index fd14495a44..b1d8faabd1 100644 --- a/source/simulation2/components/CCmpRallyPointRenderer.h +++ b/source/simulation2/components/CCmpRallyPointRenderer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -21,7 +21,6 @@ #include "graphics/Color.h" #include "graphics/Overlay.h" #include "graphics/Texture.h" -#include "lib/types.h" #include "maths/FixedVector2D.h" #include "maths/Vector2D.h" #include "simulation2/components/ICmpRallyPointRenderer.h" @@ -89,7 +88,7 @@ public: void SetPosition(const CFixedVector2D& pos) override; - void UpdatePosition(u32 rallyPointId, const CFixedVector2D& pos) override; + void UpdatePosition(std::uint32_t rallyPointId, const CFixedVector2D& pos) override; void SetDisplayed(bool displayed) override; diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 41d9c35378..00b508d75c 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -94,7 +94,7 @@ const fixed PARABOLIC_RANGE_TOLERANCE = fixed::FromInt(1)/2; * Convert an owner ID (-1 = unowned, 0 = gaia, 1..30 = players) * into a 32-bit mask for quick set-membership tests. */ -u32 CalcOwnerMask(player_id_t owner) +std::uint32_t CalcOwnerMask(player_id_t owner) { if (owner >= -1 && owner < 31) return 1 << (1+owner); @@ -105,19 +105,19 @@ u32 CalcOwnerMask(player_id_t owner) /** * Returns LOS mask for given player. */ -u32 CalcPlayerLosMask(player_id_t player) +std::uint32_t CalcPlayerLosMask(player_id_t player) { if (player > 0 && player <= 16) - return (u32)LosState::MASK << (2*(player-1)); + return static_cast(LosState::MASK) << (2*(player-1)); return 0; } /** * Returns shared LOS mask for given list of players. */ -u32 CalcSharedLosMask(std::vector players) +std::uint32_t CalcSharedLosMask(std::vector players) { - u32 playerMask = 0; + std::uint32_t playerMask = 0; for (size_t i = 0; i < players.size(); i++) playerMask |= CalcPlayerLosMask(players[i]); @@ -146,7 +146,7 @@ bool SetPlayerSharedDirtyVisibilityBit(std::uint16_t& mask, player_id_t player, /** * Computes the 2-bit visibility for one player, given the total 32-bit visibilities */ -LosVisibility GetPlayerVisibility(u32 visibilities, player_id_t player) +LosVisibility GetPlayerVisibility(std::uint32_t visibilities, player_id_t player) { if (player > 0 && player <= 16) return static_cast( (visibilities >> (2 *(player-1))) & 0x3 ); @@ -190,7 +190,7 @@ struct Query entity_pos_t maxRange; entity_pos_t baseRange; // Non-parabolic detection range entity_pos_t yOrigin; // Used for parabolas only. - u32 ownersMask; + std::uint32_t ownersMask; std::int32_t interface; std::uint8_t flagsMask; bool enabled; @@ -262,8 +262,8 @@ struct EntityData { } entity_pos_t x, z; entity_pos_t visionRange; - u32 visibilities; // 2-bit visibility, per player - u32 size; + std::uint32_t visibilities; // 2-bit visibility, per player + std::uint32_t size; std::uint16_t visionSharing; // 1-bit per player std::int8_t owner; std::uint8_t flags; // See the FlagMasks enum @@ -486,20 +486,20 @@ public: std::array, MAX_LOS_PLAYER_ID> m_LosPlayerCounts; // 2-bit LosState per player, starting with player 1 (not 0!) up to player MAX_LOS_PLAYER_ID (inclusive) - Grid m_LosState; + Grid m_LosState; // Special static visibility data for the "reveal whole map" mode // (TODO: this is usually a waste of memory) - Grid m_LosStateRevealed; + Grid m_LosStateRevealed; // Shared LOS masks, one per player. - std::array m_SharedLosMasks; + std::array m_SharedLosMasks; // Shared dirty visibility masks, one per player. std::array m_SharedDirtyVisibilityMasks; // Cache explored vertices per player (not serialized) - u32 m_TotalInworldVertices; - std::vector m_ExploredVertices; + std::uint32_t m_TotalInworldVertices; + std::vector m_ExploredVertices; static std::string GetSchema() { @@ -877,7 +877,7 @@ public: // does not affect the incrementally-computed state std::array, MAX_LOS_PLAYER_ID> oldPlayerCounts = m_LosPlayerCounts; - Grid oldStateRevealed = m_LosStateRevealed; + Grid oldStateRevealed = m_LosStateRevealed; FastSpatialSubdivision oldSubdivision = m_Subdivision; Grid > oldLosRegions = m_LosRegions; @@ -943,7 +943,11 @@ public: for (std::int32_t i = 0; i < m_LosVerticesPerSide; i++) if (!LosIsOffWorld(i, j)) 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); + { + m_ExploredVertices.at(k) += ((m_LosState.get(i, j) & + (static_cast(LosState::EXPLORED) << + (2 * (k - 1)))) > 0); + } } else m_LosState.resize(m_LosVerticesPerSide, m_LosVerticesPerSide); @@ -1153,7 +1157,7 @@ public: return GetEntitiesByMask(~1u); // bit 0 for owner=-1 } - std::vector GetEntitiesByMask(u32 ownerMask) const + std::vector GetEntitiesByMask(std::uint32_t ownerMask) const { std::vector entities; @@ -1635,7 +1639,7 @@ public: if (q.accountForSize && q.source.GetId() != INVALID_ENTITY && q.maxRange != ALWAYS_IN_RANGE) { - u32 size = 0; + std::uint32_t size = 0; if (ENTITY_IS_LOCAL(q.source.GetId())) { CmpPtr cmpObstruction(GetSimContext(), q.source.GetId()); @@ -2194,7 +2198,7 @@ public: m_GlobalPlayerVisibilityUpdate[player-1] = 1; } - u32 GetSharedLosMask(player_id_t player) const override + std::uint32_t GetSharedLosMask(player_id_t player) const override { return m_SharedLosMasks[player]; } @@ -2206,9 +2210,11 @@ public: { if (LosIsOffWorld(i,j)) continue; - u32 &explored = m_ExploredVertices.at(p); - explored += !(m_LosState.get(i, j) & ((u32)LosState::EXPLORED << (2*(p-1)))); - m_LosState.get(i, j) |= ((u32)LosState::EXPLORED << (2*(p-1))); + std::uint32_t &explored = m_ExploredVertices.at(p); + explored += !(m_LosState.get(i, j) & + (static_cast(LosState::EXPLORED) << (2*(p-1)))); + m_LosState.get(i, j) |= + (static_cast(LosState::EXPLORED) << (2*(p-1))); } SeeExploredEntities(p); @@ -2238,16 +2244,18 @@ public: 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); + std::uint32_t& explored = m_ExploredVertices.at(p); if (LosIsOffWorld(i, j)) continue; - u32& losState = m_LosState.get(i, j); - if (!(losState & ((u32)LosState::EXPLORED << (2*(p-1))))) + std::uint32_t& losState = m_LosState.get(i, j); + if (!(losState & + (static_cast(LosState::EXPLORED) << (2*(p-1))))) { ++explored; - losState |= ((u32)LosState::EXPLORED << (2*(p-1))); + losState |= + (static_cast(LosState::EXPLORED) << (2*(p-1))); } } } @@ -2280,8 +2288,8 @@ public: return; const TileCircle circle{WorldToTileCircle(worldX, worldZ, radius)}; - const u32 exploredBitMask{static_cast(LosState::EXPLORED) << (2 * (playerId - 1))}; - u32& exploredCount = m_ExploredVertices.at(playerId); + const std::uint32_t exploredBitMask{static_cast(LosState::EXPLORED) << (2 * (playerId - 1))}; + std::uint32_t& exploredCount = m_ExploredVertices.at(playerId); ForEachTileInCircle(circle, [&](std::int32_t tileX, std::int32_t tileZ) @@ -2289,7 +2297,7 @@ public: if (LosIsOffWorld(tileX, tileZ)) return; - u32& losState = m_LosState.get(tileX, tileZ); + std::uint32_t& losState = m_LosState.get(tileX, tileZ); if (losState & exploredBitMask) return; @@ -2409,7 +2417,7 @@ public: if (i1 < i0) return; - u32 &explored = m_ExploredVertices.at(owner); + std::uint32_t &explored = m_ExploredVertices.at(owner); for (std::int32_t i = i0; i <= i1; ++i) { // Increasing from zero to non-zero - move from unexplored/explored to visible+explored @@ -2417,8 +2425,10 @@ public: { if (!LosIsOffWorld(i, j)) { - explored += !(m_LosState.get(i, j) & ((u32)LosState::EXPLORED << (2*(owner-1)))); - m_LosState.get(i, j) |= (((int)LosState::VISIBLE | (u32)LosState::EXPLORED) << (2*(owner-1))); + explored += !(m_LosState.get(i, j) & + (static_cast(LosState::EXPLORED) << (2*(owner-1)))); + m_LosState.get(i, j) |= (((int)LosState::VISIBLE | + static_cast(LosState::EXPLORED)) << (2*(owner-1))); } MarkVisibilityDirtyAroundTile(owner, i, j); @@ -2764,7 +2774,7 @@ public: std::uint8_t GetUnionPercentMapExplored(const std::vector& players) const override { - u32 exploredVertices = 0; + std::uint32_t exploredVertices = 0; std::vector::const_iterator playerIt; for (std::int32_t j = 0; j < m_LosVerticesPerSide; j++) @@ -2774,7 +2784,8 @@ public: continue; for (playerIt = players.begin(); playerIt != players.end(); ++playerIt) - if (m_LosState.get(i, j) & ((u32)LosState::EXPLORED << (2*((*playerIt)-1)))) + if (m_LosState.get(i, j) & (static_cast(LosState::EXPLORED) << + (2*((*playerIt)-1)))) { exploredVertices += 1; break; diff --git a/source/simulation2/components/CCmpTerrain.cpp b/source/simulation2/components/CCmpTerrain.cpp index 7d39735249..995f9a40ac 100644 --- a/source/simulation2/components/CCmpTerrain.cpp +++ b/source/simulation2/components/CCmpTerrain.cpp @@ -22,7 +22,6 @@ #include "graphics/Terrain.h" #include "lib/debug.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector3D.h" #include "maths/Vector3D.h" @@ -110,7 +109,7 @@ public: return static_cast(tiles); } - u32 GetMapSize() const override + std::uint32_t GetMapSize() const override { return GetTilesPerSide() * TERRAIN_TILE_SIZE; } diff --git a/source/simulation2/components/CCmpTerritoryInfluence.cpp b/source/simulation2/components/CCmpTerritoryInfluence.cpp index 745fd01568..9aa90c95ce 100644 --- a/source/simulation2/components/CCmpTerritoryInfluence.cpp +++ b/source/simulation2/components/CCmpTerritoryInfluence.cpp @@ -19,7 +19,6 @@ #include "ICmpTerritoryInfluence.h" -#include "lib/types.h" #include "simulation2/components/ICmpValueModificationManager.h" #include "simulation2/system/Component.h" @@ -36,7 +35,7 @@ public: bool m_Root; std::uint16_t m_Weight; - u32 m_Radius; + std::uint32_t m_Radius; static std::string GetSchema() { @@ -92,13 +91,13 @@ public: return cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Weight", m_Weight, GetEntityId()); } - u32 GetRadius() const override + std::uint32_t GetRadius() const override { CmpPtr cmpValueModificationManager(GetSystemEntity()); if (!cmpValueModificationManager) return m_Radius; - u32 newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId()); + std::uint32_t newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId()); return newRadius; } }; diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index a157d2f088..3b3c2458d0 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/source/simulation2/components/CCmpTerritoryManager.cpp @@ -29,7 +29,6 @@ #include "lib/code_generation.h" #include "lib/debug.h" #include "lib/path.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/MathUtil.h" @@ -284,7 +283,7 @@ public: } player_id_t GetOwner(entity_pos_t x, entity_pos_t z) override; - std::vector GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) override; + std::vector GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) override; bool IsConnected(entity_pos_t x, entity_pos_t z) override; void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable) override; @@ -521,16 +520,16 @@ void CCmpTerritoryManager::CalculateTerritories() } // Store the overall best weight for comparison - Grid bestWeightGrid(tilesW, tilesH); + Grid bestWeightGrid(tilesW, tilesH); // store the root influences to mark territory as connected std::vector rootInfluenceEntities; for (const std::pair>& pair : influenceEntities) { // entityGrid stores the weight for a single entity, and is reset per entity - Grid entityGrid(tilesW, tilesH); + Grid entityGrid(tilesW, tilesH); // playerGrid stores the combined weight of all entities for this player - Grid playerGrid(tilesW, tilesH); + Grid playerGrid(tilesW, tilesH); std::uint8_t owner = static_cast(pair.first); const std::vector& ents = pair.second; @@ -544,11 +543,11 @@ void CCmpTerritoryManager::CalculateTerritories() continue; CmpPtr cmpTerritoryInfluence(GetSimContext(), ent); - const u32 originWeight = cmpTerritoryInfluence->GetWeight(); - u32 radius = cmpTerritoryInfluence->GetRadius(); + const std::uint32_t originWeight = cmpTerritoryInfluence->GetWeight(); + std::uint32_t radius = cmpTerritoryInfluence->GetRadius(); if (originWeight == 0 || radius == 0) continue; - const u32 relativeFalloff = originWeight * + const std::uint32_t relativeFalloff = originWeight * (Pathfinding::NAVCELL_SIZE * NAVCELLS_PER_TERRITORY_TILE) .ToInt_RoundToNegInfinity() / radius; @@ -565,10 +564,10 @@ void CCmpTerritoryManager::CalculateTerritories() const bool diagonalProgression{current && neighbour.x != current->x && neighbour.z != current->z}; - const u32 falloffPerTile{relativeFalloff * + const std::uint32_t falloffPerTile{relativeFalloff * m_CostGrid->get(neighbour.x, neighbour.z)}; // diagonal neighbour -> multiply with approx sqrt(2) - const u32 falloff{diagonalProgression ? (falloffPerTile * 362) / 256 : + const std::uint32_t falloff{diagonalProgression ? (falloffPerTile * 362) / 256 : falloffPerTile}; // Don't expand if new cost is not better than previous value for that tile @@ -581,9 +580,9 @@ void CCmpTerritoryManager::CalculateTerritories() } // weight of this tile = weight of predecessor - falloff from predecessor - const u32 weight{current ? entityGrid.get(current->x, current->z) - falloff : - originWeight}; - const u32 totalWeight{weight + (current ? + const std::uint32_t weight{current ? + entityGrid.get(current->x, current->z) - falloff : originWeight}; + const std::uint32_t totalWeight{weight + (current ? playerGrid.get(neighbour.x, neighbour.z) - entityGrid.get(neighbour.x, neighbour.z) : 0)}; @@ -794,13 +793,13 @@ player_id_t CCmpTerritoryManager::GetOwner(entity_pos_t x, entity_pos_t z) return m_Territories->get(i, j) & TERRITORY_PLAYER_MASK; } -std::vector CCmpTerritoryManager::GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) +std::vector CCmpTerritoryManager::GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) { CmpPtr cmpPlayerManager(GetSystemEntity()); if (!cmpPlayerManager) - return std::vector(); + return std::vector(); - std::vector ret(cmpPlayerManager->GetNumPlayers(), 0); + std::vector ret(cmpPlayerManager->GetNumPlayers(), 0); CalculateTerritories(); if (!m_Territories) return ret; diff --git a/source/simulation2/components/CCmpUnitMotion.h b/source/simulation2/components/CCmpUnitMotion.h index 1fe9e71458..322c271c64 100644 --- a/source/simulation2/components/CCmpUnitMotion.h +++ b/source/simulation2/components/CCmpUnitMotion.h @@ -21,7 +21,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/FixedVector3D.h" @@ -208,7 +207,7 @@ public: std::uint8_t m_FollowKnownImperfectPathCountdown = 0; struct Ticket { - u32 m_Ticket = 0; // asynchronous request ID we're waiting for, or 0 if none + std::uint32_t m_Ticket = 0; // asynchronous request ID we're waiting for, or 0 if none enum Type { SHORT_PATH, LONG_PATH @@ -768,7 +767,7 @@ private: /** * Handle the result of an asynchronous path query. */ - void PathResult(u32 ticket, const WaypointPath& path); + void PathResult(std::uint32_t ticket, const WaypointPath& path); void OnValueModification() { @@ -938,7 +937,7 @@ bool CCmpUnitMotion::RejectFartherPaths(const PathGoal& goal, const WaypointPath return false; } -void CCmpUnitMotion::PathResult(u32 ticket, const WaypointPath& path) +void CCmpUnitMotion::PathResult(std::uint32_t ticket, const WaypointPath& path) { // Ignore obsolete path requests if (ticket != m_ExpectedPathTicket.m_Ticket || m_MoveRequest.m_Type == MoveRequest::NONE) diff --git a/source/simulation2/components/CCmpUnitMotion_System.cpp b/source/simulation2/components/CCmpUnitMotion_System.cpp index 7c2c51a93e..585e25c204 100644 --- a/source/simulation2/components/CCmpUnitMotion_System.cpp +++ b/source/simulation2/components/CCmpUnitMotion_System.cpp @@ -20,7 +20,6 @@ #include "CCmpUnitMotion.h" #include "lib/debug.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/FixedVector3D.h" @@ -313,7 +312,7 @@ struct SerializeHelper> EntityMap& value) { // Serialize manually, we don't have a default-constructor for deserialization. - Serializer(serialize, "size", static_cast(value.size())); + Serializer(serialize, "size", static_cast(value.size())); for (EntityMap::iterator it = value.begin(); it != value.end(); ++it) { Serializer(serialize, "ent id", it->first); @@ -324,9 +323,9 @@ struct SerializeHelper> void operator()(IDeserializer& deserialize, const char* /*name*/, EntityMap& value) { - u32 units = 0; + std::uint32_t units = 0; Serializer(deserialize, "size", units); - for (u32 i = 0; i < units; ++i) + for (std::uint32_t i = 0; i < units; ++i) { entity_id_t ent = INVALID_ENTITY; Serializer(deserialize, "ent id", ent); diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp index 26b8f6fbe8..6d671e8b4a 100644 --- a/source/simulation2/components/CCmpVisualActor.cpp +++ b/source/simulation2/components/CCmpVisualActor.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 @@ -30,7 +30,6 @@ #include "graphics/UnitManager.h" #include "lib/debug.h" #include "lib/path.h" -#include "lib/types.h" #include "lib/utf8.h" #include "maths/BoundingBoxAligned.h" #include "maths/BoundingBoxOriented.h" @@ -104,7 +103,7 @@ private: std::map m_VariantSelections; - u32 m_Seed; // seed used for random variations + std::uint32_t m_Seed; // seed used for random variations bool m_ConstructionPreview; @@ -300,7 +299,7 @@ public: { Init(paramNode); - u32 oldSeed = GetActorSeed(); + std::uint32_t oldSeed = GetActorSeed(); SerializeCommon(deserialize); @@ -531,12 +530,12 @@ public: m_Unit->GetModel().SetEntityVariable(name, value); } - u32 GetActorSeed() const override + std::uint32_t GetActorSeed() const override { return m_Seed; } - void SetActorSeed(u32 seed) override + void SetActorSeed(std::uint32_t seed) override { if (seed == m_Seed) return; @@ -625,7 +624,7 @@ void CCmpVisualActor::InitModel() CModelAbstract& model = m_Unit->GetModel(); if (model.ToCModel()) { - u32 modelFlags = 0; + std::uint32_t modelFlags = 0; if (m_SilhouetteDisplay) modelFlags |= ModelFlag::SILHOUETTE_DISPLAY; diff --git a/source/simulation2/components/ICmpAIManager.cpp b/source/simulation2/components/ICmpAIManager.cpp index cf44c37135..6894b229c1 100644 --- a/source/simulation2/components/ICmpAIManager.cpp +++ b/source/simulation2/components/ICmpAIManager.cpp @@ -23,7 +23,6 @@ #include "lib/file/vfs/vfs_util.h" #include "lib/path.h" #include "lib/status.h" -#include "lib/types.h" #include "ps/Filesystem.h" #include "scriptinterface/JSON.h" #include "scriptinterface/Object.h" @@ -84,7 +83,7 @@ public: Script::ReadJSONFile(rq, pathname, &data); Script::SetProperty(rq, ai, "id", dirname, true); Script::SetProperty(rq, ai, "data", data, true); - u32 length; + std::uint32_t length; JS::GetArrayLength(rq.cx, self->m_AIs, &length); JS_SetElement(rq.cx, self->m_AIs, length, ai); diff --git a/source/simulation2/components/ICmpObstructionManager.h b/source/simulation2/components/ICmpObstructionManager.h index 4381f49d4b..3def8723ee 100644 --- a/source/simulation2/components/ICmpObstructionManager.h +++ b/source/simulation2/components/ICmpObstructionManager.h @@ -19,7 +19,6 @@ #define INCLUDED_ICMPOBSTRUCTIONMANAGER #include "lib/debug.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "simulation2/helpers/Position.h" @@ -76,15 +75,15 @@ public: /** * External identifiers for shapes. - * (This is a struct rather than a raw u32 for type-safety.) + * (This is a struct rather than a raw std::uint32_t for type-safety.) */ struct tag_t { tag_t() : n(0) {} - explicit tag_t(u32 n) : n(n) {} + explicit tag_t(std::uint32_t n) : n(n) {} bool valid() const { return n != 0; } - u32 n; + std::uint32_t n; }; /** diff --git a/source/simulation2/components/ICmpPathfinder.h b/source/simulation2/components/ICmpPathfinder.h index 3899a476d1..5155f27979 100644 --- a/source/simulation2/components/ICmpPathfinder.h +++ b/source/simulation2/components/ICmpPathfinder.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_ICMPPATHFINDER #define INCLUDED_ICMPPATHFINDER -#include "lib/types.h" #include "simulation2/components/ICmpObstruction.h" #include "simulation2/helpers/Pathfinding.h" #include "simulation2/helpers/Position.h" @@ -40,9 +39,9 @@ template class Grid; struct PathResult { PathResult() = default; - PathResult(u32 t, entity_id_t n, WaypointPath p) : ticket(t), notify(n), path(p) {}; + PathResult(std::uint32_t t, entity_id_t n, WaypointPath p) : ticket(t), notify(n), path(p) {}; - u32 ticket; + std::uint32_t ticket; entity_id_t notify; WaypointPath path; }; @@ -109,7 +108,7 @@ public: * Returns a unique non-zero number, which will match the 'ticket' in the result, * so callers can recognise each individual request they make. */ - virtual u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) = 0; + virtual std::uint32_t ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) = 0; /* * Request a long-path computation immediately @@ -122,7 +121,7 @@ public: * Returns a unique non-zero number, which will match the 'ticket' in the result, * so callers can recognise each individual request they make. */ - virtual u32 ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t controller, entity_id_t notify) = 0; + virtual std::uint32_t ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t controller, entity_id_t notify) = 0; /* * Request a short-path computation immediately. @@ -207,7 +206,7 @@ public: /** * Returns some stats about the last ComputePath. */ - virtual void GetDebugData(u32& steps, double& time, Grid& grid) const = 0; + virtual void GetDebugData(std::uint32_t& steps, double& time, Grid& grid) const = 0; /** * Sets up the pathfinder passability overlay in Atlas. diff --git a/source/simulation2/components/ICmpRallyPointRenderer.h b/source/simulation2/components/ICmpRallyPointRenderer.h index 12d9082f41..9e8fa50a64 100644 --- a/source/simulation2/components/ICmpRallyPointRenderer.h +++ b/source/simulation2/components/ICmpRallyPointRenderer.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_ICMPRALLYPOINTRENDERER #define INCLUDED_ICMPRALLYPOINTRENDERER -#include "lib/types.h" #include "maths/FixedVector2D.h" #include "simulation2/system/Component.h" #include "simulation2/system/Interface.h" @@ -41,7 +40,7 @@ public: virtual void SetPosition(const CFixedVector2D& position) = 0; /// Updates the position of one given rally point marker. - virtual void UpdatePosition(u32 rallyPointId, const CFixedVector2D& position) = 0; + virtual void UpdatePosition(std::uint32_t rallyPointId, const CFixedVector2D& position) = 0; /// Add another position at which a marker should be displayed, connected /// to the previous one. diff --git a/source/simulation2/components/ICmpRangeManager.h b/source/simulation2/components/ICmpRangeManager.h index 439dad244b..5182ac3497 100644 --- a/source/simulation2/components/ICmpRangeManager.h +++ b/source/simulation2/components/ICmpRangeManager.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_ICMPRANGEMANAGER #define INCLUDED_ICMPRANGEMANAGER -#include "lib/types.h" #include "maths/FixedVector2D.h" #include "maths/FixedVector3D.h" #include "simulation2/helpers/Player.h" @@ -111,7 +110,7 @@ public: /** * External identifiers for active queries. */ - typedef u32 tag_t; + typedef std::uint32_t tag_t; /** * Access the spatial subdivision kept by the range manager. @@ -411,7 +410,7 @@ public: /** * Returns shared LOS mask for player. */ - virtual u32 GetSharedLosMask(player_id_t player) const = 0; + virtual std::uint32_t GetSharedLosMask(player_id_t player) const = 0; /** * Get percent map explored statistics for specified player. diff --git a/source/simulation2/components/ICmpTerrain.h b/source/simulation2/components/ICmpTerrain.h index b50d39c03c..606254596a 100644 --- a/source/simulation2/components/ICmpTerrain.h +++ b/source/simulation2/components/ICmpTerrain.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_ICMPTERRAIN #define INCLUDED_ICMPTERRAIN -#include "lib/types.h" #include "maths/FixedVector3D.h" #include "simulation2/helpers/Position.h" #include "simulation2/system/Component.h" @@ -57,7 +56,7 @@ public: /** * Returns the map size in metres (world space units). */ - virtual u32 GetMapSize() const = 0; + virtual std::uint32_t GetMapSize() const = 0; virtual CTerrain* GetCTerrain() = 0; diff --git a/source/simulation2/components/ICmpTerritoryInfluence.h b/source/simulation2/components/ICmpTerritoryInfluence.h index ec1aafb9c3..d3ad87a9e1 100644 --- a/source/simulation2/components/ICmpTerritoryInfluence.h +++ b/source/simulation2/components/ICmpTerritoryInfluence.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_ICMPTERRITORYINFLUENCE #define INCLUDED_ICMPTERRITORYINFLUENCE -#include "lib/types.h" #include "simulation2/system/Component.h" #include "simulation2/system/Interface.h" @@ -31,7 +30,7 @@ public: virtual std::uint16_t GetWeight() const = 0; - virtual u32 GetRadius() const = 0; + virtual std::uint32_t GetRadius() const = 0; DECLARE_INTERFACE_TYPE(TerritoryInfluence) }; diff --git a/source/simulation2/components/ICmpTerritoryManager.h b/source/simulation2/components/ICmpTerritoryManager.h index f5f748e143..e0869ddc75 100644 --- a/source/simulation2/components/ICmpTerritoryManager.h +++ b/source/simulation2/components/ICmpTerritoryManager.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_ICMPTERRITORYMANAGER #define INCLUDED_ICMPTERRITORYMANAGER -#include "lib/types.h" #include "simulation2/helpers/Player.h" #include "simulation2/helpers/Position.h" #include "simulation2/system/Component.h" @@ -73,7 +72,7 @@ public: * get the number of neighbour tiles for per player for the selected position * @return A list with the number of neighbour tiles per player */ - virtual std::vector GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) = 0; + virtual std::vector GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) = 0; /** * Get whether territory at given position is connected to a root object diff --git a/source/simulation2/components/ICmpUnitRenderer.h b/source/simulation2/components/ICmpUnitRenderer.h index 05f43b82b2..ff8e0cd2d3 100644 --- a/source/simulation2/components/ICmpUnitRenderer.h +++ b/source/simulation2/components/ICmpUnitRenderer.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_ICMPMODELRENDERER #define INCLUDED_ICMPMODELRENDERER -#include "lib/types.h" #include "simulation2/system/Component.h" #include "simulation2/system/Interface.h" @@ -36,15 +35,15 @@ class ICmpUnitRenderer : public IComponent public: /** * External identifiers for models. - * (This is a struct rather than a raw u32 for type-safety.) + * (This is a struct rather than a raw std::uint32_t for type-safety.) */ struct tag_t { tag_t() : n(0) {} - explicit tag_t(u32 n) : n(n) {} + explicit tag_t(std::uint32_t n) : n(n) {} bool valid() const { return n != 0; } - u32 n; + std::uint32_t n; }; enum diff --git a/source/simulation2/components/ICmpValueModificationManager.cpp b/source/simulation2/components/ICmpValueModificationManager.cpp index 20f10aa43f..7719c82a51 100644 --- a/source/simulation2/components/ICmpValueModificationManager.cpp +++ b/source/simulation2/components/ICmpValueModificationManager.cpp @@ -35,9 +35,10 @@ public: return m_Script.Call("ApplyModifications", valueName, currentValue, entity); } - u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) const override + std::uint32_t ApplyModifications(std::wstring valueName, std::uint32_t currentValue, + entity_id_t entity) const override { - return m_Script.Call("ApplyModifications", valueName, currentValue, entity); + return m_Script.Call("ApplyModifications", valueName, currentValue, entity); } std::uint16_t ApplyModifications(std::wstring valueName, std::uint16_t currentValue, entity_id_t entity) const override diff --git a/source/simulation2/components/ICmpValueModificationManager.h b/source/simulation2/components/ICmpValueModificationManager.h index 0d82ba7ab9..c28849c382 100644 --- a/source/simulation2/components/ICmpValueModificationManager.h +++ b/source/simulation2/components/ICmpValueModificationManager.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_ICMPVALUEMODIFICATIONMANAGER #define INCLUDED_ICMPVALUEMODIFICATIONMANAGER -#include "lib/types.h" #include "maths/Fixed.h" #include "simulation2/system/Component.h" #include "simulation2/system/Entity.h" @@ -36,7 +35,8 @@ class ICmpValueModificationManager : public IComponent { public: virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) const = 0; - virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) const = 0; + virtual std::uint32_t ApplyModifications(std::wstring valueName, + std::uint32_t currentValue, entity_id_t entity) const = 0; virtual std::uint16_t ApplyModifications(std::wstring valueName, std::uint16_t currentValue, entity_id_t entity) const = 0; virtual std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity) const = 0; diff --git a/source/simulation2/components/ICmpVisual.h b/source/simulation2/components/ICmpVisual.h index 6eb00d4181..28e7e0d499 100644 --- a/source/simulation2/components/ICmpVisual.h +++ b/source/simulation2/components/ICmpVisual.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 "simulation2/system/Interface.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "maths/BoundingBoxAligned.h" #include "maths/BoundingBoxOriented.h" #include "maths/Fixed.h" @@ -145,12 +144,12 @@ public: /** * Get actor seed used for random variations */ - virtual u32 GetActorSeed() const = 0; + virtual std::uint32_t GetActorSeed() const = 0; /** * Set actor seed for random variations and reload model */ - virtual void SetActorSeed(u32 seed) = 0; + virtual void SetActorSeed(std::uint32_t seed) = 0; /** * Recalculate the actor name, applying modifiers. diff --git a/source/simulation2/components/tests/test_Pathfinder.h b/source/simulation2/components/tests/test_Pathfinder.h index ece244aa34..4de351a1ef 100644 --- a/source/simulation2/components/tests/test_Pathfinder.h +++ b/source/simulation2/components/tests/test_Pathfinder.h @@ -26,7 +26,6 @@ #include "lib/path.h" #include "lib/posix/posix_types.h" #include "lib/timer.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "ps/Filesystem.h" @@ -405,7 +404,7 @@ public: WaypointPath path; cmpPathfinder->ComputePathImmediate(x0, z0, goal, cmpPathfinder->GetPassabilityClass("default"), path); - u32 debugSteps; + std::uint32_t debugSteps; double debugTime; Grid debugGrid; cmpPathfinder->GetDebugData(debugSteps, debugTime, debugGrid); diff --git a/source/simulation2/components/tests/test_TerritoryManager.h b/source/simulation2/components/tests/test_TerritoryManager.h index ecec411acb..2d29b800fe 100644 --- a/source/simulation2/components/tests/test_TerritoryManager.h +++ b/source/simulation2/components/tests/test_TerritoryManager.h @@ -22,7 +22,6 @@ #include "lib/file/file_system.h" #include "lib/file/vfs/vfs.h" #include "lib/path.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/FixedVector3D.h" @@ -75,9 +74,11 @@ public: const GridUpdateInformation& GetAIPathfinderDirtinessInformation() const override { static GridUpdateInformation gridInfo; return gridInfo; } void FlushAIPathfinderDirtinessInformation() override {} Grid ComputeShoreGrid(bool = false) override { return Grid {}; } - u32 ComputePathAsync(entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t, entity_id_t) override { return 1; } + std::uint32_t ComputePathAsync(entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t, + entity_id_t) override { return 1; } void ComputePathImmediate(entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t, WaypointPath&) const override {} - u32 ComputeShortPathAsync(entity_pos_t, entity_pos_t, entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t, bool, entity_id_t, entity_id_t) override { return 1; } + std::uint32_t ComputeShortPathAsync(entity_pos_t, entity_pos_t, entity_pos_t, entity_pos_t, + const PathGoal&, pass_class_t, bool, entity_id_t, entity_id_t) override { return 1; } WaypointPath ComputeShortPathImmediate(const ShortPathRequest&) const override { return WaypointPath(); } void SetDebugPath(entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t) override {} bool IsGoalReachable(entity_pos_t, entity_pos_t, const PathGoal&, pass_class_t) override { return false; } @@ -91,7 +92,7 @@ public: void SendRequestedPaths() override {} void StartProcessingMoves(bool) override {} void UpdateGrid() override {} - void GetDebugData(u32&, double&, Grid&) const override {} + void GetDebugData(std::uint32_t&, double&, Grid&) const override {} void SetAtlasOverlay(bool, pass_class_t = 0) override {} }; @@ -111,9 +112,9 @@ public: bool IsRoot() const override { return true; }; std::uint16_t GetWeight() const override { return 10; }; - u32 GetRadius() const override { return m_Radius; }; + std::uint32_t GetRadius() const override { return m_Radius; }; - u32 m_Radius = 0; + std::uint32_t m_Radius = 0; }; class MockOwnershipTerrManager : public ICmpOwnership diff --git a/source/simulation2/helpers/Grid.h b/source/simulation2/helpers/Grid.h index 872f3ab99f..98b04a00f3 100644 --- a/source/simulation2/helpers/Grid.h +++ b/source/simulation2/helpers/Grid.h @@ -21,7 +21,6 @@ #include "lib/code_annotation.h" #include "lib/code_generation.h" #include "lib/debug.h" -#include "lib/types.h" #include "simulation2/serialization/SerializeTemplates.h" #include "simulation2/system/Component.h" @@ -258,7 +257,7 @@ struct SerializeHelper> serialize.NumberU16_Unbounded("height", value.m_H); if (len == 0) return; - u32 count = 1; + std::uint32_t count = 1; T prevVal = value.m_Data[0]; for (size_t i = 1; i < len; ++i) { @@ -281,11 +280,11 @@ struct SerializeHelper> std::uint16_t w, h; deserialize.NumberU16_Unbounded("width", w); deserialize.NumberU16_Unbounded("height", h); - u32 len = h * w; + std::uint32_t len = h * w; value.resize(w, h); for (size_t i = 0; i < len;) { - u32 count; + std::uint32_t count; deserialize.NumberU32_Unbounded("#", count); T el; Serializer(deserialize, name, el); diff --git a/source/simulation2/helpers/HierarchicalPathfinder.cpp b/source/simulation2/helpers/HierarchicalPathfinder.cpp index 00bca0efdc..7638f52e78 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.cpp +++ b/source/simulation2/helpers/HierarchicalPathfinder.cpp @@ -183,8 +183,8 @@ void HierarchicalPathfinder::Chunk::RegionCenter(std::uint16_t r, int& i_out, in { // Find the mean of i,j coords of navcells in this region: - u32 si = 0, sj = 0; // sum of i,j coords - u32 n = 0; // number of navcells in region + std::uint32_t si = 0, sj = 0; // sum of i,j coords + std::uint32_t n = 0; // number of navcells in region cassert(CHUNK_SIZE < 256); // conservative limit to ensure si and sj don't overflow @@ -215,11 +215,11 @@ void HierarchicalPathfinder::Chunk::RegionCenter(std::uint16_t r, int& i_out, in * that goal. */ void HierarchicalPathfinder::Chunk::RegionNavcellNearest(std::uint16_t r, int iGoal, int jGoal, int& iBest, - int& jBest, u32& dist2Best) const + int& jBest, std::uint32_t& dist2Best) const { iBest = 0; jBest = 0; - dist2Best = std::numeric_limits::max(); + dist2Best = std::numeric_limits::max(); for (int j = 0; j < CHUNK_SIZE; ++j) { @@ -228,7 +228,7 @@ void HierarchicalPathfinder::Chunk::RegionNavcellNearest(std::uint16_t r, int iG if (m_Regions[j][i] != r) continue; - u32 dist2 = (i + m_ChunkI*CHUNK_SIZE - iGoal)*(i + m_ChunkI*CHUNK_SIZE - iGoal) + std::uint32_t dist2 = (i + m_ChunkI*CHUNK_SIZE - iGoal)*(i + m_ChunkI*CHUNK_SIZE - iGoal) + (j + m_ChunkJ*CHUNK_SIZE - jGoal)*(j + m_ChunkJ*CHUNK_SIZE - jGoal); if (dist2 < dist2Best) @@ -248,13 +248,14 @@ void HierarchicalPathfinder::Chunk::RegionNavcellNearest(std::uint16_t r, int iG * Returns true if the goal is inside the region, false otherwise. */ bool HierarchicalPathfinder::Chunk::RegionNearestNavcellInGoal(std::uint16_t r, std::uint16_t i0, - std::uint16_t j0, const PathGoal& goal, std::uint16_t& iOut, std::uint16_t& jOut, u32& dist2Best) const + std::uint16_t j0, const PathGoal& goal, std::uint16_t& iOut, std::uint16_t& jOut, + std::uint32_t& dist2Best) const { // TODO: this should be optimized further. // Most used cases empirically seem to be SQUARE, INVERTED_CIRCLE and then POINT and CIRCLE somehwat equally iOut = 0; jOut = 0; - dist2Best = std::numeric_limits::max(); + dist2Best = std::numeric_limits::max(); // Calculate the navcell that contains the center of the goal. int gi = (goal.x >> Pathfinding::NAVCELL_SIZE_LOG2).ToInt_RoundToNegInfinity(); @@ -288,7 +289,7 @@ bool HierarchicalPathfinder::Chunk::RegionNearestNavcellInGoal(std::uint16_t r, int jmin = std::max(0, gj-m_ChunkJ*CHUNK_SIZE-radius); int jmax = std::min((int)CHUNK_SIZE, gj-m_ChunkJ*CHUNK_SIZE+radius+1); bool found = false; - u32 dist2 = std::numeric_limits::max(); + std::uint32_t dist2 = std::numeric_limits::max(); for (std::uint16_t j = jmin; j < jmax; ++j) { for (std::uint16_t i = imin; i < imax; ++i) @@ -324,7 +325,7 @@ bool HierarchicalPathfinder::Chunk::RegionNearestNavcellInGoal(std::uint16_t r, case PathGoal::INVERTED_SQUARE: { bool found = false; - u32 dist2 = std::numeric_limits::max(); + std::uint32_t dist2 = std::numeric_limits::max(); // loop over all navcells. for (std::uint16_t j = 0; j < CHUNK_SIZE; ++j) { @@ -787,26 +788,29 @@ void HierarchicalPathfinder::FindNearestNavcellInRegions( pass_class_t passClass) const { std::uint16_t bestI = iGoal, bestJ = jGoal; // Somewhat sensible default-values should regions() be passed empty. - u32 bestDist = std::numeric_limits::max(); + std::uint32_t bestDist = std::numeric_limits::max(); // Because regions are sorted by increasing distance, we can ignore regions that are obviously farther than the current best point. // Since regions are squares, that happens when the center of a region is at least sqrt(2) * CHUNK_SIZE farther than the current best point. // Add one to avoid cases where the center navcell is actually slightly off-center (= CHUNK_SIZE is even) - u32 maxDistFromBest = (fixed::FromInt(3) / 2 * CHUNK_SIZE).ToInt_RoundToInfinity() + 1; + std::uint32_t maxDistFromBest = (fixed::FromInt(3) / 2 * CHUNK_SIZE).ToInt_RoundToInfinity() + 1; // TODO: update to static_assert with constexpr ENSURE(maxDistFromBest < std::numeric_limits::max()); maxDistFromBest *= maxDistFromBest; for (const RegionID& region : regions) { - u32 chunkDist = region.DistanceTo(iGoal, jGoal); + std::uint32_t chunkDist = region.DistanceTo(iGoal, jGoal); // This might overflow, but only if we are already close to the maximal possible distance, so the condition would probably be false anyways. // It's also a bit pessimistic, so we'll still consider a few too many regions. - if (bestDist < std::numeric_limits::max() && chunkDist > maxDistFromBest + bestDist) + if (bestDist < std::numeric_limits::max() && + chunkDist > maxDistFromBest + bestDist) + { break; // Break, the set is ordered by increased distance so a closer region will not be found. + } int ri, rj; - u32 dist; + std::uint32_t dist; GetChunk(region.ci, region.cj, passClass).RegionNavcellNearest(region.r, iGoal, jGoal, ri, rj, dist); if (dist < bestDist) { @@ -842,7 +846,7 @@ void HierarchicalPathfinder::FindGoalRegionsAndBestNavcells(std::uint16_t i0, st int size = (std::max(goal.hh, goal.hw) * 3 / 2).ToInt_RoundToInfinity(); std::uint16_t bestI, bestJ; - u32 c; // Unused. + std::uint32_t c; // Unused. for (std::uint8_t sz = std::max(0,(gj - size) / CHUNK_SIZE); sz <= std::min(m_ChunksH-1, (gj + size + 1) / CHUNK_SIZE); ++sz) diff --git a/source/simulation2/helpers/HierarchicalPathfinder.h b/source/simulation2/helpers/HierarchicalPathfinder.h index 3c14bf901b..1bbf373e46 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.h +++ b/source/simulation2/helpers/HierarchicalPathfinder.h @@ -23,7 +23,6 @@ #include "graphics/SColor.h" #include "lib/code_annotation.h" #include "lib/debug.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "renderer/TerrainOverlay.h" @@ -75,7 +74,7 @@ class HierarchicalPathfinder friend class TestHierarchicalPathfinder; #endif public: - typedef u32 GlobalRegionID; + typedef std::uint32_t GlobalRegionID; struct RegionID { @@ -104,7 +103,7 @@ public: } // Returns the distance from the center to the point (i, j) - inline u32 DistanceTo(std::uint16_t i, std::uint16_t j) const + inline std::uint32_t DistanceTo(std::uint16_t i, std::uint16_t j) const { return (ci * CHUNK_SIZE + CHUNK_SIZE/2 - i) * (ci * CHUNK_SIZE + CHUNK_SIZE/2 - i) + (cj * CHUNK_SIZE + CHUNK_SIZE/2 - j) * (cj * CHUNK_SIZE + CHUNK_SIZE/2 - j); @@ -193,11 +192,11 @@ private: void RegionCenter(std::uint16_t r, int& i, int& j) const; void RegionNavcellNearest(std::uint16_t r, int iGoal, int jGoal, int& iBest, int& jBest, - u32& dist2Best) const; + std::uint32_t& dist2Best) const; bool RegionNearestNavcellInGoal(std::uint16_t r, std::uint16_t i0, std::uint16_t j0, const PathGoal& goal, std::uint16_t& iOut, std::uint16_t& jOut, - u32& dist2Best) const; + std::uint32_t& dist2Best) const; #ifdef TEST bool operator==(const Chunk& b) const diff --git a/source/simulation2/helpers/LongPathfinder.cpp b/source/simulation2/helpers/LongPathfinder.cpp index 5d79b389d8..b390cf8c42 100644 --- a/source/simulation2/helpers/LongPathfinder.cpp +++ b/source/simulation2/helpers/LongPathfinder.cpp @@ -42,7 +42,7 @@ static std::mutex g_DebugMutex; void BuildTextureRGBA(LongPathfinder& pathfinder, std::uint8_t* data, std::size_t w, std::size_t h) { // Grab the debug data for the most recently generated path - u32 steps; + std::uint32_t steps; double time; Grid debugGrid; pathfinder.GetDebugData(steps, time, debugGrid); @@ -181,7 +181,7 @@ class JumpPointCache /** * Represents an interval [u15 x0, u16 x1) * with a boolean obstruction flag, - * packed into a single u32. + * packed into a single std::uint32_t. */ struct Interval { @@ -191,14 +191,16 @@ class JumpPointCache { ENSURE(0 <= x0 && x0 < 0x8000); ENSURE(0 <= x1 && x1 < 0x10000); - data = ((u32)x0 << 17) | (u32)(obstruction ? 0x10000 : 0) | (u32)x1; + data = static_cast(x0 << 17) | + static_cast(obstruction ? 0x10000 : 0) | + static_cast(x1); } int x0() { return data >> 17; } int x1() { return data & 0xFFFF; } bool obstruction() { return (data & 0x10000) != 0; } - u32 data; + std::uint32_t data; }; std::vector data; @@ -1060,7 +1062,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(std::uint32_t& steps, double& time, Grid& grid) const { steps = m_Debug.Steps; time = m_Debug.Time; diff --git a/source/simulation2/helpers/LongPathfinder.h b/source/simulation2/helpers/LongPathfinder.h index e828e128b9..2766498d09 100644 --- a/source/simulation2/helpers/LongPathfinder.h +++ b/source/simulation2/helpers/LongPathfinder.h @@ -22,7 +22,6 @@ #include "lib/code_generation.h" #include "lib/debug.h" -#include "lib/types.h" #include "simulation2/helpers/Grid.h" #include "simulation2/helpers/PathGoal.h" #include "simulation2/helpers/Position.h" @@ -35,7 +34,7 @@ /** * Represents the 2D coordinates of a tile. - * The i/j components are packed into a single u32, since we usually use these + * The i/j components are packed into a single std::uint32_t, since we usually use these * objects for equality comparisons and the VC2010 optimizer doesn't seem to automatically * compare two std::uint16_ts in a single operation. * TODO: maybe VC2012 will? @@ -61,7 +60,7 @@ struct TileID std::uint16_t j() const { return data & 0xFFFF; } private: - u32 data; + std::uint32_t data; }; /** @@ -92,7 +91,7 @@ public: private: PathCost g; // cost to reach this tile - u32 data; // 2-bit status; 15-bit PredI; 15-bit PredJ; packed for storage efficiency + std::uint32_t data; // 2-bit status; 15-bit PredI; 15-bit PredJ; packed for storage efficiency public: inline std::uint8_t GetStatus() const @@ -125,7 +124,8 @@ public: ASSERT(-16384 <= di && di < 16384); ASSERT(-16384 <= dj && dj < 16384); data &= 3; - data |= (((u32)di & 0x7FFF) << 17) | (((u32)dj & 0x7FFF) << 2); + data |= ((static_cast(di) & 0x7FFF) << 17) | + ((static_cast(dj) & 0x7FFF) << 2); } }; @@ -142,7 +142,7 @@ class JumpPointCache; struct PathfinderState { - u32 steps; // number of algorithm iterations + std::uint32_t steps; // number of algorithm iterations PathGoal goal; @@ -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(std::uint32_t& steps, double& time, Grid& grid) const { GetDebugDataJPS(steps, time, grid); } @@ -242,7 +242,7 @@ public: // Mutable - set by ComputeJPSPath (thus possibly from different threads). // Synchronized via mutex if necessary. mutable PathfindTileGrid* Grid = nullptr; - mutable u32 Steps; + mutable std::uint32_t Steps; mutable double Time; mutable PathGoal Goal; @@ -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(std::uint32_t& 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 f94b9681a3..93208636fa 100644 --- a/source/simulation2/helpers/Los.h +++ b/source/simulation2/helpers/Los.h @@ -19,7 +19,6 @@ #define INCLUDED_LOS #include "lib/posix/posix_types.h" -#include "lib/types.h" // It doesn't seem worth moving the implementation to c++ and early-declaring Grid // since files must include "Los.h" explicitly, and that's only done in .cpp files. #include "simulation2/helpers/Grid.h" @@ -51,7 +50,7 @@ private: friend class CCmpRangeManager; friend class TestLOSTexture; - CLosQuerier(u32 playerMask, const Grid& data, ssize_t verticesPerSide) : + CLosQuerier(std::uint32_t playerMask, const Grid& data, ssize_t verticesPerSide) : m_Data(data), m_PlayerMask(playerMask), m_VerticesPerSide(verticesPerSide) { } @@ -122,8 +121,8 @@ public: } private: - u32 m_PlayerMask; - const Grid& m_Data; + std::uint32_t m_PlayerMask; + const Grid& m_Data; ssize_t m_VerticesPerSide; }; diff --git a/source/simulation2/helpers/Pathfinding.h b/source/simulation2/helpers/Pathfinding.h index 688e000478..6a5602d9e9 100644 --- a/source/simulation2/helpers/Pathfinding.h +++ b/source/simulation2/helpers/Pathfinding.h @@ -19,7 +19,6 @@ #define INCLUDED_PATHFINDING #include "graphics/Terrain.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/MathUtil.h" #include "simulation2/helpers/PathGoal.h" @@ -35,7 +34,7 @@ typedef std::uint16_t pass_class_t; struct LongPathRequest { - u32 ticket; + std::uint32_t ticket; entity_pos_t x0; entity_pos_t z0; PathGoal goal; @@ -45,7 +44,7 @@ struct LongPathRequest struct ShortPathRequest { - u32 ticket; + std::uint32_t ticket; entity_pos_t x0; entity_pos_t z0; entity_pos_t clearance; @@ -116,13 +115,13 @@ struct PathCost bool operator>=(const PathCost& b) const { return data >= b.data; } bool operator>(const PathCost& b) const { return data > b.data; } - u32 ToInt() + std::uint32_t ToInt() { return data; } private: - u32 data; + std::uint32_t data; }; inline constexpr int PASS_CLASS_BITS = 16; diff --git a/source/simulation2/helpers/Spatial.h b/source/simulation2/helpers/Spatial.h index 2c1088b7c1..c8bbea85e9 100644 --- a/source/simulation2/helpers/Spatial.h +++ b/source/simulation2/helpers/Spatial.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_SPATIAL #include "lib/debug.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/MathUtil.h" @@ -172,13 +171,13 @@ public: { ENSURE(toMin.X <= toMax.X && toMin.Y <= toMax.Y); - u32 i0 = GetI0(toMin.X); - u32 j0 = GetJ0(toMin.Y); - u32 i1 = GetI1(toMax.X); - u32 j1 = GetJ1(toMax.Y); - for (u32 j = j0; j <= j1; ++j) + std::uint32_t i0 = GetI0(toMin.X); + std::uint32_t j0 = GetJ0(toMin.Y); + std::uint32_t i1 = GetI1(toMax.X); + std::uint32_t j1 = GetJ1(toMax.Y); + for (std::uint32_t j = j0; j <= j1; ++j) { - for (u32 i = i0; i <= i1; ++i) + for (std::uint32_t i = i0; i <= i1; ++i) { m_Divisions[i + j*m_DivisionsW].push_back(item); } @@ -194,13 +193,13 @@ public: { ENSURE(fromMin.X <= fromMax.X && fromMin.Y <= fromMax.Y); - u32 i0 = GetI0(fromMin.X); - u32 j0 = GetJ0(fromMin.Y); - u32 i1 = GetI1(fromMax.X); - u32 j1 = GetJ1(fromMax.Y); - for (u32 j = j0; j <= j1; ++j) + std::uint32_t i0 = GetI0(fromMin.X); + std::uint32_t j0 = GetJ0(fromMin.Y); + std::uint32_t i1 = GetI1(fromMax.X); + std::uint32_t j1 = GetJ1(fromMax.Y); + for (std::uint32_t j = j0; j <= j1; ++j) { - for (u32 i = i0; i <= i1; ++i) + for (std::uint32_t i = i0; i <= i1; ++i) { SubDivisionGrid& div = m_Divisions[i + j*m_DivisionsW]; int size = div.items.size(); @@ -263,13 +262,13 @@ public: out.clear(); ENSURE(posMin.X <= posMax.X && posMin.Y <= posMax.Y); - u32 i0 = GetI0(posMin.X); - u32 j0 = GetJ0(posMin.Y); - u32 i1 = GetI1(posMax.X); - u32 j1 = GetJ1(posMax.Y); - for (u32 j = j0; j <= j1; ++j) + std::uint32_t i0 = GetI0(posMin.X); + std::uint32_t j0 = GetJ0(posMin.Y); + std::uint32_t i1 = GetI1(posMax.X); + std::uint32_t j1 = GetJ1(posMax.Y); + for (std::uint32_t j = j0; j <= j1; ++j) { - for (u32 i = i0; i <= i1; ++i) + for (std::uint32_t i = i0; i <= i1; ++i) { m_Divisions[i + j*m_DivisionsW].copy_items_at_end(out); } @@ -475,7 +474,7 @@ public: /** * Add an item. */ - void Add(entity_id_t item, CFixedVector2D position, u32 size) + void Add(entity_id_t item, CFixedVector2D position, std::uint32_t size) { if (size > SUBDIVISION_SIZE) { @@ -494,7 +493,7 @@ public: * Remove an item. * Position must be where we expect to find it, or we won't find it. */ - void Remove(entity_id_t item, CFixedVector2D position, u32 size) + void Remove(entity_id_t item, CFixedVector2D position, std::uint32_t size) { if (size > SUBDIVISION_SIZE) EraseFrom(m_OverSizedData, item); @@ -509,7 +508,7 @@ public: * Equivalent to Remove() then Add(), but slightly faster. * In particular for big objects nothing needs to be done. */ - void Move(entity_id_t item, CFixedVector2D oldPosition, CFixedVector2D newPosition, u32 size) + void Move(entity_id_t item, CFixedVector2D oldPosition, CFixedVector2D newPosition, std::uint32_t size) { if (size > SUBDIVISION_SIZE) return; diff --git a/source/simulation2/scripting/EngineScriptConversions.cpp b/source/simulation2/scripting/EngineScriptConversions.cpp index fcde02cf87..d38285f519 100644 --- a/source/simulation2/scripting/EngineScriptConversions.cpp +++ b/source/simulation2/scripting/EngineScriptConversions.cpp @@ -19,7 +19,6 @@ #include "graphics/Color.h" #include "lib/code_generation.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/FixedVector3D.h" @@ -238,8 +237,8 @@ template<> void Script::ToJSVal>(const Script::Req 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(std::uint8_t)); + std::uint32_t length = static_cast(val.m_W * val.m_H); + std::uint32_t nbytes = static_cast(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 { @@ -260,8 +259,8 @@ template<> void Script::ToJSVal>(const Script::Request& rq, J 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(std::uint16_t)); + std::uint32_t length = static_cast(val.m_W * val.m_H); + std::uint32_t nbytes = static_cast(length * sizeof(std::uint16_t)); JS::RootedObject objArr(rq.cx, JS_NewUint16Array(rq.cx, length)); // Copy the array data and then remove the no-GC check to allow further changes to the JS data { @@ -289,11 +288,11 @@ template<> bool Script::FromJSVal(const Script::Request& rq, JS::Hand if (!JS::IsArrayObject(rq.cx, obj, &isArray) || !isArray) FAIL("Argument must be an array"); - u32 numberOfNodes = 0; + std::uint32_t numberOfNodes = 0; if (!JS::GetArrayLength(rq.cx, obj, &numberOfNodes)) FAIL("Failed to get array length"); - for (u32 i = 0; i < numberOfNodes; ++i) + for (std::uint32_t i = 0; i < numberOfNodes; ++i) { JS::RootedValue node(rq.cx); if (!JS_GetElement(rq.cx, obj, i, &node)) diff --git a/source/simulation2/serialization/BinarySerializer.cpp b/source/simulation2/serialization/BinarySerializer.cpp index 9f7880b7e5..3c701c6bbb 100644 --- a/source/simulation2/serialization/BinarySerializer.cpp +++ b/source/simulation2/serialization/BinarySerializer.cpp @@ -117,7 +117,7 @@ void CBinarySerializerScriptImpl::HandleScriptVal(const Script::Request& rq, JS: JS::RootedObject obj(rq.cx, &val.toObject()); // If we've already serialized this object, just output a reference to it - u32 tag = GetScriptBackrefTag(rq, obj); + std::uint32_t tag = GetScriptBackrefTag(rq, obj); if (tag != 0) { m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_BACKREF); @@ -165,7 +165,7 @@ void CBinarySerializerScriptImpl::HandleScriptVal(const Script::Request& rq, JS: #error TODO: need to convert JS ArrayBuffer data to little-endian #endif - u32 length = JS::GetArrayBufferByteLength(obj); + std::uint32_t length = JS::GetArrayBufferByteLength(obj); m_Serializer.NumberU32_Unbounded("buffer length", length); JS::AutoCheckCannotGC nogc; bool sharedMemory; @@ -332,7 +332,7 @@ void CBinarySerializerScriptImpl::HandleScriptVal(const Script::Request& rq, JS: if (!JS_Enumerate(rq.cx, obj, &ida)) throw PSERROR_Serialize_ScriptError("JS_Enumerate failed"); - m_Serializer.NumberU32_Unbounded("num props", (u32)ida.length()); + m_Serializer.NumberU32_Unbounded("num props", static_cast(ida.length())); for (size_t i = 0; i < ida.length(); ++i) { @@ -467,7 +467,7 @@ void CBinarySerializerScriptImpl::ScriptString(const Script::Request& rq, const const JS::Latin1Char* chars = JS_GetLatin1StringCharsAndLength(rq.cx, nogc, string, &length); if (!chars) throw PSERROR_Serialize_ScriptError("JS_GetLatin1StringCharsAndLength failed"); - m_Serializer.NumberU32_Unbounded("string length", (u32)length); + m_Serializer.NumberU32_Unbounded("string length", static_cast(length)); m_Serializer.RawBytes(name, static_cast(chars), length); } else @@ -476,7 +476,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.NumberU32_Unbounded("string length", static_cast(length)); m_Serializer.RawBytes(name, reinterpret_cast(chars), length*2); } } @@ -487,7 +487,7 @@ void CBinarySerializerScriptImpl::Trace(JSTracer *trc, void *data) serializer->m_ScriptBackrefTags.trace(trc); } -u32 CBinarySerializerScriptImpl::GetScriptBackrefTag(const Script::Request& rq, JS::HandleObject obj) +std::uint32_t CBinarySerializerScriptImpl::GetScriptBackrefTag(const Script::Request& rq, JS::HandleObject obj) { // To support non-tree structures (e.g. "var x = []; var y = [x, x];"), we need a way // to indicate multiple references to one object(/array). So every time we serialize a diff --git a/source/simulation2/serialization/BinarySerializer.h b/source/simulation2/serialization/BinarySerializer.h index 52bdb714d2..037c2c4d52 100644 --- a/source/simulation2/serialization/BinarySerializer.h +++ b/source/simulation2/serialization/BinarySerializer.h @@ -23,7 +23,6 @@ #include "lib/byte_order.h" #include "lib/code_annotation.h" #include "lib/debug.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "simulation2/system/Component.h" @@ -110,10 +109,11 @@ private: const Script::Interface& m_ScriptInterface; ISerializer& m_Serializer; - using ObjectTagMap = JS::GCHashMap, u32, js::StableCellHasher, js::SystemAllocPolicy>; + using ObjectTagMap = JS::GCHashMap, std::uint32_t, + js::StableCellHasher, js::SystemAllocPolicy>; ObjectTagMap m_ScriptBackrefTags; - u32 m_ScriptBackrefsNext; - u32 GetScriptBackrefTag(const Script::Request& rq, JS::HandleObject obj); + std::uint32_t m_ScriptBackrefsNext; + std::uint32_t GetScriptBackrefTag(const Script::Request& rq, JS::HandleObject obj); JS::PropertyKey m_SerializePropId; JS::PropertyKey m_DeserializePropId; @@ -187,7 +187,7 @@ protected: virtual void PutNumber(const char* name, int32_t value) { - int32_t v = static_cast(to_le32((u32)value)); + int32_t v = static_cast(to_le32(static_cast(value))); m_Impl.Put(name, reinterpret_cast(&v), sizeof(int32_t)); } @@ -203,7 +203,8 @@ protected: virtual void PutNumber(const char* name, fixed value) { - int32_t v = static_cast(to_le32((u32)value.GetInternalValue())); + int32_t v = static_cast(to_le32(static_cast( + value.GetInternalValue()))); m_Impl.Put(name, reinterpret_cast(&v), sizeof(int32_t)); } diff --git a/source/simulation2/serialization/IDeserializer.cpp b/source/simulation2/serialization/IDeserializer.cpp index 8b661c22c6..092318721a 100644 --- a/source/simulation2/serialization/IDeserializer.cpp +++ b/source/simulation2/serialization/IDeserializer.cpp @@ -91,7 +91,7 @@ void IDeserializer::NumberI32(const char* name, int32_t& out, int32_t lower, int { int32_t value; Get(name, reinterpret_cast(&value), sizeof(uint32_t)); - value = static_cast(to_le32((u32)value)); + value = static_cast(to_le32(static_cast(value))); if (!(lower <= value && value <= upper)) throw PSERROR_Deserialize_OutOfBounds(name); @@ -134,7 +134,7 @@ void IDeserializer::NumberI32_Unbounded(const char* name, int32_t& out) { int32_t value; Get(name, reinterpret_cast(&value), sizeof(int32_t)); - out = static_cast(to_le32((u32)value)); + out = static_cast(to_le32(static_cast(value))); } void IDeserializer::NumberFloat_Unbounded(const char* name, float& out) diff --git a/source/simulation2/serialization/SerializedTypes.h b/source/simulation2/serialization/SerializedTypes.h index a4fd9ad9df..5dc34f7fa0 100644 --- a/source/simulation2/serialization/SerializedTypes.h +++ b/source/simulation2/serialization/SerializedTypes.h @@ -25,8 +25,6 @@ #include "simulation2/serialization/SerializeTemplates.h" -#include "lib/types.h" - #include #include #include @@ -56,7 +54,7 @@ struct SerializeHelper> void operator()(ISerializer& serialize, const char* name, std::vector& value) { size_t len = value.size(); - serialize.NumberU32_Unbounded("length", (u32)len); + serialize.NumberU32_Unbounded("length", static_cast(len)); for (size_t i = 0; i < len; ++i) Serializer(serialize, name, value[i]); } @@ -64,7 +62,7 @@ struct SerializeHelper> void operator()(IDeserializer& deserialize, const char* name, std::vector& value) { value.clear(); - u32 len; + std::uint32_t len; deserialize.NumberU32_Unbounded("length", len); value.reserve(len); // TODO: watch out for out-of-memory for (size_t i = 0; i < len; ++i) @@ -81,7 +79,7 @@ struct SerializeHelper> { void operator()(ISerializer& serialize, const char* name, const std::set& value) { - serialize.NumberU32_Unbounded("size", static_cast(value.size())); + serialize.NumberU32_Unbounded("size", static_cast(value.size())); for (const T& elem : value) Serializer(serialize, name, elem); } @@ -89,7 +87,7 @@ struct SerializeHelper> void operator()(IDeserializer& deserialize, const char* name, std::set& value) { value.clear(); - u32 size; + std::uint32_t size; deserialize.NumberU32_Unbounded("size", size); for (size_t i = 0; i < size; ++i) { @@ -107,7 +105,7 @@ struct SerializeHelper> void operator()(ISerializer& serialize, const char* /*name*/, std::map& value, Args&&... args) { size_t len = value.size(); - serialize.NumberU32_Unbounded("length", (u32)len); + serialize.NumberU32_Unbounded("length", static_cast(len)); for (typename std::map::iterator it = value.begin(); it != value.end(); ++it) { Serializer(serialize, "key", it->first, std::forward(args)...); @@ -120,7 +118,7 @@ struct SerializeHelper> Args&&... args) { value.clear(); - u32 len; + std::uint32_t len; deserialize.NumberU32_Unbounded("length", len); for (size_t i = 0; i < len; ++i) { @@ -196,16 +194,16 @@ struct SerializeHelper }; template<> -struct SerializeHelper +struct SerializeHelper { template - void operator()(ISerializer& serialize, const char* name, u32 value, Args&&...) + void operator()(ISerializer& serialize, const char* name, std::uint32_t value, Args&&...) { serialize.NumberU32_Unbounded(name, value); } template - void operator()(IDeserializer& deserialize, const char* name, u32& value, Args&&...) + void operator()(IDeserializer& deserialize, const char* name, std::uint32_t& value, Args&&...) { deserialize.NumberU32_Unbounded(name, value); } diff --git a/source/simulation2/serialization/StdDeserializer.cpp b/source/simulation2/serialization/StdDeserializer.cpp index 6b4620eb67..aa654d499d 100644 --- a/source/simulation2/serialization/StdDeserializer.cpp +++ b/source/simulation2/serialization/StdDeserializer.cpp @@ -159,7 +159,7 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* /*name*/, JS::HandleObject JS::RootedObject obj(rq.cx); if (type == SCRIPT_TYPE_ARRAY) { - u32 length; + std::uint32_t length; NumberU32_Unbounded("array length", length); obj.set(JS::NewArrayObject(rq.cx, length)); } @@ -346,7 +346,7 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* /*name*/, JS::HandleObject case SCRIPT_TYPE_TYPED_ARRAY: { std::uint8_t arrayType; - u32 byteOffset, length; + std::uint32_t byteOffset, length; NumberU8_Unbounded("array type", arrayType); NumberU32_Unbounded("byte offset", byteOffset); NumberU32_Unbounded("length", length); @@ -404,7 +404,7 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* /*name*/, JS::HandleObject } case SCRIPT_TYPE_ARRAY_BUFFER: { - u32 length; + std::uint32_t length; NumberU32_Unbounded("buffer length", length); #if BYTE_ORDER != LITTLE_ENDIAN @@ -425,10 +425,10 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* /*name*/, JS::HandleObject JS::RootedObject obj(rq.cx, JS::NewMapObject(rq.cx)); AddScriptBackref(obj); - u32 mapSize; + std::uint32_t mapSize; NumberU32_Unbounded("map size", mapSize); - for (u32 i=0; i class IComponent; @@ -28,7 +26,7 @@ class IComponent; * Entity ID type. * ID numbers are never reused within a simulation run. */ -typedef u32 entity_id_t; +typedef std::uint32_t entity_id_t; /** * Invalid entity ID. Used as an error return value by some functions. diff --git a/source/simulation2/system/EntityMap.h b/source/simulation2/system/EntityMap.h index 49dc7d8c75..7270b24e42 100644 --- a/source/simulation2/system/EntityMap.h +++ b/source/simulation2/system/EntityMap.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 @@ #define INCLUDED_ENTITYMAP #include "lib/debug.h" -#include "lib/types.h" #include "simulation2/serialization/SerializeTemplates.h" #include "simulation2/system/Component.h" #include "simulation2/system/Entity.h" @@ -263,7 +262,7 @@ struct SerializeHelper> void operator()(ISerializer& serialize, const char* /*name*/, EntityMap& value) { size_t len = value.size(); - serialize.NumberU32_Unbounded("length", (u32)len); + serialize.NumberU32_Unbounded("length", static_cast(len)); size_t count = 0; for (typename EntityMap::iterator it = value.begin(); it != value.end(); ++it) { diff --git a/source/simulation2/system/ParamNode.h b/source/simulation2/system/ParamNode.h index 7fee32526b..fefa9a546d 100644 --- a/source/simulation2/system/ParamNode.h +++ b/source/simulation2/system/ParamNode.h @@ -19,7 +19,6 @@ #define INCLUDED_PARAMNODE #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "ps/Errors.h" @@ -275,7 +274,7 @@ public: static std::string EscapeXMLString(const std::string& str); std::string m_Name; - u32 m_Index; + std::uint32_t m_Index; private: diff --git a/source/simulation2/system/ReplayTurnManager.cpp b/source/simulation2/system/ReplayTurnManager.cpp index d2fed32a40..3d0f4c41cc 100644 --- a/source/simulation2/system/ReplayTurnManager.cpp +++ b/source/simulation2/system/ReplayTurnManager.cpp @@ -58,7 +58,7 @@ void CReplayTurnManager::StoreReplayHash(turn_id_t turn, const std::string& hash m_ReplayHash[turn] = std::make_pair(hash, quick); } -void CReplayTurnManager::StoreReplayTurnLength(turn_id_t turn, u32 turnLength) +void CReplayTurnManager::StoreReplayTurnLength(turn_id_t turn, std::uint32_t turnLength) { m_ReplayTurnLengths[turn] = turnLength; diff --git a/source/simulation2/system/ReplayTurnManager.h b/source/simulation2/system/ReplayTurnManager.h index 4c3500b5fb..b7a6cbb425 100644 --- a/source/simulation2/system/ReplayTurnManager.h +++ b/source/simulation2/system/ReplayTurnManager.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_REPLAYTURNMANAGER #define INCLUDED_REPLAYTURNMANAGER -#include "lib/types.h" #include "ps/CStr.h" #include "simulation2/helpers/Player.h" #include "simulation2/system/LocalTurnManager.h" @@ -42,7 +41,7 @@ public: void StoreReplayCommand(turn_id_t turn, int player, const std::string& command); - void StoreReplayTurnLength(turn_id_t turn, u32 turnLength); + void StoreReplayTurnLength(turn_id_t turn, std::uint32_t turnLength); void StoreReplayHash(turn_id_t turn, const std::string& hash, bool quick); @@ -62,7 +61,7 @@ private: std::map>> m_ReplayCommands; // Contains the length of every turn - std::map m_ReplayTurnLengths; + std::map m_ReplayTurnLengths; // Contains all replay hash values and weather or not the quick hash method was used std::map> m_ReplayHash; diff --git a/source/simulation2/system/TurnManager.cpp b/source/simulation2/system/TurnManager.cpp index 60c8e72df3..ab833958ba 100644 --- a/source/simulation2/system/TurnManager.cpp +++ b/source/simulation2/system/TurnManager.cpp @@ -45,7 +45,8 @@ const CStr CTurnManager::EventNameSavegameLoaded = "SavegameLoaded"; -CTurnManager::CTurnManager(CSimulation2& simulation, u32 defaultTurnLength, u32 commandDelay, int clientId, IReplayLogger& replay) +CTurnManager::CTurnManager(CSimulation2& simulation, std::uint32_t defaultTurnLength, + std::uint32_t commandDelay, int clientId, IReplayLogger& replay) : m_Simulation2(simulation), m_CurrentTurn(0), m_CommandDelay(commandDelay), m_ReadyTurn(commandDelay - 1), m_TurnLength(defaultTurnLength), m_PlayerId(-1), m_ClientId(clientId), m_DeltaSimTime(0), m_Replay(replay), m_FinalTurn(std::numeric_limits::max()), m_TimeWarpNumTurns(0) @@ -239,7 +240,7 @@ void CTurnManager::AddCommand(int client, int player, JS::HandleValue data, turn m_QueuedCommands[turn - (m_CurrentTurn+1)][client].emplace_back(player, rq.cx, data); } -void CTurnManager::FinishedAllCommands(turn_id_t turn, u32 turnLength) +void CTurnManager::FinishedAllCommands(turn_id_t turn, std::uint32_t turnLength) { NETTURN_LOG("FinishedAllCommands(%d, %d)\n", turn, turnLength); diff --git a/source/simulation2/system/TurnManager.h b/source/simulation2/system/TurnManager.h index 8e1c50dc7f..7ec5a941e9 100644 --- a/source/simulation2/system/TurnManager.h +++ b/source/simulation2/system/TurnManager.h @@ -61,12 +61,12 @@ class IReplayLogger; * Default turn length in SP & MP. * This value should be as low as possible, while not introducing un-necessary lag. */ -inline constexpr u32 DEFAULT_TURN_LENGTH = 200; +inline constexpr std::uint32_t DEFAULT_TURN_LENGTH = 200; /** * In single-player, commands are directly scheduled for the next turn. */ -inline constexpr u32 COMMAND_DELAY_SP = 1; +inline constexpr std::uint32_t COMMAND_DELAY_SP = 1; /** * In multi-player, clients can only compute turn N if all clients have finished sending commands for it, @@ -80,7 +80,7 @@ inline constexpr u32 COMMAND_DELAY_SP = 1; * - this command-delay could vary based on server-client pings * - it ought be possible to send commands in a P2P fashion (with server verification), which would lower the ping. */ -inline constexpr u32 COMMAND_DELAY_MP = 4; +inline constexpr std::uint32_t COMMAND_DELAY_MP = 4; /** * Common turn system (used by clients and offline games). @@ -97,7 +97,8 @@ public: /** * Construct for a given network session ID. */ - CTurnManager(CSimulation2& simulation, u32 defaultTurnLength, u32 commandDelay, int clientId, IReplayLogger& replay); + CTurnManager(CSimulation2& simulation, std::uint32_t defaultTurnLength, std::uint32_t commandDelay, + int clientId, IReplayLogger& replay); virtual ~CTurnManager() { } @@ -146,7 +147,7 @@ public: * Called when all commands for a given turn have been received. * This allows Update to progress to that turn. */ - void FinishedAllCommands(turn_id_t turn, u32 turnLength); + void FinishedAllCommands(turn_id_t turn, std::uint32_t turnLength); /** * Enables the recording of state snapshots every @p numTurns, @@ -199,13 +200,13 @@ protected: turn_id_t m_CurrentTurn; // Current command delay (commands are scheduled for m_CurrentTurn + m_CommandDelay) - u32 m_CommandDelay; + std::uint32_t m_CommandDelay; /// The latest turn for which we have received all commands from all clients turn_id_t m_ReadyTurn; // Current turn length - u32 m_TurnLength; + std::uint32_t m_TurnLength; /// Commands queued at each turn (index 0 is for m_CurrentTurn+1) std::deque>> m_QueuedCommands; diff --git a/source/simulation2/tests/test_ComponentManager.h b/source/simulation2/tests/test_ComponentManager.h index a72bfcd018..feff7f7d2f 100644 --- a/source/simulation2/tests/test_ComponentManager.h +++ b/source/simulation2/tests/test_ComponentManager.h @@ -20,7 +20,6 @@ #include "lib/file/file_system.h" #include "lib/file/vfs/vfs.h" #include "lib/path.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "ps/CLogger.h" #include "ps/Errors.h" @@ -88,22 +87,23 @@ public: CSimContext context; CComponentManager man(context, *g_ScriptContext); - TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)2); - TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)3); - TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)4); - TS_ASSERT_EQUALS(man.AllocateNewEntity(100), (u32)100); - TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)101); + TS_ASSERT_EQUALS(man.AllocateNewEntity(), static_cast(2)); + TS_ASSERT_EQUALS(man.AllocateNewEntity(), static_cast(3)); + TS_ASSERT_EQUALS(man.AllocateNewEntity(), static_cast(4)); + TS_ASSERT_EQUALS(man.AllocateNewEntity(100), static_cast(100)); + TS_ASSERT_EQUALS(man.AllocateNewEntity(), static_cast(101)); // TODO: - // TS_ASSERT_EQUALS(man.AllocateNewEntity(3), (u32)102); + // TS_ASSERT_EQUALS(man.AllocateNewEntity(3), static_cast(102)); - TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), (u32)FIRST_LOCAL_ENTITY); - TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), (u32)FIRST_LOCAL_ENTITY+1); + TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), static_cast(FIRST_LOCAL_ENTITY)); + TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), + static_cast(FIRST_LOCAL_ENTITY) + 1); man.ResetState(); - TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)2); - TS_ASSERT_EQUALS(man.AllocateNewEntity(3), (u32)3); - TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), (u32)FIRST_LOCAL_ENTITY); + TS_ASSERT_EQUALS(man.AllocateNewEntity(), static_cast(2)); + TS_ASSERT_EQUALS(man.AllocateNewEntity(3), static_cast(3)); + TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), static_cast(FIRST_LOCAL_ENTITY)); } void test_rng() diff --git a/source/simulation2/tests/test_SerializeTemplates.h b/source/simulation2/tests/test_SerializeTemplates.h index 9beb7e3538..3f05324134 100644 --- a/source/simulation2/tests/test_SerializeTemplates.h +++ b/source/simulation2/tests/test_SerializeTemplates.h @@ -17,7 +17,6 @@ #include "lib/self_test.h" -#include "lib/types.h" #include "scriptinterface/Interface.h" #include "simulation2/helpers/Grid.h" #include "simulation2/serialization/DebugSerializer.h" @@ -40,7 +39,7 @@ public: std::stringstream stream; CDebugSerializer serialize(script, stream); - std::array value = { + std::array value = { 3, 0, 1, 4, 1, 5 }; Serializer(serialize, "E", value); @@ -53,7 +52,7 @@ public: std::stringstream stream; CDebugSerializer serialize(script, stream); - std::vector value = { + std::vector value = { 3, 0, 1, 4, 1, 5 }; Serializer(serialize, "E", value); @@ -66,7 +65,7 @@ public: std::stringstream stream; CDebugSerializer serialize(script, stream); - std::set value = { + std::set value = { 3, 0, 1, 4, 1, 5 }; Serializer(serialize, "E", value); diff --git a/source/simulation2/tests/test_Simulation2.h b/source/simulation2/tests/test_Simulation2.h index 189ce3478c..7b7b785041 100644 --- a/source/simulation2/tests/test_Simulation2.h +++ b/source/simulation2/tests/test_Simulation2.h @@ -21,7 +21,6 @@ #include "lib/file/file_system.h" #include "lib/file/vfs/vfs.h" #include "lib/path.h" -#include "lib/types.h" #include "ps/Filesystem.h" #include "ps/XML/Xeromyces.h" #include "scriptinterface/Interface.h" @@ -69,13 +68,13 @@ public: sim.ResetState(true, true); entity_id_t ent1 = sim.AddEntity(L"test1"); - TS_ASSERT_EQUALS(ent1, (u32)2); + TS_ASSERT_EQUALS(ent1, static_cast(2)); TS_ASSERT_EQUALS(static_cast (sim.QueryInterface(ent1, IID_Test1))->GetX(), 999); TS_ASSERT_EQUALS(static_cast (sim.QueryInterface(ent1, IID_Test2))->GetX(), 12345); entity_id_t ent2 = sim.AddEntity(L"test1-inherit"); - TS_ASSERT_EQUALS(ent2, (u32)3); + TS_ASSERT_EQUALS(ent2, static_cast(3)); TS_ASSERT_EQUALS(static_cast (sim.QueryInterface(ent2, IID_Test1))->GetX(), 1234); TS_ASSERT_EQUALS(static_cast (sim.QueryInterface(ent2, IID_Test2))->GetX(), 12345); diff --git a/source/soundmanager/scripting/SoundGroup.cpp b/source/soundmanager/scripting/SoundGroup.cpp index 13902d5c39..be22c4cadb 100644 --- a/source/soundmanager/scripting/SoundGroup.cpp +++ b/source/soundmanager/scripting/SoundGroup.cpp @@ -67,7 +67,7 @@ constexpr ALfloat MAX_ROLLOFF = 0.7f; class CFastRand { public: - using result_type = u32; + using result_type = std::uint32_t; constexpr static result_type min() { return 0; } constexpr static result_type max() { return 0xFFFF; } diff --git a/source/soundmanager/scripting/SoundGroup.h b/source/soundmanager/scripting/SoundGroup.h index 332f86d374..2682e76a20 100644 --- a/source/soundmanager/scripting/SoundGroup.h +++ b/source/soundmanager/scripting/SoundGroup.h @@ -21,7 +21,6 @@ #include "lib/code_annotation.h" #include "lib/config2.h" #include "lib/file/vfs/vfs_path.h" -#include "lib/types.h" #include "simulation2/system/Entity.h" #include @@ -86,7 +85,7 @@ private: // We store the handles so we can load now and play later std::vector m_SoundGroups; #endif - u32 m_Seed; + std::uint32_t m_Seed; // We need the filenames so we can reload when necessary. std::vector m_Filenames; // The file path for the list of sound file resources diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index 49a23340ca..4bbf9448e8 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -36,7 +36,6 @@ #include "lib/path.h" #include "lib/posix/posix_types.h" #include "lib/status.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector3D.h" #include "maths/MathUtil.h" @@ -355,8 +354,9 @@ QUERYHANDLER(RasterizeMinimap) } else { - u32 color = std::numeric_limits::max(); - const u32 hmap = static_cast(terrain.GetHeightMap()[j * dimension + i]) >> 8; + std::uint32_t color = std::numeric_limits::max(); + const std::uint32_t hmap = + static_cast(terrain.GetHeightMap()[j * dimension + i]) >> 8; float scale = hmap / 3.0f + 170.0f / 255.0f; CMiniPatch* const mp = terrain.GetTile(i, j); @@ -449,7 +449,7 @@ BEGIN_COMMAND(ResizeMap) player_id_t owner; CFixedVector3D pos; CFixedVector3D rot; - u32 actorSeed; + std::uint32_t actorSeed; }; ssize_t m_OldPatches, m_NewPatches; diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index e31d56c664..e17f71bbe3 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -24,7 +24,6 @@ #include "graphics/GameView.h" #include "graphics/Terrain.h" #include "lib/debug.h" -#include "lib/types.h" #include "lib/utf8.h" #include "maths/Fixed.h" #include "maths/FixedVector3D.h" @@ -597,7 +596,7 @@ BEGIN_COMMAND(CreateObject) float m_Angle; player_id_t m_Player; entity_id_t m_EntityID; - u32 m_ActorSeed; + std::uint32_t m_ActorSeed; void Do() { @@ -1020,7 +1019,7 @@ BEGIN_COMMAND(DeleteObjects) player_id_t owner; CFixedVector3D pos; CFixedVector3D rot; - u32 actorSeed; + std::uint32_t actorSeed; }; std::vector oldObjects; diff --git a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp index 35f58d1c61..db30d53e0e 100644 --- a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp @@ -31,7 +31,6 @@ #include "lib/posix/posix_types.h" #include "lib/status.h" #include "lib/tex/tex.h" -#include "lib/types.h" #include "maths/Vector3D.h" #include "ps/CStr.h" #include "ps/Filesystem.h" @@ -146,7 +145,7 @@ sTerrainTexturePreview GetPreview(CTerrainTextureEntry* tex, size_t width, size_ else { // Too small to preview. Just use a flat color instead. - const u32 baseColor = tex->GetBaseColor(); + const std::uint32_t baseColor = tex->GetBaseColor(); for (size_t i = 0; i < width * height; ++i) { buffer[i * previewBPP + 0] = (baseColor >> 16) & 0xff; diff --git a/source/tools/lint/cppcheck/suppressions-list.txt b/source/tools/lint/cppcheck/suppressions-list.txt index a587ff371e..a5787da60a 100644 --- a/source/tools/lint/cppcheck/suppressions-list.txt +++ b/source/tools/lint/cppcheck/suppressions-list.txt @@ -73,3 +73,5 @@ danglingLifetime:source/renderer/backend/gl/Device.cpp uninitvar:source/gui/Scripting/JSInterface_GUISize.cpp nullPointer:source/ps/scripting/JSInterface_Debug.cpp unknownMacro:source/dapinterface/tests/test_DapInterface.h + +shiftTooManyBits:source/lib/bits.h