Depsgraph: Replace LIB_TAG_DOIT with hash lookup
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_relations.h
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) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Original Author: Lukas Toenne
22  * Contributor(s): None Yet
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/builder/deg_builder_relations.h
28  *  \ingroup depsgraph
29  */
30
31 #pragma once
32
33 #include <cstdio>
34 #include <cstring>
35
36 #include "intern/depsgraph_types.h"
37
38 #include "DNA_ID.h"
39
40 #include "RNA_access.h"
41 #include "RNA_types.h"
42
43 #include "BLI_utildefines.h"
44 #include "BLI_string.h"
45
46 #include "intern/builder/deg_builder_map.h"
47 #include "intern/nodes/deg_node.h"
48 #include "intern/nodes/deg_node_component.h"
49 #include "intern/nodes/deg_node_operation.h"
50
51 struct Base;
52 struct bGPdata;
53 struct CacheFile;
54 struct ListBase;
55 struct GHash;
56 struct ID;
57 struct FCurve;
58 struct Group;
59 struct Key;
60 struct Main;
61 struct Mask;
62 struct Material;
63 struct MTex;
64 struct ModifierData;
65 struct MovieClip;
66 struct bNodeTree;
67 struct Object;
68 struct bPoseChannel;
69 struct bConstraint;
70 struct ParticleSystem;
71 struct Scene;
72 struct Tex;
73 struct World;
74 struct EffectorWeights;
75
76 struct PropertyRNA;
77
78 namespace DEG {
79
80 struct Depsgraph;
81 struct DepsNode;
82 struct DepsNodeHandle;
83 struct RootDepsNode;
84 struct IDDepsNode;
85 struct TimeSourceDepsNode;
86 struct ComponentDepsNode;
87 struct OperationDepsNode;
88 struct RootPChanMap;
89
90 struct TimeSourceKey
91 {
92         TimeSourceKey();
93         TimeSourceKey(ID *id);
94
95         string identifier() const;
96
97         ID *id;
98 };
99
100 struct ComponentKey
101 {
102         ComponentKey();
103         ComponentKey(ID *id, eDepsNode_Type type, const char *name = "");
104
105         string identifier() const;
106
107         ID *id;
108         eDepsNode_Type type;
109         const char *name;
110 };
111
112 struct OperationKey
113 {
114         OperationKey();
115         OperationKey(ID *id,
116                      eDepsNode_Type component_type,
117                      const char *name,
118                      int name_tag = -1);
119         OperationKey(ID *id,
120                      eDepsNode_Type component_type,
121                      const char *component_name,
122                      const char *name,
123                      int name_tag);
124
125         OperationKey(ID *id,
126                      eDepsNode_Type component_type,
127                      eDepsOperation_Code opcode);
128         OperationKey(ID *id,
129                      eDepsNode_Type component_type,
130                      const char *component_name,
131                      eDepsOperation_Code opcode);
132
133         OperationKey(ID *id,
134                      eDepsNode_Type component_type,
135                      eDepsOperation_Code opcode,
136                      const char *name,
137                      int name_tag = -1);
138         OperationKey(ID *id,
139                      eDepsNode_Type component_type,
140                      const char *component_name,
141                      eDepsOperation_Code opcode,
142                      const char *name,
143                      int name_tag = -1);
144
145         string identifier() const;
146
147         ID *id;
148         eDepsNode_Type component_type;
149         const char *component_name;
150         eDepsOperation_Code opcode;
151         const char *name;
152         int name_tag;
153 };
154
155 struct RNAPathKey
156 {
157         /* NOTE: see depsgraph_build.cpp for implementation */
158         RNAPathKey(ID *id, const char *path);
159
160         RNAPathKey(ID *id, const PointerRNA &ptr, PropertyRNA *prop);
161
162         string identifier() const;
163
164         ID *id;
165         PointerRNA ptr;
166         PropertyRNA *prop;
167 };
168
169 struct DepsgraphRelationBuilder
170 {
171         DepsgraphRelationBuilder(Main *bmain, Depsgraph *graph);
172
173         void begin_build();
174
175         template <typename KeyFrom, typename KeyTo>
176         void add_relation(const KeyFrom& key_from,
177                           const KeyTo& key_to,
178                           const char *description,
179                           bool check_unique = false);
180
181         template <typename KeyTo>
182         void add_relation(const TimeSourceKey& key_from,
183                           const KeyTo& key_to,
184                           const char *description,
185                           bool check_unique = false);
186
187         template <typename KeyType>
188         void add_node_handle_relation(const KeyType& key_from,
189                                       const DepsNodeHandle *handle,
190                                       const char *description,
191                                       bool check_unique = false);
192
193         void build_scene(Scene *scene);
194         void build_group(Object *object, Group *group);
195         void build_object(Object *object);
196         void build_object_data(Object *object);
197         void build_object_parent(Object *object);
198         void build_constraints(ID *id,
199                                eDepsNode_Type component_type,
200                                const char *component_subdata,
201                                ListBase *constraints,
202                                RootPChanMap *root_map);
203         void build_animdata(ID *id);
204         void build_animdata_curves(ID *id);
205         void build_animdata_curves_targets(ID *id,
206                                            ComponentKey &adt_key,
207                                            OperationDepsNode *operation_from,
208                                            ListBase *curves);
209         void build_animdata_nlastrip_targets(ID *id,
210                                              ComponentKey &adt_key,
211                                              OperationDepsNode *operation_from,
212                                              ListBase *strips);
213         void build_animdata_drivers(ID *id);
214         void build_driver(ID *id, FCurve *fcurve);
215         void build_driver_data(ID *id, FCurve *fcurve);
216         void build_driver_variables(ID *id, FCurve *fcurve);
217         void build_world(World *world);
218         void build_rigidbody(Scene *scene);
219         void build_particles(Object *object);
220         void build_particles_visualization_object(Object *object,
221                                                   ParticleSystem *psys,
222                                                   Object *draw_object);
223         void build_cloth(Object *object, ModifierData *md);
224         void build_ik_pose(Object *object,
225                            bPoseChannel *pchan,
226                            bConstraint *con,
227                            RootPChanMap *root_map);
228         void build_splineik_pose(Object *object,
229                                  bPoseChannel *pchan,
230                                  bConstraint *con,
231                                  RootPChanMap *root_map);
232         void build_rig(Object *object);
233         void build_proxy_rig(Object *object);
234         void build_shapekeys(ID *obdata, Key *key);
235         void build_obdata_geom(Object *object);
236         void build_camera(Object *object);
237         void build_lamp(Object *object);
238         void build_nodetree(bNodeTree *ntree);
239         void build_material(Material *ma);
240         void build_texture(Tex *tex);
241         void build_texture_stack(MTex **texture_stack);
242         void build_compositor(Scene *scene);
243         void build_gpencil(bGPdata *gpd);
244         void build_cachefile(CacheFile *cache_file);
245         void build_mask(Mask *mask);
246         void build_movieclip(MovieClip *clip);
247
248         void add_collision_relations(const OperationKey &key,
249                                      Scene *scene,
250                                      Object *object,
251                                      Group *group,
252                                      int layer,
253                                      bool dupli,
254                                      const char *name);
255         void add_forcefield_relations(const OperationKey &key,
256                                       Scene *scene,
257                                       Object *object,
258                                       ParticleSystem *psys,
259                                       EffectorWeights *eff,
260                                       bool add_absorption,
261                                       const char *name);
262
263         template <typename KeyType>
264         OperationDepsNode *find_operation_node(const KeyType &key);
265
266         Depsgraph *getGraph();
267
268 protected:
269         TimeSourceDepsNode *get_node(const TimeSourceKey &key) const;
270         ComponentDepsNode *get_node(const ComponentKey &key) const;
271         OperationDepsNode *get_node(const OperationKey &key) const;
272         DepsNode *get_node(const RNAPathKey &key) const;
273
274         OperationDepsNode *find_node(const OperationKey &key) const;
275         bool has_node(const OperationKey &key) const;
276
277         void add_time_relation(TimeSourceDepsNode *timesrc,
278                                DepsNode *node_to,
279                                const char *description,
280                                bool check_unique = false);
281         void add_operation_relation(OperationDepsNode *node_from,
282                                     OperationDepsNode *node_to,
283                                     const char *description,
284                                     bool check_unique = false);
285
286         template <typename KeyType>
287         DepsNodeHandle create_node_handle(const KeyType& key,
288                                           const char *default_name = "");
289
290         /* TODO(sergey): All those is_same* functions are to be generalized. */
291
292         /* Check whether two keys correponds to the same bone from same armature.
293          *
294          * This is used by drivers relations builder to avoid possible fake
295          * dependency cycle when one bone property drives another property of the
296          * same bone.
297          */
298         template <typename KeyFrom, typename KeyTo>
299         bool is_same_bone_dependency(const KeyFrom& key_from, const KeyTo& key_to);
300
301         /* Similar to above, but used to check whether driver is using node from
302          * the same node tree as a driver variable.
303          */
304         template <typename KeyFrom, typename KeyTo>
305         bool is_same_nodetree_node_dependency(const KeyFrom& key_from,
306                                               const KeyTo& key_to);
307
308         /* Similar to above, but used to check whether driver is using key from
309          * the same key datablock as a driver variable.
310          */
311         template <typename KeyFrom, typename KeyTo>
312         bool is_same_shapekey_dependency(const KeyFrom& key_from,
313                                          const KeyTo& key_to);
314
315 private:
316         /* State which never changes, same for the whole builder time. */
317         Main *bmain_;
318         Depsgraph *graph_;
319
320         /* State which demotes currently built entities. */
321         Scene *scene_;
322
323         BuilderMap built_map_;
324 };
325
326 struct DepsNodeHandle
327 {
328         DepsNodeHandle(DepsgraphRelationBuilder *builder,
329                        OperationDepsNode *node,
330                        const char *default_name = "")
331                 : builder(builder),
332                   node(node),
333                   default_name(default_name)
334         {
335                 BLI_assert(node != NULL);
336         }
337
338         DepsgraphRelationBuilder *builder;
339         OperationDepsNode *node;
340         const char *default_name;
341 };
342
343 }  // namespace DEG
344
345
346 #include "intern/builder/deg_builder_relations_impl.h"