gl1: make currententity local

This commit is contained in:
Denis Pauk 2021-09-19 20:05:38 +03:00
parent 2d1a090feb
commit 083cfca305
5 changed files with 75 additions and 83 deletions

View file

@ -326,7 +326,7 @@ R_RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end)
}
void
R_LightPoint(vec3_t p, vec3_t color)
R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
{
vec3_t end;
float r;

View file

@ -39,8 +39,6 @@ glstate_t gl_state;
image_t *r_notexture; /* use for bad textures */
image_t *r_particletexture; /* little dot for particles */
entity_t *currententity;
cplane_t frustum[4];
int r_visframecount; /* bumped when going to a new PVS */
@ -175,7 +173,7 @@ R_RotateForEntity(entity_t *e)
}
void
R_DrawSpriteModel(entity_t *e, const model_t *currentmodel)
R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel)
{
float alpha = 1.0F;
vec3_t point[4];
@ -187,16 +185,16 @@ R_DrawSpriteModel(entity_t *e, const model_t *currentmodel)
a single polygon without a surface cache */
psprite = (dsprite_t *)currentmodel->extradata;
e->frame %= psprite->numframes;
frame = &psprite->frames[e->frame];
currententity->frame %= psprite->numframes;
frame = &psprite->frames[currententity->frame];
/* normal sprite */
up = vup;
right = vright;
if (e->flags & RF_TRANSLUCENT)
if (currententity->flags & RF_TRANSLUCENT)
{
alpha = e->alpha;
alpha = currententity->alpha;
}
if (alpha != 1.0F)
@ -206,7 +204,7 @@ R_DrawSpriteModel(entity_t *e, const model_t *currentmodel)
glColor4f(1, 1, 1, alpha);
R_Bind(currentmodel->skins[e->frame]->texnum);
R_Bind(currentmodel->skins[currententity->frame]->texnum);
R_TexEnv(GL_MODULATE);
@ -226,16 +224,16 @@ R_DrawSpriteModel(entity_t *e, const model_t *currentmodel)
1, 1
};
VectorMA( e->origin, -frame->origin_y, up, point[0] );
VectorMA( currententity->origin, -frame->origin_y, up, point[0] );
VectorMA( point[0], -frame->origin_x, right, point[0] );
VectorMA( e->origin, frame->height - frame->origin_y, up, point[1] );
VectorMA( currententity->origin, frame->height - frame->origin_y, up, point[1] );
VectorMA( point[1], -frame->origin_x, right, point[1] );
VectorMA( e->origin, frame->height - frame->origin_y, up, point[2] );
VectorMA( currententity->origin, frame->height - frame->origin_y, up, point[2] );
VectorMA( point[2], frame->width - frame->origin_x, right, point[2] );
VectorMA( e->origin, -frame->origin_y, up, point[3] );
VectorMA( currententity->origin, -frame->origin_y, up, point[3] );
VectorMA( point[3], frame->width - frame->origin_x, right, point[3] );
glEnableClientState( GL_VERTEX_ARRAY );
@ -260,7 +258,7 @@ R_DrawSpriteModel(entity_t *e, const model_t *currentmodel)
}
void
R_DrawNullModel(void)
R_DrawNullModel(entity_t *currententity)
{
vec3_t shadelight;
@ -270,7 +268,7 @@ R_DrawNullModel(void)
}
else
{
R_LightPoint(currententity->origin, shadelight);
R_LightPoint(currententity, currententity->origin, shadelight);
}
glPushMatrix();
@ -329,7 +327,7 @@ R_DrawEntitiesOnList(void)
/* draw non-transparent first */
for (i = 0; i < r_newrefdef.num_entities; i++)
{
currententity = &r_newrefdef.entities[i];
entity_t *currententity = &r_newrefdef.entities[i];
if (currententity->flags & RF_TRANSLUCENT)
{
@ -346,7 +344,7 @@ R_DrawEntitiesOnList(void)
if (!currentmodel)
{
R_DrawNullModel();
R_DrawNullModel(currententity);
continue;
}
@ -375,7 +373,7 @@ R_DrawEntitiesOnList(void)
for (i = 0; i < r_newrefdef.num_entities; i++)
{
currententity = &r_newrefdef.entities[i];
entity_t *currententity = &r_newrefdef.entities[i];
if (!(currententity->flags & RF_TRANSLUCENT))
{
@ -392,7 +390,7 @@ R_DrawEntitiesOnList(void)
if (!currentmodel)
{
R_DrawNullModel();
R_DrawNullModel(currententity);
continue;
}
@ -951,7 +949,7 @@ R_SetGL2D(void)
/*
* r_newrefdef must be set before the first call
*/
void
static void
R_RenderView(refdef_t *fd)
{
if ((gl_state.stereo_mode != STEREO_MODE_NONE) && gl_state.camera_separation) {
@ -1072,7 +1070,7 @@ R_RenderView(refdef_t *fd)
if (!r_worldmodel && !(r_newrefdef.rdflags & RDF_NOWORLDMODEL))
{
ri.Sys_Error(ERR_DROP, "R_RenderView: NULL worldmodel");
ri.Sys_Error(ERR_DROP, "%s: NULL worldmodel", __func__);
}
if (r_speeds->value)
@ -1149,8 +1147,8 @@ GL_GetSpecialBufferModeForStereoMode(enum stereo_modes stereo_mode) {
return OPENGL_SPECIAL_BUFFER_MODE_NONE;
}
void
R_SetLightLevel(void)
static void
R_SetLightLevel(entity_t *currententity)
{
vec3_t shadelight;
@ -1160,7 +1158,7 @@ R_SetLightLevel(void)
}
/* save off light value for server to look at */
R_LightPoint(r_newrefdef.vieworg, shadelight);
R_LightPoint(currententity, r_newrefdef.vieworg, shadelight);
/* pick the greatest component, which should be the
* same as the mono value returned by software */
@ -1188,11 +1186,11 @@ R_SetLightLevel(void)
}
}
void
static void
RI_RenderFrame(refdef_t *fd)
{
R_RenderView(fd);
R_SetLightLevel();
R_SetLightLevel (NULL);
R_SetGL2D();
}

View file

@ -45,8 +45,8 @@ float shadelight[3];
float *shadedots = r_avertexnormal_dots[0];
extern vec3_t lightspot;
void
R_LerpVerts(int nverts, dtrivertx_t *v, dtrivertx_t *ov,
static void
R_LerpVerts(entity_t *currententity, int nverts, dtrivertx_t *v, dtrivertx_t *ov,
dtrivertx_t *verts, float *lerp, float move[3],
float frontv[3], float backv[3])
{
@ -83,8 +83,8 @@ R_LerpVerts(int nverts, dtrivertx_t *v, dtrivertx_t *ov,
/*
* Interpolates between two frames and origins
*/
void
R_DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp)
static void
R_DrawAliasFrameLerp(entity_t *currententity, dmdl_t *paliashdr, float backlerp)
{
unsigned short total;
GLenum type;
@ -152,7 +152,7 @@ R_DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp)
lerp = s_lerped[0];
R_LerpVerts(paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv);
R_LerpVerts(currententity, paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv);
while (1)
{
@ -250,8 +250,8 @@ R_DrawAliasFrameLerp(dmdl_t *paliashdr, float backlerp)
}
}
void
R_DrawAliasShadow(dmdl_t *paliashdr, int posenum)
static void
R_DrawAliasShadow(entity_t *currententity, dmdl_t *paliashdr, int posenum)
{
unsigned short total;
GLenum type;
@ -482,7 +482,7 @@ R_CullAliasModel(const model_t *currentmodel, vec3_t bbox[8], entity_t *e)
}
void
R_DrawAliasModel(entity_t *e, const model_t *currentmodel)
R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
{
int i;
dmdl_t *paliashdr;
@ -490,15 +490,15 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel)
vec3_t bbox[8];
image_t *skin;
if (!(e->flags & RF_WEAPONMODEL))
if (!(currententity->flags & RF_WEAPONMODEL))
{
if (R_CullAliasModel(currentmodel, bbox, e))
if (R_CullAliasModel(currentmodel, bbox, currententity))
{
return;
}
}
if (e->flags & RF_WEAPONMODEL)
if (currententity->flags & RF_WEAPONMODEL)
{
if (gl_lefthand->value == 2)
{
@ -552,7 +552,7 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel)
}
else
{
R_LightPoint(currententity->origin, shadelight);
R_LightPoint(currententity, currententity->origin, shadelight);
/* player lighting hack for communication back to server */
if (currententity->flags & RF_WEAPONMODEL)
@ -695,9 +695,9 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel)
}
glPushMatrix();
e->angles[PITCH] = -e->angles[PITCH];
R_RotateForEntity(e);
e->angles[PITCH] = -e->angles[PITCH];
currententity->angles[PITCH] = -currententity->angles[PITCH];
R_RotateForEntity(currententity);
currententity->angles[PITCH] = -currententity->angles[PITCH];
/* select skin */
if (currententity->skin)
@ -761,7 +761,7 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel)
currententity->backlerp = 0;
}
R_DrawAliasFrameLerp(paliashdr, currententity->backlerp);
R_DrawAliasFrameLerp(currententity, paliashdr, currententity->backlerp);
R_TexEnv(GL_REPLACE);
glShadeModel(GL_FLAT);
@ -811,13 +811,13 @@ R_DrawAliasModel(entity_t *e, const model_t *currentmodel)
glPushMatrix();
/* don't rotate shadows on ungodly axes */
glTranslatef(e->origin[0], e->origin[1], e->origin[2]);
glRotatef(e->angles[1], 0, 0, 1);
glTranslatef(currententity->origin[0], currententity->origin[1], currententity->origin[2]);
glRotatef(currententity->angles[1], 0, 0, 1);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glColor4f(0, 0, 0, 0.5f);
R_DrawAliasShadow(paliashdr, currententity->frame);
R_DrawAliasShadow(currententity, paliashdr, currententity->frame);
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glPopMatrix();

View file

@ -46,7 +46,7 @@ void R_BuildLightMap(msurface_t *surf, byte *dest, int stride);
* Returns the proper texture for a given time and base texture
*/
static image_t *
R_TextureAnimation(mtexinfo_t *tex)
R_TextureAnimation(entity_t *currententity, mtexinfo_t *tex)
{
int c;
@ -421,7 +421,7 @@ R_BlendLightmaps(const model_t *currentmodel)
}
static void
R_RenderBrushPoly(msurface_t *fa)
R_RenderBrushPoly(entity_t *currententity, msurface_t *fa)
{
int maps;
image_t *image;
@ -429,7 +429,7 @@ R_RenderBrushPoly(msurface_t *fa)
c_brush_polys++;
image = R_TextureAnimation(fa->texinfo);
image = R_TextureAnimation(currententity, fa->texinfo);
if (fa->flags & SURF_DRAWTURB)
{
@ -605,7 +605,7 @@ R_DrawAlphaSurfaces(void)
}
static void
R_DrawTextureChains(void)
R_DrawTextureChains(entity_t *currententity)
{
int i;
msurface_t *s;
@ -631,7 +631,7 @@ R_DrawTextureChains(void)
for ( ; s; s = s->texturechain)
{
R_RenderBrushPoly(s);
R_RenderBrushPoly(currententity, s);
}
image->texturechain = NULL;
@ -641,7 +641,7 @@ R_DrawTextureChains(void)
}
static void
R_DrawInlineBModel(const model_t *currentmodel)
R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel)
{
int i, k;
cplane_t *pplane;
@ -689,7 +689,7 @@ R_DrawInlineBModel(const model_t *currentmodel)
}
else
{
R_RenderBrushPoly(psurf);
R_RenderBrushPoly(currententity, psurf);
}
}
}
@ -708,7 +708,7 @@ R_DrawInlineBModel(const model_t *currentmodel)
}
void
R_DrawBrushModel(entity_t *e, const model_t *currentmodel)
R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel)
{
vec3_t mins, maxs;
int i;
@ -719,24 +719,23 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel)
return;
}
currententity = e;
gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1;
if (e->angles[0] || e->angles[1] || e->angles[2])
if (currententity->angles[0] || currententity->angles[1] || currententity->angles[2])
{
rotated = true;
for (i = 0; i < 3; i++)
{
mins[i] = e->origin[i] - currentmodel->radius;
maxs[i] = e->origin[i] + currentmodel->radius;
mins[i] = currententity->origin[i] - currentmodel->radius;
maxs[i] = currententity->origin[i] + currentmodel->radius;
}
}
else
{
rotated = false;
VectorAdd(e->origin, currentmodel->mins, mins);
VectorAdd(e->origin, currentmodel->maxs, maxs);
VectorAdd(currententity->origin, currentmodel->mins, mins);
VectorAdd(currententity->origin, currentmodel->maxs, maxs);
}
if (R_CullBox(mins, maxs))
@ -752,7 +751,7 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel)
glColor4f(1, 1, 1, 1);
memset(gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));
VectorSubtract(r_newrefdef.vieworg, e->origin, modelorg);
VectorSubtract(r_newrefdef.vieworg, currententity->origin, modelorg);
if (rotated)
{
@ -760,18 +759,18 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel)
vec3_t forward, right, up;
VectorCopy(modelorg, temp);
AngleVectors(e->angles, forward, right, up);
AngleVectors(currententity->angles, forward, right, up);
modelorg[0] = DotProduct(temp, forward);
modelorg[1] = -DotProduct(temp, right);
modelorg[2] = DotProduct(temp, up);
}
glPushMatrix();
e->angles[0] = -e->angles[0];
e->angles[2] = -e->angles[2];
R_RotateForEntity(e);
e->angles[0] = -e->angles[0];
e->angles[2] = -e->angles[2];
currententity->angles[0] = -currententity->angles[0];
currententity->angles[2] = -currententity->angles[2];
R_RotateForEntity(currententity);
currententity->angles[0] = -currententity->angles[0];
currententity->angles[2] = -currententity->angles[2];
R_TexEnv(GL_REPLACE);
@ -784,7 +783,7 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel)
R_TexEnv(GL_MODULATE);
}
R_DrawInlineBModel(currentmodel);
R_DrawInlineBModel(currententity, currentmodel);
glPopMatrix();
@ -795,7 +794,7 @@ R_DrawBrushModel(entity_t *e, const model_t *currentmodel)
}
static void
R_RecursiveWorldNode(mnode_t *node)
R_RecursiveWorldNode(entity_t *currententity, mnode_t *node)
{
int c, side, sidebit;
cplane_t *plane;
@ -881,7 +880,7 @@ R_RecursiveWorldNode(mnode_t *node)
}
/* recurse down the children, front side first */
R_RecursiveWorldNode(node->children[side]);
R_RecursiveWorldNode(currententity, node->children[side]);
/* draw stuff */
for (c = node->numsurfaces,
@ -908,19 +907,19 @@ R_RecursiveWorldNode(mnode_t *node)
/* add to the translucent chain */
surf->texturechain = r_alpha_surfaces;
r_alpha_surfaces = surf;
r_alpha_surfaces->texinfo->image = R_TextureAnimation(surf->texinfo);
r_alpha_surfaces->texinfo->image = R_TextureAnimation(currententity, surf->texinfo);
}
else
{
/* the polygon is visible, so add it to the texture sorted chain */
image = R_TextureAnimation(surf->texinfo);
image = R_TextureAnimation(currententity, surf->texinfo);
surf->texturechain = image->texturechain;
image->texturechain = surf;
}
}
/* recurse down the back side */
R_RecursiveWorldNode(node->children[!side]);
R_RecursiveWorldNode(currententity, node->children[!side]);
}
void
@ -946,7 +945,6 @@ R_DrawWorld(void)
/* auto cycle the world frame for texture animation */
memset(&ent, 0, sizeof(ent));
ent.frame = (int)(r_newrefdef.time * 2);
currententity = &ent;
gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1;
@ -954,13 +952,11 @@ R_DrawWorld(void)
memset(gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));
R_ClearSkyBox();
R_RecursiveWorldNode(r_worldmodel->nodes);
R_DrawTextureChains();
R_RecursiveWorldNode(&ent, r_worldmodel->nodes);
R_DrawTextureChains(&ent);
R_BlendLightmaps(currentmodel);
R_DrawSkyBox();
R_DrawTriangleOutlines();
currententity = NULL;
}
/*

View file

@ -145,7 +145,6 @@ extern int numgltextures;
extern image_t *r_notexture;
extern image_t *r_particletexture;
extern entity_t *currententity;
extern int r_visframecount;
extern int r_framecount;
extern cplane_t frustum[4];
@ -243,7 +242,7 @@ void R_Bind(int texnum);
void R_TexEnv(GLenum value);
void R_LightPoint(vec3_t p, vec3_t color);
void R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color);
void R_PushDlights(void);
extern model_t *r_worldmodel;
@ -252,11 +251,10 @@ extern int registration_sequence;
void V_AddBlend(float r, float g, float b, float a, float *v_blend);
void R_RenderView(refdef_t *fd);
void R_ScreenShot(void);
void R_DrawAliasModel(entity_t *e, const model_t *currentmodel);
void R_DrawBrushModel(entity_t *e, const model_t *currentmodel);
void R_DrawSpriteModel(entity_t *e, const model_t *currentmodel);
void R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel);
void R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel);
void R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel);
void R_DrawBeam(entity_t *e);
void R_DrawWorld(void);
void R_RenderDlights(void);