land bindings afterwork

- fix include order + style
- cellOrName -> cellOrId
- bump lua api revision to 78
- cellOrId is not optional anymore for getHeightAt
This commit is contained in:
Sebastian Fieber 2025-06-25 20:27:30 +02:00
parent eb4d3b7224
commit e4439806ed
3 changed files with 21 additions and 18 deletions

View File

@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
set(OPENMW_VERSION_MAJOR 0)
set(OPENMW_VERSION_MINOR 50)
set(OPENMW_VERSION_RELEASE 0)
set(OPENMW_LUA_API_REVISION 77)
set(OPENMW_LUA_API_REVISION 78)
set(OPENMW_POSTPROCESSING_API_REVISION 2)
set(OPENMW_VERSION_COMMITHASH "")

View File

@ -1,15 +1,15 @@
#include "landbindings.hpp"
#include <apps/openmw/mwlua/object.hpp>
#include <apps/openmw/mwworld/cellstore.hpp>
#include <apps/openmw/mwworld/worldmodel.hpp>
#include <components/esm/refid.hpp>
#include <components/esm/util.hpp>
#include <components/esmterrain/storage.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/worldmodel.hpp"
#include "object.hpp"
namespace
{
@ -37,15 +37,18 @@ namespace
return { tex, plugin };
}
const ESM::RefId worldspaceAt(sol::object cellOrName)
const ESM::RefId worldspaceAt(sol::object cellOrId)
{
const MWWorld::Cell* cell = nullptr;
if (cellOrName.is<MWLua::GCell>())
cell = cellOrName.as<MWLua::GCell>().mStore->getCell();
else if (cellOrName.is<MWLua::LCell>())
cell = cellOrName.as<MWLua::LCell>().mStore->getCell();
else if (cellOrName.is<std::string_view>() && !cellOrName.as<std::string_view>().empty())
cell = MWBase::Environment::get().getWorldModel()->getCell(cellOrName.as<std::string_view>()).getCell();
if (cellOrId.is<MWLua::GCell>())
cell = cellOrId.as<MWLua::GCell>().mStore->getCell();
else if (cellOrId.is<MWLua::LCell>())
cell = cellOrId.as<MWLua::LCell>().mStore->getCell();
else if (cellOrId.is<std::string_view>() && !cellOrId.as<std::string_view>().empty())
cell = MWBase::Environment::get()
.getWorldModel()
->getCell(ESM::RefId::deserializeText(cellOrId.as<std::string_view>()))
.getCell();
if (cell == nullptr)
throw std::runtime_error("Invalid cell");
else if (!cell->isExterior())
@ -62,16 +65,16 @@ namespace MWLua
sol::state_view lua = context.sol();
sol::table landApi(lua, sol::create);
landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) {
ESM::RefId worldspace = worldspaceAt(cellOrName);
landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrId) {
ESM::RefId worldspace = worldspaceAt(cellOrId);
return MWBase::Environment::get().getWorld()->getTerrainHeightAt(pos, worldspace);
};
landApi["getTextureAt"] = [lua = lua](const osg::Vec3f& pos, sol::object cellOrName) {
landApi["getTextureAt"] = [lua = lua](const osg::Vec3f& pos, sol::object cellOrId) {
sol::variadic_results values;
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
const MWWorld::Store<ESM::Land>& landStore = store.get<ESM::Land>();
ESM::RefId worldspace = worldspaceAt(cellOrName);
ESM::RefId worldspace = worldspaceAt(cellOrId);
if (worldspace != ESM::Cell::sDefaultWorldspaceId)
return values;

View File

@ -457,7 +457,7 @@
-- Get the terrain height at a given location.
-- @function [parent=#Land] getHeightAt
-- @param openmw.util#Vector3 position
-- @param #any cellOrName (optional) cell or cell name in their exterior world space to query
-- @param #any cellOrId cell or cell id in their exterior world space to query
-- @return #number
---
@ -467,7 +467,7 @@
--
-- @function [parent=#Land] getTextureAt
-- @param openmw.util#Vector3 position
-- @param #any cellOrName cell or cell name in their exterior world space to query
-- @param #any cellOrId cell or cell id 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