[Bf-blender-cvs] [cdfb3d3a28d] functions: move responsibility of keeping track of particle ids
Jacques Lucke
noreply at git.blender.org
Fri Sep 20 16:38:26 CEST 2019
Commit: cdfb3d3a28df71cfe4ed0d4887fdbfc062787c3d
Author: Jacques Lucke
Date: Fri Sep 20 16:09:01 2019 +0200
Branches: functions
https://developer.blender.org/rBcdfb3d3a28df71cfe4ed0d4887fdbfc062787c3d
move responsibility of keeping track of particle ids
===================================================================
M source/blender/blenkernel/BKE_attributes_block_container.hpp
M source/blender/simulations/bparticles/particle_allocator.cpp
M source/blender/simulations/bparticles/particle_allocator.hpp
M source/blender/simulations/bparticles/particles_state.hpp
===================================================================
diff --git a/source/blender/blenkernel/BKE_attributes_block_container.hpp b/source/blender/blenkernel/BKE_attributes_block_container.hpp
index 5f5b3bab91a..6dd111e55f7 100644
--- a/source/blender/blenkernel/BKE_attributes_block_container.hpp
+++ b/source/blender/blenkernel/BKE_attributes_block_container.hpp
@@ -17,7 +17,6 @@ class AttributesBlockContainer : BLI::NonCopyable, BLI::NonMovable {
uint m_block_size;
VectorSet<AttributesBlock *> m_active_blocks;
std::mutex m_blocks_mutex;
- std::atomic<uint> m_next_id;
public:
AttributesBlockContainer(AttributesInfo attributes_info, uint block_size);
@@ -50,12 +49,6 @@ class AttributesBlockContainer : BLI::NonCopyable, BLI::NonMovable {
return &a == &b;
}
- IndexRange new_ids(uint amount)
- {
- uint start = m_next_id.fetch_add(amount);
- return IndexRange(start, amount);
- }
-
ArrayRef<AttributesBlock *> active_blocks()
{
return m_active_blocks;
diff --git a/source/blender/simulations/bparticles/particle_allocator.cpp b/source/blender/simulations/bparticles/particle_allocator.cpp
index 77cf965508a..b09d6a3c860 100644
--- a/source/blender/simulations/bparticles/particle_allocator.cpp
+++ b/source/blender/simulations/bparticles/particle_allocator.cpp
@@ -40,8 +40,7 @@ void ParticleAllocator::allocate_buffer_ranges(AttributesBlockContainer &contain
}
}
-void ParticleAllocator::initialize_new_particles(AttributesBlockContainer &container,
- AttributesRefGroup &attributes_group)
+void ParticleAllocator::initialize_new_particles(AttributesRefGroup &attributes_group)
{
for (AttributesRef attributes : attributes_group) {
for (uint i : attributes.info().attribute_indices()) {
@@ -49,7 +48,7 @@ void ParticleAllocator::initialize_new_particles(AttributesBlockContainer &conta
}
MutableArrayRef<int32_t> particle_ids = attributes.get<int32_t>("ID");
- IndexRange new_ids = container.new_ids(attributes.size());
+ IndexRange new_ids = m_state.get_new_particle_ids(attributes.size());
BLI_assert(particle_ids.size() == new_ids.size());
for (uint i = 0; i < new_ids.size(); i++) {
particle_ids[i] = new_ids[i];
@@ -68,7 +67,7 @@ AttributesRefGroup ParticleAllocator::request(StringRef particle_system_name, ui
const AttributesInfo &attributes_info = container.attributes_info();
AttributesRefGroup attributes_group(attributes_info, std::move(buffers), std::move(ranges));
- this->initialize_new_particles(container, attributes_group);
+ this->initialize_new_particles(attributes_group);
return attributes_group;
}
diff --git a/source/blender/simulations/bparticles/particle_allocator.hpp b/source/blender/simulations/bparticles/particle_allocator.hpp
index 79b41363e61..fc048944d68 100644
--- a/source/blender/simulations/bparticles/particle_allocator.hpp
+++ b/source/blender/simulations/bparticles/particle_allocator.hpp
@@ -42,8 +42,7 @@ class ParticleAllocator : BLI::NonCopyable, BLI::NonMovable {
Vector<ArrayRef<void *>> &r_buffers,
Vector<IndexRange> &r_ranges);
- void initialize_new_particles(AttributesBlockContainer &container,
- AttributesRefGroup &attributes_group);
+ void initialize_new_particles(AttributesRefGroup &attributes_group);
};
/* ParticleAllocator inline functions
diff --git a/source/blender/simulations/bparticles/particles_state.hpp b/source/blender/simulations/bparticles/particles_state.hpp
index 9e80af8540b..14c41fe44af 100644
--- a/source/blender/simulations/bparticles/particles_state.hpp
+++ b/source/blender/simulations/bparticles/particles_state.hpp
@@ -24,9 +24,12 @@ using BLI::VectorSet;
class ParticlesState {
private:
StringMap<AttributesBlockContainer *> m_container_by_id;
+ std::atomic<uint> m_next_id;
public:
- ParticlesState() = default;
+ ParticlesState() : m_next_id(0)
+ {
+ }
ParticlesState(ParticlesState &other) = delete;
~ParticlesState();
@@ -45,6 +48,15 @@ class ParticlesState {
* Get the name of a container in the context of this particle state.
*/
StringRefNull particle_container_name(AttributesBlockContainer &container);
+
+ /**
+ * Get range of unique particle ids.
+ */
+ IndexRange get_new_particle_ids(uint amount)
+ {
+ uint start = m_next_id.fetch_add(amount);
+ return IndexRange(start, amount);
+ }
};
/* ParticlesState inline functions
More information about the Bf-blender-cvs
mailing list