diff --git a/godot-cpp b/godot-cpp index 21d526e..a62f633 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit 21d526e5e5b1e5d8b6be4db05a704c2c2e7837a9 +Subproject commit a62f633cebee4b36356dc903d00670733cd28fb1 diff --git a/src/RecastConfig.cpp b/src/RecastConfig.cpp index 8a76517..7bc33f5 100644 --- a/src/RecastConfig.cpp +++ b/src/RecastConfig.cpp @@ -26,4 +26,5 @@ void godot::RecastConfig::_bind_methods() { ClassDB::bind_method(D_METHOD("set_max_verts_per_poly", "max_verts_per_poly"), &RecastConfig::set_max_verts_per_poly); ClassDB::bind_method(D_METHOD("set_detail_sample_dist", "detail_sample_dist"), &RecastConfig::set_detail_sample_dist); ClassDB::bind_method(D_METHOD("set_detail_sample_max_error", "detail_sample_max_error"), &RecastConfig::set_detail_sample_max_error); + ClassDB::bind_method(D_METHOD("set_partition_type", "partition_type"), &RecastConfig::set_partition_type); } diff --git a/src/RecastConfig.hpp b/src/RecastConfig.hpp index 4dbca66..6a0e95c 100644 --- a/src/RecastConfig.hpp +++ b/src/RecastConfig.hpp @@ -5,17 +5,24 @@ #include "godot_cpp/classes/object.hpp" #include "godot_cpp/classes/node3d.hpp" +enum RecastPartitionTypes { + WATERSHED, + MONOTONE, + LAYERS +}; + namespace godot { struct RecastConfig : public Object { GDCLASS(RecastConfig, Object) private: - rcConfig config; protected: static void _bind_methods(); public: + rcConfig config; + RecastPartitionTypes partition_type = WATERSHED; + RecastConfig(); ~RecastConfig(); - rcConfig get_config() { return config; } /// The width of the field along the x-axis. [Limit: >= 0] [Units: vx] void set_width(int width) { config.width = width; } /// The height of the field along the z-axis. [Limit: >= 0] [Units: vx] @@ -70,5 +77,22 @@ public: /// The maximum distance the detail mesh surface should deviate from heightfield /// data. (For height detail only.) [Limit: >=0] [Units: wu] void set_detail_sample_max_error(float detail_sample_max_error) { config.detailSampleMaxError = detail_sample_max_error; } + /// The partition type to use for the heightfield. + /// + /// Allowed values are: + /// - WATERSHED + /// - MONOTONE + /// - LAYERS + /// + /// Any other value will lead to no change in the partition type. + void set_partition_type(const std::string& partition_type) { + if (partition_type == "WATERSHED") { + this->partition_type = WATERSHED; + } else if (partition_type == "MONOTONE") { + this->partition_type = MONOTONE; + } else if (partition_type == "LAYERS") { + this->partition_type = LAYERS; + } + } }; } diff --git a/src/RecastNavMesh.cpp b/src/RecastNavMesh.cpp index aab7be8..186cbbe 100644 --- a/src/RecastNavMesh.cpp +++ b/src/RecastNavMesh.cpp @@ -5,7 +5,7 @@ godot::RecastNavMesh::RecastNavMesh() { } godot::RecastNavMesh::~RecastNavMesh() { - + cleanup(); } void godot::RecastNavMesh::_bind_methods() { @@ -15,6 +15,25 @@ void godot::RecastNavMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("is_calculated"), &RecastNavMesh::is_calculated); } +void godot::RecastNavMesh::cleanup() { + /* + delete [] m_triareas; + m_triareas = 0; + rcFreeHeightField(m_solid); + m_solid = 0; + rcFreeCompactHeightfield(m_chf); + m_chf = 0; + rcFreeContourSet(m_cset); + m_cset = 0; + rcFreePolyMesh(m_pmesh); + m_pmesh = 0; + rcFreePolyMeshDetail(m_dmesh); + m_dmesh = 0; + dtFreeNavMesh(m_navMesh); + m_navMesh = 0; + */ +} + bool godot::RecastNavMesh::add_vertices(const PackedByteArray& vertices, unsigned char area_id) { return false; } diff --git a/src/RecastNavMesh.hpp b/src/RecastNavMesh.hpp index 1c8f3f9..217624e 100644 --- a/src/RecastNavMesh.hpp +++ b/src/RecastNavMesh.hpp @@ -13,6 +13,7 @@ namespace godot { public: RecastNavMesh(); ~RecastNavMesh(); + void cleanup(); void clear_vertices(); bool add_vertices(const PackedByteArray& vertices, unsigned char area_id); bool recalculate_navmesh();