Particles optimization

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

Particles optimization

Post by Mateus » Thu Feb 18, 2016 6:38 am

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 !

bobbyjones
Party member
Posts: 712
Joined: Sat Apr 26, 2014 7:46 pm

Re: Particles optimization

Post by bobbyjones » Thu Feb 18, 2016 6:47 am

You can use a particle system or mesh or spritebatches. Each has their own advantages and disadvantages. I would try particle system first.
Check out my most recent medium post, please give feedback.
Link

Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

Re: Particles optimization

Post by Mateus » Thu Feb 18, 2016 6:49 am

Isn't there any kind of canvas so I can use my own pSystem ?

User avatar
ivan
Party member
Posts: 1455
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Particles optimization

Post by ivan » Thu Feb 18, 2016 7:13 am

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.

Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

Re: Particles optimization

Post by Mateus » Thu Feb 18, 2016 5:46 pm

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.

User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

Re: Particles optimization

Post by Evine » Thu Feb 18, 2016 6:58 pm

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)

bobbyjones
Party member
Posts: 712
Joined: Sat Apr 26, 2014 7:46 pm

Re: Particles optimization

Post by bobbyjones » Thu Feb 18, 2016 7:47 pm

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.
Check out my most recent medium post, please give feedback.
Link

Mateus
Prole
Posts: 42
Joined: Sat Apr 04, 2015 1:02 pm

Re: Particles optimization

Post by Mateus » Fri Feb 19, 2016 2:37 pm

My bad guys. @ivan was right. Lua seems like it can't handle FOR very well.

User avatar
ivan
Party member
Posts: 1455
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Particles optimization

Post by ivan » Fri Feb 19, 2016 3:03 pm

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.

User avatar
zorg
Party member
Posts: 2620
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Particles optimization

Post by zorg » Fri Feb 19, 2016 3:26 pm

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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Post Reply

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], JJSax and 8 guests