Commit: 7e3e301bb1e5f4d5a136038033e3e8fa6555ebf2
Author: Jacques Lucke
Date: Mon Sep 16 11:39:43 2019 +0200
Branches: functions
https://developer.blender.org/rB7e3e301bb1e5f4d5a136038033e3e8fa6555ebf2
more centralized ownership of actions
===================================================================
M source/blender/simulations/bparticles/actions.hpp
M source/blender/simulations/bparticles/emitters.hpp
M source/blender/simulations/bparticles/events.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
M source/blender/simulations/bparticles/offset_handlers.cpp
M source/blender/simulations/bparticles/offset_handlers.hpp
===================================================================
diff --git a/source/blender/simulations/bparticles/actions.hpp
b/source/blender/simulations/bparticles/actions.hpp
index 789157e2965..31f77aa8fcc 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -11,10 +11,10 @@ class NoneAction : public Action {
class ActionSequence : public Action {
private:
- Vector<std::unique_ptr<Action>> m_actions;
+ Vector<Action *> m_actions;
public:
- ActionSequence(Vector<std::unique_ptr<Action>> actions) :
m_actions(std::move(actions))
+ ActionSequence(Vector<Action *> actions) : m_actions(std::move(actions))
{
}
@@ -89,15 +89,15 @@ class ExplodeAction : public Action {
private:
ArrayRef<std::string> m_systems_to_emit;
ParticleFunction *m_inputs_fn;
- std::unique_ptr<Action> m_on_birth_action;
+ Action *m_on_birth_action;
public:
ExplodeAction(ArrayRef<std::string> systems_to_emit,
ParticleFunction *inputs_fn,
- std::unique_ptr<Action> on_birth_action)
+ Action *on_birth_action)
: m_systems_to_emit(systems_to_emit),
m_inputs_fn(inputs_fn),
- m_on_birth_action(std::move(on_birth_action))
+ m_on_birth_action(on_birth_action)
{
}
@@ -107,15 +107,12 @@ class ExplodeAction : public Action {
class ConditionAction : public Action {
private:
ParticleFunction *m_inputs_fn;
- std::unique_ptr<Action> m_true_action, m_false_action;
+ Action *m_true_action;
+ Action *m_false_action;
public:
- ConditionAction(ParticleFunction *inputs_fn,
- std::unique_ptr<Action> true_action,
- std::unique_ptr<Action> false_action)
- : m_inputs_fn(inputs_fn),
- m_true_action(std::move(true_action)),
- m_false_action(std::move(false_action))
+ ConditionAction(ParticleFunction *inputs_fn, Action *true_action, Action
*false_action)
+ : m_inputs_fn(inputs_fn), m_true_action(true_action),
m_false_action(false_action)
{
}
diff --git a/source/blender/simulations/bparticles/emitters.hpp
b/source/blender/simulations/bparticles/emitters.hpp
index 4027519e688..ee9bf562dbe 100644
--- a/source/blender/simulations/bparticles/emitters.hpp
+++ b/source/blender/simulations/bparticles/emitters.hpp
@@ -14,7 +14,7 @@ using FN::TupleCallBody;
class SurfaceEmitter : public Emitter {
private:
ArrayRef<std::string> m_systems_to_emit;
- std::unique_ptr<Action> m_on_birth_action;
+ Action *m_on_birth_action;
Object *m_object;
VaryingFloat4x4 m_transform;
@@ -24,13 +24,13 @@ class SurfaceEmitter : public Emitter {
public:
SurfaceEmitter(ArrayRef<std::string> systems_to_emit,
- std::unique_ptr<Action> on_birth_action,
+ Action *on_birth_action,
Object *object,
VaryingFloat4x4 transform,
float rate,
Vector<float> vertex_weights)
: m_systems_to_emit(systems_to_emit),
- m_on_birth_action(std::move(on_birth_action)),
+ m_on_birth_action(on_birth_action),
m_object(object),
m_transform(transform),
m_rate(rate),
diff --git a/source/blender/simulations/bparticles/events.hpp
b/source/blender/simulations/bparticles/events.hpp
index 9d05605423d..6bb93026d09 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -20,13 +20,11 @@ class AgeReachedEvent : public Event {
private:
std::string m_identifier;
ParticleFunction *m_inputs_fn;
- std::unique_ptr<Action> m_action;
+ Action *m_action;
public:
- AgeReachedEvent(StringRef identifier,
- ParticleFunction *inputs_fn,
- std::unique_ptr<Action> action)
- : m_identifier(identifier), m_inputs_fn(inputs_fn),
m_action(std::move(action))
+ AgeReachedEvent(StringRef identifier, ParticleFunction *inputs_fn, Action
*action)
+ : m_identifier(identifier), m_inputs_fn(inputs_fn), m_action(action)
{
}
@@ -39,11 +37,11 @@ class CustomEvent : public Event {
private:
std::string m_identifier;
ParticleFunction *m_inputs_fn;
- std::unique_ptr<Action> m_action;
+ Action *m_action;
public:
- CustomEvent(StringRef identifier, ParticleFunction *inputs_fn,
std::unique_ptr<Action> action)
- : m_identifier(identifier), m_inputs_fn(inputs_fn),
m_action(std::move(action))
+ CustomEvent(StringRef identifier, ParticleFunction *inputs_fn, Action
*action)
+ : m_identifier(identifier), m_inputs_fn(inputs_fn), m_action(action)
{
}
@@ -59,7 +57,7 @@ class MeshCollisionEvent : public Event {
BVHTreeFromMesh m_bvhtree_data;
float4x4 m_local_to_world;
float4x4 m_world_to_local;
- std::unique_ptr<Action> m_action;
+ Action *m_action;
struct RayCastResult {
bool success;
@@ -75,8 +73,8 @@ class MeshCollisionEvent : public Event {
};
public:
- MeshCollisionEvent(StringRef identifier, Object *object,
std::unique_ptr<Action> action)
- : m_identifier(identifier), m_object(object), m_action(std::move(action))
+ MeshCollisionEvent(StringRef identifier, Object *object, Action *action)
+ : m_identifier(identifier), m_object(object), m_action(action)
{
BLI_assert(object->type == OB_MESH);
m_local_to_world = m_object->obmat;
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp
b/source/blender/simulations/bparticles/node_frontend.cpp
index 7f3f0ff8d7a..508a15351bc 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -35,6 +35,11 @@ using FN::Types::StringW;
static StringRef particle_system_idname = "bp_ParticleSystemNode";
static StringRef combine_influences_idname = "bp_CombineInfluencesNode";
+class VTreeData;
+using ActionParserCallback =
+ std::function<std::unique_ptr<Action>(VTreeData &vtree_data, VirtualSocket
*execute_vsocket)>;
+StringMap<ActionParserCallback> &get_action_parsers();
+
class InfluencesCollector {
public:
Vector<Emitter *> &m_emitters;
@@ -51,6 +56,7 @@ class VTreeData {
Vector<std::unique_ptr<Tuple>> m_tuples;
Vector<std::unique_ptr<FN::FunctionOutputNamesProvider>> m_name_providers;
Vector<std::unique_ptr<Vector<std::string>>> m_string_vectors;
+ Vector<std::unique_ptr<Action>> m_actions;
public:
VTreeData(VTreeDataGraph &vtree_data) : m_vtree_data_graph(vtree_data)
@@ -85,26 +91,6 @@ class VTreeData {
return fn_ptr;
}
- TupleCallBody *function_body_for_inputs(VirtualNode *vnode, ArrayRef<uint>
input_indices)
- {
- VectorSet<DataSocket> sockets_to_compute;
- for (uint index : input_indices) {
-
sockets_to_compute.add_new(m_vtree_data_graph.lookup_socket(vnode->input(index)));
- }
-
- Vector<VirtualSocket *> dependencies =
m_vtree_data_graph.find_placeholder_dependencies(
- sockets_to_compute);
- if (dependencies.size() > 0) {
- return nullptr;
- }
-
- FunctionGraph fgraph(m_vtree_data_graph.graph(), {}, sockets_to_compute);
- auto fn = fgraph.new_function(vnode->name());
- FN::fgraph_add_TupleCallBody(fn, fgraph);
- m_functions.append(fn);
- return &fn->body<TupleCallBody>();
- }
-
Optional<NamedTupleRef> compute_inputs(VirtualNode *vnode, ArrayRef<uint>
input_indices)
{
TupleCallBody *body_ptr = this->function_body_for_inputs(vnode,
input_indices);
@@ -147,6 +133,44 @@ class VTreeData {
return *system_names;
}
+ Action *build_action(VirtualSocket *start)
+ {
+ BLI_assert(start->is_input());
+ if (start->links().size() != 1) {
+ return nullptr;
+ }
+
+ VirtualSocket *execute_socket = start->links()[0];
+ if (execute_socket->idname() != "bp_ExecuteSocket") {
+ return nullptr;
+ }
+
+ StringMap<ActionParserCallback> &parsers = get_action_parsers();
+ ActionParserCallback &parser =
parsers.lookup(execute_socket->vnode()->idname());
+ std::unique_ptr<Action> action = parser(*this, execute_socket);
+ Action *action_ptr = action.get();
+ if (action_ptr == nullptr) {
+ return nullptr;
+ }
+ m_actions.append(std::move(action));
+ return action_ptr;
+ }
+
+ Action *build_action_list(VirtualNode *start_vnode, StringRef name)
+ {
+ Vector<VirtualSocket *> execute_sockets =
this->find_execute_sockets(start_vnode, name);
+ Vector<Action *> actions;
+ for (VirtualSocket *socket : execute_sockets) {
+ Action *action = this->build_action(socket);
+ if (action != nullptr) {
+ actions.append(action);
+ }
+ }
+ Action *sequence = new ActionSequence(std::move(actions));
+ m_actions.append(std::unique_ptr<Action>(sequence));
+ return sequence;
+ }
+
private:
Vector<VirtualNode *> find_target_system_nodes(VirtualSocket *vsocket)
{
@@ -169,34 +193,47 @@ class VTreeData {
}
}
}
-};
-static std::unique_ptr<Action> build_action_list(VTreeData &vtree_data,
- VirtualNode *start_vnode,
- StringRef name);
+ TupleCallBody *function_body_for_inputs(VirtualNode *vnode, ArrayRef<uint>
input_indices)
+ {
+ VectorSet<DataSocket> sockets_to_compute;
+ for (uint index : input_indices) {
+
sockets_to_compute.add_new(m_vtree_data_graph.lookup_socket(vnode->input(index)));
+ }
+
+ Vector<VirtualSocket *> dependencies =
m_vtree_data_graph.find_placeholder_dependencies(
+ sockets_to_compute);
+ if (dependencies.size() > 0) {
+ return nullptr;
+ }
-static Vector<VirtualSocket *> find_execute_sockets(VirtualNode *vnode,
StringRef name_prefix)
-{
- bool found_name = false;
- Vector<VirtualSocket *> execute_sockets;
- for (VirtualSocket *vsocket : vnode->inputs()) {
- if (StringRef(vsocket->name()).startswith(name_prefix)) {
- if (vsocket->idname() == "fn_OperatorSocket") {
- found_name = true;
- break;
- }
- else {
- execute_sockets.append(vsocket);
+ FunctionGraph fgraph(m_vtree_data_graph.graph(), {}, sockets_to_compute);
+ auto fn = fgraph.new_function(vnode->name());
+ FN::fgraph_add_TupleCallBody(fn, fgraph);
+ m_functions.
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs