]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Fix for image replacement in sprites, now the sprite extension is stripped before...
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 12 Jan 2001 11:36:47 +0000 (11:36 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 12 Jan 2001 11:36:47 +0000 (11:36 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@127 d7cf8633-e32d-0410-b094-e92efae38249

image.c
model_sprite.c

diff --git a/image.c b/image.c
index a0bd89a3bc26cd5ea24ee43bd43d1dd7dcea6d03..e3b62d4bd2166835603824926a277193480564c4 100644 (file)
--- 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)
index eaff930db14855196e87efb8e2f3d309d24b0a98..22de0177abf12a4900ddb103825bb70131dc3a22 100644 (file)
@@ -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 ; i<numframes ; i++)
-       {
                ptemp = Mod_LoadSpriteFrame (ptemp, &pspritegroup->frames[i], framenum * 100 + i, bytesperpixel);
-       }
 
        return ptemp;
 }