Depsgraph: Use iterator over flat array for depsgraph_query

This way iteration order is much more predictable. This also solves issue with
randomly failing Cycles regression tests.
This commit is contained in:
2017-11-08 14:37:31 +01:00
parent 19c14f0c8a
commit 2a1e828711
2 changed files with 24 additions and 19 deletions

View File

@@ -33,8 +33,6 @@
#ifndef __DEG_DEPSGRAPH_QUERY_H__
#define __DEG_DEPSGRAPH_QUERY_H__
#include "BLI_ghash.h"
#include "DEG_depsgraph.h"
struct ID;
@@ -102,9 +100,9 @@ typedef struct DEGObjectsIteratorData {
*/
struct Object temp_dupli_object;
/* **** ghash **** */
struct GHashIterator gh_iter;
/* **** Iteration ober ID nodes **** */
size_t id_node_index;
size_t num_id_nodes;
} DEGObjectsIteratorData;
void DEG_objects_iterator_begin(struct BLI_Iterator *iter, DEGObjectsIteratorData *data);

View File

@@ -256,23 +256,29 @@ static void deg_objects_iterator_step(BLI_Iterator *iter, DEG::IDDepsNode *id_no
void DEG_objects_iterator_begin(BLI_Iterator *iter, DEGObjectsIteratorData *data)
{
Depsgraph *graph = data->graph;
Depsgraph *depsgraph = data->graph;
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(depsgraph);
const size_t num_id_nodes = deg_graph->id_nodes.size();
if (num_id_nodes == 0) {
iter->valid = false;
return;
}
/* TODO(sergey): What evaluation type we want here? */
DEG_evaluation_context_init(&data->eval_ctx, DAG_EVAL_RENDER);
data->eval_ctx.scene_layer = DEG_get_evaluated_scene_layer(depsgraph);
iter->data = data;
DEG_evaluation_context_init(&data->eval_ctx, DAG_EVAL_RENDER);
data->eval_ctx.scene_layer = DEG_get_evaluated_scene_layer(graph);
data->dupli_parent = NULL;
data->dupli_list = NULL;
data->dupli_object_next = NULL;
data->dupli_object_current = NULL;
data->scene = DEG_get_evaluated_scene(graph);
data->scene = DEG_get_evaluated_scene(depsgraph);
data->id_node_index = 0;
data->num_id_nodes = num_id_nodes;
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
BLI_ghashIterator_init(&data->gh_iter, deg_graph->id_hash);
DEG::IDDepsNode *id_node = (DEG::IDDepsNode *) BLI_ghashIterator_getValue(&data->gh_iter);
DEG::IDDepsNode *id_node = deg_graph->id_nodes[data->id_node_index];
deg_objects_iterator_step(iter, id_node);
if (iter->skip) {
@@ -283,6 +289,8 @@ void DEG_objects_iterator_begin(BLI_Iterator *iter, DEGObjectsIteratorData *data
void DEG_objects_iterator_next(BLI_Iterator *iter)
{
DEGObjectsIteratorData *data = (DEGObjectsIteratorData *)iter->data;
Depsgraph *depsgraph = data->graph;
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(depsgraph);
do {
if (data->dupli_list) {
if (deg_objects_dupli_iterator_next(iter)) {
@@ -297,14 +305,13 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
}
}
BLI_ghashIterator_step(&data->gh_iter);
if (BLI_ghashIterator_done(&data->gh_iter)) {
++data->id_node_index;
if (data->id_node_index == data->num_id_nodes) {
iter->valid = false;
return;
}
DEG::IDDepsNode *id_node = (DEG::IDDepsNode *) BLI_ghashIterator_getValue(&data->gh_iter);
DEG::IDDepsNode *id_node = deg_graph->id_nodes[data->id_node_index];
deg_objects_iterator_step(iter, id_node);
} while (iter->skip);
}