What happens when r_maxparticles is reached?

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
Post Reply
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

What happens when r_maxparticles is reached?

Post 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.
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: What happens when r_maxparticles is reached?

Post 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.
User avatar
Enjay
 
 
Posts: 26534
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: What happens when r_maxparticles is reached?

Post 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.
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: What happens when r_maxparticles is reached?

Post 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-)
User avatar
22alpha22
Posts: 303
Joined: Fri Feb 21, 2014 5:04 pm
Graphics Processor: nVidia with Vulkan support
Location: Montana, USA

Re: What happens when r_maxparticles is reached?

Post 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.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: What happens when r_maxparticles is reached?

Post 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.
Post Reply

Return to “General”