UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_particle.cpp File Reference

Client particle parsing and rendering functions. More...

#include "../client.h"
#include "cl_particle.h"
#include "cl_localentity.h"
#include "cl_hud.h"
#include "../renderer/r_light.h"
#include "../renderer/r_particle.h"
#include "../../shared/parse.h"
Include dependency graph for cl_particle.cpp:

Go to the source code of this file.

Data Structures

struct  mapParticle_t
 map particles More...
struct  timedParticle_t
struct  ptlTraceCache_t

Macros

#define MAX_MAPPARTICLES   1024
#define MAX_TIMEDPARTICLES   16
#define PTL_INTENSITY_TO_RADIUS   256 /** @todo better scale factor: is 256 too big or not? */
#define V_VECS   ((1 << V_FLOAT) | (1 << V_POS) | (1 << V_VECTOR) | (1 << V_COLOR))
#define PTL_ONLY_ONE_TYPE   (1<<31)
#define V_UNTYPED   0x7FFF
#define MAX_PTLDEFS   256
#define MAX_PTLCMDS   (MAX_PTLDEFS * 32)
#define MAX_PCMD_DATA   (MAX_PTLCMDS * 8)
#define MAX_STACK_DEPTH   8
#define MAX_STACK_DATA   512

Enumerations

enum  pf_t {
  PF_INIT , PF_RUN , PF_THINK , PF_ROUND ,
  PF_PHYSICS , PF_NUM_PTLFUNCS
}
 particle functions enums - see pf_strings and pf_values More...
enum  pc_t {
  PC_END , PC_PUSH , PC_POP , PC_KPOP ,
  PC_ADD , PC_SUB , PC_MUL , PC_DIV ,
  PC_SIN , PC_COS , PC_TAN , PC_RAND ,
  PC_CRAND , PC_V2 , PC_V3 , PC_V4 ,
  PC_KILL , PC_SPAWN , PC_NSPAWN , PC_TNSPAWN ,
  PC_CHILD , PC_NUM_PTLCMDS
}
 particle commands - see pc_strings More...

Functions

 CASSERT (lengthof(pf_strings)==PF_NUM_PTLFUNCS)
 CASSERT (lengthof(pf_values)==PF_NUM_PTLFUNCS)
 CASSERT (lengthof(pc_strings)==PC_NUM_PTLCMDS)
 CASSERT (lengthof(pc_types)==PC_NUM_PTLCMDS)
static void CL_ParticleSpawnTimed (const char *name, ptl_t *parent, bool children, int deltaTime, int n)
 Will spawn a n particles deltaTime ms after the parent was spawned.
void CL_AddMapParticle (const char *ptl, const vec3_t origin, const vec2_t wait, const char *info, int levelflags)
 Spawns the map particle.
static void CL_ParticleLoadArt (ptlArt_t *a)
 Loads the image or model for a given particle art.
void CL_ParticleRegisterArt (void)
static ptlArt_tCL_ParticleGetArt (const char *name, int frame, artType_t type)
 Register art (pics, models) for each particle.
static voidCL_ParticleCommandGetDataLocation (ptl_t *p, const ptlCmd_t *cmd)
 Determine the memory location where the command accesses and stores its data.
static void CL_ParticleFunction (ptl_t *p, ptlCmd_t *cmd)
ptlDef_tCL_ParticleGet (const char *name)
ptl_tCL_ParticleSpawn (const char *name, int levelFlags, const vec3_t s, const vec3_t v, const vec3_t a)
 Spawn a new particle to the map.
void CL_ParticleFree (ptl_t *p)
 Free a particle and all it's children.
static void CL_Fading (vec4_t color, fade_t fade, float frac, bool onlyAlpha)
 Color fade function.
void CL_ParticleCheckRounds (void)
 checks whether a particle is still active in the current round
static trace_t PTL_Trace (ptl_t *ptl, const AABB &aabb)
 Particle tracing with caching.
static void CL_ParticleRun2 (ptl_t *p)
 Prepares the particle rendering, calculate new position, velocity and all the other particle values that are needed to display it.
static void CL_ParticleRunTimed (void)
 Called every frame and checks whether a timed particle should be spawned.
static void CL_ParseMapParticle (ptl_t *ptl, const char *es, bool afterwards)
 Parses particle used on maps.
static void CL_RunMapParticles (void)
void CL_ParticleRun (void)
 General system for particle running during the game.
static void CL_ParsePtlCmds (const char *name, const char **text)
void CL_ParseParticle (const char *name, const char **text)
 Parses particle definitions from UFO-script files.
