TileMaps now support navigation map overrides.

This commit is contained in:
Relintai 2023-09-05 10:46:22 +02:00
parent 102ef3ac12
commit 268c27458a
3 changed files with 44 additions and 7 deletions

View File

@ -153,6 +153,19 @@
<description>
</description>
</method>
<method name="set_navigation_map">
<return type="void" />
<argument index="0" name="navigation_map" type="RID" />
<description>
Sets the [RID] of the navigation map this region should use. By default the region will automatically join the [World2D] default navigation map so this function is only required to override the default map.
</description>
</method>
<method name="get_navigation_map" qualifiers="const">
<return type="RID" />
<description>
Returns the current navigation map [RID] use by this region.
</description>
</method>
</methods>
<members>
<member name="bake_navigation" type="bool" setter="set_bake_navigation" getter="is_baking_navigation" default="false">

View File

@ -68,8 +68,6 @@ void TileMap::_notification(int p_what) {
while (c) {
navigation = Object::cast_to<Navigation2D>(c);
if (navigation) {
// only for <3.5 backward compatibility
bake_navigation = true;
break;
}
@ -697,11 +695,7 @@ void TileMap::update_dirty_quadrants() {
RID region = Navigation2DServer::get_singleton()->region_create();
Navigation2DServer::get_singleton()->region_set_owner_id(region, get_instance_id());
if (navigation) {
Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid());
} else {
Navigation2DServer::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map());
}
Navigation2DServer::get_singleton()->region_set_map(region, get_navigation_map());
Navigation2DServer::get_singleton()->region_set_navigation_layers(region, navigation_layers);
Navigation2DServer::get_singleton()->region_set_transform(region, nav_rel * xform);
Navigation2DServer::get_singleton()->region_set_navigation_polygon(region, navigation_polygon);
@ -1771,6 +1765,29 @@ bool TileMap::is_centered_textures_enabled() const {
return centered_textures;
}
void TileMap::set_navigation_map(RID p_navigation_map) {
if (navigation_map_override == p_navigation_map) {
return;
}
navigation_map_override = p_navigation_map;
for (RBMap<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
_make_quadrant_dirty(E);
}
}
RID TileMap::get_navigation_map() const {
if (navigation_map_override.is_valid()) {
return navigation_map_override;
} else if (navigation) {
return navigation->get_rid();
} else if (is_inside_tree()) {
return get_world_2d()->get_navigation_map();
}
return RID();
}
Array TileMap::get_used_cells() const {
Array a;
a.resize(tile_map.size());
@ -1961,6 +1978,9 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("fix_invalid_tiles"), &TileMap::fix_invalid_tiles);
ClassDB::bind_method(D_METHOD("clear"), &TileMap::clear);
ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &TileMap::set_navigation_map);
ClassDB::bind_method(D_METHOD("get_navigation_map"), &TileMap::get_navigation_map);
ClassDB::bind_method(D_METHOD("get_used_cells"), &TileMap::get_used_cells);
ClassDB::bind_method(D_METHOD("get_used_cells_by_id", "id"), &TileMap::get_used_cells_by_id);
ClassDB::bind_method(D_METHOD("get_used_rect"), &TileMap::get_used_rect);

View File

@ -79,6 +79,7 @@ private:
bool use_parent;
CollisionObject2D *collision_parent;
bool use_kinematic;
RID navigation_map_override;
Navigation2D *navigation;
bool bake_navigation;
uint32_t navigation_layers;
@ -350,6 +351,9 @@ public:
void set_centered_textures(bool p_enable);
bool is_centered_textures_enabled() const;
void set_navigation_map(RID p_navigation_map);
RID get_navigation_map() const;
// TODO change these to PoolVector2iArrays
Array get_used_cells() const;
Array get_used_cells_by_id(int p_id) const;