Page 1 of 1

What happens when r_maxparticles is reached?

Posted: Wed Jun 08, 2022 6:51 pm
by Matt
Are any new particles just prevented from appearing until there's more room, or are old particles destroyed to make room?

If it's the latter that would give me a lot more freedom to use particles for visual effects that the player needs to know about, rather than just a purely decorative optional bonus.

Re: What happens when r_maxparticles is reached?

Posted: Wed Jun 08, 2022 11:42 pm
by Player701
Particles are not spawned dynamically but are allocated once for the entire lifetime of a level. The engine tracks the lists of both "active" (i.e. existing) and "inactive" particles, using the latter as a "reserve" to take from when a new particle is to be spawned. If there are no "inactive" particles available, a new particle is not spawned. Ergo, if r_maxparticles is reached, new particles won't appear until some previous ones despawn and go "inactive". This is also confirmed experimentally:

Code: Select all

class TestInv : Inventory
{
    override bool Use(bool pickup)
    {
        if (Owner != null)
        {
            for (int i = 0; i < 100; i++)
            {
                Owner.A_SpawnParticle(
                    Color(Random(0, 255), Random(0, 255), Random(0, 255)),
                    SPF_FULLBRIGHT,
                    GameTicRate * 10,
                    FRandom(4.5, 5.5),
                    0,
                    FRandom(-10, 10), FRandom(-10, 10), FRandom(-10, 10) + Owner.Height / 2);
            }
        }

        return false;
    }
}
Set r_maxparticles to 100, then type give testinv, then use testinv. Do not wait, move around slightly and use testinv again. New particles won't appear if the old ones are still visible.

Re: What happens when r_maxparticles is reached?

Posted: Thu Jun 09, 2022 10:05 am
by Enjay
It's actually quite easy to check with the standard features. Enable a feature that spawns particles (I recommend using particles with bullet puffs for this), type "freeze" at the console so that once they have been generated particles never disappear, then do whatever will generate the particles repeatedly until you notice no more appearing.

e.g. with the bullet puff example, fire the super shotgun at a wall several times. By the seventh shot, there will probably be fewer particles appear and the eighth will probably not show any particles at all.

Re: What happens when r_maxparticles is reached?

Posted: Thu Jun 09, 2022 10:18 am
by Caligari87
I've always felt that the behavior of not spawning new particles was quite backwards. To me, despawning old particles would make more sense and I wish this was optional behavior (along with other niceties such as textured particles or the ability to modify existing particles)

To help combat this in some of my own projects, I often set up particle emitters with a system that only spawns particles for a single tic but preserves their motion and other details in an array for the next tic, so they can be manipulated more consistently and given more complex queue behavior. It's probably slower than letting GZDoom handle it for me, but it's a lot more convenient and flexible.

8-)

Re: What happens when r_maxparticles is reached?

Posted: Thu Jun 09, 2022 6:07 pm
by 22alpha22
Caligari87 wrote:I've always felt that the behavior of not spawning new particles was quite backwards. To me, despawning old particles would make more sense and I wish this was optional behavior (along with other niceties such as textured particles or the ability to modify existing particles)
I imagine the reason the particle spawning works the way it does is because some effects need it to work properly. Take a railgun for instance, the particles all seem to spawn at once but actually spawn starting closest to the firer and then toward the impact location. If you freeze the game and shoot a railgun shot or two at an exceptionally long distance, you'll find the particles stop well before they reach the impact point because the particle limit was reached.

In an unfrozen game this likely wouldn't be noticeable but if new particles instead despawned old ones, then you could end up in situations where your railgun trace starts much further down the line because the new particles instantly despawned the particles that would have appeared at the firing location. I hope that makes sense.

Re: What happens when r_maxparticles is reached?

Posted: Sat Jun 11, 2022 2:17 pm
by Matt
Cali's reply was really what I'd originally wanted to type but I wasn't entirely sure if that was actually what was happening.

My issue with this is that the ultra-far railgun not having particles on the shooter end is much rarer (and arguably less UI-breaking for the shooter) than shooting one rail that has a visible effect, then shooting a second one that does not.

In PvP this would also hurt the target player disproportionately since the railgun's balance would presumably be built around there being an instantly visible indicator of where the shot came from.