Skip to content

Commit

Permalink
Rename Listener2D/Listener3D to AudioListener2D/AudioListener3D
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubonnek committed Sep 16, 2021
1 parent 3581b89 commit f3a564f
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 183 deletions.
35 changes: 35 additions & 0 deletions doc/classes/AudioListener2D.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="AudioListener2D" inherits="Node2D" version="4.0">
<brief_description>
Overrides the location sounds are heard from.
</brief_description>
<description>
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.
</description>
<tutorials>
</tutorials>
<methods>
<method name="clear_current">
<return type="void" />
<description>
Disables the [AudioListener2D]. If it's not set as current, this method will have no effect.
</description>
</method>
<method name="is_current" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if this [AudioListener2D] is currently active.
</description>
</method>
<method name="make_current">
<return type="void" />
<description>
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].
</description>
</method>
</methods>
<constants>
</constants>
</class>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Listener3D" inherits="Node3D" version="4.0">
<class name="AudioListener3D" inherits="Node3D" version="4.0">
<brief_description>
Overrides the location sounds are heard from.
</brief_description>
Expand All @@ -25,7 +25,7 @@
<return type="bool" />
<description>
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.
[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.
</description>
</method>
<method name="make_current">
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/AudioStreamPlayer3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</brief_description>
<description>
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).
</description>
Expand Down
35 changes: 0 additions & 35 deletions doc/classes/Listener2D.xml

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
20 changes: 10 additions & 10 deletions editor/plugins/node_3d_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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<Listener3D>(p_spatial) != nullptr;
bool AudioListener3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<AudioListener3D>(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<Material> icon = get_material("listener_3d_icon", p_gizmo);
void AudioListener3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
const Ref<Material> icon = get_material("audio_listener_3d_icon", p_gizmo);
p_gizmo->add_unscaled_billboard(icon, 0.05);
}

Expand Down
6 changes: 3 additions & 3 deletions editor/plugins/node_3d_editor_gizmos.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ class AudioStreamPlayer3DGizmoPlugin : public EditorNode3DGizmoPlugin {
AudioStreamPlayer3DGizmoPlugin();
};

class Listener3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(Listener3DGizmoPlugin, EditorNode3DGizmoPlugin);
class AudioListener3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(AudioListener3DGizmoPlugin, EditorNode3DGizmoPlugin);

public:
bool has_gizmo(Node3D *p_spatial) override;
Expand All @@ -259,7 +259,7 @@ class Listener3DGizmoPlugin : public EditorNode3DGizmoPlugin {

void redraw(EditorNode3DGizmo *p_gizmo) override;

Listener3DGizmoPlugin();
AudioListener3DGizmoPlugin();
};

class Camera3DGizmoPlugin : public EditorNode3DGizmoPlugin {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6863,7 +6863,7 @@ void Node3DEditor::_register_all_gizmos() {
add_gizmo_plugin(Ref<Camera3DGizmoPlugin>(memnew(Camera3DGizmoPlugin)));
add_gizmo_plugin(Ref<Light3DGizmoPlugin>(memnew(Light3DGizmoPlugin)));
add_gizmo_plugin(Ref<AudioStreamPlayer3DGizmoPlugin>(memnew(AudioStreamPlayer3DGizmoPlugin)));
add_gizmo_plugin(Ref<Listener3DGizmoPlugin>(memnew(Listener3DGizmoPlugin)));
add_gizmo_plugin(Ref<AudioListener3DGizmoPlugin>(memnew(AudioListener3DGizmoPlugin)));
add_gizmo_plugin(Ref<MeshInstance3DGizmoPlugin>(memnew(MeshInstance3DGizmoPlugin)));
add_gizmo_plugin(Ref<OccluderInstance3DGizmoPlugin>(memnew(OccluderInstance3DGizmoPlugin)));
add_gizmo_plugin(Ref<SoftDynamicBody3DGizmoPlugin>(memnew(SoftDynamicBody3DGizmoPlugin)));
Expand Down
32 changes: 16 additions & 16 deletions scene/2d/listener_2d.cpp → scene/2d/audio_listener_2d.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************/
/* listener_2d.cpp */
/* audio_listener_2d.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#include "listener_2d.h"
#include "audio_listener_2d.h"

bool Listener2D::_set(const StringName &p_name, const Variant &p_value) {
bool AudioListener2D::_set(const StringName &p_name, const Variant &p_value) {
if (p_name == "current") {
if (p_value.operator bool()) {
make_current();
Expand All @@ -43,7 +43,7 @@ bool Listener2D::_set(const StringName &p_name, const Variant &p_value) {
return true;
}

bool Listener2D::_get(const StringName &p_name, Variant &r_ret) const {
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;
Expand All @@ -56,11 +56,11 @@ bool Listener2D::_get(const StringName &p_name, Variant &r_ret) const {
return true;
}

void Listener2D::_get_property_list(List<PropertyInfo> *p_list) const {
void AudioListener2D::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::BOOL, "current"));
}

void Listener2D::_notification(int p_what) {
void AudioListener2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (!get_tree()->is_node_being_edited(this) && current) {
Expand All @@ -80,33 +80,33 @@ void Listener2D::_notification(int p_what) {
}
}

void Listener2D::make_current() {
void AudioListener2D::make_current() {
current = true;
if (!is_inside_tree()) {
return;
}
get_viewport()->_listener_2d_set(this);
get_viewport()->_audio_listener_2d_set(this);
}

void Listener2D::clear_current() {
void AudioListener2D::clear_current() {
current = false;
if (!is_inside_tree()) {
return;
}
get_viewport()->_listener_2d_remove(this);
get_viewport()->_audio_listener_2d_remove(this);
}

bool Listener2D::is_current() const {
bool AudioListener2D::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
return get_viewport()->get_listener_2d() == this;
return get_viewport()->get_audio_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);
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);
}
6 changes: 3 additions & 3 deletions scene/2d/listener_2d.h → scene/2d/audio_listener_2d.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************/
/* listener_2d.h */
/* audio_listener_2d.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -34,8 +34,8 @@
#include "scene/2d/node_2d.h"
#include "scene/main/window.h"

class Listener2D : public Node2D {
GDCLASS(Listener2D, Node2D);
class AudioListener2D : public Node2D {
GDCLASS(AudioListener2D, Node2D);

private:
bool current = false;
Expand Down
4 changes: 2 additions & 2 deletions scene/2d/audio_stream_player_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit f3a564f

Please sign in to comment.