1 #ifndef DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_MODIFIER_H
2 #define DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_MODIFIER_H
4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dali-toolkit/public-api/particle-system/particle-types.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/callback.h>
28 namespace Dali::Toolkit::ParticleSystem::Internal
30 class ParticleModifier;
33 namespace Dali::Toolkit::ParticleSystem
35 class ParticleEmitter;
39 class DALI_TOOLKIT_API ParticleModifierInterface
45 virtual ~ParticleModifierInterface() = default;
48 * @brief Update function to update the modifier to alter the behavior of particles.
49 * @param[in] particleList List of particles
50 * @param[in] firstParticleIndex Index of the first particle
51 * @param[in] particleCount Number of particles
53 virtual void Update(ParticleList& particleList, uint32_t firstParticleIndex, uint32_t particleCount) = 0;
56 * @brief Will be called to check whether modifier supports multi-threading
58 * If modifier supports multi-threading then Update() function will be called
59 * providing partial range of particles to process.
61 * It is important to make sure, the batch of particles has no dependencies
62 * on particles from outside the batch. If this is the case, the function
63 * must return false and single threaded process will proceed.
65 * @return True if modifier supports multi-threading
67 virtual bool IsMultiThreaded()
74 * @class ParticleModifier
76 * @brief ParticleModifer allows altering particle behaviour during simulation.
78 * Multiple modifiers can be used in the modifier stack.
80 * Output of previous modifier becomes an input of the next one.
83 class DALI_TOOLKIT_API ParticleModifier : public Dali::BaseHandle
89 ParticleModifier() = default;
94 ~ParticleModifier() = default;
97 * @brief Creates new modifier with given functor object.
98 * The modifier takes over the ownership over the functor object.
100 * @param[in] modifierUpdater Functor for the modifier
101 * @return New ParticleModifier object
103 static ParticleModifier New(std::unique_ptr<ParticleModifierInterface>&& modifierUpdater);
106 * @brief Creates new modifier with given class and construction arguments
108 * @return New ParticleModifier object
110 template<class T, class... Args>
111 static ParticleModifier New(Args... args)
113 return New(std::move(std::make_unique<T>(args...)));
116 * @brief Returns associated particle modifier callback
118 * @return Valid reference to associated callback
120 ParticleModifierInterface& GetModifierCallback();
123 * @brief Downcasts a handle to ParticleModifier handle.
125 * If handle points to an ParticleModifier object, the downcast produces valid handle.
126 * If not, the returned handle is left uninitialized.
128 * @param[in] handle to An object
129 * @return handle to a ParticleModifier object or an uninitialized handle
131 static ParticleModifier DownCast(BaseHandle handle);
136 * @brief This constructor is used by ParticleModifier::New() methods.
138 * @param [in] impl A pointer to a newly allocated implementation
140 ParticleModifier(Internal::ParticleModifier* impl);
144 } // namespace Dali::Toolkit::ParticleSystem