/
LIGHT.C
821 lines (690 loc) · 21.1 KB
/
LIGHT.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
// lighting.c
#include <windows.h>
#include "light.h"
#pragma comment (lib, "Winmm.lib")
// threads compatibility
#define LOCK WaitForSingleObject (hThreadMutex, INFINITE)
#define UNLOCK ReleaseMutex (hThreadMutex)
HANDLE hThreadMutex;
volatile int finished;
int numthreads = 4;
typedef struct threadinfo_s
{
int firstface;
int lastface;
int threadnum;
} threadinfo_t;
threadinfo_t *threadinfos;
void RunThreadsOn (LPTHREAD_START_ROUTINE proc)
{
int i;
int start = timeGetTime ();
int end;
finished = 0;
if (numthreads < 1) numthreads = 1;
if (numfaces < numthreads) numthreads = 1;
InitPercents (numthreads);
threadinfos = (threadinfo_t *) malloc (numthreads * sizeof (threadinfo_t));
for (i = 0; i < numthreads; i++)
{
threadinfos[i].threadnum = i + 1;
threadinfos[i].firstface = (numfaces / numthreads) * i;
}
for (i = 1; i < numthreads; i++)
threadinfos[i - 1].lastface = threadinfos[i].firstface;
threadinfos[numthreads - 1].lastface = numfaces;
for (i = 0; i < numthreads; i++)
CreateThread (NULL, 0, proc, &threadinfos[i], 0, NULL);
while (1)
{
if (finished >= numthreads) break;
Sleep (1);
}
if (!SimpPercent)
printf ("\n");
printf ("\n");
end = timeGetTime ();
#ifdef _DEBUG
printf ("done in %f seconds\npress any key... ", (float) (end - start) / 1000.0f);
while (1)
{
if (_kbhit ()) break;
Sleep (1);
}
#endif
}
void InitThreads (void)
{
hThreadMutex = CreateMutex (NULL, FALSE, NULL);
}
#define LOGFILENAME "LIGHT.LOG"
/*
NOTES
-----
*/
float scaledist = -1; // "-dist" value
float scalecos = 0.5; // Default angle sensitivity
float ShadowSense = -1; // Angle (shadow) sensitivity for 2nd sunlight
float rangescale = -1; // "-range" value
float GateVal = 0; // Fade Gate value (limit attenuated lights)
int worldminlight = -1;
int worldmaxlight = -1;
byte *filebase1, *file_p1, *file_end1;
byte *filebase3, *file_p3, *file_end3;
dmodel_t *bspmodel;
int bspfileface; // next surface to dispatch
vec3_t bsp_origin;
vec3_t *faceoffset; // Rotating entities related
int OverSample = 1; // 1 = No oversampling
int SoftLight = -1; // -1 = Disabled
int SoftDist = SOFTDIST; // Distance tolerance for lights behind surface
int SingleDist; // Distance tolerance for lights behind surface in SingleLightFace
int SkyDist; // Distance tolerance for lights behind surface in SkyLightFace
int LightCap = 0; // 0 = Disabled
int NumSurfPts = 0; // Total # surface points
unsigned int FastLight = 0; // 0 = No fast lighting
qboolean NoLight = false; // Disables all light entities except global
qboolean SrcLight = false; // Disables all unsourced light entities
qboolean NoWarnings = false; // Disable repetitive warnings
qboolean DisableScreen = false;
qboolean OldLight = false; // Disables wait/delay/mangle
qboolean TyrLiteMode = false; // Enables TyrLite mode
qboolean TyrLite95Mode = false;// Enables TyrLite95 mode
qboolean ArghLiteMode = false; // Enables ArghLite mode
qboolean AddMinLight = false; // Enables additive minlight
qboolean UnsupDetails = false; // Prints out unsupported details
qboolean DetectKeys = false; // Prints out detected keys summary
qboolean NoSkillChk = false; // Disable fuzzy skill target check
qboolean NoFlash = false; // Disables flashing lights
qboolean GlobRange = false; // Enables global light range
qboolean IKLiteMode = false; // Enables IKLite mode
qboolean IKAngle = false; // Enables IKLite angle sensitivity
qboolean LightDLXMode = false; // Enables LightDLX mode
qboolean OnlyEnts = false; // Only process switchable lights
qboolean NoWrite = false; // Disable bsp write
qboolean NoReverse = false; // Prevents reverse entity key order
qboolean GenCompatible = false;// Enables closer general compatibility
qboolean ATCompatible = false; // Enables closer Argh/TyrLite compatibility
qboolean TyrCompatible = false;// Enables closer TyrLite compatibility
qboolean EnhancedTP = false; // Enables QuArK/Hammer Enhanced Texture Positioning support
qboolean AntiLights = false; // True if negative lights used
qboolean NoAnti = false; // True if negative lights disabled
qboolean NoAntiOption = false; // True if negative lights disabled via "-noanti" option
qboolean KinnDelay = false; // Translates delay 2 lights into delay 5
qboolean SolidSky = false; // True if also solid sky brushes will cast sunlight
qboolean PreScan; // True when only calculating # total surfpts, avoid ray tracing
//new settings
qboolean FakeGISunlight2 = false;//makes sunlight2 cast additive light instead of minlight.
qboolean FakeGIMode = false; //makes fake GI with additive light from an array of lights that emit from the void
float SunLight[2] = {-1, -1};
int SunMangleVal[3] = {-1, -1, -1};
float SunLightColor[2][3] = {{255, 255, 255}, {255, 255, 255}};
int NoOfSuns, NoOfHSuns, NoOfVSuns;
vec3_t SunMangle[NOOFSUNS];
/*
If you are not using fake GI modes, the SunMangle array is actually overlarge. I don't want to mess with malloc
so I took the lazy route. Big deal, it's a few extra byes. :S
*/
vec_t DistFactor1; // IKLite related values
vec_t DistFactor2;
double start = 0, end;
FILE *logfile;
void logvprintf (char *fmt, va_list argptr)
{
if (PreScan)
return; // No printouts during prescan
if (!NoWarnings || !DisableScreen)
{
// ShowPercent (0, NULL, 0, -1);
vprintf (fmt, argptr);
fflush (stdout);
}
vfprintf (logfile, fmt, argptr);
fflush (logfile);
}
void logprintf (char *fmt, ...)
{
va_list argptr;
va_start (argptr, fmt);
logvprintf (fmt, argptr);
va_end (argptr);
}
void logwprintf (char *fmt, ...)
{
va_list argptr;
DisableScreen = true;
va_start (argptr, fmt);
logvprintf (fmt, argptr);
va_end (argptr);
DisableScreen = false;
}
void PrintFinish (void)
{
char Str[20];
if (start != 0)
{
end = I_FloatTime ();
SecToStr ((end - start + 0.5), Str, true);
logprintf ("\nElapsed time : %s\n", Str);
}
fclose (logfile);
}
void ErrorExit (void)
{
PrintFinish ();
exit (1);
}
/*
==================
ToRad
Converts from degrees to radians
==================
*/
vec_t ToRad (vec_t Degree)
{
return Degree * Q_PI / 180;
}
/*
==================
ToDegree
Converts from radians to degrees
==================
*/
vec_t ToDegree (vec_t Rad)
{
return Rad * 180 / Q_PI;
}
byte *GetFileSpace (int size)
{
byte *buf;
LOCK;
buf = file_p1;
file_p1 = (byte *) (((long) file_p1 + 3) & ~3);
if (file_p1 - buf > 0)
memset (buf, 0, file_p1 - buf); // Clear pad bytes
buf = file_p1;
file_p1 += size;
UNLOCK;
if (file_p1 > file_end1)
Error ("Light data size exceeded, max = %s", PrtSize (MAX_MAP_LIGHTING));
return buf;
}
DWORD WINAPI LightThread (LPVOID *data)
{
int i;
// only print on the first thread
threadinfo_t *threadinfo = (threadinfo_t *) data;
if (NewLine)
fprintf (logfile, "\n");
else logprintf ("\n");
if (SimpPercent)
printf ("\n");
ShowPercent (threadinfo->threadnum, "Light", 0, 0);
// reduce thread locking overhead by partitioning the BSP faces
for (i = threadinfo->firstface; i < threadinfo->lastface; i++)
{
ShowPercent (threadinfo->threadnum, NULL, (i - threadinfo->firstface), (threadinfo->lastface - threadinfo->firstface));
LightFace (i, faceoffset[i]);
}
ShowPercent (threadinfo->threadnum, NULL, 100, 100);
LOCK;
finished++;
UNLOCK;
return 0;
}
void FindFaceOffsets (void)
{
int i, j;
entity_t *ent;
char name[20];
vec3_t org;
faceoffset = malloc (numfaces * sizeof (vec3_t));
memset (faceoffset, 0, numfaces * sizeof (vec3_t));
for (i = 1; i < nummodels; i++)
{
sprintf (name, "*%d", i);
ent = FindEntityWithKeyPair ("model", name);
if (!ent)
logprintf ("WARNING: FindFaceOffsets: Couldn't find entity for model %s\n", name);
else if (!strncmp (ValueForKey (ent, "classname"), "rotate_", 7))
{
int start;
int end;
GetVectorForKey (ent, "origin", org);
start = dmodels[ i ].firstface;
end = start + dmodels[ i ].numfaces;
if (start >= numfaces || end > numfaces)
Error ("FindFaceOffsets: numfaces (%d) exceeded, start=%d, end=%d", numfaces, start, end);
for (j = start; j < end; j++)
{
faceoffset[ j ][ 0 ] = org[ 0 ];
faceoffset[ j ][ 1 ] = org[ 1 ];
faceoffset[ j ][ 2 ] = org[ 2 ];
}
}
}
}
/*
=============
LightWorld
=============
*/
void LightWorld (void)
{
// Allocate max lightdata
if (dlightdata1 != NULL)
free (dlightdata1);
if (dlightdata3 != NULL)
free (dlightdata3);
dlightdata1 = malloc (MAX_MAP_LIGHTING);
dlightdata3 = malloc (MAX_MAP_LIGHTING * 3);
lightdatasize1 = MAX_MAP_LIGHTING;
lightdatasize3 = MAX_MAP_LIGHTING * 3;
filebase1 = file_p1 = dlightdata1;
file_end1 = filebase1 + MAX_MAP_LIGHTING;
filebase3 = file_p3 = dlightdata3;
file_end3 = filebase3 + MAX_MAP_LIGHTING * 3;
RunThreadsOn (LightThread);
lightdatasize1 = file_p1 - filebase1;
lightdatasize3 = file_p3 - filebase3;
logprintf ("lightdatasize: %s\n", PrtSize (lightdatasize1));
}
/*
==============
PrintOptions
==============
*/
void PrintOptions (void)
{
logprintf ("Light performs light processing of Quake .BSP files\n\n");
logprintf ("light [options] bspfile\n\n");
logprintf ("Options:\n");
logprintf (" -threads [n] Enable multithreaded processing (faster, default 4)\n");
logprintf (" -fast [n] Enable fast lighting (lower quality, default 2)\n");
logprintf (" -soft [n] Enable soft lighting (reduce jagged shadows)\n");
logprintf (" -softdist [n] Distance tolerance for lights behind surface (default 3)\n");
logprintf (" -extra Enable extra 2x2 sampling for higher quality\n");
logprintf (" -extra4 Enable extra 4x4 sampling for even higher quality\n");
logprintf (" -dist [n] Set fade distance, higher is darker (default 1.0)\n");
logprintf (" -range [n] Set brightness range, higher is brighter (default 0.5)\n");
logprintf (" -globrange Enable global range (range affects global light)\n");
logprintf (" -noglobrange Disable global range (use with arghlite/tyrlite)\n");
logprintf (" -light [n] Set minimum light level (default 0)\n");
logprintf (" -maxlight [n] Set maximum light level (default disabled)\n");
logprintf (" -nolight Disable light entities, only global light remains\n");
logprintf (" -srclight Disable all unsourced light entities\n");
logprintf (" -sunlight [n] Set sunlight level (default 0)\n");
logprintf (" -sunlight2 [n] Set 2nd sunlight (outdoor minlight) level (default 0)\n");
logprintf (" -sunlight3 [n] Same as sunlight2 + set Shadow sensitivity to 0.4\n");
logprintf (" -sunmangle [y,p] Set sun direction, y=yaw (0 to 360),\n");
logprintf (" p=pitch (90 to -90) (default (0,-90)\n");
logprintf (" -nowarnings Disable repetitive warnings\n");
logprintf (" -rate [s,p,l,t] Control extended progress update rate and format,\n");
logprintf (" s=seconds, p=percent, l=line, t=total (default 10,1.0,1,1)\n");
logprintf (" -barpercent Simplified and weighted bargraph progress information\n");
logprintf (" -numpercent Simplified and weighted numerical progress information\n");
logprintf (" -oldlight Disable entity wait/delay/mangle/antilight features\n");
logprintf (" -tyrlite Enable TyrLite mode\n");
logprintf (" -tyrlite95 Enable TyrLite95 mode\n");
logprintf (" -arghlite Enable ArghLite mode\n");
logprintf (" -addmin Enable additive minlight\n");
logprintf (" -iklite Enable IKLite mode\n");
logprintf (" -ikangle Enable IKLite angle sensitivity\n");
logprintf (" -anglesense [n] Set angle sensitivity (default 0.5)\n");
logprintf (" -shadowsense [n] Set angle sensitivity for 2nd sunlight (default 0.0)\n");
logprintf (" -gate [n] Set Fade Gate (limit attenuated lights) (default 0.0)\n");
logprintf (" -dlx Enable limited LightDLX mode\n");
logprintf (" -kinn Translate delay 2 lights into delay 5\n");
logprintf (" -solidsky Enable solid sky brushes\n");
logprintf (" -unsup Print details about unsupported keys\n");
logprintf (" -detect Print detected keys summary\n");
logprintf (" -noskill Disable fuzzy skill target check\n");
logprintf (" -noflash Disable flashing lights\n");
logprintf (" -noanti Disable antilights\n");
logprintf (" -lightcap [n] Set maximum light entity intensity\n");
logprintf (" -onlyents Only process switchable light entities\n");
logprintf (" -nowrite Disable bsp write\n");
logprintf (" -norev Prevent reverse entity key order\n");
logprintf (" -etp Enable Enhanced Texture Positioning support\n");
logprintf (" -priority [n] Set thread priority 0-2 (below/normal/above, default 1)\n");
logprintf (" -oldhformat Enable hour format HH:MM:SS instead of HHh MMm\n");
logprintf (" -fakeGISun2 Causes sunlight2 to cast additive light.\n");
logprintf (" -fakeGIMode Casts additive light in an array around the world origin from the void.\n");
logprintf (" bspfile .BSP file to process\n");
fclose (logfile);
exit (1);
}
/*
========
main
light modelfile
========
*/
int main (int argc, char **argv)
{
int i, ModeCnt = 0, Val;
char source[1024], *Option, *NextOption;
float FVal;
qboolean NoGlobRange = false;
logfile = fopen (LOGFILENAME, "w");
logprintf ("----- Light 1.43 ---- Modified by Bengt Jardrup\n");
logprintf ("----- Release 2 ---- Coloured light and LIT support by MH\n\n");
for (i = 1; i < argc; i++)
{
Option = argv[i];
NextOption = i + 1 < argc ? argv[i + 1] : NULL;
if (Option[0] != '-')
break;
++Option;
if (!stricmp (Option, "fast"))
{
FastLight = 2;
if (NextOption != NULL && isdigit (NextOption[0]) && i + 2 < argc)
{
Val = atoi (NextOption);
i++;
if (Val > 2)
FastLight = Val;
}
logprintf ("Fast light %d enabled\n", FastLight);
}
else if (!stricmp (Option, "soft"))
{
SoftLight = 0;
if (NextOption != NULL && isdigit (NextOption[0]) && i + 2 < argc)
{
SoftLight = atoi (NextOption);
i++;
}
}
else if (!stricmp (Option, "softdist"))
{
SoftDist = GetArgument (Option, NextOption);
i++;
}
else if (!stricmp (Option, "extra") || !stricmp (Option, "extra4"))
{
OverSample = Option[5] == '4' ? 4 : 2;
logprintf ("Extra %dx%d sampling enabled\n", OverSample, OverSample);
}
else if (!stricmp (Option, "threads"))
{
numthreads = GetFloatArgument (Option, NextOption);
i++;
}
else if (!stricmp (Option, "dist"))
{
scaledist = GetFloatArgument (Option, NextOption);
i++;
}
else if (!stricmp (Option, "range"))
{
rangescale = GetFloatArgument (Option, NextOption);
i++;
}
else if (!stricmp (Option, "globrange"))
{
GlobRange = true;
logprintf ("Global range enabled\n");
}
else if (!stricmp (Option, "noglobrange"))
NoGlobRange = true;
else if (!stricmp (Option, "light"))
{
worldminlight = GetArgument (Option, NextOption);
i++;
}
else if (!stricmp (Option, "maxlight"))
{
worldmaxlight = GetArgument (Option, NextOption);
i++;
}
else if (!stricmp (Option, "nolight"))
{
NoLight = true;
logprintf ("Light entities disabled\n");
}
else if (!stricmp (Option, "srclight"))
{
SrcLight = true;
logprintf ("Unsourced light entities disabled\n");
}
else if (!stricmp (Option, "sunlight"))
{
SunLight[0] = GetArgument (Option, NextOption);
i++;
}
else if (!stricmp (Option, "sunlight2"))
{
SunLight[1] = GetArgument (Option, NextOption);
i++;
}
else if (!stricmp (Option, "sunlight3"))
{
SunLight[1] = GetArgument (Option, NextOption);
if (ShadowSense == -1)
ShadowSense = SHADOWSENSE;
i++;
}
else if (!stricmp (Option, "sunmangle"))
{
ChkArgument (Option, NextOption);
if (sscanf (NextOption, "%d,%d", &SunMangleVal[0], &SunMangleVal[1]) != 2)
Error ("Missing arguments for '%s'", Option);
SunMangleVal[2] = 0;
i++;
}
else if (!stricmp (Option, "nowarnings"))
NoWarnings = true;
else if (!stricmp (Option, "rate"))
{
ChkArgument (Option, NextOption);
if (sscanf (NextOption, "%d,%f,%d,%d", &SecRate, &FVal, &NewLine, &TotTime) > 1)
PercRate = (FVal + 0.05) * 10; // Fix roundoff
AutoRate = false;
i++;
}
else if (!stricmp (Option, "barpercent"))
{
SimpPercent = true;
NumPercent = false;
}
else if (!stricmp (Option, "numpercent"))
{
SimpPercent = true;
NumPercent = true;
}
else if (!stricmp (Option, "oldlight"))
{
OldLight = NoAnti = true;
logprintf ("Oldlight mode enabled\n");
++ModeCnt;
}
else if (!stricmp (Option, "tyrlite"))
{
TyrLiteMode = GlobRange = true;
logprintf ("TyrLite mode enabled\n");
++ModeCnt;
}
else if (!stricmp (Option, "tyrlite95"))
{
TyrLite95Mode = TyrLiteMode = GlobRange = true;
logprintf ("TyrLite95 mode enabled\n");
++ModeCnt;
}
else if (!stricmp (Option, "arghlite"))
{
ArghLiteMode = GlobRange = AddMinLight = true;
logprintf ("ArghLite mode enabled\n");
++ModeCnt;
}
else if (!stricmp (Option, "addmin"))
{
AddMinLight = true;
logprintf ("Additive minlight enabled\n");
}
else if (!stricmp (Option, "iklite"))
{
IKLiteMode = IKAngle = OldLight = NoAnti = true;
logprintf ("IKLite mode enabled\n");
++ModeCnt;
}
else if (!stricmp (Option, "ikangle"))
{
IKAngle = true;
logprintf ("IKLite angle sensitivity enabled\n");
}
else if (!stricmp (Option, "anglesense"))
{
FVal = GetFloatArgument (Option, NextOption);
i++;
if (FVal >= 0 && FVal <= 1 && FVal != scalecos)
logprintf ("Angle sensitivity %g set\n", scalecos = FVal);
}
else if (!stricmp (Option, "shadowsense"))
{
FVal = GetFloatArgument (Option, NextOption);
i++;
if (FVal >= 0 && FVal <= 1)
ShadowSense = FVal;
}
else if (!stricmp (Option, "gate"))
{
FVal = GetFloatArgument (Option, NextOption);
i++;
if (FVal >= 0 && FVal != GateVal)
logprintf ("Fade Gate %g set\n", GateVal = FVal);
}
else if (!stricmp (Option, "dlx"))
{
LightDLXMode = OldLight = true;
logprintf ("LightDLX mode enabled\n");
++ModeCnt;
}
else if (!stricmp (Option, "kinn"))
{
KinnDelay = true;
logprintf ("Kinn translation enabled\n");
}
else if (!stricmp (Option, "solidsky"))
{
SolidSky = true;
logprintf ("Solid sky brushes enabled\n");
}
else if (!stricmp (Option, "unsup"))
UnsupDetails = DetectKeys = true;
else if (!stricmp (Option, "detect"))
DetectKeys = true;
else if (!stricmp (Option, "noskill"))
NoSkillChk = true;
else if (!stricmp (Option, "noflash"))
NoFlash = true;
else if (!stricmp (Option, "noanti"))
NoAnti = NoAntiOption = true;
else if (!stricmp (Option, "lightcap"))
{
Val = GetArgument (Option, NextOption);
i++;
if (Val >= 0 && Val != LightCap)
logprintf ("LightCap %d enabled\n", LightCap = Val);
}
else if (!stricmp (Option, "onlyents"))
OnlyEnts = true;
else if (!stricmp (Option, "nowrite"))
NoWrite = true;
else if (!stricmp (Option, "norev"))
NoReverse = true;
else if (!stricmp (Option, "etp"))
{
EnhancedTP = true;
logprintf ("Enhanced Texture Positioning enabled\n");
}
else if (!stricmp (Option, "priority"))
{
SetQPriority (GetArgument (Option, NextOption));
i++;
}
else if (!stricmp (Option, "oldhformat"))
OldHFormat = true;
else if (!stricmp (Option, "?") || !stricmp (Option, "help"))
PrintOptions ();
else if (!stricmp (Option, "fakeGISun2"))
{
FakeGISunlight2 = true;
logprintf ("Additive sunlight2 enabled\n");
}
else if (!stricmp (Option, "fakeGIMode"))
{
FakeGIMode = true;
logprintf ("FakeGI mode enabled\n");
}
else
Error ("Unknown option '%s'", Option);
}
if (i != argc - 1)
PrintOptions ();
if (GlobRange && NoGlobRange)
{
GlobRange = false;
logprintf ("Global range disabled\n");
}
if (ModeCnt > 1)
Error ("Only one emulation mode allowed");
if (SoftLight >= 0)
{
if (SoftLight == 0)
SoftLight = OverSample / 2 + 1; // Auto mode
logprintf ("Soft light %d enabled\n", SoftLight);
if (SoftDist != SOFTDIST)
logprintf ("Soft distance %d set\n", SoftDist);
}
if (SoftLight > 0)
{
// Soft option is in charge
SingleDist = -SoftDist;
SkyDist = -SOFTDIST;
}
else
{
if (TyrLite95Mode)
{
SingleDist = 0;
SkyDist = -ANGLE_EPSILON;
}
else
SingleDist = SkyDist = 1; // Classic (no) soft distance
}
if (OverSample <= 2)
{
// Set compatibility modes
GenCompatible = OldLight || TyrLiteMode || ArghLiteMode || IKLiteMode || LightDLXMode;
ATCompatible = TyrLiteMode || ArghLiteMode;
TyrCompatible = TyrLiteMode;
}
InitThreads ();
if (!OnlyEnts && !NoWrite)
start = I_FloatTime ();
strcpy (source, argv[i]);
StripExtension (source);
DefaultExtension (source, ".bsp");
if (!NoWrite)
WriteChk (source);
logprintf ("File: %s\n", source);
LoadBSPFile (source);
LoadEntities ();
if (OnlyEnts)
logprintf ("Updating entities lump...\n");
else if (!NoWrite)
{
MakeTnodes (&dmodels[0]);
FindFaceOffsets ();
LightWorld ();
}
if (!NoWrite)
{
WriteEntitiesToString ();
WriteBSPFile (source);
}
PrintFinish ();
return 0;
}