diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-22 15:16:08 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-22 15:16:08 +0300 |
commit | 980dd43bd4be7d5f2d893148984e5fd96c5747f4 (patch) | |
tree | bcfd4a1f02358f97ea1804f81f469689be00f31a /source/blender/simulation/intern/simulation_collect_influences.hh | |
parent | 47b6c332587ca45eddc98e75b3f563e2f17a0d47 (diff) |
Particles: give emitter its own state
High quality emitters need to maintain state themselves. For example,
this it needs to remember when it spawned the last particle.
This is especially important when the birth rate is changing over time.
Otherwise, there will be very visible artifacts.
It is quite likely that other components of the simulation need their own
state as well. Therefore, I refactored the `SimulationState` type a bit,
to make it more extensible. Instead of using hardcoded type numbers, a
string is used to identify the state type. Also, instead of having switch
statements in many places, there is a new `SimulationStateType` that
encapsulates information about how a specific state is created/freed/copied/...
I removed the integration with the point cache for now, because it was
not used anyway in it's current state.
Diffstat (limited to 'source/blender/simulation/intern/simulation_collect_influences.hh')
-rw-r--r-- | source/blender/simulation/intern/simulation_collect_influences.hh | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/source/blender/simulation/intern/simulation_collect_influences.hh b/source/blender/simulation/intern/simulation_collect_influences.hh index cca396ffa66..42cbea6977e 100644 --- a/source/blender/simulation/intern/simulation_collect_influences.hh +++ b/source/blender/simulation/intern/simulation_collect_influences.hh @@ -25,14 +25,43 @@ namespace blender::sim { -struct SimulationStatesInfo { - VectorSet<std::string> particle_simulation_names; +class RequiredStates { + private: + Map<std::string, const char *> state_type_by_state_name_; + + public: + void add(std::string state_name, const char *state_type) + { + BLI_assert(state_type != nullptr); + const char *type_name = state_type_by_state_name_.lookup_default(state_name, nullptr); + if (type_name != nullptr) { + if (!STREQ(state_type, type_name)) { + std::cout << "Warning: Tried to have two different states with the same name.\n"; + std::cout << " Name: " << state_name << "\n"; + std::cout << " Type 1: " << state_type << "\n"; + std::cout << " Type 2: " << type_name << "\n"; + } + return; + } + + state_type_by_state_name_.add(std::move(state_name), state_type); + } + + const Map<std::string, const char *> &states() const + { + return state_type_by_state_name_; + } + + bool is_required(StringRef state_name, StringRef state_type) const + { + return state_type_by_state_name_.lookup_default_as(state_name, "") == state_type; + } }; void collect_simulation_influences(Simulation &simulation, ResourceCollector &resources, SimulationInfluences &r_influences, - SimulationStatesInfo &r_states_info); + RequiredStates &r_required_states); } // namespace blender::sim |