From 83d931ad3cb2af295b2511fdfa29a00c9efb8c7a Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Mon, 6 Jun 2022 21:34:40 +0800 Subject: [PATCH] Fix `Viewport.own_world_3d` documentation Also fixed the naming of the setter's parameter and made an `if` block straightforward. --- doc/classes/Viewport.xml | 2 +- scene/main/viewport.cpp | 16 ++++++++-------- scene/main/viewport.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 148c6d70643..def99b8a7ab 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -227,7 +227,7 @@ The multisample anti-aliasing mode. A higher number results in smoother edges at the cost of significantly worse performance. A value of 2 or 4 is best unless targeting very high-end systems. See also bilinear scaling 3d [member scaling_3d_mode] for supersampling, which provides higher quality but is much more expensive. - If [code]true[/code], the viewport will use the [World3D] defined in [member world_3d]. + If [code]true[/code], the viewport will use a unique copy of the [World3D] defined in [member world_3d]. If [code]true[/code], the objects rendered by viewport become subjects of mouse picking process. diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 590c73de0bc..7c7809fd75b 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -3458,8 +3458,8 @@ void Viewport::_own_world_3d_changed() { _update_audio_listener_3d(); } -void Viewport::set_use_own_world_3d(bool p_world_3d) { - if (p_world_3d == own_world_3d.is_valid()) { +void Viewport::set_use_own_world_3d(bool p_use_own_world_3d) { + if (p_use_own_world_3d == own_world_3d.is_valid()) { return; } @@ -3467,18 +3467,18 @@ void Viewport::set_use_own_world_3d(bool p_world_3d) { _propagate_exit_world_3d(this); } - if (!p_world_3d) { - own_world_3d = Ref(); - if (world_3d.is_valid()) { - world_3d->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_3d_changed)); - } - } else { + if (p_use_own_world_3d) { if (world_3d.is_valid()) { own_world_3d = world_3d->duplicate(); world_3d->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_3d_changed)); } else { own_world_3d = Ref(memnew(World3D)); } + } else { + own_world_3d = Ref(); + if (world_3d.is_valid()) { + world_3d->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_3d_changed)); + } } if (is_inside_tree()) { diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 5bca5a2ddad..833b302e972 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -676,7 +676,7 @@ public: Ref get_world_3d() const; Ref find_world_3d() const; void _own_world_3d_changed(); - void set_use_own_world_3d(bool p_world_3d); + void set_use_own_world_3d(bool p_use_own_world_3d); bool is_using_own_world_3d() const; void _propagate_enter_world_3d(Node *p_node); void _propagate_exit_world_3d(Node *p_node);