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

deg_builder.cc « builder « intern « depsgraph « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb2f057a090ac7aefe064401458575a68cc27f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2016 Blender Foundation.
 * All rights reserved.
 *
 * Original Author: Sergey Sharybin
 * Contributor(s): None Yet
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/depsgraph/intern/builder/deg_builder.cc
 *  \ingroup depsgraph
 */

#include "intern/builder/deg_builder.h"

// TODO(sergey): Use own wrapper over STD.
#include <stack>

#include "DNA_anim_types.h"
#include "DNA_object_types.h"
#include "DNA_ID.h"

#include "BLI_utildefines.h"
#include "BLI_ghash.h"

#include "intern/depsgraph.h"
#include "intern/depsgraph_types.h"
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_operation.h"

#include "util/deg_util_foreach.h"

#include <cstdio>

namespace DEG {

string deg_fcurve_id_name(const FCurve *fcu)
{
	char index_buf[32];
	// TODO(sergey): Use int-to-string utility or so.
	BLI_snprintf(index_buf, sizeof(index_buf), "[%d]", fcu->array_index);
	return string(fcu->rna_path) + index_buf;
}

static bool check_object_needs_evaluation(Object *object)
{
	if (object->recalc & OB_RECALC_ALL) {
		/* Object is tagged for update anyway, no need to re-tag it. */
		return false;
	}
	if (object->type == OB_MESH) {
		return object->derivedFinal == NULL;
	}
	else if (ELEM(object->type,
	              OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE))
	{
		return object->curve_cache == NULL;
	}
	return false;
}

void deg_graph_build_finalize(Depsgraph *graph)
{
	/* STEP 1: Make sure new invisible dependencies are ready for use.
	 *
	 * TODO(sergey): This might do a bit of extra tagging, but it's kinda nice
	 * to do it ahead of a time and don't spend time on flushing updates on
	 * every frame change.
	 */
	GHASH_FOREACH_BEGIN(IDDepsNode *, id_node, graph->id_hash)
	{
		if (id_node->layers == 0) {
			ID *id = id_node->id;
			if (GS(id->name) == ID_OB) {
				Object *object = (Object *)id;
				if (check_object_needs_evaluation(object)) {
					id_node->tag_update(graph);
				}
			}
		}
	}
	GHASH_FOREACH_END();
	/* STEP 2: Flush visibility layers from children to parent. */
	std::stack<OperationDepsNode *> stack;
	foreach (OperationDepsNode *node, graph->operations) {
		IDDepsNode *id_node = node->owner->owner;
		node->done = 0;
		node->num_links_pending = 0;
		foreach (DepsRelation *rel, node->outlinks) {
			if ((rel->from->type == DEPSNODE_TYPE_OPERATION) &&
			    (rel->flag & DEPSREL_FLAG_CYCLIC) == 0)
			{
				++node->num_links_pending;
			}
		}
		if (node->num_links_pending == 0) {
			stack.push(node);
			node->done = 1;
		}
		node->owner->layers = id_node->layers;
		id_node->id->tag |= LIB_TAG_DOIT;
	}
	while (!stack.empty()) {
		OperationDepsNode *node = stack.top();
		stack.pop();
		/* Flush layers to parents. */
		foreach (DepsRelation *rel, node->inlinks) {
			if (rel->from->type == DEPSNODE_TYPE_OPERATION) {
				OperationDepsNode *from = (OperationDepsNode *)rel->from;
				from->owner->layers |= node->owner->layers;
			}
		}
		/* Schedule parent nodes. */
		foreach (DepsRelation *rel, node->inlinks) {
			if (rel->from->type == DEPSNODE_TYPE_OPERATION) {
				OperationDepsNode *from = (OperationDepsNode *)rel->from;
				if ((rel->flag & DEPSREL_FLAG_CYCLIC) == 0) {
					BLI_assert(from->num_links_pending > 0);
					--from->num_links_pending;
				}
				if (from->num_links_pending == 0 && from->done == 0) {
					stack.push(from);
					from->done = 1;
				}
			}
		}
	}
	/* STEP 3: Re-tag IDs for update if it was tagged before the relations
	 * update tag.
	 */
	GHASH_FOREACH_BEGIN(IDDepsNode *, id_node, graph->id_hash)
	{
		GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp, id_node->components)
		{
			id_node->layers |= comp->layers;
		}
		GHASH_FOREACH_END();

		if ((id_node->layers & graph->layers) != 0) {
			ID *id = id_node->id;
			if ((id->tag & LIB_TAG_ID_RECALC_ALL) &&
			    (id->tag & LIB_TAG_DOIT))
			{
				id_node->tag_update(graph);
				id->tag &= ~LIB_TAG_DOIT;
			}
			else if (GS(id->name) == ID_OB) {
				Object *object = (Object *)id;
				if (object->recalc & OB_RECALC_ALL) {
					id_node->tag_update(graph);
					id->tag &= ~LIB_TAG_DOIT;
				}
			}
		}
		id_node->finalize_build();
	}
	GHASH_FOREACH_END();
}

}  // namespace DEG