cl_particle.c File Reference

Client particle parsing and rendering functions. More...

#include "../client.h"
#include "cl_particle.h"
#include "cl_localentity.h"
#include "cl_view.h"
#include "cl_parse.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.c:

Go to the source code of this file.

Data Structures

struct  mapParticle_s
 map particles More...
struct  timedParticle_s

Defines

#define MAX_MAPPARTICLES   1024
#define MAX_TIMEDPARTICLES   16
#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
typedef struct timedParticle_s timedParticle_t
typedef enum pf_s pf_t
 particle functions enums - see pf_strings and pf_values
typedef enum pc_s pc_t
 particle commands - see pc_strings

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, qboolean 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, byte type)
 Register art (pics, models) for each particle.
void PTL_InitStartup (void)
static void * CL_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)
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_ParticleVisible (ptl_t *p, qboolean hide)
 Mark a particle an all its children as invisible or visible.
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, qboolean onlyAlpha)
 Color fade function.
void CL_ParticleCheckRounds (void)
 checks whether a particle is still active in the current round
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.
void CL_ParticleRun (void)
 General system for particle running during the game.
static void CL_ParseMapParticle (ptl_t *ptl, const char *es, qboolean afterwards)
 Parses particle used on maps.
void CL_RunMapParticles (void)
static void CL_ParsePtlCmds (const char *name, const char **text)
int CL_ParseParticle (const char *name, const char **text)
 Parses particle definitions from UFO-script files.
static void PTL_DebugSpawnMarker_f (void)
 Spawns a debug marker particle in the world.
static void PTL_DebugList_f (void)
void CL_InitParticles (void)
 Initializes cvars and commands.

Variables

static cvar_tcl_particleweather
static mapParticle_t mapParticles [MAX_MAPPARTICLES]
static timedParticle_t timedParticles [MAX_TIMEDPARTICLES]
static const char * 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 const char * pc_strings [PC_NUM_PTLCMDS]
 particle commands - see pc_t
static const 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 void * stackPtr [MAX_STACK_DEPTH]
static byte stackType [MAX_STACK_DEPTH]

Detailed Description

Client particle parsing and rendering functions.

Definition in file cl_particle.c.


Define Documentation

#define MAX_MAPPARTICLES   1024

Definition at line 36 of file cl_particle.c.

Referenced by CL_AddMapParticle().

#define MAX_PCMD_DATA   (MAX_PTLCMDS * 8)

Definition at line 214 of file cl_particle.c.

#define MAX_PTLCMDS   (MAX_PTLDEFS * 32)

Definition at line 206 of file cl_particle.c.

Referenced by CL_ParsePtlCmds().

#define MAX_PTLDEFS   256

Definition at line 205 of file cl_particle.c.

Referenced by CL_ParseParticle().

#define MAX_STACK_DATA   512

Definition at line 223 of file cl_particle.c.

#define MAX_STACK_DEPTH   8

Definition at line 222 of file cl_particle.c.

Referenced by CL_ParticleFunction().

#define MAX_TIMEDPARTICLES   16

Definition at line 37 of file cl_particle.c.

#define PTL_ONLY_ONE_TYPE   (1<<31)

Definition at line 70 of file cl_particle.c.

Referenced by CL_ParsePtlCmds().

#define V_UNTYPED   0x7FFF

Definition at line 71 of file cl_particle.c.

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

Definition at line 69 of file cl_particle.c.

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 105 of file cl_particle.c.

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 74 of file cl_particle.c.


Function Documentation

