[Bf-blender-cvs] [c2fa4a33fa8] functions: test NamedBuffersRef abstraction to separate components
Jacques Lucke
noreply at git.blender.org
Fri Jun 7 18:08:03 CEST 2019
Commit: c2fa4a33fa88b43f4df989d04176b8b1e526abe5
Author: Jacques Lucke
Date: Fri Jun 7 18:07:54 2019 +0200
Branches: functions
https://developer.blender.org/rBc2fa4a33fa88b43f4df989d04176b8b1e526abe5
test NamedBuffersRef abstraction to separate components
More specifically this separates implementation details of
Forces and ParticleBlocks.
===================================================================
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/particles_container.hpp
M source/blender/simulations/bparticles/playground_solver.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 039ca9e3c44..2ec8841dfa1 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -13,6 +13,7 @@
}
using BParticles::Description;
+using BParticles::NamedBuffersRef;
using BParticles::Solver;
using BParticles::StateBase;
using BParticles::WrappedState;
@@ -33,7 +34,7 @@ class TestForce : public BParticles::Force {
{
}
- void add_force(ArrayRef<Vec3> dst) override
+ void add_force(NamedBuffersRef &UNUSED(buffers), ArrayRef<Vec3> dst) override
{
for (uint i = 0; i < dst.size(); i++) {
dst[i].x += m_value_1;
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index d1c66252257..3bab636f6e4 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -5,6 +5,7 @@
#include "BLI_array_ref.hpp"
#include "BLI_math.hpp"
#include "BLI_utildefines.h"
+#include "BLI_string_ref.hpp"
namespace BParticles {
class Description;
@@ -14,12 +15,19 @@ class StateBase;
using BLI::ArrayRef;
using BLI::SmallVector;
+using BLI::StringRef;
using BLI::Vec3;
using std::unique_ptr;
+class NamedBuffersRef {
+ public:
+ virtual ArrayRef<float> float_buffer(StringRef name) = 0;
+ virtual ArrayRef<Vec3> vec3_buffer(StringRef name) = 0;
+};
+
class Force {
public:
- virtual void add_force(ArrayRef<Vec3> dst) = 0;
+ virtual void add_force(NamedBuffersRef &buffers, ArrayRef<Vec3> dst) = 0;
};
class Description {
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index 6e387149403..f68d727c8c8 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -6,6 +6,8 @@
#include "BLI_math.hpp"
#include "BLI_string_ref.hpp"
+#include "core.hpp"
+
namespace BParticles {
using BLI::ArrayRef;
@@ -17,6 +19,7 @@ using BLI::Vec3;
class ParticlesContainer;
class ParticlesBlock;
+class BlockBuffersRef;
class ParticlesContainer {
private:
@@ -74,6 +77,26 @@ class ParticlesBlock {
static void Compress(ArrayRef<ParticlesBlock *> blocks);
};
+class BlockBuffersRef : public NamedBuffersRef {
+ private:
+ ParticlesBlock *m_block;
+
+ public:
+ BlockBuffersRef(ParticlesBlock *block) : m_block(block)
+ {
+ }
+
+ ArrayRef<float> float_buffer(StringRef name) override
+ {
+ return ArrayRef<float>(m_block->float_buffer(name), m_block->active_amount());
+ }
+
+ ArrayRef<Vec3> vec3_buffer(StringRef name) override
+ {
+ return ArrayRef<Vec3>(m_block->vec3_buffer(name), m_block->active_amount());
+ }
+};
+
/* Particles Container
***********************************************/
diff --git a/source/blender/simulations/bparticles/playground_solver.cpp b/source/blender/simulations/bparticles/playground_solver.cpp
index c21bcbcad37..4611dc5a340 100644
--- a/source/blender/simulations/bparticles/playground_solver.cpp
+++ b/source/blender/simulations/bparticles/playground_solver.cpp
@@ -50,8 +50,10 @@ class SimpleSolver : public Solver {
SmallVector<Vec3> combined_force(active_amount);
combined_force.fill({0, 0, 0});
+ BlockBuffersRef buffers{block};
+
for (Force *force : m_description.forces()) {
- force->add_force(combined_force);
+ force->add_force(buffers, combined_force);
}
float time_step = 0.01f;
More information about the Bf-blender-cvs
mailing list