summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/camera_2d.cpp6
-rw-r--r--scene/2d/camera_2d.h2
-rw-r--r--scene/2d/line_builder.cpp2
-rw-r--r--scene/2d/navigation_agent_2d.cpp18
-rw-r--r--scene/2d/navigation_link_2d.cpp38
-rw-r--r--scene/2d/navigation_link_2d.h6
-rw-r--r--scene/2d/navigation_region_2d.cpp90
-rw-r--r--scene/2d/tile_map.cpp117
-rw-r--r--scene/2d/tile_map.h7
9 files changed, 231 insertions, 55 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index fe6bee0f1b..f7d2ae7d2d 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -266,6 +266,8 @@ void Camera2D::_notification(int p_what) {
clear_current();
}
viewport = nullptr;
+ just_exited_tree = true;
+ callable_mp(this, &Camera2D::_reset_just_exited).call_deferred();
} break;
#ifdef TOOLS_ENABLED
@@ -438,6 +440,10 @@ void Camera2D::_update_process_internal_for_smoothing() {
void Camera2D::make_current() {
ERR_FAIL_COND(!enabled || !is_inside_tree());
get_tree()->call_group(group_name, "_make_current", this);
+ if (just_exited_tree) {
+ // If camera exited the scene tree in the same frame, group call will skip it, so this needs to be called manually.
+ _make_current(this);
+ }
_update_scroll();
}
diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h
index 7a77266db8..2417953691 100644
--- a/scene/2d/camera_2d.h
+++ b/scene/2d/camera_2d.h
@@ -51,6 +51,7 @@ protected:
Point2 camera_pos;
Point2 smoothed_camera_pos;
bool first = true;
+ bool just_exited_tree = false;
ObjectID custom_viewport_id; // to check validity
Viewport *custom_viewport = nullptr;
@@ -88,6 +89,7 @@ protected:
void _update_scroll();
void _make_current(Object *p_which);
+ void _reset_just_exited() { just_exited_tree = false; }
void _set_old_smoothing(real_t p_enable);
diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp
index d91f6e36bb..0970325502 100644
--- a/scene/2d/line_builder.cpp
+++ b/scene/2d/line_builder.cpp
@@ -393,6 +393,8 @@ void LineBuilder::build() {
if (end_cap_mode == Line2D::LINE_CAP_BOX) {
pos_up1 += f0 * hw * width_factor;
pos_down1 += f0 * hw * width_factor;
+
+ current_distance1 += hw * width_factor;
}
if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp
index 6aa7779b09..1ee6a0b779 100644
--- a/scene/2d/navigation_agent_2d.cpp
+++ b/scene/2d/navigation_agent_2d.cpp
@@ -31,6 +31,7 @@
#include "navigation_agent_2d.h"
#include "core/math/geometry_2d.h"
+#include "scene/2d/navigation_link_2d.h"
#include "scene/resources/world_2d.h"
#include "servers/navigation_server_2d.h"
@@ -119,7 +120,7 @@ void NavigationAgent2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_debug_path_custom_line_width", "line_width"), &NavigationAgent2D::set_debug_path_custom_line_width);
ClassDB::bind_method(D_METHOD("get_debug_path_custom_line_width"), &NavigationAgent2D::get_debug_path_custom_line_width);
- ADD_GROUP("Debug", "");
+ ADD_GROUP("Debug", "debug_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_enabled"), "set_debug_enabled", "get_debug_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_use_custom"), "set_debug_use_custom", "get_debug_use_custom");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "debug_path_custom_color"), "set_debug_path_custom_color", "get_debug_path_custom_color");
@@ -623,6 +624,21 @@ void NavigationAgent2D::update_navigation() {
}
details[SNAME("owner")] = owner;
+
+ if (waypoint_type == NavigationPathQueryResult2D::PATH_SEGMENT_TYPE_LINK) {
+ const NavigationLink2D *navlink = Object::cast_to<NavigationLink2D>(owner);
+ if (navlink) {
+ Vector2 link_global_start_position = navlink->get_global_start_position();
+ Vector2 link_global_end_position = navlink->get_global_end_position();
+ if (waypoint.distance_to(link_global_start_position) < waypoint.distance_to(link_global_end_position)) {
+ details[SNAME("link_entry_position")] = link_global_start_position;
+ details[SNAME("link_exit_position")] = link_global_end_position;
+ } else {
+ details[SNAME("link_entry_position")] = link_global_end_position;
+ details[SNAME("link_exit_position")] = link_global_start_position;
+ }
+ }
+ }
}
// Emit a signal for the waypoint
diff --git a/scene/2d/navigation_link_2d.cpp b/scene/2d/navigation_link_2d.cpp
index 26dca40176..8adb7c6305 100644
--- a/scene/2d/navigation_link_2d.cpp
+++ b/scene/2d/navigation_link_2d.cpp
@@ -54,6 +54,12 @@ void NavigationLink2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_end_position", "position"), &NavigationLink2D::set_end_position);
ClassDB::bind_method(D_METHOD("get_end_position"), &NavigationLink2D::get_end_position);
+ ClassDB::bind_method(D_METHOD("set_global_start_position", "position"), &NavigationLink2D::set_global_start_position);
+ ClassDB::bind_method(D_METHOD("get_global_start_position"), &NavigationLink2D::get_global_start_position);
+
+ ClassDB::bind_method(D_METHOD("set_global_end_position", "position"), &NavigationLink2D::set_global_end_position);
+ ClassDB::bind_method(D_METHOD("get_global_end_position"), &NavigationLink2D::get_global_end_position);
+
ClassDB::bind_method(D_METHOD("set_enter_cost", "enter_cost"), &NavigationLink2D::set_enter_cost);
ClassDB::bind_method(D_METHOD("get_enter_cost"), &NavigationLink2D::get_enter_cost);
@@ -271,6 +277,38 @@ void NavigationLink2D::set_end_position(Vector2 p_position) {
#endif // DEBUG_ENABLED
}
+void NavigationLink2D::set_global_start_position(Vector2 p_position) {
+ if (is_inside_tree()) {
+ set_start_position(to_local(p_position));
+ } else {
+ set_start_position(p_position);
+ }
+}
+
+Vector2 NavigationLink2D::get_global_start_position() const {
+ if (is_inside_tree()) {
+ return to_global(start_position);
+ } else {
+ return start_position;
+ }
+}
+
+void NavigationLink2D::set_global_end_position(Vector2 p_position) {
+ if (is_inside_tree()) {
+ set_end_position(to_local(p_position));
+ } else {
+ set_end_position(p_position);
+ }
+}
+
+Vector2 NavigationLink2D::get_global_end_position() const {
+ if (is_inside_tree()) {
+ return to_global(end_position);
+ } else {
+ return end_position;
+ }
+}
+
void NavigationLink2D::set_enter_cost(real_t p_enter_cost) {
ERR_FAIL_COND_MSG(p_enter_cost < 0.0, "The enter_cost must be positive.");
if (Math::is_equal_approx(enter_cost, p_enter_cost)) {
diff --git a/scene/2d/navigation_link_2d.h b/scene/2d/navigation_link_2d.h
index 5bf2a72358..8a24d611c9 100644
--- a/scene/2d/navigation_link_2d.h
+++ b/scene/2d/navigation_link_2d.h
@@ -78,6 +78,12 @@ public:
void set_end_position(Vector2 p_position);
Vector2 get_end_position() const { return end_position; }
+ void set_global_start_position(Vector2 p_position);
+ Vector2 get_global_start_position() const;
+
+ void set_global_end_position(Vector2 p_position);
+ Vector2 get_global_end_position() const;
+
void set_enter_cost(real_t p_enter_cost);
real_t get_enter_cost() const { return enter_cost; }
diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp
index 3484a9de65..5dbba313bc 100644
--- a/scene/2d/navigation_region_2d.cpp
+++ b/scene/2d/navigation_region_2d.cpp
@@ -167,58 +167,78 @@ void NavigationRegion2D::_notification(int p_what) {
case NOTIFICATION_DRAW: {
#ifdef DEBUG_ENABLED
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer3D::get_singleton()->get_debug_enabled()) && navigation_polygon.is_valid()) {
- Vector<Vector2> verts = navigation_polygon->get_vertices();
- if (verts.size() < 3) {
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) && navigation_polygon.is_valid()) {
+ Vector<Vector2> navigation_polygon_vertices = navigation_polygon->get_vertices();
+ if (navigation_polygon_vertices.size() < 3) {
return;
}
- Color color;
- if (enabled) {
- color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color();
- } else {
- color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_disabled_color();
+ const NavigationServer2D *ns2d = NavigationServer2D::get_singleton();
+
+ bool enabled_geometry_face_random_color = ns2d->get_debug_navigation_enable_geometry_face_random_color();
+ bool enabled_edge_lines = ns2d->get_debug_navigation_enable_edge_lines();
+ bool enable_edge_connections = ns2d->get_debug_navigation_enable_edge_connections();
+
+ Color debug_face_color = ns2d->get_debug_navigation_geometry_face_color();
+ Color debug_edge_color = ns2d->get_debug_navigation_geometry_edge_color();
+ Color debug_edge_connection_color = ns2d->get_debug_navigation_edge_connection_color();
+
+ if (!enabled) {
+ debug_face_color = ns2d->get_debug_navigation_geometry_face_disabled_color();
+ debug_edge_color = ns2d->get_debug_navigation_geometry_edge_disabled_color();
}
- Color doors_color = NavigationServer3D::get_singleton()->get_debug_navigation_edge_connection_color();
RandomPCG rand;
for (int i = 0; i < navigation_polygon->get_polygon_count(); i++) {
// An array of vertices for this polygon.
Vector<int> polygon = navigation_polygon->get_polygon(i);
- Vector<Vector2> vertices;
- vertices.resize(polygon.size());
+ Vector<Vector2> debug_polygon_vertices;
+ debug_polygon_vertices.resize(polygon.size());
for (int j = 0; j < polygon.size(); j++) {
- ERR_FAIL_INDEX(polygon[j], verts.size());
- vertices.write[j] = verts[polygon[j]];
+ ERR_FAIL_INDEX(polygon[j], navigation_polygon_vertices.size());
+ debug_polygon_vertices.write[j] = navigation_polygon_vertices[polygon[j]];
}
// Generate the polygon color, slightly randomly modified from the settings one.
- Color random_variation_color;
- random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.1, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.2);
- random_variation_color.a = color.a;
- Vector<Color> colors;
- colors.push_back(random_variation_color);
+ Color random_variation_color = debug_face_color;
+ if (enabled_geometry_face_random_color) {
+ random_variation_color.set_hsv(
+ debug_face_color.get_h() + rand.random(-1.0, 1.0) * 0.1,
+ debug_face_color.get_s(),
+ debug_face_color.get_v() + rand.random(-1.0, 1.0) * 0.2);
+ }
+ random_variation_color.a = debug_face_color.a;
- RS::get_singleton()->canvas_item_add_polygon(get_canvas_item(), vertices, colors);
+ Vector<Color> debug_face_colors;
+ debug_face_colors.push_back(random_variation_color);
+ RS::get_singleton()->canvas_item_add_polygon(get_canvas_item(), debug_polygon_vertices, debug_face_colors);
+
+ if (enabled_edge_lines) {
+ Vector<Color> debug_edge_colors;
+ debug_edge_colors.push_back(debug_edge_color);
+ debug_polygon_vertices.push_back(debug_polygon_vertices[0]); // Add first again for closing polyline.
+ RS::get_singleton()->canvas_item_add_polyline(get_canvas_item(), debug_polygon_vertices, debug_edge_colors);
+ }
}
- // Draw the region
- Transform2D xform = get_global_transform();
- const NavigationServer2D *ns = NavigationServer2D::get_singleton();
- real_t radius = ns->map_get_edge_connection_margin(get_world_2d()->get_navigation_map()) / 2.0;
- for (int i = 0; i < ns->region_get_connections_count(region); i++) {
- // Two main points
- Vector2 a = ns->region_get_connection_pathway_start(region, i);
- a = xform.affine_inverse().xform(a);
- Vector2 b = ns->region_get_connection_pathway_end(region, i);
- b = xform.affine_inverse().xform(b);
- draw_line(a, b, doors_color);
-
- // Draw a circle to illustrate the margins.
- real_t angle = a.angle_to_point(b);
- draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, doors_color);
- draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, doors_color);
+ if (enable_edge_connections) {
+ // Draw the region edge connections.
+ Transform2D xform = get_global_transform();
+ real_t radius = ns2d->map_get_edge_connection_margin(get_world_2d()->get_navigation_map()) / 2.0;
+ for (int i = 0; i < ns2d->region_get_connections_count(region); i++) {
+ // Two main points
+ Vector2 a = ns2d->region_get_connection_pathway_start(region, i);
+ a = xform.affine_inverse().xform(a);
+ Vector2 b = ns2d->region_get_connection_pathway_end(region, i);
+ b = xform.affine_inverse().xform(b);
+ draw_line(a, b, debug_edge_connection_color);
+
+ // Draw a circle to illustrate the margins.
+ real_t angle = a.angle_to_point(b);
+ draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, debug_edge_connection_color);
+ draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, debug_edge_connection_color);
+ }
}
}
#endif // DEBUG_ENABLED
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 95bf67d38d..11e59d9858 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -752,6 +752,21 @@ TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() {
return navigation_visibility_mode;
}
+void TileMap::set_navigation_map(int p_layer, RID p_map) {
+ ERR_FAIL_INDEX(p_layer, (int)layers.size());
+ ERR_FAIL_COND_MSG(!is_inside_tree(), "A TileMap navigation map can only be changed while inside the SceneTree.");
+ layers[p_layer].navigation_map = p_map;
+ layers[p_layer].uses_world_navigation_map = p_map == get_world_2d()->get_navigation_map();
+}
+
+RID TileMap::get_navigation_map(int p_layer) const {
+ ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), RID());
+ if (layers[p_layer].navigation_map.is_valid()) {
+ return layers[p_layer].navigation_map;
+ }
+ return RID();
+}
+
void TileMap::set_y_sort_enabled(bool p_enable) {
Node2D::set_y_sort_enabled(p_enable);
_clear_internals();
@@ -897,6 +912,9 @@ void TileMap::_recreate_layer_internals(int p_layer) {
// Update the layer internals.
_rendering_update_layer(p_layer);
+ // Update the layer internal navigation maps.
+ _navigation_update_layer(p_layer);
+
// Recreate the quadrants.
const HashMap<Vector2i, TileMapCell> &tile_map = layers[p_layer].tile_map;
for (const KeyValue<Vector2i, TileMapCell> &E : tile_map) {
@@ -959,6 +977,9 @@ void TileMap::_clear_layer_internals(int p_layer) {
// Clear the layers internals.
_rendering_cleanup_layer(p_layer);
+ // Clear the layers internal navigation maps.
+ _navigation_cleanup_layer(p_layer);
+
// Clear the dirty quadrants list.
while (layers[p_layer].dirty_quadrant_list.first()) {
layers[p_layer].dirty_quadrant_list.remove(layers[p_layer].dirty_quadrant_list.first());
@@ -1083,6 +1104,38 @@ void TileMap::_rendering_notification(int p_what) {
}
}
+void TileMap::_navigation_update_layer(int p_layer) {
+ ERR_FAIL_INDEX(p_layer, (int)layers.size());
+ ERR_FAIL_NULL(NavigationServer2D::get_singleton());
+
+ if (!layers[p_layer].navigation_map.is_valid()) {
+ if (p_layer == 0 && is_inside_tree()) {
+ // Use the default World2D navigation map for the first layer when empty.
+ layers[p_layer].navigation_map = get_world_2d()->get_navigation_map();
+ layers[p_layer].uses_world_navigation_map = true;
+ } else {
+ RID new_layer_map = NavigationServer2D::get_singleton()->map_create();
+ NavigationServer2D::get_singleton()->map_set_active(new_layer_map, true);
+ layers[p_layer].navigation_map = new_layer_map;
+ layers[p_layer].uses_world_navigation_map = false;
+ }
+ }
+}
+
+void TileMap::_navigation_cleanup_layer(int p_layer) {
+ ERR_FAIL_INDEX(p_layer, (int)layers.size());
+ ERR_FAIL_NULL(NavigationServer2D::get_singleton());
+
+ if (layers[p_layer].navigation_map.is_valid()) {
+ if (layers[p_layer].uses_world_navigation_map) {
+ // Do not delete the World2D default navigation map.
+ return;
+ }
+ NavigationServer2D::get_singleton()->free(layers[p_layer].navigation_map);
+ layers[p_layer].navigation_map = RID();
+ }
+}
+
void TileMap::_rendering_update_layer(int p_layer) {
ERR_FAIL_INDEX(p_layer, (int)layers.size());
@@ -1732,6 +1785,9 @@ void TileMap::_navigation_update_dirty_quadrants(SelfList<TileMapQuadrant>::List
q.navigation_regions[E_cell].resize(tile_set->get_navigation_layers_count());
for (int layer_index = 0; layer_index < tile_set->get_navigation_layers_count(); layer_index++) {
+ if (layer_index >= (int)layers.size() || !layers[layer_index].navigation_map.is_valid()) {
+ continue;
+ }
Ref<NavigationPolygon> navigation_polygon;
navigation_polygon = tile_data->get_navigation_polygon(layer_index);
@@ -1741,7 +1797,7 @@ void TileMap::_navigation_update_dirty_quadrants(SelfList<TileMapQuadrant>::List
RID region = NavigationServer2D::get_singleton()->region_create();
NavigationServer2D::get_singleton()->region_set_owner_id(region, get_instance_id());
- NavigationServer2D::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map());
+ NavigationServer2D::get_singleton()->region_set_map(region, layers[layer_index].navigation_map);
NavigationServer2D::get_singleton()->region_set_transform(region, tilemap_xform * tile_transform);
NavigationServer2D::get_singleton()->region_set_navigation_layers(region, tile_set->get_navigation_layer_layers(layer_index));
NavigationServer2D::get_singleton()->region_set_navigation_polygon(region, navigation_polygon);
@@ -1795,12 +1851,16 @@ void TileMap::_navigation_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
return;
}
+#ifdef DEBUG_ENABLED
RenderingServer *rs = RenderingServer::get_singleton();
+ const NavigationServer2D *ns2d = NavigationServer2D::get_singleton();
+
+ bool enabled_geometry_face_random_color = ns2d->get_debug_navigation_enable_geometry_face_random_color();
+ bool enabled_edge_lines = ns2d->get_debug_navigation_enable_edge_lines();
+
+ Color debug_face_color = ns2d->get_debug_navigation_geometry_face_color();
+ Color debug_edge_color = ns2d->get_debug_navigation_geometry_edge_color();
- Color color = Color(0.5, 1.0, 1.0, 1.0);
-#ifdef DEBUG_ENABLED
- color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color();
-#endif // DEBUG_ENABLED
RandomPCG rand;
Vector2 quadrant_pos = map_to_local(p_quadrant->coords * get_effective_quadrant_size(p_quadrant->layer));
@@ -1830,34 +1890,50 @@ void TileMap::_navigation_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
rs->canvas_item_add_set_transform(p_quadrant->debug_canvas_item, cell_to_quadrant);
for (int layer_index = 0; layer_index < tile_set->get_navigation_layers_count(); layer_index++) {
- Ref<NavigationPolygon> navpoly = tile_data->get_navigation_polygon(layer_index);
- if (navpoly.is_valid()) {
- PackedVector2Array navigation_polygon_vertices = navpoly->get_vertices();
+ Ref<NavigationPolygon> navigation_polygon = tile_data->get_navigation_polygon(layer_index);
+ if (navigation_polygon.is_valid()) {
+ Vector<Vector2> navigation_polygon_vertices = navigation_polygon->get_vertices();
+ if (navigation_polygon_vertices.size() < 3) {
+ continue;
+ }
- for (int i = 0; i < navpoly->get_polygon_count(); i++) {
+ for (int i = 0; i < navigation_polygon->get_polygon_count(); i++) {
// An array of vertices for this polygon.
- Vector<int> polygon = navpoly->get_polygon(i);
- Vector<Vector2> vertices;
- vertices.resize(polygon.size());
+ Vector<int> polygon = navigation_polygon->get_polygon(i);
+ Vector<Vector2> debug_polygon_vertices;
+ debug_polygon_vertices.resize(polygon.size());
for (int j = 0; j < polygon.size(); j++) {
ERR_FAIL_INDEX(polygon[j], navigation_polygon_vertices.size());
- vertices.write[j] = navigation_polygon_vertices[polygon[j]];
+ debug_polygon_vertices.write[j] = navigation_polygon_vertices[polygon[j]];
}
// Generate the polygon color, slightly randomly modified from the settings one.
- Color random_variation_color;
- random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.05, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.1);
- random_variation_color.a = color.a;
- Vector<Color> colors;
- colors.push_back(random_variation_color);
+ Color random_variation_color = debug_face_color;
+ if (enabled_geometry_face_random_color) {
+ random_variation_color.set_hsv(
+ debug_face_color.get_h() + rand.random(-1.0, 1.0) * 0.1,
+ debug_face_color.get_s(),
+ debug_face_color.get_v() + rand.random(-1.0, 1.0) * 0.2);
+ }
+ random_variation_color.a = debug_face_color.a;
- rs->canvas_item_add_polygon(p_quadrant->debug_canvas_item, vertices, colors);
+ Vector<Color> debug_face_colors;
+ debug_face_colors.push_back(random_variation_color);
+ rs->canvas_item_add_polygon(p_quadrant->debug_canvas_item, debug_polygon_vertices, debug_face_colors);
+
+ if (enabled_edge_lines) {
+ Vector<Color> debug_edge_colors;
+ debug_edge_colors.push_back(debug_edge_color);
+ debug_polygon_vertices.push_back(debug_polygon_vertices[0]); // Add first again for closing polyline.
+ rs->canvas_item_add_polyline(p_quadrant->debug_canvas_item, debug_polygon_vertices, debug_edge_colors);
+ }
}
}
}
}
}
}
+#endif // DEBUG_ENABLED
}
/////////////////////////////// Scenes //////////////////////////////////////
@@ -4031,6 +4107,9 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_navigation_visibility_mode", "navigation_visibility_mode"), &TileMap::set_navigation_visibility_mode);
ClassDB::bind_method(D_METHOD("get_navigation_visibility_mode"), &TileMap::get_navigation_visibility_mode);
+ ClassDB::bind_method(D_METHOD("set_navigation_map", "layer", "map"), &TileMap::set_navigation_map);
+ ClassDB::bind_method(D_METHOD("get_navigation_map", "layer"), &TileMap::get_navigation_map);
+
ClassDB::bind_method(D_METHOD("set_cell", "layer", "coords", "source_id", "atlas_coords", "alternative_tile"), &TileMap::set_cell, DEFVAL(TileSet::INVALID_SOURCE), DEFVAL(TileSetSource::INVALID_ATLAS_COORDS), DEFVAL(0));
ClassDB::bind_method(D_METHOD("erase_cell", "layer", "coords"), &TileMap::erase_cell);
ClassDB::bind_method(D_METHOD("get_cell_source_id", "layer", "coords", "use_proxies"), &TileMap::get_cell_source_id, DEFVAL(false));
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index 7cf2a2eded..e9c1cb0c11 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -211,6 +211,8 @@ private:
HashMap<Vector2i, TileMapCell> tile_map;
HashMap<Vector2i, TileMapQuadrant> quadrant_map;
SelfList<TileMapQuadrant>::List dirty_quadrant_list;
+ RID navigation_map;
+ bool uses_world_navigation_map = false;
};
LocalVector<TileMapLayer> layers;
int selected_layer = -1;
@@ -259,6 +261,8 @@ private:
void _physics_draw_quadrant_debug(TileMapQuadrant *p_quadrant);
void _navigation_notification(int p_what);
+ void _navigation_update_layer(int p_layer);
+ void _navigation_cleanup_layer(int p_layer);
void _navigation_update_dirty_quadrants(SelfList<TileMapQuadrant>::List &r_dirty_quadrant_list);
void _navigation_cleanup_quadrant(TileMapQuadrant *p_quadrant);
void _navigation_draw_quadrant_debug(TileMapQuadrant *p_quadrant);
@@ -339,6 +343,9 @@ public:
void set_navigation_visibility_mode(VisibilityMode p_show_navigation);
VisibilityMode get_navigation_visibility_mode();
+ void set_navigation_map(int p_layer, RID p_map);
+ RID get_navigation_map(int p_layer) const;
+
// Cells accessors.
void set_cell(int p_layer, const Vector2i &p_coords, int p_source_id = TileSet::INVALID_SOURCE, const Vector2i p_atlas_coords = TileSetSource::INVALID_ATLAS_COORDS, int p_alternative_tile = 0);
void erase_cell(int p_layer, const Vector2i &p_coords);