[Bf-blender-cvs] [d00557bd19a] functions: use IndexMask in more places
Jacques Lucke
noreply at git.blender.org
Sun Dec 22 14:25:30 CET 2019
Commit: d00557bd19ac55179e59d1b760622c3744e54e6d
Author: Jacques Lucke
Date: Fri Dec 20 16:37:50 2019 +0100
Branches: functions
https://developer.blender.org/rBd00557bd19ac55179e59d1b760622c3744e54e6d
use IndexMask in more places
===================================================================
M source/blender/blenlib/BLI_index_mask.h
M source/blender/functions/FN_attributes_block_container.h
M source/blender/functions/FN_attributes_ref.h
M source/blender/functions/FN_generic_array_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/network.cc
M source/blender/functions/intern/multi_functions/particles.cc
M source/blender/functions/intern/multi_functions/surface_hook.cc
M source/blender/functions/intern/multi_functions/util.h
M source/blender/functions/intern/multi_functions/vectorize.cc
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/blenlib/BLI_index_mask.h b/source/blender/blenlib/BLI_index_mask.h
index 8a120adb775..f61f7351358 100644
--- a/source/blender/blenlib/BLI_index_mask.h
+++ b/source/blender/blenlib/BLI_index_mask.h
@@ -30,7 +30,27 @@ class IndexMask {
{
}
- uint indices_amount() const
+ operator ArrayRef<uint>() const
+ {
+ return m_indices;
+ }
+
+ const uint *begin() const
+ {
+ return m_indices.begin();
+ }
+
+ const uint *end() const
+ {
+ return m_indices.end();
+ }
+
+ uint operator[](uint index) const
+ {
+ return m_indices[index];
+ }
+
+ uint size() const
{
return m_indices.size();
}
@@ -70,6 +90,16 @@ class IndexMask {
}
}
}
+
+ IndexRange index_iterator() const
+ {
+ return m_indices.index_iterator();
+ }
+
+ uint last() const
+ {
+ return m_indices.last();
+ }
};
} // namespace BLI
diff --git a/source/blender/functions/FN_attributes_block_container.h b/source/blender/functions/FN_attributes_block_container.h
index b7e07820534..7cd5364d8c7 100644
--- a/source/blender/functions/FN_attributes_block_container.h
+++ b/source/blender/functions/FN_attributes_block_container.h
@@ -94,7 +94,7 @@ class AttributesBlock : BLI::NonCopyable, BLI::NonMovable {
m_used_size = new_used_size;
}
- void destruct_and_reorder(ArrayRef<uint> sorted_indices_to_destruct);
+ void destruct_and_reorder(IndexMask indices_to_destruct);
AttributesBlockContainer &owner()
{
diff --git a/source/blender/functions/FN_attributes_ref.h b/source/blender/functions/FN_attributes_ref.h
index 140ec148564..6e7ee468e2b 100644
--- a/source/blender/functions/FN_attributes_ref.h
+++ b/source/blender/functions/FN_attributes_ref.h
@@ -273,7 +273,7 @@ class AttributesRef {
return this->slice(0, n);
}
- void destruct_and_reorder(ArrayRef<uint> sorted_indices_to_destruct);
+ void destruct_and_reorder(IndexMask indices_to_destruct);
static void RelocateUninitialized(AttributesRef from, AttributesRef to);
};
diff --git a/source/blender/functions/FN_generic_array_ref.h b/source/blender/functions/FN_generic_array_ref.h
index 54ed98278e1..4e46fa4eafb 100644
--- a/source/blender/functions/FN_generic_array_ref.h
+++ b/source/blender/functions/FN_generic_array_ref.h
@@ -96,7 +96,7 @@ class GenericMutableArrayRef {
m_type->destruct_n(m_buffer, m_size);
}
- void destruct_indices(ArrayRef<uint> indices)
+ void destruct_indices(IndexMask indices)
{
m_type->destruct_indices(m_buffer, indices);
}
@@ -122,7 +122,7 @@ class GenericMutableArrayRef {
return m_size;
}
- void default_initialize(ArrayRef<uint> indices)
+ void default_initialize(IndexMask indices)
{
m_type->construct_default_indices(m_buffer, indices);
}
diff --git a/source/blender/functions/intern/attributes_block_container.cc b/source/blender/functions/intern/attributes_block_container.cc
index e772584cfda..eaf373b17b6 100644
--- a/source/blender/functions/intern/attributes_block_container.cc
+++ b/source/blender/functions/intern/attributes_block_container.cc
@@ -93,10 +93,10 @@ AttributesBlock::~AttributesBlock()
}
}
-void AttributesBlock::destruct_and_reorder(ArrayRef<uint> sorted_indices_to_destruct)
+void AttributesBlock::destruct_and_reorder(IndexMask indices_to_destruct)
{
- this->as_ref().destruct_and_reorder(sorted_indices_to_destruct);
- this->set_used_size(m_used_size - sorted_indices_to_destruct.size());
+ this->as_ref().destruct_and_reorder(indices_to_destruct);
+ this->set_used_size(m_used_size - indices_to_destruct.size());
}
void AttributesBlock::MoveUntilFull(AttributesBlock &from, AttributesBlock &to)
diff --git a/source/blender/functions/intern/attributes_ref.cc b/source/blender/functions/intern/attributes_ref.cc
index 13c1df1f2f6..b0329b5e6ca 100644
--- a/source/blender/functions/intern/attributes_ref.cc
+++ b/source/blender/functions/intern/attributes_ref.cc
@@ -47,13 +47,13 @@ AttributesInfo::~AttributesInfo()
}
}
-void AttributesRef::destruct_and_reorder(ArrayRef<uint> indices)
+void AttributesRef::destruct_and_reorder(IndexMask index_mask)
{
#ifdef DEBUG
- BLI_assert(indices.size() <= m_range.size());
- BLI_assert(indices.size() == 0 || indices.last() < m_range.size());
- for (uint i = 1; i < indices.size(); i++) {
- BLI_assert(indices[i - 1] < indices[i]);
+ BLI_assert(index_mask.size() <= m_range.size());
+ BLI_assert(index_mask.size() == 0 || index_mask.last() < m_range.size());
+ for (uint i = 1; i < index_mask.size(); i++) {
+ BLI_assert(index_mask[i - 1] < index_mask[i]);
}
#endif
@@ -61,11 +61,11 @@ void AttributesRef::destruct_and_reorder(ArrayRef<uint> indices)
GenericMutableArrayRef array = this->get(attribute_index);
const CPPType &type = m_info->type_of(attribute_index);
- array.destruct_indices(indices);
+ array.destruct_indices(index_mask);
- for (uint i = 0; i < indices.size(); i++) {
+ for (uint i : index_mask.index_iterator()) {
uint last_index = m_range.size() - 1 - i;
- uint index_to_remove = indices[indices.size() - 1 - i];
+ uint index_to_remove = index_mask[index_mask.size() - 1 - i];
if (index_to_remove == last_index) {
/* Do nothing. It has been destructed before. */
}
diff --git a/source/blender/functions/intern/multi_functions/network.cc b/source/blender/functions/intern/multi_functions/network.cc
index b6ea8ee4a4c..397af26e87b 100644
--- a/source/blender/functions/intern/multi_functions/network.cc
+++ b/source/blender/functions/intern/multi_functions/network.cc
@@ -24,11 +24,11 @@ class MF_EvaluateNetwork_Storage {
delete vector_array;
}
for (GenericMutableArrayRef array : m_arrays) {
- array.destruct_indices(m_mask.indices());
+ array.destruct_indices(m_mask);
MEM_freeN(array.buffer());
}
for (GenericMutableArrayRef array : m_single_element_arrays) {
- array.destruct_indices({0});
+ array.destruct_indices(IndexMask(1));
MEM_freeN(array.buffer());
}
}
@@ -244,7 +244,7 @@ MF_EvaluateNetwork::MF_EvaluateNetwork(Vector<const MFOutputSocket *> inputs,
void MF_EvaluateNetwork::call(IndexMask mask, MFParams params, MFContext context) const
{
- if (mask.indices_amount() == 0) {
+ if (mask.size() == 0) {
return;
}
diff --git a/source/blender/functions/intern/multi_functions/particles.cc b/source/blender/functions/intern/multi_functions/particles.cc
index 9212c9b8fa4..5fab7a50865 100644
--- a/source/blender/functions/intern/multi_functions/particles.cc
+++ b/source/blender/functions/intern/multi_functions/particles.cc
@@ -29,9 +29,7 @@ void MF_ParticleAttribute::call(IndexMask mask, MFParams params, MFContext conte
VirtualListRef<uint> element_indices = context_data->indices;
group_indices_by_same_value(
- mask.indices(),
- attribute_names,
- [&](StringRef attribute_name, ArrayRef<uint> indices_with_same_name) {
+ mask, attribute_names, [&](StringRef attribute_name, IndexMask indices_with_same_name) {
Optional<GenericMutableArrayRef> opt_array = attributes.try_get(attribute_name, m_type);
if (!opt_array.has_value()) {
r_values.default_initialize(indices_with_same_name);
@@ -64,18 +62,17 @@ void MF_EmitterTimeInfo::call(IndexMask mask, MFParams params, MFContext context
auto *time_context = context.try_find_global<EmitterTimeInfoContext>();
- ArrayRef<uint> indices = mask.indices();
if (time_context == nullptr) {
- r_durations.fill_indices(indices, 0.0f);
- r_begins.fill_indices(indices, 0.0f);
- r_ends.fill_indices(indices, 0.0f);
- r_steps.fill_indices(indices, 0);
+ r_durations.fill_indices(mask, 0.0f);
+ r_begins.fill_indices(mask, 0.0f);
+ r_ends.fill_indices(mask, 0.0f);
+ r_steps.fill_indices(mask, 0);
}
else {
- r_durations.fill_indices(indices, time_context->duration);
- r_begins.fill_indices(indices, time_context->begin);
- r_ends.fill_indices(indices, time_context->end);
- r_steps.fill_indices(indices, time_context->step);
+ r_durations.fill_indices(mask, time_context->duration);
+ r_begins.fill_indices(mask, time_context->begin);
+ r_ends.fill_indices(mask, time_context->end);
+ r_steps.fill_indices(mask, time_context->step);
}
}
diff --git a/source/blender/functions/intern/multi_functions/surface_hook.cc b/source/blender/functions/intern/multi_functions/surface_hook.cc
index 27046f88ef6..2c9ab2f2e34 100644
--- a/source/blender/functions/intern/multi_functions/surface_hook.cc
+++ b/source/blender/functions/intern/multi_functions/surface_hook.cc
@@ -89,7 +89,7 @@ void MF_ClosestSurfaceHookOnObject::call(IndexMask mask, MFParams params, MFCont
group_indices_by_same_value(
mask.indices(),
object_handles,
- [&](ObjectIDHandle object_handle, ArrayRef<uint> indices_with_same_object) {
+ [&](ObjectIDHandle object_handle, IndexMask indices_with_same_object) {
Object *object = id_handle_lookup->lookup(object_handle);
if (object == nullptr) {
r_surface_hooks.fill_indices(indices_with_same_object, {});
@@ -146,7 +146,7 @@ void MF_GetPositionOnSurface::call(IndexMask mask, MFParams params, MFContext co
group_indices_by_same_value(
mask.indices(),
surface_hooks,
- [&](SurfaceHook base_hook, ArrayRef<uint> indices_on_same_surface) {
+ [&](SurfaceHook base_hook, IndexMask indices_on_same_surface) {
if (base_hook.type() != BKE::SurfaceHookType::MeshObject) {
r_positions.fill_indices(indices_on_same_surface, fallback);
return;
@@ -217,7 +217,7 @@ void MF_GetNormalOnSurface::call(IndexMask mask, MFParams params, MFContext cont
group_indices_by_same_value(
mask.indices(),
surface_hooks,
- [&](SurfaceHook base_hook, ArrayRef<uint> indices_on_same_surface) {
+ [&](SurfaceHook base_hook, IndexMask indices_on_same_surface) {
if (base_hook.type() != BKE::SurfaceHookType::MeshObject) {
r_normals.fill_indices(indices_on_same_surface, fallback);
return;
@@ -285,7 +285,7 @@ void MF_GetWeightOnSurface::call(IndexMask mask, MFParams params, MFContext cont
group_in
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list