-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwl_atmos.cpp
328 lines (292 loc) · 9.63 KB
/
wl_atmos.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
#include "version.h"
#if defined(USE_STARSKY) || defined(USE_RAIN) || defined(USE_SNOW)
#include "wl_def.h"
#include "wl_atmos.h"
#if defined(USE_RAIN) || defined(USE_SNOW)
uint32_t rainpos = 0;
#endif
typedef struct {
int32_t x, y, z;
} point3d_t;
#define MAXPOINTS 500
point3d_t points[MAXPOINTS];
byte moon[100]={
0, 0, 27, 18, 15, 16, 19, 29, 0, 0,
0, 22, 16, 15, 15, 16, 16, 18, 24, 0,
27, 17, 15, 17, 16, 16, 17, 17, 18, 29,
18, 15, 15, 15, 16, 16, 17, 17, 18, 20,
16, 15, 15, 16, 16, 17, 17, 18, 19, 21,
16, 15, 17, 20, 18, 17, 18, 18, 20, 22,
19, 16, 18, 19, 17, 17, 18, 19, 22, 24,
28, 19, 17, 17, 17, 18, 19, 21, 25, 31,
0, 23, 18, 19, 18, 20, 22, 24, 28, 0,
0, 0, 28, 21, 20, 22, 28, 30, 0, 0 };
/*
======================
=
= Init3DPoints
=
======================
*/
void Init3DPoints()
{
for(int i = 0; i < MAXPOINTS; i++)
{
point3d_t *pt = &points[i];
pt->x = 16384 - (rand() & 32767);
pt->z = 16384 - (rand() & 32767);
float len = sqrt((float)pt->x * pt->x + (float)pt->z * pt->z);
int j=50;
do
{
pt->y = 1024 + (rand() & 8191);
j--;
}
while(j > 0 && (float)pt->y * 256.F / len >= halfviewheight);
}
}
#endif
#ifdef USE_STARSKY
/*
======================
=
= DrawStarSky
=
======================
*/
void DrawStarSky(byte *vbuf, uint32_t vbufPitch)
{
if (!switches.textures && MAPSPOT(player->tilex,player->tiley,2) != 0)
return;
byte *ptr = vbuf;
int i;
for(i = 0; i < halfviewheight; i++, ptr += vbufPitch)
memset(ptr, 0, viewwidth);
for(i = 0; i < MAXPOINTS; i++)
{
point3d_t *pt = &points[i];
int32_t x = pt->x * viewcos + pt->z * viewsin;
int32_t y = pt->y << 16;
int32_t z = (pt->z * viewcos - pt->x * viewsin) >> 8;
if(z <= 0) continue;
int shade = z >> 18;
if(shade > 15) continue;
int32_t xx = x / z * scaleFactor + halfviewwidth;
int32_t yy = halfviewheight - y / z;
if(xx >= 0 && xx < viewwidth && yy >= 0 && yy < halfviewheight)
vbuf[yy * vbufPitch + xx] = shade + 15;
}
int32_t x = 16384 * viewcos + 16384 * viewsin;
int32_t z = (16384 * viewcos - 16384 * viewsin) >> 8;
if(z <= 0) return;
int32_t xx = x / z * scaleFactor + halfviewwidth;
int32_t yy = halfviewheight - ((halfviewheight - (halfviewheight >> 3)) << 22) / z;
if(xx > -10 && xx < viewwidth)
{
int stopx = 10 * scaleFactor, starty = 0, stopy = 10 * scaleFactor;
i = 0;
if(xx < 0) {i = -xx; xx = 0;}
if(xx > viewwidth - 11 * (signed)scaleFactor) stopx = viewwidth - xx;
if(yy < 0) starty = -yy;
if(yy > viewheight - 11 * (signed)scaleFactor) stopy = viewheight - yy;
for(; i < stopx; i++)
for(int j = starty; j < stopy; j++)
vbuf[(yy + j) * vbufPitch + xx + i] = moon[j/scaleFactor * 10 + i/scaleFactor];
}
}
#endif
#ifdef USE_RAIN
/*
======================
=
= DrawRain
=
======================
*/
void DrawRain(byte *vbuf, uint32_t vbufPitch)
{
#if defined(USE_FLOORCEILINGTEX) && defined(FIXRAINSNOWLEAKS)
fixed dist; // distance to row projection
fixed gu, gv, floorx, floory; // global texture coordinates
#endif
fixed px = (player->y + FixedMul(0x7900, viewsin)) >> 6;
fixed pz = (player->x - FixedMul(0x7900, viewcos)) >> 6;
int32_t ax, az, x, y, z, xx, yy, height, actheight;
int shade;
rainpos -= tics * 900;
for(int i = 0; i < MAXPOINTS; i++)
{
#ifdef VARIABLEWEATHER
if (i > gamestate.weatherpoints) break;
#endif
point3d_t *pt = &points[i];
ax = pt->x + px;
ax = 0x1fff - (ax & 0x3fff);
az = pt->z + pz;
az = 0x1fff - (az & 0x3fff);
x = ax * viewcos + az * viewsin;
y = -(57278464) + +((((pt->y << 6) + rainpos) & 0x0ffff) << 11);
z = (az * viewcos - ax * viewsin) << 8 ;
if(z <= 0) continue;
shade = z >> 17;
if(shade > 13) continue;
xx = x / z + halfviewwidth;
if(xx < 0 || xx >= viewwidth) continue;
actheight = y / z;
yy = halfviewheight - actheight;
height = (458227712) / z;
if(actheight < 0) actheight = -actheight;
if(actheight < (wallheight[xx] >> 3) && height < wallheight[xx]) continue;
if(xx >= 0 && xx < viewwidth && yy > 0 && yy < viewheight)
{
#if defined(USE_FLOORCEILINGTEX) && defined(FIXRAINSNOWLEAKS)
// Find the rain's tile coordinate
// NOTE: This sometimes goes over the map edges.
dist = ((heightnumerator / (( (( heightnumerator << 10) / z)>> 3) + 1)) << 5);
gu = viewx + FixedMul(dist, viewcos);
gv = -viewy + FixedMul(dist, viewsin);
floorx = ( gu >> TILESHIFT ) & (MAPSIZE-1);
floory = (-(gv >> TILESHIFT) - 1) & (MAPSIZE-1);
// Is there a ceiling tile?
if(MAPSPOT(floorx, floory, 2) >> 8) continue;
#endif
vbuf[yy * vbufPitch + xx] = shade+15;
vbuf[(yy - 1) * vbufPitch + xx] = shade+16;
if(yy > 2)
vbuf[(yy - 2) * vbufPitch + xx] = shade+17;
}
}
}
#endif
#ifdef USE_SNOW
/*
======================
=
= DrawSnow
=
======================
*/
void DrawSnow(byte *vbuf, uint32_t vbufPitch)
{
#if defined(USE_FLOORCEILINGTEX) && defined(FIXRAINSNOWLEAKS)
fixed dist; // distance to row projection
// fixed tex_step; // global step per one screen pixel
fixed gu, gv, floorx, floory; // global texture coordinates
#endif
fixed px = (player->y + FixedMul(0x7900, viewsin)) >> 6;
fixed pz = (player->x - FixedMul(0x7900, viewcos)) >> 6;
int32_t ax, az, x, y, z, xx, yy, height, actheight;
int shade;
rainpos -= tics * 256;
for(int i = 0; i < MAXPOINTS; i++)
{
#ifdef VARIABLEWEATHER
if (i > gamestate.weatherpoints) break;
#endif
point3d_t *pt = &points[i];
ax = pt->x + px;
ax = 0x1fff - (ax & 0x3fff);
az = pt->z + pz;
az = 0x1fff - (az & 0x3fff);
x = ax * viewcos + az * viewsin;
y = -(57278464) + ((((pt->y << 6) + rainpos) & 0x0ffff) << 11);
z = (az * viewcos - ax * viewsin) >> 8;
if(z <= 0) continue;
shade = z >> 17;
if(shade > 13) continue;
xx = x / z * scaleFactor + halfviewwidth;
if(xx < 0 || xx >= viewwidth) continue;
actheight = y/z;
yy = halfviewheight - actheight;
height = (458227712) / z;
if(actheight < 0) actheight = -actheight;
if(actheight < (wallheight[xx] >> 3) && height < wallheight[xx]) continue;
if(xx > 0 && xx < viewwidth && yy > 0 && yy < viewheight)
{
#if defined(USE_FLOORCEILINGTEX) && defined(FIXRAINSNOWLEAKS)
// Find the snow's tile coordinate
// NOTE: This sometimes goes over the map edges.
dist = ((heightnumerator / ((( heightnumerator << 10) / z) + 1)) << 5);
gu = viewx + FixedMul(dist, viewcos);
gv = -viewy + FixedMul(dist, viewsin);
floorx = ( gu >> TILESHIFT ) & (MAPSIZE - 1);
floory = (-(gv >> TILESHIFT) - 1) & (MAPSIZE - 1);
// Is there a ceiling tile?
if(MAPSPOT(floorx, floory, 2) >> 8) continue;
#endif
if(shade < 10)
{
vbuf[yy * vbufPitch + xx] = shade+17;
vbuf[yy * vbufPitch + xx - 1] = shade+16;
vbuf[(yy - 1) * vbufPitch + xx] = shade+16;
vbuf[(yy - 1) * vbufPitch + xx - 1] = shade+15;
}
else
vbuf[yy * vbufPitch + xx] = shade+15;
}
}
}
#endif
#ifdef VARIABLEWEATHER
/*
======================
=
= InitializeWeatherState
=
======================
*/
void InitializeWeatherState() {
#ifdef CRAND
int chance = Random(100);
#else
int chance = US_RndT();
#endif
gamestate.weatherchecktics = WEATHERCHANGEDELAY * 70;
gamestate.weatherdelaytics = WEATHERDELAY * 70;
gamestate.weatherchange = 0;
#ifdef CRAND
if (chance < 40) { // 40% no weather
gamestate.weatherpoints = 0; // no weather
} else if (chance < 60) { // 20% in-between
gamestate.weatherpoints = Random(100) + 5;
} else { // 40% weather
gamestate.weatherpoints = MAXPOINTS;
}
#else
if (chance < 100) { // 40% no weather
gamestate.weatherpoints = 0; // no weather
} else if (chance < 125) { // 20% in-between
gamestate.weatherpoints = US_RndT() + 5;
} else { // 40% weather
gamestate.weatherpoints = MAXPOINTS;
}
#endif
}
/*
======================
=
= PollWeatherChange
=
======================
*/
void PollWeatherChange() {
#ifdef CRAND
if (Random(100) < 20) {
#else
if (US_RndT() < 50) {
#endif// 20% chance for weather to change
if (gamestate.weatherpoints == 0) {
gamestate.weatherchange = 1;
} else if (gamestate.weatherpoints == MAXPOINTS) {
gamestate.weatherchange = -1;
} else {
#ifdef CRAND
gamestate.weatherchange = (Random(2) == 0 ? -1 : 1);
#else
gamestate.weatherchange = (US_RndT() % 2 == 0 ? -1 : 1);
#endif
}
}
gamestate.weatherchecktics = WEATHERCHANGEDELAY * 70;
}
#endif