[Bf-blender-cvs] [a19a5f86758] functions: initial code layout for updating the required attributes
Jacques Lucke
noreply at git.blender.org
Fri Jun 21 16:56:42 CEST 2019
Commit: a19a5f867585041dc3e3736a91e85da58e06ea71
Author: Jacques Lucke
Date: Fri Jun 21 16:56:19 2019 +0200
Branches: functions
https://developer.blender.org/rBa19a5f867585041dc3e3736a91e85da58e06ea71
initial code layout for updating the required attributes
===================================================================
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/particles_container.cpp
M source/blender/simulations/bparticles/particles_container.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 89588569a76..4fdf4aa677b 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -42,11 +42,6 @@ WRAPPERS(ParticlesState *, BParticlesState);
BParticlesState BParticles_new_empty_state()
{
ParticlesState *state = new ParticlesState();
-
- AttributesInfo info{{"Kill State"}, {"Birth Time"}, {"Position", "Velocity"}};
- auto &containers = state->particle_containers();
- containers.add_new(0, new ParticlesContainer(info, 1000));
-
return wrap(state);
}
diff --git a/source/blender/simulations/bparticles/particles_container.cpp b/source/blender/simulations/bparticles/particles_container.cpp
index c5b8a3c4c13..ca35fd2598b 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -41,6 +41,12 @@ void ParticlesContainer::release_block(ParticlesBlock *block)
delete block;
}
+void ParticlesContainer::update_attributes(AttributesInfo new_info)
+{
+ m_attributes = new_info;
+ /* TODO: actually update attributes */
+}
+
void ParticlesBlock::MoveUntilFull(ParticlesBlock &from, ParticlesBlock &to)
{
BLI_assert(&from.container() == &to.container());
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index 9e49d2dfafa..5a06822eab2 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -37,6 +37,7 @@ class ParticlesContainer {
uint count_active() const;
AttributesInfo &attributes();
+ void update_attributes(AttributesInfo new_info);
const SmallSet<ParticlesBlock *> &active_blocks();
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index f82542ce1e4..eb229a82eef 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -429,6 +429,40 @@ BLI_NOINLINE static void compress_all_blocks(ParticlesContainer &particles)
}
}
+/* Fix state based on description.
+ *****************************************************/
+
+BLI_NOINLINE static void ensure_required_containers_exist(
+ SmallMap<uint, ParticlesContainer *> &containers, StepDescription &description)
+{
+ for (uint type_id : description.particle_type_ids()) {
+ if (!containers.contains(type_id)) {
+ ParticlesContainer *container = new ParticlesContainer({}, 1000);
+ containers.add_new(type_id, container);
+ }
+ }
+}
+
+BLI_NOINLINE static AttributesInfo build_attribute_info_for_type(ParticleType &UNUSED(type),
+ AttributesInfo &UNUSED(last_info))
+{
+ AttributesInfo new_info{{"Kill State"}, {"Birth Time"}, {"Position", "Velocity"}};
+ return new_info;
+}
+
+BLI_NOINLINE static void ensure_required_attributes_exist(
+ SmallMap<uint, ParticlesContainer *> &containers, StepDescription &description)
+{
+ for (uint type_id : description.particle_type_ids()) {
+ ParticleType &type = description.particle_type(type_id);
+ ParticlesContainer &container = *containers.lookup(type_id);
+
+ AttributesInfo new_attributes_info = build_attribute_info_for_type(type,
+ container.attributes());
+ container.update_attributes(new_attributes_info);
+ }
+}
+
/* Main Entry Point
**************************************************/
@@ -438,12 +472,8 @@ void simulate_step(ParticlesState &state, StepDescription &description)
state.m_current_time = time_span.end();
auto &containers = state.particle_containers();
-
- for (uint type_id : description.particle_type_ids()) {
- if (!containers.contains(type_id)) {
- /* TODO: create container */
- }
- }
+ ensure_required_containers_exist(containers, description);
+ ensure_required_attributes_exist(containers, description);
for (uint type_id : description.particle_type_ids()) {
ParticleType &type = description.particle_type(type_id);
More information about the Bf-blender-cvs
mailing list