-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbsp.c
1133 lines (978 loc) · 27.5 KB
/
bsp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -------------------------------------------------------------------------------
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
For a list of contributors, see the accompanying CONTRIBUTORS file.
This file is part of GtkRadiant.
GtkRadiant is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GtkRadiant is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
----------------------------------------------------------------------------------
This code has been altered significantly from its original form, to support
several games based on the Quake III Arena engine, in the form of "Q3Map2."
------------------------------------------------------------------------------- */
/* marker */
#define BSP_C
/* dependencies */
//#include "q3map2.h"
#include "kmap2.h" //add hypov8
/* -------------------------------------------------------------------------------
functions
------------------------------------------------------------------------------- */
/*
ProcessAdvertisements()
copies advertisement info into the BSP structures
*/
static void ProcessAdvertisements(void)
{
int i;
const char *className;
const char *modelKey;
int modelNum;
bspModel_t *adModel;
bspDrawSurface_t *adSurface;
Sys_FPrintf(SYS_VRB, "--- ProcessAdvertisements ---\n");
for(i = 0; i < numEntities; i++)
{
/* is an advertisement? */
className = ValueForKey(&entities[i], "classname");
if(!Q_stricmp("advertisement", className))
{
modelKey = ValueForKey(&entities[i], "model");
if(strlen(modelKey) > MAX_QPATH - 1)
{
Error("Model Key for entity exceeds ad struct string length.");
}
else
{
if(numBSPAds < MAX_MAP_ADVERTISEMENTS)
{
bspAds[numBSPAds].cellId = IntForKey(&entities[i], "cellId");
strncpy(bspAds[numBSPAds].model, modelKey, sizeof(bspAds[numBSPAds].model));
modelKey++;
modelNum = atoi(modelKey);
adModel = &bspModels[modelNum];
if(adModel->numBSPSurfaces != 1)
{
Error("Ad cell id %d has more than one surface.", bspAds[numBSPAds].cellId);
}
adSurface = &bspDrawSurfaces[adModel->firstBSPSurface];
// store the normal for use at run time.. all ad verts are assumed to
// have identical normals (because they should be a simple rectangle)
// so just use the first vert's normal
VectorCopy(bspDrawVerts[adSurface->firstVert].normal, bspAds[numBSPAds].normal);
// store the ad quad for quick use at run time
if(adSurface->surfaceType == MST_PATCH)
{
int v0 = adSurface->firstVert + adSurface->patchHeight - 1;
int v1 = adSurface->firstVert + adSurface->numVerts - 1;
int v2 = adSurface->firstVert + adSurface->numVerts - adSurface->patchWidth;
int v3 = adSurface->firstVert;
VectorCopy(bspDrawVerts[v0].xyz, bspAds[numBSPAds].rect[0]);
VectorCopy(bspDrawVerts[v1].xyz, bspAds[numBSPAds].rect[1]);
VectorCopy(bspDrawVerts[v2].xyz, bspAds[numBSPAds].rect[2]);
VectorCopy(bspDrawVerts[v3].xyz, bspAds[numBSPAds].rect[3]);
}
else
{
Error("Ad cell %d has an unsupported Ad Surface type.", bspAds[numBSPAds].cellId);
}
numBSPAds++;
}
else
{
Error("Maximum number of map advertisements exceeded.");
}
}
}
}
Sys_FPrintf(SYS_VRB, "%9d in-game advertisements\n", numBSPAds);
}
/*
SetCloneModelNumbers() - ydnar
sets the model numbers for brush entities
*/
static void SetCloneModelNumbers(void)
{
int i; // j;
entity_t *ent;
int models;
char modelValue[10];
// const char *value, *value2, *value3;
const char *classname;
const char *model;
/* start with 1 (worldspawn is model 0) */
models = 1;
for(i = 1; i < numEntities; i++)
{
ent = &entities[i];
classname = ValueForKey(ent, "classname");
model = ValueForKey(ent, "model");
/* only entities with brushes or patches get a model number */
if(ent->brushes || ent->patches ||
(inlineEntityModels && !ent->brushes && !ent->patches && model[0] != '\0' && Q_stricmp("misc_model", classname)))
{
/* is this a clone? */
/*
value = ValueForKey(&entities[i], "_clone");
if(value[0] != '\0')
continue;
*/
/* add the model key */
sprintf(modelValue, "*%d", models);
SetKeyValue(&entities[i], "model", modelValue);
/* increment model count */
models++;
}
}
#if 0
/* fix up clones */
for(i = 1; i < numEntities; i++)
{
/* only entities with brushes or patches get a model number */
if(entities[i].brushes == NULL && entities[i].patches == NULL)
continue;
/* is this a clone? */
value = ValueForKey(&entities[i], "_ins");
if(value[0] == '\0')
value = ValueForKey(&entities[i], "_instance");
if(value[0] == '\0')
value = ValueForKey(&entities[i], "_clone");
if(value[0] == '\0')
continue;
/* find an entity with matching clone name */
for(j = 0; j < numEntities; j++)
{
/* is this a clone parent? */
value2 = ValueForKey(&entities[j], "_clonename");
if(value2[0] == '\0')
continue;
/* do they match? */
if(strcmp(value, value2) == 0)
{
/* get the model num */
value3 = ValueForKey(&entities[j], "model");
if(value3[0] == '\0')
{
Sys_Printf("WARNING: Cloned entity %s referenced entity without model\n", value2);
continue;
}
models = atoi(&value2[1]);
/* add the model key */
sprintf(modelValue, "*%d", models);
SetKeyValue(&entities[i], "model", modelValue);
/* nuke the brushes/patches for this entity (fixme: leak!) */
entities[i].brushes = NULL;
entities[i].patches = NULL;
}
}
}
#endif
}
/*
FixBrushSides() - ydnar
matches brushsides back to their appropriate drawsurface and shader
*/
static void FixBrushSides(entity_t * e)
{
int i;
mapDrawSurface_t *ds;
sideRef_t *sideRef;
bspBrushSide_t *side;
/* note it */
Sys_FPrintf(SYS_VRB, "--- FixBrushSides ---\n");
/* walk list of drawsurfaces */
for(i = e->firstDrawSurf; i < numMapDrawSurfs; i++)
{
/* get surface and try to early out */
ds = &mapDrawSurfs[i];
if(ds->outputNum < 0)
continue;
/* walk sideref list */
for(sideRef = ds->sideRef; sideRef != NULL; sideRef = sideRef->next)
{
/* get bsp brush side */
if(sideRef->side == NULL || sideRef->side->outputNum < 0)
continue;
side = &bspBrushSides[sideRef->side->outputNum];
/* set drawsurface */
side->surfaceNum = ds->outputNum;
//% Sys_FPrintf( SYS_VRB, "DS: %7d Side: %7d ", ds->outputNum, sideRef->side->outputNum );
/* set shader */
if(strcmp(bspShaders[side->shaderNum].shader, ds->shaderInfo->shader))
{
//% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader );
side->shaderNum =
EmitShader(ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags);
}
}
}
}
int PortalVisibleSides(portal_t * p)
{
int fcon, bcon;
if(!p->onnode)
return 0; // outside
fcon = p->nodes[0]->opaque;
bcon = p->nodes[1]->opaque;
// same contents never create a face
if(fcon == bcon)
return 0;
if(!fcon)
return 1;
if(!bcon)
return 2;
return 0;
}
static void DrawPortal(portal_t * p, qboolean areaportal)
{
winding_t *w;
int sides;
sides = PortalVisibleSides(p);
if(!sides)
return;
w = p->winding;
if(sides == 2) // back side
w = ReverseWinding(w);
if(areaportal)
{
Draw_Winding(w, 1, 0, 0, 0.3);
}
else
{
Draw_Winding(w, 0, 0, 1, 0.3);
}
if(sides == 2)
FreeWinding(w);
}
static void DrawTreePortals_r(node_t * node)
{
int s;
portal_t *p/*, *nextp*/;
winding_t *w;
if(node->planenum != PLANENUM_LEAF)
{
DrawTreePortals_r(node->children[0]);
DrawTreePortals_r(node->children[1]);
return;
}
// draw all the portals
for(p = node->portals; p; p = p->next[s])
{
w = p->winding;
s = (p->nodes[1] == node);
if(w) // && p->nodes[0] == node)
{
//if(PortalPassable(p))
// continue;
DrawPortal(p, node->areaportal);
}
}
}
static tree_t *drawTree = NULL;
static int drawTreeNodesNum;
static void DrawTreePortals(void)
{
DrawTreePortals_r(drawTree->headnode);
}
static void DrawTreeNodes_r(node_t * node)
{
int i/*, s*/;
brush_t *b;
winding_t *w;
vec4_t nodeColor = {1, 1, 0, 0.3};
vec4_t leafColor = {0, 0, 1, 0.3};
if(!node)
return;
drawTreeNodesNum++;
if(node->planenum == PLANENUM_LEAF)
{
//VectorCopy(debugColors[drawTreeNodesNum % 12], leafColor);
Draw_AABB(vec3_origin, node->mins, node->maxs, leafColor);
for(b = node->brushlist; b != NULL; b = b->next)
{
for(i = 0; i < b->numsides; i++)
{
w = b->sides[i].winding;
if(!w)
continue;
if(node->areaportal)
{
Draw_Winding(w, 1, 0, 0, 0.3);
}
else if(b->detail)
{
Draw_Winding(w, 0, 1, 0, 0.3);
}
else
{
// opaque
Draw_Winding(w, 0, 0, 0, 0.1);
}
}
}
return;
}
//Draw_AABB(vec3_origin, node->mins, node->maxs, nodeColor);
DrawTreeNodes_r(node->children[0]);
DrawTreeNodes_r(node->children[1]);
}
static void DrawNodes(void)
{
drawTreeNodesNum = 0;
DrawTreeNodes_r(drawTree->headnode);
}
static void DrawTree(void)
{
DrawNodes();
}
/*
ProcessWorldModel()
creates a full bsp + surfaces for the worldspawn entity
*/
void ProcessWorldModel(void)
{
int i, s;
entity_t *e;
tree_t *tree;
face_t *faces;
qboolean ignoreLeaks, leaked;
/*xmlNodePtr polyline, leaknode;*/
char /*level[2],*/ shader[1024];
const char *value;
/* sets integer blockSize from worldspawn "_blocksize" key if it exists */
value = ValueForKey(&entities[0], "_blocksize");
if(value[0] == '\0')
value = ValueForKey(&entities[0], "blocksize");
if(value[0] == '\0')
value = ValueForKey(&entities[0], "chopsize"); /* sof2 */
if(value[0] != '\0')
{
/* scan 3 numbers */
s = sscanf(value, "%d %d %d", &blockSize[0], &blockSize[1], &blockSize[2]);
/* handle legacy case */
if(s == 1)
{
blockSize[1] = blockSize[0];
blockSize[2] = blockSize[0];
}
}
Sys_Printf("block size = { %d %d %d }\n", blockSize[0], blockSize[1], blockSize[2]);
/* sof2: ignore leaks? */
value = ValueForKey(&entities[0], "_ignoreleaks"); /* ydnar */
if(value[0] == '\0')
value = ValueForKey(&entities[0], "ignoreleaks");
if(value[0] == '1')
ignoreLeaks = qtrue;
else
ignoreLeaks = qfalse;
/* begin worldspawn model */
BeginModel();
e = &entities[0];
e->firstDrawSurf = 0;
/* ydnar: gs mods */
ClearMetaTriangles();
/* check for patches with adjacent edges that need to lod together */
PatchMapDrawSurfs(e);
/* build an initial bsp tree using all of the sides of all of the structural brushes */
faces = MakeStructuralBSPFaceList(entities[0].brushes);
tree = FaceBSP(faces, qtrue);
MakeTreePortals(tree);
FilterStructuralBrushesIntoTree(e, tree);
/* see if the bsp is completely enclosed */
if(FloodEntities(tree) || ignoreLeaks)
{
/* rebuild a better bsp tree using only the sides that are visible from the inside */
FillOutside(tree->headnode);
/* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
ClipSidesIntoTree(e, tree);
/* build a visible face tree */
faces = MakeVisibleBSPFaceList(entities[0].brushes);
FreeTree(tree);
tree = FaceBSP(faces, qtrue);
MakeTreePortals(tree);
FilterStructuralBrushesIntoTree(e, tree);
leaked = qfalse;
/* ydnar: flood again for skybox */
if(skyboxPresent)
FloodEntities(tree);
}
else
{
Sys_FPrintf(SYS_NOXML, "**********************\n");
Sys_FPrintf(SYS_NOXML, "******* leaked *******\n");
Sys_FPrintf(SYS_NOXML, "**********************\n");
#if defined(USE_XML)
polyline = LeakFile(tree);
leaknode = xmlNewNode(NULL, "message");
xmlNodeSetContent(leaknode, "MAP LEAKED\n");
xmlAddChild(leaknode, polyline);
level[0] = (int)'0' + SYS_ERR;
level[1] = 0;
xmlSetProp(leaknode, "level", (char *)&level);
xml_SendNode(leaknode);
#else
LeakFile(tree);
#endif
if(leaktest)
{
Sys_Printf("--- MAP LEAKED, ABORTING LEAKTEST ---\n");
exit(0);
}
leaked = qtrue;
/* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
ClipSidesIntoTree(e, tree);
}
#if 1
if(drawBSP)
{
drawTree = tree;
Draw_Scene(DrawNodes);
Draw_Scene(DrawTreePortals);
}
#endif
/* save out information for visibility processing */
NumberClusters(tree);
if(!leaked)
WritePortalFile(tree);
/* flood from entities */
FloodAreas(tree);
/* create drawsurfs for triangle models */
AddTriangleModels(e);
/* create drawsurfs for surface models */
AddEntitySurfaceModels(e);
/* generate bsp brushes from map brushes */
EmitBrushes(e->brushes, &e->firstBrush, &e->numBrushes);
/* add references to the detail brushes */
FilterDetailBrushesIntoTree(e, tree);
/* drawsurfs that cross fog boundaries will need to be split along the fog boundary */
if(!nofog)
FogDrawSurfaces(e);
/* subdivide each drawsurf as required by shader tesselation */
if(!nosubdivide)
SubdivideFaceSurfaces(e, tree);
/* add in any vertexes required to fix t-junctions */
if(!notjunc)
FixTJunctions(e);
/* ydnar: classify the surfaces */
ClassifyEntitySurfaces(e);
/* ydnar: project decals */
MakeEntityDecals(e);
/* ydnar: meta surfaces */
MakeEntityMetaTriangles(e);
SmoothMetaTriangles();
FixMetaTJunctions();
MergeMetaTriangles();
/* ydnar: debug portals */
if(debugPortals)
MakeDebugPortalSurfs(tree);
/* ydnar: fog hull */
value = ValueForKey(&entities[0], "_foghull");
if(value[0] != '\0')
{
sprintf(shader, "textures/%s", value);
MakeFogHullSurfs(e, tree, shader);
}
/* ydnar: bug 645: do flares for lights */
for(i = 0; i < numEntities && emitFlares; i++)
{
entity_t *light, *target;
const char *value, *flareShader;
vec3_t origin, targetOrigin, normal, color;
int lightStyle;
/* get light */
light = &entities[i];
value = ValueForKey(light, "classname");
if(!strcmp(value, "light"))
{
/* get flare shader */
flareShader = ValueForKey(light, "_flareshader");
value = ValueForKey(light, "_flare");
if(flareShader[0] != '\0' || value[0] != '\0')
{
/* get specifics */
GetVectorForKey(light, "origin", origin);
GetVectorForKey(light, "_color", color);
lightStyle = IntForKey(light, "_style");
if(lightStyle == 0)
lightStyle = IntForKey(light, "style");
/* handle directional spotlights */
value = ValueForKey(light, "target");
if(value[0] != '\0')
{
/* get target light */
target = FindTargetEntity(value);
if(target != NULL)
{
GetVectorForKey(target, "origin", targetOrigin);
VectorSubtract(targetOrigin, origin, normal);
VectorNormalize(normal);
}
}
else
//% VectorClear( normal );
VectorSet(normal, 0, 0, -1);
/* create the flare surface (note shader defaults automatically) */
DrawSurfaceForFlare(mapEntityNum, origin, normal, color, (char *)flareShader, lightStyle);
}
}
}
/* add references to the final drawsurfs in the apropriate clusters */
FilterDrawsurfsIntoTree(e, tree);
/* match drawsurfaces back to original brushsides (sof2) */
FixBrushSides(e);
/* finish */
EndModel(e, tree->headnode);
#if 1
if(drawBSP)
{
// draw unoptimized portals in new window
drawTree = tree;
Draw_Scene(DrawNodes);
}
#endif
FreeTree(tree);
}
/*
ProcessSubModel()
creates bsp + surfaces for other brush models
*/
void ProcessSubModel(void)
{
entity_t *e;
tree_t *tree;
brush_t *b, *bc;
node_t *node;
/* start a brush model */
BeginModel();
e = &entities[mapEntityNum];
e->firstDrawSurf = numMapDrawSurfs;
/* ydnar: gs mods */
ClearMetaTriangles();
/* check for patches with adjacent edges that need to lod together */
PatchMapDrawSurfs(e);
/* allocate a tree */
node = AllocNode();
node->planenum = PLANENUM_LEAF;
tree = AllocTree();
tree->headnode = node;
/* add the sides to the tree */
ClipSidesIntoTree(e, tree);
/* Tr3B: create drawsurfs for triangle models in Doom3 style */
AddTriangleModel(e);
/* create drawsurfs for surface models */
AddEntitySurfaceModels(e);
/* generate bsp brushes from map brushes */
EmitBrushes(e->brushes, &e->firstBrush, &e->numBrushes);
/* just put all the brushes in headnode */
for(b = e->brushes; b; b = b->next)
{
bc = CopyBrush(b);
bc->next = node->brushlist;
node->brushlist = bc;
}
/* subdivide each drawsurf as required by shader tesselation */
if(!nosubdivide)
SubdivideFaceSurfaces(e, tree);
/* add in any vertexes required to fix t-junctions */
if(!notjunc)
FixTJunctions(e);
/* ydnar: classify the surfaces and project lightmaps */
ClassifyEntitySurfaces(e);
/* ydnar: project decals */
MakeEntityDecals(e);
/* ydnar: meta surfaces */
MakeEntityMetaTriangles(e);
SmoothMetaTriangles();
FixMetaTJunctions();
MergeMetaTriangles();
/* add references to the final drawsurfs in the apropriate clusters */
FilterDrawsurfsIntoTree(e, tree);
/* match drawsurfaces back to original brushsides (sof2) */
FixBrushSides(e);
/* finish */
EndModel(e, node);
FreeTree(tree);
}
/*
ProcessModels()
process world + other models into the bsp
*/
void ProcessModels(void)
{
qboolean oldVerbose;
entity_t *entity;
const char *classname;
const char *name;
const char *model;
/* preserve -v setting */
oldVerbose = verbose;
/* start a new bsp */
BeginBSPFile();
/* create map fogs */
CreateMapFogs();
/* walk entity list */
for(mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++)
{
/* get entity */
entity = &entities[mapEntityNum];
classname = ValueForKey(entity, "classname");
model = ValueForKey(entity, "model");
name = ValueForKey(entity, "name");
if(entity->brushes || entity->patches ||
(inlineEntityModels && !entity->brushes && !entity->patches && model[0] != '\0' && Q_stricmp("misc_model", classname)))
{
/* process the model */
Sys_FPrintf(SYS_VRB, "############### model %i '%s' ###############\n", numBSPModels, name);
if(mapEntityNum == 0)
ProcessWorldModel();
else
ProcessSubModel();
/* potentially turn off the deluge of text */
verbose = verboseEntities;
}
}
/* restore -v setting */
verbose = oldVerbose;
/* write fogs */
EmitFogs();
/* vortex: emit meta stats */
EmitMetaStats();
}
/*
OnlyEnts()
this is probably broken unless teamed with a radiant version that preserves entity order
*/
void OnlyEnts(void)
{
char out[1024];
char save_cmdline[1024], save_version[1024];
const char *p;
/* note it */
Sys_Printf("--- OnlyEnts ---\n");
sprintf(out, "%s.bsp", source);
LoadBSPFile(out);
ParseEntities();
p = ValueForKey(&entities[0], "_xmap2_cmdline");
strncpy(save_cmdline, p, sizeof(save_cmdline));
save_cmdline[sizeof(save_cmdline) - 1] = 0;
p = ValueForKey(&entities[0], "_xmap2_version");
strncpy(save_version, p, sizeof(save_version));
save_version[sizeof(save_version) - 1] = 0;
numEntities = 0;
LoadShaderInfo();
LoadMapFile(name, qfalse);
SetModelNumbers();
//% Tr3B: SetLightStyles();
if(*save_cmdline)
SetKeyValue(&entities[0], "_xmap2_cmdline", save_cmdline);
if(*save_version)
SetKeyValue(&entities[0], "_xmap2_version", save_version);
numBSPEntities = numEntities;
UnparseEntities();
WriteBSPFile(out);
}
/*
BSPMain() - ydnar
handles creation of a bsp from a map file
*/
int BSPMain(int argc, char **argv)
{
int i;
char path[1024], tempSource[1024];
qboolean onlyents = qfalse;
/* note it */
Sys_Printf("--- BSP ---\n");
SetDrawSurfacesBuffer();
mapDrawSurfs = safe_malloc(sizeof(mapDrawSurface_t) * MAX_MAP_DRAW_SURFS);
memset(mapDrawSurfs, 0, sizeof(mapDrawSurface_t) * MAX_MAP_DRAW_SURFS);
numMapDrawSurfs = 0;
tempSource[0] = '\0';
/* set standard game flags */
maxSurfaceVerts = game->maxSurfaceVerts;
maxLMSurfaceVerts = game->maxLMSurfaceVerts;
maxSurfaceIndexes = game->maxSurfaceIndexes;
emitFlares = game->emitFlares;
/* process arguments */
for(i = 1; i < (argc - 1); i++)
{
if(!strcmp(argv[i], "-onlyents"))
{
Sys_Printf("Running entity-only compile\n");
onlyents = qtrue;
}
else if(!strcmp(argv[i], "-tempname"))
strcpy(tempSource, argv[++i]);
else if(!strcmp(argv[i], "-tmpout"))
strcpy(outbase, "/tmp");
else if(!strcmp(argv[i], "-nowater"))
{
Sys_Printf("Disabling water\n");
nowater = qtrue;
}
else if(!strcmp(argv[i], "-nodetail"))
{
Sys_Printf("Ignoring detail brushes\n");
nodetail = qtrue;
}
else if(!strcmp(argv[i], "-fulldetail"))
{
Sys_Printf("Turning detail brushes into structural brushes\n");
fulldetail = qtrue;
}
else if(!strcmp(argv[i], "-nofog"))
{
Sys_Printf("Fog volumes disabled\n");
nofog = qtrue;
}
else if(!strcmp(argv[i], "-nosubdivide"))
{
Sys_Printf("Disabling brush face subdivision\n");
nosubdivide = qtrue;
}
else if(!strcmp(argv[i], "-leaktest"))
{
Sys_Printf("Leaktest enabled\n");
leaktest = qtrue;
}
else if(!strcmp(argv[i], "-verboseentities"))
{
Sys_Printf("Verbose entities enabled\n");
verboseEntities = qtrue;
}
else if(!strcmp(argv[i], "-nocurves"))
{
Sys_Printf("Ignoring curved surfaces (patches)\n");
noCurveBrushes = qtrue;
}
else if(!strcmp(argv[i], "-notjunc"))
{
Sys_Printf("T-junction fixing disabled\n");
notjunc = qtrue;
}
else if(!strcmp(argv[i], "-fakemap"))
{
Sys_Printf("Generating fakemap.map\n");
fakemap = qtrue;
}
else if(!strcmp(argv[i], "-samplesize"))
{
sampleSize = atoi(argv[i + 1]);
if(sampleSize < 1)
sampleSize = 1;
i++;
Sys_Printf("Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize);
}
else if(!strcmp(argv[i], "-minsamplesize"))
{
minSampleSize = atoi(argv[i + 1]);
if(minSampleSize < 1)
minSampleSize = 1;
i++;
Sys_Printf("Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize);
}
else if(!strcmp(argv[i], "-custinfoparms"))
{
Sys_Printf("Custom info parms enabled\n");
useCustomInfoParms = qtrue;
}
/* sof2 args */
else if(!strcmp(argv[i], "-rename"))
{
Sys_Printf("Appending _bsp suffix to misc_model shaders (SOF2)\n");
renameModelShaders = qtrue;
}
/* ydnar args */
else if(!strcmp(argv[i], "-ne"))
{
normalEpsilon = atof(argv[i + 1]);
i++;
Sys_Printf("Normal epsilon set to %f\n", normalEpsilon);
}
else if(!strcmp(argv[i], "-de"))
{
distanceEpsilon = atof(argv[i + 1]);
i++;
Sys_Printf("Distance epsilon set to %f\n", distanceEpsilon);
}
else if(!strcmp(argv[i], "-mv"))
{
maxLMSurfaceVerts = atoi(argv[i + 1]);
if(maxLMSurfaceVerts < 3)
maxLMSurfaceVerts = 3;
if(maxLMSurfaceVerts > maxSurfaceVerts)
maxSurfaceVerts = maxLMSurfaceVerts;
i++;
Sys_Printf("Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts);
}
else if(!strcmp(argv[i], "-mi"))
{
maxSurfaceIndexes = atoi(argv[i + 1]);
if(maxSurfaceIndexes < 3)
maxSurfaceIndexes = 3;
i++;
Sys_Printf("Maximum per-surface index count set to %d\n", maxSurfaceIndexes);
}
else if(!strcmp(argv[i], "-np"))
{
npDegrees = atof(argv[i + 1]);
if(npDegrees < 0.0f)
shadeAngleDegrees = 0.0f;
else if(npDegrees > 0.0f)
Sys_Printf("Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees);
i++;
}
else if(!strcmp(argv[i], "-snap"))
{
bevelSnap = atoi(argv[i + 1]);
if(bevelSnap < 0)
bevelSnap = 0;
i++;
if(bevelSnap > 0)
Sys_Printf("Snapping brush bevel planes to %d units\n", bevelSnap);
}
else if(!strcmp(argv[i], "-texrange"))
{
texRange = atoi(argv[i + 1]);
if(texRange < 0)
texRange = 0;
i++;
Sys_Printf("Limiting per-surface texture range to %d texels\n", texRange);
}
else if(!strcmp(argv[i], "-nohint"))
{
Sys_Printf("Hint brushes disabled\n");
noHint = qtrue;
}
else if(!strcmp(argv[i], "-flat"))
{
Sys_Printf("Flatshading enabled\n");
flat = qtrue;
}
else if(!strcmp(argv[i], "-meta"))
{
Sys_Printf("Creating meta surfaces from brush faces\n");