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