2021-10-29 12:47:17 +00:00
|
|
|
#include "groundcoverstore.hpp"
|
|
|
|
|
|
|
|
#include <components/esm3/loadcell.hpp>
|
2022-06-26 17:05:00 +00:00
|
|
|
#include <components/esm3/loadstat.hpp>
|
2022-06-01 20:53:18 +00:00
|
|
|
#include <components/esm3/readerscache.hpp>
|
2022-08-16 20:44:13 +00:00
|
|
|
#include <components/esmloader/esmdata.hpp>
|
|
|
|
#include <components/esmloader/load.hpp>
|
2022-06-28 22:32:11 +00:00
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
2022-08-02 22:00:54 +00:00
|
|
|
#include <components/misc/strings/lower.hpp>
|
2022-06-28 22:32:11 +00:00
|
|
|
#include <components/resource/resourcesystem.hpp>
|
2021-10-29 12:47:17 +00:00
|
|
|
|
2022-06-26 17:05:00 +00:00
|
|
|
#include "store.hpp"
|
|
|
|
|
2021-10-29 12:47:17 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
2022-06-03 16:59:08 +00: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 12:47:17 +00:00
|
|
|
{
|
2022-05-13 10:35:58 +00:00
|
|
|
::EsmLoader::Query query;
|
2021-10-29 12:47:17 +00:00
|
|
|
query.mLoadStatics = true;
|
|
|
|
query.mLoadCells = true;
|
|
|
|
|
2022-06-01 20:53:18 +00:00
|
|
|
ESM::ReadersCache readers;
|
2024-10-12 12:16:50 +00:00
|
|
|
::EsmLoader::EsmData content
|
2022-06-03 16:59:08 +00:00
|
|
|
= ::EsmLoader::loadEsmData(query, groundcoverFiles, fileCollections, readers, encoder, listener);
|
2021-10-29 12:47:17 +00:00
|
|
|
|
2024-10-12 12:16:50 +00:00
|
|
|
static constexpr std::string_view prefix = "grass/";
|
2021-10-29 12:47:17 +00:00
|
|
|
for (const ESM::Static& stat : statics)
|
|
|
|
{
|
2024-10-12 12:16:50 +00:00
|
|
|
VFS::Path::Normalized model = VFS::Path::toNormalized(stat.mModel);
|
|
|
|
if (!model.value().starts_with(prefix))
|
2022-06-16 12:46:08 +00:00
|
|
|
continue;
|
2023-12-26 12:00:30 +00:00
|
|
|
mMeshCache[stat.mId] = Misc::ResourceHelpers::correctMeshPath(model);
|
2021-10-29 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const ESM::Static& stat : content.mStatics)
|
|
|
|
{
|
2024-10-12 12:16:50 +00:00
|
|
|
VFS::Path::Normalized model = VFS::Path::toNormalized(stat.mModel);
|
|
|
|
if (!model.value().starts_with(prefix))
|
2022-06-16 12:46:08 +00:00
|
|
|
continue;
|
2023-12-26 12:00:30 +00:00
|
|
|
mMeshCache[stat.mId] = Misc::ResourceHelpers::correctMeshPath(model);
|
2021-10-29 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
2024-10-12 12:16:50 +00:00
|
|
|
for (ESM::Cell& cell : content.mCells)
|
2021-10-29 12:47:17 +00:00
|
|
|
{
|
|
|
|
if (!cell.isExterior())
|
|
|
|
continue;
|
2023-02-21 22:26:40 +00:00
|
|
|
auto cellIndex = std::make_pair(cell.getGridX(), cell.getGridY());
|
2021-10-29 12:47:17 +00:00
|
|
|
mCellContexts[cellIndex] = std::move(cell.mContextList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|