[Bf-blender-cvs] [33c29f35b82] functions: simplify the way attribute information is stored
Jacques Lucke
noreply at git.blender.org
Tue Jul 30 13:27:58 CEST 2019
Commit: 33c29f35b827477e4375110d0acbb7bd746d168a
Author: Jacques Lucke
Date: Tue Jul 30 13:27:37 2019 +0200
Branches: functions
https://developer.blender.org/rB33c29f35b827477e4375110d0acbb7bd746d168a
simplify the way attribute information is stored
===================================================================
M source/blender/simulations/bparticles/attributes.cpp
M source/blender/simulations/bparticles/attributes.hpp
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/integrator.cpp
M source/blender/simulations/bparticles/node_frontend.cpp
M source/blender/simulations/bparticles/particles_container.cpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index dfa8e53f467..c55c197d5ea 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -4,101 +4,27 @@ namespace BParticles {
void AttributesDeclaration::join(AttributesDeclaration &other)
{
- for (uint i = 0; i < other.m_byte_names.size(); i++) {
- if (m_byte_names.add(other.m_byte_names[i])) {
- m_byte_defaults.append(other.m_byte_defaults[i]);
- }
- }
- for (uint i = 0; i < other.m_integer_names.size(); i++) {
- if (m_integer_names.add(other.m_integer_names[i])) {
- m_integer_defaults.append(other.m_integer_defaults[i]);
- }
- }
- for (uint i = 0; i < other.m_float_names.size(); i++) {
- if (m_float_names.add(other.m_float_names[i])) {
- m_float_defaults.append(other.m_float_defaults[i]);
- }
- }
- for (uint i = 0; i < other.m_float3_names.size(); i++) {
- if (m_float3_names.add(other.m_float3_names[i])) {
- m_float3_defaults.append(other.m_float3_defaults[i]);
+ for (uint i = 0; i < other.size(); i++) {
+ if (m_names.add(other.m_names[i])) {
+ m_types.append(other.m_types[i]);
+ m_defaults.append(other.m_defaults[i]);
}
}
}
void AttributesDeclaration::join(AttributesInfo &other)
{
- for (uint i : other.byte_attributes()) {
- if (m_byte_names.add(other.name_of(i).to_std_string())) {
- m_byte_defaults.append(*(uint8_t *)other.default_value_ptr(i));
- }
- }
- for (uint i : other.integer_attributes()) {
- if (m_integer_names.add(other.name_of(i).to_std_string())) {
- m_integer_defaults.append(*(uint8_t *)other.default_value_ptr(i));
- }
- }
- for (uint i : other.float_attributes()) {
- if (m_float_names.add(other.name_of(i).to_std_string())) {
- m_float_defaults.append(*(float *)other.default_value_ptr(i));
- }
- }
- for (uint i : other.float3_attributes()) {
- if (m_float3_names.add(other.name_of(i).to_std_string())) {
- m_float3_defaults.append(*(float3 *)other.default_value_ptr(i));
+ for (uint i = 0; i < other.size(); i++) {
+ if (m_names.add(other.m_names[i])) {
+ m_types.append(other.m_types[i]);
+ m_defaults.append(other.m_defaults[i]);
}
}
}
AttributesInfo::AttributesInfo(AttributesDeclaration &builder)
- : AttributesInfo(builder.m_byte_names,
- builder.m_integer_names,
- builder.m_float_names,
- builder.m_float3_names,
- builder.m_byte_defaults,
- builder.m_integer_defaults,
- builder.m_float_defaults,
- builder.m_float3_defaults)
-{
-}
-
-AttributesInfo::AttributesInfo(ArrayRef<std::string> byte_names,
- ArrayRef<std::string> integer_names,
- ArrayRef<std::string> float_names,
- ArrayRef<std::string> float3_names,
- ArrayRef<uint8_t> byte_defaults,
- ArrayRef<int32_t> integer_defaults,
- ArrayRef<float> float_defaults,
- ArrayRef<float3> float3_defaults)
+ : m_names(builder.m_names), m_types(builder.m_types), m_defaults(builder.m_defaults)
{
- BLI_assert(byte_names.size() == byte_defaults.size());
- BLI_assert(integer_names.size() == integer_defaults.size());
- BLI_assert(float_names.size() == float_defaults.size());
- BLI_assert(float3_names.size() == float3_defaults.size());
-
- m_indices = {};
- m_indices.add_multiple_new(byte_names);
- m_indices.add_multiple_new(integer_names);
- m_indices.add_multiple_new(float_names);
- m_indices.add_multiple_new(float3_names);
- BLI_assert(m_indices.size() ==
- byte_names.size() + integer_names.size() + float_names.size() + float3_names.size());
-
- m_byte_attributes = Range<uint>(0, byte_names.size());
- m_integer_attributes = m_byte_attributes.after(integer_names.size());
- m_float_attributes = m_integer_attributes.after(float_names.size());
- m_float3_attributes = m_float_attributes.after(float3_names.size());
-
- m_types = {};
- m_types.append_n_times(AttributeType::Byte, m_byte_attributes.size());
- m_types.append_n_times(AttributeType::Integer, m_integer_attributes.size());
- m_types.append_n_times(AttributeType::Float, m_float_attributes.size());
- m_types.append_n_times(AttributeType::Float3, m_float3_attributes.size());
-
- m_byte_defaults = byte_defaults;
- m_integer_defaults = integer_defaults;
- m_float_defaults = float_defaults;
- m_float3_defaults = float3_defaults;
}
AttributeArraysCore::AttributeArraysCore(AttributesInfo &info, ArrayRef<void *> arrays, uint size)
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index 7f8c51b1513..9ea8b6fcb60 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -71,28 +71,47 @@ inline uint size_of_attribute_type(AttributeType type)
};
}
+#define MAX_ATTRIBUTE_SIZE sizeof(float3)
+
+struct AnyAttributeValue {
+ char storage[MAX_ATTRIBUTE_SIZE];
+
+ template<typename T> static AnyAttributeValue FromValue(T value)
+ {
+ BLI_STATIC_ASSERT(attribute_type_by_type<T>::value >= 0, "");
+ BLI_STATIC_ASSERT(sizeof(T) <= MAX_ATTRIBUTE_SIZE, "");
+ AnyAttributeValue attribute;
+ memcpy(attribute.storage, &value, sizeof(T));
+ return attribute;
+ }
+};
+
class AttributesInfo;
class AttributesDeclaration {
private:
- SetVector<std::string> m_byte_names;
- SetVector<std::string> m_integer_names;
- SetVector<std::string> m_float_names;
- SetVector<std::string> m_float3_names;
- Vector<uint8_t> m_byte_defaults;
- Vector<int32_t> m_integer_defaults;
- Vector<float> m_float_defaults;
- Vector<float3> m_float3_defaults;
+ SetVector<std::string> m_names;
+ Vector<AttributeType> m_types;
+ Vector<AnyAttributeValue> m_defaults;
friend AttributesInfo;
public:
AttributesDeclaration() = default;
- void add_byte(StringRef name, uint8_t default_value);
- void add_integer(StringRef name, int32_t default_value);
- void add_float(StringRef name, float default_value);
- void add_float3(StringRef name, float3 default_value);
+ template<typename T> void add(StringRef name, T default_value)
+ {
+ if (m_names.add(name.to_std_string())) {
+ AttributeType type = attribute_type_by_type<T>::value;
+ m_types.append(type);
+ m_defaults.append(AnyAttributeValue::FromValue(default_value));
+ }
+ }
+
+ uint size() const
+ {
+ return m_names.size();
+ }
void join(AttributesDeclaration &other);
void join(AttributesInfo &other);
@@ -102,42 +121,26 @@ class AttributesDeclaration {
* Contains information about a set of attributes. Every attribute is identified by a unique name
* and a unique index. So two attributes of different types have to have different names.
*
- * The attributes are sorted such that attributes with the same type have consecutive indices.
- *
* Furthermore, every attribute has a default value.
*/
class AttributesInfo {
private:
- Range<uint> m_byte_attributes;
- Range<uint> m_integer_attributes;
- Range<uint> m_float_attributes;
- Range<uint> m_float3_attributes;
+ SetVector<std::string> m_names;
Vector<AttributeType> m_types;
- SetVector<std::string> m_indices;
+ Vector<AnyAttributeValue> m_defaults;
- Vector<uint8_t> m_byte_defaults;
- Vector<int32_t> m_integer_defaults;
- Vector<float> m_float_defaults;
- Vector<float3> m_float3_defaults;
+ friend AttributesDeclaration;
public:
AttributesInfo() = default;
AttributesInfo(AttributesDeclaration &builder);
- AttributesInfo(ArrayRef<std::string> byte_names,
- ArrayRef<std::string> integer_names,
- ArrayRef<std::string> float_names,
- ArrayRef<std::string> float3_names,
- ArrayRef<uint8_t> byte_defaults,
- ArrayRef<int32_t> integer_defaults,
- ArrayRef<float> float_defaults,
- ArrayRef<float3> float3_defaults);
/**
* Get the number of different attributes.
*/
- uint amount() const
+ uint size() const
{
- return m_indices.size();
+ return m_names.size();
}
/**
@@ -146,7 +149,7 @@ class AttributesInfo {
*/
StringRefNull name_of(uint index) const
{
- return m_indices[index];
+ return m_names[index];
}
/**
@@ -182,7 +185,7 @@ class AttributesInfo {
*/
int attribute_index_try(StringRef name) const
{
- return m_indices.index(name.to_std_string());
+ return m_names.index(name.to_std_string());
}
/**
@@ -220,39 +223,7 @@ class AttributesInfo {
*/
Range<uint> attribute_indices() const
{
- return Range<uint>(0, m_indices.size());
- }
-
- /**
- * Get a range with all byte attribute indices.
- */
- Range<uint> byte_attributes() const
- {
- return m_byte_attributes;
- }
-
- /**
- * Get a range with all integer attribute indices.
- */
- Range<uint> integer_attributes() const
- {
- return m_integer_attributes;
- }
-
- /**
- * Get a range with all float attribute indices.
- */
- Range<uint> float_attributes() const
- {
- return m_float_attributes;
- }
-
- /**
- * Get a range with all float3 attribute indices.
- */
- Range<uint> float3_attributes() const
- {
- return m_float3_attributes;
+ return Range<uint>(0, this->size());
}
/**
@@ -260,20 +231,8 @@ class AttributesInfo {
*/
void *default_value_ptr(uint index) const
{
- BLI_assert(index < m_indices.size());
- AttributeType type = this->type_of(index);
- switch (type) {
- case AttributeType::Byte:
- return (void *)&m_byte_defaults[index - m_byte_attributes.first()];
- case AttributeType::Integer:
- return (void *)&m_integer_defaults[index - m_integer_attributes.first()];
- case AttributeType::Float:
- return (void *)&m_float_defaults[index - m_float_attributes.first()];
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list