Blender V5.3
deg_node_component.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include <cstdio>
12
13#include "DNA_object_types.h"
14
15#include "BKE_action.hh"
16
20
21namespace blender::deg {
22
23/* *********** */
24/* Outer Nodes */
25
26/* -------------------------------------------------------------------- */
29
31{
32 const std::string codebuf = std::to_string(int(opcode));
33 return "OperationIDKey(" + codebuf + ", " + name + ")";
34}
35
45
46void ComponentNode::init(const ID * /*id*/, const char * /*subdata*/)
47{
48 /* hook up eval context? */
49 /* XXX: maybe this needs a special API? */
50}
51
52/* Free 'component' node */
58
59std::string ComponentNode::identifier() const
60{
61 const std::string type_name = type_get_factory(type)->type_name();
62 const std::string name_part = name[0] ? (std::string(" '") + name + "'") : "";
63
64 return "[" + type_name + "]" + name_part + " : " +
65 "(affects_visible_id: " + (affects_visible_id ? "true" : "false") + ")";
66}
67
69{
70 OperationNode *node = nullptr;
71 if (operations_map != nullptr) {
72 node = operations_map->lookup_default(key, nullptr);
73 }
74 else {
75 for (OperationNode *op_node : operations) {
76 if (op_node->opcode == key.opcode && op_node->name_tag == key.name_tag &&
77 op_node->name == key.name)
78 {
79 node = op_node;
80 break;
81 }
82 }
83 }
84 return node;
85}
86
88 const StringRef name,
89 int name_tag) const
90{
91 OperationIDKey key(opcode, name, name_tag);
92 return find_operation(key);
93}
94
96{
98 if (node == nullptr) {
99 fprintf(stderr,
100 "%s: find_operation(%s) failed\n",
101 this->identifier().c_str(),
102 key.identifier().c_str());
103 BLI_assert_msg(0, "Request for non-existing operation, should not happen");
104 return nullptr;
105 }
106 return node;
107}
108
110 const StringRef name,
111 int name_tag) const
112{
113 OperationIDKey key(opcode, name, name_tag);
114 return get_operation(key);
115}
116
118{
119 return find_operation(key) != nullptr;
120}
121
122bool ComponentNode::has_operation(OperationCode opcode, const StringRef name, int name_tag) const
123{
124 OperationIDKey key(opcode, name, name_tag);
125 return has_operation(key);
126}
127
129 OperationCode opcode,
130 const StringRef name,
131 int name_tag)
132{
133 OperationNode *op_node = find_operation(opcode, name, name_tag);
134 if (!op_node) {
136 op_node = static_cast<OperationNode *>(factory->create_node(this->owner->id_orig, "", name));
137
138 /* register opnode in this component's operation set */
139 OperationIDKey key(opcode, op_node->name, name_tag);
140 operations_map->add(key, op_node);
141
142 /* Set back-link. */
143 op_node->owner = this;
144 }
145 else {
146 fprintf(stderr,
147 "add_operation: Operation already exists - %s has %s at %p\n",
148 this->identifier().c_str(),
149 op_node->identifier().c_str(),
150 op_node);
151 BLI_assert_msg(0, "Should not happen!");
152 }
153
154 /* attach extra data */
155 op_node->evaluate = op;
156 op_node->opcode = opcode;
157 op_node->name = name;
158 op_node->name_tag = name_tag;
159
160 return op_node;
161}
162
164{
165 BLI_assert(entry_operation == nullptr);
166 entry_operation = op_node;
167}
168
170{
171 BLI_assert(exit_operation == nullptr);
172 exit_operation = op_node;
173}
174
176{
177 if (operations_map != nullptr) {
178 for (OperationNode *op_node : operations_map->values()) {
179 delete op_node;
180 }
181 operations_map->clear();
182 }
183 for (OperationNode *op_node : operations) {
184 delete op_node;
185 }
186 operations.clear();
187}
188
190{
191 /* Note that the node might already be tagged for an update due invisible state of the node
192 * during previous dependency evaluation. Here the node gets re-tagged, so we need to give
193 * the evaluated clues that evaluation needs to happen again. */
194 for (OperationNode *op_node : operations) {
195 op_node->tag_update(graph, source);
196 }
197 /* It is possible that tag happens before finalization. */
198 if (operations_map != nullptr) {
199 for (OperationNode *op_node : operations_map->values()) {
200 op_node->tag_update(graph, source);
201 }
202 }
203}
204
206{
207 if (entry_operation) {
208 return entry_operation;
209 }
210 if (operations_map != nullptr && operations_map->size() == 1) {
211 OperationNode *op_node = nullptr;
212 /* TODO(sergey): This is somewhat slow. */
213 for (OperationNode *tmp : operations_map->values()) {
214 op_node = tmp;
215 }
216 /* Cache for the subsequent usage. */
217 entry_operation = op_node;
218 return op_node;
219 }
220 if (operations.size() == 1) {
221 return operations[0];
222 }
223 return nullptr;
224}
225
227{
228 if (exit_operation) {
229 return exit_operation;
230 }
231 if (operations_map != nullptr && operations_map->size() == 1) {
232 OperationNode *op_node = nullptr;
233 /* TODO(sergey): This is somewhat slow. */
234 for (OperationNode *tmp : operations_map->values()) {
235 op_node = tmp;
236 }
237 /* Cache for the subsequent usage. */
238 exit_operation = op_node;
239 return op_node;
240 }
241 if (operations.size() == 1) {
242 return operations[0];
243 }
244 return nullptr;
245}
246
248{
250 for (OperationNode *op_node : operations_map->values()) {
251 operations.append(op_node);
252 }
253 delete operations_map;
254 operations_map = nullptr;
255}
256
258
259/* -------------------------------------------------------------------- */
262
263void BoneComponentNode::init(const ID *id, const char *subdata)
264{
265 /* generic component-node... */
266 ComponentNode::init(id, subdata);
267
268 /* name of component comes is bone name */
269 /* TODO(sergey): This sets name to an empty string because subdata is
270 * empty. Is it a bug? */
271 // this->name = subdata;
272
273 /* bone-specific node data */
274 Object *object = id_cast<Object *>(const_cast<ID *>(id));
275 this->pchan = BKE_pose_channel_find_name(object->pose, subdata);
276}
277
279
280/* -------------------------------------------------------------------- */
283
285/* TODO(sergey): Is this a correct tag? */
290DEG_COMPONENT_NODE_DEFINE(ImageAnimation, IMAGE_ANIMATION, 0);
292DEG_COMPONENT_NODE_DEFINE(LayerCollections, LAYER_COLLECTIONS, 0);
298DEG_COMPONENT_NODE_DEFINE(Sequencer, SEQUENCER, 0);
302DEG_COMPONENT_NODE_DEFINE(ObjectFromLayer, OBJECT_FROM_LAYER, 0);
303DEG_COMPONENT_NODE_DEFINE(Hierarchy, HIERARCHY, 0);
304DEG_COMPONENT_NODE_DEFINE(Instancing, INSTANCING, 0);
305DEG_COMPONENT_NODE_DEFINE(Synchronization, SYNCHRONIZATION, 0);
307DEG_COMPONENT_NODE_DEFINE(Armature, ARMATURE, 0);
308DEG_COMPONENT_NODE_DEFINE(GenericDatablock, GENERIC_DATABLOCK, 0);
310DEG_COMPONENT_NODE_DEFINE(Visibility, VISIBILITY, 0);
312DEG_COMPONENT_NODE_DEFINE(NTreeGeometryPreprocess, NTREE_GEOMETRY_PREPROCESS, 0);
313
315
316/* -------------------------------------------------------------------- */
319
321{
322 register_node_typeinfo(&DNTI_ANIMATION);
323 register_node_typeinfo(&DNTI_BONE);
324 register_node_typeinfo(&DNTI_CACHE);
325 register_node_typeinfo(&DNTI_BATCH_CACHE);
326 register_node_typeinfo(&DNTI_COPY_ON_EVAL);
327 register_node_typeinfo(&DNTI_GEOMETRY);
328 register_node_typeinfo(&DNTI_LAYER_COLLECTIONS);
329 register_node_typeinfo(&DNTI_PARAMETERS);
330 register_node_typeinfo(&DNTI_PARTICLE_SYSTEM);
331 register_node_typeinfo(&DNTI_PARTICLE_SETTINGS);
332 register_node_typeinfo(&DNTI_POINT_CACHE);
333 register_node_typeinfo(&DNTI_IMAGE_ANIMATION);
334 register_node_typeinfo(&DNTI_EVAL_POSE);
335 register_node_typeinfo(&DNTI_SEQUENCER);
336 register_node_typeinfo(&DNTI_COMPOSITOR);
337 register_node_typeinfo(&DNTI_SHADING);
338 register_node_typeinfo(&DNTI_TRANSFORM);
339 register_node_typeinfo(&DNTI_OBJECT_FROM_LAYER);
340 register_node_typeinfo(&DNTI_HIERARCHY);
341 register_node_typeinfo(&DNTI_INSTANCING);
342 register_node_typeinfo(&DNTI_SYNCHRONIZATION);
343 register_node_typeinfo(&DNTI_AUDIO);
344 register_node_typeinfo(&DNTI_ARMATURE);
345 register_node_typeinfo(&DNTI_GENERIC_DATABLOCK);
346 register_node_typeinfo(&DNTI_SCENE);
347 register_node_typeinfo(&DNTI_VISIBILITY);
348 register_node_typeinfo(&DNTI_NTREE_OUTPUT);
349 register_node_typeinfo(&DNTI_NTREE_GEOMETRY_PREPROCESS);
350}
351
353
354} // namespace blender::deg
Blender kernel action and pose functionality.
Object is a sort of wrapper for general info.
#define BLI_assert_msg(a, msg)
int64_t size() const
void append(const T &value)
void reserve(const int64_t min_capacity)
DEG_COMPONENT_NODE_DEFINE(Animation, ANIMATION, ID_RECALC_ANIMATION)
void register_node_typeinfo(DepsNodeFactory *factory)
void deg_register_component_depsnodes()
std::function< void(blender::Depsgraph *)> DepsEvalOperationCb
DepsNodeFactory * type_get_factory(const NodeType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ ID_RECALC_PARAMETERS
Definition DNA_ID.h:1138
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_SHADING
Definition DNA_ID.h:1094
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_COMPOSITOR
Definition DNA_ID.h:1161
@ ID_RECALC_NTREE_OUTPUT
Definition DNA_ID.h:1155
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
void init(const ID *id, const char *subdata) override
OperationNode * get_entry_operation() override
std::string identifier() const override
OperationNode * get_operation(OperationIDKey key) const
void init(const ID *id, const char *subdata) override
void tag_update(Depsgraph *graph, eUpdateSource source) override
Vector< OperationNode * > operations
OperationNode * find_operation(OperationIDKey key) const
OperationNode * add_operation(const DepsEvalOperationCb &op, OperationCode opcode, const StringRef name="", int name_tag=-1)
OperationNode * get_exit_operation() override
bool has_operation(OperationIDKey key) const
void set_exit_operation(OperationNode *op_node)
void finalize_build(Depsgraph *graph)
Map< ComponentNode::OperationIDKey, OperationNode * > * operations_map
void set_entry_operation(OperationNode *op_node)
virtual const char * type_name() const =0
virtual Node * create_node(const ID *id, const char *subdata, StringRef name) const =0
std::string name
Definition deg_node.hh:186
std::string identifier() const override