mirror of https://github.com/OpenMW/openmw.git
Use a separate storage for groundcover data
parent
ca64d7bc18
commit
3275440f0d
@ -0,0 +1,54 @@
|
|||||||
|
#include "groundcoverstore.hpp"
|
||||||
|
|
||||||
|
#include <components/esmloader/load.hpp>
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
void GroundcoverStore::init(const Store<ESM::Static>& statics, const Files::Collections& fileCollections, const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder)
|
||||||
|
{
|
||||||
|
EsmLoader::Query query;
|
||||||
|
query.mLoadStatics = true;
|
||||||
|
query.mLoadCells = true;
|
||||||
|
|
||||||
|
std::vector<ESM::ESMReader> readers(groundcoverFiles.size());
|
||||||
|
const EsmLoader::EsmData content = EsmLoader::loadEsmData(query, groundcoverFiles, fileCollections, readers, encoder);
|
||||||
|
|
||||||
|
for (const ESM::Static& stat : statics)
|
||||||
|
{
|
||||||
|
std::string id = Misc::StringUtils::lowerCase(stat.mId);
|
||||||
|
mMeshCache[id] = "meshes\\" + Misc::StringUtils::lowerCase(stat.mModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const ESM::Static& stat : content.mStatics)
|
||||||
|
{
|
||||||
|
std::string id = Misc::StringUtils::lowerCase(stat.mId);
|
||||||
|
mMeshCache[id] = "meshes\\" + Misc::StringUtils::lowerCase(stat.mModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const ESM::Cell& cell : content.mCells)
|
||||||
|
{
|
||||||
|
if (!cell.isExterior()) continue;
|
||||||
|
auto cellIndex = std::make_pair(cell.getCellId().mIndex.mX, cell.getCellId().mIndex.mY);
|
||||||
|
mCellContexts[cellIndex] = std::move(cell.mContextList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GroundcoverStore::getGroundcoverModel(const std::string& id) const
|
||||||
|
{
|
||||||
|
std::string idLower = Misc::StringUtils::lowerCase(id);
|
||||||
|
auto search = mMeshCache.find(idLower);
|
||||||
|
if (search == mMeshCache.end()) return std::string();
|
||||||
|
|
||||||
|
return search->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroundcoverStore::initCell(ESM::Cell& cell, int cellX, int cellY) const
|
||||||
|
{
|
||||||
|
cell.blank();
|
||||||
|
|
||||||
|
auto searchCell = mCellContexts.find(std::make_pair(cellX, cellY));
|
||||||
|
if (searchCell != mCellContexts.end())
|
||||||
|
cell.mContextList = searchCell->second;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef GAME_MWWORLD_GROUNDCOVER_STORE_H
|
||||||
|
#define GAME_MWWORLD_GROUNDCOVER_STORE_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <components/esm/esmreader.hpp>
|
||||||
|
#include <components/esmloader/esmdata.hpp>
|
||||||
|
#include <components/files/collections.hpp>
|
||||||
|
|
||||||
|
#include "esmstore.hpp"
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
class GroundcoverStore
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::map<std::string, std::string> mMeshCache;
|
||||||
|
std::map<std::pair<int, int>, std::vector<ESM::ESM_Context>> mCellContexts;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init(const Store<ESM::Static>& statics, const Files::Collections& fileCollections, const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder);
|
||||||
|
std::string getGroundcoverModel(const std::string& id) const;
|
||||||
|
void initCell(ESM::Cell& cell, int cellX, int cellY) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue