ParticleEmitter2.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_PARTICLE_EMITTER2_HPP
12 #define CUBBYFLOW_PARTICLE_EMITTER2_HPP
13 
15 
16 namespace CubbyFlow
17 {
22 {
23  public:
30  using OnBeginUpdateCallback =
31  std::function<void(ParticleEmitter2*, double, double)>;
32 
34  ParticleEmitter2() = default;
35 
37  ParticleEmitter2(const ParticleEmitter2&) = default;
38 
40  ParticleEmitter2(ParticleEmitter2&&) noexcept = default;
41 
43  virtual ~ParticleEmitter2() = default;
44 
46  ParticleEmitter2& operator=(const ParticleEmitter2&) = default;
47 
49  ParticleEmitter2& operator=(ParticleEmitter2&&) noexcept = default;
50 
53  void Update(double currentTimeInSeconds, double timeIntervalInSeconds);
54 
56  [[nodiscard]] const ParticleSystemData2Ptr& GetTarget() const;
57 
59  void SetTarget(const ParticleSystemData2Ptr& particles);
60 
62  [[nodiscard]] bool GetIsEnabled() const;
63 
65  void SetIsEnabled(bool enabled);
66 
77  void SetOnBeginUpdateCallback(const OnBeginUpdateCallback& callback);
78 
79  protected:
81  virtual void OnSetTarget(const ParticleSystemData2Ptr& particles);
82 
84  virtual void OnUpdate(double currentTimeInSeconds,
85  double timeIntervalInSeconds) = 0;
86 
87  private:
88  ParticleSystemData2Ptr m_particles;
89  OnBeginUpdateCallback m_onBeginUpdateCallback;
90  bool m_isEnabled = true;
91 };
92 
94 using ParticleEmitter2Ptr = std::shared_ptr<ParticleEmitter2>;
95 } // namespace CubbyFlow
96 
97 #endif
void SetOnBeginUpdateCallback(const OnBeginUpdateCallback &callback)
Sets the callback function to be called when ParticleEmitter2::Update function is invoked...
std::shared_ptr< ParticleEmitter2 > ParticleEmitter2Ptr
Shared pointer for the ParticleEmitter2 type.
Definition: ParticleEmitter2.hpp:94
bool GetIsEnabled() const
Returns true if the emitter is enabled.
void SetTarget(const ParticleSystemData2Ptr &particles)
Sets the target particle system to emit.
void SetIsEnabled(bool enabled)
Sets true/false to enable/disable the emitter.
virtual void OnSetTarget(const ParticleSystemData2Ptr &particles)
Called when ParticleEmitter2::SetTarget is executed.
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition: ParticleSystemData.hpp:281
ParticleEmitter2()=default
Default constructor.
Definition: pybind11Utils.hpp:20
const ParticleSystemData2Ptr & GetTarget() const
Returns the target particle system to emit.
std::function< void(ParticleEmitter2 *, double, double)> OnBeginUpdateCallback
Callback function type for update calls.
Definition: ParticleEmitter2.hpp:31
void Update(double currentTimeInSeconds, double timeIntervalInSeconds)
virtual void OnUpdate(double currentTimeInSeconds, double timeIntervalInSeconds)=0
Called when ParticleEmitter2::Update is executed.
Abstract base class for 2-D particle emitter.
Definition: ParticleEmitter2.hpp:21