diff options
Diffstat (limited to 'scene/main/node.h')
-rw-r--r-- | scene/main/node.h | 209 |
1 files changed, 99 insertions, 110 deletions
diff --git a/scene/main/node.h b/scene/main/node.h index b042cabb6f..714a58bd82 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -29,24 +29,22 @@ #ifndef NODE_H #define NODE_H +#include "class_db.h" #include "global_config.h" +#include "map.h" #include "object.h" #include "path_db.h" -#include "map.h" -#include "class_db.h" -#include "script_language.h" #include "scene/main/scene_main_loop.h" - +#include "script_language.h" class Viewport; class SceneState; class Node : public Object { - GDCLASS( Node, Object ); + GDCLASS(Node, Object); OBJ_CATEGORY("Nodes"); public: - enum PauseMode { PAUSE_MODE_INHERIT, @@ -56,10 +54,10 @@ public: enum DuplicateFlags { - DUPLICATE_SIGNALS=1, - DUPLICATE_GROUPS=2, - DUPLICATE_SCRIPTS=4, - DUPLICATE_USE_INSTANCING=8 + DUPLICATE_SIGNALS = 1, + DUPLICATE_GROUPS = 2, + DUPLICATE_SCRIPTS = 4, + DUPLICATE_USE_INSTANCING = 8 }; enum NetworkMode { @@ -80,31 +78,28 @@ public: struct Comparator { - bool operator()(const Node* p_a, const Node* p_b) const { return p_b->is_greater_than(p_a); } + bool operator()(const Node *p_a, const Node *p_b) const { return p_b->is_greater_than(p_a); } }; private: - struct GroupData { bool persistent; SceneTree::Group *group; - GroupData() { persistent=false; } + GroupData() { persistent = false; } }; - - struct Data { String filename; Ref<SceneState> instance_state; Ref<SceneState> inherited_state; - HashMap<NodePath,int> editable_instances; + HashMap<NodePath, int> editable_instances; Node *parent; Node *owner; - Vector<Node*> children; // list of children + Vector<Node *> children; // list of children int pos; int depth; int blocked; // safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed. @@ -119,19 +114,17 @@ private: Viewport *viewport; - - Map< StringName, GroupData> grouped; - List<Node*>::Element *OW; // owned element - List<Node*> owned; + Map<StringName, GroupData> grouped; + List<Node *>::Element *OW; // owned element + List<Node *> owned; PauseMode pause_mode; Node *pause_owner; NetworkMode network_mode; Node *network_owner; - Map<StringName,RPCMode> rpc_methods; - Map<StringName,RPCMode> rpc_properties; - + Map<StringName, RPCMode> rpc_methods; + Map<StringName, RPCMode> rpc_properties; // variables used to properly sort the node when processing, ignored otherwise //should move all the stuff below to bits @@ -161,15 +154,14 @@ private: NAME_CASING_SNAKE_CASE }; - void _print_tree(const Node *p_node); - Node *_get_node(const NodePath& p_path) const; - Node *_get_child_by_name(const StringName& p_name) const; + Node *_get_node(const NodePath &p_path) const; + Node *_get_child_by_name(const StringName &p_name) const; - void _replace_connections_target(Node* p_new_target); + void _replace_connections_target(Node *p_new_target); - void _validate_child_name(Node *p_child, bool p_force_human_readable=false); + void _validate_child_name(Node *p_child, bool p_force_human_readable = false); String _generate_serial_child_name(Node *p_child); void _propagate_reverse_notification(int p_notification); @@ -179,29 +171,29 @@ private: void _propagate_exit_tree(); void _propagate_validate_owner(); void _print_stray_nodes(); - void _propagate_pause_owner(Node*p_owner); - void _propagate_network_owner(Node*p_owner); - Array _get_node_and_resource(const NodePath& p_path); + void _propagate_pause_owner(Node *p_owner); + void _propagate_network_owner(Node *p_owner); + Array _get_node_and_resource(const NodePath &p_path); - void _duplicate_signals(const Node* p_original,Node* p_copy) const; - void _duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const; + void _duplicate_signals(const Node *p_original, Node *p_copy) const; + void _duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p_reown_map) const; Node *_duplicate(int p_flags) const; Array _get_children() const; Array _get_groups() const; - Variant _rpc_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error); - Variant _rpc_unreliable_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error); - Variant _rpc_id_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error); - Variant _rpc_unreliable_id_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error); + Variant _rpc_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + Variant _rpc_unreliable_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + Variant _rpc_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + Variant _rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error); -friend class SceneTree; + friend class SceneTree; void _set_tree(SceneTree *p_tree); -protected: +protected: void _block() { data.blocked++; } - void _unblock() { data.blocked--; } + void _unblock() { data.blocked--; } void _notification(int p_notification); @@ -210,37 +202,36 @@ protected: virtual void move_child_notify(Node *p_child); //void remove_and_delete_child(Node *p_child); - void _propagate_replace_owner(Node *p_owner,Node* p_by_owner); + void _propagate_replace_owner(Node *p_owner, Node *p_by_owner); static void _bind_methods(); static String _get_name_num_separator(); -friend class SceneState; + friend class SceneState; - 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); + 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); 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, - NOTIFICATION_MOVED_IN_PARENT =12, - NOTIFICATION_READY=13, + NOTIFICATION_ENTER_TREE = 10, + NOTIFICATION_EXIT_TREE = 11, + NOTIFICATION_MOVED_IN_PARENT = 12, + NOTIFICATION_READY = 13, //NOTIFICATION_PARENT_DECONFIGURED =15, - it's confusing, it's going away - NOTIFICATION_PAUSED=14, - NOTIFICATION_UNPAUSED=15, + NOTIFICATION_PAUSED = 14, + NOTIFICATION_UNPAUSED = 15, NOTIFICATION_FIXED_PROCESS = 16, NOTIFICATION_PROCESS = 17, - NOTIFICATION_PARENTED=18, - NOTIFICATION_UNPARENTED=19, - NOTIFICATION_INSTANCED=20, - NOTIFICATION_DRAG_BEGIN=21, - NOTIFICATION_DRAG_END=22, - NOTIFICATION_PATH_CHANGED=23, - NOTIFICATION_TRANSLATION_CHANGED=24, + NOTIFICATION_PARENTED = 18, + NOTIFICATION_UNPARENTED = 19, + NOTIFICATION_INSTANCED = 20, + NOTIFICATION_DRAG_BEGIN = 21, + NOTIFICATION_DRAG_END = 22, + NOTIFICATION_PATH_CHANGED = 23, + NOTIFICATION_TRANSLATION_CHANGED = 24, NOTIFICATION_INTERNAL_PROCESS = 25, NOTIFICATION_INTERNAL_FIXED_PROCESS = 26, @@ -249,22 +240,25 @@ public: /* NODE/TREE */ StringName get_name() const; - void set_name(const String& p_name); + void set_name(const String &p_name); - void add_child(Node *p_child,bool p_legible_unique_name=false); - void add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name=false); + void add_child(Node *p_child, bool p_legible_unique_name = false); + void add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name = false); void remove_child(Node *p_child); int get_child_count() const; Node *get_child(int p_index) const; - bool has_node(const NodePath& p_path) const; - Node *get_node(const NodePath& p_path) const; - Node* find_node(const String& p_mask,bool p_recursive=true,bool p_owned=true) const; - bool has_node_and_resource(const NodePath& p_path) const; - Node *get_node_and_resource(const NodePath& p_path,RES& r_res) const; + bool has_node(const NodePath &p_path) const; + Node *get_node(const NodePath &p_path) const; + Node *find_node(const String &p_mask, bool p_recursive = true, bool p_owned = true) const; + bool has_node_and_resource(const NodePath &p_path) const; + Node *get_node_and_resource(const NodePath &p_path, RES &r_res) const; Node *get_parent() const; - _FORCE_INLINE_ SceneTree *get_tree() const { ERR_FAIL_COND_V( !data.tree, NULL ); return data.tree; } + _FORCE_INLINE_ SceneTree *get_tree() const { + ERR_FAIL_COND_V(!data.tree, NULL); + return data.tree; + } _FORCE_INLINE_ bool is_inside_tree() const { return data.inside_tree; } @@ -273,11 +267,11 @@ public: NodePath get_path() const; NodePath get_path_to(const Node *p_node) const; - Node* find_common_parent_with(const Node *p_node) const; + Node *find_common_parent_with(const Node *p_node) const; - 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; + 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; struct GroupInfo { @@ -288,27 +282,25 @@ public: void get_groups(List<GroupInfo> *p_groups) const; bool has_persistent_groups() const; - void move_child(Node *p_child,int p_pos); + void move_child(Node *p_child, int p_pos); void raise(); void set_owner(Node *p_owner); Node *get_owner() const; - void get_owned_by(Node *p_by,List<Node*> *p_owned); - + void get_owned_by(Node *p_by, List<Node *> *p_owned); void remove_and_skip(); int get_index() const; void print_tree(); - void set_filename(const String& p_filename); + void set_filename(const String &p_filename); String get_filename() const; - void set_editable_instance(Node* p_node,bool p_editable); - bool is_editable_instance(Node* p_node) const; - void set_editable_instances(const HashMap<NodePath,int>& p_editable_instances); - HashMap<NodePath,int> get_editable_instances() const; - + void set_editable_instance(Node *p_node, bool p_editable); + bool is_editable_instance(Node *p_node) const; + void set_editable_instances(const HashMap<NodePath, int> &p_editable_instances); + HashMap<NodePath, int> get_editable_instances() const; /* NOTIFICATIONS */ @@ -340,16 +332,16 @@ public: int get_position_in_parent() const; - Node *duplicate(int p_flags=DUPLICATE_GROUPS|DUPLICATE_SIGNALS|DUPLICATE_SCRIPTS) const; - Node *duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const; + Node *duplicate(int p_flags = DUPLICATE_GROUPS | DUPLICATE_SIGNALS | DUPLICATE_SCRIPTS) const; + Node *duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const; //Node *clone_tree() const; // used by editors, to save what has changed only - void set_scene_instance_state(const Ref<SceneState>& p_state); + 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); + 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); @@ -357,7 +349,7 @@ public: static Vector<Variant> make_binds(VARIANT_ARG_LIST); - void replace_by(Node* p_node,bool p_keep_data=false); + void replace_by(Node *p_node, bool p_keep_data = false); void set_pause_mode(PauseMode p_mode); PauseMode get_pause_mode() const; @@ -368,25 +360,25 @@ public: static void print_stray_nodes(); #ifdef TOOLS_ENABLED - String validate_child_name(Node* p_child); + String validate_child_name(Node *p_child); #endif void queue_delete(); -//shitty hacks for speed + //shitty hacks for speed static void set_human_readable_collision_renaming(bool p_enabled); static void init_node_hrcr(); - void force_parent_owned() { data.parent_owned=true; } //hack to avoid duplicate nodes + void force_parent_owned() { data.parent_owned = true; } //hack to avoid duplicate nodes #ifdef TOOLS_ENABLED - void set_import_path(const NodePath& p_import_path); //path used when imported, used by scene editors to keep tracking + 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; #endif bool is_owned_by_parent() const; - void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; + void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const; void clear_internal_tree_resource_paths(); @@ -404,33 +396,30 @@ public: NetworkMode get_network_mode() const; bool is_network_master() const; - void rpc_config(const StringName& p_method,RPCMode p_mode); // config a local method for RPC - void rset_config(const StringName& p_property,RPCMode p_mode); // config a local property for RPC - - void rpc(const StringName& p_method,VARIANT_ARG_LIST); //rpc call, honors RPCMode - void rpc_unreliable(const StringName& p_method,VARIANT_ARG_LIST); //rpc call, honors RPCMode - void rpc_id(int p_peer_id,const StringName& p_method,VARIANT_ARG_LIST); //rpc call, honors RPCMode - void rpc_unreliable_id(int p_peer_id,const StringName& p_method,VARIANT_ARG_LIST); //rpc call, honors RPCMode + void rpc_config(const StringName &p_method, RPCMode p_mode); // config a local method for RPC + void rset_config(const StringName &p_property, RPCMode p_mode); // config a local property for RPC - void rpcp(int p_peer_id,bool p_unreliable,const StringName& p_method,const Variant** p_arg,int p_argcount); + void rpc(const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode + void rpc_unreliable(const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode + void rpc_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode + void rpc_unreliable_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode - void rset(const StringName& p_property, const Variant& p_value); //remote set call, honors RPCMode - void rset_unreliable(const StringName& p_property,const Variant& p_value); //remote set call, honors RPCMode - void rset_id(int p_peer_id,const StringName& p_property,const Variant& p_value); //remote set call, honors RPCMode - void rset_unreliable_id(int p_peer_id,const StringName& p_property,const Variant& p_value); //remote set call, honors RPCMode + void rpcp(int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount); - void rsetp(int p_peer_id,bool p_unreliable,const StringName& p_property,const Variant& p_value); + void rset(const StringName &p_property, const Variant &p_value); //remote set call, honors RPCMode + void rset_unreliable(const StringName &p_property, const Variant &p_value); //remote set call, honors RPCMode + void rset_id(int p_peer_id, const StringName &p_property, const Variant &p_value); //remote set call, honors RPCMode + void rset_unreliable_id(int p_peer_id, const StringName &p_property, const Variant &p_value); //remote set call, honors RPCMode - bool can_call_rpc(const StringName& p_method) const; - bool can_call_rset(const StringName& p_property) const; + void rsetp(int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value); + bool can_call_rpc(const StringName &p_method) const; + bool can_call_rset(const StringName &p_property) const; Node(); ~Node(); }; - -typedef Set<Node*,Node::Comparator> NodeSet; - +typedef Set<Node *, Node::Comparator> NodeSet; #endif |