32using TraversalQueue = std::deque<OperationNode *>;
39bool deg_foreach_needs_visit(
const OperationNode *op_node,
const int flags)
49void deg_foreach_dependent_operation(
const Depsgraph * ,
50 const IDNode *target_id_node,
53 DEGForeachOperation callback,
56 if (target_id_node ==
nullptr) {
63 Set<OperationNode *> scheduled;
64 for (
ComponentNode *comp_node : target_id_node->components.values()) {
77 if (!deg_foreach_needs_visit(op_node, flags)) {
80 queue.push_back(op_node);
81 scheduled.add(op_node);
85 while (!queue.empty()) {
90 callback(op_node, user_data);
92 if (op_node->outlinks.size() == 1) {
94 if (!scheduled.contains(to_node) && deg_foreach_needs_visit(to_node, flags)) {
95 scheduled.add_new(to_node);
103 for (
Relation *rel : op_node->outlinks) {
105 if (!scheduled.contains(to_node) && deg_foreach_needs_visit(to_node, flags)) {
106 queue.push_front(to_node);
107 scheduled.add_new(to_node);
118void deg_foreach_dependent_operation(
const ComponentNode &start_component,
119 DEGForeachOperation callback,
122 TraversalQueue queue;
123 Set<OperationNode *> was_queued;
127 queue.push_back(op_node);
128 was_queued.add(op_node);
132 while (!queue.empty()) {
135 if (!callback(op_node, user_data)) {
139 for (
const Relation *rel : op_node->outlinks) {
141 if (!was_queued.contains(to_node)) {
142 queue.push_back(to_node);
143 was_queued.add_new(to_node);
149struct ForeachIDComponentData {
151 IDNode *target_id_node;
152 Set<ComponentNode *> visited;
155struct ForeachNamedComponentData {
159bool deg_foreach_dependent_component_callback(
OperationNode *op_node,
void *user_data_v)
161 ForeachIDComponentData *user_data =
reinterpret_cast<ForeachIDComponentData *
>(user_data_v);
163 IDNode *id_node = comp_node->owner;
164 if (id_node != user_data->target_id_node && !user_data->visited.contains(comp_node)) {
166 user_data->visited.add_new(comp_node);
171bool deg_foreach_named_dependent_component_callback(
OperationNode *op_node,
void *user_data_v)
173 ForeachNamedComponentData *user_data =
reinterpret_cast<ForeachNamedComponentData *
>(
181 IDNode *id_node = comp_node->owner;
182 return user_data->callback(
186void deg_foreach_dependent_ID_component(
const Depsgraph *graph,
192 ForeachIDComponentData
data;
193 data.callback = callback;
194 data.target_id_node = graph->find_id_node(
id);
195 deg_foreach_dependent_operation(graph,
197 source_component_type,
199 deg_foreach_dependent_component_callback,
203void deg_foreach_dependent_component(
const Depsgraph *graph,
206 const StringRef component_name,
209 ForeachNamedComponentData
data;
210 data.callback = callback;
211 IDNode *id_node = graph->find_id_node(start_id);
216 const ComponentNode *start_component = id_node->find_component(
219 if (!start_component) {
223 deg_foreach_dependent_operation(
224 *start_component, deg_foreach_named_dependent_component_callback, &
data);
227struct ForeachIDData {
229 IDNode *target_id_node;
230 Set<IDNode *> visited;
233bool deg_foreach_dependent_ID_callback(
OperationNode *op_node,
void *user_data_v)
235 ForeachIDData *user_data =
reinterpret_cast<ForeachIDData *
>(user_data_v);
237 IDNode *id_node = comp_node->owner;
238 if (id_node != user_data->target_id_node && !user_data->visited.contains(id_node)) {
239 user_data->callback(id_node->id_orig);
240 user_data->visited.add_new(id_node);
248 data.callback = callback;
249 data.target_id_node = graph->find_id_node(
id);
250 deg_foreach_dependent_operation(
257 IDNode *target_id_node = graph->find_id_node(
id);
258 if (target_id_node ==
nullptr) {
264 TraversalQueue queue;
265 Set<OperationNode *> scheduled;
266 for (
ComponentNode *comp_node : target_id_node->components.values()) {
268 queue.push_back(op_node);
269 scheduled.add(op_node);
272 Set<IDNode *> visited;
273 visited.add_new(target_id_node);
275 while (!queue.empty()) {
282 IDNode *id_node = comp_node->owner;
283 if (!visited.contains(id_node)) {
285 callback(id_node->id_orig);
286 visited.add_new(id_node);
289 if (op_node->inlinks.size() == 1) {
293 if (scheduled.add(from_node)) {
302 for (
Relation *rel : op_node->inlinks) {
303 Node *from = rel->from;
306 if (scheduled.add(from_node)) {
307 queue.push_front(from_node);
319 for (
const IDNode *id_node : depsgraph->id_nodes) {
320 callback(id_node->id_orig);
328 for (
const ComponentNode *component_node : id_node.components.values()) {
329 if (component_node->type == component_node_type) {
330 return component_node;
340bool deg_scene_component_depends_on_time(
const Depsgraph &depsgraph,
344 const TimeSourceNode *time_source_node = depsgraph.find_time_source();
345 if (!time_source_node) {
349 IDNode *scene_id_node = depsgraph.find_id_node(
reinterpret_cast<const ID *
>(&scene));
350 if (!scene_id_node) {
356 const ComponentNode *component_node = find_component_node(*scene_id_node, component_node_type);
357 if (!component_node) {
362 std::queue<const Node *> queue;
363 Set<const Node *> nodes_already_scheduled;
364 queue.push(component_node);
365 nodes_already_scheduled.add_new(component_node);
367 for (
const OperationNode *operation_node : component_node->operations) {
368 queue.push(operation_node);
369 nodes_already_scheduled.add_new(operation_node);
372 while (!queue.empty()) {
373 const Node *current_node = queue.front();
376 for (
const Relation *relation : current_node->inlinks) {
377 const Node *from_node = relation->from;
378 if (from_node == time_source_node) {
382 if (!nodes_already_scheduled.contains(from_node)) {
383 queue.push(from_node);
384 nodes_already_scheduled.add_new(from_node);
399 deg::deg_foreach_dependent_ID(
reinterpret_cast<const deg::Depsgraph *
>(depsgraph),
id, callback);
408 deg::deg_foreach_dependent_ID_component(
reinterpret_cast<const deg::Depsgraph *
>(depsgraph),
410 source_component_type,
419 deg::deg_foreach_ancestor_ID(
reinterpret_cast<const deg::Depsgraph *
>(depsgraph),
id, callback);
429 deg::deg_foreach_dependent_component(
430 deg, start_id, start_component_type, start_component_name, callback);
435 deg::deg_foreach_id(
reinterpret_cast<const deg::Depsgraph *
>(depsgraph), callback);
443 return deg::deg_scene_component_depends_on_time(
444 reinterpret_cast<const deg::Depsgraph &
>(depsgraph), scene, component_type);
#define BLI_assert_unreachable()
eDepsObjectComponentType nodeTypeToObjectComponent(NodeType type)
NodeType nodeTypeFromSceneComponent(eDepsSceneComponentType component)
NodeType nodeTypeFromObjectComponent(eDepsObjectComponentType component_type)
FunctionRef< bool(ID *id, eDepsObjectComponentType component, StringRef component_name)> DEGForeachNamedIDComponentCallback
void DEG_foreach_dependent_ID(const Depsgraph *depsgraph, const ID *id, DEGForeachIDCallback callback)
void DEG_foreach_ID(const Depsgraph *depsgraph, DEGForeachIDCallback callback)
BMesh const char void * data
void DEG_foreach_ancestor_ID(const Depsgraph *depsgraph, const ID *id, DEGForeachIDCallback callback)
void DEG_foreach_dependent_ID_component(const Depsgraph *depsgraph, const ID *id, eDepsObjectComponentType source_component_type, int flags, DEGForeachIDComponentCallback callback)
FunctionRef< void(ID *id, eDepsObjectComponentType component)> DEGForeachIDComponentCallback
@ DEG_FOREACH_COMPONENT_IGNORE_TRANSFORM_SOLVERS
void DEG_foreach_dependent_component(const Depsgraph *depsgraph, const ID *start_id, eDepsObjectComponentType start_component_type, StringRef start_component_name, DEGForeachNamedIDComponentCallback callback)
FunctionRef< void(ID *id)> DEGForeachIDCallback
bool DEG_scene_component_depends_on_time(const Depsgraph &depsgraph, const Scene &scene, const eDepsSceneComponentType component_type)