From 283be9f4f061c1cff821eeb2ed7b145f8ba22899 Mon Sep 17 00:00:00 2001 From: Calandiel Date: Sun, 18 Aug 2024 03:26:52 +0200 Subject: [PATCH] add docs for the new binding --- apps/openmw/mwlua/corebindings.cpp | 9 +++++---- files/lua_api/openmw/core.lua | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwlua/corebindings.cpp b/apps/openmw/mwlua/corebindings.cpp index eb0c8c4175..9574564ada 100644 --- a/apps/openmw/mwlua/corebindings.cpp +++ b/apps/openmw/mwlua/corebindings.cpp @@ -153,7 +153,8 @@ namespace MWLua { std::move(eventName), LuaUtil::serialize(eventData, context.mSerializer) }); }; } - api["getHeightAt"] = [](float x, float y, sol::object cellOrName) { + + api["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) { ESM::RefId worldspace; if (cellOrName.is()) worldspace = cellOrName.as().mStore->getCell()->getWorldSpace(); @@ -167,8 +168,8 @@ namespace MWLua worldspace = ESM::Cell::sDefaultWorldspaceId; const float cellSize = ESM::getCellSize(worldspace); - int cellX = static_cast(std::floor(x / cellSize)); - int cellY = static_cast(std::floor(y / cellSize)); + int cellX = static_cast(std::floor(pos.x() / cellSize)); + int cellY = static_cast(std::floor(pos.y() / cellSize)); auto store = MWBase::Environment::get().getESMStore(); auto landStore = store->get(); @@ -188,7 +189,7 @@ namespace MWLua // If we failed to load data, return the default height return static_cast(ESM::Land::DEFAULT_HEIGHT); } - return ESMTerrain::Storage::getHeightAt(landData->mHeights, landData->sLandSize, { x, y, 0 }, cellSize); + return ESMTerrain::Storage::getHeightAt(landData->mHeights, landData->sLandSize, pos, cellSize); }; sol::table readOnlyApi = LuaUtil::makeReadOnly(api); diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 8a78a52441..5813b32b27 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -62,6 +62,13 @@ -- @param #string setting Setting name -- @return #any +--- +-- Get the terrain height at a given location. +-- @function [parent=#core] getHeightAt +-- @param openmw.util#Vector3 position +-- @param #any cellOrName (optional) cell or cell name in their exterior world space to query +-- @return #number + --- -- Return l10n formatting function for the given context. -- Localisation files (containing the message names and translations) should be stored in