void PTL_InitStartup (void)
 Clears particle data.

Variables

static cvar_tcl_particleweather
static mapParticle_t mapParticles [MAX_MAPPARTICLES]
static timedParticle_t timedParticles [MAX_TIMEDPARTICLES]
static ptlArt_t r_particlesArt [MAX_PTL_ART]
static int r_numParticlesArt
static char const *const pf_strings []
 valid particle functions - see pf_t and pf_values
static const size_t pf_values []
 particle functions offsets - see pf_strings and pf_t
static char const *const pc_strings []
 particle commands - see pc_t
static const unsigned int pc_types [PC_NUM_PTLCMDS]
 particle commands parameter and types
static const value_t pps []
 particle script values
static ptlDef_t ptlDef [MAX_PTLDEFS]
static ptlCmd_t ptlCmd [MAX_PTLCMDS]
static int numPtlDefs
static int numPtlCmds
static byte pcmdData [MAX_PCMD_DATA]
static bytepcmdPos = pcmdData
static const int RSTACK = -(MAX_PCMD_DATA)
static byte cmdStack [MAX_STACK_DATA]
static voidstackPtr [MAX_STACK_DEPTH]
static byte stackType [MAX_STACK_DEPTH]

Detailed Description

Client particle parsing and rendering functions.

Definition in file cl_particle.cpp.

Macro Definition Documentation

◆ MAX_MAPPARTICLES

#define MAX_MAPPARTICLES   1024

Definition at line 34 of file cl_particle.cpp.

Referenced by CL_AddMapParticle().

◆ MAX_PCMD_DATA

#define MAX_PCMD_DATA   (MAX_PTLCMDS * 8)

Definition at line 219 of file cl_particle.cpp.

◆ MAX_PTLCMDS

#define MAX_PTLCMDS   (MAX_PTLDEFS * 32)

Definition at line 211 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds().

◆ MAX_PTLDEFS

#define MAX_PTLDEFS   256

Definition at line 210 of file cl_particle.cpp.

Referenced by CL_ParseParticle().

◆ MAX_STACK_DATA

#define MAX_STACK_DATA   512

Definition at line 228 of file cl_particle.cpp.

◆ MAX_STACK_DEPTH

#define MAX_STACK_DEPTH   8

Definition at line 227 of file cl_particle.cpp.

Referenced by CL_ParticleFunction().

◆ MAX_TIMEDPARTICLES

#define MAX_TIMEDPARTICLES   16

Definition at line 35 of file cl_particle.cpp.

◆ PTL_INTENSITY_TO_RADIUS

#define PTL_INTENSITY_TO_RADIUS   256 /** @todo better scale factor: is 256 too big or not? */

Definition at line 37 of file cl_particle.cpp.

Referenced by CL_ParticleRun2().

◆ PTL_ONLY_ONE_TYPE

#define PTL_ONLY_ONE_TYPE   (1<<31)

Definition at line 73 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds().

◆ V_UNTYPED

#define V_UNTYPED   0x7FFF

Definition at line 74 of file cl_particle.cpp.

◆ V_VECS

#define V_VECS   ((1 << V_FLOAT) | (1 << V_POS) | (1 << V_VECTOR) | (1 << V_COLOR))

Definition at line 72 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds(), and CL_ParticleFunction().

Enumeration Type Documentation

◆ pc_t

enum pc_t

particle commands - see pc_strings

Enumerator
PC_END 
PC_PUSH 
PC_POP 
PC_KPOP 
PC_ADD 
PC_SUB 
PC_MUL 
PC_DIV 
PC_SIN 
PC_COS 
PC_TAN 
PC_RAND 
PC_CRAND 
PC_V2 
PC_V3 
PC_V4 
PC_KILL 
PC_SPAWN 
PC_NSPAWN 
PC_TNSPAWN 
PC_CHILD 
PC_NUM_PTLCMDS 

Definition at line 108 of file cl_particle.cpp.

◆ pf_t

enum pf_t

particle functions enums - see pf_strings and pf_values

Enumerator
PF_INIT 
PF_RUN 
PF_THINK 
PF_ROUND 
PF_PHYSICS 

if a particle hits the ground

PF_NUM_PTLFUNCS 

Definition at line 77 of file cl_particle.cpp.

Function Documentation

◆ CASSERT() [1/4]

References PC_NUM_PTLCMDS, and pc_strings.

◆ CASSERT() [2/4]

References PC_NUM_PTLCMDS, and pc_types.

◆ CASSERT() [3/4]

