UFO: Alien Invasion
Loading...
Searching...
No Matches
bspfile.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 1997-2001 Id Software, Inc.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "shared.h"
27#include "bspfile.h"
28#include "scriplib.h"
29#include "../bsp.h"
30#include <errno.h>
31
37byte* CompressRouting (byte* dataStart, byte* destStart, int l)
38{
39 int c;
40 byte val;
41 byte* data, *dend, *dest_p;
42
43 dest_p = destStart;
44 data = dataStart;
45 dend = dataStart + l;
46
47 while (data < dend) {
48 byte* count_p;
49 if (data + 1 < dend && *data == *(data + 1)) {
50 /* repetitions */
51 val = *data++;
52 data++; /* Advance data again. The first two bytes are identical!!! */
53 c = 0; /* This means 2 bytes are the same. Total bytes the same is 2 + c */
54 /* Loop while the piece of data being looked at equals val */
55 while (data + 1 < dend && val == *(data)) {
56 if (c >= SCHAR_MAX) /* must fit into one byte */
57 break;
58 data++;
59 c++;
60 }
61 count_p = dest_p;
62 *dest_p++ = (byte)(c) | 0x80;
63 *dest_p++ = val;
64 } else {
65 /* identities */
66 count_p = dest_p++;
67 c = 0;
68 while ((data + 1 < dend && *data != *(data + 1)) || data == dend - 1) {
69 if (c >= SCHAR_MAX) /* must fit into one byte */
70 break;
71 *dest_p++ = *data++;
72 c++;
73 }
74 *count_p = (byte)c;
75 }
76 }
77
78 /* terminate compressed data */
79 *dest_p++ = 0;
80
81 return dest_p;
82}
83
87static void SwapBSPFile (void)
88{
89 int i, j;
90
91 /* models */
92 for (i = 0; i < curTile->nummodels; i++) {
93 dBspModel_t* d = &curTile->models[i];
94
98
99 for (j = 0; j < 3; j++) {
100 d->dbmBox.mins[j] = LittleFloat(d->dbmBox.mins[j]);
101 d->dbmBox.maxs[j] = LittleFloat(d->dbmBox.maxs[j]);
102 d->origin[j] = LittleFloat(d->origin[j]);
103 }
104 }
105
106 /* vertexes */
107 for (i = 0; i < curTile->numvertexes; i++) {
108 dBspVertex_t* vertexes = &curTile->vertexes[i];
109 for (j = 0; j < 3; j++)
110 vertexes->point[j] = LittleFloat(vertexes->point[j]);
111 }
112
113 /* planes */
114 for (i = 0; i < curTile->numplanes; i++) {
115 dBspPlane_t* plane = &curTile->planes[i];
116 for (j = 0; j < 3; j++)
117 plane->normal[j] = LittleFloat(plane->normal[j]);
118 plane->dist = LittleFloat(plane->dist);
119 plane->type = LittleLong(plane->type);
120 }
121
122 /* texinfos */
123 for (i = 0; i < curTile->numtexinfo; i++) {
124 dBspTexinfo_t* texinfo = &curTile->texinfo[i];
125 for (j = 0; j < 2; j++)
126 for (int k = 0; k < 4; k++)
127 texinfo->vecs[j][k] = LittleFloat(texinfo->vecs[j][k]);
128 texinfo->surfaceFlags = LittleLong(texinfo->surfaceFlags);
129 texinfo->value = LittleLong(texinfo->value);
130 }
131
132 /* faces */
133 for (i = 0; i < curTile->numfaces; i++) {
134 dBspSurface_t* face = &curTile->faces[i];
135 face->texinfo = LittleShort(face->texinfo);
136 face->planenum = LittleShort(face->planenum);
137 face->side = LittleShort(face->side);
138 for (j = 0; j < LIGHTMAP_MAX; j++)
139 face->lightofs[j] = LittleLong(face->lightofs[j]);
140 face->firstedge = LittleLong(face->firstedge);
141 face->numedges = LittleShort(face->numedges);
142 }
143
144 /* nodes */
145 for (i = 0; i < curTile->numnodes; i++) {
146 dBspNode_t* node = &curTile->nodes[i];
147 /* planenum might be -1 here - special case for pathfinding nodes */
148 node->planenum = LittleLong(node->planenum);
149 for (j = 0; j < 3; j++) {
150 node->mins[j] = LittleShort(node->mins[j]);
151 node->maxs[j] = LittleShort(node->maxs[j]);
152 }
153 node->children[0] = LittleLong(node->children[0]);
154 node->children[1] = LittleLong(node->children[1]);
155 node->firstface = LittleShort(node->firstface);
156 node->numfaces = LittleShort(node->numfaces);
157 }
158
159 /* leafs */
160 for (i = 0; i < curTile->numleafs; i++) {
161 dBspLeaf_t* leaf = &curTile->leafs[i];
162 leaf->contentFlags = LittleLong(leaf->contentFlags);
163 leaf->area = LittleShort(leaf->area);
164 for (j = 0; j < 3; j++) {
165 leaf->mins[j] = LittleShort(leaf->mins[j]);
166 leaf->maxs[j] = LittleShort(leaf->maxs[j]);
167 }
168
171 }
172
173 /* leafbrushes */
174 for (i = 0; i < curTile->numleafbrushes; i++)
175 curTile->leafbrushes[i] = LittleShort(curTile->leafbrushes[i]);
176
177 /* surfedges */
178 for (i = 0; i < curTile->numsurfedges; i++)
179 curTile->surfedges[i] = LittleLong(curTile->surfedges[i]);
180
181 /* edges */
182 for (i = 0; i < curTile->numedges; i++) {
183 dBspEdge_t* edge = &curTile->edges[i];
184 edge->v[0] = LittleShort(edge->v[0]);
185 edge->v[1] = LittleShort(edge->v[1]);
186 }
187
188 /* dbrushes */
189 for (i = 0; i < curTile->numbrushes; i++) {
190 dBspBrush_t* dbrush = &curTile->dbrushes[i];
191 dbrush->firstbrushside = LittleLong(dbrush->firstbrushside);
192 dbrush->numsides = LittleLong(dbrush->numsides);
194 }
195
196 /* brushes */
197 for (i = 0; i < curTile->numbrushes; i++) {
198 cBspBrush_t* cbrush = &curTile->brushes[i];
199 cbrush->firstbrushside = LittleLong(cbrush->firstbrushside);
200 cbrush->numsides = LittleLong(cbrush->numsides);
202 }
203
204 /* brushsides */
205 for (i = 0; i < curTile->numbrushsides; i++) {
206 dBspBrushSide_t* brushSide = &curTile->brushsides[i];
207 brushSide->planenum = LittleShort(brushSide->planenum);
208 brushSide->texinfo = LittleShort(brushSide->texinfo);
209 }
210}
211
212static uint32_t CopyLump (const dBspHeader_t* header, int lumpIdx, void* dest, size_t size)
213{
214 const lump_t* lump = &header->lumps[lumpIdx];
215 const uint32_t length = lump->filelen;
216 const uint32_t ofs = lump->fileofs;
217
218 if (length == 0)
219 return 0;
220 if (length % size)
221 Sys_Error("LoadBSPFile: odd lump size");
222
223 memcpy(dest, (const byte*)header + ofs, length);
224
225 return length / size;
226}
227
232{
233 dBspHeader_t* header;
234
235 /* Create this shortcut to mapTiles[0] */
236 curTile = &mapTiles.mapTiles[0];
237 /* Set the number of tiles to 1. */
238 mapTiles.numTiles = 1;
239
240 /* load the file header */
241 int size = FS_LoadFile(filename, (byte**)&header);
242 if (size == -1)
243 Sys_Error("'%s' doesn't exist", filename);
244
245 /* swap the header */
246 BSP_SwapHeader(header, filename);
247
248 if (header->ident != IDBSPHEADER)
249 Sys_Error("%s is not a IBSP file", filename);
250 if (header->version != BSPVERSION)
251 Sys_Error("%s is version %i, not %i", filename, header->version, BSPVERSION);
252
253 curTile->nummodels = CopyLump(header, LUMP_MODELS, curTile->models, sizeof(dBspModel_t));
254 curTile->numvertexes = CopyLump(header, LUMP_VERTEXES, curTile->vertexes, sizeof(dBspVertex_t));
255 curTile->numplanes = CopyLump(header, LUMP_PLANES, curTile->planes, sizeof(dBspPlane_t));
256 curTile->numleafs = CopyLump(header, LUMP_LEAFS, curTile->leafs, sizeof(dBspLeaf_t));
257 curTile->numnormals = CopyLump(header, LUMP_NORMALS, curTile->normals, sizeof(dBspNormal_t));
258 curTile->numnodes = CopyLump(header, LUMP_NODES, curTile->nodes, sizeof(dBspNode_t));
259 curTile->numtexinfo = CopyLump(header, LUMP_TEXINFO, curTile->texinfo, sizeof(dBspTexinfo_t));
260 curTile->numfaces = CopyLump(header, LUMP_FACES, curTile->faces, sizeof(dBspSurface_t));
261 curTile->numleafbrushes = CopyLump(header, LUMP_LEAFBRUSHES, curTile->leafbrushes, sizeof(curTile->leafbrushes[0]));
262 curTile->numsurfedges = CopyLump(header, LUMP_SURFEDGES, curTile->surfedges, sizeof(curTile->surfedges[0]));
263 curTile->numedges = CopyLump(header, LUMP_EDGES, curTile->edges, sizeof(dBspEdge_t));
264 curTile->numbrushes = CopyLump(header, LUMP_BRUSHES, curTile->dbrushes, sizeof(dBspBrush_t));
265 curTile->numbrushsides = CopyLump(header, LUMP_BRUSHSIDES, curTile->brushsides, sizeof(dBspBrushSide_t));
266 curTile->routedatasize = CopyLump(header, LUMP_ROUTING, curTile->routedata, 1);
267 curTile->lightdatasize[LIGHTMAP_NIGHT] = CopyLump(header, LUMP_LIGHTING_NIGHT, curTile->lightdata[LIGHTMAP_NIGHT], 1);
268 curTile->lightdatasize[LIGHTMAP_DAY] = CopyLump(header, LUMP_LIGHTING_DAY, curTile->lightdata[LIGHTMAP_DAY], 1);
269 curTile->entdatasize = CopyLump(header, LUMP_ENTITIES, curTile->entdata, 1);
270
271 /* Because the tracing functions use cBspBrush_t and not dBspBrush_t,
272 * copy data from curTile->dbrushes into curTile->cbrushes */
273 OBJZERO(curTile->brushes);
274 for (int i = 0; i < curTile->numbrushes; i++) {
275 dBspBrush_t* dbrush = &curTile->dbrushes[i];
276 cBspBrush_t* brush = &curTile->brushes[i];
277 brush->firstbrushside = dbrush->firstbrushside;
278 brush->numsides = dbrush->numsides;
279 brush->brushContentFlags = dbrush->brushContentFlags;
280 }
281
282 /* everything has been copied out */
283 FS_FreeFile(header);
284
285 /* swap everything */
286 SwapBSPFile();
287
288 return curTile;
289}
290
295static void AddLump (qFILE* bspfile, dBspHeader_t* header, int lumpnum, void* data, int len)
296{
297 lump_t* lump;
298 long offset;
299
300 lump = &header->lumps[lumpnum];
301
302 offset = ftell(bspfile->f);
303 if (offset == -1) {
304 Sys_Error("Overflow in AddLump for lump %i (%s) %s", lumpnum, bspfile->name, strerror(errno));
305 }
306 lump->fileofs = LittleLong(offset);
307 lump->filelen = LittleLong(len);
308 /* 4 byte align */
309 FS_Write(data, (len + 3) &~ 3, bspfile);
310}
311
316long WriteBSPFile (const char* filename)
317{
318 dBspHeader_t outheader;
319 long size;
320
321 OBJZERO(outheader);
322
323 SwapBSPFile();
324
325 outheader.ident = LittleLong(IDBSPHEADER);
326 outheader.version = LittleLong(BSPVERSION);
327
328 ScopedFile bspfile;
329 FS_OpenFile(filename, &bspfile, FILE_WRITE);
330 if (!bspfile)
331 Sys_Error("Could not write bsp file");
332 FS_Write(&outheader, sizeof(outheader), &bspfile); /* overwritten later */
333
334 AddLump(&bspfile, &outheader, LUMP_PLANES, curTile->planes, curTile->numplanes * sizeof(dBspPlane_t));
335 AddLump(&bspfile, &outheader, LUMP_LEAFS, curTile->leafs, curTile->numleafs * sizeof(dBspLeaf_t));
336 AddLump(&bspfile, &outheader, LUMP_VERTEXES, curTile->vertexes, curTile->numvertexes * sizeof(dBspVertex_t));
337 AddLump(&bspfile, &outheader, LUMP_NORMALS, curTile->normals, curTile->numnormals * sizeof(dBspNormal_t));
338 AddLump(&bspfile, &outheader, LUMP_NODES, curTile->nodes, curTile->numnodes * sizeof(dBspNode_t));
339 AddLump(&bspfile, &outheader, LUMP_TEXINFO, curTile->texinfo, curTile->numtexinfo * sizeof(dBspTexinfo_t));
340 AddLump(&bspfile, &outheader, LUMP_FACES, curTile->faces, curTile->numfaces * sizeof(dBspSurface_t));
341 AddLump(&bspfile, &outheader, LUMP_BRUSHES, curTile->dbrushes, curTile->numbrushes * sizeof(dBspBrush_t));
342 AddLump(&bspfile, &outheader, LUMP_BRUSHSIDES, curTile->brushsides, curTile->numbrushsides * sizeof(dBspBrushSide_t));
343 AddLump(&bspfile, &outheader, LUMP_LEAFBRUSHES, curTile->leafbrushes, curTile->numleafbrushes * sizeof(curTile->leafbrushes[0]));
344 AddLump(&bspfile, &outheader, LUMP_SURFEDGES, curTile->surfedges, curTile->numsurfedges * sizeof(curTile->surfedges[0]));
345 AddLump(&bspfile, &outheader, LUMP_EDGES, curTile->edges, curTile->numedges * sizeof(dBspEdge_t));
346 AddLump(&bspfile, &outheader, LUMP_MODELS, curTile->models, curTile->nummodels * sizeof(dBspModel_t));
347 AddLump(&bspfile, &outheader, LUMP_LIGHTING_NIGHT, curTile->lightdata[0], curTile->lightdatasize[0]);
348 AddLump(&bspfile, &outheader, LUMP_LIGHTING_DAY, curTile->lightdata[1], curTile->lightdatasize[1]);
349 AddLump(&bspfile, &outheader, LUMP_ROUTING, curTile->routedata, curTile->routedatasize);
350 AddLump(&bspfile, &outheader, LUMP_ENTITIES, curTile->entdata, curTile->entdatasize);
351 size = ftell(bspfile.getFile());
352
353 fseek(bspfile.getFile(), 0L, SEEK_SET);
354 FS_Write(&outheader, sizeof(outheader), &bspfile);
355
356 SwapBSPFile();
357
358 return size;
359}
360
365{
366 if (!num_entities)
368
369 Com_Printf("amount type size in bytes\n");
370 Com_Printf("================================\n");
371 Com_Printf("%5i models %7i\n", curTile->nummodels, (int)(curTile->nummodels * sizeof(cBspModel_t)));
372 Com_Printf("%5i brushes %7i\n", curTile->numbrushes, (int)(curTile->numbrushes * sizeof(dBspBrush_t)));
373 Com_Printf("%5i brushsides %7i\n", curTile->numbrushsides, (int)(curTile->numbrushsides * sizeof(dBspBrushSide_t)));
374 Com_Printf("%5i planes %7i\n", curTile->numplanes, (int)(curTile->numplanes * sizeof(dBspPlane_t)));
375 Com_Printf("%5i texinfo %7i\n", curTile->numtexinfo, (int)(curTile->numtexinfo * sizeof(dBspTexinfo_t)));
376 Com_Printf("%5i entdata %7i\n", num_entities, curTile->entdatasize);
377
378 Com_Printf("\n");
379
380 Com_Printf("%5i normales %7i\n", curTile->numnormals, (int)(curTile->numnormals * sizeof(dBspNormal_t)));
381 Com_Printf("%5i vertexes %7i\n", curTile->numvertexes, (int)(curTile->numvertexes * sizeof(dBspVertex_t)));
382 Com_Printf("%5i nodes %7i\n", curTile->numnodes, (int)(curTile->numnodes * sizeof(dBspNode_t)));
383 Com_Printf("%5i faces %7i\n", curTile->numfaces, (int)(curTile->numfaces * sizeof(dBspSurface_t)));
384 Com_Printf("%5i leafs %7i\n", curTile->numleafs, (int)(curTile->numleafs * sizeof(dBspLeaf_t)));
385 Com_Printf("%5i leafbrushes %7i\n", curTile->numleafbrushes, (int)(curTile->numleafbrushes * sizeof(curTile->leafbrushes[0])));
386 Com_Printf("%5i surfedges %7i\n", curTile->numsurfedges, (int)(curTile->numsurfedges * sizeof(curTile->surfedges[0])));
387 Com_Printf("%5i edges %7i\n", curTile->numedges, (int)(curTile->numedges * sizeof(dBspEdge_t)));
388 Com_Printf("night lightdata %7i\n", curTile->lightdatasize[0]);
389 Com_Printf(" day lightdata %7i\n", curTile->lightdatasize[1]);
390 Com_Printf(" routedata %7i\n", curTile->routedatasize);
391}
392
393
396
402static void StripTrailingWhitespaces (char* str)
403{
404 char* s;
405
406 s = str + strlen(str) - 1;
407 while (s >= str && *s <= ' ') {
408 *s = '\0';
409 s--;
410 }
411}
412
413static inline bool IsInvalidEntityToken (const char* token)
414{
415 return Q_streq(token, "}") || Q_streq(token, "{");
416}
417
418bool EpairCheckForDuplicate (const entity_t* ent, const epair_t *e)
419{
420 for (const epair_t* ep = ent->epairs; ep; ep = ep->next) {
421 if (Q_streq(ep->key, e->key)) {
422 return true;
423 }
424 }
425 return false;
426}
427
428epair_t* AddEpair (const char* key, const char* value, int entNum)
429{
431
433 Sys_Error("Invalid entity %i found with key '%s' and value '%s'", entNum, key, value);
434
435 if (strlen(key) >= MAX_KEY - 1)
436 Sys_Error("ParseEpar: token too long");
437 e->key = key;
438 if (strlen(value) >= MAX_VALUE - 1)
439 Sys_Error("ParseEpar: token too long");
440 e->value = value;
441 e->ump = false;
442
443 return e;
444}
445
453epair_t* ParseEpair (int entNum)
454{
456 const char* key = Mem_StrDup(parsedToken);
457 GetToken();
459 const char* value = Mem_StrDup(parsedToken);
460 return AddEpair(key, value, entNum);
461}
462
466static entity_t* ParseEntity (void)
467{
468 entity_t* mapent;
469
470 if (Q_strnull(GetToken()))
471 return nullptr;
472
473 if (parsedToken[0] != '{')
474 Sys_Error("ParseEntity: { not found");
475
477 Sys_Error("num_entities >= MAX_MAP_ENTITIES (%i)", num_entities);
478
479 mapent = &entities[num_entities];
480 num_entities++;
481
482 do {
483 if (Q_strnull(GetToken()))
484 Sys_Error("ParseEntity: EOF without closing brace");
485 if (*parsedToken == '}') {
486 break;
487 } else {
489 e->next = mapent->epairs;
490 mapent->epairs = e;
491 }
492 } while (1);
493
494 return mapent;
495}
496
502void ParseEntities (void)
503{
504 num_entities = 0;
505 ParseFromMemory(curTile->entdata, curTile->entdatasize);
506
507 while (ParseEntity() != nullptr) {
508 }
509}
510
515const char* UnparseEntities (void)
516{
517 char key[1024];
518 char value[1024];
519
520 curTile->entdata[0] = '\0';
521
522 for (int i = 0; i < num_entities; i++) {
523 const epair_t* ep = entities[i].epairs;
524 if (!ep)
525 continue; /* ent got removed */
526
527 Q_strcat(curTile->entdata, sizeof(curTile->entdata), "{\n");
528
529 for (ep = entities[i].epairs; ep; ep = ep->next) {
530 Q_strncpyz(key, ep->key, sizeof(key));
532 Q_strncpyz(value, ep->value, sizeof(value));
534
536 Sys_Error("Invalid entity %i found with key '%s' and value '%s'", i, key, value);
537 Q_strcat(curTile->entdata, sizeof(curTile->entdata), "\"%s\" \"%s\"\n", key, value);
538 }
539 Q_strcat(curTile->entdata, sizeof(curTile->entdata), "}\n");
540 }
541 curTile->entdatasize = strlen(curTile->entdata);
542
543 return curTile->entdata;
544}
545
546void SetKeyValue (entity_t* ent, const char* key, const char* value)
547{
548 for (epair_t* ep = ent->epairs; ep; ep = ep->next)
549 if (Q_streq(ep->key, key)) {
550 ep->value = Mem_StrDup(value);
551 return;
552 }
553 epair_t* e = AddEpair(Mem_StrDup(key), Mem_StrDup(value), -1);
554 e->next = ent->epairs;
555 ent->epairs = e;
556}
557
558const char* ValueForKey (const entity_t* ent, const char* key)
559{
560 for (const epair_t* ep = ent->epairs; ep; ep = ep->next)
561 if (Q_streq(ep->key, key))
562 return ep->value;
563 return "";
564}
565
566vec_t FloatForKey (const entity_t* ent, const char* key)
567{
568 const char* k = ValueForKey(ent, key);
569 return atof(k);
570}
571
575void GetVectorFromString (const char* value, vec3_t vec)
576{
577 if (value[0] != '\0') {
578 double v1, v2, v3;
579
580 /* scanf into doubles, then assign, so it is vec_t size independent */
581 v1 = v2 = v3 = 0;
582 if (sscanf(value, "%lf %lf %lf", &v1, &v2, &v3) != 3)
583 Sys_Error("invalid vector statement given: '%s'", value);
584 VectorSet(vec, v1, v2, v3);
585 } else
586 VectorClear(vec);
587}
588
592void GetVectorForKey (const entity_t* ent, const char* key, vec3_t vec)
593{
594 const char* k = ValueForKey(ent, key);
595 GetVectorFromString(k, vec);
596}
void GetVectorFromString(const char *value, vec3_t vec)
Converts a string into a vec3_t.
Definition bspfile.cpp:575
const char * UnparseEntities(void)
Generates the curTile->entdata string from all the entities.
Definition bspfile.cpp:515
void ParseEntities(void)
Parses the curTile->entdata string into entities.
Definition bspfile.cpp:502
void GetVectorForKey(const entity_t *ent, const char *key, vec3_t vec)
Converts the value of a entity parameter into a vec3_t.
Definition bspfile.cpp:592
vec_t FloatForKey(const entity_t *ent, const char *key)
Definition bspfile.cpp:566
void SetKeyValue(entity_t *ent, const char *key, const char *value)
Definition bspfile.cpp:546
int num_entities
Definition bspfile.cpp:394
static uint32_t CopyLump(const dBspHeader_t *header, int lumpIdx, void *dest, size_t size)
Definition bspfile.cpp:212
entity_t entities[MAX_MAP_ENTITIES]
Definition bspfile.cpp:395
static entity_t * ParseEntity(void)
Definition bspfile.cpp:466
void PrintBSPFileSizes(void)
Dumps info about current file.
Definition bspfile.cpp:364
static bool IsInvalidEntityToken(const char *token)
Definition bspfile.cpp:413
long WriteBSPFile(const char *filename)
Swaps the bsp file in place, so it should not be referenced again.
Definition bspfile.cpp:316
bool EpairCheckForDuplicate(const entity_t *ent, const epair_t *e)
Definition bspfile.cpp:418
epair_t * AddEpair(const char *key, const char *value, int entNum)
Definition bspfile.cpp:428
static void AddLump(qFILE *bspfile, dBspHeader_t *header, int lumpnum, void *data, int len)
Definition bspfile.cpp:295
dMapTile_t * LoadBSPFile(const char *filename)
Definition bspfile.cpp:231
static void SwapBSPFile(void)
Byte swaps all data in a bsp file.
Definition bspfile.cpp:87
static void StripTrailingWhitespaces(char *str)
Removes trailing whitespaces from the given string.
Definition bspfile.cpp:402
epair_t * ParseEpair(int entNum)
Parses one key and value for an entity from the current tokens.
Definition bspfile.cpp:453
const char * ValueForKey(const entity_t *ent, const char *key)
Definition bspfile.cpp:558
byte * CompressRouting(byte *dataStart, byte *destStart, int l)
Compress the routing data of a map.
Definition bspfile.cpp:37
#define LittleLong(X)
Definition byte.h:37
#define LittleShort(X)
Definition byte.h:35
#define LittleFloat(X)
Definition byte.h:57
unsigned int key
Definition cl_input.cpp:64
vec3_t maxs
Definition aabb.h:258
vec3_t mins
Definition aabb.h:257
FILE * getFile() const
Definition filesys.h:214
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
#define LUMP_EDGES
Definition defines.h:178
#define LIGHTMAP_NIGHT
Definition defines.h:363
#define LUMP_SURFEDGES
Definition defines.h:179
#define LUMP_LEAFS
Definition defines.h:176
#define LUMP_VERTEXES
Definition defines.h:169
#define MAX_KEY
Definition defines.h:163
#define LIGHTMAP_MAX
Definition defines.h:365
#define LUMP_LEAFBRUSHES
Definition defines.h:177
#define LUMP_LIGHTING_NIGHT
Definition defines.h:174
#define MAX_VALUE
Definition defines.h:164
#define LUMP_ROUTING
Definition defines.h:170
#define LUMP_BRUSHES
Definition defines.h:181
#define LUMP_PLANES
Definition defines.h:168
#define LUMP_TEXINFO
Definition defines.h:172
#define LUMP_LIGHTING_DAY
Definition defines.h:175
#define LUMP_MODELS
Definition defines.h:180
#define LUMP_NORMALS
Definition defines.h:183
#define LUMP_FACES
Definition defines.h:173
#define LUMP_BRUSHSIDES
Definition defines.h:182
#define MAX_MAP_ENTITIES
Definition defines.h:136
#define LUMP_NODES
Definition defines.h:171
#define LUMP_ENTITIES
Definition defines.h:167
#define LIGHTMAP_DAY
Definition defines.h:364
int FS_Write(const void *buffer, int len, qFILE *f)
Properly handles partial writes.
Definition files.cpp:1513
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition files.cpp:384
void FS_FreeFile(void *buffer)
Definition files.cpp:411
int FS_OpenFile(const char *filename, qFILE *file, filemode_t mode)
Finds and opens the file in the search path.
Definition files.cpp:162
@ FILE_WRITE
Definition filesys.h:111
void Sys_Error(const char *error,...)
Definition g_main.cpp:421
#define SEEK_SET
Definition ioapi.cpp:30
voidpf void uLong size
Definition ioapi.h:42
const char * filename
Definition ioapi.h:41
voidpf uLong offset
Definition ioapi.h:45
#define Mem_AllocType(type)
Definition mem.h:39
#define Mem_StrDup(in)
Definition mem.h:48
#define IDBSPHEADER
Definition qfiles.h:251
#define BSPVERSION
Definition qfiles.h:253
#define BSP_SwapHeader(header, name)
Definition qfiles.h:269
QGL_EXTERN GLuint GLchar GLuint * len
Definition r_gl.h:99
QGL_EXTERN GLenum GLuint * dest
Definition r_gl.h:101
QGL_EXTERN GLsizei const GLvoid * data
Definition r_gl.h:89
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition r_gl.h:110
QGL_EXTERN GLint i
Definition r_gl.h:113
void ParseFromMemory(char *buffer, int size)
Parses e.g. the entity string that is already stored in memory.
Definition scriplib.cpp:62
char parsedToken[MAX_TOKEN_CHARS]
Definition scriplib.cpp:45
const char * GetToken()
Parses the next token from the current script on the stack and store the result in parsedToken.
Definition scriplib.cpp:75
#define Q_streq(a, b)
Definition shared.h:136
bool Q_strnull(const char *string)
Definition shared.h:138
#define OBJZERO(obj)
Definition shared.h:178
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition shared.cpp:457
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
Definition shared.cpp:475
int firstbrushside
Definition typedefs.h:62
uint32_t brushContentFlags
Definition typedefs.h:60
int numsides
Definition typedefs.h:61
int firstbrushside
Definition typedefs.h:435
uint32_t brushContentFlags
Definition typedefs.h:437
uint16_t planenum
Definition typedefs.h:429
unsigned short v[2]
Definition typedefs.h:400
The BSP header definition with the data block directory.
Definition qfiles.h:262
uint32_t version
Definition qfiles.h:264
uint32_t ident
Definition qfiles.h:263
lump_t lumps[HEADER_LUMPS]
Definition qfiles.h:265
convex region of space in the BSP tree
Definition typedefs.h:416
short mins[3]
Definition typedefs.h:421
short area
Definition typedefs.h:419
uint16_t numleafbrushes
Definition typedefs.h:425
uint32_t contentFlags
Definition typedefs.h:417
uint16_t firstleafbrush
Definition typedefs.h:424
short maxs[3]
Definition typedefs.h:422
int32_t headnode
Definition typedefs.h:357
int firstface
Definition typedefs.h:358
vec3_t origin
Definition typedefs.h:356
AABB dbmBox
Definition typedefs.h:355
int32_t planenum
Definition typedefs.h:379
short maxs[3]
Definition typedefs.h:382
unsigned short numfaces
Definition typedefs.h:384
unsigned short firstface
Definition typedefs.h:383
short mins[3]
Definition typedefs.h:381
int32_t children[2]
Definition typedefs.h:380
vec3_t normal
Definition typedefs.h:373
float dist
Definition typedefs.h:374
int lightofs[LIGHTMAP_MAX]
Definition typedefs.h:412
short texinfo
Definition typedefs.h:409
short numedges
Definition typedefs.h:408
uint16_t planenum
Definition typedefs.h:404
uint32_t surfaceFlags
Definition typedefs.h:390
float vecs[2][4]
Definition typedefs.h:389
uint32_t value
Definition typedefs.h:391
float point[3]
Definition typedefs.h:362
epair_t * epairs
Definition bspfile.h:50
const char * key
Definition bspfile.h:38
struct epair_s * next
Definition bspfile.h:37
bool ump
Definition bspfile.h:40
const char * value
Definition bspfile.h:39
Directory of the different data blocks.
Definition qfiles.h:256
uint32_t filelen
Definition qfiles.h:258
uint32_t fileofs
Definition qfiles.h:257
char name[MAX_OSPATH]
Definition filesys.h:57
FILE * f
Definition filesys.h:56
static mapTiles_t mapTiles
dMapTile_t * curTile
Definition bsp.cpp:32
float vec_t
Definition ufotypes.h:37
vec_t vec3_t[3]
Definition ufotypes.h:39
uint8_t byte
Definition ufotypes.h:34
#define VectorClear(a)
Definition vector.h:55
#define VectorSet(v, x, y, z)
Definition vector.h:59