mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 07:45:36 +00:00
Convert PositionCellGrid into a struct
This commit is contained in:
parent
491a59b035
commit
d71b422615
6 changed files with 36 additions and 24 deletions
|
@ -84,6 +84,7 @@ add_openmw_dir (mwworld
|
|||
store esmstore fallback actionrepair actionsoulgem livecellref actiondoor
|
||||
contentloader esmloader actiontrap cellreflist cellref weather projectilemanager
|
||||
cellpreloader datetimemanager groundcoverstore magiceffects cell ptrregistry
|
||||
positioncellgrid
|
||||
)
|
||||
|
||||
add_openmw_dir (mwphysics
|
||||
|
|
|
@ -29,15 +29,15 @@
|
|||
namespace
|
||||
{
|
||||
template <class Contained>
|
||||
bool contains(const std::vector<MWWorld::CellPreloader::PositionCellGrid>& container, const Contained& contained,
|
||||
float tolerance)
|
||||
bool contains(const std::vector<MWWorld::PositionCellGrid>& container, const Contained& contained, float tolerance)
|
||||
{
|
||||
for (const auto& pos : contained)
|
||||
{
|
||||
bool found = false;
|
||||
for (const auto& pos2 : container)
|
||||
{
|
||||
if ((pos.first - pos2.first).length2() < tolerance * tolerance && pos.second == pos2.second)
|
||||
if ((pos.mPosition - pos2.mPosition).length2() < tolerance * tolerance
|
||||
&& pos.mCellBounds == pos2.mCellBounds)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
|
@ -52,7 +52,6 @@ namespace
|
|||
|
||||
namespace MWWorld
|
||||
{
|
||||
|
||||
struct ListModelsVisitor
|
||||
{
|
||||
bool operator()(const MWWorld::ConstPtr& ptr)
|
||||
|
@ -170,7 +169,7 @@ namespace MWWorld
|
|||
{
|
||||
public:
|
||||
TerrainPreloadItem(const std::vector<osg::ref_ptr<Terrain::View>>& views, Terrain::World* world,
|
||||
const std::vector<CellPreloader::PositionCellGrid>& preloadPositions)
|
||||
const std::vector<PositionCellGrid>& preloadPositions)
|
||||
: mAbort(false)
|
||||
, mTerrainViews(views)
|
||||
, mWorld(world)
|
||||
|
@ -183,8 +182,8 @@ namespace MWWorld
|
|||
for (unsigned int i = 0; i < mTerrainViews.size() && i < mPreloadPositions.size() && !mAbort; ++i)
|
||||
{
|
||||
mTerrainViews[i]->reset();
|
||||
mWorld->preload(mTerrainViews[i], mPreloadPositions[i].first, mPreloadPositions[i].second, mAbort,
|
||||
mLoadingReporter);
|
||||
mWorld->preload(mTerrainViews[i], mPreloadPositions[i].mPosition, mPreloadPositions[i].mCellBounds,
|
||||
mAbort, mLoadingReporter);
|
||||
}
|
||||
mLoadingReporter.complete();
|
||||
}
|
||||
|
@ -197,7 +196,7 @@ namespace MWWorld
|
|||
std::atomic<bool> mAbort;
|
||||
std::vector<osg::ref_ptr<Terrain::View>> mTerrainViews;
|
||||
Terrain::World* mWorld;
|
||||
std::vector<CellPreloader::PositionCellGrid> mPreloadPositions;
|
||||
std::vector<PositionCellGrid> mPreloadPositions;
|
||||
Loading::Reporter mLoadingReporter;
|
||||
};
|
||||
|
||||
|
@ -375,7 +374,7 @@ namespace MWWorld
|
|||
mTerrainPreloadItem->wait(listener);
|
||||
}
|
||||
|
||||
void CellPreloader::abortTerrainPreloadExcept(const CellPreloader::PositionCellGrid* exceptPos)
|
||||
void CellPreloader::abortTerrainPreloadExcept(const PositionCellGrid* exceptPos)
|
||||
{
|
||||
if (exceptPos && contains(mTerrainPreloadPositions, std::array{ *exceptPos }, Constants::CellSizeInUnits))
|
||||
return;
|
||||
|
@ -384,10 +383,10 @@ namespace MWWorld
|
|||
mTerrainPreloadItem->abort();
|
||||
mTerrainPreloadItem->waitTillDone();
|
||||
}
|
||||
setTerrainPreloadPositions(std::vector<CellPreloader::PositionCellGrid>());
|
||||
setTerrainPreloadPositions(std::vector<PositionCellGrid>());
|
||||
}
|
||||
|
||||
void CellPreloader::setTerrainPreloadPositions(const std::vector<CellPreloader::PositionCellGrid>& positions)
|
||||
void CellPreloader::setTerrainPreloadPositions(const std::vector<PositionCellGrid>& positions)
|
||||
{
|
||||
if (positions.empty())
|
||||
{
|
||||
|
@ -417,7 +416,7 @@ namespace MWWorld
|
|||
}
|
||||
}
|
||||
|
||||
bool CellPreloader::isTerrainLoaded(const CellPreloader::PositionCellGrid& position, double referenceTime) const
|
||||
bool CellPreloader::isTerrainLoaded(const PositionCellGrid& position, double referenceTime) const
|
||||
{
|
||||
return mLoadedTerrainTimestamp + mResourceSystem->getSceneManager()->getExpiryDelay() > referenceTime
|
||||
&& contains(mLoadedTerrainPositions, std::array{ position }, Constants::CellSizeInUnits);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#ifndef OPENMW_MWWORLD_CELLPRELOADER_H
|
||||
#define OPENMW_MWWORLD_CELLPRELOADER_H
|
||||
|
||||
#include "positioncellgrid.hpp"
|
||||
|
||||
#include <components/sceneutil/workqueue.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <osg/Vec3f>
|
||||
#include <osg/Vec4i>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <map>
|
||||
|
@ -79,12 +77,11 @@ namespace MWWorld
|
|||
|
||||
void setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue);
|
||||
|
||||
typedef std::pair<osg::Vec3f, osg::Vec4i> PositionCellGrid;
|
||||
void setTerrainPreloadPositions(const std::vector<PositionCellGrid>& positions);
|
||||
|
||||
void syncTerrainLoad(Loading::Listener& listener);
|
||||
void abortTerrainPreloadExcept(const PositionCellGrid* exceptPos);
|
||||
bool isTerrainLoaded(const CellPreloader::PositionCellGrid& position, double referenceTime) const;
|
||||
bool isTerrainLoaded(const PositionCellGrid& position, double referenceTime) const;
|
||||
void setTerrain(Terrain::World* terrain);
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
|
||||
|
|
16
apps/openmw/mwworld/positioncellgrid.hpp
Normal file
16
apps/openmw/mwworld/positioncellgrid.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef OPENMW_APPS_OPENMW_MWWORLD_POSITIONCELLGRID_H
|
||||
#define OPENMW_APPS_OPENMW_MWWORLD_POSITIONCELLGRID_H
|
||||
|
||||
#include <osg/Vec3f>
|
||||
#include <osg/Vec4i>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
struct PositionCellGrid
|
||||
{
|
||||
osg::Vec3f mPosition;
|
||||
osg::Vec4i mCellBounds;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -603,7 +603,7 @@ namespace MWWorld
|
|||
mPreloader->setTerrain(mRendering.getTerrain());
|
||||
if (mRendering.pagingUnlockCache())
|
||||
mPreloader->abortTerrainPreloadExcept(nullptr);
|
||||
if (!mPreloader->isTerrainLoaded(std::make_pair(pos, newGrid), mRendering.getReferenceTime()))
|
||||
if (!mPreloader->isTerrainLoaded(PositionCellGrid{ pos, newGrid }, mRendering.getReferenceTime()))
|
||||
preloadTerrain(pos, playerCellIndex.mWorldspace, true);
|
||||
mPagedRefs.clear();
|
||||
mRendering.getPagedRefnums(newGrid, mPagedRefs);
|
||||
|
@ -1093,8 +1093,8 @@ namespace MWWorld
|
|||
osg::Vec3f predictedPos = playerPos + moved / dt * mPredictionTime;
|
||||
|
||||
if (mCurrentCell->isExterior())
|
||||
exteriorPositions.emplace_back(
|
||||
predictedPos, gridCenterToBounds(getNewGridCenter(predictedPos, &mCurrentGridCenter)));
|
||||
exteriorPositions.push_back(PositionCellGrid{
|
||||
predictedPos, gridCenterToBounds(getNewGridCenter(predictedPos, &mCurrentGridCenter)) });
|
||||
|
||||
mLastPlayerPos = playerPos;
|
||||
|
||||
|
@ -1305,7 +1305,7 @@ namespace MWWorld
|
|||
const ESM::ExteriorCellLocation cellIndex
|
||||
= ESM::positionToExteriorCellLocation(pos.x(), pos.y(), extWorldspace);
|
||||
preloadCellWithSurroundings(mWorld.getWorldModel().getExterior(cellIndex));
|
||||
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
|
||||
exteriorPositions.push_back(PositionCellGrid{ pos, gridCenterToBounds(getNewGridCenter(pos)) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <osg/Vec4i>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include "positioncellgrid.hpp"
|
||||
#include "ptr.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
@ -122,8 +123,6 @@ namespace MWWorld
|
|||
|
||||
void requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent = true);
|
||||
|
||||
typedef std::pair<osg::Vec3f, osg::Vec4i> PositionCellGrid;
|
||||
|
||||
void preloadCells(float dt);
|
||||
void preloadTeleportDoorDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos,
|
||||
std::vector<PositionCellGrid>& exteriorPositions);
|
||||
|
|
Loading…
Reference in a new issue