summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorreduz <juan@okamstudio.com>2015-10-10 09:09:09 -0300
committerreduz <juan@okamstudio.com>2015-10-10 09:09:09 -0300
commit422929e87fbe91be1efedf1fe3a9a71d61e58b40 (patch)
treea9a7d1862505f06b41b6f8c5fe96bd0012c93d29 /scene/main
parentafbb0ca8d7d978f27c62271273a1a6bc866a73ce (diff)
Large improvements on scene packing and management
-Ability to edit and keep changes of instanced scenes and sub-scenes -Ability to inherit from other scenes
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/node.cpp64
-rw-r--r--scene/main/node.h27
2 files changed, 83 insertions, 8 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 8336ce35f6..b02e9c5645 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -841,6 +841,20 @@ Node *Node::get_child(int p_index) const {
return data.children[p_index];
}
+
+Node *Node::_get_child_by_name(const StringName& p_name) const {
+
+ int cc=data.children.size();
+ Node* const* cd=data.children.ptr();
+
+ for(int i=0;i<cc;i++){
+ if (cd[i]->data.name==p_name)
+ return cd[i];
+ }
+
+ return NULL;
+}
+
Node *Node::_get_node(const NodePath& p_path) const {
ERR_FAIL_COND_V( !data.inside_tree && p_path.is_absolute(), NULL );
@@ -906,8 +920,10 @@ Node *Node::_get_node(const NodePath& p_path) const {
Node *Node::get_node(const NodePath& p_path) const {
Node *node = _get_node(p_path);
- ERR_EXPLAIN("Node not found: "+p_path);
- ERR_FAIL_COND_V(!node,NULL);
+ if (!node) {
+ ERR_EXPLAIN("Node not found: "+p_path);
+ ERR_FAIL_COND_V(!node,NULL);
+ }
return node;
}
@@ -1332,7 +1348,29 @@ String Node::get_filename() const {
return data.filename;
}
+void Node::set_editable_instance(Node* p_node,bool p_editable) {
+
+ ERR_FAIL_NULL(p_node);
+ ERR_FAIL_COND(!is_a_parent_of(p_node));
+ NodePath p = get_path_to(p_node);
+ if (!p_editable)
+ data.editable_instances.erase(p);
+ else
+ data.editable_instances[p]=true;
+}
+
+bool Node::is_editable_instance(Node *p_node) const {
+
+ if (!p_node)
+ return false; //easier, null is never editable :)
+ ERR_FAIL_COND_V(!is_a_parent_of(p_node),false);
+ NodePath p = get_path_to(p_node);
+ return data.editable_instances.has(p);
+}
+
+
+#if 0
void Node::generate_instance_state() {
@@ -1383,6 +1421,28 @@ Dictionary Node::get_instance_state() const {
return data.instance_state;
}
+#endif
+
+void Node::set_scene_instance_state(const Ref<SceneState>& p_state) {
+
+ data.instance_state=p_state;
+}
+
+Ref<SceneState> Node::get_scene_instance_state() const{
+
+ return data.instance_state;
+}
+
+void Node::set_scene_inherited_state(const Ref<SceneState>& p_state) {
+
+ data.inherited_state=p_state;
+}
+
+Ref<SceneState> Node::get_scene_inherited_state() const{
+
+ return data.inherited_state;
+}
+
Vector<StringName> Node::get_instance_groups() const {
return data.instance_groups;
diff --git a/scene/main/node.h b/scene/main/node.h
index a6d5bfbd9f..55557c6356 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -38,6 +38,7 @@
class Viewport;
+class SceneState;
class Node : public Object {
OBJ_TYPE( Node, Object );
@@ -69,7 +70,11 @@ private:
struct Data {
String filename;
- Dictionary instance_state;
+ Ref<SceneState> instance_state;
+ Ref<SceneState> inherited_state;
+
+ HashMap<NodePath,int> editable_instances;
+
Vector<StringName> instance_groups;
Vector<Connection> instance_connections;
@@ -96,6 +101,7 @@ private:
PauseMode pause_mode;
Node *pause_owner;
// variables used to properly sort the node when processing, ignored otherwise
+ //should move all the stuff below to bits
bool fixed_process;
bool idle_process;
@@ -105,6 +111,7 @@ private:
bool parent_owned;
bool in_constructor;
+
} data;
@@ -112,6 +119,7 @@ private:
virtual bool _use_builtin_script() const { return true; }
Node *_get_node(const NodePath& p_path) const;
+ Node *_get_child_by_name(const StringName& p_name) const;
@@ -151,7 +159,7 @@ protected:
static void _bind_methods();
-friend class PackedScene;
+friend class SceneState;
void _add_child_nocheck(Node* p_child,const StringName& p_name);
void _set_owner_nocheck(Node* p_owner);
@@ -208,7 +216,7 @@ public:
struct GroupInfo {
- String name;
+ StringName name;
bool persistent;
};
@@ -229,7 +237,10 @@ public:
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;
+
/* NOTIFICATIONS */
void propagate_notification(int p_notification);
@@ -261,8 +272,12 @@ public:
//Node *clone_tree() const;
// used by editors, to save what has changed only
- void generate_instance_state();
- Dictionary get_instance_state() const;
+ 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;
+
Vector<StringName> get_instance_groups() const;
Vector<Connection> get_instance_connections() const;