summaryrefslogtreecommitdiffstats
path: root/scene/3d/listener.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/listener.cpp')
-rw-r--r--scene/3d/listener.cpp167
1 files changed, 167 insertions, 0 deletions
diff --git a/scene/3d/listener.cpp b/scene/3d/listener.cpp
new file mode 100644
index 0000000000..bf42a5c92e
--- /dev/null
+++ b/scene/3d/listener.cpp
@@ -0,0 +1,167 @@
+#include "listener.h"
+
+#include "scene/resources/mesh.h"
+
+void Listener::_update_audio_listener_state() {
+
+
+}
+
+void Listener::_request_listener_update() {
+
+ _update_listener();
+}
+
+bool Listener::_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 Listener::_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 Listener::_get_property_list( List<PropertyInfo> *p_list) const {
+
+ p_list->push_back( PropertyInfo( Variant::BOOL, "current" ) );
+}
+
+void Listener::_update_listener() {
+
+ if (is_inside_tree() && is_current()) {
+ get_viewport()->_listener_transform_changed_notify();
+
+ }
+}
+
+void Listener::_notification(int p_what) {
+
+ switch(p_what) {
+
+ case NOTIFICATION_ENTER_WORLD: {
+ bool first_listener = get_viewport()->_listener_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_remove(this);
+
+
+ } break;
+
+
+ }
+
+}
+
+
+Transform Listener::get_listener_transform() const {
+
+ return get_global_transform().orthonormalized();
+}
+
+void Listener::make_current() {
+
+ current=true;
+
+ if (!is_inside_tree())
+ return;
+
+ get_viewport()->_listener_set(this);
+}
+
+
+
+
+void Listener::clear_current() {
+
+ current=false;
+ if (!is_inside_tree())
+ return;
+
+ if (get_viewport()->get_listener()==this) {
+ get_viewport()->_listener_set(NULL);
+ get_viewport()->_listener_make_next_current(this);
+ }
+
+}
+
+bool Listener::is_current() const {
+
+ if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
+
+ return get_viewport()->get_listener()==this;
+ } else
+ return current;
+
+ return false;
+}
+
+bool Listener::_can_gizmo_scale() const {
+
+ return false;
+}
+
+RES Listener::_get_gizmo_geometry() const {
+ Ref<Mesh> mesh = memnew(Mesh);
+
+ return mesh;
+}
+
+void Listener::_bind_methods() {
+
+ ObjectTypeDB::bind_method( _MD("make_current"),&Listener::make_current );
+ ObjectTypeDB::bind_method( _MD("clear_current"),&Listener::clear_current );
+ ObjectTypeDB::bind_method( _MD("is_current"),&Listener::is_current );
+ ObjectTypeDB::bind_method( _MD("get_listener_transform"),&Listener::get_listener_transform );
+}
+
+Listener::Listener() {
+
+ current=false;
+ force_change=false;
+ //active=false;
+}
+
+
+Listener::~Listener() {
+
+}
+
+