CASSERT ( lengthof(pc_types = =PC_NUM_PTLCMDS  ) 
CASSERT ( lengthof(pc_strings = =PC_NUM_PTLCMDS  ) 
CASSERT ( lengthof(pf_values = =PF_NUM_PTLFUNCS  ) 
CASSERT ( lengthof(pf_strings = =PF_NUM_PTLFUNCS  ) 
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] ptl Particle name
[in] origin The position in the world
[in] wait 
[in] info 
[in] levelflags The levelflag mask to show the particle on

Definition at line 273 of file cl_particle.c.

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

Referenced by SP_misc_particle().

static void CL_Fading ( vec4_t  color,
fade_t  fade,
float  frac,
qboolean  onlyAlpha 
) [static]

Color fade function.

Parameters:
[in,out] color The color vector to fade.
[in] fade The type of the fade.
[in] frac The fraction to fade the color with.
[in] onlyAlpha Only fade the alpha channel of the given RGBA color.

Definition at line 819 of file cl_particle.c.

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

Referenced by CL_ParticleRun2().

void CL_InitParticles ( void   ) 

Initializes cvars and commands.

Definition at line 1470 of file cl_particle.c.

References Cmd_AddCommand(), CVAR_ARCHIVE, Cvar_Get(), CVAR_LATCH, PTL_DebugList_f(), and PTL_DebugSpawnMarker_f().

Referenced by CL_Init().

static void CL_ParseMapParticle ( ptl_t ptl,
const char *  es,
qboolean  afterwards 
) [static]

Parses particle used on maps.

Parameters:
[in,out] ptl Pointer to particle being parsed and updated.
[in] es Entity string to parse the particle from
[in] afterwards If this is true you can modify the particle after the init function for the particle was already called

Definition at line 1061 of file cl_particle.c.

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

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

Parses particle definitions from UFO-script files.

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

Definition at line 1344 of file cl_particle.c.

References byte, CL_ParsePtlCmds(), Com_EParse(), Com_Parse(), Com_Printf(), i, ptlDef_s::init, MAX_PTLDEFS, ptlDef_s::name, PF_NUM_PTLFUNCS, pf_strings, pos, and Q_strncpyz().

Referenced by CL_ParseClientData().

static void CL_ParsePtlCmds ( const char *  name,
const char **  text 
) [static]
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 856 of file cl_particle.c.

References CL_ParticleFree(), CL_ParticleFunction(), ptl_s::ctrl, i, ptl_s::inuse, r_numParticles, r_particles, 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 
) [inline, static]

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

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

Definition at line 391 of file cl_particle.c.

References byte, and ptlCmd_s::ref.

Referenced by CL_ParticleFunction().

void CL_ParticleFree ( ptl_t p  ) 

Free a particle and all it's children.

Parameters:
[in] p the particle to free
See also:
CL_ParticleSpawn

Definition at line 801 of file cl_particle.c.

References ptl_s::children, CL_ParticleFree(), ptl_s::inuse, ptl_s::invis, ptl_s::next, qfalse, and qtrue.

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

static void CL_ParticleFunction ( ptl_t p,
ptlCmd_t cmd 
) [static]
static ptlArt_t* CL_ParticleGetArt ( const char *  name,
int  frame,
byte  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
Note:
We have to use the char* cast here because the image_t and model_t have their names at the beginning of their structs

Definition at line 341 of file cl_particle.c.

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_strncpyz(), r_numParticlesArt, r_particlesArt, ptlArt_s::skin, and ptlArt_s::type.

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

static void CL_ParticleLoadArt ( ptlArt_t a  )  [inline, static]

Loads the image or model for a given particle art.

Todo:
Support the frame data from ptlArt_t for models, too

Definition at line 299 of file cl_particle.c.

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_RegisterImage(), R_RegisterModelShort(), ptlArt_s::type, and va().

Referenced by CL_ParticleGetArt(), and CL_ParticleRegisterArt().

void CL_ParticleRegisterArt ( void   ) 

Definition at line 325 of file cl_particle.c.

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

Referenced by CL_ViewLoadMedia().

void CL_ParticleRun ( void   ) 

General system for particle running during the game.

See also:
CL_Frame

Definition at line 1039 of file cl_particle.c.

References ca_active, CL_ParticleRun2(), CL_ParticleRunTimed(), cls, i, ptl_s::inuse, r_numParticles, r_particles, and client_static_s::state.

Referenced by CL_Frame().

static void CL_ParticleRun2 ( ptl_t p  )  [static]
static void CL_ParticleRunTimed ( void   )  [static]
ptl_t* CL_ParticleSpawn ( const char *  name,
int  levelFlags,
const vec3_t  s,
const vec3_t  v,
const vec3_t  a 
)
static void CL_ParticleSpawnTimed ( const char *  name,
ptl_t parent,
qboolean  children,
int  deltaTime,
int  n 
) [static]

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

Parameters:
[in] name The id of the particle (see ptl_*.ufo script files in base/ufos)
[in] parent The parent particle
[in] children Spawn as children
[in] deltaTime The time to wait until this particle should get spawned
[in] n The amount of particles to spawn (each after deltaTime of its predecessor)

Definition at line 237 of file cl_particle.c.

References timedParticle_s::children, Com_Error(), Com_Printf(), timedParticle_s::dt, ERR_DROP, i, lengthof, ptl_s::levelFlags, timedParticle_s::levelFlags, timedParticle_s::max, timedParticle_s::n, timedParticle_s::parent, timedParticle_s::ptl, and Q_strncpyz().

Referenced by CL_ParticleFunction().

void CL_ParticleVisible ( ptl_t p,
qboolean  hide 
)

Mark a particle an all its children as invisible or visible.

Parameters:
[in] p Particle to set the invis flags for
[in] hide Boolean value for hiding the particle

Definition at line 785 of file cl_particle.c.

References ptl_s::children, CL_ParticleVisible(), ptl_s::invis, and ptl_s::next.

Referenced by CL_ParticleVisible().

void CL_RunMapParticles ( void   ) 
static void PTL_DebugList_f ( void   )  [static]
static void PTL_DebugSpawnMarker_f ( void   )  [static]

Spawns a debug marker particle in the world.

Definition at line 1422 of file cl_particle.c.

References CL_ParticleSpawn(), Cmd_Argc(), Cmd_Argv(), and Com_Printf().

Referenced by CL_InitParticles().

void PTL_InitStartup ( void   ) 
See also:
CL_InitLocal

Definition at line 376 of file cl_particle.c.

References r_numParticles, and r_numParticlesArt.

Referenced by CL_InitLocal().


Variable Documentation

Definition at line 39 of file cl_particle.c.

byte cmdStack[MAX_STACK_DATA] [static]

Definition at line 225 of file cl_particle.c.

mapParticle_t mapParticles[MAX_MAPPARTICLES] [static]

Definition at line 66 of file cl_particle.c.

int numPtlCmds [static]

Definition at line 212 of file cl_particle.c.

int numPtlDefs [static]

Definition at line 211 of file cl_particle.c.

const char* pc_strings[PC_NUM_PTLCMDS] [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 122 of file cl_particle.c.

const int pc_types[PC_NUM_PTLCMDS] [static]
Initial value:

particle commands parameter and types

Definition at line 138 of file cl_particle.c.

byte pcmdData[MAX_PCMD_DATA] [static]
Todo:
check pcmdData overflow

Definition at line 217 of file cl_particle.c.

byte* pcmdPos = pcmdData [static]

Definition at line 218 of file cl_particle.c.

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

valid particle functions - see pf_t and pf_values

Definition at line 85 of file cl_particle.c.

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 95 of file cl_particle.c.

const value_t pps[] [static]

particle script values

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

Definition at line 157 of file cl_particle.c.

ptlCmd_t ptlCmd[MAX_PTLCMDS] [static]

Definition at line 209 of file cl_particle.c.

ptlDef_t ptlDef[MAX_PTLDEFS] [static]

Definition at line 208 of file cl_particle.c.

const int RSTACK = -(MAX_PCMD_DATA) [static]

Definition at line 220 of file cl_particle.c.

void* stackPtr[MAX_STACK_DEPTH] [static]

Definition at line 226 of file cl_particle.c.

byte stackType[MAX_STACK_DEPTH] [static]

Definition at line 227 of file cl_particle.c.

timedParticle_t timedParticles[MAX_TIMEDPARTICLES] [static]

Definition at line 67 of file cl_particle.c.


Generated by  doxygen 1.6.2