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