Terrain has a mandatory worldspace in constructor

getTerrainHeightAt takes a worldspace.

Doesn't change anything for now => Therrain is created with the default ESM3 worldspace, and is never changed.
macos_ci
florent.teppe 2 years ago
parent 4399748889
commit 93e7b0d946

@ -146,8 +146,8 @@ void CSVRender::Cell::updateLand()
}
else
{
mTerrain = std::make_unique<Terrain::TerrainGrid>(
mCellNode, mCellNode, mData.getResourceSystem().get(), mTerrainStorage, Mask_Terrain);
mTerrain = std::make_unique<Terrain::TerrainGrid>(mCellNode, mCellNode, mData.getResourceSystem().get(),
mTerrainStorage, Mask_Terrain, ESM::Cell::sDefaultWorldspaceId);
}
mTerrain->loadCell(esmLand.mX, esmLand.mY);

@ -572,7 +572,7 @@ namespace MWBase
virtual void rotateWorldObject(const MWWorld::Ptr& ptr, const osg::Quat& rotate) = 0;
/// Return terrain height at \a worldPos position.
virtual float getTerrainHeightAt(const osg::Vec3f& worldPos) const = 0;
virtual float getTerrainHeightAt(const osg::Vec3f& worldPos, ESM::RefId worldspace) const = 0;
/// Return physical or rendering half extents of the given actor.
virtual osg::Vec3f getHalfExtents(const MWWorld::ConstPtr& actor, bool rendering = false) const = 0;

@ -474,7 +474,8 @@ namespace MWMechanics
if (enemy.getCell()->isExterior())
{
if (attackDistance < (enemyPos.pos[2]
- MWBase::Environment::get().getWorld()->getTerrainHeightAt(enemyPos.asVec3())))
- MWBase::Environment::get().getWorld()->getTerrainHeightAt(
enemyPos.asVec3(), enemy.getCell()->getCell()->getWorldSpace())))
return false;
}
}

@ -473,7 +473,7 @@ namespace MWRender
bool debugChunks = Settings::Manager::getBool("debug chunks", "Terrain");
mTerrain = std::make_unique<Terrain::QuadTreeWorld>(sceneRoot, mRootNode, mResourceSystem,
mTerrainStorage.get(), Mask_Terrain, Mask_PreCompile, Mask_Debug, compMapResolution, compMapLevel,
lodFactor, vertexLodMod, maxCompGeometrySize, debugChunks);
lodFactor, vertexLodMod, maxCompGeometrySize, debugChunks, ESM::Cell::sDefaultWorldspaceId);
if (Settings::Manager::getBool("object paging", "Terrain"))
{
mObjectPaging = std::make_unique<ObjectPaging>(mResourceSystem->getSceneManager());
@ -483,7 +483,7 @@ namespace MWRender
}
else
mTerrain = std::make_unique<Terrain::TerrainGrid>(sceneRoot, mRootNode, mResourceSystem,
mTerrainStorage.get(), Mask_Terrain, Mask_PreCompile, Mask_Debug);
mTerrainStorage.get(), Mask_Terrain, ESM::Cell::sDefaultWorldspaceId, Mask_PreCompile, Mask_Debug);
mTerrain->setTargetFrameRate(Settings::cells().mTargetFramerate);
@ -1444,7 +1444,7 @@ namespace MWRender
updateProjectionMatrix();
}
float RenderingManager::getTerrainHeightAt(const osg::Vec3f& pos)
float RenderingManager::getTerrainHeightAt(const osg::Vec3f& pos, ESM::RefId worldspace)
{
return mTerrain->getHeightAt(pos);
}

@ -230,7 +230,7 @@ namespace MWRender
void setViewDistance(float distance, bool delay = false);
float getTerrainHeightAt(const osg::Vec3f& pos);
float getTerrainHeightAt(const osg::Vec3f& pos, ESM::RefId worldspace);
// camera stuff
Camera* getCamera() { return mCamera.get(); }

@ -316,7 +316,8 @@ namespace MWScript
{
float terrainHeight = -std::numeric_limits<float>::max();
if (ptr.getCell()->isExterior())
terrainHeight = MWBase::Environment::get().getWorld()->getTerrainHeightAt(curPos);
terrainHeight = MWBase::Environment::get().getWorld()->getTerrainHeightAt(
curPos, ptr.getCell()->getCell()->getWorldSpace());
if (pos < terrainHeight)
pos = terrainHeight;

@ -53,7 +53,8 @@ namespace MWSound
{
const float terrainX = pos.x() - mSettings.mNearWaterRadius + x * step;
const float terrainY = pos.y() - mSettings.mNearWaterRadius + y * step;
const float height = world.getTerrainHeightAt(osg::Vec3f(terrainX, terrainY, 0.0f));
const float height = world.getTerrainHeightAt(
osg::Vec3f(terrainX, terrainY, 0.0f), cell.getCell()->getWorldSpace());
if (height < 0)
underwaterPoints++;

@ -1363,9 +1363,11 @@ namespace MWWorld
return;
}
if (ptr.getCell()->isExterior() && !ptr.getCell()->getCell()->isEsm4())
pos.z() = std::max(pos.z(), getTerrainHeightAt(pos));
pos.z() += 20; // place slightly above terrain. will snap down to ground with code below
const float terrainHeight = ptr.getCell()->isExterior()
? getTerrainHeightAt(pos, ptr.getCell()->getCell()->getWorldSpace())
: -std::numeric_limits<float>::max();
pos.z() = std::max(pos.z(), terrainHeight)
+ 20; // place slightly above terrain. will snap down to ground with code below
// We still should trace down dead persistent actors - they do not use the "swimdeath" animation.
bool swims = ptr.getClass().isActor() && isSwimming(ptr)
@ -3607,9 +3609,9 @@ namespace MWWorld
return mPlayerTraveling;
}
float World::getTerrainHeightAt(const osg::Vec3f& worldPos) const
float World::getTerrainHeightAt(const osg::Vec3f& worldPos, ESM::RefId worldspace) const
{
return mRendering->getTerrainHeightAt(worldPos);
return mRendering->getTerrainHeightAt(worldPos, worldspace);
}
osg::Vec3f World::getHalfExtents(const ConstPtr& object, bool rendering) const

