Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2019-08-26 12:33:50 +0300
committerJacques Lucke <mail@jlucke.com>2019-08-26 12:33:50 +0300
commit5a3a155438c7a1dc97b5c660eac626cee46354cb (patch)
treed6a03624cabbb8a915352ee0598202680a06efc5
parent3f01ddd5d22ca4acbd827ca4bc2c07e8773d67eb (diff)
remove StepDescription and ParticleType entirely
-rw-r--r--source/blender/blenlib/BLI_multi_map.hpp9
-rw-r--r--source/blender/simulations/bparticles/node_frontend.cpp98
-rw-r--r--source/blender/simulations/bparticles/step_description.cpp21
-rw-r--r--source/blender/simulations/bparticles/step_description.hpp77
-rw-r--r--source/blender/simulations/bparticles/step_description_interfaces.hpp2
5 files changed, 68 insertions, 139 deletions
diff --git a/source/blender/blenlib/BLI_multi_map.hpp b/source/blender/blenlib/BLI_multi_map.hpp
index 75bfd962e1b..9d2a9fbc5b1 100644
--- a/source/blender/blenlib/BLI_multi_map.hpp
+++ b/source/blender/blenlib/BLI_multi_map.hpp
@@ -148,6 +148,15 @@ template<typename K, typename V, uint N = 4> class MultiMap {
{
return m_map.keys();
}
+
+ template<typename FuncT> void foreach_value(const FuncT &func)
+ {
+ for (Entry &entry : m_map.values()) {
+ for (const V &value : entry.get_slice(m_elements)) {
+ func(value);
+ }
+ }
+ }
};
} /* namespace BLI */
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 169e6147c69..586e5a19271 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -26,10 +26,10 @@ using FN::DataFlowNodes::VTreeDataGraph;
class BehaviorCollector {
public:
- Vector<Emitter *> m_emitters;
- MultiMap<std::string, Force *> m_forces;
- MultiMap<std::string, Event *> m_events;
- MultiMap<std::string, OffsetHandler *> m_offset_handlers;
+ Vector<Emitter *> &m_emitters;
+ MultiMap<std::string, Force *> &m_forces;
+ MultiMap<std::string, Event *> &m_events;
+ MultiMap<std::string, OffsetHandler *> &m_offset_handlers;
};
static bool is_particle_type_node(VirtualNode *vnode)
@@ -435,22 +435,34 @@ BLI_LAZY_INIT_STATIC(StringMap<ParseNodeCallback>, get_node_parsers)
return map;
}
-static std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualNodeTree &vtree,
- WorldState &world_state,
- float time_step)
+static void collect_particle_behaviors(
+ VirtualNodeTree &vtree,
+ WorldState &world_state,
+ Vector<std::string> &r_type_names,
+ Vector<Emitter *> &r_emitters,
+ MultiMap<std::string, Event *> &r_events_per_type,
+ MultiMap<std::string, OffsetHandler *> &r_offset_handler_per_type,
+ StringMap<AttributesDeclaration> &r_attributes_per_type,
+ StringMap<Integrator *> &r_integrators)
{
SCOPED_TIMER(__func__);
auto data_graph_or_error = FN::DataFlowNodes::generate_graph(vtree);
if (data_graph_or_error.is_error()) {
- return {};
+ return;
}
VTreeDataGraph vtree_data_graph = data_graph_or_error.extract_value();
- BehaviorCollector collector;
-
StringMap<ParseNodeCallback> &parsers = get_node_parsers();
+ MultiMap<std::string, Force *> forces;
+ BehaviorCollector collector = {
+ r_emitters,
+ forces,
+ r_events_per_type,
+ r_offset_handler_per_type,
+ };
+
for (VirtualNode *vnode : vtree.nodes()) {
StringRef idname = vnode->idname();
ParseNodeCallback *callback = parsers.lookup_ptr(idname);
@@ -459,15 +471,12 @@ static std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualN
}
}
- StringMap<ParticleType *> types;
-
- Vector<std::string> type_names;
for (VirtualNode *vnode : vtree.nodes_with_idname("bp_ParticleTypeNode")) {
StringRef name = vnode->name();
- type_names.append(name);
+ r_type_names.append(name);
}
- for (std::string &type_name : type_names) {
+ for (std::string &type_name : r_type_names) {
AttributesDeclaration attributes;
attributes.add<float3>("Position", float3(0, 0, 0));
attributes.add<float3>("Velocity", float3(0, 0, 0));
@@ -477,16 +486,9 @@ static std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualN
ArrayRef<Force *> forces = collector.m_forces.lookup_default(type_name);
EulerIntegrator *integrator = new EulerIntegrator(forces);
- ArrayRef<Event *> events = collector.m_events.lookup_default(type_name);
- ArrayRef<OffsetHandler *> offset_handlers = collector.m_offset_handlers.lookup_default(
- type_name);
-
- ParticleType *type = new ParticleType(attributes, integrator, events, offset_handlers);
- types.add_new(type_name, type);
+ r_attributes_per_type.add_new(type_name, attributes);
+ r_integrators.add_new(type_name, integrator);
}
-
- StepDescription *step_description = new StepDescription(time_step, types, collector.m_emitters);
- return std::unique_ptr<StepDescription>(step_description);
}
class NodeTreeStepSimulator : public StepSimulator {
@@ -504,24 +506,42 @@ class NodeTreeStepSimulator : public StepSimulator {
vtree.add_all_of_tree(m_btree);
vtree.freeze_and_index();
- auto step_description = step_description_from_node_tree(
- vtree, simulation_state.world(), time_step);
+ Vector<std::string> type_names;
+ Vector<Emitter *> emitters;
+ MultiMap<std::string, Event *> events;
+ MultiMap<std::string, OffsetHandler *> offset_handlers;
+ StringMap<AttributesDeclaration> attributes;
+ StringMap<Integrator *> integrators;
+
+ collect_particle_behaviors(vtree,
+ simulation_state.world(),
+ type_names,
+ emitters,
+ events,
+ offset_handlers,
+ attributes,
+ integrators);
StringMap<ParticleTypeInfo> types_to_simulate;
- step_description->particle_types().foreach_key_value_pair(
- [&types_to_simulate](StringRefNull name, ParticleType *type) {
- ParticleTypeInfo type_info = {
- &type->attributes(),
- &type->integrator(),
- type->events(),
- type->offset_handlers(),
- };
- types_to_simulate.add_new(name, type_info);
- });
-
- simulate_particles(
- simulation_state.particles(), time_step, step_description->emitters(), types_to_simulate);
+ for (std::string name : type_names) {
+ ParticleTypeInfo type_info = {
+ &attributes.lookup(name),
+ integrators.lookup(name),
+ events.lookup_default(name),
+ offset_handlers.lookup_default(name),
+ };
+ types_to_simulate.add_new(name, type_info);
+ }
+
+ simulate_particles(simulation_state.particles(), time_step, emitters, types_to_simulate);
simulation_state.world().current_step_is_over();
+
+ for (Emitter *emitter : emitters) {
+ delete emitter;
+ }
+ events.foreach_value([](Event *event) { delete event; });
+ offset_handlers.foreach_value([](OffsetHandler *handler) { delete handler; });
+ integrators.foreach_value([](Integrator *integrator) { delete integrator; });
}
};
diff --git a/source/blender/simulations/bparticles/step_description.cpp b/source/blender/simulations/bparticles/step_description.cpp
index 05a3641b3d1..decb1e3f4bb 100644
--- a/source/blender/simulations/bparticles/step_description.cpp
+++ b/source/blender/simulations/bparticles/step_description.cpp
@@ -22,25 +22,4 @@ OffsetHandler::~OffsetHandler()
{
}
-ParticleType::~ParticleType()
-{
- delete m_integrator;
-
- for (Event *event : m_events) {
- delete event;
- }
- for (OffsetHandler *handler : m_offset_handlers) {
- delete handler;
- }
-}
-
-StepDescription::~StepDescription()
-{
- m_types.foreach_value([](ParticleType *type) { delete type; });
-
- for (Emitter *emitter : m_emitters) {
- delete emitter;
- }
-}
-
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/step_description.hpp b/source/blender/simulations/bparticles/step_description.hpp
index 73d339ba44c..198064fbb33 100644
--- a/source/blender/simulations/bparticles/step_description.hpp
+++ b/source/blender/simulations/bparticles/step_description.hpp
@@ -99,81 +99,4 @@ class OffsetHandler {
virtual void execute(OffsetHandlerInterface &interface) = 0;
};
-/**
- * Describes how one type of particle behaves and which attributes it has.
- */
-class ParticleType {
- private:
- AttributesDeclaration m_attributes;
- Integrator *m_integrator;
- Vector<Event *> m_events;
- Vector<OffsetHandler *> m_offset_handlers;
-
- public:
- ParticleType(AttributesDeclaration &attributes,
- Integrator *integrator,
- ArrayRef<Event *> events,
- ArrayRef<OffsetHandler *> offset_handlers)
- : m_attributes(attributes),
- m_integrator(integrator),
- m_events(events),
- m_offset_handlers(offset_handlers)
- {
- }
-
- ~ParticleType();
-
- Integrator &integrator()
- {
- return *m_integrator;
- }
-
- ArrayRef<OffsetHandler *> offset_handlers()
- {
- return m_offset_handlers;
- }
-
- ArrayRef<Event *> events()
- {
- return m_events;
- }
-
- AttributesDeclaration &attributes()
- {
- return m_attributes;
- }
-};
-
-/**
- * Describes how the current state of a particle system transitions to the next state.
- */
-class StepDescription {
- float m_duration;
- StringMap<ParticleType *> m_types;
- Vector<Emitter *> m_emitters;
-
- public:
- StepDescription(float duration, StringMap<ParticleType *> types, ArrayRef<Emitter *> emitters)
- : m_duration(duration), m_types(types), m_emitters(emitters)
- {
- }
-
- ~StepDescription();
-
- float step_duration()
- {
- return m_duration;
- }
-
- ArrayRef<Emitter *> emitters()
- {
- return m_emitters;
- }
-
- StringMap<ParticleType *> &particle_types()
- {
- return m_types;
- }
-};
-
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/step_description_interfaces.hpp b/source/blender/simulations/bparticles/step_description_interfaces.hpp
index 602d9730c0f..c2747d9a2bc 100644
--- a/source/blender/simulations/bparticles/step_description_interfaces.hpp
+++ b/source/blender/simulations/bparticles/step_description_interfaces.hpp
@@ -5,8 +5,6 @@
namespace BParticles {
-class ParticleType;
-
struct BlockStepData {
ParticleAllocator &particle_allocator;
ParticlesBlock &block;