From 95a39b328148165bdd163a5a1edee5b81dd5054a Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 12 Aug 2023 13:12:05 +0200 Subject: [PATCH] Use sized types for land records members --- apps/esmtool/labels.cpp | 2 +- apps/esmtool/labels.hpp | 3 ++- components/esm/esmterrain.cpp | 8 ++++---- components/esm/esmterrain.hpp | 15 +++++++-------- components/esm3/loadland.cpp | 12 ++++++------ components/esm3/loadland.hpp | 30 +++++++++++++++--------------- components/esm4/loadland.hpp | 6 +++--- 7 files changed, 38 insertions(+), 38 deletions(-) diff --git a/apps/esmtool/labels.cpp b/apps/esmtool/labels.cpp index 5f2026b724..d0a443de53 100644 --- a/apps/esmtool/labels.cpp +++ b/apps/esmtool/labels.cpp @@ -759,7 +759,7 @@ std::string enchantmentFlags(int flags) return properties; } -std::string landFlags(int flags) +std::string landFlags(std::uint32_t flags) { std::string properties; // The ESM component says that this first four bits are used, but diff --git a/apps/esmtool/labels.hpp b/apps/esmtool/labels.hpp index 2baa8a3fdc..df6d419ca3 100644 --- a/apps/esmtool/labels.hpp +++ b/apps/esmtool/labels.hpp @@ -1,6 +1,7 @@ #ifndef OPENMW_ESMTOOL_LABELS_H #define OPENMW_ESMTOOL_LABELS_H +#include #include #include @@ -53,7 +54,7 @@ std::string cellFlags(int flags); std::string containerFlags(int flags); std::string creatureFlags(int flags); std::string enchantmentFlags(int flags); -std::string landFlags(int flags); +std::string landFlags(std::uint32_t flags); std::string creatureListFlags(int flags); std::string itemListFlags(int flags); std::string lightFlags(int flags); diff --git a/components/esm/esmterrain.cpp b/components/esm/esmterrain.cpp index eda6bbc785..42b7a4b8b3 100644 --- a/components/esm/esmterrain.cpp +++ b/components/esm/esmterrain.cpp @@ -13,10 +13,10 @@ ESM::LandData::LandData(const ESM::Land& land, int loadFlags) std::span heights(data.mHeights); mHeights = std::vector(heights.begin(), heights.end()); - std::span normals(data.mNormals); + std::span normals(data.mNormals); mNormals = std::vector(normals.begin(), normals.end()); - std::span colors(data.mColours); + std::span colors(data.mColours); mColors = std::vector(colors.begin(), colors.end()); std::span textures(data.mTextures); @@ -59,9 +59,9 @@ ESM::LandData::LandData(const ESM4::Land& land, int /*loadFlags*/) } } - std::span normals(land.mVertNorm); + std::span normals(land.mVertNorm); mNormals = std::vector(normals.begin(), normals.end()); - std::span colors(land.mVertColr); + std::span colors(land.mVertColr); mColors = std::vector(colors.begin(), colors.end()); } diff --git a/components/esm/esmterrain.hpp b/components/esm/esmterrain.hpp index 9ada20f467..eeb8519dfc 100644 --- a/components/esm/esmterrain.hpp +++ b/components/esm/esmterrain.hpp @@ -1,6 +1,7 @@ #ifndef COMPONENTS_ESM_ESMTERRAIN #define COMPONENTS_ESM_ESMTERRAIN +#include #include #include @@ -18,12 +19,10 @@ namespace ESM LandData(const ESM::Land& Land, int loadFLags); LandData(const ESM4::Land& Land, int loadFLags); - typedef signed char VNML; - std::span getHeights() const { return mHeights; } - std::span getNormals() const { return mNormals; } - std::span getColors() const { return mColors; } - std::span getTextures() const { return mTextures; } + std::span getNormals() const { return mNormals; } + std::span getColors() const { return mColors; } + std::span getTextures() const { return mTextures; } float getSize() const { return mSize; } float getMinHeight() const { return mMinHeight; } float getMaxHeight() const { return mMaxHeight; } @@ -37,9 +36,9 @@ namespace ESM float mSize = 0.f; int mLandSize = 0; std::vector mHeights; - std::vector mNormals; - std::vector mColors; - std::vector mTextures; + std::vector mNormals; + std::vector mColors; + std::vector mTextures; }; } diff --git a/components/esm3/loadland.cpp b/components/esm3/loadland.cpp index c64a2d35b5..653cd03fd2 100644 --- a/components/esm3/loadland.cpp +++ b/components/esm3/loadland.cpp @@ -49,8 +49,8 @@ namespace ESM esm.getSubHeader(); if (esm.getSubSize() != 8) esm.fail("Subrecord size is not equal to 8"); - esm.getT(mX); - esm.getT(mY); + esm.getT(mX); + esm.getT(mY); hasLocation = true; break; case fourCC("DATA"): @@ -160,9 +160,9 @@ namespace ESM if (mDataTypes & Land::DATA_WNAM) { // Generate WNAM record - signed char wnam[LAND_GLOBAL_MAP_LOD_SIZE]; - constexpr float max = std::numeric_limits::max(); - constexpr float min = std::numeric_limits::min(); + std::int8_t wnam[LAND_GLOBAL_MAP_LOD_SIZE]; + constexpr float max = std::numeric_limits::max(); + constexpr float min = std::numeric_limits::min(); constexpr float vertMult = static_cast(Land::LAND_SIZE - 1) / LAND_GLOBAL_MAP_LOD_SIZE_SQRT; for (int row = 0; row < LAND_GLOBAL_MAP_LOD_SIZE_SQRT; ++row) { @@ -171,7 +171,7 @@ namespace ESM float height = mLandData->mHeights[int(row * vertMult) * Land::LAND_SIZE + int(col * vertMult)]; height /= height > 0 ? 128.f : 16.f; height = std::clamp(height, min, max); - wnam[row * LAND_GLOBAL_MAP_LOD_SIZE_SQRT + col] = static_cast(height); + wnam[row * LAND_GLOBAL_MAP_LOD_SIZE_SQRT + col] = static_cast(height); } } esm.writeHNT("WNAM", wnam); diff --git a/components/esm3/loadland.hpp b/components/esm3/loadland.hpp index 9712aa3066..5ee9ab447c 100644 --- a/components/esm3/loadland.hpp +++ b/components/esm3/loadland.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_ESM_LAND_H #define OPENMW_ESM_LAND_H -#include +#include #include @@ -28,9 +28,11 @@ namespace ESM Land(); ~Land(); - int mFlags; // Only first four bits seem to be used, don't know what - // they mean. - int mX, mY; // Map coordinates. + // Only first four bits seem to be used, don't know what they mean. + std::uint32_t mFlags; + // Map coordinates. + std::int32_t mX; + std::int32_t mY; // Plugin index, used to reference the correct material palette. int getPlugin() const { return mContext.index; } @@ -81,16 +83,14 @@ namespace ESM struct VHGT { float mHeightOffset; - int8_t mHeightData[LAND_NUM_VERTS]; - short mUnk1; - char mUnk2; + std::int8_t mHeightData[LAND_NUM_VERTS]; + std::uint16_t mUnk1; + std::uint8_t mUnk2; }; #pragma pack(pop) struct LandData { - typedef signed char VNML; - LandData() : mHeightOffset(0) , mMinHeight(0) @@ -109,25 +109,25 @@ namespace ESM float mMaxHeight; // 24-bit normals, these aren't always correct though. Edge and corner normals may be garbage. - VNML mNormals[LAND_NUM_VERTS * 3]; + std::int8_t mNormals[LAND_NUM_VERTS * 3]; // 2D array of texture indices. An index can be used to look up an LandTexture, // but to do so you must subtract 1 from the index first! // An index of 0 indicates the default texture. - uint16_t mTextures[LAND_NUM_TEXTURES]; + std::uint16_t mTextures[LAND_NUM_TEXTURES]; // 24-bit RGB color for each vertex - unsigned char mColours[3 * LAND_NUM_VERTS]; + std::uint8_t mColours[3 * LAND_NUM_VERTS]; // ??? - short mUnk1; - uint8_t mUnk2; + std::uint16_t mUnk1; + std::uint8_t mUnk2; int mDataLoaded; }; // low-LOD heightmap (used for rendering the global map) - signed char mWnam[LAND_GLOBAL_MAP_LOD_SIZE]; + std::int8_t mWnam[LAND_GLOBAL_MAP_LOD_SIZE]; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm4/loadland.hpp b/components/esm4/loadland.hpp index cbd3941a2b..3b81dc0d40 100644 --- a/components/esm4/loadland.hpp +++ b/components/esm4/loadland.hpp @@ -69,7 +69,7 @@ namespace ESM4 float heightOffset; std::int8_t gradientData[VERTS_PER_SIDE * VERTS_PER_SIDE]; std::uint16_t unknown1; - unsigned char unknown2; + std::uint8_t unknown2; }; struct BTXT @@ -119,8 +119,8 @@ namespace ESM4 float mHeights[VERTS_PER_SIDE * VERTS_PER_SIDE]; // Float value of compressed Heightmap float mMinHeight, mMaxHeight; - signed char mVertNorm[VERTS_PER_SIDE * VERTS_PER_SIDE * 3]; // from VNML subrecord - unsigned char mVertColr[VERTS_PER_SIDE * VERTS_PER_SIDE * 3]; // from VCLR subrecord + std::int8_t mVertNorm[VERTS_PER_SIDE * VERTS_PER_SIDE * 3]; // from VNML subrecord + std::uint8_t mVertColr[VERTS_PER_SIDE * VERTS_PER_SIDE * 3]; // from VCLR subrecord VHGT mHeightMap; Texture mTextures[4]; // 0 = bottom left, 1 = bottom right, 2 = top left, 3 = top right std::vector mIds; // land texture (LTEX) formids