[Bf-blender-cvs] [888aec82345] functions: move particle function building to separate file
Jacques Lucke
noreply at git.blender.org
Mon Jul 29 17:57:16 CEST 2019
Commit: 888aec823454a548a016f3fb847526aa4fe50110
Author: Jacques Lucke
Date: Mon Jul 29 12:07:08 2019 +0200
Branches: functions
https://developer.blender.org/rB888aec823454a548a016f3fb847526aa4fe50110
move particle function building to separate file
===================================================================
M source/blender/simulations/CMakeLists.txt
M source/blender/simulations/bparticles/inserters.cpp
M source/blender/simulations/bparticles/inserters.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
A source/blender/simulations/bparticles/particle_function_builder.cpp
A source/blender/simulations/bparticles/particle_function_builder.hpp
===================================================================
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index 49d081d890e..1882a1c87d6 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -56,6 +56,8 @@ set(SRC
bparticles/particle_function.cpp
bparticles/force_interface.hpp
bparticles/force_interface.cpp
+ bparticles/particle_function_builder.hpp
+ bparticles/particle_function_builder.cpp
)
set(LIB
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index b166670a22c..dc9d74b1773 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -15,6 +15,7 @@
#include "forces.hpp"
#include "integrator.hpp"
#include "offset_handlers.hpp"
+#include "particle_function_builder.hpp"
namespace BParticles {
@@ -26,44 +27,6 @@ using FN::SharedDataFlowGraph;
using FN::SharedFunction;
using FN::SharedType;
-static Vector<DFGraphSocket> find_input_data_sockets(VirtualNode *vnode,
- VTreeDataGraph &data_graph)
-{
- Vector<DFGraphSocket> inputs;
- for (VirtualSocket *vsocket : vnode->inputs()) {
- DFGraphSocket *socket = data_graph.lookup_socket_ptr(vsocket);
- if (socket != nullptr) {
- inputs.append(*socket);
- }
- }
- return inputs;
-}
-
-struct SocketDependencies {
- SetVector<DFGraphSocket> sockets;
- SetVector<VirtualSocket *> vsockets;
-};
-
-static SocketDependencies find_particle_dependencies(VTreeDataGraph &data_graph,
- ArrayRef<DFGraphSocket> sockets,
- ArrayRef<bool> r_depends_on_particle)
-{
- SocketDependencies combined_dependencies;
-
- for (uint i = 0; i < sockets.size(); i++) {
- DFGraphSocket socket = sockets[i];
- auto dependencies = data_graph.find_placeholder_dependencies(socket);
- bool has_dependency = dependencies.size() > 0;
- r_depends_on_particle[i] = has_dependency;
-
- combined_dependencies.sockets.add_multiple(dependencies.sockets);
- combined_dependencies.vsockets.add_multiple(dependencies.vsockets);
- BLI_assert(combined_dependencies.sockets.size() == combined_dependencies.vsockets.size());
- }
-
- return combined_dependencies;
-}
-
static ValueOrError<SharedFunction> create_function__emitter_inputs(VirtualNode *emitter_vnode,
VTreeDataGraph &data_graph)
{
@@ -80,81 +43,6 @@ static ValueOrError<SharedFunction> create_function__emitter_inputs(VirtualNode
return fn;
}
-static SharedFunction create_function__with_deps(SharedDataFlowGraph &graph,
- StringRef function_name,
- ArrayRef<DFGraphSocket> sockets_to_compute,
- SocketDependencies &dependencies)
-{
- FunctionBuilder fn_builder;
- fn_builder.add_outputs(graph, sockets_to_compute);
-
- for (uint i = 0; i < dependencies.sockets.size(); i++) {
- VirtualSocket *vsocket = dependencies.vsockets[i];
- DFGraphSocket socket = dependencies.sockets[i];
- VirtualNode *vnode = vsocket->vnode();
-
- SharedType &type = graph->type_of_output(socket);
- StringRef name_prefix;
- if (STREQ(vnode->idname(), "bp_ParticleInfoNode")) {
- name_prefix = "Attribute: ";
- }
- else if (STREQ(vnode->idname(), "bp_CollisionInfoNode")) {
- name_prefix = "Action Context: ";
- }
- else {
- BLI_assert(false);
- }
- BLI_STRINGREF_STACK_COMBINE(name, name_prefix, vsocket->name());
- fn_builder.add_input(name, type);
- }
-
- SharedFunction fn = fn_builder.build(function_name);
- FunctionGraph fgraph(graph, dependencies.sockets, sockets_to_compute);
- FN::fgraph_add_TupleCallBody(fn, fgraph);
-
- return fn;
-}
-
-static SharedFunction create_function__without_deps(SharedDataFlowGraph &graph,
- StringRef function_name,
- ArrayRef<DFGraphSocket> sockets_to_compute)
-{
- FunctionBuilder fn_builder;
- fn_builder.add_outputs(graph, sockets_to_compute);
- SharedFunction fn = fn_builder.build(function_name);
- FunctionGraph fgraph(graph, {}, sockets_to_compute);
- FN::fgraph_add_TupleCallBody(fn, fgraph);
- return fn;
-}
-
-ValueOrError<ParticleFunction> create_particle_function(VirtualNode *main_vnode,
- VTreeDataGraph &data_graph)
-{
- Vector<DFGraphSocket> sockets_to_compute = find_input_data_sockets(main_vnode, data_graph);
- Vector<bool> parameter_depends_on_particle(sockets_to_compute.size());
- auto dependencies = find_particle_dependencies(
- data_graph, sockets_to_compute, parameter_depends_on_particle);
-
- Vector<DFGraphSocket> sockets_with_deps;
- Vector<DFGraphSocket> sockets_without_deps;
- for (uint i = 0; i < sockets_to_compute.size(); i++) {
- if (parameter_depends_on_particle[i]) {
- sockets_with_deps.append(sockets_to_compute[i]);
- }
- else {
- sockets_without_deps.append(sockets_to_compute[i]);
- }
- }
-
- SharedFunction fn_without_deps = create_function__without_deps(
- data_graph.graph(), main_vnode->name(), sockets_without_deps);
- SharedFunction fn_with_deps = create_function__with_deps(
- data_graph.graph(), main_vnode->name(), sockets_with_deps, dependencies);
-
- ParticleFunction particle_function(fn_without_deps, fn_with_deps, parameter_depends_on_particle);
- return particle_function;
-}
-
static std::unique_ptr<Action> build_action(BuildContext &ctx,
VirtualSocket *start,
VirtualSocket *trigger);
diff --git a/source/blender/simulations/bparticles/inserters.hpp b/source/blender/simulations/bparticles/inserters.hpp
index a98f86e8b9b..d7349382f55 100644
--- a/source/blender/simulations/bparticles/inserters.hpp
+++ b/source/blender/simulations/bparticles/inserters.hpp
@@ -36,9 +36,6 @@ struct BuildContext {
}
};
-ValueOrError<ParticleFunction> create_particle_function(VirtualNode *main_vnode,
- VTreeDataGraph &data_graph);
-
using ForceFromNodeCallback = std::function<std::unique_ptr<Force>(
BuildContext &ctx, VirtualNode *vnode, ParticleFunction compute_inputs_fn)>;
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 2410e05b428..dfbdc3dade1 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -4,6 +4,7 @@
#include "node_frontend.hpp"
#include "inserters.hpp"
#include "integrator.hpp"
+#include "particle_function_builder.hpp"
namespace BParticles {
diff --git a/source/blender/simulations/bparticles/particle_function_builder.cpp b/source/blender/simulations/bparticles/particle_function_builder.cpp
new file mode 100644
index 00000000000..d0b80818857
--- /dev/null
+++ b/source/blender/simulations/bparticles/particle_function_builder.cpp
@@ -0,0 +1,125 @@
+#include "particle_function_builder.hpp"
+
+namespace BParticles {
+
+using BKE::VirtualSocket;
+using FN::DFGraphSocket;
+using FN::FunctionBuilder;
+using FN::FunctionGraph;
+using FN::SharedDataFlowGraph;
+using FN::SharedFunction;
+using FN::SharedType;
+
+Vector<DFGraphSocket> find_input_data_sockets(VirtualNode *vnode, VTreeDataGraph &data_graph)
+{
+ Vector<DFGraphSocket> inputs;
+ for (VirtualSocket *vsocket : vnode->inputs()) {
+ DFGraphSocket *socket = data_graph.lookup_socket_ptr(vsocket);
+ if (socket != nullptr) {
+ inputs.append(*socket);
+ }
+ }
+ return inputs;
+}
+
+struct SocketDependencies {
+ SetVector<DFGraphSocket> sockets;
+ SetVector<VirtualSocket *> vsockets;
+};
+
+static SocketDependencies find_particle_dependencies(VTreeDataGraph &data_graph,
+ ArrayRef<DFGraphSocket> sockets,
+ ArrayRef<bool> r_depends_on_particle)
+{
+ SocketDependencies combined_dependencies;
+
+ for (uint i = 0; i < sockets.size(); i++) {
+ DFGraphSocket socket = sockets[i];
+ auto dependencies = data_graph.find_placeholder_dependencies(socket);
+ bool has_dependency = dependencies.size() > 0;
+ r_depends_on_particle[i] = has_dependency;
+
+ combined_dependencies.sockets.add_multiple(dependencies.sockets);
+ combined_dependencies.vsockets.add_multiple(dependencies.vsockets);
+ BLI_assert(combined_dependencies.sockets.size() == combined_dependencies.vsockets.size());
+ }
+
+ return combined_dependencies;
+}
+
+static SharedFunction create_function__with_deps(SharedDataFlowGraph &graph,
+ StringRef function_name,
+ ArrayRef<DFGraphSocket> sockets_to_compute,
+ SocketDependencies &dependencies)
+{
+ FunctionBuilder fn_builder;
+ fn_builder.add_outputs(graph, sockets_to_compute);
+
+ for (uint i = 0; i < dependencies.sockets.size(); i++) {
+ VirtualSocket *vsocket = dependencies.vsockets[i];
+ DFGraphSocket socket = dependencies.sockets[i];
+ VirtualNode *vnode = vsocket->vnode();
+
+ SharedType &type = graph->type_of_output(socket);
+ StringRef name_prefix;
+ if (STREQ(vnode->idname(), "bp_ParticleInfoNode")) {
+ name_prefix = "Attribute: ";
+ }
+ else if (STREQ(vnode->idname(), "bp_CollisionInfoNode")) {
+ name_prefix = "Action Context: ";
+ }
+ else {
+ BLI_assert(false);
+ }
+ BLI_STRINGREF_STACK_COMBINE(name, name_prefix, vsocket->name());
+ fn_builder.add_input(name, type);
+ }
+
+ SharedFunction fn = fn_builder.build(function_name);
+ FunctionGraph fgraph(graph, dependencies.sockets, sockets_to_compute);
+ FN::fgraph_add_TupleCallBody(fn, fgraph);
+
+ return fn;
+}
+
+static SharedFunctio
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list