Immortal emitter is now mortal as it should be. 77/293877/3
authorAdam Bialogonski <adam.b@samsung.com>
Wed, 7 Jun 2023 08:46:40 +0000 (09:46 +0100)
committerAdam Bialogonski <adam.b@samsung.com>
Tue, 20 Jun 2023 15:55:15 +0000 (16:55 +0100)
Change-Id: I6709952446a8cb5ccdf6c6e1691600e42bff7e7a

13 files changed:
examples/particle-system/effects/fire-ring-effect-modifier.cpp
examples/particle-system/effects/fire-ring-effect-modifier.h
examples/particle-system/effects/fire-ring-effect-source.cpp
examples/particle-system/effects/fire-ring-effect-source.h
examples/particle-system/effects/image-effect-modifier.cpp
examples/particle-system/effects/image-effect-modifier.h
examples/particle-system/effects/image-effect-source.cpp
examples/particle-system/effects/image-effect-source.h
examples/particle-system/effects/particle-effect.h
examples/particle-system/effects/sparkles-effect-modifier.cpp
examples/particle-system/effects/sparkles-effect-modifier.h
examples/particle-system/effects/sparkles-effect-source.cpp
examples/particle-system/effects/sparkles-effect-source.h

index 56f7e5b2220de956488bda2c85ef7f1b49396e2f..f7027b868b5e2f3dd378ba83d219270750e44ed1 100644 (file)
@@ -55,7 +55,12 @@ void FireModifier::Update(ParticleList& particleList, uint32_t first, uint32_t c
   // Retrieve the Source and get the stream
   if(!mStreamBasePos)
   {
-    mStreamBasePos = static_cast<FireSource*>(&mEmitter.GetSource().GetSourceCallback())->mStreamBasePos;
+    auto handle = mEmitter.GetHandle();
+    if(!handle)
+    {
+      return;
+    }
+    mStreamBasePos = static_cast<FireSource*>(&handle.GetSource().GetSourceCallback())->mStreamBasePos;
   }
 
   // Missing stream, return!
index 3f9f6ea4ec2de107060020b19c9b4258036bb787..7bf4f52c6b7887018b37f6062782e55c018547ee 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali-toolkit/public-api/particle-system/particle-list.h>
 #include <dali-toolkit/public-api/particle-system/particle.h>
 #include <dali/public-api/common/vector-wrapper.h>
+#include <dali/public-api/object/weak-handle.h>
 #include <ctime>
 
 namespace Dali::ParticleEffect
@@ -76,7 +77,7 @@ public:
   void Update(ParticleList& particleList, uint32_t first, uint32_t count) override;
 
   ColorGradient mFireGradient;
-  ParticleEmitter mEmitter;
+  Dali::WeakHandle<ParticleEmitter> mEmitter;
   uint32_t mStreamBasePos{0u};
   uint32_t mAngle{0u};
 };
index 0ff0652a495796bafbabd5b281c9c0788813ee44..f76d40d4457105be755d1d49d35326a94ac9e045 100644 (file)
@@ -40,7 +40,11 @@ mEmitter(emitter)
 
 void FireSource::Init()
 {
-  mStreamBasePos = mEmitter.GetParticleList().AddLocalStream<Vector3>(Vector3::ZERO);
+  auto handle = mEmitter.GetHandle();
+  if(handle)
+  {
+    mStreamBasePos = handle.GetParticleList().AddLocalStream<Vector3>(Vector3::ZERO);
+  }
 }
 
 uint32_t FireSource::Update(ParticleList& particleList, uint32_t count)
index 28f78efaf2a1ebb8c2200e16b0b8a465c529d7b6..1af4513db17f108e7278b9f7c7b15ad73d3aafc9 100644 (file)
@@ -23,6 +23,7 @@
 #include <dali-toolkit/public-api/particle-system/particle-modifier.h>
 #include <dali-toolkit/public-api/particle-system/particle-list.h>
 #include <dali-toolkit/public-api/particle-system/particle.h>
+#include <dali/public-api/object/weak-handle.h>
 #include <ctime>
 
 namespace Dali::ParticleEffect
@@ -43,7 +44,7 @@ public:
 
   void UpdateParticle(Vector3& position, Vector3& basePosition, Vector4& color, Vector3& velocity, Vector3& scale);
 
