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

depsnode.cc « intern « depsgraph « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1736aadf9999637cafd4761bb7ce7528ac60568b (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
 * ***** 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) 2013 Blender Foundation.
 * All rights reserved.
 *
 * Original Author: Joshua Leung
 * Contributor(s): None Yet
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/depsgraph/intern/depsnode.cc
 *  \ingroup depsgraph
 */

#include <stdio.h>
#include <string.h>

#include "BLI_utildefines.h"

extern "C" {
#include "DNA_ID.h"
#include "DNA_anim_types.h"

#include "BKE_animsys.h"

#include "DEG_depsgraph.h"
}

#include "depsnode.h" /* own include */
#include "depsnode_component.h"
#include "depsnode_operation.h"
#include "depsgraph_intern.h"

/* *************** */
/* Node Management */

/* Add ------------------------------------------------ */

DepsNode::TypeInfo::TypeInfo(eDepsNode_Type type, const char *tname)
{
	this->type = type;
	if (type == DEPSNODE_TYPE_OPERATION)
		this->tclass = DEPSNODE_CLASS_OPERATION;
	else if (type < DEPSNODE_TYPE_PARAMETERS)
		this->tclass = DEPSNODE_CLASS_GENERIC;
	else
		this->tclass = DEPSNODE_CLASS_COMPONENT;
	this->tname = tname;
}

DepsNode::DepsNode()
{
	this->name[0] = '\0';
}

DepsNode::~DepsNode()
{
	/* free links
	 * note: deleting relations will remove them from the node relations set,
	 * but only touch the same position as we are using here, which is safe.
	 */
	DEPSNODE_RELATIONS_ITER_BEGIN(this->inlinks, rel)
	{
		OBJECT_GUARDED_DELETE(rel, DepsRelation);
	}
	DEPSNODE_RELATIONS_ITER_END;

	DEPSNODE_RELATIONS_ITER_BEGIN(this->outlinks, rel)
	{
		OBJECT_GUARDED_DELETE(rel, DepsRelation);
	}
	DEPSNODE_RELATIONS_ITER_END;
}


/* Generic identifier for Depsgraph Nodes. */
string DepsNode::identifier() const
{
	char typebuf[7];
	sprintf(typebuf, "(%d)", type);

	return string(typebuf) + " : " + name;
}

/* ************* */
/* Generic Nodes */

/* Time Source Node ============================================== */

void TimeSourceDepsNode::tag_update(Depsgraph *graph)
{
	for (DepsNode::Relations::const_iterator it = outlinks.begin();
	     it != outlinks.end();
	     ++it)
	{
		DepsRelation *rel = *it;
		DepsNode *node = rel->to;
		node->tag_update(graph);
	}
}


/* Root Node ============================================== */

RootDepsNode::RootDepsNode() : scene(NULL), time_source(NULL)
{
}

RootDepsNode::~RootDepsNode()
{
	OBJECT_GUARDED_DELETE(time_source, TimeSourceDepsNode);
}

TimeSourceDepsNode *RootDepsNode::add_time_source(const string &name)
{
	if (!time_source) {
		DepsNodeFactory *factory = DEG_get_node_factory(DEPSNODE_TYPE_TIMESOURCE);
		time_source = (TimeSourceDepsNode *)factory->create_node(NULL, "", name);
		/*time_source->owner = this;*/ // XXX
	}
	return time_source;
}

DEG_DEPSNODE_DEFINE(RootDepsNode, DEPSNODE_TYPE_ROOT, "Root DepsNode");
static DepsNodeFactoryImpl<RootDepsNode> DNTI_ROOT;

/* Time Source Node ======================================= */

DEG_DEPSNODE_DEFINE(TimeSourceDepsNode, DEPSNODE_TYPE_TIMESOURCE, "Time Source");
static DepsNodeFactoryImpl<TimeSourceDepsNode> DNTI_TIMESOURCE;

/* ID Node ================================================ */

/* Initialize 'id' node - from pointer data given. */
void IDDepsNode::init(const ID *id, const string &UNUSED(subdata))
{
	/* Store ID-pointer. */
	BLI_assert(id != NULL);
	this->id = (ID *)id;
	this->layers = (1 << 20) - 1;
	this->eval_flags = 0;

	/* NOTE: components themselves are created if/when needed.
	 * This prevents problems with components getting added
	 * twice if an ID-Ref needs to be created to house it...
	 */
}

/* Free 'id' node. */
IDDepsNode::~IDDepsNode()
{
	clear_components();
}

