2016-03-20 02:10:04 +00:00
|
|
|
#include "listener.h"
|
|
|
|
|
|
|
|
#include "scene/resources/mesh.h"
|
|
|
|
|
|
|
|
void Listener::_update_audio_listener_state() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Listener::_request_listener_update() {
|
|
|
|
|
|
|
|
_update_listener();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool Listener::_set(const StringName &p_name, const Variant &p_value) {
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
if (p_name == "current") {
|
|
|
|
if (p_value.operator bool()) {
|
|
|
|
make_current();
|
2017-03-18 23:36:26 +00:00
|
|
|
} else {
|
2016-03-20 02:10:04 +00:00
|
|
|
clear_current();
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else
|
2016-03-20 02:10:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool Listener::_get(const StringName &p_name, Variant &r_ret) const {
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
if (p_name == "current") {
|
|
|
|
if (is_inside_tree() && get_tree()->is_node_being_edited(this)) {
|
|
|
|
r_ret = current;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else {
|
2016-03-20 02:10:04 +00:00
|
|
|
r_ret = is_current();
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else
|
2016-03-20 02:10:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void Listener::_get_property_list(List<PropertyInfo> *p_list) const {
|
2016-03-20 02:10:04 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "current"));
|
2016-03-20 02:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Listener::_update_listener() {
|
|
|
|
|
|
|
|
if (is_inside_tree() && is_current()) {
|
|
|
|
get_viewport()->_listener_transform_changed_notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Listener::_notification(int p_what) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_what) {
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
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();
|
2017-03-18 23:36:26 +00:00
|
|
|
current = true; //keep it true
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
current = false;
|
2016-03-20 02:10:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get_viewport()->_listener_remove(this);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform Listener::get_listener_transform() const {
|
|
|
|
|
|
|
|
return get_global_transform().orthonormalized();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Listener::make_current() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
current = true;
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
if (!is_inside_tree())
|
|
|
|
return;
|
|
|
|
|
|
|
|
get_viewport()->_listener_set(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Listener::clear_current() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
current = false;
|
2016-03-20 02:10:04 +00:00
|
|
|
if (!is_inside_tree())
|
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (get_viewport()->get_listener() == this) {
|
2016-03-20 02:10:04 +00:00
|
|
|
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)) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return get_viewport()->get_listener() == this;
|
2016-03-20 02:10:04 +00:00
|
|
|
} 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() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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);
|
2016-03-20 02:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Listener::Listener() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
current = false;
|
|
|
|
force_change = false;
|
2016-03-20 02:10:04 +00:00
|
|
|
//active=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Listener::~Listener() {
|
|
|
|
}
|