depsgraph_private.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2004 Blender Foundation.
  19. * All rights reserved.
  20. *
  21. * Contributor(s): none yet.
  22. *
  23. * ***** END GPL LICENSE BLOCK *****
  24. */
  25. /** \file blender/blenkernel/depsgraph_private.h
  26. * \ingroup bke
  27. */
  28. #ifndef __DEPSGRAPH_PRIVATE_H__
  29. #define __DEPSGRAPH_PRIVATE_H__
  30. #include "BKE_depsgraph.h"
  31. #include "DNA_constraint_types.h"
  32. #include "BKE_constraint.h"
  33. struct Scene;
  34. struct Group;
  35. struct EffectorWeights;
  36. struct ModifierData;
  37. /* **** DAG relation types *** */
  38. /* scene link to object */
  39. #define DAG_RL_SCENE (1 << 0)
  40. /* object link to data */
  41. #define DAG_RL_DATA (1 << 1)
  42. /* object changes object (parent, track, constraints) */
  43. #define DAG_RL_OB_OB (1 << 2)
  44. /* object changes obdata (hooks, constraints) */
  45. #define DAG_RL_OB_DATA (1 << 3)
  46. /* data changes object (vertex parent) */
  47. #define DAG_RL_DATA_OB (1 << 4)
  48. /* data changes data (deformers) */
  49. #define DAG_RL_DATA_DATA (1 << 5)
  50. #define DAG_NO_RELATION (1 << 6)
  51. #define DAG_RL_ALL_BUT_DATA (DAG_RL_SCENE | DAG_RL_OB_OB | DAG_RL_OB_DATA | DAG_RL_DATA_OB | DAG_RL_DATA_DATA)
  52. #define DAG_RL_ALL (DAG_RL_ALL_BUT_DATA | DAG_RL_DATA)
  53. #define DAGQUEUEALLOC 50
  54. enum {
  55. DAG_WHITE = 0,
  56. DAG_GRAY = 1,
  57. DAG_BLACK = 2
  58. };
  59. typedef struct DagAdjList {
  60. struct DagNode *node;
  61. short type;
  62. int count; /* number of identical arcs */
  63. unsigned int lay; // for flushing redraw/rebuild events
  64. const char *name;
  65. struct DagAdjList *next;
  66. } DagAdjList;
  67. typedef struct DagNode {
  68. int color;
  69. short type;
  70. float x, y, k;
  71. void *ob;
  72. void *first_ancestor;
  73. int ancestor_count;
  74. unsigned int lay; /* accumulated layers of its relations + itself */
  75. unsigned int scelay; /* layers due to being in scene */
  76. uint64_t customdata_mask; /* customdata mask */
  77. int lasttime; /* if lasttime != DagForest->time, this node was not evaluated yet for flushing */
  78. int BFS_dist; /* BFS distance */
  79. int DFS_dist; /* DFS distance */
  80. int DFS_dvtm; /* DFS discovery time */
  81. int DFS_fntm; /* DFS Finishing time */
  82. struct DagAdjList *child;
  83. struct DagAdjList *parent;
  84. struct DagNode *next;
  85. /* Threaded evaluation routines */
  86. uint32_t num_pending_parents; /* number of parents which are not updated yet
  87. * this node has got.
  88. * Used by threaded update for faster detect whether node could be
  89. * updated aready.
  90. */
  91. bool scheduled;
  92. /* Runtime flags mainly used to determine which extra data is to be evaluated
  93. * during object_handle_update(). Such an extra data is what depends on the
  94. * DAG topology, meaning this flags indicates the data evaluation of which
  95. * depends on the node dependencies.
  96. */
  97. short eval_flags;
  98. } DagNode;
  99. typedef struct DagNodeQueueElem {
  100. struct DagNode *node;
  101. struct DagNodeQueueElem *next;
  102. } DagNodeQueueElem;
  103. typedef struct DagNodeQueue {
  104. DagNodeQueueElem *first;
  105. DagNodeQueueElem *last;
  106. int count;
  107. int maxlevel;
  108. struct DagNodeQueue *freenodes;
  109. } DagNodeQueue;
  110. /* forest as we may have more than one DAG unconnected */
  111. typedef struct DagForest {
  112. ListBase DagNode;
  113. struct GHash *nodeHash;
  114. int numNodes;
  115. bool is_acyclic;
  116. int time; /* for flushing/tagging, compare with node->lasttime */
  117. bool ugly_hack_sorry; /* prevent type check */
  118. bool need_update;
  119. } DagForest;
  120. // queue operations
  121. DagNodeQueue *queue_create(int slots);
  122. void queue_raz(DagNodeQueue *queue);
  123. void push_queue(DagNodeQueue *queue, DagNode *node);
  124. void push_stack(DagNodeQueue *queue, DagNode *node);
  125. DagNode *pop_queue(DagNodeQueue *queue);
  126. DagNode *get_top_node_queue(DagNodeQueue *queue);
  127. void queue_delete(DagNodeQueue *queue);
  128. // Dag management
  129. DagForest *dag_init(void);
  130. DagForest *build_dag(struct Main *bmain, struct Scene *sce, short mask);
  131. void free_forest(struct DagForest *Dag);
  132. DagNode *dag_find_node(DagForest *forest, void *fob);
  133. DagNode *dag_add_node(DagForest *forest, void *fob);
  134. DagNode *dag_get_node(DagForest *forest, void *fob);
  135. DagNode *dag_get_sub_node(DagForest *forest, void *fob);
  136. void dag_add_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, const char *name);
  137. typedef bool (*DagCollobjFilterFunction)(struct Object *obj, struct ModifierData *md);
  138. void dag_add_collision_relations(DagForest *dag, struct Scene *scene, Object *ob, DagNode *node, struct Group *group, int layer, unsigned int modifier_type, DagCollobjFilterFunction fn, bool dupli, const char *name);
  139. void dag_add_forcefield_relations(DagForest *dag, struct Scene *scene, Object *ob, DagNode *node, struct EffectorWeights *eff, bool add_absorption, int skip_forcefield, const char *name);
  140. void graph_print_queue(DagNodeQueue *nqueue);
  141. void graph_print_queue_dist(DagNodeQueue *nqueue);
  142. void graph_print_adj_list(DagForest *dag);
  143. #endif /* __DEPSGRAPH_PRIVATE_H__ */