From a22bbc8719701095aadf95d69c80eb4ef53103a0 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 15 Oct 2022 13:23:27 +0300 Subject: [PATCH] Image: Share Draw_FindPic --- src/client/refresh/files/pcx.c | 2 +- src/client/refresh/files/stb.c | 41 ++++++++++++++++++++++++++- src/client/refresh/gl1/gl1_draw.c | 25 ++++------------ src/client/refresh/gl1/gl1_main.c | 10 ------- src/client/refresh/gl1/header/local.h | 11 +++++++ src/client/refresh/gl3/gl3_draw.c | 25 ++++------------ src/client/refresh/ref_shared.h | 3 +- src/client/refresh/soft/sw_draw.c | 30 +++++++------------- 8 files changed, 76 insertions(+), 71 deletions(-) diff --git a/src/client/refresh/files/pcx.c b/src/client/refresh/files/pcx.c index fbda3146..89eb07b6 100644 --- a/src/client/refresh/files/pcx.c +++ b/src/client/refresh/files/pcx.c @@ -325,7 +325,7 @@ GetPCXPalette (byte **colormap, unsigned *d_8to24table) /* get the palette and colormap */ LoadPCX ("pics/colormap.pcx", colormap, &pal, NULL, NULL); - if (!colormap) + if (!*colormap || !pal) { ri.Sys_Error (ERR_FATAL, "Couldn't load pics/colormap.pcx"); } diff --git a/src/client/refresh/files/stb.c b/src/client/refresh/files/stb.c index 7d0929f7..7ceae69a 100644 --- a/src/client/refresh/files/stb.c +++ b/src/client/refresh/files/stb.c @@ -568,6 +568,7 @@ GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, struct image_s *image = NULL; char pathname[MAX_QPATH]; + /* Quake 2 */ if (palettedtexture) { Com_sprintf(pathname, sizeof(pathname), "env/%s%s.pcx", @@ -582,6 +583,7 @@ GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, image = find_image(pathname, it_sky); } + /* Heretic 2 */ if (!image) { Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m32", @@ -599,14 +601,17 @@ GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, return image; } -struct image_s *GetTexImage(const char *name, findimage_t find_image) +struct image_s * +GetTexImage(const char *name, findimage_t find_image) { struct image_s *image = NULL; char pathname[MAX_QPATH]; + /* Quake 2 */ Com_sprintf(pathname, sizeof(pathname), "textures/%s.wal", name); image = find_image(pathname, it_wall); + /* Heretic 2 */ if (!image) { Com_sprintf(pathname, sizeof(pathname), "textures/%s.m32", name); @@ -621,3 +626,37 @@ struct image_s *GetTexImage(const char *name, findimage_t find_image) return image; } + +struct image_s * +FindPic(const char *name, findimage_t find_image) +{ + struct image_s *image = NULL; + + if ((name[0] != '/') && (name[0] != '\\')) + { + char pathname[MAX_QPATH]; + + /* Quake 2 */ + Com_sprintf(pathname, sizeof(pathname), "pics/%s.pcx", name); + image = find_image(pathname, it_pic); + + /* Heretic 2 */ + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "pics/misc/%s.m32", name); + image = find_image(pathname, it_pic); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "pics/misc/%s.m8", name); + image = find_image(pathname, it_pic); + } + } + else + { + image = find_image(name + 1, it_pic); + } + + return image; +} diff --git a/src/client/refresh/gl1/gl1_draw.c b/src/client/refresh/gl1/gl1_draw.c index d1aef3e6..082bbceb 100644 --- a/src/client/refresh/gl1/gl1_draw.c +++ b/src/client/refresh/gl1/gl1_draw.c @@ -37,7 +37,7 @@ void Draw_InitLocal(void) { /* load console characters */ - draw_chars = R_FindImage("pics/conchars.pcx", it_pic); + draw_chars = FindPic("conchars", (findimage_t)R_FindImageUnsafe); if (!draw_chars) { ri.Sys_Error(ERR_FATAL, "Couldn't load pics/conchars.pcx"); @@ -106,20 +106,7 @@ RDraw_CharScaled(int x, int y, int num, float scale) image_t * RDraw_FindPic(char *name) { - image_t *gl; - char fullname[MAX_QPATH]; - - if ((name[0] != '/') && (name[0] != '\\')) - { - Com_sprintf(fullname, sizeof(fullname), "pics/%s.pcx", name); - gl = R_FindImage(fullname, it_pic); - } - else - { - gl = R_FindImage(name + 1, it_pic); - } - - return gl; + return FindPic(name, (findimage_t)R_FindImageUnsafe); } void @@ -127,7 +114,7 @@ RDraw_GetPicSize(int *w, int *h, char *pic) { image_t *gl; - gl = RDraw_FindPic(pic); + gl = FindPic(pic, (findimage_t)R_FindImageUnsafe); if (!gl) { @@ -144,7 +131,7 @@ RDraw_StretchPic(int x, int y, int w, int h, char *pic) { image_t *gl; - gl = RDraw_FindPic(pic); + gl = FindPic(pic, (findimage_t)R_FindImageUnsafe); if (!gl) { @@ -189,7 +176,7 @@ RDraw_PicScaled(int x, int y, char *pic, float factor) { image_t *gl; - gl = RDraw_FindPic(pic); + gl = FindPic(pic, (findimage_t)R_FindImageUnsafe); if (!gl) { @@ -239,7 +226,7 @@ RDraw_TileClear(int x, int y, int w, int h, char *pic) { image_t *image; - image = RDraw_FindPic(pic); + image = FindPic(pic, (findimage_t)R_FindImageUnsafe); if (!image) { diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index 3c013958..670854a1 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -1893,16 +1893,6 @@ extern void RI_EndRegistration(void); extern void RI_RenderFrame(refdef_t *fd); -extern image_t * RDraw_FindPic(char *name); -extern void RDraw_GetPicSize(int *w, int *h, char *pic); -extern void RDraw_PicScaled(int x, int y, char *pic, float factor); -extern void RDraw_StretchPic(int x, int y, int w, int h, char *pic); -extern void RDraw_CharScaled(int x, int y, int num, float scale); -extern void RDraw_TileClear(int x, int y, int w, int h, char *pic); -extern void RDraw_Fill(int x, int y, int w, int h, int c); -extern void RDraw_FadeScreen(void); -extern void RDraw_StretchRaw(int x, int y, int w, int h, int cols, int rows, byte *data); - extern void RI_SetPalette(const unsigned char *palette); extern qboolean RI_IsVSyncActive(void); extern void RI_EndFrame(void); diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index 055ad23d..58926ea0 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -390,4 +390,15 @@ void RI_ShutdownContext(void); */ void *RI_GetProcAddress (const char* proc); +/* g11_draw */ +extern image_t * RDraw_FindPic(char *name); +extern void RDraw_GetPicSize(int *w, int *h, char *pic); +extern void RDraw_PicScaled(int x, int y, char *pic, float factor); +extern void RDraw_StretchPic(int x, int y, int w, int h, char *pic); +extern void RDraw_CharScaled(int x, int y, int num, float scale); +extern void RDraw_TileClear(int x, int y, int w, int h, char *pic); +extern void RDraw_Fill(int x, int y, int w, int h, int c); +extern void RDraw_FadeScreen(void); +extern void RDraw_StretchRaw(int x, int y, int w, int h, int cols, int rows, byte *data); + #endif diff --git a/src/client/refresh/gl3/gl3_draw.c b/src/client/refresh/gl3/gl3_draw.c index e325e8b3..53c06fc3 100644 --- a/src/client/refresh/gl3/gl3_draw.c +++ b/src/client/refresh/gl3/gl3_draw.c @@ -37,7 +37,7 @@ void GL3_Draw_InitLocal(void) { /* load console characters */ - draw_chars = GL3_FindImage("pics/conchars.pcx", it_pic); + draw_chars = FindPic("conchars", (findimage_t)GL3_FindImageUnsafe); if (!draw_chars) { ri.Sys_Error(ERR_FATAL, "Couldn't load pics/conchars.pcx"); @@ -162,20 +162,7 @@ GL3_Draw_CharScaled(int x, int y, int num, float scale) gl3image_t * GL3_Draw_FindPic(char *name) { - gl3image_t *gl; - char fullname[MAX_QPATH]; - - if ((name[0] != '/') && (name[0] != '\\')) - { - Com_sprintf(fullname, sizeof(fullname), "pics/%s.pcx", name); - gl = GL3_FindImage(fullname, it_pic); - } - else - { - gl = GL3_FindImage(name + 1, it_pic); - } - - return gl; + return FindPic(name, (findimage_t)GL3_FindImageUnsafe); } void @@ -183,7 +170,7 @@ GL3_Draw_GetPicSize(int *w, int *h, char *pic) { gl3image_t *gl; - gl = GL3_Draw_FindPic(pic); + gl = FindPic(pic, (findimage_t)GL3_FindImageUnsafe); if (!gl) { @@ -198,7 +185,7 @@ GL3_Draw_GetPicSize(int *w, int *h, char *pic) void GL3_Draw_StretchPic(int x, int y, int w, int h, char *pic) { - gl3image_t *gl = GL3_Draw_FindPic(pic); + gl3image_t *gl = FindPic(pic, (findimage_t)GL3_FindImageUnsafe); if (!gl) { @@ -215,7 +202,7 @@ GL3_Draw_StretchPic(int x, int y, int w, int h, char *pic) void GL3_Draw_PicScaled(int x, int y, char *pic, float factor) { - gl3image_t *gl = GL3_Draw_FindPic(pic); + gl3image_t *gl = FindPic(pic, (findimage_t)GL3_FindImageUnsafe); if (!gl) { R_Printf(PRINT_ALL, "Can't find pic: %s\n", pic); @@ -236,7 +223,7 @@ GL3_Draw_PicScaled(int x, int y, char *pic, float factor) void GL3_Draw_TileClear(int x, int y, int w, int h, char *pic) { - gl3image_t *image = GL3_Draw_FindPic(pic); + gl3image_t *image = FindPic(pic, (findimage_t)GL3_FindImageUnsafe); if (!image) { R_Printf(PRINT_ALL, "Can't find pic: %s\n", pic); diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index 40b40f05..3bfe4608 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -104,7 +104,7 @@ extern float Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs); extern const byte* Mod_DecompressVis(const byte *in, int row); /* Shared models load */ -typedef struct image_s* (*findimage_t)(char *name, imagetype_t type); +typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type); extern void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen, vec3_t mins, vec3_t maxs, struct image_s **skins, findimage_t find_image, modtype_t *type); @@ -115,5 +115,6 @@ extern int Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, extern struct image_s *GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, findimage_t find_image); extern struct image_s *GetTexImage(const char *name, findimage_t find_image); +extern struct image_s *FindPic(const char *name, findimage_t find_image); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/client/refresh/soft/sw_draw.c b/src/client/refresh/soft/sw_draw.c index d078236c..e1f2e240 100644 --- a/src/client/refresh/soft/sw_draw.c +++ b/src/client/refresh/soft/sw_draw.c @@ -35,15 +35,7 @@ RE_Draw_FindPic image_t * RE_Draw_FindPic (char *name) { - if (name[0] != '/' && name[0] != '\\') - { - char fullname[MAX_QPATH]; - - Com_sprintf (fullname, sizeof(fullname), "pics/%s.pcx", name); - return R_FindImage (fullname, it_pic); - } - else - return R_FindImage (name+1, it_pic); + return FindPic(name, (findimage_t)R_FindImageUnsafe); } @@ -56,15 +48,13 @@ Draw_InitLocal void Draw_InitLocal (void) { - draw_chars = RE_Draw_FindPic ("conchars"); + draw_chars = FindPic ("conchars", (findimage_t)R_FindImageUnsafe); if (!draw_chars) { ri.Sys_Error(ERR_FATAL, "%s: Couldn't load pics/conchars.pcx", __func__); } } - - /* ================ Draw_Char @@ -156,16 +146,16 @@ RE_Draw_GetPicSize void RE_Draw_GetPicSize (int *w, int *h, char *name) { - image_t *gl; + image_t *image; - gl = RE_Draw_FindPic (name); - if (!gl) + image = FindPic (name, (findimage_t)R_FindImageUnsafe); + if (!image) { *w = *h = -1; return; } - *w = gl->asset_width; - *h = gl->asset_height; + *w = image->asset_width; + *h = image->asset_height; } /* @@ -316,7 +306,7 @@ RE_Draw_StretchPic (int x, int y, int w, int h, char *name) { image_t *pic; - pic = RE_Draw_FindPic (name); + pic = FindPic (name, (findimage_t)R_FindImageUnsafe); if (!pic) { R_Printf(PRINT_ALL, "Can't find pic: %s\n", name); @@ -389,7 +379,7 @@ RE_Draw_PicScaled(int x, int y, char *name, float scale) { image_t *pic; - pic = RE_Draw_FindPic (name); + pic = FindPic (name, (findimage_t)R_FindImageUnsafe); if (!pic) { R_Printf(PRINT_ALL, "Can't find pic: %s\n", name); @@ -439,7 +429,7 @@ RE_Draw_TileClear (int x, int y, int w, int h, char *name) VID_DamageBuffer(x, y); VID_DamageBuffer(x + w, y + h); - pic = RE_Draw_FindPic (name); + pic = FindPic (name, (findimage_t)R_FindImageUnsafe); if (!pic) { R_Printf(PRINT_ALL, "Can't find pic: %s\n", name);