]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake2/qdata_heretic2/sprites.c
set eol-style
[xonotic/netradiant.git] / tools / quake2 / qdata_heretic2 / sprites.c
index 68514c201d139f019fb858aef86c888b391ca33f..86854063556c901e92b74ee09665c40a68598f04 100644 (file)
-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-*/\r
-\r
-\r
-#include "qdata.h"\r
-\r
-#define MAX_SPRFRAMES                  MAX_MD2SKINS\r
-\r
-dsprite_t              sprite;\r
-dsprframe_t            frames[MAX_SPRFRAMES];\r
-\r
-byte                   *byteimage, *lbmpalette;\r
-int                            byteimagewidth, byteimageheight;\r
-\r
-qboolean               TrueColorImage;\r
-unsigned               *longimage;\r
-int                            longimagewidth, longimageheight;\r
-\r
-char                   spritename[1024];\r
-\r
-\r
-void FinishSprite (void);\r
-void Cmd_Spritename (void);\r
-\r
-char spr_prefix[1024];\r
-char pic_prefix[1024];\r
-\r
-extern         char            *g_outputDir;\r
-\r
-\r
-/*\r
-==============\r
-FinishSprite   \r
-==============\r
-*/\r
-void FinishSprite (void)\r
-{\r
-       FILE    *spriteouthandle;\r
-       int                     i, curframe;\r
-       dsprite_t       spritetemp;\r
-       char            savename[1024];\r
-\r
-       if (sprite.numframes == 0)\r
-               return;\r
-\r
-       if (!strlen(spritename))\r
-               Error ("Didn't name sprite file");\r
-               \r
-       sprintf (savename, "%sSprites/%s/%s.sp2", g_outputDir, spr_prefix, spritename);\r
-\r
-       if (g_release)\r
-       {\r
-               char    name[1024];\r
-\r
-               sprintf (name, "%s.sp2", spritename);\r
-               ReleaseFile (name);\r
-               spritename[0] = 0;              // clear for a new sprite\r
-               sprite.numframes = 0;\r
-               return;\r
-       }\r
-\r
-\r
-       printf ("saving in %s\n", savename);\r
-       CreatePath (savename);\r
-       spriteouthandle = SafeOpenWrite (savename);\r
-\r
-\r
-//\r
-// write out the sprite header\r
-//\r
-       spritetemp.ident = LittleLong (IDSPRITEHEADER);\r
-       spritetemp.version = LittleLong (SPRITE_VERSION);\r
-       spritetemp.numframes = LittleLong (sprite.numframes);\r
-\r
-       SafeWrite (spriteouthandle, &spritetemp, 12);\r
-\r
-//\r
-// write out the frames\r
-//\r
-       curframe = 0;\r
-\r
-       for (i=0 ; i<sprite.numframes ; i++)\r
-       {\r
-               frames[i].width = LittleLong(frames[i].width);\r
-               frames[i].height = LittleLong(frames[i].height);\r
-               frames[i].origin_x = LittleLong(frames[i].origin_x);\r
-               frames[i].origin_y = LittleLong(frames[i].origin_y);\r
-       }\r
-       SafeWrite (spriteouthandle, frames, sizeof(frames[0])*sprite.numframes);\r
-\r
-       fclose (spriteouthandle);\r
-       \r
-       spritename[0] = 0;              // clear for a new sprite\r
-       sprite.numframes = 0;\r
-}\r
-\r
-\r
-/*\r
-===============\r
-Cmd_Load\r
-===============\r
-*/\r
-void Cmd_Load (void)\r
-{\r
-       char    *name;\r
-\r
-       GetScriptToken (false);\r
-\r
-       if (g_release)\r
-               return;\r
-\r
-       name = ExpandPathAndArchive(token);\r
-\r
-       // load the image\r
-       printf ("loading %s\n", name);\r
-       TrueColorImage = LoadAnyImage (name, &byteimage, &lbmpalette, &byteimagewidth, &byteimageheight);\r
-\r
-       if (!TrueColorImage)\r
-       {\r
-//             RemapZero (byteimage, lbmpalette, byteimagewidth, byteimageheight);\r
-       }\r
-       else\r
-       {\r
-               if (longimage)\r
-                       free(longimage);\r
-               longimage = (unsigned *)byteimage;\r
-               longimagewidth = byteimagewidth;\r
-               longimageheight = byteimageheight;\r
-\r
-               byteimage = NULL;\r
-               byteimagewidth = 0;\r
-               byteimageheight = 0;\r
-       }\r
-}\r
-\r
-\r
-/*\r
-===============\r
-Cmd_SpriteFrame\r
-===============\r
-*/\r
-\r
-void Cmd_SpriteFrame (void)\r
-{\r
-       int             x,y,xl,yl,xh,yh,w,h;\r
-       dsprframe_t             *pframe;\r
-       int                             ox, oy, linedelta, size;\r
-//     byte                    *cropped;\r
-       char                    filename[1024];\r
-       miptex_t                *qtex;\r
-       miptex32_t              *qtex32;\r
-       unsigned        *destl, *sourcel;\r
-       unsigned                bufferl[256*256];\r
-       byte            *dest, *source;\r
-       byte                    buffer[256*256];\r
-\r
-       GetScriptToken (false);\r
-       xl = atoi (token);\r
-       GetScriptToken (false);\r
-       yl = atoi (token);\r
-       GetScriptToken (false);\r
-       w = atoi (token);\r
-       GetScriptToken (false);\r
-       h = atoi (token);\r
-\r
-       // origin offset is optional\r
-       if (ScriptTokenAvailable ())\r
-       {\r
-               GetScriptToken (false);\r
-               ox = atoi (token);\r
-               GetScriptToken (false);\r
-               oy = atoi (token);              \r
-       }\r
-       else\r
-       {\r
-               ox = w/2;\r
-               oy = h/2;\r
-       }\r
-\r
-       if ((xl & 0x0f) || (yl & 0x0f) || (w & 0x0f) || (h & 0x0f))\r
-               Error ("Sprite dimensions not multiples of 16\n");\r
-\r
-       if ((w > 256) || (h > 256))\r
-               Error ("Sprite has a dimension longer than 256");\r
-\r
-       xh = xl+w;\r
-       yh = yl+h;\r
-\r
-       if (sprite.numframes >= MAX_SPRFRAMES)\r
-               Error ("Too many frames; increase MAX_SPRFRAMES\n");\r
-\r
-       pframe = &frames[sprite.numframes];\r
-       pframe->width = w;\r
-       pframe->height = h;\r
-       pframe->origin_x = ox;\r
-       pframe->origin_y = oy;\r
-\r
-       if (g_release)\r
-       {\r
-               ReleaseFile (pframe->name);\r
-               return;\r
-       }\r
-\r
-       if (TrueColorImage)\r
-       {\r
-               sprintf (filename, "%ssprites/%s/%s_%i.m32", g_outputDir, spr_prefix, spritename, sprite.numframes);\r
-               sprintf (pframe->name, "%s/%s_%i.m32", spr_prefix, spritename, sprite.numframes);\r
-\r
-               if (g_release)\r
-                       return; // textures are only released by $maps\r
-\r
-               xh = xl+w;\r
-               yh = yl+h;\r
-\r
-               if (xl >= longimagewidth || xh > longimagewidth ||\r
-                       yl >= longimageheight || yh > longimageheight)\r
-               {\r
-                       Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,longimagewidth,longimageheight);\r
-               }\r
-\r
-               sourcel = longimage + (yl*longimagewidth) + xl;\r
-               destl = bufferl;\r
-               linedelta = (longimagewidth - w);\r
-\r
-               for (y=yl ; y<yh ; y++)\r
-               {\r
-                       for (x=xl ; x<xh ; x++)\r
-                       {\r
-                               *destl++ = *sourcel++;  // RGBA\r
-                       }\r
-                       sourcel += linedelta;\r
-               }\r
-\r
-               qtex32 = CreateMip32(bufferl, w, h, &size, true);\r
-\r
-               qtex32->contents = 0;\r
-               qtex32->value = 0;\r
-               strcpy(qtex32->name, pframe->name);\r
-       //\r
-       // write it out\r
-       //\r
-               printf ("writing %s\n", filename);\r
-               SaveFile (filename, (byte *)qtex32, size);\r
-\r
-               free (qtex32);\r
-       }\r
-       else\r
-       {\r
-               sprintf (filename, "%ssprites/%s/%s_%i.m8", g_outputDir, spr_prefix, spritename, sprite.numframes);\r
-               sprintf (pframe->name, "%s/%s_%i.m8", spr_prefix, spritename, sprite.numframes);\r
-\r
-               if (g_release)\r
-                       return; // textures are only released by $maps\r
-\r
-               xh = xl+w;\r
-               yh = yl+h;\r
-\r
-               if (xl >= byteimagewidth || xh > byteimagewidth ||\r
-                       yl >= byteimageheight || yh > byteimageheight)\r
-               {\r
-                       Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,byteimagewidth,byteimageheight);\r
-               }\r
-\r
-               source = byteimage + yl*byteimagewidth + xl;\r
-               dest = buffer;\r
-               linedelta = byteimagewidth - w;\r
-\r
-               for (y=yl ; y<yh ; y++)\r
-               {\r
-                       for (x=xl ; x<xh ; x++)\r
-                       {\r
-                               *dest++ = *source++;\r
-                       }\r
-                       source += linedelta;\r
-               }\r
-\r
-               qtex = CreateMip(buffer, w, h, lbmpalette, &size, true);\r
-\r
-               qtex->flags = 0;\r
-               qtex->contents = 0;\r
-               qtex->value = 0;\r
-               strcpy(qtex->name, pframe->name);\r
-       //\r
-       // write it out\r
-       //\r
-               printf ("writing %s\n", filename);\r
-               SaveFile (filename, (byte *)qtex, size);\r
-\r
-               free (qtex);\r
-       }\r
-\r
-       sprite.numframes++;\r
-}\r
-\r
-\r
-/*\r
-==============\r
-Cmd_SpriteName\r
-==============\r
-*/\r
-void Cmd_SpriteName (void)\r
-{\r
-       if (sprite.numframes)\r
-               FinishSprite ();\r
-\r
-       GetScriptToken (false);\r
-       strcpy (spritename, token);\r
-       memset (&sprite, 0, sizeof(sprite));\r
-       memset (&frames, 0, sizeof(frames));\r
-}\r
-\r
-\r
-/*\r
-===============\r
-Cmd_Sprdir\r
-===============\r
-*/\r
-void Cmd_Sprdir (void)\r
-{\r
-       char    filename[1024];\r
-\r
-       GetScriptToken (false);\r
-       strcpy (spr_prefix, token);\r
-       // create the directory if needed\r
-       sprintf (filename, "%sSprites", g_outputDir);\r
-       Q_mkdir (filename); \r
-       sprintf (filename, "%sSprites/%s", g_outputDir, spr_prefix);\r
-       Q_mkdir (filename); \r
-}\r
-\r
-\r
+/*
+Copyright (C) 1999-2007 id Software, Inc. and contributors.
+For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+This file is part of GtkRadiant.
+
+GtkRadiant 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.
+
+GtkRadiant 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 GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#include "qdata.h"
+
+#define MAX_SPRFRAMES                  MAX_MD2SKINS
+
+dsprite_t              sprite;
+dsprframe_t            frames[MAX_SPRFRAMES];
+
+byte                   *byteimage, *lbmpalette;
+int                            byteimagewidth, byteimageheight;
+
+qboolean               TrueColorImage;
+unsigned               *longimage;
+int                            longimagewidth, longimageheight;
+
+char                   spritename[1024];
+
+
+void FinishSprite (void);
+void Cmd_Spritename (void);
+
+char spr_prefix[1024];
+char pic_prefix[1024];
+
+extern         char            *g_outputDir;
+
+
+/*
+==============
+FinishSprite   
+==============
+*/
+void FinishSprite (void)
+{
+       FILE    *spriteouthandle;
+       int                     i, curframe;
+       dsprite_t       spritetemp;
+       char            savename[1024];
+
+       if (sprite.numframes == 0)
+               return;
+
+       if (!strlen(spritename))
+               Error ("Didn't name sprite file");
+               
+       sprintf (savename, "%sSprites/%s/%s.sp2", g_outputDir, spr_prefix, spritename);
+
+       if (g_release)
+       {
+               char    name[1024];
+
+               sprintf (name, "%s.sp2", spritename);
+               ReleaseFile (name);
+               spritename[0] = 0;              // clear for a new sprite
+               sprite.numframes = 0;
+               return;
+       }
+
+
+       printf ("saving in %s\n", savename);
+       CreatePath (savename);
+       spriteouthandle = SafeOpenWrite (savename);
+
+
+//
+// write out the sprite header
+//
+       spritetemp.ident = LittleLong (IDSPRITEHEADER);
+       spritetemp.version = LittleLong (SPRITE_VERSION);
+       spritetemp.numframes = LittleLong (sprite.numframes);
+
+       SafeWrite (spriteouthandle, &spritetemp, 12);
+
+//
+// write out the frames
+//
+       curframe = 0;
+
+       for (i=0 ; i<sprite.numframes ; i++)
+       {
+               frames[i].width = LittleLong(frames[i].width);
+               frames[i].height = LittleLong(frames[i].height);
+               frames[i].origin_x = LittleLong(frames[i].origin_x);
+               frames[i].origin_y = LittleLong(frames[i].origin_y);
+       }
+       SafeWrite (spriteouthandle, frames, sizeof(frames[0])*sprite.numframes);
+
+       fclose (spriteouthandle);
+       
+       spritename[0] = 0;              // clear for a new sprite
+       sprite.numframes = 0;
+}
+
+
+/*
+===============
+Cmd_Load
+===============
+*/
+void Cmd_Load (void)
+{
+       char    *name;
+
+       GetScriptToken (false);
+
+       if (g_release)
+               return;
+
+       name = ExpandPathAndArchive(token);
+
+       // load the image
+       printf ("loading %s\n", name);
+       TrueColorImage = LoadAnyImage (name, &byteimage, &lbmpalette, &byteimagewidth, &byteimageheight);
+
+       if (!TrueColorImage)
+       {
+//             RemapZero (byteimage, lbmpalette, byteimagewidth, byteimageheight);
+       }
+       else
+       {
+               if (longimage)
+                       free(longimage);
+               longimage = (unsigned *)byteimage;
+               longimagewidth = byteimagewidth;
+               longimageheight = byteimageheight;
+
+               byteimage = NULL;
+               byteimagewidth = 0;
+               byteimageheight = 0;
+       }
+}
+
+
+/*
+===============
+Cmd_SpriteFrame
+===============
+*/
+
+void Cmd_SpriteFrame (void)
+{
+       int             x,y,xl,yl,xh,yh,w,h;
+       dsprframe_t             *pframe;
+       int                             ox, oy, linedelta, size;
+//     byte                    *cropped;
+       char                    filename[1024];
+       miptex_t                *qtex;
+       miptex32_t              *qtex32;
+       unsigned        *destl, *sourcel;
+       unsigned                bufferl[256*256];
+       byte            *dest, *source;
+       byte                    buffer[256*256];
+
+       GetScriptToken (false);
+       xl = atoi (token);
+       GetScriptToken (false);
+       yl = atoi (token);
+       GetScriptToken (false);
+       w = atoi (token);
+       GetScriptToken (false);
+       h = atoi (token);
+
+       // origin offset is optional
+       if (ScriptTokenAvailable ())
+       {
+               GetScriptToken (false);
+               ox = atoi (token);
+               GetScriptToken (false);
+               oy = atoi (token);              
+       }
+       else
+       {
+               ox = w/2;
+               oy = h/2;
+       }
+
+       if ((xl & 0x0f) || (yl & 0x0f) || (w & 0x0f) || (h & 0x0f))
+               Error ("Sprite dimensions not multiples of 16\n");
+
+       if ((w > 256) || (h > 256))
+               Error ("Sprite has a dimension longer than 256");
+
+       xh = xl+w;
+       yh = yl+h;
+
+       if (sprite.numframes >= MAX_SPRFRAMES)
+               Error ("Too many frames; increase MAX_SPRFRAMES\n");
+
+       pframe = &frames[sprite.numframes];
+       pframe->width = w;
+       pframe->height = h;
+       pframe->origin_x = ox;
+       pframe->origin_y = oy;
+
+       if (g_release)
+       {
+               ReleaseFile (pframe->name);
+               return;
+       }
+
+       if (TrueColorImage)
+       {
+               sprintf (filename, "%ssprites/%s/%s_%i.m32", g_outputDir, spr_prefix, spritename, sprite.numframes);
+               sprintf (pframe->name, "%s/%s_%i.m32", spr_prefix, spritename, sprite.numframes);
+
+               if (g_release)
+                       return; // textures are only released by $maps
+
+               xh = xl+w;
+               yh = yl+h;
+
+               if (xl >= longimagewidth || xh > longimagewidth ||
+                       yl >= longimageheight || yh > longimageheight)
+               {
+                       Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,longimagewidth,longimageheight);
+               }
+
+               sourcel = longimage + (yl*longimagewidth) + xl;
+               destl = bufferl;
+               linedelta = (longimagewidth - w);
+
+               for (y=yl ; y<yh ; y++)
+               {
+                       for (x=xl ; x<xh ; x++)
+                       {
+                               *destl++ = *sourcel++;  // RGBA
+                       }
+                       sourcel += linedelta;
+               }
+
+               qtex32 = CreateMip32(bufferl, w, h, &size, true);
+
+               qtex32->contents = 0;
+               qtex32->value = 0;
+               strcpy(qtex32->name, pframe->name);
+       //
+       // write it out
+       //
+               printf ("writing %s\n", filename);
+               SaveFile (filename, (byte *)qtex32, size);
+
+               free (qtex32);
+       }
+       else
+       {
+               sprintf (filename, "%ssprites/%s/%s_%i.m8", g_outputDir, spr_prefix, spritename, sprite.numframes);
+               sprintf (pframe->name, "%s/%s_%i.m8", spr_prefix, spritename, sprite.numframes);
+
+               if (g_release)
+                       return; // textures are only released by $maps
+
+               xh = xl+w;
+               yh = yl+h;
+
+               if (xl >= byteimagewidth || xh > byteimagewidth ||
+                       yl >= byteimageheight || yh > byteimageheight)
+               {
+                       Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,byteimagewidth,byteimageheight);
+               }
+
+               source = byteimage + yl*byteimagewidth + xl;
+               dest = buffer;
+               linedelta = byteimagewidth - w;
+
+               for (y=yl ; y<yh ; y++)
+               {
+                       for (x=xl ; x<xh ; x++)
+                       {
+                               *dest++ = *source++;
+                       }
+                       source += linedelta;
+               }
+
+               qtex = CreateMip(buffer, w, h, lbmpalette, &size, true);
+
+               qtex->flags = 0;
+               qtex->contents = 0;
+               qtex->value = 0;
+               strcpy(qtex->name, pframe->name);
+       //
+       // write it out
+       //
+               printf ("writing %s\n", filename);
+               SaveFile (filename, (byte *)qtex, size);
+
+               free (qtex);
+       }
+
+       sprite.numframes++;
+}
+
+
+/*
+==============
+Cmd_SpriteName
+==============
+*/
+void Cmd_SpriteName (void)
+{
+       if (sprite.numframes)
+               FinishSprite ();
+
+       GetScriptToken (false);
+       strcpy (spritename, token);
+       memset (&sprite, 0, sizeof(sprite));
+       memset (&frames, 0, sizeof(frames));
+}
+
+
+/*
+===============
+Cmd_Sprdir
+===============
+*/
+void Cmd_Sprdir (void)
+{
+       char    filename[1024];
+
+       GetScriptToken (false);
+       strcpy (spr_prefix, token);
+       // create the directory if needed
+       sprintf (filename, "%sSprites", g_outputDir);
+       Q_mkdir (filename); 
+       sprintf (filename, "%sSprites/%s", g_outputDir, spr_prefix);
+       Q_mkdir (filename); 
+}
+
+