2014-02-10 02:10:30 +01:00
/**************************************************************************/
/* node.h */
/**************************************************************************/
/* 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
2014-02-10 02:10:30 +01:00
# ifndef NODE_H
# define NODE_H
2020-11-07 23:33:38 +01:00
# include "core/string/node_path.h"
2022-05-13 15:04:37 +02:00
# include "core/templates/rb_map.h"
2020-11-07 23:33:38 +01:00
# include "core/variant/typed_array.h"
2017-06-27 03:58:03 +02:00
# include "scene/main/scene_tree.h"
2014-02-10 02:10:30 +01:00
2014-04-10 05:18:27 +02:00
class Viewport ;
2023-01-10 08:40:44 +01:00
class Window ;
2015-10-10 14:09:09 +02:00
class SceneState ;
2020-09-05 03:05:30 +02:00
class Tween ;
class PropertyTweener ;
2023-05-17 01:44:41 +02:00
SAFE_FLAG_TYPE_PUN_GUARANTEES
SAFE_NUMERIC_TYPE_PUN_GUARANTEES ( uint32_t )
2014-02-10 02:10:30 +01:00
class Node : public Object {
2017-01-03 03:03:46 +01:00
GDCLASS ( Node , Object ) ;
2016-03-09 00:00:52 +01:00
2023-05-17 01:44:41 +02:00
protected :
// During group processing, these are thread-safe.
// Outside group processing, these avoid the cost of sync by working as plain primitive types.
union MTFlag {
2023-05-22 13:33:40 +02:00
SafeFlag mt ;
2023-05-17 01:44:41 +02:00
bool st ;
2023-05-22 13:33:40 +02:00
MTFlag ( ) :
mt { } { }
2023-05-17 01:44:41 +02:00
} ;
template < typename T >
union MTNumeric {
2023-05-22 13:33:40 +02:00
SafeNumeric < T > mt ;
2023-05-17 01:44:41 +02:00
T st ;
2023-05-22 13:33:40 +02:00
MTNumeric ( ) :
mt { } { }
2023-05-17 01:44:41 +02:00
} ;
2014-02-10 02:10:30 +01:00
public :
2024-02-17 00:57:32 +01:00
// N.B. Any enum stored as a bitfield should be specified as UNSIGNED to work around
// some compilers trying to store it as signed, and requiring 1 more bit than necessary.
enum ProcessMode : unsigned int {
2021-02-18 19:52:29 +01:00
PROCESS_MODE_INHERIT , // same as parent node
PROCESS_MODE_PAUSABLE , // process only if not paused
PROCESS_MODE_WHEN_PAUSED , // process only if paused
PROCESS_MODE_ALWAYS , // process always
PROCESS_MODE_DISABLED , // never process
2014-02-10 02:10:30 +01:00
} ;
2023-04-10 18:45:53 +02:00
enum ProcessThreadGroup {
PROCESS_THREAD_GROUP_INHERIT ,
PROCESS_THREAD_GROUP_MAIN_THREAD ,
PROCESS_THREAD_GROUP_SUB_THREAD ,
} ;
enum ProcessThreadMessages {
FLAG_PROCESS_THREAD_MESSAGES = 1 ,
FLAG_PROCESS_THREAD_MESSAGES_PHYSICS = 2 ,
FLAG_PROCESS_THREAD_MESSAGES_ALL = 3 ,
} ;
2024-02-17 00:57:32 +01:00
enum PhysicsInterpolationMode : unsigned int {
PHYSICS_INTERPOLATION_MODE_INHERIT ,
PHYSICS_INTERPOLATION_MODE_ON ,
PHYSICS_INTERPOLATION_MODE_OFF ,
} ;
2017-02-20 20:05:01 +01:00
enum DuplicateFlags {
DUPLICATE_SIGNALS = 1 ,
DUPLICATE_GROUPS = 2 ,
DUPLICATE_SCRIPTS = 4 ,
2022-11-16 00:13:39 +01:00
DUPLICATE_USE_INSTANTIATION = 8 ,
2017-11-19 14:32:10 +01:00
# ifdef TOOLS_ENABLED
DUPLICATE_FROM_EDITOR = 16 ,
# endif
2017-02-20 20:05:01 +01:00
} ;
2021-07-29 06:26:34 +02:00
enum NameCasing {
NAME_CASING_PASCAL_CASE ,
NAME_CASING_CAMEL_CASE ,
NAME_CASING_SNAKE_CASE
} ;
2021-08-25 15:49:30 +02:00
enum InternalMode {
INTERNAL_MODE_DISABLED ,
INTERNAL_MODE_FRONT ,
INTERNAL_MODE_BACK ,
} ;
2024-01-23 22:29:45 +01:00
enum AutoTranslateMode {
AUTO_TRANSLATE_MODE_INHERIT ,
AUTO_TRANSLATE_MODE_ALWAYS ,
AUTO_TRANSLATE_MODE_DISABLED ,
} ;
2014-02-10 02:10:30 +01:00
struct Comparator {
bool operator ( ) ( const Node * p_a , const Node * p_b ) const { return p_b - > is_greater_than ( p_a ) ; }
} ;
2019-04-17 22:46:21 +02:00
static int orphan_node_count ;
2023-04-10 18:45:53 +02:00
void _update_process ( bool p_enable , bool p_for_children ) ;
2016-03-09 00:00:52 +01:00
private :
2014-02-10 02:10:30 +01:00
struct GroupData {
2020-12-08 19:58:49 +01:00
bool persistent = false ;
SceneTree : : Group * group = nullptr ;
2014-02-10 02:10:30 +01:00
} ;
2016-03-09 00:00:52 +01:00
2023-04-03 22:31:47 +02:00
struct ComparatorByIndex {
bool operator ( ) ( const Node * p_left , const Node * p_right ) const {
static const uint32_t order [ 3 ] = { 1 , 0 , 2 } ;
uint32_t order_left = order [ p_left - > data . internal_mode ] ;
uint32_t order_right = order [ p_right - > data . internal_mode ] ;
if ( order_left = = order_right ) {
return p_left - > data . index < p_right - > data . index ;
}
return order_left < order_right ;
}
} ;
2023-04-10 18:45:53 +02:00
struct ComparatorWithPriority {
bool operator ( ) ( const Node * p_a , const Node * p_b ) const { return p_b - > data . process_priority = = p_a - > data . process_priority ? p_b - > is_greater_than ( p_a ) : p_b - > data . process_priority > p_a - > data . process_priority ; }
} ;
struct ComparatorWithPhysicsPriority {
bool operator ( ) ( const Node * p_a , const Node * p_b ) const { return p_b - > data . physics_process_priority = = p_a - > data . physics_process_priority ? p_b - > is_greater_than ( p_a ) : p_b - > data . physics_process_priority > p_a - > data . physics_process_priority ; }
} ;
2022-10-13 15:30:23 +02:00
// This Data struct is to avoid namespace pollution in derived classes.
2014-02-10 02:10:30 +01:00
struct Data {
2021-09-30 16:30:55 +02:00
String scene_file_path ;
2015-10-10 14:09:09 +02:00
Ref < SceneState > instance_state ;
Ref < SceneState > inherited_state ;
2020-12-11 15:54:03 +01:00
Node * parent = nullptr ;
Node * owner = nullptr ;
2023-04-03 22:31:47 +02:00
HashMap < StringName , Node * > children ;
mutable bool children_cache_dirty = true ;
mutable LocalVector < Node * > children_cache ;
2022-04-16 12:23:32 +02:00
HashMap < StringName , Node * > owned_unique_nodes ;
bool unique_name_in_owner = false ;
2023-04-03 22:31:47 +02:00
InternalMode internal_mode = INTERNAL_MODE_DISABLED ;
mutable int internal_children_front_count_cache = 0 ;
mutable int internal_children_back_count_cache = 0 ;
mutable int external_children_count_cache = 0 ;
mutable int index = - 1 ; // relative to front, normal or back.
2020-12-11 15:54:03 +01:00
int depth = - 1 ;
int blocked = 0 ; // Safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed.
2014-02-10 02:10:30 +01:00
StringName name ;
2020-12-11 15:54:03 +01:00
SceneTree * tree = nullptr ;
2024-02-17 00:57:32 +01:00
2014-06-19 07:23:03 +02:00
# ifdef TOOLS_ENABLED
2020-12-11 15:54:03 +01:00
NodePath import_path ; // Path used when imported, used by scene editors to keep tracking.
2014-06-19 07:23:03 +02:00
# endif
2021-02-18 19:52:29 +01:00
String editor_description ;
2014-02-10 02:10:30 +01:00
2020-12-11 15:54:03 +01:00
Viewport * viewport = nullptr ;
2014-04-10 05:18:27 +02:00
2022-05-13 15:04:37 +02:00
HashMap < StringName , GroupData > grouped ;
2020-12-11 15:54:03 +01:00
List < Node * > : : Element * OW = nullptr ; // Owned element.
2014-02-10 02:10:30 +01:00
List < Node * > owned ;
2016-03-09 00:00:52 +01:00
2021-02-18 19:52:29 +01:00
Node * process_owner = nullptr ;
2023-04-10 18:45:53 +02:00
ProcessThreadGroup process_thread_group = PROCESS_THREAD_GROUP_INHERIT ;
Node * process_thread_group_owner = nullptr ;
int process_thread_group_order = 0 ;
BitField < ProcessThreadMessages > process_thread_messages ;
void * process_group = nullptr ; // to avoid cyclic dependency
2016-08-14 23:49:50 +02:00
2021-09-07 23:35:19 +02:00
int multiplayer_authority = 1 ; // Server by default.
2022-07-12 23:12:42 +02:00
Variant rpc_config ;
2016-08-14 23:49:50 +02:00
2020-12-11 15:54:03 +01:00
// Variables used to properly sort the node when processing, ignored otherwise.
int process_priority = 0 ;
2023-04-10 18:45:53 +02:00
int physics_process_priority = 0 ;
2014-02-10 02:10:30 +01:00
2024-02-17 00:57:32 +01:00
// Keep bitpacked values together to get better packing.
ProcessMode process_mode : 3 ;
PhysicsInterpolationMode physics_interpolation_mode : 2 ;
bool physics_process : 1 ;
bool process : 1 ;
bool physics_process_internal : 1 ;
bool process_internal : 1 ;
bool input : 1 ;
bool shortcut_input : 1 ;
bool unhandled_input : 1 ;
bool unhandled_key_input : 1 ;
2017-01-10 22:02:19 +01:00
2024-02-17 00:57:32 +01:00
// Physics interpolation can be turned on and off on a per node basis.
// This only takes effect when the SceneTree (or project setting) physics interpolation
// is switched on.
bool physics_interpolated : 1 ;
2014-02-10 02:10:30 +01:00
2024-02-17 00:57:32 +01:00
bool parent_owned : 1 ;
bool in_constructor : 1 ;
bool use_placeholder : 1 ;
2015-10-17 00:11:23 +02:00
2024-02-17 00:57:32 +01:00
bool display_folded : 1 ;
bool editable_instance : 1 ;
bool inside_tree : 1 ;
bool ready_notified : 1 ;
bool ready_first : 1 ;
2015-10-10 14:09:09 +02:00
2024-01-23 22:29:45 +01:00
AutoTranslateMode auto_translate_mode = AUTO_TRANSLATE_MODE_INHERIT ;
mutable bool is_auto_translating = true ;
mutable bool is_auto_translate_dirty = true ;
2020-12-11 15:54:03 +01:00
mutable NodePath * path_cache = nullptr ;
2016-08-14 23:49:50 +02:00
2014-02-10 02:10:30 +01:00
} data ;
2018-05-08 10:51:04 +02:00
Ref < MultiplayerAPI > multiplayer ;
2018-03-03 18:30:11 +01:00
2023-05-21 18:04:03 +02:00
String _get_tree_string_pretty ( const String & p_prefix , bool p_last ) ;
String _get_tree_string ( const Node * p_node ) ;
2016-03-09 00:00:52 +01:00
2015-10-10 14:09:09 +02:00
Node * _get_child_by_name ( const StringName & p_name ) const ;
2014-02-10 02:10:30 +01:00
2016-06-09 16:24:12 +02:00
void _replace_connections_target ( Node * p_new_target ) ;
2015-06-08 05:33:10 +02:00
2016-10-07 20:25:29 +02:00
void _validate_child_name ( Node * p_child , bool p_force_human_readable = false ) ;
2019-01-10 22:52:47 +01:00
void _generate_serial_child_name ( const Node * p_child , StringName & name ) const ;
2014-02-10 02:10:30 +01:00
2016-03-09 00:00:52 +01:00
void _propagate_reverse_notification ( int p_notification ) ;
2014-02-10 02:10:30 +01:00
void _propagate_deferred_notification ( int p_notification , bool p_reverse ) ;
2014-11-06 01:20:42 +01:00
void _propagate_enter_tree ( ) ;
2014-02-10 02:10:30 +01:00
void _propagate_ready ( ) ;
2014-11-06 01:20:42 +01:00
void _propagate_exit_tree ( ) ;
2018-09-07 20:31:19 +02:00
void _propagate_after_exit_tree ( ) ;
2024-02-17 00:57:32 +01:00
void _propagate_physics_interpolated ( bool p_interpolated ) ;
2021-06-18 03:09:40 +02:00
void _propagate_process_owner ( Node * p_owner , int p_pause_notification , int p_enabled_notification ) ;
2022-05-31 20:28:04 +02:00
void _propagate_groups_dirty ( ) ;
2014-02-10 02:10:30 +01:00
Array _get_node_and_resource ( const NodePath & p_path ) ;
2024-01-19 21:57:31 +01:00
void _duplicate_properties_node ( const Node * p_root , const Node * p_original , Node * p_copy ) const ;
2015-05-10 20:45:33 +02:00
void _duplicate_signals ( const Node * p_original , Node * p_copy ) const ;
2022-05-13 15:04:37 +02:00
Node * _duplicate ( int p_flags , HashMap < const Node * , Node * > * r_duplimap = nullptr ) const ;
2016-07-07 02:43:31 +02:00
2022-08-05 20:35:08 +02:00
TypedArray < StringName > _get_groups ( ) const ;
2014-02-10 02:10:30 +01:00
2022-07-12 23:12:42 +02:00
Error _rpc_bind ( const Variant * * p_args , int p_argcount , Callable : : CallError & r_error ) ;
Error _rpc_id_bind ( const Variant * * p_args , int p_argcount , Callable : : CallError & r_error ) ;
2016-08-14 23:49:50 +02:00
2014-11-06 01:20:42 +01:00
friend class SceneTree ;
2014-02-10 02:10:30 +01:00
2014-11-06 01:20:42 +01:00
void _set_tree ( SceneTree * p_tree ) ;
2021-02-18 19:52:29 +01:00
void _propagate_pause_notification ( bool p_enable ) ;
_FORCE_INLINE_ bool _can_process ( bool p_paused ) const ;
2021-06-18 03:09:40 +02:00
_FORCE_INLINE_ bool _is_enabled ( ) const ;
2014-02-10 02:10:30 +01:00
2022-04-16 12:23:32 +02:00
void _release_unique_name_in_owner ( ) ;
void _acquire_unique_name_in_owner ( ) ;
2023-02-27 09:16:51 +01:00
void _clean_up_owner ( ) ;
2023-04-03 22:31:47 +02:00
_FORCE_INLINE_ void _update_children_cache ( ) const {
if ( unlikely ( data . children_cache_dirty ) ) {
_update_children_cache_impl ( ) ;
}
}
void _update_children_cache_impl ( ) const ;
2023-04-10 18:45:53 +02:00
// Process group management
void _add_process_group ( ) ;
void _remove_process_group ( ) ;
void _add_to_process_thread_group ( ) ;
void _remove_from_process_thread_group ( ) ;
void _remove_tree_from_process_thread_group ( ) ;
void _add_tree_to_process_thread_group ( Node * p_owner ) ;
static thread_local Node * current_process_thread_group ;
Variant _call_deferred_thread_group_bind ( const Variant * * p_args , int p_argcount , Callable : : CallError & r_error ) ;
Variant _call_thread_safe_bind ( const Variant * * p_args , int p_argcount , Callable : : CallError & r_error ) ;
2014-02-10 02:10:30 +01:00
protected :
void _block ( ) { data . blocked + + ; }
void _unblock ( ) { data . blocked - - ; }
2016-03-09 00:00:52 +01:00
void _notification ( int p_notification ) ;
2024-02-17 00:57:32 +01:00
virtual void _physics_interpolated_changed ( ) ;
2014-02-10 02:10:30 +01:00
virtual void add_child_notify ( Node * p_child ) ;
virtual void remove_child_notify ( Node * p_child ) ;
2014-12-03 05:17:23 +01:00
virtual void move_child_notify ( Node * p_child ) ;
2022-06-23 08:19:18 +02:00
virtual void owner_changed_notify ( ) ;
2016-03-09 00:00:52 +01:00
void _propagate_replace_owner ( Node * p_owner , Node * p_by_owner ) ;
2014-02-10 02:10:30 +01:00
static void _bind_methods ( ) ;
2016-10-07 20:25:29 +02:00
static String _get_name_num_separator ( ) ;
2014-02-10 02:10:30 +01:00
2015-10-10 14:09:09 +02:00
friend class SceneState ;
2014-02-10 02:10:30 +01:00
2023-04-03 22:31:47 +02:00
void _add_child_nocheck ( Node * p_child , const StringName & p_name , InternalMode p_internal_mode = INTERNAL_MODE_DISABLED ) ;
2014-02-10 02:10:30 +01:00
void _set_owner_nocheck ( Node * p_owner ) ;
void _set_name_nocheck ( const StringName & p_name ) ;
2021-08-22 17:37:22 +02:00
//call from SceneTree
void _call_input ( const Ref < InputEvent > & p_event ) ;
2022-01-11 14:59:52 +01:00
void _call_shortcut_input ( const Ref < InputEvent > & p_event ) ;
2021-08-22 17:37:22 +02:00
void _call_unhandled_input ( const Ref < InputEvent > & p_event ) ;
void _call_unhandled_key_input ( const Ref < InputEvent > & p_event ) ;
2023-04-10 18:45:53 +02:00
void _validate_property ( PropertyInfo & p_property ) const ;
2021-08-22 17:37:22 +02:00
protected :
virtual void input ( const Ref < InputEvent > & p_event ) ;
2022-01-11 14:59:52 +01:00
virtual void shortcut_input ( const Ref < InputEvent > & p_key_event ) ;
2021-08-22 17:37:22 +02:00
virtual void unhandled_input ( const Ref < InputEvent > & p_event ) ;
virtual void unhandled_key_input ( const Ref < InputEvent > & p_key_event ) ;
2021-08-22 03:52:44 +02:00
GDVIRTUAL1 ( _process , double )
GDVIRTUAL1 ( _physics_process , double )
GDVIRTUAL0 ( _enter_tree )
GDVIRTUAL0 ( _exit_tree )
GDVIRTUAL0 ( _ready )
2024-02-17 19:04:18 +01:00
GDVIRTUAL0RC ( Vector < String > , _get_configuration_warnings )
2021-08-22 17:37:22 +02:00
GDVIRTUAL1 ( _input , Ref < InputEvent > )
2022-01-11 14:59:52 +01:00
GDVIRTUAL1 ( _shortcut_input , Ref < InputEvent > )
2021-08-22 17:37:22 +02:00
GDVIRTUAL1 ( _unhandled_input , Ref < InputEvent > )
GDVIRTUAL1 ( _unhandled_key_input , Ref < InputEvent > )
2014-02-10 02:10:30 +01:00
public :
enum {
2024-02-17 00:57:32 +01:00
// You can make your own, but don't use the same numbers as other notifications in other nodes.
2014-11-06 01:20:42 +01:00
NOTIFICATION_ENTER_TREE = 10 ,
NOTIFICATION_EXIT_TREE = 11 ,
2014-02-10 02:10:30 +01:00
NOTIFICATION_MOVED_IN_PARENT = 12 ,
NOTIFICATION_READY = 13 ,
NOTIFICATION_PAUSED = 14 ,
NOTIFICATION_UNPAUSED = 15 ,
2017-09-30 16:19:07 +02:00
NOTIFICATION_PHYSICS_PROCESS = 16 ,
2014-02-10 02:10:30 +01:00
NOTIFICATION_PROCESS = 17 ,
NOTIFICATION_PARENTED = 18 ,
NOTIFICATION_UNPARENTED = 19 ,
2022-08-15 00:50:31 +02:00
NOTIFICATION_SCENE_INSTANTIATED = 20 ,
2016-05-11 16:46:08 +02:00
NOTIFICATION_DRAG_BEGIN = 21 ,
NOTIFICATION_DRAG_END = 22 ,
2021-09-04 00:12:37 +02:00
NOTIFICATION_PATH_RENAMED = 23 ,
2023-04-05 18:53:32 +02:00
NOTIFICATION_CHILD_ORDER_CHANGED = 24 ,
2017-01-10 22:02:19 +01:00
NOTIFICATION_INTERNAL_PROCESS = 25 ,
2017-09-30 16:19:07 +02:00
NOTIFICATION_INTERNAL_PHYSICS_PROCESS = 26 ,
2018-05-15 22:12:35 +02:00
NOTIFICATION_POST_ENTER_TREE = 27 ,
2021-06-18 03:09:40 +02:00
NOTIFICATION_DISABLED = 28 ,
NOTIFICATION_ENABLED = 29 ,
2024-02-17 00:57:32 +01:00
NOTIFICATION_RESET_PHYSICS_INTERPOLATION = 2001 , // A GodotSpace Odyssey.
// Keep these linked to Node.
2020-03-04 17:36:09 +01:00
NOTIFICATION_WM_MOUSE_ENTER = 1002 ,
NOTIFICATION_WM_MOUSE_EXIT = 1003 ,
2020-06-30 01:47:18 +02:00
NOTIFICATION_WM_WINDOW_FOCUS_IN = 1004 ,
NOTIFICATION_WM_WINDOW_FOCUS_OUT = 1005 ,
2020-03-04 17:36:09 +01:00
NOTIFICATION_WM_CLOSE_REQUEST = 1006 ,
NOTIFICATION_WM_GO_BACK_REQUEST = 1007 ,
2020-03-06 18:00:16 +01:00
NOTIFICATION_WM_SIZE_CHANGED = 1008 ,
2020-03-07 17:02:54 +01:00
NOTIFICATION_WM_DPI_CHANGE = 1009 ,
2022-02-15 22:14:39 +01:00
NOTIFICATION_VP_MOUSE_ENTER = 1010 ,
NOTIFICATION_VP_MOUSE_EXIT = 1011 ,
2020-03-04 17:36:09 +01:00
2019-04-04 15:34:03 +02:00
NOTIFICATION_OS_MEMORY_WARNING = MainLoop : : NOTIFICATION_OS_MEMORY_WARNING ,
NOTIFICATION_TRANSLATION_CHANGED = MainLoop : : NOTIFICATION_TRANSLATION_CHANGED ,
NOTIFICATION_WM_ABOUT = MainLoop : : NOTIFICATION_WM_ABOUT ,
NOTIFICATION_CRASH = MainLoop : : NOTIFICATION_CRASH ,
2019-09-09 23:42:17 +02:00
NOTIFICATION_OS_IME_UPDATE = MainLoop : : NOTIFICATION_OS_IME_UPDATE ,
2020-06-30 01:47:18 +02:00
NOTIFICATION_APPLICATION_RESUMED = MainLoop : : NOTIFICATION_APPLICATION_RESUMED ,
NOTIFICATION_APPLICATION_PAUSED = MainLoop : : NOTIFICATION_APPLICATION_PAUSED ,
NOTIFICATION_APPLICATION_FOCUS_IN = MainLoop : : NOTIFICATION_APPLICATION_FOCUS_IN ,
2020-09-03 13:22:16 +02:00
NOTIFICATION_APPLICATION_FOCUS_OUT = MainLoop : : NOTIFICATION_APPLICATION_FOCUS_OUT ,
NOTIFICATION_TEXT_SERVER_CHANGED = MainLoop : : NOTIFICATION_TEXT_SERVER_CHANGED ,
New and improved IK system for Skeleton2D
This PR and commit adds a new IK system for 2D with the Skeleton2D node
that adds several new IK solvers, a way to control bones in a Skeleton2D
node similar to that in Skeleton3D. It also adds additional changes
and functionality.
This work was sponsored by GSoC 2020 and TwistedTwigleg.
Full list of changes:
* Adds a SkeletonModifier2D resource
* This resource is the base where all IK code is written and executed
* Has a function for clamping angles, since it is so commonly used
* Modifiers are unique when duplicated so it works with instancing
* Adds a SkeletonModifierStack2D resource
* This resource manages a series of SkeletonModification2Ds
* This is what the Skeleton2D directly interfaces with to make IK possible
* Adds SkeletonModifier2D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in its own file
* There is also a SkeletonModifier2D resource that acts as a stack for using multiple stacks together
* Adds a PhysicalBone2D node
* Works similar to the PhysicalBone3D node, but uses a RigidBody2D node
* Changes to Skeleton2D listed below:
* Skeleton2D now holds a single SkeletonModificationStack2D for IK
* Skeleton2D now has a local_pose_override, which overrides the Bone2D position similar to how the overrides work in Skeleton3D
* Changes to Bone2D listed below:
* The default_length property has been changed to length. Length is the length of the bone to its child bone node
* New bone_angle property, which is the angle the bone has to its first child bone node
* Bone2D caches its transform when not modified by IK for IK interpolation purposes
* Bone2D draws its own editor gizmo, though this is stated to change in the future
* Changes to CanvasItemEditor listed below:
* Bone2D gizmo drawing code removed
* The 2D IK code is removed. Now Bone2D is the only bone system for 2D
* Transform2D now has a looking_at function for rotating to face a position
* Two new node notifications: NOTIFICATION_EDITOR_PRE_SAVE and NOTIFICATION_EDITOR_POST_SAVE
* These notifications only are called in the editor right before and after saving a scene
* Needed for not saving the IK position when executing IK in the editor
* Documentation for all the changes listed above.
2020-08-03 20:02:24 +02:00
// Editor specific node notifications
NOTIFICATION_EDITOR_PRE_SAVE = 9001 ,
NOTIFICATION_EDITOR_POST_SAVE = 9002 ,
2014-02-10 02:10:30 +01:00
} ;
2016-03-09 00:00:52 +01:00
/* NODE/TREE */
2014-02-10 02:10:30 +01:00
StringName get_name ( ) const ;
2023-06-05 19:57:33 +02:00
String get_description ( ) const ;
2014-02-10 02:10:30 +01:00
void set_name ( const String & p_name ) ;
2016-03-09 00:00:52 +01:00
2023-06-29 00:46:11 +02:00
InternalMode get_internal_mode ( ) const ;
2022-08-15 19:55:38 +02:00
void add_child ( Node * p_child , bool p_force_readable_name = false , InternalMode p_internal = INTERNAL_MODE_DISABLED ) ;
void add_sibling ( Node * p_sibling , bool p_force_readable_name = false ) ;
2014-02-10 02:10:30 +01:00
void remove_child ( Node * p_child ) ;
2016-03-09 00:00:52 +01:00
2021-08-25 15:49:30 +02:00
int get_child_count ( bool p_include_internal = true ) const ;
Node * get_child ( int p_index , bool p_include_internal = true ) const ;
2022-11-08 03:27:50 +01:00
TypedArray < Node > get_children ( bool p_include_internal = true ) const ;
2014-02-10 02:10:30 +01:00
bool has_node ( const NodePath & p_path ) const ;
Node * get_node ( const NodePath & p_path ) const ;
2019-01-29 17:15:34 +01:00
Node * get_node_or_null ( const NodePath & p_path ) const ;
2022-04-25 15:16:44 +02:00
Node * find_child ( const String & p_pattern , bool p_recursive = true , bool p_owned = true ) const ;
TypedArray < Node > find_children ( const String & p_pattern , const String & p_type = " " , bool p_recursive = true , bool p_owned = true ) const ;
2014-02-10 02:10:30 +01:00
bool has_node_and_resource ( const NodePath & p_path ) const ;
2022-05-03 01:43:50 +02:00
Node * get_node_and_resource ( const NodePath & p_path , Ref < Resource > & r_res , Vector < StringName > & r_leftover_subpath , bool p_last_is_property = true ) const ;
2016-03-09 00:00:52 +01:00
2020-02-17 18:29:14 +01:00
virtual void reparent ( Node * p_parent , bool p_keep_global_transform = true ) ;
2014-02-10 02:10:30 +01:00
Node * get_parent ( ) const ;
2022-04-25 15:16:44 +02:00
Node * find_parent ( const String & p_pattern ) const ;
2018-09-15 18:22:06 +02:00
2023-01-10 08:40:44 +01:00
Window * get_window ( ) const ;
2023-04-20 15:13:21 +02:00
Window * get_last_exclusive_window ( ) const ;
2023-01-10 08:40:44 +01:00
2014-11-06 01:20:42 +01:00
_FORCE_INLINE_ SceneTree * get_tree ( ) const {
2023-09-28 11:40:18 +02:00
ERR_FAIL_NULL_V ( data . tree , nullptr ) ;
2014-11-06 01:20:42 +01:00
return data . tree ;
}
2014-02-10 02:10:30 +01:00
2014-11-06 01:20:42 +01:00
_FORCE_INLINE_ bool is_inside_tree ( ) const { return data . inside_tree ; }
2016-03-09 00:00:52 +01:00
2021-06-19 00:02:50 +02:00
bool is_ancestor_of ( const Node * p_node ) const ;
2014-02-10 02:10:30 +01:00
bool is_greater_than ( const Node * p_node ) const ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
NodePath get_path ( ) const ;
2022-11-18 23:23:38 +01:00
NodePath get_path_to ( const Node * p_node , bool p_use_unique_path = false ) const ;
2016-07-20 01:04:06 +02:00
Node * find_common_parent_with ( const Node * p_node ) const ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
void add_to_group ( const StringName & p_identifier , bool p_persistent = false ) ;
void remove_from_group ( const StringName & p_identifier ) ;
bool is_in_group ( const StringName & p_identifier ) const ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
struct GroupInfo {
2015-10-10 14:09:09 +02:00
StringName name ;
2021-02-09 18:24:36 +01:00
bool persistent = false ;
2014-02-10 02:10:30 +01:00
} ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
void get_groups ( List < GroupInfo > * p_groups ) const ;
2019-08-16 22:30:31 +02:00
int get_persistent_group_count ( ) const ;
2016-03-09 00:00:52 +01:00
2022-10-14 20:21:41 +02:00
void move_child ( Node * p_child , int p_index ) ;
void _move_child ( Node * p_child , int p_index , bool p_ignore_end = false ) ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
void set_owner ( Node * p_owner ) ;
Node * get_owner ( ) const ;
void get_owned_by ( Node * p_by , List < Node * > * p_owned ) ;
2016-03-09 00:00:52 +01:00
2022-04-16 12:23:32 +02:00
void set_unique_name_in_owner ( bool p_enabled ) ;
bool is_unique_name_in_owner ( ) const ;
2023-04-03 22:31:47 +02:00
_FORCE_INLINE_ int get_index ( bool p_include_internal = true ) const {
// p_include_internal = false doesn't make sense if the node is internal.
ERR_FAIL_COND_V_MSG ( ! p_include_internal & & data . internal_mode ! = INTERNAL_MODE_DISABLED , - 1 , " Node is internal. Can't get index with 'include_internal' being false. " ) ;
if ( ! data . parent ) {
return data . index ;
}
data . parent - > _update_children_cache ( ) ;
if ( ! p_include_internal ) {
return data . index ;
} else {
switch ( data . internal_mode ) {
case INTERNAL_MODE_DISABLED : {
return data . parent - > data . internal_children_front_count_cache + data . index ;
} break ;
case INTERNAL_MODE_FRONT : {
return data . index ;
} break ;
case INTERNAL_MODE_BACK : {
return data . parent - > data . internal_children_front_count_cache + data . parent - > data . external_children_count_cache + data . index ;
} break ;
}
return - 1 ;
}
}
2016-03-09 00:00:52 +01:00
2020-09-05 03:05:30 +02:00
Ref < Tween > create_tween ( ) ;
2014-02-10 02:10:30 +01:00
void print_tree ( ) ;
2018-02-28 10:12:06 +01:00
void print_tree_pretty ( ) ;
2023-05-21 18:04:03 +02:00
String get_tree_string ( ) ;
String get_tree_string_pretty ( ) ;
2016-03-09 00:00:52 +01:00
2021-09-30 16:30:55 +02:00
void set_scene_file_path ( const String & p_scene_file_path ) ;
String get_scene_file_path ( ) const ;
2015-10-10 14:09:09 +02:00
2019-08-15 14:50:26 +02:00
void set_editor_description ( const String & p_editor_description ) ;
String get_editor_description ( ) const ;
2015-10-10 14:09:09 +02:00
void set_editable_instance ( Node * p_node , bool p_editable ) ;
2018-10-29 20:36:31 +01:00
bool is_editable_instance ( const Node * p_node ) const ;
2021-02-21 09:19:48 +01:00
Node * get_deepest_editable_node ( Node * p_start_node ) const ;
2015-10-17 00:11:23 +02:00
2021-10-26 21:12:25 +02:00
# ifdef TOOLS_ENABLED
void set_property_pinned ( const String & p_property , bool p_pinned ) ;
bool is_property_pinned ( const StringName & p_property ) const ;
virtual StringName get_property_store_alias ( const StringName & p_property ) const ;
2023-03-17 01:58:30 +01:00
bool is_part_of_edited_scene ( ) const ;
2023-11-29 16:54:34 +01:00
# else
bool is_part_of_edited_scene ( ) const { return false ; }
2021-10-26 21:12:25 +02:00
# endif
2022-05-19 17:00:06 +02:00
void get_storable_properties ( HashSet < StringName > & r_storable_properties ) const ;
2021-10-26 21:12:25 +02:00
2021-07-11 16:40:18 +02:00
virtual String to_string ( ) override ;
2014-02-10 02:10:30 +01:00
/* NOTIFICATIONS */
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
void propagate_notification ( int p_notification ) ;
2016-03-09 00:00:52 +01:00
2017-08-19 15:17:06 +02:00
void propagate_call ( const StringName & p_method , const Array & p_args = Array ( ) , const bool p_parent_first = false ) ;
2014-02-10 02:10:30 +01:00
/* PROCESSING */
2024-01-23 22:29:45 +01:00
2017-09-30 16:19:07 +02:00
void set_physics_process ( bool p_process ) ;
2021-02-02 03:16:37 +01:00
double get_physics_process_delta_time ( ) const ;
2017-09-30 16:19:07 +02:00
bool is_physics_processing ( ) const ;
2014-02-10 02:10:30 +01:00
2020-12-22 10:50:29 +01:00
void set_process ( bool p_process ) ;
2021-02-02 03:16:37 +01:00
double get_process_delta_time ( ) const ;
2014-02-10 02:10:30 +01:00
bool is_processing ( ) const ;
2017-09-30 16:19:07 +02:00
void set_physics_process_internal ( bool p_process_internal ) ;
bool is_physics_processing_internal ( ) const ;
2017-01-10 22:02:19 +01:00
2020-12-22 10:50:29 +01:00
void set_process_internal ( bool p_process_internal ) ;
2017-01-10 22:02:19 +01:00
bool is_processing_internal ( ) const ;
2014-02-10 02:10:30 +01:00
2018-07-02 07:30:40 +02:00
void set_process_priority ( int p_priority ) ;
2019-11-16 22:07:02 +01:00
int get_process_priority ( ) const ;
2018-07-02 07:30:40 +02:00
2023-04-10 18:45:53 +02:00
void set_process_thread_group_order ( int p_order ) ;
int get_process_thread_group_order ( ) const ;
void set_physics_process_priority ( int p_priority ) ;
int get_physics_process_priority ( ) const ;
2014-02-10 02:10:30 +01:00
void set_process_input ( bool p_enable ) ;
bool is_processing_input ( ) const ;
2022-01-11 14:59:52 +01:00
void set_process_shortcut_input ( bool p_enable ) ;
bool is_processing_shortcut_input ( ) const ;
2014-02-10 02:10:30 +01:00
void set_process_unhandled_input ( bool p_enable ) ;
bool is_processing_unhandled_input ( ) const ;
2014-04-10 05:18:27 +02:00
void set_process_unhandled_key_input ( bool p_enable ) ;
bool is_processing_unhandled_key_input ( ) const ;
2023-04-10 18:45:53 +02:00
_FORCE_INLINE_ bool _is_any_processing ( ) const {
return data . process | | data . process_internal | | data . physics_process | | data . physics_process_internal ;
}
_FORCE_INLINE_ bool is_accessible_from_caller_thread ( ) const {
if ( current_process_thread_group = = nullptr ) {
2023-06-01 11:03:32 +02:00
// No thread processing.
// Only accessible if node is outside the scene tree
// or access will happen from a node-safe thread.
2023-05-23 23:28:47 +02:00
return ! data . inside_tree | | is_current_thread_safe_for_nodes ( ) ;
2023-04-10 18:45:53 +02:00
} else {
2023-06-01 11:03:32 +02:00
// Thread processing.
2023-04-10 18:45:53 +02:00
return current_process_thread_group = = data . process_thread_group_owner ;
}
}
2023-05-12 13:53:15 +02:00
_FORCE_INLINE_ bool is_readable_from_caller_thread ( ) const {
if ( current_process_thread_group = = nullptr ) {
2023-06-01 11:03:32 +02:00
// No thread processing.
2024-01-08 10:33:09 +01:00
// Only accessible if node is outside the scene tree
// or access will happen from a node-safe thread.
return ! data . inside_tree | | is_current_thread_safe_for_nodes ( ) ;
2023-05-12 13:53:15 +02:00
} else {
2023-06-01 11:03:32 +02:00
// Thread processing.
2023-05-12 13:53:15 +02:00
return true ;
}
}
2023-05-17 01:44:41 +02:00
_FORCE_INLINE_ static bool is_group_processing ( ) { return current_process_thread_group ; }
2023-04-10 18:45:53 +02:00
void set_process_thread_messages ( BitField < ProcessThreadMessages > p_flags ) ;
BitField < ProcessThreadMessages > get_process_thread_messages ( ) const ;
2017-02-20 20:05:01 +01:00
Node * duplicate ( int p_flags = DUPLICATE_GROUPS | DUPLICATE_SIGNALS | DUPLICATE_SCRIPTS ) const ;
2017-11-19 14:32:10 +01:00
# ifdef TOOLS_ENABLED
2022-05-13 15:04:37 +02:00
Node * duplicate_from_editor ( HashMap < const Node * , Node * > & r_duplimap ) const ;
Node * duplicate_from_editor ( HashMap < const Node * , Node * > & r_duplimap , const HashMap < Ref < Resource > , Ref < Resource > > & p_resource_remap ) const ;
void remap_node_resources ( Node * p_node , const HashMap < Ref < Resource > , Ref < Resource > > & p_resource_remap ) const ;
void remap_nested_resources ( Ref < Resource > p_resource , const HashMap < Ref < Resource > , Ref < Resource > > & p_resource_remap ) const ;
2017-11-19 14:32:10 +01:00
# endif
2015-08-02 17:29:37 +02:00
2014-02-10 02:10:30 +01:00
// used by editors, to save what has changed only
2015-10-10 14:09:09 +02:00
void set_scene_instance_state ( const Ref < SceneState > & p_state ) ;
Ref < SceneState > get_scene_instance_state ( ) const ;
void set_scene_inherited_state ( const Ref < SceneState > & p_state ) ;
Ref < SceneState > get_scene_inherited_state ( ) const ;
2015-10-17 00:11:23 +02:00
void set_scene_instance_load_placeholder ( bool p_enable ) ;
bool get_scene_instance_load_placeholder ( ) const ;
2014-02-10 02:10:30 +01:00
2022-03-09 14:58:40 +01:00
template < typename . . . VarArgs >
Vector < Variant > make_binds ( VarArgs . . . p_args ) {
Vector < Variant > binds = { p_args . . . } ;
return binds ;
}
2014-02-10 02:10:30 +01:00
2024-04-09 18:07:07 +02:00
void replace_by ( Node * p_node , bool p_keep_data = false ) ;
2014-02-10 02:10:30 +01:00
2021-02-18 19:52:29 +01:00
void set_process_mode ( ProcessMode p_mode ) ;
ProcessMode get_process_mode ( ) const ;
2014-02-10 02:10:30 +01:00
bool can_process ( ) const ;
2018-07-30 02:20:41 +02:00
bool can_process_notification ( int p_what ) const ;
2024-02-17 00:57:32 +01:00
void set_physics_interpolation_mode ( PhysicsInterpolationMode p_mode ) ;
PhysicsInterpolationMode get_physics_interpolation_mode ( ) const { return data . physics_interpolation_mode ; }
_FORCE_INLINE_ bool is_physics_interpolated ( ) const { return data . physics_interpolated ; }
_FORCE_INLINE_ bool is_physics_interpolated_and_enabled ( ) const { return is_inside_tree ( ) & & get_tree ( ) - > is_physics_interpolation_enabled ( ) & & is_physics_interpolated ( ) ; }
void reset_physics_interpolation ( ) ;
2021-06-18 03:09:40 +02:00
bool is_enabled ( ) const ;
2023-04-06 14:47:49 +02:00
bool is_ready ( ) const ;
2023-04-10 18:45:53 +02:00
2017-01-10 22:02:19 +01:00
void request_ready ( ) ;
2023-04-10 18:45:53 +02:00
void set_process_thread_group ( ProcessThreadGroup p_mode ) ;
ProcessThreadGroup get_process_thread_group ( ) const ;
2022-03-27 19:30:49 +02:00
static void print_orphan_nodes ( ) ;
2014-02-10 02:10:30 +01:00
2016-10-07 20:25:29 +02:00
# ifdef TOOLS_ENABLED
String validate_child_name ( Node * p_child ) ;
2024-01-16 15:16:58 +01:00
String prevalidate_child_name ( Node * p_child , StringName p_name ) ;
2024-01-03 12:10:11 +01:00
void get_argument_options ( const StringName & p_function , int p_idx , List < String > * r_options ) const override ;
2016-10-07 20:25:29 +02:00
# endif
2022-08-18 13:47:05 +02:00
static String adjust_name_casing ( const String & p_name ) ;
2015-08-02 17:29:37 +02:00
2022-10-24 23:07:02 +02:00
void queue_free ( ) ;
2014-02-10 02:10:30 +01:00
2018-02-17 14:00:39 +01:00
//hacks for speed
2014-02-23 00:28:19 +01:00
static void init_node_hrcr ( ) ;
2014-04-05 17:39:30 +02:00
void force_parent_owned ( ) { data . parent_owned = true ; } //hack to avoid duplicate nodes
2014-06-19 07:23:03 +02:00
void set_import_path ( const NodePath & p_import_path ) ; //path used when imported, used by scene editors to keep tracking
NodePath get_import_path ( ) const ;
2016-06-21 03:57:07 +02:00
bool is_owned_by_parent ( ) const ;
2015-06-22 05:03:19 +02:00
void clear_internal_tree_resource_paths ( ) ;
2014-04-10 05:18:27 +02:00
_FORCE_INLINE_ Viewport * get_viewport ( ) const { return data . viewport ; }
2024-02-17 19:04:18 +01:00
virtual PackedStringArray get_configuration_warnings ( ) const ;
2016-05-17 23:27:15 +02:00
2020-10-29 11:01:28 +01:00
void update_configuration_warnings ( ) ;
2016-05-17 23:27:15 +02:00
2016-06-28 18:10:15 +02:00
void set_display_folded ( bool p_folded ) ;
bool is_displayed_folded ( ) const ;
2024-01-23 22:29:45 +01:00
2016-08-14 23:49:50 +02:00
/* NETWORK */
2021-10-08 14:13:06 +02:00
virtual void set_multiplayer_authority ( int p_peer_id , bool p_recursive = true ) ;
2021-09-07 23:35:19 +02:00
int get_multiplayer_authority ( ) const ;
bool is_multiplayer_authority ( ) const ;
2016-08-14 23:49:50 +02:00
2022-07-12 23:12:42 +02:00
void rpc_config ( const StringName & p_method , const Variant & p_config ) ; // config a local method for RPC
const Variant get_node_rpc_config ( ) const ;
2016-08-14 23:49:50 +02:00
2022-03-09 14:58:40 +01:00
template < typename . . . VarArgs >
2022-07-12 23:12:42 +02:00
Error rpc ( const StringName & p_method , VarArgs . . . p_args ) ;
2022-03-09 14:58:40 +01:00
template < typename . . . VarArgs >
2022-07-12 23:12:42 +02:00
Error rpc_id ( int p_peer_id , const StringName & p_method , VarArgs . . . p_args ) ;
2022-03-09 14:58:40 +01:00
2022-07-12 23:12:42 +02:00
Error rpcp ( int p_peer_id , const StringName & p_method , const Variant * * p_arg , int p_argcount ) ;
2016-08-14 23:49:50 +02:00
2018-05-08 10:51:04 +02:00
Ref < MultiplayerAPI > get_multiplayer ( ) const ;
2020-02-12 11:51:50 +01:00
2024-01-23 22:29:45 +01:00
/* INTERNATIONALIZATION */
void set_auto_translate_mode ( AutoTranslateMode p_mode ) ;
AutoTranslateMode get_auto_translate_mode ( ) const ;
bool can_auto_translate ( ) const ;
_FORCE_INLINE_ String atr ( const String p_message , const StringName p_context = " " ) const { return can_auto_translate ( ) ? tr ( p_message , p_context ) : p_message ; }
_FORCE_INLINE_ String atr_n ( const String p_message , const StringName & p_message_plural , int p_n , const StringName p_context = " " ) const { return can_auto_translate ( ) ? tr_n ( p_message , p_message_plural , p_n , p_context ) : p_message ; }
/* THREADING */
2023-04-10 18:45:53 +02:00
void call_deferred_thread_groupp ( const StringName & p_method , const Variant * * p_args , int p_argcount , bool p_show_error = false ) ;
template < typename . . . VarArgs >
void call_deferred_thread_group ( const StringName & p_method , VarArgs . . . p_args ) {
Variant args [ sizeof . . . ( p_args ) + 1 ] = { p_args . . . , Variant ( ) } ; // +1 makes sure zero sized arrays are also supported.
const Variant * argptrs [ sizeof . . . ( p_args ) + 1 ] ;
for ( uint32_t i = 0 ; i < sizeof . . . ( p_args ) ; i + + ) {
argptrs [ i ] = & args [ i ] ;
}
call_deferred_thread_groupp ( p_method , sizeof . . . ( p_args ) = = 0 ? nullptr : ( const Variant * * ) argptrs , sizeof . . . ( p_args ) ) ;
}
void set_deferred_thread_group ( const StringName & p_property , const Variant & p_value ) ;
void notify_deferred_thread_group ( int p_notification ) ;
void call_thread_safep ( const StringName & p_method , const Variant * * p_args , int p_argcount , bool p_show_error = false ) ;
template < typename . . . VarArgs >
void call_thread_safe ( const StringName & p_method , VarArgs . . . p_args ) {
Variant args [ sizeof . . . ( p_args ) + 1 ] = { p_args . . . , Variant ( ) } ; // +1 makes sure zero sized arrays are also supported.
const Variant * argptrs [ sizeof . . . ( p_args ) + 1 ] ;
for ( uint32_t i = 0 ; i < sizeof . . . ( p_args ) ; i + + ) {
argptrs [ i ] = & args [ i ] ;
}
call_deferred_thread_groupp ( p_method , sizeof . . . ( p_args ) = = 0 ? nullptr : ( const Variant * * ) argptrs , sizeof . . . ( p_args ) ) ;
}
void set_thread_safe ( const StringName & p_property , const Variant & p_value ) ;
void notify_thread_safe ( int p_notification ) ;
2023-05-12 13:53:15 +02:00
// These inherited functions need proper multithread locking when overridden in Node.
# ifdef DEBUG_ENABLED
virtual void set_script ( const Variant & p_script ) override ;
virtual Variant get_script ( ) const override ;
virtual bool has_meta ( const StringName & p_name ) const override ;
virtual void set_meta ( const StringName & p_name , const Variant & p_value ) override ;
virtual void remove_meta ( const StringName & p_name ) override ;
virtual Variant get_meta ( const StringName & p_name , const Variant & p_default = Variant ( ) ) const override ;
virtual void get_meta_list ( List < StringName > * p_list ) const override ;
virtual Error emit_signalp ( const StringName & p_name , const Variant * * p_args , int p_argcount ) override ;
virtual bool has_signal ( const StringName & p_name ) const override ;
virtual void get_signal_list ( List < MethodInfo > * p_signals ) const override ;
virtual void get_signal_connection_list ( const StringName & p_signal , List < Connection > * p_connections ) const override ;
virtual void get_all_signal_connections ( List < Connection > * p_connections ) const override ;
virtual int get_persistent_signal_connection_count ( ) const override ;
virtual void get_signals_connected_to_this ( List < Connection > * p_connections ) const override ;
virtual Error connect ( const StringName & p_signal , const Callable & p_callable , uint32_t p_flags = 0 ) override ;
virtual void disconnect ( const StringName & p_signal , const Callable & p_callable ) override ;
virtual bool is_connected ( const StringName & p_signal , const Callable & p_callable ) const override ;
# endif
2014-02-10 02:10:30 +01:00
Node ( ) ;
~ Node ( ) ;
} ;
2017-08-20 17:45:01 +02:00
VARIANT_ENUM_CAST ( Node : : DuplicateFlags ) ;
2023-06-15 16:06:22 +02:00
VARIANT_ENUM_CAST ( Node : : ProcessMode ) ;
VARIANT_ENUM_CAST ( Node : : ProcessThreadGroup ) ;
VARIANT_BITFIELD_CAST ( Node : : ProcessThreadMessages ) ;
VARIANT_ENUM_CAST ( Node : : InternalMode ) ;
2024-02-17 00:57:32 +01:00
VARIANT_ENUM_CAST ( Node : : PhysicsInterpolationMode ) ;
2024-01-23 22:29:45 +01:00
VARIANT_ENUM_CAST ( Node : : AutoTranslateMode ) ;
2017-08-20 17:45:01 +02:00
2022-05-19 17:00:06 +02:00
typedef HashSet < Node * , Node : : Comparator > NodeSet ;
2014-02-10 02:10:30 +01:00
2022-08-02 12:47:16 +02:00
// Template definitions must be in the header so they are always fully initialized before their usage.
// See this StackOverflow question for more information: https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file
template < typename . . . VarArgs >
Error Node : : rpc ( const StringName & p_method , VarArgs . . . p_args ) {
return rpc_id ( 0 , p_method , p_args . . . ) ;
}
template < typename . . . VarArgs >
Error Node : : rpc_id ( int p_peer_id , const StringName & p_method , VarArgs . . . p_args ) {
Variant args [ sizeof . . . ( p_args ) + 1 ] = { p_args . . . , Variant ( ) } ; // +1 makes sure zero sized arrays are also supported.
const Variant * argptrs [ sizeof . . . ( p_args ) + 1 ] ;
for ( uint32_t i = 0 ; i < sizeof . . . ( p_args ) ; i + + ) {
argptrs [ i ] = & args [ i ] ;
}
return rpcp ( p_peer_id , p_method , sizeof . . . ( p_args ) = = 0 ? nullptr : ( const Variant * * ) argptrs , sizeof . . . ( p_args ) ) ;
}
2023-04-10 18:45:53 +02:00
# ifdef DEBUG_ENABLED
2023-06-05 19:57:33 +02:00
# define ERR_THREAD_GUARD ERR_FAIL_COND_MSG(!is_accessible_from_caller_thread(), vformat("Caller thread can't call this function in this node (%s). Use call_deferred() or call_thread_group() instead.", get_description()));
# define ERR_THREAD_GUARD_V(m_ret) ERR_FAIL_COND_V_MSG(!is_accessible_from_caller_thread(), (m_ret), vformat("Caller thread can't call this function in this node (%s). Use call_deferred() or call_thread_group() instead.", get_description()));
# define ERR_MAIN_THREAD_GUARD ERR_FAIL_COND_MSG(is_inside_tree() && !is_current_thread_safe_for_nodes(), vformat("This function in this node (%s) can only be accessed from the main thread. Use call_deferred() instead.", get_description()));
# define ERR_MAIN_THREAD_GUARD_V(m_ret) ERR_FAIL_COND_V_MSG(is_inside_tree() && !is_current_thread_safe_for_nodes(), (m_ret), vformat("This function in this node (%s) can only be accessed from the main thread. Use call_deferred() instead.", get_description()));
# define ERR_READ_THREAD_GUARD ERR_FAIL_COND_MSG(!is_readable_from_caller_thread(), vformat("This function in this node (%s) can only be accessed from either the main thread or a thread group. Use call_deferred() instead.", get_description()));
# define ERR_READ_THREAD_GUARD_V(m_ret) ERR_FAIL_COND_V_MSG(!is_readable_from_caller_thread(), (m_ret), vformat("This function in this node (%s) can only be accessed from either the main thread or a thread group. Use call_deferred() instead.", get_description()));
2023-04-10 18:45:53 +02:00
# else
# define ERR_THREAD_GUARD
# define ERR_THREAD_GUARD_V(m_ret)
# define ERR_MAIN_THREAD_GUARD
# define ERR_MAIN_THREAD_GUARD_V(m_ret)
2023-05-12 13:53:15 +02:00
# define ERR_READ_THREAD_GUARD
# define ERR_READ_THREAD_GUARD_V(m_ret)
2023-04-10 18:45:53 +02:00
# endif
2022-08-28 08:17:25 +02:00
// Add these macro to your class's 'get_configuration_warnings' function to have warnings show up in the scene tree inspector.
# define DEPRECATED_NODE_WARNING warnings.push_back(RTR("This node is marked as deprecated and will be removed in future versions.\nPlease check the Godot documentation for information about migration."));
# define EXPERIMENTAL_NODE_WARNING warnings.push_back(RTR("This node is marked as experimental and may be subject to removal or major changes in future versions."));
2022-07-23 23:41:51 +02:00
# endif // NODE_H