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