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.cpp78
1 files changed, 39 insertions, 39 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 0538f679cc..633771506e 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -35,7 +35,7 @@
#include "core/io/resource_loader.h"
#include "core/project_settings.h"
#include "scene/2d/node_2d.h"
-#include "scene/3d/spatial.h"
+#include "scene/3d/node_3d.h"
#include "scene/gui/control.h"
#include "scene/main/instance_placeholder.h"
@@ -51,25 +51,25 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
// nodes where instancing failed (because something is missing)
List<Node *> stray_instances;
-#define NODE_FROM_ID(p_name, p_id) \
- Node *p_name; \
- if (p_id & FLAG_ID_IS_PATH) { \
- NodePath np = node_paths[p_id & FLAG_MASK]; \
- p_name = ret_nodes[0]->get_node_or_null(np); \
- } else { \
- ERR_FAIL_INDEX_V(p_id &FLAG_MASK, nc, NULL); \
- p_name = ret_nodes[p_id & FLAG_MASK]; \
+#define NODE_FROM_ID(p_name, p_id) \
+ Node *p_name; \
+ if (p_id & FLAG_ID_IS_PATH) { \
+ NodePath np = node_paths[p_id & FLAG_MASK]; \
+ p_name = ret_nodes[0]->get_node_or_null(np); \
+ } else { \
+ ERR_FAIL_INDEX_V(p_id &FLAG_MASK, nc, nullptr); \
+ p_name = ret_nodes[p_id & FLAG_MASK]; \
}
int nc = nodes.size();
- ERR_FAIL_COND_V(nc == 0, NULL);
+ ERR_FAIL_COND_V(nc == 0, nullptr);
- const StringName *snames = NULL;
+ const StringName *snames = nullptr;
int sname_count = names.size();
if (sname_count)
snames = &names[0];
- const Variant *props = NULL;
+ const Variant *props = nullptr;
int prop_count = variants.size();
if (prop_count)
props = &variants[0];
@@ -82,17 +82,17 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
bool gen_node_path_cache = p_edit_state != GEN_EDIT_STATE_DISABLED && node_path_cache.empty();
- Map<Ref<Resource>, Ref<Resource> > resources_local_to_scene;
+ Map<Ref<Resource>, Ref<Resource>> resources_local_to_scene;
for (int i = 0; i < nc; i++) {
const NodeData &n = nd[i];
- Node *parent = NULL;
+ Node *parent = nullptr;
if (i > 0) {
- ERR_FAIL_COND_V_MSG(n.parent == -1, NULL, vformat("Invalid scene: node %s does not specify its parent node.", snames[n.name]));
+ ERR_FAIL_COND_V_MSG(n.parent == -1, nullptr, vformat("Invalid scene: node %s does not specify its parent node.", snames[n.name]));
NODE_FROM_ID(nparent, n.parent);
#ifdef DEBUG_ENABLED
if (!nparent && (n.parent & FLAG_ID_IS_PATH)) {
@@ -103,14 +103,14 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
parent = nparent;
}
- Node *node = NULL;
+ Node *node = nullptr;
if (i == 0 && base_scene_idx >= 0) {
//scene inheritance on root node
Ref<PackedScene> sdata = props[base_scene_idx];
- ERR_FAIL_COND_V(!sdata.is_valid(), NULL);
+ ERR_FAIL_COND_V(!sdata.is_valid(), nullptr);
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
- ERR_FAIL_COND_V(!node, NULL);
+ ERR_FAIL_COND_V(!node, nullptr);
if (p_edit_state != GEN_EDIT_STATE_DISABLED) {
node->set_scene_inherited_state(sdata->get_state());
}
@@ -123,9 +123,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (disable_placeholders) {
Ref<PackedScene> sdata = ResourceLoader::load(path, "PackedScene");
- ERR_FAIL_COND_V(!sdata.is_valid(), NULL);
+ ERR_FAIL_COND_V(!sdata.is_valid(), nullptr);
node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE);
- ERR_FAIL_COND_V(!node, NULL);
+ ERR_FAIL_COND_V(!node, nullptr);
} else {
InstancePlaceholder *ip = memnew(InstancePlaceholder);
ip->set_instance_path(path);
@@ -134,9 +134,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
node->set_scene_instance_load_placeholder(true);
} else {
Ref<PackedScene> sdata = props[n.instance & FLAG_MASK];
- ERR_FAIL_COND_V(!sdata.is_valid(), NULL);
+ ERR_FAIL_COND_V(!sdata.is_valid(), nullptr);
node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE);
- ERR_FAIL_COND_V(!node, NULL);
+ ERR_FAIL_COND_V(!node, nullptr);
}
} else if (n.type == TYPE_INSTANCED) {
@@ -155,12 +155,12 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (!Object::cast_to<Node>(obj)) {
if (obj) {
memdelete(obj);
- obj = NULL;
+ obj = nullptr;
}
WARN_PRINT(String("Warning node of type " + snames[n.type].operator String() + " does not exist.").ascii().get_data());
if (n.parent >= 0 && n.parent < nc && ret_nodes[n.parent]) {
- if (Object::cast_to<Spatial>(ret_nodes[n.parent])) {
- obj = memnew(Spatial);
+ if (Object::cast_to<Node3D>(ret_nodes[n.parent])) {
+ obj = memnew(Node3D);
} else if (Object::cast_to<Control>(ret_nodes[n.parent])) {
obj = memnew(Control);
} else if (Object::cast_to<Node2D>(ret_nodes[n.parent])) {
@@ -193,15 +193,15 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
for (int j = 0; j < nprop_count; j++) {
bool valid;
- ERR_FAIL_INDEX_V(nprops[j].name, sname_count, NULL);
- ERR_FAIL_INDEX_V(nprops[j].value, prop_count, NULL);
+ ERR_FAIL_INDEX_V(nprops[j].name, sname_count, nullptr);
+ ERR_FAIL_INDEX_V(nprops[j].value, prop_count, nullptr);
if (snames[nprops[j].name] == CoreStringNames::get_singleton()->_script) {
//work around to avoid old script variables from disappearing, should be the proper fix to:
//https://github.com/godotengine/godot/issues/2958
//store old state
- List<Pair<StringName, Variant> > old_state;
+ List<Pair<StringName, Variant>> old_state;
if (node->get_script_instance()) {
node->get_script_instance()->get_property_state(old_state);
}
@@ -209,7 +209,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
node->set(snames[nprops[j].name], props[nprops[j].value], &valid);
//restore old state for new script, if exists
- for (List<Pair<StringName, Variant> >::Element *E = old_state.front(); E; E = E->next()) {
+ for (List<Pair<StringName, Variant>>::Element *E = old_state.front(); E; E = E->next()) {
node->set(E->get().first, E->get().second);
}
} else {
@@ -222,7 +222,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (res.is_valid()) {
if (res->is_local_to_scene()) {
- Map<Ref<Resource>, Ref<Resource> >::Element *E = resources_local_to_scene.find(res);
+ Map<Ref<Resource>, Ref<Resource>>::Element *E = resources_local_to_scene.find(res);
if (E) {
value = E->get();
@@ -260,7 +260,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
//groups
for (int j = 0; j < n.groups.size(); j++) {
- ERR_FAIL_INDEX_V(n.groups[j], sname_count, NULL);
+ ERR_FAIL_INDEX_V(n.groups[j], sname_count, nullptr);
node->add_to_group(snames[n.groups[j]], true);
}
@@ -302,7 +302,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
}
}
- for (Map<Ref<Resource>, Ref<Resource> >::Element *E = resources_local_to_scene.front(); E; E = E->next()) {
+ for (Map<Ref<Resource>, Ref<Resource>>::Element *E = resources_local_to_scene.front(); E; E = E->next()) {
E->get()->setup_local_to_scene();
}
@@ -315,8 +315,8 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
for (int i = 0; i < cc; i++) {
const ConnectionData &c = cdata[i];
- //ERR_FAIL_INDEX_V( c.from, nc, NULL );
- //ERR_FAIL_INDEX_V( c.to, nc, NULL );
+ //ERR_FAIL_INDEX_V( c.from, nc, nullptr );
+ //ERR_FAIL_INDEX_V( c.to, nc, nullptr );
NODE_FROM_ID(cfrom, c.from);
NODE_FROM_ID(cto, c.to);
@@ -450,7 +450,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
nd.instance = _vm_get_variant(instance, variant_map);
}
}
- n = NULL;
+ n = nullptr;
} else {
if (n->get_filename() != String()) {
//is an instance
@@ -773,7 +773,7 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
}
}
- nl = NULL;
+ nl = nullptr;
} else {
if (nl->get_filename() != String()) {
//is an instance
@@ -896,7 +896,7 @@ Error SceneState::pack(Node *p_scene) {
}
variants.resize(variant_map.size());
- const Variant *K = NULL;
+ const Variant *K = nullptr;
while ((K = variant_map.next(K))) {
int idx = variant_map[*K];
@@ -1689,12 +1689,12 @@ bool PackedScene::can_instance() const {
Node *PackedScene::instance(GenEditState p_edit_state) const {
#ifndef TOOLS_ENABLED
- ERR_FAIL_COND_V_MSG(p_edit_state != GEN_EDIT_STATE_DISABLED, NULL, "Edit state is only for editors, does not work without tools compiled.");
+ ERR_FAIL_COND_V_MSG(p_edit_state != GEN_EDIT_STATE_DISABLED, nullptr, "Edit state is only for editors, does not work without tools compiled.");
#endif
Node *s = state->instance((SceneState::GenEditState)p_edit_state);
if (!s)
- return NULL;
+ return nullptr;
if (p_edit_state != GEN_EDIT_STATE_DISABLED) {
s->set_scene_instance_state(state);