#ifndef GAME_MWWORLD_WORLDMODEL_H #define GAME_MWWORLD_WORLDMODEL_H #include #include #include #include #include #include #include #include "cellstore.hpp" #include "ptr.hpp" #include "ptrregistry.hpp" namespace ESM { class ESMReader; class ESMWriter; class ReadersCache; struct Cell; } namespace ESM4 { struct Cell; } namespace Loading { class Listener; } namespace MWWorld { class ESMStore; /// \brief Cell container class WorldModel { public: explicit WorldModel(ESMStore& store, ESM::ReadersCache& reader); WorldModel(const WorldModel&) = delete; WorldModel& operator=(const WorldModel&) = delete; void clear(); CellStore& getExterior(ESM::ExteriorCellLocation cellIndex, bool forceLoad = true); CellStore& getInterior(std::string_view name, bool forceLoad = true); CellStore& getCell(std::string_view name, bool forceLoad = true); // interior or named exterior CellStore& getCell(const ESM::RefId& Id, bool forceLoad = true); Ptr getPtr(const ESM::RefId& name); PtrRegistry& getPtrRegistry() { return mPtrRegistry; } template void forEachLoadedCellStore(Fn&& fn) { for (auto& [_, store] : mCells) fn(store); } /// Get all Ptrs referencing \a name in exterior cells /// @note Due to the current implementation of getPtr this only supports one Ptr per cell. /// @note name must be lower case void getExteriorPtrs(const ESM::RefId& name, std::vector& out); std::vector getAll(const ESM::RefId& id); int countSavedGameRecords() const; void write(ESM::ESMWriter& writer, Loading::Listener& progress) const; bool readRecord(ESM::ESMReader& reader, uint32_t type, const std::map& contentFileMap); private: MWWorld::ESMStore& mStore; ESM::ReadersCache& mReaders; mutable std::unordered_map mCells; mutable std::map mInteriors; mutable std::map mExteriors; std::vector> mIdCache; std::size_t mIdCacheIndex = 0; PtrRegistry mPtrRegistry; CellStore& getOrInsertCellStore(const ESM::Cell& cell); CellStore& insertCellStore(const ESM::Cell& cell); CellStore* getInteriorOrNull(std::string_view name); Ptr getPtrAndCache(const ESM::RefId& name, CellStore& cellStore); void writeCell(ESM::ESMWriter& writer, CellStore& cell) const; }; } #endif