2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
#include "bsplib.h"
|
2008-07-23 22:00:00 +02:00
|
|
|
#include "byteorder.h"
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
void GetLeafNums (void);
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int nummodels;
|
|
|
|
dmodel_t dmodels[MAX_MAP_MODELS];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int visdatasize;
|
|
|
|
byte dvisdata[MAX_MAP_VISIBILITY];
|
|
|
|
dvis_t *dvis = (dvis_t *)dvisdata;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int lightdatasize;
|
|
|
|
byte dlightdata[MAX_MAP_LIGHTING];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int entdatasize;
|
|
|
|
char dentdata[MAX_MAP_ENTSTRING];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numleafs;
|
|
|
|
dleaf_t dleafs[MAX_MAP_LEAFS];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numplanes;
|
|
|
|
dplane_t dplanes[MAX_MAP_PLANES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numvertexes;
|
|
|
|
dvertex_t dvertexes[MAX_MAP_VERTS];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numnodes;
|
|
|
|
dnode_t dnodes[MAX_MAP_NODES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numtexinfo;
|
|
|
|
dtexinfo_t texinfo[MAX_MAP_TEXINFO];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numfaces;
|
|
|
|
dface_t dfaces[MAX_MAP_FACES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numedges;
|
|
|
|
dedge_t dedges[MAX_MAP_EDGES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numleaffaces;
|
|
|
|
dword dleaffaces[MAX_MAP_LEAFFACES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numleafbrushes;
|
|
|
|
dword dleafbrushes[MAX_MAP_LEAFBRUSHES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numsurfedges;
|
|
|
|
int dsurfedges[MAX_MAP_SURFEDGES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numbrushes;
|
|
|
|
dbrush_t dbrushes[MAX_MAP_BRUSHES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numbrushsides;
|
2007-06-21 22:00:00 +02:00
|
|
|
dbrushside_t dbrushsides[MAX_MAP_BRUSHSIDES];
|
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int nummiptex;
|
|
|
|
dmiptex_t dmiptex[MAX_MAP_TEXTURES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
int numareas;
|
|
|
|
darea_t dareas[MAX_MAP_AREAS];
|
|
|
|
|
|
|
|
int numareaportals;
|
2007-06-21 22:00:00 +02:00
|
|
|
dareaportal_t dareaportals[MAX_MAP_AREAPORTALS];
|
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
byte dcollision[MAX_MAP_COLLISION];
|
|
|
|
int dcollisiondatasize = 256; // variable sized
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2007-12-16 22:00:00 +01:00
|
|
|
// string table system
|
2008-08-12 22:00:00 +02:00
|
|
|
char dstringdata[MAX_MAP_STRINGDATA];
|
|
|
|
int stringdatasize;
|
|
|
|
int dstringtable[MAX_MAP_NUMSTRINGS];
|
|
|
|
int numstrings;
|
2007-12-16 22:00:00 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
String table system
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
const char *GetStringFromTable( int index )
|
|
|
|
{
|
|
|
|
return &dstringdata[dstringtable[index]];
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetIndexFromTable( const char *string )
|
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
for( i = 0; i < numstrings; i++ )
|
|
|
|
{
|
|
|
|
if(!com.stricmp( string, &dstringdata[dstringtable[i]]))
|
|
|
|
return i; // found index
|
|
|
|
}
|
|
|
|
|
|
|
|
// register new string
|
|
|
|
len = com.strlen( string );
|
|
|
|
if( len + stringdatasize + 1 > MAX_MAP_STRINGDATA )
|
|
|
|
Sys_Error( "GetIndexFromTable: string data lump limit exeeded\n" );
|
|
|
|
|
|
|
|
if( numstrings + 1 > MAX_MAP_NUMSTRINGS )
|
|
|
|
Sys_Error( "GetIndexFromTable: string table lump limit exeeded\n" );
|
|
|
|
|
|
|
|
com.strcpy( &dstringdata[stringdatasize], string );
|
|
|
|
dstringtable[numstrings] = stringdatasize;
|
|
|
|
stringdatasize += len + 1; // null terminator
|
|
|
|
numstrings++;
|
|
|
|
|
|
|
|
return numstrings - 1; // current index
|
|
|
|
}
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
CompressVis
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2008-08-12 22:00:00 +02:00
|
|
|
int CompressVis( byte *vis, byte *dest )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
===================
|
|
|
|
*/
|
2008-08-12 22:00:00 +02:00
|
|
|
void DecompressVis( byte *in, byte *decompressed )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
byte *out;
|
|
|
|
int row;
|
|
|
|
|
|
|
|
// row = (r_numvisleafs+7)>>3;
|
|
|
|
row = (dvis->numclusters+7)>>3;
|
|
|
|
out = decompressed;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (*in)
|
|
|
|
{
|
|
|
|
*out++ = *in++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = in[1];
|
2007-11-25 22:00:00 +01:00
|
|
|
if (!c) Sys_Error("DecompressVis: 0 repeat");
|
2007-06-21 22:00:00 +02:00
|
|
|
in += 2;
|
|
|
|
while (c)
|
|
|
|
{
|
|
|
|
*out++ = 0;
|
|
|
|
c--;
|
|
|
|
}
|
|
|
|
} while (out - decompressed < row);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
SwapBSPFile
|
|
|
|
|
|
|
|
Byte swaps all data in a bsp file.
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void SwapBSPFile (bool todisk)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
// models
|
2008-08-12 22:00:00 +02:00
|
|
|
SwapBlock( (int *)dmodels, nummodels * sizeof(dmodels[0]));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
// vertexes
|
2008-08-12 22:00:00 +02:00
|
|
|
SwapBlock( (int *)dvertexes, numvertexes * sizeof(dvertexes[0]));
|
|
|
|
|
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
|
|
|
|
|
|
|
// texinfos
|
2008-08-12 22:00:00 +02:00
|
|
|
SwapBlock( (int *)texinfo, numtexinfo * sizeof(texinfo[0]));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
// nodes
|
2008-08-12 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
|
|
|
|
|
|
|
// surfedges
|
2008-08-12 22:00:00 +02:00
|
|
|
SwapBlock( (int *)texinfo, numsurfedges * sizeof(dsurfedges[0]));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
// edges
|
2008-08-12 22:00:00 +02:00
|
|
|
SwapBlock( (int *)dedges, numedges * sizeof(dedges[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
|
|
|
|
|
|
|
// areas
|
2008-08-12 22:00:00 +02:00
|
|
|
SwapBlock( (int *)dareas, numareas * sizeof(dareas[0]));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
// areasportals
|
2008-08-12 22:00:00 +02:00
|
|
|
SwapBlock( (int *)dareaportals, numareaportals * sizeof(dareaportals[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]));
|
|
|
|
|
|
|
|
// miptexes
|
|
|
|
SwapBlock( (int *)dmiptex, nummiptex * sizeof(dmiptex[0]));
|
|
|
|
|
|
|
|
// faces
|
|
|
|
// FIXME: i want using SwapBlock too
|
|
|
|
for( i = 0; i < numfaces; i++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
2008-08-12 22:00:00 +02:00
|
|
|
dfaces[i].planenum = LittleLong( dfaces[i].planenum );
|
|
|
|
dfaces[i].firstedge = LittleLong( dfaces[i].firstedge );
|
|
|
|
dfaces[i].numedges = LittleLong( dfaces[i].numedges );
|
|
|
|
dfaces[i].texinfo = LittleLong( dfaces[i].texinfo );
|
|
|
|
dfaces[i].lightofs = LittleLong( dfaces[i].lightofs );
|
|
|
|
dfaces[i].side = LittleShort (dfaces[i].side);
|
2007-06-21 22:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// visibility
|
2008-08-12 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++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
2008-08-12 22:00:00 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dheader_t *header;
|
|
|
|
|
2007-12-13 22:00:00 +01:00
|
|
|
int CopyLump( int lump, void *dest, int size )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
int length, ofs;
|
|
|
|
|
|
|
|
length = header->lumps[lump].filelen;
|
|
|
|
ofs = header->lumps[lump].fileofs;
|
|
|
|
|
2007-12-13 22:00:00 +01:00
|
|
|
if (length % size) Sys_Error("LoadBSPFile: odd lump size");
|
|
|
|
Mem_Copy(dest, (byte *)header + ofs, length);
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
return length / size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
LoadBSPFile
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
bool LoadBSPFile( void )
|
|
|
|
{
|
2007-12-13 22:00:00 +01:00
|
|
|
int i, size;
|
|
|
|
char path[MAX_SYSPATH];
|
|
|
|
byte *buffer;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2008-01-05 22:00:00 +01:00
|
|
|
sprintf(path, "maps/%s.bsp", gs_filename );
|
2007-12-13 22:00:00 +01:00
|
|
|
buffer = (byte *)FS_LoadFile(path, &size);
|
2007-06-21 22:00:00 +02:00
|
|
|
if(!size) return false;
|
2007-12-13 22:00:00 +01:00
|
|
|
|
|
|
|
header = (dheader_t *)buffer; // load the file header
|
|
|
|
if(pe) pe->LoadBSP( buffer );
|
|
|
|
|
|
|
|
MsgDev(D_NOTE, "reading %s\n", path);
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
// swap the header
|
2007-11-25 22:00:00 +01:00
|
|
|
for(i = 0; i < sizeof(dheader_t)/4; i++)
|
2007-06-21 22:00:00 +02:00
|
|
|
((int *)header)[i] = LittleLong (((int *)header)[i]);
|
|
|
|
|
2008-01-05 22:00:00 +01:00
|
|
|
if(header->ident != IDBSPMODHEADER) Sys_Error("%s is not a IBSP file", gs_filename);
|
|
|
|
if(header->version != BSPMOD_VERSION) Sys_Error("%s is version %i, not %i", gs_filename, header->version, BSPMOD_VERSION);
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2007-12-13 22:00:00 +01:00
|
|
|
entdatasize = CopyLump (LUMP_ENTITIES, dentdata, 1);
|
2007-06-21 22:00:00 +02:00
|
|
|
numplanes = CopyLump (LUMP_PLANES, dplanes, sizeof(dplane_t));
|
2007-12-13 22:00:00 +01:00
|
|
|
numvertexes = CopyLump (LUMP_VERTEXES, dvertexes, sizeof(dvertex_t));
|
|
|
|
visdatasize = CopyLump (LUMP_VISIBILITY, dvisdata, 1);
|
2007-06-21 22:00:00 +02:00
|
|
|
numnodes = CopyLump (LUMP_NODES, dnodes, sizeof(dnode_t));
|
2008-08-12 22:00:00 +02:00
|
|
|
numtexinfo = CopyLump (LUMP_TEXINFO, texinfo, sizeof(dtexinfo_t));
|
2007-06-21 22:00:00 +02:00
|
|
|
numfaces = CopyLump (LUMP_FACES, dfaces, sizeof(dface_t));
|
2007-12-13 22:00:00 +01:00
|
|
|
lightdatasize = CopyLump (LUMP_LIGHTING, dlightdata, 1);
|
|
|
|
numleafs = CopyLump (LUMP_LEAFS, dleafs, sizeof(dleaf_t));
|
2007-06-21 22:00:00 +02:00
|
|
|
numleaffaces = CopyLump (LUMP_LEAFFACES, dleaffaces, sizeof(dleaffaces[0]));
|
|
|
|
numleafbrushes = CopyLump (LUMP_LEAFBRUSHES, dleafbrushes, sizeof(dleafbrushes[0]));
|
|
|
|
numedges = CopyLump (LUMP_EDGES, dedges, sizeof(dedge_t));
|
2007-12-13 22:00:00 +01:00
|
|
|
numsurfedges = CopyLump (LUMP_SURFEDGES, dsurfedges, sizeof(dsurfedges[0]));
|
|
|
|
nummodels = CopyLump (LUMP_MODELS, dmodels, sizeof(dmodel_t));
|
2007-06-21 22:00:00 +02:00
|
|
|
numbrushes = CopyLump (LUMP_BRUSHES, dbrushes, sizeof(dbrush_t));
|
|
|
|
numbrushsides = CopyLump (LUMP_BRUSHSIDES, dbrushsides, sizeof(dbrushside_t));
|
2007-12-13 22:00:00 +01:00
|
|
|
dcollisiondatasize = CopyLump(LUMP_COLLISION, dcollision, 1);
|
2008-08-12 22:00:00 +02:00
|
|
|
nummiptex = CopyLump(LUMP_TEXTURES, dmiptex, sizeof(dmiptex_t));
|
2007-12-16 22:00:00 +01:00
|
|
|
stringdatasize = CopyLump( LUMP_STRINGDATA, dstringdata, sizeof(dstringdata[0]));
|
|
|
|
numstrings = CopyLump( LUMP_STRINGTABLE, dstringtable, sizeof(dstringtable[0]));
|
2007-06-21 22:00:00 +02:00
|
|
|
numareas = CopyLump (LUMP_AREAS, dareas, sizeof(darea_t));
|
|
|
|
numareaportals = CopyLump (LUMP_AREAPORTALS, dareaportals, sizeof(dareaportal_t));
|
|
|
|
|
|
|
|
// swap everything
|
|
|
|
SwapBSPFile (false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
file_t *wadfile; // because bsp it's really wadfile with fixed lump counter
|
2007-06-21 22:00:00 +02:00
|
|
|
dheader_t outheader;
|
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
void AddLump( int lumpnum, const void *data, size_t length )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
lump_t *lump;
|
|
|
|
|
|
|
|
lump = &header->lumps[lumpnum];
|
2008-08-12 22:00:00 +02:00
|
|
|
lump->fileofs = LittleLong( FS_Tell( wadfile ));
|
|
|
|
lump->filelen = LittleLong( length );
|
2007-12-13 22:00:00 +01:00
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
FS_Write( wadfile, data, (length + 3) & ~3 );
|
2007-06-21 22:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
WriteBSPFile
|
|
|
|
|
|
|
|
Swaps the bsp file in place, so it should not be referenced again
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void WriteBSPFile( void )
|
|
|
|
{
|
|
|
|
char path[MAX_SYSPATH];
|
|
|
|
|
|
|
|
header = &outheader;
|
|
|
|
memset (header, 0, sizeof(dheader_t));
|
|
|
|
|
|
|
|
SwapBSPFile (true);
|
|
|
|
|
|
|
|
header->ident = LittleLong (IDBSPMODHEADER);
|
|
|
|
header->version = LittleLong (BSPMOD_VERSION);
|
|
|
|
|
2008-08-12 22:00:00 +02:00
|
|
|
// build path
|
|
|
|
sprintf( path, "maps/%s.bsp", gs_filename );
|
|
|
|
MsgDev( D_NOTE, "writing %s\n", path );
|
|
|
|
if( pe ) pe->FreeBSP();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2007-11-10 22:00:00 +01:00
|
|
|
wadfile = FS_Open( path, "wb" );
|
2007-06-21 22:00:00 +02:00
|
|
|
FS_Write( wadfile, header, sizeof(dheader_t)); // overwritten later
|
|
|
|
|
2007-12-13 22:00:00 +01:00
|
|
|
AddLump (LUMP_ENTITIES, dentdata, entdatasize);
|
2007-06-21 22:00:00 +02:00
|
|
|
AddLump (LUMP_PLANES, dplanes, numplanes*sizeof(dplane_t));
|
|
|
|
AddLump (LUMP_VERTEXES, dvertexes, numvertexes*sizeof(dvertex_t));
|
2007-12-13 22:00:00 +01:00
|
|
|
AddLump (LUMP_VISIBILITY, dvisdata, visdatasize);
|
2007-06-21 22:00:00 +02:00
|
|
|
AddLump (LUMP_NODES, dnodes, numnodes*sizeof(dnode_t));
|
2008-08-12 22:00:00 +02:00
|
|
|
AddLump (LUMP_TEXINFO, texinfo, numtexinfo*sizeof(dtexinfo_t));
|
2007-06-21 22:00:00 +02:00
|
|
|
AddLump (LUMP_FACES, dfaces, numfaces*sizeof(dface_t));
|
2007-12-13 22:00:00 +01:00
|
|
|
AddLump (LUMP_LIGHTING, dlightdata, lightdatasize);
|
|
|
|
AddLump (LUMP_LEAFS, dleafs, numleafs*sizeof(dleaf_t));
|
2007-06-21 22:00:00 +02:00
|
|
|
AddLump (LUMP_LEAFFACES, dleaffaces, numleaffaces*sizeof(dleaffaces[0]));
|
|
|
|
AddLump (LUMP_LEAFBRUSHES, dleafbrushes, numleafbrushes*sizeof(dleafbrushes[0]));
|
|
|
|
AddLump (LUMP_EDGES, dedges, numedges*sizeof(dedge_t));
|
2007-12-13 22:00:00 +01:00
|
|
|
AddLump (LUMP_SURFEDGES, dsurfedges, numsurfedges*sizeof(dsurfedges[0]));
|
2007-06-21 22:00:00 +02:00
|
|
|
AddLump (LUMP_MODELS, dmodels, nummodels*sizeof(dmodel_t));
|
2007-12-13 22:00:00 +01:00
|
|
|
AddLump (LUMP_BRUSHES, dbrushes, numbrushes*sizeof(dbrush_t));
|
|
|
|
AddLump (LUMP_BRUSHSIDES, dbrushsides, numbrushsides*sizeof(dbrushside_t));
|
|
|
|
AddLump (LUMP_COLLISION, dcollision, dcollisiondatasize );
|
2008-08-12 22:00:00 +02:00
|
|
|
AddLump (LUMP_TEXTURES, dmiptex, nummiptex*sizeof(dmiptex[0]));
|
2007-12-16 22:00:00 +01:00
|
|
|
AddLump (LUMP_STRINGDATA, dstringdata, stringdatasize * sizeof(dstringdata[0]));
|
|
|
|
AddLump (LUMP_STRINGTABLE, dstringtable, numstrings * sizeof(dstringtable[0]));
|
2007-06-21 22:00:00 +02:00
|
|
|
AddLump (LUMP_AREAS, dareas, numareas*sizeof(darea_t));
|
|
|
|
AddLump (LUMP_AREAPORTALS, dareaportals, numareaportals*sizeof(dareaportal_t));
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//============================================
|
|
|
|
|
|
|
|
int num_entities;
|
2007-07-28 22:00:00 +02:00
|
|
|
bsp_entity_t entities[MAX_MAP_ENTITIES];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
void StripTrailing (char *e)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = e + strlen(e)-1;
|
|
|
|
while (s >= e && *s <= 32)
|
|
|
|
{
|
|
|
|
*s = 0;
|
|
|
|
s--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
ParseEpair
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
epair_t *ParseEpair (void)
|
|
|
|
{
|
|
|
|
epair_t *e;
|
|
|
|
|
|
|
|
e = Malloc (sizeof(epair_t));
|
|
|
|
|
2007-11-25 22:00:00 +01:00
|
|
|
if (strlen(com_token) >= MAX_KEY - 1)Sys_Error ("ParseEpar: token too long");
|
2007-11-11 22:00:00 +01:00
|
|
|
e->key = copystring(com_token);
|
|
|
|
Com_GetToken (false);
|
2007-11-25 22:00:00 +01:00
|
|
|
if (strlen(com_token) >= MAX_VALUE - 1)Sys_Error ("ParseEpar: token too long");
|
2007-11-11 22:00:00 +01:00
|
|
|
e->value = copystring(com_token);
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
// strip trailing spaces
|
|
|
|
StripTrailing (e->key);
|
|
|
|
StripTrailing (e->value);
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
ParseEntity
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
bool ParseEntity (void)
|
|
|
|
{
|
|
|
|
epair_t *e;
|
2007-07-28 22:00:00 +02:00
|
|
|
bsp_entity_t *mapent;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2007-11-11 22:00:00 +01:00
|
|
|
if (!Com_GetToken (true)) return false;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2007-11-25 22:00:00 +01:00
|
|
|
if (!Com_MatchToken( "{")) Sys_Error ("ParseEntity: { not found");
|
2007-06-21 22:00:00 +02:00
|
|
|
if (num_entities == MAX_MAP_ENTITIES) Sys_Error ("num_entities == MAX_MAP_ENTITIES");
|
|
|
|
|
|
|
|
mapent = &entities[num_entities];
|
|
|
|
num_entities++;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2007-11-25 22:00:00 +01:00
|
|
|
if (!Com_GetToken (true)) Sys_Error("ParseEntity: EOF without closing brace");
|
2007-11-11 22:00:00 +01:00
|
|
|
if (Com_MatchToken("}")) break;
|
2007-11-25 22:00:00 +01:00
|
|
|
e = ParseEpair();
|
2007-06-21 22:00:00 +02:00
|
|
|
e->next = mapent->epairs;
|
|
|
|
mapent->epairs = e;
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
ParseEntities
|
|
|
|
|
|
|
|
Parses the dentdata string into entities
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void ParseEntities (void)
|
|
|
|
{
|
|
|
|
num_entities = 0;
|
2007-11-11 22:00:00 +01:00
|
|
|
if(Com_LoadScript("entities", dentdata, entdatasize))
|
2007-06-21 22:00:00 +02:00
|
|
|
while(ParseEntity());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
UnparseEntities
|
|
|
|
|
|
|
|
Generates the dentdata string from all the entities
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void UnparseEntities (void)
|
|
|
|
{
|
|
|
|
char *buf, *end;
|
|
|
|
epair_t *ep;
|
|
|
|
char line[2048];
|
|
|
|
int i;
|
|
|
|
char key[1024], value[1024];
|
|
|
|
|
|
|
|
buf = dentdata;
|
|
|
|
end = buf;
|
|
|
|
*end = 0;
|
|
|
|
|
2007-11-25 22:00:00 +01:00
|
|
|
for (i = 0; i < num_entities; i++)
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
ep = entities[i].epairs;
|
|
|
|
if (!ep) continue; // ent got removed
|
|
|
|
|
|
|
|
strcat (end,"{\n");
|
|
|
|
end += 2;
|
|
|
|
|
|
|
|
for (ep = entities[i].epairs ; ep ; ep=ep->next)
|
|
|
|
{
|
|
|
|
strcpy (key, ep->key);
|
|
|
|
StripTrailing (key);
|
|
|
|
strcpy (value, ep->value);
|
|
|
|
StripTrailing (value);
|
|
|
|
|
|
|
|
sprintf (line, "\"%s\" \"%s\"\n", key, value);
|
|
|
|
strcat (end, line);
|
|
|
|
end += strlen(line);
|
|
|
|
}
|
|
|
|
strcat (end,"}\n");
|
|
|
|
end += 2;
|
|
|
|
|
2007-11-25 22:00:00 +01:00
|
|
|
if (end > buf + MAX_MAP_ENTSTRING) Sys_Error("Entity text too long");
|
2007-06-21 22:00:00 +02:00
|
|
|
}
|
|
|
|
entdatasize = end - buf + 1;
|
|
|
|
}
|
|
|
|
|
2007-07-28 22:00:00 +02:00
|
|
|
void SetKeyValue (bsp_entity_t *ent, char *key, char *value)
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
epair_t *ep;
|
|
|
|
|
|
|
|
for (ep=ent->epairs ; ep ; ep=ep->next)
|
|
|
|
if (!strcmp (ep->key, key) )
|
|
|
|
{
|
2008-01-28 22:00:00 +01:00
|
|
|
Mem_Free (ep->value);
|
2007-06-21 22:00:00 +02:00
|
|
|
ep->value = copystring(value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ep = Malloc (sizeof(*ep));
|
|
|
|
ep->next = ent->epairs;
|
|
|
|
ent->epairs = ep;
|
|
|
|
ep->key = copystring(key);
|
|
|
|
ep->value = copystring(value);
|
|
|
|
}
|
|
|
|
|
2007-07-28 22:00:00 +02:00
|
|
|
char *ValueForKey (bsp_entity_t *ent, char *key)
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
epair_t *ep;
|
|
|
|
|
|
|
|
for (ep=ent->epairs ; ep ; ep=ep->next)
|
|
|
|
if (!strcmp (ep->key, key) )
|
|
|
|
return ep->value;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2007-07-28 22:00:00 +02:00
|
|
|
vec_t FloatForKey (bsp_entity_t *ent, char *key)
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
char *k;
|
|
|
|
|
|
|
|
k = ValueForKey (ent, key);
|
|
|
|
return atof(k);
|
|
|
|
}
|
|
|
|
|
2007-07-28 22:00:00 +02:00
|
|
|
void GetVectorForKey (bsp_entity_t *ent, char *key, vec3_t vec)
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
char *k;
|
|
|
|
double v1, v2, v3;
|
|
|
|
|
|
|
|
k = ValueForKey (ent, key);
|
|
|
|
// scanf into doubles, then assign, so it is vec_t size independent
|
|
|
|
v1 = v2 = v3 = 0;
|
|
|
|
sscanf (k, "%lf %lf %lf", &v1, &v2, &v3);
|
|
|
|
vec[0] = v1;
|
|
|
|
vec[1] = v2;
|
|
|
|
vec[2] = v3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|