From 2f730011dcaa2f89d8f2faf4bbc80bf7cfd6c877 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 9 Jan 2023 10:50:30 +0100 Subject: [PATCH 1/3] Initialize WorldModel::mIdCache in the class initializer list --- apps/openmw/mwworld/worldmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 4157c42b15..a2400e662c 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -153,11 +153,11 @@ void MWWorld::WorldModel::writeCell(ESM::ESMWriter& writer, CellStore& cell) con MWWorld::WorldModel::WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCache& readers) : mStore(store) , mReaders(readers) + , mIdCache(std::clamp(Settings::Manager::getInt("pointers cache size", "Cells"), 40, 1000), + { ESM::RefId::sEmpty, nullptr }) , mIdCacheIndex(0) , mPtrIndexUpdateCounter(0) { - int cacheSize = std::clamp(Settings::Manager::getInt("pointers cache size", "Cells"), 40, 1000); - mIdCache = IdCache(cacheSize, std::pair(ESM::RefId(), (CellStore*)nullptr)); } MWWorld::CellStore* MWWorld::WorldModel::getExterior(int x, int y) From 48fde4b5179ede5338b411f5861cfa5aefeb1c07 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 9 Jan 2023 10:54:11 +0100 Subject: [PATCH 2/3] Use default initializers for WorldModel members --- apps/openmw/mwworld/worldmodel.cpp | 2 -- apps/openmw/mwworld/worldmodel.hpp | 9 ++++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index a2400e662c..79d59de902 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -155,8 +155,6 @@ MWWorld::WorldModel::WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCach , mReaders(readers) , mIdCache(std::clamp(Settings::Manager::getInt("pointers cache size", "Cells"), 40, 1000), { ESM::RefId::sEmpty, nullptr }) - , mIdCacheIndex(0) - , mPtrIndexUpdateCounter(0) { } diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index 52f426f854..f7abbe10ac 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -45,7 +45,10 @@ namespace MWWorld mutable std::map mInteriors; mutable std::map, CellStore> mExteriors; IdCache mIdCache; - std::size_t mIdCacheIndex; + std::size_t mIdCacheIndex = 0; + std::unordered_map mPtrIndex; + std::size_t mPtrIndexUpdateCounter = 0; + ESM::RefNum mLastGeneratedRefnum; WorldModel(const WorldModel&); WorldModel& operator=(const WorldModel&); @@ -58,10 +61,6 @@ namespace MWWorld void writeCell(ESM::ESMWriter& writer, CellStore& cell) const; - std::unordered_map mPtrIndex; - size_t mPtrIndexUpdateCounter; - ESM::RefNum mLastGeneratedRefnum; - public: void clear(); From 4cf5136143d7eff1e1a8dfaf37922783ceb3aea8 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 9 Jan 2023 10:55:42 +0100 Subject: [PATCH 3/3] Mark WorldModel copy ctor and assignment operators as delete --- apps/openmw/mwworld/worldmodel.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index f7abbe10ac..909e85d25b 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -50,9 +50,6 @@ namespace MWWorld std::size_t mPtrIndexUpdateCounter = 0; ESM::RefNum mLastGeneratedRefnum; - WorldModel(const WorldModel&); - WorldModel& operator=(const WorldModel&); - const ESM::Cell* getESMCellByName(std::string_view name); ESM::CellVariant getCellByName(std::string_view name); @@ -62,10 +59,13 @@ namespace MWWorld void writeCell(ESM::ESMWriter& writer, CellStore& cell) const; public: - void clear(); - explicit WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCache& reader); + WorldModel(const WorldModel&) = delete; + WorldModel& operator=(const WorldModel&) = delete; + + void clear(); + CellStore* getExterior(int x, int y); CellStore* getInterior(std::string_view name); CellStore* getCell(std::string_view name); // interior or named exterior