summaryrefslogtreecommitdiff
path: root/scene/resources/packed_scene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/packed_scene.cpp')
-rw-r--r--scene/resources/packed_scene.cpp65
1 files changed, 34 insertions, 31 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 3df9285bb6..f034e07ff9 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -31,6 +31,7 @@
#include "packed_scene.h"
#include "core/core_string_names.h"
+#include "engine.h"
#include "io/resource_loader.h"
#include "project_settings.h"
#include "scene/2d/node_2d.h"
@@ -105,7 +106,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (i == 0 && base_scene_idx >= 0) {
//scene inheritance on root node
- //print_line("scene inherit");
Ref<PackedScene> sdata = props[base_scene_idx];
ERR_FAIL_COND_V(!sdata.is_valid(), NULL);
node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); //only main gets main edit state
@@ -116,7 +116,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
} else if (n.instance >= 0) {
//instance a scene into this node
- //print_line("instance");
if (n.instance & FLAG_INSTANCE_IS_PLACEHOLDER) {
String path = props[n.instance & FLAG_MASK];
@@ -140,7 +139,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
}
} else if (n.type == TYPE_INSTANCED) {
- //print_line("instanced");
//get the node from somewhere, it likely already exists from another instance
if (parent) {
node = parent->_get_child_by_name(snames[n.name]);
@@ -151,7 +149,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
#endif
}
} else if (ClassDB::is_class_enabled(snames[n.type])) {
- //print_line("created");
//node belongs to this scene and must be created
Object *obj = ClassDB::instance(snames[n.type]);
if (!Object::cast_to<Node>(obj)) {
@@ -249,6 +246,8 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
//must make a copy, because this res is local to scene
}
}
+ } else if (p_edit_state == GEN_EDIT_STATE_INSTANCE) {
+ value = value.duplicate(true); // Duplicate arrays and dictionaries for the editor
}
node->set(snames[nprops[j].name], value, &valid);
}
@@ -277,7 +276,12 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
stray_instances.push_back(node); //can't be added, go to stray list
}
} else {
- node->_set_name_nocheck(snames[n.name]);
+ if (Engine::get_singleton()->is_editor_hint()) {
+ //validate name if using editor, to avoid broken
+ node->set_name(snames[n.name]);
+ } else {
+ node->_set_name_nocheck(snames[n.name]);
+ }
}
}
@@ -323,7 +327,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (c.binds.size()) {
binds.resize(c.binds.size());
for (int j = 0; j < c.binds.size(); j++)
- binds[j] = props[c.binds[j]];
+ binds.write[j] = props[c.binds[j]];
}
cfrom->connect(snames[c.signal], cto, snames[c.method], binds, CONNECT_PERSIST | c.flags);
@@ -387,7 +391,15 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
nd.name = _nm_get_string(p_node->get_name(), name_map);
nd.instance = -1; //not instanced by default
- nd.index = p_node->get_index();
+
+ //really convoluted condition, but it basically checks that index is only saved when part of an inherited scene OR the node parent is from the edited scene
+ if (p_owner->get_scene_inherited_state().is_null() && (p_node == p_owner || (p_node->get_owner() == p_owner && (p_node->get_parent() == p_owner || p_node->get_parent()->get_owner() == p_owner)))) {
+ //do not save index, because it belongs to saved scene and scene is not inherited
+ nd.index = -1;
+ } else {
+ //part of an inherited scene, or parent is from an instanced scene
+ nd.index = p_node->get_index();
+ }
// if this node is part of an instanced scene or sub-instanced scene
// we need to get the corresponding instance states.
@@ -475,15 +487,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
if (E->get().usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) {
isdefault = true; //is script default value
}
- /*
- if (nd.instance<0 && ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO) && value.is_zero()) || ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONONE) && value.is_one())) {
- continue;
- }
- */
-
- //print_line("PASSED!");
- //print_line("at: "+String(p_node->get_name())+"::"+name+": - nz: "+itos(E->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO)+" no: "+itos(E->get().usage&PROPERTY_USAGE_STORE_IF_NONONE));
- //print_line("value: "+String(value)+" is zero: "+itos(value.is_zero())+" is one" +itos(value.is_one()));
if (pack_state_stack.size()) {
// we are on part of an instanced subscene
@@ -873,7 +876,7 @@ Error SceneState::pack(Node *p_scene) {
for (Map<StringName, int>::Element *E = name_map.front(); E; E = E->next()) {
- names[E->get()] = E->key();
+ names.write[E->get()] = E->key();
}
variants.resize(variant_map.size());
@@ -881,13 +884,13 @@ Error SceneState::pack(Node *p_scene) {
while ((K = variant_map.next(K))) {
int idx = variant_map[*K];
- variants[idx] = *K;
+ variants.write[idx] = *K;
}
node_paths.resize(nodepath_map.size());
for (Map<Node *, int>::Element *E = nodepath_map.front(); E; E = E->next()) {
- node_paths[E->get()] = scene->get_path_to(E->key());
+ node_paths.write[E->get()] = scene->get_path_to(E->key());
}
return OK;
@@ -1088,7 +1091,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
names.resize(namecount);
PoolVector<String>::Read r = snames.read();
for (int i = 0; i < names.size(); i++)
- names[i] = r[i];
+ names.write[i] = r[i];
}
Array svariants = p_dictionary["variants"];
@@ -1098,7 +1101,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
variants.resize(varcount);
for (int i = 0; i < varcount; i++) {
- variants[i] = svariants[i];
+ variants.write[i] = svariants[i];
}
} else {
@@ -1112,7 +1115,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
PoolVector<int>::Read r = snodes.read();
int idx = 0;
for (int i = 0; i < nc; i++) {
- NodeData &nd = nodes[i];
+ NodeData &nd = nodes.write[i];
nd.parent = r[idx++];
nd.owner = r[idx++];
nd.type = r[idx++];
@@ -1124,13 +1127,13 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
nd.properties.resize(r[idx++]);
for (int j = 0; j < nd.properties.size(); j++) {
- nd.properties[j].name = r[idx++];
- nd.properties[j].value = r[idx++];
+ nd.properties.write[j].name = r[idx++];
+ nd.properties.write[j].value = r[idx++];
}
nd.groups.resize(r[idx++]);
for (int j = 0; j < nd.groups.size(); j++) {
- nd.groups[j] = r[idx++];
+ nd.groups.write[j] = r[idx++];
}
}
}
@@ -1144,7 +1147,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
PoolVector<int>::Read r = sconns.read();
int idx = 0;
for (int i = 0; i < cc; i++) {
- ConnectionData &cd = connections[i];
+ ConnectionData &cd = connections.write[i];
cd.from = r[idx++];
cd.to = r[idx++];
cd.signal = r[idx++];
@@ -1154,7 +1157,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
for (int j = 0; j < cd.binds.size(); j++) {
- cd.binds[j] = r[idx++];
+ cd.binds.write[j] = r[idx++];
}
}
}
@@ -1165,7 +1168,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
}
node_paths.resize(np.size());
for (int i = 0; i < np.size(); i++) {
- node_paths[i] = np[i];
+ node_paths.write[i] = np[i];
}
Array ei;
@@ -1179,7 +1182,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
editable_instances.resize(ei.size());
for (int i = 0; i < editable_instances.size(); i++) {
- editable_instances[i] = ei[i];
+ editable_instances.write[i] = ei[i];
}
//path=p_dictionary["path"];
@@ -1561,13 +1564,13 @@ void SceneState::add_node_property(int p_node, int p_name, int p_value) {
NodeData::Property prop;
prop.name = p_name;
prop.value = p_value;
- nodes[p_node].properties.push_back(prop);
+ nodes.write[p_node].properties.push_back(prop);
}
void SceneState::add_node_group(int p_node, int p_group) {
ERR_FAIL_INDEX(p_node, nodes.size());
ERR_FAIL_INDEX(p_group, names.size());
- nodes[p_node].groups.push_back(p_group);
+ nodes.write[p_node].groups.push_back(p_group);
}
void SceneState::set_base_scene(int p_idx) {