Particle System Performance

Situation

I created a particle system with JavaFX using the following technique:

Each particle is an ImageView that contains an image with a radial gradient:

enter image description here

The particle processing loop is an AnimationTimer in which the particle list is processed using the list stream () method. parallel (), it actually gives a boost to the whole system. Something like that:

loop = new AnimationTimer() {

    @Override
    public void handle(long now) {

        addParticle();

        // apply force: gravity
        allParticles.stream().parallel().forEach(Particle::applyForceGravity);

        // move particle
        allParticles.stream().parallel().forEach(Particle::move);

        // update position in fx scene
        allParticles.forEach(Particle::display);

        // remove all particles that aren't visible anymore
        removeDeadParticles();

    }
};

Particle color changes through ColorAdjust during its life cycle. I used the colors of fire for testing, something like this, which contains 1700 particles:

enter image description here

What I learned:

  • Not using parallel () function slower
  • Using Circle with transparency is slower than using ImageView
  • Using blend mode is very slow
  • PixelWriter . : ColorAdjust ( d3d )? JavaFX.

JavaFX ( Node, Thread ..) ?

, - .

!


: , , , . , coloradjust, .

, , .

+4
2

, . , - , , , , , :

JavaFX ImageView 10x. , :

  • , .. .

- , . " Zip" zip "application" JavaFX . Particle.java. , , node .

"", , ..

3 25400 Full-HD, 60 :

enter image description here

+4

, :

// apply force: gravity
allParticles.stream().parallel().forEach(Particle::applyForceGravity);

// move particle
allParticles.stream().parallel().forEach(Particle::move);

:

allParticles.stream().parallel().forEach(particle -> {
  particle.applyForceGravity();
  particle.move();
});

, .

0

Source: https://habr.com/ru/post/1599538/


All Articles