Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_particles.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
27#ifndef __N_PARTICLE_HEADER
28#define __N_PARTICLE_HEADER
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
39#include <allegro5/allegro.h>
40#include <allegro5/allegro_audio.h>
41#include <allegro5/allegro_acodec.h>
42#include <allegro5/allegro_font.h>
43#include <allegro5/allegro_image.h>
44#include <allegro5/allegro_primitives.h>
45
46#include "n_common.h"
47#include "n_log.h"
48#include "n_list.h"
49#include "n_3d.h"
50#include "n_time.h"
51
53#define NORMAL_PART 0
55#define SINUS_PART 1
57#define TRANS_PART 2
59#define SNOW_PART 3
61#define FIRE_PART 4
63#define STAR_PART 5
65#define CIRCLE_PART 6
67#define PIXEL_PART 7
69#define BITMAP_PART 8
71#define TEXT_PART 9
72
74typedef struct PARTICLE {
76 int mode,
83
85 ALLEGRO_COLOR color;
86
89
91 ALLEGRO_COLOR color_start;
93 ALLEGRO_COLOR color_end;
95 int age;
108
109} PARTICLE;
110
166
186
188int init_particle_system(PARTICLE_SYSTEM** psys, int max, double x, double y, double z, int max_sprites);
189
191int add_particle(PARTICLE_SYSTEM* psys, int spr, int mode, int lifetime, int size, ALLEGRO_COLOR color, PHYSICS object);
193int add_particle_ex(PARTICLE_SYSTEM* psys, int spr, int mode, int off_x, int off_y, int lifetime, int size, ALLEGRO_COLOR color, double vx, double vy, double vz, double ax, double ay, double az);
194
196int manage_particle_ex(PARTICLE_SYSTEM* psys, double delta_t);
197
200
202int draw_particle(PARTICLE_SYSTEM* psys, double xpos, double ypos, int w, int h, double range);
203
206
208int move_particles(PARTICLE_SYSTEM* psys, double vx, double vy, double vz);
209
216
218int add_particle_at(PARTICLE_SYSTEM* psys, int spr, int mode, double px, double py, double pz, int lifetime, int size_start, int size_end, ALLEGRO_COLOR color_start, ALLEGRO_COLOR color_end, double vx, double vy, double vz, double ax, double ay, double az);
219
224#ifdef __cplusplus
225}
226#endif
227
228#endif /* __N_PARTICLE_HEADER */
static int mode
Structure of a generic LIST container.
Definition n_list.h:58
Timing Structure.
Definition n_time.h:48
double shape_h
shape dimension 2: rect height (world units)
int size_start
particle size at birth
Definition n_particles.h:99
int particle_mode
particle draw mode (NORMAL_PART, CIRCLE_PART, PIXEL_PART, FIRE_PART, etc.)
N_TIME timer
Internal: particle system timer.
LIST * emitters
list of PARTICLE_EMITTER pointers
int size
current size of particle
Definition n_particles.h:82
int max_sprites
size of the picture library
VECTOR3D velocity_max
random velocity range max
ALLEGRO_COLOR color
color of the particle
Definition n_particles.h:85
ALLEGRO_COLOR color_end
end color for lerp
Definition n_particles.h:93
int additive
1=additive blend, 0=normal alpha
int depth_sort
1=depth-sorted with terrain, 0=flat overlay after iso pass
int active
1=emitting, 0=paused
PHYSICS object
particle physical properties
Definition n_particles.h:88
int spr_id
sprite id in library
Definition n_particles.h:80
int size_end
particle size at death
int lifetime
lifetime (counts down, msecs)
Definition n_particles.h:78
ALLEGRO_COLOR color_start
particle start color
ALLEGRO_COLOR color_end
particle end color (lerp over lifetime)
int shape
emission shape: 0=point, 1=line, 2=rect, 3=circle
VECTOR3D velocity_min
random velocity range min
int live_count
current live particle count for this emitter (managed by system)
VECTOR3D source
Coordinate of emitting point (used by add_particle/add_particle_ex)
double emit_accumulator
internal: fractional particle accumulator
VECTOR3D position
emitter world position
VECTOR3D offset
offset when attached to entity
int size_start
particle size at birth
LIST * list
list of PARTICLE pointers
int attached_entity_id
-1=not attached, >=0=entity id
int spr_id
sprite id or -1
struct PARTICLE_EMITTER * emitter
back-pointer to owning emitter (NULL if spawned manually)
int mode
particle mode: NORMAL_PART,SINUS_PART,PIXEL_PART
Definition n_particles.h:76
double emit_rate
particles per second (continuous mode)
int max_particles
per-emitter particle cap (0=unlimited)
ALLEGRO_BITMAP ** sprites
Library of picture for the particles.
int lifetime_min
particle lifetime range min (msecs)
int lifetime_max
original lifetime at birth (needed for lerp ratio = age/lifetime_max)
Definition n_particles.h:97
int size_end
particle size at death
double shape_rotation
shape rotation in radians
int depth_sort
1=depth-sorted with terrain, 0=flat overlay
double shape_w
shape dimension 1: line length, rect width, or circle radius (world units)
int lifetime_max
particle lifetime range max (msecs)
int burst_count
if >0, emit this many instantly then deactivate
ALLEGRO_COLOR color_start
start color for lerp (set by emitter, ignored if color_start == color_end)
Definition n_particles.h:91
VECTOR3D acceleration
constant acceleration (gravity etc.)
int additive_blend
1=additive blend, 0=normal alpha blend
int age
current age in msecs (incremented by manage_particle_ex)
Definition n_particles.h:95
int draw_particle(PARTICLE_SYSTEM *psys, double xpos, double ypos, int w, int h, double range)
draw particles on screen
int add_particle_at(PARTICLE_SYSTEM *psys, int spr, int mode, double px, double py, double pz, int lifetime, int size_start, int size_end, ALLEGRO_COLOR color_start, ALLEGRO_COLOR color_end, double vx, double vy, double vz, double ax, double ay, double az)
add a particle at an absolute world position (not relative to psys->source)
int move_particles(PARTICLE_SYSTEM *psys, double vx, double vy, double vz)
move all particles by a velocity offset
PARTICLE_EMITTER * add_emitter(PARTICLE_SYSTEM *psys)
add a new emitter to the particle system.
int free_emitters(PARTICLE_SYSTEM *psys)
free all emitters in the particle system
int manage_particle_ex(PARTICLE_SYSTEM *psys, double delta_t)
manage particles with custom delta time
int remove_emitter(PARTICLE_SYSTEM *psys, const PARTICLE_EMITTER *em)
remove an emitter from the particle system and free it
int free_particle_system(PARTICLE_SYSTEM **psys)
free a particle system
int manage_particle(PARTICLE_SYSTEM *psys)
manage particles using internal timer
int add_particle_ex(PARTICLE_SYSTEM *psys, int spr, int mode, int off_x, int off_y, int lifetime, int size, ALLEGRO_COLOR color, double vx, double vy, double vz, double ax, double ay, double az)
add a particle to the system (extended version)
int add_particle(PARTICLE_SYSTEM *psys, int spr, int mode, int lifetime, int size, ALLEGRO_COLOR color, PHYSICS object)
add a particle to the system
Definition n_particles.c:78
int init_particle_system(PARTICLE_SYSTEM **psys, int max, double x, double y, double z, int max_sprites)
initialize a particle system
Definition n_particles.c:40
Structure of a single particle.
Definition n_particles.h:74
Structure of a particle emitter.
Structure of a particle system.
double VECTOR3D[3]
struct of a point
Definition n_3d.h:58
structure of the physics of an object
Definition n_3d.h:69
Simple 3D movement simulation.
Common headers and low-level functions & define.
List structures and definitions.
Generic log system.
Timing utilities.