b265ed09f1ecd166beae3a41483c3109f46faf59
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_nodes.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_nodes.h
28  *  \ingroup depsgraph
29  */
30
31 #pragma once
32
33 #include "intern/builder/deg_builder_map.h"
34 #include "intern/depsgraph_types.h"
35
36 #include "DEG_depsgraph.h"
37
38 struct Base;
39 struct CacheFile;
40 struct Camera;
41 struct bGPdata;
42 struct ListBase;
43 struct GHash;
44 struct ID;
45 struct Image;
46 struct FCurve;
47 struct Collection;
48 struct Key;
49 struct Lamp;
50 struct LayerCollection;
51 struct LightProbe;
52 struct Main;
53 struct Material;
54 struct Mask;
55 struct MTex;
56 struct MovieClip;
57 struct bNodeTree;
58 struct Object;
59 struct ParticleSettings;
60 struct Probe;
61 struct bPoseChannel;
62 struct bConstraint;
63 struct Scene;
64 struct Tex;
65 struct World;
66
67 struct PropertyRNA;
68
69 namespace DEG {
70
71 struct Depsgraph;
72 struct DepsNode;
73 struct IDDepsNode;
74 struct TimeSourceDepsNode;
75 struct ComponentDepsNode;
76 struct OperationDepsNode;
77
78 struct DepsgraphNodeBuilder {
79         DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
80         ~DepsgraphNodeBuilder();
81
82         /* For given original ID get ID which is created by CoW system. */
83         ID *get_cow_id(const ID *id_orig) const;
84         /* Similar to above, but for the cases when there is no ID node we create
85          * one.
86          */
87         ID *ensure_cow_id(ID *id_orig);
88
89         /* Helper wrapper function which wraps get_cow_id with a needed type cast. */
90         template<typename T>
91         T *get_cow_datablock(const T *orig) const {
92                 return (T *)get_cow_id(&orig->id);
93         }
94
95         /* For a given COW datablock get corresponding original one. */
96         template<typename T>
97         T *get_orig_datablock(const T *cow) const {
98                 return (T *)cow->id.orig_id;
99         }
100
101         void begin_build();
102         void end_build();
103
104         IDDepsNode *add_id_node(ID *id);
105         IDDepsNode *find_id_node(ID *id);
106         TimeSourceDepsNode *add_time_source();
107
108         ComponentDepsNode *add_component_node(ID *id,
109                                               eDepsNode_Type comp_type,
110                                               const char *comp_name = "");
111
112         OperationDepsNode *add_operation_node(ComponentDepsNode *comp_node,
113                                               const DepsEvalOperationCb& op,
114                                               eDepsOperation_Code opcode,
115                                               const char *name = "",
116                                               int name_tag = -1);
117         OperationDepsNode *add_operation_node(ID *id,
118                                               eDepsNode_Type comp_type,
119                                               const char *comp_name,
120                                               const DepsEvalOperationCb& op,
121                                               eDepsOperation_Code opcode,
122                                               const char *name = "",
123                                               int name_tag = -1);
124         OperationDepsNode *add_operation_node(ID *id,
125                                               eDepsNode_Type comp_type,
126                                               const DepsEvalOperationCb& op,
127                                               eDepsOperation_Code opcode,
128                                               const char *name = "",
129                                               int name_tag = -1);
130
131         OperationDepsNode *ensure_operation_node(ID *id,
132                                                  eDepsNode_Type comp_type,
133                                                  const DepsEvalOperationCb& op,
134                                                  eDepsOperation_Code opcode,
135                                                  const char *name = "",
136                                                  int name_tag = -1);
137
138         bool has_operation_node(ID *id,
139                                 eDepsNode_Type comp_type,
140                                 const char *comp_name,
141                                 eDepsOperation_Code opcode,
142                                 const char *name = "",
143                                 int name_tag = -1);
144
145         OperationDepsNode *find_operation_node(ID *id,
146                                                eDepsNode_Type comp_type,
147                                                const char *comp_name,
148                                                eDepsOperation_Code opcode,
149                                                const char *name = "",
150                                                int name_tag = -1);
151
152         OperationDepsNode *find_operation_node(ID *id,
153                                                eDepsNode_Type comp_type,
154                                                eDepsOperation_Code opcode,
155                                                const char *name = "",
156                                                int name_tag = -1);
157
158         void build_id(ID* id);
159         void build_layer_collections(ListBase *lb);
160         void build_view_layer(Scene *scene,
161                                ViewLayer *view_layer,
162                                eDepsNode_LinkedState_Type linked_state);
163         void build_collection(Collection *collection);
164         void build_object(int base_index,
165                           Object *object,
166                           eDepsNode_LinkedState_Type linked_state);
167         void build_object_flags(int base_index,
168                                 Object *object,
169                                 eDepsNode_LinkedState_Type linked_state);
170         void build_object_data(Object *object);
171         void build_object_data_camera(Object *object);
172         void build_object_data_geometry(Object *object);
173         void build_object_data_geometry_datablock(ID *obdata);
174         void build_object_data_lamp(Object *object);
175         void build_object_data_lightprobe(Object *object);
176         void build_object_transform(Object *object);
177         void build_object_constraints(Object *object);
178         void build_pose_constraints(Object *object, bPoseChannel *pchan, int pchan_index);
179         void build_rigidbody(Scene *scene);
180         void build_particles(Object *object);
181         void build_particle_settings(ParticleSettings *part);
182         void build_cloth(Object *object);
183         void build_animdata(ID *id);
184         void build_driver(ID *id, FCurve *fcurve, int driver_index);
185         void build_driver_variables(ID *id, FCurve *fcurve);
186         void build_driver_id_property(ID *id, const char *rna_path);
187         void build_ik_pose(Object *object,
188                            bPoseChannel *pchan,
189                            bConstraint *con);
190         void build_splineik_pose(Object *object,
191                                  bPoseChannel *pchan,
192                                  bConstraint *con);
193         void build_rig(Object *object);
194         void build_proxy_rig(Object *object);
195         void build_shapekeys(Key *key);
196         void build_camera(Camera *camera);
197         void build_lamp(Lamp *lamp);
198         void build_nodetree(bNodeTree *ntree);
199         void build_material(Material *ma);
200         void build_texture(Tex *tex);
201         void build_image(Image *image);
202         void build_world(World *world);
203         void build_compositor(Scene *scene);
204         void build_gpencil(bGPdata *gpd);
205         void build_cachefile(CacheFile *cache_file);
206         void build_mask(Mask *mask);
207         void build_movieclip(MovieClip *clip);
208         void build_lightprobe(LightProbe *probe);
209
210 protected:
211         struct SavedEntryTag {
212                 ID *id;
213                 eDepsNode_Type component_type;
214                 eDepsOperation_Code opcode;
215         };
216         vector<SavedEntryTag> saved_entry_tags_;
217
218         struct BuilderWalkUserData {
219                 DepsgraphNodeBuilder *builder;
220         };
221
222         static void modifier_walk(void *user_data,
223                                   struct Object *object,
224                                   struct ID **idpoin,
225                                   int cb_flag);
226
227         static void constraint_walk(bConstraint *constraint,
228                                     ID **idpoin,
229                                     bool is_reference,
230                                     void *user_data);
231
232         /* State which never changes, same for the whole builder time. */
233         Main *bmain_;
234         Depsgraph *graph_;
235
236         /* State which demotes currently built entities. */
237         Scene *scene_;
238         ViewLayer *view_layer_;
239         int view_layer_index_;
240
241         GHash *cow_id_hash_;
242         BuilderMap built_map_;
243 };
244
245 }  // namespace DEG