Merge pull request #78665 from smix8/fix_navobjects_map_4.x

Fix NavObjects map assignments
This commit is contained in:
Rémi Verschelde 2023-06-26 10:12:19 +02:00
commit 710d2e7edf
No known key found for this signature in database
GPG Key ID: C3336907360768E1
4 changed files with 48 additions and 75 deletions

View File

@ -358,22 +358,9 @@ COMMAND_2(region_set_map, RID, p_region, RID, p_map) {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_COND(region == nullptr);
if (region->get_map() != nullptr) {
if (region->get_map()->get_self() == p_map) {
return; // Pointless
}
NavMap *map = map_owner.get_or_null(p_map);
region->get_map()->remove_region(region);
region->set_map(nullptr);
}
if (p_map.is_valid()) {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_COND(map == nullptr);
map->add_region(region);
region->set_map(map);
}
region->set_map(map);
}
COMMAND_2(region_set_transform, RID, p_region, Transform3D, p_transform) {
@ -506,22 +493,9 @@ COMMAND_2(link_set_map, RID, p_link, RID, p_map) {
NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_COND(link == nullptr);
if (link->get_map() != nullptr) {
if (link->get_map()->get_self() == p_map) {
return; // Pointless
}
NavMap *map = map_owner.get_or_null(p_map);
link->get_map()->remove_link(link);
link->set_map(nullptr);
}
if (p_map.is_valid()) {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_COND(map == nullptr);
map->add_link(link);
link->set_map(map);
}
link->set_map(map);
}
RID GodotNavigationServer::link_get_map(const RID p_link) const {
@ -673,27 +647,9 @@ COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_COND(agent == nullptr);
if (agent->get_map()) {
if (agent->get_map()->get_self() == p_map) {
return; // Pointless
}
NavMap *map = map_owner.get_or_null(p_map);
agent->get_map()->remove_agent(agent);
}
agent->set_map(nullptr);
if (p_map.is_valid()) {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_COND(map == nullptr);
agent->set_map(map);
map->add_agent(agent);
if (agent->has_avoidance_callback()) {
map->set_agent_as_controlled(agent);
}
}
agent->set_map(map);
}
COMMAND_2(agent_set_paused, RID, p_agent, bool, p_paused) {
@ -875,23 +831,9 @@ COMMAND_2(obstacle_set_map, RID, p_obstacle, RID, p_map) {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_COND(obstacle == nullptr);
if (obstacle->get_map()) {
if (obstacle->get_map()->get_self() == p_map) {
return; // Pointless
}
NavMap *map = map_owner.get_or_null(p_map);
obstacle->get_map()->remove_obstacle(obstacle);
}
obstacle->set_map(nullptr);
if (p_map.is_valid()) {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_COND(map == nullptr);
obstacle->set_map(map);
map->add_obstacle(obstacle);
}
obstacle->set_map(map);
}
RID GodotNavigationServer::obstacle_get_map(RID p_obstacle) const {
@ -1050,17 +992,16 @@ void GodotNavigationServer::internal_free_agent(RID p_object) {
void GodotNavigationServer::internal_free_obstacle(RID p_object) {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_object);
if (obstacle) {
NavAgent *obstacle_agent = obstacle->get_agent();
if (obstacle_agent) {
RID _agent_rid = obstacle_agent->get_self();
internal_free_agent(_agent_rid);
obstacle->set_agent(nullptr);
}
if (obstacle->get_map() != nullptr) {
obstacle->get_map()->remove_obstacle(obstacle);
obstacle->set_map(nullptr);
}
if (obstacle->get_agent()) {
if (obstacle->get_agent()->get_self() != RID()) {
RID _agent_rid = obstacle->get_agent()->get_self();
obstacle->set_agent(nullptr);
internal_free_agent(_agent_rid);
}
}
obstacle_owner.free(p_object);
}
}

View File

@ -90,8 +90,23 @@ void NavAgent::_update_rvo_agent_properties() {
}
void NavAgent::set_map(NavMap *p_map) {
if (map == p_map) {
return;
}
if (map) {
map->remove_agent(this);
}
map = p_map;
agent_dirty = true;
if (map) {
map->add_agent(this);
if (avoidance_enabled) {
map->set_agent_as_controlled(this);
}
}
}
bool NavAgent::is_map_changed() {

View File

@ -36,8 +36,17 @@ void NavLink::set_map(NavMap *p_map) {
if (map == p_map) {
return;
}
if (map) {
map->remove_link(this);
}
map = p_map;
link_dirty = true;
if (map) {
map->add_link(this);
}
}
void NavLink::set_bidirectional(bool p_bidirectional) {

View File

@ -36,10 +36,18 @@ void NavRegion::set_map(NavMap *p_map) {
if (map == p_map) {
return;
}
if (map) {
map->remove_region(this);
}
map = p_map;
polygons_dirty = true;
if (!map) {
connections.clear();
connections.clear();
if (map) {
map->add_region(this);
}
}