]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake2/qdata_heretic2/sprites.c
my own uncrustify run
[xonotic/netradiant.git] / tools / quake2 / qdata_heretic2 / sprites.c
index bd9d8bf2dfef37783453f8269b6a642f1e432071..098e6a1452ca1333866a566dc595c243808b2dba 100644 (file)
 /*
 /*
-Copyright (C) 1999-2006 Id Software, Inc. and contributors.
-For a list of contributors, see the accompanying CONTRIBUTORS file.
+   Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+   For a list of contributors, see the accompanying CONTRIBUTORS file.
 
 
-This file is part of GtkRadiant.
+   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 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.
+   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
-*/
+   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"
 
 
 
 #include "qdata.h"
 
-#define MAX_SPRFRAMES                  MAX_MD2SKINS
+#define MAX_SPRFRAMES           MAX_MD2SKINS
 
 
-dsprite_t              sprite;
-dsprframe_t            frames[MAX_SPRFRAMES];
+dsprite_t sprite;
+dsprframe_t frames[MAX_SPRFRAMES];
 
 
-byte                   *byteimage, *lbmpalette;
-int                            byteimagewidth, byteimageheight;
+byte            *byteimage, *lbmpalette;
+int byteimagewidth, byteimageheight;
 
 
-qboolean               TrueColorImage;
-unsigned               *longimage;
-int                            longimagewidth, longimageheight;
+qboolean TrueColorImage;
+unsigned        *longimage;
+int longimagewidth, longimageheight;
 
 
-char                   spritename[1024];
+char spritename[1024];
 
 
 
 
-void FinishSprite (void);
-void Cmd_Spritename (void);
+void FinishSprite( void );
+void Cmd_Spritename( void );
 
 char spr_prefix[1024];
 char pic_prefix[1024];
 
 
 char spr_prefix[1024];
 char pic_prefix[1024];
 
