Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8557 | maxcodehac | 1 | #include "version.h" |
2 | |||
3 | #if defined(USE_STARSKY) || defined(USE_RAIN) || defined(USE_SNOW) |
||
4 | |||
5 | #include "wl_def.h" |
||
6 | |||
7 | #if defined(USE_RAIN) || defined(USE_SNOW) |
||
8 | uint32_t rainpos = 0; |
||
9 | #endif |
||
10 | |||
11 | typedef struct { |
||
12 | int32_t x, y, z; |
||
13 | } point3d_t; |
||
14 | |||
15 | #define MAXPOINTS 400 |
||
16 | point3d_t points[MAXPOINTS]; |
||
17 | |||
18 | byte moon[100]={ |
||
19 | 0, 0, 27, 18, 15, 16, 19, 29, 0, 0, |
||
20 | 0, 22, 16, 15, 15, 16, 16, 18, 24, 0, |
||
21 | 27, 17, 15, 17, 16, 16, 17, 17, 18, 29, |
||
22 | 18, 15, 15, 15, 16, 16, 17, 17, 18, 20, |
||
23 | 16, 15, 15, 16, 16, 17, 17, 18, 19, 21, |
||
24 | 16, 15, 17, 20, 18, 17, 18, 18, 20, 22, |
||
25 | 19, 16, 18, 19, 17, 17, 18, 19, 22, 24, |
||
26 | 28, 19, 17, 17, 17, 18, 19, 21, 25, 31, |
||
27 | 0, 23, 18, 19, 18, 20, 22, 24, 28, 0, |
||
28 | 0, 0, 28, 21, 20, 22, 28, 30, 0, 0 }; |
||
29 | |||
30 | void Init3DPoints() |
||
31 | { |
||
32 | int hvheight = viewheight >> 1; |
||
33 | for(int i = 0; i < MAXPOINTS; i++) |
||
34 | { |
||
35 | point3d_t *pt = &points[i]; |
||
36 | pt->x = 16384 - (rand() & 32767); |
||
37 | pt->z = 16384 - (rand() & 32767); |
||
38 | float len = sqrt((float)pt->x * pt->x + (float)pt->z * pt->z); |
||
39 | int j=50; |
||
40 | do |
||
41 | { |
||
42 | pt->y = 1024 + (rand() & 8191); |
||
43 | j--; |
||
44 | } |
||
45 | while(j > 0 && (float)pt->y * 256.F / len >= hvheight); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | #endif |
||
50 | |||
51 | #ifdef USE_STARSKY |
||
52 | |||
53 | void DrawStarSky(byte *vbuf, uint32_t vbufPitch) |
||
54 | { |
||
55 | int hvheight = viewheight >> 1; |
||
56 | int hvwidth = viewwidth >> 1; |
||
57 | |||
58 | byte *ptr = vbuf; |
||
59 | int i; |
||
60 | for(i = 0; i < hvheight; i++, ptr += vbufPitch) |
||
61 | memset(ptr, 0, viewwidth); |
||
62 | |||
63 | for(i = 0; i < MAXPOINTS; i++) |
||
64 | { |
||
65 | point3d_t *pt = &points[i]; |
||
66 | int32_t x = pt->x * viewcos + pt->z * viewsin; |
||
67 | int32_t y = pt->y << 16; |
||
68 | int32_t z = (pt->z * viewcos - pt->x * viewsin) >> 8; |
||
69 | if(z <= 0) continue; |
||
70 | int shade = z >> 18; |
||
71 | if(shade > 15) continue; |
||
72 | int32_t xx = x / z + hvwidth; |
||
73 | int32_t yy = hvheight - y / z; |
||
74 | if(xx >= 0 && xx < viewwidth && yy >= 0 && yy < hvheight) |
||
75 | vbuf[yy * vbufPitch + xx] = shade + 15; |
||
76 | } |
||
77 | |||
78 | int32_t x = 16384 * viewcos + 16384 * viewsin; |
||
79 | int32_t z = (16384 * viewcos - 16384 * viewsin) >> 8; |
||
80 | if(z <= 0) return; |
||
81 | int32_t xx = x / z + hvwidth; |
||
82 | int32_t yy = hvheight - ((hvheight - (hvheight >> 3)) << 22) / z; |
||
83 | if(xx > -10 && xx < viewwidth) |
||
84 | { |
||
85 | int stopx = 10, starty = 0, stopy = 10; |
||
86 | i = 0; |
||
87 | if(xx < 0) i = -xx; |
||
88 | if(xx > viewwidth - 11) stopx = viewwidth - xx; |
||
89 | if(yy < 0) startj = -yy; |
||
90 | if(yy > viewheight - 11) stopy = viewheight - yy; |
||
91 | for(; i < stopx; i++) |
||
92 | for(int j = starty; j < stopy; j++) |
||
93 | vbuf[(yy + j) * vbufPitch + xx + i] = moon[j * 10 + i]; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | #endif |
||
98 | |||
99 | #ifdef USE_RAIN |
||
100 | |||
101 | void DrawRain(byte *vbuf, uint32_t vbufPitch) |
||
102 | { |
||
103 | #if defined(USE_FLOORCEILINGTEX) && defined(FIXRAINSNOWLEAKS) |
||
104 | fixed dist; // distance to row projection |
||
105 | fixed tex_step; // global step per one screen pixel |
||
106 | fixed gu, gv, floorx, floory; // global texture coordinates |
||
107 | #endif |
||
108 | |||
109 | fixed px = (player->y + FixedMul(0x7900, viewsin)) >> 6; |
||
110 | fixed pz = (player->x - FixedMul(0x7900, viewcos)) >> 6; |
||
111 | int32_t ax, az, x, y, z, xx, yy, height, actheight; |
||
112 | int shade; |
||
113 | int hvheight = viewheight >> 1; |
||
114 | int hvwidth = viewwidth >> 1; |
||
115 | |||
116 | rainpos -= tics * 900; |
||
117 | for(int i = 0; i < MAXPOINTS; i++) |
||
118 | { |
||
119 | point3d_t *pt = &points[i]; |
||
120 | ax = pt->x + px; |
||
121 | ax = 0x1fff - (ax & 0x3fff); |
||
122 | az = pt->z + pz; |
||
123 | az = 0x1fff - (az & 0x3fff); |
||
124 | x = ax * viewcos + az * viewsin; |
||
125 | y = -(heightnumerator << 7) + ((((pt->y << 6) + rainpos) & 0x0ffff) << 11); |
||
126 | z = (az * viewcos - ax * viewsin) >> 8; |
||
127 | if(z <= 0) continue; |
||
128 | shade = z >> 17; |
||
129 | if(shade > 13) continue; |
||
130 | xx = x / z + hvwidth; |
||
131 | if(xx < 0 || xx >= viewwidth) continue; |
||
132 | actheight = y / z; |
||
133 | yy = hvheight - actheight; |
||
134 | height = (heightnumerator << 10) / z; |
||
135 | if(actheight < 0) actheight = -actheight; |
||
136 | if(actheight < (wallheight[xx] >> 3) && height < wallheight[xx]) continue; |
||
137 | |||
138 | if(xx >= 0 && xx < viewwidth && yy > 0 && yy < viewheight) |
||
139 | { |
||
140 | #if defined(USE_FLOORCEILINGTEX) && defined(FIXRAINSNOWLEAKS) |
||
141 | // Find the rain's tile coordinate |
||
142 | // NOTE: This sometimes goes over the map edges. |
||
143 | dist = ((heightnumerator / ((height >> 3) + 1)) << 5); |
||
144 | gu = viewx + FixedMul(dist, viewcos); |
||
145 | gv = -viewy + FixedMul(dist, viewsin); |
||
146 | floorx = ( gu >> TILESHIFT ) & 63; |
||
147 | floory = (-(gv >> TILESHIFT) - 1) & 63; |
||
148 | |||
149 | // Is there a ceiling tile? |
||
150 | if(MAPSPOT(floorx, floory, 2) >> 8) continue; |
||
151 | #endif |
||
152 | |||
153 | vbuf[yy * vbufPitch + xx] = shade+15; |
||
154 | vbuf[(yy - 1) * vbufPitch + xx] = shade+16; |
||
155 | if(yy > 2) |
||
156 | vbuf[(yy - 2) * vbufPitch + xx] = shade+17; |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | #endif |
||
162 | |||
163 | #ifdef USE_SNOW |
||
164 | |||
165 | void DrawSnow(byte *vbuf, uint32_t vbufPitch) |
||
166 | { |
||
167 | #if defined(USE_FLOORCEILINGTEX) && defined(FIXRAINSNOWLEAKS) |
||
168 | fixed dist; // distance to row projection |
||
169 | fixed tex_step; // global step per one screen pixel |
||
170 | fixed gu, gv, floorx, floory; // global texture coordinates |
||
171 | #endif |
||
172 | |||
173 | fixed px = (player->y + FixedMul(0x7900, viewsin)) >> 6; |
||
174 | fixed pz = (player->x - FixedMul(0x7900, viewcos)) >> 6; |
||
175 | int32_t ax, az, x, y, z, xx, yy, height, actheight; |
||
176 | int shade; |
||
177 | int hvheight = viewheight >> 1; |
||
178 | int hvwidth = viewwidth >> 1; |
||
179 | |||
180 | rainpos -= tics * 256; |
||
181 | for(int i = 0; i < MAXPOINTS; i++) |
||
182 | { |
||
183 | point3d_t *pt = &points[i]; |
||
184 | ax = pt->x + px; |
||
185 | ax = 0x1fff - (ax & 0x3fff); |
||
186 | az = pt->z + pz; |
||
187 | az = 0x1fff - (az & 0x3fff); |
||
188 | x = ax * viewcos + az * viewsin; |
||
189 | y = -(heightnumerator << 7) + ((((pt->y << 6) + rainpos) & 0x0ffff) << 11); |
||
190 | z = (az * viewcos - ax * viewsin) >> 8; |
||
191 | if(z <= 0) continue; |
||
192 | shade = z >> 17; |
||
193 | if(shade > 13) continue; |
||
194 | xx = x / z + hvwidth; |
||
195 | if(xx < 0 || xx >= viewwidth) continue; |
||
196 | actheight = y / z; |
||
197 | yy = hvheight - actheight; |
||
198 | height = (heightnumerator << 10) / z; |
||
199 | if(actheight < 0) actheight = -actheight; |
||
200 | if(actheight < (wallheight[xx] >> 3) && height < wallheight[xx]) continue; |
||
201 | if(xx > 0 && xx < viewwidth && yy > 0 && yy < viewheight) |
||
202 | { |
||
203 | #if defined(USE_FLOORCEILINGTEX) && defined(FIXRAINSNOWLEAKS) |
||
204 | // Find the snow's tile coordinate |
||
205 | // NOTE: This sometimes goes over the map edges. |
||
206 | dist = ((heightnumerator / ((height >> 3) + 1)) << 5); |
||
207 | gu = viewx + FixedMul(dist, viewcos); |
||
208 | gv = -viewy + FixedMul(dist, viewsin); |
||
209 | floorx = ( gu >> TILESHIFT ) & 63; |
||
210 | floory = (-(gv >> TILESHIFT) - 1) & 63; |
||
211 | |||
212 | // Is there a ceiling tile? |
||
213 | if(MAPSPOT(floorx, floory, 2) >> 8) continue; |
||
214 | #endif |
||
215 | |||
216 | if(shade < 10) |
||
217 | { |
||
218 | vbuf[yy * vbufPitch + xx] = shade+17; |
||
219 | vbuf[yy * vbufPitch + xx - 1] = shade+16; |
||
220 | vbuf[(yy - 1) * vbufPitch + xx] = shade+16; |
||
221 | vbuf[(yy - 1) * vbufPitch + xx - 1] = shade+15; |
||
222 | } |
||
223 | else |
||
224 | vbuf[yy * vbufPitch + xx] = shade+15; |
||
225 | } |
||
226 | } |
||
227 | } |
||
228 | |||
229 | #endif>><>>>>>>><>>=>><>><>><>>><>>>>>>><>>=>><>><>><>>>>>>>><>=>>>=>><>>>> |