Use more of the static prop properties - alphafading, lightorg, and leafrefs.

This commit is contained in:
Shpoike 2021-05-15 22:33:38 +01:00
parent f0fc7bfa0f
commit 483b25be2c
4 changed files with 74 additions and 18 deletions

View File

@ -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;
}
}
}
}

View File

@ -2154,19 +2154,19 @@ void R_DrawNameTags(void)
for (i=0 ; i<cl.worldmodel->numstaticents; 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;

View File

@ -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;

View File

@ -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