forked from bnoordhuis/bspc
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bspc.cpp
815 lines (777 loc) · 23.7 KB
/
bspc.cpp
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
/*
===========================================================================
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>
#else
#include <unistd.h>
#include <glob.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include "qbsp.h"
#include "l_mem.h"
#include "aasfile.h"
#include "be_aas_cluster.h"
#include "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; //qtrue 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 = qfalse;
/*
============================================================================
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: -
//===========================================================================
static void AASOuputFile(quakefile_t *qf, const 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: -
//===========================================================================
static void CreateAASFilesForAllBSPFiles(const char *quakepath)
{
#if defined(WIN32)|defined(_WIN32)
WIN32_FIND_DATA filedata;
HWND handle;
struct _stat statbuf;
#else
glob_t globbuf;
struct stat statbuf;
#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 = static_cast<HWND>(FindFirstFile(filter, &filedata));
int 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 (size_t 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)
{
snprintf(aasfile, sizeof(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)
{
snprintf(buf, sizeof(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: -
//===========================================================================
static quakefile_t *GetArgumentFiles(int argc, char * argv[], int *i, const 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 = static_cast<int>(strlen(buf))-1; j >= static_cast<int>(strlen(buf))-4; j--) {
if (buf[j] == '.') break;
}
if (j >= static_cast<int>(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 "\n");
Log_Print("Sago's version from https://github.com/sago007/bspc\n");
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 = qfalse;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nocsg"))
{
Log_Print("nocsg = qtrue\n");
nocsg = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-optimize"))
{
Log_Print("optimize = qtrue\n");
optimize = qtrue;
} //end else if
/*
else if (!Q_strcasecmp(argv[i],"-glview"))
{
glview = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-draw"))
{
Log_Print("drawflag = qtrue\n");
drawflag = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-noweld"))
{
Log_Print("noweld = qtrue\n");
noweld = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-noshare"))
{
Log_Print("noshare = qtrue\n");
noshare = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-notjunc"))
{
Log_Print("notjunc = qtrue\n");
notjunc = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nowater"))
{
Log_Print("nowater = qtrue\n");
nowater = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-noprune"))
{
Log_Print("noprune = qtrue\n");
noprune = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nomerge"))
{
Log_Print("nomerge = qtrue\n");
nomerge = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nosubdiv"))
{
Log_Print("nosubdiv = qtrue\n");
nosubdiv = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-nodetail"))
{
Log_Print("nodetail = qtrue\n");
nodetail = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-fulldetail"))
{
Log_Print("fulldetail = qtrue\n");
fulldetail = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-onlyents"))
{
Log_Print("onlyents = qtrue\n");
onlyents = qtrue;
} //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 = qtrue\n");
leaktest = qtrue;
} //end else if
else if (!Q_strcasecmp(argv[i], "-verboseentities"))
{
Log_Print("verboseentities = qtrue\n");
verboseentities = qtrue;
} //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 = qtrue;
Log_Print("freetree = qtrue\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-grapplereach"))
{
calcgrapplereach = qtrue;
Log_Print("grapplereach = qtrue\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-nobrushmerge"))
{
nobrushmerge = qtrue;
Log_Print("nobrushmerge = qtrue\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-noliquids"))
{
noliquids = qtrue;
Log_Print("noliquids = qtrue\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-forcesidesvisible"))
{
forcesidesvisible = qtrue;
Log_Print("forcesidesvisible = qtrue\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 = qtrue;
Log_Print("breadthfirst = qtrue\n");
} //end else if
else if (!Q_strcasecmp(argv[i], "-capsule"))
{
capsule_collision = qtrue;
Log_Print("capsule_collision = qtrue\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 = qtrue;
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 = qtrue;
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 = qtrue;
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
break;
} //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"
" cluster <filter.aas> = compute clusters\n"
" aasopt <filter.aas> = optimize aas file\n"
" aasinfo <filter.aas> = show AAS file info\n"
" output <output path> = set output path\n"
" threads <X> = set number of threads to X\n"
" cfg <filename> = use this cfg file\n"
" optimize = enable optimization\n"
" noverbose = disable verbose output\n"
" breadthfirst = breadth first bsp building\n"
" nobrushmerge = don't merge brushes\n"
" noliquids = don't write liquids to map\n"
" freetree = free the bsp tree\n"
" nocsg = disables brush chopping\n"
" forcesidesvisible = force all sides to be visible\n"
" grapplereach = calculate grapple reachabilities\n"
/* " glview = output a GL view\n"
" draw = enables drawing\n"
" noweld = disables weld\n"
" noshare = disables sharing\n"
" notjunc = disables juncs\n"
" nowater = disables water brushes\n"
" noprune = disables node prunes\n"
" nomerge = disables face merging\n"
" nosubdiv = disables subdeviding\n"
" nodetail = disables detail brushes\n"
" fulldetail = enables full detail\n"
" onlyents = only compile entities with bsp\n"
" micro <volume>\n"
" = sets the micro volume to the given float\n"
" leaktest = perform a leak test\n"
" verboseentities\n"
" = enable entity verbose mode\n"
" chop <subdivide_size>\n"
" = sets the subdivide size to the given float\n"*/
"\n");
} //end else
Log_Print("BSPC run time is %5.0f seconds\n", I_FloatTime() - start_time);
Log_Close(); //close the log file
return 0;
} //end of the function main