forked from TTimo/bspc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bspc.c
1042 lines (970 loc) · 28.7 KB
/
bspc.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-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code 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.
Quake III Arena source code 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 Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#define AASINTERN /* make more botlib function prototypes visible */
#if defined(WIN32) || defined(_WIN32)
#include <direct.h>
#include <windows.h>
#include <sys/types.h>
#include <sys/stat.h>
#else
#include <unistd.h>
#include <glob.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#include "qbsp.h"
#include "l_mem.h"
#include "botlib/aasfile.h"
#include "botlib/be_aas_cluster.h"
#include "botlib/be_aas_optimize.h"
#include "aas_create.h"
#include "aas_store.h"
#include "aas_file.h"
#include "aas_cfg.h"
#include "be_aas_bspc.h"
extern int use_nodequeue; //brushbsp.c
extern int calcgrapplereach; //be_aas_reach.c
float subdivide_size = 240;
char source[1024];
char name[1024];
vec_t microvolume = 1.0;
char outbase[32];
int entity_num;
aas_settings_t aassettings;
qboolean noprune; //don't prune nodes (bspc.c)
qboolean glview; //create a gl view
qboolean nodetail; //don't use detail brushes (map.c)
qboolean fulldetail; //use but don't mark detail brushes (map.c)
qboolean onlyents; //only process the entities (bspc.c)
qboolean nomerge; //don't merge bsp node faces (faces.c)
qboolean nowater; //don't use the water brushes (map.c)
qboolean nocsg; //don't carve intersecting brushes (bspc.c)
qboolean noweld; //use unique face vertexes (faces.c)
qboolean noshare; //don't share bsp edges (faces.c)
qboolean nosubdiv; //don't subdivide bsp node faces (faces.c)
qboolean notjunc; //don't create tjunctions (edge melting) (faces.c)
qboolean optimize; //enable optimisation
qboolean leaktest; //perform a leak test
qboolean verboseentities;
qboolean freetree; //free the bsp tree when not needed anymore
qboolean create_aas; //create an .AAS file
qboolean nobrushmerge; //don't merge brushes
qboolean lessbrushes; //create less brushes instead of correct texture placement
qboolean cancelconversion; //true if the conversion is being cancelled
qboolean noliquids; //no liquids when writing map file
qboolean forcesidesvisible; //force all brush sides to be visible when loaded from bsp
qboolean capsule_collision = 0;
/*
============================================================================
BYTE ORDER FUNCTIONS
============================================================================
*/
short ShortSwap (short l)
{
byte b1,b2;
b1 = l&255;
b2 = (l>>8)&255;
return (b1<<8) + b2;
}
int LongSwap (int l)
{
byte b1,b2,b3,b4;
b1 = l&255;
b2 = (l>>8)&255;
b3 = (l>>16)&255;
b4 = (l>>24)&255;
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}
typedef union {
float f;
unsigned int i;
} _FloatByteUnion;
float FloatSwap (const float *f) {
_FloatByteUnion out;
out.f = *f;
out.i = LongSwap(out.i);
return out.f;
}
/*
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void ProcessWorldModel (void)
{
entity_t *e;
tree_t *tree;
qboolean leaked;
int brush_start, brush_end;
e = &entities[entity_num];
brush_start = e->firstbrush;
brush_end = brush_start + e->numbrushes;
leaked = false;
//process the whole world in one time
tree = ProcessWorldBrushes(brush_start, brush_end);
//create the bsp tree portals
MakeTreePortals(tree);
//mark all leafs that can be reached by entities
if (FloodEntities(tree))
{
FillOutside(tree->headnode);
} //end if
else
{
Log_Print("**** leaked ****\n");
leaked = true;
LeakFile(tree);
if (leaktest)
{
Log_Print("--- MAP LEAKED ---\n");
exit(0);
} //end if
} //end else
MarkVisibleSides (tree, brush_start, brush_end);
FloodAreas (tree);
#ifndef ME
if (glview) WriteGLView(tree, source);
#endif
MakeFaces(tree->headnode);
FixTjuncs(tree->headnode);
//NOTE: Never prune the nodes because the portals
// are screwed when prunning is done and as
// a result portal writing will crash
//if (!noprune) PruneNodes(tree->headnode);
WriteBSP(tree->headnode);
if (!leaked) WritePortalFile(tree);
Tree_Free(tree);
} //end of the function ProcessWorldModel
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void ProcessSubModel (void)
{
entity_t *e;
int start, end;
tree_t *tree;
bspbrush_t *list;
vec3_t mins, maxs;
e = &entities[entity_num];
start = e->firstbrush;
end = start + e->numbrushes;
mins[0] = mins[1] = mins[2] = -4096;
maxs[0] = maxs[1] = maxs[2] = 4096;
list = MakeBspBrushList(start, end, mins, maxs);
if (!nocsg) list = ChopBrushes (list);
tree = BrushBSP (list, mins, maxs);
MakeTreePortals (tree);
MarkVisibleSides (tree, start, end);
MakeFaces (tree->headnode);
FixTjuncs (tree->headnode);
WriteBSP (tree->headnode);
Tree_Free(tree);
} //end of the function ProcessSubModel
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void ProcessModels (void)
{
BeginBSPFile();
for (entity_num = 0; entity_num < num_entities; entity_num++)
{
if (!entities[entity_num].numbrushes)
continue;
Log_Print("############### model %i ###############\n", nummodels);
BeginModel();
if (entity_num == 0) ProcessWorldModel();
else ProcessSubModel();
EndModel();
if (!verboseentities)
verbose = false; // don't bother printing submodels
} //end for
EndBSPFile();
} //end of the function ProcessModels
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void Win_Map2Bsp(char *bspfilename)
{
double start, end;
char path[1024];
start = I_FloatTime();
ThreadSetDefault();
//yeah sure Carmack
//numthreads = 1; // multiple threads aren't helping...
strcpy(source, ExpandArg(bspfilename));
StripExtension(source);
//delete portal and line files
sprintf(path, "%s.prt", source);
remove(path);
sprintf(path, "%s.lin", source);
remove(path);
strcpy(name, ExpandArg(bspfilename));
DefaultExtension(name, ".map"); // might be .reg
Q2_AllocMaxBSP();
//
SetModelNumbers();
SetLightStyles();
ProcessModels();
//write the BSP
Q2_WriteBSPFile(bspfilename);
Q2_FreeMaxBSP();
end = I_FloatTime();
Log_Print("%5.0f seconds elapsed\n", end-start);
} //end of the function Win_Map2Bsp
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void Map2Bsp(char *mapfilename, char *outputfilename)
{
double start, end;
char path[1024];
start = I_FloatTime ();
ThreadSetDefault ();
//yeah sure Carmack
//numthreads = 1; //multiple threads aren't helping...
//SetQdirFromPath(bspfilename);
strcpy(source, ExpandArg(mapfilename));
StripExtension(source);
// delete portal and line files
sprintf(path, "%s.prt", source);
remove(path);
sprintf(path, "%s.lin", source);
remove(path);
strcpy(name, ExpandArg(mapfilename));
DefaultExtension(name, ".map"); // might be .reg
//
// if onlyents, just grab the entites and resave
//
if (onlyents)
{
char out[1024];
Q2_AllocMaxBSP();
sprintf (out, "%s.bsp", source);
Q2_LoadBSPFile(out, 0, 0);
num_entities = 0;
Q2_LoadMapFile(name);
SetModelNumbers();
SetLightStyles();
Q2_UnparseEntities();
Q2_WriteBSPFile(out);
//
Q2_FreeMaxBSP();
} //end if
else
{
//
// start from scratch
//
Q2_AllocMaxBSP();
//load the map
Q2_LoadMapFile(name);
//create the .bsp file
SetModelNumbers();
SetLightStyles();
ProcessModels();
//write the BSP
Q2_WriteBSPFile(outputfilename);
//
Q2_FreeMaxBSP();
} //end else
end = I_FloatTime();
Log_Print("%5.0f seconds elapsed\n", end-start);
} //end of the function Map2Bsp
*/
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AASOuputFile(quakefile_t *qf, char *outputpath, char *filename)
{
char ext[MAX_PATH];
//
if (strlen(outputpath))
{
strcpy(filename, outputpath);
//append the bsp file base
AppendPathSeperator(filename, MAX_PATH);
ExtractFileBase(qf->origname, &filename[strlen(filename)]);
//append .aas
strcat(filename, ".aas");
return;
} //end if
//
ExtractFileExtension(qf->filename, ext);
if (!Q_strcasecmp(ext, "pk3") || !Q_strcasecmp(ext, "pak") || !Q_strcasecmp(ext, "sin"))
{
strcpy(filename, qf->filename);
while(strlen(filename) &&
filename[strlen(filename)-1] != '\\' &&
filename[strlen(filename)-1] != '/')
{
filename[strlen(filename)-1] = '\0';
} //end while
strcat(filename, "maps");
if (access(filename, 0x04)) CreatePath(filename);
//append the bsp file base
AppendPathSeperator(filename, MAX_PATH);
ExtractFileBase(qf->origname, &filename[strlen(filename)]);
//append .aas
strcat(filename, ".aas");
} //end if
else
{
strcpy(filename, qf->filename);
while(strlen(filename) &&
filename[strlen(filename)-1] != '.')
{
filename[strlen(filename)-1] = '\0';
} //end while
strcat(filename, "aas");
} //end else
} //end of the function AASOutputFile
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void CreateAASFilesForAllBSPFiles(char *quakepath)
{
#if defined(WIN32)|defined(_WIN32)
WIN32_FIND_DATA filedata;
HWND handle;
struct _stat statbuf;
int done;
#else
glob_t globbuf;
struct stat statbuf;
int j;
#endif
char filter[_MAX_PATH], bspfilter[_MAX_PATH], aasfilter[_MAX_PATH];
char aasfile[_MAX_PATH], buf[_MAX_PATH], foldername[_MAX_PATH];
quakefile_t *qf, *qf2, *files, *bspfiles, *aasfiles;
strcpy(filter, quakepath);
AppendPathSeperator(filter, sizeof(filter));
strcat(filter, "*");
#if defined(WIN32)|defined(_WIN32)
handle = FindFirstFile(filter, &filedata);
done = (handle == INVALID_HANDLE_VALUE);
while(!done)
{
_splitpath(filter, foldername, NULL, NULL, NULL);
_splitpath(filter, NULL, &foldername[strlen(foldername)], NULL, NULL);
AppendPathSeperator(foldername, _MAX_PATH);
strcat(foldername, filedata.cFileName);
_stat(foldername, &statbuf);
#else
glob(filter, 0, NULL, &globbuf);
for (j = 0; j < globbuf.gl_pathc; j++)
{
strcpy(foldername, globbuf.gl_pathv[j]);
stat(foldername, &statbuf);
#endif
//if it is a folder
if (statbuf.st_mode & S_IFDIR)
{
//
AppendPathSeperator(foldername, sizeof(foldername));
//get all the bsp files
strcpy(bspfilter, foldername);
strcat(bspfilter, "maps/*.bsp");
files = FindQuakeFiles(bspfilter);
strcpy(bspfilter, foldername);
strcat(bspfilter, "*.pk3/maps/*.bsp");
bspfiles = FindQuakeFiles(bspfilter);
for (qf = bspfiles; qf; qf = qf->next) if (!qf->next) break;
if (qf) qf->next = files;
else bspfiles = files;
//get all the aas files
strcpy(aasfilter, foldername);
strcat(aasfilter, "maps/*.aas");
files = FindQuakeFiles(aasfilter);
strcpy(aasfilter, foldername);
strcat(aasfilter, "*.pk3/maps/*.aas");
aasfiles = FindQuakeFiles(aasfilter);
for (qf = aasfiles; qf; qf = qf->next) if (!qf->next) break;
if (qf) qf->next = files;
else aasfiles = files;
//
for (qf = bspfiles; qf; qf = qf->next)
{
sprintf(aasfile, "%s/%s", qf->pakfile, qf->origname);
Log_Print("found %s\n", aasfile);
strcpy(&aasfile[strlen(aasfile)-strlen(".bsp")], ".aas");
for (qf2 = aasfiles; qf2; qf2 = qf2->next)
{
sprintf(buf, "%s/%s", qf2->pakfile, qf2->origname);
if (!Q_strcasecmp(aasfile, buf))
{
Log_Print("found %s\n", buf);
break;
} //end if
} //end for
} //end for
} //end if
#if defined(WIN32)|defined(_WIN32)
//find the next file
done = !FindNextFile(handle, &filedata);
} //end while
#else
} //end for
globfree(&globbuf);
#endif
} //end of the function CreateAASFilesForAllBSPFiles
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
quakefile_t *GetArgumentFiles(int argc, char *argv[], int *i, char *ext)
{
quakefile_t *qfiles, *lastqf, *qf;
int j;
char buf[1024];
qfiles = NULL;
lastqf = NULL;
for (; (*i)+1 < argc && argv[(*i)+1][0] != '-'; (*i)++)
{
strcpy(buf, argv[(*i)+1]);
for (j = strlen(buf)-1; j >= strlen(buf)-4; j--)
if (buf[j] == '.') break;
if (j >= strlen(buf)-4)
strcpy(&buf[j+1], ext);
qf = FindQuakeFiles(buf);
if (!qf) continue;
if (lastqf) lastqf->next = qf;
else qfiles = qf;
lastqf = qf;
while(lastqf->next) lastqf = lastqf->next;
} //end for
return qfiles;
} //end of the function GetArgumentFiles
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
#define COMP_BSP2MAP 1
#define COMP_BSP2AAS 2
#define COMP_REACH 3
#define COMP_CLUSTER 4
#define COMP_AASOPTIMIZE 5
#define COMP_AASINFO 6
int main (int argc, char **argv)
{
int i, comp = 0;
char outputpath[MAX_PATH] = "";
char filename[MAX_PATH] = "unknown";
quakefile_t *qfiles, *qf;
double start_time;
qfiles = NULL;
myargc = argc;
myargv = argv;
start_time = I_FloatTime();
Log_Open("bspc.log"); //open a log file
Log_Print("BSPC version "BSPC_VERSION", %s %s\n", __DATE__, __TIME__);
#ifdef SMOKINGUNS
Log_Print("%s\n", SMOKINGUNS_MESSAGE);
#endif
DefaultCfg();
for (i = 1; i < argc; i++)
{
if (!Q_strcasecmp(argv[i],"-threads"))
{
if (i + 1 >= argc) {i = 0; break;}
numthreads = atoi(argv[++i]);
Log_Print("threads = %d\n", numthreads);
} //end if
else if (!Q_strcasecmp(argv[i], "-noverbose"))
{
Log_Print("verbose = false\n");
verbose = false;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nocsg"))
{
Log_Print("nocsg = true\n");
nocsg = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-optimize"))
{
Log_Print("optimize = true\n");
optimize = true;
} //end else if
/*
else if (!Q_strcasecmp(argv[i],"-glview"))
{
glview = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-draw"))
{
Log_Print("drawflag = true\n");
drawflag = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-noweld"))
{
Log_Print("noweld = true\n");
noweld = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-noshare"))
{
Log_Print("noshare = true\n");
noshare = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-notjunc"))
{
Log_Print("notjunc = true\n");
notjunc = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nowater"))
{
Log_Print("nowater = true\n");
nowater = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-noprune"))
{
Log_Print("noprune = true\n");
noprune = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nomerge"))
{
Log_Print("nomerge = true\n");
nomerge = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nosubdiv"))
{
Log_Print("nosubdiv = true\n");
nosubdiv = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nodetail"))
{
Log_Print("nodetail = true\n");
nodetail = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-fulldetail"))
{
Log_Print("fulldetail = true\n");
fulldetail = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-onlyents"))
{
Log_Print("onlyents = true\n");
onlyents = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-micro"))
{
if (i + 1 >= argc) {i = 0; break;}
microvolume = atof(argv[++i]);
Log_Print("microvolume = %f\n", microvolume);
} //end else if
else if (!Q_strcasecmp(argv[i], "-leaktest"))
{
Log_Print("leaktest = true\n");
leaktest = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-verboseentities"))
{
Log_Print("verboseentities = true\n");
verboseentities = true;
} //end else if
else if (!Q_strcasecmp(argv[i], "-chop"))
{
if (i + 1 >= argc) {i = 0; break;}
subdivide_size = atof(argv[++i]);
Log_Print("subdivide_size = %f\n", subdivide_size);
} //end else if
else if (!Q_strcasecmp (argv[i], "-tmpout"))
{
strcpy (outbase, "/tmp");
Log_Print("temp output\n");
} //end else if
*/
#ifdef ME
else if (!Q_strcasecmp(argv[i], "-freetree"))
{
freetree = true;
Log_Print("freetree = true\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-grapplereach"))
{
calcgrapplereach = true;
Log_Print("grapplereach = true\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-nobrushmerge"))
{
nobrushmerge = true;
Log_Print("nobrushmerge = true\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-noliquids"))
{
noliquids = true;
Log_Print("noliquids = true\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-forcesidesvisible"))
{
forcesidesvisible = true;
Log_Print("forcesidesvisible = true\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-output"))
{
if (i + 1 >= argc) {i = 0; break;}
if (access(argv[i+1], 0x04)) Warning("the folder %s does not exist", argv[i+1]);
strcpy(outputpath, argv[++i]);
} //end else if
else if (!Q_strcasecmp(argv[i], "-breadthfirst"))
{
use_nodequeue = true;
Log_Print("breadthfirst = true\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-capsule"))
{
capsule_collision = true;
Log_Print("capsule_collision = true\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-cfg"))
{
if (i + 1 >= argc) {i = 0; break;}
if (!LoadCfgFile(argv[++i]))
exit(0);
} //end else if
else if (!Q_strcasecmp(argv[i], "-bsp2map"))
{
if (i + 1 >= argc) {i = 0; break;}
comp = COMP_BSP2MAP;
qfiles = GetArgumentFiles(argc, argv, &i, "bsp");
} //end else if
else if (!Q_strcasecmp(argv[i], "-bsp2aas"))
{
if (i + 1 >= argc) {i = 0; break;}
comp = COMP_BSP2AAS;
qfiles = GetArgumentFiles(argc, argv, &i, "bsp");
} //end else if
else if (!Q_strcasecmp(argv[i], "-aasall"))
{
if (i + 1 >= argc) {i = 0; break;}
CreateAASFilesForAllBSPFiles(argv[++i]);
} //end else if
else if (!Q_strcasecmp(argv[i], "-reach"))
{
if (i + 1 >= argc) {i = 0; break;}
comp = COMP_REACH;
qfiles = GetArgumentFiles(argc, argv, &i, "bsp");
} //end else if
else if (!Q_strcasecmp(argv[i], "-cluster"))
{
if (i + 1 >= argc) {i = 0; break;}
comp = COMP_CLUSTER;
qfiles = GetArgumentFiles(argc, argv, &i, "bsp");
} //end else if
else if (!Q_strcasecmp(argv[i], "-aasinfo"))
{
if (i + 1 >= argc) {i = 0; break;}
comp = COMP_AASINFO;
qfiles = GetArgumentFiles(argc, argv, &i, "aas");
} //end else if
else if (!Q_strcasecmp(argv[i], "-aasopt"))
{
if (i + 1 >= argc) {i = 0; break;}
comp = COMP_AASOPTIMIZE;
qfiles = GetArgumentFiles(argc, argv, &i, "aas");
} //end else if
#endif //ME
else
{
Log_Print("unknown parameter %s\n", argv[i]);
break;
} //end else
} //end for
//if there are parameters and there's no mismatch in one of the parameters
if (argc > 1 && i == argc)
{
switch(comp)
{
case COMP_BSP2MAP:
{
if (!qfiles) Log_Print("no files found\n");
for (qf = qfiles; qf; qf = qf->next)
{
//copy the output path
strcpy(filename, outputpath);
//append the bsp file base
AppendPathSeperator(filename, MAX_PATH);
ExtractFileBase(qf->origname, &filename[strlen(filename)]);
//append .map
strcat(filename, ".map");
//
Log_Print("bsp2map: %s to %s\n", qf->origname, filename);
if (qf->type != QFILETYPE_BSP) Warning("%s is probably not a BSP file\n", qf->origname);
//
LoadMapFromBSP(qf);
//write the map file
WriteMapFile(filename);
} //end for
break;
} //end case
case COMP_BSP2AAS:
{
if (!qfiles) Log_Print("no files found\n");
for (qf = qfiles; qf; qf = qf->next)
{
AASOuputFile(qf, outputpath, filename);
//
Log_Print("bsp2aas: %s to %s\n", qf->origname, filename);
if (qf->type != QFILETYPE_BSP) Warning("%s is probably not a BSP file\n", qf->origname);
//set before map loading
create_aas = 1;
LoadMapFromBSP(qf);
//create the AAS file
AAS_Create(filename);
//if it's a Quake3 map calculate the reachabilities and clusters
if (loadedmaptype == MAPTYPE_QUAKE3) AAS_CalcReachAndClusters(qf);
//
if (optimize) AAS_Optimize();
//
//write out the stored AAS file
if (!AAS_WriteAASFile(filename))
{
Error("error writing %s\n", filename);
} //end if
//deallocate memory
AAS_FreeMaxAAS();
} //end for
break;
} //end case
case COMP_REACH:
{
if (!qfiles) Log_Print("no files found\n");
for (qf = qfiles; qf; qf = qf->next)
{
AASOuputFile(qf, outputpath, filename);
//
Log_Print("reach: %s to %s\n", qf->origname, filename);
if (qf->type != QFILETYPE_BSP) Warning("%s is probably not a BSP file\n", qf->origname);
//if the AAS file exists in the output directory
if (!access(filename, 0x04))
{
if (!AAS_LoadAASFile(filename, 0, 0))
{
Error("error loading aas file %s\n", filename);
} //end if
//assume it's a Quake3 BSP file
loadedmaptype = MAPTYPE_QUAKE3;
} //end if
else
{
Warning("AAS file %s not found in output folder\n", filename);
Log_Print("creating %s...\n", filename);
//set before map loading
create_aas = 1;
LoadMapFromBSP(qf);
//create the AAS file
AAS_Create(filename);
} //end else
//if it's a Quake3 map calculate the reachabilities and clusters
if (loadedmaptype == MAPTYPE_QUAKE3)
{
AAS_CalcReachAndClusters(qf);
} //end if
//
if (optimize) AAS_Optimize();
//write out the stored AAS file
if (!AAS_WriteAASFile(filename))
{
Error("error writing %s\n", filename);
} //end if
//deallocate memory
AAS_FreeMaxAAS();
} //end for
break;
} //end case
case COMP_CLUSTER:
{
if (!qfiles) Log_Print("no files found\n");
for (qf = qfiles; qf; qf = qf->next)
{
AASOuputFile(qf, outputpath, filename);
//
Log_Print("cluster: %s to %s\n", qf->origname, filename);
if (qf->type != QFILETYPE_BSP) Warning("%s is probably not a BSP file\n", qf->origname);
//if the AAS file exists in the output directory
if (!access(filename, 0x04))
{
if (!AAS_LoadAASFile(filename, 0, 0))
{
Error("error loading aas file %s\n", filename);
} //end if
//assume it's a Quake3 BSP file
loadedmaptype = MAPTYPE_QUAKE3;
//if it's a Quake3 map calculate the clusters
if (loadedmaptype == MAPTYPE_QUAKE3)
{
aasworld.numclusters = 0;
AAS_InitBotImport();
AAS_InitClustering();
} //end if
} //end if
else
{
Warning("AAS file %s not found in output folder\n", filename);
Log_Print("creating %s...\n", filename);
//set before map loading
create_aas = 1;
LoadMapFromBSP(qf);
//create the AAS file
AAS_Create(filename);
//if it's a Quake3 map calculate the reachabilities and clusters
if (loadedmaptype == MAPTYPE_QUAKE3) AAS_CalcReachAndClusters(qf);
} //end else
//
if (optimize) AAS_Optimize();
//write out the stored AAS file
if (!AAS_WriteAASFile(filename))
{
Error("error writing %s\n", filename);
} //end if
//deallocate memory
AAS_FreeMaxAAS();
} //end for
break;
} //end case
case COMP_AASOPTIMIZE:
{
if (!qfiles) Log_Print("no files found\n");
for (qf = qfiles; qf; qf = qf->next)
{
AASOuputFile(qf, outputpath, filename);
//
Log_Print("optimizing: %s to %s\n", qf->origname, filename);
if (qf->type != QFILETYPE_AAS) Warning("%s is probably not a AAS file\n", qf->origname);
//
AAS_InitBotImport();
//
if (!AAS_LoadAASFile(qf->filename, qf->offset, qf->length))
{
Error("error loading aas file %s\n", qf->filename);
} //end if
AAS_Optimize();
//write out the stored AAS file
if (!AAS_WriteAASFile(filename))
{
Error("error writing %s\n", filename);
} //end if
//deallocate memory
AAS_FreeMaxAAS();
} //end for
break;
} //end case
case COMP_AASINFO:
{
if (!qfiles) Log_Print("no files found\n");
for (qf = qfiles; qf; qf = qf->next)
{
AASOuputFile(qf, outputpath, filename);
//
Log_Print("aas info for: %s\n", filename);
if (qf->type != QFILETYPE_AAS) Warning("%s is probably not a AAS file\n", qf->origname);
//
AAS_InitBotImport();
//
if (!AAS_LoadAASFile(qf->filename, qf->offset, qf->length))
{
Error("error loading aas file %s\n", qf->filename);
} //end if
AAS_ShowTotals();
} //end for
} //end case
default:
{
Log_Print("don't know what to do\n");
break;
} //end default
} //end switch
} //end if
else
{
Log_Print("Usage: bspc [-<switch> [-<switch> ...]]\n"
#if defined(WIN32) || defined(_WIN32)
"Example 1: bspc -bsp2aas d:\\quake3\\baseq3\\maps\\mymap?.bsp\n"
"Example 2: bspc -bsp2aas d:\\quake3\\baseq3\\pak0.pk3\\maps/q3dm*.bsp\n"
#else
"Example 1: bspc -bsp2aas /quake3/baseq3/maps/mymap?.bsp\n"
"Example 2: bspc -bsp2aas /quake3/baseq3/pak0.pk3/maps/q3dm*.bsp\n"
#endif
"\n"
"Switches:\n"
//" bsp2map <[pakfilter/]filter.bsp> = convert BSP to MAP\n"
//" aasall <quake3folder> = create AAS files for all BSPs\n"
" bsp2aas <[pakfilter/]filter.bsp> = convert BSP to AAS\n"
" reach <filter.bsp> = compute reachability & clusters\n"