Image: Share Draw_FindPic

This commit is contained in:
Denis Pauk 2022-10-15 13:23:27 +03:00
parent 395641e1dc
commit a22bbc8719
8 changed files with 76 additions and 71 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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_ */

View file

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