[Bf-blender-cvs] [a0f9564d1b1] functions: cleanup finding placeholder dependencies
Jacques Lucke
noreply at git.blender.org
Wed Jul 24 19:11:19 CEST 2019
Commit: a0f9564d1b177fba003941bd010ae54aeb03d084
Author: Jacques Lucke
Date: Wed Jul 24 10:14:51 2019 +0200
Branches: functions
https://developer.blender.org/rBa0f9564d1b177fba003941bd010ae54aeb03d084
cleanup finding placeholder dependencies
===================================================================
M source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
M source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
M source/blender/simulations/bparticles/inserters.cpp
===================================================================
diff --git a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
index d8f14f41886..37d848ff5c3 100644
--- a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
@@ -145,5 +145,65 @@ Optional<VTreeDataGraph> generate_graph(VirtualNodeTree &vtree)
build_mapping_for_original_sockets(socket_map, build_result.mapping));
}
+Vector<VirtualSocket *> VTreeDataGraph::find_placeholder_dependencies(
+ ArrayRef<VirtualSocket *> sockets)
+{
+ Stack<DFGraphSocket> to_be_checked;
+ Set<DFGraphSocket> found;
+ Vector<VirtualSocket *> dependencies;
+
+ for (VirtualSocket *vsocket : sockets) {
+ DFGraphSocket socket = this->lookup_socket(vsocket);
+ to_be_checked.push(socket);
+ found.add_new(socket);
+ }
+
+ while (!to_be_checked.empty()) {
+ DFGraphSocket socket = to_be_checked.pop();
+ if (socket.is_input()) {
+ DFGraphSocket origin = m_graph->origin_of_input(socket);
+ if (found.add(origin)) {
+ to_be_checked.push(origin);
+ }
+ }
+ else {
+ uint node_id = m_graph->node_id_of_output(socket);
+ SharedFunction &fn = m_graph->function_of_node(node_id);
+ auto *body = fn->body<VNodePlaceholderBody>();
+ if (body == nullptr) {
+ for (DFGraphSocket input : m_graph->inputs_of_node(node_id)) {
+ if (found.add(input)) {
+ to_be_checked.push(input);
+ }
+ }
+ }
+ else {
+ VirtualNode *vnode = body->vnode();
+ uint data_output_index = m_graph->index_of_output(socket);
+ VirtualSocket *vsocket = this->find_data_output(vnode, data_output_index);
+ dependencies.append(vsocket);
+ }
+ }
+ }
+
+ return dependencies;
+}
+
+VirtualSocket *VTreeDataGraph::find_data_output(VirtualNode *vnode, uint index)
+{
+ uint count = 0;
+ for (uint i = 0; i < vnode->outputs().size(); i++) {
+ VirtualSocket *vsocket = vnode->output(i);
+ if (this->uses_socket(vsocket)) {
+ if (index == count) {
+ return vsocket;
+ }
+ count++;
+ }
+ }
+ BLI_assert(false);
+ return nullptr;
+}
+
} // namespace DataFlowNodes
} // namespace FN
diff --git a/source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp b/source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
index c5086de509d..ec0d36a1709 100644
--- a/source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
@@ -45,6 +45,11 @@ class VTreeDataGraph {
{
return m_mapping.contains(vsocket);
}
+
+ Vector<VirtualSocket *> find_placeholder_dependencies(ArrayRef<VirtualSocket *> sockets);
+
+ private:
+ VirtualSocket *find_data_output(VirtualNode *vnode, uint index);
};
class VNodePlaceholderBody : public FunctionBody {
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 88cb9a00997..8bd96771f9f 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -21,80 +21,22 @@ namespace BParticles {
using FN::DFGraphSocket;
using FN::SharedFunction;
using FN::SharedType;
-using FN::DataFlowNodes::VNodePlaceholderBody;
-static Vector<DFGraphSocket> find_function_inputs(VTreeDataGraph &data_graph,
- ArrayRef<VirtualSocket *> output_vsockets)
+static Vector<DFGraphSocket> insert_function_inputs(FN::FunctionBuilder &fn_builder,
+ VTreeDataGraph &data_graph,
+ ArrayRef<VirtualSocket *> output_vsockets)
{
- Stack<DFGraphSocket> to_be_checked;
- Set<DFGraphSocket> found;
- Vector<DFGraphSocket> output;
+ Vector<VirtualSocket *> placeholder_dependencies = data_graph.find_placeholder_dependencies(
+ output_vsockets);
- auto &graph = data_graph.graph();
-
- for (VirtualSocket *vsocket : output_vsockets) {
- DFGraphSocket socket = data_graph.lookup_socket(vsocket);
- to_be_checked.push(socket);
- found.add_new(socket);
- }
-
- while (!to_be_checked.empty()) {
- DFGraphSocket socket = to_be_checked.pop();
- if (socket.is_input()) {
- DFGraphSocket origin = graph->origin_of_input(socket);
- if (found.add(origin)) {
- to_be_checked.push(origin);
- }
- }
- else {
- uint node_id = graph->node_id_of_output(socket);
- SharedFunction &fn = graph->function_of_node(node_id);
- auto *body = fn->body<VNodePlaceholderBody>();
- if (body == nullptr) {
- for (DFGraphSocket input : graph->inputs_of_node(node_id)) {
- if (found.add(input)) {
- to_be_checked.push(input);
- }
- }
- }
- else {
- output.append(socket);
- }
- }
- }
-
- return output;
-}
-
-static VirtualSocket *find_data_output(VTreeDataGraph &data_graph, VirtualNode *vnode, uint index)
-{
- uint count = 0;
- for (uint i = 0; i < vnode->outputs().size(); i++) {
- VirtualSocket *vsocket = vnode->output(i);
- if (data_graph.uses_socket(vsocket)) {
- if (index == count) {
- return vsocket;
- }
- count++;
- }
- }
- BLI_assert(false);
- return nullptr;
-}
-
-static Vector<FN::DFGraphSocket> insert_function_inputs(FN::FunctionBuilder &fn_builder,
- VTreeDataGraph &data_graph,
- ArrayRef<VirtualSocket *> output_vsockets)
-{
- Vector<DFGraphSocket> inputs = find_function_inputs(data_graph, output_vsockets);
+ Vector<DFGraphSocket> function_inputs;
auto &graph = data_graph.graph();
- for (DFGraphSocket socket : inputs) {
- BLI_assert(socket.is_output());
- uint index = graph->index_of_output(socket);
- VirtualNode *vnode = graph->function_body_of_output<VNodePlaceholderBody>(socket)->vnode();
- VirtualSocket *vsocket = find_data_output(data_graph, vnode, index);
+ for (VirtualSocket *vsocket : placeholder_dependencies) {
+ BLI_assert(vsocket->is_output());
+ VirtualNode *vnode = vsocket->vnode();
+ DFGraphSocket socket = data_graph.lookup_socket(vsocket);
SharedType &type = graph->type_of_output(socket);
std::string name_prefix;
@@ -104,10 +46,14 @@ static Vector<FN::DFGraphSocket> insert_function_inputs(FN::FunctionBuilder &fn_
else if (STREQ(vnode->idname(), "bp_MeshCollisionEventNode")) {
name_prefix = "Event: ";
}
+ else {
+ BLI_assert(false);
+ }
fn_builder.add_input(name_prefix + vsocket->name(), type);
+ function_inputs.append(socket);
}
- return inputs;
+ return function_inputs;
}
static SharedFunction create_function(VTreeDataGraph &data_graph,
More information about the Bf-blender-cvs
mailing list