From 00e6a2f827b15d04d583d91db3865e6c3230748d Mon Sep 17 00:00:00 2001 From: lordhavoc Date: Fri, 12 Jan 2001 11:36:47 +0000 Subject: [PATCH] Fix for image replacement in sprites, now the sprite extension is stripped before the frame names are generated (so naming for s_explod.spr is like s_explod_0.tga, s_explod_1.tga, etc) and the extension stripping in the image loader will only strip off .lmp or .pcx or .tga, not other extensions, the sprite extension stripper is similar but for .spr and .spr32. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@127 d7cf8633-e32d-0410-b094-e92efae38249 --- image.c | 26 ++++++++++++++++++++++++-- model_sprite.c | 24 +++++++++++++++++++----- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/image.c b/image.c index a0bd89a3..e3b62d4b 100644 --- a/image.c +++ b/image.c @@ -407,12 +407,28 @@ byte* LoadLMP (FILE *f, int matchwidth, int matchheight) return image_rgba; } +void Image_StripImageExtension (char *in, char *out) +{ + byte *end; + end = in + strlen(in); + if ((end - in) >= 4) + { + if (strcmp(end - 4, ".tga") == 0 || strcmp(end - 4, ".pcx") == 0 || strcmp(end - 4, ".lmp") == 0) + end -= 4; + while (in < end) + *out++ = *in++; + *out++ = 0; + } + else + strcpy(out, in); +} + byte* loadimagepixels (char* filename, qboolean complain, int matchwidth, int matchheight) { FILE *f; - char basename[128], name[128]; + char basename[256], name[256]; byte *image_rgba, *c; - COM_StripExtension(filename, basename); // strip the extension to allow TGA skins on Q2 models despite the .pcx in the skin name + Image_StripImageExtension(filename, basename); // strip .tga, .pcx and .lmp extensions to allow replacement by other types // replace *'s with #, so commandline utils don't get confused when dealing with the external files for (c = basename;*c;c++) if (*c == '*') @@ -426,9 +442,15 @@ byte* loadimagepixels (char* filename, qboolean complain, int matchwidth, int ma if (f) return LoadPCX (f, matchwidth, matchheight); sprintf (name, "%s.tga", basename); + Con_Printf("name = %s : ", name); COM_FOpenFile (name, &f, true); if (f) + { + Con_Printf("succeeded\n"); return LoadTGA (f, matchwidth, matchheight); + } + else + Con_Printf("failed\n"); sprintf (name, "%s.pcx", basename); COM_FOpenFile (name, &f, true); if (f) diff --git a/model_sprite.c b/model_sprite.c index eaff930d..22de0177 100644 --- a/model_sprite.c +++ b/model_sprite.c @@ -33,6 +33,21 @@ void Mod_SpriteInit (void) { } +void Mod_Sprite_StripExtension(char *in, char *out) +{ + byte *end; + end = in + strlen(in); + if ((end - in) >= 6) + if (strcmp(end - 6, ".spr32") == 0) + end -= 6; + if ((end - in) >= 4) + if (strcmp(end - 4, ".spr") == 0) + end -= 4; + while (in < end) + *out++ = *in++; + *out++ = 0; +} + /* ================= Mod_LoadSpriteFrame @@ -43,7 +58,7 @@ void * Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int framenum, dspriteframe_t *pinframe; mspriteframe_t *pspriteframe; int i, width, height, size, origin[2]; - char name[64]; + char name[256], tempname[256]; byte *pixbuf, *pixel, *inpixel; pinframe = (dspriteframe_t *)pin; @@ -68,8 +83,9 @@ void * Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int framenum, pspriteframe->left = origin[0]; pspriteframe->right = width + origin[0]; - sprintf (name, "%s_%i", loadmodel->name, framenum); - pspriteframe->gl_texturenum = loadtextureimagewithmask(name, 0, 0, false, true); + Mod_Sprite_StripExtension(loadmodel->name, tempname); + sprintf (name, "%s_%i", tempname, framenum); + pspriteframe->gl_texturenum = loadtextureimagewithmask(name, 0, 0, true, true); pspriteframe->gl_fogtexturenum = image_masktexnum; if (pspriteframe->gl_texturenum == 0) { @@ -155,9 +171,7 @@ void * Mod_LoadSpriteGroup (void * pin, mspriteframe_t **ppframe, int framenum, ptemp = (void *)pin_intervals; for (i=0 ; iframes[i], framenum * 100 + i, bytesperpixel); - } return ptemp; } -- 2.39.2