1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 03:59:56 +00:00

Use sized types for land records members

This commit is contained in:
elsid 2023-08-12 13:12:05 +02:00
parent f15ccec0d9
commit 95a39b3281
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
7 changed files with 38 additions and 38 deletions

View file

@ -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

View file

@ -1,6 +1,7 @@
#ifndef OPENMW_ESMTOOL_LABELS_H
#define OPENMW_ESMTOOL_LABELS_H
#include <cstdint>
#include <string>
#include <string_view>
@ -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);

View file

@ -13,10 +13,10 @@ ESM::LandData::LandData(const ESM::Land& land, int loadFlags)
std::span<const float> heights(data.mHeights);
mHeights = std::vector(heights.begin(), heights.end());
std::span<const VNML> normals(data.mNormals);
std::span<const std::int8_t> normals(data.mNormals);
mNormals = std::vector(normals.begin(), normals.end());
std::span<const unsigned char> colors(data.mColours);
std::span<const std::uint8_t> colors(data.mColours);
mColors = std::vector(colors.begin(), colors.end());
std::span<const uint16_t> textures(data.mTextures);
@ -59,9 +59,9 @@ ESM::LandData::LandData(const ESM4::Land& land, int /*loadFlags*/)
}
}
std::span<const VNML> normals(land.mVertNorm);
std::span<const std::int8_t> normals(land.mVertNorm);
mNormals = std::vector(normals.begin(), normals.end());
std::span<const unsigned char> colors(land.mVertColr);
std::span<const std::uint8_t> colors(land.mVertColr);
mColors = std::vector(colors.begin(), colors.end());
}

View file

@ -1,6 +1,7 @@
#ifndef COMPONENTS_ESM_ESMTERRAIN
#define COMPONENTS_ESM_ESMTERRAIN
#include <cstdint>
#include <span>
#include <vector>
@ -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<const float> getHeights() const { return mHeights; }
std::span<const VNML> getNormals() const { return mNormals; }
std::span<const unsigned char> getColors() const { return mColors; }
std::span<const uint16_t> getTextures() const { return mTextures; }
std::span<const std::int8_t> getNormals() const { return mNormals; }
std::span<const std::uint8_t> getColors() const { return mColors; }
std::span<const std::uint16_t> 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<float> mHeights;
std::vector<VNML> mNormals;
std::vector<unsigned char> mColors;
std::vector<uint16_t> mTextures;
std::vector<std::int8_t> mNormals;
std::vector<std::uint8_t> mColors;
std::vector<std::uint16_t> mTextures;
};
}

View file

@ -49,8 +49,8 @@ namespace ESM
esm.getSubHeader();
if (esm.getSubSize() != 8)
esm.fail("Subrecord size is not equal to 8");
esm.getT<int>(mX);
esm.getT<int>(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<signed char>::max();
constexpr float min = std::numeric_limits<signed char>::min();
std::int8_t wnam[LAND_GLOBAL_MAP_LOD_SIZE];
constexpr float max = std::numeric_limits<std::int8_t>::max();
constexpr float min = std::numeric_limits<std::int8_t>::min();
constexpr float vertMult = static_cast<float>(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<signed char>(height);
wnam[row * LAND_GLOBAL_MAP_LOD_SIZE_SQRT + col] = static_cast<std::int8_t>(height);
}
}
esm.writeHNT("WNAM", wnam);

View file

@ -1,7 +1,7 @@
#ifndef OPENMW_ESM_LAND_H
#define OPENMW_ESM_LAND_H
#include <stdint.h>
#include <cstdint>
#include <components/misc/constants.hpp>
@ -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;

View file

@ -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<ESM::FormId> mIds; // land texture (LTEX) formids