[Bf-blender-cvs] [7fbebda942d] functions: basic code structure
Jacques Lucke
noreply at git.blender.org
Sun Feb 10 20:24:46 CET 2019
Commit: 7fbebda942d0b94f8317c321c0543fcdd7de5fa4
Author: Jacques Lucke
Date: Mon Jan 21 17:02:29 2019 +0100
Branches: functions
https://developer.blender.org/rB7fbebda942d0b94f8317c321c0543fcdd7de5fa4
basic code structure
===================================================================
M build_files/cmake/macros.cmake
M source/blender/CMakeLists.txt
A source/blender/blenlib/BLI_small_vector.hpp
M source/blender/blenlib/CMakeLists.txt
M source/blender/editors/object/CMakeLists.txt
M source/blender/editors/object/object_edit.c
M source/blender/editors/object/object_intern.h
M source/blender/editors/object/object_ops.c
A source/blender/functions/CMakeLists.txt
A source/blender/functions/FN_functions.h
A source/blender/functions/FN_functions.hpp
D source/blender/functions/FN_funtions.h
A source/blender/functions/intern/c_wrapper.cpp
A source/blender/functions/intern/function.cpp
A source/blender/functions/types/numeric.hpp
A source/blender/functions/types/types.hpp
===================================================================
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 5b6e3fa0011..9caf9971c38 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -624,6 +624,7 @@ function(SETUP_BLENDER_SORTED_LIBS)
bf_python_gpu
bf_python_bmesh
bf_freestyle
+ bf_functions
bf_ikplugin
bf_modifiers
bf_gpencil_modifiers
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index c51e0b5b01c..6a2158a8557 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -111,6 +111,7 @@ add_subdirectory(nodes)
add_subdirectory(modifiers)
add_subdirectory(gpencil_modifiers)
add_subdirectory(shader_fx)
+add_subdirectory(functions)
add_subdirectory(makesdna)
add_subdirectory(makesrna)
diff --git a/source/blender/blenlib/BLI_small_vector.hpp b/source/blender/blenlib/BLI_small_vector.hpp
new file mode 100644
index 00000000000..ec933d5bb08
--- /dev/null
+++ b/source/blender/blenlib/BLI_small_vector.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "BLI_utildefines.h"
+#include <vector>
+
+namespace BLI {
+
+ template<typename T, uint N = 4>
+ class SmallVector {
+ public:
+ SmallVector() {}
+
+ private:
+ std::vector<T> elements;
+ };
+
+} /* namespace BLI */
\ No newline at end of file
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index f1aac6cd5b2..3f89a1c6603 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -224,6 +224,8 @@ set(SRC
BLI_winstuff.h
PIL_time.h
PIL_time_utildefines.h
+
+ BLI_small_vector.hpp
)
if(WITH_MEM_VALGRIND)
diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt
index f15427e61ac..a0d7555c0c6 100644
--- a/source/blender/editors/object/CMakeLists.txt
+++ b/source/blender/editors/object/CMakeLists.txt
@@ -33,6 +33,7 @@ set(INC
../../python
../../render/extern/include
../../windowmanager
+ ../../functions
../../../../intern/guardedalloc
../../../../intern/glew-mx
)
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 89f043966db..bd25ec2c799 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1743,3 +1743,29 @@ void OBJECT_OT_link_to_collection(wmOperatorType *ot)
"Name of the newly added collection");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
+
+#include "FN_functions.h"
+
+static int test_functions_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
+{
+ FunctionRef fn = NULL;
+ FnTypeRef type = FN_type_get_float_vector_3d();
+ printf("Type: %s\n", FN_type_name(type));
+ printf("Finished\n");
+ return OPERATOR_FINISHED;
+}
+
+
+void TEST_OT_test_functions(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Test Functions";
+ ot->description = "Test Functions";
+ ot->idname = "TEST_OT_test_functions";
+
+ /* api callbacks */
+ ot->exec = test_functions_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
+}
\ No newline at end of file
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index ff153488042..fc349f43827 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -277,4 +277,6 @@ void TRANSFORM_OT_vertex_random(struct wmOperatorType *ot);
void OBJECT_OT_data_transfer(struct wmOperatorType *ot);
void OBJECT_OT_datalayout_transfer(struct wmOperatorType *ot);
+void TEST_OT_test_functions(struct wmOperatorType *ot);
+
#endif /* __OBJECT_INTERN_H__ */
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 5d9aeab7eb8..e2715400251 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -259,6 +259,8 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_hide_view_clear);
WM_operatortype_append(OBJECT_OT_hide_view_set);
WM_operatortype_append(OBJECT_OT_hide_collection);
+
+ WM_operatortype_append(TEST_OT_test_functions);
}
void ED_operatormacros_object(void)
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
new file mode 100644
index 00000000000..53596722345
--- /dev/null
+++ b/source/blender/functions/CMakeLists.txt
@@ -0,0 +1,20 @@
+set(INC
+ .
+ ../blenlib
+)
+
+set(INC_SYS
+)
+
+set(SRC
+ intern/c_wrapper.cpp
+ intern/function.cpp
+
+ FN_functions.h
+ FN_functions.hpp
+
+ types/numeric.hpp
+ types/types.hpp
+)
+
+blender_add_lib(bf_functions "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/functions/FN_functions.h b/source/blender/functions/FN_functions.h
new file mode 100644
index 00000000000..dd6f88b7f52
--- /dev/null
+++ b/source/blender/functions/FN_functions.h
@@ -0,0 +1,69 @@
+#ifndef __FUNCTIONS_H__
+#define __FUNCTIONS_H__
+
+#include "BLI_utildefines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Function *FunctionRef;
+typedef struct FnType *FnTypeRef;
+typedef struct FnInputs *FnInputsRef;
+typedef struct FnOutputs *FnOutputsRef;
+
+/* Split ownership of the function. */
+void FN_function_copy_ref(FunctionRef fn);
+
+/* Tag the function as unused by the caller. */
+void FN_function_free_ref(FunctionRef fn);
+
+
+/* Raw function pointer to call when the function should be executed. */
+void *FN_function_get_pointer(FunctionRef fn);
+
+/* Pass into the function as first argument. */
+void *FN_function_get_settings(FunctionRef fn);
+
+/* Call a function with the given input.
+ * The function output will be written into fn_out.
+ * Returns true on success. */
+bool FN_function_call(FunctionRef fn, FnInputsRef fn_in, FnOutputsRef fn_out);
+
+
+/* Create a container to store function inputs. */
+FnInputsRef FN_inputs_new(FunctionRef fn);
+
+/* Free a set of function inputs. */
+void FN_inputs_free(FnInputsRef fn_in);
+
+/* Set a funtion input by name. Returns true on success. */
+bool FN_inputs_set_name(FnInputsRef fn_in, const char *name, void *value);
+
+/* Set a function input by index. Returns true on success. */
+bool FN_inputs_set_index(FnInputsRef fn_in, uint index, void *value);
+
+
+/* Create a container to store function outputs. */
+FnOutputsRef FN_outputs_new(FunctionRef fn);
+
+/* Free a set of output functions. */
+void FN_outputs_free(FnOutputsRef fn_out);
+
+/* Extract the result of an executed function by name. */
+void *FN_outputs_get_name(FnOutputsRef fn_out, const char *name);
+
+/* Extract the result of an executed function by index. */
+void *FN_outputs_get_index(FnOutputsRef fn_out, const char *name);
+
+const char *FN_type_name(FnTypeRef type);
+
+FnTypeRef FN_type_get_float(void);
+FnTypeRef FN_type_get_int32(void);
+FnTypeRef FN_type_get_float_vector_3d(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __FUNCTIONS_H__ */
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
new file mode 100644
index 00000000000..f9f17ade2fe
--- /dev/null
+++ b/source/blender/functions/FN_functions.hpp
@@ -0,0 +1,64 @@
+#pragma once
+
+#include <string>
+
+#include "BLI_utildefines.h"
+#include "BLI_small_vector.hpp"
+
+namespace FN {
+ using namespace BLI;
+
+ class Type;
+ class Inputs;
+ class Outputs;
+ class Signature;
+ class Function;
+
+ class Type {
+ public:
+ const std::string &name() const;
+ const uint size() const;
+
+ protected:
+ std::string m_name;
+ uint m_size;
+ };
+
+ class Inputs {
+ public:
+ static Inputs *New(Function *fn);
+
+ bool set(uint index, void *value);
+
+ private:
+ Inputs() {}
+
+ Function *fn;
+ };
+
+ class Outputs {
+ public:
+ static Outputs *New(Function *fn);
+
+ bool get(uint index, void *value);
+
+ private:
+ Outputs() {}
+
+ Function *fn;
+ };
+
+ class Signature {
+ private:
+ SmallVector<Type *> inputs;
+ SmallVector<Type *> outputs;
+ };
+
+ class Function {
+ public:
+ bool call(Inputs *fn_in, Outputs *fn_out);
+
+ private:
+ Signature *signature;
+ };
+} /* namespace FN */
diff --git a/source/blender/functions/FN_funtions.h b/source/blender/functions/FN_funtions.h
deleted file mode 100644
index 8d19c261bc4..00000000000
--- a/source/blender/functions/FN_funtions.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "BLI_utildefines.h"
-
-struct Function;
-typedef struct Function Function;
-
-struct FnInputs;
-typedef struct FnInputs FnInputs;
-
-struct FnOutputs;
-typedef struct FnOutputs FnOutputs;
-
-struct FnStaticInputs;
-typedef struct FnStaticInputs FnStaticInputs;
-
-struct FnDependencies;
-typedef struct FnDependencies FnDependencies;
-
-/* Split ownership of the function. */
-void FN_function_copy_ref(Function *fn);
-
-/* Tag the function as unused by the caller. */
-void FN_function_free_ref(Function *fn);
-
-
-/* Raw function pointer to call when the function should be executed. */
-void *FN_function_get_pointer(Function *fn);
-
-/* Pass into the function as first argument. */
-void *FN_function_get_settings(Function *fn);
-
-/* Call a function with the given input.
- * The function output will be written into fn_out.
- * Returns true on success. */
-bool FN_function_call(Function *fn, FnInputs *fn_in, FnOutputs *fn_out);
-
-
-/* Create a container to store function inputs. */
-FnInputs *FN_inputs_new(Function *fn);
-
-/* Free a set of function inputs. */
-void FN_inputs_free(FnInputs *fn_in);
-
-/* Set a funtion input by name. Returns true on success. */
-bool FN_inputs_set_name(FnInputs *fn_in, const char *name, void *value);
-
-/* Set a function input by index. Returns true on success. */
-bool FN_inputs_set_index(FnInputs *fn_in, uint index, void *value);
-
-
-/* Create a container to store function outputs. */
-FnOutputs *FN_outputs_new(Function *fn);
-
-/* Free a set of output functions. */
-void FN_outputs_free(FnOutputs *fn_out);
-
-/* Extract the result of an executed function by name. */
-void *FN_outputs_get_name(FnOutputs *fn_out, const char *name);
-
-/* Extract the result of an executed function by index. */
-void *FN_outputs_get_index(FnOutputs *fn_out, const char *name);
-
-
-/* Get dependencies of function given some static inputs.
- * Returns NULL on failure (when not al
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list