Portals - add autoplace priority setting to CullInstance

The default autoplace algorithm places instances in the highest priority Room. It became apparent that there are some situations in which users will want to override this and force placement in a Room from a particular RoomGroup, especially an "outside" RoomGroup.

This setting allows the user to specify a preference for Room priority. When set to 0, the setting is ignored and the highest priority Room is chosen.
This commit is contained in:
lawnjelly
2021-07-28 17:17:36 +01:00
parent 5d4352fad4
commit d0ba355520
4 changed files with 33 additions and 0 deletions

View File

@@ -1121,14 +1121,26 @@ bool RoomManager::_autoplace_object(VisualInstance *p_vi) {
int best_priority = -INT32_MAX;
Room *best_room = nullptr;
// if not set to zero (no preference) this can override a preference
// for a certain RoomGroup priority to ensure the instance gets placed in the correct
// RoomGroup (e.g. outside, for building exteriors)
int preferred_priority = p_vi->get_portal_autoplace_priority();
for (int n = 0; n < _rooms.size(); n++) {
Room *room = _rooms[n];
if (room->contains_point(centre)) {
// the standard routine autoplaces in the highest priority room
if (room->_room_priority > best_priority) {
best_priority = room->_room_priority;
best_room = room;
}
// if we override the preferred priority we always choose this
if (preferred_priority && (room->_room_priority == preferred_priority)) {
best_room = room;
break;
}
}
}