[Bf-blender-cvs] [c2d3708224c] functions: introduce MutableAttributesRef

Jacques Lucke noreply at git.blender.org
Thu Jan 2 16:37:39 CET 2020


Commit: c2d3708224c1df8976f8a54ad80e9bce62f8839c
Author: Jacques Lucke
Date:   Tue Dec 31 14:59:48 2019 +0100
Branches: functions
https://developer.blender.org/rBc2d3708224c1df8976f8a54ad80e9bce62f8839c

introduce MutableAttributesRef

===================================================================

M	source/blender/functions/FN_attributes_block_container.h
M	source/blender/functions/FN_attributes_ref.h
M	source/blender/functions/intern/attributes_block_container.cc
M	source/blender/functions/intern/attributes_ref.cc
M	source/blender/functions/intern/multi_functions/particles.cc
M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/block_step_data.hpp
M	source/blender/simulations/bparticles/integrator.cpp
M	source/blender/simulations/bparticles/particle_action.cpp
M	source/blender/simulations/bparticles/particle_action.hpp
M	source/blender/simulations/bparticles/particle_allocator.cpp
M	source/blender/simulations/bparticles/particles_state.hpp
M	source/blender/simulations/bparticles/simulate.cpp

===================================================================

diff --git a/source/blender/functions/FN_attributes_block_container.h b/source/blender/functions/FN_attributes_block_container.h
index 7cd5364d8c7..0d44d070584 100644
--- a/source/blender/functions/FN_attributes_block_container.h
+++ b/source/blender/functions/FN_attributes_block_container.h
@@ -101,14 +101,14 @@ class AttributesBlock : BLI::NonCopyable, BLI::NonMovable {
     return m_owner;
   }
 
-  AttributesRef as_ref()
+  MutableAttributesRef as_ref()
   {
-    return AttributesRef(m_owner.info(), m_buffers, m_used_size);
+    return MutableAttributesRef(m_owner.info(), m_buffers, m_used_size);
   }
 
-  AttributesRef as_ref__all()
+  MutableAttributesRef as_ref__all()
   {
-    return AttributesRef(m_owner.info(), m_buffers, this->capacity());
+    return MutableAttributesRef(m_owner.info(), m_buffers, this->capacity());
   }
 
   ArrayRef<void *> buffers()
diff --git a/source/blender/functions/FN_attributes_ref.h b/source/blender/functions/FN_attributes_ref.h
index 6e7ee468e2b..2648f4da973 100644
--- a/source/blender/functions/FN_attributes_ref.h
+++ b/source/blender/functions/FN_attributes_ref.h
@@ -186,19 +186,21 @@ class AttributesInfo : BLI::NonCopyable, BLI::NonMovable {
   }
 };
 
