|
|
@ -13,6 +13,7 @@
|
|
|
|
#include <components/detournavigator/navigator.hpp>
|
|
|
|
#include <components/detournavigator/navigator.hpp>
|
|
|
|
#include <components/detournavigator/updateguard.hpp>
|
|
|
|
#include <components/detournavigator/updateguard.hpp>
|
|
|
|
#include <components/esm/records.hpp>
|
|
|
|
#include <components/esm/records.hpp>
|
|
|
|
|
|
|
|
#include <components/esm3/loadcell.hpp>
|
|
|
|
#include <components/loadinglistener/loadinglistener.hpp>
|
|
|
|
#include <components/loadinglistener/loadinglistener.hpp>
|
|
|
|
#include <components/misc/convert.hpp>
|
|
|
|
#include <components/misc/convert.hpp>
|
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
|
|
@ -39,7 +40,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "cellpreloader.hpp"
|
|
|
|
#include "cellpreloader.hpp"
|
|
|
|
#include "cellstore.hpp"
|
|
|
|
#include "cellstore.hpp"
|
|
|
|
#include "cellutils.hpp"
|
|
|
|
|
|
|
|
#include "cellvisitors.hpp"
|
|
|
|
#include "cellvisitors.hpp"
|
|
|
|
#include "class.hpp"
|
|
|
|
#include "class.hpp"
|
|
|
|
#include "esmstore.hpp"
|
|
|
|
#include "esmstore.hpp"
|
|
|
@ -247,12 +247,12 @@ namespace
|
|
|
|
return std::abs(cellPosition.first) + std::abs(cellPosition.second);
|
|
|
|
return std::abs(cellPosition.first) + std::abs(cellPosition.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool isCellInCollection(int x, int y, MWWorld::Scene::CellStoreCollection& collection)
|
|
|
|
bool isCellInCollection(ESM::ExteriorCellLocation cellIndex, MWWorld::Scene::CellStoreCollection& collection)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (auto* cell : collection)
|
|
|
|
for (auto* cell : collection)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(cell->getCell()->isExterior());
|
|
|
|
assert(cell->getCell()->isExterior());
|
|
|
|
if (x == cell->getCell()->getGridX() && y == cell->getCell()->getGridY())
|
|
|
|
if (cellIndex == cell->getCell()->getExteriorCellLocation())
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -304,8 +304,8 @@ namespace MWWorld
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mChangeCellGridRequest.has_value())
|
|
|
|
if (mChangeCellGridRequest.has_value())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
changeCellGrid(mChangeCellGridRequest->mPosition, mChangeCellGridRequest->mCell.x(),
|
|
|
|
changeCellGrid(mChangeCellGridRequest->mPosition, mChangeCellGridRequest->mCellIndex,
|
|
|
|
mChangeCellGridRequest->mCell.y(), mChangeCellGridRequest->mChangeEvent);
|
|
|
|
mChangeCellGridRequest->mChangeEvent);
|
|
|
|
mChangeCellGridRequest.reset();
|
|
|
|
mChangeCellGridRequest.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -345,7 +345,8 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
|
|
if (cell->getCell()->isExterior())
|
|
|
|
if (cell->getCell()->isExterior())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mPhysics->getHeightField(cellX, cellY) != nullptr)
|
|
|
|
if (mPhysics->getHeightField(ESM::ExteriorCellLocation(cellX, cellY, cell->getCell()->getWorldSpace()))
|
|
|
|
|
|
|
|
!= nullptr)
|
|
|
|
mNavigator.removeHeightfield(osg::Vec2i(cellX, cellY), navigatorUpdateGuard);
|
|
|
|
mNavigator.removeHeightfield(osg::Vec2i(cellX, cellY), navigatorUpdateGuard);
|
|
|
|
|
|
|
|
|
|
|
|
mPhysics->removeHeightField(cellX, cellY);
|
|
|
|
mPhysics->removeHeightField(cellX, cellY);
|
|
|
@ -390,10 +391,12 @@ namespace MWWorld
|
|
|
|
const int cellX = cell.getCell()->getGridX();
|
|
|
|
const int cellX = cell.getCell()->getGridX();
|
|
|
|
const int cellY = cell.getCell()->getGridY();
|
|
|
|
const int cellY = cell.getCell()->getGridY();
|
|
|
|
const MWWorld::Cell& cellVariant = *cell.getCell();
|
|
|
|
const MWWorld::Cell& cellVariant = *cell.getCell();
|
|
|
|
|
|
|
|
ESM::RefId worldspace = cellVariant.getWorldSpace();
|
|
|
|
|
|
|
|
ESM::ExteriorCellLocation cellIndex(cellX, cellY, worldspace);
|
|
|
|
|
|
|
|
|
|
|
|
if (cellVariant.isExterior())
|
|
|
|
if (cellVariant.isExterior())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
osg::ref_ptr<const ESMTerrain::LandObject> land = mRendering.getLandManager()->getLand(cellX, cellY);
|
|
|
|
osg::ref_ptr<const ESMTerrain::LandObject> land = mRendering.getLandManager()->getLand(cellIndex);
|
|
|
|
const ESM::Land::LandData* data = land ? land->getData(ESM::Land::DATA_VHGT) : nullptr;
|
|
|
|
const ESM::Land::LandData* data = land ? land->getData(ESM::Land::DATA_VHGT) : nullptr;
|
|
|
|
const int verts = ESM::Land::LAND_SIZE;
|
|
|
|
const int verts = ESM::Land::LAND_SIZE;
|
|
|
|
const int worldsize = ESM::Land::REAL_SIZE;
|
|
|
|
const int worldsize = ESM::Land::REAL_SIZE;
|
|
|
@ -409,7 +412,7 @@ namespace MWWorld
|
|
|
|
mPhysics->addHeightField(defaultHeight.data(), cellX, cellY, worldsize, verts,
|
|
|
|
mPhysics->addHeightField(defaultHeight.data(), cellX, cellY, worldsize, verts,
|
|
|
|
ESM::Land::DEFAULT_HEIGHT, ESM::Land::DEFAULT_HEIGHT, land.get());
|
|
|
|
ESM::Land::DEFAULT_HEIGHT, ESM::Land::DEFAULT_HEIGHT, land.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (const auto heightField = mPhysics->getHeightField(cellX, cellY))
|
|
|
|
if (const auto heightField = mPhysics->getHeightField(cellIndex))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const osg::Vec2i cellPosition(cellX, cellY);
|
|
|
|
const osg::Vec2i cellPosition(cellX, cellY);
|
|
|
|
const btVector3& origin = heightField->getCollisionObject()->getWorldTransform().getOrigin();
|
|
|
|
const btVector3& origin = heightField->getCollisionObject()->getWorldTransform().getOrigin();
|
|
|
@ -464,7 +467,7 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
|
|
if (cellVariant.isExterior())
|
|
|
|
if (cellVariant.isExterior())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (const auto heightField = mPhysics->getHeightField(cellX, cellY))
|
|
|
|
if (const auto heightField = mPhysics->getHeightField(cellIndex))
|
|
|
|
mNavigator.addWater(
|
|
|
|
mNavigator.addWater(
|
|
|
|
osg::Vec2i(cellX, cellY), ESM::Land::REAL_SIZE, waterLevel, navigatorUpdateGuard);
|
|
|
|
osg::Vec2i(cellX, cellY), ESM::Land::REAL_SIZE, waterLevel, navigatorUpdateGuard);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -506,17 +509,20 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
|
|
osg::Vec2i Scene::getNewGridCenter(const osg::Vec3f& pos, const osg::Vec2i* currentGridCenter) const
|
|
|
|
osg::Vec2i Scene::getNewGridCenter(const osg::Vec3f& pos, const osg::Vec2i* currentGridCenter) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
ESM::RefId worldspace
|
|
|
|
|
|
|
|
= mCurrentCell ? mCurrentCell->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId;
|
|
|
|
if (currentGridCenter)
|
|
|
|
if (currentGridCenter)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
float centerX, centerY;
|
|
|
|
osg::Vec2 center = ESM::indexToPosition(
|
|
|
|
mWorld.indexToPosition(currentGridCenter->x(), currentGridCenter->y(), centerX, centerY, true);
|
|
|
|
ESM::ExteriorCellLocation(currentGridCenter->x(), currentGridCenter->y(), worldspace), true);
|
|
|
|
float distance = std::max(std::abs(centerX - pos.x()), std::abs(centerY - pos.y()));
|
|
|
|
float distance = std::max(std::abs(center.x() - pos.x()), std::abs(center.y() - pos.y()));
|
|
|
|
const float maxDistance
|
|
|
|
float cellSize = ESM::getCellSize(worldspace);
|
|
|
|
= Constants::CellSizeInUnits / 2 + mCellLoadingThreshold; // 1/2 cell size + threshold
|
|
|
|
const float maxDistance = cellSize / 2 + mCellLoadingThreshold; // 1/2 cell size + threshold
|
|
|
|
if (distance <= maxDistance)
|
|
|
|
if (distance <= maxDistance)
|
|
|
|
return *currentGridCenter;
|
|
|
|
return *currentGridCenter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return positionToCellIndex(pos.x(), pos.y());
|
|
|
|
ESM::ExteriorCellLocation cellPos = ESM::positionToCellIndex(pos.x(), pos.y(), worldspace);
|
|
|
|
|
|
|
|
return { cellPos.mX, cellPos.mY };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Scene::playerMoved(const osg::Vec3f& pos)
|
|
|
|
void Scene::playerMoved(const osg::Vec3f& pos)
|
|
|
@ -531,12 +537,15 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
|
|
void Scene::requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent)
|
|
|
|
void Scene::requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mChangeCellGridRequest = ChangeCellGridRequest{ position, cell, changeEvent };
|
|
|
|
mChangeCellGridRequest = ChangeCellGridRequest{ position,
|
|
|
|
|
|
|
|
ESM::ExteriorCellLocation(cell.x(), cell.y(), mCurrentCell->getCell()->getWorldSpace()), changeEvent };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Scene::changeCellGrid(const osg::Vec3f& pos, int playerCellX, int playerCellY, bool changeEvent)
|
|
|
|
void Scene::changeCellGrid(const osg::Vec3f& pos, ESM::ExteriorCellLocation playerCellIndex, bool changeEvent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto navigatorUpdateGuard = mNavigator.makeUpdateGuard();
|
|
|
|
auto navigatorUpdateGuard = mNavigator.makeUpdateGuard();
|
|
|
|
|
|
|
|
int playerCellX = playerCellIndex.mX;
|
|
|
|
|
|
|
|
int playerCellY = playerCellIndex.mY;
|
|
|
|
|
|
|
|
|
|
|
|
for (auto iter = mActiveCells.begin(); iter != mActiveCells.end();)
|
|
|
|
for (auto iter = mActiveCells.begin(); iter != mActiveCells.end();)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -551,12 +560,8 @@ namespace MWWorld
|
|
|
|
else
|
|
|
|
else
|
|
|
|
unloadCell(cell, navigatorUpdateGuard.get());
|
|
|
|
unloadCell(cell, navigatorUpdateGuard.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mNavigator.setWorldspace(
|
|
|
|
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(mWorld.getWorldModel()
|
|
|
|
mWorld.getWorldModel().getExterior(playerCellIndex).getCell()->getWorldSpace().serializeText(),
|
|
|
|
.getExterior(playerCellX, playerCellY)
|
|
|
|
|
|
|
|
.getCell()
|
|
|
|
|
|
|
|
->getWorldSpace()
|
|
|
|
|
|
|
|
.serializeText()),
|
|
|
|
|
|
|
|
navigatorUpdateGuard.get());
|
|
|
|
navigatorUpdateGuard.get());
|
|
|
|
mNavigator.updateBounds(pos, navigatorUpdateGuard.get());
|
|
|
|
mNavigator.updateBounds(pos, navigatorUpdateGuard.get());
|
|
|
|
|
|
|
|
|
|
|
@ -578,9 +583,9 @@ namespace MWWorld
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int y = playerCellY - range; y <= playerCellY + range; ++y)
|
|
|
|
for (int y = playerCellY - range; y <= playerCellY + range; ++y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isCellInCollection(x, y, collection))
|
|
|
|
if (!isCellInCollection(ESM::ExteriorCellLocation(x, y, playerCellIndex.mWorldspace), collection))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
refsToLoad += mWorld.getWorldModel().getExterior(x, y).count();
|
|
|
|
refsToLoad += mWorld.getWorldModel().getExterior(playerCellIndex).count();
|
|
|
|
cellsPositionsToLoad.emplace_back(x, y);
|
|
|
|
cellsPositionsToLoad.emplace_back(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -612,9 +617,10 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& [x, y] : cellsPositionsToLoad)
|
|
|
|
for (const auto& [x, y] : cellsPositionsToLoad)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isCellInCollection(x, y, mActiveCells))
|
|
|
|
ESM::ExteriorCellLocation indexToLoad = { x, y, playerCellIndex.mWorldspace };
|
|
|
|
|
|
|
|
if (!isCellInCollection(indexToLoad, mActiveCells))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CellStore& cell = mWorld.getWorldModel().getExterior(x, y);
|
|
|
|
CellStore& cell = mWorld.getWorldModel().getExterior(indexToLoad);
|
|
|
|
loadCell(cell, loadingListener, changeEvent, pos, navigatorUpdateGuard.get());
|
|
|
|
loadCell(cell, loadingListener, changeEvent, pos, navigatorUpdateGuard.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -623,7 +629,7 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
|
|
navigatorUpdateGuard.reset();
|
|
|
|
navigatorUpdateGuard.reset();
|
|
|
|
|
|
|
|
|
|
|
|
CellStore& current = mWorld.getWorldModel().getExterior(playerCellX, playerCellY);
|
|
|
|
CellStore& current = mWorld.getWorldModel().getExterior(playerCellIndex);
|
|
|
|
MWBase::Environment::get().getWindowManager()->changeCell(¤t);
|
|
|
|
MWBase::Environment::get().getWindowManager()->changeCell(¤t);
|
|
|
|
|
|
|
|
|
|
|
|
if (changeEvent)
|
|
|
|
if (changeEvent)
|
|
|
@ -676,9 +682,9 @@ namespace MWWorld
|
|
|
|
loadingListener->setLabel("#{OMWEngine:TestingExteriorCells} (" + std::to_string(i) + "/"
|
|
|
|
loadingListener->setLabel("#{OMWEngine:TestingExteriorCells} (" + std::to_string(i) + "/"
|
|
|
|
+ std::to_string(cells.getExtSize()) + ")...");
|
|
|
|
+ std::to_string(cells.getExtSize()) + ")...");
|
|
|
|
|
|
|
|
|
|
|
|
CellStore& cell = mWorld.getWorldModel().getExterior(it->mData.mX, it->mData.mY);
|
|
|
|
CellStore& cell = mWorld.getWorldModel().getExterior(
|
|
|
|
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()),
|
|
|
|
ESM::ExteriorCellLocation(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId));
|
|
|
|
navigatorUpdateGuard.get());
|
|
|
|
mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get());
|
|
|
|
const osg::Vec3f position
|
|
|
|
const osg::Vec3f position
|
|
|
|
= osg::Vec3f(it->mData.mX + 0.5f, it->mData.mY + 0.5f, 0) * Constants::CellSizeInUnits;
|
|
|
|
= osg::Vec3f(it->mData.mX + 0.5f, it->mData.mY + 0.5f, 0) * Constants::CellSizeInUnits;
|
|
|
|
mNavigator.updateBounds(position, navigatorUpdateGuard.get());
|
|
|
|
mNavigator.updateBounds(position, navigatorUpdateGuard.get());
|
|
|
@ -735,8 +741,7 @@ namespace MWWorld
|
|
|
|
+ std::to_string(cells.getIntSize()) + ")...");
|
|
|
|
+ std::to_string(cells.getIntSize()) + ")...");
|
|
|
|
|
|
|
|
|
|
|
|
CellStore& cell = mWorld.getWorldModel().getInterior(it->mName);
|
|
|
|
CellStore& cell = mWorld.getWorldModel().getInterior(it->mName);
|
|
|
|
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()),
|
|
|
|
mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get());
|
|
|
|
navigatorUpdateGuard.get());
|
|
|
|
|
|
|
|
ESM::Position position;
|
|
|
|
ESM::Position position;
|
|
|
|
mWorld.findInteriorPosition(it->mName, position);
|
|
|
|
mWorld.findInteriorPosition(it->mName, position);
|
|
|
|
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
|
|
|
|
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
|
|
|
@ -891,8 +896,7 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
|
|
loadingListener->setProgressRange(cell.count());
|
|
|
|
loadingListener->setProgressRange(cell.count());
|
|
|
|
|
|
|
|
|
|
|
|
mNavigator.setWorldspace(
|
|
|
|
mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get());
|
|
|
|
Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), navigatorUpdateGuard.get());
|
|
|
|
|
|
|
|
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
|
|
|
|
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
|
|
|
|
|
|
|
|
|
|
|
|
// Load cell.
|
|
|
|
// Load cell.
|
|
|
@ -932,7 +936,8 @@ namespace MWWorld
|
|
|
|
|
|
|
|
|
|
|
|
const osg::Vec2i cellIndex(current.getCell()->getGridX(), current.getCell()->getGridY());
|
|
|
|
const osg::Vec2i cellIndex(current.getCell()->getGridX(), current.getCell()->getGridY());
|
|
|
|
|
|
|
|
|
|
|
|
changeCellGrid(position.asVec3(), cellIndex.x(), cellIndex.y(), changeEvent);
|
|
|
|
changeCellGrid(position.asVec3(),
|
|
|
|
|
|
|
|
ESM::ExteriorCellLocation(cellIndex.x(), cellIndex.y(), current.getCell()->getWorldSpace()), changeEvent);
|
|
|
|
|
|
|
|
|
|
|
|
changePlayerCell(current, position, adjustPlayerPos);
|
|
|
|
changePlayerCell(current, position, adjustPlayerPos);
|
|
|
|
|
|
|
|
|
|
|
@ -1153,9 +1158,9 @@ namespace MWWorld
|
|
|
|
int cellX, cellY;
|
|
|
|
int cellX, cellY;
|
|
|
|
cellX = mCurrentGridCenter.x();
|
|
|
|
cellX = mCurrentGridCenter.x();
|
|
|
|
cellY = mCurrentGridCenter.y();
|
|
|
|
cellY = mCurrentGridCenter.y();
|
|
|
|
|
|
|
|
ESM::RefId extWorldspace = mWorld.getCurrentWorldspace();
|
|
|
|
|
|
|
|
|
|
|
|
float centerX, centerY;
|
|
|
|
float cellSize = ESM::getCellSize(extWorldspace);
|
|
|
|
mWorld.indexToPosition(cellX, cellY, centerX, centerY, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int dx = -halfGridSizePlusOne; dx <= halfGridSizePlusOne; ++dx)
|
|
|
|
for (int dx = -halfGridSizePlusOne; dx <= halfGridSizePlusOne; ++dx)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1164,20 +1169,18 @@ namespace MWWorld
|
|
|
|
if (dy != halfGridSizePlusOne && dy != -halfGridSizePlusOne && dx != halfGridSizePlusOne
|
|
|
|
if (dy != halfGridSizePlusOne && dy != -halfGridSizePlusOne && dx != halfGridSizePlusOne
|
|
|
|
&& dx != -halfGridSizePlusOne)
|
|
|
|
&& dx != -halfGridSizePlusOne)
|
|
|
|
continue; // only care about the outer (not yet loaded) part of the grid
|
|
|
|
continue; // only care about the outer (not yet loaded) part of the grid
|
|
|
|
|
|
|
|
ESM::ExteriorCellLocation cellIndex(cellX + dx, cellY + dy, extWorldspace);
|
|
|
|
|
|
|
|
osg::Vec2 thisCellCenter = ESM::indexToPosition(cellIndex, true);
|
|
|
|
|
|
|
|
|
|
|
|
float thisCellCenterX, thisCellCenterY;
|
|
|
|
float dist = std::max(
|
|
|
|
mWorld.indexToPosition(cellX + dx, cellY + dy, thisCellCenterX, thisCellCenterY, true);
|
|
|
|
std::abs(thisCellCenter.x() - playerPos.x()), std::abs(thisCellCenter.y() - playerPos.y()));
|
|
|
|
|
|
|
|
|
|
|
|
float dist
|
|
|
|
|
|
|
|
= std::max(std::abs(thisCellCenterX - playerPos.x()), std::abs(thisCellCenterY - playerPos.y()));
|
|
|
|
|
|
|
|
dist = std::min(dist,
|
|
|
|
dist = std::min(dist,
|
|
|
|
std::max(
|
|
|
|
std::max(std::abs(thisCellCenter.x() - predictedPos.x()),
|
|
|
|
std::abs(thisCellCenterX - predictedPos.x()), std::abs(thisCellCenterY - predictedPos.y())));
|
|
|
|
std::abs(thisCellCenter.y() - predictedPos.y())));
|
|
|
|
float loadDist = Constants::CellSizeInUnits / 2 + Constants::CellSizeInUnits - mCellLoadingThreshold
|
|
|
|
float loadDist = cellSize / 2 + cellSize - mCellLoadingThreshold + mPreloadDistance;
|
|
|
|
+ mPreloadDistance;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dist < loadDist)
|
|
|
|
if (dist < loadDist)
|
|
|
|
preloadCell(mWorld.getWorldModel().getExterior(cellX + dx, cellY + dy));
|
|
|
|
preloadCell(mWorld.getWorldModel().getExterior(cellIndex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1193,8 +1196,9 @@ namespace MWWorld
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy)
|
|
|
|
for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mPreloader->preload(
|
|
|
|
mPreloader->preload(mWorld.getWorldModel().getExterior(
|
|
|
|
mWorld.getWorldModel().getExterior(x + dx, y + dy), mRendering.getReferenceTime());
|
|
|
|
ESM::ExteriorCellLocation(x + dx, y + dy, cell.getCell()->getWorldSpace())),
|
|
|
|
|
|
|
|
mRendering.getReferenceTime());
|
|
|
|
if (++numpreloaded >= mPreloader->getMaxCacheSize())
|
|
|
|
if (++numpreloaded >= mPreloader->getMaxCacheSize())
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1257,12 +1261,12 @@ namespace MWWorld
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void Scene::preloadFastTravelDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& /*predictedPos*/,
|
|
|
|
void Scene::preloadFastTravelDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& /*predictedPos*/,
|
|
|
|
std::vector<PositionCellGrid>&
|
|
|
|
std::vector<PositionCellGrid>& exteriorPositions) // ignore predictedPos here since opening dialogue with
|
|
|
|
exteriorPositions) // ignore predictedPos here since opening dialogue with travel service takes extra time
|
|
|
|
// travel service takes extra time
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const MWWorld::ConstPtr player = mWorld.getPlayerPtr();
|
|
|
|
const MWWorld::ConstPtr player = mWorld.getPlayerPtr();
|
|
|
|
ListFastTravelDestinationsVisitor listVisitor(mPreloadDistance, player.getRefData().getPosition().asVec3());
|
|
|
|
ListFastTravelDestinationsVisitor listVisitor(mPreloadDistance, player.getRefData().getPosition().asVec3());
|
|
|
|
|
|
|
|
ESM::RefId extWorldspace = mWorld.getCurrentWorldspace();
|
|
|
|
for (MWWorld::CellStore* cellStore : mActiveCells)
|
|
|
|
for (MWWorld::CellStore* cellStore : mActiveCells)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cellStore->forEachType<ESM::NPC>(listVisitor);
|
|
|
|
cellStore->forEachType<ESM::NPC>(listVisitor);
|
|
|
@ -1276,8 +1280,8 @@ namespace MWWorld
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
osg::Vec3f pos = dest.mPos.asVec3();
|
|
|
|
osg::Vec3f pos = dest.mPos.asVec3();
|
|
|
|
const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y());
|
|
|
|
const ESM::ExteriorCellLocation cellIndex = ESM::positionToCellIndex(pos.x(), pos.y(), extWorldspace);
|
|
|
|
preloadCell(mWorld.getWorldModel().getExterior(cellIndex.x(), cellIndex.y()), true);
|
|
|
|
preloadCell(mWorld.getWorldModel().getExterior(cellIndex), true);
|
|
|
|
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
|
|
|
|
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|