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