]> git.xonotic.org Git - xonotic/darkplaces.git/blob - cl_particles.h
physics: fix and refactor unsticking
[xonotic/darkplaces.git] / cl_particles.h
1 #ifndef CL_PARTICLES_H
2 #define CL_PARTICLES_H
3
4 #include "qtypes.h"
5 struct entity_s;
6
7 extern struct cvar_s cl_particles;
8 extern struct cvar_s cl_particles_quality;
9 extern struct cvar_s cl_particles_size;
10 extern struct cvar_s cl_particles_quake;
11 extern struct cvar_s cl_particles_blood;
12 extern struct cvar_s cl_particles_blood_alpha;
13 extern struct cvar_s cl_particles_blood_decal_alpha;
14 extern struct cvar_s cl_particles_blood_decal_scalemin;
15 extern struct cvar_s cl_particles_blood_decal_scalemax;
16 extern struct cvar_s cl_particles_blood_bloodhack;
17 extern struct cvar_s cl_particles_bulletimpacts;
18 extern struct cvar_s cl_particles_explosions_sparks;
19 extern struct cvar_s cl_particles_explosions_shell;
20 extern struct cvar_s cl_particles_rain;
21 extern struct cvar_s cl_particles_snow;
22 extern struct cvar_s cl_particles_smoke;
23 extern struct cvar_s cl_particles_smoke_alpha;
24 extern struct cvar_s cl_particles_smoke_alphafade;
25 extern struct cvar_s cl_particles_sparks;
26 extern struct cvar_s cl_particles_bubbles;
27 extern struct cvar_s cl_decals;
28 extern struct cvar_s cl_decals_time;
29 extern struct cvar_s cl_decals_fadetime;
30
31 typedef enum
32 {
33         PARTICLE_BILLBOARD = 0,
34         PARTICLE_SPARK = 1,
35         PARTICLE_ORIENTED_DOUBLESIDED = 2,
36         PARTICLE_VBEAM = 3,
37         PARTICLE_HBEAM = 4,
38         PARTICLE_INVALID = -1
39 }
40 porientation_t;
41
42 typedef enum
43 {
44         PBLEND_ALPHA = 0,
45         PBLEND_ADD = 1,
46         PBLEND_INVMOD = 2,
47         PBLEND_INVALID = -1
48 }
49 pblend_t;
50
51 typedef struct particletype_s
52 {
53         pblend_t blendmode;
54         porientation_t orientation;
55         qbool lighting;
56 }
57 particletype_t;
58
59 typedef enum ptype_e
60 {
61         pt_dead,
62         pt_alphastatic,
63         pt_static,
64         pt_spark,
65         pt_beam,
66         pt_rain,
67         pt_raindecal,
68         pt_snow,
69         pt_bubble,
70         pt_blood,
71         pt_smoke,
72         pt_decal,
73         pt_entityparticle,
74         pt_explode,   // used for Quake-style explosion particle colour ramping
75         pt_explode2,  // used for Quake-style explosion particle colour ramping
76         pt_total
77 }
78 ptype_t;
79
80 typedef struct particle_s
81 {
82         // for faster batch rendering, particles are rendered in groups by effect (resulting in less perfect sorting but far less state changes)
83
84         // fields used by rendering: (48 bytes)
85         vec3_t          sortorigin; // sort by this group origin, not particle org
86         vec3_t          org;
87         vec3_t          vel; // velocity of particle, or orientation of decal, or end point of beam
88         float           size;
89         float           alpha; // 0-255
90         float           stretch; // only for sparks
91
92         // fields not used by rendering:  (44 bytes)
93         float           stainsize;
94         float           stainalpha;
95         float           sizeincrease; // rate of size change per second
96         float           alphafade; // how much alpha reduces per second
97         float           time2; // used for snow fluttering and decal fade
98         float           bounce; // how much bounce-back from a surface the particle hits (0 = no physics, 1 = stop and slide, 2 = keep bouncing forever, 1.5 is typical)
99         float           gravity; // how much gravity affects this particle (1.0 = normal gravity, 0.0 = none)
100         float           airfriction; // how much air friction affects this object (objects with a low mass/size ratio tend to get more air friction)
101         float           liquidfriction; // how much liquid friction affects this object (objects with a low mass/size ratio tend to get more liquid friction)
102 //      float           delayedcollisions; // time that p->bounce becomes active
103         float           delayedspawn; // time that particle appears and begins moving
104         float           die; // time when this particle should be removed, regardless of alpha
105
106         // short variables grouped to save memory (4 bytes)
107         short                   angle; // base rotation of particle
108         short                   spin; // geometry rotation speed around the particle center normal
109
110         // byte variables grouped to save memory (12 bytes)
111         unsigned char   color[3];
112         unsigned char   qualityreduction; // enables skipping of this particle according to r_refdef.view.qualityreduction
113         unsigned char   typeindex;
114         unsigned char   blendmode;
115         unsigned char   orientation;
116         unsigned char   texnum;
117         unsigned char   staincolor[3];
118         signed char     staintexnum;
119 }
120 particle_t;
121
122 void CL_Particles_Clear(void);
123 void CL_Particles_Init(void);
124 void CL_Particles_Shutdown(void);
125 particle_t *CL_NewParticle(const vec3_t sortorigin, unsigned short ptypeindex, int pcolor1, int pcolor2, int ptex, float psize, float psizeincrease, float palpha, float palphafade, float pgravity, float pbounce, float px, float py, float pz, float pvx, float pvy, float pvz, float pairfriction, float pliquidfriction, float originjitter, float velocityjitter, qbool pqualityreduction, float lifetime, float stretch, pblend_t blendmode, porientation_t orientation, int staincolor1, int staincolor2, int staintex, float stainalpha, float stainsize, float angle, float spin, float tint[4]);
126 particle_t *CL_NewQuakeParticle(const vec3_t origin, const int color_1, const int color_2, const float gravity, const float offset_x, const float offset_y, const float offset_z, const float velocity_offset_x, const float velocity_offset_y, const float velocity_offset_z, const float air_friction, const float liquid_friction, const float origin_jitter, const float velocity_jitter, const float lifetime);
127
128 typedef enum effectnameindex_s
129 {
130         EFFECT_NONE,
131         EFFECT_TE_GUNSHOT,
132         EFFECT_TE_GUNSHOTQUAD,
133         EFFECT_TE_SPIKE,
134         EFFECT_TE_SPIKEQUAD,
135         EFFECT_TE_SUPERSPIKE,
136         EFFECT_TE_SUPERSPIKEQUAD,
137         EFFECT_TE_WIZSPIKE,
138         EFFECT_TE_KNIGHTSPIKE,
139         EFFECT_TE_EXPLOSION,
140         EFFECT_TE_EXPLOSIONQUAD,
141         EFFECT_TE_TAREXPLOSION,
142         EFFECT_TE_TELEPORT,
143         EFFECT_TE_LAVASPLASH,
144         EFFECT_TE_SMALLFLASH,
145         EFFECT_TE_FLAMEJET,
146         EFFECT_EF_FLAME,
147         EFFECT_TE_BLOOD,
148         EFFECT_TE_SPARK,
149         EFFECT_TE_PLASMABURN,
150         EFFECT_TE_TEI_G3,
151         EFFECT_TE_TEI_SMOKE,
152         EFFECT_TE_TEI_BIGEXPLOSION,
153         EFFECT_TE_TEI_PLASMAHIT,
154         EFFECT_EF_STARDUST,
155         EFFECT_TR_ROCKET,
156         EFFECT_TR_GRENADE,
157         EFFECT_TR_BLOOD,
158         EFFECT_TR_WIZSPIKE,
159         EFFECT_TR_SLIGHTBLOOD,
160         EFFECT_TR_KNIGHTSPIKE,
161         EFFECT_TR_VORESPIKE,
162         EFFECT_TR_NEHAHRASMOKE,
163         EFFECT_TR_NEXUIZPLASMA,
164         EFFECT_TR_GLOWTRAIL,
165         EFFECT_SVC_PARTICLE,
166         EFFECT_TOTAL
167 }
168 effectnameindex_t;
169
170 int CL_ParticleEffectIndexForName(const char *name);
171 const char *CL_ParticleEffectNameForIndex(int i);
172 void CL_ParticleEffect(int effectindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, struct entity_s *ent, int palettecolor);
173 void CL_ParticleTrail(int effectindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, struct entity_s *ent, int palettecolor, qbool spawndlight, qbool spawnparticles, float tintmins[4], float tintmaxs[4], float fade);
174 void CL_ParticleBox(int effectindex, float pcount, const vec3_t originmins, const vec3_t originmaxs, const vec3_t velocitymins, const vec3_t velocitymaxs, struct entity_s *ent, int palettecolor, qbool spawndlight, qbool spawnparticles, float tintmins[4], float tintmaxs[4], float fade);
175 void CL_ParseParticleEffect (void);
176 void CL_ParticleCube (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, vec_t gravity, vec_t randomvel);
177 void CL_ParticleRain (const vec3_t mins, const vec3_t maxs, const vec3_t dir, int count, int colorbase, int type);
178 void CL_EntityParticles (const struct entity_s *ent);
179 void CL_ParticleExplosion (const vec3_t org);
180 void CL_ParticleExplosion2 (const vec3_t org, int colorStart, int colorLength);
181
182 #endif