This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/common/bsplib/bspfile.c

569 lines
14 KiB
C
Raw Normal View History

2008-09-10 22:00:00 +02:00
//=======================================================================
// Copyright XashXT Group 2007 <20>
// bspfile.c - read\save bsp file
//=======================================================================
2007-06-21 22:00:00 +02:00
#include "bsplib.h"
2008-07-23 22:00:00 +02:00
#include "byteorder.h"
2008-08-16 22:00:00 +02:00
#include "const.h"
2007-06-21 22:00:00 +02:00
2008-08-16 22:00:00 +02:00
wfile_t *handle;
2008-09-10 22:00:00 +02:00
file_t *wadfile;
2008-08-16 22:00:00 +02:00
int s_table;
2008-09-10 22:00:00 +02:00
dheader_t *header;
dheader_t outheader;
int num_entities;
bsp_entity_t entities[MAX_MAP_ENTITIES];
2008-08-12 22:00:00 +02:00
char dentdata[MAX_MAP_ENTSTRING];
2008-09-07 22:00:00 +02:00
int entdatasize;
dshader_t dshaders[MAX_MAP_SHADERS];
int numshaders;
2008-08-12 22:00:00 +02:00
dplane_t dplanes[MAX_MAP_PLANES];
2008-09-07 22:00:00 +02:00
int numplanes;
2008-08-12 22:00:00 +02:00
dnode_t dnodes[MAX_MAP_NODES];
2008-09-07 22:00:00 +02:00
int numnodes;
dleaf_t dleafs[MAX_MAP_LEAFS];
int numleafs;
2008-08-12 22:00:00 +02:00
dword dleaffaces[MAX_MAP_LEAFFACES];
2008-09-07 22:00:00 +02:00
int numleaffaces;
2008-08-12 22:00:00 +02:00
dword dleafbrushes[MAX_MAP_LEAFBRUSHES];
2008-09-07 22:00:00 +02:00
int numleafbrushes;
dmodel_t dmodels[MAX_MAP_MODELS];
int nummodels;
2008-08-12 22:00:00 +02:00
dbrush_t dbrushes[MAX_MAP_BRUSHES];
2008-09-07 22:00:00 +02:00
int numbrushes;
2007-06-21 22:00:00 +02:00
dbrushside_t dbrushsides[MAX_MAP_BRUSHSIDES];
2008-09-07 22:00:00 +02:00
int numbrushsides;
dvertex_t dvertexes[MAX_MAP_VERTEXES];
int numvertexes;
2008-08-18 22:00:00 +02:00
int dindexes[MAX_MAP_INDEXES];
int numindexes;
2008-09-28 22:00:00 +02:00
byte dcollision[MAX_MAP_COLLISION];
int dcollisiondatasize;
2008-10-19 22:00:00 +02:00
dsurface_t dsurfaces[MAX_MAP_SURFACES];
int numsurfaces;
byte dlightdata[MAX_MAP_LIGHTDATA];
int lightdatasize;
byte dlightgrid[MAX_MAP_LIGHTGRID];
2008-09-10 22:00:00 +02:00
int numgridpoints;
2008-10-19 22:00:00 +02:00
int visdatasize;
2008-09-10 22:00:00 +02:00
byte dvisdata[MAX_MAP_VISIBILITY];
dvis_t *dvis = (dvis_t *)dvisdata;
2007-06-21 22:00:00 +02:00
//=============================================================================
2008-09-10 22:00:00 +02:00
/*
===============
CompressVis
===============
*/
int CompressVis( byte *vis, byte *dest )
{
int j;
int rep;
int visrow;
byte *dest_p;
dest_p = dest;
visrow = (dvis->numclusters + 7)>>3;
for( j = 0; j < visrow; j++ )
{
*dest_p++ = vis[j];
if( vis[j] ) continue;
rep = 1;
for( j++; j < visrow; j++ )
if( vis[j] || rep == 255 )
break;
else rep++;
*dest_p++ = rep;
j--;
}
return dest_p - dest;
}
/*
===================
DecompressVis
===================
*/
void DecompressVis( byte *in, byte *decompressed )
{
int c;
byte *out;
int row;
row = (dvis->numclusters+7)>>3;
out = decompressed;
do
{
if( *in )
{
*out++ = *in++;
continue;
}
c = in[1];
if( !c ) Sys_Error( "DecompressVis: 0 repeat\n" );
in += 2;
while( c )
{
*out++ = 0;
c--;
}
} while( out - decompressed < row );
}
2007-06-21 22:00:00 +02:00
/*
=============
SwapBSPFile
Byte swaps all data in a bsp file.
=============
*/
2008-09-10 22:00:00 +02:00
void SwapBSPFile( bool todisk )
2007-06-21 22:00:00 +02:00
{
2008-09-10 22:00:00 +02:00
int i, j;
2007-06-21 22:00:00 +02:00
2008-09-07 22:00:00 +02:00
// shaders
for( i = 0; i < numshaders; i++ )
{
dshaders[i].contents = LittleLong( dshaders[i].contents );
2008-10-19 22:00:00 +02:00
dshaders[i].flags = LittleLong( dshaders[i].flags );
2008-09-07 22:00:00 +02:00
}
2008-08-12 22:00:00 +02:00
2007-06-21 22:00:00 +02:00
// planes
2008-08-12 22:00:00 +02:00
SwapBlock( (int *)dplanes, numplanes * sizeof(dplanes[0]));
2007-06-21 22:00:00 +02:00
// nodes
2008-09-07 22:00:00 +02:00
SwapBlock( (int *)dnodes, numnodes * sizeof(dnodes[0]));
2007-06-21 22:00:00 +02:00
// leafs
2008-08-12 22:00:00 +02:00
SwapBlock( (int *)dleafs, numleafs * sizeof(dleafs[0]));
2007-06-21 22:00:00 +02:00
// leaffaces
2008-08-12 22:00:00 +02:00
SwapBlock( (int *)dleaffaces, numleaffaces * sizeof(dleaffaces[0]));
2007-06-21 22:00:00 +02:00
// leafbrushes
2008-08-12 22:00:00 +02:00
SwapBlock( (int *)dleafbrushes, numleafbrushes * sizeof(dleafbrushes[0]));
2007-06-21 22:00:00 +02:00
2008-09-07 22:00:00 +02:00
// models
SwapBlock( (int *)dmodels, nummodels * sizeof(dmodels[0]));
2007-06-21 22:00:00 +02:00
// brushes
2008-08-12 22:00:00 +02:00
SwapBlock( (int *)dbrushes, numbrushes * sizeof(dbrushes[0]));
2007-06-21 22:00:00 +02:00
// brushsides
2008-08-12 22:00:00 +02:00
SwapBlock( (int *)dbrushsides, numbrushsides * sizeof(dbrushsides[0]));
2008-09-07 22:00:00 +02:00
// vertices
SwapBlock( (int *)dvertexes, numvertexes * sizeof(dvertexes[0]));
2008-08-18 22:00:00 +02:00
// indices
SwapBlock( (int *)dindexes, numindexes * sizeof(dindexes[0]));
2008-09-07 22:00:00 +02:00
// surfaces
SwapBlock( (int *)dsurfaces, numsurfaces * sizeof(dsurfaces[0]));
2007-06-21 22:00:00 +02:00
// visibility
2008-09-10 22:00:00 +02:00
if( todisk ) j = dvis->numclusters;
else j = LittleLong( dvis->numclusters );
dvis->numclusters = LittleLong( dvis->numclusters );
for( i = 0; i < j; i++ )
{
dvis->bitofs[i][0] = LittleLong( dvis->bitofs[i][0] );
dvis->bitofs[i][1] = LittleLong( dvis->bitofs[i][1] );
}
2007-06-21 22:00:00 +02:00
}
2008-09-10 22:00:00 +02:00
#ifdef BSP_WADFILE
size_t CopyLump( const char *lumpname, void *dest, size_t block_size )
2008-08-16 22:00:00 +02:00
{
size_t length;
byte *in;
if( !handle ) return 0;
in = WAD_Read( handle, lumpname, &length, TYPE_BINDATA );
2008-09-10 22:00:00 +02:00
if( length % block_size ) Sys_Break( "LoadBSPFile: %s funny lump size\n", lumpname );
2008-08-16 22:00:00 +02:00
Mem_Copy( dest, in, length );
Mem_Free( in ); // no need more
return length / block_size;
}
2008-09-10 22:00:00 +02:00
void AddLump( const char *lumpname, const void *data, size_t length )
2008-08-16 22:00:00 +02:00
{
2008-09-10 22:00:00 +02:00
int compress = CMP_NONE;
2008-08-16 22:00:00 +02:00
if( !handle ) return;
2008-09-10 22:00:00 +02:00
if( length > 0xffff ) compress = CMP_ZLIB;
WAD_Write( handle, lumpname, data, length, TYPE_BINDATA, compress );
2008-08-16 22:00:00 +02:00
}
2008-09-10 22:00:00 +02:00
#else
2007-06-21 22:00:00 +02:00
2008-09-10 22:00:00 +02:00
size_t CopyLump( const int lumpname, void *dest, size_t block_size )
2007-06-21 22:00:00 +02:00
{
2008-09-10 22:00:00 +02:00
size_t length, ofs;
2007-06-21 22:00:00 +02:00
2008-09-10 22:00:00 +02:00
length = header->lumps[lumpname].filelen;
ofs = header->lumps[lumpname].fileofs;
2007-06-21 22:00:00 +02:00
2008-10-19 22:00:00 +02:00
if( length % block_size) Sys_Break( "LoadBSPFile: %i funny lump size", lumpname );
2007-12-13 22:00:00 +01:00
Mem_Copy(dest, (byte *)header + ofs, length);
2007-06-21 22:00:00 +02:00
2008-09-10 22:00:00 +02:00
return length / block_size;
2007-06-21 22:00:00 +02:00
}
2008-09-10 22:00:00 +02:00
void AddLump( const int lumpname, const void *data, size_t length )
{
lump_t *lump;
lump = &header->lumps[lumpname];
lump->fileofs = LittleLong( FS_Tell( wadfile ));
lump->filelen = LittleLong( length );
FS_Write( wadfile, data, (length + 3) & ~3 );
}
#endif
2007-06-21 22:00:00 +02:00
/*
=============
LoadBSPFile
=============
*/
bool LoadBSPFile( void )
{
2007-12-13 22:00:00 +01:00
byte *buffer;
2007-06-21 22:00:00 +02:00
2008-09-12 22:00:00 +02:00
buffer = (byte *)FS_LoadFile( va("maps/%s.bsp", gs_filename ), NULL );
2008-09-10 22:00:00 +02:00
if( !buffer ) return false;
2007-12-13 22:00:00 +01:00
header = (dheader_t *)buffer; // load the file header
2008-09-10 22:00:00 +02:00
if( pe ) pe->LoadBSP( buffer );
2007-12-13 22:00:00 +01:00
2008-09-10 22:00:00 +02:00
MsgDev( D_NOTE, "reading %s.bsp\n", gs_filename );
2007-06-21 22:00:00 +02:00
// swap the header
2008-09-10 22:00:00 +02:00
SwapBlock( (int *)header, sizeof( header ));
if( header->ident != IDBSPMODHEADER )
Sys_Break( "%s.bsp is not a IBSP file\n", gs_filename );
if( header->version != BSPMOD_VERSION )
Sys_Break( "%s.bsp is version %i, not %i\n", gs_filename, header->version, BSPMOD_VERSION );
entdatasize = CopyLump( LUMP_ENTITIES, dentdata, 1);
numshaders = CopyLump( LUMP_SHADERS, dshaders, sizeof(dshader_t));
numplanes = CopyLump( LUMP_PLANES, dplanes, sizeof(dplane_t));
numnodes = CopyLump( LUMP_NODES, dnodes, sizeof(dnode_t));
numleafs = CopyLump( LUMP_LEAFS, dleafs, sizeof(dleaf_t));
2008-10-19 22:00:00 +02:00
numleaffaces = CopyLump( LUMP_LEAFFACES, dleaffaces, sizeof(dleaffaces[0]));
2008-09-10 22:00:00 +02:00
numleafbrushes = CopyLump( LUMP_LEAFBRUSHES, dleafbrushes, sizeof(dleafbrushes[0]));
nummodels = CopyLump( LUMP_MODELS, dmodels, sizeof(dmodel_t));
numbrushes = CopyLump( LUMP_BRUSHES, dbrushes, sizeof(dbrush_t));
numbrushsides = CopyLump( LUMP_BRUSHSIDES, dbrushsides, sizeof(dbrushside_t));
numvertexes = CopyLump( LUMP_VERTICES, dvertexes, sizeof(dvertex_t));
numindexes = CopyLump( LUMP_INDICES, dindexes, sizeof(dindexes[0]));
2008-09-28 22:00:00 +02:00
dcollisiondatasize = CopyLump( LUMP_COLLISION, dcollision, 1);
2008-10-19 22:00:00 +02:00
numsurfaces = CopyLump( LUMP_SURFACES, dsurfaces, sizeof(dsurfaces[0]));
lightdatasize = CopyLump( LUMP_LIGHTMAPS, dlightdata, 1);
numgridpoints = CopyLump( LUMP_LIGHTGRID, dlightgrid, sizeof(dlightgrid_t));
2008-09-10 22:00:00 +02:00
visdatasize = CopyLump( LUMP_VISIBILITY, dvisdata, 1);
2007-06-21 22:00:00 +02:00
// swap everything
2008-09-10 22:00:00 +02:00
SwapBSPFile( false );
2007-06-21 22:00:00 +02:00
return true;
}
//============================================================================
/*
=============
WriteBSPFile
Swaps the bsp file in place, so it should not be referenced again
=============
*/
void WriteBSPFile( void )
{
header = &outheader;
2008-09-07 22:00:00 +02:00
memset( header, 0, sizeof( dheader_t ));
2007-06-21 22:00:00 +02:00
2008-09-10 22:00:00 +02:00
SwapBSPFile( true );
2007-06-21 22:00:00 +02:00
2008-09-07 22:00:00 +02:00
header->ident = LittleLong( IDBSPMODHEADER );
header->version = LittleLong( BSPMOD_VERSION );
2007-06-21 22:00:00 +02:00
2008-08-12 22:00:00 +02:00
// build path
2008-09-10 22:00:00 +02:00
MsgDev( D_NOTE, "writing %s.bsp\n", gs_filename );
2008-08-12 22:00:00 +02:00
if( pe ) pe->FreeBSP();
2007-06-21 22:00:00 +02:00
2008-09-10 22:00:00 +02:00
wadfile = FS_Open( va( "maps/%s.bsp", gs_filename ), "wb" );
2008-09-07 22:00:00 +02:00
FS_Write( wadfile, header, sizeof( dheader_t )); // overwritten later
2007-06-21 22:00:00 +02:00
2007-12-13 22:00:00 +01:00
AddLump (LUMP_ENTITIES, dentdata, entdatasize);
2008-09-07 22:00:00 +02:00
AddLump (LUMP_SHADERS, dshaders, numshaders*sizeof(dshaders[0]));
AddLump (LUMP_PLANES, dplanes, numplanes*sizeof(dplanes[0]));
AddLump (LUMP_NODES, dnodes, numnodes*sizeof(dnodes[0]));
AddLump (LUMP_LEAFS, dleafs, numleafs*sizeof(dleafs[0]));
2008-10-19 22:00:00 +02:00
AddLump (LUMP_LEAFFACES, dleaffaces, numleaffaces*sizeof(dleaffaces[0]));
2007-06-21 22:00:00 +02:00
AddLump (LUMP_LEAFBRUSHES, dleafbrushes, numleafbrushes*sizeof(dleafbrushes[0]));
2008-09-07 22:00:00 +02:00
AddLump (LUMP_MODELS, dmodels, nummodels*sizeof(dmodels[0]));
AddLump (LUMP_BRUSHES, dbrushes, numbrushes*sizeof(dbrushes[0]));
AddLump (LUMP_BRUSHSIDES, dbrushsides, numbrushsides*sizeof(dbrushsides[0]));
AddLump (LUMP_VERTICES, dvertexes, numvertexes*sizeof(dvertexes[0]));
AddLump (LUMP_INDICES, dindexes, numindexes*sizeof(dindexes[0]));
2008-09-28 22:00:00 +02:00
AddLump (LUMP_COLLISION, dcollision, dcollisiondatasize );
2008-10-19 22:00:00 +02:00
AddLump (LUMP_SURFACES, dsurfaces, numsurfaces*sizeof(dsurfaces[0]));
AddLump (LUMP_LIGHTMAPS, dlightdata, lightdatasize);
AddLump (LUMP_LIGHTGRID, dlightgrid, numgridpoints*sizeof(dlightgrid_t));
2008-09-10 22:00:00 +02:00
AddLump (LUMP_VISIBILITY, dvisdata, visdatasize);
2007-06-21 22:00:00 +02:00
FS_Seek( wadfile, 0, SEEK_SET );
FS_Write( wadfile, header, sizeof(dheader_t));
2007-12-13 22:00:00 +01:00
FS_Close( wadfile );
2007-06-21 22:00:00 +02:00
}
2008-09-10 22:00:00 +02:00
//============================================
// misc parse functions
2007-06-21 22:00:00 +02:00
//============================================
2008-09-10 22:00:00 +02:00
void StripTrailing( char *e )
2007-06-21 22:00:00 +02:00
{
char *s;
2008-09-10 22:00:00 +02:00
s = e + com.strlen( e ) - 1;
while( s >= e && *s <= 32 )
2007-06-21 22:00:00 +02:00
{
*s = 0;
s--;
}
}
/*
=================
ParseEpair
=================
*/
2008-11-01 22:00:00 +01:00
epair_t *ParseEpair( token_t *token )
2007-06-21 22:00:00 +02:00
{
epair_t *e;
2008-09-10 22:00:00 +02:00
e = BSP_Malloc( sizeof( epair_t ));
2007-06-21 22:00:00 +02:00
2008-11-01 22:00:00 +01:00
if( com.strlen( token->string ) >= MAX_KEY - 1 )
2008-09-10 22:00:00 +02:00
Sys_Break( "ParseEpair: token too long\n" );
2008-11-01 22:00:00 +01:00
e->key = copystring( token->string );
Com_ReadToken( mapfile, 0, token );
if( com.strlen( token->string ) >= MAX_VALUE - 1 )
2008-09-10 22:00:00 +02:00
Sys_Break( "ParseEpair: token too long\n" );
2008-11-01 22:00:00 +01:00
e->value = copystring( token->string );
2007-06-21 22:00:00 +02:00
// strip trailing spaces
2008-09-10 22:00:00 +02:00
StripTrailing( e->key );
StripTrailing( e->value );
2007-06-21 22:00:00 +02:00
return e;
}
/*
================
ParseEntity
================
*/
2008-09-10 22:00:00 +02:00
bool ParseEntity( void )
2007-06-21 22:00:00 +02:00
{
2008-09-10 22:00:00 +02:00
epair_t *e;
2008-11-01 22:00:00 +01:00
token_t token;
2007-07-28 22:00:00 +02:00
bsp_entity_t *mapent;
2007-06-21 22:00:00 +02:00
2008-11-01 22:00:00 +01:00
if( !Com_ReadToken( mapfile, SC_ALLOW_NEWLINES, &token ))
2008-09-10 22:00:00 +02:00
return false;
2007-06-21 22:00:00 +02:00
2008-11-01 22:00:00 +01:00
if( com.stricmp( token.string, "{" )) Sys_Break( "ParseEntity: '{' not found\n" );
if( num_entities == MAX_MAP_ENTITIES ) Sys_Break( "MAX_MAP_ENTITIES limit excceded\n" );
2007-06-21 22:00:00 +02:00
mapent = &entities[num_entities];
num_entities++;
2008-09-10 22:00:00 +02:00
while( 1 )
2007-06-21 22:00:00 +02:00
{
2008-11-01 22:00:00 +01:00
if( !Com_ReadToken( mapfile, SC_ALLOW_NEWLINES, &token ))
2008-09-10 22:00:00 +02:00
Sys_Break( "ParseEntity: EOF without closing brace\n" );
2008-11-01 22:00:00 +01:00
if( !com.stricmp( token.string, "}" )) break;
e = ParseEpair( &token );
2007-06-21 22:00:00 +02:00
e->next = mapent->epairs;
mapent->epairs = e;
2008-09-10 22:00:00 +02:00
}
2007-06-21 22:00:00 +02:00
return true;
}
/*
================
ParseEntities
Parses the dentdata string into entities
================
*/
2008-09-10 22:00:00 +02:00
void ParseEntities( void )
2007-06-21 22:00:00 +02:00
{
num_entities = 0;
2008-11-01 22:00:00 +01:00
mapfile = Com_OpenScript( "entities", dentdata, entdatasize );
if( mapfile ) while( ParseEntity( ));
Com_CloseScript( mapfile );
2007-06-21 22:00:00 +02:00
}
/*
================
UnparseEntities
Generates the dentdata string from all the entities
================
*/
2008-09-10 22:00:00 +02:00
void UnparseEntities( void )
2007-06-21 22:00:00 +02:00
{
2008-10-19 22:00:00 +02:00
epair_t *ep;
char *buf, *end;
char line[2048];
char key[MAX_KEY], value[MAX_VALUE];
int i;
2007-06-21 22:00:00 +02:00
buf = dentdata;
end = buf;
*end = 0;
2008-09-10 22:00:00 +02:00
for( i = 0; i < num_entities; i++ )
2007-06-21 22:00:00 +02:00
{
ep = entities[i].epairs;
2008-09-10 22:00:00 +02:00
if( !ep ) continue; // ent got removed
2007-06-21 22:00:00 +02:00
2008-09-10 22:00:00 +02:00
com.strcat( end, "{\n" );
2007-06-21 22:00:00 +02:00
end += 2;
2008-09-10 22:00:00 +02:00
for( ep = entities[i].epairs; ep; ep = ep->next )
2007-06-21 22:00:00 +02:00
{
2008-09-10 22:00:00 +02:00
com.strncpy( key, ep->key, MAX_KEY );
StripTrailing( key );
com.strncpy( value, ep->value, MAX_VALUE );
StripTrailing( value );
2007-06-21 22:00:00 +02:00
2008-09-10 22:00:00 +02:00
com.snprintf( line, 2048, "\"%s\" \"%s\"\n", key, value );
com.strcat( end, line );
end += com.strlen( line );
2007-06-21 22:00:00 +02:00
}
2008-09-10 22:00:00 +02:00
com.strcat( end, "}\n" );
2007-06-21 22:00:00 +02:00
end += 2;
2008-09-10 22:00:00 +02:00
if( end > buf + MAX_MAP_ENTSTRING )
Sys_Break( "Entity text too long\n" );
2007-06-21 22:00:00 +02:00
}
entdatasize = end - buf + 1;
}
2008-09-10 22:00:00 +02:00
void SetKeyValue( bsp_entity_t *ent, const char *key, const char *value )
2007-06-21 22:00:00 +02:00
{
epair_t *ep;
2008-09-10 22:00:00 +02:00
for( ep = ent->epairs; ep; ep = ep->next )
{
if(!com.strcmp( ep->key, key ))
2007-06-21 22:00:00 +02:00
{
2008-09-10 22:00:00 +02:00
Mem_Free( ep->value );
ep->value = copystring( value );
2007-06-21 22:00:00 +02:00
return;
}
2008-09-10 22:00:00 +02:00
}
ep = BSP_Malloc( sizeof( *ep ));
2007-06-21 22:00:00 +02:00
ep->next = ent->epairs;
ent->epairs = ep;
2008-09-10 22:00:00 +02:00
ep->key = copystring( key );
ep->value = copystring( value );
2007-06-21 22:00:00 +02:00
}
2008-10-19 22:00:00 +02:00
char *ValueForKey( bsp_entity_t *ent, const char *key )
2007-06-21 22:00:00 +02:00
{
epair_t *ep;
2008-09-10 22:00:00 +02:00
for( ep = ent->epairs; ep; ep = ep->next )
{
if(!com.strcmp( ep->key, key ))
2007-06-21 22:00:00 +02:00
return ep->value;
2008-09-10 22:00:00 +02:00
}
2007-06-21 22:00:00 +02:00
return "";
}
2008-10-19 22:00:00 +02:00
vec_t FloatForKey( bsp_entity_t *ent, const char *key )
2007-06-21 22:00:00 +02:00
{
char *k;
2008-09-10 22:00:00 +02:00
k = ValueForKey( ent, key );
return com.atof( k );
2007-06-21 22:00:00 +02:00
}
2008-10-19 22:00:00 +02:00
void GetVectorForKey( bsp_entity_t *ent, const char *key, vec3_t vec )
2007-06-21 22:00:00 +02:00
{
char *k;
double v1, v2, v3;
2008-11-01 22:00:00 +01:00
k = ValueForKey( ent, key );
2008-09-10 22:00:00 +02:00
2007-06-21 22:00:00 +02:00
// scanf into doubles, then assign, so it is vec_t size independent
v1 = v2 = v3 = 0;
2008-09-10 22:00:00 +02:00
sscanf( k, "%lf %lf %lf", &v1, &v2, &v3 );
VectorSet( vec, v1, v2, v3 );
2007-06-21 22:00:00 +02:00
}
2008-09-10 22:00:00 +02:00
void Com_CheckToken( const char *match )
{
2008-11-01 22:00:00 +01:00
token_t token;
Com_ReadToken( mapfile, SC_ALLOW_NEWLINES, &token );
2007-06-21 22:00:00 +02:00
2008-11-01 22:00:00 +01:00
if( com.stricmp( token.string, match ))
2008-09-10 22:00:00 +02:00
{
2008-10-19 22:00:00 +02:00
Sys_Break( "Com_CheckToken: \"%s\" not found\n", match );
2008-09-10 22:00:00 +02:00
}
}
void Com_Parse1DMatrix( int x, vec_t *m )
{
int i;
Com_CheckToken( "(" );
for( i = 0; i < x; i++ )
2008-11-01 22:00:00 +01:00
Com_ReadFloat( mapfile, false, &m[i] );
2008-09-10 22:00:00 +02:00
Com_CheckToken( ")" );
}
void Com_Parse2DMatrix( int y, int x, vec_t *m )
{
int i;
Com_CheckToken( "(" );
for( i = 0; i < y; i++ )
{
Com_Parse1DMatrix( x, m+i*x );
}
Com_CheckToken( ")" );
}
void Com_Parse3DMatrix( int z, int y, int x, vec_t *m )
{
int i;
Com_CheckToken( "(" );
for( i = 0; i < z; i++ )
{
Com_Parse2DMatrix( y, x, m+i*x*y );
}
Com_CheckToken( ")" );
}