[Bf-blender-cvs] [eaa0c567fc7] functions: make element contexts non virtual
Jacques Lucke
noreply at git.blender.org
Wed Dec 11 10:53:43 CET 2019
Commit: eaa0c567fc70697de7febc8d6564136166cfcab2
Author: Jacques Lucke
Date: Wed Dec 11 10:21:44 2019 +0100
Branches: functions
https://developer.blender.org/rBeaa0c567fc70697de7febc8d6564136166cfcab2
make element contexts non virtual
===================================================================
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_multi_function_common_contexts.h
M source/blender/functions/FN_multi_function_context.h
A source/blender/functions/intern/multi_function_common_contexts.cc
M source/blender/functions/intern/multi_function_context.cc
M source/blender/functions/intern/multi_functions/mixed.cc
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index f4702536bbf..7e274d38d34 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -9,7 +9,7 @@ set(INC
../imbuf
../../../intern/guardedalloc
)
-
+
set(INC_SYS
${LLVM_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
@@ -38,6 +38,7 @@ set(SRC
intern/generic_array_ref.cc
intern/generic_tuple.cc
intern/initialize.cc
+ intern/multi_function_common_contexts.cc
intern/multi_function_context.cc
intern/multi_function_network.cc
diff --git a/source/blender/functions/FN_multi_function_common_contexts.h b/source/blender/functions/FN_multi_function_common_contexts.h
index 8d41e9c888e..eb2049c66b9 100644
--- a/source/blender/functions/FN_multi_function_common_contexts.h
+++ b/source/blender/functions/FN_multi_function_common_contexts.h
@@ -21,17 +21,17 @@ namespace FN {
using BLI::Map;
-class VertexPositionArray : public MFElementContext {
+class VertexPositionArray {
public:
ArrayRef<BLI::float3> positions;
};
-class SceneTimeContext : public MFElementContext {
+class SceneTimeContext {
public:
float time;
};
-class ParticleAttributesContext : public MFElementContext {
+class ParticleAttributesContext {
public:
AttributesRef attributes;
@@ -40,7 +40,7 @@ class ParticleAttributesContext : public MFElementContext {
}
};
-class ExternalDataCacheContext : public MFElementContext {
+class ExternalDataCacheContext {
private:
mutable Map<Object *, BVHTreeFromMesh *> m_bvh_trees;
mutable std::mutex m_bvt_trees_mutex;
diff --git a/source/blender/functions/FN_multi_function_context.h b/source/blender/functions/FN_multi_function_context.h
index 00b8b8b3b0f..966aa6dadfb 100644
--- a/source/blender/functions/FN_multi_function_context.h
+++ b/source/blender/functions/FN_multi_function_context.h
@@ -19,14 +19,20 @@ using BLI::Optional;
using BLI::Vector;
using BLI::VirtualListRef;
-class MFElementContext {
- public:
- virtual ~MFElementContext();
-};
+template<typename T> uintptr_t get_multi_function_element_context_id();
+
+#define FN_MAKE_MF_ELEMENT_CONTEXT(name) \
+ char name##_id_char = 0; \
+ uintptr_t name##_id = (uintptr_t)&name##_id_char; \
+ template<> uintptr_t get_multi_function_element_context_id<name>() \
+ { \
+ return name##_id; \
+ }
class MFElementContexts {
private:
- Vector<const MFElementContext *> m_contexts;
+ Vector<uintptr_t> m_ids;
+ Vector<const void *> m_contexts;
Vector<VirtualListRef<uint>> m_indices;
friend class MFContextBuilder;
@@ -39,12 +45,12 @@ class MFElementContexts {
VirtualListRef<uint> indices;
};
- template<typename T> Optional<TypedContext<T>> find_first() const
+ template<typename T> Optional<TypedContext<T>> try_find() const
{
- BLI_STATIC_ASSERT((std::is_base_of<MFElementContext, T>::value), "");
+ uintptr_t context_id = get_multi_function_element_context_id<T>();
for (uint i : m_contexts.index_iterator()) {
- const T *context = dynamic_cast<const T *>(m_contexts[i]);
- if (context != nullptr) {
+ if (m_ids[i] == context_id) {
+ const T *context = (const T *)m_contexts[i];
return TypedContext<T>{context, m_indices[i]};
}
}
@@ -66,19 +72,20 @@ class MFContextBuilder : BLI::NonCopyable, BLI::NonMovable {
{
}
- void add_element_context(const MFElementContext &context, VirtualListRef<uint> indices)
+ template<typename T> void add_element_context(const T &context, VirtualListRef<uint> indices)
{
- m_element_contexts.m_contexts.append(&context);
+ m_element_contexts.m_ids.append(get_multi_function_element_context_id<T>());
+ m_element_contexts.m_contexts.append((const void *)&context);
m_element_contexts.m_indices.append(indices);
}
- void add_element_context(const MFElementContext &context, IndexRange indices)
+ template<typename T> void add_element_context(const T &context, IndexRange indices)
{
this->add_element_context(context,
VirtualListRef<uint>::FromFullArray(indices.as_array_ref()));
}
- void add_element_context(const MFElementContext &context)
+ template<typename T> void add_element_context(const T &context)
{
static uint dummy_index = 0;
this->add_element_context(context, VirtualListRef<uint>::FromSingle_MaxSize(&dummy_index));
diff --git a/source/blender/functions/intern/multi_function_common_contexts.cc b/source/blender/functions/intern/multi_function_common_contexts.cc
new file mode 100644
index 00000000000..1f4ca5c7cd6
--- /dev/null
+++ b/source/blender/functions/intern/multi_function_common_contexts.cc
@@ -0,0 +1,10 @@
+#include "FN_multi_function_common_contexts.h"
+
+namespace FN {
+
+FN_MAKE_MF_ELEMENT_CONTEXT(VertexPositionArray)
+FN_MAKE_MF_ELEMENT_CONTEXT(SceneTimeContext)
+FN_MAKE_MF_ELEMENT_CONTEXT(ParticleAttributesContext)
+FN_MAKE_MF_ELEMENT_CONTEXT(ExternalDataCacheContext)
+
+} // namespace FN
diff --git a/source/blender/functions/intern/multi_function_context.cc b/source/blender/functions/intern/multi_function_context.cc
index e37558635b9..c58331b4895 100644
--- a/source/blender/functions/intern/multi_function_context.cc
+++ b/source/blender/functions/intern/multi_function_context.cc
@@ -2,8 +2,4 @@
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 2488e90b06d..52777647ea3 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -744,7 +744,7 @@ MF_ContextVertexPosition::MF_ContextVertexPosition()
void MF_ContextVertexPosition::call(MFMask mask, MFParams params, MFContext context) const
{
MutableArrayRef<float3> positions = params.uninitialized_single_output<float3>(0, "Position");
- auto vertices_context = context.element_contexts().find_first<VertexPositionArray>();
+ auto vertices_context = context.element_contexts().try_find<VertexPositionArray>();
if (vertices_context.has_value()) {
for (uint i : mask.indices()) {
@@ -769,7 +769,7 @@ void MF_ContextCurrentFrame::call(MFMask mask, MFParams params, MFContext contex
{
MutableArrayRef<float> frames = params.uninitialized_single_output<float>(0, "Frame");
- auto time_context = context.element_contexts().find_first<SceneTimeContext>();
+ auto time_context = context.element_contexts().try_find<SceneTimeContext>();
if (time_context.has_value()) {
float current_frame = time_context.value().data->time;
@@ -831,7 +831,7 @@ MF_ParticleAttributes::MF_ParticleAttributes(Vector<std::string> attribute_names
void MF_ParticleAttributes::call(MFMask mask, MFParams params, MFContext context) const
{
- auto context_data = context.element_contexts().find_first<ParticleAttributesContext>();
+ auto context_data = context.element_contexts().try_find<ParticleAttributesContext>();
for (uint i = 0; i < m_attribute_names.size(); i++) {
StringRef attribute_name = m_attribute_names[i];
@@ -874,7 +874,7 @@ void MF_ParticleIsInGroup::call(MFMask mask, MFParams params, MFContext context)
0, "Group Name");
MutableArrayRef<bool> r_is_in_group = params.uninitialized_single_output<bool>(1, "Is in Group");
- auto context_data = context.element_contexts().find_first<ParticleAttributesContext>();
+ auto context_data = context.element_contexts().try_find<ParticleAttributesContext>();
if (!context_data.has_value()) {
r_is_in_group.fill_indices(mask.indices(), false);
return;
@@ -935,7 +935,7 @@ static float3 get_barycentric_coords(Mesh *mesh,
void MF_ClosestSurfaceHookOnObject::call(MFMask mask, MFParams params, MFContext context) const
{
- auto context_data = context.element_contexts().find_first<ExternalDataCacheContext>();
+ auto context_data = context.element_contexts().try_find<ExternalDataCacheContext>();
VirtualListRef<ObjectIDHandle> objects = params.readonly_single_input<ObjectIDHandle>(0,
"Object");
More information about the Bf-blender-cvs
mailing list