FS2_Open
Open source remastering of the Freespace 2 engine
particle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _PARTICLE_H
13 #define _PARTICLE_H
14 
15 #include "globalincs/pstypes.h"
16 
17 //#define MAX_PARTICLES 2000 // Reduced from 2000 to 800 by MK on 4/1/98. Most I ever saw was 400 and the system recovers
18  // gracefully from running out of slots.
19  // AP: Put it to 1500 on 4/15/98. Primary hit sparks weren't finding open slots.
20  // Made todo item for John to force oldest smoke particles to give up their slots.
21  // 06/05/24 - taylor - made it dynamic
22 
23 //============================================================================
24 //==================== PARTICLE SYSTEM GAME SEQUENCING CODE ==================
25 //============================================================================
26 
27 // Resets particle system. Call between levels.
28 void particle_init();
29 
30 // called at game exit to cleanup any used resources
31 void particle_close();
32 
33 // Moves the particles for each frame
34 void particle_move_all(float frametime);
35 
36 // Renders all the particles
37 void particle_render_all();
38 
39 // kill all active particles
40 void particle_kill_all();
41 
42 
43 //============================================================================
44 //=============== LOW-LEVEL SINGLE PARTICLE CREATION CODE ====================
45 //============================================================================
46 
47 // The different types of particles...
48 #define PARTICLE_DEBUG 0 // A red sphere, no optional data required
49 #define PARTICLE_BITMAP 1 // A bitmap, optional data is the bitmap number. If bitmap is an animation,
50  // lifetime is calculated by the number of frames and fps.
51 #define PARTICLE_FIRE 2 // The vclip used for explosions, optional means nothing
52 #define PARTICLE_SMOKE 3 // The vclip used for smoke, optional means nothing
53 #define PARTICLE_SMOKE2 4 // The vclip used for smoke, optional means nothing
54 #define PARTICLE_BITMAP_PERSISTENT 5 // A bitmap, optional data is the bitmap number. If bitmap is an animation,
55  // lifetime is calculated by the number of frames and fps.
56 
57 #define NUM_PARTICLE_TYPES 6
58 
59 // particle creation stuff
60 typedef struct particle_info {
61  // old-style particle info
64  float lifetime;
65  float rad;
66  int type;
68 
69  // new-style particle info
71  int attached_objnum; // if these are set, the pos is relative to the pos of the origin of the attached object
72  int attached_sig; // to make sure the object hasn't changed or died. velocity is ignored in this case
73  ubyte reverse; // play any animations in reverse
75 
76 typedef struct particle {
77  // old style data
78  vec3d pos; // position
79  vec3d velocity; // velocity
80  float age; // How long it's been alive
81  float max_life; // How much life we had
82  float radius; // radius
83  int type; // type // -1 = None
84  int optional_data; // depends on type
85  int nframes; // If an ani, how many frames?
86 
87  // new style data
88  float tracer_length; // if this is set, draw as a rod to simulate a "tracer" effect
89  int attached_objnum; // if this is set, pos is relative to the attached object. velocity is ignored
90  int attached_sig; // to check for dead/nonexistent objects
91  ubyte reverse; // play any animations in reverse
92  int particle_index; // used to keep particle offset in dynamic array for orient usage
93 
95 } particle;
96 
97 // Creates a single particle. See the PARTICLE_?? defines for types.
99 particle *particle_create( vec3d *pos, vec3d *vel, float lifetime, float rad, int type, int optional_data = -1, float tracer_length=-1.0f, class object *objp=NULL, bool reverse=false );
100 
101 //============================================================================
102 //============== HIGH-LEVEL PARTICLE SYSTEM CREATION CODE ====================
103 //============================================================================
104 
105 // Use a structure rather than pass a ton of parameters to particle_emit
106 typedef struct particle_emitter {
107  int num_low; // Lowest number of particles to create
108  int num_high; // Highest number of particles to create
109  vec3d pos; // Where the particles emit from
110  vec3d vel; // Initial velocity of all the particles
111  float min_life; // How long the particles live
112  float max_life; // How long the particles live
113  vec3d normal; // What normal the particle emit arond
114  float normal_variance; // How close they stick to that normal 0=good, 1=360 degree
115  float min_vel; // How fast the slowest particle can move
116  float max_vel; // How fast the fastest particle can move
117  float min_rad; // Min radius
118  float max_rad; // Max radius
120 
121 // Creates a bunch of particles. You pass a structure
122 // rather than a bunch of parameters.
123 void particle_emit( particle_emitter *pe, int type, int optional_data, float range=1.0 );
124 
125 #endif // _PARTICLE_H
126 
int attached_objnum
Definition: particle.h:89
float tracer_length
Definition: particle.h:88
int optional_data
Definition: particle.h:84
void particle_init()
Definition: particle.cpp:47
float max_life
Definition: particle.h:81
struct particle_emitter particle_emitter
float age
Definition: particle.h:80
Definition: pstypes.h:88
ubyte reverse
Definition: particle.h:91
int type
Definition: particle.h:83
GLclampf f
Definition: Glext.h:7097
vec3d pos
Definition: particle.h:78
object * objp
Definition: lua.cpp:3105
GLenum type
Definition: Gl.h:1492
void particle_close()
Definition: particle.cpp:83
int optional_data
Definition: particle.h:67
GLenum GLint * range
Definition: Glext.h:7096
int nframes
Definition: particle.h:85
unsigned int uint
Definition: pstypes.h:64
vec3d vel
Definition: particle.h:63
struct particle_info particle_info
vec3d pos
Definition: particle.h:62
unsigned char ubyte
Definition: pstypes.h:62
float tracer_length
Definition: particle.h:70
struct particle particle
int attached_sig
Definition: particle.h:72
void particle_move_all(float frametime)
Definition: particle.cpp:239
float lifetime
Definition: particle.h:64
int particle_index
Definition: particle.h:92
float normal_variance
Definition: particle.h:114
void particle_kill_all()
Definition: particle.cpp:304
hull_check pos
Definition: lua.cpp:5050
float radius
Definition: particle.h:82
vec3d velocity
Definition: particle.h:79
int attached_sig
Definition: particle.h:90
float rad
Definition: particle.h:65
uint signature
Definition: particle.h:94
ubyte reverse
Definition: particle.h:73
int attached_objnum
Definition: particle.h:71
particle * particle_create(particle_info *pinfo)
Definition: particle.cpp:105
void particle_emit(particle_emitter *pe, int type, int optional_data, float range=1.0)
Definition: particle.cpp:495
void particle_render_all()
Definition: particle.cpp:346