UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"

Go to the source code of this file.

Data Structures

struct  mapParticle_s
 map particles More...
 
struct  timedParticle_s
 
struct  ptlTraceCache_s
 

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
 

Typedefs

typedef struct mapParticle_s mapParticle_t
 map particles More...
 
typedef struct timedParticle_s timedParticle_t
 
typedef enum pf_s pf_t
 particle functions enums - see pf_strings and pf_values More...
 
typedef enum pc_s pc_t
 particle commands - see pc_strings More...
 
typedef struct ptlTraceCache_s ptlTraceCache_t
 

Enumerations

enum  pf_s {
  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_s {
  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. More...
 
void CL_AddMapParticle (const char *ptl, const vec3_t origin, const vec2_t wait, const char *info, int levelflags)
 Spawns the map particle. More...
 
static void CL_ParticleLoadArt (ptlArt_t *a)
 Loads the image or model for a given particle art. More...
 
void CL_ParticleRegisterArt (void)
 
static ptlArt_tCL_ParticleGetArt (const char *name, int frame, artType_t type)
 Register art (pics, models) for each particle. More...
 
static voidCL_ParticleCommandGetDataLocation (ptl_t *p, const ptlCmd_t *cmd)
 Determine the memory location where the command accesses and stores its data. More...
 
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. More...
 
void CL_ParticleFree (ptl_t *p)
 Free a particle and all it's children. More...
 
static void CL_Fading (vec4_t color, fade_t fade, float frac, bool onlyAlpha)
 Color fade function. More...
 
void CL_ParticleCheckRounds (void)
 checks whether a particle is still active in the current round More...
 
static trace_t PTL_Trace (ptl_t *ptl, const AABB &aabb)
 Particle tracing with caching. More...
 
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. More...
 
static void CL_ParticleRunTimed (void)
 Called every frame and checks whether a timed particle should be spawned. More...
 
static void CL_ParseMapParticle (ptl_t *ptl, const char *es, bool afterwards)
 Parses particle used on maps. More...
 
static void CL_RunMapParticles (void)
 
void CL_ParticleRun (void)
 General system for particle running during the game. More...
 
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. More...
 
void PTL_InitStartup (void)
 Clears particle data. More...
 

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 More...
 
static const size_t pf_values []
 particle functions offsets - see pf_strings and pf_t More...
 
static char const *const pc_strings []
 particle commands - see pc_t More...
 
static const unsigned int pc_types [PC_NUM_PTLCMDS]
 particle commands parameter and types More...
 
static const value_t pps []
 particle script values More...
 
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

#define MAX_MAPPARTICLES   1024

Definition at line 34 of file cl_particle.cpp.

Referenced by CL_AddMapParticle().

#define MAX_PCMD_DATA   (MAX_PTLCMDS * 8)

Definition at line 219 of file cl_particle.cpp.

#define MAX_PTLCMDS   (MAX_PTLDEFS * 32)

Definition at line 211 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds().

#define MAX_PTLDEFS   256

Definition at line 210 of file cl_particle.cpp.

Referenced by CL_ParseParticle().

#define MAX_STACK_DATA   512

Definition at line 228 of file cl_particle.cpp.

#define MAX_STACK_DEPTH   8

Definition at line 227 of file cl_particle.cpp.

Referenced by CL_ParticleFunction().

#define MAX_TIMEDPARTICLES   16

Definition at line 35 of file cl_particle.cpp.

#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().

#define PTL_ONLY_ONE_TYPE   (1<<31)

Definition at line 73 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds().

#define V_UNTYPED   0x7FFF

Definition at line 74 of file cl_particle.cpp.

#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().

Typedef Documentation

typedef struct mapParticle_s mapParticle_t

map particles

typedef enum pc_s pc_t

particle commands - see pc_strings

typedef enum pf_s pf_t

particle functions enums - see pf_strings and pf_values

Enumeration Type Documentation

enum pc_s

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.

enum pf_s

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 ( lengthof(pc_types = =PC_NUM_PTLCMDS)
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_s::info, mapParticle_s::levelflags, MAX_MAPPARTICLES, mapParticle_s::nextTime, clientBattleScape_s::numMapParticles, mapParticle_s::origin, mapParticle_s::ptl, Q_strncpyz(), clientBattleScape_s::time, VectorCopy, and mapParticle_s::wait.

Referenced by SP_misc_particle().

static 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().

static 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_s::frame, key, MAX_VAR, ptl_s::model, value_s::ofs, ptl_s::pic, ptl_s::program, Q_streq, Q_strncpyz(), R_InitParticleProgram(), R_LoadProgram(), R_UseParticleProgram(), value_s::size, value_s::string, value_s::type, and r_program_s::userdata.

Referenced by CL_RunMapParticles().

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_s::init, MAX_PTLDEFS, ptlDef_s::name, numPtlCmds, numPtlDefs, OBJZERO, PF_NUM_PTLFUNCS, pf_strings, Q_streq, and Q_strncpyz().

Referenced by CL_ParseClientData().

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_s::ctrl, i, ptl_s::inuse, r_numParticles, r_particleArray, ptlDef_s::round, ptl_s::rounds, and ptl_s::roundsCnt.

Referenced by CL_DoEndRound().

static 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 ptlCmd_s::ref.

Referenced by CL_ParticleFunction().

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_s::children, CL_ParticleFree(), ptl_s::inuse, ptl_s::invis, and ptl_s::next.

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

ptlDef_t* CL_ParticleGet ( const char *  name)

Definition at line 678 of file cl_particle.cpp.

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

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

static 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_s::art, ART_PIC, CL_ParticleLoadArt(), Com_Error(), ERR_DROP, ptlArt_s::frame, i, ptlArt_s::image, MAX_PTL_ART, ptlArt_s::name, Q_streq, Q_strncpyz(), r_numParticlesArt, ptlArt_s::skin, type, and ptlArt_s::type.

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

static 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_s::art, ART_MODEL, ART_PIC, Com_Error(), Com_Printf(), ERR_DROP, ptlArt_s::frame, ptlArt_s::image, ptlArt_s::model, ptlArt_s::name, R_FindModel(), R_FindPics(), ptlArt_s::type, and va().

Referenced by CL_ParticleGetArt(), and CL_ParticleRegisterArt().

void CL_ParticleRegisterArt ( void  )

Definition at line 324 of file cl_particle.cpp.

References CL_ParticleLoadArt(), i, and r_numParticlesArt.

Referenced by CL_ViewLoadMedia().

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_s::inuse, r_numParticles, and r_particleArray.

Referenced by CL_Frame(), and TEST_F().

static void CL_ParticleRun2 ( ptl_t p)
static
static 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_s::children, Com_Error(), Com_Printf(), timedParticle_s::dt, ERR_DROP, i, length, lengthof, timedParticle_s::levelFlags, ptl_s::levelFlags, timedParticle_s::max, timedParticle_s::n, timedParticle_s::parent, timedParticle_s::ptl, and Q_strncpyz().

Referenced by CL_ParticleFunction().

void PTL_InitStartup ( void  )

Clears particle data.

See also
CL_InitLocal

Definition at line 1475 of file cl_particle.cpp.

References cl_particleweather, Cmd_AddCommand(), CVAR_ARCHIVE, Cvar_Get(), OBJZERO, and r_numParticlesArt.

Referenced by CL_InitLocal(), ParticleTest::SetUpTestCase(), and TEST_Shutdown().

Variable Documentation

cvar_t* cl_particleweather
static

Definition at line 39 of file cl_particle.cpp.

Referenced by CL_ParticleRun2(), and PTL_InitStartup().

byte cmdStack[MAX_STACK_DATA]
static

Definition at line 230 of file cl_particle.cpp.

mapParticle_t mapParticles[MAX_MAPPARTICLES]
static

Definition at line 66 of file cl_particle.cpp.

int numPtlCmds
static

Definition at line 217 of file cl_particle.cpp.

Referenced by CL_ParseParticle().

int numPtlDefs
static

Definition at line 216 of file cl_particle.cpp.

Referenced by CL_ParseParticle(), and CL_ParticleGet().

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.

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.

byte pcmdData[MAX_PCMD_DATA]
static
Todo:
check pcmdData overflow

Definition at line 222 of file cl_particle.cpp.

byte* pcmdPos = pcmdData
static

Definition at line 223 of file cl_particle.cpp.

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 CL_ParseParticle().

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.

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.

ptlCmd_t ptlCmd[MAX_PTLCMDS]
static

Definition at line 214 of file cl_particle.cpp.

ptlDef_t ptlDef[MAX_PTLDEFS]
static

Definition at line 213 of file cl_particle.cpp.

int r_numParticlesArt
static

Definition at line 70 of file cl_particle.cpp.

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

ptlArt_t r_particlesArt[MAX_PTL_ART]
static

Definition at line 69 of file cl_particle.cpp.

const int RSTACK = -(MAX_PCMD_DATA)
static

Definition at line 225 of file cl_particle.cpp.

Referenced by CL_ParsePtlCmds().

void* stackPtr[MAX_STACK_DEPTH]
static

Definition at line 231 of file cl_particle.cpp.

byte stackType[MAX_STACK_DEPTH]
static

Definition at line 232 of file cl_particle.cpp.

timedParticle_t timedParticles[MAX_TIMEDPARTICLES]
static

Definition at line 67 of file cl_particle.cpp.