@ -648,7 +648,7 @@ namespace MWWorld
bool isPlayerTraveling() const override;
/// Return terrain height at \a worldPos position.
float getTerrainHeightAt(const osg::Vec3f& worldPos) const override;
float getTerrainHeightAt(const osg::Vec3f& worldPos, ESM::RefId worldspace) const override;
/// Return physical or rendering half extents of the given actor.
osg::Vec3f getHalfExtents(const MWWorld::ConstPtr& actor, bool rendering = false) const override;

@ -272,8 +272,8 @@ namespace Terrain
QuadTreeWorld::QuadTreeWorld(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem,
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask,
int compMapResolution, float compMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize,
bool debugChunks)
: TerrainGrid(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask, borderMask)
bool debugChunks, ESM::RefId worldspace)
: TerrainGrid(parent, compileRoot, resourceSystem, storage, nodeMask, worldspace, preCompileMask, borderMask)
, mViewDataMap(new ViewDataMap)
, mQuadTreeBuilt(false)
, mLodFactor(lodFactor)

@ -31,7 +31,7 @@ namespace Terrain
QuadTreeWorld(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem,
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask,
int compMapResolution, float comMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize,
bool debugChunks);
bool debugChunks, ESM::RefId worldspace);
~QuadTreeWorld();

@ -23,14 +23,15 @@ namespace Terrain
};
TerrainGrid::TerrainGrid(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem,
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask)
: Terrain::World(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask, borderMask)
Storage* storage, unsigned int nodeMask, ESM::RefId worldspace, unsigned int preCompileMask,
unsigned int borderMask)
: Terrain::World(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask, borderMask, worldspace)
, mNumSplits(4)
{
}
TerrainGrid::TerrainGrid(osg::Group* parent, Storage* storage, unsigned int nodeMask)
: Terrain::World(parent, storage, nodeMask)
TerrainGrid::TerrainGrid(osg::Group* parent, Storage* storage, ESM::RefId worldspace, unsigned int nodeMask)
: Terrain::World(parent, storage, nodeMask, worldspace)
, mNumSplits(4)
{
}

@ -27,8 +27,9 @@ namespace Terrain
{
public:
TerrainGrid(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem,
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask = ~0u, unsigned int borderMask = 0);
TerrainGrid(osg::Group* parent, Storage* storage, unsigned int nodeMask = ~0u);
Storage* storage, unsigned int nodeMask, ESM::RefId worldspace, unsigned int preCompileMask = ~0u,
unsigned int borderMask = 0);
TerrainGrid(osg::Group* parent, Storage* storage, ESM::RefId worldspace, unsigned int nodeMask = ~0u);
~TerrainGrid();
void cacheCell(View* view, int x, int y) override;

@ -16,12 +16,14 @@ namespace Terrain
{
World::World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem,
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask)
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask,
ESM::RefId worldspace)
: mStorage(storage)
, mParent(parent)
, mResourceSystem(resourceSystem)
, mBorderVisible(false)
, mHeightCullCallback(new HeightCullCallback)
, mWorldspace(worldspace)
{
mTerrainRoot = new osg::Group;
mTerrainRoot->setNodeMask(nodeMask);
@ -54,7 +56,7 @@ namespace Terrain
mResourceSystem->addResourceManager(mTextureManager.get());
}
World::World(osg::Group* parent, Storage* storage, unsigned int nodeMask)
World::World(osg::Group* parent, Storage* storage, unsigned int nodeMask, ESM::RefId worldspace)
: mStorage(storage)
, mParent(parent)
, mCompositeMapCamera(nullptr)
@ -65,6 +67,7 @@ namespace Terrain
, mCellBorder(nullptr)
, mBorderVisible(false)
, mHeightCullCallback(nullptr)
, mWorldspace(worldspace)
{
mTerrainRoot = new osg::Group;
mTerrainRoot->setNodeMask(nodeMask);

@ -8,6 +8,8 @@
#include <memory>
#include <set>
#include <components/esm/refid.hpp>
#include "cellborder.hpp"
namespace osg
@ -48,8 +50,8 @@ namespace Terrain
/// @param nodeMask mask for the terrain root
/// @param preCompileMask mask for pre compiling textures
World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage,
unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask);
World(osg::Group* parent, Storage* storage, unsigned int nodeMask);
unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask, ESM::RefId worldspace);
World(osg::Group* parent, Storage* storage, unsigned int nodeMask, ESM::RefId worldspace);
virtual ~World();
/// See CompositeMapRenderer::setTargetFrameRate
@ -127,6 +129,7 @@ namespace Terrain
osg::ref_ptr<HeightCullCallback> mHeightCullCallback;
osg::Vec4i mActiveGrid;
ESM::RefId mWorldspace;
};
}

Loading…
Cancel
Save