[Bf-blender-cvs] [d5e9fa61d9d] functions: testing another way to use multi function contexts
Jacques Lucke
noreply at git.blender.org
Tue Nov 12 15:54:41 CET 2019
Commit: d5e9fa61d9d3ecac30b8de90d1e141f3c9a7f670
Author: Jacques Lucke
Date: Tue Nov 12 15:53:00 2019 +0100
Branches: functions
https://developer.blender.org/rBd5e9fa61d9d3ecac30b8de90d1e141f3c9a7f670
testing another way to use multi function contexts
===================================================================
M source/blender/functions/CMakeLists.txt
D source/blender/functions/FN_multi_function_common_context_ids.h
A source/blender/functions/FN_multi_function_common_contexts.h
M source/blender/functions/FN_multi_function_context.h
D source/blender/functions/intern/multi_function_common_context_ids.cc
A source/blender/functions/intern/multi_function_context.cc
M source/blender/functions/intern/multi_functions/mixed.cc
M source/blender/modifiers/intern/MOD_functiondeform.c
M source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
M source/blender/modifiers/intern/MOD_functionpoints_cxx.cc
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index c6cf83f8531..5d83c907b38 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -37,7 +37,7 @@ set(SRC
intern/generic_array_ref.cc
intern/generic_tuple.cc
intern/initialize.cc
- intern/multi_function_common_context_ids.cc
+ intern/multi_function_context.cc
intern/multi_function_network.cc
FN_attributes_block_container.h
@@ -49,7 +49,7 @@ set(SRC
FN_generic_virtual_list_list_ref.h
FN_generic_virtual_list_ref.h
FN_initialize.h
- FN_multi_function_common_context_ids.h
+ FN_multi_function_common_contexts.h
FN_multi_function_context.h
FN_multi_function_data_type.h
FN_multi_function_mask.h
diff --git a/source/blender/functions/FN_multi_function_common_context_ids.h b/source/blender/functions/FN_multi_function_common_context_ids.h
deleted file mode 100644
index 05ede273586..00000000000
--- a/source/blender/functions/FN_multi_function_common_context_ids.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef __FN_MULTI_FUNCTION_COMMON_CONTEXT_IDS_H__
-#define __FN_MULTI_FUNCTION_COMMON_CONTEXT_IDS_H__
-
-#ifdef FN_COMMON_CONTEXT_IDS_CC
-# define DEFINE_UNIQUE_CONTEXT_ID(name) \
- namespace UniqueVars { \
- char variable_with_unique_address_##name; \
- } \
- const void *name = (const void *)&UniqueVars::variable_with_unique_address_##name;
-
-#else
-# define DEFINE_UNIQUE_CONTEXT_ID(name) extern const void *name;
-#endif
-
-namespace FN {
-namespace ContextIDs {
-
-DEFINE_UNIQUE_CONTEXT_ID(vertex_locations);
-DEFINE_UNIQUE_CONTEXT_ID(current_frame);
-
-} // namespace ContextIDs
-} // namespace FN
-
-#endif /* __FN_MULTI_FUNCTION_COMMON_CONTEXT_IDS_H__ */
diff --git a/source/blender/functions/FN_multi_function_common_contexts.h b/source/blender/functions/FN_multi_function_common_contexts.h
new file mode 100644
index 00000000000..7f253295eec
--- /dev/null
+++ b/source/blender/functions/FN_multi_function_common_contexts.h
@@ -0,0 +1,25 @@
+#ifndef __FN_MULTI_FUNCTION_COMMON_CONTEXTS_H__
+#define __FN_MULTI_FUNCTION_COMMON_CONTEXTS_H__
+
+#include "FN_multi_function_context.h"
+
+#include "BLI_math_cxx.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+namespace FN {
+
+class VertexPositionArray : public MFElementContext {
+ public:
+ ArrayRef<BLI::float3> positions;
+};
+
+class SceneTimeContext : public MFElementContext {
+ public:
+ float time;
+};
+
+} // namespace FN
+
+#endif /* __FN_MULTI_FUNCTION_COMMON_CONTEXTS_H__ */
diff --git a/source/blender/functions/FN_multi_function_context.h b/source/blender/functions/FN_multi_function_context.h
index dddd577c0c9..a825a327d13 100644
--- a/source/blender/functions/FN_multi_function_context.h
+++ b/source/blender/functions/FN_multi_function_context.h
@@ -5,6 +5,7 @@
#include "BLI_optional.h"
#include "BLI_virtual_list_ref.h"
#include "BLI_vector.h"
+#include "BLI_utility_mixins.h"
namespace FN {
@@ -13,72 +14,87 @@ using BLI::Optional;
using BLI::Vector;
using BLI::VirtualListRef;
-class MFContext : BLI::NonCopyable, BLI::NonMovable {
+class MFElementContext {
+ public:
+ virtual ~MFElementContext();
+};
+
+class MFElementContexts {
private:
- ArrayRef<const void *> m_context_ids;
- ArrayRef<const void *> m_context_data;
- ArrayRef<VirtualListRef<uint>> m_context_indices;
+ ArrayRef<const MFElementContext *> m_contexts;
+ ArrayRef<VirtualListRef<uint>> m_indices;
public:
- MFContext(ArrayRef<const void *> context_ids,
- ArrayRef<const void *> context_data,
- ArrayRef<VirtualListRef<uint>> context_indices)
- : m_context_ids(context_ids),
- m_context_data(context_data),
- m_context_indices(context_indices)
+ MFElementContexts() = default;
+
+ MFElementContexts(ArrayRef<const MFElementContext *> contexts,
+ ArrayRef<VirtualListRef<uint>> indices)
+ : m_contexts(contexts), m_indices(indices)
{
- BLI_assert(m_context_ids.size() == m_context_data.size());
- BLI_assert(m_context_ids.size() == m_context_indices.size());
+ BLI_assert(contexts.size() == indices.size());
}
- struct ElementContext {
- const void *data;
+ template<typename T> struct TypedContext {
+ const T *data;
VirtualListRef<uint> indices;
};
- Optional<ElementContext> try_find_context(const void *context_type_id) const
+ template<typename T> Optional<TypedContext<T>> find_first() const
{
- int index = m_context_ids.first_index_try(context_type_id);
- if (index >= 0) {
- return ElementContext{m_context_data[index], m_context_indices[index]};
- }
- else {
- return {};
+ BLI_STATIC_ASSERT((std::is_base_of<MFElementContext, T>::value), "");
+ for (uint i = 0; i < m_contexts.size(); i++) {
+ const T *context = dynamic_cast<const T *>(m_contexts[i]);
+ if (context != nullptr) {
+ return TypedContext<T>{context, m_indices[i]};
+ }
}
+ return {};
+ }
+};
+
+class MFContext : BLI::NonCopyable, BLI::NonMovable {
+ private:
+ MFElementContexts m_element_contexts;
+
+ public:
+ MFContext() = default;
+ MFContext(MFElementContexts element_contexts) : m_element_contexts(element_contexts)
+ {
+ }
+
+ const MFElementContexts &element_contexts() const
+ {
+ return m_element_contexts;
}
};
class MFContextBuilder {
private:
- Vector<const void *> m_context_ids;
- Vector<const void *> m_context_data;
- Vector<VirtualListRef<uint>> m_context_indices;
+ Vector<const MFElementContext *> m_element_contexts;
+ Vector<VirtualListRef<uint>> m_element_context_indices;
MFContext m_context;
public:
- MFContextBuilder() : m_context({}, {}, {})
+ MFContextBuilder()
{
}
- void add(const void *id, const void *data, VirtualListRef<uint> indices)
+ void add_element_context(const MFElementContext *context, VirtualListRef<uint> indices)
{
- m_context_ids.append(id);
- m_context_data.append(data);
- m_context_indices.append(indices);
+ m_element_contexts.append(context);
+ m_element_context_indices.append(indices);
}
- void add(const void *id, const void *data)
+ void add_element_context(const MFElementContext *context)
{
static uint dummy_index = 0;
- m_context_ids.append(id);
- m_context_data.append(data);
- m_context_indices.append(VirtualListRef<uint>::FromSingle_MaxSize(&dummy_index));
+ this->add_element_context(context, VirtualListRef<uint>::FromSingle_MaxSize(&dummy_index));
}
MFContext &build()
{
m_context.~MFContext();
- new (&m_context) MFContext(m_context_ids, m_context_data, m_context_indices);
+ new (&m_context) MFContext(MFElementContexts(m_element_contexts, m_element_context_indices));
return m_context;
}
};
diff --git a/source/blender/functions/intern/multi_function_common_context_ids.cc b/source/blender/functions/intern/multi_function_common_context_ids.cc
deleted file mode 100644
index ab4a920ab8a..00000000000
--- a/source/blender/functions/intern/multi_function_common_context_ids.cc
+++ /dev/null
@@ -1,3 +0,0 @@
-#define FN_COMMON_CONTEXT_IDS_CC
-
-#include "FN_multi_function_common_context_ids.h"
diff --git a/source/blender/functions/intern/multi_function_context.cc b/source/blender/functions/intern/multi_function_context.cc
new file mode 100644
index 00000000000..e37558635b9
--- /dev/null
+++ b/source/blender/functions/intern/multi_function_context.cc
@@ -0,0 +1,9 @@
+#include "FN_multi_function_context.h"
+
+namespace FN {
+
+MFElementContext::~MFElementContext()
+{
+}
+
+} // namespace FN
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc
index fe191e86c2d..b3ea925ff32 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -2,7 +2,7 @@
#include "FN_generic_array_ref.h"
#include "FN_generic_vector_array.h"
-#include "FN_multi_function_common_context_ids.h"
+#include "FN_multi_function_common_contexts.h"
#include "BLI_math_cxx.h"
#include "BLI_lazy_init_cxx.h"
@@ -489,13 +489,12 @@ MF_ContextVertexPosition::MF_ContextVertexPosition()
void MF_ContextVertexPosition::call(const MFMask &mask, MFParams ¶ms, MFContext &context) const
{
MutableArrayRef<float3> positions = params.uninitialized_single_output<float3>(0, "Position");
- auto positions_context = context.try_find_context(ContextIDs::vertex_locations);
+ auto vertices_context = context.element_contexts().find_first<VertexPositionArray>();
- if (positions_context.has_value()) {
- ArrayRef<float3> vertex_positions = *(ArrayRef<float3> *)positions_context.value().data;
+ if (vertices_context.has_value()) {
for (uint i : mask.indices()) {
- uint context_index = positions_context.value().indices[i];
- positions[i] = vertex_positions[context_index];
+ uint context_index = vertices_context.value().indices[i];
+ positions[i] = vertices_context.value().data->positions[context_index];
}
}
else {
@@ -513,10 +512,11 @@ MF_ContextCurrentFrame::MF_ContextCurrentFrame()
void MF_ContextCurrentFrame::call(const MFMask &mask, MFParams ¶ms, MFContext &context) const
{
MutableArrayRef<float> frames = params.uninitialized_single_output<float>(0, "Frame");
- auto context_data = context.try_find_context(ContextIDs::current_frame);
- if (context_data.has_value()) {
- float current_frame = *(float *)context_data.value().data;
+ auto time_context = context.element_contexts().find_first<SceneTimeContext>();
+
+ if (time_context.has_value()) {
+ float current_frame = time_context.value().data->time;
frames.fill_indices(mask.indices(), current_frame);
}
else {
diff --git a/source/blender/modifiers/intern/MOD_functiondeform.c b/source/blender/modifiers/intern/MOD_functiondeform.c
index d969b7f47f6..3f2d4f2b102 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform.c
+++ b/source/blender/modifiers/intern/MOD_functiondeform.c
@@ -54,25 +54,26 @@
void MOD_functiondeform_do(FunctionDeformModifierData *fdmd,
float (*vertexCos)[3],
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list