2014-02-10 02:10:30 +01:00
/**************************************************************************/
2020-03-26 22:49:16 +01:00
/* area_3d.cpp */
2014-02-10 02:10:30 +01:00
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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-05 00:50:27 +01:00
2020-03-26 22:49:16 +01:00
# include "area_3d.h"
2020-02-21 23:26:13 +01:00
2014-02-10 02:10:30 +01:00
# include "scene/scene_string_names.h"
2017-07-15 06:23:10 +02:00
# include "servers/audio_server.h"
2021-11-05 02:12:00 +01:00
void Area3D : : set_gravity_space_override_mode ( SpaceOverride p_mode ) {
gravity_space_override = p_mode ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_GRAVITY_OVERRIDE_MODE , p_mode ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2021-11-05 02:12:00 +01:00
Area3D : : SpaceOverride Area3D : : get_gravity_space_override_mode ( ) const {
return gravity_space_override ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
void Area3D : : set_gravity_is_point ( bool p_enabled ) {
2014-02-10 02:10:30 +01:00
gravity_is_point = p_enabled ;
2020-03-27 19:21:27 +01:00
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_GRAVITY_IS_POINT , p_enabled ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
bool Area3D : : is_gravity_a_point ( ) const {
2014-02-10 02:10:30 +01:00
return gravity_is_point ;
}
2023-01-30 01:11:41 +01:00
void Area3D : : set_gravity_point_unit_distance ( real_t p_scale ) {
gravity_point_unit_distance = p_scale ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE , p_scale ) ;
2015-03-19 15:10:07 +01:00
}
2023-01-30 01:11:41 +01:00
real_t Area3D : : get_gravity_point_unit_distance ( ) const {
return gravity_point_unit_distance ;
2015-03-19 15:10:07 +01:00
}
2021-11-05 02:12:00 +01:00
void Area3D : : set_gravity_point_center ( const Vector3 & p_center ) {
gravity_vec = p_center ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_GRAVITY_VECTOR , p_center ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2021-11-05 02:12:00 +01:00
const Vector3 & Area3D : : get_gravity_point_center ( ) const {
return gravity_vec ;
}
void Area3D : : set_gravity_direction ( const Vector3 & p_direction ) {
gravity_vec = p_direction ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_GRAVITY_VECTOR , p_direction ) ;
}
const Vector3 & Area3D : : get_gravity_direction ( ) const {
2014-02-10 02:10:30 +01:00
return gravity_vec ;
}
2020-03-26 22:49:16 +01:00
void Area3D : : set_gravity ( real_t p_gravity ) {
2014-02-10 02:10:30 +01:00
gravity = p_gravity ;
2020-03-27 19:21:27 +01:00
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_GRAVITY , p_gravity ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
real_t Area3D : : get_gravity ( ) const {
2014-02-10 02:10:30 +01:00
return gravity ;
}
2020-05-14 14:29:06 +02:00
2021-11-05 02:12:00 +01:00
void Area3D : : set_linear_damp_space_override_mode ( SpaceOverride p_mode ) {
linear_damp_space_override = p_mode ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE , p_mode ) ;
}
Area3D : : SpaceOverride Area3D : : get_linear_damp_space_override_mode ( ) const {
return linear_damp_space_override ;
}
void Area3D : : set_angular_damp_space_override_mode ( SpaceOverride p_mode ) {
angular_damp_space_override = p_mode ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE , p_mode ) ;
}
Area3D : : SpaceOverride Area3D : : get_angular_damp_space_override_mode ( ) const {
return angular_damp_space_override ;
}
2020-03-26 22:49:16 +01:00
void Area3D : : set_linear_damp ( real_t p_linear_damp ) {
2015-08-30 23:57:17 +02:00
linear_damp = p_linear_damp ;
2020-03-27 19:21:27 +01:00
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_LINEAR_DAMP , p_linear_damp ) ;
2015-08-30 23:57:17 +02:00
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
real_t Area3D : : get_linear_damp ( ) const {
2015-08-30 23:57:17 +02:00
return linear_damp ;
}
2014-02-10 02:10:30 +01:00
2020-03-26 22:49:16 +01:00
void Area3D : : set_angular_damp ( real_t p_angular_damp ) {
2015-08-30 23:57:17 +02:00
angular_damp = p_angular_damp ;
2020-03-27 19:21:27 +01:00
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_ANGULAR_DAMP , p_angular_damp ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
real_t Area3D : : get_angular_damp ( ) const {
2015-08-30 23:57:17 +02:00
return angular_damp ;
2014-02-10 02:10:30 +01:00
}
2023-02-05 09:09:32 +01:00
void Area3D : : set_priority ( int p_priority ) {
2014-02-10 02:10:30 +01:00
priority = p_priority ;
2020-03-27 19:21:27 +01:00
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_PRIORITY , p_priority ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2023-02-05 09:09:32 +01:00
int Area3D : : get_priority ( ) const {
2014-02-10 02:10:30 +01:00
return priority ;
}
2021-07-20 06:23:32 +02:00
void Area3D : : set_wind_force_magnitude ( real_t p_wind_force_magnitude ) {
wind_force_magnitude = p_wind_force_magnitude ;
if ( is_inside_tree ( ) ) {
_initialize_wind ( ) ;
}
}
real_t Area3D : : get_wind_force_magnitude ( ) const {
return wind_force_magnitude ;
}
void Area3D : : set_wind_attenuation_factor ( real_t p_wind_force_attenuation_factor ) {
wind_attenuation_factor = p_wind_force_attenuation_factor ;
if ( is_inside_tree ( ) ) {
_initialize_wind ( ) ;
}
}
real_t Area3D : : get_wind_attenuation_factor ( ) const {
return wind_attenuation_factor ;
}
void Area3D : : set_wind_source_path ( const NodePath & p_wind_source_path ) {
wind_source_path = p_wind_source_path ;
if ( is_inside_tree ( ) ) {
_initialize_wind ( ) ;
}
}
const NodePath & Area3D : : get_wind_source_path ( ) const {
return wind_source_path ;
}
void Area3D : : _initialize_wind ( ) {
real_t temp_magnitude = 0.0 ;
Vector3 wind_direction ( 0. , 0. , 0. ) ;
Vector3 wind_source ( 0. , 0. , 0. ) ;
// Overwrite with area-specified info if available
if ( ! wind_source_path . is_empty ( ) ) {
2023-06-05 14:56:54 +02:00
Node * wind_source_node = get_node_or_null ( wind_source_path ) ;
ERR_FAIL_NULL_MSG ( wind_source_node , " Path to wind source is invalid: ' " + wind_source_path + " '. " ) ;
Node3D * wind_source_node3d = Object : : cast_to < Node3D > ( wind_source_node ) ;
ERR_FAIL_NULL_MSG ( wind_source_node3d , " Path to wind source does not point to a Node3D: ' " + wind_source_path + " '. " ) ;
Transform3D global_transform = wind_source_node3d - > get_transform ( ) ;
2022-05-03 14:50:35 +02:00
wind_direction = - global_transform . basis . get_column ( Vector3 : : AXIS_Z ) . normalized ( ) ;
2021-07-20 06:23:32 +02:00
wind_source = global_transform . origin ;
temp_magnitude = wind_force_magnitude ;
}
// Set force, source and direction in the physics server.
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_WIND_ATTENUATION_FACTOR , wind_attenuation_factor ) ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_WIND_SOURCE , wind_source ) ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_WIND_DIRECTION , wind_direction ) ;
PhysicsServer3D : : get_singleton ( ) - > area_set_param ( get_rid ( ) , PhysicsServer3D : : AREA_PARAM_WIND_FORCE_MAGNITUDE , temp_magnitude ) ;
}
2020-03-26 22:49:16 +01:00
void Area3D : : _body_enter_tree ( ObjectID p_id ) {
2014-02-10 02:10:30 +01:00
Object * obj = ObjectDB : : get_instance ( p_id ) ;
2017-08-24 22:58:51 +02:00
Node * node = Object : : cast_to < Node > ( obj ) ;
2023-06-06 14:59:54 +02:00
ERR_FAIL_NULL ( node ) ;
2014-02-10 02:10:30 +01:00
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , BodyState > : : Iterator E = body_map . find ( p_id ) ;
2014-02-10 02:10:30 +01:00
ERR_FAIL_COND ( ! E ) ;
2022-05-13 15:04:37 +02:00
ERR_FAIL_COND ( E - > value . in_tree ) ;
2014-02-10 02:10:30 +01:00
2022-05-13 15:04:37 +02:00
E - > value . in_tree = true ;
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_entered , node ) ;
2022-05-13 15:04:37 +02:00
for ( int i = 0 ; i < E - > value . shapes . size ( ) ; i + + ) {
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_shape_entered , E - > value . rid , node , E - > value . shapes [ i ] . body_shape , E - > value . shapes [ i ] . area_shape ) ;
2014-02-10 02:10:30 +01:00
}
}
2020-03-26 22:49:16 +01:00
void Area3D : : _body_exit_tree ( ObjectID p_id ) {
2014-02-10 02:10:30 +01:00
Object * obj = ObjectDB : : get_instance ( p_id ) ;
2017-08-24 22:58:51 +02:00
Node * node = Object : : cast_to < Node > ( obj ) ;
2023-06-06 14:59:54 +02:00
ERR_FAIL_NULL ( node ) ;
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , BodyState > : : Iterator E = body_map . find ( p_id ) ;
2014-02-10 02:10:30 +01:00
ERR_FAIL_COND ( ! E ) ;
2022-05-13 15:04:37 +02:00
ERR_FAIL_COND ( ! E - > value . in_tree ) ;
E - > value . in_tree = false ;
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_exited , node ) ;
2022-05-13 15:04:37 +02:00
for ( int i = 0 ; i < E - > value . shapes . size ( ) ; i + + ) {
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_shape_exited , E - > value . rid , node , E - > value . shapes [ i ] . body_shape , E - > value . shapes [ i ] . area_shape ) ;
2014-02-10 02:10:30 +01:00
}
}
2020-03-26 22:49:16 +01:00
void Area3D : : _body_inout ( int p_status , const RID & p_body , ObjectID p_instance , int p_body_shape , int p_area_shape ) {
2020-03-27 19:21:27 +01:00
bool body_in = p_status = = PhysicsServer3D : : AREA_BODY_ADDED ;
2014-02-10 02:10:30 +01:00
ObjectID objid = p_instance ;
Object * obj = ObjectDB : : get_instance ( objid ) ;
2017-08-24 22:58:51 +02:00
Node * node = Object : : cast_to < Node > ( obj ) ;
2014-02-10 02:10:30 +01:00
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , BodyState > : : Iterator E = body_map . find ( objid ) ;
2014-02-10 02:10:30 +01:00
2018-11-28 22:40:58 +01:00
if ( ! body_in & & ! E ) {
return ; //likely removed from the tree
}
2014-02-10 02:10:30 +01:00
2023-01-07 12:12:24 +01:00
lock_callback ( ) ;
2014-12-07 06:04:20 +01:00
locked = true ;
2014-02-10 02:10:30 +01:00
if ( body_in ) {
if ( ! E ) {
E = body_map . insert ( objid , BodyState ( ) ) ;
2022-05-13 15:04:37 +02:00
E - > value . rid = p_body ;
E - > value . rc = 0 ;
E - > value . in_tree = node & & node - > is_inside_tree ( ) ;
2014-02-10 02:10:30 +01:00
if ( node ) {
2022-07-28 22:56:41 +02:00
node - > connect ( SceneStringNames : : get_singleton ( ) - > tree_entered , callable_mp ( this , & Area3D : : _body_enter_tree ) . bind ( objid ) ) ;
node - > connect ( SceneStringNames : : get_singleton ( ) - > tree_exiting , callable_mp ( this , & Area3D : : _body_exit_tree ) . bind ( objid ) ) ;
2022-05-13 15:04:37 +02:00
if ( E - > value . in_tree ) {
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_entered , node ) ;
2014-02-10 02:10:30 +01:00
}
}
}
2022-05-13 15:04:37 +02:00
E - > value . rc + + ;
2020-05-14 16:41:43 +02:00
if ( node ) {
2022-05-13 15:04:37 +02:00
E - > value . shapes . insert ( ShapePair ( p_body_shape , p_area_shape ) ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
2022-05-13 15:04:37 +02:00
if ( E - > value . in_tree ) {
2020-10-12 17:25:32 +02:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_shape_entered , p_body , node , p_body_shape , p_area_shape ) ;
2014-02-10 02:10:30 +01:00
}
} else {
2022-05-13 15:04:37 +02:00
E - > value . rc - - ;
2014-02-10 02:10:30 +01:00
2020-05-14 16:41:43 +02:00
if ( node ) {
2022-05-13 15:04:37 +02:00
E - > value . shapes . erase ( ShapePair ( p_body_shape , p_area_shape ) ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
2022-05-13 15:04:37 +02:00
bool in_tree = E - > value . in_tree ;
if ( E - > value . rc = = 0 ) {
body_map . remove ( E ) ;
2014-02-10 02:10:30 +01:00
if ( node ) {
2020-03-26 22:49:16 +01:00
node - > disconnect ( SceneStringNames : : get_singleton ( ) - > tree_entered , callable_mp ( this , & Area3D : : _body_enter_tree ) ) ;
node - > disconnect ( SceneStringNames : : get_singleton ( ) - > tree_exiting , callable_mp ( this , & Area3D : : _body_exit_tree ) ) ;
2020-10-02 17:41:55 +02:00
if ( in_tree ) {
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_exited , obj ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
}
2020-10-02 17:41:55 +02:00
if ( node & & in_tree ) {
2020-10-12 17:25:32 +02:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_shape_exited , p_body , obj , p_body_shape , p_area_shape ) ;
2014-02-10 02:10:30 +01:00
}
}
2014-12-07 06:04:20 +01:00
locked = false ;
2023-01-07 12:12:24 +01:00
unlock_callback ( ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
void Area3D : : _clear_monitoring ( ) {
2019-08-08 22:11:48 +02:00
ERR_FAIL_COND_MSG ( locked , " This function can't be used during the in/out signal. " ) ;
2014-12-07 06:04:20 +01:00
2015-06-12 20:52:21 +02:00
{
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , BodyState > bmcopy = body_map ;
2015-06-12 20:52:21 +02:00
body_map . clear ( ) ;
//disconnect all monitored stuff
2014-02-10 02:10:30 +01:00
2021-08-09 22:13:42 +02:00
for ( const KeyValue < ObjectID , BodyState > & E : bmcopy ) {
Object * obj = ObjectDB : : get_instance ( E . key ) ;
2017-08-24 22:58:51 +02:00
Node * node = Object : : cast_to < Node > ( obj ) ;
2017-07-10 16:20:56 +02:00
2021-03-12 14:35:16 +01:00
if ( ! node ) { //node may have been deleted in previous frame or at other legitimate point
2017-07-10 16:20:56 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2017-07-10 16:20:56 +02:00
//ERR_CONTINUE(!node);
2020-08-23 12:13:02 +02:00
node - > disconnect ( SceneStringNames : : get_singleton ( ) - > tree_entered , callable_mp ( this , & Area3D : : _body_enter_tree ) ) ;
node - > disconnect ( SceneStringNames : : get_singleton ( ) - > tree_exiting , callable_mp ( this , & Area3D : : _body_exit_tree ) ) ;
2021-08-09 22:13:42 +02:00
if ( ! E . value . in_tree ) {
2015-06-12 20:52:21 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2015-06-12 20:52:21 +02:00
2021-08-09 22:13:42 +02:00
for ( int i = 0 ; i < E . value . shapes . size ( ) ; i + + ) {
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_shape_exited , E . value . rid , node , E . value . shapes [ i ] . body_shape , E . value . shapes [ i ] . area_shape ) ;
2015-06-12 20:52:21 +02:00
}
2014-02-10 02:10:30 +01:00
2018-09-01 12:05:51 +02:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > body_exited , node ) ;
2014-02-10 02:10:30 +01:00
}
2015-06-12 20:52:21 +02:00
}
{
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , AreaState > bmcopy = area_map ;
2015-06-12 20:52:21 +02:00
area_map . clear ( ) ;
//disconnect all monitored stuff
2021-08-09 22:13:42 +02:00
for ( const KeyValue < ObjectID , AreaState > & E : bmcopy ) {
Object * obj = ObjectDB : : get_instance ( E . key ) ;
2017-08-24 22:58:51 +02:00
Node * node = Object : : cast_to < Node > ( obj ) ;
2017-07-10 16:20:56 +02:00
2021-03-12 14:35:16 +01:00
if ( ! node ) { //node may have been deleted in previous frame or at other legitimate point
2017-07-10 16:20:56 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2017-07-10 16:20:56 +02:00
//ERR_CONTINUE(!node);
2020-08-23 12:13:02 +02:00
node - > disconnect ( SceneStringNames : : get_singleton ( ) - > tree_entered , callable_mp ( this , & Area3D : : _area_enter_tree ) ) ;
node - > disconnect ( SceneStringNames : : get_singleton ( ) - > tree_exiting , callable_mp ( this , & Area3D : : _area_exit_tree ) ) ;
2021-08-09 22:13:42 +02:00
if ( ! E . value . in_tree ) {
2015-06-12 20:52:21 +02:00
continue ;
2020-05-14 16:41:43 +02:00
}
2015-06-12 20:52:21 +02:00
2021-08-09 22:13:42 +02:00
for ( int i = 0 ; i < E . value . shapes . size ( ) ; i + + ) {
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_shape_exited , E . value . rid , node , E . value . shapes [ i ] . area_shape , E . value . shapes [ i ] . self_shape ) ;
2015-06-12 20:52:21 +02:00
}
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_exited , obj ) ;
2015-06-12 20:52:21 +02:00
}
2014-02-10 02:10:30 +01:00
}
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
void Area3D : : _notification ( int p_what ) {
2022-02-15 18:06:48 +01:00
switch ( p_what ) {
case NOTIFICATION_EXIT_TREE : {
_clear_monitoring ( ) ;
} break ;
case NOTIFICATION_ENTER_TREE : {
_initialize_wind ( ) ;
} break ;
2014-02-10 02:10:30 +01:00
}
}
2020-03-26 22:49:16 +01:00
void Area3D : : set_monitoring ( bool p_enable ) {
2019-08-08 22:11:48 +02:00
ERR_FAIL_COND_MSG ( locked , " Function blocked during in/out signal. Use set_deferred( \" monitoring \" , true/false). " ) ;
2014-12-07 06:04:20 +01:00
2020-05-14 16:41:43 +02:00
if ( p_enable = = monitoring ) {
2014-02-10 02:10:30 +01:00
return ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
monitoring = p_enable ;
if ( monitoring ) {
2021-10-31 22:45:58 +01:00
PhysicsServer3D : : get_singleton ( ) - > area_set_monitor_callback ( get_rid ( ) , callable_mp ( this , & Area3D : : _body_inout ) ) ;
PhysicsServer3D : : get_singleton ( ) - > area_set_area_monitor_callback ( get_rid ( ) , callable_mp ( this , & Area3D : : _area_inout ) ) ;
2014-02-10 02:10:30 +01:00
} else {
2021-10-31 22:45:58 +01:00
PhysicsServer3D : : get_singleton ( ) - > area_set_monitor_callback ( get_rid ( ) , Callable ( ) ) ;
PhysicsServer3D : : get_singleton ( ) - > area_set_area_monitor_callback ( get_rid ( ) , Callable ( ) ) ;
2014-02-10 02:10:30 +01:00
_clear_monitoring ( ) ;
2015-06-12 20:52:21 +02:00
}
}
2020-03-26 22:49:16 +01:00
void Area3D : : _area_enter_tree ( ObjectID p_id ) {
2015-06-12 20:52:21 +02:00
Object * obj = ObjectDB : : get_instance ( p_id ) ;
2017-08-24 22:58:51 +02:00
Node * node = Object : : cast_to < Node > ( obj ) ;
2023-06-06 14:59:54 +02:00
ERR_FAIL_NULL ( node ) ;
2015-06-12 20:52:21 +02:00
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , AreaState > : : Iterator E = area_map . find ( p_id ) ;
2015-06-12 20:52:21 +02:00
ERR_FAIL_COND ( ! E ) ;
2022-05-13 15:04:37 +02:00
ERR_FAIL_COND ( E - > value . in_tree ) ;
2015-06-12 20:52:21 +02:00
2022-05-13 15:04:37 +02:00
E - > value . in_tree = true ;
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_entered , node ) ;
2022-05-13 15:04:37 +02:00
for ( int i = 0 ; i < E - > value . shapes . size ( ) ; i + + ) {
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_shape_entered , E - > value . rid , node , E - > value . shapes [ i ] . area_shape , E - > value . shapes [ i ] . self_shape ) ;
2015-06-12 20:52:21 +02:00
}
}
2020-03-26 22:49:16 +01:00
void Area3D : : _area_exit_tree ( ObjectID p_id ) {
2015-06-12 20:52:21 +02:00
Object * obj = ObjectDB : : get_instance ( p_id ) ;
2017-08-24 22:58:51 +02:00
Node * node = Object : : cast_to < Node > ( obj ) ;
2023-06-06 14:59:54 +02:00
ERR_FAIL_NULL ( node ) ;
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , AreaState > : : Iterator E = area_map . find ( p_id ) ;
2015-06-12 20:52:21 +02:00
ERR_FAIL_COND ( ! E ) ;
2022-05-13 15:04:37 +02:00
ERR_FAIL_COND ( ! E - > value . in_tree ) ;
E - > value . in_tree = false ;
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_exited , node ) ;
2022-05-13 15:04:37 +02:00
for ( int i = 0 ; i < E - > value . shapes . size ( ) ; i + + ) {
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_shape_exited , E - > value . rid , node , E - > value . shapes [ i ] . area_shape , E - > value . shapes [ i ] . self_shape ) ;
2014-02-10 02:10:30 +01:00
}
2015-06-12 20:52:21 +02:00
}
2020-03-26 22:49:16 +01:00
void Area3D : : _area_inout ( int p_status , const RID & p_area , ObjectID p_instance , int p_area_shape , int p_self_shape ) {
2020-03-27 19:21:27 +01:00
bool area_in = p_status = = PhysicsServer3D : : AREA_BODY_ADDED ;
2015-06-12 20:52:21 +02:00
ObjectID objid = p_instance ;
Object * obj = ObjectDB : : get_instance ( objid ) ;
2017-08-24 22:58:51 +02:00
Node * node = Object : : cast_to < Node > ( obj ) ;
2015-06-12 20:52:21 +02:00
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , AreaState > : : Iterator E = area_map . find ( objid ) ;
2015-06-12 20:52:21 +02:00
2019-04-15 04:31:51 +02:00
if ( ! area_in & & ! E ) {
return ; //likely removed from the tree
}
2015-06-12 20:52:21 +02:00
2023-01-07 12:12:24 +01:00
lock_callback ( ) ;
2015-06-12 20:52:21 +02:00
locked = true ;
if ( area_in ) {
if ( ! E ) {
E = area_map . insert ( objid , AreaState ( ) ) ;
2022-05-13 15:04:37 +02:00
E - > value . rid = p_area ;
E - > value . rc = 0 ;
E - > value . in_tree = node & & node - > is_inside_tree ( ) ;
2015-06-12 20:52:21 +02:00
if ( node ) {
2022-07-28 22:56:41 +02:00
node - > connect ( SceneStringNames : : get_singleton ( ) - > tree_entered , callable_mp ( this , & Area3D : : _area_enter_tree ) . bind ( objid ) ) ;
node - > connect ( SceneStringNames : : get_singleton ( ) - > tree_exiting , callable_mp ( this , & Area3D : : _area_exit_tree ) . bind ( objid ) ) ;
2022-05-13 15:04:37 +02:00
if ( E - > value . in_tree ) {
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_entered , node ) ;
2015-06-12 20:52:21 +02:00
}
}
}
2022-05-13 15:04:37 +02:00
E - > value . rc + + ;
2020-05-14 16:41:43 +02:00
if ( node ) {
2022-05-13 15:04:37 +02:00
E - > value . shapes . insert ( AreaShapePair ( p_area_shape , p_self_shape ) ) ;
2020-05-14 16:41:43 +02:00
}
2015-06-12 20:52:21 +02:00
2022-05-13 15:04:37 +02:00
if ( ! node | | E - > value . in_tree ) {
2020-10-12 17:25:32 +02:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_shape_entered , p_area , node , p_area_shape , p_self_shape ) ;
2015-06-12 20:52:21 +02:00
}
} else {
2022-05-13 15:04:37 +02:00
E - > value . rc - - ;
2015-06-12 20:52:21 +02:00
2020-05-14 16:41:43 +02:00
if ( node ) {
2022-05-13 15:04:37 +02:00
E - > value . shapes . erase ( AreaShapePair ( p_area_shape , p_self_shape ) ) ;
2020-05-14 16:41:43 +02:00
}
2015-06-12 20:52:21 +02:00
2022-05-13 15:04:37 +02:00
bool in_tree = E - > value . in_tree ;
if ( E - > value . rc = = 0 ) {
area_map . remove ( E ) ;
2015-06-12 20:52:21 +02:00
if ( node ) {
2020-03-26 22:49:16 +01:00
node - > disconnect ( SceneStringNames : : get_singleton ( ) - > tree_entered , callable_mp ( this , & Area3D : : _area_enter_tree ) ) ;
node - > disconnect ( SceneStringNames : : get_singleton ( ) - > tree_exiting , callable_mp ( this , & Area3D : : _area_exit_tree ) ) ;
2020-10-02 17:41:55 +02:00
if ( in_tree ) {
2017-01-12 04:51:08 +01:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_exited , obj ) ;
2015-06-12 20:52:21 +02:00
}
}
}
2020-10-02 17:41:55 +02:00
if ( ! node | | in_tree ) {
2020-10-12 17:25:32 +02:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > area_shape_exited , p_area , obj , p_area_shape , p_self_shape ) ;
2015-06-12 20:52:21 +02:00
}
}
locked = false ;
2023-01-07 12:12:24 +01:00
unlock_callback ( ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
bool Area3D : : is_monitoring ( ) const {
2014-02-10 02:10:30 +01:00
return monitoring ;
}
2020-04-21 17:16:45 +02:00
TypedArray < Node3D > Area3D : : get_overlapping_bodies ( ) const {
2022-09-01 21:02:43 +02:00
TypedArray < Node3D > ret ;
ERR_FAIL_COND_V_MSG ( ! monitoring , ret , " Can't find overlapping bodies when monitoring is off. " ) ;
2014-11-13 04:53:12 +01:00
ret . resize ( body_map . size ( ) ) ;
int idx = 0 ;
2021-08-09 22:13:42 +02:00
for ( const KeyValue < ObjectID , BodyState > & E : body_map ) {
Object * obj = ObjectDB : : get_instance ( E . key ) ;
2022-09-01 21:02:43 +02:00
if ( obj ) {
ret [ idx ] = obj ;
idx + + ;
2014-11-13 04:53:12 +01:00
}
}
2022-09-01 21:02:43 +02:00
ret . resize ( idx ) ;
2014-11-13 04:53:12 +01:00
return ret ;
}
2014-09-15 16:33:30 +02:00
2022-09-09 23:26:14 +02:00
bool Area3D : : has_overlapping_bodies ( ) const {
ERR_FAIL_COND_V_MSG ( ! monitoring , false , " Can't find overlapping bodies when monitoring is off. " ) ;
return ! body_map . is_empty ( ) ;
}
2020-03-26 22:49:16 +01:00
void Area3D : : set_monitorable ( bool p_enable ) {
2020-03-27 19:21:27 +01:00
ERR_FAIL_COND_MSG ( locked | | ( is_inside_tree ( ) & & PhysicsServer3D : : get_singleton ( ) - > is_flushing_queries ( ) ) , " Function blocked during in/out signal. Use set_deferred( \" monitorable \" , true/false). " ) ;
2015-06-12 20:52:21 +02:00
2020-05-14 16:41:43 +02:00
if ( p_enable = = monitorable ) {
2015-06-12 20:52:21 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2015-06-12 20:52:21 +02:00
monitorable = p_enable ;
2020-03-27 19:21:27 +01:00
PhysicsServer3D : : get_singleton ( ) - > area_set_monitorable ( get_rid ( ) , monitorable ) ;
2015-06-12 20:52:21 +02:00
}
2020-03-26 22:49:16 +01:00
bool Area3D : : is_monitorable ( ) const {
2015-06-12 20:52:21 +02:00
return monitorable ;
}
2020-04-21 17:16:45 +02:00
TypedArray < Area3D > Area3D : : get_overlapping_areas ( ) const {
2022-09-01 21:02:43 +02:00
TypedArray < Area3D > ret ;
ERR_FAIL_COND_V_MSG ( ! monitoring , ret , " Can't find overlapping areas when monitoring is off. " ) ;
2015-06-12 20:52:21 +02:00
ret . resize ( area_map . size ( ) ) ;
int idx = 0 ;
2021-08-09 22:13:42 +02:00
for ( const KeyValue < ObjectID , AreaState > & E : area_map ) {
Object * obj = ObjectDB : : get_instance ( E . key ) ;
2022-09-01 21:02:43 +02:00
if ( obj ) {
ret [ idx ] = obj ;
idx + + ;
2015-06-12 20:52:21 +02:00
}
}
2022-09-01 21:02:43 +02:00
ret . resize ( idx ) ;
2015-06-12 20:52:21 +02:00
return ret ;
}
2022-09-09 23:26:14 +02:00
bool Area3D : : has_overlapping_areas ( ) const {
ERR_FAIL_COND_V_MSG ( ! monitoring , false , " Can't find overlapping areas when monitoring is off. " ) ;
return ! area_map . is_empty ( ) ;
}
2020-03-26 22:49:16 +01:00
bool Area3D : : overlaps_area ( Node * p_area ) const {
2015-06-12 20:52:21 +02:00
ERR_FAIL_NULL_V ( p_area , false ) ;
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , AreaState > : : ConstIterator E = area_map . find ( p_area - > get_instance_id ( ) ) ;
2020-05-14 16:41:43 +02:00
if ( ! E ) {
2015-06-12 20:52:21 +02:00
return false ;
2020-05-14 16:41:43 +02:00
}
2022-05-13 15:04:37 +02:00
return E - > value . in_tree ;
2015-06-12 20:52:21 +02:00
}
2020-03-26 22:49:16 +01:00
bool Area3D : : overlaps_body ( Node * p_body ) const {
2015-06-12 20:52:21 +02:00
ERR_FAIL_NULL_V ( p_body , false ) ;
2022-05-13 15:04:37 +02:00
HashMap < ObjectID , BodyState > : : ConstIterator E = body_map . find ( p_body - > get_instance_id ( ) ) ;
2020-05-14 16:41:43 +02:00
if ( ! E ) {
2015-06-12 20:52:21 +02:00
return false ;
2020-05-14 16:41:43 +02:00
}
2022-05-13 15:04:37 +02:00
return E - > value . in_tree ;
2015-06-12 20:52:21 +02:00
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
void Area3D : : set_audio_bus_override ( bool p_override ) {
2017-07-15 06:23:10 +02:00
audio_bus_override = p_override ;
}
2020-03-26 22:49:16 +01:00
bool Area3D : : is_overriding_audio_bus ( ) const {
2017-07-15 06:23:10 +02:00
return audio_bus_override ;
}
2020-12-10 09:31:14 +01:00
void Area3D : : set_audio_bus_name ( const StringName & p_audio_bus ) {
2017-07-15 06:23:10 +02:00
audio_bus = p_audio_bus ;
}
2020-05-14 14:29:06 +02:00
2020-12-10 09:31:14 +01:00
StringName Area3D : : get_audio_bus_name ( ) const {
2017-07-15 06:23:10 +02:00
for ( int i = 0 ; i < AudioServer : : get_singleton ( ) - > get_bus_count ( ) ; i + + ) {
if ( AudioServer : : get_singleton ( ) - > get_bus_name ( i ) = = audio_bus ) {
return audio_bus ;
}
}
2023-08-07 17:33:07 +02:00
return SceneStringNames : : get_singleton ( ) - > Master ;
2017-07-15 06:23:10 +02:00
}
2020-03-26 22:49:16 +01:00
void Area3D : : set_use_reverb_bus ( bool p_enable ) {
2017-07-15 06:23:10 +02:00
use_reverb_bus = p_enable ;
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
bool Area3D : : is_using_reverb_bus ( ) const {
2017-07-15 06:23:10 +02:00
return use_reverb_bus ;
}
2022-09-21 18:56:03 +02:00
void Area3D : : set_reverb_bus_name ( const StringName & p_audio_bus ) {
2017-07-15 06:23:10 +02:00
reverb_bus = p_audio_bus ;
}
2020-05-14 14:29:06 +02:00
2022-09-21 18:56:03 +02:00
StringName Area3D : : get_reverb_bus_name ( ) const {
2017-07-15 06:23:10 +02:00
for ( int i = 0 ; i < AudioServer : : get_singleton ( ) - > get_bus_count ( ) ; i + + ) {
if ( AudioServer : : get_singleton ( ) - > get_bus_name ( i ) = = reverb_bus ) {
return reverb_bus ;
}
}
2023-08-07 17:33:07 +02:00
return SceneStringNames : : get_singleton ( ) - > Master ;
2017-07-15 06:23:10 +02:00
}
2020-03-26 22:49:16 +01:00
void Area3D : : set_reverb_amount ( float p_amount ) {
2017-07-15 06:23:10 +02:00
reverb_amount = p_amount ;
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
float Area3D : : get_reverb_amount ( ) const {
2017-07-15 06:23:10 +02:00
return reverb_amount ;
}
2020-03-26 22:49:16 +01:00
void Area3D : : set_reverb_uniformity ( float p_uniformity ) {
2017-07-15 06:23:10 +02:00
reverb_uniformity = p_uniformity ;
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
float Area3D : : get_reverb_uniformity ( ) const {
2017-07-15 06:23:10 +02:00
return reverb_uniformity ;
}
2022-08-12 22:57:11 +02:00
void Area3D : : _validate_property ( PropertyInfo & p_property ) const {
if ( p_property . name = = " audio_bus_name " | | p_property . name = = " reverb_bus_name " ) {
2017-07-15 06:23:10 +02:00
String options ;
for ( int i = 0 ; i < AudioServer : : get_singleton ( ) - > get_bus_count ( ) ; i + + ) {
2020-05-14 16:41:43 +02:00
if ( i > 0 ) {
2017-07-15 06:23:10 +02:00
options + = " , " ;
2020-05-14 16:41:43 +02:00
}
2017-07-15 06:23:10 +02:00
String name = AudioServer : : get_singleton ( ) - > get_bus_name ( i ) ;
options + = name ;
}
2022-08-12 22:57:11 +02:00
p_property . hint_string = options ;
} else if ( p_property . name . begins_with ( " gravity " ) & & p_property . name ! = " gravity_space_override " ) {
2021-11-05 02:12:00 +01:00
if ( gravity_space_override = = SPACE_OVERRIDE_DISABLED ) {
2022-08-12 22:57:11 +02:00
p_property . usage = PROPERTY_USAGE_NO_EDITOR ;
2021-11-05 02:12:00 +01:00
} else {
if ( gravity_is_point ) {
2022-08-12 22:57:11 +02:00
if ( p_property . name = = " gravity_direction " ) {
p_property . usage = PROPERTY_USAGE_NO_EDITOR ;
2021-11-05 02:12:00 +01:00
}
} else {
2022-08-12 22:57:11 +02:00
if ( p_property . name . begins_with ( " gravity_point_ " ) ) {
p_property . usage = PROPERTY_USAGE_NO_EDITOR ;
2021-11-05 02:12:00 +01:00
}
}
}
2022-08-12 22:57:11 +02:00
} else if ( p_property . name . begins_with ( " linear_damp " ) & & p_property . name ! = " linear_damp_space_override " ) {
2021-11-05 02:12:00 +01:00
if ( linear_damp_space_override = = SPACE_OVERRIDE_DISABLED ) {
2022-08-12 22:57:11 +02:00
p_property . usage = PROPERTY_USAGE_NO_EDITOR ;
2021-11-05 02:12:00 +01:00
}
2022-08-12 22:57:11 +02:00
} else if ( p_property . name . begins_with ( " angular_damp " ) & & p_property . name ! = " angular_damp_space_override " ) {
2021-11-05 02:12:00 +01:00
if ( angular_damp_space_override = = SPACE_OVERRIDE_DISABLED ) {
2022-08-12 22:57:11 +02:00
p_property . usage = PROPERTY_USAGE_NO_EDITOR ;
2021-11-05 02:12:00 +01:00
}
2017-07-15 06:23:10 +02:00
}
}
2020-03-26 22:49:16 +01:00
void Area3D : : _bind_methods ( ) {
2021-11-05 02:12:00 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_gravity_space_override_mode " , " space_override_mode " ) , & Area3D : : set_gravity_space_override_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_gravity_space_override_mode " ) , & Area3D : : get_gravity_space_override_mode ) ;
2014-02-10 02:10:30 +01:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_gravity_is_point " , " enable " ) , & Area3D : : set_gravity_is_point ) ;
ClassDB : : bind_method ( D_METHOD ( " is_gravity_a_point " ) , & Area3D : : is_gravity_a_point ) ;
2014-02-10 02:10:30 +01:00
2023-01-30 01:11:41 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_gravity_point_unit_distance " , " distance_scale " ) , & Area3D : : set_gravity_point_unit_distance ) ;
ClassDB : : bind_method ( D_METHOD ( " get_gravity_point_unit_distance " ) , & Area3D : : get_gravity_point_unit_distance ) ;
2015-03-19 15:10:07 +01:00
2021-11-05 02:12:00 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_gravity_point_center " , " center " ) , & Area3D : : set_gravity_point_center ) ;
ClassDB : : bind_method ( D_METHOD ( " get_gravity_point_center " ) , & Area3D : : get_gravity_point_center ) ;
ClassDB : : bind_method ( D_METHOD ( " set_gravity_direction " , " direction " ) , & Area3D : : set_gravity_direction ) ;
ClassDB : : bind_method ( D_METHOD ( " get_gravity_direction " ) , & Area3D : : get_gravity_direction ) ;
2014-02-10 02:10:30 +01:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_gravity " , " gravity " ) , & Area3D : : set_gravity ) ;
ClassDB : : bind_method ( D_METHOD ( " get_gravity " ) , & Area3D : : get_gravity ) ;
2014-02-10 02:10:30 +01:00
2021-11-05 02:12:00 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_linear_damp_space_override_mode " , " space_override_mode " ) , & Area3D : : set_linear_damp_space_override_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_linear_damp_space_override_mode " ) , & Area3D : : get_linear_damp_space_override_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " set_angular_damp_space_override_mode " , " space_override_mode " ) , & Area3D : : set_angular_damp_space_override_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_angular_damp_space_override_mode " ) , & Area3D : : get_angular_damp_space_override_mode ) ;
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_angular_damp " , " angular_damp " ) , & Area3D : : set_angular_damp ) ;
ClassDB : : bind_method ( D_METHOD ( " get_angular_damp " ) , & Area3D : : get_angular_damp ) ;
2015-08-30 23:57:17 +02:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_linear_damp " , " linear_damp " ) , & Area3D : : set_linear_damp ) ;
ClassDB : : bind_method ( D_METHOD ( " get_linear_damp " ) , & Area3D : : get_linear_damp ) ;
2014-02-10 02:10:30 +01:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_priority " , " priority " ) , & Area3D : : set_priority ) ;
ClassDB : : bind_method ( D_METHOD ( " get_priority " ) , & Area3D : : get_priority ) ;
2014-02-10 02:10:30 +01:00
2021-07-20 06:23:32 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_wind_force_magnitude " , " wind_force_magnitude " ) , & Area3D : : set_wind_force_magnitude ) ;
ClassDB : : bind_method ( D_METHOD ( " get_wind_force_magnitude " ) , & Area3D : : get_wind_force_magnitude ) ;
ClassDB : : bind_method ( D_METHOD ( " set_wind_attenuation_factor " , " wind_attenuation_factor " ) , & Area3D : : set_wind_attenuation_factor ) ;
ClassDB : : bind_method ( D_METHOD ( " get_wind_attenuation_factor " ) , & Area3D : : get_wind_attenuation_factor ) ;
ClassDB : : bind_method ( D_METHOD ( " set_wind_source_path " , " wind_source_path " ) , & Area3D : : set_wind_source_path ) ;
ClassDB : : bind_method ( D_METHOD ( " get_wind_source_path " ) , & Area3D : : get_wind_source_path ) ;
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_monitorable " , " enable " ) , & Area3D : : set_monitorable ) ;
ClassDB : : bind_method ( D_METHOD ( " is_monitorable " ) , & Area3D : : is_monitorable ) ;
2015-06-12 20:52:21 +02:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_monitoring " , " enable " ) , & Area3D : : set_monitoring ) ;
ClassDB : : bind_method ( D_METHOD ( " is_monitoring " ) , & Area3D : : is_monitoring ) ;
2014-09-15 16:33:30 +02:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_overlapping_bodies " ) , & Area3D : : get_overlapping_bodies ) ;
ClassDB : : bind_method ( D_METHOD ( " get_overlapping_areas " ) , & Area3D : : get_overlapping_areas ) ;
2014-02-10 02:10:30 +01:00
2022-09-09 23:26:14 +02:00
ClassDB : : bind_method ( D_METHOD ( " has_overlapping_bodies " ) , & Area3D : : has_overlapping_bodies ) ;
ClassDB : : bind_method ( D_METHOD ( " has_overlapping_areas " ) , & Area3D : : has_overlapping_areas ) ;
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " overlaps_body " , " body " ) , & Area3D : : overlaps_body ) ;
ClassDB : : bind_method ( D_METHOD ( " overlaps_area " , " area " ) , & Area3D : : overlaps_area ) ;
2015-06-12 20:52:21 +02:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_audio_bus_override " , " enable " ) , & Area3D : : set_audio_bus_override ) ;
ClassDB : : bind_method ( D_METHOD ( " is_overriding_audio_bus " ) , & Area3D : : is_overriding_audio_bus ) ;
2017-07-15 06:23:10 +02:00
2020-12-10 09:31:14 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_audio_bus_name " , " name " ) , & Area3D : : set_audio_bus_name ) ;
ClassDB : : bind_method ( D_METHOD ( " get_audio_bus_name " ) , & Area3D : : get_audio_bus_name ) ;
2017-07-15 06:23:10 +02:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_use_reverb_bus " , " enable " ) , & Area3D : : set_use_reverb_bus ) ;
ClassDB : : bind_method ( D_METHOD ( " is_using_reverb_bus " ) , & Area3D : : is_using_reverb_bus ) ;
2017-07-15 06:23:10 +02:00
2022-09-21 18:56:03 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_reverb_bus_name " , " name " ) , & Area3D : : set_reverb_bus_name ) ;
ClassDB : : bind_method ( D_METHOD ( " get_reverb_bus_name " ) , & Area3D : : get_reverb_bus_name ) ;
2017-07-15 06:23:10 +02:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_reverb_amount " , " amount " ) , & Area3D : : set_reverb_amount ) ;
ClassDB : : bind_method ( D_METHOD ( " get_reverb_amount " ) , & Area3D : : get_reverb_amount ) ;
2017-07-15 06:23:10 +02:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_reverb_uniformity " , " amount " ) , & Area3D : : set_reverb_uniformity ) ;
ClassDB : : bind_method ( D_METHOD ( " get_reverb_uniformity " ) , & Area3D : : get_reverb_uniformity ) ;
2017-07-15 06:23:10 +02:00
2021-09-25 14:44:18 +02:00
ADD_SIGNAL ( MethodInfo ( " body_shape_entered " , PropertyInfo ( Variant : : RID , " body_rid " ) , PropertyInfo ( Variant : : OBJECT , " body " , PROPERTY_HINT_RESOURCE_TYPE , " Node3D " ) , PropertyInfo ( Variant : : INT , " body_shape_index " ) , PropertyInfo ( Variant : : INT , " local_shape_index " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " body_shape_exited " , PropertyInfo ( Variant : : RID , " body_rid " ) , PropertyInfo ( Variant : : OBJECT , " body " , PROPERTY_HINT_RESOURCE_TYPE , " Node3D " ) , PropertyInfo ( Variant : : INT , " body_shape_index " ) , PropertyInfo ( Variant : : INT , " local_shape_index " ) ) ) ;
2021-02-24 05:51:20 +01:00
ADD_SIGNAL ( MethodInfo ( " body_entered " , PropertyInfo ( Variant : : OBJECT , " body " , PROPERTY_HINT_RESOURCE_TYPE , " Node3D " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " body_exited " , PropertyInfo ( Variant : : OBJECT , " body " , PROPERTY_HINT_RESOURCE_TYPE , " Node3D " ) ) ) ;
2014-02-10 02:10:30 +01:00
2021-09-25 14:44:18 +02:00
ADD_SIGNAL ( MethodInfo ( " area_shape_entered " , PropertyInfo ( Variant : : RID , " area_rid " ) , PropertyInfo ( Variant : : OBJECT , " area " , PROPERTY_HINT_RESOURCE_TYPE , " Area3D " ) , PropertyInfo ( Variant : : INT , " area_shape_index " ) , PropertyInfo ( Variant : : INT , " local_shape_index " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " area_shape_exited " , PropertyInfo ( Variant : : RID , " area_rid " ) , PropertyInfo ( Variant : : OBJECT , " area " , PROPERTY_HINT_RESOURCE_TYPE , " Area3D " ) , PropertyInfo ( Variant : : INT , " area_shape_index " ) , PropertyInfo ( Variant : : INT , " local_shape_index " ) ) ) ;
2020-03-26 22:49:16 +01:00
ADD_SIGNAL ( MethodInfo ( " area_entered " , PropertyInfo ( Variant : : OBJECT , " area " , PROPERTY_HINT_RESOURCE_TYPE , " Area3D " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " area_exited " , PropertyInfo ( Variant : : OBJECT , " area " , PROPERTY_HINT_RESOURCE_TYPE , " Area3D " ) ) ) ;
2014-02-10 02:10:30 +01:00
2021-04-18 02:18:17 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " monitoring " ) , " set_monitoring " , " is_monitoring " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " monitorable " ) , " set_monitorable " , " is_monitorable " ) ;
2023-02-05 09:09:32 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " priority " , PROPERTY_HINT_RANGE , " 0,100000,1,or_greater,or_less " ) , " set_priority " , " get_priority " ) ;
2021-04-18 02:18:17 +02:00
2021-11-05 02:12:00 +01:00
ADD_GROUP ( " Gravity " , " gravity_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " gravity_space_override " , PROPERTY_HINT_ENUM , " Disabled,Combine,Combine-Replace,Replace,Replace-Combine " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED ) , " set_gravity_space_override_mode " , " get_gravity_space_override_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " gravity_point " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED ) , " set_gravity_is_point " , " is_gravity_a_point " ) ;
2023-01-30 01:11:41 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " gravity_point_unit_distance " , PROPERTY_HINT_RANGE , " 0,1024,0.001,or_greater,exp,suffix:m " ) , " set_gravity_point_unit_distance " , " get_gravity_point_unit_distance " ) ;
2022-05-20 07:24:41 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " gravity_point_center " , PROPERTY_HINT_NONE , " suffix:m " ) , " set_gravity_point_center " , " get_gravity_point_center " ) ;
2021-11-05 02:12:00 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " gravity_direction " ) , " set_gravity_direction " , " get_gravity_direction " ) ;
2022-03-27 19:16:03 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " gravity " , PROPERTY_HINT_RANGE , U " -32,32,0.001,or_less,or_greater,suffix:m/s \u00B2 " ) , " set_gravity " , " get_gravity " ) ;
2021-11-05 02:12:00 +01:00
ADD_GROUP ( " Linear Damp " , " linear_damp_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " linear_damp_space_override " , PROPERTY_HINT_ENUM , " Disabled,Combine,Combine-Replace,Replace,Replace-Combine " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED ) , " set_linear_damp_space_override_mode " , " get_linear_damp_space_override_mode " ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " linear_damp " , PROPERTY_HINT_RANGE , " 0,100,0.001,or_greater " ) , " set_linear_damp " , " get_linear_damp " ) ;
2021-11-05 02:12:00 +01:00
ADD_GROUP ( " Angular Damp " , " angular_damp_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " angular_damp_space_override " , PROPERTY_HINT_ENUM , " Disabled,Combine,Combine-Replace,Replace,Replace-Combine " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED ) , " set_angular_damp_space_override_mode " , " get_angular_damp_space_override_mode " ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " angular_damp " , PROPERTY_HINT_RANGE , " 0,100,0.001,or_greater " ) , " set_angular_damp " , " get_angular_damp " ) ;
2021-11-05 02:12:00 +01:00
ADD_GROUP ( " Wind " , " wind_ " ) ;
2021-07-20 06:23:32 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " wind_force_magnitude " , PROPERTY_HINT_RANGE , " 0,10,0.001,or_greater " ) , " set_wind_force_magnitude " , " get_wind_force_magnitude " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " wind_attenuation_factor " , PROPERTY_HINT_RANGE , " 0.0,3.0,0.001,or_greater " ) , " set_wind_attenuation_factor " , " get_wind_attenuation_factor " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : NODE_PATH , " wind_source_path " , PROPERTY_HINT_NODE_PATH_VALID_TYPES , " Node3D " ) , " set_wind_source_path " , " get_wind_source_path " ) ;
2021-04-18 02:18:17 +02:00
2017-07-15 06:23:10 +02:00
ADD_GROUP ( " Audio Bus " , " audio_bus_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " audio_bus_override " ) , " set_audio_bus_override " , " is_overriding_audio_bus " ) ;
2020-12-10 09:31:14 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING_NAME , " audio_bus_name " , PROPERTY_HINT_ENUM , " " ) , " set_audio_bus_name " , " get_audio_bus_name " ) ;
2021-04-18 02:18:17 +02:00
2017-07-15 06:23:10 +02:00
ADD_GROUP ( " Reverb Bus " , " reverb_bus_ " ) ;
2022-09-21 18:56:03 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " reverb_bus_enabled " ) , " set_use_reverb_bus " , " is_using_reverb_bus " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING_NAME , " reverb_bus_name " , PROPERTY_HINT_ENUM , " " ) , " set_reverb_bus_name " , " get_reverb_bus_name " ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " reverb_bus_amount " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_reverb_amount " , " get_reverb_amount " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " reverb_bus_uniformity " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_reverb_uniformity " , " get_reverb_uniformity " ) ;
2017-09-12 21:09:06 +02:00
BIND_ENUM_CONSTANT ( SPACE_OVERRIDE_DISABLED ) ;
BIND_ENUM_CONSTANT ( SPACE_OVERRIDE_COMBINE ) ;
BIND_ENUM_CONSTANT ( SPACE_OVERRIDE_COMBINE_REPLACE ) ;
BIND_ENUM_CONSTANT ( SPACE_OVERRIDE_REPLACE ) ;
BIND_ENUM_CONSTANT ( SPACE_OVERRIDE_REPLACE_COMBINE ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
Area3D : : Area3D ( ) :
2020-03-27 19:21:27 +01:00
CollisionObject3D ( PhysicsServer3D : : get_singleton ( ) - > area_create ( ) , true ) {
2017-01-14 18:03:38 +01:00
set_gravity ( 9.8 ) ;
2021-11-05 02:12:00 +01:00
set_gravity_direction ( Vector3 ( 0 , - 1 , 0 ) ) ;
2017-01-14 00:03:51 +01:00
set_monitoring ( true ) ;
2015-06-12 20:52:21 +02:00
set_monitorable ( true ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
Area3D : : ~ Area3D ( ) {
2014-02-10 02:10:30 +01:00
}