diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index cfd7084965..ac7a8a9351 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -18,6 +18,7 @@ #include #include +#include #include "../mwbase/environment.hpp" diff --git a/apps/openmw/mwrender/terrainstorage.cpp b/apps/openmw/mwrender/terrainstorage.cpp index 3ae99e9465..11fdbd774f 100644 --- a/apps/openmw/mwrender/terrainstorage.cpp +++ b/apps/openmw/mwrender/terrainstorage.cpp @@ -1,5 +1,7 @@ #include "terrainstorage.hpp" +#include + #include "../mwbase/environment.hpp" #include "../mwworld/esmstore.hpp" diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index e7d2a322c5..7da5e8f848 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -394,7 +395,7 @@ namespace MWWorld void CellPreloader::abortTerrainPreloadExcept(const CellPreloader::PositionCellGrid* exceptPos) { - if (exceptPos && contains(mTerrainPreloadPositions, std::array{ *exceptPos }, ESM::Land::REAL_SIZE)) + if (exceptPos && contains(mTerrainPreloadPositions, std::array{ *exceptPos }, Constants::CellSizeInUnits)) return; if (mTerrainPreloadItem && !mTerrainPreloadItem->isDone()) { @@ -437,7 +438,7 @@ namespace MWWorld bool CellPreloader::isTerrainLoaded(const CellPreloader::PositionCellGrid& position, double referenceTime) const { return mLoadedTerrainTimestamp + mResourceSystem->getSceneManager()->getExpiryDelay() > referenceTime - && contains(mLoadedTerrainPositions, std::array{ position }, ESM::Land::REAL_SIZE); + && contains(mLoadedTerrainPositions, std::array{ position }, Constants::CellSizeInUnits); } void CellPreloader::setTerrain(Terrain::World* terrain) diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index b8fbda4118..bbf095fed1 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -37,11 +37,6 @@ namespace ESM class ESMWriter; } -namespace ESM4 -{ - struct Land; -} - namespace Loading { class Listener; diff --git a/components/esm/esmterrain.cpp b/components/esm/esmterrain.cpp index 27f21b6a32..4bc6768e51 100644 --- a/components/esm/esmterrain.cpp +++ b/components/esm/esmterrain.cpp @@ -1,19 +1,26 @@ -#include - #include "esmterrain.hpp" +#include +#include +#include + namespace { - constexpr std::uint16_t textures[ESM::Land::LAND_NUM_TEXTURES]{ 0 }; + constexpr std::uint16_t textures[ESM::LandRecordData::sLandNumTextures]{ 0 }; - std::unique_ptr loadData(const ESM::Land& land, int loadFlags) + std::unique_ptr loadData(const ESM::Land& land, int loadFlags) { - std::unique_ptr result = std::make_unique(); + std::unique_ptr result = std::make_unique(); land.loadData(loadFlags, *result); return result; } } +namespace ESM +{ + LandData::LandData() = default; +} + ESM::LandData::LandData(const ESM::Land& land, int loadFlags) : mData(loadData(land, loadFlags)) , mLoadFlags(mData->mDataLoaded) @@ -63,3 +70,8 @@ ESM::LandData::LandData(const ESM4::Land& land, int /*loadFlags*/) mHeights = mHeightsData; } + +namespace ESM +{ + LandData::~LandData() = default; +} diff --git a/components/esm/esmterrain.hpp b/components/esm/esmterrain.hpp index 8aaf4d078c..991df54c8f 100644 --- a/components/esm/esmterrain.hpp +++ b/components/esm/esmterrain.hpp @@ -6,19 +6,25 @@ #include #include -#include -#include +namespace ESM4 +{ + struct Land; +} namespace ESM { + struct Land; + struct LandRecordData; + class LandData { public: - ~LandData() = default; - LandData() = default; + LandData(); LandData(const ESM::Land& Land, int loadFlags); LandData(const ESM4::Land& Land, int loadFlags); + ~LandData(); + std::span getHeights() const { return mHeights; } std::span getNormals() const { return mNormals; } std::span getColors() const { return mColors; } @@ -31,7 +37,7 @@ namespace ESM int getPlugin() const { return mPlugin; } private: - std::unique_ptr mData; + std::unique_ptr mData; int mLoadFlags = 0; std::vector mHeightsData; float mMinHeight = 0.f; diff --git a/components/esm3/landrecorddata.hpp b/components/esm3/landrecorddata.hpp new file mode 100644 index 0000000000..e7db0d9f3a --- /dev/null +++ b/components/esm3/landrecorddata.hpp @@ -0,0 +1,48 @@ +#ifndef OPENMW_COMPONENTS_ESM3_LANDRECORDDATA_H +#define OPENMW_COMPONENTS_ESM3_LANDRECORDDATA_H + +#include + +namespace ESM +{ + struct LandRecordData + { + // number of vertices per side + static constexpr unsigned sLandSize = 65; + + // total number of vertices + static constexpr unsigned sLandNumVerts = sLandSize * sLandSize; + + // number of textures per side of land + static constexpr unsigned sLandTextureSize = 16; + + // total number of textures per land + static constexpr unsigned sLandNumTextures = sLandTextureSize * sLandTextureSize; + + // Initial reference height for the first vertex, only needed for filling mHeights + float mHeightOffset = 0; + // Height in world space for each vertex + float mHeights[sLandNumVerts]; + float mMinHeight = 0; + float mMaxHeight = 0; + + // 24-bit normals, these aren't always correct though. Edge and corner normals may be garbage. + std::int8_t mNormals[sLandNumVerts * 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. + std::uint16_t mTextures[sLandNumTextures]; + + // 24-bit RGB color for each vertex + std::uint8_t mColours[3 * sLandNumVerts]; + + // ??? + std::uint16_t mUnk1 = 0; + std::uint8_t mUnk2 = 0; + + int mDataLoaded = 0; + }; +} + +#endif diff --git a/components/esm3/loadland.hpp b/components/esm3/loadland.hpp index 0aef70a476..0d32407a5d 100644 --- a/components/esm3/loadland.hpp +++ b/components/esm3/loadland.hpp @@ -10,6 +10,8 @@ #include "components/esm/defs.hpp" #include "components/esm/esmcommon.hpp" +#include "landrecorddata.hpp" + namespace ESM { @@ -68,21 +70,21 @@ namespace ESM static constexpr int DEFAULT_HEIGHT = -2048; // number of vertices per side - static constexpr int LAND_SIZE = 65; + static constexpr int LAND_SIZE = LandRecordData::sLandSize; // cell terrain size in world coords static constexpr int REAL_SIZE = Constants::CellSizeInUnits; // total number of vertices - static constexpr int LAND_NUM_VERTS = LAND_SIZE * LAND_SIZE; + static constexpr int LAND_NUM_VERTS = LandRecordData::sLandNumVerts; static constexpr int HEIGHT_SCALE = 8; // number of textures per side of land - static constexpr int LAND_TEXTURE_SIZE = 16; + static constexpr int LAND_TEXTURE_SIZE = LandRecordData::sLandTextureSize; // total number of textures per land - static constexpr int LAND_NUM_TEXTURES = LAND_TEXTURE_SIZE * LAND_TEXTURE_SIZE; + static constexpr int LAND_NUM_TEXTURES = LandRecordData::sLandNumTextures; static constexpr int LAND_GLOBAL_MAP_LOD_SIZE = 81; @@ -98,32 +100,7 @@ namespace ESM }; #pragma pack(pop) - struct LandData - { - // Initial reference height for the first vertex, only needed for filling mHeights - float mHeightOffset = 0; - // Height in world space for each vertex - float mHeights[LAND_NUM_VERTS]; - float mMinHeight = 0; - float mMaxHeight = 0; - - // 24-bit normals, these aren't always correct though. Edge and corner normals may be garbage. - 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. - std::uint16_t mTextures[LAND_NUM_TEXTURES]; - - // 24-bit RGB color for each vertex - std::uint8_t mColours[3 * LAND_NUM_VERTS]; - - // ??? - std::uint16_t mUnk1 = 0; - std::uint8_t mUnk2 = 0; - - int mDataLoaded = 0; - }; + using LandData = ESM::LandRecordData; // low-LOD heightmap (used for rendering the global map) std::array mWnam; diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index d2f34f95b9..af6d9754a3 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/components/esmterrain/storage.hpp b/components/esmterrain/storage.hpp index 465d12071d..4858dfd544 100644 --- a/components/esmterrain/storage.hpp +++ b/components/esmterrain/storage.hpp @@ -8,7 +8,6 @@ #include #include -#include #include namespace ESM4