Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

l_bsp_q1.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 
00023 #include "l_cmd.h"
00024 #include "l_math.h"
00025 #include "l_mem.h"
00026 #include "l_log.h"
00027 #include "../botlib/l_script.h"
00028 #include "l_bsp_q1.h"
00029 #include "l_bsp_ent.h"
00030 
00031 //=============================================================================
00032 
00033 int             q1_nummodels;
00034 q1_dmodel_t     *q1_dmodels;//[MAX_MAP_MODELS];
00035 
00036 int             q1_visdatasize;
00037 byte                *q1_dvisdata;//[MAX_MAP_VISIBILITY];
00038 
00039 int             q1_lightdatasize;
00040 byte                *q1_dlightdata;//[MAX_MAP_LIGHTING];
00041 
00042 int             q1_texdatasize;
00043 byte                *q1_dtexdata;//[MAX_MAP_MIPTEX]; // (dmiptexlump_t)
00044 
00045 int             q1_entdatasize;
00046 char                *q1_dentdata;//[MAX_MAP_ENTSTRING];
00047 
00048 int             q1_numleafs;
00049 q1_dleaf_t      *q1_dleafs;//[MAX_MAP_LEAFS];
00050 
00051 int             q1_numplanes;
00052 q1_dplane_t     *q1_dplanes;//[MAX_MAP_PLANES];
00053 
00054 int             q1_numvertexes;
00055 q1_dvertex_t    *q1_dvertexes;//[MAX_MAP_VERTS];
00056 
00057 int             q1_numnodes;
00058 q1_dnode_t      *q1_dnodes;//[MAX_MAP_NODES];
00059 
00060 int             q1_numtexinfo;
00061 q1_texinfo_t    *q1_texinfo;//[MAX_MAP_TEXINFO];
00062 
00063 int             q1_numfaces;
00064 q1_dface_t      *q1_dfaces;//[MAX_MAP_FACES];
00065 
00066 int             q1_numclipnodes;
00067 q1_dclipnode_t  *q1_dclipnodes;//[MAX_MAP_CLIPNODES];
00068 
00069 int             q1_numedges;
00070 q1_dedge_t      *q1_dedges;//[MAX_MAP_EDGES];
00071 
00072 int             q1_nummarksurfaces;
00073 unsigned short  *q1_dmarksurfaces;//[MAX_MAP_MARKSURFACES];
00074 
00075 int             q1_numsurfedges;
00076 int             *q1_dsurfedges;//[MAX_MAP_SURFEDGES];
00077 
00078 //=============================================================================
00079 
00080 int q1_bspallocated = false;
00081 int q1_allocatedbspmem = 0;
00082 
00083 void Q1_AllocMaxBSP(void)
00084 {
00085     //models
00086     q1_nummodels = 0;
00087     q1_dmodels = (q1_dmodel_t *) GetMemory(Q1_MAX_MAP_MODELS * sizeof(q1_dmodel_t));
00088     q1_allocatedbspmem = Q1_MAX_MAP_MODELS * sizeof(q1_dmodel_t);
00089     //visibility
00090     q1_visdatasize = 0;
00091     q1_dvisdata = (byte *) GetMemory(Q1_MAX_MAP_VISIBILITY * sizeof(byte));
00092     q1_allocatedbspmem += Q1_MAX_MAP_VISIBILITY * sizeof(byte);
00093     //light data
00094     q1_lightdatasize = 0;
00095     q1_dlightdata = (byte *) GetMemory(Q1_MAX_MAP_LIGHTING * sizeof(byte));
00096     q1_allocatedbspmem += Q1_MAX_MAP_LIGHTING * sizeof(byte);
00097     //texture data
00098     q1_texdatasize = 0;
00099     q1_dtexdata = (byte *) GetMemory(Q1_MAX_MAP_MIPTEX * sizeof(byte)); // (dmiptexlump_t)
00100     q1_allocatedbspmem += Q1_MAX_MAP_MIPTEX * sizeof(byte);
00101     //entities
00102     q1_entdatasize = 0;
00103     q1_dentdata = (char *) GetMemory(Q1_MAX_MAP_ENTSTRING * sizeof(char));
00104     q1_allocatedbspmem += Q1_MAX_MAP_ENTSTRING * sizeof(char);
00105     //leaves
00106     q1_numleafs = 0;
00107     q1_dleafs = (q1_dleaf_t *) GetMemory(Q1_MAX_MAP_LEAFS * sizeof(q1_dleaf_t));
00108     q1_allocatedbspmem += Q1_MAX_MAP_LEAFS * sizeof(q1_dleaf_t);
00109     //planes
00110     q1_numplanes = 0;
00111     q1_dplanes = (q1_dplane_t *) GetMemory(Q1_MAX_MAP_PLANES * sizeof(q1_dplane_t));
00112     q1_allocatedbspmem += Q1_MAX_MAP_PLANES * sizeof(q1_dplane_t);
00113     //vertexes
00114     q1_numvertexes = 0;
00115     q1_dvertexes = (q1_dvertex_t *) GetMemory(Q1_MAX_MAP_VERTS * sizeof(q1_dvertex_t));
00116     q1_allocatedbspmem += Q1_MAX_MAP_VERTS * sizeof(q1_dvertex_t);
00117     //nodes
00118     q1_numnodes = 0;
00119     q1_dnodes = (q1_dnode_t *) GetMemory(Q1_MAX_MAP_NODES * sizeof(q1_dnode_t));
00120     q1_allocatedbspmem += Q1_MAX_MAP_NODES * sizeof(q1_dnode_t);
00121     //texture info
00122     q1_numtexinfo = 0;
00123     q1_texinfo = (q1_texinfo_t *) GetMemory(Q1_MAX_MAP_TEXINFO * sizeof(q1_texinfo_t));
00124     q1_allocatedbspmem += Q1_MAX_MAP_TEXINFO * sizeof(q1_texinfo_t);
00125     //faces
00126     q1_numfaces = 0;
00127     q1_dfaces = (q1_dface_t *) GetMemory(Q1_MAX_MAP_FACES * sizeof(q1_dface_t));
00128     q1_allocatedbspmem += Q1_MAX_MAP_FACES * sizeof(q1_dface_t);
00129     //clip nodes
00130     q1_numclipnodes = 0;
00131     q1_dclipnodes = (q1_dclipnode_t *) GetMemory(Q1_MAX_MAP_CLIPNODES * sizeof(q1_dclipnode_t));
00132     q1_allocatedbspmem += Q1_MAX_MAP_CLIPNODES * sizeof(q1_dclipnode_t);
00133     //edges
00134     q1_numedges = 0;
00135     q1_dedges = (q1_dedge_t *) GetMemory(Q1_MAX_MAP_EDGES * sizeof(q1_dedge_t));
00136     q1_allocatedbspmem += Q1_MAX_MAP_EDGES, sizeof(q1_dedge_t);
00137     //mark surfaces
00138     q1_nummarksurfaces = 0;
00139     q1_dmarksurfaces = (unsigned short *) GetMemory(Q1_MAX_MAP_MARKSURFACES * sizeof(unsigned short));
00140     q1_allocatedbspmem += Q1_MAX_MAP_MARKSURFACES * sizeof(unsigned short);
00141     //surface edges
00142     q1_numsurfedges = 0;
00143     q1_dsurfedges = (int *) GetMemory(Q1_MAX_MAP_SURFEDGES * sizeof(int));
00144     q1_allocatedbspmem += Q1_MAX_MAP_SURFEDGES * sizeof(int);
00145     //print allocated memory
00146     Log_Print("allocated ");
00147     PrintMemorySize(q1_allocatedbspmem);
00148     Log_Print(" of BSP memory\n");
00149 } //end of the function Q1_AllocMaxBSP
00150 
00151 void Q1_FreeMaxBSP(void)
00152 {
00153     //models
00154     q1_nummodels = 0;
00155     FreeMemory(q1_dmodels);
00156     q1_dmodels = NULL;
00157     //visibility
00158     q1_visdatasize = 0;
00159     FreeMemory(q1_dvisdata);
00160     q1_dvisdata = NULL;
00161     //light data
00162     q1_lightdatasize = 0;
00163     FreeMemory(q1_dlightdata);
00164     q1_dlightdata = NULL;
00165     //texture data
00166     q1_texdatasize = 0;
00167     FreeMemory(q1_dtexdata);
00168     q1_dtexdata = NULL;
00169     //entities
00170     q1_entdatasize = 0;
00171     FreeMemory(q1_dentdata);
00172     q1_dentdata = NULL;
00173     //leaves
00174     q1_numleafs = 0;
00175     FreeMemory(q1_dleafs);
00176     q1_dleafs = NULL;
00177     //planes
00178     q1_numplanes = 0;
00179     FreeMemory(q1_dplanes);
00180     q1_dplanes = NULL;
00181     //vertexes
00182     q1_numvertexes = 0;
00183     FreeMemory(q1_dvertexes);
00184     q1_dvertexes = NULL;
00185     //nodes
00186     q1_numnodes = 0;
00187     FreeMemory(q1_dnodes);
00188     q1_dnodes = NULL;
00189     //texture info
00190     q1_numtexinfo = 0;
00191     FreeMemory(q1_texinfo);
00192     q1_texinfo = NULL;
00193     //faces
00194     q1_numfaces = 0;
00195     FreeMemory(q1_dfaces);
00196     q1_dfaces = NULL;
00197     //clip nodes
00198     q1_numclipnodes = 0;
00199     FreeMemory(q1_dclipnodes);
00200     q1_dclipnodes = NULL;
00201     //edges
00202     q1_numedges = 0;
00203     FreeMemory(q1_dedges);
00204     q1_dedges = NULL;
00205     //mark surfaces
00206     q1_nummarksurfaces = 0;
00207     FreeMemory(q1_dmarksurfaces);
00208     q1_dmarksurfaces = NULL;
00209     //surface edges
00210     q1_numsurfedges = 0;
00211     FreeMemory(q1_dsurfedges);
00212     q1_dsurfedges = NULL;
00213     //
00214     Log_Print("freed ");
00215     PrintMemorySize(q1_allocatedbspmem);
00216     Log_Print(" of BSP memory\n");
00217     q1_allocatedbspmem = 0;
00218 } //end of the function Q1_FreeMaxBSP
00219 //#endif //ME
00220 
00221 /*
00222 =============
00223 Q1_SwapBSPFile
00224 
00225 Byte swaps all data in a bsp file.
00226 =============
00227 */
00228 void Q1_SwapBSPFile (qboolean todisk)
00229 {
00230     int i, j, c;
00231     q1_dmodel_t *d;
00232     q1_dmiptexlump_t *mtl;
00233 
00234     
00235 // models   
00236     for (i=0 ; i<q1_nummodels ; i++)
00237     {
00238         d = &q1_dmodels[i];
00239 
00240         for (j=0 ; j<Q1_MAX_MAP_HULLS ; j++)
00241             d->headnode[j] = LittleLong (d->headnode[j]);
00242 
00243         d->visleafs = LittleLong (d->visleafs);
00244         d->firstface = LittleLong (d->firstface);
00245         d->numfaces = LittleLong (d->numfaces);
00246         
00247         for (j=0 ; j<3 ; j++)
00248         {
00249             d->mins[j] = LittleFloat(d->mins[j]);
00250             d->maxs[j] = LittleFloat(d->maxs[j]);
00251             d->origin[j] = LittleFloat(d->origin[j]);
00252         }
00253     }
00254 
00255 //
00256 // vertexes
00257 //
00258     for (i=0 ; i<q1_numvertexes ; i++)
00259     {
00260         for (j=0 ; j<3 ; j++)
00261             q1_dvertexes[i].point[j] = LittleFloat(q1_dvertexes[i].point[j]);
00262     }
00263         
00264 //
00265 // planes
00266 //  
00267     for (i=0 ; i<q1_numplanes ; i++)
00268     {
00269         for (j=0 ; j<3 ; j++)
00270             q1_dplanes[i].normal[j] = LittleFloat(q1_dplanes[i].normal[j]);
00271         q1_dplanes[i].dist = LittleFloat(q1_dplanes[i].dist);
00272         q1_dplanes[i].type = LittleLong(q1_dplanes[i].type);
00273     }
00274     
00275 //
00276 // texinfos
00277 //  
00278     for (i=0 ; i<q1_numtexinfo ; i++)
00279     {
00280         for (j=0 ; j<8 ; j++)
00281             q1_texinfo[i].vecs[0][j] = LittleFloat(q1_texinfo[i].vecs[0][j]);
00282         q1_texinfo[i].miptex = LittleLong(q1_texinfo[i].miptex);
00283         q1_texinfo[i].flags = LittleLong(q1_texinfo[i].flags);
00284     }
00285     
00286 //
00287 // faces
00288 //
00289     for (i=0 ; i<q1_numfaces ; i++)
00290     {
00291         q1_dfaces[i].texinfo = LittleShort(q1_dfaces[i].texinfo);
00292         q1_dfaces[i].planenum = LittleShort(q1_dfaces[i].planenum);
00293         q1_dfaces[i].side = LittleShort(q1_dfaces[i].side);
00294         q1_dfaces[i].lightofs = LittleLong(q1_dfaces[i].lightofs);
00295         q1_dfaces[i].firstedge = LittleLong(q1_dfaces[i].firstedge);
00296         q1_dfaces[i].numedges = LittleShort(q1_dfaces[i].numedges);
00297     }
00298 
00299 //
00300 // nodes
00301 //
00302     for (i=0 ; i<q1_numnodes ; i++)
00303     {
00304         q1_dnodes[i].planenum = LittleLong(q1_dnodes[i].planenum);
00305         for (j=0 ; j<3 ; j++)
00306         {
00307             q1_dnodes[i].mins[j] = LittleShort(q1_dnodes[i].mins[j]);
00308             q1_dnodes[i].maxs[j] = LittleShort(q1_dnodes[i].maxs[j]);
00309         }
00310         q1_dnodes[i].children[0] = LittleShort(q1_dnodes[i].children[0]);
00311         q1_dnodes[i].children[1] = LittleShort(q1_dnodes[i].children[1]);
00312         q1_dnodes[i].firstface = LittleShort(q1_dnodes[i].firstface);
00313         q1_dnodes[i].numfaces = LittleShort(q1_dnodes[i].numfaces);
00314     }
00315 
00316 //
00317 // leafs
00318 //
00319     for (i=0 ; i<q1_numleafs ; i++)
00320     {
00321         q1_dleafs[i].contents = LittleLong(q1_dleafs[i].contents);
00322         for (j=0 ; j<3 ; j++)
00323         {
00324             q1_dleafs[i].mins[j] = LittleShort(q1_dleafs[i].mins[j]);
00325             q1_dleafs[i].maxs[j] = LittleShort(q1_dleafs[i].maxs[j]);
00326         }
00327 
00328         q1_dleafs[i].firstmarksurface = LittleShort(q1_dleafs[i].firstmarksurface);
00329         q1_dleafs[i].nummarksurfaces = LittleShort(q1_dleafs[i].nummarksurfaces);
00330         q1_dleafs[i].visofs = LittleLong(q1_dleafs[i].visofs);
00331     }
00332 
00333 //
00334 // clipnodes
00335 //
00336     for (i=0 ; i<q1_numclipnodes ; i++)
00337     {
00338         q1_dclipnodes[i].planenum = LittleLong(q1_dclipnodes[i].planenum);
00339         q1_dclipnodes[i].children[0] = LittleShort(q1_dclipnodes[i].children[0]);
00340         q1_dclipnodes[i].children[1] = LittleShort(q1_dclipnodes[i].children[1]);
00341     }
00342 
00343 //
00344 // miptex
00345 //
00346     if (q1_texdatasize)
00347     {
00348         mtl = (q1_dmiptexlump_t *)q1_dtexdata;
00349         if (todisk)
00350             c = mtl->nummiptex;
00351         else
00352             c = LittleLong(mtl->nummiptex);
00353         mtl->nummiptex = LittleLong (mtl->nummiptex);
00354         for (i=0 ; i<c ; i++)
00355             mtl->dataofs[i] = LittleLong(mtl->dataofs[i]);
00356     }
00357     
00358 //
00359 // marksurfaces
00360 //
00361     for (i=0 ; i<q1_nummarksurfaces ; i++)
00362         q1_dmarksurfaces[i] = LittleShort(q1_dmarksurfaces[i]);
00363 
00364 //
00365 // surfedges
00366 //
00367     for (i=0 ; i<q1_numsurfedges ; i++)
00368         q1_dsurfedges[i] = LittleLong(q1_dsurfedges[i]);
00369 
00370 //
00371 // edges
00372 //
00373     for (i=0 ; i<q1_numedges ; i++)
00374     {
00375         q1_dedges[i].v[0] = LittleShort(q1_dedges[i].v[0]);
00376         q1_dedges[i].v[1] = LittleShort(q1_dedges[i].v[1]);
00377     }
00378 }
00379 
00380 
00381 q1_dheader_t *q1_header;
00382 int         q1_fileLength;
00383 
00384 int Q1_CopyLump (int lump, void *dest, int size, int maxsize)
00385 {
00386     int     length, ofs;
00387 
00388     length = q1_header->lumps[lump].filelen;
00389     ofs = q1_header->lumps[lump].fileofs;
00390     
00391     if (length % size) {
00392         Error ("LoadBSPFile: odd lump size");
00393     }
00394     // somehow things got out of range
00395     if ((length/size) > maxsize) {
00396         printf("WARNING: exceeded max size for lump %d size %d > maxsize %d\n", lump, (length/size), maxsize);
00397         length = maxsize * size;
00398     }
00399     if ( ofs + length > q1_fileLength ) {
00400         printf("WARNING: exceeded file length for lump %d\n", lump);
00401         length = q1_fileLength - ofs;
00402         if ( length <= 0 ) {
00403             return 0;
00404         }
00405     }
00406 
00407     memcpy (dest, (byte *)q1_header + ofs, length);
00408 
00409     return length / size;
00410 }
00411 
00412 /*
00413 =============
00414 Q1_LoadBSPFile
00415 =============
00416 */
00417 void    Q1_LoadBSPFile(char *filename, int offset, int length)
00418 {
00419     int         i;
00420     
00421 //
00422 // load the file header
00423 //
00424     q1_fileLength = LoadFile(filename, (void **)&q1_header, offset, length);
00425 
00426 // swap the header
00427     for (i=0 ; i< sizeof(q1_dheader_t)/4 ; i++)
00428         ((int *)q1_header)[i] = LittleLong ( ((int *)q1_header)[i]);
00429 
00430     if (q1_header->version != Q1_BSPVERSION)
00431         Error ("%s is version %i, not %i", filename, i, Q1_BSPVERSION);
00432 
00433     q1_nummodels = Q1_CopyLump (Q1_LUMP_MODELS, q1_dmodels, sizeof(q1_dmodel_t), Q1_MAX_MAP_MODELS );
00434     q1_numvertexes = Q1_CopyLump (Q1_LUMP_VERTEXES, q1_dvertexes, sizeof(q1_dvertex_t), Q1_MAX_MAP_VERTS );
00435     q1_numplanes = Q1_CopyLump (Q1_LUMP_PLANES, q1_dplanes, sizeof(q1_dplane_t), Q1_MAX_MAP_PLANES );
00436     q1_numleafs = Q1_CopyLump (Q1_LUMP_LEAFS, q1_dleafs, sizeof(q1_dleaf_t), Q1_MAX_MAP_LEAFS );
00437     q1_numnodes = Q1_CopyLump (Q1_LUMP_NODES, q1_dnodes, sizeof(q1_dnode_t), Q1_MAX_MAP_NODES );
00438     q1_numtexinfo = Q1_CopyLump (Q1_LUMP_TEXINFO, q1_texinfo, sizeof(q1_texinfo_t), Q1_MAX_MAP_TEXINFO );
00439     q1_numclipnodes = Q1_CopyLump (Q1_LUMP_CLIPNODES, q1_dclipnodes, sizeof(q1_dclipnode_t), Q1_MAX_MAP_CLIPNODES );
00440     q1_numfaces = Q1_CopyLump (Q1_LUMP_FACES, q1_dfaces, sizeof(q1_dface_t), Q1_MAX_MAP_FACES );
00441     q1_nummarksurfaces = Q1_CopyLump (Q1_LUMP_MARKSURFACES, q1_dmarksurfaces, sizeof(q1_dmarksurfaces[0]), Q1_MAX_MAP_MARKSURFACES );
00442     q1_numsurfedges = Q1_CopyLump (Q1_LUMP_SURFEDGES, q1_dsurfedges, sizeof(q1_dsurfedges[0]), Q1_MAX_MAP_SURFEDGES );
00443     q1_numedges = Q1_CopyLump (Q1_LUMP_EDGES, q1_dedges, sizeof(q1_dedge_t), Q1_MAX_MAP_EDGES );
00444 
00445     q1_texdatasize = Q1_CopyLump (Q1_LUMP_TEXTURES, q1_dtexdata, 1, Q1_MAX_MAP_MIPTEX );
00446     q1_visdatasize = Q1_CopyLump (Q1_LUMP_VISIBILITY, q1_dvisdata, 1, Q1_MAX_MAP_VISIBILITY );
00447     q1_lightdatasize = Q1_CopyLump (Q1_LUMP_LIGHTING, q1_dlightdata, 1, Q1_MAX_MAP_LIGHTING );
00448     q1_entdatasize = Q1_CopyLump (Q1_LUMP_ENTITIES, q1_dentdata, 1, Q1_MAX_MAP_ENTSTRING );
00449 
00450     FreeMemory(q1_header);      // everything has been copied out
00451         
00452 //
00453 // swap everything
00454 //  
00455     Q1_SwapBSPFile (false);
00456 }
00457 
00458 //============================================================================
00459 
00460 FILE *q1_wadfile;
00461 q1_dheader_t q1_outheader;
00462 
00463 void Q1_AddLump (int lumpnum, void *data, int len)
00464 {
00465     q1_lump_t *lump;
00466 
00467     lump = &q1_header->lumps[lumpnum];
00468     
00469     lump->fileofs = LittleLong(ftell(q1_wadfile));
00470     lump->filelen = LittleLong(len);
00471     SafeWrite(q1_wadfile, data, (len+3)&~3);
00472 }
00473 
00474 /*
00475 =============
00476 Q1_WriteBSPFile
00477 
00478 Swaps the bsp file in place, so it should not be referenced again
00479 =============
00480 */
00481 void    Q1_WriteBSPFile (char *filename)
00482 {       
00483     q1_header = &q1_outheader;
00484     memset (q1_header, 0, sizeof(q1_dheader_t));
00485     
00486     Q1_SwapBSPFile (true);
00487 
00488     q1_header->version = LittleLong (Q1_BSPVERSION);
00489     
00490     q1_wadfile = SafeOpenWrite (filename);
00491     SafeWrite (q1_wadfile, q1_header, sizeof(q1_dheader_t));    // overwritten later
00492 
00493     Q1_AddLump (Q1_LUMP_PLANES, q1_dplanes, q1_numplanes*sizeof(q1_dplane_t));
00494     Q1_AddLump (Q1_LUMP_LEAFS, q1_dleafs, q1_numleafs*sizeof(q1_dleaf_t));
00495     Q1_AddLump (Q1_LUMP_VERTEXES, q1_dvertexes, q1_numvertexes*sizeof(q1_dvertex_t));
00496     Q1_AddLump (Q1_LUMP_NODES, q1_dnodes, q1_numnodes*sizeof(q1_dnode_t));
00497     Q1_AddLump (Q1_LUMP_TEXINFO, q1_texinfo, q1_numtexinfo*sizeof(q1_texinfo_t));
00498     Q1_AddLump (Q1_LUMP_FACES, q1_dfaces, q1_numfaces*sizeof(q1_dface_t));
00499     Q1_AddLump (Q1_LUMP_CLIPNODES, q1_dclipnodes, q1_numclipnodes*sizeof(q1_dclipnode_t));
00500     Q1_AddLump (Q1_LUMP_MARKSURFACES, q1_dmarksurfaces, q1_nummarksurfaces*sizeof(q1_dmarksurfaces[0]));
00501     Q1_AddLump (Q1_LUMP_SURFEDGES, q1_dsurfedges, q1_numsurfedges*sizeof(q1_dsurfedges[0]));
00502     Q1_AddLump (Q1_LUMP_EDGES, q1_dedges, q1_numedges*sizeof(q1_dedge_t));
00503     Q1_AddLump (Q1_LUMP_MODELS, q1_dmodels, q1_nummodels*sizeof(q1_dmodel_t));
00504 
00505     Q1_AddLump (Q1_LUMP_LIGHTING, q1_dlightdata, q1_lightdatasize);
00506     Q1_AddLump (Q1_LUMP_VISIBILITY, q1_dvisdata, q1_visdatasize);
00507     Q1_AddLump (Q1_LUMP_ENTITIES, q1_dentdata, q1_entdatasize);
00508     Q1_AddLump (Q1_LUMP_TEXTURES, q1_dtexdata, q1_texdatasize);
00509     
00510     fseek (q1_wadfile, 0, SEEK_SET);
00511     SafeWrite (q1_wadfile, q1_header, sizeof(q1_dheader_t));
00512     fclose (q1_wadfile);    
00513 }
00514 
00515 //============================================================================
00516 
00517 /*
00518 =============
00519 Q1_PrintBSPFileSizes
00520 
00521 Dumps info about current file
00522 =============
00523 */
00524 void Q1_PrintBSPFileSizes (void)
00525 {
00526     printf ("%5i planes       %6i\n"
00527         ,q1_numplanes, (int)(q1_numplanes*sizeof(q1_dplane_t)));
00528     printf ("%5i vertexes     %6i\n"
00529         ,q1_numvertexes, (int)(q1_numvertexes*sizeof(q1_dvertex_t)));
00530     printf ("%5i nodes        %6i\n"
00531         ,q1_numnodes, (int)(q1_numnodes*sizeof(q1_dnode_t)));
00532     printf ("%5i texinfo      %6i\n"
00533         ,q1_numtexinfo, (int)(q1_numtexinfo*sizeof(q1_texinfo_t)));
00534     printf ("%5i faces        %6i\n"
00535         ,q1_numfaces, (int)(q1_numfaces*sizeof(q1_dface_t)));
00536     printf ("%5i clipnodes    %6i\n"
00537         ,q1_numclipnodes, (int)(q1_numclipnodes*sizeof(q1_dclipnode_t)));
00538     printf ("%5i leafs        %6i\n"
00539         ,q1_numleafs, (int)(q1_numleafs*sizeof(q1_dleaf_t)));
00540     printf ("%5i marksurfaces %6i\n"
00541         ,q1_nummarksurfaces, (int)(q1_nummarksurfaces*sizeof(q1_dmarksurfaces[0])));
00542     printf ("%5i surfedges    %6i\n"
00543         ,q1_numsurfedges, (int)(q1_numsurfedges*sizeof(q1_dmarksurfaces[0])));
00544     printf ("%5i edges        %6i\n"
00545         ,q1_numedges, (int)(q1_numedges*sizeof(q1_dedge_t)));
00546     if (!q1_texdatasize)
00547         printf ("    0 textures          0\n");
00548     else
00549         printf ("%5i textures     %6i\n",((q1_dmiptexlump_t*)q1_dtexdata)->nummiptex, q1_texdatasize);
00550     printf ("      lightdata    %6i\n", q1_lightdatasize);
00551     printf ("      visdata      %6i\n", q1_visdatasize);
00552     printf ("      entdata      %6i\n", q1_entdatasize);
00553 } //end of the function Q1_PrintBSPFileSizes
00554 
00555 
00556 /*
00557 ================
00558 Q1_ParseEntities
00559 
00560 Parses the dentdata string into entities
00561 ================
00562 */
00563 void Q1_ParseEntities (void)
00564 {
00565     script_t *script;
00566 
00567     num_entities = 0;
00568     script = LoadScriptMemory(q1_dentdata, q1_entdatasize, "*Quake1 bsp file");
00569     SetScriptFlags(script, SCFL_NOSTRINGWHITESPACES |
00570                                     SCFL_NOSTRINGESCAPECHARS);
00571 
00572     while(ParseEntity(script))
00573     {
00574     } //end while
00575 
00576     FreeScript(script);
00577 } //end of the function Q1_ParseEntities
00578 
00579 
00580 /*
00581 ================
00582 Q1_UnparseEntities
00583 
00584 Generates the dentdata string from all the entities
00585 ================
00586 */
00587 void Q1_UnparseEntities (void)
00588 {
00589     char *buf, *end;
00590     epair_t *ep;
00591     char line[2048];
00592     int i;
00593     
00594     buf = q1_dentdata;
00595     end = buf;
00596     *end = 0;
00597     
00598     for (i=0 ; i<num_entities ; i++)
00599     {
00600         ep = entities[i].epairs;
00601         if (!ep)
00602             continue;   // ent got removed
00603         
00604         strcat (end,"{\n");
00605         end += 2;
00606                 
00607         for (ep = entities[i].epairs ; ep ; ep=ep->next)
00608         {
00609             sprintf (line, "\"%s\" \"%s\"\n", ep->key, ep->value);
00610             strcat (end, line);
00611             end += strlen(line);
00612         }
00613         strcat (end,"}\n");
00614         end += 2;
00615 
00616         if (end > buf + Q1_MAX_MAP_ENTSTRING)
00617             Error ("Entity text too long");
00618     }
00619     q1_entdatasize = end - buf + 1;
00620 } //end of the function Q1_UnparseEntities

Generated on Thu Aug 25 12:37:15 2005 for Quake III Arena by  doxygen 1.3.9.1