-
Notifications
You must be signed in to change notification settings - Fork 1
/
light.c
200 lines (145 loc) · 2.79 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
// lighting.c
#include "light.h"
void GenerateLITFile (char *source);
void ProcessColour (void);
int oversample = 1;
/*
NOTES
-----
*/
float scaledist = 1.0;
float scalecos = 0.5;
float rangescale = 0.5;
byte *filebase, *file_p, *file_end;
dmodel_t *bspmodel;
int bspfileface; // next surface to dispatch
vec3_t bsp_origin;
int extrasamples = 1;
float minlights[MAX_MAP_FACES];
byte *GetFileSpace (int size)
{
byte *buf;
file_p = (byte *)(((long)file_p + 3)&~3);
buf = file_p;
file_p += size;
if (file_p > file_end)
Error ("GetFileSpace: overrun");
return buf;
}
void LightThread (qboolean test)
{
int i;
int progress_stride;
int progress_tick = 0;
progress_stride = numfaces / 77;
// set up progress as if it was for real
progress_tick = 0;
bspfileface = 0;
if (test)
printf ("Building Coloured Light...\n[");
else printf ("Lighting World...\n[");
while (1)
{
i = bspfileface++;
if (i >= numfaces)
break;
progress_tick++;
if (progress_tick > progress_stride)
{
printf (" ");
progress_tick = 0;
}
}
printf ("]\r[");
// now do it really for real
progress_tick = 0;
bspfileface = 0;
while (1)
{
i = bspfileface++;
if (i >= numfaces)
{
printf ("\n\n");
return;
}
progress_tick++;
if (progress_tick > progress_stride)
{
printf ("*");
progress_tick = 0;
}
LightFace (i, test);
}
}
/*
=============
LightWorld
=============
*/
void LightWorld (void)
{
filebase = file_p = dlightdata;
file_end = filebase + MAX_MAP_LIGHTING;
LightThread (false);
lightdatasize = file_p - filebase;
printf ("Light Data Size: %i\n\n", lightdatasize);
}
/*
========
main
light modelfile
========
*/
int main (int argc, char **argv)
{
int i;
double start, end;
char source[1024];
for (i=1 ; i<argc ; i++)
{
if (!strcmp(argv[i], "-extra"))
{
extrasamples = 2;
printf ("2 x extra sampling enabled\n");
}
else if (!strcmp(argv[i], "-extra4"))
{
extrasamples = 4;
printf ("4 x extra sampling enabled\n");
}
else if (!strcmp(argv[i],"-dist"))
{
scaledist = atof (argv[i+1]);
i++;
}
else if (!strcmp(argv[i],"-range"))
{
rangescale = atof (argv[i+1]);
i++;
}
else if (argv[i][0] == '-')
Error ("Unknown option \"%s\"", argv[i]);
else
break;
}
if (i != argc - 1)
Error ("usage: light [-extra] bspfile");
InitThreads ();
start = I_FloatTime ();
strcpy (source, argv[i]);
StripExtension (source);
DefaultExtension (source, ".bsp");
LoadBSPFile (source);
LoadEntities ();
MakeTnodes (&dmodels[0]);
printf ("Lighting %i Surfaces\n", numfaces);
printf ("\n");
ProcessColour ();
LightWorld ();
WriteEntitiesToString ();
WriteBSPFile (source);
GenerateLITFile (source);
end = I_FloatTime ();
printf ("%0.2f Seconds Elapsed\n", end - start);
return 0;
}