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

deg_node_id.cc « nodes « intern « depsgraph « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 478cc2863b07f81c80d3184e643b8dd72828421a (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
/*
 * ***** 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/nodes/deg_node_id.cc
 *  \ingroup depsgraph
 */

#include "intern/nodes/deg_node_id.h"

#include <stdio.h>
#include <cstring>  /* required for STREQ later on. */

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

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

#include "BKE_animsys.h"
}

#include "intern/nodes/deg_node_time.h"
#include "intern/depsgraph_intern.h"

#include "util/deg_util_foreach.h"

namespace DEG {

IDDepsNode::ComponentIDKey::ComponentIDKey(eDepsNode_Type type,
                                           const char *name)
        : type(type), name(name)
{
}

bool IDDepsNode::ComponentIDKey::operator== (const ComponentIDKey &other) const
{
    return type == other.type &&
           STREQ(name, other.name);
}

static unsigned int id_deps_node_hash_key(const void *key_v)
{
	const IDDepsNode::ComponentIDKey *key =
	        reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v);
	return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->type),
	                                  BLI_ghashutil_strhash_p(key->name));
}

static bool id_deps_node_hash_key_cmp(const void *a, const void *b)
{
	const IDDepsNode::ComponentIDKey *key_a =
	        reinterpret_cast<const IDDepsNode::ComponentIDKey *>(a);
	const IDDepsNode::ComponentIDKey *key_b =
	        reinterpret_cast<const IDDepsNode::ComponentIDKey *>(b);
	return !(*key_a == *key_b);
}

static void id_deps_node_hash_key_free(void *key_v)
{
	typedef IDDepsNode::ComponentIDKey ComponentIDKey;
	ComponentIDKey *key = reinterpret_cast<ComponentIDKey *>(key_v);
	OBJECT_GUARDED_DELETE(key, ComponentIDKey);
}

static void id_deps_node_hash_value_free(void *value_v)
{
	ComponentDepsNode *comp_node = reinterpret_cast<ComponentDepsNode *>(value_v);
	OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode);
}

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

	/* For object we initialize layers to layer from base. */
	if (GS(id->name) == ID_OB) {
		this->layers = 0;
	}

	components = BLI_ghash_new(id_deps_node_hash_key,
	                           id_deps_node_hash_key_cmp,
	                           "Depsgraph id components hash");

	/* 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()
{
	BLI_ghash_free(components,
	               id_deps_node_hash_key_free,
	               id_deps_node_hash_value_free);
}

ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type,
                                              const char *name) const
{
	ComponentIDKey key(type, name);
	return reinterpret_cast<ComponentDepsNode *>(BLI_ghash_lookup(components, &key));
}

ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type,
                                             const char *name)
{
	ComponentDepsNode *comp_node = find_component(type, name);
	if (!comp_node) {
		DepsNodeFactory *factory = deg_type_get_factory(type);
		comp_node = (ComponentDepsNode *)factory->create_node(this->id, "", name);

		/* Register. */
		ComponentIDKey *key = OBJECT_GUARDED_NEW(ComponentIDKey, type, name);
		BLI_ghash_insert(components, key, comp_node);
		comp_node->owner = this;
	}
	return comp_node;
}

void IDDepsNode::tag_update(Depsgraph *graph)
{
	GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components)
	{
		/* TODO(sergey): What about drievrs? */
		bool do_component_tag = comp_node->type != DEG_NODE_TYPE_ANIMATION;
		if (comp_node->type == DEG_NODE_TYPE_ANIMATION) {
			AnimData *adt = BKE_animdata_from_id(id);
			/* Animation data might be null if relations are tagged for update. */
			if (adt != NULL && (adt->recalc & ADT_RECALC_ANIM)) {
				do_component_tag = true;
			}
		}
		if (do_component_tag) {
			comp_node->tag_update(graph);
		}
	}
	GHASH_FOREACH_END();
}

void IDDepsNode::finalize_build()
{
	GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components)
	{
		comp_node->finalize_build();
	}
	GHASH_FOREACH_END();
}

}  // namespace DEG