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 "MEM_guardedalloc.h"
27 
28 #include "intern/depsgraph_type.h"
29 
30 #include "BLI_utildefines.h"
31 
32 #include "DEG_depsgraph_build.h"
33 
34 struct ID;
35 struct Scene;
36 
37 namespace blender {
38 namespace deg {
39 
40 struct Depsgraph;
41 struct OperationNode;
42 struct Relation;
43 
44 /* Metatype of Nodes - The general "level" in the graph structure
45  * the node serves. */
46 enum class NodeClass {
47   /* Types generally unassociated with user-visible entities,
48    * but needed for graph functioning. */
49   GENERIC = 0,
50   /* [Outer Node] An "aspect" of evaluating/updating an ID-Block, requiring
51    * certain types of evaluation behavior. */
52   COMPONENT = 1,
53   /* [Inner Node] A glorified function-pointer/callback for scheduling up
54    * evaluation operations for components, subject to relationship
55    * requirements. */
56   OPERATION = 2,
57 };
58 const char *nodeClassAsString(NodeClass node_class);
59 
60 /* Types of Nodes */
61 enum class NodeType {
62   /* Fallback type for invalid return value */
63   UNDEFINED = 0,
64   /* Inner Node (Operation) */
65   OPERATION,
66 
67   /* **** Generic Types **** */
68 
69   /* Time-Source */
70   TIMESOURCE,
71   /* ID-Block reference - used as landmarks/collection point for components,
72    * but not usually part of main graph. */
73   ID_REF,
74 
75   /* **** Outer Types **** */
76 
77   /* Parameters Component - Default when nothing else fits
78    * (i.e. just SDNA property setting). */
79   PARAMETERS,
80   /* Generic "Proxy-Inherit" Component. */
81   PROXY,
82   /* Animation Component */
83   ANIMATION,
84   /* Transform Component (Parenting/Constraints) */
85   TRANSFORM,
86   /* Geometry Component (Mesh/Displist) */
87   GEOMETRY,
88   /* Sequencer Component (Scene Only) */
89   SEQUENCER,
90   /* Component which contains all operations needed for layer collections
91    * evaluation. */
92   LAYER_COLLECTIONS,
93   /* Entry component of majority of ID nodes: prepares CoW pointers for
94    * execution. */
95   COPY_ON_WRITE,
96   /* Used by all operations which are updating object when something is
97    * changed in view layer. */
98   OBJECT_FROM_LAYER,
99   /* Audio-related evaluation. */
100   AUDIO,
101   ARMATURE,
102   /* Un-interesting data-block, which is a part of dependency graph, but does
103    * not have very distinctive update procedure.  */
104   GENERIC_DATABLOCK,
105 
106   /* **** Evaluation-Related Outer Types (with Subdata) **** */
107 
108   /* Pose Component - Owner/Container of Bones Eval */
109   EVAL_POSE,
110   /* Bone Component - Child/Subcomponent of Pose */
111   BONE,
112   /* Particle Systems Component */
113   PARTICLE_SYSTEM,
114   PARTICLE_SETTINGS,
115   /* Material Shading Component */
116   SHADING,
117   SHADING_PARAMETERS,
118   /* Point cache Component */
119   POINT_CACHE,
120   /* Image Animation Component */
121   IMAGE_ANIMATION,
122   /* Cache Component */
123   /* TODO(sergey); Verify that we really need this. */
124   CACHE,
125   /* Batch Cache Component.
126    * TODO(dfelinto/sergey): rename to make it more generic. */
127   BATCH_CACHE,
128   /* Duplication system. Used to force duplicated objects visible when
129    * when duplicator is visible. */
130   DUPLI,
131   /* Synchronization back to original datablock. */
132   SYNCHRONIZATION,
133   /* Simulation component. */
134   SIMULATION,
135 
136   /* Total number of meaningful node types. */
137   NUM_TYPES,
138 };
139 const char *nodeTypeAsString(NodeType type);
140 
141 NodeType nodeTypeFromSceneComponent(eDepsSceneComponentType component_type);
142 eDepsSceneComponentType nodeTypeToSceneComponent(NodeType type);
143 
144 NodeType nodeTypeFromObjectComponent(eDepsObjectComponentType component_type);
145 eDepsObjectComponentType nodeTypeToObjectComponent(NodeType type);
146 
147 /* All nodes in Depsgraph are descended from this. */
148 struct Node {
149   /* Helper class for static typeinfo in subclasses. */
150   struct TypeInfo {
151     TypeInfo(NodeType type, const char *type_name, int id_recalc_tag = 0);
152     NodeType type;
153     const char *type_name;
154     int id_recalc_tag;
155   };
156   struct Stats {
157     Stats();
158     /* Reset all the counters. Including all stats needed for average
159      * evaluation time calculation. */
160     void reset();
161     /* Reset counters needed for the current graph evaluation, does not
162      * touch averaging accumulators. */
163     void reset_current();
164     /* Time spend on this node during current graph evaluation. */
165     double current_time;
166   };
167   /* Relationships between nodes
168    * The reason why all depsgraph nodes are descended from this type (apart
169    * from basic serialization benefits - from the typeinfo) is that we can
170    * have relationships between these nodes. */
171   typedef Vector<Relation *> Relations;
172 
173   string name;        /* Identifier - mainly for debugging purposes. */
174   NodeType type;      /* Structural type of node. */
175   Relations inlinks;  /* Nodes which this one depends on. */
176   Relations outlinks; /* Nodes which depend on this one. */
177   Stats stats;        /* Evaluation statistics. */
178 
179   /* Generic tags for traversal algorithms and such.
180    *
181    * Actual meaning of values depends on a specific area. Every area is to
182    * clean this before use. */
183   int custom_flags;
184 
185   /* Methods. */
186   Node();
187   virtual ~Node();
188 
189   virtual string identifier() const;
190 
initNode191   virtual void init(const ID * /*id*/, const char * /*subdata*/)
192   {
193   }
194 
tag_updateNode195   virtual void tag_update(Depsgraph * /*graph*/, eUpdateSource /*source*/)
196   {
197   }
198 
get_entry_operationNode199   virtual OperationNode *get_entry_operation()
200   {
201     return nullptr;
202   }
get_exit_operationNode203   virtual OperationNode *get_exit_operation()
204   {
205     return nullptr;
206   }
207 
208   virtual NodeClass get_class() const;
209 
210   MEM_CXX_CLASS_ALLOC_FUNCS("Node");
211 };
212 
213 /* Macros for common static typeinfo. */
214 #define DEG_DEPSNODE_DECLARE static const Node::TypeInfo typeinfo
215 #define DEG_DEPSNODE_DEFINE(NodeType, type_, tname_) \
216   const Node::TypeInfo NodeType::typeinfo = Node::TypeInfo(type_, tname_)
217 
218 void deg_register_base_depsnodes();
219 
220 }  // namespace deg
221 }  // namespace blender
222