Cleanup: remove redundant doxygen \file argument
[blender.git] / source / blender / depsgraph / intern / node / deg_node.cc
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 #include "intern/node/deg_node.h"
24
25 #include <stdio.h>
26
27 #include "BLI_utildefines.h"
28
29 #include "intern/depsgraph.h"
30 #include "intern/eval/deg_eval_copy_on_write.h"
31 #include "intern/node/deg_node_component.h"
32 #include "intern/node/deg_node_factory.h"
33 #include "intern/node/deg_node_id.h"
34 #include "intern/node/deg_node_operation.h"
35 #include "intern/node/deg_node_time.h"
36
37 namespace DEG {
38
39 const char *nodeClassAsString(NodeClass node_class)
40 {
41         switch (node_class) {
42                 case NodeClass::GENERIC: return "GENERIC";
43                 case NodeClass::COMPONENT: return "COMPONENT";
44                 case NodeClass::OPERATION: return "OPERATION";
45         }
46         BLI_assert(!"Unhandled node class, should never happen.");
47         return "UNKNOWN";
48 }
49
50 const char *nodeTypeAsString(NodeType type)
51 {
52         switch (type) {
53                 case NodeType::UNDEFINED: return "UNDEFINED";
54                 case NodeType::OPERATION: return "OPERATION";
55                 /* **** Generic Types **** */
56                 case NodeType::TIMESOURCE: return "TIMESOURCE";
57                 case NodeType::ID_REF: return "ID_REF";
58                 /* **** Outer Types **** */
59                 case NodeType::PARAMETERS: return "PARAMETERS";
60                 case NodeType::PROXY: return "PROXY";
61                 case NodeType::ANIMATION: return "ANIMATION";
62                 case NodeType::TRANSFORM: return "TRANSFORM";
63                 case NodeType::GEOMETRY: return "GEOMETRY";
64                 case NodeType::SEQUENCER: return "SEQUENCER";
65                 case NodeType::LAYER_COLLECTIONS: return "LAYER_COLLECTIONS";
66                 case NodeType::COPY_ON_WRITE: return "COPY_ON_WRITE";
67                 case NodeType::OBJECT_FROM_LAYER: return "OBJECT_FROM_LAYER";
68                 /* **** Evaluation-Related Outer Types (with Subdata) **** */
69                 case NodeType::EVAL_POSE: return "EVAL_POSE";
70                 case NodeType::BONE: return "BONE";
71                 case NodeType::PARTICLE_SYSTEM: return "PARTICLE_SYSTEM";
72                 case NodeType::PARTICLE_SETTINGS: return "PARTICLE_SETTINGS";
73                 case NodeType::SHADING: return "SHADING";
74                 case NodeType::SHADING_PARAMETERS: return "SHADING_PARAMETERS";
75                 case NodeType::CACHE: return "CACHE";
76                 case NodeType::POINT_CACHE: return "POINT_CACHE";
77                 case NodeType::BATCH_CACHE: return "BATCH_CACHE";
78                 /* Duplication. */
79                 case NodeType::DUPLI: return "DUPLI";
80                 /* Synchronization. */
81                 case NodeType::SYNCHRONIZATION: return "SYNCHRONIZATION";
82                 /* Generic datablock. */
83                 case NodeType::GENERIC_DATABLOCK: return "GENERIC_DATABLOCK";
84
85                 /* Total number of meaningful node types. */
86                 case NodeType::NUM_TYPES: return "SpecialCase";
87         }
88         BLI_assert(!"Unhandled node type, should never happen.");
89         return "UNKNOWN";
90 }
91
92 /*******************************************************************************
93  * Type information.
94  */
95
96 Node::TypeInfo::TypeInfo(NodeType type,
97                              const char *type_name,
98                              int id_recalc_tag)
99         : type(type),
100           type_name(type_name),
101           id_recalc_tag(id_recalc_tag)
102 {
103 }
104
105 /*******************************************************************************
106  * Evaluation statistics.
107  */
108
109 Node::Stats::Stats()
110 {
111         reset();
112 }
113
114 void Node::Stats::reset()
115 {
116         current_time = 0.0;
117 }
118
119 void Node::Stats::reset_current()
120 {
121         current_time = 0.0;
122 }
123
124 /*******************************************************************************
125  * Node itself.
126  */
127
128 Node::Node()
129 {
130         name = "";
131 }
132
133 Node::~Node()
134 {
135         /* Free links. */
136         /* NOTE: We only free incoming links. This is to avoid double-free of links
137          * when we're trying to free same link from both it's sides. We don't have
138          * dangling links so this is not a problem from memory leaks point of view. */
139         for (Relation *rel : inlinks) {
140                 OBJECT_GUARDED_DELETE(rel, Relation);
141         }
142 }
143
144
145 /* Generic identifier for Depsgraph Nodes. */
146 string Node::identifier() const
147 {
148         return string(nodeTypeAsString(type)) + " : " + name;
149 }
150
151 NodeClass Node::get_class() const {
152         if (type == NodeType::OPERATION) {
153                 return NodeClass::OPERATION;
154         }
155         else if (type < NodeType::PARAMETERS) {
156                 return NodeClass::GENERIC;
157         }
158         else {
159                 return NodeClass::COMPONENT;
160         }
161 }
162
163 /*******************************************************************************
164  * Generic nodes definition.
165  */
166
167 DEG_DEPSNODE_DEFINE(TimeSourceNode, NodeType::TIMESOURCE, "Time Source");
168 static DepsNodeFactoryImpl<TimeSourceNode> DNTI_TIMESOURCE;
169
170 DEG_DEPSNODE_DEFINE(IDNode, NodeType::ID_REF, "ID Node");
171 static DepsNodeFactoryImpl<IDNode> DNTI_ID_REF;
172
173 void deg_register_base_depsnodes()
174 {
175         register_node_typeinfo(&DNTI_TIMESOURCE);
176         register_node_typeinfo(&DNTI_ID_REF);
177 }
178
179 }  // namespace DEG