2006-04-23 06:44:19 +00:00
/*
* Definitions file parser for Build
2012-03-12 04:47:04 +00:00
* by Jonathon Fowler ( jf @ jonof . id . au )
2006-04-23 06:44:19 +00:00
* Remixed substantially by Ken Silverman
* See the included license file " BUILDLIC.TXT " for license info .
*/
# include "build.h"
# include "compat.h"
2011-01-27 07:05:12 +00:00
# include "engine_priv.h"
2006-04-23 06:44:19 +00:00
# include "baselayer.h"
# include "scriptfile.h"
2006-04-13 20:47:06 +00:00
# include "cache1d.h"
2007-05-01 04:35:27 +00:00
# include "kplib.h"
2009-12-05 09:22:43 +00:00
# include "quicklz.h"
2006-04-13 20:47:06 +00:00
2010-08-02 08:13:51 +00:00
enum scripttoken_t
2007-12-12 17:42:14 +00:00
{
2006-04-24 19:04:22 +00:00
T_EOF = - 2 ,
T_ERROR = - 1 ,
T_INCLUDE = 0 ,
T_DEFINE ,
T_DEFINETEXTURE ,
T_DEFINESKYBOX ,
T_DEFINETINT ,
T_DEFINEMODEL ,
T_DEFINEMODELFRAME ,
T_DEFINEMODELANIM ,
T_DEFINEMODELSKIN ,
T_SELECTMODELSKIN ,
T_DEFINEVOXEL ,
T_DEFINEVOXELTILES ,
T_MODEL ,
T_FILE ,
T_SCALE ,
T_SHADE ,
T_FRAME ,
2007-04-12 03:09:41 +00:00
T_SMOOTHDURATION ,
2006-04-24 19:04:22 +00:00
T_ANIM ,
T_SKIN ,
T_SURF ,
T_TILE ,
T_TILE0 ,
T_TILE1 ,
T_FRAME0 ,
T_FRAME1 ,
T_FPS ,
T_FLAGS ,
T_PAL ,
2011-01-27 07:05:12 +00:00
T_BASEPAL ,
2007-01-15 09:08:57 +00:00
T_DETAIL ,
2007-02-15 01:35:34 +00:00
T_GLOW ,
2009-04-28 22:56:43 +00:00
T_SPECULAR ,
T_NORMAL ,
2007-02-16 01:34:41 +00:00
T_PARAM ,
2006-04-24 19:04:22 +00:00
T_HUD ,
T_XADD ,
T_YADD ,
T_ZADD ,
T_ANGADD ,
2011-03-01 05:52:33 +00:00
T_FOV ,
2006-04-24 19:04:22 +00:00
T_FLIPPED ,
T_HIDE ,
T_NOBOB ,
T_NODEPTH ,
T_VOXEL ,
T_SKYBOX ,
T_FRONT , T_RIGHT , T_BACK , T_LEFT , T_TOP , T_BOTTOM ,
2010-12-30 08:13:37 +00:00
T_HIGHPALOOKUP ,
2006-04-24 19:04:22 +00:00
T_TINT , T_RED , T_GREEN , T_BLUE ,
2009-03-28 12:14:37 +00:00
T_TEXTURE , T_ALPHACUT , T_XSCALE , T_YSCALE , T_SPECPOWER , T_SPECFACTOR , T_NOCOMPRESS , T_NODOWNSIZE ,
2006-04-24 19:04:22 +00:00
T_UNDEFMODEL , T_UNDEFMODELRANGE , T_UNDEFMODELOF , T_UNDEFTEXTURE , T_UNDEFTEXTURERANGE ,
T_ALPHAHACK , T_ALPHAHACKRANGE ,
T_SPRITECOL , T_2DCOL ,
T_FOGPAL ,
T_LOADGRP ,
2006-07-20 01:50:56 +00:00
T_DUMMYTILE , T_DUMMYTILERANGE ,
2008-03-27 21:32:23 +00:00
T_SETUPTILE , T_SETUPTILERANGE ,
2008-08-02 13:00:41 +00:00
T_ANIMTILERANGE ,
2007-12-20 19:14:38 +00:00
T_CACHESIZE ,
2008-11-24 09:22:07 +00:00
T_IMPORTTILE ,
2007-12-20 19:14:38 +00:00
T_MUSIC , T_ID , T_SOUND ,
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
T_TILEFROMTEXTURE , T_XOFFSET , T_YOFFSET ,
Possibility of specifying sounds for a VPX anim-replacement via DEF.
The syntax is as follows:
animsounds <anim> { frame1 sound1 frame2 sound2 ... }
<anim> has to be one of the tokens: cineov2, cineov3, RADLOGO, DUKETEAM,
logo, vol41a, vol42a, vol4e1, vol43a, vol4e2, or vol4e3, corresponding
to hard-coded Duke3D anims.
The frameN's (1-based frame numbers) have to be in ascending order (but not
necessarily strictly ascending, so that a frame may have more than one sound).
Example: for Duke3D's XBLA nuke logo animation (IVF extracted from nuke.webm),
the following definition overlays the video with a sound sequence similar
(identical save for timing) to the original nuke animation:
// frame 1: FLY_BY, frame 64: PIPEBOMB_EXPLODE
animsounds logo { 1 244 64 14 }
git-svn-id: https://svn.eduke32.com/eduke32@2242 1a8010ca-5511-0410-912e-c29ae57300e0
2012-01-10 23:43:54 +00:00
T_INCLUDEDEFAULT ,
T_ANIMSOUNDS ,
2012-03-10 09:44:17 +00:00
T_ECHO ,
2006-04-23 06:44:19 +00:00
} ;
2011-02-21 23:08:21 +00:00
typedef struct { const char * text ; int32_t tokenid ; } tokenlist ;
2007-12-12 17:42:14 +00:00
2010-08-02 08:13:51 +00:00
static int32_t getatoken ( scriptfile * sf , const tokenlist * tl , int32_t ntokens )
2006-04-23 06:44:19 +00:00
{
2006-04-24 19:04:22 +00:00
char * tok ;
2009-01-09 09:29:17 +00:00
int32_t i ;
2006-04-23 06:44:19 +00:00
2006-04-24 19:04:22 +00:00
if ( ! sf ) return T_ERROR ;
tok = scriptfile_gettoken ( sf ) ;
if ( ! tok ) return T_EOF ;
2006-04-23 06:44:19 +00:00
2010-08-02 08:13:51 +00:00
for ( i = ntokens - 1 ; i > = 0 ; i - - )
2007-12-12 17:42:14 +00:00
{
2006-04-24 19:04:22 +00:00
if ( ! Bstrcasecmp ( tok , tl [ i ] . text ) )
return tl [ i ] . tokenid ;
}
2006-04-23 06:44:19 +00:00
2006-04-24 19:04:22 +00:00
return T_ERROR ;
2006-04-23 06:44:19 +00:00
}
2009-01-09 09:29:17 +00:00
static int32_t lastmodelid = - 1 , lastvoxid = - 1 , modelskin = - 1 , lastmodelskin = - 1 , seenframe = 0 ;
2011-12-25 15:30:50 +00:00
int32_t nextvoxid = 0 ;
2006-04-13 20:47:06 +00:00
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2006-04-13 20:47:06 +00:00
extern float alphahackarray [ MAXTILES ] ;
2006-05-12 21:55:05 +00:00
# endif
2006-04-13 20:47:06 +00:00
2007-12-12 17:42:14 +00:00
static const char * skyfaces [ 6 ] =
{
" front face " , " right face " , " back face " ,
" left face " , " top face " , " bottom face "
} ;
2006-04-23 06:44:19 +00:00
2011-07-21 22:39:29 +00:00
static int32_t defsparser ( scriptfile * script ) ;
static void defsparser_include ( const char * fn , scriptfile * script , char * cmdtokptr )
{
scriptfile * included ;
included = scriptfile_fromfile ( fn ) ;
if ( ! included )
{
if ( ! Bstrcasecmp ( cmdtokptr , " null " ) )
initprintf ( " Warning: Failed including %s as module \n " , fn ) ;
else
initprintf ( " Warning: Failed including %s on line %s:%d \n " ,
fn , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
}
else
{
defsparser ( included ) ;
scriptfile_close ( included ) ;
}
}
2009-01-09 09:29:17 +00:00
static int32_t defsparser ( scriptfile * script )
2006-04-23 06:44:19 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t tokn ;
2006-04-24 19:04:22 +00:00
char * cmdtokptr ;
2010-08-02 08:13:51 +00:00
static const tokenlist basetokens [ ] =
{
{ " include " , T_INCLUDE } ,
{ " #include " , T_INCLUDE } ,
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
{ " includedefault " , T_INCLUDEDEFAULT } ,
{ " #includedefault " , T_INCLUDEDEFAULT } ,
2010-08-02 08:13:51 +00:00
{ " define " , T_DEFINE } ,
{ " #define " , T_DEFINE } ,
// deprecated style
{ " definetexture " , T_DEFINETEXTURE } ,
{ " defineskybox " , T_DEFINESKYBOX } ,
{ " definetint " , T_DEFINETINT } ,
{ " definemodel " , T_DEFINEMODEL } ,
{ " definemodelframe " , T_DEFINEMODELFRAME } ,
{ " definemodelanim " , T_DEFINEMODELANIM } ,
{ " definemodelskin " , T_DEFINEMODELSKIN } ,
{ " selectmodelskin " , T_SELECTMODELSKIN } ,
{ " definevoxel " , T_DEFINEVOXEL } ,
{ " definevoxeltiles " , T_DEFINEVOXELTILES } ,
// new style
{ " model " , T_MODEL } ,
{ " voxel " , T_VOXEL } ,
{ " skybox " , T_SKYBOX } ,
2010-12-30 08:13:37 +00:00
{ " highpalookup " , T_HIGHPALOOKUP } ,
2010-08-02 08:13:51 +00:00
{ " tint " , T_TINT } ,
{ " texture " , T_TEXTURE } ,
{ " tile " , T_TEXTURE } ,
{ " music " , T_MUSIC } ,
{ " sound " , T_SOUND } ,
Possibility of specifying sounds for a VPX anim-replacement via DEF.
The syntax is as follows:
animsounds <anim> { frame1 sound1 frame2 sound2 ... }
<anim> has to be one of the tokens: cineov2, cineov3, RADLOGO, DUKETEAM,
logo, vol41a, vol42a, vol4e1, vol43a, vol4e2, or vol4e3, corresponding
to hard-coded Duke3D anims.
The frameN's (1-based frame numbers) have to be in ascending order (but not
necessarily strictly ascending, so that a frame may have more than one sound).
Example: for Duke3D's XBLA nuke logo animation (IVF extracted from nuke.webm),
the following definition overlays the video with a sound sequence similar
(identical save for timing) to the original nuke animation:
// frame 1: FLY_BY, frame 64: PIPEBOMB_EXPLODE
animsounds logo { 1 244 64 14 }
git-svn-id: https://svn.eduke32.com/eduke32@2242 1a8010ca-5511-0410-912e-c29ae57300e0
2012-01-10 23:43:54 +00:00
{ " animsounds " , T_ANIMSOUNDS } , // dummy
2010-08-02 08:13:51 +00:00
// other stuff
{ " undefmodel " , T_UNDEFMODEL } ,
{ " undefmodelrange " , T_UNDEFMODELRANGE } ,
{ " undefmodelof " , T_UNDEFMODELOF } ,
{ " undeftexture " , T_UNDEFTEXTURE } ,
{ " undeftexturerange " , T_UNDEFTEXTURERANGE } ,
{ " alphahack " , T_ALPHAHACK } ,
{ " alphahackrange " , T_ALPHAHACKRANGE } ,
{ " spritecol " , T_SPRITECOL } ,
{ " 2dcol " , T_2DCOL } ,
{ " fogpal " , T_FOGPAL } ,
{ " loadgrp " , T_LOADGRP } ,
{ " dummytile " , T_DUMMYTILE } ,
{ " dummytilerange " , T_DUMMYTILERANGE } ,
{ " setuptile " , T_SETUPTILE } ,
{ " setuptilerange " , T_SETUPTILERANGE } ,
{ " animtilerange " , T_ANIMTILERANGE } ,
{ " cachesize " , T_CACHESIZE } ,
{ " dummytilefrompic " , T_IMPORTTILE } ,
{ " tilefromtexture " , T_TILEFROMTEXTURE } ,
2012-03-10 09:44:17 +00:00
{ " echo " , T_ECHO } ,
2010-08-02 08:13:51 +00:00
} ;
2007-12-12 17:42:14 +00:00
while ( 1 )
{
2008-08-20 09:17:23 +00:00
if ( quitevent ) return 0 ;
2006-04-24 19:04:22 +00:00
tokn = getatoken ( script , basetokens , sizeof ( basetokens ) / sizeof ( tokenlist ) ) ;
cmdtokptr = script - > ltextptr ;
2007-12-12 17:42:14 +00:00
switch ( tokn )
{
2006-04-24 19:04:22 +00:00
case T_ERROR :
initprintf ( " Error on line %s:%d. \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
case T_EOF :
return ( 0 ) ;
case T_INCLUDE :
2006-11-13 23:12:47 +00:00
{
char * fn ;
2007-12-12 17:42:14 +00:00
if ( ! scriptfile_getstring ( script , & fn ) )
2011-07-21 22:39:29 +00:00
defsparser_include ( fn , script , cmdtokptr ) ;
2006-11-13 23:12:47 +00:00
break ;
}
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
case T_INCLUDEDEFAULT :
{
2011-07-21 22:39:29 +00:00
defsparser_include ( defsfilename , script , cmdtokptr ) ;
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
break ;
}
2006-04-24 19:04:22 +00:00
case T_DEFINE :
2006-11-13 23:12:47 +00:00
{
char * name ;
2009-01-09 09:29:17 +00:00
int32_t number ;
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getstring ( script , & name ) ) break ;
if ( scriptfile_getsymbol ( script , & number ) ) break ;
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_addsymbolvalue ( name , number ) < 0 )
initprintf ( " Warning: Symbol %s was NOT redefined to %d on line %s:%d \n " ,
name , number , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
}
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
// OLD (DEPRECATED) DEFINITION SYNTAX
2006-04-24 19:04:22 +00:00
case T_DEFINETEXTURE :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t tile , pal , fnoo , i ;
2007-04-30 19:41:19 +00:00
char * fn , * tfn = NULL ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( scriptfile_getsymbol ( script , & pal ) ) break ;
if ( scriptfile_getnumber ( script , & fnoo ) ) break ; //x-center
if ( scriptfile_getnumber ( script , & fnoo ) ) break ; //y-center
if ( scriptfile_getnumber ( script , & fnoo ) ) break ; //x-size
if ( scriptfile_getnumber ( script , & fnoo ) ) break ; //y-size
if ( scriptfile_getstring ( script , & fn ) ) break ;
2007-04-30 19:41:19 +00:00
i = pathsearchmode ;
2007-05-01 04:35:27 +00:00
pathsearchmode = 1 ;
2007-12-12 17:42:14 +00:00
if ( findfrompath ( fn , & tfn ) < 0 )
{
2007-05-01 04:35:27 +00:00
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , fn ) ;
kzfindfilestart ( buf ) ;
2007-12-12 17:42:14 +00:00
if ( ! kzfindfile ( buf ) )
{
2007-05-01 04:35:27 +00:00
initprintf ( " Error: file '%s' does not exist \n " , fn ) ;
2008-02-01 03:36:54 +00:00
pathsearchmode = i ;
2007-05-01 04:35:27 +00:00
break ;
2007-12-12 17:42:14 +00:00
}
}
else Bfree ( tfn ) ;
2007-04-30 19:41:19 +00:00
pathsearchmode = i ;
2006-10-31 18:32:29 +00:00
2009-03-28 12:14:37 +00:00
hicsetsubsttex ( tile , pal , fn , - 1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 0 ) ;
2006-11-13 23:12:47 +00:00
}
break ;
2006-04-24 19:04:22 +00:00
case T_DEFINESKYBOX :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t tile , pal , i , ii ;
2007-04-30 19:41:19 +00:00
char * fn [ 6 ] , happy = 1 , * tfn = NULL ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( scriptfile_getsymbol ( script , & pal ) ) break ;
if ( scriptfile_getsymbol ( script , & i ) ) break ; //future expansion
2009-02-19 16:47:54 +00:00
for ( i = 0 ; i < 6 ; i + + )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
if ( scriptfile_getstring ( script , & fn [ i ] ) ) break ; //grab the 6 faces
2007-04-30 19:41:19 +00:00
ii = pathsearchmode ;
pathsearchmode = 1 ;
2007-12-12 17:42:14 +00:00
if ( findfrompath ( fn [ i ] , & tfn ) < 0 )
{
2007-05-01 04:35:27 +00:00
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , fn [ i ] ) ;
kzfindfilestart ( buf ) ;
2007-12-12 17:42:14 +00:00
if ( ! kzfindfile ( buf ) )
{
2007-05-01 04:35:27 +00:00
initprintf ( " Error: file '%s' does not exist \n " , fn [ i ] ) ;
happy = 0 ;
2007-12-12 17:42:14 +00:00
}
}
else Bfree ( tfn ) ;
2007-04-30 19:41:19 +00:00
pathsearchmode = ii ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
if ( i < 6 | | ! happy ) break ;
hicsetskybox ( tile , pal , fn ) ;
}
break ;
2006-04-24 19:04:22 +00:00
case T_DEFINETINT :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t pal , r , g , b , f ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & pal ) ) break ;
if ( scriptfile_getnumber ( script , & r ) ) break ;
if ( scriptfile_getnumber ( script , & g ) ) break ;
if ( scriptfile_getnumber ( script , & b ) ) break ;
if ( scriptfile_getnumber ( script , & f ) ) break ; //effects
hicsetpalettetint ( pal , r , g , b , f ) ;
}
break ;
2006-04-24 19:04:22 +00:00
case T_ALPHAHACK :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t tile ;
2006-11-13 23:12:47 +00:00
double alpha ;
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( scriptfile_getdouble ( script , & alpha ) ) break ;
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2009-01-09 09:29:17 +00:00
if ( ( uint32_t ) tile < MAXTILES ) alphahackarray [ tile ] = alpha ;
2006-05-12 21:55:05 +00:00
# endif
2006-11-13 23:12:47 +00:00
}
break ;
2006-04-24 19:04:22 +00:00
case T_ALPHAHACKRANGE :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t tilenume1 , tilenume2 , i ;
2006-11-13 23:12:47 +00:00
double alpha ;
if ( scriptfile_getsymbol ( script , & tilenume1 ) ) break ;
if ( scriptfile_getsymbol ( script , & tilenume2 ) ) break ;
if ( scriptfile_getdouble ( script , & alpha ) ) break ;
2007-12-12 17:42:14 +00:00
if ( tilenume2 < tilenume1 )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
i = tilenume2 ;
tilenume2 = tilenume1 ;
tilenume1 = i ;
}
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
if ( ( tilenume1 > = 0 & & tilenume1 < MAXTILES ) & & ( tilenume2 > = 0 & & tilenume2 < MAXTILES ) )
{
2009-02-19 16:47:54 +00:00
for ( i = tilenume1 ; i < = tilenume2 ; i + + )
2006-04-24 19:04:22 +00:00
{
2009-01-09 09:29:17 +00:00
if ( ( uint32_t ) i < MAXTILES )
2006-11-13 23:12:47 +00:00
alphahackarray [ i ] = alpha ;
2006-04-24 19:04:22 +00:00
}
}
2006-11-13 23:12:47 +00:00
# endif
}
break ;
2006-04-24 19:04:22 +00:00
case T_SPRITECOL :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t tile , col , col2 ;
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( scriptfile_getnumber ( script , & col ) ) break ;
if ( scriptfile_getnumber ( script , & col2 ) ) break ;
2009-01-09 09:29:17 +00:00
if ( ( uint32_t ) tile < MAXTILES )
2006-11-13 23:12:47 +00:00
{
spritecol2d [ tile ] [ 0 ] = col ;
spritecol2d [ tile ] [ 1 ] = col2 ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
}
break ;
2006-04-24 19:04:22 +00:00
case T_2DCOL :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t col , b , g , r ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getnumber ( script , & col ) ) break ;
if ( scriptfile_getnumber ( script , & r ) ) break ;
if ( scriptfile_getnumber ( script , & g ) ) break ;
if ( scriptfile_getnumber ( script , & b ) ) break ;
2012-03-18 23:17:51 +00:00
if ( ( unsigned ) col < 256 )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
vgapal16 [ col * 4 + 0 ] = b ; // blue
vgapal16 [ col * 4 + 1 ] = g ; // green
vgapal16 [ col * 4 + 2 ] = r ; // red
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
}
break ;
2006-04-24 19:04:22 +00:00
case T_FOGPAL :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t p , r , g , b , j ;
2006-11-13 23:12:47 +00:00
char tempbuf [ 256 ] ;
if ( scriptfile_getnumber ( script , & p ) ) break ;
if ( scriptfile_getnumber ( script , & r ) ) break ;
if ( scriptfile_getnumber ( script , & g ) ) break ;
if ( scriptfile_getnumber ( script , & b ) ) break ;
for ( j = 0 ; j < 256 ; j + + )
tempbuf [ j ] = j ;
makepalookup ( p , tempbuf , r , g , b , 1 ) ;
}
break ;
2006-04-24 19:04:22 +00:00
case T_LOADGRP :
2006-11-13 23:12:47 +00:00
{
char * bs ;
scriptfile_getstring ( script , & bs ) ;
}
break ;
2007-01-02 02:27:31 +00:00
case T_CACHESIZE :
{
2009-01-09 09:29:17 +00:00
int32_t j ;
2007-12-12 17:42:14 +00:00
2007-01-02 02:27:31 +00:00
if ( scriptfile_getnumber ( script , & j ) ) break ;
}
break ;
2008-03-27 21:32:23 +00:00
case T_SETUPTILE :
{
2009-01-09 09:29:17 +00:00
int32_t tile , tmp ;
2008-03-27 21:32:23 +00:00
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( tile > = MAXTILES ) break ;
if ( scriptfile_getsymbol ( script , & h_xsize [ tile ] ) ) break ;
if ( scriptfile_getsymbol ( script , & h_ysize [ tile ] ) ) break ;
if ( scriptfile_getsymbol ( script , & tmp ) ) break ;
h_xoffs [ tile ] = tmp ;
if ( scriptfile_getsymbol ( script , & tmp ) ) break ;
h_yoffs [ tile ] = tmp ;
break ;
}
case T_SETUPTILERANGE :
{
2009-01-09 09:29:17 +00:00
int32_t tile1 , tile2 , xsiz , ysiz , xoffs , yoffs , i ;
2008-03-27 21:32:23 +00:00
if ( scriptfile_getnumber ( script , & tile1 ) ) break ;
if ( scriptfile_getnumber ( script , & tile2 ) ) break ;
if ( scriptfile_getnumber ( script , & xsiz ) ) break ;
if ( scriptfile_getnumber ( script , & ysiz ) ) break ;
if ( scriptfile_getsymbol ( script , & xoffs ) ) break ;
if ( scriptfile_getsymbol ( script , & yoffs ) ) break ;
if ( tile2 < tile1 )
{
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
i = tile2 ;
tile2 = tile1 ;
tile1 = i ;
}
if ( ( tile1 > = 0 & & tile1 < MAXTILES ) & & ( tile2 > = 0 & & tile2 < MAXTILES ) )
{
2009-02-19 16:47:54 +00:00
for ( i = tile1 ; i < = tile2 ; i + + )
2008-03-27 21:32:23 +00:00
{
2009-01-09 09:29:17 +00:00
if ( ( uint32_t ) i < MAXTILES )
2008-03-27 21:32:23 +00:00
{
h_xsize [ i ] = xsiz ;
h_ysize [ i ] = ysiz ;
h_xoffs [ i ] = xoffs ;
h_yoffs [ i ] = yoffs ;
}
}
}
break ;
}
2008-08-02 13:00:41 +00:00
case T_ANIMTILERANGE :
{
2009-01-09 09:29:17 +00:00
int32_t tile1 , tile2 , spd , type , i ;
2008-08-02 13:00:41 +00:00
if ( scriptfile_getsymbol ( script , & tile1 ) ) break ;
if ( tile1 > = MAXTILES ) break ;
if ( scriptfile_getsymbol ( script , & tile2 ) ) break ;
if ( tile2 > = MAXTILES ) break ;
if ( scriptfile_getsymbol ( script , & spd ) ) break ;
if ( scriptfile_getsymbol ( script , & type ) ) break ;
if ( tile2 < tile1 )
{
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
i = tile2 ;
tile2 = tile1 ;
tile1 = i ;
}
2008-12-19 00:53:54 +00:00
picanm [ tile1 ] = ( picanm [ tile1 ] & 0xffffff3f ) + ( spd < < 24 ) + ( type < < 6 ) + tile2 - tile1 ;
2008-08-02 13:00:41 +00:00
break ;
}
2008-11-24 11:31:05 +00:00
case T_TILEFROMTEXTURE :
{
2010-12-17 14:22:15 +00:00
char * texturetokptr = script - > ltextptr , * textureend , * fn = NULL , * tfn = NULL , * ftd = NULL ;
2009-01-09 09:29:17 +00:00
int32_t tile = - 1 , token , i ;
int32_t alphacut = 255 ;
2011-02-27 19:13:44 +00:00
int32_t xoffset = 0 , yoffset = 0 , goodtogo = 0 ;
2008-11-24 11:31:05 +00:00
2010-08-02 08:13:51 +00:00
static const tokenlist tilefromtexturetokens [ ] =
{
{ " file " , T_FILE } ,
{ " name " , T_FILE } ,
{ " alphacut " , T_ALPHACUT } ,
{ " xoffset " , T_XOFFSET } ,
{ " xoff " , T_XOFFSET } ,
{ " yoffset " , T_YOFFSET } ,
{ " yoff " , T_YOFFSET } ,
} ;
2008-11-24 11:31:05 +00:00
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( scriptfile_getbraces ( script , & textureend ) ) break ;
while ( script - > textptr < textureend )
{
token = getatoken ( script , tilefromtexturetokens , sizeof ( tilefromtexturetokens ) / sizeof ( tokenlist ) ) ;
switch ( token )
{
case T_FILE :
scriptfile_getstring ( script , & fn ) ; break ;
case T_ALPHACUT :
scriptfile_getsymbol ( script , & alphacut ) ; break ;
2008-12-19 00:53:54 +00:00
case T_XOFFSET :
scriptfile_getsymbol ( script , & xoffset ) ; break ;
case T_YOFFSET :
scriptfile_getsymbol ( script , & yoffset ) ; break ;
2008-11-24 11:31:05 +00:00
default :
break ;
}
if ( ( unsigned ) tile > ( unsigned ) MAXTILES ) break ; // message is printed later
if ( ! fn )
{
initprintf ( " Error: missing 'file name' for tilefromtexture definition near line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , texturetokptr ) ) ;
break ;
}
if ( alphacut > 255 ) alphacut = 255 ;
if ( alphacut < 0 ) alphacut = 0 ;
i = pathsearchmode ;
pathsearchmode = 1 ;
if ( findfrompath ( fn , & tfn ) < 0 )
{
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , fn ) ;
kzfindfilestart ( buf ) ;
if ( ! kzfindfile ( buf ) )
{
initprintf ( " Error: file '%s' does not exist \n " , fn ) ;
pathsearchmode = i ;
break ;
}
}
else Bfree ( tfn ) ;
pathsearchmode = i ;
2011-02-27 19:13:44 +00:00
goodtogo = 1 ;
2008-11-24 11:31:05 +00:00
}
if ( ( unsigned ) tile > = ( unsigned ) MAXTILES )
{
initprintf ( " Error: missing or invalid 'tile number' for texture definition near line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , texturetokptr ) ) ;
break ;
}
2011-02-27 19:13:44 +00:00
if ( goodtogo )
2008-11-24 11:31:05 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t xsiz , ysiz , j ;
int32_t * picptr = NULL ;
2008-11-24 11:31:05 +00:00
palette_t * col ;
kpzload ( fn , ( intptr_t * ) & picptr , & j , & xsiz , & ysiz ) ;
// initprintf("got bpl %d xsiz %d ysiz %d\n",bpl,xsiz,ysiz);
2009-11-15 09:10:50 +00:00
ftd = Bmalloc ( xsiz * ysiz ) ;
2011-05-12 23:31:13 +00:00
faketiledata [ tile ] = Bmalloc ( xsiz * ysiz + 400 ) ;
2008-11-24 11:31:05 +00:00
2009-02-19 16:47:54 +00:00
for ( i = xsiz - 1 ; i > = 0 ; i - - )
2008-11-24 11:31:05 +00:00
{
2009-02-19 16:47:54 +00:00
for ( j = ysiz - 1 ; j > = 0 ; j - - )
2008-11-24 11:31:05 +00:00
{
col = ( palette_t * ) & picptr [ j * xsiz + i ] ;
2009-11-15 09:10:50 +00:00
if ( col - > f < alphacut ) { ftd [ i * ysiz + j ] = 255 ; continue ; }
ftd [ i * ysiz + j ] = getclosestcol ( col - > b > > 2 , col - > g > > 2 , col - > r > > 2 ) ;
2008-11-24 11:31:05 +00:00
}
// initprintf(" %d %d %d %d\n",col->r,col->g,col->b,col->f);
}
if ( xsiz > 0 & & ysiz > 0 )
{
tilesizx [ tile ] = xsiz ;
tilesizy [ tile ] = ysiz ;
2009-11-15 09:10:50 +00:00
2009-12-05 09:22:43 +00:00
faketilesiz [ tile ] = qlz_compress ( ftd , faketiledata [ tile ] , xsiz * ysiz , state_compress ) ;
2008-12-19 00:53:54 +00:00
xoffset = clamp ( xoffset , - 128 , 127 ) ;
picanm [ tile ] = ( picanm [ tile ] & 0xffff00ff ) + ( ( xoffset & 255 ) < < 8 ) ;
yoffset = clamp ( yoffset , - 128 , 127 ) ;
picanm [ tile ] = ( picanm [ tile ] & 0xff00ffff ) + ( ( yoffset & 255 ) < < 16 ) ;
2008-11-24 11:31:05 +00:00
j = 15 ; while ( ( j > 1 ) & & ( pow2long [ j ] > xsiz ) ) j - - ;
2009-01-09 09:29:17 +00:00
picsiz [ tile ] = ( ( uint8_t ) j ) ;
2008-11-24 11:31:05 +00:00
j = 15 ; while ( ( j > 1 ) & & ( pow2long [ j ] > ysiz ) ) j - - ;
2009-01-09 09:29:17 +00:00
picsiz [ tile ] + = ( ( uint8_t ) ( j < < 4 ) ) ;
2008-11-24 11:31:05 +00:00
}
Bfree ( picptr ) ;
2009-11-15 09:10:50 +00:00
Bfree ( ftd ) ;
2008-11-24 11:31:05 +00:00
}
}
break ;
2008-11-24 09:22:07 +00:00
case T_IMPORTTILE :
{
2009-01-09 09:29:17 +00:00
int32_t tile , xsiz , ysiz , j , i ;
int32_t * picptr = NULL ;
int32_t bpl ;
2009-11-15 09:10:50 +00:00
char * fn , * ftd = NULL ;
2008-11-24 09:22:07 +00:00
palette_t * col ;
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( scriptfile_getstring ( script , & fn ) ) break ;
kpzload ( fn , ( intptr_t * ) & picptr , & bpl , & xsiz , & ysiz ) ;
2008-11-24 11:31:05 +00:00
// initprintf("got bpl %d xsiz %d ysiz %d\n",bpl,xsiz,ysiz);
2008-11-24 09:22:07 +00:00
2009-11-15 09:10:50 +00:00
ftd = Bmalloc ( xsiz * ysiz ) ;
2011-05-12 23:31:13 +00:00
faketiledata [ tile ] = Bmalloc ( xsiz * ysiz + 400 ) ;
2008-11-24 09:22:07 +00:00
2009-02-19 16:47:54 +00:00
for ( i = xsiz - 1 ; i > = 0 ; i - - )
2008-11-24 09:22:07 +00:00
{
2009-02-19 16:47:54 +00:00
for ( j = ysiz - 1 ; j > = 0 ; j - - )
2008-11-24 11:31:05 +00:00
{
col = ( palette_t * ) & picptr [ j * xsiz + i ] ;
2009-11-15 09:10:50 +00:00
if ( col - > f ! = 255 ) { ftd [ i * ysiz + j ] = 255 ; continue ; }
ftd [ i * ysiz + j ] = getclosestcol ( col - > b > > 2 , col - > g > > 2 , col - > r > > 2 ) ;
2008-11-24 11:31:05 +00:00
}
2008-11-24 09:22:07 +00:00
// initprintf(" %d %d %d %d\n",col->r,col->g,col->b,col->f);
}
if ( xsiz > 0 & & ysiz > 0 )
{
tilesizx [ tile ] = xsiz ;
tilesizy [ tile ] = ysiz ;
2009-12-05 09:22:43 +00:00
faketilesiz [ tile ] = qlz_compress ( ftd , faketiledata [ tile ] , xsiz * ysiz , state_compress ) ;
2008-11-24 09:22:07 +00:00
picanm [ tile ] = 0 ;
j = 15 ; while ( ( j > 1 ) & & ( pow2long [ j ] > xsiz ) ) j - - ;
2009-01-09 09:29:17 +00:00
picsiz [ tile ] = ( ( uint8_t ) j ) ;
2008-11-24 09:22:07 +00:00
j = 15 ; while ( ( j > 1 ) & & ( pow2long [ j ] > ysiz ) ) j - - ;
2009-01-09 09:29:17 +00:00
picsiz [ tile ] + = ( ( uint8_t ) ( j < < 4 ) ) ;
2008-11-24 09:22:07 +00:00
}
2008-11-24 11:31:05 +00:00
Bfree ( picptr ) ;
2009-11-15 09:10:50 +00:00
Bfree ( ftd ) ;
2008-11-24 09:22:07 +00:00
break ;
}
2006-04-26 01:25:18 +00:00
case T_DUMMYTILE :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t tile , xsiz , ysiz , j ;
2006-04-26 01:25:18 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( scriptfile_getsymbol ( script , & xsiz ) ) break ;
if ( scriptfile_getsymbol ( script , & ysiz ) ) break ;
2006-08-04 04:01:17 +00:00
2006-11-13 23:12:47 +00:00
if ( xsiz > 0 & & ysiz > 0 )
{
tilesizx [ tile ] = xsiz ;
tilesizy [ tile ] = ysiz ;
2009-11-15 09:10:50 +00:00
faketilesiz [ tile ] = - 1 ;
2006-11-13 23:12:47 +00:00
picanm [ tile ] = 0 ;
j = 15 ; while ( ( j > 1 ) & & ( pow2long [ j ] > xsiz ) ) j - - ;
2009-01-09 09:29:17 +00:00
picsiz [ tile ] = ( ( uint8_t ) j ) ;
2006-11-13 23:12:47 +00:00
j = 15 ; while ( ( j > 1 ) & & ( pow2long [ j ] > ysiz ) ) j - - ;
2009-01-09 09:29:17 +00:00
picsiz [ tile ] + = ( ( uint8_t ) ( j < < 4 ) ) ;
2006-04-26 01:25:18 +00:00
}
2006-11-13 23:12:47 +00:00
break ;
}
2006-04-26 01:25:18 +00:00
case T_DUMMYTILERANGE :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t tile1 , tile2 , xsiz , ysiz , i , j ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getnumber ( script , & tile1 ) ) break ;
if ( scriptfile_getnumber ( script , & tile2 ) ) break ;
if ( scriptfile_getnumber ( script , & xsiz ) ) break ;
if ( scriptfile_getnumber ( script , & ysiz ) ) break ;
2007-12-12 17:42:14 +00:00
if ( tile2 < tile1 )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
i = tile2 ;
tile2 = tile1 ;
tile1 = i ;
}
if ( ( tile1 > = 0 & & tile1 < MAXTILES ) & & ( tile2 > = 0 & & tile2 < MAXTILES ) )
2006-04-26 01:25:18 +00:00
{
2009-02-19 16:47:54 +00:00
for ( i = tile1 ; i < = tile2 ; i + + )
2006-04-26 01:25:18 +00:00
{
2009-01-09 09:29:17 +00:00
if ( ( uint32_t ) i < MAXTILES )
2006-04-26 01:25:18 +00:00
{
2006-11-13 23:12:47 +00:00
if ( xsiz > 0 & & ysiz > 0 )
2006-04-26 01:25:18 +00:00
{
2006-11-13 23:12:47 +00:00
tilesizx [ i ] = xsiz ;
tilesizy [ i ] = ysiz ;
2009-11-15 09:10:50 +00:00
faketilesiz [ i ] = - 1 ;
2006-11-13 23:12:47 +00:00
picanm [ i ] = 0 ;
j = 15 ; while ( ( j > 1 ) & & ( pow2long [ j ] > xsiz ) ) j - - ;
2009-01-09 09:29:17 +00:00
picsiz [ i ] = ( ( uint8_t ) j ) ;
2006-11-13 23:12:47 +00:00
j = 15 ; while ( ( j > 1 ) & & ( pow2long [ j ] > ysiz ) ) j - - ;
2009-01-09 09:29:17 +00:00
picsiz [ i ] + = ( ( uint8_t ) ( j < < 4 ) ) ;
2006-04-26 01:25:18 +00:00
}
}
}
}
2006-11-13 23:12:47 +00:00
break ;
}
2006-04-26 01:25:18 +00:00
2006-04-24 19:04:22 +00:00
case T_DEFINEMODEL :
2006-11-13 23:12:47 +00:00
{
char * modelfn ;
double scale ;
2009-01-09 09:29:17 +00:00
int32_t shadeoffs ;
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getstring ( script , & modelfn ) ) break ;
if ( scriptfile_getdouble ( script , & scale ) ) break ;
if ( scriptfile_getnumber ( script , & shadeoffs ) ) break ;
2006-04-23 06:44:19 +00:00
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
lastmodelid = md_loadmodel ( modelfn ) ;
2007-12-12 17:42:14 +00:00
if ( lastmodelid < 0 )
{
2008-07-20 04:12:52 +00:00
initprintf ( " Warning: Failed loading MD2/MD3 model \" %s \" \n " , modelfn ) ;
2006-11-13 23:12:47 +00:00
break ;
2006-04-24 19:04:22 +00:00
}
2012-01-17 04:31:59 +00:00
md_setmisc ( lastmodelid , ( float ) scale , shadeoffs , 0.0 , 0.0 , 0 ) ;
2011-06-19 18:30:32 +00:00
if ( glrendmode = = 4 )
md3postload_polymer ( ( md3model_t * ) models [ lastmodelid ] ) ;
2006-04-23 06:44:19 +00:00
# endif
2006-11-13 23:12:47 +00:00
modelskin = lastmodelskin = 0 ;
seenframe = 0 ;
}
break ;
case T_DEFINEMODELFRAME :
{
2008-07-24 11:16:20 +00:00
char * framename ;
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2008-07-24 11:16:20 +00:00
char happy = 1 ;
# endif
2009-01-09 09:29:17 +00:00
int32_t ftilenume , ltilenume , tilex ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getstring ( script , & framename ) ) break ;
if ( scriptfile_getnumber ( script , & ftilenume ) ) break ; //first tile number
if ( scriptfile_getnumber ( script , & ltilenume ) ) break ; //last tile number (inclusive)
2007-12-12 17:42:14 +00:00
if ( ltilenume < ftilenume )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
tilex = ftilenume ;
ftilenume = ltilenume ;
ltilenume = tilex ;
2006-04-24 19:04:22 +00:00
}
2007-12-12 17:42:14 +00:00
if ( lastmodelid < 0 )
{
2012-01-27 15:03:18 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: Ignoring frame definition. \n " ) ;
2012-01-27 15:03:18 +00:00
# endif
2006-11-13 23:12:47 +00:00
break ;
}
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2007-12-12 17:42:14 +00:00
for ( tilex = ftilenume ; tilex < = ltilenume & & happy ; tilex + + )
{
2007-12-20 19:14:38 +00:00
switch ( md_defineframe ( lastmodelid , framename , tilex , max ( 0 , modelskin ) , 0.0f , 0 ) )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
case - 1 :
happy = 0 ; break ; // invalid model id!?
case - 2 :
initprintf ( " Invalid tile number on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
happy = 0 ;
2006-04-24 19:04:22 +00:00
break ;
2006-11-13 23:12:47 +00:00
case - 3 :
initprintf ( " Invalid frame name on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
happy = 0 ;
2006-04-24 19:04:22 +00:00
break ;
2011-06-19 18:30:32 +00:00
default :
break ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
}
2006-04-23 06:44:19 +00:00
# endif
2006-11-13 23:12:47 +00:00
seenframe = 1 ;
}
break ;
case T_DEFINEMODELANIM :
{
char * startframe , * endframe ;
2009-01-09 09:29:17 +00:00
int32_t flags ;
2006-11-13 23:12:47 +00:00
double dfps ;
if ( scriptfile_getstring ( script , & startframe ) ) break ;
if ( scriptfile_getstring ( script , & endframe ) ) break ;
if ( scriptfile_getdouble ( script , & dfps ) ) break ; //animation frame rate
if ( scriptfile_getnumber ( script , & flags ) ) break ;
2007-12-12 17:42:14 +00:00
if ( lastmodelid < 0 )
{
2012-01-27 15:03:18 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: Ignoring animation definition. \n " ) ;
2012-01-27 15:03:18 +00:00
# endif
2006-11-13 23:12:47 +00:00
break ;
2006-04-24 19:04:22 +00:00
}
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2009-01-09 09:29:17 +00:00
switch ( md_defineanimation ( lastmodelid , startframe , endframe , ( int32_t ) ( dfps * ( 65536.0 * .001 ) ) , flags ) )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
case 0 :
break ;
case - 1 :
break ; // invalid model id!?
case - 2 :
initprintf ( " Invalid starting frame name on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
case - 3 :
initprintf ( " Invalid ending frame name on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
case - 4 :
initprintf ( " Out of memory on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
}
# endif
}
break ;
2006-04-24 19:04:22 +00:00
case T_DEFINEMODELSKIN :
2006-11-13 23:12:47 +00:00
{
2012-03-10 09:44:54 +00:00
int32_t palnum , i ;
char * skinfn , * tfn = NULL ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & palnum ) ) break ;
if ( scriptfile_getstring ( script , & skinfn ) ) break ; //skin filename
// if we see a sequence of definemodelskin, then a sequence of definemodelframe,
// and then a definemodelskin, we need to increment the skin counter.
//
// definemodel "mymodel.md2" 1 1
// definemodelskin 0 "normal.png" // skin 0
// definemodelskin 21 "normal21.png"
// definemodelframe "foo" 1000 1002 // these use skin 0
// definemodelskin 0 "wounded.png" // skin 1
// definemodelskin 21 "wounded21.png"
// definemodelframe "foo2" 1003 1004 // these use skin 1
// selectmodelskin 0 // resets to skin 0
// definemodelframe "foo3" 1005 1006 // these use skin 0
2007-12-12 17:42:14 +00:00
if ( seenframe ) { modelskin = + + lastmodelskin ; }
2006-11-13 23:12:47 +00:00
seenframe = 0 ;
2006-04-23 06:44:19 +00:00
2012-03-10 09:44:54 +00:00
i = pathsearchmode ;
pathsearchmode = 1 ;
if ( findfrompath ( skinfn , & tfn ) < 0 )
{
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , skinfn ) ;
kzfindfilestart ( buf ) ;
if ( ! kzfindfile ( buf ) )
{
initprintf ( " Error: file '%s' does not exist \n " , skinfn ) ;
pathsearchmode = i ;
break ;
}
}
else Bfree ( tfn ) ;
pathsearchmode = i ;
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2009-03-28 15:19:44 +00:00
switch ( md_defineskin ( lastmodelid , skinfn , palnum , max ( 0 , modelskin ) , 0 , 0.0f , 1.0f , 1.0f ) )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
case 0 :
break ;
case - 1 :
break ; // invalid model id!?
case - 2 :
initprintf ( " Invalid skin filename on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
case - 3 :
initprintf ( " Invalid palette number on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
case - 4 :
initprintf ( " Out of memory on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
# endif
}
break ;
2006-04-24 19:04:22 +00:00
case T_SELECTMODELSKIN :
2006-11-13 23:12:47 +00:00
{
if ( scriptfile_getsymbol ( script , & modelskin ) ) break ;
}
break ;
2006-04-24 19:04:22 +00:00
case T_DEFINEVOXEL :
2006-11-13 23:12:47 +00:00
{
char * fn ;
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getstring ( script , & fn ) ) break ; //voxel filename
2006-04-24 19:04:22 +00:00
2007-12-12 17:42:14 +00:00
if ( nextvoxid = = MAXVOXELS )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Maximum number of voxels already defined. \n " ) ;
break ;
}
2006-04-23 06:44:19 +00:00
2007-12-12 17:42:14 +00:00
if ( qloadkvx ( nextvoxid , fn ) )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Failure loading voxel file \" %s \" \n " , fn ) ;
break ;
}
2006-04-23 06:44:19 +00:00
2006-11-13 23:12:47 +00:00
lastvoxid = nextvoxid + + ;
}
break ;
2006-04-24 19:04:22 +00:00
case T_DEFINEVOXELTILES :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t ftilenume , ltilenume , tilex ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getnumber ( script , & ftilenume ) ) break ; //1st tile #
if ( scriptfile_getnumber ( script , & ltilenume ) ) break ; //last tile #
2007-12-12 17:42:14 +00:00
if ( ltilenume < ftilenume )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: backwards tile range on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
tilex = ftilenume ;
ftilenume = ltilenume ;
ltilenume = tilex ;
}
2007-12-12 17:42:14 +00:00
if ( ltilenume < 0 | | ftilenume > = MAXTILES )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Invalid tile range on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
}
2006-04-24 19:04:22 +00:00
2007-12-12 17:42:14 +00:00
if ( lastvoxid < 0 )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: Ignoring voxel tiles definition. \n " ) ;
break ;
}
2011-03-04 08:50:58 +00:00
2007-12-12 17:42:14 +00:00
for ( tilex = ftilenume ; tilex < = ltilenume ; tilex + + )
2006-11-13 23:12:47 +00:00
tiletovox [ tilex ] = lastvoxid ;
}
break ;
2006-04-23 06:44:19 +00:00
2006-11-13 23:12:47 +00:00
// NEW (ENCOURAGED) DEFINITION SYNTAX
2006-04-24 19:04:22 +00:00
case T_MODEL :
2006-11-13 23:12:47 +00:00
{
char * modelend , * modelfn ;
2012-01-17 04:31:59 +00:00
double scale = 1.0 , mzadd = 0.0 , myoffset = 0.0 ;
2009-01-09 09:29:17 +00:00
int32_t shadeoffs = 0 , pal = 0 , flags = 0 ;
2011-06-19 18:30:32 +00:00
uint8_t usedframebitmap [ 1024 > > 3 ] ;
2012-01-07 17:48:55 +00:00
int32_t model_ok = 1 ;
2010-08-02 08:13:51 +00:00
static const tokenlist modeltokens [ ] =
{
{ " scale " , T_SCALE } ,
{ " shade " , T_SHADE } ,
{ " zadd " , T_ZADD } ,
2012-01-17 04:31:59 +00:00
{ " yoffset " , T_YOFFSET } ,
2010-08-02 08:13:51 +00:00
{ " frame " , T_FRAME } ,
{ " anim " , T_ANIM } ,
{ " skin " , T_SKIN } ,
{ " detail " , T_DETAIL } ,
{ " glow " , T_GLOW } ,
{ " specular " , T_SPECULAR } ,
{ " normal " , T_NORMAL } ,
{ " hud " , T_HUD } ,
{ " flags " , T_FLAGS } ,
} ;
2011-07-01 12:22:12 +00:00
Bmemset ( usedframebitmap , 0 , sizeof ( usedframebitmap ) ) ;
2006-11-13 23:12:47 +00:00
modelskin = lastmodelskin = 0 ;
seenframe = 0 ;
2006-04-23 06:44:19 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getstring ( script , & modelfn ) ) break ;
2008-07-20 04:12:52 +00:00
if ( scriptfile_getbraces ( script , & modelend ) ) break ;
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
lastmodelid = md_loadmodel ( modelfn ) ;
2007-12-12 17:42:14 +00:00
if ( lastmodelid < 0 )
{
2008-07-20 04:12:52 +00:00
initprintf ( " Warning: Failed loading MD2/MD3 model \" %s \" \n " , modelfn ) ;
script - > textptr = modelend + 1 ;
2006-11-13 23:12:47 +00:00
break ;
}
2006-04-23 06:44:19 +00:00
# endif
2007-12-12 17:42:14 +00:00
while ( script - > textptr < modelend )
{
2009-01-09 09:29:17 +00:00
int32_t token = getatoken ( script , modeltokens , sizeof ( modeltokens ) / sizeof ( tokenlist ) ) ;
2007-12-12 17:42:14 +00:00
switch ( token )
{
2006-11-13 23:12:47 +00:00
//case T_ERROR: initprintf("Error on line %s:%d in model tokens\n", script->filename,script->linenum); break;
case T_SCALE :
scriptfile_getdouble ( script , & scale ) ; break ;
case T_SHADE :
scriptfile_getnumber ( script , & shadeoffs ) ; break ;
case T_ZADD :
scriptfile_getdouble ( script , & mzadd ) ; break ;
2012-01-17 04:31:59 +00:00
case T_YOFFSET :
scriptfile_getdouble ( script , & myoffset ) ; break ;
2007-12-20 19:14:38 +00:00
case T_FLAGS :
scriptfile_getnumber ( script , & flags ) ; break ;
2006-11-13 23:12:47 +00:00
case T_FRAME :
{
char * frametokptr = script - > ltextptr ;
char * frameend , * framename = 0 , happy = 1 ;
2011-06-19 18:30:32 +00:00
int32_t ftilenume = - 1 , ltilenume = - 1 , tilex = 0 , framei ;
2008-12-10 11:36:53 +00:00
double smoothduration = 0.1f ;
2006-11-13 23:12:47 +00:00
2010-08-02 08:13:51 +00:00
static const tokenlist modelframetokens [ ] =
{
{ " pal " , T_PAL } ,
{ " frame " , T_FRAME } ,
{ " name " , T_FRAME } ,
{ " tile " , T_TILE } ,
{ " tile0 " , T_TILE0 } ,
{ " tile1 " , T_TILE1 } ,
{ " smoothduration " , T_SMOOTHDURATION } ,
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getbraces ( script , & frameend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < frameend )
{
switch ( getatoken ( script , modelframetokens , sizeof ( modelframetokens ) / sizeof ( tokenlist ) ) )
{
2007-12-20 19:14:38 +00:00
case T_PAL :
scriptfile_getnumber ( script , & pal ) ; break ;
2006-11-13 23:12:47 +00:00
case T_FRAME :
scriptfile_getstring ( script , & framename ) ; break ;
case T_TILE :
scriptfile_getsymbol ( script , & ftilenume ) ; ltilenume = ftilenume ; break ;
case T_TILE0 :
scriptfile_getsymbol ( script , & ftilenume ) ; break ; //first tile number
case T_TILE1 :
scriptfile_getsymbol ( script , & ltilenume ) ; break ; //last tile number (inclusive)
2007-04-12 03:09:41 +00:00
case T_SMOOTHDURATION :
scriptfile_getdouble ( script , & smoothduration ) ; break ;
2006-11-13 23:12:47 +00:00
}
}
if ( ftilenume < 0 ) initprintf ( " Error: missing 'first tile number' for frame definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , frametokptr ) ) , happy = 0 ;
if ( ltilenume < 0 ) initprintf ( " Error: missing 'last tile number' for frame definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , frametokptr ) ) , happy = 0 ;
2012-01-07 17:48:55 +00:00
model_ok & = happy ;
2006-11-13 23:12:47 +00:00
if ( ! happy ) break ;
2007-12-12 17:42:14 +00:00
if ( ltilenume < ftilenume )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , frametokptr ) ) ;
tilex = ftilenume ;
ftilenume = ltilenume ;
ltilenume = tilex ;
}
2007-12-12 17:42:14 +00:00
if ( lastmodelid < 0 )
{
2012-01-27 15:03:18 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: Ignoring frame definition. \n " ) ;
2012-01-27 15:03:18 +00:00
# endif
2006-11-13 23:12:47 +00:00
break ;
}
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2007-12-12 17:42:14 +00:00
for ( tilex = ftilenume ; tilex < = ltilenume & & happy ; tilex + + )
{
2011-06-19 18:30:32 +00:00
framei = md_defineframe ( lastmodelid , framename , tilex , max ( 0 , modelskin ) , smoothduration , pal ) ;
switch ( framei )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
case - 1 :
happy = 0 ; break ; // invalid model id!?
case - 2 :
initprintf ( " Invalid tile number on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , frametokptr ) ) ;
happy = 0 ;
break ;
case - 3 :
initprintf ( " Invalid frame name on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , frametokptr ) ) ;
happy = 0 ;
break ;
2011-06-19 18:30:32 +00:00
default :
if ( framei > = 0 & & framei < 1024 )
usedframebitmap [ framei > > 3 ] | = ( 1 < < ( framei & 7 ) ) ;
2006-11-13 23:12:47 +00:00
}
2012-01-07 17:48:55 +00:00
model_ok & = happy ;
2006-11-13 23:12:47 +00:00
}
2006-04-23 06:44:19 +00:00
# endif
2006-11-13 23:12:47 +00:00
seenframe = 1 ;
}
break ;
case T_ANIM :
{
char * animtokptr = script - > ltextptr ;
char * animend , * startframe = 0 , * endframe = 0 , happy = 1 ;
2009-01-09 09:29:17 +00:00
int32_t flags = 0 ;
2006-11-13 23:12:47 +00:00
double dfps = 1.0 ;
2010-08-02 08:13:51 +00:00
static const tokenlist modelanimtokens [ ] =
{
{ " frame0 " , T_FRAME0 } ,
{ " frame1 " , T_FRAME1 } ,
{ " fps " , T_FPS } ,
{ " flags " , T_FLAGS } ,
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getbraces ( script , & animend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < animend )
{
switch ( getatoken ( script , modelanimtokens , sizeof ( modelanimtokens ) / sizeof ( tokenlist ) ) )
{
2006-11-13 23:12:47 +00:00
case T_FRAME0 :
scriptfile_getstring ( script , & startframe ) ; break ;
case T_FRAME1 :
scriptfile_getstring ( script , & endframe ) ; break ;
case T_FPS :
scriptfile_getdouble ( script , & dfps ) ; break ; //animation frame rate
case T_FLAGS :
scriptfile_getsymbol ( script , & flags ) ; break ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
}
if ( ! startframe ) initprintf ( " Error: missing 'start frame' for anim definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , animtokptr ) ) , happy = 0 ;
if ( ! endframe ) initprintf ( " Error: missing 'end frame' for anim definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , animtokptr ) ) , happy = 0 ;
2012-01-07 17:48:55 +00:00
model_ok & = happy ;
2006-11-13 23:12:47 +00:00
if ( ! happy ) break ;
2007-12-12 17:42:14 +00:00
if ( lastmodelid < 0 )
{
2012-01-27 15:03:18 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: Ignoring animation definition. \n " ) ;
2012-01-27 15:03:18 +00:00
# endif
2006-04-24 19:04:22 +00:00
break ;
2006-11-13 23:12:47 +00:00
}
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2009-01-09 09:29:17 +00:00
switch ( md_defineanimation ( lastmodelid , startframe , endframe , ( int32_t ) ( dfps * ( 65536.0 * .001 ) ) , flags ) )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
case 0 :
break ;
case - 1 :
break ; // invalid model id!?
case - 2 :
initprintf ( " Invalid starting frame name on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , animtokptr ) ) ;
2012-01-07 17:48:55 +00:00
model_ok = 0 ;
2006-11-13 23:12:47 +00:00
break ;
case - 3 :
initprintf ( " Invalid ending frame name on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , animtokptr ) ) ;
2012-01-07 17:48:55 +00:00
model_ok = 0 ;
2006-11-13 23:12:47 +00:00
break ;
case - 4 :
initprintf ( " Out of memory on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , animtokptr ) ) ;
2012-01-07 17:48:55 +00:00
model_ok = 0 ;
2006-11-13 23:12:47 +00:00
break ;
}
2006-04-23 06:44:19 +00:00
# endif
2007-12-12 17:42:14 +00:00
}
break ;
2009-04-28 22:56:43 +00:00
case T_SKIN : case T_DETAIL : case T_GLOW : case T_SPECULAR : case T_NORMAL :
2006-11-13 23:12:47 +00:00
{
char * skintokptr = script - > ltextptr ;
2012-03-10 09:44:54 +00:00
char * skinend , * skinfn = 0 , * tfn = NULL ;
int32_t palnum = 0 , surfnum = 0 , i ;
2009-03-28 15:19:44 +00:00
double param = 1.0 , specpower = 1.0 , specfactor = 1.0 ;
2006-11-13 23:12:47 +00:00
2010-08-02 08:13:51 +00:00
static const tokenlist modelskintokens [ ] =
{
{ " pal " , T_PAL } ,
{ " file " , T_FILE } ,
{ " surf " , T_SURF } ,
{ " surface " , T_SURF } ,
{ " intensity " , T_PARAM } ,
{ " scale " , T_PARAM } ,
{ " detailscale " , T_PARAM } ,
{ " specpower " , T_SPECPOWER } , { " parallaxscale " , T_SPECPOWER } ,
{ " specfactor " , T_SPECFACTOR } , { " parallaxbias " , T_SPECFACTOR } ,
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getbraces ( script , & skinend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < skinend )
{
switch ( getatoken ( script , modelskintokens , sizeof ( modelskintokens ) / sizeof ( tokenlist ) ) )
{
2006-11-13 23:12:47 +00:00
case T_PAL :
scriptfile_getsymbol ( script , & palnum ) ; break ;
2007-02-16 01:34:41 +00:00
case T_PARAM :
scriptfile_getdouble ( script , & param ) ; break ;
2009-03-28 15:19:44 +00:00
case T_SPECPOWER :
scriptfile_getdouble ( script , & specpower ) ; break ;
case T_SPECFACTOR :
scriptfile_getdouble ( script , & specfactor ) ; break ;
2006-11-13 23:12:47 +00:00
case T_FILE :
scriptfile_getstring ( script , & skinfn ) ; break ; //skin filename
case T_SURF :
scriptfile_getnumber ( script , & surfnum ) ; break ;
}
}
2007-12-12 17:42:14 +00:00
if ( ! skinfn )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: missing 'skin filename' for skin definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , skintokptr ) ) ;
2012-01-07 17:48:55 +00:00
model_ok = 0 ;
2006-11-13 23:12:47 +00:00
break ;
}
if ( seenframe ) { modelskin = + + lastmodelskin ; }
seenframe = 0 ;
2006-04-23 06:44:19 +00:00
2007-12-20 19:14:38 +00:00
switch ( token )
2007-02-16 01:34:41 +00:00
{
2007-12-20 19:14:38 +00:00
case T_DETAIL :
2007-02-16 01:34:41 +00:00
palnum = DETAILPAL ;
param = 1.0f / param ;
2007-12-20 19:14:38 +00:00
break ;
case T_GLOW :
2007-02-16 01:34:41 +00:00
palnum = GLOWPAL ;
2007-12-20 19:14:38 +00:00
break ;
2009-04-28 22:56:43 +00:00
case T_SPECULAR :
palnum = SPECULARPAL ;
break ;
case T_NORMAL :
palnum = NORMALPAL ;
break ;
2007-12-20 19:14:38 +00:00
}
2007-02-16 01:34:41 +00:00
2012-03-10 09:44:54 +00:00
i = pathsearchmode ;
pathsearchmode = 1 ;
if ( findfrompath ( skinfn , & tfn ) < 0 )
{
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , skinfn ) ;
kzfindfilestart ( buf ) ;
if ( ! kzfindfile ( buf ) )
{
initprintf ( " Error: file '%s' does not exist \n " , skinfn ) ;
pathsearchmode = i ;
break ;
}
}
else Bfree ( tfn ) ;
pathsearchmode = i ;
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2009-03-28 15:19:44 +00:00
switch ( md_defineskin ( lastmodelid , skinfn , palnum , max ( 0 , modelskin ) , surfnum , param , specpower , specfactor ) )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
case 0 :
break ;
case - 1 :
break ; // invalid model id!?
case - 2 :
initprintf ( " Invalid skin filename on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , skintokptr ) ) ;
2012-01-07 17:48:55 +00:00
model_ok = 0 ;
2006-11-13 23:12:47 +00:00
break ;
case - 3 :
initprintf ( " Invalid palette number on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , skintokptr ) ) ;
2012-01-07 17:48:55 +00:00
model_ok = 0 ;
2006-11-13 23:12:47 +00:00
break ;
case - 4 :
initprintf ( " Out of memory on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , skintokptr ) ) ;
2012-01-07 17:48:55 +00:00
model_ok = 0 ;
2006-11-13 23:12:47 +00:00
break ;
}
2006-04-23 06:44:19 +00:00
# endif
2007-12-12 17:42:14 +00:00
}
break ;
2006-11-13 23:12:47 +00:00
case T_HUD :
{
char * hudtokptr = script - > ltextptr ;
char happy = 1 , * frameend ;
2011-03-01 05:52:33 +00:00
int32_t ftilenume = - 1 , ltilenume = - 1 , tilex = 0 , flags = 0 , fov = - 1 ;
2006-11-13 23:12:47 +00:00
double xadd = 0.0 , yadd = 0.0 , zadd = 0.0 , angadd = 0.0 ;
2010-08-02 08:13:51 +00:00
static const tokenlist modelhudtokens [ ] =
{
{ " tile " , T_TILE } ,
{ " tile0 " , T_TILE0 } ,
{ " tile1 " , T_TILE1 } ,
{ " xadd " , T_XADD } ,
{ " yadd " , T_YADD } ,
{ " zadd " , T_ZADD } ,
{ " angadd " , T_ANGADD } ,
2011-03-01 05:52:33 +00:00
{ " fov " , T_FOV } ,
2010-08-02 08:13:51 +00:00
{ " hide " , T_HIDE } ,
{ " nobob " , T_NOBOB } ,
{ " flipped " , T_FLIPPED } ,
{ " nodepth " , T_NODEPTH } ,
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getbraces ( script , & frameend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < frameend )
{
switch ( getatoken ( script , modelhudtokens , sizeof ( modelhudtokens ) / sizeof ( tokenlist ) ) )
{
2006-11-13 23:12:47 +00:00
case T_TILE :
scriptfile_getsymbol ( script , & ftilenume ) ; ltilenume = ftilenume ; break ;
case T_TILE0 :
scriptfile_getsymbol ( script , & ftilenume ) ; break ; //first tile number
case T_TILE1 :
scriptfile_getsymbol ( script , & ltilenume ) ; break ; //last tile number (inclusive)
case T_XADD :
scriptfile_getdouble ( script , & xadd ) ; break ;
case T_YADD :
scriptfile_getdouble ( script , & yadd ) ; break ;
case T_ZADD :
scriptfile_getdouble ( script , & zadd ) ; break ;
case T_ANGADD :
scriptfile_getdouble ( script , & angadd ) ; break ;
2011-03-01 05:52:33 +00:00
case T_FOV :
scriptfile_getsymbol ( script , & fov ) ; break ;
2006-11-13 23:12:47 +00:00
case T_HIDE :
flags | = 1 ; break ;
case T_NOBOB :
flags | = 2 ; break ;
case T_FLIPPED :
flags | = 4 ; break ;
case T_NODEPTH :
flags | = 8 ; break ;
}
}
if ( ftilenume < 0 ) initprintf ( " Error: missing 'first tile number' for hud definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , hudtokptr ) ) , happy = 0 ;
if ( ltilenume < 0 ) initprintf ( " Error: missing 'last tile number' for hud definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , hudtokptr ) ) , happy = 0 ;
2012-01-07 17:48:55 +00:00
model_ok & = happy ;
2006-11-13 23:12:47 +00:00
if ( ! happy ) break ;
2007-12-12 17:42:14 +00:00
if ( ltilenume < ftilenume )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , hudtokptr ) ) ;
tilex = ftilenume ;
ftilenume = ltilenume ;
ltilenume = tilex ;
}
2007-12-12 17:42:14 +00:00
if ( lastmodelid < 0 )
{
2012-01-27 15:03:18 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
initprintf ( " Warning: Ignoring frame definition. \n " ) ;
2012-01-27 15:03:18 +00:00
# endif
2006-11-13 23:12:47 +00:00
break ;
}
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2007-12-12 17:42:14 +00:00
for ( tilex = ftilenume ; tilex < = ltilenume & & happy ; tilex + + )
{
2011-03-01 05:52:33 +00:00
switch ( md_definehud ( lastmodelid , tilex , xadd , yadd , zadd , angadd , flags , fov ) )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
case 0 :
break ;
case - 1 :
happy = 0 ; break ; // invalid model id!?
case - 2 :
initprintf ( " Invalid tile number on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , hudtokptr ) ) ;
happy = 0 ;
break ;
case - 3 :
initprintf ( " Invalid frame name on line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , hudtokptr ) ) ;
happy = 0 ;
break ;
}
2012-01-07 17:48:55 +00:00
model_ok & = happy ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
# endif
2007-12-12 17:42:14 +00:00
}
break ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
}
2006-04-23 06:44:19 +00:00
2012-01-27 15:03:02 +00:00
# ifdef USE_OPENGL
2012-01-07 17:48:55 +00:00
if ( ! model_ok )
{
if ( lastmodelid > = 0 )
{
initprintf ( " Removing model %d due to errors. \n " , lastmodelid ) ;
md_undefinemodel ( lastmodelid ) ;
nextmodelid - - ;
}
break ;
}
2012-01-17 04:31:59 +00:00
md_setmisc ( lastmodelid , ( float ) scale , shadeoffs , ( float ) mzadd , ( float ) myoffset , flags ) ;
2011-06-19 18:30:32 +00:00
// thin out the loaded model by throwing away unused frames
2012-01-12 20:48:38 +00:00
// FIXME: CURRENTLY DISABLED: interpolation may access frames we consider 'unused'?
# if 0
2011-06-19 18:30:32 +00:00
if ( models [ lastmodelid ] - > mdnum = = 3 & & ( ( md3model_t * ) models [ lastmodelid ] ) - > numframes < = 1024 )
{
2012-01-12 20:48:38 +00:00
# ifdef DEBUG_MODEL_MEM
2011-06-19 18:30:32 +00:00
md3model_t * m = ( md3model_t * ) models [ lastmodelid ] ;
int32_t i , onumframes ;
onumframes = m - > numframes ;
2011-10-17 18:42:10 +00:00
i =
2012-01-12 20:48:38 +00:00
# endif
2011-10-17 18:42:10 +00:00
md_thinoutmodel ( lastmodelid , usedframebitmap ) ;
2012-01-12 20:48:38 +00:00
# ifdef DEBUG_MODEL_MEM
2011-06-19 18:30:32 +00:00
if ( i > = 0 & & i < onumframes )
initprintf ( " used %d/%d frames: %s \n " , i , onumframes , modelfn ) ;
else if ( i < 0 )
initprintf ( " md_thinoutmodel returned %d: %s \n " , i , modelfn ) ;
2012-01-12 20:48:38 +00:00
# endif
2011-06-19 18:30:32 +00:00
}
2012-01-12 20:48:38 +00:00
# endif
2011-06-19 18:30:32 +00:00
if ( glrendmode = = 4 )
md3postload_polymer ( ( md3model_t * ) models [ lastmodelid ] ) ;
2006-04-23 06:44:19 +00:00
# endif
2006-11-13 23:12:47 +00:00
modelskin = lastmodelskin = 0 ;
seenframe = 0 ;
2006-04-23 06:44:19 +00:00
2006-11-13 23:12:47 +00:00
}
break ;
2006-04-24 19:04:22 +00:00
case T_VOXEL :
2006-11-13 23:12:47 +00:00
{
char * voxeltokptr = script - > ltextptr ;
char * fn , * modelend ;
2009-01-09 09:29:17 +00:00
int32_t tile0 = MAXTILES , tile1 = - 1 , tilex = - 1 ;
2006-04-23 06:44:19 +00:00
2010-08-02 08:13:51 +00:00
static const tokenlist voxeltokens [ ] =
{
{ " tile " , T_TILE } ,
{ " tile0 " , T_TILE0 } ,
{ " tile1 " , T_TILE1 } ,
{ " scale " , T_SCALE } ,
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getstring ( script , & fn ) ) break ; //voxel filename
2007-12-12 17:42:14 +00:00
if ( nextvoxid = = MAXVOXELS ) { initprintf ( " Maximum number of voxels already defined. \n " ) ; break ; }
2006-11-13 23:12:47 +00:00
if ( qloadkvx ( nextvoxid , fn ) ) { initprintf ( " Failure loading voxel file \" %s \" \n " , fn ) ; break ; }
lastvoxid = nextvoxid + + ;
2006-04-23 06:44:19 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getbraces ( script , & modelend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < modelend )
{
switch ( getatoken ( script , voxeltokens , sizeof ( voxeltokens ) / sizeof ( tokenlist ) ) )
{
2006-11-13 23:12:47 +00:00
//case T_ERROR: initprintf("Error on line %s:%d in voxel tokens\n", script->filename,linenum); break;
case T_TILE :
scriptfile_getsymbol ( script , & tilex ) ;
2009-01-09 09:29:17 +00:00
if ( ( uint32_t ) tilex < MAXTILES ) tiletovox [ tilex ] = lastvoxid ;
2006-11-13 23:12:47 +00:00
else initprintf ( " Invalid tile number on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , voxeltokptr ) ) ;
break ;
case T_TILE0 :
scriptfile_getsymbol ( script , & tile0 ) ; break ; //1st tile #
case T_TILE1 :
scriptfile_getsymbol ( script , & tile1 ) ;
if ( tile0 > tile1 )
{
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , voxeltokptr ) ) ;
tilex = tile0 ; tile0 = tile1 ; tile1 = tilex ;
}
if ( ( tile1 < 0 ) | | ( tile0 > = MAXTILES ) )
2007-12-12 17:42:14 +00:00
{ initprintf ( " Invalid tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , voxeltokptr ) ) ; break ; }
2009-02-19 16:47:54 +00:00
for ( tilex = tile0 ; tilex < = tile1 ; tilex + + ) tiletovox [ tilex ] = lastvoxid ;
2006-11-13 23:12:47 +00:00
break ; //last tile number (inclusive)
2007-12-12 17:42:14 +00:00
case T_SCALE :
{
2006-11-13 23:12:47 +00:00
double scale = 1.0 ;
scriptfile_getdouble ( script , & scale ) ;
2009-01-09 09:29:17 +00:00
voxscale [ lastvoxid ] = ( int32_t ) ( 65536 * scale ) ;
2011-06-18 13:02:08 +00:00
# ifdef USE_OPENGL
if ( voxmodels [ lastvoxid ] )
voxmodels [ lastvoxid ] - > scale = scale ;
# endif
2006-11-13 23:12:47 +00:00
break ;
}
2006-04-24 19:04:22 +00:00
}
}
2006-11-13 23:12:47 +00:00
lastvoxid = - 1 ;
}
break ;
2006-04-24 19:04:22 +00:00
case T_SKYBOX :
2006-11-13 23:12:47 +00:00
{
char * skyboxtokptr = script - > ltextptr ;
2007-04-30 19:41:19 +00:00
char * fn [ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 } , * modelend , happy = 1 , * tfn = NULL ;
2009-01-09 09:29:17 +00:00
int32_t i , tile = - 1 , pal = 0 , ii ;
2006-11-13 23:12:47 +00:00
2010-08-02 08:13:51 +00:00
static const tokenlist skyboxtokens [ ] =
{
{ " tile " , T_TILE } ,
{ " pal " , T_PAL } ,
{ " ft " , T_FRONT } , { " front " , T_FRONT } , { " forward " , T_FRONT } ,
{ " rt " , T_RIGHT } , { " right " , T_RIGHT } ,
{ " bk " , T_BACK } , { " back " , T_BACK } ,
{ " lf " , T_LEFT } , { " left " , T_LEFT } , { " lt " , T_LEFT } ,
{ " up " , T_TOP } , { " top " , T_TOP } , { " ceiling " , T_TOP } , { " ceil " , T_TOP } ,
{ " dn " , T_BOTTOM } , { " bottom " , T_BOTTOM } , { " floor " , T_BOTTOM } , { " down " , T_BOTTOM }
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getbraces ( script , & modelend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < modelend )
{
switch ( getatoken ( script , skyboxtokens , sizeof ( skyboxtokens ) / sizeof ( tokenlist ) ) )
{
2006-11-13 23:12:47 +00:00
//case T_ERROR: initprintf("Error on line %s:%d in skybox tokens\n",script->filename,linenum); break;
case T_TILE :
2007-12-12 17:42:14 +00:00
scriptfile_getsymbol ( script , & tile ) ; break ;
2006-11-13 23:12:47 +00:00
case T_PAL :
2007-12-12 17:42:14 +00:00
scriptfile_getsymbol ( script , & pal ) ; break ;
2006-11-13 23:12:47 +00:00
case T_FRONT :
scriptfile_getstring ( script , & fn [ 0 ] ) ; break ;
case T_RIGHT :
scriptfile_getstring ( script , & fn [ 1 ] ) ; break ;
case T_BACK :
scriptfile_getstring ( script , & fn [ 2 ] ) ; break ;
case T_LEFT :
scriptfile_getstring ( script , & fn [ 3 ] ) ; break ;
case T_TOP :
scriptfile_getstring ( script , & fn [ 4 ] ) ; break ;
case T_BOTTOM :
scriptfile_getstring ( script , & fn [ 5 ] ) ; break ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
}
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
if ( tile < 0 ) initprintf ( " Error: missing 'tile number' for skybox definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , skyboxtokptr ) ) , happy = 0 ;
2009-02-19 16:47:54 +00:00
for ( i = 0 ; i < 6 ; i + + )
2007-12-12 17:42:14 +00:00
{
2006-11-13 23:12:47 +00:00
if ( ! fn [ i ] ) initprintf ( " Error: missing '%s filename' for skybox definition near line %s:%d \n " , skyfaces [ i ] , script - > filename , scriptfile_getlinum ( script , skyboxtokptr ) ) , happy = 0 ;
2010-12-17 14:22:15 +00:00
// FIXME?
2007-04-30 19:41:19 +00:00
ii = pathsearchmode ;
pathsearchmode = 1 ;
2007-12-12 17:42:14 +00:00
if ( findfrompath ( fn [ i ] , & tfn ) < 0 )
{
2007-05-01 04:35:27 +00:00
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , fn [ i ] ) ;
kzfindfilestart ( buf ) ;
2007-12-12 17:42:14 +00:00
if ( ! kzfindfile ( buf ) )
{
2007-05-01 04:35:27 +00:00
initprintf ( " Error: file '%s' does not exist \n " , fn [ i ] ) ;
happy = 0 ;
2007-12-12 17:42:14 +00:00
}
}
else Bfree ( tfn ) ;
2007-04-30 19:41:19 +00:00
pathsearchmode = ii ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
if ( ! happy ) break ;
2006-04-24 19:04:22 +00:00
2006-11-13 23:12:47 +00:00
hicsetskybox ( tile , pal , fn ) ;
}
break ;
2010-12-30 08:13:37 +00:00
case T_HIGHPALOOKUP :
{
char * highpaltokptr = script - > ltextptr ;
2011-01-27 07:05:12 +00:00
int32_t basepal = - 1 , pal = - 1 , oldpathsearchmode ;
2010-12-30 08:13:37 +00:00
char * fn = NULL , * tfn = NULL ;
char * highpalend ;
2011-01-20 21:46:15 +00:00
# ifdef POLYMER
int32_t fd ;
2010-12-30 08:13:37 +00:00
char * highpaldata ;
2011-01-20 21:46:15 +00:00
# endif
2010-12-30 08:13:37 +00:00
static const tokenlist highpaltokens [ ] =
{
2011-01-27 07:05:12 +00:00
{ " basepal " , T_BASEPAL } ,
2010-12-30 08:13:37 +00:00
{ " pal " , T_PAL } ,
{ " file " , T_FILE }
} ;
if ( scriptfile_getbraces ( script , & highpalend ) ) break ;
while ( script - > textptr < highpalend )
{
switch ( getatoken ( script , highpaltokens , sizeof ( highpaltokens ) / sizeof ( tokenlist ) ) )
{
2011-01-27 07:05:12 +00:00
case T_BASEPAL :
scriptfile_getsymbol ( script , & basepal ) ; break ;
2010-12-30 08:13:37 +00:00
case T_PAL :
scriptfile_getsymbol ( script , & pal ) ; break ;
case T_FILE :
scriptfile_getstring ( script , & fn ) ; break ;
}
}
2011-01-27 07:05:12 +00:00
if ( ( unsigned ) basepal > = ( ( unsigned ) basepalcount ) )
{
initprintf ( " Error: missing or invalid 'base palette number' for highpalookup definition "
" near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , highpaltokptr ) ) ;
break ;
}
2010-12-30 08:13:37 +00:00
if ( ( unsigned ) pal > = ( ( unsigned ) MAXPALOOKUPS - RESERVEDPALS ) )
{
initprintf ( " Error: missing or invalid 'palette number' for highpalookup definition near "
" line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , highpaltokptr ) ) ;
break ;
}
2011-01-27 07:05:12 +00:00
2010-12-30 08:13:37 +00:00
if ( ! fn )
{
initprintf ( " Error: missing 'file name' for highpalookup definition near line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , highpaltokptr ) ) ;
break ;
}
2011-01-16 02:50:27 +00:00
2010-12-30 08:13:37 +00:00
oldpathsearchmode = pathsearchmode ;
pathsearchmode = 1 ;
if ( findfrompath ( fn , & tfn ) < 0 )
{
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , fn ) ;
kzfindfilestart ( buf ) ;
if ( ! kzfindfile ( buf ) )
{
initprintf ( " Error: file '%s' does not exist \n " , fn ) ;
pathsearchmode = oldpathsearchmode ;
break ;
}
}
else Bfree ( tfn ) ;
pathsearchmode = oldpathsearchmode ;
2010-12-31 01:35:00 +00:00
2011-01-20 21:46:15 +00:00
# ifdef POLYMER
2010-12-30 08:13:37 +00:00
fd = kopen4load ( fn , 0 ) ;
2010-12-31 01:35:00 +00:00
2011-01-03 22:04:20 +00:00
// load the highpalookup and send it to polymer
highpaldata = Bmalloc ( PR_HIGHPALOOKUP_DATA_SIZE ) ;
2010-12-31 01:35:00 +00:00
{
2011-01-03 22:04:20 +00:00
char * filebuf ;
2010-12-31 01:35:00 +00:00
int32_t xsiz , ysiz , filesize , i ;
filesize = kfilelength ( fd ) ;
filebuf = Bmalloc ( filesize ) ;
2011-01-20 21:46:15 +00:00
if ( ! filebuf ) { kclose ( fd ) ; Bfree ( highpaldata ) ; break ; }
2010-12-31 01:35:00 +00:00
klseek ( fd , 0 , SEEK_SET ) ;
if ( kread ( fd , filebuf , filesize ) ! = filesize )
2011-01-20 21:46:15 +00:00
{ kclose ( fd ) ; Bfree ( highpaldata ) ; initprintf ( " Error: didn't read all of '%s'. \n " , fn ) ; break ; }
2010-12-31 01:35:00 +00:00
kclose ( fd ) ;
kpgetdim ( filebuf , filesize , & xsiz , & ysiz ) ;
2011-01-16 02:50:27 +00:00
if ( xsiz ! = PR_HIGHPALOOKUP_DIM * PR_HIGHPALOOKUP_DIM | | ysiz ! = PR_HIGHPALOOKUP_DIM )
2010-12-31 01:35:00 +00:00
{
2011-01-03 22:04:20 +00:00
initprintf ( " Error: image dimensions of '%s' must be %dx%d. \n " ,
fn , PR_HIGHPALOOKUP_DIM * PR_HIGHPALOOKUP_DIM , PR_HIGHPALOOKUP_DIM ) ;
2010-12-31 01:35:00 +00:00
Bfree ( filebuf ) ; Bfree ( highpaldata ) ;
2010-12-30 08:13:37 +00:00
break ;
2010-12-31 01:35:00 +00:00
}
i = kprender ( filebuf , filesize , ( intptr_t ) highpaldata , xsiz * sizeof ( coltype ) , xsiz , ysiz , 0 , 0 ) ;
Bfree ( filebuf ) ;
if ( i )
2011-01-16 02:50:27 +00:00
{ Bfree ( highpaldata ) ; initprintf ( " Error: failed rendering '%s'. \n " , fn ) ; break ; }
2010-12-30 08:13:37 +00:00
}
2010-12-31 01:35:00 +00:00
2011-01-27 07:05:12 +00:00
polymer_definehighpalookup ( basepal , pal , highpaldata ) ;
2010-12-30 08:13:37 +00:00
Bfree ( highpaldata ) ;
2011-01-20 21:46:15 +00:00
# endif
2010-12-30 08:13:37 +00:00
}
break ;
2006-11-13 23:12:47 +00:00
case T_TINT :
{
char * tinttokptr = script - > ltextptr ;
2009-01-09 09:29:17 +00:00
int32_t red = 255 , green = 255 , blue = 255 , pal = - 1 , flags = 0 ;
2006-11-13 23:12:47 +00:00
char * tintend ;
2010-08-02 08:13:51 +00:00
static const tokenlist tinttokens [ ] =
{
{ " pal " , T_PAL } ,
{ " red " , T_RED } , { " r " , T_RED } ,
{ " green " , T_GREEN } , { " g " , T_GREEN } ,
{ " blue " , T_BLUE } , { " b " , T_BLUE } ,
{ " flags " , T_FLAGS }
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getbraces ( script , & tintend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < tintend )
{
switch ( getatoken ( script , tinttokens , sizeof ( tinttokens ) / sizeof ( tokenlist ) ) )
{
2006-11-13 23:12:47 +00:00
case T_PAL :
scriptfile_getsymbol ( script , & pal ) ; break ;
case T_RED :
scriptfile_getnumber ( script , & red ) ; red = min ( 255 , max ( 0 , red ) ) ; break ;
case T_GREEN :
scriptfile_getnumber ( script , & green ) ; green = min ( 255 , max ( 0 , green ) ) ; break ;
case T_BLUE :
scriptfile_getnumber ( script , & blue ) ; blue = min ( 255 , max ( 0 , blue ) ) ; break ;
case T_FLAGS :
scriptfile_getsymbol ( script , & flags ) ; break ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
}
2006-04-24 19:04:22 +00:00
2007-12-12 17:42:14 +00:00
if ( pal < 0 )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: missing 'palette number' for tint definition near line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , tinttokptr ) ) ;
break ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
hicsetpalettetint ( pal , red , green , blue , flags ) ;
}
break ;
2006-04-24 19:04:22 +00:00
case T_TEXTURE :
2006-11-13 23:12:47 +00:00
{
char * texturetokptr = script - > ltextptr , * textureend ;
2009-01-09 09:29:17 +00:00
int32_t tile = - 1 , token ;
2006-11-13 23:12:47 +00:00
2010-08-02 08:13:51 +00:00
static const tokenlist texturetokens [ ] =
{
{ " pal " , T_PAL } ,
{ " detail " , T_DETAIL } ,
{ " glow " , T_GLOW } ,
{ " specular " , T_SPECULAR } ,
{ " normal " , T_NORMAL } ,
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & tile ) ) break ;
if ( scriptfile_getbraces ( script , & textureend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < textureend )
{
2007-02-16 01:34:41 +00:00
token = getatoken ( script , texturetokens , sizeof ( texturetokens ) / sizeof ( tokenlist ) ) ;
2007-12-12 17:42:14 +00:00
switch ( token )
{
case T_PAL :
{
2006-11-13 23:12:47 +00:00
char * paltokptr = script - > ltextptr , * palend ;
2009-01-09 09:29:17 +00:00
int32_t pal = - 1 , i ;
2007-04-30 19:41:19 +00:00
char * fn = NULL , * tfn = NULL ;
2009-10-04 15:41:40 +00:00
double alphacut = - 1.0 , xscale = 1.0 , yscale = 1.0 , specpower = 1.0 , specfactor = 1.0 ;
2006-11-13 23:12:47 +00:00
char flags = 0 ;
2010-08-02 08:13:51 +00:00
static const tokenlist texturetokens_pal [ ] =
{
{ " file " , T_FILE } , { " name " , T_FILE } ,
{ " alphacut " , T_ALPHACUT } ,
{ " detailscale " , T_XSCALE } , { " scale " , T_XSCALE } , { " xscale " , T_XSCALE } , { " intensity " , T_XSCALE } ,
{ " yscale " , T_YSCALE } ,
{ " specpower " , T_SPECPOWER } , { " parallaxscale " , T_SPECPOWER } ,
{ " specfactor " , T_SPECFACTOR } , { " parallaxbias " , T_SPECFACTOR } ,
{ " nocompress " , T_NOCOMPRESS } ,
{ " nodownsize " , T_NODOWNSIZE } ,
} ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & pal ) ) break ;
if ( scriptfile_getbraces ( script , & palend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < palend )
{
switch ( getatoken ( script , texturetokens_pal , sizeof ( texturetokens_pal ) / sizeof ( tokenlist ) ) )
{
2006-11-13 23:12:47 +00:00
case T_FILE :
scriptfile_getstring ( script , & fn ) ; break ;
case T_ALPHACUT :
scriptfile_getdouble ( script , & alphacut ) ; break ;
2007-02-17 02:23:50 +00:00
case T_XSCALE :
scriptfile_getdouble ( script , & xscale ) ; break ;
case T_YSCALE :
scriptfile_getdouble ( script , & yscale ) ; break ;
2009-10-04 15:41:40 +00:00
case T_SPECPOWER :
scriptfile_getdouble ( script , & specpower ) ; break ;
case T_SPECFACTOR :
scriptfile_getdouble ( script , & specfactor ) ; break ;
2006-11-13 23:12:47 +00:00
case T_NOCOMPRESS :
flags | = 1 ; break ;
2008-08-26 04:00:42 +00:00
case T_NODOWNSIZE :
flags | = 16 ; break ;
2006-11-13 23:12:47 +00:00
default :
break ;
}
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
if ( ( unsigned ) tile > ( unsigned ) MAXTILES ) break ; // message is printed later
2007-12-12 17:42:14 +00:00
if ( ( unsigned ) pal > = ( ( unsigned ) MAXPALOOKUPS - RESERVEDPALS ) )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: missing or invalid 'palette number' for texture definition near "
" line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , paltokptr ) ) ;
break ;
}
2007-12-12 17:42:14 +00:00
if ( ! fn )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: missing 'file name' for texture definition near line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , paltokptr ) ) ;
break ;
}
2007-04-30 19:41:19 +00:00
i = pathsearchmode ;
pathsearchmode = 1 ;
2007-12-12 17:42:14 +00:00
if ( findfrompath ( fn , & tfn ) < 0 )
{
2007-05-01 04:35:27 +00:00
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , fn ) ;
kzfindfilestart ( buf ) ;
2007-12-12 17:42:14 +00:00
if ( ! kzfindfile ( buf ) )
{
2007-05-01 04:35:27 +00:00
initprintf ( " Error: file '%s' does not exist \n " , fn ) ;
2008-01-06 04:07:21 +00:00
pathsearchmode = i ;
2007-05-01 04:35:27 +00:00
break ;
}
2007-12-12 17:42:14 +00:00
}
else Bfree ( tfn ) ;
2007-04-30 19:41:19 +00:00
pathsearchmode = i ;
2007-02-17 02:23:50 +00:00
xscale = 1.0f / xscale ;
yscale = 1.0f / yscale ;
2009-10-04 15:41:40 +00:00
hicsetsubsttex ( tile , pal , fn , alphacut , xscale , yscale , specpower , specfactor , flags ) ;
2007-12-12 17:42:14 +00:00
}
break ;
2009-04-28 22:56:43 +00:00
case T_DETAIL : case T_GLOW : case T_SPECULAR : case T_NORMAL :
2007-12-12 17:42:14 +00:00
{
2007-01-15 09:08:57 +00:00
char * detailtokptr = script - > ltextptr , * detailend ;
2009-01-09 09:29:17 +00:00
int32_t pal = 0 , i ;
2007-04-30 19:41:19 +00:00
char * fn = NULL , * tfn = NULL ;
2009-04-28 22:56:43 +00:00
double xscale = 1.0 , yscale = 1.0 , specpower = 1.0 , specfactor = 1.0 ;
2007-01-15 09:08:57 +00:00
char flags = 0 ;
2010-08-02 08:13:51 +00:00
static const tokenlist texturetokens_pal [ ] =
{
{ " file " , T_FILE } , { " name " , T_FILE } ,
{ " alphacut " , T_ALPHACUT } ,
{ " detailscale " , T_XSCALE } , { " scale " , T_XSCALE } , { " xscale " , T_XSCALE } , { " intensity " , T_XSCALE } ,
{ " yscale " , T_YSCALE } ,
{ " specpower " , T_SPECPOWER } , { " parallaxscale " , T_SPECPOWER } ,
{ " specfactor " , T_SPECFACTOR } , { " parallaxbias " , T_SPECFACTOR } ,
{ " nocompress " , T_NOCOMPRESS } ,
{ " nodownsize " , T_NODOWNSIZE } ,
} ;
2007-01-15 09:08:57 +00:00
if ( scriptfile_getbraces ( script , & detailend ) ) break ;
2007-12-12 17:42:14 +00:00
while ( script - > textptr < detailend )
{
switch ( getatoken ( script , texturetokens_pal , sizeof ( texturetokens_pal ) / sizeof ( tokenlist ) ) )
{
2007-01-15 09:08:57 +00:00
case T_FILE :
scriptfile_getstring ( script , & fn ) ; break ;
2007-02-17 02:23:50 +00:00
case T_XSCALE :
2007-03-01 18:19:11 +00:00
scriptfile_getdouble ( script , & xscale ) ; break ;
case T_YSCALE :
scriptfile_getdouble ( script , & yscale ) ; break ;
2009-04-28 22:56:43 +00:00
case T_SPECPOWER :
scriptfile_getdouble ( script , & specpower ) ; break ;
case T_SPECFACTOR :
scriptfile_getdouble ( script , & specfactor ) ; break ;
2007-01-15 09:08:57 +00:00
case T_NOCOMPRESS :
flags | = 1 ; break ;
2008-08-26 04:00:42 +00:00
case T_NODOWNSIZE :
flags | = 16 ; break ;
2007-01-15 09:08:57 +00:00
default :
break ;
}
}
if ( ( unsigned ) tile > ( unsigned ) MAXTILES ) break ; // message is printed later
2007-12-12 17:42:14 +00:00
if ( ! fn )
{
2007-01-15 09:08:57 +00:00
initprintf ( " Error: missing 'file name' for texture definition near line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , detailtokptr ) ) ;
break ;
}
2007-04-30 19:41:19 +00:00
i = pathsearchmode ;
2007-05-01 04:35:27 +00:00
pathsearchmode = 1 ;
2007-12-12 17:42:14 +00:00
if ( findfrompath ( fn , & tfn ) < 0 )
{
2007-05-01 04:35:27 +00:00
char buf [ BMAX_PATH ] ;
Bstrcpy ( buf , fn ) ;
kzfindfilestart ( buf ) ;
2007-12-12 17:42:14 +00:00
if ( ! kzfindfile ( buf ) )
{
2007-05-01 04:35:27 +00:00
initprintf ( " Error: file '%s' does not exist \n " , fn ) ;
2008-01-06 04:07:21 +00:00
pathsearchmode = i ;
2007-05-01 04:35:27 +00:00
break ;
2007-12-12 17:42:14 +00:00
}
}
else Bfree ( tfn ) ;
2007-04-30 19:41:19 +00:00
pathsearchmode = i ;
2007-01-15 09:08:57 +00:00
2007-12-20 19:14:38 +00:00
switch ( token )
2007-02-16 01:34:41 +00:00
{
2007-12-20 19:14:38 +00:00
case T_DETAIL :
2007-02-16 01:34:41 +00:00
pal = DETAILPAL ;
2007-03-01 18:19:11 +00:00
xscale = 1.0f / xscale ;
2007-03-03 23:09:40 +00:00
yscale = 1.0f / yscale ;
2007-12-20 19:14:38 +00:00
break ;
case T_GLOW :
2007-02-16 01:34:41 +00:00
pal = GLOWPAL ;
2007-12-20 19:14:38 +00:00
break ;
2009-04-28 22:56:43 +00:00
case T_SPECULAR :
pal = SPECULARPAL ;
break ;
case T_NORMAL :
pal = NORMALPAL ;
break ;
2007-12-20 19:14:38 +00:00
}
2009-04-28 22:56:43 +00:00
hicsetsubsttex ( tile , pal , fn , - 1.0f , xscale , yscale , specpower , specfactor , flags ) ;
2007-12-12 17:42:14 +00:00
}
break ;
2006-11-13 23:12:47 +00:00
default :
2006-04-24 19:04:22 +00:00
break ;
}
}
2007-12-12 17:42:14 +00:00
if ( ( unsigned ) tile > = ( unsigned ) MAXTILES )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: missing or invalid 'tile number' for texture definition near line %s:%d \n " ,
script - > filename , scriptfile_getlinum ( script , texturetokptr ) ) ;
break ;
}
}
break ;
2006-04-24 19:04:22 +00:00
case T_UNDEFMODEL :
case T_UNDEFMODELRANGE :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t r0 , r1 ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & r0 ) ) break ;
2007-12-12 17:42:14 +00:00
if ( tokn = = T_UNDEFMODELRANGE )
{
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & r1 ) ) break ;
2007-12-12 17:42:14 +00:00
if ( r1 < r0 )
{
2009-01-09 09:29:17 +00:00
int32_t t = r1 ;
2006-04-24 19:04:22 +00:00
r1 = r0 ;
2006-11-13 23:12:47 +00:00
r0 = t ;
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
}
2007-12-12 17:42:14 +00:00
if ( r0 < 0 | | r1 > = MAXTILES )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: invalid tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
}
2007-12-12 17:42:14 +00:00
}
else
{
2006-11-13 23:12:47 +00:00
r1 = r0 ;
2007-12-12 17:42:14 +00:00
if ( ( unsigned ) r0 > = ( unsigned ) MAXTILES )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: invalid tile number on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
2006-04-24 19:04:22 +00:00
}
2006-11-13 23:12:47 +00:00
}
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2006-11-13 23:12:47 +00:00
for ( ; r0 < = r1 ; r0 + + ) md_undefinetile ( r0 ) ;
2006-04-23 06:44:19 +00:00
# endif
2006-11-13 23:12:47 +00:00
}
break ;
2006-04-23 06:44:19 +00:00
2006-04-24 19:04:22 +00:00
case T_UNDEFMODELOF :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t r0 ;
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2009-01-09 09:29:17 +00:00
int32_t mid ;
2008-07-24 11:16:20 +00:00
# endif
2006-04-23 06:44:19 +00:00
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & r0 ) ) break ;
2007-12-12 17:42:14 +00:00
if ( ( unsigned ) r0 > = ( unsigned ) MAXTILES )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: invalid tile number on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
}
2006-04-23 06:44:19 +00:00
2011-03-04 08:50:58 +00:00
# ifdef USE_OPENGL
2007-12-20 19:14:38 +00:00
mid = md_tilehasmodel ( r0 , 0 ) ;
2006-11-13 23:12:47 +00:00
if ( mid < 0 ) break ;
2006-04-23 06:44:19 +00:00
2006-11-13 23:12:47 +00:00
md_undefinemodel ( mid ) ;
2006-04-23 06:44:19 +00:00
# endif
2006-11-13 23:12:47 +00:00
}
break ;
2006-04-24 19:04:22 +00:00
case T_UNDEFTEXTURE :
case T_UNDEFTEXTURERANGE :
2006-11-13 23:12:47 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t r0 , r1 , i ;
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & r0 ) ) break ;
2007-12-12 17:42:14 +00:00
if ( tokn = = T_UNDEFTEXTURERANGE )
{
2006-11-13 23:12:47 +00:00
if ( scriptfile_getsymbol ( script , & r1 ) ) break ;
2007-12-12 17:42:14 +00:00
if ( r1 < r0 )
{
2009-01-09 09:29:17 +00:00
int32_t t = r1 ;
2006-04-24 19:04:22 +00:00
r1 = r0 ;
2006-11-13 23:12:47 +00:00
r0 = t ;
initprintf ( " Warning: backwards tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
}
2007-12-12 17:42:14 +00:00
if ( r0 < 0 | | r1 > = MAXTILES )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: invalid tile range on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
}
2007-12-12 17:42:14 +00:00
}
else
{
2006-11-13 23:12:47 +00:00
r1 = r0 ;
2007-12-12 17:42:14 +00:00
if ( ( unsigned ) r0 > = ( unsigned ) MAXTILES )
{
2006-11-13 23:12:47 +00:00
initprintf ( " Error: invalid tile number on line %s:%d \n " , script - > filename , scriptfile_getlinum ( script , cmdtokptr ) ) ;
break ;
2006-04-24 19:04:22 +00:00
}
}
2006-11-13 23:12:47 +00:00
for ( ; r0 < = r1 ; r0 + + )
for ( i = MAXPALOOKUPS - 1 ; i > = 0 ; i - - )
hicclearsubst ( r0 , i ) ;
}
break ;
2006-04-24 19:04:22 +00:00
Possibility of specifying sounds for a VPX anim-replacement via DEF.
The syntax is as follows:
animsounds <anim> { frame1 sound1 frame2 sound2 ... }
<anim> has to be one of the tokens: cineov2, cineov3, RADLOGO, DUKETEAM,
logo, vol41a, vol42a, vol4e1, vol43a, vol4e2, or vol4e3, corresponding
to hard-coded Duke3D anims.
The frameN's (1-based frame numbers) have to be in ascending order (but not
necessarily strictly ascending, so that a frame may have more than one sound).
Example: for Duke3D's XBLA nuke logo animation (IVF extracted from nuke.webm),
the following definition overlays the video with a sound sequence similar
(identical save for timing) to the original nuke animation:
// frame 1: FLY_BY, frame 64: PIPEBOMB_EXPLODE
animsounds logo { 1 244 64 14 }
git-svn-id: https://svn.eduke32.com/eduke32@2242 1a8010ca-5511-0410-912e-c29ae57300e0
2012-01-10 23:43:54 +00:00
case T_ANIMSOUNDS :
{
char * dummy ;
static const tokenlist dummytokens [ ] = { { " id " , T_ID } , } ;
if ( scriptfile_getstring ( script , & dummy ) ) break ;
if ( scriptfile_getbraces ( script , & dummy ) ) break ;
while ( script - > textptr < dummy )
{
// XXX?
getatoken ( script , dummytokens , sizeof ( dummytokens ) / sizeof ( dummytokens ) ) ;
}
}
break ;
2010-08-02 08:13:51 +00:00
case T_SOUND :
2007-12-20 19:14:38 +00:00
case T_MUSIC :
{
2008-03-08 05:23:15 +00:00
char * dummy , * dummy2 ;
2010-08-02 08:13:51 +00:00
static const tokenlist sound_musictokens [ ] =
2007-12-20 19:14:38 +00:00
{
2010-08-02 08:13:51 +00:00
{ " id " , T_ID } ,
{ " file " , T_FILE } ,
} ;
2007-12-20 19:14:38 +00:00
2008-03-08 05:23:15 +00:00
if ( scriptfile_getbraces ( script , & dummy ) ) break ;
while ( script - > textptr < dummy )
2007-12-20 19:14:38 +00:00
{
2008-03-08 05:23:15 +00:00
switch ( getatoken ( script , sound_musictokens , sizeof ( sound_musictokens ) / sizeof ( tokenlist ) ) )
2007-12-20 19:14:38 +00:00
{
case T_ID :
2010-08-02 08:13:51 +00:00
scriptfile_getstring ( script , & dummy2 ) ;
2008-03-08 05:23:15 +00:00
break ;
2007-12-20 19:14:38 +00:00
case T_FILE :
2008-03-08 05:23:15 +00:00
scriptfile_getstring ( script , & dummy2 ) ;
break ;
2007-12-20 19:14:38 +00:00
}
}
}
break ;
2012-03-10 09:44:17 +00:00
case T_ECHO :
{
char * string = NULL ;
scriptfile_getstring ( script , & string ) ;
initprintf ( " %s \n " , string ) ;
}
break ;
2006-04-24 19:04:22 +00:00
default :
initprintf ( " Unknown token. \n " ) ; break ;
}
}
return 0 ;
2006-04-23 06:44:19 +00:00
}
2011-01-16 00:23:39 +00:00
int32_t loaddefinitionsfile ( const char * fn )
2006-04-23 06:44:19 +00:00
{
2006-04-24 19:04:22 +00:00
scriptfile * script ;
2009-06-13 21:06:45 +00:00
int32_t f = flushlogwindow ;
2011-07-21 22:39:29 +00:00
int32_t i ;
2006-04-23 06:44:19 +00:00
2006-04-24 19:04:22 +00:00
script = scriptfile_fromfile ( fn ) ;
if ( ! script ) return - 1 ;
2006-04-23 06:44:19 +00:00
2009-06-13 21:06:45 +00:00
flushlogwindow = 1 ;
initprintf ( " Loading '%s' \n " , fn ) ;
flushlogwindow = 0 ;
2006-04-24 19:04:22 +00:00
defsparser ( script ) ;
2006-04-23 06:44:19 +00:00
2011-07-21 22:39:29 +00:00
for ( i = 0 ; i < g_defModulesNum ; + + i )
defsparser_include ( g_defModules [ i ] , NULL , " null " ) ;
2009-06-13 21:06:45 +00:00
flushlogwindow = f ;
2006-04-24 19:04:22 +00:00
scriptfile_close ( script ) ;
scriptfile_clearsymbols ( ) ;
2006-04-23 06:44:19 +00:00
2006-04-24 19:04:22 +00:00
return 0 ;
2006-04-23 06:44:19 +00:00
}
// vim:ts=4: