diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/scene_tree.cpp | 9 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 21 | ||||
-rw-r--r-- | scene/main/viewport.h | 7 |
3 files changed, 27 insertions, 10 deletions
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 8260d0dff5..bef7ecb462 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -858,15 +858,6 @@ void SceneTree::_notify_group_pause(const StringName &p_group, int p_notificatio } } -/* -void SceneMainLoop::_update_listener_2d() { - if (listener_2d.is_valid()) { - SpatialSound2DServer::get_singleton()->listener_set_space( listener_2d, world_2d->get_sound_space() ); - } -} - -*/ - void SceneTree::_call_input_pause(const StringName &p_group, CallInputType p_call_type, const Ref<InputEvent> &p_input, Viewport *p_viewport) { Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 8ec8c193fb..c5b0f47140 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -37,6 +37,7 @@ #include "core/templates/pair.h" #include "scene/2d/camera_2d.h" #include "scene/2d/collision_object_2d.h" +#include "scene/2d/listener_2d.cpp" #ifndef _3D_DISABLED #include "scene/3d/camera_3d.h" #include "scene/3d/collision_object_3d.h" @@ -831,7 +832,6 @@ void Viewport::set_as_audio_listener_2d(bool p_enable) { } audio_listener_2d = p_enable; - _update_listener_2d(); } @@ -839,6 +839,10 @@ bool Viewport::is_audio_listener_2d() const { return audio_listener_2d; } +Listener2D *Viewport::get_listener_2d() const { + return listener_2d; +} + void Viewport::enable_canvas_transform_override(bool p_enable) { if (override_canvas_transform == p_enable) { return; @@ -903,6 +907,21 @@ 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) { + return; + } else if (listener_2d) { + listener_2d->clear_current(); + } + listener_2d = p_listener; +} + +void Viewport::_listener_2d_remove(Listener2D *p_listener) { + if (listener_2d == p_listener) { + listener_2d = nullptr; + } +} + void Viewport::_canvas_layer_add(CanvasLayer *p_canvas_layer) { canvas_layers.insert(p_canvas_layer); } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index d9b21ce6a8..06efd27073 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -41,6 +41,7 @@ class Listener3D; class World3D; #endif // _3D_DISABLED +class Listener2D; class Camera2D; class CanvasItem; class CanvasLayer; @@ -201,6 +202,7 @@ private: Viewport *parent = nullptr; + Listener2D *listener_2d = nullptr; Camera2D *camera_2d = nullptr; Set<CanvasLayer *> canvas_layers; @@ -416,6 +418,10 @@ 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 Camera2D; void _camera_2d_set(Camera2D *p_camera_2d); @@ -457,6 +463,7 @@ protected: public: uint64_t get_processed_events_count() const { return event_count; } + Listener2D *get_listener_2d() const; Camera2D *get_camera_2d() const; void set_as_audio_listener_2d(bool p_enable); bool is_audio_listener_2d() const; |