◆ CASSERT() [4/4]

References PF_NUM_PTLFUNCS, and pf_values.

◆ CL_AddMapParticle()

void CL_AddMapParticle ( const char * ptl,
const vec3_t origin,
const vec2_t wait,
const char * info,
int levelflags )

Spawns the map particle.

Parameters
[in]ptlParticle name
[in]originThe position in the world
[in]wait
[in]info
[in]levelflagsThe levelflag mask to show the particle on

Definition at line 276 of file cl_particle.cpp.

References cl, Com_DPrintf(), Com_Printf(), DEBUG_CLIENT, frand(), mapParticle_t::info, mapParticle_t::levelflags, mapParticles, MAX_MAPPARTICLES, mapParticle_t::nextTime, mapParticle_t::origin, mapParticle_t::ptl, Q_strncpyz(), VectorCopy, and mapParticle_t::wait.

Referenced by SP_misc_particle().

◆ CL_Fading()

void CL_Fading ( vec4_t color,
fade_t fade,
float frac,
bool onlyAlpha )
static

Color fade function.

Parameters
[in,out]colorThe color vector to fade.
[in]fadeThe type of the fade.
[in]fracThe fraction to fade the color with.
[in]onlyAlphaOnly fade the alpha channel of the given RGBA color.

Definition at line 792 of file cl_particle.cpp.

References FADE_IN, FADE_LAST, FADE_NONE, FADE_OUT, FADE_SAW, FADE_SIN, i, and M_PI.

Referenced by CL_ParticleRun2().

◆ CL_ParseMapParticle()

void CL_ParseMapParticle ( ptl_t * ptl,
const char * es,
bool afterwards )
static

Parses particle used on maps.

Parameters
[in,out]ptlPointer to particle being parsed and updated.
[in]esEntity string to parse the particle from
[in]afterwardsIf this is true you can modify the particle after the init function for the particle was already called

Definition at line 1062 of file cl_particle.cpp.

References ART_MODEL, ART_PIC, CL_ParticleGetArt(), Com_EParseValue(), Com_Error(), Com_Parse(), ERR_DROP, ptl_t::frame, key, MAX_VAR, ptl_t::model, value_t::ofs, ptl_t::pic, pps, ptl_t::program, Q_streq, Q_strncpyz(), R_InitParticleProgram(), R_LoadProgram(), R_UseParticleProgram(), value_t::size, value_t::string, value_t::type, and r_program_t::userdata.

Referenced by CL_RunMapParticles().

◆ CL_ParseParticle()

void CL_ParseParticle ( const char * name,
const char ** text )

Parses particle definitions from UFO-script files.

Parameters
[in]nameparticle name/id
[in]textpointer to the buffer to parse from
Returns
the position of the particle in ptlDef array
See also
CL_ParseClientData

Definition at line 1355 of file cl_particle.cpp.

References CL_ParsePtlCmds(), Com_EParse(), Com_Parse(), Com_Printf(), i, ptlDef_t::init, MAX_PTLDEFS, name, ptlDef_t::name, numPtlCmds, numPtlDefs, OBJZERO, PF_NUM_PTLFUNCS, pf_strings, pf_values, ptlCmd, ptlDef, Q_streq, and Q_strncpyz().

Referenced by CL_ParseClientData().

◆ CL_ParsePtlCmds()

◆ CL_ParticleCheckRounds()

void CL_ParticleCheckRounds ( void )

checks whether a particle is still active in the current round

Note
also calls the round function of each particle (if defined)
See also
CL_ParticleFunction

Definition at line 827 of file cl_particle.cpp.

References CL_ParticleFree(), CL_ParticleFunction(), ptl_t::ctrl, i, ptl_t::inuse, r_numParticles, r_particleArray, ptlDef_t::round, ptl_t::rounds, and ptl_t::roundsCnt.

Referenced by CL_DoEndRound().

◆ CL_ParticleCommandGetDataLocation()

void * CL_ParticleCommandGetDataLocation ( ptl_t * p,
const ptlCmd_t * cmd )
inlinestatic

Determine the memory location where the command accesses and stores its data.

Parameters
pThe particle that is used to get local command data locations.
cmdThe command to get the data location for.
Returns
The position where the command stores the data.

Definition at line 377 of file cl_particle.cpp.

References pcmdData, and ptlCmd_t::ref.

Referenced by CL_ParticleFunction().

◆ CL_ParticleFree()

void CL_ParticleFree ( ptl_t * p)

Free a particle and all it's children.

Parameters
[in]pthe particle to free
See also
CL_ParticleSpawn

