2008-07-25 07:31:37 +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.
|
2008-07-25 07:31:37 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2008-07-25 07:31:37 +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.
|
2008-07-25 07:31:37 +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.
|
2008-07-25 07:31:37 +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"
|
|
|
|
#include "inout.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
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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, "%s%s.sp2", gamedir, spritename );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release ) {
|
|
|
|
char name[1024];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( spriteouthandle );
|
|
|
|
|
|
|
|
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
|
|
|
GetToken( 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 );
|
|
|
|
Load256Image( name, &byteimage, &lbmpalette,
|
|
|
|
&byteimagewidth, &byteimageheight );
|
|
|
|
RemapZero( byteimage, lbmpalette,
|
|
|
|
byteimagewidth, byteimageheight );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_SpriteFrame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Cmd_SpriteFrame( void ){
|
|
|
|
int y,xl,yl,xh,yh,w,h;
|
|
|
|
dsprframe_t *pframe;
|
|
|
|
int ox, oy;
|
|
|
|
byte *cropped;
|
|
|
|
char savename[1024];
|
|
|
|
|
|
|
|
GetToken( false );
|
|
|
|
xl = atoi( token );
|
|
|
|
GetToken( false );
|
|
|
|
yl = atoi( token );
|
|
|
|
GetToken( false );
|
|
|
|
w = atoi( token );
|
|
|
|
GetToken( 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 ( TokenAvailable() ) {
|
|
|
|
GetToken( false );
|
|
|
|
ox = atoi( token );
|
|
|
|
GetToken( 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 & 0x07 ) || ( yl & 0x07 ) || ( w & 0x07 ) || ( h & 0x07 ) ) {
|
|
|
|
Error( "Sprite dimensions not multiples of 8\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
|
|
|
sprintf( pframe->name, "%s_%i.pcx", spritename, sprite.numframes );
|
|
|
|
sprintf( savename, "%s%s_%i.pcx", gamedir, spritename, sprite.numframes );
|
2007-11-04 03:34:51 +00:00
|
|
|
sprite.numframes++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release ) {
|
|
|
|
ReleaseFile( pframe->name );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// crop it to the proper size
|
2012-03-17 20:01:54 +00:00
|
|
|
cropped = malloc( w * h );
|
|
|
|
for ( y = 0 ; y < h ; y++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
memcpy( cropped + y * w, byteimage + ( y + yl ) * byteimagewidth + xl, w );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// save off the new image
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "saving %s\n", savename );
|
|
|
|
CreatePath( savename );
|
|
|
|
WritePCXfile( savename, cropped, w, h, lbmpalette );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
free( cropped );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============
|
|
|
|
Cmd_SpriteName
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void Cmd_SpriteName( void ){
|
|
|
|
if ( sprite.numframes ) {
|
|
|
|
FinishSprite();
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( false );
|
|
|
|
strcpy( spritename, token );
|
|
|
|
memset( &sprite, 0, sizeof( sprite ) );
|
|
|
|
memset( &frames, 0, sizeof( frames ) );
|
|
|
|
}
|