From 483b25be2c1b8823b46dafcd09000718eb3efeda Mon Sep 17 00:00:00 2001 From: Shpoike Date: Sat, 15 May 2021 22:33:38 +0100 Subject: [PATCH] Use more of the static prop properties - alphafading, lightorg, and leafrefs. --- engine/client/cl_ents.c | 32 ++++++++++++++++++++++++++++- engine/client/view.c | 8 ++++---- engine/common/gl_q2bsp.c | 44 +++++++++++++++++++++++++++++----------- engine/gl/gl_model.h | 8 +++++++- 4 files changed, 74 insertions(+), 18 deletions(-) diff --git a/engine/client/cl_ents.c b/engine/client/cl_ents.c index 9c6fdb49..9478ca3e 100644 --- a/engine/client/cl_ents.c +++ b/engine/client/cl_ents.c @@ -3405,7 +3405,10 @@ void CL_LinkStaticEntities(void *pvs, int *areas) if (cl.worldmodel->numstaticents) { + struct modelstaticent_s *sent; entity_t *src; + float d; + vec3_t disp; for (i = 0; i < cl.worldmodel->numstaticents; i++) { if (cl_numvisedicts == cl_maxvisedicts) @@ -3413,7 +3416,23 @@ void CL_LinkStaticEntities(void *pvs, int *areas) cl_expandvisents=true; break; } - src = &cl.worldmodel->staticents[i]; + sent = &cl.worldmodel->staticents[i]; + src = &sent->ent; + + if (sent->fademaxdist) + { + VectorSubtract(r_refdef.vieworg, src->origin, disp); + d = VectorLength(disp); + if (d > sent->fademaxdist) + continue; //skip it. + d -= sent->fademindist; + d /= sent->fademaxdist-sent->fademindist; + if (d < 0) + d = 0; + } + else + d = 0; + if (!src->model || src->model->loadstate != MLS_LOADED) { if (src->model && src->model->loadstate == MLS_NOTLOADED) @@ -3421,7 +3440,13 @@ void CL_LinkStaticEntities(void *pvs, int *areas) continue; } if (!src->light_known) + { + vec3_t tmp; + VectorCopy(src->origin, tmp); + VectorCopy(sent->lightorg, src->origin); R_CalcModelLighting(src, src->model); //bake and cache, now everything else is working. + VectorCopy(tmp, src->origin); + } if (src->pvscache.num_leafs==-2) { vec3_t absmin, absmax; @@ -3437,6 +3462,11 @@ void CL_LinkStaticEntities(void *pvs, int *areas) *ent = *src; ent->framestate.g[FS_REG].frametime[0] = cl.time; ent->framestate.g[FS_REG].frametime[1] = cl.time; + if (d) + { + ent->shaderRGBAf[3] *= 1-d; + ent->flags |= RF_TRANSLUCENT; + } } } } diff --git a/engine/client/view.c b/engine/client/view.c index a78b8143..185e221c 100644 --- a/engine/client/view.c +++ b/engine/client/view.c @@ -2154,19 +2154,19 @@ void R_DrawNameTags(void) for (i=0 ; inumstaticents; i++) { - entity_t *state = &cl.worldmodel->staticents[i]; - mod = state->model; + struct modelstaticent_s *state = &cl.worldmodel->staticents[i]; + mod = state->ent.model; if (mod && mod->loadstate == MLS_LOADED) VectorInterpolate(mod->mins, 0.5, mod->maxs, org); else VectorClear(org); - VectorAdd(org, state->origin, org); + VectorAdd(org, state->ent.origin, org); if (Matrix4x4_CM_Project(org, screenspace, r_refdef.viewangles, r_refdef.vieworg, r_refdef.fov_x, r_refdef.fov_y)) { char *entstr; int x, y; - entstr = state->model->name; + entstr = mod->name; if (entstr) { x = screenspace[0]*r_refdef.vrect.width+r_refdef.vrect.x; diff --git a/engine/common/gl_q2bsp.c b/engine/common/gl_q2bsp.c index fb584c19..9668c6d6 100644 --- a/engine/common/gl_q2bsp.c +++ b/engine/common/gl_q2bsp.c @@ -5486,19 +5486,21 @@ typedef struct { unsigned int len; } sl[1]; } hlgamelumpheader_t; -static qboolean CModHL2_LoadStaticProps(model_t *mod, qbyte *offset, size_t size, int version) +static qboolean CModHL2_LoadStaticProps(model_t *mod, qbyte *offset, size_t size, int version) //present on server, because they're potentially solid. { struct { const char name[128]; } *modelref; size_t nummodels, numleafrefs, numprops, i; - unsigned short *leafref; + unsigned short *leafref, *eleafref; + struct modelstaticent_s *sent; entity_t *ent; size_t modelindex; qboolean skip = false; int dxlevel = 95, cpulevel=0, gpulevel=0; + unsigned int leafcount, l; qbyte *prop; size_t propsize; @@ -5554,8 +5556,9 @@ static qboolean CModHL2_LoadStaticProps(model_t *mod, qbyte *offset, size_t size return true; //funny lump size... mod->staticents = ZG_Malloc(&mod->memgroup, sizeof(*mod->staticents)*numprops); - for (i = 0, ent = mod->staticents; i < numprops; i++) + for (i = 0, sent = mod->staticents; i < numprops; i++) { + ent = &sent->ent; skip = false; #ifdef HAVE_CLIENT V_ClearEntity(ent); @@ -5584,16 +5587,16 @@ static qboolean CModHL2_LoadStaticProps(model_t *mod, qbyte *offset, size_t size ent->angles[1] = LittleFloat(*(float*)prop); prop += sizeof(float); ent->angles[2] = LittleFloat(*(float*)prop); prop += sizeof(float); modelindex = (unsigned short)LittleShort(*(short*)prop); prop += sizeof(unsigned short); - /*firstleaf = LittleShort(*(unsigned short*)prop)*/; prop += sizeof(unsigned short); - /*leafcount = LittleShort(*(unsigned short*)prop)*/; prop += sizeof(unsigned short); + eleafref = leafref+(unsigned short)LittleShort(*(unsigned short*)prop); prop += sizeof(unsigned short); + leafcount = LittleShort(*(unsigned short*)prop); prop += sizeof(unsigned short); /*ent->solid = *prop*/; prop += sizeof(qbyte); /*ent->flags = *prop*/; prop += sizeof(qbyte); ent->skinnum = LittleLong(*(unsigned int*)prop); prop += sizeof(unsigned int); - /*ent->fademindist = LittleFloat(*(float*)prop)*/; prop += sizeof(float); - /*ent->fademaxdist = LittleFloat(*(float*)prop)*/; prop += sizeof(float); - /*ent->lightingorigin[0] = LittleFloat(*(float*)prop)*/; prop += sizeof(float); - /*ent->lightingorigin[1] = LittleFloat(*(float*)prop)*/; prop += sizeof(float); - /*ent->lightingorigin[2] = LittleFloat(*(float*)prop)*/; prop += sizeof(float); + sent->fademindist = LittleFloat(*(float*)prop); prop += sizeof(float); + sent->fademaxdist = LittleFloat(*(float*)prop); prop += sizeof(float); + sent->lightorg[0] = LittleFloat(*(float*)prop); prop += sizeof(float); + sent->lightorg[1] = LittleFloat(*(float*)prop); prop += sizeof(float); + sent->lightorg[2] = LittleFloat(*(float*)prop); prop += sizeof(float); if (version >= 5) { /*ent->fadescale = LittleFloat(*(float*)prop);*/ prop += sizeof(float); @@ -5636,7 +5639,24 @@ static qboolean CModHL2_LoadStaticProps(model_t *mod, qbyte *offset, size_t size AngleVectorsFLU(ent->angles, ent->axis[0], ent->axis[1], ent->axis[2]); //Hack: special value to flag it for linking once we've loaded its model. this needs to go when we make them solid. - ent->pvscache.num_leafs = -2; + if (leafcount > countof(ent->pvscache.leafnums)) + ent->pvscache.num_leafs = -2; //overflow. calculate it later once its loaded. + else + { + ent->pvscache.areanum = -1; //FIXME + ent->pvscache.areanum2 = -1; + ent->pvscache.num_leafs = leafcount; //overflow. calculate it later once its loaded. + for (l = 0; l < leafcount; l++) + { + mleaf_t *lf = mod->leafs + *eleafref++; + ent->pvscache.leafnums[l]/*actually clusters*/ = lf->cluster; + //and try to track the areas too. not quite so reliable... + if (ent->pvscache.areanum == -1) + ent->pvscache.areanum = lf->area; + else + ent->pvscache.areanum2 = lf->area; + } + } //Hack: lighting is wrong. ent->light_known = 1; VectorSet(ent->light_dir, 0, 0.707, 0.707); @@ -5645,7 +5665,7 @@ static qboolean CModHL2_LoadStaticProps(model_t *mod, qbyte *offset, size_t size //not all props will be emitted, according to d3d levels... mod->numstaticents++; - ent++; + sent++; } return true; diff --git a/engine/gl/gl_model.h b/engine/gl/gl_model.h index 032859d2..d497f19f 100644 --- a/engine/gl/gl_model.h +++ b/engine/gl/gl_model.h @@ -1133,7 +1133,13 @@ typedef struct model_s #ifdef HL2BSPS dispinfo_t *displacements; unsigned int numdisplacements; - entity_t *staticents; + struct modelstaticent_s + { + float fademindist; + float fademaxdist; + vec3_t lightorg; + entity_t ent; + } *staticents; size_t numstaticents; #endif