[Bf-blender-cvs] [6593ba7e6b3] functions: improved C function API
Jacques Lucke
noreply at git.blender.org
Thu Feb 21 17:00:49 CET 2019
Commit: 6593ba7e6b3b54d5e58a12a1ccb532598a23ffb0
Author: Jacques Lucke
Date: Thu Feb 21 14:27:10 2019 +0100
Branches: functions
https://developer.blender.org/rB6593ba7e6b3b54d5e58a12a1ccb532598a23ffb0
improved C function API
===================================================================
M source/blender/functions/FN_functions.h
M source/blender/functions/c_wrapper.cpp
M source/blender/modifiers/intern/MOD_functiondeform.c
===================================================================
diff --git a/source/blender/functions/FN_functions.h b/source/blender/functions/FN_functions.h
index 30b5fa5ad60..adf84de3de3 100644
--- a/source/blender/functions/FN_functions.h
+++ b/source/blender/functions/FN_functions.h
@@ -34,7 +34,7 @@ void FN_tuple_free(FnTuple tuple);
void FN_tuple_set_float(FnTuple tuple, uint index, float value);
void FN_tuple_set_float_vector_3(FnTuple tuple, uint index, float vector[3]);
-
+float FN_tuple_get_float(FnTuple tuple, uint index);
void FN_tuple_get_float_vector_3(FnTuple tuple, uint index, float dst[3]);
const char *FN_type_name(FnType type);
@@ -44,11 +44,13 @@ FnType FN_type_get_float(void);
FnType FN_type_get_int32(void);
FnType FN_type_get_fvec3(void);
-FnFunction FN_get_deform_function(int type);
-
-FnFunction FN_get_generated_function(void);
+FnType FN_type_borrow_float(void);
+FnType FN_type_borrow_int32(void);
+FnType FN_type_borrow_fvec3(void);
FnFunction FN_tree_to_function(bNodeTree *bnodetree);
+FnFunction FN_function_get_with_signature(
+ bNodeTree *btree, FnType *inputs, FnType *outputs);
struct DepsNodeHandle;
void FN_function_update_dependencies(
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index 7121692977d..a3fd6aa209c 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -112,6 +112,11 @@ void FN_tuple_set_float(FnTuple tuple, uint index, float value)
unwrap(tuple)->set<float>(index, value);
}
+float FN_tuple_get_float(FnTuple tuple, uint index)
+{
+ return unwrap(tuple)->get<float>(index);
+}
+
using FN::Types::Vector;
void FN_tuple_set_float_vector_3(FnTuple tuple, uint index, float value[3])
@@ -143,7 +148,9 @@ static FnType get_type_with_increased_refcount(const FN::SharedType &type)
#define SIMPLE_TYPE_GETTER(name) \
FnType FN_type_get_##name() \
- { return get_type_with_increased_refcount(FN::Types::get_##name##_type()); }
+ { return get_type_with_increased_refcount(FN::Types::get_##name##_type()); } \
+ FnType FN_type_borrow_##name() \
+ { return wrap(FN::Types::get_##name##_type().refcounter()); }
SIMPLE_TYPE_GETTER(float);
SIMPLE_TYPE_GETTER(int32);
@@ -163,6 +170,26 @@ FnFunction FN_tree_to_function(bNodeTree *btree)
return wrap(fn_ref);
}
+FnFunction FN_function_get_with_signature(
+ bNodeTree *btree, FnType *inputs, FnType *outputs)
+{
+ if (btree == NULL) {
+ return NULL;
+ }
+
+ FnFunction fn = FN_tree_to_function(btree);
+ if (fn == NULL) {
+ return NULL;
+ }
+ else if (FN_function_has_signature(fn, inputs, outputs)) {
+ return fn;
+ }
+ else {
+ FN_function_free(fn);
+ return NULL;
+ }
+}
+
void FN_function_update_dependencies(
FnFunction fn,
struct DepsNodeHandle *deps_node)
diff --git a/source/blender/modifiers/intern/MOD_functiondeform.c b/source/blender/modifiers/intern/MOD_functiondeform.c
index 7663c11cd08..816fd64bac9 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform.c
+++ b/source/blender/modifiers/intern/MOD_functiondeform.c
@@ -54,25 +54,15 @@
static FnFunction get_current_function(FunctionDeformModifierData *fdmd)
{
- bNodeTree *tree = (bNodeTree *)DEG_get_original_id(fdmd->function_tree);
- if (tree == NULL) return NULL;
- return FN_tree_to_function(tree);
-}
+ bNodeTree *tree = (bNodeTree *)DEG_get_original_id((ID *)fdmd->function_tree);
-static bool is_deform_function(FnFunction fn)
-{
- FnType float_ty = FN_type_get_float();
- FnType fvec3_ty = FN_type_get_fvec3();
+ FnType float_ty = FN_type_borrow_float();
+ FnType fvec3_ty = FN_type_borrow_fvec3();
FnType inputs[] = { fvec3_ty, float_ty, NULL };
FnType outputs[] = { fvec3_ty, NULL };
- bool match = FN_function_has_signature(fn, inputs, outputs);
-
- FN_type_free(float_ty);
- FN_type_free(fvec3_ty);
-
- return match;
+ return FN_function_get_with_signature(tree, inputs, outputs);
}
static void do_deformation(
@@ -84,10 +74,6 @@ static void do_deformation(
if (fn == NULL) {
return;
}
- FN_function_print(fn);
- if (!is_deform_function(fn)) {
- return;
- }
FnCallable fn_call = FN_function_get_callable(fn);
BLI_assert(fn_call);
More information about the Bf-blender-cvs
mailing list