From 904fa4ce64fac0126ac451fe66e7a8f3b28c4a9a Mon Sep 17 00:00:00 2001 From: TimeServ Date: Mon, 23 Aug 2021 22:14:34 +0000 Subject: [PATCH] pass integer key reference instead of pointer reference to particle systems, remove switch fallthrough on q64 bsp switch git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6041 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_tent.c | 16 +++--- engine/client/client.h | 6 +-- engine/client/clq2_ents.c | 4 +- engine/client/p_classic.c | 26 ++++----- engine/client/p_null.c | 10 ++-- engine/client/p_script.c | 108 +++++++++++++++++++------------------- engine/client/pr_csqc.c | 2 +- engine/client/r_part.c | 8 +-- engine/common/particles.h | 29 +++------- engine/gl/gl_model.c | 3 ++ 10 files changed, 100 insertions(+), 112 deletions(-) diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index fd183e149..5313d4bff 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -208,8 +208,8 @@ struct beam_s { vec3_t start, end; vec3_t offset; //when attached, this is the offset from the owning entity. probably only z is meaningful. // int particlecolour; //some effects have specific colours. which is weird. - trailstate_t *trailstate; - trailstate_t *emitstate; + trailkey_t trailstate; + trailkey_t emitstate; }; beam_t *cl_beams; @@ -237,7 +237,7 @@ typedef struct model_t *model; int skinnum; int traileffect; - trailstate_t *trailstate; + trailkey_t trailstate; } explosion_t; static explosion_t *cl_explosions; @@ -2326,7 +2326,7 @@ void CL_ParseTrailParticles(void) int entityindex; int effectindex; vec3_t start, end; - trailstate_t **ts; + trailkey_t *tk; entityindex = MSGCL_ReadEntity(); effectindex = (unsigned short)MSG_ReadShort(); @@ -2341,12 +2341,12 @@ void CL_ParseTrailParticles(void) effectindex = CL_TranslateParticleFromServer(effectindex); if (entityindex>0 && (unsigned int)entityindex < cl.maxlerpents) - ts = &cl.lerpents[entityindex].trailstate; + tk = &cl.lerpents[entityindex].trailstate; else - ts = NULL; + tk = NULL; - if (P_ParticleTrail(start, end, effectindex, 1, entityindex, NULL, ts)) - P_ParticleTrail(start, end, rt_blood, 1, entityindex, NULL, ts); + if (P_ParticleTrail(start, end, effectindex, 1, entityindex, NULL, tk)) + P_ParticleTrail(start, end, rt_blood, 1, entityindex, NULL, tk); } void CL_ParsePointParticles(qboolean compact) diff --git a/engine/client/client.h b/engine/client/client.h index 0f06b5412..58a93af3c 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -584,8 +584,8 @@ typedef struct downloadlist_s { typedef struct { //current persistant state - trailstate_t *trailstate; //when to next throw out a trail - trailstate_t *emitstate; //when to next emit + trailkey_t trailstate; //when to next throw out a trail + trailkey_t emitstate; //when to next emit //current origin vec3_t origin; //current render position @@ -1084,7 +1084,7 @@ typedef struct { entity_t ent; entity_state_t state; - trailstate_t *emit; + trailkey_t emit; int mdlidx; /*negative are csqc indexes*/ } static_entity_t; diff --git a/engine/client/clq2_ents.c b/engine/client/clq2_ents.c index f250c1030..770e2a7df 100644 --- a/engine/client/clq2_ents.c +++ b/engine/client/clq2_ents.c @@ -89,8 +89,8 @@ typedef struct q2centity_s int serverframe; // if not current, this ent isn't in the frame - trailstate_t *trailstate; - trailstate_t *emitstate; + trailkey_t trailstate; + trailkey_t emitstate; // float trailcount; // for diminishing grenade trails vec3_t lerp_origin; // for trails (variable hz) diff --git a/engine/client/p_classic.c b/engine/client/p_classic.c index d00625b2e..60563cc60 100644 --- a/engine/client/p_classic.c +++ b/engine/client/p_classic.c @@ -265,7 +265,7 @@ static void PClassic_RunParticleEffect4 (vec3_t org, float radius, int color, in } //this function is used as a fallback in case a trail effect is unknown. -static void PClassic_ParticleTrailIndex (vec3_t start, vec3_t end, int type, float timestep, int color, int crnd, trailstate_t **tsk) +static void PClassic_ParticleTrailIndex (vec3_t start, vec3_t end, int type, float timestep, int color, int crnd, trailkey_t *tk) { } @@ -328,11 +328,11 @@ static void PClassic_ShutdownParticles(void) particles = NULL; } -// a classic trailstate is really just a float stored in a pointer variable... -// assuming float alignment/size is more strict than pointer -static float Classic_GetLeftover(trailstate_t **tsk) +// a classic trailstate key is really just a float +// assuming float alignment/size is more strict than our key type +static float Classic_GetLeftover(trailkey_t *tk) { - float *f = (float *)tsk; + float *f = (float *)tk; if (!f) return 0; @@ -340,18 +340,18 @@ static float Classic_GetLeftover(trailstate_t **tsk) return *f; } -static void Classic_SetLeftover(trailstate_t **tsk, float leftover) +static void Classic_SetLeftover(trailkey_t *tk, float leftover) { - float *f = (float *)tsk; + float *f = (float *)tk; if (f) *f = leftover; } //called when an entity is removed from the world, taking its trailstate with it. -static void PClassic_DelinkTrailstate(trailstate_t **tsk) +static void PClassic_DelinkTrailstate(trailkey_t *tk) { - *tsk = NULL; + *tk = 0; } //wipes all the particles ready for the next map. @@ -907,7 +907,7 @@ static void Classic_BrightField (vec3_t org) //svc_tempentity support: this is the function that handles 'special' point effects. //use the trail state so fast/slow frames keep the correct particle counts on certain every-frame effects -static int PClassic_RunParticleEffectState (vec3_t org, vec3_t dir, float count, int typenum, trailstate_t **tsk) +static int PClassic_RunParticleEffectState (vec3_t org, vec3_t dir, float count, int typenum, trailkey_t *tk) { switch(typenum&0xff) { @@ -1125,15 +1125,15 @@ int PClassic_PointFile(int c, vec3_t point) } //builds a trail from here to there. The trail state can be used to remember how far you got last frame. -static int PClassic_ParticleTrail (vec3_t startpos, vec3_t end, int type, float timestep, int dlkey, vec3_t dlaxis[3], trailstate_t **tsk) +static int PClassic_ParticleTrail (vec3_t startpos, vec3_t end, int type, float timestep, int dlkey, vec3_t dlaxis[3], trailkey_t *tk) { float leftover; if (type == P_INVALID) return 1; - leftover = Classic_ParticleTrail(startpos, end, Classic_GetLeftover(tsk), type); - Classic_SetLeftover(tsk, leftover); + leftover = Classic_ParticleTrail(startpos, end, Classic_GetLeftover(tk), type); + Classic_SetLeftover(tk, leftover); return 0; } diff --git a/engine/client/p_null.c b/engine/client/p_null.c index a0118f1ec..bc057442d 100644 --- a/engine/client/p_null.c +++ b/engine/client/p_null.c @@ -12,8 +12,8 @@ static int PNULL_FindParticleType(const char *name) } static int PNULL_RunParticleEffectTypeString (vec3_t org, vec3_t dir, float count, char *name){return 1;} -static int PNULL_ParticleTrail (vec3_t startpos, vec3_t end, int type, float timestep, int dlkey, vec3_t dlaxis[3], trailstate_t **tsk){return 1;} -static int PNULL_RunParticleEffectState (vec3_t org, vec3_t dir, float count, int typenum, trailstate_t **tsk){return 1;} +static int PNULL_ParticleTrail (vec3_t startpos, vec3_t end, int type, float timestep, int dlkey, vec3_t dlaxis[3], trailkey_t *tk){return 1;} +static int PNULL_RunParticleEffectState (vec3_t org, vec3_t dir, float count, int typenum, trailkey_t *tk){return 1;} static void PNULL_RunParticleWeather(vec3_t minb, vec3_t maxb, vec3_t dir, float count, int colour, char *efname){} static void PNULL_RunParticleCube(int typenum, vec3_t minb, vec3_t maxb, vec3_t dir_min, vec3_t dir_max, float count, int colour, qboolean gravity, float jitter){} static void PNULL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count){} @@ -22,7 +22,7 @@ static void PNULL_RunParticleEffect3 (vec3_t org, vec3_t box, int color, int eff static void PNULL_RunParticleEffect4 (vec3_t org, float radius, int color, int effect, int count){} static void PNULL_RunParticleEffectPalette (const char *nameprefix, vec3_t org, vec3_t dir, int color, int count){} -static void PNULL_ParticleTrailIndex (vec3_t start, vec3_t end, int type, float timestep, int color, int crnd, trailstate_t **tsk){} +static void PNULL_ParticleTrailIndex (vec3_t start, vec3_t end, int type, float timestep, int color, int crnd, trailkey_t *tk){} static qboolean PNULL_InitParticles (void) { @@ -33,9 +33,9 @@ static void PNULL_ShutdownParticles(void) { } -static void PNULL_DelinkTrailstate(trailstate_t **tsk) +static void PNULL_DelinkTrailstate(trailkey_t *tk) { - *tsk = NULL; + *tk = 0; } static void PNULL_ClearParticles (void){} static void PNULL_DrawParticles(void) diff --git a/engine/client/p_script.c b/engine/client/p_script.c index 6cec8e0b9..5707e2753 100644 --- a/engine/client/p_script.c +++ b/engine/client/p_script.c @@ -110,7 +110,7 @@ typedef struct particle_s float angle; union { float nextemit; - trailstate_t *trailstate; + trailkey_t trailstate; } state; // drivers never touch the following fields float rotationspeed; @@ -146,6 +146,22 @@ typedef struct beamseg_s float texture_s; } beamseg_t; +typedef struct trailstate_s { + trailkey_t key; // key to check if ts has been overwriten + trailkey_t assoc; // assoc linked trail + struct beamseg_s* lastbeam; // last beam pointer (flagged with BS_LASTSEG) + union { + struct { + float lastdist; // last distance used with particle effect + float laststop; // last stopping point for particle effect + } trail; + struct { + float statetime; // time to emit effect again (used by spawntime field) + float emittime; // used by r_effect emitters + } effect; + trailkey_t fallbackkey; // passed to fallback system + }; +} trailstate_t; typedef struct skytris_s { @@ -4123,33 +4139,27 @@ static void P_CleanTrailstate(trailstate_t *ts) memset(ts, 0, sizeof(trailstate_t)); } -static void PScript_DelinkTrailstate(trailstate_t **tsk) +static void PScript_DelinkTrailstate(trailkey_t *tk) { + trailkey_t key; trailstate_t *ts; - trailstate_t *assoc; - if (*tsk == NULL) - return; // not linked to a trailstate + key = *tk; + *tk = 0; - ts = *tsk; // store old pointer - *tsk = NULL; // clear pointer - - if (ts->key != tsk) - return; // prevent overwrite - - assoc = ts->assoc; // store assoc - P_CleanTrailstate(ts); // clean directly linked trailstate - - // clean trailstates assoc linked - while (assoc) + while (key && key <= r_numtrailstates) { - ts = assoc->assoc; - P_CleanTrailstate(assoc); - assoc = ts; + ts = trailstates + (key - 1); + + if (ts->key != key) + break; // prevent overwrite + + key = ts->assoc; // next to clean + P_CleanTrailstate(ts); } } -static trailstate_t *P_NewTrailstate(trailstate_t **key) +static trailstate_t *P_NewTrailstate() { trailstate_t *ts; @@ -4157,42 +4167,34 @@ static trailstate_t *P_NewTrailstate(trailstate_t **key) if (ts_cycle >= r_numtrailstates) ts_cycle = 0; - // get trailstate ts = trailstates + ts_cycle; - - // clear trailstate P_CleanTrailstate(ts); - - // set key - ts->key = key; - - // advance index cycle ts_cycle++; + ts->key = ts_cycle; // key is 1 above index, allows 0 to be invalid - // return clean trailstate return ts; } -static trailstate_t* P_FetchTrailstate(trailstate_t** tsk) +static trailstate_t* P_FetchTrailstate(trailkey_t* tk) { trailstate_t* ts; // trailstate allocation/deallocation - if (tsk) + if (tk) { - if (*tsk == NULL) + trailkey_t key = *tk; + if (key == 0 || key > r_numtrailstates) { - ts = P_NewTrailstate(tsk); - *tsk = ts; + ts = P_NewTrailstate(); + *tk = ts->key; } else { - ts = *tsk; - - if (ts->key != tsk) // trailstate was overwritten + ts = trailstates + (key - 1); + if (ts->key != key) // trailstate was overwritten { - ts = P_NewTrailstate(tsk); // so get a new one - *tsk = ts; + ts = P_NewTrailstate(); // so get a new one + *tk = ts->key; } } } @@ -4658,7 +4660,7 @@ static void PScript_AddDecals(void *vctx, vec3_t *fte_restrict points, size_t nu } } -static int PScript_RunParticleEffectState (vec3_t org, vec3_t dir, float count, int typenum, trailstate_t **tsk) +static int PScript_RunParticleEffectState (vec3_t org, vec3_t dir, float count, int typenum, trailkey_t *tk) { part_type_t *ptype = &part_type[typenum]; int i, j, k, l, spawnspc; @@ -4692,9 +4694,9 @@ static int PScript_RunParticleEffectState (vec3_t org, vec3_t dir, float count, // eliminate trailstate if flag set if (ptype->flags & PT_NOSTATE) - tsk = NULL; + tk = NULL; - ts = P_FetchTrailstate(tsk); + ts = P_FetchTrailstate(tk); // get msvc to shut up j = k = l = 0; @@ -5263,8 +5265,8 @@ skip: // new trailstate if (ts) { - tsk = &(ts->assoc); - ts = P_FetchTrailstate(tsk); + tk = &(ts->assoc); + ts = P_FetchTrailstate(tk); } ptype = &part_type[ptype->assoc]; @@ -5550,7 +5552,7 @@ static void PScript_RunParticleEffectPalette (const char *nameprefix, vec3_t org } } -static void P_ParticleTrailSpawn (vec3_t startpos, vec3_t end, part_type_t *ptype, float timeinterval, trailstate_t** tsk, int dlkey, vec3_t dlaxis[3]) +static void P_ParticleTrailSpawn (vec3_t startpos, vec3_t end, part_type_t *ptype, float timeinterval, trailkey_t* tk, int dlkey, vec3_t dlaxis[3]) { vec3_t vec, vstep, right, up, start; float len; @@ -5572,9 +5574,9 @@ static void P_ParticleTrailSpawn (vec3_t startpos, vec3_t end, part_type_t *ptyp // eliminate trailstate if flag set if (ptype->flags & PT_NOSTATE) - tsk = NULL; + tk = NULL; - ts = P_FetchTrailstate(tsk); + ts = P_FetchTrailstate(tk); PScript_EffectSpawned(ptype, start, dlaxis, dlkey, 1); @@ -6051,7 +6053,7 @@ static void P_ParticleTrailSpawn (vec3_t startpos, vec3_t end, part_type_t *ptyp return; } -static int PScript_ParticleTrail (vec3_t startpos, vec3_t end, int type, float timeinterval, int dlkey, vec3_t axis[3], trailstate_t **tsk) +static int PScript_ParticleTrail (vec3_t startpos, vec3_t end, int type, float timeinterval, int dlkey, vec3_t axis[3], trailkey_t *tk) { part_type_t *ptype = &part_type[type]; @@ -6063,8 +6065,8 @@ static int PScript_ParticleTrail (vec3_t startpos, vec3_t end, int type, float t // also reusing fallback space for emit/trail info will cause some // issues with entities in action during particle reconfiguration // but that shouldn't be happening too often - trailstate_t* ts = P_FetchTrailstate(tsk); - return fallback->ParticleTrail(startpos, end, type - FALLBACKBIAS, timeinterval, dlkey, axis, &(ts->fallback)); + trailstate_t* ts = P_FetchTrailstate(tk); + return fallback->ParticleTrail(startpos, end, type - FALLBACKBIAS, timeinterval, dlkey, axis, &(ts->fallbackkey)); } if (type < 0 || type >= numparticletypes) @@ -6083,11 +6085,11 @@ static int PScript_ParticleTrail (vec3_t startpos, vec3_t end, int type, float t ptype = &part_type[ptype->inwater]; } - P_ParticleTrailSpawn (startpos, end, ptype, timeinterval, tsk, dlkey, axis); + P_ParticleTrailSpawn (startpos, end, ptype, timeinterval, tk, dlkey, axis); return 0; } -static void PScript_ParticleTrailIndex (vec3_t start, vec3_t end, int type, float timeinterval, int color, int crnd, trailstate_t **tsk) +static void PScript_ParticleTrailIndex (vec3_t start, vec3_t end, int type, float timeinterval, int color, int crnd, trailkey_t *tk) { if (type == P_INVALID) type = pe_defaulttrail; @@ -6095,7 +6097,7 @@ static void PScript_ParticleTrailIndex (vec3_t start, vec3_t end, int type, floa { part_type[type].colorindex = color; part_type[type].colorrand = crnd; - P_ParticleTrail(start, end, type, timeinterval, 0, NULL, tsk); + P_ParticleTrail(start, end, type, timeinterval, 0, NULL, tk); } } diff --git a/engine/client/pr_csqc.c b/engine/client/pr_csqc.c index 3471d337a..9a0f91218 100644 --- a/engine/client/pr_csqc.c +++ b/engine/client/pr_csqc.c @@ -419,7 +419,7 @@ typedef struct csqcedict_s /*the above is shared with ssqc*/ //add whatever you wish here - trailstate_t *trailstate; + trailkey_t trailstate; int skinobject; } csqcedict_t; diff --git a/engine/client/r_part.c b/engine/client/r_part.c index 21756e90e..98d96f6d8 100644 --- a/engine/client/r_part.c +++ b/engine/client/r_part.c @@ -958,7 +958,7 @@ float CL_TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int } //handy utility... -void P_EmitEffect (vec3_t pos, vec3_t orientation[3], unsigned int modeleflags, int type, trailstate_t **tsk) +void P_EmitEffect (vec3_t pos, vec3_t orientation[3], unsigned int modeleflags, int type, trailkey_t *tk) { float count; if (cl.paused) @@ -968,16 +968,16 @@ void P_EmitEffect (vec3_t pos, vec3_t orientation[3], unsigned int modeleflags, if (orientation) { if (modeleflags & MDLF_EMITFORWARDS) - pe->RunParticleEffectState(pos, orientation[0], count, type, tsk); + pe->RunParticleEffectState(pos, orientation[0], count, type, tk); else { vec3_t down; VectorNegate(orientation[2], down); - pe->RunParticleEffectState(pos, down, count, type, tsk); + pe->RunParticleEffectState(pos, down, count, type, tk); } } else - pe->RunParticleEffectState(pos, NULL, count, type, tsk); + pe->RunParticleEffectState(pos, NULL, count, type, tk); } diff --git a/engine/common/particles.h b/engine/common/particles.h index 7d1e4800a..6446c463a 100644 --- a/engine/common/particles.h +++ b/engine/common/particles.h @@ -166,24 +166,7 @@ typedef enum extern int pt_q2[]; #endif -struct beamseg_s; - -typedef struct trailstate_s { - struct trailstate_s **key; // key to check if ts has been overwriten - struct trailstate_s *assoc; // assoc linked trail - struct beamseg_s *lastbeam; // last beam pointer (flagged with BS_LASTSEG) - union { - struct { - float lastdist; // last distance used with particle effect - float laststop; // last stopping point for particle effect - } trail; - struct { - float statetime; // time to emit effect again (used by spawntime field) - float emittime; // used by r_effect emitters - } effect; - struct trailstate_s* fallback; - }; -} trailstate_t; +typedef quint32_t trailkey_t; #define PARTICLE_Z_CLIP 8.0 @@ -218,7 +201,7 @@ void P_ShutdownParticleSystem(void); void P_Shutdown(void); void P_LoadedModel(struct model_s *mod); /*checks a model's various effects*/ void P_DefaultTrail (unsigned int entityeffects, unsigned int modelflags, int *trailid, int *trailpalidx); -void P_EmitEffect (vec3_t pos, vec3_t orientation[3], unsigned int modeleflags, int type, trailstate_t **tsk);//this is just a wrapper +void P_EmitEffect (vec3_t pos, vec3_t orientation[3], unsigned int modeleflags, int type, trailkey_t *tsk);//this is just a wrapper int P_FindParticleType(const char *efname); #ifdef PSET_SCRIPT void PScript_ClearSurfaceParticles(struct model_s *mod); @@ -249,8 +232,8 @@ typedef struct { qboolean (*ParticleQuery) (int type, int body, char *outstr, int outstrlen); int (*RunParticleEffectTypeString) (vec3_t org, vec3_t dir, float count, char *name); - int (*ParticleTrail) (vec3_t startpos, vec3_t end, int type, float timeinterval, int dlkey, vec3_t dlaxis[3], trailstate_t **tsk); - int (*RunParticleEffectState) (vec3_t org, vec3_t dir, float count, int typenum, trailstate_t **tsk); + int (*ParticleTrail) (vec3_t startpos, vec3_t end, int type, float timeinterval, int dlkey, vec3_t dlaxis[3], trailkey_t *tk); + int (*RunParticleEffectState) (vec3_t org, vec3_t dir, float count, int typenum, trailkey_t *tk); void (*RunParticleWeather) (vec3_t minb, vec3_t maxb, vec3_t dir, float count, int colour, char *efname); void (*RunParticleCube) (int typenum, vec3_t minb, vec3_t maxb, vec3_t dir_min, vec3_t dir_max, float count, int colour, qboolean gravity, float jitter); //typenum may be P_INVALID void (*RunParticleEffect) (vec3_t org, vec3_t dir, int color, int count); @@ -259,10 +242,10 @@ typedef struct { void (*RunParticleEffect4) (vec3_t org, float radius, int color, int effect, int count); void (*RunParticleEffectPalette) (const char *nameprefix, vec3_t org, vec3_t dir, int color, int count); - void (*ParticleTrailIndex) (vec3_t start, vec3_t end, int type, float timeinterval, int color, int crnd, trailstate_t **tsk); //P_INVALID is fine for the type here, you'll get a default trail. + void (*ParticleTrailIndex) (vec3_t start, vec3_t end, int type, float timeinterval, int color, int crnd, trailkey_t *tk); //P_INVALID is fine for the type here, you'll get a default trail. qboolean (*InitParticles) (void); void (*ShutdownParticles) (void); - void (*DelinkTrailstate) (trailstate_t **tsk); + void (*DelinkTrailstate) (trailkey_t *tk); void (*ClearParticles) (void); void (*DrawParticles) (void); } particleengine_t; diff --git a/engine/gl/gl_model.c b/engine/gl/gl_model.c index 0faf0d90c..335b1496f 100644 --- a/engine/gl/gl_model.c +++ b/engine/gl/gl_model.c @@ -5260,6 +5260,9 @@ static qboolean QDECL Mod_LoadBrushModel (model_t *mod, void *buffer, size_t fsi { case BSPVERSIONQ64: subbsp = sb_quake64; + mod->fromgame = fg_quake; + mod->engineflags |= MDLF_NEEDOVERBRIGHT; + break; case BSPVERSION: case BSPVERSIONPREREL: mod->fromgame = fg_quake;