-class AttributesRef {
+class MutableAttributesRef {
  private:
   const AttributesInfo *m_info;
   ArrayRef<void *> m_buffers;
   IndexRange m_range;
 
+  friend class AttributesRef;
+
  public:
-  AttributesRef(const AttributesInfo &info, ArrayRef<void *> buffers, uint size)
-      : AttributesRef(info, buffers, IndexRange(size))
+  MutableAttributesRef(const AttributesInfo &info, ArrayRef<void *> buffers, uint size)
+      : MutableAttributesRef(info, buffers, IndexRange(size))
   {
   }
 
-  AttributesRef(const AttributesInfo &info, ArrayRef<void *> buffers, IndexRange range)
+  MutableAttributesRef(const AttributesInfo &info, ArrayRef<void *> buffers, IndexRange range)
       : m_info(&info), m_buffers(buffers), m_range(range)
   {
   }
@@ -258,24 +260,105 @@ class AttributesRef {
     }
   }
 
-  AttributesRef slice(IndexRange range) const
+  MutableAttributesRef slice(IndexRange range) const
   {
     return this->slice(range.start(), range.size());
   }
 
-  AttributesRef slice(uint start, uint size) const
+  MutableAttributesRef slice(uint start, uint size) const
   {
-    return AttributesRef(*m_info, m_buffers, m_range.slice(start, size));
+    return MutableAttributesRef(*m_info, m_buffers, m_range.slice(start, size));
   }
 
-  AttributesRef take_front(uint n) const
+  MutableAttributesRef take_front(uint n) const
   {
     return this->slice(0, n);
   }
 
   void destruct_and_reorder(IndexMask indices_to_destruct);
 
-  static void RelocateUninitialized(AttributesRef from, AttributesRef to);
+  static void RelocateUninitialized(MutableAttributesRef from, MutableAttributesRef to);
+};
+
+class AttributesRef {
+ private:
+  mutable MutableAttributesRef m_ref;
+
+ public:
+  AttributesRef(const AttributesInfo &info, ArrayRef<void *> buffers, uint size)
+      : m_ref(info, buffers, IndexRange(size))
+  {
+  }
+
+  AttributesRef(const AttributesInfo &info, ArrayRef<void *> buffers, IndexRange range)
+      : m_ref(info, buffers, range)
+  {
+  }
+
+  AttributesRef(MutableAttributesRef ref) : m_ref(ref)
+  {
+  }
+
+  uint size() const
+  {
+    return m_ref.size();
+  }
+
+  const AttributesInfo &info() const
+  {
+    return m_ref.info();
+  }
+
+  GenericArrayRef get(uint index) const
+  {
+    return m_ref.get(index);
+  }
+
+  GenericArrayRef get(StringRef name) const
+  {
+    return m_ref.get(name);
+  }
+
+  template<typename T> ArrayRef<T> get(uint index) const
+  {
+    return m_ref.get<T>(index);
+  }
+
+  template<typename T> ArrayRef<T> get(StringRef name) const
+  {
+    return m_ref.get<T>(name);
+  }
+
+  Optional<GenericArrayRef> try_get(StringRef name, const CPPType &type) const
+  {
+    Optional<GenericMutableArrayRef> array = m_ref.try_get(name, type);
+    if (array.has_value()) {
+      return GenericArrayRef(array.value());
+    }
+    else {
+      return {};
+    }
+  }
+
+  template<typename T> Optional<ArrayRef<T>> try_get(StringRef name)
+  {
+    return m_ref.try_get<T>(name);
+  }
+
+  AttributesRef slice(IndexRange range) const
+  {
+    return m_ref.slice(range);
+  }
+
+  AttributesRef slice(uint start, uint size) const
+  {
+    return m_ref.slice(start, size);
+  }
+
+  AttributesRef take_front(uint n) const
+  {
+    return this->slice(0, n);
+  }
 };
 
 class AttributesRefGroup {
@@ -301,7 +384,7 @@ class AttributesRefGroup {
     BLI_assert(m_info->type_of(index) == CPP_TYPE<T>());
 
     uint offset = 0;
-    for (AttributesRef attributes : *this) {
+    for (MutableAttributesRef attributes : *this) {
       MutableArrayRef<T> array = attributes.get<T>(index);
       array.copy_from(data.slice(offset, array.size()));
       offset += array.size();
@@ -319,7 +402,7 @@ class AttributesRefGroup {
     BLI_assert(m_info->type_of(index) == data.type());
 
     uint offset = 0;
-    for (AttributesRef attributes : *this) {
+    for (MutableAttributesRef attributes : *this) {
       GenericMutableArrayRef array = attributes.get(index);
       array.type().copy_to_initialized_n(data[offset], array[0], attributes.size());
       offset += attributes.size();
@@ -361,7 +444,7 @@ class AttributesRefGroup {
     BLI_assert(m_info->type_of(index) == data.type());
 
     uint src_index = 0;
-    for (AttributesRef attributes : *this) {
+    for (MutableAttributesRef attributes : *this) {
       GenericMutableArrayRef array = attributes.get(index);
 
       for (uint i = 0; i < attributes.size(); i++) {
@@ -383,7 +466,7 @@ class AttributesRefGroup {
   {
     BLI_assert(m_info->type_of(index) == CPP_TYPE<T>());
 
-    for (AttributesRef attributes : *this) {
+    for (MutableAttributesRef attributes : *this) {
       MutableArrayRef<T> array = attributes.get<T>(index);
       array.fill(value);
     }
@@ -399,7 +482,7 @@ class AttributesRefGroup {
     BLI_assert(m_info->type_of(index) == type);
     UNUSED_VARS_NDEBUG(type);
 
-    for (AttributesRef attributes : *this) {
+    for (MutableAttributesRef attributes : *this) {
       GenericMutableArrayRef array = attributes.get(index);
       array.fill__initialized(value);
     }
@@ -431,9 +514,9 @@ class AttributesRefGroup {
       return *this;
     }
 
-    AttributesRef operator*()
+    MutableAttributesRef operator*()
     {
-      return AttributesRef(
+      return MutableAttributesRef(
           *m_group->m_info, m_group->m_buffers[m_current], m_group->m_ranges[m_current]);
     }
 
diff --git a/source/blender/functions/intern/attributes_block_container.cc b/source/blender/functions/intern/attributes_block_container.cc
index eaf373b17b6..88ae4700d2e 100644
--- a/source/blender/functions/intern/attributes_block_container.cc
+++ b/source/blender/functions/intern/attributes_block_container.cc
@@ -108,10 +108,11 @@ void AttributesBlock::MoveUntilFull(AttributesBlock &from, AttributesBlock &to)
     return;
   }
 
-  AttributesRef from_ref = from.as_ref__all().slice(from.used_size() - move_amount, move_amount);
-  AttributesRef to_ref = to.as_ref__all().slice(to.used_size(), move_amount);
+  MutableAttributesRef from_ref = from.as_ref__all().slice(from.used_size() - move_amount,
+                                                           move_amount);
+  MutableAttributesRef to_ref = to.as_ref__all().slice(to.used_size(), move_amount);
 
-  AttributesRef::RelocateUninitialized(from_ref, to_ref);
+  MutableAttributesRef::RelocateUninitialized(from_ref, to_ref);
 
   from.set_used_size(from.used_size() - move_amount);
   to.set_used_size(to.used_size() + move_amount);
diff --git a/source/blender/functions/intern/attributes_ref.cc b/source/blender/functions/intern/attributes_ref.cc
index b0329b5e6ca..78ab5612f79 100644
--- a/source/blender/functions/intern/attributes_ref.cc
+++ b/source/blender/functions/intern/attributes_ref.cc
@@ -47,7 +47,7 @@ AttributesInfo::~AttributesInfo()
   }
 }
 
-void AttributesRef::destruct_and_reorder(IndexMask index_mask)
+void MutableAttributesRef::destruct_and_reorder(IndexMask index_mask)
 {
 #ifdef DEBUG
   BLI_assert(index_mask.size() <= m_range.size());
@@ -77,7 +77,8 @@ void AttributesRef::destruct_and_reorder(IndexMask index_mask)
   }
 }
 
-void AttributesRef::RelocateUninitialized(AttributesRef from, AttributesRef to)
+void MutableAttributesRef::RelocateUninitialized(MutableAttributesRef from,
+                                                 MutableAttributesRef to)
 {
   BLI_assert(from.size() == to.size());
   BLI_assert(&from.info() == &to.info());
diff --git a/source/blender/functions/intern/multi_functions/particles.cc b/source/blender/functions/intern/multi_functions/particles.cc
index 06c49a4d777..5dfb356e9dd 100644
--- a/source/blender/functions/intern/multi_functions/particles.cc
+++ b/source/blender/functions/intern/multi_functions/particles.cc
@@ -30,12 +30,12 @@ void MF_ParticleAttribute::call(IndexMask mask, MFParams params, MFContext conte
 
   group_indices_by_same_value(
       mask, attribute_names, [&](StringRef attribute_name, IndexMask indices_with_same_name) {
-        Optional<GenericMutableArrayRef> opt_array = attributes.try_get(attribute_name, m_type);
+        Optional<GenericArrayRef> opt_array = attributes.try_get(attribute_name, m_type);
         if (!opt_array.has_value()) {
           r_values.default_initialize(indices_with_same_name);
           return;
         }
-        GenericMutableArrayRef array = opt_array.value();
+        GenericArrayRef array = opt_array.value();
         if (element_indices.is_direct_mapping()) {
           m_type.copy_to_uninitialized_indices(
               array.buffer(), r_values.buffer(), indices_with_same_name);
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 3f74a447260..c60a7967b98 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -22,7 +22,7 @@ static void update_position_and_velocity_offsets(ParticleActionContext &context)
   }
 
   AttributesRef attributes = context.attributes();
-  AttributesRef attribute_offsets = 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list