doxygen: add newline after \file
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_nodes.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup depsgraph
22  */
23
24 #pragma once
25
26 #include "intern/builder/deg_builder_map.h"
27 #include "intern/depsgraph_type.h"
28
29 #include "DEG_depsgraph.h"
30
31 #include "intern/node/deg_node_id.h"
32 #include "intern/node/deg_node_operation.h"
33
34 struct Base;
35 struct CacheFile;
36 struct Camera;
37 struct Collection;
38 struct FCurve;
39 struct GHash;
40 struct ID;
41 struct Image;
42 struct Key;
43 struct Lamp;
44 struct LayerCollection;
45 struct LightProbe;
46 struct ListBase;
47 struct MTex;
48 struct Main;
49 struct Mask;
50 struct Material;
51 struct MovieClip;
52 struct Object;
53 struct ParticleSettings;
54 struct Probe;
55 struct Scene;
56 struct Speaker;
57 struct Tex;
58 struct World;
59 struct bAction;
60 struct bArmature;
61 struct bConstraint;
62 struct bGPdata;
63 struct bNodeTree;
64 struct bPoseChannel;
65
66 struct PropertyRNA;
67
68 namespace DEG {
69
70 struct ComponentNode;
71 struct Depsgraph;
72 struct IDNode;
73 struct Node;
74 struct OperationNode;
75 struct TimeSourceNode;
76
77 struct DepsgraphNodeBuilder {
78         DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
79         ~DepsgraphNodeBuilder();
80
81         /* For given original ID get ID which is created by CoW system. */
82         ID *get_cow_id(const ID *id_orig) const;
83         /* Similar to above, but for the cases when there is no ID node we create
84          * one. */
85         ID *ensure_cow_id(ID *id_orig);
86
87         /* Helper wrapper function which wraps get_cow_id with a needed type cast. */
88         template<typename T>
89         T *get_cow_datablock(const T *orig) const {
90                 return (T *)get_cow_id(&orig->id);
91         }
92
93         /* For a given COW datablock get corresponding original one. */
94         template<typename T>
95         T *get_orig_datablock(const T *cow) const {
96                 return (T *)cow->id.orig_id;
97         }
98
99         void begin_build();
100         void end_build();
101
102         IDNode *add_id_node(ID *id);
103         IDNode *find_id_node(ID *id);
104         TimeSourceNode *add_time_source();
105
106         ComponentNode *add_component_node(ID *id,
107                                           NodeType comp_type,
108                                           const char *comp_name = "");
109
110         OperationNode *add_operation_node(ComponentNode *comp_node,
111                                           OperationCode opcode,
112                                           const DepsEvalOperationCb& op = NULL,
113                                           const char *name = "",
114                                           int name_tag = -1);
115         OperationNode *add_operation_node(ID *id,
116                                           NodeType comp_type,
117                                           const char *comp_name,
118                                           OperationCode opcode,
119                                           const DepsEvalOperationCb& op = NULL,
120                                           const char *name = "",
121                                           int name_tag = -1);
122         OperationNode *add_operation_node(ID *id,
123                                           NodeType comp_type,
124                                           OperationCode opcode,
125                                           const DepsEvalOperationCb& op = NULL,
126                                           const char *name = "",
127                                           int name_tag = -1);
128
129         OperationNode *ensure_operation_node(ID *id,
130                                              NodeType comp_type,
131                                              OperationCode opcode,
132                                              const DepsEvalOperationCb& op = NULL,
133                                              const char *name = "",
134                                              int name_tag = -1);
135
136         bool has_operation_node(ID *id,
137                                 NodeType comp_type,
138                                 const char *comp_name,
139                                 OperationCode opcode,
140                                 const char *name = "",
141                                 int name_tag = -1);
142
143         OperationNode *find_operation_node(ID *id,
144                                            NodeType comp_type,
145                                            const char *comp_name,
146                                            OperationCode opcode,
147                                            const char *name = "",
148                                                int name_tag = -1);
149
150         OperationNode *find_operation_node(ID *id,
151                                            NodeType comp_type,
152                                            OperationCode opcode,
153                                            const char *name = "",
154                                            int name_tag = -1);
155
156         void build_id(ID *id);
157         void build_layer_collections(ListBase *lb);
158         void build_view_layer(Scene *scene,
159                               ViewLayer *view_layer,
160                               eDepsNode_LinkedState_Type linked_state);
161         void build_collection(LayerCollection *from_layer_collection,
162                               Collection *collection);
163         void build_object(int base_index,
164                           Object *object,
165                           eDepsNode_LinkedState_Type linked_state,
166                           bool is_visible);
167         void build_object_flags(int base_index,
168                                 Object *object,
169                                 eDepsNode_LinkedState_Type linked_state);
170         void build_object_data(Object *object, bool is_object_visible);
171         void build_object_data_camera(Object *object);
172         void build_object_data_geometry(Object *object, bool is_object_visible);
173         void build_object_data_geometry_datablock(ID *obdata,
174                                                   bool is_object_visible);
175         void build_object_data_lamp(Object *object);
176         void build_object_data_lightprobe(Object *object);
177         void build_object_data_speaker(Object *object);
178         void build_object_transform(Object *object);
179         void build_object_constraints(Object *object);
180         void build_object_pointcache(Object *object);
181         void build_pose_constraints(Object *object,
182                                     bPoseChannel *pchan,
183                                     int pchan_index,
184                                     bool is_object_visible);
185         void build_rigidbody(Scene *scene);
186         void build_particle_systems(Object *object, bool is_object_visible);
187         void build_particle_settings(ParticleSettings *part);
188         void build_animdata(ID *id);
189         void build_animdata_nlastrip_targets(ListBase *strips);
190         void build_action(bAction *action);
191         void build_driver(ID *id, FCurve *fcurve, int driver_index);
192         void build_driver_variables(ID *id, FCurve *fcurve);
193         void build_driver_id_property(ID *id, const char *rna_path);
194         void build_ik_pose(Object *object,
195                            bPoseChannel *pchan,
196                            bConstraint *con);
197         void build_splineik_pose(Object *object,
198                                  bPoseChannel *pchan,
199                                  bConstraint *con);
200         void build_rig(Object *object, bool is_object_visible);
201         void build_proxy_rig(Object *object);
202         void build_armature(bArmature *armature);
203         void build_shapekeys(Key *key);
204         void build_camera(Camera *camera);
205         void build_lamp(Lamp *lamp);
206         void build_nodetree(bNodeTree *ntree);
207         void build_material(Material *ma);
208         void build_texture(Tex *tex);
209         void build_image(Image *image);
210         void build_world(World *world);
211         void build_compositor(Scene *scene);
212         void build_gpencil(bGPdata *gpd);
213         void build_cachefile(CacheFile *cache_file);
214         void build_mask(Mask *mask);
215         void build_movieclip(MovieClip *clip);
216         void build_lightprobe(LightProbe *probe);
217         void build_speaker(Speaker *speaker);
218
219         /* Per-ID information about what was already in the dependency graph.
220          * Allows to re-use certain values, to speed up following evaluation. */
221         struct IDInfo {
222                 /* Copy-on-written pointer of the corresponding ID. */
223                 ID *id_cow;
224                 /* Mask of visible components from previous state of the
225                  * dependency graph. */
226                 IDComponentsMask previously_visible_components_mask;
227                 /* Special evaluation flag mask from the previous depsgraph. */
228                 uint32_t previous_eval_flags;
229                 /* Mesh CustomData mask from the previous depsgraph. */
230                 uint64_t previous_customdata_mask;
231         };
232
233 protected:
234         /* Allows to identify an operation which was tagged for update at the time
235          * relations are being updated. We can not reuse operation node pointer
236          * since it will change during dependency graph construction. */
237         struct SavedEntryTag {
238                 ID *id_orig;
239                 NodeType component_type;
240                 OperationCode opcode;
241                 const char *name;
242                 int name_tag;
243         };
244         vector<SavedEntryTag> saved_entry_tags_;
245
246         struct BuilderWalkUserData {
247                 DepsgraphNodeBuilder *builder;
248                 /* Denotes whether object the walk is invoked from is visible. */
249                 bool is_parent_visible;
250         };
251         static void modifier_walk(void *user_data,
252                                   struct Object *object,
253                                   struct ID **idpoin,
254                                   int cb_flag);
255         static void constraint_walk(bConstraint *constraint,
256                                     ID **idpoin,
257                                     bool is_reference,
258                                     void *user_data);
259
260         /* State which never changes, same for the whole builder time. */
261         Main *bmain_;
262         Depsgraph *graph_;
263
264         /* State which demotes currently built entities. */
265         Scene *scene_;
266         ViewLayer *view_layer_;
267         int view_layer_index_;
268         /* NOTE: Collection are possibly built recursively, so be careful when
269          * setting the current state. */
270         Collection *collection_;
271         /* Accumulated flag over the hierarchy opf currently building collections.
272          * Denotes whether all the hierarchy from parent of collection_ to the
273          * very root is visible (aka not restricted.). */
274         bool is_parent_collection_visible_;
275
276         /* Indexed by original ID, values are IDInfo. */
277         GHash *id_info_hash_;
278
279         /* Set of IDs which were already build. Makes it easier to keep track of
280          * what was already built and what was not. */
281         BuilderMap built_map_;
282 };
283
284 }  // namespace DEG