From edefc33278c648a125f111a2a38822512be9dc8a Mon Sep 17 00:00:00 2001 From: Gtker Date: Mon, 4 Sep 2023 20:02:37 +0200 Subject: [PATCH 1/3] Add Python/C way of checking if BVH/maps have been built Fixes https://github.com/namreeb/namigator/issues/51. --- MapBuilder/CMakeLists.txt | 2 +- MapBuilder/FileExist.cpp | 17 ++++++++++++ MapBuilder/FileExist.hpp | 9 +++++++ MapBuilder/MapBuilder_c_bindings.cpp | 39 ++++++++++++++++++++++++++++ MapBuilder/mapbuilder_c_bindings.h | 19 +++++++++++++- MapBuilder/python.cpp | 11 ++++++++ test/smoke_tests.py | 10 +++++++ 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 MapBuilder/FileExist.cpp create mode 100644 MapBuilder/FileExist.hpp diff --git a/MapBuilder/CMakeLists.txt b/MapBuilder/CMakeLists.txt index a2ce294..930fe3b 100644 --- a/MapBuilder/CMakeLists.txt +++ b/MapBuilder/CMakeLists.txt @@ -2,7 +2,7 @@ set(EXECUTABLE_NAME MapBuilder) set(LIBRARY_NAME libmapbuild) set(PYTHON_NAME mapbuild) -set(SRC BVHConstructor.cpp GameObjectBVHBuilder.cpp MeshBuilder.cpp RecastContext.cpp Worker.cpp MapBuilder_c_bindings.cpp) +set(SRC BVHConstructor.cpp GameObjectBVHBuilder.cpp MeshBuilder.cpp RecastContext.cpp Worker.cpp MapBuilder_c_bindings.cpp FileExist.cpp) add_library(${LIBRARY_NAME} ${SRC}) target_include_directories(${LIBRARY_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../") diff --git a/MapBuilder/FileExist.cpp b/MapBuilder/FileExist.cpp new file mode 100644 index 0000000..4cc109c --- /dev/null +++ b/MapBuilder/FileExist.cpp @@ -0,0 +1,17 @@ +#include "FileExist.hpp" + +#include + +namespace file_exist { + +bool bvh_files_exist(const std::string& outputPath) { + // bvh.idx is created at the very end of building game objects + return std::filesystem::exists(outputPath + "/BVH/bvh.idx"); +} + +bool map_files_exist(const std::string& outputPath, const std::string& mapName) { + // mapName.map is created in MeshBuilder::SaveMap which should be after successful creation + return std::filesystem::exists(outputPath + "/" + mapName + ".map"); +} + +} // namespace file_exist diff --git a/MapBuilder/FileExist.hpp b/MapBuilder/FileExist.hpp new file mode 100644 index 0000000..dd060fc --- /dev/null +++ b/MapBuilder/FileExist.hpp @@ -0,0 +1,9 @@ +#include + +namespace file_exist { + +bool bvh_files_exist(const std::string& outputPath); + +bool map_files_exist(const std::string& outputPath, const std::string& mapName); + +} // namespace file_exist \ No newline at end of file diff --git a/MapBuilder/MapBuilder_c_bindings.cpp b/MapBuilder/MapBuilder_c_bindings.cpp index a22b323..9f0c1fa 100644 --- a/MapBuilder/MapBuilder_c_bindings.cpp +++ b/MapBuilder/MapBuilder_c_bindings.cpp @@ -1,5 +1,6 @@ #include "mapbuilder_c_bindings.h" +#include "FileExist.hpp" #include "GameObjectBVHBuilder.hpp" #include "MeshBuilder.hpp" #include "Worker.hpp" @@ -134,5 +135,43 @@ MapBuildResultType mapbuild_build_map(const char* const data_path, return static_cast(Result::SUCCESS); } +MapBuildResultType mapbuild_bvh_files_exist(const char* const output_path, + uint8_t* const exists) { + std::string outputPath = output_path; + + try { + if (file_exist::bvh_files_exist(outputPath)) { + *exists = 1; + } else { + *exists = 0; + } + } + catch (...) { + return static_cast(Result::UNKNOWN_EXCEPTION); + } + + return static_cast(Result::SUCCESS); +} + +MapBuildResultType mapbuild_map_files_exist(const char* const output_path, + const char* const map_name, + uint8_t* const exists) { + + std::string outputPath = output_path; + std::string mapName = map_name; + + try { + if (file_exist::map_files_exist(outputPath, mapName)) { + *exists = 1; + } else { + *exists = 0; + } + } + catch (...) { + return static_cast(Result::UNKNOWN_EXCEPTION); + } + + return static_cast(Result::SUCCESS); +} } diff --git a/MapBuilder/mapbuilder_c_bindings.h b/MapBuilder/mapbuilder_c_bindings.h index ff84c5d..9678e56 100644 --- a/MapBuilder/mapbuilder_c_bindings.h +++ b/MapBuilder/mapbuilder_c_bindings.h @@ -16,4 +16,21 @@ MapBuildResultType mapbuild_build_map(const char* const data_path, const char* const gameobject_csv, uint32_t threads); -} +/* + Tests if gameobjects have been built in `output_path`. + + `exists` will be `0` if the gameobject files haven't been built, and `1` if they have. + */ +MapBuildResultType mapbuild_bvh_files_exist(const char* const output_path, + uint8_t* const exists); + +/* + Tests if the map with `map_name` has already been built in `output_path`. + + `exists` will be `0` if the map hasn't been built, and `1` if it has. + */ +MapBuildResultType mapbuild_map_files_exist(const char* const output_path, + const char* const map_name, + uint8_t* const exists); + +} \ No newline at end of file diff --git a/MapBuilder/python.cpp b/MapBuilder/python.cpp index eb63519..6ed5419 100644 --- a/MapBuilder/python.cpp +++ b/MapBuilder/python.cpp @@ -2,6 +2,7 @@ #include "MeshBuilder.hpp" #include "Worker.hpp" #include "parser/MpqManager.hpp" +#include "FileExist.hpp" #include #include @@ -142,9 +143,19 @@ bool BuildADT(const std::string& dataPath, const std::string& outputPath, return true; } +bool BVHFilesExist(const std::string& outputPath) { + return file_exist::bvh_files_exist(outputPath); +} + +bool MapFilesExist(const std::string& outputPath, const std::string& mapName) { + return file_exist::map_files_exist(outputPath, mapName); +} + BOOST_PYTHON_MODULE(mapbuild) { boost::python::def("build_bvh", BuildBVH); boost::python::def("build_map", BuildMap); boost::python::def("build_adt", BuildADT); + boost::python::def("map_files_exist", MapFilesExist); + boost::python::def("bvh_files_exist", BVHFilesExist); } \ No newline at end of file diff --git a/test/smoke_tests.py b/test/smoke_tests.py index 13204cf..e4cb722 100644 --- a/test/smoke_tests.py +++ b/test/smoke_tests.py @@ -18,6 +18,11 @@ def approximate(a, b, epsilon=0.002): def test_build(temp_dir): data_dir = os.path.dirname(__file__) + if mapbuild.map_files_exist(temp_dir, "development"): + raise Exception("map_files_exist returned True when it should be False") + if mapbuild.bvh_files_exist(temp_dir): + raise Exception("map_files_exist returned True when it should be False") + start = time.time() mapbuild.build_map(data_dir, temp_dir, "development", 8, "") stop = time.time() @@ -30,6 +35,11 @@ def test_build(temp_dir): print("Map bladesedgearena built in {} seconds".format(int(stop-start))) + if not mapbuild.map_files_exist(temp_dir, "development"): + raise Exception("map_files_exist returned False when it should be True") + if not mapbuild.bvh_files_exist(temp_dir): + raise Exception("map_files_exist returned False when it should be True") + def test_pathfind(temp_dir): map_data = pathfind.Map(temp_dir, "development") From 000632018415375ec21b68a3a668375a4f23401b Mon Sep 17 00:00:00 2001 From: Gtker Date: Mon, 4 Sep 2023 20:02:37 +0200 Subject: [PATCH 2/3] Add C API documentation Fixes https://github.com/namreeb/namigator/issues/52. --- MapBuilder/mapbuilder_c_bindings.h | 27 ++++++++++++++++++++ pathfind/pathfind_c_bindings.hpp | 40 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/MapBuilder/mapbuilder_c_bindings.h b/MapBuilder/mapbuilder_c_bindings.h index 9678e56..03003bc 100644 --- a/MapBuilder/mapbuilder_c_bindings.h +++ b/MapBuilder/mapbuilder_c_bindings.h @@ -5,11 +5,38 @@ extern "C" { typedef uint8_t MapBuildResultType; +/* + Build gameobjects as bounded volume hierachy (BVH). + + `data_path` is the `Data` directory containing `MPQ` files of a client. + + `output_path` is the location where generated data will be placed. + + `threads` is the amount of concurrent jobs that will be used to build the data. + + `amount_of_bvhs_built` returns the amount of gameobjects built. + + This MUST be done before building the maps with `mapbuild_build_map`. + */ MapBuildResultType mapbuild_build_bvh(const char* const data_path, const char* const output_path, uint32_t threads, uint32_t* const amount_of_bvhs_built); +/* + Builds a single map. + + `data_path` is the `Data` directory containing `MPQ` files of a client. + + `output_path` is the location where generated data will be placed. + + `threads` is the amount of concurrent jobs that will be used to build the data. + + `map_name` is the name of the map folder inside the MPQ. For example `Azeroth` for Eastern Kingdoms. + + `gameobject_csv` is the path to a CSV file containing a list of dynamically loaded objects. + This feature is unlikely to work. +*/ MapBuildResultType mapbuild_build_map(const char* const data_path, const char* const output_path, const char* const map_name, diff --git a/pathfind/pathfind_c_bindings.hpp b/pathfind/pathfind_c_bindings.hpp index cd16199..be833eb 100644 --- a/pathfind/pathfind_c_bindings.hpp +++ b/pathfind/pathfind_c_bindings.hpp @@ -13,26 +13,52 @@ typedef struct { typedef uint8_t PathfindResultType; typedef uint8_t* PathfindResultTypePtr; +/* + Creates a new Map for `map_name` using data from the `data_path`. + + This pointer MUST be freed using `pathfind_free_map`, otherwise it will leak. + */ pathfind::Map* pathfind_new_map(const char* const data_path, const char* const map_name, PathfindResultTypePtr result); +/* + Cleans up a map created by `pathfind_new_map`. + + This function will delete the object but will not change the pointer. +*/ void pathfind_free_map(pathfind::Map* const map); +/* + Loads all ADTs on a map. +*/ PathfindResultType pathfind_load_all_adts(pathfind::Map* const map, int32_t* const amount_of_adts_loaded); +/* + Loads specific ADT. +*/ PathfindResultType pathfind_load_adt(pathfind::Map* const map, int adt_x, int adt_y, float* const out_adt_x, float* const out_adt_y); +/* + Loads specific ADT at in game coordinate (x, y) and returns the ADT x and y. +*/ PathfindResultType pathfind_load_adt_at(pathfind::Map* const map, float x, float y, float* const out_adt_x, float* const out_adt_y); +/* + Returns the zone and area of a particular x, y, z. +*/ PathfindResultType pathfind_get_zone_and_area(pathfind::Map* const map, float x, float y, float z, unsigned int* const out_zone, unsigned int* const out_area); +/* + Calculates a path from `start_x`, `start_y`, and `start_z` to + `stop_x`, `stop_y`, and `stop_z`. +*/ PathfindResultType pathfind_find_path(pathfind::Map* const map, float start_x, float start_y, float start_z, float stop_x, float stop_y, float stop_z, @@ -40,16 +66,30 @@ PathfindResultType pathfind_find_path(pathfind::Map* const map, float start_x, unsigned int buffer_length, unsigned int* const amount_of_vertices); +/* + Slices the map at `x`, `y` and returns all possible `z` values. +*/ PathfindResultType pathfind_find_heights(pathfind::Map* const map, float x, float y, float* const buffer, unsigned int buffer_length, unsigned int* const amount_of_heights); +/* + Returns the `stop_z` for the path between `start_x`, `start_y`, `start_z` + and `stop_x`, `stop_y`. + This is the value that would be achieved by walking from start to stop. +*/ PathfindResultType pathfind_find_height(pathfind::Map* const map, float start_x, float start_y, float start_z, float stop_x, float stop_y, float* const stop_z); +/* + Calculates whether there is line of sight between `start_x`, `start_y`, `start_z` + and `stop_x`, `stop_y`, `stop_z`. + + If `doodads` is not `0` doodads will be included in the calculations. +*/ PathfindResultType pathfind_line_of_sight(pathfind::Map* const map, float start_x, float start_y, float start_z, float stop_x, float stop_y, float stop_z, From b6c5c629a4ee11ffe96d7854d1ae2d7d26b2e733 Mon Sep 17 00:00:00 2001 From: Gtker Date: Mon, 4 Sep 2023 20:02:37 +0200 Subject: [PATCH 3/3] Replace boost with pybind11 2.11.1 Fixes https://github.com/namreeb/namigator/issues/31. pybind11 appears to work with both Python 2 and 3. pybind11 appears to name the final shared objects as mapbuild.cpython-310-x86_64-linux-gnu.so instead of just mapbuild.so But Python appears to handle this just fine. --- .github/workflows/build.yml | 14 ++----- .gitmodules | 3 ++ CMakeLists.txt | 80 ++----------------------------------- MapBuilder/CMakeLists.txt | 16 ++------ MapBuilder/python.cpp | 14 +++---- README.md | 2 +- pathfind/CMakeLists.txt | 14 ++----- pathfind/python.cpp | 28 +++++++------ pybind11 | 1 + 9 files changed, 40 insertions(+), 132 deletions(-) create mode 160000 pybind11 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 805b7ea..6b79b0c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,10 +19,10 @@ jobs: - name: Checkout submodules run: git submodule update --init --recursive - - name: Install python and boost + - name: Install python run: | sudo apt-get -y update - sudo apt-get install python3 python3-dev libboost-python-dev + sudo apt-get install python3 python3-dev - name: Configure CMake run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} @@ -59,16 +59,8 @@ jobs: python-version: '3.9' architecture: 'x64' - - name: Build Boost - run: | - Invoke-WebRequest https://boostorg.jfrog.io/artifactory/main/release/1.78.0/source/boost_1_78_0.zip -OutFile boost.zip - Expand-Archive -Path boost.zip -DestinationPath . - cd boost_1_78_0 - .\bootstrap - .\b2 --with-python link=static threading=multi runtime-link=shared architecture=x86 address-model=64 stage - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBOOST_ROOT=${{github.workspace}}/boost_1_78_0 -DBOOST_LIBRARYDIR=${{github.workspace}}/boost_1_78_0/stage/lib + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} diff --git a/.gitmodules b/.gitmodules index d237859..3b5006b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "stormlib"] path = stormlib url = https://github.com/ladislav-zezula/StormLib.git +[submodule "pybind11"] + path = pybind11 + url = https://github.com/pybind/pybind11 diff --git a/CMakeLists.txt b/CMakeLists.txt index 292d954..893ac5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,87 +21,13 @@ if (CMAKE_COMPILER_IS_GNUCC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-multichar") endif() -unset(Python3_FOUND CACHE) -unset(PYTHON_COMPONENT CACHE) - -# github python setup action will set this environment variable -if(DEFINED ENV{pythonLocation}) - set(Python3_ROOT_DIR $ENV{pythonLocation}) - set(Python3_FIND_REGISTRY NEVER) -endif() - option(NAMIGATOR_BUILD_PYTHON "Build Python bindings if Python2/3 is present." TRUE) option(NAMIGATOR_INSTALL_TESTS "Install tests." TRUE) if(NAMIGATOR_BUILD_PYTHON) - # First try finding python 3 development files - find_package(Python3 COMPONENTS Development) - - if (Python3_FOUND) - set(PYTHON_COMPONENT "python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}") - set(PYTHON_LIBRARIES "${Python3_LIBRARIES}") - set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}") - else() - message(STATUS "Could not find python3. Attemping to find python2.") - find_package(Python2 COMPONENTS Development) - if (Python2_FOUND) - set(PYTHON_COMPONENT "python${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}") - set(PYTHON_LIBRARIES "${Python2_LIBRARIES}") - set(PYTHON_INCLUDE_DIRS "${Python2_INCLUDE_DIRS}") - else() - message(STATUS "Could not find python2 either.") - endif() - endif() -endif() # NAMIGATOR_BUILD_PYTHON - -# Enable debug output from FindBoost -#set(Boost_DEBUG ON) -#set(Boost_DETAILED_FAILURE_MSG ON) - -if (PYTHON_COMPONENT) - # There currently seems to be a bug with the Linux distro of boost binaries - # where some symbols are not built with position independent code (-fPIC). - # So rather than requiring our users to build boost themselves, we can just - # disable static linking of Boost libraries for now. - if (MSVC) - set(Boost_USE_STATIC_LIBS ON) - else() - set(Boost_USE_STATIC_LIBS OFF) - endif() - - set(Boost_USE_MULTITHREADED ON) - set(Boost_USE_STATIC_RUNTIME OFF) - set(Boost_FIND_QUIETLY ON) - - find_package(Boost COMPONENTS "${PYTHON_COMPONENT}") - - # If we found python 3 and boost rejected it, try again with python 2 - if (NOT Boost_FOUND AND Python3_FOUND) - message(STATUS "Boost rejected ${PYTHON_COMPONENT}. Trying with python2.") - find_package(Python2 COMPONENTS Development) - - if (Python2_FOUND) - message(STATUS "Python2 found. Checking for support from boost.") - set(PYTHON_COMPONENT "python${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}") - set(PYTHON_LIBRARIES "${Python2_LIBRARIES}") - set(PYTHON_INCLUDE_DIRS "${Python2_INCLUDE_DIRS}") - find_package(Boost COMPONENTS "${PYTHON_COMPONENT}") - else() - message(STATUS "Could not find python2 either.") - endif() - - # Failed? Give up - if (NOT Boost_FOUND) - message(STATUS "Giving up on finding boost and python match") - unset(PYTHON_COMPONENT) - unset(PYTHON_LIBRARIES) - unset(PYTHON_INCLUDE_DIRS) - endif() - endif() -endif() - -if (NAMIGATOR_BUILD_PYTHON AND NOT PYTHON_COMPONENT) - message(WARNING "No boost-compatible python was found. Python bindings for ${CMAKE_PROJECT_NAME} will not be compiled") + add_subdirectory(pybind11) +else() + message(WARNING "Python bindings for ${CMAKE_PROJECT_NAME} will not be compiled") endif() # GCC 7 requires an extra lib for this, but MSVC does not diff --git a/MapBuilder/CMakeLists.txt b/MapBuilder/CMakeLists.txt index 930fe3b..f8bcfab 100644 --- a/MapBuilder/CMakeLists.txt +++ b/MapBuilder/CMakeLists.txt @@ -15,18 +15,10 @@ target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME}) install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin) -if (PYTHON_COMPONENT) - if (Python3_FOUND) - Python3_add_library(${PYTHON_NAME} ${SRC} python.cpp) - elseif (Python2_FOUND) - Python2_add_library(${PYTHON_NAME} ${SRC} python.cpp) - else() - message(FATAL_ERROR "Python component defined but neither python2 nor python3 were found") - endif() - - target_compile_definitions(${PYTHON_NAME} PUBLIC PYTHON BOOST_PYTHON_STATIC_LIB) - target_include_directories(${PYTHON_NAME} PUBLIC ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) - target_link_libraries(${PYTHON_NAME} PRIVATE parser utility RecastNavigation::Recast RecastNavigation::Detour storm ${Boost_LIBRARIES}) +if (NAMIGATOR_BUILD_PYTHON) + pybind11_add_module(${PYTHON_NAME} ${SRC} python.cpp) + + target_link_libraries(${PYTHON_NAME} PRIVATE parser utility RecastNavigation::Recast RecastNavigation::Detour storm) install(TARGETS ${PYTHON_NAME} DESTINATION lib) endif() diff --git a/MapBuilder/python.cpp b/MapBuilder/python.cpp index 6ed5419..6237267 100644 --- a/MapBuilder/python.cpp +++ b/MapBuilder/python.cpp @@ -4,7 +4,7 @@ #include "parser/MpqManager.hpp" #include "FileExist.hpp" -#include +#include #include #include #include @@ -151,11 +151,11 @@ bool MapFilesExist(const std::string& outputPath, const std::string& mapName) { return file_exist::map_files_exist(outputPath, mapName); } -BOOST_PYTHON_MODULE(mapbuild) +PYBIND11_MODULE(mapbuild, m) { - boost::python::def("build_bvh", BuildBVH); - boost::python::def("build_map", BuildMap); - boost::python::def("build_adt", BuildADT); - boost::python::def("map_files_exist", MapFilesExist); - boost::python::def("bvh_files_exist", BVHFilesExist); + m.def("build_bvh", &BuildBVH); + m.def("build_map", &BuildMap); + m.def("build_adt", &BuildADT); + m.def("map_files_exist", &MapFilesExist); + m.def("bvh_files_exist", &BVHFilesExist); } \ No newline at end of file diff --git a/README.md b/README.md index 2a5c1a8..3611216 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ server. * **stormlib** -- Used for extracting source data from its containers. * **recastnavigation** -- Underlying computational geometry library. Used for mesh generation, pathfinding, and more. -* **boost** -- Optional. Used in creating python modules. +* **pybind11** -- Optional. Used in creating python modules. * **python** -- Optional. Used in creating python modules. ## Future Plans diff --git a/pathfind/CMakeLists.txt b/pathfind/CMakeLists.txt index bf58b37..73a0179 100644 --- a/pathfind/CMakeLists.txt +++ b/pathfind/CMakeLists.txt @@ -15,18 +15,10 @@ target_link_libraries(${LIBRARY_NAME} PRIVATE ${FILESYSTEM_LIBRARY} utility Reca install(TARGETS ${LIBRARY_NAME} ARCHIVE DESTINATION lib) -if (PYTHON_COMPONENT) - if (Python3_FOUND) - Python3_add_library(${PYTHON_NAME} ${SRC} python.cpp) - elseif (Python2_FOUND) - Python2_add_library(${PYTHON_NAME} ${SRC} python.cpp) - else() - message(FATAL_ERROR "Python component defined but neither python2 nor python3 were found") - endif() +if (NAMIGATOR_BUILD_PYTHON) + pybind11_add_module(${PYTHON_NAME} ${SRC} python.cpp) - target_compile_definitions(${PYTHON_NAME} PUBLIC PYTHON BOOST_PYTHON_STATIC_LIB) - target_include_directories(${PYTHON_NAME} PRIVATE ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) - target_link_libraries(${PYTHON_NAME} PRIVATE ${FILESYSTEM_LIBRARY} utility RecastNavigation::Recast RecastNavigation::Detour storm ${Boost_LIBRARIES}) + target_link_libraries(${PYTHON_NAME} PRIVATE ${FILESYSTEM_LIBRARY} utility RecastNavigation::Recast RecastNavigation::Detour storm) install(TARGETS ${PYTHON_NAME} DESTINATION lib) endif() diff --git a/pathfind/python.cpp b/pathfind/python.cpp index d722678..e591070 100644 --- a/pathfind/python.cpp +++ b/pathfind/python.cpp @@ -1,13 +1,16 @@ #include "Map.hpp" #include "utility/MathHelper.hpp" -#include +#include +#include + #include #include #include #include +#include -namespace py = boost::python; +namespace py = pybind11; namespace { @@ -68,23 +71,22 @@ py::list python_query_heights(const pathfind::Map& map, float x, float y) return result; } -py::object python_query_z(const pathfind::Map& map, float start_x, float start_y, float start_z, +std::optional python_query_z(const pathfind::Map& map, float start_x, float start_y, float start_z, float stop_x, float stop_y) { float result; if (!map.FindHeight({start_x, start_y, start_z}, stop_x, stop_y, result)) - return py::object(py::handle<>(Py_None)); - return py::object(result); + return {}; + return result; } -py::object los(const pathfind::Map& map, float start_x, float start_y, float start_z, +bool los(const pathfind::Map& map, float start_x, float start_y, float start_z, float stop_x, float stop_y, float stop_z, bool doodads) { - return py::object( - map.LineOfSight( + return map.LineOfSight( {start_x, start_y, start_z}, {stop_x, stop_y, stop_z}, - doodads)); + doodads); } py::object get_zone_and_area(pathfind::Map& map, float x, float y, float z) @@ -92,15 +94,15 @@ py::object get_zone_and_area(pathfind::Map& map, float x, float y, float z) math::Vertex p {x, y, z}; unsigned int zone = -1, area = -1; if (!map.ZoneAndArea(p, zone, area)) - return py::object(py::handle<>(Py_None)); + return py::none(); return py::make_tuple(zone, area); } } // namespace -BOOST_PYTHON_MODULE(pathfind) +PYBIND11_MODULE(pathfind, m) { - py::class_( - "Map", py::init()) + py::class_(m, "Map") + .def(py::init()) .def("load_all_adts", &pathfind::Map::LoadAllADTs) .def("load_adt_at", &load_adt_at) .def("load_adt", &load_adt) diff --git a/pybind11 b/pybind11 new file mode 160000 index 0000000..8a099e4 --- /dev/null +++ b/pybind11 @@ -0,0 +1 @@ +Subproject commit 8a099e44b3d5f85b20f05828d919d2332a8de841