/* Copy 'id' node. */
void IDDepsNode::copy(DepsgraphCopyContext *dcc, const IDDepsNode *src)
{
	(void)src;  /* Ignored. */
	/* Iterate over items in original hash, adding them to new hash. */
	for (IDDepsNode::ComponentMap::const_iterator it = this->components.begin();
	     it != this->components.end();
	     ++it)
	{
		/* Get current <type : component> mapping. */
		ComponentIDKey c_key    = it->first;
		DepsNode *old_component = it->second;

		/* Make a copy of component. */
		ComponentDepsNode *component = (ComponentDepsNode *)DEG_copy_node(dcc, old_component);

		/* Add new node to hash... */
		this->components[c_key] = component;
	}

	// TODO: perform a second loop to fix up links?
	BLI_assert(!"Not expected to be used");
}

ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type,
                                              const string &name) const
{
	ComponentIDKey key(type, name);
	ComponentMap::const_iterator it = components.find(key);
	return it != components.end() ? it->second : NULL;
}

ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type,
                                             const string &name)
{
	ComponentIDKey key(type, name);
	ComponentDepsNode *comp_node = find_component(type, name);
	if (!comp_node) {
		DepsNodeFactory *factory = DEG_get_node_factory(type);
		comp_node = (ComponentDepsNode *)factory->create_node(this->id, "", name);

		/* Register. */
		this->components[key] = comp_node;
		comp_node->owner = this;
	}
	return comp_node;
}

void IDDepsNode::remove_component(eDepsNode_Type type, const string &name)
{
	ComponentIDKey key(type, name);
	ComponentDepsNode *comp_node = find_component(type, name);
	if (comp_node) {
		/* Unregister. */
		this->components.erase(key);
		OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode);
	}
}

void IDDepsNode::clear_components()
{
	for (ComponentMap::const_iterator it = components.begin();
	     it != components.end();
	     ++it)
	{
		ComponentDepsNode *comp_node = it->second;
		OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode);
	}
	components.clear();
}

void IDDepsNode::tag_update(Depsgraph *graph)
{
	for (ComponentMap::const_iterator it = components.begin();
	     it != components.end();
	     ++it)
	{
		ComponentDepsNode *comp_node = it->second;
		/* TODO(sergey): What about drievrs? */
		bool do_component_tag = comp_node->type != DEPSNODE_TYPE_ANIMATION;
		if (comp_node->type == DEPSNODE_TYPE_ANIMATION) {
			AnimData *adt = BKE_animdata_from_id(id);
			BLI_assert(adt != NULL);
			if (adt->recalc & ADT_RECALC_ANIM) {
				do_component_tag = true;
			}
		}
		if (do_component_tag) {
			comp_node->tag_update(graph);
		}
	}
}

DEG_DEPSNODE_DEFINE(IDDepsNode, DEPSNODE_TYPE_ID_REF, "ID Node");
static DepsNodeFactoryImpl<IDDepsNode> DNTI_ID_REF;

/* Subgraph Node ========================================== */

/* Initialize 'subgraph' node - from pointer data given. */
void SubgraphDepsNode::init(const ID *id, const string &UNUSED(subdata))
{
	/* Store ID-ref if provided. */
	this->root_id = (ID *)id;

	/* NOTE: graph will need to be added manually,
	 * as we don't have any way of passing this down.
	 */
}

/* Free 'subgraph' node */
SubgraphDepsNode::~SubgraphDepsNode()
{
	/* Only free if graph not shared, of if this node is the first
	 * reference to it...
	 */
	// XXX: prune these flags a bit...
	if ((this->flag & SUBGRAPH_FLAG_FIRSTREF) || !(this->flag & SUBGRAPH_FLAG_SHARED)) {
		/* Free the referenced graph. */
		DEG_graph_free(this->graph);
		this->graph = NULL;
	}
}

/* Copy 'subgraph' node - Assume that the subgraph doesn't get copied for now... */
void SubgraphDepsNode::copy(DepsgraphCopyContext * /*dcc*/,
                            const SubgraphDepsNode * /*src*/)
{
	//const SubgraphDepsNode *src_node = (const SubgraphDepsNode *)src;
	//SubgraphDepsNode *dst_node       = (SubgraphDepsNode *)dst;

	/* for now, subgraph itself isn't copied... */
	BLI_assert(!"Not expected to be used");
}

DEG_DEPSNODE_DEFINE(SubgraphDepsNode, DEPSNODE_TYPE_SUBGRAPH, "Subgraph Node");
static DepsNodeFactoryImpl<SubgraphDepsNode> DNTI_SUBGRAPH;


void DEG_register_base_depsnodes()
{
	DEG_register_node_typeinfo(&DNTI_ROOT);
	DEG_register_node_typeinfo(&DNTI_TIMESOURCE);

	DEG_register_node_typeinfo(&DNTI_ID_REF);
	DEG_register_node_typeinfo(&DNTI_SUBGRAPH);
}