2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* node.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2015-04-18 17:38:54 +00:00
|
|
|
/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef NODE_H
|
|
|
|
#define NODE_H
|
|
|
|
|
|
|
|
#include "object.h"
|
|
|
|
#include "path_db.h"
|
|
|
|
#include "map.h"
|
|
|
|
#include "object_type_db.h"
|
|
|
|
#include "script_language.h"
|
|
|
|
#include "scene/main/scene_main_loop.h"
|
|
|
|
|
|
|
|
|
2014-04-10 03:18:27 +00:00
|
|
|
class Viewport;
|
2014-02-10 01:10:30 +00:00
|
|
|
class Node : public Object {
|
|
|
|
|
|
|
|
OBJ_TYPE( Node, Object );
|
|
|
|
OBJ_CATEGORY("Nodes");
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum PauseMode {
|
|
|
|
|
|
|
|
PAUSE_MODE_INHERIT,
|
|
|
|
PAUSE_MODE_STOP,
|
|
|
|
PAUSE_MODE_PROCESS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Comparator {
|
|
|
|
|
|
|
|
bool operator()(const Node* p_a, const Node* p_b) const { return p_b->is_greater_than(p_a); }
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct GroupData {
|
|
|
|
|
|
|
|
bool persistent;
|
|
|
|
GroupData() { persistent=false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
|
|
|
|
String filename;
|
|
|
|
Dictionary instance_state;
|
|
|
|
Vector<StringName> instance_groups;
|
|
|
|
Vector<Connection> instance_connections;
|
|
|
|
|
|
|
|
Node *parent;
|
|
|
|
Node *owner;
|
|
|
|
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.
|
|
|
|
StringName name;
|
2014-11-06 00:20:42 +00:00
|
|
|
SceneTree *tree;
|
|
|
|
bool inside_tree;
|
2014-06-19 05:23:03 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
NodePath import_path; //path used when imported, used by scene editors to keep tracking
|
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-04-10 03:18:27 +00:00
|
|
|
Viewport *viewport;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
HashMap< StringName, GroupData,StringNameHasher> grouped;
|
|
|
|
List<Node*>::Element *OW; // owned element
|
|
|
|
List<Node*> owned;
|
|
|
|
|
|
|
|
PauseMode pause_mode;
|
|
|
|
Node *pause_owner;
|
|
|
|
// variables used to properly sort the node when processing, ignored otherwise
|
|
|
|
bool fixed_process;
|
|
|
|
bool idle_process;
|
|
|
|
|
|
|
|
bool input;
|
|
|
|
bool unhandled_input;
|
2014-04-10 03:18:27 +00:00
|
|
|
bool unhandled_key_input;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool parent_owned;
|
|
|
|
bool in_constructor;
|
|
|
|
} data;
|
|
|
|
|
|
|
|
|
|
|
|
void _print_tree(const Node *p_node);
|
|
|
|
|
|
|
|
virtual bool _use_builtin_script() const { return true; }
|
|
|
|
Node *_get_node(const NodePath& p_path) const;
|
|
|
|
|
|
|
|
|
2015-06-08 03:33:10 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _validate_child_name(Node *p_name);
|
|
|
|
|
|
|
|
void _propagate_reverse_notification(int p_notification);
|
|
|
|
void _propagate_deferred_notification(int p_notification, bool p_reverse);
|
2014-11-06 00:20:42 +00:00
|
|
|
void _propagate_enter_tree();
|
2014-02-10 01:10:30 +00:00
|
|
|
void _propagate_ready();
|
2014-11-06 00:20:42 +00:00
|
|
|
void _propagate_exit_tree();
|
2014-02-10 01:10:30 +00:00
|
|
|
void _propagate_validate_owner();
|
|
|
|
void _print_stray_nodes();
|
|
|
|
void _propagate_pause_owner(Node*p_owner);
|
|
|
|
Array _get_node_and_resource(const NodePath& p_path);
|
|
|
|
|
2015-05-10 18:45:33 +00:00
|
|
|
void _duplicate_signals(const Node* p_original,Node* p_copy) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const;
|
|
|
|
Array _get_children() const;
|
2014-06-16 13:22:26 +00:00
|
|
|
Array _get_groups() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
friend class SceneTree;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
void _set_tree(SceneTree *p_tree);
|
2014-02-10 01:10:30 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void _block() { data.blocked++; }
|
|
|
|
void _unblock() { data.blocked--; }
|
|
|
|
|
|
|
|
void _notification(int p_notification);
|
|
|
|
|
|
|
|
virtual void add_child_notify(Node *p_child);
|
|
|
|
virtual void remove_child_notify(Node *p_child);
|
2014-12-03 04:17:23 +00:00
|
|
|
virtual void move_child_notify(Node *p_child);
|
2015-04-09 03:49:48 +00:00
|
|
|
//void remove_and_delete_child(Node *p_child);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _propagate_replace_owner(Node *p_owner,Node* p_by_owner);
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
friend class PackedScene;
|
|
|
|
|
|
|
|
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
|
2014-11-06 00:20:42 +00:00
|
|
|
NOTIFICATION_ENTER_TREE=10,
|
|
|
|
NOTIFICATION_EXIT_TREE =11,
|
2014-02-10 01:10:30 +00:00
|
|
|
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_FIXED_PROCESS = 16,
|
|
|
|
NOTIFICATION_PROCESS = 17,
|
|
|
|
NOTIFICATION_PARENTED=18,
|
|
|
|
NOTIFICATION_UNPARENTED=19,
|
2015-05-04 21:30:57 +00:00
|
|
|
NOTIFICATION_INSTANCED=20,
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* NODE/TREE */
|
|
|
|
|
|
|
|
StringName get_name() const;
|
|
|
|
void set_name(const String& p_name);
|
|
|
|
|
|
|
|
void add_child(Node *p_child);
|
|
|
|
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;
|
2015-06-08 03:33:10 +00:00
|
|
|
Node* find_node(const String& p_mask,bool p_recursive=true,bool p_owned=true) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
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;
|
2014-11-06 00:20:42 +00:00
|
|
|
_FORCE_INLINE_ SceneTree *get_tree() const { ERR_FAIL_COND_V( !data.tree, NULL ); return data.tree; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
_FORCE_INLINE_ bool is_inside_tree() const { return data.inside_tree; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool is_a_parent_of(const Node *p_node) const;
|
|
|
|
bool is_greater_than(const Node *p_node) const;
|
|
|
|
|
|
|
|
NodePath get_path() const;
|
|
|
|
NodePath get_path_to(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;
|
|
|
|
|
|
|
|
struct GroupInfo {
|
|
|
|
|
|
|
|
String name;
|
|
|
|
bool persistent;
|
|
|
|
};
|
|
|
|
|
|
|
|
void get_groups(List<GroupInfo> *p_groups) const;
|
|
|
|
|
|
|
|
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 remove_and_skip();
|
|
|
|
int get_index() const;
|
|
|
|
|
|
|
|
void print_tree();
|
|
|
|
|
|
|
|
void set_filename(const String& p_filename);
|
|
|
|
String get_filename() const;
|
|
|
|
|
|
|
|
/* NOTIFICATIONS */
|
|
|
|
|
|
|
|
void propagate_notification(int p_notification);
|
|
|
|
|
|
|
|
/* PROCESSING */
|
|
|
|
void set_fixed_process(bool p_process);
|
|
|
|
float get_fixed_process_delta_time() const;
|
|
|
|
bool is_fixed_processing() const;
|
|
|
|
|
|
|
|
void set_process(bool p_process);
|
|
|
|
float get_process_delta_time() const;
|
|
|
|
bool is_processing() const;
|
|
|
|
|
|
|
|
|
|
|
|
void set_process_input(bool p_enable);
|
|
|
|
bool is_processing_input() const;
|
|
|
|
|
|
|
|
void set_process_unhandled_input(bool p_enable);
|
|
|
|
bool is_processing_unhandled_input() const;
|
|
|
|
|
2014-04-10 03:18:27 +00:00
|
|
|
void set_process_unhandled_key_input(bool p_enable);
|
|
|
|
bool is_processing_unhandled_key_input() const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int get_position_in_parent() const;
|
|
|
|
|
2015-08-02 15:29:37 +00:00
|
|
|
Node *duplicate(bool p_use_instancing=false) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const;
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//Node *clone_tree() const;
|
|
|
|
|
|
|
|
// used by editors, to save what has changed only
|
|
|
|
void generate_instance_state();
|
|
|
|
Dictionary get_instance_state() const;
|
|
|
|
Vector<StringName> get_instance_groups() const;
|
|
|
|
Vector<Connection> get_instance_connections() const;
|
|
|
|
|
|
|
|
static Vector<Variant> make_binds(VARIANT_ARG_LIST);
|
|
|
|
|
|
|
|
void replace_by(Node* p_node,bool p_keep_data=false);
|
|
|
|
|
|
|
|
void set_pause_mode(PauseMode p_mode);
|
|
|
|
PauseMode get_pause_mode() const;
|
|
|
|
bool can_process() const;
|
|
|
|
|
|
|
|
static void print_stray_nodes();
|
|
|
|
|
2015-08-02 15:29:37 +00:00
|
|
|
String validate_child_name(const String& p_name) const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void queue_delete();
|
|
|
|
|
2014-06-19 05:23:03 +00:00
|
|
|
//shitty hacks for speed
|
2014-02-22 23:28:19 +00:00
|
|
|
static void set_human_readable_collision_renaming(bool p_enabled);
|
|
|
|
static void init_node_hrcr();
|
|
|
|
|
2014-04-05 15:39:30 +00:00
|
|
|
void force_parent_owned() { data.parent_owned=true; } //hack to avoid duplicate nodes
|
|
|
|
|
2014-06-19 05:23:03 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
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
|
|
|
|
|
2014-12-17 01:31:57 +00:00
|
|
|
void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
|
2014-06-19 05:23:03 +00:00
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
void clear_internal_tree_resource_paths();
|
|
|
|
|
2014-04-10 03:18:27 +00:00
|
|
|
_FORCE_INLINE_ Viewport *get_viewport() const { return data.viewport; }
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* CANVAS */
|
|
|
|
|
|
|
|
Node();
|
|
|
|
~Node();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef Set<Node*,Node::Comparator> NodeSet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|