-  ParticleEmitter mEmitter;
+  Dali::WeakHandle<ParticleEmitter> mEmitter;
 
   Dali::Vector2 mRadius;
 
index 395040c7b21dd1e86689ce55eda9e54d68c007c8..2fa3c444c1fc3db525702d735f8f91f084a57b18 100644 (file)
@@ -44,7 +44,12 @@ void ImageExplodeEffectModifier::Update(ParticleList& particleList, uint32_t fir
   // Retrieve the Source and get the stream
   if(!mStreamBasePos)
   {
-    mStreamBasePos = static_cast<ImageExplodeEffectSource*>(&mEmitter.GetSource().GetSourceCallback())->mStreamBasePos;
+    auto handle = mEmitter.GetHandle();
+    if(!handle)
+    {
+      return;
+    }
+    mStreamBasePos = static_cast<ImageExplodeEffectSource*>(&handle.GetSource().GetSourceCallback())->mStreamBasePos;
   }
 
   // Missing stream, return!
index 8a0781e4549a7a3c7e5e8123b73e8bf17df676cd..471facd8740cf4c73c7cd6eecd708d7214d0b867 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali-toolkit/public-api/particle-system/particle-modifier.h>
 #include <dali-toolkit/public-api/particle-system/particle-list.h>
 #include <dali-toolkit/public-api/particle-system/particle.h>
+#include <dali/public-api/object/weak-handle.h>
 #include <ctime>
 
 namespace Dali::ParticleEffect
@@ -40,7 +41,7 @@ public:
 
   void Update(ParticleList& particleList, uint32_t first, uint32_t count) override;
 
-  ParticleEmitter mEmitter;
+  WeakHandle<ParticleEmitter> mEmitter;
   uint32_t mStreamBasePos{0u};
   float mAngle{0.0f};
 
index 52d558a4c77a13e8cd3e2ff95e9c121cc380d33d..17963d0d28a3a82e0464270146b8bd0f7c04e744 100644 (file)
@@ -64,12 +64,16 @@ mEmitter(emitter)
 
 void ImageExplodeEffectSource::Init()
 {
-  mStreamBasePos = mEmitter.GetParticleList().AddLocalStream<Vector3>(Vector3::ZERO);
+  auto handle = mEmitter.GetHandle();
+  if(handle)
+  {
+    mStreamBasePos = handle.GetParticleList().AddLocalStream<Vector3>(Vector3::ZERO);
+  }
 }
 
 uint32_t ImageExplodeEffectSource::Update(ParticleList& particleList, uint32_t count)
 {
-  if(!mShouldEmit)
+  if(!mShouldEmit || !mStreamBasePos)
   {
     return 0;
   }
index 49d84c91dc4a3271e00c2e49c39bd03ebfcc9e42..c30ba993df700e043062036c40de05bce8d38f29 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali-toolkit/public-api/particle-system/particle-list.h>
 #include <dali-toolkit/public-api/particle-system/particle.h>
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/public-api/object/weak-handle.h>
 #include <ctime>
 
 namespace Dali::ParticleEffect
@@ -46,7 +47,7 @@ public:
 
   void Init() override;
 
-  ParticleEmitter mEmitter;
+  WeakHandle<ParticleEmitter> mEmitter;
 
   uint32_t mImageWidth{0u};
   uint32_t mImageHeight{0u};
index a1277ef2b651a5818e661ee95add6e8b83e8f2a1..88e1b323e8f69390214c6427c26708613154d9d7 100644 (file)
@@ -55,10 +55,6 @@ public:
   ~ParticleEffect();
 
   Dali::Toolkit::ParticleSystem::ParticleEmitter CreateEffectEmitter( EffectType effectType, Actor parentActor, const ParticleEffectParams& params );
-
-private:
-
-
 };
 }
 
