bb9cb2bd13458e175f4da8cf9552ab70b85f2ea8
[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 bGPdata;
41 struct ListBase;
42 struct GHash;
43 struct ID;
44 struct Image;
45 struct FCurve;
46 struct Collection;
47 struct Key;
48 struct LayerCollection;
49 struct Main;
50 struct Material;
51 struct Mask;
52 struct MTex;
53 struct LightProbe;
54 struct MovieClip;
55 struct bNodeTree;
56 struct Object;
57 struct ParticleSettings;
58 struct Probe;
59 struct bPoseChannel;
60 struct bConstraint;
61 struct Scene;
62 struct Tex;
63 struct World;
64
65 struct PropertyRNA;
66
67 namespace DEG {
68
69 struct Depsgraph;
70 struct DepsNode;
71 struct IDDepsNode;
72 struct TimeSourceDepsNode;
73 struct ComponentDepsNode;
74 struct OperationDepsNode;
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          */
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         IDDepsNode *add_id_node(ID *id);
103         IDDepsNode *find_id_node(ID *id);
104         TimeSourceDepsNode *add_time_source();
105
106         ComponentDepsNode *add_component_node(ID *id,
107                                               eDepsNode_Type comp_type,
108                                               const char *comp_name = "");
109
110         OperationDepsNode *add_operation_node(ComponentDepsNode *comp_node,
111                                               const DepsEvalOperationCb& op,
112                                               eDepsOperation_Code opcode,
113                                               const char *name = "",
114                                               int name_tag = -1);
115         OperationDepsNode *add_operation_node(ID *id,
116                                               eDepsNode_Type comp_type,
117                                               const char *comp_name,
118                                               const DepsEvalOperationCb& op,
119                                               eDepsOperation_Code opcode,
120                                               const char *name = "",
121                                               int name_tag = -1);
122         OperationDepsNode *add_operation_node(ID *id,
123                                               eDepsNode_Type comp_type,
124                                               const DepsEvalOperationCb& op,
125                                               eDepsOperation_Code opcode,
126                                               const char *name = "",
127                                               int name_tag = -1);
128
129         OperationDepsNode *ensure_operation_node(ID *id,
130                                                  eDepsNode_Type comp_type,
131                                                  const DepsEvalOperationCb& op,
132                                                  eDepsOperation_Code opcode,
133                                                  const char *name = "",
134                                                  int name_tag = -1);
135
136         bool has_operation_node(ID *id,
137                                 eDepsNode_Type comp_type,
138                                 const char *comp_name,
139                                 eDepsOperation_Code opcode,
140                                 const char *name = "",
141                                 int name_tag = -1);
142
143         OperationDepsNode *find_operation_node(ID *id,
144                                                eDepsNode_Type comp_type,
145                                                const char *comp_name,
146                                                eDepsOperation_Code opcode,
147                                                const char *name = "",
148                                                int name_tag = -1);
149
150         OperationDepsNode *find_operation_node(ID *id,
151                                                eDepsNode_Type comp_type,
152                                                eDepsOperation_Code 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(Collection *collection);
162         void build_object(int base_index,
163                           Object *object,
164                           eDepsNode_LinkedState_Type linked_state);
165         void build_object_flags(int base_index,
166                                 Object *object,
167                                 eDepsNode_LinkedState_Type linked_state);
168         void build_object_data(Object *object);
169         void build_object_data_lightprobe(Object *object);
170         void build_object_transform(Object *object);
171         void build_object_constraints(Object *object);
172         void build_pose_constraints(Object *object, bPoseChannel *pchan, int pchan_index);
173         void build_rigidbody(Scene *scene);
174         void build_particles(Object *object);
175         void build_particle_settings(ParticleSettings *part);
176         void build_cloth(Object *object);
177         void build_animdata(ID *id);
178         void build_driver(ID *id, FCurve *fcurve, int driver_index);
179         void build_driver_variables(ID *id, FCurve *fcurve);
180         void build_driver_id_property(ID *id, const char *rna_path);
181         void build_ik_pose(Object *object,
182                            bPoseChannel *pchan,
183                            bConstraint *con);
184         void build_splineik_pose(Object *object,
185                                  bPoseChannel *pchan,
186                                  bConstraint *con);
187         void build_rig(Object *object);
188         void build_proxy_rig(Object *object);
189         void build_shapekeys(Key *key);
190         void build_obdata_geom(Object *object);
191         void build_camera(Object *object);
192         void build_lamp(Object *object);
193         void build_nodetree(bNodeTree *ntree);
194         void build_material(Material *ma);
195         void build_texture(Tex *tex);
196         void build_image(Image *image);
197         void build_world(World *world);
198         void build_compositor(Scene *scene);
199         void build_gpencil(bGPdata *gpd);
200         void build_cachefile(CacheFile *cache_file);
201         void build_mask(Mask *mask);
202         void build_movieclip(MovieClip *clip);
203         void build_lightprobe(LightProbe *probe);
204
205 protected:
206         struct SavedEntryTag {
207                 ID *id;
208                 eDepsNode_Type component_type;
209                 eDepsOperation_Code opcode;
210         };
211         vector<SavedEntryTag> saved_entry_tags_;
212
213         struct BuilderWalkUserData {
214                 DepsgraphNodeBuilder *builder;
215         };
216
217         static void modifier_walk(void *user_data,
218                                   struct Object *object,
219                                   struct ID **idpoin,
220                                   int cb_flag);
221
222         static void constraint_walk(bConstraint *constraint,
223                                     ID **idpoin,
224                                     bool is_reference,
225                                     void *user_data);
226
227         /* State which never changes, same for the whole builder time. */
228         Main *bmain_;
229         Depsgraph *graph_;
230
231         /* State which demotes currently built entities. */
232         Scene *scene_;
233         ViewLayer *view_layer_;
234         int view_layer_index_;
235
236         GHash *cow_id_hash_;
237         BuilderMap built_map_;
238 };
239
240 }  // namespace DEG