|
@@ -34,10 +34,12 @@
|
|
#include "core/engine.h"
|
|
#include "core/engine.h"
|
|
#include "core/io/resource_loader.h"
|
|
#include "core/io/resource_loader.h"
|
|
#include "core/project_settings.h"
|
|
#include "core/project_settings.h"
|
|
|
|
+#include "editor/editor_inspector.h"
|
|
#include "scene/2d/node_2d.h"
|
|
#include "scene/2d/node_2d.h"
|
|
#include "scene/3d/spatial.h"
|
|
#include "scene/3d/spatial.h"
|
|
#include "scene/gui/control.h"
|
|
#include "scene/gui/control.h"
|
|
#include "scene/main/instance_placeholder.h"
|
|
#include "scene/main/instance_placeholder.h"
|
|
|
|
+#include "scene/property_utils.h"
|
|
|
|
|
|
#define PACKED_SCENE_VERSION 2
|
|
#define PACKED_SCENE_VERSION 2
|
|
|
|
|
|
@@ -413,61 +415,22 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
|
|
// with the instance states, we can query for identical properties/groups
|
|
// with the instance states, we can query for identical properties/groups
|
|
// and only save what has changed
|
|
// and only save what has changed
|
|
|
|
|
|
- List<PackState> pack_state_stack;
|
|
|
|
-
|
|
|
|
- bool instanced_by_owner = true;
|
|
|
|
-
|
|
|
|
- {
|
|
|
|
- Node *n = p_node;
|
|
|
|
-
|
|
|
|
- while (n) {
|
|
|
|
- if (n == p_owner) {
|
|
|
|
- Ref<SceneState> state = n->get_scene_inherited_state();
|
|
|
|
- if (state.is_valid()) {
|
|
|
|
- int node = state->find_node_by_path(n->get_path_to(p_node));
|
|
|
|
- if (node >= 0) {
|
|
|
|
- //this one has state for this node, save
|
|
|
|
- PackState ps;
|
|
|
|
- ps.node = node;
|
|
|
|
- ps.state = state;
|
|
|
|
- pack_state_stack.push_back(ps);
|
|
|
|
- instanced_by_owner = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (p_node->get_filename() != String() && p_node->get_owner() == p_owner && instanced_by_owner) {
|
|
|
|
- if (p_node->get_scene_instance_load_placeholder()) {
|
|
|
|
- //it's a placeholder, use the placeholder path
|
|
|
|
- nd.instance = _vm_get_variant(p_node->get_filename(), variant_map);
|
|
|
|
- nd.instance |= FLAG_INSTANCE_IS_PLACEHOLDER;
|
|
|
|
- } else {
|
|
|
|
- //must instance ourselves
|
|
|
|
- Ref<PackedScene> instance = ResourceLoader::load(p_node->get_filename());
|
|
|
|
- if (!instance.is_valid()) {
|
|
|
|
- return ERR_CANT_OPEN;
|
|
|
|
- }
|
|
|
|
|
|
+ bool instanced_by_owner = false;
|
|
|
|
+ Vector<SceneState::PackState> states_stack = PropertyUtils::get_node_states_stack(p_node, p_owner, &instanced_by_owner);
|
|
|
|
|
|
- nd.instance = _vm_get_variant(instance, variant_map);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- n = nullptr;
|
|
|
|
- } else {
|
|
|
|
- if (n->get_filename() != String()) {
|
|
|
|
- //is an instance
|
|
|
|
- Ref<SceneState> state = n->get_scene_instance_state();
|
|
|
|
- if (state.is_valid()) {
|
|
|
|
- int node = state->find_node_by_path(n->get_path_to(p_node));
|
|
|
|
- if (node >= 0) {
|
|
|
|
- //this one has state for this node, save
|
|
|
|
- PackState ps;
|
|
|
|
- ps.node = node;
|
|
|
|
- ps.state = state;
|
|
|
|
- pack_state_stack.push_back(ps);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- n = n->get_owner();
|
|
|
|
|
|
+ if (p_node->get_filename() != String() && p_node->get_owner() == p_owner && instanced_by_owner) {
|
|
|
|
+ if (p_node->get_scene_instance_load_placeholder()) {
|
|
|
|
+ //it's a placeholder, use the placeholder path
|
|
|
|
+ nd.instance = _vm_get_variant(p_node->get_filename(), variant_map);
|
|
|
|
+ nd.instance |= FLAG_INSTANCE_IS_PLACEHOLDER;
|
|
|
|
+ } else {
|
|
|
|
+ //must instance ourselves
|
|
|
|
+ Ref<PackedScene> instance = ResourceLoader::load(p_node->get_filename());
|
|
|
|
+ if (!instance.is_valid()) {
|
|
|
|
+ return ERR_CANT_OPEN;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ nd.instance = _vm_get_variant(instance, variant_map);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -476,90 +439,23 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
|
|
|
|
|
|
List<PropertyInfo> plist;
|
|
List<PropertyInfo> plist;
|
|
p_node->get_property_list(&plist);
|
|
p_node->get_property_list(&plist);
|
|
- StringName type = p_node->get_class();
|
|
|
|
-
|
|
|
|
- Ref<Script> script = p_node->get_script();
|
|
|
|
- if (Engine::get_singleton()->is_editor_hint() && script.is_valid()) {
|
|
|
|
- // Should be called in the editor only and not at runtime,
|
|
|
|
- // otherwise it can cause problems because of missing instance state support.
|
|
|
|
- script->update_exports();
|
|
|
|
- }
|
|
|
|
|
|
|
|
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
|
|
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
|
|
if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
|
|
if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- String name = E->get().name;
|
|
|
|
- Variant value = p_node->get(E->get().name);
|
|
|
|
-
|
|
|
|
- bool isdefault = false;
|
|
|
|
- Variant default_value = ClassDB::class_get_default_property_value(type, name);
|
|
|
|
-
|
|
|
|
- if (default_value.get_type() != Variant::NIL) {
|
|
|
|
- isdefault = bool(Variant::evaluate(Variant::OP_EQUAL, value, default_value));
|
|
|
|
|
|
+ // If instance or inheriting, not saving if property requested so, or it's meta
|
|
|
|
+ if (states_stack.size() && ((E->get().usage & PROPERTY_USAGE_NO_INSTANCE_STATE) || E->get().name == "__meta__")) {
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!isdefault && script.is_valid() && script->get_property_default_value(name, default_value)) {
|
|
|
|
- isdefault = bool(Variant::evaluate(Variant::OP_EQUAL, value, default_value));
|
|
|
|
- }
|
|
|
|
- // the version above makes more sense, because it does not rely on placeholder or usage flag
|
|
|
|
- // in the script, just the default value function.
|
|
|
|
- // if (E->get().usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) {
|
|
|
|
- // isdefault = true; //is script default value
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- if (pack_state_stack.size()) {
|
|
|
|
- // we are on part of an instanced subscene
|
|
|
|
- // or part of instanced scene.
|
|
|
|
- // only save what has been changed
|
|
|
|
- // only save changed properties in instance
|
|
|
|
-
|
|
|
|
- if ((E->get().usage & PROPERTY_USAGE_NO_INSTANCE_STATE) || E->get().name == "__meta__") {
|
|
|
|
- //property has requested that no instance state is saved, sorry
|
|
|
|
- //also, meta won't be overridden or saved
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- bool exists = false;
|
|
|
|
- Variant original;
|
|
|
|
-
|
|
|
|
- for (List<PackState>::Element *F = pack_state_stack.back(); F; F = F->prev()) {
|
|
|
|
- //check all levels of pack to see if the property exists somewhere
|
|
|
|
- const PackState &ps = F->get();
|
|
|
|
-
|
|
|
|
- original = ps.state->get_property_value(ps.node, E->get().name, exists);
|
|
|
|
- if (exists) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (exists) {
|
|
|
|
- //check if already exists and did not change
|
|
|
|
- if (value.get_type() == Variant::REAL && original.get_type() == Variant::REAL) {
|
|
|
|
- //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error
|
|
|
|
- float a = value;
|
|
|
|
- float b = original;
|
|
|
|
-
|
|
|
|
- if (Math::is_equal_approx(a, b)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- } else if (bool(Variant::evaluate(Variant::OP_EQUAL, value, original))) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!exists && isdefault) {
|
|
|
|
- //does not exist in original node, but it's the default value
|
|
|
|
- //so safe to skip too.
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
+ String name = E->get().name;
|
|
|
|
+ Variant value = p_node->get(name);
|
|
|
|
|
|
- } else {
|
|
|
|
- if (isdefault) {
|
|
|
|
- //it's the default value, no point in saving it
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
+ Variant default_value = PropertyUtils::get_property_default_value(p_node, name, &states_stack, true);
|
|
|
|
+ if (!PropertyUtils::is_property_value_different(value, default_value)) {
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
|
|
NodeData::Property prop;
|
|
NodeData::Property prop;
|
|
@@ -585,10 +481,10 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
|
|
*/
|
|
*/
|
|
|
|
|
|
bool skip = false;
|
|
bool skip = false;
|
|
- for (List<PackState>::Element *F = pack_state_stack.front(); F; F = F->next()) {
|
|
|
|
|
|
+ for (int i = 0; i < states_stack.size(); ++i) {
|
|
|
|
+ const auto &ia = states_stack[i];
|
|
//check all levels of pack to see if the group was added somewhere
|
|
//check all levels of pack to see if the group was added somewhere
|
|
- const PackState &ps = F->get();
|
|
|
|
- if (ps.state->is_node_in_group(ps.node, gi.name)) {
|
|
|
|
|
|
+ if (ia.state->is_node_in_group(ia.node, gi.name)) {
|
|
skip = true;
|
|
skip = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -618,7 +514,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
|
|
|
|
|
|
// Save the right type. If this node was created by an instance
|
|
// Save the right type. If this node was created by an instance
|
|
// then flag that the node should not be created but reused
|
|
// then flag that the node should not be created but reused
|
|
- if (pack_state_stack.empty() && !is_editable_instance) {
|
|
|
|
|
|
+ if (states_stack.empty() && !is_editable_instance) {
|
|
//this node is not part of an instancing process, so save the type
|
|
//this node is not part of an instancing process, so save the type
|
|
nd.type = _nm_get_string(p_node->get_class(), name_map);
|
|
nd.type = _nm_get_string(p_node->get_class(), name_map);
|
|
} else {
|
|
} else {
|
|
@@ -932,7 +828,7 @@ void SceneState::clear() {
|
|
base_scene_idx = -1;
|
|
base_scene_idx = -1;
|
|
}
|
|
}
|
|
|
|
|
|
-Ref<SceneState> SceneState::_get_base_scene_state() const {
|
|
|
|
|
|
+Ref<SceneState> SceneState::get_base_scene_state() const {
|
|
if (base_scene_idx >= 0) {
|
|
if (base_scene_idx >= 0) {
|
|
Ref<PackedScene> ps = variants[base_scene_idx];
|
|
Ref<PackedScene> ps = variants[base_scene_idx];
|
|
if (ps.is_valid()) {
|
|
if (ps.is_valid()) {
|
|
@@ -947,8 +843,8 @@ int SceneState::find_node_by_path(const NodePath &p_node) const {
|
|
ERR_FAIL_COND_V_MSG(node_path_cache.size() == 0, -1, "This operation requires the node cache to have been built.");
|
|
ERR_FAIL_COND_V_MSG(node_path_cache.size() == 0, -1, "This operation requires the node cache to have been built.");
|
|
|
|
|
|
if (!node_path_cache.has(p_node)) {
|
|
if (!node_path_cache.has(p_node)) {
|
|
- if (_get_base_scene_state().is_valid()) {
|
|
|
|
- int idx = _get_base_scene_state()->find_node_by_path(p_node);
|
|
|
|
|
|
+ if (get_base_scene_state().is_valid()) {
|
|
|
|
+ int idx = get_base_scene_state()->find_node_by_path(p_node);
|
|
if (idx != -1) {
|
|
if (idx != -1) {
|
|
int rkey = _find_base_scene_node_remap_key(idx);
|
|
int rkey = _find_base_scene_node_remap_key(idx);
|
|
if (rkey == -1) {
|
|
if (rkey == -1) {
|
|
@@ -963,11 +859,11 @@ int SceneState::find_node_by_path(const NodePath &p_node) const {
|
|
|
|
|
|
int nid = node_path_cache[p_node];
|
|
int nid = node_path_cache[p_node];
|
|
|
|
|
|
- if (_get_base_scene_state().is_valid() && !base_scene_node_remap.has(nid)) {
|
|
|
|
|
|
+ if (get_base_scene_state().is_valid() && !base_scene_node_remap.has(nid)) {
|
|
//for nodes that _do_ exist in current scene, still try to look for
|
|
//for nodes that _do_ exist in current scene, still try to look for
|
|
//the node in the instanced scene, as a property may be missing
|
|
//the node in the instanced scene, as a property may be missing
|
|
//from the local one
|
|
//from the local one
|
|
- int idx = _get_base_scene_state()->find_node_by_path(p_node);
|
|
|
|
|
|
+ int idx = get_base_scene_state()->find_node_by_path(p_node);
|
|
if (idx != -1) {
|
|
if (idx != -1) {
|
|
base_scene_node_remap[nid] = idx;
|
|
base_scene_node_remap[nid] = idx;
|
|
}
|
|
}
|
|
@@ -1007,7 +903,7 @@ Variant SceneState::get_property_value(int p_node, const StringName &p_property,
|
|
//property not found, try on instance
|
|
//property not found, try on instance
|
|
|
|
|
|
if (base_scene_node_remap.has(p_node)) {
|
|
if (base_scene_node_remap.has(p_node)) {
|
|
- return _get_base_scene_state()->get_property_value(base_scene_node_remap[p_node], p_property, found);
|
|
|
|
|
|
+ return get_base_scene_state()->get_property_value(base_scene_node_remap[p_node], p_property, found);
|
|
}
|
|
}
|
|
|
|
|
|
return Variant();
|
|
return Variant();
|
|
@@ -1026,7 +922,7 @@ bool SceneState::is_node_in_group(int p_node, const StringName &p_group) const {
|
|
}
|
|
}
|
|
|
|
|
|
if (base_scene_node_remap.has(p_node)) {
|
|
if (base_scene_node_remap.has(p_node)) {
|
|
- return _get_base_scene_state()->is_node_in_group(base_scene_node_remap[p_node], p_group);
|
|
|
|
|
|
+ return get_base_scene_state()->is_node_in_group(base_scene_node_remap[p_node], p_group);
|
|
}
|
|
}
|
|
|
|
|
|
return false;
|
|
return false;
|
|
@@ -1065,7 +961,7 @@ bool SceneState::is_connection(int p_node, const StringName &p_signal, int p_to_
|
|
}
|
|
}
|
|
|
|
|
|
if (base_scene_node_remap.has(p_node) && base_scene_node_remap.has(p_to_node)) {
|
|
if (base_scene_node_remap.has(p_node) && base_scene_node_remap.has(p_to_node)) {
|
|
- return _get_base_scene_state()->is_connection(base_scene_node_remap[p_node], p_signal, base_scene_node_remap[p_to_node], p_to_method);
|
|
|
|
|
|
+ return get_base_scene_state()->is_connection(base_scene_node_remap[p_node], p_signal, base_scene_node_remap[p_to_node], p_to_method);
|
|
}
|
|
}
|
|
|
|
|
|
return false;
|
|
return false;
|
|
@@ -1483,7 +1379,7 @@ bool SceneState::has_connection(const NodePath &p_node_from, const StringName &p
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- ss = ss->_get_base_scene_state();
|
|
|
|
|
|
+ ss = ss->get_base_scene_state();
|
|
} while (ss.is_valid());
|
|
} while (ss.is_valid());
|
|
|
|
|
|
return false;
|
|
return false;
|