From f3a564f9a5bf7f5a9c99253b7d9ac37fb65bff8e Mon Sep 17 00:00:00 2001 From: "Wilson E. Alvarez" Date: Thu, 16 Sep 2021 15:28:20 -0400 Subject: Rename Listener2D/Listener3D to AudioListener2D/AudioListener3D --- doc/classes/AudioListener2D.xml | 35 +++++++ doc/classes/AudioListener3D.xml | 40 ++++++++ doc/classes/AudioStreamPlayer3D.xml | 2 +- doc/classes/Listener2D.xml | 35 ------- doc/classes/Listener3D.xml | 40 -------- editor/icons/AudioListener2D.svg | 1 + editor/icons/AudioListener3D.svg | 1 + editor/icons/GizmoAudioListener3D.svg | 1 + editor/icons/GizmoListener3D.svg | 1 - editor/icons/Listener2D.svg | 1 - editor/icons/Listener3D.svg | 1 - editor/plugins/node_3d_editor_gizmos.cpp | 20 ++-- editor/plugins/node_3d_editor_gizmos.h | 6 +- editor/plugins/node_3d_editor_plugin.cpp | 2 +- scene/2d/audio_listener_2d.cpp | 112 ++++++++++++++++++++++ scene/2d/audio_listener_2d.h | 61 ++++++++++++ scene/2d/audio_stream_player_2d.cpp | 4 +- scene/2d/listener_2d.cpp | 112 ---------------------- scene/2d/listener_2d.h | 61 ------------ scene/3d/audio_listener_3d.cpp | 156 +++++++++++++++++++++++++++++++ scene/3d/audio_listener_3d.h | 73 +++++++++++++++ scene/3d/audio_stream_player_3d.cpp | 4 +- scene/3d/listener_3d.cpp | 156 ------------------------------- scene/3d/listener_3d.h | 73 --------------- scene/main/viewport.cpp | 100 ++++++++++---------- scene/main/viewport.h | 42 ++++----- scene/register_scene_types.cpp | 10 +- 27 files changed, 575 insertions(+), 575 deletions(-) create mode 100644 doc/classes/AudioListener2D.xml create mode 100644 doc/classes/AudioListener3D.xml delete mode 100644 doc/classes/Listener2D.xml delete mode 100644 doc/classes/Listener3D.xml create mode 100644 editor/icons/AudioListener2D.svg create mode 100644 editor/icons/AudioListener3D.svg create mode 100644 editor/icons/GizmoAudioListener3D.svg delete mode 100644 editor/icons/GizmoListener3D.svg delete mode 100644 editor/icons/Listener2D.svg delete mode 100644 editor/icons/Listener3D.svg create mode 100644 scene/2d/audio_listener_2d.cpp create mode 100644 scene/2d/audio_listener_2d.h delete mode 100644 scene/2d/listener_2d.cpp delete mode 100644 scene/2d/listener_2d.h create mode 100644 scene/3d/audio_listener_3d.cpp create mode 100644 scene/3d/audio_listener_3d.h delete mode 100644 scene/3d/listener_3d.cpp delete mode 100644 scene/3d/listener_3d.h diff --git a/doc/classes/AudioListener2D.xml b/doc/classes/AudioListener2D.xml new file mode 100644 index 0000000000..86dc870926 --- /dev/null +++ b/doc/classes/AudioListener2D.xml @@ -0,0 +1,35 @@ + + + + Overrides the location sounds are heard from. + + + Once added to the scene tree and enabled using [method make_current], this node will override the location sounds are heard from. Only one [AudioListener2D] can be current. Using [method make_current] will disable the previous [AudioListener2D]. + If there is no active [AudioListener2D] in the current [Viewport], center of the screen will be used as a hearing point for the audio. [AudioListener2D] needs to be inside [SceneTree] to function. + + + + + + + + Disables the [AudioListener2D]. If it's not set as current, this method will have no effect. + + + + + + Returns [code]true[/code] if this [AudioListener2D] is currently active. + + + + + + Makes the [AudioListener2D] active, setting it as the hearing point for the sounds. If there is already another active [AudioListener2D], it will be disabled. + This method will have no effect if the [AudioListener2D] is not added to [SceneTree]. + + + + + + diff --git a/doc/classes/AudioListener3D.xml b/doc/classes/AudioListener3D.xml new file mode 100644 index 0000000000..ed1f7fcc8f --- /dev/null +++ b/doc/classes/AudioListener3D.xml @@ -0,0 +1,40 @@ + + + + Overrides the location sounds are heard from. + + + Once added to the scene tree and enabled using [method make_current], this node will override the location sounds are heard from. This can be used to listen from a location different from the [Camera3D]. + + + + + + + + Disables the listener to use the current camera's listener instead. + + + + + + Returns the listener's global orthonormalized [Transform3D]. + + + + + + Returns [code]true[/code] if the listener was made current using [method make_current], [code]false[/code] otherwise. + [b]Note:[/b] There may be more than one AudioListener3D marked as "current" in the scene tree, but only the one that was made current last will be used. + + + + + + Enables the listener. This will override the current camera's listener. + + + + + + diff --git a/doc/classes/AudioStreamPlayer3D.xml b/doc/classes/AudioStreamPlayer3D.xml index fa2fa5a8e3..c848812011 100644 --- a/doc/classes/AudioStreamPlayer3D.xml +++ b/doc/classes/AudioStreamPlayer3D.xml @@ -5,7 +5,7 @@ Plays a sound effect with directed sound effects, dampens with distance if needed, generates effect of hearable position in space. For greater realism, a low-pass filter is automatically applied to distant sounds. This can be disabled by setting [member attenuation_filter_cutoff_hz] to [code]20500[/code]. - By default, audio is heard from the camera position. This can be changed by adding a [Listener3D] node to the scene and enabling it by calling [method Listener3D.make_current] on it. + By default, audio is heard from the camera position. This can be changed by adding a [AudioListener3D] node to the scene and enabling it by calling [method AudioListener3D.make_current] on it. See also [AudioStreamPlayer] to play a sound non-positionally. [b]Note:[/b] Hiding an [AudioStreamPlayer3D] node does not disable its audio output. To temporarily disable an [AudioStreamPlayer3D]'s audio output, set [member unit_db] to a very low value like [code]-100[/code] (which isn't audible to human hearing). diff --git a/doc/classes/Listener2D.xml b/doc/classes/Listener2D.xml deleted file mode 100644 index 27ee63d201..0000000000 --- a/doc/classes/Listener2D.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - Overrides the location sounds are heard from. - - - Once added to the scene tree and enabled using [method make_current], this node will override the location sounds are heard from. Only one [Listener2D] can be current. Using [method make_current] will disable the previous [Listener2D]. - If there is no active [Listener2D] in the current [Viewport], center of the screen will be used as a hearing point for the audio. [Listener2D] needs to be inside [SceneTree] to function. - - - - - - - - Disables the [Listener2D]. If it's not set as current, this method will have no effect. - - - - - - Returns [code]true[/code] if this [Listener2D] is currently active. - - - - - - Makes the [Listener2D] active, setting it as the hearing point for the sounds. If there is already another active [Listener2D], it will be disabled. - This method will have no effect if the [Listener2D] is not added to [SceneTree]. - - - - - - diff --git a/doc/classes/Listener3D.xml b/doc/classes/Listener3D.xml deleted file mode 100644 index 5e1b2ce7fc..0000000000 --- a/doc/classes/Listener3D.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - Overrides the location sounds are heard from. - - - Once added to the scene tree and enabled using [method make_current], this node will override the location sounds are heard from. This can be used to listen from a location different from the [Camera3D]. - - - - - - - - Disables the listener to use the current camera's listener instead. - - - - - - Returns the listener's global orthonormalized [Transform3D]. - - - - - - Returns [code]true[/code] if the listener was made current using [method make_current], [code]false[/code] otherwise. - [b]Note:[/b] There may be more than one Listener3D marked as "current" in the scene tree, but only the one that was made current last will be used. - - - - - - Enables the listener. This will override the current camera's listener. - - - - - - diff --git a/editor/icons/AudioListener2D.svg b/editor/icons/AudioListener2D.svg new file mode 100644 index 0000000000..db84dcfed7 --- /dev/null +++ b/editor/icons/AudioListener2D.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/AudioListener3D.svg b/editor/icons/AudioListener3D.svg new file mode 100644 index 0000000000..c068474d17 --- /dev/null +++ b/editor/icons/AudioListener3D.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/GizmoAudioListener3D.svg b/editor/icons/GizmoAudioListener3D.svg new file mode 100644 index 0000000000..9d3ddf8b85 --- /dev/null +++ b/editor/icons/GizmoAudioListener3D.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/GizmoListener3D.svg b/editor/icons/GizmoListener3D.svg deleted file mode 100644 index 9d3ddf8b85..0000000000 --- a/editor/icons/GizmoListener3D.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/icons/Listener2D.svg b/editor/icons/Listener2D.svg deleted file mode 100644 index db84dcfed7..0000000000 --- a/editor/icons/Listener2D.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/icons/Listener3D.svg b/editor/icons/Listener3D.svg deleted file mode 100644 index c068474d17..0000000000 --- a/editor/icons/Listener3D.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index c2ba987cd7..33c30db006 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -34,6 +34,7 @@ #include "core/math/geometry_2d.h" #include "core/math/geometry_3d.h" #include "editor/plugins/node_3d_editor_plugin.h" +#include "scene/3d/audio_listener_3d.h" #include "scene/3d/audio_stream_player_3d.h" #include "scene/3d/camera_3d.h" #include "scene/3d/collision_polygon_3d.h" @@ -45,7 +46,6 @@ #include "scene/3d/light_3d.h" #include "scene/3d/lightmap_gi.h" #include "scene/3d/lightmap_probe.h" -#include "scene/3d/listener_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/navigation_region_3d.h" #include "scene/3d/occluder_instance_3d.h" @@ -1619,24 +1619,24 @@ void AudioStreamPlayer3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { ////// -Listener3DGizmoPlugin::Listener3DGizmoPlugin() { - create_icon_material("listener_3d_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoListener3D", "EditorIcons")); +AudioListener3DGizmoPlugin::AudioListener3DGizmoPlugin() { + create_icon_material("audio_listener_3d_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoAudioListener3D", "EditorIcons")); } -bool Listener3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { - return Object::cast_to(p_spatial) != nullptr; +bool AudioListener3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { + return Object::cast_to(p_spatial) != nullptr; } -String Listener3DGizmoPlugin::get_gizmo_name() const { - return "Listener3D"; +String AudioListener3DGizmoPlugin::get_gizmo_name() const { + return "AudioListener3D"; } -int Listener3DGizmoPlugin::get_priority() const { +int AudioListener3DGizmoPlugin::get_priority() const { return -1; } -void Listener3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { - const Ref icon = get_material("listener_3d_icon", p_gizmo); +void AudioListener3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { + const Ref icon = get_material("audio_listener_3d_icon", p_gizmo); p_gizmo->add_unscaled_billboard(icon, 0.05); } diff --git a/editor/plugins/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h index 67f54562b1..24b4a23d4b 100644 --- a/editor/plugins/node_3d_editor_gizmos.h +++ b/editor/plugins/node_3d_editor_gizmos.h @@ -249,8 +249,8 @@ public: AudioStreamPlayer3DGizmoPlugin(); }; -class Listener3DGizmoPlugin : public EditorNode3DGizmoPlugin { - GDCLASS(Listener3DGizmoPlugin, EditorNode3DGizmoPlugin); +class AudioListener3DGizmoPlugin : public EditorNode3DGizmoPlugin { + GDCLASS(AudioListener3DGizmoPlugin, EditorNode3DGizmoPlugin); public: bool has_gizmo(Node3D *p_spatial) override; @@ -259,7 +259,7 @@ public: void redraw(EditorNode3DGizmo *p_gizmo) override; - Listener3DGizmoPlugin(); + AudioListener3DGizmoPlugin(); }; class Camera3DGizmoPlugin : public EditorNode3DGizmoPlugin { diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 1b725d5d3a..5263352502 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -6863,7 +6863,7 @@ void Node3DEditor::_register_all_gizmos() { add_gizmo_plugin(Ref(memnew(Camera3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(Light3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(AudioStreamPlayer3DGizmoPlugin))); - add_gizmo_plugin(Ref(memnew(Listener3DGizmoPlugin))); + add_gizmo_plugin(Ref(memnew(AudioListener3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(MeshInstance3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(OccluderInstance3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(SoftDynamicBody3DGizmoPlugin))); diff --git a/scene/2d/audio_listener_2d.cpp b/scene/2d/audio_listener_2d.cpp new file mode 100644 index 0000000000..f16e359a1d --- /dev/null +++ b/scene/2d/audio_listener_2d.cpp @@ -0,0 +1,112 @@ +/*************************************************************************/ +/* audio_listener_2d.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "audio_listener_2d.h" + +bool AudioListener2D::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "current") { + if (p_value.operator bool()) { + make_current(); + } else { + clear_current(); + } + } else { + return false; + } + return true; +} + +bool AudioListener2D::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "current") { + if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { + r_ret = current; + } else { + r_ret = is_current(); + } + } else { + return false; + } + return true; +} + +void AudioListener2D::_get_property_list(List *p_list) const { + p_list->push_back(PropertyInfo(Variant::BOOL, "current")); +} + +void AudioListener2D::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + if (!get_tree()->is_node_being_edited(this) && current) { + make_current(); + } + } break; + case NOTIFICATION_EXIT_TREE: { + if (!get_tree()->is_node_being_edited(this)) { + if (is_current()) { + clear_current(); + current = true; // Keep it true. + } else { + current = false; + } + } + } break; + } +} + +void AudioListener2D::make_current() { + current = true; + if (!is_inside_tree()) { + return; + } + get_viewport()->_audio_listener_2d_set(this); +} + +void AudioListener2D::clear_current() { + current = false; + if (!is_inside_tree()) { + return; + } + get_viewport()->_audio_listener_2d_remove(this); +} + +bool AudioListener2D::is_current() const { + if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { + return get_viewport()->get_audio_listener_2d() == this; + } else { + return current; + } + return false; +} + +void AudioListener2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("make_current"), &AudioListener2D::make_current); + ClassDB::bind_method(D_METHOD("clear_current"), &AudioListener2D::clear_current); + ClassDB::bind_method(D_METHOD("is_current"), &AudioListener2D::is_current); +} diff --git a/scene/2d/audio_listener_2d.h b/scene/2d/audio_listener_2d.h new file mode 100644 index 0000000000..875887acc6 --- /dev/null +++ b/scene/2d/audio_listener_2d.h @@ -0,0 +1,61 @@ +/*************************************************************************/ +/* audio_listener_2d.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef LISTENER_2D_H +#define LISTENER_2D_H + +#include "scene/2d/node_2d.h" +#include "scene/main/window.h" + +class AudioListener2D : public Node2D { + GDCLASS(AudioListener2D, Node2D); + +private: + bool current = false; + + friend class Viewport; + +protected: + void _update_listener(); + + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; + void _notification(int p_what); + + static void _bind_methods(); + +public: + void make_current(); + void clear_current(); + bool is_current() const; +}; + +#endif diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 8401909384..bddc342c1a 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -31,7 +31,7 @@ #include "audio_stream_player_2d.h" #include "scene/2d/area_2d.h" -#include "scene/2d/listener_2d.h" +#include "scene/2d/audio_listener_2d.h" #include "scene/main/window.h" void AudioStreamPlayer2D::_notification(int p_what) { @@ -156,7 +156,7 @@ void AudioStreamPlayer2D::_update_panning() { Vector2 relative_to_listener; //screen in global is used for attenuation - Listener2D *listener = vp->get_listener_2d(); + AudioListener2D *listener = vp->get_audio_listener_2d(); if (listener) { listener_in_global = listener->get_global_position(); relative_to_listener = global_pos - listener_in_global; diff --git a/scene/2d/listener_2d.cpp b/scene/2d/listener_2d.cpp deleted file mode 100644 index 444f05f2b1..0000000000 --- a/scene/2d/listener_2d.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/*************************************************************************/ -/* listener_2d.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "listener_2d.h" - -bool Listener2D::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "current") { - if (p_value.operator bool()) { - make_current(); - } else { - clear_current(); - } - } else { - return false; - } - return true; -} - -bool Listener2D::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "current") { - if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { - r_ret = current; - } else { - r_ret = is_current(); - } - } else { - return false; - } - return true; -} - -void Listener2D::_get_property_list(List *p_list) const { - p_list->push_back(PropertyInfo(Variant::BOOL, "current")); -} - -void Listener2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - if (!get_tree()->is_node_being_edited(this) && current) { - make_current(); - } - } break; - case NOTIFICATION_EXIT_TREE: { - if (!get_tree()->is_node_being_edited(this)) { - if (is_current()) { - clear_current(); - current = true; // Keep it true. - } else { - current = false; - } - } - } break; - } -} - -void Listener2D::make_current() { - current = true; - if (!is_inside_tree()) { - return; - } - get_viewport()->_listener_2d_set(this); -} - -void Listener2D::clear_current() { - current = false; - if (!is_inside_tree()) { - return; - } - get_viewport()->_listener_2d_remove(this); -} - -bool Listener2D::is_current() const { - if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { - return get_viewport()->get_listener_2d() == this; - } else { - return current; - } - return false; -} - -void Listener2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("make_current"), &Listener2D::make_current); - ClassDB::bind_method(D_METHOD("clear_current"), &Listener2D::clear_current); - ClassDB::bind_method(D_METHOD("is_current"), &Listener2D::is_current); -} diff --git a/scene/2d/listener_2d.h b/scene/2d/listener_2d.h deleted file mode 100644 index 0289a8087d..0000000000 --- a/scene/2d/listener_2d.h +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************/ -/* listener_2d.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef LISTENER_2D_H -#define LISTENER_2D_H - -#include "scene/2d/node_2d.h" -#include "scene/main/window.h" - -class Listener2D : public Node2D { - GDCLASS(Listener2D, Node2D); - -private: - bool current = false; - - friend class Viewport; - -protected: - void _update_listener(); - - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; - void _notification(int p_what); - - static void _bind_methods(); - -public: - void make_current(); - void clear_current(); - bool is_current() const; -}; - -#endif diff --git a/scene/3d/audio_listener_3d.cpp b/scene/3d/audio_listener_3d.cpp new file mode 100644 index 0000000000..b2319e40d7 --- /dev/null +++ b/scene/3d/audio_listener_3d.cpp @@ -0,0 +1,156 @@ +/*************************************************************************/ +/* audio_listener_3d.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "audio_listener_3d.h" + +#include "scene/main/viewport.h" + +void AudioListener3D::_update_audio_listener_state() { +} + +void AudioListener3D::_request_listener_update() { + _update_listener(); +} + +bool AudioListener3D::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "current") { + if (p_value.operator bool()) { + make_current(); + } else { + clear_current(); + } + } else { + return false; + } + + return true; +} + +bool AudioListener3D::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "current") { + if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { + r_ret = current; + } else { + r_ret = is_current(); + } + } else { + return false; + } + + return true; +} + +void AudioListener3D::_get_property_list(List *p_list) const { + p_list->push_back(PropertyInfo(Variant::BOOL, "current")); +} + +void AudioListener3D::_update_listener() { + if (is_inside_tree() && is_current()) { + get_viewport()->_listener_transform_3d_changed_notify(); + } +} + +void AudioListener3D::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_WORLD: { + bool first_listener = get_viewport()->_audio_listener_3d_add(this); + if (!get_tree()->is_node_being_edited(this) && (current || first_listener)) { + make_current(); + } + } break; + case NOTIFICATION_TRANSFORM_CHANGED: { + _request_listener_update(); + } break; + case NOTIFICATION_EXIT_WORLD: { + if (!get_tree()->is_node_being_edited(this)) { + if (is_current()) { + clear_current(); + current = true; //keep it true + + } else { + current = false; + } + } + + get_viewport()->_audio_listener_3d_remove(this); + + } break; + } +} + +Transform3D AudioListener3D::get_listener_transform() const { + return get_global_transform().orthonormalized(); +} + +void AudioListener3D::make_current() { + current = true; + + if (!is_inside_tree()) { + return; + } + + get_viewport()->_audio_listener_3d_set(this); +} + +void AudioListener3D::clear_current() { + current = false; + if (!is_inside_tree()) { + return; + } + + if (get_viewport()->get_audio_listener_3d() == this) { + get_viewport()->_audio_listener_3d_set(nullptr); + get_viewport()->_audio_listener_3d_make_next_current(this); + } +} + +bool AudioListener3D::is_current() const { + if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { + return get_viewport()->get_audio_listener_3d() == this; + } else { + return current; + } + + return false; +} + +void AudioListener3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("make_current"), &AudioListener3D::make_current); + ClassDB::bind_method(D_METHOD("clear_current"), &AudioListener3D::clear_current); + ClassDB::bind_method(D_METHOD("is_current"), &AudioListener3D::is_current); + ClassDB::bind_method(D_METHOD("get_listener_transform"), &AudioListener3D::get_listener_transform); +} + +AudioListener3D::AudioListener3D() { + set_notify_transform(true); +} + +AudioListener3D::~AudioListener3D() { +} diff --git a/scene/3d/audio_listener_3d.h b/scene/3d/audio_listener_3d.h new file mode 100644 index 0000000000..492cacb0e9 --- /dev/null +++ b/scene/3d/audio_listener_3d.h @@ -0,0 +1,73 @@ +/*************************************************************************/ +/* audio_listener_3d.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef LISTENER_3D_H +#define LISTENER_3D_H + +#include "scene/3d/node_3d.h" + +class AudioListener3D : public Node3D { + GDCLASS(AudioListener3D, Node3D); + +private: + bool force_change = false; + bool current = false; + + RID scenario_id; + + friend class Viewport; + void _update_audio_listener_state(); + +protected: + void _update_listener(); + virtual void _request_listener_update(); + + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; + void _notification(int p_what); + + static void _bind_methods(); + +public: + void make_current(); + void clear_current(); + bool is_current() const; + + virtual Transform3D get_listener_transform() const; + + void set_visible_layers(uint32_t p_layers); + uint32_t get_visible_layers() const; + + AudioListener3D(); + ~AudioListener3D(); +}; + +#endif diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 907c6cd03a..6c7cb6e61a 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -31,8 +31,8 @@ #include "audio_stream_player_3d.h" #include "scene/3d/area_3d.h" +#include "scene/3d/audio_listener_3d.h" #include "scene/3d/camera_3d.h" -#include "scene/3d/listener_3d.h" #include "scene/main/viewport.h" // Based on "A Novel Multichannel Panning Method for Standard and Arbitrary Loudspeaker Configurations" by Ramy Sadek and Chris Kyriakakis (2004) @@ -391,7 +391,7 @@ Vector AudioStreamPlayer3D::_update_panning() { bool listener_is_camera = true; Node3D *listener_node = camera; - Listener3D *listener = vp->get_listener_3d(); + AudioListener3D *listener = vp->get_audio_listener_3d(); if (listener) { listener_node = listener; listener_is_camera = false; diff --git a/scene/3d/listener_3d.cpp b/scene/3d/listener_3d.cpp deleted file mode 100644 index 8ae1f1940f..0000000000 --- a/scene/3d/listener_3d.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/*************************************************************************/ -/* listener_3d.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "listener_3d.h" - -#include "scene/main/viewport.h" - -void Listener3D::_update_audio_listener_state() { -} - -void Listener3D::_request_listener_update() { - _update_listener(); -} - -bool Listener3D::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "current") { - if (p_value.operator bool()) { - make_current(); - } else { - clear_current(); - } - } else { - return false; - } - - return true; -} - -bool Listener3D::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "current") { - if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { - r_ret = current; - } else { - r_ret = is_current(); - } - } else { - return false; - } - - return true; -} - -void Listener3D::_get_property_list(List *p_list) const { - p_list->push_back(PropertyInfo(Variant::BOOL, "current")); -} - -void Listener3D::_update_listener() { - if (is_inside_tree() && is_current()) { - get_viewport()->_listener_transform_3d_changed_notify(); - } -} - -void Listener3D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_WORLD: { - bool first_listener = get_viewport()->_listener_3d_add(this); - if (!get_tree()->is_node_being_edited(this) && (current || first_listener)) { - make_current(); - } - } break; - case NOTIFICATION_TRANSFORM_CHANGED: { - _request_listener_update(); - } break; - case NOTIFICATION_EXIT_WORLD: { - if (!get_tree()->is_node_being_edited(this)) { - if (is_current()) { - clear_current(); - current = true; //keep it true - - } else { - current = false; - } - } - - get_viewport()->_listener_3d_remove(this); - - } break; - } -} - -Transform3D Listener3D::get_listener_transform() const { - return get_global_transform().orthonormalized(); -} - -void Listener3D::make_current() { - current = true; - - if (!is_inside_tree()) { - return; - } - - get_viewport()->_listener_3d_set(this); -} - -void Listener3D::clear_current() { - current = false; - if (!is_inside_tree()) { - return; - } - - if (get_viewport()->get_listener_3d() == this) { - get_viewport()->_listener_3d_set(nullptr); - get_viewport()->_listener_3d_make_next_current(this); - } -} - -bool Listener3D::is_current() const { - if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { - return get_viewport()->get_listener_3d() == this; - } else { - return current; - } - - return false; -} - -void Listener3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("make_current"), &Listener3D::make_current); - ClassDB::bind_method(D_METHOD("clear_current"), &Listener3D::clear_current); - ClassDB::bind_method(D_METHOD("is_current"), &Listener3D::is_current); - ClassDB::bind_method(D_METHOD("get_listener_transform"), &Listener3D::get_listener_transform); -} - -Listener3D::Listener3D() { - set_notify_transform(true); -} - -Listener3D::~Listener3D() { -} diff --git a/scene/3d/listener_3d.h b/scene/3d/listener_3d.h deleted file mode 100644 index 08c08aa0cb..0000000000 --- a/scene/3d/listener_3d.h +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************/ -/* listener_3d.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef LISTENER_3D_H -#define LISTENER_3D_H - -#include "scene/3d/node_3d.h" - -class Listener3D : public Node3D { - GDCLASS(Listener3D, Node3D); - -private: - bool force_change = false; - bool current = false; - - RID scenario_id; - - friend class Viewport; - void _update_audio_listener_state(); - -protected: - void _update_listener(); - virtual void _request_listener_update(); - - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; - void _notification(int p_what); - - static void _bind_methods(); - -public: - void make_current(); - void clear_current(); - bool is_current() const; - - virtual Transform3D get_listener_transform() const; - - void set_visible_layers(uint32_t p_layers); - uint32_t get_visible_layers() const; - - Listener3D(); - ~Listener3D(); -}; - -#endif diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index fb86d37280..cef1b830df 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -35,13 +35,13 @@ #include "core/object/message_queue.h" #include "core/string/translation.h" #include "core/templates/pair.h" +#include "scene/2d/audio_listener_2d.h" #include "scene/2d/camera_2d.h" #include "scene/2d/collision_object_2d.h" -#include "scene/2d/listener_2d.h" #ifndef _3D_DISABLED +#include "scene/3d/audio_listener_3d.h" #include "scene/3d/camera_3d.h" #include "scene/3d/collision_object_3d.h" -#include "scene/3d/listener_3d.h" #include "scene/3d/world_environment.h" #endif // _3D_DISABLED #include "scene/gui/control.h" @@ -381,10 +381,10 @@ void Viewport::_notification(int p_what) { current_canvas = find_world_2d()->get_canvas(); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); - _update_listener_2d(); + _update_audio_listener_2d(); #ifndef _3D_DISABLED RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); - _update_listener_3d(); + _update_audio_listener_3d(); #endif // _3D_DISABLED add_to_group("_viewports"); @@ -408,9 +408,9 @@ void Viewport::_notification(int p_what) { } break; case NOTIFICATION_READY: { #ifndef _3D_DISABLED - if (listener_3d_set.size() && !listener_3d) { - Listener3D *first = nullptr; - for (Set::Element *E = listener_3d_set.front(); E; E = E->next()) { + if (audio_listener_3d_set.size() && !audio_listener_3d) { + AudioListener3D *first = nullptr; + for (Set::Element *E = audio_listener_3d_set.front(); E; E = E->next()) { if (first == nullptr || first->is_greater_than(E->get())) { first = E->get(); } @@ -822,27 +822,27 @@ Rect2 Viewport::get_visible_rect() const { return r; } -void Viewport::_update_listener_2d() { +void Viewport::_update_audio_listener_2d() { if (AudioServer::get_singleton()) { AudioServer::get_singleton()->notify_listener_changed(); } } void Viewport::set_as_audio_listener_2d(bool p_enable) { - if (p_enable == audio_listener_2d) { + if (p_enable == is_audio_listener_2d_enabled) { return; } - audio_listener_2d = p_enable; - _update_listener_2d(); + is_audio_listener_2d_enabled = p_enable; + _update_audio_listener_2d(); } bool Viewport::is_audio_listener_2d() const { - return audio_listener_2d; + return is_audio_listener_2d_enabled; } -Listener2D *Viewport::get_listener_2d() const { - return listener_2d; +AudioListener2D *Viewport::get_audio_listener_2d() const { + return audio_listener_2d; } void Viewport::enable_canvas_transform_override(bool p_enable) { @@ -909,18 +909,18 @@ void Viewport::_camera_2d_set(Camera2D *p_camera_2d) { camera_2d = p_camera_2d; } -void Viewport::_listener_2d_set(Listener2D *p_listener) { - if (listener_2d == p_listener) { +void Viewport::_audio_listener_2d_set(AudioListener2D *p_listener) { + if (audio_listener_2d == p_listener) { return; - } else if (listener_2d) { - listener_2d->clear_current(); + } else if (audio_listener_2d) { + audio_listener_2d->clear_current(); } - listener_2d = p_listener; + audio_listener_2d = p_listener; } -void Viewport::_listener_2d_remove(Listener2D *p_listener) { - if (listener_2d == p_listener) { - listener_2d = nullptr; +void Viewport::_audio_listener_2d_remove(AudioListener2D *p_listener) { + if (audio_listener_2d == p_listener) { + audio_listener_2d = nullptr; } } @@ -962,7 +962,7 @@ void Viewport::set_world_2d(const Ref &p_world_2d) { world_2d = Ref(memnew(World2D)); } - _update_listener_2d(); + _update_audio_listener_2d(); if (is_inside_tree()) { current_canvas = find_world_2d()->get_canvas(); @@ -3047,24 +3047,24 @@ Viewport::SDFScale Viewport::get_sdf_scale() const { } #ifndef _3D_DISABLED -Listener3D *Viewport::get_listener_3d() const { - return listener_3d; +AudioListener3D *Viewport::get_audio_listener_3d() const { + return audio_listener_3d; } void Viewport::set_as_audio_listener_3d(bool p_enable) { - if (p_enable == audio_listener_3d) { + if (p_enable == is_audio_listener_3d_enabled) { return; } - audio_listener_3d = p_enable; - _update_listener_3d(); + is_audio_listener_3d_enabled = p_enable; + _update_audio_listener_3d(); } bool Viewport::is_audio_listener_3d() const { - return audio_listener_3d; + return is_audio_listener_3d_enabled; } -void Viewport::_update_listener_3d() { +void Viewport::_update_audio_listener_3d() { if (AudioServer::get_singleton()) { AudioServer::get_singleton()->notify_listener_changed(); } @@ -3073,39 +3073,39 @@ void Viewport::_update_listener_3d() { void Viewport::_listener_transform_3d_changed_notify() { } -void Viewport::_listener_3d_set(Listener3D *p_listener) { - if (listener_3d == p_listener) { +void Viewport::_audio_listener_3d_set(AudioListener3D *p_listener) { + if (audio_listener_3d == p_listener) { return; } - listener_3d = p_listener; + audio_listener_3d = p_listener; - _update_listener_3d(); + _update_audio_listener_3d(); _listener_transform_3d_changed_notify(); } -bool Viewport::_listener_3d_add(Listener3D *p_listener) { - listener_3d_set.insert(p_listener); - return listener_3d_set.size() == 1; +bool Viewport::_audio_listener_3d_add(AudioListener3D *p_listener) { + audio_listener_3d_set.insert(p_listener); + return audio_listener_3d_set.size() == 1; } -void Viewport::_listener_3d_remove(Listener3D *p_listener) { - listener_3d_set.erase(p_listener); - if (listener_3d == p_listener) { - listener_3d = nullptr; +void Viewport::_audio_listener_3d_remove(AudioListener3D *p_listener) { + audio_listener_3d_set.erase(p_listener); + if (audio_listener_3d == p_listener) { + audio_listener_3d = nullptr; } } -void Viewport::_listener_3d_make_next_current(Listener3D *p_exclude) { - if (listener_3d_set.size() > 0) { - for (Set::Element *E = listener_3d_set.front(); E; E = E->next()) { +void Viewport::_audio_listener_3d_make_next_current(AudioListener3D *p_exclude) { + if (audio_listener_3d_set.size() > 0) { + for (Set::Element *E = audio_listener_3d_set.front(); E; E = E->next()) { if (p_exclude == E->get()) { continue; } if (!E->get()->is_inside_tree()) { continue; } - if (listener_3d != nullptr) { + if (audio_listener_3d != nullptr) { return; } @@ -3114,7 +3114,7 @@ void Viewport::_listener_3d_make_next_current(Listener3D *p_exclude) { } else { // Attempt to reset listener to the camera position. if (camera_3d != nullptr) { - _update_listener_3d(); + _update_audio_listener_3d(); _camera_3d_transform_changed_notify(); } } @@ -3168,7 +3168,7 @@ void Viewport::_camera_3d_set(Camera3D *p_camera) { camera_3d->notification(Camera3D::NOTIFICATION_BECAME_CURRENT); } - _update_listener_3d(); + _update_audio_listener_3d(); _camera_3d_transform_changed_notify(); } @@ -3330,7 +3330,7 @@ void Viewport::set_world_3d(const Ref &p_world_3d) { RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); } - _update_listener_3d(); + _update_audio_listener_3d(); } void Viewport::_own_world_3d_changed() { @@ -3351,7 +3351,7 @@ void Viewport::_own_world_3d_changed() { RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); } - _update_listener_3d(); + _update_audio_listener_3d(); } void Viewport::set_use_own_world_3d(bool p_world_3d) { @@ -3385,7 +3385,7 @@ void Viewport::set_use_own_world_3d(bool p_world_3d) { RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario()); } - _update_listener_3d(); + _update_audio_listener_3d(); } bool Viewport::is_using_own_world_3d() const { diff --git a/scene/main/viewport.h b/scene/main/viewport.h index bfb52c4b98..3732f9cfd1 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -37,11 +37,11 @@ #ifndef _3D_DISABLED class Camera3D; class CollisionObject3D; -class Listener3D; +class AudioListener3D; class World3D; #endif // _3D_DISABLED -class Listener2D; +class AudioListener2D; class Camera2D; class CanvasItem; class CanvasLayer; @@ -202,7 +202,7 @@ private: Viewport *parent = nullptr; - Listener2D *listener_2d = nullptr; + AudioListener2D *audio_listener_2d = nullptr; Camera2D *camera_2d = nullptr; Set canvas_layers; @@ -210,8 +210,8 @@ private: RID current_canvas; RID subwindow_canvas; - bool audio_listener_2d = false; - RID internal_listener_2d; + bool is_audio_listener_2d_enabled = false; + RID internal_audio_listener_2d; bool override_canvas_transform = false; @@ -274,7 +274,7 @@ private: StringName unhandled_input_group; StringName unhandled_key_input_group; - void _update_listener_2d(); + void _update_audio_listener_2d(); bool disable_3d = false; @@ -418,9 +418,9 @@ private: bool _gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check); - friend class Listener2D; - void _listener_2d_set(Listener2D *p_listener); - void _listener_2d_remove(Listener2D *p_listener); + friend class AudioListener2D; + void _audio_listener_2d_set(AudioListener2D *p_listener); + void _audio_listener_2d_remove(AudioListener2D *p_listener); friend class Camera2D; void _camera_2d_set(Camera2D *p_camera_2d); @@ -463,7 +463,7 @@ protected: public: uint64_t get_processed_events_count() const { return event_count; } - Listener2D *get_listener_2d() const; + AudioListener2D *get_audio_listener_2d() const; Camera2D *get_camera_2d() const; void set_as_audio_listener_2d(bool p_enable); bool is_audio_listener_2d() const; @@ -593,20 +593,20 @@ public: #ifndef _3D_DISABLED bool use_xr = false; Scale3D scale_3d = SCALE_3D_DISABLED; - friend class Listener3D; - Listener3D *listener_3d = nullptr; - Set listener_3d_set; - bool audio_listener_3d = false; - RID internal_listener_3d; - Listener3D *get_listener_3d() const; + friend class AudioListener3D; + AudioListener3D *audio_listener_3d = nullptr; + Set audio_listener_3d_set; + bool is_audio_listener_3d_enabled = false; + RID internal_audio_listener_3d; + AudioListener3D *get_audio_listener_3d() const; void set_as_audio_listener_3d(bool p_enable); bool is_audio_listener_3d() const; - void _update_listener_3d(); + void _update_audio_listener_3d(); void _listener_transform_3d_changed_notify(); - void _listener_3d_set(Listener3D *p_listener); - bool _listener_3d_add(Listener3D *p_listener); //true if first - void _listener_3d_remove(Listener3D *p_listener); - void _listener_3d_make_next_current(Listener3D *p_exclude); + void _audio_listener_3d_set(AudioListener3D *p_listener); + bool _audio_listener_3d_add(AudioListener3D *p_listener); //true if first + void _audio_listener_3d_remove(AudioListener3D *p_listener); + void _audio_listener_3d_make_next_current(AudioListener3D *p_exclude); void _collision_object_3d_input_event(CollisionObject3D *p_object, Camera3D *p_camera, const Ref &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index db4d3eea20..1e89b17044 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -36,6 +36,7 @@ #include "core/os/os.h" #include "scene/2d/animated_sprite_2d.h" #include "scene/2d/area_2d.h" +#include "scene/2d/audio_listener_2d.h" #include "scene/2d/audio_stream_player_2d.h" #include "scene/2d/back_buffer_copy.h" #include "scene/2d/camera_2d.h" @@ -49,7 +50,6 @@ #include "scene/2d/light_2d.h" #include "scene/2d/light_occluder_2d.h" #include "scene/2d/line_2d.h" -#include "scene/2d/listener_2d.h" #include "scene/2d/mesh_instance_2d.h" #include "scene/2d/multimesh_instance_2d.h" #include "scene/2d/navigation_agent_2d.h" @@ -205,6 +205,7 @@ #ifndef _3D_DISABLED #include "scene/3d/area_3d.h" +#include "scene/3d/audio_listener_3d.h" #include "scene/3d/audio_stream_player_3d.h" #include "scene/3d/bone_attachment_3d.h" #include "scene/3d/camera_3d.h" @@ -217,7 +218,6 @@ #include "scene/3d/light_3d.h" #include "scene/3d/lightmap_gi.h" #include "scene/3d/lightmap_probe.h" -#include "scene/3d/listener_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/multimesh_instance_3d.h" #include "scene/3d/navigation_agent_3d.h" @@ -445,7 +445,7 @@ void register_scene_types() { GDREGISTER_VIRTUAL_CLASS(GeometryInstance3D); GDREGISTER_CLASS(Camera3D); GDREGISTER_CLASS(ClippedCamera3D); - GDREGISTER_CLASS(Listener3D); + GDREGISTER_CLASS(AudioListener3D); GDREGISTER_CLASS(XRCamera3D); GDREGISTER_CLASS(XRController3D); GDREGISTER_CLASS(XRAnchor3D); @@ -672,7 +672,7 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init GDREGISTER_CLASS(Camera2D); - GDREGISTER_CLASS(Listener2D); + GDREGISTER_CLASS(AudioListener2D); GDREGISTER_VIRTUAL_CLASS(Joint2D); GDREGISTER_CLASS(PinJoint2D); GDREGISTER_CLASS(GrooveJoint2D); @@ -920,7 +920,7 @@ void register_scene_types() { ClassDB::add_compatibility_class("KinematicCollision", "KinematicCollision3D"); ClassDB::add_compatibility_class("Light", "Light3D"); ClassDB::add_compatibility_class("LineShape2D", "WorldBoundaryShape2D"); - ClassDB::add_compatibility_class("Listener", "Listener3D"); + ClassDB::add_compatibility_class("Listener", "AudioListener3D"); ClassDB::add_compatibility_class("MeshInstance", "MeshInstance3D"); ClassDB::add_compatibility_class("MultiMeshInstance", "MultiMeshInstance3D"); ClassDB::add_compatibility_class("NavigationAgent", "NavigationAgent3D"); -- cgit v1.2.3