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 else
{ {
mTerrain = std::make_unique<Terrain::TerrainGrid>( mTerrain = std::make_unique<Terrain::TerrainGrid>(mCellNode, mCellNode, mData.getResourceSystem().get(),
mCellNode, mCellNode, mData.getResourceSystem().get(), mTerrainStorage, Mask_Terrain); mTerrainStorage, Mask_Terrain, ESM::Cell::sDefaultWorldspaceId);
} }
mTerrain->loadCell(esmLand.mX, esmLand.mY); mTerrain->loadCell(esmLand.mX, esmLand.mY);

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

@ -474,7 +474,8 @@ namespace MWMechanics
if (enemy.getCell()->isExterior()) if (enemy.getCell()->isExterior())
{ {
if (attackDistance < (enemyPos.pos[2] 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; return false;
} }
} }

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

@ -230,7 +230,7 @@ namespace MWRender
void setViewDistance(float distance, bool delay = false); 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 stuff
Camera* getCamera() { return mCamera.get(); } Camera* getCamera() { return mCamera.get(); }

@ -316,7 +316,8 @@ namespace MWScript
{ {
float terrainHeight = -std::numeric_limits<float>::max(); float terrainHeight = -std::numeric_limits<float>::max();
if (ptr.getCell()->isExterior()) 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) if (pos < terrainHeight)
pos = terrainHeight; pos = terrainHeight;

@ -53,7 +53,8 @@ namespace MWSound
{ {
const float terrainX = pos.x() - mSettings.mNearWaterRadius + x * step; const float terrainX = pos.x() - mSettings.mNearWaterRadius + x * step;
const float terrainY = pos.y() - mSettings.mNearWaterRadius + y * 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) if (height < 0)
underwaterPoints++; underwaterPoints++;

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

@ -648,7 +648,7 @@ namespace MWWorld
bool isPlayerTraveling() const override; bool isPlayerTraveling() const override;
/// Return terrain height at \a worldPos position. /// 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. /// Return physical or rendering half extents of the given actor.
osg::Vec3f getHalfExtents(const MWWorld::ConstPtr& actor, bool rendering = false) const override; 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, QuadTreeWorld::QuadTreeWorld(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,
int compMapResolution, float compMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize, int compMapResolution, float compMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize,
bool debugChunks) bool debugChunks, ESM::RefId worldspace)
: TerrainGrid(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask, borderMask) : TerrainGrid(parent, compileRoot, resourceSystem, storage, nodeMask, worldspace, preCompileMask, borderMask)
, mViewDataMap(new ViewDataMap) , mViewDataMap(new ViewDataMap)
, mQuadTreeBuilt(false) , mQuadTreeBuilt(false)
, mLodFactor(lodFactor) , mLodFactor(lodFactor)

@ -31,7 +31,7 @@ namespace Terrain
QuadTreeWorld(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, QuadTreeWorld(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,
int compMapResolution, float comMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize, int compMapResolution, float comMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize,
bool debugChunks); bool debugChunks, ESM::RefId worldspace);
~QuadTreeWorld(); ~QuadTreeWorld();

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

@ -27,8 +27,9 @@ namespace Terrain
{ {
public: public:
TerrainGrid(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, TerrainGrid(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem,
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask = ~0u, unsigned int borderMask = 0); Storage* storage, unsigned int nodeMask, ESM::RefId worldspace, unsigned int preCompileMask = ~0u,
TerrainGrid(osg::Group* parent, Storage* storage, unsigned int nodeMask = ~0u); unsigned int borderMask = 0);
TerrainGrid(osg::Group* parent, Storage* storage, ESM::RefId worldspace, unsigned int nodeMask = ~0u);
~TerrainGrid(); ~TerrainGrid();
void cacheCell(View* view, int x, int y) override; 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, 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) : mStorage(storage)
, mParent(parent) , mParent(parent)
, mResourceSystem(resourceSystem) , mResourceSystem(resourceSystem)
, mBorderVisible(false) , mBorderVisible(false)
, mHeightCullCallback(new HeightCullCallback) , mHeightCullCallback(new HeightCullCallback)
, mWorldspace(worldspace)
{ {
mTerrainRoot = new osg::Group; mTerrainRoot = new osg::Group;
mTerrainRoot->setNodeMask(nodeMask); mTerrainRoot->setNodeMask(nodeMask);
@ -54,7 +56,7 @@ namespace Terrain
mResourceSystem->addResourceManager(mTextureManager.get()); 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) : mStorage(storage)
, mParent(parent) , mParent(parent)
, mCompositeMapCamera(nullptr) , mCompositeMapCamera(nullptr)
@ -65,6 +67,7 @@ namespace Terrain
, mCellBorder(nullptr) , mCellBorder(nullptr)
, mBorderVisible(false) , mBorderVisible(false)
, mHeightCullCallback(nullptr) , mHeightCullCallback(nullptr)
, mWorldspace(worldspace)
{ {
mTerrainRoot = new osg::Group; mTerrainRoot = new osg::Group;
mTerrainRoot->setNodeMask(nodeMask); mTerrainRoot->setNodeMask(nodeMask);

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

Loading…
Cancel
Save