Definition at line 776 of file cl_particle.cpp.

References ptl_t::children, CL_ParticleFree(), ptl_t::inuse, and ptl_t::invis.

Referenced by CL_ActorDie(), CL_ActorRevitalised(), CL_EntPerish(), CL_ParticleCheckRounds(), CL_ParticleFree(), CL_ParticleFunction(), CL_ParticleRun2(), and LET_Projectile().

◆ CL_ParticleFunction()

◆ CL_ParticleGet()

ptlDef_t * CL_ParticleGet ( const char * name)

Definition at line 678 of file cl_particle.cpp.

References i, name, ptlDef_t::name, numPtlDefs, ptlDef, Q_streq, and Q_strnull().

Referenced by CL_ParticleSpawn(), TEST_CheckParticle(), and TEST_F().

◆ CL_ParticleGetArt()

ptlArt_t * CL_ParticleGetArt ( const char * name,
int frame,
artType_t type )
static

Register art (pics, models) for each particle.

Note
searches the global particle art list and checks whether the pic or model was already loaded
Returns
index of global art array have their names at the beginning of their structs

Definition at line 339 of file cl_particle.cpp.

References ptlArt_t::art, ART_PIC, CL_ParticleLoadArt(), Com_Error(), ERR_DROP, ptlArt_t::frame, i, ptlArt_t::image, MAX_PTL_ART, name, ptlArt_t::name, Q_streq, Q_strncpyz(), r_numParticlesArt, r_particlesArt, ptlArt_t::skin, ptlArt_t::type, and type.

Referenced by CL_ParseMapParticle(), CL_ParticleFunction(), and CL_ParticleRun2().

◆ CL_ParticleLoadArt()

void CL_ParticleLoadArt ( ptlArt_t * a)
inlinestatic

Loads the image or model for a given particle art.

Todo
Support the frame data from ptlArt_t for models, too

Definition at line 298 of file cl_particle.cpp.

References ptlArt_t::art, ART_MODEL, ART_PIC, Com_Error(), Com_Printf(), ERR_DROP, ptlArt_t::frame, ptlArt_t::image, ptlArt_t::model, ptlArt_t::name, R_FindModel(), R_FindPics(), ptlArt_t::type, and va().

Referenced by CL_ParticleGetArt(), and CL_ParticleRegisterArt().

◆ CL_ParticleRegisterArt()

void CL_ParticleRegisterArt ( void )

Definition at line 324 of file cl_particle.cpp.

References CL_ParticleLoadArt(), i, r_numParticlesArt, and r_particlesArt.

Referenced by CL_ViewLoadMedia().

◆ CL_ParticleRun()

void CL_ParticleRun ( void )

General system for particle running during the game.

See also
CL_Frame

Definition at line 1148 of file cl_particle.cpp.

References CL_ParticleRun2(), CL_ParticleRunTimed(), CL_RunMapParticles(), i, ptl_t::inuse, r_numParticles, and r_particleArray.

Referenced by CL_Frame(), and TEST_F().

◆ CL_ParticleRun2()

◆ CL_ParticleRunTimed()

◆ CL_ParticleSpawn()

◆ CL_ParticleSpawnTimed()

void CL_ParticleSpawnTimed ( const char * name,
ptl_t * parent,
bool children,
int deltaTime,
int n )
static

Will spawn a n particles deltaTime ms after the parent was spawned.

Parameters
[in]nameThe id of the particle (see ptl_*.ufo script files in base/ufos)
[in]parentThe parent particle
[in]childrenSpawn as children
[in]deltaTimeThe time to wait until this particle should get spawned
[in]nThe amount of particles to spawn (each after deltaTime of its predecessor)

Definition at line 242 of file cl_particle.cpp.

References timedParticle_t::children, Com_Error(), Com_Printf(), timedParticle_t::dt, ERR_DROP, i, length, lengthof, ptl_t::levelFlags, timedParticle_t::levelFlags, timedParticle_t::max, timedParticle_t::n, name, timedParticle_t::parent, timedParticle_t::ptl, Q_strncpyz(), and timedParticles.

Referenced by CL_ParticleFunction().

◆ CL_RunMapParticles()

◆ PTL_InitStartup()

◆ PTL_Trace()

Variable Documentation

◆ cl_particleweather

cvar_t* cl_particleweather
static

Definition at line 39 of file cl_particle.cpp.

Referenced by CL_ParticleRun2(), and PTL_InitStartup().

◆ cmdStack

byte cmdStack[MAX_STACK_DATA]
static

