diff --git a/apps/openmw/mwrender/terrainstorage.cpp b/apps/openmw/mwrender/terrainstorage.cpp index 66a3e1c545..871f6fd70e 100644 --- a/apps/openmw/mwrender/terrainstorage.cpp +++ b/apps/openmw/mwrender/terrainstorage.cpp @@ -34,7 +34,7 @@ namespace MWRender return land != nullptr; } - void TerrainStorage::getBounds(float& minX, float& maxX, float& minY, float& maxY) + void TerrainStorage::getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) { minX = 0; minY = 0; @@ -43,19 +43,41 @@ namespace MWRender const MWWorld::ESMStore& esmStore = *MWBase::Environment::get().getESMStore(); - MWWorld::Store::iterator it = esmStore.get().begin(); - for (; it != esmStore.get().end(); ++it) + if (ESM::isEsm4Ext(worldspace)) { - if (it->mX < minX) - minX = static_cast(it->mX); - if (it->mX > maxX) - maxX = static_cast(it->mX); - if (it->mY < minY) - minY = static_cast(it->mY); - if (it->mY > maxY) - maxY = static_cast(it->mY); + const auto& lands = esmStore.get().getLands(); + for (const auto& it : lands) + { + if (it.first.mWorldspace == worldspace) + { + int x = it.first.mX; + int y = it.first.mY; + if (x < minX) + minX = static_cast(x); + if (x > maxX) + maxX = static_cast(x); + if (y < minY) + minY = static_cast(y); + if (y > maxY) + maxY = static_cast(y); + } + } + } + else + { + MWWorld::Store::iterator it = esmStore.get().begin(); + for (; it != esmStore.get().end(); ++it) + { + if (it->mX < minX) + minX = static_cast(it->mX); + if (it->mX > maxX) + maxX = static_cast(it->mX); + if (it->mY < minY) + minY = static_cast(it->mY); + if (it->mY > maxY) + maxY = static_cast(it->mY); + } } - // since grid coords are at cell origin, we need to add 1 cell maxX += 1; maxY += 1; diff --git a/apps/openmw/mwrender/terrainstorage.hpp b/apps/openmw/mwrender/terrainstorage.hpp index a375fd0d91..2526c779c6 100644 --- a/apps/openmw/mwrender/terrainstorage.hpp +++ b/apps/openmw/mwrender/terrainstorage.hpp @@ -27,7 +27,7 @@ namespace MWRender bool hasData(ESM::ExteriorCellLocation cellLocation) override; /// Get bounds of the whole terrain in cell units - void getBounds(float& minX, float& maxX, float& minY, float& maxY) override; + void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) override; LandManager* getLandManager() const; diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index e2581f8bc7..a6f218ffe6 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -312,6 +312,7 @@ namespace MWWorld void updateLandPositions(const Store& cells); const ESM4::Land* search(ESM::ExteriorCellLocation cellLocation) const; + const std::unordered_map& getLands() const { return mLands; }; }; template <> diff --git a/components/esm3terrain/storage.hpp b/components/esm3terrain/storage.hpp index 2f3522b394..8876ae9755 100644 --- a/components/esm3terrain/storage.hpp +++ b/components/esm3terrain/storage.hpp @@ -72,7 +72,7 @@ namespace ESMTerrain virtual osg::ref_ptr getLand(ESM::ExteriorCellLocation cellLocation) = 0; virtual const ESM::LandTexture* getLandTexture(int index, short plugin) = 0; /// Get bounds of the whole terrain in cell units - void getBounds(float& minX, float& maxX, float& minY, float& maxY) override = 0; + void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) override = 0; /// Get the minimum and maximum heights of a terrain region. /// @note Will only be called for chunks with size = minBatchSize, i.e. leafs of the quad tree. diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 9d559ecc22..50415cc8a8 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -130,7 +130,7 @@ namespace Terrain void build() { - mStorage->getBounds(mMinX, mMaxX, mMinY, mMaxY); + mStorage->getBounds(mMinX, mMaxX, mMinY, mMaxY, mWorldspace); int origSizeX = static_cast(mMaxX - mMinX); int origSizeY = static_cast(mMaxY - mMinY); diff --git a/components/terrain/storage.hpp b/components/terrain/storage.hpp index db712570ee..c4a44f5024 100644 --- a/components/terrain/storage.hpp +++ b/components/terrain/storage.hpp @@ -29,7 +29,7 @@ namespace Terrain public: /// Get bounds of the whole terrain in cell units - virtual void getBounds(float& minX, float& maxX, float& minY, float& maxY) = 0; + virtual void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) = 0; /// Return true if there is land data for this cell /// May be overriden for a faster implementation