Skip to content

04_ Systems

Matias Poggini edited this page Oct 6, 2023 · 1 revision

What are Systems

Systems are the "containers" of particles. Particles exist within the coordinate space of a system, and are updated and drawn by them. Systems also have a depth or a layer where they will render. Systems are also they way GM refers to the particle system asset, fo the particle effects created with the visual editor.

Creating Systems in Pulse

Like particles, systems be created while creating an emitter, just by writing a name as a string

emitter = new pulse_local_emitter("system","particle")

Or you can leave it empty to generate a system named with the default name as in the config file.

You can also create a system by using

system = pulse_make_system("system_name")

All of these options are analogous and create a system struct in Pulse's global variable global.pulse. To access a particle created with a string only, you can use global.pulse.part_systems.particle_name or emitter.part_system

Cloning Systems

In the same way as particles, you can clone a previously existing Pulse system by using

pulse_clone_system(__name,__new_name=__name)

Note that if you don't provide a new name, the system will be named as the one being cloned + "_copy". If you do this more than once with the same system, it will have some unintended behaviour (either overwrite or something else).

This, however, is arguably less useful than in the case of particles (at least for now) as there are less properties and less opportunities to create them dynamically.

Memory management: Particle thresholds and particle amount factor

You might find that you want to dynamically tweak the amount of created particles for performance purposes. GM doesn't have a way of doing this, but Pulse does! The factor variable present inside a system will change how many particles are created. If a system.factor = 0.5 , and you emitter.pulse(1000,x,y), only 500 particles will be emitted.

You can give an automatic threshold of particle amount to a system by changing:

system.threshold = 150

This will make that, if particles are ever above this threshold, it will tune down the system's factor by the difference between the threshold and the particles currently in the system. It will check after a determinate amount of steps and adjust if necessary.

There is also a global factor called global.pulse.particle_factor which will affect all systems throughout.

Destroying Systems

To destroy a system simply use

pulse_destroy_system("particle_name") or pulse_destroy_all() if you want to completely clear Pulse.

Destroying a system will remove it from the global.pulse struct and it will destroy the index system itself. It's recommended that you do this when you no longer need a specific system. Systems have an impact on memory even when completely empty, and with automatic update and draw disabled. If for whatever reason you need to juggle a bunch of systems simultaneously, Pulse gives the option of sleeping your system instead of destroying it.

Sleeping and Awakening Systems

In Pulse, systems can be removed from GM's pipeline without destroying the connections made with Pulse or losing the chosen properties. We call that "sleeping" and it can be triggered automatically by giving it a threshold and then setting:

system.sleep_when_empty = true

This won't trigger without a threshold.

You can set a system to wake up automatically when an emitter requires it by setting:

system.wake_on_emit = true

Finally, you can do this manually by using the functions system.make_asleep() system.make_awake()

Supersampling

This is an idea on how to do delta time while using GM's native particle system rendering. You can activate by setting :

set_super_sampling(_active, _samples)

This will update the system several times each step (as many times as you indicate in _samples), which you can later