zz85 / sparks.js

a lightweight 3d particle engine in javascript, compatible with THREE.js and TWEEN.js
435 stars 47 forks source link

Performance Degradation #19

Closed renegademaster88 closed 12 years ago

renegademaster88 commented 12 years ago

Hello again, i have been putting together a simple fire works demo: http://www.nickfallon.net/3D/Fireworks.html

That continuosly fires fireworks, by adding and deleting them from an array. Unfortunately the performance degrades over time. I have checked my array is deleting and deleted the objects from the THREE scene, but to no avail. When deleting SPARS do i need to do anything specific other than automatic garbage collection?

I look at the SPARKS.Engine global, but actually my emitters don't seem to be added to it...

thanx

zz85 commented 12 years ago

@renegademaster88 looking nice.

my guess is this - there are too many running emitter systems running without be freed. in http://www.nickfallon.net/3D/Firework.js you are calling this.tail.emitter().start(); - this causes the emitter to run in its own loop.

instead, you might like to try something like this

var engine = new SPARKS.Engine();
engine.start();

engine.add(emitter);

you might however need to figure a way to remove the emitter from the engine once the all the particles are fired. right now this is not automatic.

renegademaster88 commented 12 years ago

Great i will give it a go, thanx for the advice. I'll add a removeEmitter() function to engine then push it to my Branch. I now have quite allot of Initializers and Actions - i think i will break them into Canvas2D, WebGL, and independent in the next push.

zz85 commented 12 years ago

cool :) you can check out the latest in my m2 branch. its has a remove for emitters.

https://github.com/zz85/sparks.js/commit/182651c632a173a4af7f6e3f0c0fb8062edfca85#src/core/Engine.js

renegademaster88 commented 12 years ago

I got the Fireworks demo above to work perfectly thanks to your tip ( http://www.nickfallon.net/3D/Fireworks.html ) I also managed to get rid of the particle flickering issue i had https://github.com/jeromeetienne/sparkseditor/issues/9 I am going to start integrating SPARKS into my game engine now! thanx

zz85 commented 12 years ago

cool! :)