Page 1 of 2

Particles optimization

Posted: Thu Feb 18, 2016 6:38 am
by Mateus
Hey, simple question.

How do I optimize my program to be able to draw like 50000 particles without problem ? Is it even possible ?
(50000 love.graphics.circle)

Thanks !

Re: Particles optimization

Posted: Thu Feb 18, 2016 6:47 am
by bobbyjones
You can use a particle system or mesh or spritebatches. Each has their own advantages and disadvantages. I would try particle system first.

Re: Particles optimization

Posted: Thu Feb 18, 2016 6:49 am
by Mateus
Isn't there any kind of canvas so I can use my own pSystem ?

Re: Particles optimization

Posted: Thu Feb 18, 2016 7:13 am
by ivan
Apart from the drawing, if Lua code is used to move each individual particle then there are obvious CPU constraints.
Another option is to pre-render the effect and draw an animation using textures.

Re: Particles optimization

Posted: Thu Feb 18, 2016 5:46 pm
by Mateus
ivan wrote:Apart from the drawing, if Lua code is used to move each individual particle then there are obvious CPU constraints.
Another option is to pre-render the effect and draw an animation using textures.

Everything is fine until I try to draw them.

Re: Particles optimization

Posted: Thu Feb 18, 2016 6:58 pm
by Evine
You might be able to get away with just using love.graphics.points(). So look if that suits your needs. Otherwise look into spritebatches.

The process of spritebatches would go something like this.
-- Draw the various sizes of love.graphics.circle() you want to a canvas. love.graphics.newCanvas()
-- Split the different images on the canvas with love.graphics.newQuad() , (Not needed if you only do 1 size)
-- Create a Spritebatch with the texture. love.graphics.newSpriteBatch()
-- Position the particles with SpriteBatch:add().
-- Draw all particles with love.graphics.draw(Spritebatch)

Re: Particles optimization

Posted: Thu Feb 18, 2016 7:47 pm
by bobbyjones
Evine wrote:You might be able to get away with just using love.graphics.points(). So look if that suits your needs. Otherwise look into spritebatches.

The process of spritebatches would go something like this.
-- Draw the various sizes of love.graphics.circle() you want to a canvas. love.graphics.newCanvas()
-- Split the different images on the canvas with love.graphics.newQuad() , (Not needed if you only do 1 size)
-- Create a Spritebatch with the texture. love.graphics.newSpriteBatch()
-- Position the particles with SpriteBatch:add().
-- Draw all particles with love.graphics.draw(Spritebatch)

He could just use one white circle I believe. And just scale and color it.

Re: Particles optimization

Posted: Fri Feb 19, 2016 2:37 pm
by Mateus
My bad guys. @ivan was right. Lua seems like it can't handle FOR very well.

Re: Particles optimization

Posted: Fri Feb 19, 2016 3:03 pm
by ivan
Mateus, Lua and LuaJit are quite fast compared to most scripting languages.
Please post your love file and we'll see if it can be optimized.

Re: Particles optimization

Posted: Fri Feb 19, 2016 3:26 pm
by zorg
Mateus wrote:My bad guys. @ivan was right. Lua seems like it can't handle FOR very well.
Lua thanks you very much, and says it can indeed handle for loops as much as any programming language :3
All sillyness aside, modifying 50 000 objects every tick may be too much work, so if i may be so premature as to suggest that somehow cutting down the number would be the #1 solution to this issue, if that's a route you can take.
That said, if you post your code, then as ivan said, other alternatives may reveal themselves.