Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: ParticlesSystem efficient  (Read 1024 times)

0 Members and 1 Guest are viewing this topic.

Tojmak

  • Newbie
  • *
  • Posts: 4
    • View Profile
ParticlesSystem efficient
« on: April 12, 2020, 12:11:57 pm »
Hello!
I'm working on particle system that have some predefined features like creating a force wave to push particles floating on the screen. It causes change of direction, speed, etc. The problem is that with every force wave i have to iterate through every particle on the screen if it is in range of force wave. Because of that i have some huge fps drops.  Do you have some optimization idea? I really want to have a lot particles on the screen ;d.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: ParticlesSystem efficient
« Reply #1 on: April 13, 2020, 11:34:44 pm »
Performance issues are usually dealt with by 1) profiling the issue, 2) identifying the bottlenecks and 3) thinking of solutions to optimize the bottleneck. So without you doing step 1 and 2 first, we can't really help with step 3. ;)

A general rendering optimization (probably not your issue), use a vertex array to reduce draw calls.
A general math optimization, don't calculate the new velocity for each particle, but you could apply the same velocity for each particle that has the same or similar enough distance.

Iterating objects is not really expensive, so it's really important to figure out what operation is taking the longest. Maybe you have some unintended copying of a large amount of objects, causing tons of allocations/deallactions, or maybe you just use some too realistic math and a simpler model would work just as well.

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/