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.cpp99
1 files changed, 65 insertions, 34 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index ba2cdf75e4..058e89cf2e 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -64,13 +64,15 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
const StringName *snames = nullptr;
int sname_count = names.size();
- if (sname_count)
+ if (sname_count) {
snames = &names[0];
+ }
const Variant *props = nullptr;
int prop_count = variants.size();
- if (prop_count)
+ if (prop_count) {
props = &variants[0];
+ }
//Vector<Variant> properties;
@@ -256,8 +258,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (i > 0) {
if (parent) {
parent->_add_child_nocheck(node, snames[n.name]);
- if (n.index >= 0 && n.index < parent->get_child_count() - 1)
+ if (n.index >= 0 && n.index < parent->get_child_count() - 1) {
parent->move_child(node, n.index);
+ }
} else {
//it may be possible that an instanced scene has changed
//and the node has nowhere to go anymore
@@ -275,8 +278,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (n.owner >= 0) {
NODE_FROM_ID(owner, n.owner);
- if (owner)
+ if (owner) {
node->_set_owner_nocheck(owner);
+ }
}
}
@@ -305,14 +309,16 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
NODE_FROM_ID(cfrom, c.from);
NODE_FROM_ID(cto, c.to);
- if (!cfrom || !cto)
+ if (!cfrom || !cto) {
continue;
+ }
Vector<Variant> binds;
if (c.binds.size()) {
binds.resize(c.binds.size());
- for (int j = 0; j < c.binds.size(); j++)
+ for (int j = 0; j < c.binds.size(); j++) {
binds.write[j] = props[c.binds[j]];
+ }
}
cfrom->connect(snames[c.signal], Callable(cto, snames[c.method]), binds, CONNECT_PERSIST | c.flags);
@@ -337,8 +343,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
}
static int _nm_get_string(const String &p_string, Map<StringName, int> &name_map) {
- if (name_map.has(p_string))
+ if (name_map.has(p_string)) {
return name_map[p_string];
+ }
int idx = name_map.size();
name_map[p_string] = idx;
@@ -346,8 +353,9 @@ static int _nm_get_string(const String &p_string, Map<StringName, int> &name_map
}
static int _vm_get_variant(const Variant &p_variant, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map) {
- if (variant_map.has(p_variant))
+ if (variant_map.has(p_variant)) {
return variant_map[p_variant];
+ }
int idx = variant_map.size();
variant_map[p_variant] = idx;
@@ -361,13 +369,15 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
// document it. if you fail to understand something, please ask!
//discard nodes that do not belong to be processed
- if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner()))
+ if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) {
return OK;
+ }
// save the child instanced scenes that are chosen as editable, so they can be restored
// upon load back
- if (p_node != p_owner && p_node->get_filename() != String() && p_owner->is_editable_instance(p_node))
+ if (p_node != p_owner && p_node->get_filename() != String() && p_owner->is_editable_instance(p_node)) {
editable_instances.push_back(p_owner->get_path_to(p_node));
+ }
NodeData nd;
@@ -513,8 +523,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
float a = value;
float b = original;
- if (Math::is_equal_approx(a, b))
+ if (Math::is_equal_approx(a, b)) {
continue;
+ }
} else if (bool(Variant::evaluate(Variant::OP_EQUAL, value, original))) {
continue;
}
@@ -547,8 +558,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
for (List<Node::GroupInfo>::Element *E = groups.front(); E; E = E->next()) {
Node::GroupInfo &gi = E->get();
- if (!gi.persistent)
+ if (!gi.persistent) {
continue;
+ }
/*
if (instance_state_node>=0 && instance_state->is_node_in_group(instance_state_node,gi.name))
continue; //group was instanced, don't add here
@@ -564,8 +576,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
}
}
- if (skip)
+ if (skip) {
continue;
+ }
nd.groups.push_back(_nm_get_string(gi.name, name_map));
}
@@ -636,16 +649,18 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
Error err = _parse_node(p_owner, c, parent_node, name_map, variant_map, node_map, nodepath_map);
- if (err)
+ if (err) {
return err;
+ }
}
return OK;
}
Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName, int> &name_map, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map, Map<Node *, int> &node_map, Map<Node *, int> &nodepath_map) {
- if (p_node != p_owner && p_node->get_owner() && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner()))
+ if (p_node != p_owner && p_node->get_owner() && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) {
return OK;
+ }
List<MethodInfo> _signals;
p_node->get_signal_list(&_signals);
@@ -663,8 +678,9 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
for (List<Node::Connection>::Element *F = conns.front(); F; F = F->next()) {
const Node::Connection &c = F->get();
- if (!(c.flags & CONNECT_PERSIST)) //only persistent connections get saved
+ if (!(c.flags & CONNECT_PERSIST)) { //only persistent connections get saved
continue;
+ }
// only connections that originate or end into main saved scene are saved
// everything else is discarded
@@ -690,10 +706,11 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
while (common_parent) {
Ref<SceneState> ps;
- if (common_parent == p_owner)
+ if (common_parent == p_owner) {
ps = common_parent->get_scene_inherited_state();
- else
+ } else {
ps = common_parent->get_scene_instance_state();
+ }
if (ps.is_valid()) {
NodePath signal_from = common_parent->get_path_to(p_node);
@@ -705,10 +722,11 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
}
}
- if (common_parent == p_owner)
+ if (common_parent == p_owner) {
break;
- else
+ } else {
common_parent = common_parent->get_owner();
+ }
}
if (exists) { //already exists (comes from instance or inheritance), so don't save
@@ -807,8 +825,9 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
Error err = _parse_connections(p_owner, c, name_map, variant_map, node_map, nodepath_map);
- if (err)
+ if (err) {
return err;
+ }
}
return OK;
@@ -973,8 +992,9 @@ bool SceneState::is_node_in_group(int p_node, const StringName &p_group) const {
if (p_node < nodes.size()) {
const StringName *namep = names.ptr();
for (int i = 0; i < nodes[p_node].groups.size(); i++) {
- if (namep[nodes[p_node].groups[i]] == p_group)
+ if (namep[nodes[p_node].groups[i]] == p_group) {
return true;
+ }
}
}
@@ -1034,8 +1054,9 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
//ERR_FAIL_COND( !p_dictionary.has("path"));
int version = 1;
- if (p_dictionary.has("version"))
+ if (p_dictionary.has("version")) {
version = p_dictionary["version"];
+ }
ERR_FAIL_COND_MSG(version > PACKED_SCENE_VERSION, "Save format version too new.");
@@ -1052,8 +1073,9 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
int namecount = snames.size();
names.resize(namecount);
const String *r = snames.ptr();
- for (int i = 0; i < names.size(); i++)
+ for (int i = 0; i < names.size(); i++) {
names.write[i] = r[i];
+ }
}
Array svariants = p_dictionary["variants"];
@@ -1147,8 +1169,9 @@ Dictionary SceneState::get_bundled_scene() const {
if (names.size()) {
String *r = rnames.ptrw();
- for (int i = 0; i < names.size(); i++)
+ for (int i = 0; i < names.size(); i++) {
r[i] = names[i];
+ }
}
Dictionary d;
@@ -1193,8 +1216,9 @@ Dictionary SceneState::get_bundled_scene() const {
rconns.push_back(cd.method);
rconns.push_back(cd.flags);
rconns.push_back(cd.binds.size());
- for (int j = 0; j < cd.binds.size(); j++)
+ for (int j = 0; j < cd.binds.size(); j++) {
rconns.push_back(cd.binds[j]);
+ }
}
d["conns"] = rconns;
@@ -1227,8 +1251,9 @@ int SceneState::get_node_count() const {
StringName SceneState::get_node_type(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, nodes.size(), StringName());
- if (nodes[p_idx].type == TYPE_INSTANCED)
+ if (nodes[p_idx].type == TYPE_INSTANCED) {
return StringName();
+ }
return names[nodes[p_idx].type];
}
@@ -1252,10 +1277,11 @@ Ref<PackedScene> SceneState::get_node_instance(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, nodes.size(), Ref<PackedScene>());
if (nodes[p_idx].instance >= 0) {
- if (nodes[p_idx].instance & FLAG_INSTANCE_IS_PLACEHOLDER)
+ if (nodes[p_idx].instance & FLAG_INSTANCE_IS_PLACEHOLDER) {
return Ref<PackedScene>();
- else
+ } else {
return variants[nodes[p_idx].instance & FLAG_MASK];
+ }
} else if (nodes[p_idx].parent < 0 || nodes[p_idx].parent == NO_PARENT_SAVED) {
if (base_scene_idx >= 0) {
return variants[base_scene_idx];
@@ -1347,8 +1373,9 @@ Variant SceneState::get_node_property_value(int p_idx, int p_prop) const {
NodePath SceneState::get_node_owner_path(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, nodes.size(), NodePath());
- if (nodes[p_idx].owner < 0 || nodes[p_idx].owner == NO_PARENT_SAVED)
+ if (nodes[p_idx].owner < 0 || nodes[p_idx].owner == NO_PARENT_SAVED) {
return NodePath(); //root likely
+ }
if (nodes[p_idx].owner & FLAG_ID_IS_PATH) {
return node_paths[nodes[p_idx].owner & FLAG_MASK];
} else {
@@ -1453,8 +1480,9 @@ int SceneState::add_name(const StringName &p_name) {
int SceneState::find_name(const StringName &p_name) const {
for (int i = 0; i < names.size(); i++) {
- if (names[i] == p_name)
+ if (names[i] == p_name) {
return i;
+ }
}
return -1;
@@ -1531,8 +1559,9 @@ Vector<String> SceneState::_get_node_groups(int p_idx) const {
Vector<StringName> groups = get_node_groups(p_idx);
Vector<String> ret;
- for (int i = 0; i < groups.size(); i++)
+ for (int i = 0; i < groups.size(); i++) {
ret.push_back(groups[i]);
+ }
return ret;
}
@@ -1599,15 +1628,17 @@ Node *PackedScene::instance(GenEditState p_edit_state) const {
#endif
Node *s = state->instance((SceneState::GenEditState)p_edit_state);
- if (!s)
+ if (!s) {
return nullptr;
+ }
if (p_edit_state != GEN_EDIT_STATE_DISABLED) {
s->set_scene_instance_state(state);
}
- if (get_path() != "" && get_path().find("::") == -1)
+ if (get_path() != "" && get_path().find("::") == -1) {
s->set_filename(get_path());
+ }
s->notification(Node::NOTIFICATION_INSTANCED);