Definition at line 230 of file cl_particle.cpp.

Referenced by CL_ParticleFunction().

◆ mapParticles

mapParticle_t mapParticles[MAX_MAPPARTICLES]
static

Definition at line 66 of file cl_particle.cpp.

Referenced by CL_AddMapParticle(), and CL_RunMapParticles().

◆ numPtlCmds

int numPtlCmds
static

Definition at line 217 of file cl_particle.cpp.

Referenced by CL_ParseParticle(), CL_ParsePtlCmds(), and PTL_InitStartup().

◆ numPtlDefs

int numPtlDefs
static

Definition at line 216 of file cl_particle.cpp.

Referenced by CL_ParseParticle(), CL_ParticleGet(), and PTL_InitStartup().

◆ pc_strings

char const* const pc_strings[]
static
Initial value:
= {
"end",
"push", "pop", "kpop",
"add", "sub",
"mul", "div",
"sin", "cos", "tan",
"rand", "crand",
"v2", "v3", "v4",
"kill",
"spawn", "nspawn", "tnspawn", "child"
}

particle commands - see pc_t

Definition at line 125 of file cl_particle.cpp.

Referenced by CASSERT(), and CL_ParsePtlCmds().

◆ pc_types

const unsigned int pc_types[PC_NUM_PTLCMDS]
static
Initial value:

particle commands parameter and types

Definition at line 141 of file cl_particle.cpp.

Referenced by CASSERT(), and CL_ParsePtlCmds().

◆ pcmdData

byte pcmdData[MAX_PCMD_DATA]
static
Todo
check pcmdData overflow

Definition at line 222 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds(), and CL_ParticleCommandGetDataLocation().

◆ pcmdPos

byte* pcmdPos = pcmdData
static

Definition at line 223 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds().

◆ pf_strings

char const* const pf_strings[]
static
Initial value:
= {
"init",
"run",
"think",
"round",
"physics"
}

valid particle functions - see pf_t and pf_values

Definition at line 88 of file cl_particle.cpp.

Referenced by CASSERT(), and CL_ParseParticle().

◆ pf_values

const size_t pf_values[]
static
Initial value:
= {
offsetof(ptlDef_t, init),
offsetof(ptlDef_t, run),
offsetof(ptlDef_t, think),
offsetof(ptlDef_t, round),
offsetof(ptlDef_t, physics)
}

particle functions offsets - see pf_strings and pf_t

Definition at line 98 of file cl_particle.cpp.

Referenced by CASSERT(), and CL_ParseParticle().

◆ pps

const value_t pps[]
static

particle script values

Note
image, model and program are special values - see CL_ParticleFunction

Definition at line 160 of file cl_particle.cpp.

Referenced by CL_ParseMapParticle(), and CL_ParsePtlCmds().

◆ ptlCmd

ptlCmd_t ptlCmd[MAX_PTLCMDS]
static

Definition at line 214 of file cl_particle.cpp.

Referenced by CL_ParseParticle(), CL_ParsePtlCmds(), and PTL_InitStartup().

◆ ptlDef

ptlDef_t ptlDef[MAX_PTLDEFS]
static

Definition at line 213 of file cl_particle.cpp.

Referenced by CL_ParseParticle(), CL_ParticleGet(), and PTL_InitStartup().

◆ r_numParticlesArt

int r_numParticlesArt
static

Definition at line 70 of file cl_particle.cpp.

Referenced by CL_ParticleGetArt(), CL_ParticleRegisterArt(), and PTL_InitStartup().

◆ r_particlesArt

ptlArt_t r_particlesArt[MAX_PTL_ART]
static

Definition at line 69 of file cl_particle.cpp.

Referenced by CL_ParticleGetArt(), CL_ParticleRegisterArt(), and PTL_InitStartup().

◆ RSTACK

const int RSTACK = -(MAX_PCMD_DATA)
static

Definition at line 225 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds(), and CL_ParticleFunction().

◆ stackPtr

void* stackPtr[MAX_STACK_DEPTH]
static

Definition at line 231 of file cl_particle.cpp.

Referenced by CL_ParticleFunction().

◆ stackType

byte stackType[MAX_STACK_DEPTH]
static

Definition at line 232 of file cl_particle.cpp.

Referenced by CL_ParticleFunction().

◆ timedParticles

timedParticle_t timedParticles[MAX_TIMEDPARTICLES]
static

Definition at line 67 of file cl_particle.cpp.

Referenced by CL_ParticleRunTimed(), and CL_ParticleSpawnTimed().