Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Issue with Cancelling a Transition
Started by Caleb P Jan 03 2014 11:11 AM

- - - - -
10 replies to this topic
transition.cancel transition cancel

Best Answer Brent Sorrentino , 07 January 2014 - 02:43 PM

Hi Caleb,

I understand your usage case now. Can't you still tag all transitions related to the vent and then cancel them (by tag) on "vent clear/cleanup" instead of looping through them manually in your own code?

 

@NerijusApps,

1500 particles seems like an extreme amount of particles, and I would be concerned about performance on any device, using that amount of particles.

 

Sincerely,

Brent

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Starter
  • PipPipPipPipPipPip
  • 1,006 posts
  • Jedi

In my rewrite of CBEffects, I've come across a very odd issue. The way particles' "lifetimes" are dealt with is by transitions (transition.to, to be specific) for the alpha. After a transition is finished, the next is started within the original one's onComplete function. Then, at the end of the final transition, a kill function is called (deletes the particle, removes stored references, etc) and everything's fine.
 
My problem? When I delete more than one particle at a time (through a loop), something is taking far too long to execute when the particle is killed. I've isolated the problem down to transition.cancel. When I comment out the line that cancels any remaining transition, multiple particle deletion finishes at a normal speed. But un-comment it? Almost a second and a half to delete 120 particles (which may seem like a lot, but without the line, you can't even see a flicker in the application speed).
 
I won't post the whole library (for obvious reasons), but here is a simplified version of the only relevant areas. The variable "p" refers to the particle; transition_cancel and transition_to are both localized forms of transition functions.


function p._kill()
-- This is the offending line
    if p._cbe_reserved.transition then transition_cancel(p._cbe_reserved.transition) end -- _cbe_reserved is a cache that holds reserved properties
    display_remove(p)

--------------------------------------------------------------------------
-- Set Up Particle Transition
--------------------------------------------------------------------------
p._cbe_reserved.transition = transition_to(p, {
    alpha = p.lifeAlpha,
    time = vent.inTime,
    onComplete = function()
p._cbe_reserved.transition = transition_to(p, {
     alpha = vent.endAlpha,
         delay = vent.lifeTime,
         time = vent.outTime, -- Time before particle is killed
         onComplete = p._kill -- Call the _kill function at the end
        })
    end -- onComplete
})


Why is this happening? Can it be fixed, or is it simply a quirk of the new transition API?

- C



[TOPIC: post.html]
#2

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,441 posts
  • Jedi

Hi Caleb,

Just as a brief thought, have you considered using tags on transitions (to "name" them) instead of looping through a big table of 100+ particles? I'm not sure if that would fit within your design structure, but just something to consider if you haven't already.

 

Brent



[TOPIC: post.html]
#3

NerijusApps

[GLOBAL: userInfoPane.html]
NerijusApps
  • Pro
  • Pip
  • 5 posts
  • Newbie

hello

 

i have the same problem in many forms. each time it seems it has something to do with transition.cancel when you try it to do many times in a loop like it was said before. i have the same problem in CBEffects and in my own code where i am using it.

anyone know the solution ?



[TOPIC: post.html]
#4

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,441 posts
  • Jedi

Hi @NerijusApps,

As I suggested above, could you please try naming (tagging) your transitions and canceling them via the tag method, instead of writing your own loop? I'd like to see if this improves performance at all, based on your test case(s).

 

Thanks,

Brent



[TOPIC: post.html]
#5

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Starter
  • PipPipPipPipPipPip
  • 1,006 posts
  • Jedi

Unfortunately, tagging my transitions isn't really an option because particles have to be "dying" at different times, so unless I tag them with their index or something, I'd be canceling ones I wouldn't want to. Tagging them with their group index isn't an option, either, because their group index could potentially change.

 

- C



[TOPIC: post.html]
#6

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,441 posts
  • Jedi

Hi Caleb,

I'm a bit confused… if particles are "dying" at different times, how is the loop as large as 120 of them dying at once? Is it common to have 120 of them dying at the same time? If so, are there like thousands of particles on the screen at once?

 

Best regards,

Brent



[TOPIC: post.html]
#7

NerijusApps

[GLOBAL: userInfoPane.html]
NerijusApps
  • Pro
  • Pip
  • 5 posts
  • Newbie

hello,

it seems i found the solution. at firts i thought
the tag is not an option but later on i found the way of using them.
again my situation is similar to  Caleb.

i have like 800-
1500 particles on screen an they must die at proper moment. as kill the
one by one requires too much resourses i fire every 0.1 sec a function
which kills all particles which are already obsolete. all the
transitions is assigned to table which is cleaned when time comes.

So
i decided use as tag simple index. (like 1,2,3 ...). and then kill a
group of particles with simple "for i to j " As i always know which
group is already obsolete (to be more clear i know which last transition
with index is obsolete)

 

As now i should also fix
CBEffects as they are used in my project i already know this solutions
is not exactly what Caleb needs but maybe a variant of it may be used?

Also i notised that this solution is a lot slower than an good old transition clean using the table. At least for me.



[TOPIC: post.html]
#8

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Starter
  • PipPipPipPipPipPip
  • 1,006 posts
  • Jedi

By default, particles "die" one by one (another reason tags wouldn't work so well), but when the vent is destroyed or cleaned of particles, all particles currently existent must needs be destroyed.

 

- C



[TOPIC: post.html]
#9

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,441 posts
  • Jedi

  Best Answer

Hi Caleb,

I understand your usage case now. Can't you still tag all transitions related to the vent and then cancel them (by tag) on "vent clear/cleanup" instead of looping through them manually in your own code?

 

@NerijusApps,

1500 particles seems like an extreme amount of particles, and I would be concerned about performance on any device, using that amount of particles.

 

Sincerely,

Brent



[TOPIC: post.html]
#10

NerijusApps

[GLOBAL: userInfoPane.html]
NerijusApps
  • Pro
  • Pip
  • 5 posts
  • Newbie

ok i fixed what was slowing me down in CBEffects also.

the only thing which really had an impact seemed the cleanup function which cleans everything when i am quiting the scene. So instead (deleteall) so instead of using original cleaning with "for i to j" i just used transition.cancel() without argument. the iteration was left only for object cleaning. after few testing it seems work ok no memory leaks no crashes.

changing algorythm in which particles is killed in the ongoing efect when they become obsolete didnt show for me any improvements. So i did not bothered playing with them more.



[TOPIC: post.html]
#11

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Starter
  • PipPipPipPipPipPip
  • 1,006 posts
  • Jedi

Ok, when I implemented tagging the transitions (with randomly generated unique IDs), it works perfectly.

Thanks for all the help :)

- C


[topic_controls]
[/topic_controls]



Also tagged with one or more of these keywords: transition.cancel, transition, cancel