From 7c76387ffe062b6ae41ef0f5ff3a17d63e2d1756 Mon Sep 17 00:00:00 2001 From: Sebastian Fieber Date: Sun, 12 Jan 2025 17:26:20 +0100 Subject: [PATCH] no interior cell + make cellOrName mandatory --- apps/openmw/mwlua/landbindings.cpp | 24 +++++++++++------------- files/lua_api/openmw/core.lua | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwlua/landbindings.cpp b/apps/openmw/mwlua/landbindings.cpp index cd3a68fbb4..72af17776a 100644 --- a/apps/openmw/mwlua/landbindings.cpp +++ b/apps/openmw/mwlua/landbindings.cpp @@ -46,21 +46,19 @@ namespace return { tex, plugin }; } - const ESM::RefId worldspaceAt(const osg::Vec3f& pos, sol::object cellOrName) + const ESM::RefId worldspaceAt(sol::object cellOrName) { - ESM::RefId worldspace; + const MWWorld::Cell* cell = nullptr; if (cellOrName.is()) - worldspace = cellOrName.as().mStore->getCell()->getWorldSpace(); + cell = cellOrName.as().mStore->getCell(); else if (cellOrName.is() && !cellOrName.as().empty()) - worldspace = MWBase::Environment::get() - .getWorldModel() - ->getCell(cellOrName.as()) - .getCell() - ->getWorldSpace(); - else - worldspace = ESM::Cell::sDefaultWorldspaceId; + cell = MWBase::Environment::get().getWorldModel()->getCell(cellOrName.as()).getCell(); + if (cell = nullptr) + throw std::runtime_error("Invalid cell"); + else if (!cell->isExterior()) + throw std::runtime_error("Cell cannot be interior"); - return worldspace; + return cell->getWorldSpace(); } bool fillLandData(const MWWorld::Store& landStore, const osg::Vec3f& pos, const float cellSize, @@ -91,7 +89,7 @@ namespace MWLua sol::table landApi(lua, sol::create); landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) { - ESM::RefId worldspace = worldspaceAt(pos, cellOrName); + ESM::RefId worldspace = worldspaceAt(cellOrName); return MWBase::Environment::get().getWorld()->getTerrainHeightAt(pos, worldspace); }; @@ -100,7 +98,7 @@ namespace MWLua MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); const MWWorld::Store& landStore = store.get(); - const float cellSize = ESM::getCellSize(worldspaceAt(pos, cellOrName)); + const float cellSize = ESM::getCellSize(worldspaceAt(cellOrName)); // We need to read land twice. Once to get the amount of texture samples per cell edge, and the second time // to get the actual data // This is because the visual land textures are offset with regards to quads that are rendered for terrain. diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 3c00f49354..b2bd58d23c 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -464,7 +464,7 @@ -- Get the terrain texture at a given location. -- @function [parent=#Land] getTextureAt -- @param openmw.util#Vector3 position --- @param #any cellOrName (optional) cell or cell name in their exterior world space to query +-- @param #any cellOrName cell or cell name in their exterior world space to query -- @return #nil, #string Texture path or nil if one isn't defined -- @return #nil, #string Plugin name or nil if failed to retrieve the texture