From 1675c740364cc19cf957bd0276745e67bf6b2793 Mon Sep 17 00:00:00 2001 From: uramer Date: Sat, 30 Nov 2024 09:32:05 +0100 Subject: [PATCH 1/3] Fix findPath returning a raw vector --- apps/openmw/mwlua/nearbybindings.cpp | 14 ++++++++------ components/lua/luastate.hpp | 6 ++++++ .../data/integration_tests/test_lua_api/player.lua | 4 ++-- scripts/data/morrowind_tests/player.lua | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwlua/nearbybindings.cpp b/apps/openmw/mwlua/nearbybindings.cpp index 40367ea45f..df317ffeba 100644 --- a/apps/openmw/mwlua/nearbybindings.cpp +++ b/apps/openmw/mwlua/nearbybindings.cpp @@ -227,7 +227,7 @@ namespace MWLua | DetourNavigator::Flag_swim | DetourNavigator::Flag_openDoor | DetourNavigator::Flag_usePathgrid; api["findPath"] - = [](const osg::Vec3f& source, const osg::Vec3f& destination, const sol::optional& options) { + = [lua](const osg::Vec3f& source, const osg::Vec3f& destination, const sol::optional& options) { DetourNavigator::AgentBounds agentBounds = defaultAgentBounds; DetourNavigator::Flags includeFlags = defaultIncludeFlags; DetourNavigator::AreaCosts areaCosts{}; @@ -259,13 +259,15 @@ namespace MWLua destinationTolerance = *v; } - std::vector result; + std::vector path; - const DetourNavigator::Status status = DetourNavigator::findPath( - *MWBase::Environment::get().getWorld()->getNavigator(), agentBounds, source, destination, - includeFlags, areaCosts, destinationTolerance, std::back_inserter(result)); + const DetourNavigator::Status status + = DetourNavigator::findPath(*MWBase::Environment::get().getWorld()->getNavigator(), agentBounds, + source, destination, includeFlags, areaCosts, destinationTolerance, std::back_inserter(path)); - return std::make_tuple(status, std::move(result)); + sol::table result(lua, sol::create); + LuaUtil::copyVectorToTable(path, result); + return std::make_tuple(status, result); }; api["findRandomPointAroundCircle"] = [](const osg::Vec3f& position, float maxRadius, diff --git a/components/lua/luastate.hpp b/components/lua/luastate.hpp index 08e4e578fc..32c3151c88 100644 --- a/components/lua/luastate.hpp +++ b/components/lua/luastate.hpp @@ -372,6 +372,12 @@ namespace LuaUtil } sol::table getMutableFromReadOnly(const sol::userdata&); + template + void copyVectorToTable(const std::vector& v, sol::table& out) + { + for (const T& t : v) + out.add(t); + } } #endif // COMPONENTS_LUA_LUASTATE_H diff --git a/scripts/data/integration_tests/test_lua_api/player.lua b/scripts/data/integration_tests/test_lua_api/player.lua index a9c2002263..18229a3cd8 100644 --- a/scripts/data/integration_tests/test_lua_api/player.lua +++ b/scripts/data/integration_tests/test_lua_api/player.lua @@ -176,8 +176,8 @@ testing.registerLocalTest('findPath', } local status, path = nearby.findPath(src, dst, options) testing.expectEqual(status, nearby.FIND_PATH_STATUS.Success, 'Status') - testing.expectLessOrEqual((path[path:size()] - dst):length(), 1, - 'Last path point ' .. testing.formatActualExpected(path[path:size()], dst)) + testing.expectLessOrEqual((path[#path] - dst):length(), 1, + 'Last path point ' .. testing.formatActualExpected(path[#path], dst)) end) testing.registerLocalTest('findRandomPointAroundCircle', diff --git a/scripts/data/morrowind_tests/player.lua b/scripts/data/morrowind_tests/player.lua index 7c2e36978e..8fc27a79dd 100644 --- a/scripts/data/morrowind_tests/player.lua +++ b/scripts/data/morrowind_tests/player.lua @@ -42,8 +42,8 @@ testing.registerLocalTest('Guard in Imperial Prison Ship should find path (#7241 } local status, path = nearby.findPath(src, dst, options) testing.expectEqual(status, nearby.FIND_PATH_STATUS.Success, 'Status') - testing.expectLessOrEqual((util.vector2(path[path:size()].x, path[path:size()].y) - util.vector2(dst.x, dst.y)):length(), 1, 'Last path point x, y') - testing.expectLessOrEqual(path[path:size()].z - dst.z, 20, 'Last path point z') + testing.expectLessOrEqual((util.vector2(path[#path].x, path[#path]) - util.vector2(dst.x, dst.y)):length(), 1, 'Last path point x, y') + testing.expectLessOrEqual(path[#path].z - dst.z, 20, 'Last path point z') if agentBounds.shapeType == nearby.COLLISION_SHAPE_TYPE.Aabb then testing.expectThat(path, testing.elementsAreArray({ testing.closeToVector(util.vector3(34.29737091064453125, 806.3817138671875, 112.76610565185546875), 1e-1), From 19014c9c47bf9f66e46eba67b8cef5a1de24a595 Mon Sep 17 00:00:00 2001 From: uramer Date: Mon, 2 Dec 2024 21:23:52 +0100 Subject: [PATCH 2/3] Add end-to-end morrowind test work directory to gitignore --- scripts/data/morrowind_tests/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 scripts/data/morrowind_tests/.gitignore diff --git a/scripts/data/morrowind_tests/.gitignore b/scripts/data/morrowind_tests/.gitignore new file mode 100644 index 0000000000..baa5e491ee --- /dev/null +++ b/scripts/data/morrowind_tests/.gitignore @@ -0,0 +1 @@ +test_workdir/* \ No newline at end of file From 30e6821d818932797ff9cba22863bcb38857b71a Mon Sep 17 00:00:00 2001 From: uramer Date: Tue, 3 Dec 2024 06:18:00 +0000 Subject: [PATCH 3/3] Fix missing `y` --- scripts/data/morrowind_tests/player.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/data/morrowind_tests/player.lua b/scripts/data/morrowind_tests/player.lua index 8fc27a79dd..7435b49553 100644 --- a/scripts/data/morrowind_tests/player.lua +++ b/scripts/data/morrowind_tests/player.lua @@ -42,7 +42,7 @@ testing.registerLocalTest('Guard in Imperial Prison Ship should find path (#7241 } local status, path = nearby.findPath(src, dst, options) testing.expectEqual(status, nearby.FIND_PATH_STATUS.Success, 'Status') - testing.expectLessOrEqual((util.vector2(path[#path].x, path[#path]) - util.vector2(dst.x, dst.y)):length(), 1, 'Last path point x, y') + testing.expectLessOrEqual((util.vector2(path[#path].x, path[#path].y) - util.vector2(dst.x, dst.y)):length(), 1, 'Last path point x, y') testing.expectLessOrEqual(path[#path].z - dst.z, 20, 'Last path point z') if agentBounds.shapeType == nearby.COLLISION_SHAPE_TYPE.Aabb then testing.expectThat(path, testing.elementsAreArray({