From c17210b34aa4886603cec665d3ea78be3f936277 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 30 Oct 2022 21:44:21 +0200 Subject: [PATCH] Share R_TextureAnimation --- Makefile | 3 ++ src/client/refresh/files/surf.c | 55 +++++++++++++++++++++++++++++++ src/client/refresh/gl1/gl1_surf.c | 24 -------------- src/client/refresh/gl3/gl3_surf.c | 33 +++---------------- src/client/refresh/ref_shared.h | 1 + src/client/refresh/soft/sw_surf.c | 28 ---------------- 6 files changed, 63 insertions(+), 81 deletions(-) create mode 100644 src/client/refresh/files/surf.c diff --git a/Makefile b/Makefile index 14cd0aa4..0abddcd2 100644 --- a/Makefile +++ b/Makefile @@ -927,6 +927,7 @@ REFGL1_OBJS_ := \ src/client/refresh/gl1/gl1_surf.o \ src/client/refresh/gl1/gl1_warp.o \ src/client/refresh/gl1/gl1_sdl.o \ + src/client/refresh/files/surf.o \ src/client/refresh/files/models.o \ src/client/refresh/files/pcx.o \ src/client/refresh/files/stb.o \ @@ -958,6 +959,7 @@ REFGL3_OBJS_ := \ src/client/refresh/gl3/gl3_surf.o \ src/client/refresh/gl3/gl3_warp.o \ src/client/refresh/gl3/gl3_shaders.o \ + src/client/refresh/files/surf.o \ src/client/refresh/files/models.o \ src/client/refresh/files/pcx.o \ src/client/refresh/files/stb.o \ @@ -1000,6 +1002,7 @@ REFSOFT_OBJS_ := \ src/client/refresh/soft/sw_scan.o \ src/client/refresh/soft/sw_sprite.o \ src/client/refresh/soft/sw_surf.o \ + src/client/refresh/files/surf.o \ src/client/refresh/files/models.o \ src/client/refresh/files/pcx.o \ src/client/refresh/files/stb.o \ diff --git a/src/client/refresh/files/surf.c b/src/client/refresh/files/surf.c new file mode 100644 index 00000000..512411be --- /dev/null +++ b/src/client/refresh/files/surf.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 1997-2001 Id Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Surface logic + * + * ======================================================================= + */ + +#include "../ref_shared.h" + +/* +=============== +R_TextureAnimation + +Returns the proper texture for a given time and base texture +=============== +*/ +struct image_s * +R_TextureAnimation(const entity_t *currententity, const mtexinfo_t *tex) +{ + int c; + + if (!tex->next) + return tex->image; + + if (!currententity) + return tex->image; + + c = currententity->frame % tex->numframes; + while (c && tex) + { + tex = tex->next; + c--; + } + + return tex->image; +} diff --git a/src/client/refresh/gl1/gl1_surf.c b/src/client/refresh/gl1/gl1_surf.c index f420dafa..06a9b96b 100644 --- a/src/client/refresh/gl1/gl1_surf.c +++ b/src/client/refresh/gl1/gl1_surf.c @@ -42,30 +42,6 @@ qboolean LM_AllocBlock(int w, int h, int *x, int *y); void R_SetCacheState(msurface_t *surf); 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(entity_t *currententity, mtexinfo_t *tex) -{ - int c; - - if (!tex->next) - { - return tex->image; - } - - c = currententity->frame % tex->numframes; - - while (c) - { - tex = tex->next; - c--; - } - - return tex->image; -} - static void R_DrawGLPoly(glpoly_t *p) { diff --git a/src/client/refresh/gl3/gl3_surf.c b/src/client/refresh/gl3/gl3_surf.c index ece8098b..846c30da 100644 --- a/src/client/refresh/gl3/gl3_surf.c +++ b/src/client/refresh/gl3/gl3_surf.c @@ -156,31 +156,6 @@ CullBox(vec3_t mins, vec3_t maxs) return false; } -/* - * Returns the proper texture for a given time and base texture - */ -static gl3image_t * -TextureAnimation(entity_t *currententity, mtexinfo_t *tex) -{ - int c; - - if (!tex->next) - { - return tex->image; - } - - c = currententity->frame % tex->numframes; - - while (c) - { - tex = tex->next; - c--; - } - - return tex->image; -} - - static void SetLightFlags(msurface_t *surf) { @@ -345,7 +320,7 @@ RenderBrushPoly(entity_t *currententity, msurface_t *fa) c_brush_polys++; - image = TextureAnimation(currententity, fa->texinfo); + image = R_TextureAnimation(currententity, fa->texinfo); if (fa->flags & SURF_DRAWTURB) { @@ -490,7 +465,7 @@ static void RenderLightmappedPoly(entity_t *currententity, msurface_t *surf) { int map; - gl3image_t *image = TextureAnimation(currententity, surf->texinfo); + gl3image_t *image = R_TextureAnimation(currententity, surf->texinfo); hmm_vec4 lmScales[MAX_LIGHTMAPS_PER_SURFACE] = {0}; lmScales[0] = HMM_Vec4(1.0f, 1.0f, 1.0f, 1.0f); @@ -782,7 +757,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node) /* add to the translucent chain */ surf->texturechain = gl3_alpha_surfaces; gl3_alpha_surfaces = surf; - gl3_alpha_surfaces->texinfo->image = TextureAnimation(currententity, surf->texinfo); + gl3_alpha_surfaces->texinfo->image = R_TextureAnimation(currententity, surf->texinfo); } else { @@ -798,7 +773,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node) #endif // 0 { /* the polygon is visible, so add it to the texture sorted chain */ - image = TextureAnimation(currententity, surf->texinfo); + image = R_TextureAnimation(currententity, surf->texinfo); surf->texturechain = image->texturechain; image->texturechain = surf; } diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index c133337d..611004a5 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -208,5 +208,6 @@ extern void Mod_LoadSurfedges (const char *name, int **surfedges, int *numsurfed const byte *mod_base, const lump_t *l, int extra); extern int Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra); extern mleaf_t *Mod_PointInLeaf(const vec3_t p, mnode_t *node); +extern struct image_s *R_TextureAnimation(const entity_t *currententity, const mtexinfo_t *tex); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/client/refresh/soft/sw_surf.c b/src/client/refresh/soft/sw_surf.c index 28cec1e7..32c7c10e 100644 --- a/src/client/refresh/soft/sw_surf.c +++ b/src/client/refresh/soft/sw_surf.c @@ -36,34 +36,6 @@ static int sc_size; static surfcache_t *sc_rover; surfcache_t *sc_base; -/* -=============== -R_TextureAnimation - -Returns the proper texture for a given time and base texture -=============== -*/ -static image_t * -R_TextureAnimation (const entity_t *currententity, mtexinfo_t *tex) -{ - int c; - - if (!tex->next) - return tex->image; - - if (!currententity) - return tex->image; - - c = currententity->frame % tex->numframes; - while (c && tex) - { - tex = tex->next; - c--; - } - - return tex->image; -} - /* * Color light apply is not required */