2021-10-29 16:47:17 +04:00
|
|
|
#include "groundcoverstore.hpp"
|
|
|
|
|
|
|
|
#include <components/esmloader/load.hpp>
|
2022-06-26 19:05:00 +02:00
|
|
|
#include <components/esmloader/esmdata.hpp>
|
2022-08-03 00:00:54 +02:00
|
|
|
#include <components/misc/strings/lower.hpp>
|
2022-06-01 22:53:18 +02:00
|
|
|
#include <components/esm3/readerscache.hpp>
|
2022-06-29 00:32:11 +02:00
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
|
|
|
#include <components/resource/resourcesystem.hpp>
|
2022-08-16 22:44:13 +02:00
|
|
|
#include <components/esm3/loadstat.hpp>
|
|
|
|
#include <components/esm3/loadcell.hpp>
|
2021-10-29 16:47:17 +04:00
|
|
|
|
2022-05-13 19:28:53 +02:00
|
|
|
#include <apps/openmw/mwbase/environment.hpp>
|
|
|
|
|
2022-06-26 19:05:00 +02:00
|
|
|
#include "store.hpp"
|
|
|
|
|
2021-10-29 16:47:17 +04:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
2022-06-03 18:59:08 +02:00
|
|
|
void GroundcoverStore::init(const Store<ESM::Static>& statics, const Files::Collections& fileCollections,
|
|
|
|
const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener)
|
2021-10-29 16:47:17 +04:00
|
|
|
{
|
2022-05-13 12:35:58 +02:00
|
|
|
::EsmLoader::Query query;
|
2021-10-29 16:47:17 +04:00
|
|
|
query.mLoadStatics = true;
|
|
|
|
query.mLoadCells = true;
|
|
|
|
|
2022-06-01 22:53:18 +02:00
|
|
|
ESM::ReadersCache readers;
|
2022-06-03 18:59:08 +02:00
|
|
|
const ::EsmLoader::EsmData content = ::EsmLoader::loadEsmData(query, groundcoverFiles, fileCollections,
|
|
|
|
readers, encoder, listener);
|
2021-10-29 16:47:17 +04:00
|
|
|
|
2022-06-29 00:32:11 +02:00
|
|
|
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
|
|
|
|
2022-06-16 15:46:08 +03:00
|
|
|
static constexpr std::string_view prefix = "grass\\";
|
2021-10-29 16:47:17 +04:00
|
|
|
for (const ESM::Static& stat : statics)
|
|
|
|
{
|
|
|
|
std::string id = Misc::StringUtils::lowerCase(stat.mId);
|
2022-06-16 15:46:08 +03:00
|
|
|
std::string model = Misc::StringUtils::lowerCase(stat.mModel);
|
|
|
|
std::replace(model.begin(), model.end(), '/', '\\');
|
|
|
|
if (model.compare(0, prefix.size(), prefix) != 0)
|
|
|
|
continue;
|
2022-06-29 00:32:11 +02:00
|
|
|
mMeshCache[id] = Misc::ResourceHelpers::correctMeshPath(model, vfs);
|
2021-10-29 16:47:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const ESM::Static& stat : content.mStatics)
|
|
|
|
{
|
|
|
|
std::string id = Misc::StringUtils::lowerCase(stat.mId);
|
2022-06-16 15:46:08 +03:00
|
|
|
std::string model = Misc::StringUtils::lowerCase(stat.mModel);
|
|
|
|
std::replace(model.begin(), model.end(), '/', '\\');
|
|
|
|
if (model.compare(0, prefix.size(), prefix) != 0)
|
|
|
|
continue;
|
2022-06-29 00:32:11 +02:00
|
|
|
mMeshCache[id] = Misc::ResourceHelpers::correctMeshPath(model, vfs);
|
2021-10-29 16:47:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|