Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
particles.c File Reference

Implements the particle system for visual effects. More...

#include <particles.h>
#include <app.h>
#include <time_system.h>
#include <timer.h>
#include <random.h>

Functions

ParticleEmitter * ParticleEmitter_CreateFromPreset (ParticleEmitter preset)
 [Start] Creates a particle emitter from a preset
 
void ParticleEmitter_Update (ParticleEmitter *emitter)
 [PostUpdate] Controls the particle emitter's particle emission, age, and rendering
 
void ParticleEmitter_Render (ParticleEmitter *emitter)
 [Render] Renders every particle of a particle emitter
 
void ParticleEmitter_Emit (ParticleEmitter *emitter)
 [Utility] Emits a single particle and set its properties based on the emitter
 
void ParticleEmitter_UpdateParticles (ParticleEmitter *emitter)
 [Utility] Update the state, movement, color and size of every particles of a particle emitter
 
void ParticleEmitter_SetMaxParticles (ParticleEmitter *emitter, int maxParticles)
 [Utility] Set the max particles property of an emitter
 
int ParticleEmitter_GetNextReady (ParticleEmitter *emitter)
 [Utility] Gets the index of the next available particle inside an emitter's particle array
 
void ParticleEmitter_DestroyEmitter (ParticleEmitter *emitter)
 [Utility/Quit] Destroys a particle emitter
 
bool ParticleEmitter_ParticlesAlive (ParticleEmitter *emitter)
 [Utility] Check if there are any alive particles inside an emitter's particle array
 
void ParticleEmitter_ActivateOnce (ParticleEmitter *emitter)
 [Utility] Allows a particle emitter to go through another loop
 
void ParticleEmitter_Deactivate (ParticleEmitter *emitter)
 [Utility] Deactivates a particle emitter
 

Detailed Description

Implements the particle system for visual effects.

This file contains the implementation of a particle emitter system that can be used to create various visual effects like explosions, muzzle flashes, smoke, etc.

Author
Mango
Date
2025-03-07

Function Documentation

◆ ParticleEmitter_ActivateOnce()

void ParticleEmitter_ActivateOnce ( ParticleEmitter *  emitter)

[Utility] Allows a particle emitter to go through another loop

Activates the emitter once.

Reactivates a particle emitter that was inactive, setting up its state for another emission cycle.

Parameters
emitterA pointer to the particle emitter

◆ ParticleEmitter_CreateFromPreset()

ParticleEmitter * ParticleEmitter_CreateFromPreset ( ParticleEmitter  preset)

[Start] Creates a particle emitter from a preset

Creates a new particle emitter from a preset.

Initializes a new particle emitter based on a preset configuration, allocating memory for the emitter and its particles.

Parameters
presetThe preset to create the emitter from. This is found inside particle_emitterpresets.h
Returns
A pointer to the created emitter, or NULL if allocation fails

◆ ParticleEmitter_Deactivate()

void ParticleEmitter_Deactivate ( ParticleEmitter *  emitter)

[Utility] Deactivates a particle emitter

Deactivates the emitter.

Stops a particle emitter from emitting new particles, though existing particles will continue to update and render.

Parameters
emitterA pointer to the particle emitter

◆ ParticleEmitter_DestroyEmitter()

void ParticleEmitter_DestroyEmitter ( ParticleEmitter *  emitter)

[Utility/Quit] Destroys a particle emitter

Destroys the emitter and frees its memory.

Frees all resources associated with a particle emitter, including particle array and timer.

Parameters
emitterA pointer to the particle emitter

◆ ParticleEmitter_Emit()

void ParticleEmitter_Emit ( ParticleEmitter *  emitter)

[Utility] Emits a single particle and set its properties based on the emitter

Emits particles from the emitter.

Creates a new particle with initial properties derived from the emitter settings plus appropriate randomization.

Parameters
emitterA pointer to the particle emitter

◆ ParticleEmitter_GetNextReady()

int ParticleEmitter_GetNextReady ( ParticleEmitter *  emitter)

[Utility] Gets the index of the next available particle inside an emitter's particle array

Gets the next available particle index.

Particle is available of it's dead, basically. Searches through the particle array to find the first particle that is not alive.

Parameters
emitterA pointer to the particle emitter
Returns
The index of the next available particle, or maxParticles if none available

◆ ParticleEmitter_ParticlesAlive()

bool ParticleEmitter_ParticlesAlive ( ParticleEmitter *  emitter)

[Utility] Check if there are any alive particles inside an emitter's particle array

Checks if the emitter has any particles alive.

Scans through all particles in the emitter to determine if any are still active.

Parameters
emitterA pointer to the particle emitter
Returns
true if any particles are alive, false otherwise

◆ ParticleEmitter_Render()

void ParticleEmitter_Render ( ParticleEmitter *  emitter)

[Render] Renders every particle of a particle emitter

Renders the particles of an emitter.

Draws all active particles with their current color, size, and position.

Parameters
emitterA pointer to the particle emitter

◆ ParticleEmitter_SetMaxParticles()

void ParticleEmitter_SetMaxParticles ( ParticleEmitter *  emitter,
int  maxParticles 
)

[Utility] Set the max particles property of an emitter

Sets the maximum number of particles for an emitter.

This is probably never going to be used, since this is already set inside particle_emitterpreset. Only use this if (for some reason) you want to change a particle emitter's max particles in the middle of a game

Parameters
emitterA pointer to the particle emitter
maxParticlesThe target max particle number

◆ ParticleEmitter_Update()

void ParticleEmitter_Update ( ParticleEmitter *  emitter)

[PostUpdate] Controls the particle emitter's particle emission, age, and rendering

Updates the emitter.

Updates all aspects of a particle emitter including emission of new particles, updating existing particles, and handling emitter lifecycle events.

Parameters
emitterA pointer to the particle emitter

◆ ParticleEmitter_UpdateParticles()

void ParticleEmitter_UpdateParticles ( ParticleEmitter *  emitter)

[Utility] Update the state, movement, color and size of every particles of a particle emitter

Updates the particles of an emitter.

Processes all active particles, updating their position, color, size, and rotation based on their current state and lifecycle.

Parameters
emitterA pointer to the particle emitter