pframes: big refactor, add pframes_named for IQMs.
This commit is contained in:
parent
453b64c179
commit
955819c03b
2 changed files with 184 additions and 25 deletions
114
pframes.c
114
pframes.c
|
|
@ -1,37 +1,97 @@
|
|||
#define _POSIX_C_SOURCE 200809L // for strnlen
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char s[4] = "0000";
|
||||
char f = 'A';
|
||||
unsigned fi = 0;
|
||||
unsigned sp = 1;
|
||||
unsigned max = 0;
|
||||
unsigned sk = 1;
|
||||
unsigned mdl = 0;
|
||||
|
||||
// recursion is fun
|
||||
int advance_sprite( int idx );
|
||||
int advance_sprite( int idx )
|
||||
{
|
||||
if ( idx < 0 ) return 0; // we reached the limit, bail out
|
||||
if ( s[idx] == '9' ) s[idx] = 'A'; // from 9 to A
|
||||
else if ( s[idx] == 'Z' ) // at limit
|
||||
{
|
||||
// advance the previous char
|
||||
if ( !advance_sprite(idx-1) ) return 0; // no more, bail out
|
||||
s[idx] = '0'; // restart
|
||||
}
|
||||
else s[idx]++; // just increment
|
||||
return 1;
|
||||
}
|
||||
|
||||
int advance_frame( void )
|
||||
{
|
||||
printf("\tFrameIndex %.4s %c %d %d\n",s,f,mdl,fi);
|
||||
fi+=sk; // advance frame in model
|
||||
f++; // advance frame in sprite
|
||||
if ( f > 'Z' ) // note that [,\ and ] are not used. this is personal preference, really
|
||||
{
|
||||
// we need to change the sprite name
|
||||
if ( !advance_sprite(3) ) return 0; // can't advance further
|
||||
f = 'A'; // restart
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
if ( argc < 5 ) return 1;
|
||||
char s[4] = "TNT1";
|
||||
char f = 'A';
|
||||
int fi = 0;
|
||||
int sp = 1;
|
||||
int max = 0;
|
||||
int sk = 1;
|
||||
int mdl = 0;
|
||||
strncpy(s,argv[1],4);
|
||||
sscanf(argv[2],"%d",&fi);
|
||||
sscanf(argv[3],"%d",&max);
|
||||
sscanf(argv[4],"%d",&sk);
|
||||
if ( argc > 5 ) sscanf(argv[5],"%d",&mdl);
|
||||
if ( argc > 6 ) sscanf(argv[6],"%c",&f);
|
||||
for ( int i=0; i<max; i+=sk )
|
||||
if ( argc < 5 )
|
||||
{
|
||||
printf("\tFrameIndex %.4s %c %d %d\n",s,f,mdl,fi);
|
||||
fi+=sk;
|
||||
f++;
|
||||
if ( f > 'Z' )
|
||||
{
|
||||
if ( s[3] == '9' ) s[3] = 'A';
|
||||
else if ( s[3] == 'Z' )
|
||||
{
|
||||
s[2]++;
|
||||
s[3] = '0';
|
||||
fprintf(stderr,"usage: pframes <sprite name> <start frame> <max frames> [frame step] [model index] [first sprite frame]\n"
|
||||
"\n"
|
||||
" - sprite name: must be 4 characters.\n"
|
||||
" - start frame: frame offset within the model to start from.\n"
|
||||
" - max frames: limit on frames advanced.\n"
|
||||
" - frame step: how many frames to move each step (default:1, must be higher than zero).\n"
|
||||
" - model index: which model to assign (default: 0).\n"
|
||||
" - first sprite frame: which sprite frame to start from (default: A).\n"
|
||||
"\n"
|
||||
" Frames advance from A to Z, wrapping around.\n"
|
||||
" Each wrap, the fourth char of the sprite name will be cycled, from 0 to 9, then A to Z.\n"
|
||||
" After ###Z is reached, the third character will by cycled instead.\n"
|
||||
" And so on for the second, then the first...\n"
|
||||
" If you somehow run out of sprite names, you need to be more reasonable. (^^;\n");
|
||||
return 1;
|
||||
}
|
||||
else s[3]++;
|
||||
f = 'A';
|
||||
strncpy(s,argv[1],4);
|
||||
if ( strnlen(s,4) < 4 )
|
||||
{
|
||||
fprintf(stderr,"fatal: sprite name must be 4 characters.\n");
|
||||
return 2;
|
||||
}
|
||||
sscanf(argv[2],"%u",&fi);
|
||||
sscanf(argv[3],"%u",&max);
|
||||
if ( max == 0 )
|
||||
{
|
||||
fprintf(stderr,"fatal: max frames must be higher than zero.\n");
|
||||
return 4;
|
||||
}
|
||||
if ( argc > 4 ) sscanf(argv[4],"%u",&sk);
|
||||
if ( sk == 0 )
|
||||
{
|
||||
fprintf(stderr,"fatal: frame step must be higher than zero.\n");
|
||||
return 8;
|
||||
}
|
||||
if ( argc > 5 ) sscanf(argv[5],"%u",&mdl);
|
||||
if ( argc > 6 ) sscanf(argv[6],"%c",&f);
|
||||
if ( (f < 'A') || (f > 'Z') )
|
||||
{
|
||||
fprintf(stderr,"fatal: first sprite frame must be between A and Z (inclusive).\n");
|
||||
return 16;
|
||||
}
|
||||
for ( unsigned i=0; i<max; i+=sk )
|
||||
{
|
||||
if ( !advance_frame() )
|
||||
{
|
||||
fprintf(stderr,"fatal: ran out of sprite names. please be reasonable.\n");
|
||||
return 32;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
99
pframes_named.c
Normal file
99
pframes_named.c
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#define _POSIX_C_SOURCE 200809L // for strnlen
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char s[4] = "0000";
|
||||
char f = 'A';
|
||||
unsigned fi = 0;
|
||||
unsigned sp = 1;
|
||||
unsigned max = 0;
|
||||
unsigned sk = 1;
|
||||
unsigned mdl = 0;
|
||||
char *anm = NULL;
|
||||
|
||||
// recursion is fun
|
||||
int advance_sprite( int idx );
|
||||
int advance_sprite( int idx )
|
||||
{
|
||||
if ( idx < 0 ) return 0; // we reached the limit, bail out
|
||||
if ( s[idx] == '9' ) s[idx] = 'A'; // from 9 to A
|
||||
else if ( s[idx] == 'Z' ) // at limit
|
||||
{
|
||||
// advance the previous char
|
||||
if ( !advance_sprite(idx-1) ) return 0; // no more, bail out
|
||||
s[idx] = '0'; // restart
|
||||
}
|
||||
else s[idx]++; // just increment
|
||||
return 1;
|
||||
}
|
||||
|
||||
int advance_frame( void )
|
||||
{
|
||||
printf("\tFrame %.4s %c %d \"%s:%d\"\n",s,f,mdl,anm,fi);
|
||||
fi+=sk; // advance frame in model
|
||||
f++; // advance frame in sprite
|
||||
if ( f > 'Z' ) // note that [,\ and ] are not used. this is personal preference, really
|
||||
{
|
||||
// we need to change the sprite name
|
||||
if ( !advance_sprite(3) ) return 0; // can't advance further
|
||||
f = 'A'; // restart
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
if ( argc < 4 )
|
||||
{
|
||||
fprintf(stderr,"usage: pframes-named <sprite name> <anim name> <max frames> [frame step] [model index] [first sprite frame]\n"
|
||||
"\n"
|
||||
" - sprite name: must be 4 characters.\n"
|
||||
" - anim name: name of the animation to use.\n"
|
||||
" - max frames: limit on frames advanced.\n"
|
||||
" - frame step: how many frames to move each step (default: 1, must be higher than zero).\n"
|
||||
" - model index: which model to assign (default: 0).\n"
|
||||
" - first sprite frame: which sprite frame to start from (default: A).\n"
|
||||
"\n"
|
||||
" Frames advance from A to Z, wrapping around.\n"
|
||||
" Each wrap, the fourth char of the sprite name will be cycled, from 0 to 9, then A to Z.\n"
|
||||
" After ###Z is reached, the third character will by cycled instead.\n"
|
||||
" And so on for the second, then the first...\n"
|
||||
" If you somehow run out of sprite names, you need to be more reasonable. (^^;\n");
|
||||
return 1;
|
||||
}
|
||||
strncpy(s,argv[1],4);
|
||||
if ( strnlen(s,4) < 4 )
|
||||
{
|
||||
fprintf(stderr,"fatal: sprite name must be 4 characters.\n");
|
||||
return 2;
|
||||
}
|
||||
anm = argv[2]; // can be used directly, but this makes the code more readable
|
||||
sscanf(argv[3],"%u",&max);
|
||||
if ( max == 0 )
|
||||
{
|
||||
fprintf(stderr,"fatal: max frames must be higher than zero.\n");
|
||||
return 4;
|
||||
}
|
||||
if ( argc > 4 ) sscanf(argv[4],"%u",&sk);
|
||||
if ( sk == 0 )
|
||||
{
|
||||
fprintf(stderr,"fatal: frame step must be higher than zero.\n");
|
||||
return 8;
|
||||
}
|
||||
if ( argc > 5 ) sscanf(argv[5],"%u",&mdl);
|
||||
if ( argc > 6 ) sscanf(argv[6],"%c",&f);
|
||||
if ( (f < 'A') || (f > 'Z') )
|
||||
{
|
||||
fprintf(stderr,"fatal: first sprite frame must be between A and Z (inclusive).\n");
|
||||
return 16;
|
||||
}
|
||||
for ( unsigned i=0; i<max; i+=sk )
|
||||
{
|
||||
if ( !advance_frame() )
|
||||
{
|
||||
fprintf(stderr,"fatal: ran out of sprite names. please be reasonable.\n");
|
||||
return 32;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue