2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2013 Blender Foundation.
19 * All rights reserved.
21 * Original Author: Joshua Leung
22 * Contributor(s): None Yet
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/depsgraph/intern/depsgraph_type_defines.cc
30 * Defines and code for core node types.
33 #include <cstdlib> // for BLI_assert()
36 #include "BLI_utildefines.h"
37 #include "BLI_ghash.h"
39 #include "DEG_depsgraph.h"
41 #include "intern/nodes/deg_node.h"
42 #include "intern/nodes/deg_node_component.h"
43 #include "intern/nodes/deg_node_operation.h"
45 #include "intern/depsgraph_intern.h"
52 /* Global type registry */
55 * \note For now, this is a hashtable not array, since the core node types
56 * currently do not have contiguous ID values. Using a hash here gives us
57 * more flexibility, albeit using more memory and also sacrificing a little
58 * speed. Later on, when things stabilise we may turn this back to an array
59 * since there are only just a few node types that an array would cope fine...
61 static GHash *_depsnode_typeinfo_registry = NULL;
63 /* Registration ------------------------------------------- */
65 /* Register node type */
66 void deg_register_node_typeinfo(DepsNodeFactory *factory)
68 BLI_assert(factory != NULL);
69 BLI_ghash_insert(_depsnode_typeinfo_registry,
70 SET_INT_IN_POINTER(factory->type()),
74 /* Getters ------------------------------------------------- */
76 /* Get typeinfo for specified type */
77 DepsNodeFactory *deg_get_node_factory(const eDepsNode_Type type)
79 /* look up type - at worst, it doesn't exist in table yet, and we fail */
80 return (DepsNodeFactory *)BLI_ghash_lookup(_depsnode_typeinfo_registry,
81 SET_INT_IN_POINTER(type));
84 /* Get typeinfo for provided node */
85 DepsNodeFactory *deg_node_get_factory(const DepsNode *node)
90 return deg_get_node_factory(node->type);
93 /* Stringified opcodes ------------------------------------- */
95 DepsOperationStringifier DEG_OPNAMES;
97 static const char *stringify_opcode(eDepsOperation_Code opcode)
100 #define STRINGIFY_OPCODE(name) case DEG_OPCODE_##name: return #name
101 /* Generic Operations. */
102 STRINGIFY_OPCODE(OPERATION);
103 STRINGIFY_OPCODE(PARAMETERS_EVAL);
104 STRINGIFY_OPCODE(PLACEHOLDER);
105 /* Animation, Drivers, etc. */
106 STRINGIFY_OPCODE(ANIMATION);
107 STRINGIFY_OPCODE(DRIVER);
109 STRINGIFY_OPCODE(TRANSFORM_LOCAL);
110 STRINGIFY_OPCODE(TRANSFORM_PARENT);
111 STRINGIFY_OPCODE(TRANSFORM_CONSTRAINTS);
112 STRINGIFY_OPCODE(TRANSFORM_FINAL);
113 STRINGIFY_OPCODE(TRANSFORM_OBJECT_UBEREVAL);
115 STRINGIFY_OPCODE(RIGIDBODY_REBUILD);
116 STRINGIFY_OPCODE(RIGIDBODY_SIM);
117 STRINGIFY_OPCODE(RIGIDBODY_TRANSFORM_COPY);
119 STRINGIFY_OPCODE(GEOMETRY_UBEREVAL);
121 STRINGIFY_OPCODE(POSE_INIT);
122 STRINGIFY_OPCODE(POSE_INIT_IK);
123 STRINGIFY_OPCODE(POSE_DONE);
124 STRINGIFY_OPCODE(POSE_IK_SOLVER);
125 STRINGIFY_OPCODE(POSE_SPLINE_IK_SOLVER);
127 STRINGIFY_OPCODE(BONE_LOCAL);
128 STRINGIFY_OPCODE(BONE_POSE_PARENT);
129 STRINGIFY_OPCODE(BONE_CONSTRAINTS);
130 STRINGIFY_OPCODE(BONE_READY);
131 STRINGIFY_OPCODE(BONE_DONE);
133 STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL_INIT);
134 STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL);
135 STRINGIFY_OPCODE(PARTICLE_SETTINGS_EVAL);
136 STRINGIFY_OPCODE(PARTICLE_SETTINGS_RECALC_CLEAR);
138 STRINGIFY_OPCODE(MASK_ANIMATION);
139 STRINGIFY_OPCODE(MASK_EVAL);
141 STRINGIFY_OPCODE(SCENE_LAYER_INIT);
142 STRINGIFY_OPCODE(SCENE_LAYER_EVAL);
143 STRINGIFY_OPCODE(SCENE_LAYER_DONE);
145 STRINGIFY_OPCODE(COPY_ON_WRITE);
147 STRINGIFY_OPCODE(SHADING);
148 STRINGIFY_OPCODE(MATERIAL_UPDATE);
149 STRINGIFY_OPCODE(WORLD_UPDATE);
151 case DEG_NUM_OPCODES: return "SpecialCase";
152 #undef STRINGIFY_OPCODE
157 DepsOperationStringifier::DepsOperationStringifier()
159 for (int i = 0; i < DEG_NUM_OPCODES; ++i) {
160 names_[i] = stringify_opcode((eDepsOperation_Code)i);
164 const char *DepsOperationStringifier::operator[](eDepsOperation_Code opcode)
166 BLI_assert((opcode >= 0) && (opcode < DEG_NUM_OPCODES));
167 if (opcode >= 0 && opcode < DEG_NUM_OPCODES) {
168 return names_[opcode];
170 return "UnknownOpcode";
175 /* Register all node types */
176 void DEG_register_node_types(void)
178 /* initialise registry */
179 DEG::_depsnode_typeinfo_registry = BLI_ghash_int_new("Depsgraph Node Type Registry");
181 /* register node types */
182 DEG::deg_register_base_depsnodes();
183 DEG::deg_register_component_depsnodes();
184 DEG::deg_register_operation_depsnodes();
187 /* Free registry on exit */
188 void DEG_free_node_types(void)
190 BLI_ghash_free(DEG::_depsnode_typeinfo_registry, NULL, NULL);