Move collectESM3References to unnamed namespace

esm4-texture
elsid 8 months ago
parent 524af5b723
commit 0040409a4d
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -15,6 +15,7 @@
#include <components/esm3/esmreader.hpp> #include <components/esm3/esmreader.hpp>
#include <components/esm3/loadacti.hpp> #include <components/esm3/loadacti.hpp>
#include <components/esm3/loadcell.hpp>
#include <components/esm3/loadcont.hpp> #include <components/esm3/loadcont.hpp>
#include <components/esm3/loaddoor.hpp> #include <components/esm3/loaddoor.hpp>
#include <components/esm3/loadstat.hpp> #include <components/esm3/loadstat.hpp>
@ -465,72 +466,76 @@ namespace MWRender
{ {
} }
std::map<ESM::RefNum, ESM::CellRef> ObjectPaging::collectESM3References( namespace
float size, const osg::Vec2i& startCell, ESM::ReadersCache& readers) const
{ {
std::map<ESM::RefNum, ESM::CellRef> refs; std::map<ESM::RefNum, ESM::CellRef> collectESM3References(
const auto& store = MWBase::Environment::get().getWorld()->getStore(); float size, const osg::Vec2i& startCell, ESM::ReadersCache& readers)
for (int cellX = startCell.x(); cellX < startCell.x() + size; ++cellX)
{ {
for (int cellY = startCell.y(); cellY < startCell.y() + size; ++cellY) std::map<ESM::RefNum, ESM::CellRef> refs;
const auto& store = MWBase::Environment::get().getWorld()->getStore();
for (int cellX = startCell.x(); cellX < startCell.x() + size; ++cellX)
{ {
const ESM::Cell* cell = store.get<ESM::Cell>().searchStatic(cellX, cellY); for (int cellY = startCell.y(); cellY < startCell.y() + size; ++cellY)
if (!cell)
continue;
for (size_t i = 0; i < cell->mContextList.size(); ++i)
{ {
try const ESM::Cell* cell = store.get<ESM::Cell>().searchStatic(cellX, cellY);
if (!cell)
continue;
for (size_t i = 0; i < cell->mContextList.size(); ++i)
{ {
const std::size_t index = static_cast<std::size_t>(cell->mContextList[i].index); try
const ESM::ReadersCache::BusyItem reader = readers.get(index);
cell->restore(*reader, i);
ESM::CellRef ref;
ESM::MovedCellRef cMRef;
bool deleted = false;
bool moved = false;
while (ESM::Cell::getNextRef(
*reader, ref, deleted, cMRef, moved, ESM::Cell::GetNextRefMode::LoadOnlyNotMoved))
{ {
if (moved) const std::size_t index = static_cast<std::size_t>(cell->mContextList[i].index);
continue; const ESM::ReadersCache::BusyItem reader = readers.get(index);
cell->restore(*reader, i);
if (std::find(cell->mMovedRefs.begin(), cell->mMovedRefs.end(), ref.mRefNum) ESM::CellRef ref;
!= cell->mMovedRefs.end()) ESM::MovedCellRef cMRef;
continue; bool deleted = false;
bool moved = false;
int type = store.findStatic(ref.mRefID); while (ESM::Cell::getNextRef(
if (!typeFilter(type, size >= 2)) *reader, ref, deleted, cMRef, moved, ESM::Cell::GetNextRefMode::LoadOnlyNotMoved))
continue;
if (deleted)
{ {
refs.erase(ref.mRefNum); if (moved)
continue; continue;
if (std::find(cell->mMovedRefs.begin(), cell->mMovedRefs.end(), ref.mRefNum)
!= cell->mMovedRefs.end())
continue;
int type = store.findStatic(ref.mRefID);
if (!typeFilter(type, size >= 2))
continue;
if (deleted)
{
refs.erase(ref.mRefNum);
continue;
}
refs[ref.mRefNum] = std::move(ref);
} }
refs[ref.mRefNum] = std::move(ref); }
catch (const std::exception& e)
{
Log(Debug::Warning) << "Failed to collect references from cell \"" << cell->getDescription()
<< "\": " << e.what();
continue;
} }
} }
catch (const std::exception& e)
{ for (auto [ref, deleted] : cell->mLeasedRefs)
Log(Debug::Warning) << "Failed to collect references from cell \"" << cell->getDescription()
<< "\": " << e.what();
continue;
}
}
for (auto [ref, deleted] : cell->mLeasedRefs)
{
if (deleted)
{ {
refs.erase(ref.mRefNum); if (deleted)
continue; {
refs.erase(ref.mRefNum);
continue;
}
int type = store.findStatic(ref.mRefID);
if (!typeFilter(type, size >= 2))
continue;
refs[ref.mRefNum] = std::move(ref);
} }
int type = store.findStatic(ref.mRefID);
if (!typeFilter(type, size >= 2))
continue;
refs[ref.mRefNum] = std::move(ref);
} }
} }
return refs;
} }
return refs;
} }
osg::ref_ptr<osg::Node> ObjectPaging::createChunk(float size, const osg::Vec2f& center, bool activeGrid, osg::ref_ptr<osg::Node> ObjectPaging::createChunk(float size, const osg::Vec2f& center, bool activeGrid,

@ -1,7 +1,7 @@
#ifndef OPENMW_MWRENDER_OBJECTPAGING_H #ifndef OPENMW_MWRENDER_OBJECTPAGING_H
#define OPENMW_MWRENDER_OBJECTPAGING_H #define OPENMW_MWRENDER_OBJECTPAGING_H
#include <components/esm3/loadcell.hpp> #include <components/esm3/refnum.hpp>
#include <components/resource/resourcemanager.hpp> #include <components/resource/resourcemanager.hpp>
#include <components/terrain/quadtreeworld.hpp> #include <components/terrain/quadtreeworld.hpp>
@ -11,15 +11,6 @@ namespace Resource
{ {
class SceneManager; class SceneManager;
} }
namespace MWWorld
{
class ESMStore;
}
namespace ESM
{
class ReadersCache;
}
namespace MWRender namespace MWRender
{ {
@ -82,9 +73,6 @@ namespace MWRender
const RefTracker& getRefTracker() const { return mRefTracker; } const RefTracker& getRefTracker() const { return mRefTracker; }
RefTracker& getWritableRefTracker() { return mRefTrackerLocked ? mRefTrackerNew : mRefTracker; } RefTracker& getWritableRefTracker() { return mRefTrackerLocked ? mRefTrackerNew : mRefTracker; }
std::map<ESM::RefNum, ESM::CellRef> collectESM3References(
float size, const osg::Vec2i& startCell, ESM::ReadersCache& readers) const;
std::mutex mSizeCacheMutex; std::mutex mSizeCacheMutex;
typedef std::map<ESM::RefNum, float> SizeCache; typedef std::map<ESM::RefNum, float> SizeCache;
SizeCache mSizeCache; SizeCache mSizeCache;

Loading…
Cancel
Save