Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2020-08-31 00:20:51 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2020-08-31 00:49:38 +0300
commit429afe0c626a6d608385c6bc3a348b3ac8cfa8c0 (patch)
tree3240319bcb09b1737c5b2759a3ecbdd3b45ca59f /intern/cycles/blender/blender_id_map.h
parent19363880a6770852a8f94565c162a987850d58e3 (diff)
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does this by directly adding and removing nodes from the scene data. If some node is not tagged as used at the end of a synchronization, it then deletes the node from the scene. This poses a problem when it comes to supporting procedural nodes who can create other nodes not known by the Blender synchonization system, which will remove them. Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods found on the owners. `delete_node` will assert that the owner is the right one. Whenever a scene level node is created or deleted, the appropriate node manager is tagged for an update, freeing this responsability from BlenderSync or other software exporters. Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they only keep track of which nodes are used, employing the scene to create and delete them. To achieve this, the ParticleSystem is now a Node, although it does not have any sockets. This is part of T79131. Reviewed By: #cycles, brecht Maniphest Tasks: T79131 Differential Revision: https://developer.blender.org/D8540
Diffstat (limited to 'intern/cycles/blender/blender_id_map.h')
-rw-r--r--intern/cycles/blender/blender_id_map.h49
1 files changed, 16 insertions, 33 deletions
diff --git a/intern/cycles/blender/blender_id_map.h b/intern/cycles/blender/blender_id_map.h
index b5f6aaa67a8..f9f201c2e4e 100644
--- a/intern/cycles/blender/blender_id_map.h
+++ b/intern/cycles/blender/blender_id_map.h
@@ -19,6 +19,8 @@
#include <string.h>
+#include "render/scene.h"
+
#include "util/util_map.h"
#include "util/util_set.h"
#include "util/util_vector.h"
@@ -32,9 +34,8 @@ CCL_NAMESPACE_BEGIN
template<typename K, typename T> class id_map {
public:
- id_map(vector<T *> *scene_data_)
+ id_map()
{
- scene_data = scene_data_;
}
T *find(const BL::ID &id)
@@ -76,7 +77,6 @@ template<typename K, typename T> class id_map {
void add(const K &key, T *data)
{
assert(find(key) == NULL);
- scene_data->push_back(data);
b_map[key] = data;
used(data);
}
@@ -97,22 +97,23 @@ template<typename K, typename T> class id_map {
}
/* Combined add and update as needed. */
- bool add_or_update(T **r_data, const BL::ID &id)
+ bool add_or_update(Scene *scene, T **r_data, const BL::ID &id)
{
- return add_or_update(r_data, id, id, id.ptr.owner_id);
+ return add_or_update(scene, r_data, id, id, id.ptr.owner_id);
}
- bool add_or_update(T **r_data, const BL::ID &id, const K &key)
+ bool add_or_update(Scene *scene, T **r_data, const BL::ID &id, const K &key)
{
- return add_or_update(r_data, id, id, key);
+ return add_or_update(scene, r_data, id, id, key);
}
- bool add_or_update(T **r_data, const BL::ID &id, const BL::ID &parent, const K &key)
+ bool add_or_update(
+ Scene *scene, T **r_data, const BL::ID &id, const BL::ID &parent, const K &key)
{
T *data = find(key);
bool recalc;
if (!data) {
/* Add data if it didn't exist yet. */
- data = new T();
+ data = scene->create_node<T>();
add(key, data);
recalc = true;
}
@@ -144,27 +145,8 @@ template<typename K, typename T> class id_map {
b_map[NULL] = data;
}
- bool post_sync(bool do_delete = true)
+ void post_sync(Scene *scene, bool do_delete = true)
{
- /* remove unused data */
- vector<T *> new_scene_data;
- typename vector<T *>::iterator it;
- bool deleted = false;
-
- for (it = scene_data->begin(); it != scene_data->end(); it++) {
- T *data = *it;
-
- if (do_delete && used_set.find(data) == used_set.end()) {
- delete data;
- deleted = true;
- }
- else
- new_scene_data.push_back(data);
- }
-
- *scene_data = new_scene_data;
-
- /* update mapping */
map<K, T *> new_map;
typedef pair<const K, T *> TMapPair;
typename map<K, T *>::iterator jt;
@@ -172,15 +154,17 @@ template<typename K, typename T> class id_map {
for (jt = b_map.begin(); jt != b_map.end(); jt++) {
TMapPair &pair = *jt;
- if (used_set.find(pair.second) != used_set.end())
+ if (do_delete && used_set.find(pair.second) == used_set.end()) {
+ scene->delete_node(pair.second);
+ }
+ else {
new_map[pair.first] = pair.second;
+ }
}
used_set.clear();
b_recalc.clear();
b_map = new_map;
-
- return deleted;
}
const map<K, T *> &key_to_scene_data()
@@ -189,7 +173,6 @@ template<typename K, typename T> class id_map {
}
protected:
- vector<T *> *scene_data;
map<K, T *> b_map;
set<T *> used_set;
set<void *> b_recalc;