-extern         char            *g_outputDir;
+extern char        *g_outputDir;
 
 
 /*
 
 
 /*
-==============
-FinishSprite   
-==============
-*/
-void FinishSprite (void)
-{
-       FILE    *spriteouthandle;
-       int                     i, curframe;
-       dsprite_t       spritetemp;
-       char            savename[1024];
-
-       if (sprite.numframes == 0)
+   ==============
+   FinishSprite
+   ==============
+ */
+void FinishSprite( void ){
+       FILE    *spriteouthandle;
+       int i, curframe;
+       dsprite_t spritetemp;
+       char savename[1024];
+
+       if ( sprite.numframes == 0 ) {
                return;
                return;
+       }
 
 
-       if (!strlen(spritename))
-               Error ("Didn't name sprite file");
-               
-       sprintf (savename, "%sSprites/%s/%s.sp2", g_outputDir, spr_prefix, spritename);
+       if ( !strlen( spritename ) ) {
+               Error( "Didn't name sprite file" );
+       }
 
 
-       if (g_release)
-       {
-               char    name[1024];
+       sprintf( savename, "%sSprites/%s/%s.sp2", g_outputDir, spr_prefix, spritename );
 
 
-               sprintf (name, "%s.sp2", spritename);
-               ReleaseFile (name);
-               spritename[0] = 0;              // clear for a new sprite
+       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;
        }
 
 
                sprite.numframes = 0;
                return;
        }
 
 
-       printf ("saving in %s\n", savename);
-       CreatePath (savename);
-       spriteouthandle = SafeOpenWrite (savename);
+       printf( "saving in %s\n", savename );
+       CreatePath( savename );
+       spriteouthandle = SafeOpenWrite( savename );
 
 
 //
 // write out the sprite header
 //
 
 
 //
 // write out the sprite header
 //
-       spritetemp.ident = LittleLong (IDSPRITEHEADER);
-       spritetemp.version = LittleLong (SPRITE_VERSION);
-       spritetemp.numframes = LittleLong (sprite.numframes);
+       spritetemp.ident = LittleLong( IDSPRITEHEADER );
+       spritetemp.version = LittleLong( SPRITE_VERSION );
+       spritetemp.numframes = LittleLong( sprite.numframes );
 
 
-       SafeWrite (spriteouthandle, &spritetemp, 12);
+       SafeWrite( spriteouthandle, &spritetemp, 12 );
 
 //
 // write out the frames
 //
        curframe = 0;
 
 
 //
 // write out the frames
 //
        curframe = 0;
 
-       for (i=0 ; i<sprite.numframes ; i++)
+       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);
+               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);
+       SafeWrite( spriteouthandle, frames, sizeof( frames[0] ) * sprite.numframes );
+
+       fclose( spriteouthandle );
 
 
-       fclose (spriteouthandle);
-       
-       spritename[0] = 0;              // clear for a new sprite
+       spritename[0] = 0;      // clear for a new sprite
        sprite.numframes = 0;
 }
 
 
 /*
        sprite.numframes = 0;
 }
 
 
 /*
-===============
-Cmd_Load
-===============
-*/
-void Cmd_Load (void)
-{
-       char    *name;
+   ===============
+   Cmd_Load
+   ===============
+ */
+void Cmd_Load( void ){
+       char    *name;
 
 
-       GetScriptToken (false);
+       GetScriptToken( false );
 
 
-       if (g_release)
+       if ( g_release ) {
                return;
                return;
+       }
 
 
-       name = ExpandPathAndArchive(token);
+       name = ExpandPathAndArchive( token );
 
        // load the image
 
        // load the image
-       printf ("loading %s\n", name);
-       TrueColorImage = LoadAnyImage (name, &byteimage, &lbmpalette, &byteimagewidth, &byteimageheight);
+       printf( "loading %s\n", name );
+       TrueColorImage = LoadAnyImage( name, &byteimage, &lbmpalette, &byteimagewidth, &byteimageheight );
 
 
-       if (!TrueColorImage)
-       {
+       if ( !TrueColorImage ) {
 //             RemapZero (byteimage, lbmpalette, byteimagewidth, byteimageheight);
        }
        else
        {
 //             RemapZero (byteimage, lbmpalette, byteimagewidth, byteimageheight);
        }
        else
        {
-               if (longimage)
-                       free(longimage);
+               if ( longimage ) {
+                       free( longimage );
+               }
                longimage = (unsigned *)byteimage;
                longimagewidth = byteimagewidth;
                longimageheight = byteimageheight;
                longimage = (unsigned *)byteimage;
                longimagewidth = byteimagewidth;
                longimageheight = byteimageheight;
@@ -153,59 +153,60 @@ void Cmd_Load (void)
 
 
 /*
 
 
 /*
-===============
-Cmd_SpriteFrame
-===============
-*/
-
-void Cmd_SpriteFrame (void)
-{
-       int             x,y,xl,yl,xh,yh,w,h;
-       dsprframe_t             *pframe;
-       int                             ox, oy, linedelta, size;
+   ===============
+   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;
 //     byte                    *cropped;
-       char                    filename[1024];
-       miptex_t                *qtex;
-       miptex32_t              *qtex32;
+       char filename[1024];
+       miptex_t        *qtex;
+       miptex32_t      *qtex32;
        unsigned        *destl, *sourcel;
        unsigned        *destl, *sourcel;
-       unsigned                bufferl[256*256];
+       unsigned bufferl[256 * 256];
        byte            *dest, *source;
        byte            *dest, *source;
-       byte                    buffer[256*256];
+       byte buffer[256 * 256];
 
 
-       GetScriptToken (false);
-       xl = atoi (token);
-       GetScriptToken (false);
-       yl = atoi (token);
-       GetScriptToken (false);
-       w = atoi (token);
-       GetScriptToken (false);
-       h = atoi (token);
+       GetScriptToken( false );
+       xl = atoi( token );
+       GetScriptToken( false );
+       yl = atoi( token );
+       GetScriptToken( false );
+       w = atoi( token );
+       GetScriptToken( false );
+       h = atoi( token );
 
        // origin offset is optional
 
        // origin offset is optional
-       if (ScriptTokenAvailable ())
-       {
-               GetScriptToken (false);
-               ox = atoi (token);
-               GetScriptToken (false);
-               oy = atoi (token);              
+       if ( ScriptTokenAvailable() ) {
+               GetScriptToken( false );
+               ox = atoi( token );
+               GetScriptToken( false );
+               oy = atoi( token );
        }
        else
        {
        }
        else
        {
-               ox = w/2;
-               oy = h/2;
+               ox = w / 2;
+               oy = h / 2;
        }
 
        }
 
-       if ((xl & 0x0f) || (yl & 0x0f) || (w & 0x0f) || (h & 0x0f))
-               Error ("Sprite dimensions not multiples of 16\n");
+       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");
+       if ( ( w > 256 ) || ( h > 256 ) ) {
+               Error( "Sprite has a dimension longer than 256" );
+       }
 
 
-       xh = xl+w;
-       yh = yl+h;
+       xh = xl + w;
+       yh = yl + h;
 
 
-       if (sprite.numframes >= MAX_SPRFRAMES)
-               Error ("Too many frames; increase MAX_SPRFRAMES\n");
+       if ( sprite.numframes >= MAX_SPRFRAMES ) {
+               Error( "Too many frames; increase MAX_SPRFRAMES\n" );
+       }
 
        pframe = &frames[sprite.numframes];
        pframe->width = w;
 
        pframe = &frames[sprite.numframes];
        pframe->width = w;
@@ -213,98 +214,96 @@ void Cmd_SpriteFrame (void)
        pframe->origin_x = ox;
        pframe->origin_y = oy;
 
        pframe->origin_x = ox;
        pframe->origin_y = oy;
 
-       if (g_release)
-       {
-               ReleaseFile (pframe->name);
+       if ( g_release ) {
+               ReleaseFile( pframe->name );
                return;
        }
 
                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 ( 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
+               if ( g_release ) {
+                       return; // textures are only released by $maps
 
 
-               xh = xl+w;
-               yh = yl+h;
+               }
+               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);
+               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;
+               sourcel = longimage + ( yl * longimagewidth ) + xl;
                destl = bufferl;
                destl = bufferl;
-               linedelta = (longimagewidth - w);
+               linedelta = ( longimagewidth - w );
 
 
-               for (y=yl ; y<yh ; y++)
+               for ( y = yl ; y < yh ; y++ )
                {
                {
-                       for (x=xl ; x<xh ; x++)
+                       for ( x = xl ; x < xh ; x++ )
                        {
                        {
-                               *destl++ = *sourcel++;  // RGBA
+                               *destl++ = *sourcel++;  // RGBA
                        }
                        sourcel += linedelta;
                }
 
                        }
                        sourcel += linedelta;
                }
 
-               qtex32 = CreateMip32(bufferl, w, h, &size, true);
+               qtex32 = CreateMip32( bufferl, w, h, &size, true );
 
                qtex32->contents = 0;
                qtex32->value = 0;
 
                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);
+               strcpy( qtex32->name, pframe->name );
+               //
+               // write it out
+               //
+               printf( "writing %s\n", filename );
+               SaveFile( filename, (byte *)qtex32, size );
+
+               free( qtex32 );
        }
        else
        {
        }
        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);
+               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
+               if ( g_release ) {
+                       return; // textures are only released by $maps
 
 
-               xh = xl+w;
-               yh = yl+h;
+               }
+               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);
+               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;
+               source = byteimage + yl * byteimagewidth + xl;
                dest = buffer;
                linedelta = byteimagewidth - w;
 
                dest = buffer;
                linedelta = byteimagewidth - w;
 
-               for (y=yl ; y<yh ; y++)
+               for ( y = yl ; y < yh ; y++ )
                {
                {
-                       for (x=xl ; x<xh ; x++)
+                       for ( x = xl ; x < xh ; x++ )
                        {
                                *dest++ = *source++;
                        }
                        source += linedelta;
                }
 
                        {
                                *dest++ = *source++;
                        }
                        source += linedelta;
                }
 
-               qtex = CreateMip(buffer, w, h, lbmpalette, &size, true);
+               qtex = CreateMip( buffer, w, h, lbmpalette, &size, true );
 
                qtex->flags = 0;
                qtex->contents = 0;
                qtex->value = 0;
 
                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);
+               strcpy( qtex->name, pframe->name );
+               //
+               // write it out
+               //
+               printf( "writing %s\n", filename );
+               SaveFile( filename, (byte *)qtex, size );
+
+               free( qtex );
        }
 
        sprite.numframes++;
        }
 
        sprite.numframes++;
@@ -312,38 +311,35 @@ void Cmd_SpriteFrame (void)
 
 
 /*
 
 
 /*
-==============
-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_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);
+   ===============
+   Cmd_Sprdir
+   ===============
+ */
+void Cmd_Sprdir( void ){
+       char filename[1024];
+
+       GetScriptToken( false );
+       strcpy( spr_prefix, token );
        // create the directory if needed
        // create the directory if needed
-       sprintf (filename, "%sSprites", g_outputDir);
-       Q_mkdir (filename); 
-       sprintf (filename, "%sSprites/%s", g_outputDir, spr_prefix);
-       Q_mkdir (filename); 
+       sprintf( filename, "%sSprites", g_outputDir );
+       Q_mkdir( filename );
+       sprintf( filename, "%sSprites/%s", g_outputDir, spr_prefix );
+       Q_mkdir( filename );
 }
 }
-
-