2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visibility_notifier.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2022-01-13 08:45:09 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +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
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "visibility_notifier.h"
|
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/engine.h"
|
2017-08-05 22:48:29 +00:00
|
|
|
#include "scene/3d/camera.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/3d/physics_body.h"
|
|
|
|
#include "scene/animation/animation_player.h"
|
2021-06-05 18:14:36 +00:00
|
|
|
#include "scene/animation/animation_tree.h"
|
|
|
|
#include "scene/animation/animation_tree_player.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/scene_string_names.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityNotifier::_enter_camera(Camera *p_camera) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(cameras.has(p_camera));
|
|
|
|
cameras.insert(p_camera);
|
2021-02-04 10:43:08 +00:00
|
|
|
|
|
|
|
bool in_gameplay = _in_gameplay;
|
|
|
|
if (!Engine::get_singleton()->are_portals_active()) {
|
|
|
|
in_gameplay = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cameras.size() == 1) && in_gameplay) {
|
2017-01-12 03:51:08 +00:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->screen_entered);
|
2014-02-10 01:10:30 +00:00
|
|
|
_screen_enter();
|
|
|
|
}
|
2017-08-05 22:48:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->camera_entered, p_camera);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityNotifier::_exit_camera(Camera *p_camera) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!cameras.has(p_camera));
|
|
|
|
cameras.erase(p_camera);
|
|
|
|
|
2021-02-04 10:43:08 +00:00
|
|
|
bool in_gameplay = _in_gameplay;
|
|
|
|
if (!Engine::get_singleton()->are_portals_active()) {
|
|
|
|
in_gameplay = true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->camera_exited, p_camera);
|
2021-02-04 10:43:08 +00:00
|
|
|
if ((cameras.size() == 0) && (in_gameplay)) {
|
2017-01-12 03:51:08 +00:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->screen_exited);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_screen_exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-30 16:31:43 +00:00
|
|
|
void VisibilityNotifier::set_max_distance(real_t p_max_distance) {
|
|
|
|
if (p_max_distance > CMP_EPSILON) {
|
|
|
|
_max_distance = p_max_distance;
|
|
|
|
_max_distance_squared = _max_distance * _max_distance;
|
|
|
|
_max_distance_active = true;
|
|
|
|
|
|
|
|
// make sure world aabb centre is up to date
|
|
|
|
if (is_inside_world()) {
|
|
|
|
AABB world_aabb = get_global_transform().xform(aabb);
|
|
|
|
_world_aabb_center = world_aabb.get_center();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_max_distance = 0.0;
|
|
|
|
_max_distance_squared = 0.0;
|
|
|
|
_max_distance_active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
void VisibilityNotifier::set_aabb(const AABB &p_aabb) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (aabb == p_aabb) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
aabb = p_aabb;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (is_inside_world()) {
|
2022-05-30 16:31:43 +00:00
|
|
|
AABB world_aabb = get_global_transform().xform(aabb);
|
|
|
|
get_world()->_update_notifier(this, world_aabb);
|
|
|
|
_world_aabb_center = world_aabb.get_center();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_change_notify("aabb");
|
|
|
|
update_gizmo();
|
|
|
|
}
|
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB VisibilityNotifier::get_aabb() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return aabb;
|
|
|
|
}
|
|
|
|
|
2021-02-04 10:43:08 +00:00
|
|
|
void VisibilityNotifier::_refresh_portal_mode() {
|
|
|
|
// only create in the visual server if we are roaming.
|
|
|
|
// All other cases don't require a visual server rep.
|
|
|
|
// Global and ignore are the same (existing client side functionality only).
|
|
|
|
// Static and dynamic require only a one off creation at conversion.
|
|
|
|
if (get_portal_mode() == PORTAL_MODE_ROAMING) {
|
|
|
|
if (is_inside_world()) {
|
|
|
|
if (_cull_instance_rid == RID()) {
|
2021-11-09 12:00:07 +00:00
|
|
|
_cull_instance_rid = RID_PRIME(VisualServer::get_singleton()->ghost_create());
|
2021-02-04 10:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_inside_world() && get_world().is_valid() && get_world()->get_scenario().is_valid() && is_inside_tree()) {
|
|
|
|
AABB world_aabb = get_global_transform().xform(aabb);
|
|
|
|
VisualServer::get_singleton()->ghost_set_scenario(_cull_instance_rid, get_world()->get_scenario(), get_instance_id(), world_aabb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_cull_instance_rid != RID()) {
|
|
|
|
VisualServer::get_singleton()->free(_cull_instance_rid);
|
|
|
|
_cull_instance_rid = RID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (_cull_instance_rid != RID()) {
|
|
|
|
VisualServer::get_singleton()->free(_cull_instance_rid);
|
|
|
|
_cull_instance_rid = RID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void VisibilityNotifier::_notification(int p_what) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case NOTIFICATION_ENTER_WORLD: {
|
2021-01-27 19:38:40 +00:00
|
|
|
world = get_world();
|
|
|
|
ERR_FAIL_COND(!world.is_valid());
|
2021-02-04 10:43:08 +00:00
|
|
|
|
|
|
|
AABB world_aabb = get_global_transform().xform(aabb);
|
2022-12-13 14:58:53 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!Engine::get_singleton()->is_editor_hint()) {
|
|
|
|
world->_register_notifier(this, world_aabb);
|
|
|
|
}
|
|
|
|
#else
|
2021-02-04 10:43:08 +00:00
|
|
|
world->_register_notifier(this, world_aabb);
|
2022-12-13 14:58:53 +00:00
|
|
|
#endif
|
2022-05-30 16:31:43 +00:00
|
|
|
_world_aabb_center = world_aabb.get_center();
|
2021-02-04 10:43:08 +00:00
|
|
|
_refresh_portal_mode();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
2021-02-04 10:43:08 +00:00
|
|
|
AABB world_aabb = get_global_transform().xform(aabb);
|
2022-12-13 14:58:53 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!Engine::get_singleton()->is_editor_hint()) {
|
|
|
|
world->_update_notifier(this, world_aabb);
|
|
|
|
}
|
|
|
|
#else
|
2021-02-04 10:43:08 +00:00
|
|
|
world->_update_notifier(this, world_aabb);
|
2022-12-13 14:58:53 +00:00
|
|
|
#endif
|
2022-05-30 16:31:43 +00:00
|
|
|
if (_max_distance_active) {
|
|
|
|
_world_aabb_center = world_aabb.get_center();
|
|
|
|
}
|
2021-02-04 10:43:08 +00:00
|
|
|
|
|
|
|
if (_cull_instance_rid != RID()) {
|
|
|
|
VisualServer::get_singleton()->ghost_update(_cull_instance_rid, world_aabb);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_WORLD: {
|
2021-01-27 19:38:40 +00:00
|
|
|
ERR_FAIL_COND(!world.is_valid());
|
2022-12-13 14:58:53 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!Engine::get_singleton()->is_editor_hint()) {
|
|
|
|
world->_remove_notifier(this);
|
|
|
|
}
|
|
|
|
#else
|
2021-01-27 19:38:40 +00:00
|
|
|
world->_remove_notifier(this);
|
2022-12-13 14:58:53 +00:00
|
|
|
#endif
|
2021-02-04 10:43:08 +00:00
|
|
|
|
|
|
|
if (_cull_instance_rid != RID()) {
|
|
|
|
VisualServer::get_singleton()->ghost_set_scenario(_cull_instance_rid, RID(), get_instance_id(), AABB());
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_ENTER_GAMEPLAY: {
|
|
|
|
_in_gameplay = true;
|
|
|
|
if (cameras.size() && Engine::get_singleton()->are_portals_active()) {
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->screen_entered);
|
|
|
|
_screen_enter();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_GAMEPLAY: {
|
|
|
|
_in_gameplay = false;
|
|
|
|
if (cameras.size() && Engine::get_singleton()->are_portals_active()) {
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->screen_exited);
|
|
|
|
_screen_exit();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisibilityNotifier::is_on_screen() const {
|
2021-02-04 10:43:08 +00:00
|
|
|
if (!Engine::get_singleton()->are_portals_active()) {
|
|
|
|
return cameras.size() != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cameras.size() != 0) && _in_gameplay;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityNotifier::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibilityNotifier::set_aabb);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_aabb"), &VisibilityNotifier::get_aabb);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier::is_on_screen);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-05-30 16:31:43 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_max_distance", "distance"), &VisibilityNotifier::set_max_distance);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_max_distance"), &VisibilityNotifier::get_max_distance);
|
|
|
|
|
2017-11-17 02:09:00 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::AABB, "aabb"), "set_aabb", "get_aabb");
|
2022-05-30 16:31:43 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_max_distance", "get_max_distance");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("camera_entered", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera")));
|
|
|
|
ADD_SIGNAL(MethodInfo("camera_exited", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera")));
|
|
|
|
ADD_SIGNAL(MethodInfo("screen_entered"));
|
|
|
|
ADD_SIGNAL(MethodInfo("screen_exited"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VisibilityNotifier::VisibilityNotifier() {
|
2017-11-17 02:09:00 +00:00
|
|
|
aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
|
2017-01-12 23:35:46 +00:00
|
|
|
set_notify_transform(true);
|
2021-02-04 10:43:08 +00:00
|
|
|
_in_gameplay = false;
|
2022-05-30 16:31:43 +00:00
|
|
|
_max_distance_active = false;
|
|
|
|
_max_distance = 0.0;
|
|
|
|
_max_distance_squared = 0.0;
|
|
|
|
_max_distance_leadin_counter = 1; // this could later be exposed as a property if necessary
|
2021-02-04 10:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VisibilityNotifier::~VisibilityNotifier() {
|
|
|
|
if (_cull_instance_rid != RID()) {
|
|
|
|
VisualServer::get_singleton()->free(_cull_instance_rid);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////
|
|
|
|
|
|
|
|
void VisibilityEnabler::_screen_enter() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
|
|
|
|
_change_node_state(E->key(), true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
visible = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisibilityEnabler::_screen_exit() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
|
|
|
|
_change_node_state(E->key(), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
visible = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityEnabler::_find_nodes(Node *p_node) {
|
|
|
|
bool add = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant meta;
|
|
|
|
|
2020-03-17 15:44:48 +00:00
|
|
|
{
|
2017-08-24 20:58:51 +00:00
|
|
|
RigidBody *rb = Object::cast_to<RigidBody>(p_node);
|
2018-11-20 02:06:02 +00:00
|
|
|
if (rb && ((rb->get_mode() == RigidBody::MODE_CHARACTER || rb->get_mode() == RigidBody::MODE_RIGID))) {
|
2017-03-05 15:44:50 +00:00
|
|
|
add = true;
|
|
|
|
meta = rb->get_mode();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-05 18:14:36 +00:00
|
|
|
if (Object::cast_to<AnimationPlayer>(p_node) || Object::cast_to<AnimationTree>(p_node) || Object::cast_to<AnimationTreePlayer>(p_node)) {
|
|
|
|
add = true;
|
2021-02-04 10:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
AnimationTree *at = Object::cast_to<AnimationTree>(p_node);
|
|
|
|
if (at) {
|
|
|
|
add = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
AnimationTreePlayer *atp = Object::cast_to<AnimationTreePlayer>(p_node);
|
|
|
|
if (atp) {
|
|
|
|
add = true;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (add) {
|
2018-01-12 11:28:39 +00:00
|
|
|
p_node->connect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed", varray(p_node), CONNECT_ONESHOT);
|
2017-03-05 15:44:50 +00:00
|
|
|
nodes[p_node] = meta;
|
|
|
|
_change_node_state(p_node, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *c = p_node->get_child(i);
|
2021-05-05 10:44:11 +00:00
|
|
|
if (c->get_filename() != String()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue; //skip, instance
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_find_nodes(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityEnabler::_notification(int p_what) {
|
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2022-12-13 14:58:53 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-05-05 10:44:11 +00:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2022-12-13 14:58:53 +00:00
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Node *from = this;
|
|
|
|
//find where current scene starts
|
2021-05-05 10:44:11 +00:00
|
|
|
while (from->get_parent() && from->get_filename() == String()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
from = from->get_parent();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_find_nodes(from);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_EXIT_TREE) {
|
2022-12-13 14:58:53 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-05-05 10:44:11 +00:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2022-12-13 14:58:53 +00:00
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!visible) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_change_node_state(E->key(), true);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-01-12 11:28:39 +00:00
|
|
|
E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nodes.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityEnabler::_change_node_state(Node *p_node, bool p_enabled) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!nodes.has(p_node));
|
|
|
|
|
2020-03-17 15:44:48 +00:00
|
|
|
if (enabler[ENABLER_FREEZE_BODIES]) {
|
2017-08-24 20:58:51 +00:00
|
|
|
RigidBody *rb = Object::cast_to<RigidBody>(p_node);
|
2021-05-05 10:44:11 +00:00
|
|
|
if (rb) {
|
2016-07-07 22:32:28 +00:00
|
|
|
rb->set_sleeping(!p_enabled);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 15:44:48 +00:00
|
|
|
if (enabler[ENABLER_PAUSE_ANIMATIONS]) {
|
2017-08-24 20:58:51 +00:00
|
|
|
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (ap) {
|
|
|
|
ap->set_active(p_enabled);
|
2021-06-05 18:14:36 +00:00
|
|
|
} else {
|
|
|
|
AnimationTree *at = Object::cast_to<AnimationTree>(p_node);
|
|
|
|
if (at) {
|
|
|
|
at->set_active(p_enabled);
|
|
|
|
} else {
|
|
|
|
AnimationTreePlayer *atp = Object::cast_to<AnimationTreePlayer>(p_node);
|
|
|
|
if (atp) {
|
|
|
|
atp->set_active(p_enabled);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityEnabler::_node_removed(Node *p_node) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!visible) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_change_node_state(p_node, true);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
nodes.erase(p_node);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityEnabler::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler::set_enabler);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler::is_enabler_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("_node_removed"), &VisibilityEnabler::_node_removed);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animations"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "freeze_bodies"), "set_enabler", "is_enabler_enabled", ENABLER_FREEZE_BODIES);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_PAUSE_ANIMATIONS);
|
2017-10-21 18:58:02 +00:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_FREEZE_BODIES);
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_MAX);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisibilityEnabler::set_enabler(Enabler p_enabler, bool p_enable) {
|
|
|
|
ERR_FAIL_INDEX(p_enabler, ENABLER_MAX);
|
|
|
|
enabler[p_enabler] = p_enable;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool VisibilityEnabler::is_enabler_enabled(Enabler p_enabler) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
return enabler[p_enabler];
|
|
|
|
}
|
|
|
|
|
|
|
|
VisibilityEnabler::VisibilityEnabler() {
|
2021-05-05 10:44:11 +00:00
|
|
|
for (int i = 0; i < ENABLER_MAX; i++) {
|
2017-03-05 15:44:50 +00:00
|
|
|
enabler[i] = true;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
visible = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|