Merge pull request #53012 from lawnjelly/portals_unload_reason

This commit is contained in:
Rémi Verschelde 2021-10-05 12:00:43 +02:00 committed by GitHub
commit 69437eb746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 29 additions and 21 deletions

View File

@ -147,7 +147,7 @@ void Portal::_changed() {
return;
}
rm->_rooms_changed();
rm->_rooms_changed("changed Portal " + get_name());
#endif
}

View File

@ -259,7 +259,7 @@ void Room::_changed(bool p_regenerate_bounds) {
if (p_regenerate_bounds) {
rm->_room_regenerate_bound(this);
}
rm->_rooms_changed();
rm->_rooms_changed("changed Room " + get_name());
#endif
}

View File

@ -80,7 +80,7 @@ void RoomGroup::_changed() {
return;
}
rm->_rooms_changed();
rm->_rooms_changed("changed RoomGroup " + get_name());
#endif
}

View File

@ -518,10 +518,10 @@ String RoomManager::get_pvs_filename() const {
return _pvs_filename;
}
void RoomManager::_rooms_changed() {
void RoomManager::_rooms_changed(String p_reason) {
_rooms.clear();
if (is_inside_world() && get_world().is_valid()) {
VisualServer::get_singleton()->rooms_unload(get_world()->get_scenario());
VisualServer::get_singleton()->rooms_unload(get_world()->get_scenario(), p_reason);
}
}
@ -543,7 +543,7 @@ void RoomManager::rooms_flip_portals() {
}
_flip_portals_recursive(_roomlist);
_rooms_changed();
_rooms_changed("flipped Portals");
}
void RoomManager::rooms_convert() {

View File

@ -109,7 +109,7 @@ public:
// for internal use in the editor..
// either we can clear the rooms and unload,
// or reconvert.
void _rooms_changed();
void _rooms_changed(String p_reason);
#ifdef TOOLS_ENABLED
// for a preview, we allow the editor to change the bound

View File

@ -165,7 +165,7 @@ void PortalRenderer::instance_moving_destroy(OcclusionHandle p_handle) {
// The alternative is to remove the reference, but this is not currently supported
// (it would mean rejigging rooms etc)
if (_occlusion_handle_is_in_room(p_handle)) {
_ensure_unloaded();
_ensure_unloaded("deleting STATIC or DYNAMIC");
return;
}
@ -224,7 +224,7 @@ PortalHandle PortalRenderer::portal_create() {
void PortalRenderer::portal_destroy(PortalHandle p_portal) {
ERR_FAIL_COND(!p_portal);
_ensure_unloaded();
_ensure_unloaded("deleting Portal");
// plus one based
p_portal--;
@ -378,7 +378,7 @@ void PortalRenderer::roomgroup_prepare(RoomGroupHandle p_roomgroup, ObjectID p_r
void PortalRenderer::roomgroup_destroy(RoomGroupHandle p_roomgroup) {
ERR_FAIL_COND(!p_roomgroup);
_ensure_unloaded();
_ensure_unloaded("deleting RoomGroup");
// plus one based
p_roomgroup--;
@ -618,7 +618,7 @@ RoomHandle PortalRenderer::room_create() {
void PortalRenderer::room_destroy(RoomHandle p_room) {
ERR_FAIL_COND(!p_room);
_ensure_unloaded();
_ensure_unloaded("deleting Room");
// plus one based
p_room--;
@ -1007,10 +1007,18 @@ void PortalRenderer::sprawl_roaming(uint32_t p_mover_pool_id, MovingBase &r_movi
}
// This gets called when you delete an instance the the room system depends on
void PortalRenderer::_ensure_unloaded() {
void PortalRenderer::_ensure_unloaded(String p_reason) {
if (_loaded) {
_loaded = false;
_log("Portal system unloaded.", 1);
String str;
if (p_reason != String()) {
str = "Portal system unloaded ( " + p_reason + " ).";
} else {
str = "Portal system unloaded.";
}
_log(str, 1);
// this should probably have some thread protection, but I doubt it matters
// as this will worst case give wrong result for a frame

View File

@ -162,7 +162,7 @@ public:
// for use in the editor only, to allow a cheap way of turning off portals
// if there has been a change, e.g. moving a room etc.
void rooms_unload() { _ensure_unloaded(); }
void rooms_unload(String p_reason) { _ensure_unloaded(p_reason); }
bool rooms_is_loaded() const { return _loaded; }
// debugging
@ -257,7 +257,7 @@ private:
void _moving_remove_from_rooms(uint32_t p_moving_pool_id);
void _rghost_remove_from_rooms(uint32_t p_pool_id);
void _occluder_remove_from_rooms(uint32_t p_pool_id);
void _ensure_unloaded();
void _ensure_unloaded(String p_reason = String());
void _rooms_add_portals_to_convex_hulls();
void _add_portal_to_convex_hull(LocalVector<Plane, int32_t> &p_planes, const Plane &p);

View File

@ -594,7 +594,7 @@ public:
BIND5(room_set_bound, RID, ObjectID, const Vector<Plane> &, const AABB &, const Vector<Vector3> &)
BIND2(room_prepare, RID, int32_t)
BIND1(rooms_and_portals_clear, RID)
BIND1(rooms_unload, RID)
BIND2(rooms_unload, RID, String)
BIND8(rooms_finalize, RID, bool, bool, bool, bool, String, bool, bool)
BIND4(rooms_override_camera, RID, bool, const Vector3 &, const Vector<Plane> *)
BIND2(rooms_set_active, RID, bool)

View File

@ -1316,10 +1316,10 @@ void VisualServerScene::room_set_bound(RID p_room, ObjectID p_room_object_id, co
room->scenario->_portal_renderer.room_set_bound(room->scenario_room_id, p_room_object_id, p_convex, p_aabb, p_verts);
}
void VisualServerScene::rooms_unload(RID p_scenario) {
void VisualServerScene::rooms_unload(RID p_scenario, String p_reason) {
Scenario *scenario = scenario_owner.getornull(p_scenario);
ERR_FAIL_COND(!scenario);
scenario->_portal_renderer.rooms_unload();
scenario->_portal_renderer.rooms_unload(p_reason);
}
void VisualServerScene::rooms_and_portals_clear(RID p_scenario) {

View File

@ -664,7 +664,7 @@ public:
virtual void room_set_bound(RID p_room, ObjectID p_room_object_id, const Vector<Plane> &p_convex, const AABB &p_aabb, const Vector<Vector3> &p_verts);
virtual void room_prepare(RID p_room, int32_t p_priority);
virtual void rooms_and_portals_clear(RID p_scenario);
virtual void rooms_unload(RID p_scenario);
virtual void rooms_unload(RID p_scenario, String p_reason);
virtual void rooms_finalize(RID p_scenario, bool p_generate_pvs, bool p_cull_using_pvs, bool p_use_secondary_pvs, bool p_use_signals, String p_pvs_filename, bool p_use_simple_pvs, bool p_log_pvs_generation);
virtual void rooms_override_camera(RID p_scenario, bool p_override, const Vector3 &p_point, const Vector<Plane> *p_convex);
virtual void rooms_set_active(RID p_scenario, bool p_active);

View File

@ -517,7 +517,7 @@ public:
FUNC5(room_set_bound, RID, ObjectID, const Vector<Plane> &, const AABB &, const Vector<Vector3> &)
FUNC2(room_prepare, RID, int32_t)
FUNC1(rooms_and_portals_clear, RID)
FUNC1(rooms_unload, RID)
FUNC2(rooms_unload, RID, String)
FUNC8(rooms_finalize, RID, bool, bool, bool, bool, String, bool, bool)
FUNC4(rooms_override_camera, RID, bool, const Vector3 &, const Vector<Plane> *)
FUNC2(rooms_set_active, RID, bool)

View File

@ -917,7 +917,7 @@ public:
virtual void room_set_bound(RID p_room, ObjectID p_room_object_id, const Vector<Plane> &p_convex, const AABB &p_aabb, const Vector<Vector3> &p_verts) = 0;
virtual void room_prepare(RID p_room, int32_t p_priority) = 0;
virtual void rooms_and_portals_clear(RID p_scenario) = 0;
virtual void rooms_unload(RID p_scenario) = 0;
virtual void rooms_unload(RID p_scenario, String p_reason) = 0;
virtual void rooms_finalize(RID p_scenario, bool p_generate_pvs, bool p_cull_using_pvs, bool p_use_secondary_pvs, bool p_use_signals, String p_pvs_filename, bool p_use_simple_pvs, bool p_log_pvs_generation) = 0;
virtual void rooms_override_camera(RID p_scenario, bool p_override, const Vector3 &p_point, const Vector<Plane> *p_convex) = 0;
virtual void rooms_set_active(RID p_scenario, bool p_active) = 0;