Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portals - fix autolinking to internal rooms #51392

Merged
merged 1 commit into from
Aug 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions scene/3d/room_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,9 @@ void RoomManager::_autolink_portals(Spatial *p_roomlist, LocalVector<Portal *> &

Vector3 test_pos = portal->_pt_center_world + (dist * portal->_plane.normal);

int best_priority = -1000;
int best_room = -1;

for (int r = 0; r < _rooms.size(); r++) {
Room *room = _rooms[r];
if (room->_room_ID == portal->_linkedroom_ID[0]) {
Expand All @@ -993,25 +996,37 @@ void RoomManager::_autolink_portals(Spatial *p_roomlist, LocalVector<Portal *> &
} // for through planes

if (!outside) {
// great, we found a linked room!
convert_log("\t\tAUTOLINK OK from " + source_room->get_name() + " to " + room->get_name(), 1);
portal->_linkedroom_ID[1] = r;
// we found a suitable room, but we want the highest priority in
// case there are internal rooms...
if (room->_room_priority > best_priority) {
best_priority = room->_room_priority;
best_room = r;
}
}

// add the portal to the portals list for the receiving room
room->_portals.push_back(n);
} // for through rooms

// send complete link to visual server so the portal will be active in the visual server room system
VisualServer::get_singleton()->portal_link(portal->_portal_rid, source_room->_room_rid, room->_room_rid, portal->_settings_two_way);
// found a suitable link room
if (best_room != -1) {
Room *room = _rooms[best_room];

// make the portal internal if necessary
// (this prevents the portal plane clipping the room bound)
portal->_internal = source_room->_room_priority > room->_room_priority;
// great, we found a linked room!
convert_log("\t\tAUTOLINK OK from " + source_room->get_name() + " to " + room->get_name(), 1);
portal->_linkedroom_ID[1] = best_room;

autolink_found = true;
break;
}
// add the portal to the portals list for the receiving room
room->_portals.push_back(n);

} // for through rooms
// send complete link to visual server so the portal will be active in the visual server room system
VisualServer::get_singleton()->portal_link(portal->_portal_rid, source_room->_room_rid, room->_room_rid, portal->_settings_two_way);

// make the portal internal if necessary
// (this prevents the portal plane clipping the room bound)
portal->_internal = source_room->_room_priority > room->_room_priority;

autolink_found = true;
break;
}

} // for attempt

Expand Down