What happens when r_maxparticles is reached?

Discuss anything ZDoom-related that doesn't fall into one of the other categories.

What happens when r_maxparticles is reached?

Postby Matt » Wed Jun 08, 2022 6:51 pm

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
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: What happens when r_maxparticles is reached?

Postby Player701 » Wed Jun 08, 2022 11:42 pm

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 allExpand view
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
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: What happens when r_maxparticles is reached?

Postby Enjay » Thu Jun 09, 2022 10:05 am

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
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: What happens when r_maxparticles is reached?

Postby Caligari87 » Thu Jun 09, 2022 10:18 am

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
Caligari87
User Accounts Assistant
 
Joined: 26 Feb 2004
Discord: Caligari87#3089
Github ID: caligari87

Re: What happens when r_maxparticles is reached?

Postby 22alpha22 » Thu Jun 09, 2022 6:07 pm

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
22alpha22
So lonely...
 
Joined: 21 Feb 2014
Location: Montana, USA
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia with Vulkan support

Re: What happens when r_maxparticles is reached?

Postby Matt » Sat Jun 11, 2022 2:17 pm

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.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia


Return to General

Who is online

Users browsing this forum: No registered users and 4 guests