2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "qdata.h"
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define MAX_SPRFRAMES MAX_MD2SKINS
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dsprite_t sprite;
|
|
|
|
dsprframe_t frames[MAX_SPRFRAMES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
byte *byteimage, *lbmpalette;
|
|
|
|
int byteimagewidth, byteimageheight;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean TrueColorImage;
|
|
|
|
unsigned *longimage;
|
|
|
|
int longimagewidth, longimageheight;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char spritename[1024];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void FinishSprite( void );
|
|
|
|
void Cmd_Spritename( void );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
char spr_prefix[1024];
|
|
|
|
char pic_prefix[1024];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern char *g_outputDir;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============
|
|
|
|
FinishSprite
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void FinishSprite( void ){
|
|
|
|
FILE *spriteouthandle;
|
|
|
|
int i, curframe;
|
|
|
|
dsprite_t spritetemp;
|
|
|
|
char savename[1024];
|
|
|
|
|
|
|
|
if ( sprite.numframes == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strlen( spritename ) ) {
|
|
|
|
Error( "Didn't name sprite file" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( savename, "%sSprites/%s/%s.sp2", g_outputDir, spr_prefix, spritename );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release ) {
|
|
|
|
char name[1024];
|
|
|
|
|
|
|
|
sprintf( name, "%s.sp2", spritename );
|
|
|
|
ReleaseFile( name );
|
|
|
|
spritename[0] = 0; // clear for a new sprite
|
2007-11-04 03:34:51 +00:00
|
|
|
sprite.numframes = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "saving in %s\n", savename );
|
|
|
|
CreatePath( savename );
|
|
|
|
spriteouthandle = SafeOpenWrite( savename );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// write out the sprite header
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
spritetemp.ident = LittleLong( IDSPRITEHEADER );
|
|
|
|
spritetemp.version = LittleLong( SPRITE_VERSION );
|
|
|
|
spritetemp.numframes = LittleLong( sprite.numframes );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( spriteouthandle, &spritetemp, 12 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write out the frames
|
|
|
|
//
|
|
|
|
curframe = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < sprite.numframes ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
SafeWrite( spriteouthandle, frames, sizeof( frames[0] ) * sprite.numframes );
|
|
|
|
|
|
|
|
fclose( spriteouthandle );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
spritename[0] = 0; // clear for a new sprite
|
2007-11-04 03:34:51 +00:00
|
|
|
sprite.numframes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_Load
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Cmd_Load( void ){
|
|
|
|
char *name;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetScriptToken( false );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
name = ExpandPathAndArchive( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// load the image
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "loading %s\n", name );
|
|
|
|
TrueColorImage = LoadAnyImage( name, &byteimage, &lbmpalette, &byteimagewidth, &byteimageheight );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !TrueColorImage ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// RemapZero (byteimage, lbmpalette, byteimagewidth, byteimageheight);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( longimage ) {
|
|
|
|
free( longimage );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
longimage = (unsigned *)byteimage;
|
|
|
|
longimagewidth = byteimagewidth;
|
|
|
|
longimageheight = byteimageheight;
|
|
|
|
|
|
|
|
byteimage = NULL;
|
|
|
|
byteimagewidth = 0;
|
|
|
|
byteimageheight = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_SpriteFrame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Cmd_SpriteFrame( void ){
|
|
|
|
int x,y,xl,yl,xh,yh,w,h;
|
|
|
|
dsprframe_t *pframe;
|
|
|
|
int ox, oy, linedelta, size;
|
2007-11-04 03:34:51 +00:00
|
|
|
// byte *cropped;
|
2012-03-17 20:01:54 +00:00
|
|
|
char filename[1024];
|
|
|
|
miptex_t *qtex;
|
|
|
|
miptex32_t *qtex32;
|
2007-11-04 03:34:51 +00:00
|
|
|
unsigned *destl, *sourcel;
|
2012-03-17 20:01:54 +00:00
|
|
|
unsigned bufferl[256 * 256];
|
2007-11-04 03:34:51 +00:00
|
|
|
byte *dest, *source;
|
2012-03-17 20:01:54 +00:00
|
|
|
byte buffer[256 * 256];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetScriptToken( false );
|
|
|
|
xl = atoi( token );
|
|
|
|
GetScriptToken( false );
|
|
|
|
yl = atoi( token );
|
|
|
|
GetScriptToken( false );
|
|
|
|
w = atoi( token );
|
|
|
|
GetScriptToken( false );
|
|
|
|
h = atoi( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// origin offset is optional
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ScriptTokenAvailable() ) {
|
|
|
|
GetScriptToken( false );
|
|
|
|
ox = atoi( token );
|
|
|
|
GetScriptToken( false );
|
|
|
|
oy = atoi( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
ox = w / 2;
|
|
|
|
oy = h / 2;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( xl & 0x0f ) || ( yl & 0x0f ) || ( w & 0x0f ) || ( h & 0x0f ) ) {
|
|
|
|
Error( "Sprite dimensions not multiples of 16\n" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( w > 256 ) || ( h > 256 ) ) {
|
|
|
|
Error( "Sprite has a dimension longer than 256" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
xh = xl + w;
|
|
|
|
yh = yl + h;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sprite.numframes >= MAX_SPRFRAMES ) {
|
|
|
|
Error( "Too many frames; increase MAX_SPRFRAMES\n" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
pframe = &frames[sprite.numframes];
|
|
|
|
pframe->width = w;
|
|
|
|
pframe->height = h;
|
|
|
|
pframe->origin_x = ox;
|
|
|
|
pframe->origin_y = oy;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release ) {
|
|
|
|
ReleaseFile( pframe->name );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release ) {
|
|
|
|
return; // textures are only released by $maps
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
xh = xl + w;
|
|
|
|
yh = yl + h;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sourcel = longimage + ( yl * longimagewidth ) + xl;
|
2007-11-04 03:34:51 +00:00
|
|
|
destl = bufferl;
|
2012-03-17 20:01:54 +00:00
|
|
|
linedelta = ( longimagewidth - w );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( y = yl ; y < yh ; y++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( x = xl ; x < xh ; x++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
*destl++ = *sourcel++; // RGBA
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
sourcel += linedelta;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qtex32 = CreateMip32( bufferl, w, h, &size, true );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
qtex32->contents = 0;
|
|
|
|
qtex32->value = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( qtex32->name, pframe->name );
|
|
|
|
//
|
|
|
|
// write it out
|
|
|
|
//
|
|
|
|
printf( "writing %s\n", filename );
|
|
|
|
SaveFile( filename, (byte *)qtex32, size );
|
|
|
|
|
|
|
|
free( qtex32 );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release ) {
|
|
|
|
return; // textures are only released by $maps
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
xh = xl + w;
|
|
|
|
yh = yl + h;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
source = byteimage + yl * byteimagewidth + xl;
|
2007-11-04 03:34:51 +00:00
|
|
|
dest = buffer;
|
|
|
|
linedelta = byteimagewidth - w;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( y = yl ; y < yh ; y++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( x = xl ; x < xh ; x++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
*dest++ = *source++;
|
|
|
|
}
|
|
|
|
source += linedelta;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qtex = CreateMip( buffer, w, h, lbmpalette, &size, true );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
qtex->flags = 0;
|
|
|
|
qtex->contents = 0;
|
|
|
|
qtex->value = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( qtex->name, pframe->name );
|
|
|
|
//
|
|
|
|
// write it out
|
|
|
|
//
|
|
|
|
printf( "writing %s\n", filename );
|
|
|
|
SaveFile( filename, (byte *)qtex, size );
|
|
|
|
|
|
|
|
free( qtex );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sprite.numframes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============
|
|
|
|
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 ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_Sprdir
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Cmd_Sprdir( void ){
|
|
|
|
char filename[1024];
|
|
|
|
|
|
|
|
GetScriptToken( false );
|
|
|
|
strcpy( spr_prefix, token );
|
2007-11-04 03:34:51 +00:00
|
|
|
// create the directory if needed
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( filename, "%sSprites", g_outputDir );
|
|
|
|
Q_mkdir( filename );
|
|
|
|
sprintf( filename, "%sSprites/%s", g_outputDir, spr_prefix );
|
|
|
|
Q_mkdir( filename );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|