diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 8b8fd9823..21f3e18a2 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -148,6 +148,7 @@ set(GAMEWORLD mwworld/actiontake.cpp mwworld/containerutil.cpp mwworld/player.cpp + mwworld/cells.cpp ) set(GAMEWORLD_HEADER mwworld/refdata.hpp @@ -168,6 +169,7 @@ set(GAMEWORLD_HEADER mwworld/containerutil.hpp mwworld/player.hpp mwworld/cellfunctors.hpp + mwworld/cells.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp new file mode 100644 index 000000000..062408ffd --- /dev/null +++ b/apps/openmw/mwworld/cells.cpp @@ -0,0 +1,33 @@ +#include "cells.hpp" + +MWWorld::Cells::Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader) +: mStore (store), mReader (reader) {} + +MWWorld::Ptr::CellStore *MWWorld::Cells::getExterior (int x, int y) +{ + std::map, Ptr::CellStore>::iterator result = + mExteriors.find (std::make_pair (x, y)); + + if (result==mExteriors.end()) + { + result = mExteriors.insert (std::make_pair (std::make_pair (x, y), Ptr::CellStore())).first; + + result->second.loadExt (x, y, mStore, mReader); + } + + return &result->second; +} + +MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name) +{ + std::map::iterator result = mInteriors.find (name); + + if (result==mInteriors.end()) + { + result = mInteriors.insert (std::make_pair (name, Ptr::CellStore())).first; + + result->second.loadInt (name, mStore, mReader); + } + + return &result->second; +} diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp new file mode 100644 index 000000000..217f61360 --- /dev/null +++ b/apps/openmw/mwworld/cells.hpp @@ -0,0 +1,43 @@ +#ifndef GAME_MWWORLD_CELLS_H +#define GAME_MWWORLD_CELLS_H + +#include +#include + +#include "ptr.hpp" + +namespace ESM +{ + class ESMReader; +} + +namespace ESM +{ + class ESMStore; +} + +namespace MWWorld +{ + /// \brief Cell container + class Cells + { + const ESMS::ESMStore& mStore; + ESM::ESMReader& mReader; + std::map mInteriors; + std::map, Ptr::CellStore> mExteriors; + + Cells (const Cells&); + Cells& operator= (const Cells&); + + public: + + Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader); + + Ptr::CellStore *getExterior (int x, int y); + + Ptr::CellStore *getInterior (const std::string& name); + + }; +} + +#endif diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 53a0ed923..11bdad35f 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -135,7 +135,6 @@ namespace MWWorld if (iter==mActiveCells.end()) { - mWorld->getExterior(x, y)->loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = mWorld->getExterior(x, y); loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); @@ -204,7 +203,6 @@ namespace MWWorld // Load cell. std::cout << "cellName:" << cellName << std::endl; - mWorld->getInterior(cellName)->loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = mWorld->getInterior(cellName); loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 86edd2b38..2e665fd1d 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -279,7 +279,7 @@ namespace MWWorld const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) : mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0), - mSky (false), mEnvironment (environment), mNextDynamicRecord (0) + mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm) { mPhysEngine = physEng; @@ -348,12 +348,12 @@ namespace MWWorld Ptr::CellStore *World::getExterior (int x, int y) { - return &mExteriors[std::make_pair (x, y)]; + return mCells.getExterior (x, y); } - Ptr::CellStore *World::getInterior (std::string name) + Ptr::CellStore *World::getInterior (const std::string& name) { - return &mInteriors[name]; + return mCells.getInterior (name); } MWWorld::Player& World::getPlayer() diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 8a5fc4bc4..fd1195268 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -16,6 +16,7 @@ #include "globals.hpp" #include "scene.hpp" #include "physicssystem.hpp" +#include "cells.hpp" #include @@ -78,8 +79,7 @@ namespace MWWorld MWRender::RenderingManager *mRenderingManager; int mNextDynamicRecord; - std::map mInteriors; - std::map, Ptr::CellStore> mExteriors; + Cells mCells; OEngine::Physic::PhysicEngine* mPhysEngine; @@ -108,7 +108,7 @@ namespace MWWorld Ptr::CellStore *getExterior (int x, int y); - Ptr::CellStore *getInterior (std::string name); + Ptr::CellStore *getInterior (const std::string& name); void removeScripts (Ptr::CellStore *cell);