virtualx-engine/scene/main/node.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

538 lines
20 KiB
C++
Raw Normal View History

2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* node.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
2014-02-10 02:10:30 +01:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
2014-02-10 02:10:30 +01:00
#ifndef NODE_H
#define NODE_H
#include "core/string/node_path.h"
#include "core/templates/rb_map.h"
#include "core/variant/typed_array.h"
#include "scene/main/scene_tree.h"
2014-02-10 02:10:30 +01:00
class Viewport;
class SceneState;
class Tween;
class PropertyTweener;
2014-02-10 02:10:30 +01:00
class Node : public Object {
GDCLASS(Node, Object);
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
public:
enum ProcessMode {
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
};
enum DuplicateFlags {
DUPLICATE_SIGNALS = 1,
DUPLICATE_GROUPS = 2,
DUPLICATE_SCRIPTS = 4,
DUPLICATE_USE_INSTANCING = 8,
#ifdef TOOLS_ENABLED
DUPLICATE_FROM_EDITOR = 16,
#endif
};
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,
};
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); }
};
2018-07-02 07:30:40 +02:00
struct ComparatorWithPriority {
2018-07-25 16:48:18 +02:00
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; }
2018-07-02 07:30:40 +02:00
};
static int orphan_node_count;
2016-03-09 00:00:52 +01:00
private:
2014-02-10 02:10:30 +01:00
struct GroupData {
bool persistent = false;
SceneTree::Group *group = nullptr;
2014-02-10 02:10:30 +01:00
};
2016-03-09 00:00:52 +01:00
// This Data struct is to avoid namespace pollution in derived classes.
2014-02-10 02:10:30 +01:00
struct Data {
String scene_file_path;
Ref<SceneState> instance_state;
Ref<SceneState> inherited_state;
Node *parent = nullptr;
Node *owner = nullptr;
Vector<Node *> children;
HashMap<StringName, Node *> owned_unique_nodes;
bool unique_name_in_owner = false;
2021-08-25 15:49:30 +02:00
int internal_children_front = 0;
int internal_children_back = 0;
2022-10-14 20:21:41 +02:00
int index = -1;
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;
SceneTree *tree = nullptr;
bool inside_tree = false;
bool ready_notified = false; // This is a small hack, so if a node is added during _ready() to the tree, it correctly gets the _ready() notification.
bool ready_first = true;
#ifdef TOOLS_ENABLED
NodePath import_path; // Path used when imported, used by scene editors to keep tracking.
#endif
String editor_description;
2014-02-10 02:10:30 +01:00
Viewport *viewport = nullptr;
HashMap<StringName, GroupData> grouped;
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
ProcessMode process_mode = PROCESS_MODE_INHERIT;
Node *process_owner = nullptr;
int multiplayer_authority = 1; // Server by default.
Variant rpc_config;
// Variables used to properly sort the node when processing, ignored otherwise.
// TODO: Should move all the stuff below to bits.
bool physics_process = false;
bool process = false;
int process_priority = 0;
2014-02-10 02:10:30 +01:00
bool physics_process_internal = false;
bool process_internal = false;
bool input = false;
bool shortcut_input = false;
bool unhandled_input = false;
bool unhandled_key_input = false;
2014-02-10 02:10:30 +01:00
bool parent_owned = false;
bool in_constructor = true;
bool use_placeholder = false;
bool display_folded = false;
bool editable_instance = false;
mutable NodePath *path_cache = nullptr;
2014-02-10 02:10:30 +01:00
} data;
Ref<MultiplayerAPI> multiplayer;
2019-07-10 11:54:12 +02:00
void _print_tree_pretty(const String &prefix, const bool last);
2016-03-09 00:00:52 +01:00
void _print_tree(const Node *p_node);
Node *_get_child_by_name(const StringName &p_name) const;
2014-02-10 02:10:30 +01:00
void _replace_connections_target(Node *p_new_target);
void _validate_child_name(Node *p_child, bool p_force_human_readable = false);
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);
void _propagate_enter_tree();
2014-02-10 02:10:30 +01:00
void _propagate_ready();
void _propagate_exit_tree();
void _propagate_after_exit_tree();
void _print_orphan_nodes();
void _propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification);
void _propagate_groups_dirty();
2014-02-10 02:10:30 +01:00
Array _get_node_and_resource(const NodePath &p_path);
void _duplicate_signals(const Node *p_original, Node *p_copy) const;
Node *_duplicate(int p_flags, HashMap<const Node *, Node *> *r_duplimap = nullptr) const;
2021-08-25 15:49:30 +02:00
TypedArray<Node> _get_children(bool p_include_internal = true) const;
TypedArray<StringName> _get_groups() const;
2014-02-10 02:10:30 +01: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);
2022-10-14 20:21:41 +02:00
_FORCE_INLINE_ bool _is_internal_front() const { return data.parent && data.index < data.parent->data.internal_children_front; }
_FORCE_INLINE_ bool _is_internal_back() const { return data.parent && data.index >= data.parent->data.children.size() - data.parent->data.internal_children_back; }
2021-08-25 15:49:30 +02:00
friend class SceneTree;
2014-02-10 02:10:30 +01:00
void _set_tree(SceneTree *p_tree);
void _propagate_pause_notification(bool p_enable);
_FORCE_INLINE_ bool _can_process(bool p_paused) const;
_FORCE_INLINE_ bool _is_enabled() const;
2014-02-10 02:10:30 +01:00
void _release_unique_name_in_owner();
void _acquire_unique_name_in_owner();
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);
2014-02-10 02:10:30 +01:00
virtual void add_child_notify(Node *p_child);
virtual void remove_child_notify(Node *p_child);
virtual void move_child_notify(Node *p_child);
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();
static String _get_name_num_separator();
2014-02-10 02:10:30 +01:00
friend class SceneState;
2014-02-10 02:10:30 +01:00
void _add_child_nocheck(Node *p_child, const StringName &p_name);
void _set_owner_nocheck(Node *p_owner);
void _set_name_nocheck(const StringName &p_name);
//call from SceneTree
void _call_input(const Ref<InputEvent> &p_event);
void _call_shortcut_input(const Ref<InputEvent> &p_event);
void _call_unhandled_input(const Ref<InputEvent> &p_event);
void _call_unhandled_key_input(const Ref<InputEvent> &p_event);
protected:
virtual void input(const Ref<InputEvent> &p_event);
virtual void shortcut_input(const Ref<InputEvent> &p_key_event);
virtual void unhandled_input(const Ref<InputEvent> &p_event);
virtual void unhandled_key_input(const Ref<InputEvent> &p_key_event);
GDVIRTUAL1(_process, double)
GDVIRTUAL1(_physics_process, double)
GDVIRTUAL0(_enter_tree)
GDVIRTUAL0(_exit_tree)
GDVIRTUAL0(_ready)
GDVIRTUAL0RC(Vector<String>, _get_configuration_warnings)
GDVIRTUAL1(_input, Ref<InputEvent>)
GDVIRTUAL1(_shortcut_input, Ref<InputEvent>)
GDVIRTUAL1(_unhandled_input, Ref<InputEvent>)
GDVIRTUAL1(_unhandled_key_input, Ref<InputEvent>)
2014-02-10 02:10:30 +01:00
public:
enum {
// you can make your own, but don't use the same numbers as other notifications in other nodes
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,
NOTIFICATION_PHYSICS_PROCESS = 16,
2014-02-10 02:10:30 +01:00
NOTIFICATION_PROCESS = 17,
NOTIFICATION_PARENTED = 18,
NOTIFICATION_UNPARENTED = 19,
NOTIFICATION_SCENE_INSTANTIATED = 20,
NOTIFICATION_DRAG_BEGIN = 21,
NOTIFICATION_DRAG_END = 22,
NOTIFICATION_PATH_RENAMED = 23,
//NOTIFICATION_TRANSLATION_CHANGED = 24, moved below
NOTIFICATION_INTERNAL_PROCESS = 25,
NOTIFICATION_INTERNAL_PHYSICS_PROCESS = 26,
NOTIFICATION_POST_ENTER_TREE = 27,
NOTIFICATION_DISABLED = 28,
NOTIFICATION_ENABLED = 29,
//keep these linked to node
NOTIFICATION_WM_MOUSE_ENTER = 1002,
NOTIFICATION_WM_MOUSE_EXIT = 1003,
NOTIFICATION_WM_WINDOW_FOCUS_IN = 1004,
NOTIFICATION_WM_WINDOW_FOCUS_OUT = 1005,
NOTIFICATION_WM_CLOSE_REQUEST = 1006,
NOTIFICATION_WM_GO_BACK_REQUEST = 1007,
NOTIFICATION_WM_SIZE_CHANGED = 1008,
NOTIFICATION_WM_DPI_CHANGE = 1009,
NOTIFICATION_VP_MOUSE_ENTER = 1010,
NOTIFICATION_VP_MOUSE_EXIT = 1011,
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,
NOTIFICATION_OS_IME_UPDATE = MainLoop::NOTIFICATION_OS_IME_UPDATE,
NOTIFICATION_APPLICATION_RESUMED = MainLoop::NOTIFICATION_APPLICATION_RESUMED,
NOTIFICATION_APPLICATION_PAUSED = MainLoop::NOTIFICATION_APPLICATION_PAUSED,
NOTIFICATION_APPLICATION_FOCUS_IN = MainLoop::NOTIFICATION_APPLICATION_FOCUS_IN,
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;
void set_name(const String &p_name);
2016-03-09 00:00:52 +01: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;
2014-02-10 02:10:30 +01:00
bool has_node(const NodePath &p_path) const;
Node *get_node(const NodePath &p_path) const;
Node *get_node_or_null(const NodePath &p_path) const;
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;
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
2014-02-10 02:10:30 +01:00
Node *get_parent() const;
Node *find_parent(const String &p_pattern) const;
2018-09-15 18:22:06 +02:00
_FORCE_INLINE_ SceneTree *get_tree() const {
2020-04-02 01:20:12 +02:00
ERR_FAIL_COND_V(!data.tree, nullptr);
return data.tree;
}
2014-02-10 02:10:30 +01:00
_FORCE_INLINE_ bool is_inside_tree() const { return data.inside_tree; }
2016-03-09 00:00:52 +01: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;
NodePath get_path_to(const Node *p_node) 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 {
StringName name;
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;
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
void set_unique_name_in_owner(bool p_enabled);
bool is_unique_name_in_owner() const;
2021-08-25 15:49:30 +02:00
int get_index(bool p_include_internal = true) const;
2016-03-09 00:00:52 +01:00
Ref<Tween> create_tween();
2014-02-10 02:10:30 +01:00
void print_tree();
void print_tree_pretty();
2016-03-09 00:00:52 +01:00
void set_scene_file_path(const String &p_scene_file_path);
String get_scene_file_path() const;
void set_editor_description(const String &p_editor_description);
String get_editor_description() const;
void set_editable_instance(Node *p_node, bool p_editable);
bool is_editable_instance(const Node *p_node) const;
Node *get_deepest_editable_node(Node *p_start_node) const;
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;
#endif
void get_storable_properties(HashSet<StringName> &r_storable_properties) const;
2021-10-26 21:12:25 +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
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 */
void set_physics_process(bool p_process);
double get_physics_process_delta_time() const;
bool is_physics_processing() const;
2014-02-10 02:10:30 +01:00
void set_process(bool p_process);
double get_process_delta_time() const;
2014-02-10 02:10:30 +01:00
bool is_processing() const;
void set_physics_process_internal(bool p_process_internal);
bool is_physics_processing_internal() const;
void set_process_internal(bool p_process_internal);
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);
int get_process_priority() const;
2018-07-02 07:30:40 +02:00
2014-02-10 02:10:30 +01:00
void set_process_input(bool p_enable);
bool is_processing_input() const;
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;
void set_process_unhandled_key_input(bool p_enable);
bool is_processing_unhandled_key_input() const;
Node *duplicate(int p_flags = DUPLICATE_GROUPS | DUPLICATE_SIGNALS | DUPLICATE_SCRIPTS) const;
#ifdef TOOLS_ENABLED
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;
#endif
2014-02-10 02:10:30 +01:00
// used by editors, to save what has changed only
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;
void set_scene_instance_load_placeholder(bool p_enable);
bool get_scene_instance_load_placeholder() const;
2014-02-10 02:10:30 +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
void replace_by(Node *p_node, bool p_keep_data = false);
void set_process_mode(ProcessMode p_mode);
ProcessMode get_process_mode() const;
2014-02-10 02:10:30 +01:00
bool can_process() const;
bool can_process_notification(int p_what) const;
bool is_enabled() const;
2014-02-10 02:10:30 +01:00
void request_ready();
static void print_orphan_nodes();
2014-02-10 02:10:30 +01:00
#ifdef TOOLS_ENABLED
String validate_child_name(Node *p_child);
#endif
2022-08-18 13:47:05 +02:00
static String adjust_name_casing(const String &p_name);
void queue_free();
2014-02-10 02:10:30 +01:00
//hacks for speed
static void init_node_hrcr();
void force_parent_owned() { data.parent_owned = true; } //hack to avoid duplicate nodes
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;
bool is_owned_by_parent() const;
2020-07-10 12:34:39 +02:00
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
void clear_internal_tree_resource_paths();
_FORCE_INLINE_ Viewport *get_viewport() const { return data.viewport; }
virtual PackedStringArray get_configuration_warnings() const;
String get_configuration_warnings_as_string() const;
void update_configuration_warnings();
void set_display_folded(bool p_folded);
bool is_displayed_folded() const;
/* NETWORK */
virtual void set_multiplayer_authority(int p_peer_id, bool p_recursive = true);
int get_multiplayer_authority() const;
bool is_multiplayer_authority() const;
void rpc_config(const StringName &p_method, const Variant &p_config); // config a local method for RPC
const Variant get_node_rpc_config() const;
template <typename... VarArgs>
Error rpc(const StringName &p_method, VarArgs... p_args);
template <typename... VarArgs>
Error rpc_id(int p_peer_id, const StringName &p_method, VarArgs... p_args);
Error rpcp(int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount);
Ref<MultiplayerAPI> get_multiplayer() const;
2014-02-10 02:10:30 +01:00
Node();
~Node();
};
VARIANT_ENUM_CAST(Node::DuplicateFlags);
typedef HashSet<Node *, Node::Comparator> NodeSet;
2014-02-10 02:10:30 +01: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));
}
// 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."));
#endif // NODE_H