From 325bf666533795d777bda39bbe62fba298e979a6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 13 Feb 2017 01:29:22 +0100 Subject: [PATCH] Return const Land in ESMStore --- apps/openmw/mwrender/globalmap.cpp | 2 +- apps/openmw/mwrender/terrainstorage.cpp | 3 ++- apps/openmw/mwworld/scene.cpp | 4 ++-- apps/openmw/mwworld/store.cpp | 8 ++++---- apps/openmw/mwworld/store.hpp | 4 ++-- components/esm/loadland.cpp | 2 +- components/esm/loadland.hpp | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index 5cf1ecd36..e89c3d147 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -153,7 +153,7 @@ namespace MWRender { for (int y = mMinY; y <= mMaxY; ++y) { - ESM::Land* land = esmStore.get().search (x,y); + const ESM::Land* land = esmStore.get().search (x,y); if (land) { diff --git a/apps/openmw/mwrender/terrainstorage.cpp b/apps/openmw/mwrender/terrainstorage.cpp index 98386690b..311eb1621 100644 --- a/apps/openmw/mwrender/terrainstorage.cpp +++ b/apps/openmw/mwrender/terrainstorage.cpp @@ -43,7 +43,8 @@ namespace MWRender { const MWWorld::ESMStore &esmStore = MWBase::Environment::get().getWorld()->getStore(); - ESM::Land* land = esmStore.get().search(cellX, cellY); + + const ESM::Land* land = esmStore.get().search(cellX, cellY); if (!land) return NULL; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 3917518a2..8a3178e6c 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -228,7 +228,7 @@ namespace MWWorld if ((*iter)->getCell()->isExterior()) { - ESM::Land* land = + const ESM::Land* land = MWBase::Environment::get().getWorld()->getStore().get().search( (*iter)->getCell()->getGridX(), (*iter)->getCell()->getGridY() @@ -262,7 +262,7 @@ namespace MWWorld // Load terrain physics first... if (cell->getCell()->isExterior()) { - ESM::Land* land = + const ESM::Land* land = MWBase::Environment::get().getWorld()->getStore().get().search( cell->getCell()->getGridX(), cell->getCell()->getGridY() diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index c13f10d9a..ce41ddf94 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -436,7 +436,7 @@ namespace MWWorld { return iterator(mStatic.end()); } - ESM::Land *Store::search(int x, int y) const + const ESM::Land *Store::search(int x, int y) const { ESM::Land land; land.mX = x, land.mY = y; @@ -445,13 +445,13 @@ namespace MWWorld std::lower_bound(mStatic.begin(), mStatic.end(), &land, Compare()); if (it != mStatic.end() && (*it)->mX == x && (*it)->mY == y) { - return const_cast(*it); + return *it; } return 0; } - ESM::Land *Store::find(int x, int y) const + const ESM::Land *Store::find(int x, int y) const { - ESM::Land *ptr = search(x, y); + const ESM::Land *ptr = search(x, y); if (ptr == 0) { std::ostringstream msg; msg << "Land at (" << x << ", " << y << ") not found"; diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 617c3552a..3babea86a 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -242,8 +242,8 @@ namespace MWWorld // Must be threadsafe! Called from terrain background loading threads. // Not a big deal here, since ESM::Land can never be modified or inserted/erased - ESM::Land *search(int x, int y) const; - ESM::Land *find(int x, int y) const; + const ESM::Land *search(int x, int y) const; + const ESM::Land *find(int x, int y) const; RecordId load(ESM::ESMReader &esm); void setUp(); diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index fd69cdacc..d30bfdf49 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -234,7 +234,7 @@ namespace ESM } } - void Land::unloadData() + void Land::unloadData() const { if (mDataLoaded) { diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index a2bf1573e..5598fb616 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -123,7 +123,7 @@ struct Land /** * Frees memory allocated for land data */ - void unloadData(); + void unloadData() const; /// Check if given data type is loaded /// @note We only check data types that *can* be loaded (present in mDataTypes)