index dda93da9176e4443bba94954e0792418ea8b0cd9..d212bfd6a865e5610f4a672c34c43a722ffe4de1 100644 (file)
@@ -42,13 +42,18 @@ void SparklesModifier::Update(ParticleList& particleList, uint32_t first, uint32
   mAngle = ((mAngle + 2) % 360);
 
   // Retrieve the Source and get the stream
+  auto handle = mEmitter.GetHandle();
+  if(!handle)
+  {
+    return;
+  }
   if(!mStreamBasePos)
   {
-    mStreamBasePos = static_cast<SparklesSource*>(&mEmitter.GetSource().GetSourceCallback())->mStreamBasePos;
+    mStreamBasePos = static_cast<SparklesSource*>(&handle.GetSource().GetSourceCallback())->mStreamBasePos;
   }
   if(!mStreamBaseAngle)
   {
-    mStreamBaseAngle = static_cast<SparklesSource*>(&mEmitter.GetSource().GetSourceCallback())->mStreamBaseAngle;
+    mStreamBaseAngle = static_cast<SparklesSource*>(&handle.GetSource().GetSourceCallback())->mStreamBaseAngle;
   }
 
   // Missing stream, return!
@@ -77,7 +82,7 @@ void SparklesModifier::Update(ParticleList& particleList, uint32_t first, uint32
     auto angle = particle.GetByIndex<float>(mStreamBaseAngle);
     auto                   radians  = ((angle * M_PI)/180.f);
     float                  lifetime = particle.Get<float>(ParticleStream::LIFETIME_STREAM_BIT);
-    position.y += velocity.y *sin(radians);
+    position.y += velocity.y * sin(radians);
     position.x += velocity.x * cos(radians);
 
     velocity *= 0.990f;
index 1c64bd63cad6cd64f5a472ea4bad7a9ef8c23947..25627aba4ec00602b2e17cfa374709899575eb21 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali-toolkit/public-api/particle-system/particle-list.h>
 #include <dali-toolkit/public-api/particle-system/particle.h>
 #include <dali/public-api/common/vector-wrapper.h>
+#include <dali/public-api/object/weak-handle.h>
 #include <ctime>
 
 namespace Dali::ParticleEffect
@@ -41,7 +42,7 @@ public:
 
   void Update(ParticleList& particleList, uint32_t first, uint32_t count) override;
 
-  ParticleEmitter mEmitter;
+  Dali::WeakHandle<ParticleEmitter> mEmitter;
   uint32_t mStreamBasePos{0u};
   uint32_t mStreamBaseAngle{0u};
   uint32_t mAngle{0u};
index 56eb29870a1e94fe7099777aa1b87b525dbd3228..c75fde2c7c46dd81bbc32bd89c33806771b2b9ec 100644 (file)
@@ -39,12 +39,22 @@ mEmitter(emitter)
 
 void SparklesSource::Init()
 {
-  mStreamBasePos = mEmitter.GetParticleList().AddLocalStream<Vector3>(Vector3::ZERO);
-  mStreamBaseAngle = mEmitter.GetParticleList().AddLocalStream<float>(0.0f);
+  auto handle = mEmitter.GetHandle();
+  if(!handle)
+  {
+    return;
+  }
+  mStreamBasePos = handle.GetParticleList().AddLocalStream<Vector3>(Vector3::ZERO);
+  mStreamBaseAngle = handle.GetParticleList().AddLocalStream<float>(0.0f);
 }
 
 uint32_t SparklesSource::Update(ParticleList& particleList, uint32_t count)
 {
+  if(!mStreamBasePos || !mStreamBaseAngle)
+  {
+    return 0u;
+  }
+
   while(count--)
   {
     auto particle = particleList.NewParticle(LIFETIME);
index 466c49b9a4b55b344ee0977b21029a87f5799d6f..bc9e8eca820583134117f998418974f4fa391824 100644 (file)
@@ -23,6 +23,8 @@
 #include <dali-toolkit/public-api/particle-system/particle-modifier.h>
 #include <dali-toolkit/public-api/particle-system/particle-list.h>
 #include <dali-toolkit/public-api/particle-system/particle.h>
+#include <dali/public-api/object/weak-handle.h>
+
 #include <ctime>
 
 namespace Dali::ParticleEffect
@@ -43,7 +45,7 @@ public:
 
   void UpdateParticle(Vector3& position, Vector3& basePosition, Vector4& color, Vector3& velocity, Vector3& scale, float& angle);
 
-  ParticleEmitter mEmitter;
+  Dali::WeakHandle<ParticleEmitter> mEmitter;
 
   Dali::Vector2 mRadius;