[Bf-blender-cvs] [c67953c53e4] functions: move particle set to separate file
Jacques Lucke
noreply at git.blender.org
Thu Jul 18 18:19:48 CEST 2019
Commit: c67953c53e496fc148f614e870037ce68c2eb38a
Author: Jacques Lucke
Date: Thu Jul 18 16:47:10 2019 +0200
Branches: functions
https://developer.blender.org/rBc67953c53e496fc148f614e870037ce68c2eb38a
move particle set to separate file
===================================================================
M source/blender/simulations/CMakeLists.txt
M source/blender/simulations/bparticles/core.cpp
M source/blender/simulations/bparticles/core.hpp
A source/blender/simulations/bparticles/particle_set.cpp
A source/blender/simulations/bparticles/particle_set.hpp
===================================================================
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index 242e6c8bb22..a7fa907c7b5 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -43,6 +43,8 @@ set(SRC
bparticles/inserters.cpp
bparticles/node_frontend.hpp
bparticles/node_frontend.cpp
+ bparticles/particle_set.hpp
+ bparticles/particle_set.cpp
)
set(LIB
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index c4881f0d2f8..8627d62ece8 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -139,190 +139,6 @@ EmitterInterface::EmitterInterface(ParticleAllocator &particle_allocator,
{
}
-/* ParticleSets
- ******************************************/
-
-ParticleSets::ParticleSets(StringRef particle_type_name,
- AttributesInfo &attributes_info,
- ArrayRef<ParticleSet> sets)
- : m_particle_type_name(particle_type_name.to_std_string()),
- m_attributes_info(attributes_info),
- m_sets(sets)
-{
- m_size = 0;
- for (auto &set : sets) {
- m_size += set.size();
- }
-}
-
-void ParticleSets::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 (ParticleSet particles : m_sets) {
- AttributeArrays attributes = particles.attributes();
- void *dst = attributes.get_ptr(index);
-
- for (uint i = 0; i < particles.size(); i++) {
- uint pindex = particles.pindices()[i];
- memcpy(POINTER_OFFSET(dst, element_size * pindex),
- POINTER_OFFSET(remaining_data, element_size * i),
- element_size);
- }
-
- remaining_data = POINTER_OFFSET(remaining_data, particles.size() * element_size);
- }
-}
-
-void ParticleSets::set_repeated_elements(uint index,
- void *data,
- uint data_element_amount,
- void *default_value)
-{
- if (data_element_amount == 0) {
- this->fill_elements(index, default_value);
- return;
- }
-
- AttributeType type = m_attributes_info.type_of(index);
- uint element_size = size_of_attribute_type(type);
- uint offset = 0;
- for (ParticleSet particles : m_sets) {
- AttributeArrays attributes = particles.attributes();
- void *dst = attributes.get_ptr(index);
- for (uint pindex : particles.pindices()) {
- memcpy(POINTER_OFFSET(dst, element_size * pindex),
- POINTER_OFFSET(data, element_size * offset),
- element_size);
- offset++;
- if (offset == data_element_amount) {
- offset = 0;
- }
- }
- }
-}
-
-void ParticleSets::fill_elements(uint index, void *value)
-{
- AttributeType type = m_attributes_info.type_of(index);
- uint element_size = size_of_attribute_type(type);
-
- for (ParticleSet particles : m_sets) {
- AttributeArrays attributes = particles.attributes();
- void *dst = attributes.get_ptr(index);
-
- for (uint pindex : particles.pindices()) {
- memcpy(POINTER_OFFSET(dst, element_size * pindex), value, element_size);
- }
- }
-}
-
-void ParticleSets::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 ParticleSets::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 ParticleSets::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 ParticleSets::set_byte(StringRef name, ArrayRef<uint8_t> data)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->set_byte(index, data);
-}
-void ParticleSets::set_float(StringRef name, ArrayRef<float> data)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->set_float(index, data);
-}
-void ParticleSets::set_float3(StringRef name, ArrayRef<float3> data)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->set_float3(index, data);
-}
-
-void ParticleSets::set_repeated_byte(uint index, ArrayRef<uint8_t> data)
-{
- BLI_assert(m_attributes_info.type_of(index) == AttributeType::Byte);
- this->set_repeated_elements(
- index, (void *)data.begin(), data.size(), m_attributes_info.default_value_ptr(index));
-}
-void ParticleSets::set_repeated_float(uint index, ArrayRef<float> data)
-{
- BLI_assert(m_attributes_info.type_of(index) == AttributeType::Float);
- this->set_repeated_elements(
- index, (void *)data.begin(), data.size(), m_attributes_info.default_value_ptr(index));
-}
-void ParticleSets::set_repeated_float3(uint index, ArrayRef<float3> data)
-{
- BLI_assert(m_attributes_info.type_of(index) == AttributeType::Float3);
- this->set_repeated_elements(
- index, (void *)data.begin(), data.size(), m_attributes_info.default_value_ptr(index));
-}
-
-void ParticleSets::set_repeated_byte(StringRef name, ArrayRef<uint8_t> data)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->set_repeated_byte(index, data);
-}
-void ParticleSets::set_repeated_float(StringRef name, ArrayRef<float> data)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->set_repeated_float(index, data);
-}
-void ParticleSets::set_repeated_float3(StringRef name, ArrayRef<float3> data)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->set_repeated_float3(index, data);
-}
-
-void ParticleSets::fill_byte(uint index, uint8_t value)
-{
- this->fill_elements(index, (void *)&value);
-}
-
-void ParticleSets::fill_byte(StringRef name, uint8_t value)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->fill_byte(index, value);
-}
-
-void ParticleSets::fill_float(uint index, float value)
-{
- this->fill_elements(index, (void *)&value);
-}
-
-void ParticleSets::fill_float(StringRef name, float value)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->fill_float(index, value);
-}
-
-void ParticleSets::fill_float3(uint index, float3 value)
-{
- this->fill_elements(index, (void *)&value);
-}
-
-void ParticleSets::fill_float3(StringRef name, float3 value)
-{
- uint index = m_attributes_info.attribute_index(name);
- this->fill_float3(index, value);
-}
-
/* EventFilterInterface
*****************************************/
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 808dce63a5e..9b06e8b6742 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -15,6 +15,7 @@
#include "attributes.hpp"
#include "particles_container.hpp"
+#include "particle_set.hpp"
#include "time_span.hpp"
namespace BParticles {
@@ -256,97 +257,6 @@ class ParticlesState {
StringRefNull particle_container_name(ParticlesContainer &container);
};
-/**
- * A set of particles all of which are in the same block.
- */
-struct ParticleSet {
- private:
- ParticlesBlock *m_block;
-
- /* Indices into the attribute arrays.
- * Invariants:
- * - Every index must exist at most once.
- * - The indices must be sorted. */
- ArrayRef<uint> m_pindices;
-
- public:
- ParticleSet(ParticlesBlock &block, ArrayRef<uint> pindices);
-
- /**
- * Return the block that contains the particles of this set.
- */
- ParticlesBlock &block();
-
- /**
- * Access the attributes of particles in the block on this set.
- */
- AttributeArrays attributes();
-
- /**
- * Access particle indices in the block that are part of the set.
- * Every value in this array is an index into the attribute arrays.
- */
- ArrayRef<uint> pindices();
-
- /**
- * Number of particles in this set.
- */
- uint size();
-
- /**
- * Returns true when pindices()[i] == i for all i, otherwise false.
- */
- bool indices_are_trivial();
-};
-
-class ParticleSets {
- private:
- std::string m_particle_type_name;
- AttributesInfo &m_attributes_info;
- SmallVector<ParticleSet> m_sets;
- uint m_size;
-
- public:
- ParticleSets(StringRef particle_type_name,
- AttributesInfo &attributes_info,
- ArrayRef<ParticleSet> sets);
-
- ArrayRef<ParticleSet> sets();
-
- 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);
-
- void set_repeated_byte(uint index, ArrayRef<uint8_t> data);
- void set_repeated_byte(StringRef name, ArrayRef<uint8_t> data);
- void set_repeated_float(uint index, ArrayRef<float> data);
- void set_repeated_float(StringRef name, ArrayRef<float> data);
- void set_repeated_float3(uint index, ArrayRef<float3> data);
- void set_repeated_float3(StringRef name, ArrayRef<float3> data);
-
- void fill_byte(uint index, uint8_t value);
- void fill_byte(StringRef name, uint8_t value);
- void fill_float(uint index, float value);
- void fill_float(StringRef name, float value);
- void fill_float3(uint index, float3 value);
- void fill_float3(StringRef name, float3 value);
-
- StringRefNull particle_type_name();
-
- AttributesInfo &attributes_info();
-
- private:
- void set_elements(uint index, void *data);
- void set_repeated_elements(uint index,
- void *data,
- uint data_element_amount,
- void *default_value);
- void fill_elements(uint index, void *value);
-};
-
/**
* This class allows allocating new blocks from different particle containers.
* A single instance is not thread safe, but multiple alloc
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list