2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* listener.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 14:47:28 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
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-05 15:44:50 +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-05 15:44:50 +00:00
|
|
|
} else {
|
2016-03-20 02:10:04 +00:00
|
|
|
clear_current();
|
|
|
|
}
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2016-03-20 02:10:04 +00:00
|
|
|
return false;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-05 15:44:50 +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-05 15:44:50 +00:00
|
|
|
} else {
|
2016-03-20 02:10:04 +00:00
|
|
|
r_ret = is_current();
|
|
|
|
}
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2016-03-20 02:10:04 +00:00
|
|
|
return false;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Listener::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
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-05 15:44:50 +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);
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!get_tree()->is_node_being_edited(this) && (current || first_listener)) {
|
2016-03-20 02:10:04 +00:00
|
|
|
make_current();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-03-20 02:10:04 +00:00
|
|
|
} 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-05 15:44:50 +00:00
|
|
|
current = true; //keep it true
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 15:44:50 +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-05 15:44:50 +00:00
|
|
|
current = true;
|
2016-03-20 02:10:04 +00:00
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!is_inside_tree()) {
|
2016-03-20 02:10:04 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
get_viewport()->_listener_set(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Listener::clear_current() {
|
2017-03-05 15:44:50 +00:00
|
|
|
current = false;
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!is_inside_tree()) {
|
2016-03-20 02:10:04 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-03-20 02:10:04 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (get_viewport()->get_listener() == this) {
|
2021-05-04 14:00:45 +00:00
|
|
|
get_viewport()->_listener_set(nullptr);
|
2016-03-20 02:10:04 +00:00
|
|
|
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-05 15:44:50 +00:00
|
|
|
return get_viewport()->get_listener() == this;
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2016-03-20 02:10:04 +00:00
|
|
|
return current;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Listener::_can_gizmo_scale() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RES Listener::_get_gizmo_geometry() const {
|
2017-06-07 21:18:55 +00:00
|
|
|
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
2016-03-20 02:10:04 +00:00
|
|
|
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Listener::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("make_current"), &Listener::make_current);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_current"), &Listener::clear_current);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_current"), &Listener::is_current);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_listener_transform"), &Listener::get_listener_transform);
|
2016-03-20 02:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Listener::Listener() {
|
2017-03-05 15:44:50 +00:00
|
|
|
current = false;
|
|
|
|
force_change = false;
|
2017-01-12 23:35:46 +00:00
|
|
|
set_notify_transform(true);
|
2016-03-20 02:10:04 +00:00
|
|
|
//active=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Listener::~Listener() {
|
|
|
|
}
|