mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-30 03:32:36 +00:00
Factorises code and fixes preload bug.
This commit is contained in:
parent
5648e03e9e
commit
75561abfca
@ -485,7 +485,7 @@ namespace MWPhysics
|
||||
|
||||
const HeightField* PhysicsSystem::getHeightField(ESM::ExteriorCellIndex cellIndex) const
|
||||
{
|
||||
if (cellIndex.mWorldspace != ESM::Cell::sDefaultWorldspaceId)
|
||||
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
|
||||
return nullptr;
|
||||
const auto heightField = mHeightFields.find(std::make_pair(cellIndex.mX, cellIndex.mY));
|
||||
if (heightField == mHeightFields.end())
|
||||
|
@ -20,7 +20,7 @@ namespace MWRender
|
||||
|
||||
osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(ESM::ExteriorCellIndex cellIndex)
|
||||
{
|
||||
if (cellIndex.mWorldspace != ESM::Cell::sDefaultWorldspaceId)
|
||||
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
|
||||
return osg::ref_ptr<ESMTerrain::LandObject>(nullptr);
|
||||
int x = cellIndex.mX;
|
||||
int y = cellIndex.mY;
|
||||
|
@ -511,13 +511,13 @@ namespace MWWorld
|
||||
|
||||
osg::Vec2i Scene::getNewGridCenter(const osg::Vec3f& pos, const osg::Vec2i* currentGridCenter) const
|
||||
{
|
||||
bool isEsm4Ext = mCurrentCell && mCurrentCell->getCell()->getWorldSpace() != ESM::Cell::sDefaultWorldspaceId;
|
||||
bool isEsm4Ext = mCurrentCell && ESM::isEsm4Ext(mCurrentCell->getCell()->getWorldSpace());
|
||||
if (currentGridCenter)
|
||||
{
|
||||
float centerX, centerY;
|
||||
mWorld.indexToPosition(currentGridCenter->x(), currentGridCenter->y(), centerX, centerY, true, isEsm4Ext);
|
||||
float distance = std::max(std::abs(centerX - pos.x()), std::abs(centerY - pos.y()));
|
||||
float cellSize = Constants::getCellSize(isEsm4Ext);
|
||||
float cellSize = ESM::getCellSize(isEsm4Ext);
|
||||
const float maxDistance = cellSize / 2 + mCellLoadingThreshold; // 1/2 cell size + threshold
|
||||
if (distance <= maxDistance)
|
||||
return *currentGridCenter;
|
||||
@ -585,7 +585,7 @@ namespace MWWorld
|
||||
{
|
||||
for (int y = playerCellY - range; y <= playerCellY + range; ++y)
|
||||
{
|
||||
if (!isCellInCollection(playerCellIndex, collection))
|
||||
if (!isCellInCollection(ESM::ExteriorCellIndex(x, y, playerCellIndex.mWorldspace), collection))
|
||||
{
|
||||
refsToLoad += mWorld.getWorldModel().getExterior(playerCellIndex).count();
|
||||
cellsPositionsToLoad.emplace_back(x, y);
|
||||
@ -1102,7 +1102,7 @@ namespace MWWorld
|
||||
|
||||
mLastPlayerPos = playerPos;
|
||||
|
||||
if (mPreloadEnabled && mCurrentCell->getCell()->getWorldSpace() == ESM::Cell::sDefaultWorldspaceId)
|
||||
if (mPreloadEnabled && !ESM::isEsm4Ext(mCurrentCell->getCell()->getWorldSpace()))
|
||||
{
|
||||
if (mPreloadDoors)
|
||||
preloadTeleportDoorDestinations(playerPos, predictedPos, exteriorPositions);
|
||||
@ -1166,8 +1166,10 @@ namespace MWWorld
|
||||
|
||||
float centerX, centerY;
|
||||
mWorld.indexToPosition(cellX, cellY, centerX, centerY, true);
|
||||
float cellSize = mWorld.getCurrentCellSize();
|
||||
bool esm4Ext = cellSize == Constants::ESM4CellSizeInUnits;
|
||||
|
||||
ESM::RefId extWorldspace = mWorld.getCurrentWorldspace();
|
||||
bool esm4Ext = ESM::isEsm4Ext(extWorldspace);
|
||||
float cellSize = ESM::getCellSize(esm4Ext);
|
||||
|
||||
for (int dx = -halfGridSizePlusOne; dx <= halfGridSizePlusOne; ++dx)
|
||||
{
|
||||
@ -1189,7 +1191,7 @@ namespace MWWorld
|
||||
|
||||
if (dist < loadDist)
|
||||
preloadCell(mWorld.getWorldModel().getExterior(
|
||||
ESM::ExteriorCellIndex(cellX + dx, cellY + dy, ESM::Cell::sDefaultWorldspaceId)));
|
||||
ESM::ExteriorCellIndex(cellX + dx, cellY + dy, extWorldspace)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1374,9 +1374,8 @@ namespace MWWorld
|
||||
&& !(ptr.getClass().isPersistent(ptr) && ptr.getClass().getCreatureStats(ptr).isDeathAnimationFinished());
|
||||
if (force || !ptr.getClass().isActor() || (!isFlying(ptr) && !swims && isActorCollisionEnabled(ptr)))
|
||||
{
|
||||
bool esm4Ext = ptr.getCell()->isExterior()
|
||||
&& ptr.getCell()->getCell()->getWorldSpace() != ESM::Cell::sDefaultWorldspaceId;
|
||||
osg::Vec3f traced = mPhysics->traceDown(ptr, pos, Constants::getCellSize(esm4Ext));
|
||||
bool esm4Ext = ptr.getCell()->isExterior() && ESM::isEsm4Ext(ptr.getCell()->getCell()->getWorldSpace());
|
||||
osg::Vec3f traced = mPhysics->traceDown(ptr, pos, ESM::getCellSize(esm4Ext));
|
||||
pos.z() = std::min(pos.z(), traced.z());
|
||||
}
|
||||
|
||||
@ -1411,10 +1410,9 @@ namespace MWWorld
|
||||
if (!mPhysics->castRay(pos, targetPos, MWPhysics::CollisionType_World | MWPhysics::CollisionType_Door).mHit)
|
||||
break;
|
||||
}
|
||||
bool esm4Ext = actor.getCell()->isExterior()
|
||||
&& actor.getCell()->getCell()->getWorldSpace() != ESM::Cell::sDefaultWorldspaceId;
|
||||
bool esm4Ext = actor.getCell()->isExterior() && ESM::isEsm4Ext(actor.getCell()->getCell()->getWorldSpace());
|
||||
targetPos.z() += distance / 2.f; // move up a bit to get out from geometry, will snap down later
|
||||
osg::Vec3f traced = mPhysics->traceDown(actor, targetPos, Constants::getCellSize(esm4Ext));
|
||||
osg::Vec3f traced = mPhysics->traceDown(actor, targetPos, ESM::getCellSize(esm4Ext));
|
||||
if (traced != pos)
|
||||
{
|
||||
esmPos.pos[0] = traced.x();
|
||||
@ -1500,7 +1498,7 @@ namespace MWWorld
|
||||
|
||||
void World::indexToPosition(int cellX, int cellY, float& x, float& y, bool centre, bool esm4Ext) const
|
||||
{
|
||||
const int cellSize = Constants::getCellSize(esm4Ext);
|
||||
const int cellSize = ESM::getCellSize(esm4Ext);
|
||||
|
||||
x = static_cast<float>(cellSize * cellX);
|
||||
y = static_cast<float>(cellSize * cellY);
|
||||
@ -1910,12 +1908,12 @@ namespace MWWorld
|
||||
return false;
|
||||
}
|
||||
|
||||
float World::getCurrentCellSize() const
|
||||
ESM::RefId World::getCurrentWorldspace() const
|
||||
{
|
||||
const CellStore* cellStore = mWorldScene->getCurrentCell();
|
||||
if (cellStore)
|
||||
return Constants::getCellSize(cellStore->getCell()->isEsm4());
|
||||
return Constants::getCellSize(false);
|
||||
return cellStore->getCell()->getWorldSpace();
|
||||
return ESM::Cell::sDefaultWorldspaceId;
|
||||
}
|
||||
|
||||
int World::getCurrentWeather() const
|
||||
@ -2762,7 +2760,7 @@ namespace MWWorld
|
||||
{
|
||||
int x = ext->getGridX();
|
||||
int y = ext->getGridY();
|
||||
bool esm4Ext = ext->getWorldSpace() != ESM::Cell::sDefaultWorldspaceId;
|
||||
bool esm4Ext = ESM::isEsm4Ext(ext->getWorldSpace());
|
||||
indexToPosition(x, y, pos.pos[0], pos.pos[1], true, esm4Ext);
|
||||
|
||||
// Note: Z pos will be adjusted by adjustPosition later
|
||||
|
@ -246,7 +246,7 @@ namespace MWWorld
|
||||
|
||||
bool isCellQuasiExterior() const override;
|
||||
|
||||
float getCurrentCellSize() const;
|
||||
ESM::RefId getCurrentWorldspace() const;
|
||||
|
||||
void getDoorMarkers(MWWorld::CellStore& cell, std::vector<DoorMarker>& out) override;
|
||||
///< get a list of teleport door markers for a given cell, to be displayed on the local map
|
||||
|
@ -169,7 +169,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellIndex cell
|
||||
|
||||
if (result == mExteriors.end())
|
||||
{
|
||||
if (cellIndex.mWorldspace == ESM::Cell::sDefaultWorldspaceId)
|
||||
if (!ESM::isEsm4Ext(cellIndex.mWorldspace))
|
||||
{
|
||||
const ESM::Cell* cell = mStore.get<ESM::Cell>().search(cellIndex.mX, cellIndex.mY);
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <osg/Vec3f>
|
||||
|
||||
#include <components/esm/refid.hpp>
|
||||
#include <components/esm3/loadcell.hpp>
|
||||
#include <components/misc/constants.hpp>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
@ -69,6 +71,15 @@ namespace ESM
|
||||
friend struct std::hash<ExteriorCellIndex>;
|
||||
};
|
||||
|
||||
static inline bool isEsm4Ext(ESM::RefId worldspaceId)
|
||||
{
|
||||
return worldspaceId != ESM::Cell::sDefaultWorldspaceId;
|
||||
}
|
||||
|
||||
static inline int getCellSize(bool isESM4Ext)
|
||||
{
|
||||
return isESM4Ext ? Constants::ESM4CellSizeInUnits : Constants::CellSizeInUnits;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
|
@ -24,10 +24,6 @@ namespace Constants
|
||||
// Size of one exterior cell in game units
|
||||
constexpr int CellSizeInUnits = 8192;
|
||||
constexpr int ESM4CellSizeInUnits = 4096;
|
||||
static inline int getCellSize(bool isESM4Ext)
|
||||
{
|
||||
return isESM4Ext ? ESM4CellSizeInUnits : CellSizeInUnits;
|
||||
}
|
||||
|
||||
// Size of active cell grid in cells (it is a square with the (2 * CellGridRadius + 1) cells side)
|
||||
constexpr int CellGridRadius = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user