[Bf-blender-cvs] [8349161f141] functions: refactor emitter interface internals
Jacques Lucke
noreply at git.blender.org
Thu Jun 27 15:49:52 CEST 2019
Commit: 8349161f1417594784d4f74b98a513fbeee1ba41
Author: Jacques Lucke
Date: Thu Jun 27 12:36:47 2019 +0200
Branches: functions
https://developer.blender.org/rB8349161f1417594784d4f74b98a513fbeee1ba41
refactor emitter interface internals
The problem previously was that all the information about which
blocks contain the attributes was not accessible by the emitter.
===================================================================
M source/blender/modifiers/intern/MOD_nodeparticles.c
M source/blender/simulations/bparticles/attributes.cpp
M source/blender/simulations/bparticles/attributes.hpp
M source/blender/simulations/bparticles/core.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/particles_container.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c
index 2e98f865a90..d616dc5b57a 100644
--- a/source/blender/modifiers/intern/MOD_nodeparticles.c
+++ b/source/blender/modifiers/intern/MOD_nodeparticles.c
@@ -179,7 +179,7 @@ static Mesh *applyModifier(ModifierData *md,
runtime->last_simulated_frame = current_frame;
}
- return BParticles_test_mesh_from_state(runtime->state);
+ return point_mesh_from_particle_state(runtime->state);
}
static void initData(ModifierData *md)
diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index 7d9ff3e0c24..d5b0cfd1358 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -52,55 +52,4 @@ void AttributeArraysCore::free_buffers()
}
}
-void JoinedAttributeArrays::set_elements(uint index, void *data)
-{
- AttributeType type = m_info.type_of(index);
- uint element_size = size_of_attribute_type(type);
-
- void *remaining_data = data;
-
- for (auto arrays : m_arrays) {
- void *target = arrays.get_ptr(index);
- uint bytes_to_copy = element_size * arrays.size();
- memcpy(target, remaining_data, bytes_to_copy);
-
- remaining_data = POINTER_OFFSET(remaining_data, bytes_to_copy);
- }
-}
-
-void JoinedAttributeArrays::set_byte(uint index, ArrayRef<uint8_t> data)
-{
- BLI_assert(data.size() == m_size);
- BLI_assert(m_info.type_of(index) == AttributeType::Byte);
- this->set_elements(index, (void *)data.begin());
-}
-void JoinedAttributeArrays::set_float(uint index, ArrayRef<float> data)
-{
- BLI_assert(data.size() == m_size);
- BLI_assert(m_info.type_of(index) == AttributeType::Float);
- this->set_elements(index, (void *)data.begin());
-}
-void JoinedAttributeArrays::set_float3(uint index, ArrayRef<float3> data)
-{
- BLI_assert(data.size() == m_size);
- BLI_assert(m_info.type_of(index) == AttributeType::Float3);
- this->set_elements(index, (void *)data.begin());
-}
-
-void JoinedAttributeArrays::set_byte(StringRef name, ArrayRef<uint8_t> data)
-{
- uint index = m_info.attribute_index(name);
- this->set_byte(index, data);
-}
-void JoinedAttributeArrays::set_float(StringRef name, ArrayRef<float> data)
-{
- uint index = m_info.attribute_index(name);
- this->set_float(index, data);
-}
-void JoinedAttributeArrays::set_float3(StringRef name, ArrayRef<float3> data)
-{
- uint index = m_info.attribute_index(name);
- this->set_float3(index, data);
-}
-
}; // namespace BParticles
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index 4876232807b..a953a6ab31f 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -181,31 +181,6 @@ class AttributeArrays {
AttributeArrays take_front(uint n) const;
};
-class JoinedAttributeArrays {
- private:
- AttributesInfo &m_info;
- SmallVector<AttributeArrays> m_arrays;
- uint m_size;
-
- public:
- JoinedAttributeArrays(AttributesInfo &info, ArrayRef<AttributeArrays> arrays_list);
-
- AttributesInfo &info();
-
- uint size() const;
- ArrayRef<AttributeArrays> arrays_list();
-
- void set_byte(uint index, ArrayRef<uint8_t> data);
- void set_byte(StringRef name, ArrayRef<uint8_t> data);
- void set_float(uint index, ArrayRef<float> data);
- void set_float(StringRef name, ArrayRef<float> data);
- void set_float3(uint index, ArrayRef<float3> data);
- void set_float3(StringRef name, ArrayRef<float3> data);
-
- private:
- void set_elements(uint index, void *data);
-};
-
/* Attribute Arrays Core
*****************************************/
@@ -315,33 +290,4 @@ inline AttributeArrays AttributeArrays::take_front(uint n) const
return AttributeArrays(m_core, m_start, n);
}
-/* Joined Attribute Arrays
- ******************************************/
-
-inline JoinedAttributeArrays::JoinedAttributeArrays(AttributesInfo &info,
- ArrayRef<AttributeArrays> arrays_list)
- : m_info(info), m_arrays(arrays_list.to_small_vector())
-{
- m_size = 0;
- for (AttributeArrays arrays : arrays_list) {
- BLI_assert(arrays.info() == m_info);
- m_size += arrays.size();
- }
-}
-
-inline AttributesInfo &JoinedAttributeArrays::info()
-{
- return m_info;
-}
-
-inline uint JoinedAttributeArrays::size() const
-{
- return m_size;
-}
-
-inline ArrayRef<AttributeArrays> JoinedAttributeArrays::arrays_list()
-{
- return m_arrays;
-}
-
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index a9faa67c74c..6bee750a1ae 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -33,4 +33,62 @@ ParticlesState::~ParticlesState()
}
}
+/* EmitTarget
+ ******************************************/
+
+void EmitTarget::set_elements(uint index, void *data)
+{
+ AttributeType type = m_attributes_info.type_of(index);
+ uint element_size = size_of_attribute_type(type);
+
+ void *remaining_data = data;
+
+ for (uint i = 0; i < m_ranges.size(); i++) {
+ ParticlesBlock &block = *m_blocks[i];
+ Range<uint> range = m_ranges[i];
+
+ AttributeArrays attributes = block.slice(range);
+ void *dst = attributes.get_ptr(index);
+ uint bytes_to_copy = element_size * attributes.size();
+ memcpy(dst, remaining_data, bytes_to_copy);
+
+ remaining_data = POINTER_OFFSET(remaining_data, bytes_to_copy);
+ }
+}
+
+void EmitTarget::set_byte(uint index, ArrayRef<uint8_t> data)
+{
+ BLI_assert(data.size() == m_size);
+ BLI_assert(m_attributes_info.type_of(index) == AttributeType::Byte);
+ this->set_elements(index, (void *)data.begin());
+}
+void EmitTarget::set_float(uint index, ArrayRef<float> data)
+{
+ BLI_assert(data.size() == m_size);
+ BLI_assert(m_attributes_info.type_of(index) == AttributeType::Float);
+ this->set_elements(index, (void *)data.begin());
+}
+void EmitTarget::set_float3(uint index, ArrayRef<float3> data)
+{
+ BLI_assert(data.size() == m_size);
+ BLI_assert(m_attributes_info.type_of(index) == AttributeType::Float3);
+ this->set_elements(index, (void *)data.begin());
+}
+
+void EmitTarget::set_byte(StringRef name, ArrayRef<uint8_t> data)
+{
+ uint index = m_attributes_info.attribute_index(name);
+ this->set_byte(index, data);
+}
+void EmitTarget::set_float(StringRef name, ArrayRef<float> data)
+{
+ uint index = m_attributes_info.attribute_index(name);
+ this->set_float(index, data);
+}
+void EmitTarget::set_float3(StringRef name, ArrayRef<float3> data)
+{
+ uint index = m_attributes_info.attribute_index(name);
+ this->set_float3(index, data);
+}
+
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 3317a78ea0c..9e2980a580f 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -25,6 +25,128 @@ using BLI::SmallVector;
using BLI::StringRef;
using std::unique_ptr;
+class ParticlesState {
+ private:
+ SmallMap<uint, ParticlesContainer *> m_particle_containers;
+
+ public:
+ float m_current_time = 0.0f;
+
+ ParticlesState() = default;
+ ParticlesState(ParticlesState &other) = delete;
+ ~ParticlesState();
+
+ SmallMap<uint, ParticlesContainer *> &particle_containers()
+ {
+ return m_particle_containers;
+ }
+
+ ParticlesContainer &particle_container(uint type_id)
+ {
+ return *m_particle_containers.lookup(type_id);
+ }
+};
+
+class EmitTarget {
+ private:
+ uint m_particle_type_id;
+ AttributesInfo &m_attributes_info;
+ SmallVector<ParticlesBlock *> m_blocks;
+ SmallVector<Range<uint>> m_ranges;
+ uint m_size = 0;
+
+ public:
+ EmitTarget(uint particle_type_id,
+ AttributesInfo &attributes_info,
+ ArrayRef<ParticlesBlock *> blocks,
+ ArrayRef<Range<uint>> ranges)
+ : m_particle_type_id(particle_type_id),
+ m_attributes_info(attributes_info),
+ m_blocks(blocks.to_small_vector()),
+ m_ranges(ranges.to_small_vector())
+ {
+ BLI_assert(blocks.size() == ranges.size());
+ for (auto range : ranges) {
+ m_size += range.size();
+ }
+ }
+
+ void set_byte(uint index, ArrayRef<uint8_t> data);
+ void set_byte(StringRef name, ArrayRef<uint8_t> data);
+ void set_float(uint index, ArrayRef<float> data);
+ void set_float(StringRef name, ArrayRef<float> data);
+ void set_float3(uint index, ArrayRef<float3> data);
+ void set_float3(StringRef name, ArrayRef<float3> data);
+
+ ArrayRef<ParticlesBlock *> blocks()
+ {
+ return m_blocks;
+ }
+
+ ArrayRef<Range<uint>> ranges()
+ {
+ return m_ranges;
+ }
+
+ uint part_amount()
+ {
+ return m_ranges.size();
+ }
+
+ AttributeArrays attributes(uint part)
+ {
+ return m_blocks[part]->slice(m_ranges[part]);
+ }
+
+ uint particle_type_id()
+ {
+ return m_particle_type_id;
+ }
+
+ private:
+ void set_elements(uint index, void *data);
+};
+
+class EmitterInterface {
+ private:
+ ParticlesState &m_state;
+ SmallVector<EmitTarget> m_targets;
+
+ public:
+ EmitterInterface(ParticlesState &state) : m_state(state)
+ {
+ }
+
+ ArrayRef<EmitTarget> targets()
+ {
+ return m_targets;
+ }
+
+ EmitTarget &request(uint particle_type_id, uint size)
+ {
+ ParticlesContainer &container = m_state.particle_container(particle_type_id);
+
+ SmallVector<ParticlesBlock *> blocks;
+ SmallVector<Range<uint>> ranges;
+
+ uint remaining_size = size;
+ while (remaining_size > 0) {
+ ParticlesBlock &block = *container.new_block();
+
+ uint size_to_use = std::min(block.size(), remaining_size);
+ block.active_amount() += size_to_use;
+
+ blocks.append(&block);
+ ranges.append(Range<uint>(0, size_to_use));
+
+ remaining_size -= size_to_use;
+ }
+
+ m_targets.append(EmitTarget(particle_type_id, container.attributes_info(), blocks, ranges));
+ return m_targets.last();
+ }
+};
+
struct ParticleSet {
private:
ParticlesBlock &m_block;
@@ -171,77 +293,6
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list