[Bf-blender-cvs] [75cc874922e] functions: introduce attributes info builder
Jacques Lucke
noreply at git.blender.org
Thu Jul 11 17:15:20 CEST 2019
Commit: 75cc874922ef28f83711856975223deb0db0190e
Author: Jacques Lucke
Date: Thu Jul 11 12:24:06 2019 +0200
Branches: functions
https://developer.blender.org/rB75cc874922ef28f83711856975223deb0db0190e
introduce attributes info builder
===================================================================
M source/blender/simulations/bparticles/attributes.cpp
M source/blender/simulations/bparticles/attributes.hpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/integrator.cpp
M source/blender/simulations/bparticles/simulate.cpp
M source/blender/simulations/bparticles/step_description.hpp
===================================================================
diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index 9d25be9eeaa..4bcba019d99 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -2,10 +2,27 @@
namespace BParticles {
+AttributesInfo::AttributesInfo(AttributesInfoBuilder &builder)
+ : AttributesInfo(builder.m_byte_names,
+ builder.m_float_names,
+ builder.m_float3_names,
+ builder.m_byte_defaults,
+ builder.m_float_defaults,
+ builder.m_float3_defaults)
+{
+}
+
AttributesInfo::AttributesInfo(ArrayRef<std::string> byte_names,
ArrayRef<std::string> float_names,
- ArrayRef<std::string> float3_names)
+ ArrayRef<std::string> float3_names,
+ ArrayRef<uint8_t> byte_defaults,
+ ArrayRef<float> float_defaults,
+ ArrayRef<float3> float3_defaults)
{
+ BLI_assert(byte_names.size() == byte_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(float_names);
@@ -21,9 +38,9 @@ AttributesInfo::AttributesInfo(ArrayRef<std::string> byte_names,
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.append_n_times(0, m_byte_attributes.size());
- m_float_defaults.append_n_times(0, m_float_attributes.size());
- m_float3_defaults.append_n_times({0, 0, 0}, m_float3_attributes.size());
+ m_byte_defaults = byte_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 afa24b95544..125cdd64fac 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -53,6 +53,27 @@ inline uint size_of_attribute_type(AttributeType type)
};
}
+class AttributesInfo;
+
+class AttributesInfoBuilder {
+ private:
+ SmallSetVector<std::string> m_byte_names;
+ SmallSetVector<std::string> m_float_names;
+ SmallSetVector<std::string> m_float3_names;
+ SmallVector<uint8_t> m_byte_defaults;
+ SmallVector<float> m_float_defaults;
+ SmallVector<float3> m_float3_defaults;
+
+ friend AttributesInfo;
+
+ public:
+ AttributesInfoBuilder() = default;
+
+ void use_byte(StringRef name, uint8_t default_value);
+ void use_float(StringRef name, float default_value);
+ void use_float3(StringRef name, float3 default_value);
+};
+
/**
* 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.
@@ -75,9 +96,13 @@ class AttributesInfo {
public:
AttributesInfo() = default;
+ AttributesInfo(AttributesInfoBuilder &builder);
AttributesInfo(ArrayRef<std::string> byte_names,
ArrayRef<std::string> float_names,
- ArrayRef<std::string> float3_names);
+ ArrayRef<std::string> float3_names,
+ ArrayRef<uint8_t> byte_defaults,
+ ArrayRef<float> float_defaults,
+ ArrayRef<float3> float3_defaults);
/**
* Get the number of different attributes.
@@ -372,6 +397,30 @@ class AttributeArrays {
AttributeArrays take_front(uint n) const;
};
+/* Attribute Info Builder
+ *****************************************/
+
+inline void AttributesInfoBuilder::use_byte(StringRef name, uint8_t default_value)
+{
+ if (m_byte_names.add(name.to_std_string())) {
+ m_byte_defaults.append(default_value);
+ }
+}
+
+inline void AttributesInfoBuilder::use_float(StringRef name, float default_value)
+{
+ if (m_float_names.add(name.to_std_string())) {
+ m_float_defaults.append(default_value);
+ }
+}
+
+inline void AttributesInfoBuilder::use_float3(StringRef name, float3 default_value)
+{
+ if (m_float3_names.add(name.to_std_string())) {
+ m_float3_defaults.append(default_value);
+ }
+}
+
/* Attribute Arrays Core
*****************************************/
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 6d84e786f2b..4f98f62495a 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -22,7 +22,6 @@ class EventFilterInterface;
class EventExecuteInterface;
class EmitterInterface;
class IntegratorInterface;
-class TypeAttributeInterface;
/* Main API for the particle simulation. These classes have to be subclassed to define how the
* particles should behave.
@@ -69,7 +68,7 @@ class Event {
/**
* Allows to define which attributes are required by the event.
*/
- virtual void attributes(TypeAttributeInterface &interface);
+ virtual void attributes(AttributesInfoBuilder &interface);
};
/**
@@ -136,7 +135,7 @@ class ParticleType {
/**
* Allows to define which attributes should exist for the type.
*/
- virtual void attributes(TypeAttributeInterface &interface);
+ virtual void attributes(AttributesInfoBuilder &interface);
};
/**
@@ -548,41 +547,17 @@ class IntegratorInterface {
AttributeArrays offset_targets();
};
-/**
- * Interface between the ParticleType->attributes() function and the core simulation code.
- */
-class TypeAttributeInterface {
- SmallVector<std::string> m_names;
- SmallVector<AttributeType> m_types;
-
- public:
- /**
- * Specify that a specific attribute is required to exist for the simulation.
- */
- void use(AttributeType type, StringRef attribute_name);
-
- /**
- * Access all attribute names.
- */
- ArrayRef<std::string> names();
-
- /**
- * Access all attribute types. This array has the same length as the names array.
- */
- ArrayRef<AttributeType> types();
-};
-
/* Event inline functions
********************************************/
-inline void Event::attributes(TypeAttributeInterface &UNUSED(interface))
+inline void Event::attributes(AttributesInfoBuilder &UNUSED(builder))
{
}
/* ParticleType inline functions
********************************************/
-inline void ParticleType::attributes(TypeAttributeInterface &UNUSED(interface))
+inline void ParticleType::attributes(AttributesInfoBuilder &UNUSED(builder))
{
}
@@ -843,23 +818,4 @@ inline AttributeArrays IntegratorInterface::offset_targets()
return m_offsets;
}
-/* TypeAttributeInterface
- ********************************************/
-
-inline void TypeAttributeInterface::use(AttributeType type, StringRef attribute_name)
-{
- m_types.append(type);
- m_names.append(attribute_name.to_std_string());
-}
-
-inline ArrayRef<std::string> TypeAttributeInterface::names()
-{
- return m_names;
-}
-
-inline ArrayRef<AttributeType> TypeAttributeInterface::types()
-{
- return m_types;
-}
-
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 4859e2bbfff..903ed38f4ea 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -33,9 +33,9 @@ class AgeReachedEvent : public Event {
m_compute_age_body = compute_age_fn->body<TupleCallBody>();
}
- void attributes(TypeAttributeInterface &interface) override
+ void attributes(AttributesInfoBuilder &builder) override
{
- interface.use(AttributeType::Byte, m_identifier);
+ builder.use_byte(m_identifier, 0);
}
void filter(EventFilterInterface &interface) override
@@ -148,9 +148,9 @@ class MeshCollisionEventFilter : public Event {
free_bvhtree_from_mesh(&m_bvhtree_data);
}
- void attributes(TypeAttributeInterface &interface) override
+ void attributes(AttributesInfoBuilder &builder) override
{
- interface.use(AttributeType::Float, m_identifier);
+ builder.use_float(m_identifier, 0.0f);
}
uint storage_size() override
diff --git a/source/blender/simulations/bparticles/integrator.cpp b/source/blender/simulations/bparticles/integrator.cpp
index 7ad24637b03..061d4770118 100644
--- a/source/blender/simulations/bparticles/integrator.cpp
+++ b/source/blender/simulations/bparticles/integrator.cpp
@@ -2,8 +2,12 @@
namespace BParticles {
-EulerIntegrator::EulerIntegrator() : m_offset_attributes_info({}, {}, {"Position", "Velocity"})
+EulerIntegrator::EulerIntegrator()
{
+ AttributesInfoBuilder builder;
+ builder.use_float3("Position", {0, 0, 0});
+ builder.use_float3("Velocity", {0, 0, 0});
+ m_offset_attributes_info = AttributesInfo(builder);
}
EulerIntegrator::~EulerIntegrator()
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 03c4d8b0a25..de4b75e4f29 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -582,33 +582,17 @@ BLI_NOINLINE static void ensure_required_containers_exist(ParticlesState &state,
BLI_NOINLINE static AttributesInfo build_attribute_info_for_type(ParticleType &type,
AttributesInfo &UNUSED(last_info))
{
- TypeAttributeInterface interface;
- type.attributes(interface);
+ AttributesInfoBuilder builder;
+ type.attributes(builder);
for (Event *event : type.events()) {
- event->attributes(interface);
- }
-
- SmallSetVector<std::string> byte_attributes = {"Kill State"};
- SmallSetVector<std::string> float_attributes = {"Birth Time"};
- SmallSetVector<std::string> float3_attributes = {};
-
- for (uint i = 0; i < interface.names().size(); i++) {
- std::string &name = interface.names()[i];
- switch (interface.t
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list